platform-api-kit-client
v0.1.23
Published
Abstract API Communication for Platform
Readme
Usage
- .npmrc in user directory (token from https://github.com/settings/tokens)
//npm.pkg.github.com/:_authToken=___GENERATED_TOKEN___- .npmrc in project
@supaapps:registry=https://npm.pkg.github.com/
- Ensure you initialize ApiKitInstances for 'user': Logged in user 'public': Public user 'admin': Admin panel only
Admin billing cheatsheet (frontend)
Initialize the admin billing ApiKit client once in your app (example):
import { ApiKitClient } from "supaapps-api-kit-client";
ApiKitClient.i("billing-admin").initialize(
process.env.BILLING_API_BASE_URL!,
async () => getAdminJwt(), // return admin bearer token
() => {}, // unauthorized callback (optional)
true // use auth
);Grab the admin billing API:
import { PlatformApi } from "@supaapps/platform-api-kit-client";
const billingAdmin = PlatformApi.admin().billingApi();List products (no auth required on backend, but you can still call through admin client)
const products = await billingAdmin.listProducts();
// Filter client-side by realm_id or realm.name if neededList entitlements for a user (admin token required)
const entitlements = await billingAdmin.listEntitlementsForUser(userId, {
page: 1,
per_page: 25,
checkout_type: "local", // or "stripe"
expired: false,
subscribed_until_ts_min: 1700000000,
subscribed_until_ts_max: 1800000000,
filter_core: "no_payments", // only entries with no last payment
});
// Returns Laravel-style pagination with user_addresses when availableCreate entitlement for a user (admin token required)
const entitlement = await billingAdmin.createEntitlement({
user_id: userId,
realm_id: realmId,
product_key: "pro_monthly",
// Optional overrides (copied from product if omitted):
// price_in_cents, currency, interval, interval_count, config_version, config
// Additional flags you might set:
subscribed_until_ts: 1800000000, // expiry in epoch seconds (no auto-expiry otherwise)
is_trial: false,
is_canceled: false,
is_custom_entitlement: false,
local_reference: `admin_${userId}`, // defaults to this pattern when omitted
checkout_type: "local", // defaults to "local"
workspace_id, // optional; ensured/created within realm if provided
});Update entitlement for a user (admin token required)
const updated = await billingAdmin.updateEntitlement(entitlementId, {
subscribed_until_ts: 1810000000, // extend/shorten
config_version: 2,
config: { plan: "pro_plus" },
is_trial: false,
is_canceled: false,
});
// Any entitlement field can be patched; publishes entitlement update events on backendReminders:
- Admin-created entitlements do not auto-expire. Always set
subscribed_until_tson create or patch later. - When creating,
is_subscriptionalways follows the product and is not overrideable.
