A typed catalog
Boolean, metered, credits, capacity and value features; plan groups, defaults, trials, add-ons and versioned plans for grandfathering.
bun add @xtandard/entitlementsThe Stigg / Schematic / Autumn niche, as an MIT library: billing-provider-agnostic,
storage-pluggable and framework-agnostic. check() is a memory read, consume() is one atomic step
and a refused request never counts. Invoicing, tax, dunning and payments stay with your provider.
import { defineCatalog, feature } from "@xtandard/entitlements/catalog";
export const catalog = defineCatalog({ features: { seats: feature.capacity({ name: "Seats", unit: "seat" }), api_calls: feature.metered({ name: "API calls", unit: "call", reset: "month" }), export_pdf: feature.boolean({ name: "PDF export" }), }, plans: { free: { default: true, features: { seats: 3, api_calls: 1_000 } }, pro: { trial: { days: 14 }, providers: { stripe: ["price_pro_monthly"] }, features: { seats: 10, api_calls: { limit: 100_000, overage: "allow" }, export_pdf: true }, }, },});Zero dependencies, fully typed — the same file drives your API, your React gates and your pricing page. Catalog guide →
import { createEntitlements } from "@xtandard/entitlements";
const ent = createEntitlements({ catalog, storage, counters });
const r = await ent.consume(org.id, "api_calls", 1, { idempotencyKey: req.id });// { allowed: false, reason: "limit_reached", denial: "payment_required",// unlockedBy: ["pro"], used: 1000, remaining: 0, resetsAt: "2026-12-01T00:00:00.000Z" }
const tokens = await ent.reserve(org.id, "gpt_tokens", 8_000);await ent.settle(tokens.reservation!.id, actualTokens);Buckets (allowance → grants → overage), idempotency keys, reserve / settle, thresholds, credits. Metering guide →
await ent.grant(org.id, { feature: "api_calls", amount: 1_000, expiresAt: "2026-12-31", reason: "outage credit" });await ent.override(org.id, { feature: "export_pdf", enabled: true, reason: "pilot" });await ent.startTrial(org.id, "pro");await ent.migratePlan("*", "pro", 2); // grandfathered customers move only when you say soEvery change runs through before / after hooks and lands in the activity log (or
@xtandard/audit). Hooks →
A typed catalog
Boolean, metered, credits, capacity and value features; plan groups, defaults, trials, add-ons and versioned plans for grandfathering.
Atomic metering
A counter port where every consume is one atomic step; Redis, Postgres, SQLite, MongoDB, Drizzle or memory; optional write-behind counters for hot soft limits.
Any billing provider
Stripe, Polar, Paddle, Lemon Squeezy, better-auth’s Stripe plugin and manual plans — verified, idempotent, order-safe webhook intake, no SDKs.
Admin UI and customer portal
Look up customers, comp features, raise limits, see usage — and give customers their plan, usage and upgrade link-outs behind short-lived portal tokens.
React
useEntitlement, <Gate>, <UsageMeter>, <PricingTable>, <UpgradePrompt>, plus the full
dashboard and portal as embeddable components.
One gate with flags
An OpenFeature provider and hook so @xtandard/flags rules can target plan and
entitlement.* — rollouts and plan gates share one decision.
@xtandard/entitlements has siblings: open-source, MIT-licensed projects that share the xtandard
name. Each one stands on its own.
All of them, with npm and GitHub links: the xtandard ecosystem.