npm
@linkskipper/sdk · v0.2.1GitHub
Source, issues, and changelog.
Install
fetch), a modern browser, or a custom fetch passed in.
Ships ESM with TypeScript types.
Initialize
Client options
Your
sk_live_… key. Throws LinkSkipperError if missing.Override the API base URL.
Per-request timeout in milliseconds.
Default poll interval for
resolveAndWait.Default overall deadline for
resolveAndWait.Retry tuning:
{ maxAttempts: 3, initialDelayMs: 500, maxDelayMs: 8000, backoffFactor: 2 }.
Retries 429 and 5xx, honoring Retry-After, with exponential backoff and jitter.Custom fetch implementation (for older Node or testing).
Override the default
User-Agent.Methods
resolve
resolve(url, options?) => Promise<ResolveResult>
Submits a URL to POST /v1/resolve. Returns immediately — a cached link comes back with
status: "done", a new one with status: "queued" and a jobId.
The shortener URL to resolve.
Sent as the
Idempotency-Key header to de-duplicate retries.ResolveResult exposes jobId, status, url, targetUrl, provider, tier,
creditsCharged, cached, balance, queuePosition, and pollUrl (camelCase mappings of
the resolve response).
resolveAndWait
resolveAndWait(url, options?) => Promise<ResolvedLink>
The high-level helper: submits the resolve, then polls the job until it is terminal and
returns the resolved link. A cached hit returns without polling.
The shortener URL to resolve.
De-duplicate retries.
How often to poll the job.
Overall deadline. Exceeding it throws
TimeoutError.Cancel the wait loop.
ResolvedLink has a guaranteed targetUrl plus jobId, provider, tier,
creditsCharged, balance, and cached.
getJob
getJob(jobId, signal?) => Promise<Job>
Reads GET /v1/jobs/{jobId} once. Use it to poll manually or check a job from a webhook.
account
account() => Promise<Account>
Reads GET /v1/account: telegramId, balance, subscriptionUntil, and providers.
providers
providers() => Promise<ProviderEntry[]>
Reads GET /v1/providers. Each entry has provider, label, hosts, tier, and
latency.
Errors
Every failed API call rejects with anApiError subclass keyed to the response
error code. JobFailedError, TimeoutError, NetworkError, and
WebhookVerificationError cover the non-HTTP cases. All extend LinkSkipperError.
| Class | Triggered by |
|---|---|
InvalidRequestError | invalid_request (400) |
InvalidKeyError | invalid_key (401) |
OutOfCreditsError | out_of_credits (402) — .balance |
ForbiddenScopeError | forbidden_scope (403) |
NotFoundError | not_found (404) |
LinkRemovedError | link_removed (410) |
UnsupportedLinkError | unsupported_link (422) |
RateLimitedError | rate_limited (429) — .retryAfter |
QuotaExceededError | quota_exceeded (429) — .retryAfter |
ResolveFailedError | resolve_failed (502) |
ProviderDownError | provider_down (503) |
JobFailedError | A polled job ended failed/invalid — .reason, .job |
TimeoutError | resolveAndWait deadline passed — .jobId, .waitedMs |
NetworkError | Transport failure after retries — .cause |
WebhookVerificationError | verifyWebhook rejected a payload |
ApiError carries status, code, title, detail, type, balance,
retryAfter, and the raw problem object.
Webhook verification
verifyWebhook(payload, signatureHeader, secret, toleranceSeconds?) checks the
X-LinkSkipper-Signature header, the timestamp tolerance (default 300s), and the HMAC, then
returns the typed WebhookEvent. It throws WebhookVerificationError on any failure.
Exported types
The package exportsAccount, AccountProvider, Job, JobStatus, ProviderEntry,
ProviderTier, ResolveResult, ResolveStatus, ResolvedLink, ProblemDetails,
WebhookEvent/WebhookPayload, WebhookEventName, ClientOptions, ResolveOptions,
ResolveAndWaitOptions, RetryConfig, ErrorCode, and the ERROR_CODES constant.