@stackbe/sdk 0.6.4 → 0.7.1

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/dist/index.d.ts CHANGED
@@ -304,8 +304,43 @@ 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
- /** Customer ID or email */
343
+ /** Customer ID or object with email. Use string for existing customer ID, object for email-based lookup/creation */
309
344
  customer: string | {
310
345
  email: string;
311
346
  name?: string;
@@ -316,6 +351,8 @@ interface CreateCheckoutOptions {
316
351
  successUrl: string;
317
352
  /** URL to redirect if checkout is canceled */
318
353
  cancelUrl?: string;
354
+ /** Organization ID for org-level subscriptions. Customer must be owner/admin of the org. */
355
+ organizationId?: string;
319
356
  /** Allow promotion codes */
320
357
  allowPromotionCodes?: boolean;
321
358
  /** Trial period in days */
@@ -790,7 +827,7 @@ declare class CheckoutClient {
790
827
  *
791
828
  * @example
792
829
  * ```typescript
793
- * // With new customer (will be created)
830
+ * // With customer email (looks up or creates customer)
794
831
  * const { url } = await stackbe.checkout.createSession({
795
832
  * customer: { email: 'user@example.com', name: 'John' },
796
833
  * planId: 'plan_pro_monthly',
@@ -798,6 +835,18 @@ declare class CheckoutClient {
798
835
  * trialDays: 14,
799
836
  * });
800
837
  * ```
838
+ *
839
+ * @example
840
+ * ```typescript
841
+ * // Organization-level subscription (B2B)
842
+ * const { url } = await stackbe.checkout.createSession({
843
+ * customer: 'cust_123',
844
+ * organizationId: 'org_456', // Customer must be owner/admin
845
+ * planId: 'plan_team',
846
+ * successUrl: 'https://myapp.com/success',
847
+ * cancelUrl: 'https://myapp.com/pricing',
848
+ * });
849
+ * ```
801
850
  */
802
851
  createSession(options: CreateCheckoutOptions): Promise<CheckoutSessionResponse>;
803
852
  /**
@@ -1230,6 +1279,342 @@ declare class OrganizationsClient {
1230
1279
  cancelInvite(orgId: string, inviteId: string): Promise<void>;
1231
1280
  }
1232
1281
 
1282
+ /**
1283
+ * Client for managing plans and products.
1284
+ * Use this to list available pricing plans for display in your pricing page.
1285
+ *
1286
+ * @example
1287
+ * ```typescript
1288
+ * // List all plans
1289
+ * const plans = await stackbe.plans.list();
1290
+ *
1291
+ * // List plans for a specific product
1292
+ * const plans = await stackbe.plans.list({ productId: 'prod_123' });
1293
+ *
1294
+ * // Get a specific plan
1295
+ * const plan = await stackbe.plans.get('plan_123');
1296
+ *
1297
+ * // List products
1298
+ * const products = await stackbe.products.list();
1299
+ * ```
1300
+ */
1301
+ declare class PlansClient {
1302
+ private readonly http;
1303
+ constructor(http: HttpClient);
1304
+ /**
1305
+ * List all plans for the app.
1306
+ *
1307
+ * @example
1308
+ * ```typescript
1309
+ * // List all plans
1310
+ * const plans = await stackbe.plans.list();
1311
+ *
1312
+ * // Filter by product
1313
+ * const plans = await stackbe.plans.list({ productId: 'prod_123' });
1314
+ *
1315
+ * // Display in pricing page
1316
+ * plans.forEach(plan => {
1317
+ * console.log(`${plan.name}: $${plan.priceCents / 100}/${plan.interval}`);
1318
+ * });
1319
+ * ```
1320
+ */
1321
+ list(options?: ListPlansOptions): Promise<Plan[]>;
1322
+ /**
1323
+ * Get a plan by ID.
1324
+ *
1325
+ * @example
1326
+ * ```typescript
1327
+ * const plan = await stackbe.plans.get('plan_123');
1328
+ * console.log(plan.name, plan.priceCents, plan.entitlements);
1329
+ * ```
1330
+ */
1331
+ get(planId: string): Promise<Plan>;
1332
+ /**
1333
+ * Get active plans only (excludes archived plans).
1334
+ *
1335
+ * @example
1336
+ * ```typescript
1337
+ * const activePlans = await stackbe.plans.getActive();
1338
+ * ```
1339
+ */
1340
+ getActive(options?: ListPlansOptions): Promise<Plan[]>;
1341
+ /**
1342
+ * Get plans sorted by price (ascending).
1343
+ *
1344
+ * @example
1345
+ * ```typescript
1346
+ * const plans = await stackbe.plans.listByPrice();
1347
+ * // [Free, Starter, Pro, Enterprise]
1348
+ * ```
1349
+ */
1350
+ listByPrice(options?: ListPlansOptions): Promise<Plan[]>;
1351
+ }
1352
+ /**
1353
+ * Client for managing products.
1354
+ *
1355
+ * @example
1356
+ * ```typescript
1357
+ * // List all products
1358
+ * const products = await stackbe.products.list();
1359
+ *
1360
+ * // Get a specific product
1361
+ * const product = await stackbe.products.get('prod_123');
1362
+ * ```
1363
+ */
1364
+ declare class ProductsClient {
1365
+ private readonly http;
1366
+ private readonly appId;
1367
+ constructor(http: HttpClient, appId: string);
1368
+ /**
1369
+ * List all products for the app.
1370
+ *
1371
+ * @example
1372
+ * ```typescript
1373
+ * const products = await stackbe.products.list();
1374
+ * products.forEach(product => {
1375
+ * console.log(product.name, product.plans?.length, 'plans');
1376
+ * });
1377
+ * ```
1378
+ */
1379
+ list(options?: ListProductsOptions): Promise<Product[]>;
1380
+ /**
1381
+ * Get a product by ID.
1382
+ *
1383
+ * @example
1384
+ * ```typescript
1385
+ * const product = await stackbe.products.get('prod_123');
1386
+ * console.log(product.name, product.description);
1387
+ * ```
1388
+ */
1389
+ get(productId: string): Promise<Product>;
1390
+ }
1391
+
1392
+ interface FeatureRequest {
1393
+ id: string;
1394
+ title: string;
1395
+ description?: string;
1396
+ status: 'new' | 'under_review' | 'planned' | 'in_progress' | 'completed' | 'declined';
1397
+ category?: string;
1398
+ authorId: string;
1399
+ authorEmail: string;
1400
+ voteCount: number;
1401
+ hasVoted?: boolean;
1402
+ createdAt: string;
1403
+ updatedAt: string;
1404
+ }
1405
+ interface FeatureRequestComment {
1406
+ id: string;
1407
+ customerEmail: string;
1408
+ content: string;
1409
+ isAdminReply: boolean;
1410
+ createdAt: string;
1411
+ }
1412
+ interface CreateFeatureRequestOptions {
1413
+ title: string;
1414
+ description?: string;
1415
+ category?: string;
1416
+ }
1417
+ interface ListFeatureRequestsOptions {
1418
+ status?: 'new' | 'under_review' | 'planned' | 'in_progress' | 'completed' | 'declined';
1419
+ category?: string;
1420
+ sortBy?: 'newest' | 'votes' | 'recent_activity';
1421
+ limit?: number;
1422
+ offset?: number;
1423
+ }
1424
+ interface FeatureRequestListResponse {
1425
+ data: FeatureRequest[];
1426
+ total: number;
1427
+ limit: number;
1428
+ offset: number;
1429
+ }
1430
+ interface InterestedCustomer {
1431
+ customerId: string;
1432
+ email: string;
1433
+ votedAt?: string;
1434
+ submittedAt?: string;
1435
+ }
1436
+ interface InterestedCustomersResponse {
1437
+ featureRequestId: string;
1438
+ title: string;
1439
+ status: string;
1440
+ author: {
1441
+ customerId: string;
1442
+ email: string;
1443
+ submittedAt: string;
1444
+ };
1445
+ voters: InterestedCustomer[];
1446
+ totalInterested: number;
1447
+ }
1448
+ interface CustomerFeatureActivity {
1449
+ customerId: string;
1450
+ submitted: Array<{
1451
+ id: string;
1452
+ title: string;
1453
+ status: string;
1454
+ voteCount: number;
1455
+ submittedAt: string;
1456
+ }>;
1457
+ votedOn: Array<{
1458
+ id: string;
1459
+ title: string;
1460
+ status: string;
1461
+ voteCount: number;
1462
+ votedAt: string;
1463
+ }>;
1464
+ totalSubmitted: number;
1465
+ totalVotes: number;
1466
+ }
1467
+ declare class FeatureRequestsClient {
1468
+ private http;
1469
+ private appId;
1470
+ constructor(http: HttpClient, appId: string);
1471
+ /**
1472
+ * List feature requests for the app.
1473
+ *
1474
+ * @example
1475
+ * ```typescript
1476
+ * // Get all feature requests
1477
+ * const { data, total } = await stackbe.featureRequests.list();
1478
+ *
1479
+ * // Filter by status
1480
+ * const planned = await stackbe.featureRequests.list({ status: 'planned' });
1481
+ *
1482
+ * // Sort by votes
1483
+ * const popular = await stackbe.featureRequests.list({ sortBy: 'votes' });
1484
+ * ```
1485
+ */
1486
+ list(options?: ListFeatureRequestsOptions): Promise<FeatureRequestListResponse>;
1487
+ /**
1488
+ * Submit a new feature request.
1489
+ * Requires customer session token.
1490
+ *
1491
+ * @example
1492
+ * ```typescript
1493
+ * const request = await stackbe.featureRequests.create({
1494
+ * title: 'Dark mode support',
1495
+ * description: 'Would love to have a dark theme option',
1496
+ * category: 'UI',
1497
+ * });
1498
+ * ```
1499
+ */
1500
+ create(options: CreateFeatureRequestOptions): Promise<FeatureRequest>;
1501
+ /**
1502
+ * Get a specific feature request by ID.
1503
+ *
1504
+ * @example
1505
+ * ```typescript
1506
+ * const request = await stackbe.featureRequests.get('req_123');
1507
+ * console.log(`${request.title} has ${request.voteCount} votes`);
1508
+ * ```
1509
+ */
1510
+ get(requestId: string): Promise<FeatureRequest & {
1511
+ comments: FeatureRequestComment[];
1512
+ }>;
1513
+ /**
1514
+ * Upvote a feature request.
1515
+ * Requires customer session token. Idempotent.
1516
+ *
1517
+ * @example
1518
+ * ```typescript
1519
+ * await stackbe.featureRequests.vote('req_123');
1520
+ * ```
1521
+ */
1522
+ vote(requestId: string): Promise<{
1523
+ success?: boolean;
1524
+ alreadyVoted?: boolean;
1525
+ voteCount: number;
1526
+ }>;
1527
+ /**
1528
+ * Remove your vote from a feature request.
1529
+ * Requires customer session token.
1530
+ *
1531
+ * @example
1532
+ * ```typescript
1533
+ * await stackbe.featureRequests.removeVote('req_123');
1534
+ * ```
1535
+ */
1536
+ removeVote(requestId: string): Promise<{
1537
+ success: boolean;
1538
+ voteCount: number;
1539
+ }>;
1540
+ /**
1541
+ * Add a comment to a feature request.
1542
+ * Requires customer session token.
1543
+ *
1544
+ * @example
1545
+ * ```typescript
1546
+ * await stackbe.featureRequests.addComment('req_123', {
1547
+ * content: 'This would be really helpful for my workflow!',
1548
+ * });
1549
+ * ```
1550
+ */
1551
+ addComment(requestId: string, options: {
1552
+ content: string;
1553
+ }): Promise<FeatureRequestComment>;
1554
+ /**
1555
+ * Update a feature request status or category.
1556
+ * Requires API key (admin).
1557
+ *
1558
+ * @example
1559
+ * ```typescript
1560
+ * await stackbe.featureRequests.update('req_123', {
1561
+ * status: 'planned',
1562
+ * category: 'Core Features',
1563
+ * });
1564
+ * ```
1565
+ */
1566
+ update(requestId: string, options: {
1567
+ status?: string;
1568
+ category?: string;
1569
+ }): Promise<FeatureRequest>;
1570
+ /**
1571
+ * Delete a feature request.
1572
+ * Requires API key (admin).
1573
+ *
1574
+ * @example
1575
+ * ```typescript
1576
+ * await stackbe.featureRequests.delete('req_123');
1577
+ * ```
1578
+ */
1579
+ delete(requestId: string): Promise<{
1580
+ success: boolean;
1581
+ }>;
1582
+ /**
1583
+ * Get all customers interested in a feature request (author + voters).
1584
+ * Useful for user research or notifying users when the feature ships.
1585
+ * Requires API key (admin).
1586
+ *
1587
+ * @example
1588
+ * ```typescript
1589
+ * const { author, voters, totalInterested } = await stackbe.featureRequests.getInterestedCustomers('req_123');
1590
+ *
1591
+ * // Notify all interested users
1592
+ * const emails = [author.email, ...voters.map(v => v.email)];
1593
+ * await sendNotification(emails, 'Your requested feature is now live!');
1594
+ * ```
1595
+ */
1596
+ getInterestedCustomers(requestId: string): Promise<InterestedCustomersResponse>;
1597
+ /**
1598
+ * Get a customer's feature request activity (requests submitted + votes).
1599
+ * Useful for displaying on customer profile.
1600
+ * Requires API key (admin).
1601
+ *
1602
+ * @example
1603
+ * ```typescript
1604
+ * const activity = await stackbe.featureRequests.getCustomerActivity('cust_123');
1605
+ *
1606
+ * console.log(`Submitted ${activity.totalSubmitted} requests`);
1607
+ * console.log(`Voted on ${activity.totalVotes} requests`);
1608
+ *
1609
+ * // Show their most wanted features
1610
+ * activity.votedOn.forEach(r => {
1611
+ * console.log(`- ${r.title} (${r.status})`);
1612
+ * });
1613
+ * ```
1614
+ */
1615
+ getCustomerActivity(customerId: string): Promise<CustomerFeatureActivity>;
1616
+ }
1617
+
1233
1618
  declare class StackBE {
1234
1619
  private http;
1235
1620
  private appId;
@@ -1247,6 +1632,12 @@ declare class StackBE {
1247
1632
  readonly auth: AuthClient;
1248
1633
  /** Organization management (B2B multi-user) */
1249
1634
  readonly organizations: OrganizationsClient;
1635
+ /** Pricing plans */
1636
+ readonly plans: PlansClient;
1637
+ /** Products */
1638
+ readonly products: ProductsClient;
1639
+ /** Feature requests and voting */
1640
+ readonly featureRequests: FeatureRequestsClient;
1250
1641
  /**
1251
1642
  * Create a new StackBE client.
1252
1643
  *
@@ -1347,4 +1738,4 @@ declare class StackBE {
1347
1738
  }): (req: any, res: any, next: any) => Promise<any>;
1348
1739
  }
1349
1740
 
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 };
1741
+ export { type AddMemberOptions, type AnyWebhookEvent, AuthClient, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type CreateCheckoutOptions, type CreateCustomerOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestListResponse, FeatureRequestsClient, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListFeatureRequestsOptions, 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 };