Skip to main content
The server side of a Tassyir app. It gets and refreshes an installation’s tokens, verifies the ID tokens the dashboard hands your embedded page and the webhooks Tassyir sends, and calls the Admin API through a client typed from its OpenAPI document (version 2026-10). It has no runtime dependency and uses only fetch and WebCrypto, so it runs on Node 22 or later and on Workers-like runtimes (Cloudflare Workers, Deno, Bun). It ships ESM and CommonJS.

Install

Example

An Express server for an app with an embedded page and webhooks. Tokens and the refresh lock live in Redis (ioredis). Secrets come from the environment, never from code.
A headless app (no embedded page) gets its first tokens from the install code that its auth.callback_url receives:

Tokens

  • tassyir.authenticate(idToken) verifies the ID token, then reuses the installation’s stored offline token, or exchanges the ID token for one and stores it. Keep that token: each exchange starts a new refresh family, and Tassyir keeps at most 25 per installation. With { tokenType: 'online' } it exchanges for a one-hour token that acts for the dashboard user; that token is not stored and has no refresh token.
  • tassyir.redeemInstallCode(code) redeems a tsy_ic_… code (5 minutes, one use) and stores the tokens.
  • tassyir.oauth is the raw token endpoint client (exchangeIdToken, redeemInstallCode, refresh), with HTTP Basic client authentication. Every refusal is a TassyirOAuthError: error is OAuth’s code (invalid_grant, …), code is OAUTH_INVALID_GRANT, and fix says what to do.
  • TokenStore is yours to implement (get, set, delete by installation id). set must be durable when it resolves, and get must return the latest set. MemoryTokenStore is for tests.

Refresh locking

A refresh rotates the refresh token. If the old token is presented again more than 60 seconds later, Tassyir revokes every token of the installation, and the merchant has to re-open or reinstall the app. TokenManager (tassyir.tokens) is built so that this does not happen:
  • At most one refresh runs per installation in a process. Concurrent callers wait for it and get its result.
  • refreshLock serialises refreshes across processes. The token set is read again inside the lock, so a process that waited picks up the fresh token instead of presenting the spent one.
  • The rotated set is written to the store before the new access token is used. If that write fails, the call throws TOKEN_STORE_FAILED. The process keeps the set in memory and writes it again on the next call.
  • A refresh whose answer was lost is retried with the same token, for at most 40 seconds. That is inside the 60-second grace, so the retry is safe.
  • The process never presents a refresh token it has already rotated (REFRESH_TOKEN_ALREADY_USED), even if a stale store hands it back.
  • A refresh token that Tassyir refuses is removed from the store. The next authenticate then exchanges again.
Without refreshLock, two processes can still refresh the same installation at the same moment. Inside the grace window that is harmless, but use a lock once you run more than one process.

ID tokens

tassyir.verifyIdToken(token) (or verifyIdToken(token, { clientId, keys })) checks the token the way the backend does:
  • alg: EdDSA only. The key is chosen by kid from GET /apps/.well-known/jwks.json, which is cached for an hour and fetched again on an unknown kid (at most once every 30 seconds).
  • The signature is checked before any claim is read.
  • iss must be https://api.tassyir.io/apps and aud your client id.
  • exp, nbf and iat allow the backend’s 30 seconds of leeway, and a token may live at most 60 seconds.
It returns the user, business, installation, session and locale. An ID token is a bearer credential for about a minute: accept it over HTTPS only.

Webhooks

tassyir.verifyWebhook({ headers, body }, { installationId }) (or verifyWebhook, or verifyWebhookRequest(request, …) for a Fetch Request) checks a delivery in this order:
  1. The v1a Ed25519 signature over {webhook-id}.{webhook-timestamp}.{body}, on the raw body bytes. During a key rotation a delivery carries several signatures, and any one that verifies is enough. Keys come from GET /apps/webhook-keys and are fetched again when no key verifies.
  2. The timestamp, within 5 minutes of now.
  3. The envelope’s appId (yours) and installationId (your check: an id, a list, or a function).
  4. The unsigned tassyir-* headers must agree with the signed envelope.
