One entitlement API across App Store, Google Play, Stripe, and web, for browsers, React Native, Expo, and Node. Stop checking raw product IDs; ask "what is this user entitled to right now?"
Docs: entitlehub.com/docs · REST API · Migrating from RevenueCat
npm install @entitlehub/sdkZero dependencies. Uses the global fetch (Node 18+, all modern browsers, React Native, Expo).
Reads only. Safe to ship in your app. Never put a secret (sk_) key here.
import { EntitleHub } from "@entitlehub/sdk";
const eh = new EntitleHub({
apiKey: "pk_live_…", // your publishable key
appUserId: user.id, // your own stable user id
});
const info = await eh.getCustomerInfo();
if (info.isActive("pro")) {
unlockProFeatures();
}
// full detail when you need it
const pro = info.active["pro"];
// → { entitlement: "pro", status: "active", store: "app_store", expires_at, will_renew, … }const eh = new EntitleHub({ apiKey: "pk_live_…", appUserId: user.id });
useEffect(() => {
const unsub = eh.addCustomerInfoUpdateListener((info) => setPro(info.isActive("pro")));
eh.getCustomerInfo(); // triggers the listener
return unsub;
}, []);await eh.logIn(newUserId); // switches user, refreshes, clears cache
eh.logOut(); // forget cached info| Method | Returns | Notes |
|---|---|---|
getCustomerInfo({ fetchPolicy }) |
CustomerInfo |
cache-first (default) or network-only. Cached cacheTtlMs (5 min default). |
isEntitled(id) |
boolean |
Convenience over cached info. |
checkEntitlement(id) |
CheckResult |
Always hits the server; includes a reason when inactive. |
getOfferings() |
Offerings |
Entitlements + products, for building a paywall. |
addCustomerInfoUpdateListener(fn) |
() => void |
Returns an unsubscribe. |
Report purchases and grant entitlements. Server only.
import { EntitleHubServer } from "@entitlehub/sdk";
const eh = new EntitleHubServer({ apiKey: process.env.ENTITLEHUB_SECRET_KEY! });
// After the store purchase is confirmed on-device, report it from your server.
// Google Play: validated (EntitleHub verifies the token with your Play service account):
const info = await eh.reportPurchase(userId, {
store: "play", storeProductId: "pro_monthly",
purchaseToken: playToken, isSubscription: true,
});
info.isActive("pro"); // → true
// Apple StoreKit 2: validated (product / environment read from the signed JWS):
await eh.reportPurchase(userId, { store: "app_store", storeProductId: "", signedTransaction: jws });
// Trusted server-report (no store validation, only if you validated the receipt elsewhere):
await eh.reportPurchase(userId, { store: "app_store", storeProductId: "pro_monthly" });
// Grant directly (promo / comp / support), no purchase:
await eh.grantEntitlement(userId, "pro", { durationDays: 30 });| Method | Returns |
|---|---|
reportPurchase(userId, { store, storeProductId, purchaseToken?, isSubscription?, signedTransaction?, isSandbox?, transactionId? }) |
CustomerInfo |
grantEntitlement(userId, id, { durationDays?, isSandbox? }) |
CustomerInfo |
getCustomerInfo(userId) / check(userId, id) |
CustomerInfo / CheckResult |
Set up and change your catalog from code. Refs take the id or the key / SKU / identifier you
already have. Every create has an ensure twin that returns the existing row instead of failing,
so a setup script can run on every deploy.
await eh.entitlements.ensure({ key: "pro", name: "Pro" });
await eh.products.ensure({
store: "stripe", storeProductId: "price_1Q...", type: "subscription", duration: "P1M",
priceMicros: 9_990_000, entitlements: ["pro"],
});
// Remap (future purchases only; access already granted is untouched):
await eh.products.update({ store: "play", storeProductId: "pro_monthly" }, { entitlements: ["pro", "team"] });
await eh.entitlements.attachProducts("team", ["price_1Q..."]);
// Retire a SKU you no longer sell. Existing subscribers keep access and renewals:
await eh.products.archive("price_old");
await eh.offerings.create({
identifier: "default", isCurrent: true, metadata: { headline: "Go Pro" },
packages: [{ identifier: "monthly", product: "price_1Q..." }],
});| Namespace | Methods |
|---|---|
eh.entitlements |
list get create ensure update delete products attachProducts detachProducts archive unarchive |
eh.products |
list get create ensure update delete attachEntitlements detachEntitlements archive unarchive |
eh.offerings |
list get create update delete archive unarchive packages addPackage updatePackage deletePackage |
Full reference: entitlehub.com/docs/catalog-api.
Keep making the actual store purchase with your existing IAP flow (StoreKit / Play Billing /
expo-iap / react-native-iap), then reportPurchase(...) from your server and read entitlements
with getCustomerInfo(). See the full guide at entitlehub.com/docs.
Every failure throws an EntitleHubError with .status and .code (auth | http | network | config).
When the API sends its own machine-readable code it is on .apiCode (e.g. product_exists,
ambiguous_product, rate_limited), with the full payload on .body.
import { EntitleHubError } from "@entitlehub/sdk";
try { await eh.getCustomerInfo(); }
catch (e) { if (e instanceof EntitleHubError && e.code === "auth") relogin(); }Point the SDK at your own EntitleHub with baseUrl:
new EntitleHub({ apiKey, appUserId, baseUrl: "https://entitlements.yourco.com/v1" });