Skip to content

TypeScript SDK

Terminal window
npm install @seal0/sdk

Server-side, with zero runtime dependencies, ESM only. Node.js 20.3 or later, Bun, Deno, and edge runtimes with a standard fetch. Source and issues: github.com/seal0-app/sdk-node (Apache-2.0).

import { Seal0 } from "@seal0/sdk";
const seal0 = new Seal0({ apiKey: process.env.SEAL0_API_KEY! }); // keep the key on the server

Options: baseURL (default https://api.seal0.app), maxRetries (default 2), and a custom fetch. The constructor refuses to run in a browser, because API keys are secrets. dangerouslyAllowBrowser: true overrides this for trusted internal tools only.

import { limit } from "@seal0/sdk";
try {
const { entitlement } = await seal0.evaluate("cus_test_0001", "max_projects");
const l = limit(entitlement.value);
if (l && (l.unlimited || projects < l.n)) allow();
} catch {
deny(); // unknown Customer or feature, auth or network failure: fail closed
}
  • Every feature at once: await seal0.evaluateAll("cus_test_0001").
  • Reading values: values are boolean | number | string. limit(value) and isUnlimited(value) read number and metered features.
  • Metered results carry entitlement.usage: used, limit, remaining, over_limit and the period.
  • Types come from the API’s OpenAPI contract, so parameters and results are checked by tsc.
import { ErrorCode, isSeal0Error } from "@seal0/sdk";
try {
await seal0.evaluate("cus_test_0001", "max_projects");
} catch (err) {
if (isSeal0Error(err, ErrorCode.CustomerNotFound)) {
// register the Customer first
} else if (isSeal0Error(err)) {
console.error(err.code, err.requestId);
}
}

Seal0Error carries status, code, field and requestId. See Errors and retries.

Every API operation has a method: createFeature, updateFeature, createPlan, putDraft, publishPlan, upsertCustomer, assignSubscription, updateSubscription, changePlanVersion, createOverride, revokeOverride, recordUsage, and the matching getters and lists.

  • PATCH fields: omit a field to leave it unchanged, or set it to null to clear it.
  • Lists: for await (const f of seal0.features()) { … } pages through everything.
  • Idempotency: every mutation sends an Idempotency-Key, reused across retries. Pass { idempotencyKey } to choose your own, and { signal } to cancel.

Automating setup has a full example.