If the keys cannot be fetched once the cached copy has expired, verification throws KEYS_UNAVAILABLE: answer 503 and Tassyir retries the delivery later. Test deliveries from the developer console carry sample data. They are refused with WEBHOOK_TEST_DELIVERY unless you pass { testDeliveries: 'accept' }. The SDK recognises them by their signed dlv_test_… id and evt_0 envelope id, not only by the tassyir-test header. delivery.event is typed per topic: switch (delivery.event.type) narrows data.

App proxy

Not live yet: the app proxy opens after the marketplace. A buyer’s request to https://<store>/apps/<handle>/<rest> reaches your server at <hosting.url><[app_proxy] path>/<rest>, forwarded by Tassyir without the buyer’s cookies or IP, with tassyir-* headers and an Ed25519 v1a signature by Tassyir’s webhook keys over tassyir-proxy.v1.{timestamp}.{METHOD}.{path+query}.{sha256 hex of the body}.{installationId}.{storeId}. verifyProxyRequest(request, { keys, installationId }) (or verifyProxy with { method, url, headers, body }) checks it:
  1. The signature, on the path and query exactly as received and the raw body. The label keeps a webhook’s signature from passing as a proxy request, and the reverse.
  2. The timestamp, within 5 minutes of now (PROXY_TIMESTAMP_OUT_OF_RANGE).
  3. The installation, by your check (an id, a list, or a function given the installation and the store). Required: the keys are Tassyir’s, the same for every app, so this check is what makes a request yours.
It answers the signed installationId, storeId, method and path, and the headers the signature does not cover (businessId, storeHost, country, locale) under unsigned. Refusals are TassyirVerificationErrors with a PROXY_* code: answer 401. A request may be replayed within the 5 minutes, so keep non-GET handlers idempotent. The store answers only JSON, plain text, XML or images from the proxy, and drops Set-Cookie. How a hosted app receives proxy requests is settled when the proxy opens.

Admin API

tassyir.admin(installationId) returns an AdminClient that uses the installation’s stored token and refreshes it as needed. To call with a token you hold (an online token, say), use tassyir.adminWithToken(tokens) or new AdminClient({ accessToken }). Paths are relative to /apps/2026-10, and paths, parameters, bodies and answers are typed from the OpenAPI document:
  • Errors. A problem+json answer becomes a TassyirApiError with code, fix, requestId, status, retryAfterSeconds, rateLimit and the whole problem. AdminApiErrorCode<'post', '/orders/{id}/confirm'> lists the codes that call can answer.
  • Idempotency. Every write sends an Idempotency-Key: a new UUID per call by default, reused by the SDK’s own retries. You can pass your own key, or false to send none.
  • Rate limits. Every answer’s RateLimit-* headers reach onResponse and ApiResponse.rateLimit.
  • Retries are off by default; turn them on with retries: 3. When on, the SDK waits Retry-After and retries, writes included, 429 RATE_LIMITED (the installation’s bucket), 429 BUSINESS_RATE_LIMITED (the ceiling all the business’s apps share), 429 BULK_EXPORT_RATE_LIMITED (5 bulk exports per business an hour) and 503 API_BUSY (the API was too busy and did nothing); a Retry-After longer than maxDelayMs (30 s by default) throws at once. It retries 409 IDEMPOTENCY_KEY_IN_USE, and any other 503, network errors, 502 and 504 for requests that are safe to repeat (reads, and writes with a key). It retries 500 only for reads. A 401 APP_TOKEN_INVALID gets a new token and one more try. It never retries 429 IMAGE_QUOTA_REACHED (POST /images): a daily quota is not worth retrying, so it throws at once and the error’s problem says which quota is full (per, window: day or minute, limit, retryAfter), for the app to wait or stop. It also never retries 503 BULK_EXPORTS_NOT_CONFIGURED (exports are off on that Tassyir environment) or 409 BULK_EXPORT_IN_PROGRESS (wait for bulk/finished, or read GET /bulk/exports/{id}).
  • Pagination. admin.paginate(path, { query }) walks the keyset cursors and yields items.
  • fields takes a list of field names, typed per resource: fields: ['status', 'total'].
  • Money stays a decimal string ("2500.00"). JSON is parsed as it is received; use a decimal library for arithmetic, never parseFloat.

Errors

Everything the SDK throws is a TassyirError. It has a stable code to act on, a message for people, and a one-sentence fix. The subclasses are TassyirVerificationError, TassyirOAuthError, TassyirApiError and TassyirTokenError. No error message contains a token or a secret.

