Skip to content

API reference

Generated from the source by TypeDoc, so it always matches the published types. Each entry point is a separate import; its optional peer dependencies are listed in its description.

Import Exports Description
@xtandard/entitlements 134 The root entry point: the engine (createEntitlements), the pure resolver, periods, the data model, and the storage / counter / hook contracts.
@xtandard/entitlements/catalog 55 The catalog: features, plans, add-ons, trials and plan versions, declared once in code and imported everywhere — server, browser, edge and marketing pages (ADR 0002).
@xtandard/entitlements/testing 5 Test helpers: an in-memory engine with a controllable clock, so tests can cross period boundaries, trial ends and grant expiries deterministically.
@xtandard/entitlements/storage/memory 3 In-memory state storage (zero deps; tests, dev, single-process apps).
@xtandard/entitlements/counters/memory 2 In-memory counter store (zero deps; atomic within one process).
@xtandard/entitlements/counters/buffered 2 Write-behind counter decorator for high-volume soft meters (ADR 0006).
@xtandard/entitlements/counters/kv 2 Counters over any compare-and-swap state storage (ADR 0004).
@xtandard/entitlements/auth/basic 2 HTTP Basic authentication for the panel: basicAuth() checks the Authorization: Basic header against a configured user list (scrypt password hashes via hashPassword, a custom verifier, or plaintext for development only).
@xtandard/entitlements/authorization/none 1 The allow-all authorization provider: noAuthorization().
@xtandard/entitlements/authorization/roles 9 Role-based authorization: rolesAuthorization() with the built-in viewer / support / billing-admin / admin / runtime-service presets or your own role → actions policy.
@xtandard/entitlements/authorization/delegated 2 Bring-your-own authorization: delegatedAuthorization() wraps a plain authorize({ principal, action, resource }) decision function (ABAC, OPA, Cedar, per-customer ownership).
@xtandard/entitlements/hooks/log 2 A reference hook: createLogHook() logs control-plane events (text or one JSON object per line).
@xtandard/entitlements/bun 3 Bun adapter: entitlementsPanel() returns the web-standard panel handler to hand to Bun.serve({ fetch }), and requireEntitlement() guards a route handler (402 / 403 JSON for denials).
@xtandard/entitlements/elysia 7 Elysia 1.x adapter: entitlementsPanel() to mount the panel as a plain handler, entitlementsElysia(), a typed plugin whose routes Eden treaty can see, and the requireEntitlement() beforeHandle guard.
@xtandard/entitlements/express 4 Express adapter: entitlementsPanel() bridges Node’s req / res to the web-standard panel handler (mount it before any body parser), and requireEntitlement() is a guard middleware setting req.entitlement.
@xtandard/entitlements/hono 4 Hono adapter: entitlementsPanel() returns a Hono sub-app serving the panel (compose with app.route(path, panel)), and requireEntitlement() is a guard middleware setting c.var.entitlement.
@xtandard/entitlements/next 3 Next.js App Router adapter: toNextHandler(panel) → the GET / POST / … exports of a catch-all route, and withEntitlement(handler, options) guards a route handler (402 / 403 JSON for denials).
@xtandard/entitlements/storage/file 3 File-system state storage: one JSON file per key under a base directory, write-then-rename, fs.watch change events, in-process compare-and-swap.
@xtandard/entitlements/storage/redis 4 Redis state storage: createRedisStorage() (JSON strings) and createRedisJSONStorage() (RedisJSON documents) over node-redis, with a Lua compare-and-swap and keyspace-notification watch.
@xtandard/entitlements/storage/postgres 4 Postgres state storage: one jsonb key/value table over pg or PGlite, created on first use, with single-statement compare-and-swap.
@xtandard/entitlements/storage/drizzle 2 Drizzle state storage: createDrizzleStorage() reads and writes a table you own (built with the drizzle/* factories) through the Drizzle database you pass.
@xtandard/entitlements/storage/mongodb 3 MongoDB state storage: one { _id: key, value } collection over the mongodb driver, with single-update compare-and-swap.
@xtandard/entitlements/storage/sqlite 3 SQLite state storage on bun:sqlite (Bun only, zero npm deps), with single-statement compare-and-swap.
@xtandard/entitlements/storage/libsql 3 libSQL / Turso state storage over @libsql/client (remote, embedded replica or local file), with single-statement compare-and-swap.
@xtandard/entitlements/drizzle/pg 4 Postgres Drizzle table factories: pgEntitlementsTable() (state KV) and pgCountersTable() (counters) put the tables in your Drizzle schema and migrations.
@xtandard/entitlements/drizzle/mysql 4 MySQL Drizzle table factories: mysqlEntitlementsTable() (state KV) and mysqlCountersTable() (counters), with binary-collated keys.
@xtandard/entitlements/drizzle/sqlite 4 SQLite Drizzle table factories: sqliteEntitlementsTable() (state KV) and sqliteCountersTable() (counters).
@xtandard/entitlements/counters/redis 3 Redis counter store: one Lua script per atomic add, SET NX PX claims, PEXPIREAT expiry (ADR 0004).
@xtandard/entitlements/counters/postgres 4 Postgres counter store: one INSERT … ON CONFLICT DO UPDATE … RETURNING statement per atomic add, over pg or PGlite (ADR 0004).
@xtandard/entitlements/counters/sqlite 4 SQLite counter store on bun:sqlite (Bun only): one upsert statement per atomic add (ADR 0004).
@xtandard/entitlements/counters/libsql 3 libSQL / Turso counter store over @libsql/client: one upsert statement per atomic add (ADR 0004).
@xtandard/entitlements/counters/mongodb 3 MongoDB counter store: one pipeline findOneAndUpdate per atomic add, unique-_id claims, TTL-index expiry (ADR 0004).
@xtandard/entitlements/counters/drizzle 4 Drizzle counter store over a counter table you own (drizzle/* *CountersTable() factories): atomic upserts on Postgres, MySQL and SQLite (ADR 0004).
@xtandard/entitlements/billing 9 The billing intake and port (ADR 0007): createBilling(ent, { providers }) verifies provider webhooks, maps provider items to catalog plans and converges subscription state; createUsageExporter forwards usage to provider meters.
@xtandard/entitlements/billing/stripe 8 Stripe billing provider: webhook verification (Stripe-Signature), subscription normalization, reconcile, Checkout / Billing Portal link-outs and meter-event usage export — fetch + Web Crypto, no SDK.
@xtandard/entitlements/billing/polar 6 Polar billing provider: Standard Webhooks verification (byte-compatible with @xtandard/webhooks/receiver), subscription normalization, reconcile, checkout / customer-portal link-outs and event-ingestion usage export.
@xtandard/entitlements/billing/paddle 7 Paddle Billing provider: Paddle-Signature verification, subscription normalization, reconcile, transaction-checkout and customer-portal link-outs.
@xtandard/entitlements/billing/lemonsqueezy 6 Lemon Squeezy billing provider: X-Signature verification, subscription normalization (variant ids), reconcile, checkout and customer-portal link-outs.
@xtandard/entitlements/billing/better-auth 8 better-auth’s Stripe plugin as a billing source: subscription callbacks that feed entitlements plus plans generated from the catalog.
@xtandard/entitlements/billing/manual 1 The no-op manual billing provider (admin UI / ent.subscribe() plan changes, comps, invoiced deals).
@xtandard/entitlements/flags 10 The flags bridge (ADR 0008): entitlementsContext (flat evaluation-context attributes), createEntitlementsHook (an OpenFeature hook that enriches every evaluation) and createEntitlementsProvider (an OpenFeature provider over entitlements).
@xtandard/entitlements/bridges/audit 6 Audit bridge (ADR 0013): auditHooks(audit) records entitlements changes into @xtandard/audit — structural types, no runtime dependency.
@xtandard/entitlements/bridges/webhooks 6 Webhooks bridge (ADR 0013): webhooksEvents(webhooks) publishes plan changes, trials, grants, overrides and usage thresholds through @xtandard/webhooks — structural types, no runtime dependency.
@xtandard/entitlements/react 28 Hooks and small components for gating your product UI on a customer’s plan: EntitlementsProvider, useEntitlement, useEntitlements, useCustomer, <Gate>, <UsageMeter>, <PricingTable>, <UpgradePrompt> and createEntitlementsReact<typeof catalog>().
@xtandard/entitlements/react/embed 9 @xtandard/entitlements/react/embed — the admin dashboard and the customer portal as React components, for hosts that want them inside their own React tree instead of the bundled SPA the adapters serve.