@stackbe/sdk 0.6.4 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +128 -0
- package/dist/index.d.mts +150 -1
- package/dist/index.d.ts +150 -1
- package/dist/index.js +109 -0
- package/dist/index.mjs +107 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -200,6 +200,64 @@ if (session) {
|
|
|
200
200
|
const isAuthenticated = await stackbe.auth.isAuthenticated(sessionToken);
|
|
201
201
|
```
|
|
202
202
|
|
|
203
|
+
### Plans & Products
|
|
204
|
+
|
|
205
|
+
List available pricing plans for your pricing page:
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
// List all plans
|
|
209
|
+
const plans = await stackbe.plans.list();
|
|
210
|
+
|
|
211
|
+
// List active plans sorted by price
|
|
212
|
+
const plans = await stackbe.plans.listByPrice();
|
|
213
|
+
// [Free ($0), Starter ($9), Pro ($29), Enterprise ($99)]
|
|
214
|
+
|
|
215
|
+
// Filter by product
|
|
216
|
+
const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
217
|
+
|
|
218
|
+
// Get a specific plan
|
|
219
|
+
const plan = await stackbe.plans.get('plan_123');
|
|
220
|
+
console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
221
|
+
|
|
222
|
+
// List products
|
|
223
|
+
const products = await stackbe.products.list();
|
|
224
|
+
|
|
225
|
+
// Get product details
|
|
226
|
+
const product = await stackbe.products.get('prod_123');
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### Dynamic Pricing Page Example
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
// Next.js pricing page
|
|
233
|
+
export default async function PricingPage() {
|
|
234
|
+
const plans = await stackbe.plans.listByPrice();
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<div className="grid grid-cols-3 gap-4">
|
|
238
|
+
{plans.map((plan) => (
|
|
239
|
+
<div key={plan.id} className="border p-4 rounded">
|
|
240
|
+
<h3>{plan.name}</h3>
|
|
241
|
+
<p className="text-2xl">
|
|
242
|
+
${plan.priceCents / 100}/{plan.interval}
|
|
243
|
+
</p>
|
|
244
|
+
<ul>
|
|
245
|
+
{Object.entries(plan.entitlements).map(([key, value]) => (
|
|
246
|
+
<li key={key}>
|
|
247
|
+
{key}: {value === true ? '✓' : value}
|
|
248
|
+
</li>
|
|
249
|
+
))}
|
|
250
|
+
</ul>
|
|
251
|
+
<a href={`/checkout?plan=${plan.id}`}>
|
|
252
|
+
{plan.priceCents === 0 ? 'Start Free' : 'Subscribe'}
|
|
253
|
+
</a>
|
|
254
|
+
</div>
|
|
255
|
+
))}
|
|
256
|
+
</div>
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
203
261
|
### Customer Management
|
|
204
262
|
|
|
205
263
|
```typescript
|
|
@@ -226,6 +284,76 @@ const customer = await stackbe.customers.getOrCreate({
|
|
|
226
284
|
await stackbe.customers.update('cust_123', { name: 'Jane Doe' });
|
|
227
285
|
```
|
|
228
286
|
|
|
287
|
+
### Organizations (B2B Multi-User)
|
|
288
|
+
|
|
289
|
+
Manage customer organizations for B2B apps:
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
// Create organization with customer as owner
|
|
293
|
+
const org = await stackbe.organizations.create({
|
|
294
|
+
name: 'Acme Corp',
|
|
295
|
+
ownerId: customer.id,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// List all organizations
|
|
299
|
+
const orgs = await stackbe.organizations.list();
|
|
300
|
+
|
|
301
|
+
// Get organization by ID
|
|
302
|
+
const org = await stackbe.organizations.get('org_123');
|
|
303
|
+
|
|
304
|
+
// Update organization
|
|
305
|
+
await stackbe.organizations.update('org_123', { name: 'New Name' });
|
|
306
|
+
|
|
307
|
+
// Delete organization (must have no active subscriptions)
|
|
308
|
+
await stackbe.organizations.delete('org_123');
|
|
309
|
+
|
|
310
|
+
// Add member to organization
|
|
311
|
+
await stackbe.organizations.addMember('org_123', {
|
|
312
|
+
customerId: 'cust_456',
|
|
313
|
+
role: 'member', // 'admin' | 'member'
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Remove member
|
|
317
|
+
await stackbe.organizations.removeMember('org_123', 'member_456');
|
|
318
|
+
|
|
319
|
+
// Update member role
|
|
320
|
+
await stackbe.organizations.updateMember('org_123', 'member_456', {
|
|
321
|
+
role: 'admin',
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Invite by email
|
|
325
|
+
await stackbe.organizations.invite('org_123', {
|
|
326
|
+
email: 'newuser@company.com',
|
|
327
|
+
role: 'member',
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// List pending invites
|
|
331
|
+
const invites = await stackbe.organizations.listInvites('org_123');
|
|
332
|
+
|
|
333
|
+
// Cancel invite
|
|
334
|
+
await stackbe.organizations.cancelInvite('org_123', 'invite_456');
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
#### B2B Signup Flow
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
async function signup(email: string, orgName: string) {
|
|
341
|
+
// 1. Get or create customer
|
|
342
|
+
const customer = await stackbe.customers.getOrCreate({ email });
|
|
343
|
+
|
|
344
|
+
// 2. Create organization with customer as owner
|
|
345
|
+
const org = await stackbe.organizations.create({
|
|
346
|
+
name: orgName,
|
|
347
|
+
ownerId: customer.id,
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// 3. Send magic link
|
|
351
|
+
await stackbe.auth.sendMagicLink(email);
|
|
352
|
+
|
|
353
|
+
return { customer, org };
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
229
357
|
## Express Middleware
|
|
230
358
|
|
|
231
359
|
### Track Usage Automatically
|
package/dist/index.d.mts
CHANGED
|
@@ -304,6 +304,41 @@ interface OrganizationInvite {
|
|
|
304
304
|
status: 'pending' | 'accepted' | 'cancelled';
|
|
305
305
|
sentAt: string;
|
|
306
306
|
}
|
|
307
|
+
interface Plan {
|
|
308
|
+
id: string;
|
|
309
|
+
name: string;
|
|
310
|
+
slug: string;
|
|
311
|
+
description?: string;
|
|
312
|
+
priceCents: number;
|
|
313
|
+
currency: string;
|
|
314
|
+
interval: 'month' | 'year';
|
|
315
|
+
trialDays?: number;
|
|
316
|
+
entitlements: Record<string, boolean | number | string>;
|
|
317
|
+
status: 'active' | 'archived';
|
|
318
|
+
requirePaymentMethod: boolean;
|
|
319
|
+
productId: string;
|
|
320
|
+
product?: Product;
|
|
321
|
+
createdAt: string;
|
|
322
|
+
updatedAt: string;
|
|
323
|
+
}
|
|
324
|
+
interface Product {
|
|
325
|
+
id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
slug: string;
|
|
328
|
+
description?: string;
|
|
329
|
+
appId: string;
|
|
330
|
+
plans?: Plan[];
|
|
331
|
+
createdAt: string;
|
|
332
|
+
updatedAt: string;
|
|
333
|
+
}
|
|
334
|
+
interface ListPlansOptions {
|
|
335
|
+
/** Filter by product ID */
|
|
336
|
+
productId?: string;
|
|
337
|
+
}
|
|
338
|
+
interface ListProductsOptions {
|
|
339
|
+
/** Filter by app ID (defaults to SDK appId) */
|
|
340
|
+
appId?: string;
|
|
341
|
+
}
|
|
307
342
|
interface CreateCheckoutOptions {
|
|
308
343
|
/** Customer ID or email */
|
|
309
344
|
customer: string | {
|
|
@@ -1230,6 +1265,116 @@ declare class OrganizationsClient {
|
|
|
1230
1265
|
cancelInvite(orgId: string, inviteId: string): Promise<void>;
|
|
1231
1266
|
}
|
|
1232
1267
|
|
|
1268
|
+
/**
|
|
1269
|
+
* Client for managing plans and products.
|
|
1270
|
+
* Use this to list available pricing plans for display in your pricing page.
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1273
|
+
* ```typescript
|
|
1274
|
+
* // List all plans
|
|
1275
|
+
* const plans = await stackbe.plans.list();
|
|
1276
|
+
*
|
|
1277
|
+
* // List plans for a specific product
|
|
1278
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1279
|
+
*
|
|
1280
|
+
* // Get a specific plan
|
|
1281
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1282
|
+
*
|
|
1283
|
+
* // List products
|
|
1284
|
+
* const products = await stackbe.products.list();
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
declare class PlansClient {
|
|
1288
|
+
private readonly http;
|
|
1289
|
+
constructor(http: HttpClient);
|
|
1290
|
+
/**
|
|
1291
|
+
* List all plans for the app.
|
|
1292
|
+
*
|
|
1293
|
+
* @example
|
|
1294
|
+
* ```typescript
|
|
1295
|
+
* // List all plans
|
|
1296
|
+
* const plans = await stackbe.plans.list();
|
|
1297
|
+
*
|
|
1298
|
+
* // Filter by product
|
|
1299
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1300
|
+
*
|
|
1301
|
+
* // Display in pricing page
|
|
1302
|
+
* plans.forEach(plan => {
|
|
1303
|
+
* console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
|
|
1304
|
+
* });
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
list(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Get a plan by ID.
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1314
|
+
* console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
1315
|
+
* ```
|
|
1316
|
+
*/
|
|
1317
|
+
get(planId: string): Promise<Plan>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Get active plans only (excludes archived plans).
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```typescript
|
|
1323
|
+
* const activePlans = await stackbe.plans.getActive();
|
|
1324
|
+
* ```
|
|
1325
|
+
*/
|
|
1326
|
+
getActive(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Get plans sorted by price (ascending).
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```typescript
|
|
1332
|
+
* const plans = await stackbe.plans.listByPrice();
|
|
1333
|
+
* // [Free, Starter, Pro, Enterprise]
|
|
1334
|
+
* ```
|
|
1335
|
+
*/
|
|
1336
|
+
listByPrice(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Client for managing products.
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```typescript
|
|
1343
|
+
* // List all products
|
|
1344
|
+
* const products = await stackbe.products.list();
|
|
1345
|
+
*
|
|
1346
|
+
* // Get a specific product
|
|
1347
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1348
|
+
* ```
|
|
1349
|
+
*/
|
|
1350
|
+
declare class ProductsClient {
|
|
1351
|
+
private readonly http;
|
|
1352
|
+
private readonly appId;
|
|
1353
|
+
constructor(http: HttpClient, appId: string);
|
|
1354
|
+
/**
|
|
1355
|
+
* List all products for the app.
|
|
1356
|
+
*
|
|
1357
|
+
* @example
|
|
1358
|
+
* ```typescript
|
|
1359
|
+
* const products = await stackbe.products.list();
|
|
1360
|
+
* products.forEach(product => {
|
|
1361
|
+
* console.log(product.name, product.plans?.length, 'plans');
|
|
1362
|
+
* });
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
list(options?: ListProductsOptions): Promise<Product[]>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Get a product by ID.
|
|
1368
|
+
*
|
|
1369
|
+
* @example
|
|
1370
|
+
* ```typescript
|
|
1371
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1372
|
+
* console.log(product.name, product.description);
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
1375
|
+
get(productId: string): Promise<Product>;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1233
1378
|
declare class StackBE {
|
|
1234
1379
|
private http;
|
|
1235
1380
|
private appId;
|
|
@@ -1247,6 +1392,10 @@ declare class StackBE {
|
|
|
1247
1392
|
readonly auth: AuthClient;
|
|
1248
1393
|
/** Organization management (B2B multi-user) */
|
|
1249
1394
|
readonly organizations: OrganizationsClient;
|
|
1395
|
+
/** Pricing plans */
|
|
1396
|
+
readonly plans: PlansClient;
|
|
1397
|
+
/** Products */
|
|
1398
|
+
readonly products: ProductsClient;
|
|
1250
1399
|
/**
|
|
1251
1400
|
* Create a new StackBE client.
|
|
1252
1401
|
*
|
|
@@ -1347,4 +1496,4 @@ declare class StackBE {
|
|
|
1347
1496
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
1348
1497
|
}
|
|
1349
1498
|
|
|
1350
|
-
export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
|
1499
|
+
export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
package/dist/index.d.ts
CHANGED
|
@@ -304,6 +304,41 @@ interface OrganizationInvite {
|
|
|
304
304
|
status: 'pending' | 'accepted' | 'cancelled';
|
|
305
305
|
sentAt: string;
|
|
306
306
|
}
|
|
307
|
+
interface Plan {
|
|
308
|
+
id: string;
|
|
309
|
+
name: string;
|
|
310
|
+
slug: string;
|
|
311
|
+
description?: string;
|
|
312
|
+
priceCents: number;
|
|
313
|
+
currency: string;
|
|
314
|
+
interval: 'month' | 'year';
|
|
315
|
+
trialDays?: number;
|
|
316
|
+
entitlements: Record<string, boolean | number | string>;
|
|
317
|
+
status: 'active' | 'archived';
|
|
318
|
+
requirePaymentMethod: boolean;
|
|
319
|
+
productId: string;
|
|
320
|
+
product?: Product;
|
|
321
|
+
createdAt: string;
|
|
322
|
+
updatedAt: string;
|
|
323
|
+
}
|
|
324
|
+
interface Product {
|
|
325
|
+
id: string;
|
|
326
|
+
name: string;
|
|
327
|
+
slug: string;
|
|
328
|
+
description?: string;
|
|
329
|
+
appId: string;
|
|
330
|
+
plans?: Plan[];
|
|
331
|
+
createdAt: string;
|
|
332
|
+
updatedAt: string;
|
|
333
|
+
}
|
|
334
|
+
interface ListPlansOptions {
|
|
335
|
+
/** Filter by product ID */
|
|
336
|
+
productId?: string;
|
|
337
|
+
}
|
|
338
|
+
interface ListProductsOptions {
|
|
339
|
+
/** Filter by app ID (defaults to SDK appId) */
|
|
340
|
+
appId?: string;
|
|
341
|
+
}
|
|
307
342
|
interface CreateCheckoutOptions {
|
|
308
343
|
/** Customer ID or email */
|
|
309
344
|
customer: string | {
|
|
@@ -1230,6 +1265,116 @@ declare class OrganizationsClient {
|
|
|
1230
1265
|
cancelInvite(orgId: string, inviteId: string): Promise<void>;
|
|
1231
1266
|
}
|
|
1232
1267
|
|
|
1268
|
+
/**
|
|
1269
|
+
* Client for managing plans and products.
|
|
1270
|
+
* Use this to list available pricing plans for display in your pricing page.
|
|
1271
|
+
*
|
|
1272
|
+
* @example
|
|
1273
|
+
* ```typescript
|
|
1274
|
+
* // List all plans
|
|
1275
|
+
* const plans = await stackbe.plans.list();
|
|
1276
|
+
*
|
|
1277
|
+
* // List plans for a specific product
|
|
1278
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1279
|
+
*
|
|
1280
|
+
* // Get a specific plan
|
|
1281
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1282
|
+
*
|
|
1283
|
+
* // List products
|
|
1284
|
+
* const products = await stackbe.products.list();
|
|
1285
|
+
* ```
|
|
1286
|
+
*/
|
|
1287
|
+
declare class PlansClient {
|
|
1288
|
+
private readonly http;
|
|
1289
|
+
constructor(http: HttpClient);
|
|
1290
|
+
/**
|
|
1291
|
+
* List all plans for the app.
|
|
1292
|
+
*
|
|
1293
|
+
* @example
|
|
1294
|
+
* ```typescript
|
|
1295
|
+
* // List all plans
|
|
1296
|
+
* const plans = await stackbe.plans.list();
|
|
1297
|
+
*
|
|
1298
|
+
* // Filter by product
|
|
1299
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1300
|
+
*
|
|
1301
|
+
* // Display in pricing page
|
|
1302
|
+
* plans.forEach(plan => {
|
|
1303
|
+
* console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
|
|
1304
|
+
* });
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
list(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Get a plan by ID.
|
|
1310
|
+
*
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```typescript
|
|
1313
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1314
|
+
* console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
1315
|
+
* ```
|
|
1316
|
+
*/
|
|
1317
|
+
get(planId: string): Promise<Plan>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Get active plans only (excludes archived plans).
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```typescript
|
|
1323
|
+
* const activePlans = await stackbe.plans.getActive();
|
|
1324
|
+
* ```
|
|
1325
|
+
*/
|
|
1326
|
+
getActive(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1327
|
+
/**
|
|
1328
|
+
* Get plans sorted by price (ascending).
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```typescript
|
|
1332
|
+
* const plans = await stackbe.plans.listByPrice();
|
|
1333
|
+
* // [Free, Starter, Pro, Enterprise]
|
|
1334
|
+
* ```
|
|
1335
|
+
*/
|
|
1336
|
+
listByPrice(options?: ListPlansOptions): Promise<Plan[]>;
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Client for managing products.
|
|
1340
|
+
*
|
|
1341
|
+
* @example
|
|
1342
|
+
* ```typescript
|
|
1343
|
+
* // List all products
|
|
1344
|
+
* const products = await stackbe.products.list();
|
|
1345
|
+
*
|
|
1346
|
+
* // Get a specific product
|
|
1347
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1348
|
+
* ```
|
|
1349
|
+
*/
|
|
1350
|
+
declare class ProductsClient {
|
|
1351
|
+
private readonly http;
|
|
1352
|
+
private readonly appId;
|
|
1353
|
+
constructor(http: HttpClient, appId: string);
|
|
1354
|
+
/**
|
|
1355
|
+
* List all products for the app.
|
|
1356
|
+
*
|
|
1357
|
+
* @example
|
|
1358
|
+
* ```typescript
|
|
1359
|
+
* const products = await stackbe.products.list();
|
|
1360
|
+
* products.forEach(product => {
|
|
1361
|
+
* console.log(product.name, product.plans?.length, 'plans');
|
|
1362
|
+
* });
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
list(options?: ListProductsOptions): Promise<Product[]>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Get a product by ID.
|
|
1368
|
+
*
|
|
1369
|
+
* @example
|
|
1370
|
+
* ```typescript
|
|
1371
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1372
|
+
* console.log(product.name, product.description);
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
1375
|
+
get(productId: string): Promise<Product>;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1233
1378
|
declare class StackBE {
|
|
1234
1379
|
private http;
|
|
1235
1380
|
private appId;
|
|
@@ -1247,6 +1392,10 @@ declare class StackBE {
|
|
|
1247
1392
|
readonly auth: AuthClient;
|
|
1248
1393
|
/** Organization management (B2B multi-user) */
|
|
1249
1394
|
readonly organizations: OrganizationsClient;
|
|
1395
|
+
/** Pricing plans */
|
|
1396
|
+
readonly plans: PlansClient;
|
|
1397
|
+
/** Products */
|
|
1398
|
+
readonly products: ProductsClient;
|
|
1250
1399
|
/**
|
|
1251
1400
|
* Create a new StackBE client.
|
|
1252
1401
|
*
|
|
@@ -1347,4 +1496,4 @@ declare class StackBE {
|
|
|
1347
1496
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
1348
1497
|
}
|
|
1349
1498
|
|
|
1350
|
-
export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
|
1499
|
+
export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type InviteMemberOptions, type ListPlansOptions, type ListProductsOptions, type MagicLinkOptions, type MagicLinkResponse, type Organization, type OrganizationInvite, type OrganizationMember, OrganizationsClient, type PaymentFailedEvent, type PaymentSucceededEvent, type PaymentWebhookPayload, type Plan, PlansClient, type Product, ProductsClient, type SessionResponse, StackBE, type StackBEConfig, StackBEError, type StackBEErrorCode, type StackBEErrorResponse, type Subscription, type SubscriptionCancelledEvent, type SubscriptionCreatedEvent, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ __export(index_exports, {
|
|
|
25
25
|
CustomersClient: () => CustomersClient,
|
|
26
26
|
EntitlementsClient: () => EntitlementsClient,
|
|
27
27
|
OrganizationsClient: () => OrganizationsClient,
|
|
28
|
+
PlansClient: () => PlansClient,
|
|
29
|
+
ProductsClient: () => ProductsClient,
|
|
28
30
|
StackBE: () => StackBE,
|
|
29
31
|
StackBEError: () => StackBEError,
|
|
30
32
|
SubscriptionsClient: () => SubscriptionsClient,
|
|
@@ -1333,6 +1335,109 @@ var OrganizationsClient = class {
|
|
|
1333
1335
|
}
|
|
1334
1336
|
};
|
|
1335
1337
|
|
|
1338
|
+
// src/plans.ts
|
|
1339
|
+
var PlansClient = class {
|
|
1340
|
+
constructor(http) {
|
|
1341
|
+
this.http = http;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* List all plans for the app.
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```typescript
|
|
1348
|
+
* // List all plans
|
|
1349
|
+
* const plans = await stackbe.plans.list();
|
|
1350
|
+
*
|
|
1351
|
+
* // Filter by product
|
|
1352
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1353
|
+
*
|
|
1354
|
+
* // Display in pricing page
|
|
1355
|
+
* plans.forEach(plan => {
|
|
1356
|
+
* console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
|
|
1357
|
+
* });
|
|
1358
|
+
* ```
|
|
1359
|
+
*/
|
|
1360
|
+
async list(options) {
|
|
1361
|
+
const params = new URLSearchParams();
|
|
1362
|
+
if (options?.productId) {
|
|
1363
|
+
params.set("productId", options.productId);
|
|
1364
|
+
}
|
|
1365
|
+
const query = params.toString();
|
|
1366
|
+
return this.http.get(`/v1/plans${query ? `?${query}` : ""}`);
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Get a plan by ID.
|
|
1370
|
+
*
|
|
1371
|
+
* @example
|
|
1372
|
+
* ```typescript
|
|
1373
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1374
|
+
* console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
1375
|
+
* ```
|
|
1376
|
+
*/
|
|
1377
|
+
async get(planId) {
|
|
1378
|
+
return this.http.get(`/v1/plans/${planId}`);
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Get active plans only (excludes archived plans).
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```typescript
|
|
1385
|
+
* const activePlans = await stackbe.plans.getActive();
|
|
1386
|
+
* ```
|
|
1387
|
+
*/
|
|
1388
|
+
async getActive(options) {
|
|
1389
|
+
const plans = await this.list(options);
|
|
1390
|
+
return plans.filter((p) => p.status === "active");
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Get plans sorted by price (ascending).
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* ```typescript
|
|
1397
|
+
* const plans = await stackbe.plans.listByPrice();
|
|
1398
|
+
* // [Free, Starter, Pro, Enterprise]
|
|
1399
|
+
* ```
|
|
1400
|
+
*/
|
|
1401
|
+
async listByPrice(options) {
|
|
1402
|
+
const plans = await this.getActive(options);
|
|
1403
|
+
return plans.sort((a, b) => a.priceCents - b.priceCents);
|
|
1404
|
+
}
|
|
1405
|
+
};
|
|
1406
|
+
var ProductsClient = class {
|
|
1407
|
+
constructor(http, appId) {
|
|
1408
|
+
this.http = http;
|
|
1409
|
+
this.appId = appId;
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* List all products for the app.
|
|
1413
|
+
*
|
|
1414
|
+
* @example
|
|
1415
|
+
* ```typescript
|
|
1416
|
+
* const products = await stackbe.products.list();
|
|
1417
|
+
* products.forEach(product => {
|
|
1418
|
+
* console.log(product.name, product.plans?.length, 'plans');
|
|
1419
|
+
* });
|
|
1420
|
+
* ```
|
|
1421
|
+
*/
|
|
1422
|
+
async list(options) {
|
|
1423
|
+
const params = new URLSearchParams();
|
|
1424
|
+
params.set("appId", options?.appId ?? this.appId);
|
|
1425
|
+
return this.http.get(`/v1/products?${params.toString()}`);
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Get a product by ID.
|
|
1429
|
+
*
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```typescript
|
|
1432
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1433
|
+
* console.log(product.name, product.description);
|
|
1434
|
+
* ```
|
|
1435
|
+
*/
|
|
1436
|
+
async get(productId) {
|
|
1437
|
+
return this.http.get(`/v1/products/${productId}`);
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1336
1441
|
// src/client.ts
|
|
1337
1442
|
var DEFAULT_BASE_URL = "https://api.stackbe.io";
|
|
1338
1443
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -1393,6 +1498,8 @@ var StackBE = class {
|
|
|
1393
1498
|
devCallbackUrl: config.devCallbackUrl
|
|
1394
1499
|
});
|
|
1395
1500
|
this.organizations = new OrganizationsClient(this.http, config.appId);
|
|
1501
|
+
this.plans = new PlansClient(this.http);
|
|
1502
|
+
this.products = new ProductsClient(this.http, config.appId);
|
|
1396
1503
|
}
|
|
1397
1504
|
/**
|
|
1398
1505
|
* Create a middleware for Express that tracks usage automatically.
|
|
@@ -1531,6 +1638,8 @@ var StackBE = class {
|
|
|
1531
1638
|
CustomersClient,
|
|
1532
1639
|
EntitlementsClient,
|
|
1533
1640
|
OrganizationsClient,
|
|
1641
|
+
PlansClient,
|
|
1642
|
+
ProductsClient,
|
|
1534
1643
|
StackBE,
|
|
1535
1644
|
StackBEError,
|
|
1536
1645
|
SubscriptionsClient,
|
package/dist/index.mjs
CHANGED
|
@@ -1299,6 +1299,109 @@ var OrganizationsClient = class {
|
|
|
1299
1299
|
}
|
|
1300
1300
|
};
|
|
1301
1301
|
|
|
1302
|
+
// src/plans.ts
|
|
1303
|
+
var PlansClient = class {
|
|
1304
|
+
constructor(http) {
|
|
1305
|
+
this.http = http;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* List all plans for the app.
|
|
1309
|
+
*
|
|
1310
|
+
* @example
|
|
1311
|
+
* ```typescript
|
|
1312
|
+
* // List all plans
|
|
1313
|
+
* const plans = await stackbe.plans.list();
|
|
1314
|
+
*
|
|
1315
|
+
* // Filter by product
|
|
1316
|
+
* const plans = await stackbe.plans.list({ productId: 'prod_123' });
|
|
1317
|
+
*
|
|
1318
|
+
* // Display in pricing page
|
|
1319
|
+
* plans.forEach(plan => {
|
|
1320
|
+
* console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
|
|
1321
|
+
* });
|
|
1322
|
+
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
async list(options) {
|
|
1325
|
+
const params = new URLSearchParams();
|
|
1326
|
+
if (options?.productId) {
|
|
1327
|
+
params.set("productId", options.productId);
|
|
1328
|
+
}
|
|
1329
|
+
const query = params.toString();
|
|
1330
|
+
return this.http.get(`/v1/plans${query ? `?${query}` : ""}`);
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Get a plan by ID.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```typescript
|
|
1337
|
+
* const plan = await stackbe.plans.get('plan_123');
|
|
1338
|
+
* console.log(plan.name, plan.priceCents, plan.entitlements);
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
async get(planId) {
|
|
1342
|
+
return this.http.get(`/v1/plans/${planId}`);
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Get active plans only (excludes archived plans).
|
|
1346
|
+
*
|
|
1347
|
+
* @example
|
|
1348
|
+
* ```typescript
|
|
1349
|
+
* const activePlans = await stackbe.plans.getActive();
|
|
1350
|
+
* ```
|
|
1351
|
+
*/
|
|
1352
|
+
async getActive(options) {
|
|
1353
|
+
const plans = await this.list(options);
|
|
1354
|
+
return plans.filter((p) => p.status === "active");
|
|
1355
|
+
}
|
|
1356
|
+
/**
|
|
1357
|
+
* Get plans sorted by price (ascending).
|
|
1358
|
+
*
|
|
1359
|
+
* @example
|
|
1360
|
+
* ```typescript
|
|
1361
|
+
* const plans = await stackbe.plans.listByPrice();
|
|
1362
|
+
* // [Free, Starter, Pro, Enterprise]
|
|
1363
|
+
* ```
|
|
1364
|
+
*/
|
|
1365
|
+
async listByPrice(options) {
|
|
1366
|
+
const plans = await this.getActive(options);
|
|
1367
|
+
return plans.sort((a, b) => a.priceCents - b.priceCents);
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
var ProductsClient = class {
|
|
1371
|
+
constructor(http, appId) {
|
|
1372
|
+
this.http = http;
|
|
1373
|
+
this.appId = appId;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* List all products for the app.
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* ```typescript
|
|
1380
|
+
* const products = await stackbe.products.list();
|
|
1381
|
+
* products.forEach(product => {
|
|
1382
|
+
* console.log(product.name, product.plans?.length, 'plans');
|
|
1383
|
+
* });
|
|
1384
|
+
* ```
|
|
1385
|
+
*/
|
|
1386
|
+
async list(options) {
|
|
1387
|
+
const params = new URLSearchParams();
|
|
1388
|
+
params.set("appId", options?.appId ?? this.appId);
|
|
1389
|
+
return this.http.get(`/v1/products?${params.toString()}`);
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Get a product by ID.
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
* ```typescript
|
|
1396
|
+
* const product = await stackbe.products.get('prod_123');
|
|
1397
|
+
* console.log(product.name, product.description);
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
async get(productId) {
|
|
1401
|
+
return this.http.get(`/v1/products/${productId}`);
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1302
1405
|
// src/client.ts
|
|
1303
1406
|
var DEFAULT_BASE_URL = "https://api.stackbe.io";
|
|
1304
1407
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -1359,6 +1462,8 @@ var StackBE = class {
|
|
|
1359
1462
|
devCallbackUrl: config.devCallbackUrl
|
|
1360
1463
|
});
|
|
1361
1464
|
this.organizations = new OrganizationsClient(this.http, config.appId);
|
|
1465
|
+
this.plans = new PlansClient(this.http);
|
|
1466
|
+
this.products = new ProductsClient(this.http, config.appId);
|
|
1362
1467
|
}
|
|
1363
1468
|
/**
|
|
1364
1469
|
* Create a middleware for Express that tracks usage automatically.
|
|
@@ -1496,6 +1601,8 @@ export {
|
|
|
1496
1601
|
CustomersClient,
|
|
1497
1602
|
EntitlementsClient,
|
|
1498
1603
|
OrganizationsClient,
|
|
1604
|
+
PlansClient,
|
|
1605
|
+
ProductsClient,
|
|
1499
1606
|
StackBE,
|
|
1500
1607
|
StackBEError,
|
|
1501
1608
|
SubscriptionsClient,
|
package/package.json
CHANGED