Skip to content

Check entitlements

An entitlement is something a plan grants: a capability such as SSO, or a limit such as five projects. You declare them in your own code, keyed by Stripe product ID. The Node SDK reads the customer’s active items from Strent and resolves the values locally. Nothing is stored in Strent or read from Stripe Entitlements.

Pass entitlements when you create the client:

import { Strent } from "@strent-dev/node";
export const strent = new Strent({
apiKey: process.env.STRENT_API_KEY!,
entitlements: {
// Every entitlement, its type, and the value a customer has when no
// active product sets it, such as a user who never subscribed.
defaults: { projects: 2, sso: false, auditLog: false },
// What each Stripe product grants. Test and live product IDs differ,
// so read them from the environment.
products: {
[process.env.STARTER_PRODUCT_ID!]: { projects: 5 },
[process.env.PRO_PRODUCT_ID!]: {
projects: 10,
sso: true,
auditLog: true,
},
},
},
});

Values are booleans or non-negative integers. A product may set only entitlements declared in defaults, with the same type; TypeScript rejects anything else, and the constructor throws StrentError for values types cannot check, such as a negative or fractional number.

Key the mapping by product, not price: monthly and yearly prices of the same product grant the same entitlements.

const entitlements = await strent.entitlements.retrieve({
customer: account.stripeCustomerId,
});
if (projectCount >= entitlements.projects) {
throw new Error("Upgrade to create more projects.");
}

retrieve returns every declared entitlement, typed from your defaults: entitlements.projects is a number and entitlements.sso a boolean.

const canUseSso = await strent.entitlements.has({
customer: account.stripeCustomerId,
entitlement: "sso",
});

has accepts only boolean entitlements. When one request checks several entitlements, call retrieve once and read the fields.

Customer Result
customer is null or undefined The defaults, without a request to Strent
No active product sets the entitlement Its default
One active product sets it That product’s value, even when lower than the default
Several active products set it The largest integer, or true if any boolean is true

Active items whose product is not in the mapping grant nothing, and item quantity does not change values. Overlapping plans therefore never grant more than the most generous one; Strent does not add values together.

retrieve and has read the same active-item list as activeItems.list, with the same cache and fallback. If Strent cannot answer, for example 409 CUSTOMER_STATE_NOT_READY for a customer that was never refreshed, the call throws instead of returning defaults. Handle it with your runtime failure policy.