Runtimes

Ed25519 verification uses WebCrypto (crypto.subtle, algorithm Ed25519). That needs no dependency, and the same code runs on Node 22, Cloudflare Workers, Deno and Bun, so this package does not use node:crypto or jose. The test suite checks the built bundle against tokens and deliveries signed by the Tassyir backend itself. Inject fetch to add a proxy, logging or a test double.

Tassyir Hosting

An app on Tassyir Hosting is a Cloudflare Worker that Tassyir runs for each installation, inside the merchant’s dashboard. It holds no client secret and no token. Its capabilities arrive with each request in ctx.props, never in env (one script serves every installation pinned to its version):
  • readHostedProps(ctx) returns ctx.props typed (HostedProps) after checking its shape, or throws HOSTED_PROPS_MISSING with a fix (the Worker runs outside Tassyir Hosting, or a test forgot its stand-ins).
  • hostedAdmin(props, { retries, timeoutMs, onResponse }) is the same AdminClient as above, its requests sent through ctx.props.TASSYIR with no Authorization header. Each call is a subrequest of the invocation (Tassyir Hosting allows 50 by default), retries included. Answers and problem+json refusals are the API’s. The binding refuses some requests itself, in the same problem shape (HOSTED_BINDING_ERRORS, with no requestId):
    • HOSTED_PATH_NOT_ALLOWED (400): only Admin API paths (/apps/<version>/…);
    • RESPONSE_TOO_LARGE (502): an answer over 8 MiB, never retried (ask for less: a smaller limit, fields);
    • TASSYIR_BINDING_NOT_AVAILABLE (503): the binding is not configured, never retried;
    • METHOD_NOT_ALLOWED, BAD_REQUEST, IDEMPOTENCY_KEY_INVALID, PAYLOAD_TOO_LARGE, UNSUPPORTED_MEDIA_TYPE and SERVICE_UNAVAILABLE (the API did not answer within 30 seconds; retried like any 503).
    A call the API refuses for the installation’s state (uninstalled, suspended, its version no longer released) is 401 HOSTED_CALL_REFUSED; it is never retried. Send ids as strings in bodies: the binding re-serialises the JSON, so a number past 2^53 would be rounded.
  • verifyHostedWebhook(request, props, { keys?, testDeliveries? }) checks a delivery to the manifest’s webhook path. The API sends a hosted app’s deliveries (the same headers, v1a signature and body as an external app’s) through Tassyir Hosting, which runs the installation’s version with viewer: null and POSTs the delivery to the app. The check is verifyWebhook’s, every rule of it: the signature, verified with Tassyir’s published keys (hostedWebhookKeys(props), below), the timestamp, test deliveries, the tassyir-* headers, the envelope naming this installation, its business and its app (taken from ctx.props). It also refuses a request with a viewer (WEBHOOK_NOT_A_DELIVERY: a page of the app). It never skips the signature: when the keys cannot be read it throws KEYS_UNAVAILABLE (or KEYS_NOT_CONFIGURED), which you answer with a 503, and Tassyir delivers again later. app/uninstalled and business/redact still arrive after an uninstall; during those two TASSYIR answers HOSTED_CALL_REFUSED (the key documents excepted).
  • hostedWebhookKeys(props) is Tassyir’s webhook keys as a hosted app reads them: GET /apps/webhook-keys through ctx.props.TASSYIR (a hosted Worker’s own fetch() never reaches a Tassyir host). Make it per request, from that request’s ctx.props, never in a module variable: the binding belongs to its request. Where Tassyir Hosting does not serve the key documents through the binding yet, it refuses the path, and deliveries answer KEYS_UNAVAILABLE until it does.
  • Shared isolates. One isolate may serve several merchants: keep per-request state per request, never in a module variable.

Updating the API types

The OpenAPI document is vendored in openapi/ at a recorded backend commit. With a clone of tassyir/backend in TASSYIR_BACKEND_DIR, run npm run openapi:check -w @tassyir/app to compare it with the backend, and npm run openapi:update -w @tassyir/app to vendor the new file and regenerate the types. npm run vectors:generate -w @tassyir/app re-signs the cross-check fixtures with the backend’s own code.