billingsdk-core
v0.1.1
Published
Core types and client for Billing SDK
Readme
billingsdk-core
Core types, client, plan definitions, entitlements, and storage for Billing SDK.
Installation
npm install billingsdk-coreUsage
import { createBilling, definePlans } from "billingsdk-core";
const plans = definePlans({
free: {
name: "Free",
prices: [],
features: { ai_generations: { limit: 10, reset: "month" } },
},
pro: {
name: "Pro",
prices: [{ id: "pro-monthly", amount: 2000, currency: "usd", interval: "month" }],
features: { ai_generations: { limit: 1000, reset: "month" } },
},
});
const billing = createBilling({
adapter: stripe({ secretKey: process.env.STRIPE_SECRET_KEY! }),
plans,
});Exports
createBilling()— Create a billing client with a provider adapterdefinePlans()— Define plan configurations with feature entitlementscreateInMemoryStorage()— In-memory storage adapter for testing- Error classes:
BillingError,BillingConfigurationError,BillingProviderError,BillingWebhookError,BillingNotFoundError,BillingAuthenticationError,BillingCapabilityError,BillingValidationError,BillingIdempotencyError - Utilities:
getHeader(),streamToString(),mergeBuffers(),bodyToString()
