fetch and Web Crypto, and ships as ES modules with its types.
new Hotkey({ apiKey, baseUrl }) takes the key and host instead. baseUrl is https://console.hotkey.so by default, and HOTKEY_BASE_URL sets it too.
One browser per end user
getOrCreate makes the browser, or, when one already has that external_id (409 browser_exists), returns that one. The same steps with webhooks are in the package’s examples/per-end-user.ts, and on One browser per end user.
What the client does for you
- Idempotency keys. Every
POSTandPATCHcarries anIdempotency-Key. The client makes one per call and sends the same key with each retry of that call, so a retry never makes a second browser or ask. To choose it, pass{ idempotencyKey: 'browser-user_829' }as the last argument. - Retries. A 429 or 503 (
rate_limited,browsers_busy,server_busy,restarting) means nothing ran: the client waits itsRetry-Afterand sends it again. So does 409idempotency_key_in_use. A lost connection, a timeout, or a 500, 502 or 504 is tried again with backoff (0.5 s, 1 s, 2 s …) only when that is safe: aGET, or a write with its key.maxRetriesis 3; aRetry-Afterlonger thanmaxRetryWaitMs(60 s) is thrown instead of waited out. The wrong-key lockout (429too_many_attempts, 10 minutes) is never retried. - Timeouts. Each try gives up after
timeoutMs, 90 s by default, since a wake may wait 20 s for a place. - Paging. Awaiting a list gives one page.
for awaitover it, or over the call, goes through every page.
onResponse is called after every try, retries included, for logs and metrics.
Errors
Every error answer is thrown as a subclass ofHotkeyError chosen by status, with the fields of the error body:
code. body holds the whole error object, with the fields some codes add, such as browser on browser_exists and limit on browsers_busy.
Lists
events.follow() reads the log as it grows, from now or after an event id you kept:
Webhooks
Pass the raw body, before any JSON parsing, theHotkey-Signature header and the endpoint’s secret:
verifySignature answers true or false instead. signPayload(body, secret) makes a header for your receiver’s own tests.
Every method
hotkey.request(method, path, { query, body }) calls any other route with the same retries and errors.