@xtandard/entitlements/catalog
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). Zero dependencies.
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" }), max_upload_mb: feature.value({ name: "Max upload (MB)", default: 10 }), }, plans: { free: { name: "Free", default: true, features: { api_calls: 1_000, seats: 3 } }, pro: { name: "Pro", trial: { days: 14 }, price: { amount: 2900, currency: "usd", interval: "month" }, providers: { stripe: ["price_pro_monthly"] }, features: { api_calls: { limit: 100_000, overage: "allow" }, seats: 10, export_pdf: true }, }, }, addons: { extra_seats: { name: "+5 seats", quantity: true, features: { seats: { add: 5 } } }, },});import { … } from "@xtandard/entitlements/catalog";Functions
Section titled “Functions”| Name | Summary |
|---|---|
addon |
Identity helper for declaring an add-on outside defineCatalog. |
defineCatalog |
Define and validate a catalog. Throws CatalogError listing every problem (unknown features, invalid limits, duplicate defaults or provider ids, broken credit references, …). |
formatQuantity |
Format a numeric amount with the feature’s unit, e.g. "1,000 calls". |
getPlanVersion |
A plan version by key and version, falling back to the current version. |
plan |
Identity helper for declaring a plan outside defineCatalog (types are checked there). |
pricingTable |
Build a JSON-safe pricing table from the catalog (current plan versions, in declaration order). Hidden plans, add-ons and features are left out unless includeHidden is set. |
Classes
Section titled “Classes”| Name | Summary |
|---|---|
CatalogError |
Thrown by defineCatalog with every problem found. |
Interfaces
Section titled “Interfaces”| Name | Summary |
|---|---|
AddonDefinition |
An add-on: stacks on top of base plans. |
AnyCatalog |
Any catalog (what the engine, resolver and UI accept). |
BooleanFeature |
An on/off feature. |
CapacityFeature |
A current count against a ceiling (seats, projects). Never resets. |
Catalog |
A defined catalog. The type parameters carry your keys and value types. |
CatalogDefinition |
Input to defineCatalog. |
CreditsFeature |
A prepaid balance other metered features can draw from (creditCost). |
FeatureCommon |
|
LimitSpec |
A limit with options, for metered / credits / capacity features on a plan. |
MeteredFeature |
A consumption counter that resets (API calls, tokens, exports per month). |
NormalizedAddon |
A normalized add-on. |
NormalizedCatalog |
The normalized catalog. |
NormalizedFeature |
A feature with every default applied. |
NormalizedLimit |
A normalized numeric entitlement on a plan. |
NormalizedPlan |
One concrete version of a plan. |
PlanDefinition |
A plan. |
PlanVersionDefinition |
One historical version of a plan (grandfathering — ADR 0012). |
PriceDisplay |
Display price (money stays with the provider — ADR 0015). Amount in minor units. |
PricingAddon |
An add-on row in a pricing table. |
PricingCell |
One cell of a pricing table. |
PricingPlan |
A plan column in a pricing table. |
PricingTable |
JSON-safe, display-ready catalog for pricing pages (GET /api/pricing, <PricingTable>). |
ProviderItemTarget |
Where a provider item id points. |
ValueFeature |
A configuration value per plan (max upload size, support tier). |
Type aliases
Section titled “Type aliases”| Name | Summary |
|---|---|
AddonFeatureEntry |
What an add-on may add for one feature, by kind. |
AddonFeatures |
An add-on’s feature map. |
AddonKey |
The add-on keys of a catalog. |
FeatureDefinition |
Any feature definition. |
FeatureKey |
The feature keys of a catalog. |
FeatureKeyOfKind |
Feature keys of a given kind. |
FeatureKind |
The five feature kinds. |
FeatureOf |
The feature definition for a key. |
FeatureValue |
The value type for a value feature (JsonValue | undefined for other kinds). |
JsonObject |
A JSON object. |
JsonPrimitive |
A JSON primitive. |
JsonValue |
Any JSON-serializable value. |
MeteringMode |
How a metered feature’s counter is written (ADR 0006). |
NormalizedAddonEntry |
A normalized add-on entry for one feature. |
NormalizedEntry |
A normalized plan entry for one feature. |
OveragePolicy |
What happens when usage would exceed the limit. |
PlanFeatureEntry |
What a plan may say about one feature, by kind. false (or omission) = not included. |
PlanFeatures |
A plan’s feature map, typed by the catalog’s features. |
PlanKey |
The plan keys of a catalog. |
ProviderMapping |
Provider item ids that map to a plan or add-on: Stripe price ids, Polar product ids, Paddle price ids, Lemon Squeezy variant ids, … |
ResetInterval |
When a metered or credits feature’s usage starts over (ADR 0014). |
Unlimited |
The literal accepted for “no limit”. |
Widen |
Widen literal types (10 → number) so feature.value({ default: 10 }) is a number feature. |
Variables
Section titled “Variables”| Name | Summary |
|---|---|
feature |
Feature builders. |