@stackbe/sdk 0.9.3 → 0.9.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/dist/index.d.mts CHANGED
@@ -184,12 +184,60 @@ interface Subscription {
184
184
  currentPeriodStart: string;
185
185
  currentPeriodEnd: string;
186
186
  cancelAtPeriodEnd: boolean;
187
+ /** When the trial started (null if no trial) */
188
+ trialStart?: string | null;
189
+ /** When the trial ends/ended (null if no trial) */
190
+ trialEnd?: string | null;
191
+ /** When trial converted to paid (null if not converted yet) */
192
+ trialConvertedAt?: string | null;
187
193
  /** When the subscription was paused (null if not paused) */
188
194
  pausedAt?: string | null;
189
195
  /** When the subscription will auto-resume (null = indefinite pause) */
190
196
  resumesAt?: string | null;
197
+ /** Number of consecutive failed payment attempts */
198
+ failedPaymentCount?: number;
199
+ /** Timestamp of most recent failed payment */
200
+ lastPaymentFailedAt?: string | null;
201
+ /** When access will be revoked if payment not recovered */
202
+ gracePeriodEndsAt?: string | null;
191
203
  createdAt: string;
192
204
  }
205
+ interface TrialStatus {
206
+ /** Whether the subscription is currently in trial */
207
+ isTrialing: boolean;
208
+ /** When the trial started */
209
+ trialStart: string | null;
210
+ /** When the trial ends/ended */
211
+ trialEnd: string | null;
212
+ /** When the trial converted to paid (null if not converted) */
213
+ trialConvertedAt: string | null;
214
+ /** Days remaining in trial (null if not trialing) */
215
+ daysRemaining: number | null;
216
+ /** Whether the trial has converted to paid */
217
+ hasConverted: boolean;
218
+ }
219
+ interface DunningStatus {
220
+ /** Whether the subscription is past due */
221
+ isPastDue: boolean;
222
+ /** Whether the subscription is in grace period (past due but still has access) */
223
+ isInGracePeriod: boolean;
224
+ /** Number of consecutive failed payment attempts */
225
+ failedPaymentCount: number;
226
+ /** Timestamp of most recent failed payment */
227
+ lastPaymentFailedAt: string | null;
228
+ /** When access will be revoked if payment not recovered */
229
+ gracePeriodEndsAt: string | null;
230
+ /** Days until access is revoked (null if not in grace period) */
231
+ daysUntilAccessRevoked: number | null;
232
+ /** Days since payment failed */
233
+ daysSinceFailure: number | null;
234
+ /** Configured dunning email schedule (days after failure) */
235
+ dunningEmailSchedule: number[];
236
+ /** Which dunning emails have been sent (days) */
237
+ emailsSent: number[];
238
+ /** Whether the customer still has access (considering grace period) */
239
+ hasAccess: boolean;
240
+ }
193
241
  interface CustomerWithSubscription extends Customer {
194
242
  subscription?: Subscription;
195
243
  }
@@ -1177,6 +1225,115 @@ declare class SubscriptionsClient {
1177
1225
  * ```
1178
1226
  */
1179
1227
  resume(subscriptionId: string): Promise<Subscription>;
1228
+ /**
1229
+ * Get trial status for a subscription.
1230
+ *
1231
+ * @example
1232
+ * ```typescript
1233
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1234
+ *
1235
+ * if (trial.isTrialing) {
1236
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1237
+ * }
1238
+ *
1239
+ * if (trial.hasConverted) {
1240
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1241
+ * }
1242
+ * ```
1243
+ */
1244
+ getTrialStatus(subscriptionId: string): Promise<TrialStatus>;
1245
+ /**
1246
+ * Extend a trial by a number of days.
1247
+ *
1248
+ * Only works for subscriptions currently in trial.
1249
+ *
1250
+ * @example
1251
+ * ```typescript
1252
+ * // Give the customer 7 more days
1253
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1254
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1255
+ * ```
1256
+ */
1257
+ extendTrial(subscriptionId: string, days: number): Promise<Subscription>;
1258
+ /**
1259
+ * End trial immediately and convert to paid subscription.
1260
+ *
1261
+ * The customer will be charged right away.
1262
+ *
1263
+ * @example
1264
+ * ```typescript
1265
+ * // Customer wants to start paying immediately
1266
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1267
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1268
+ * ```
1269
+ */
1270
+ endTrial(subscriptionId: string): Promise<Subscription>;
1271
+ /**
1272
+ * Get dunning/payment recovery status for a subscription.
1273
+ *
1274
+ * Shows if the subscription is past due, in grace period, and when access
1275
+ * will be revoked if payment isn't recovered.
1276
+ *
1277
+ * @example
1278
+ * ```typescript
1279
+ * const dunning = await stackbe.subscriptions.getDunningStatus('sub_123');
1280
+ *
1281
+ * if (dunning.isPastDue) {
1282
+ * console.log(`Payment failed ${dunning.daysSinceFailure} days ago`);
1283
+ *
1284
+ * if (dunning.isInGracePeriod) {
1285
+ * console.log(`Access ends in ${dunning.daysUntilAccessRevoked} days`);
1286
+ * }
1287
+ * }
1288
+ *
1289
+ * // Check if customer still has access
1290
+ * if (dunning.hasAccess) {
1291
+ * // Allow access
1292
+ * }
1293
+ * ```
1294
+ */
1295
+ getDunningStatus(subscriptionId: string): Promise<DunningStatus>;
1296
+ /**
1297
+ * List all past-due subscriptions.
1298
+ *
1299
+ * Useful for monitoring and recovery efforts.
1300
+ *
1301
+ * @example
1302
+ * ```typescript
1303
+ * // List all past-due subscriptions
1304
+ * const pastDue = await stackbe.subscriptions.listPastDue();
1305
+ *
1306
+ * // List subscriptions losing access within 3 days
1307
+ * const urgent = await stackbe.subscriptions.listPastDue({ gracePeriodExpiringSoon: 3 });
1308
+ *
1309
+ * for (const sub of urgent) {
1310
+ * console.log(`${sub.customer.email} loses access in ${sub.gracePeriodEndsAt}`);
1311
+ * }
1312
+ * ```
1313
+ */
1314
+ listPastDue(options?: {
1315
+ appId?: string;
1316
+ gracePeriodExpiringSoon?: number;
1317
+ }): Promise<Subscription[]>;
1318
+ /**
1319
+ * Check if a subscription still has access (considering grace period).
1320
+ *
1321
+ * Returns true if:
1322
+ * - Subscription is active
1323
+ * - Subscription is trialing
1324
+ * - Subscription is past_due but within grace period
1325
+ *
1326
+ * @example
1327
+ * ```typescript
1328
+ * const { hasAccess } = await stackbe.subscriptions.checkAccess('sub_123');
1329
+ * if (!hasAccess) {
1330
+ * // Show upgrade prompt or block feature
1331
+ * }
1332
+ * ```
1333
+ */
1334
+ checkAccess(subscriptionId: string): Promise<{
1335
+ hasAccess: boolean;
1336
+ }>;
1180
1337
  }
1181
1338
 
1182
1339
  interface AuthClientOptions {
@@ -2368,4 +2525,4 @@ declare class StackBE {
2368
2525
  }): (req: any, res: any, next: any) => Promise<any>;
2369
2526
  }
2370
2527
 
2371
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, 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 SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2528
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, 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 SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.d.ts CHANGED
@@ -184,12 +184,60 @@ interface Subscription {
184
184
  currentPeriodStart: string;
185
185
  currentPeriodEnd: string;
186
186
  cancelAtPeriodEnd: boolean;
187
+ /** When the trial started (null if no trial) */
188
+ trialStart?: string | null;
189
+ /** When the trial ends/ended (null if no trial) */
190
+ trialEnd?: string | null;
191
+ /** When trial converted to paid (null if not converted yet) */
192
+ trialConvertedAt?: string | null;
187
193
  /** When the subscription was paused (null if not paused) */
188
194
  pausedAt?: string | null;
189
195
  /** When the subscription will auto-resume (null = indefinite pause) */
190
196
  resumesAt?: string | null;
197
+ /** Number of consecutive failed payment attempts */
198
+ failedPaymentCount?: number;
199
+ /** Timestamp of most recent failed payment */
200
+ lastPaymentFailedAt?: string | null;
201
+ /** When access will be revoked if payment not recovered */
202
+ gracePeriodEndsAt?: string | null;
191
203
  createdAt: string;
192
204
  }
205
+ interface TrialStatus {
206
+ /** Whether the subscription is currently in trial */
207
+ isTrialing: boolean;
208
+ /** When the trial started */
209
+ trialStart: string | null;
210
+ /** When the trial ends/ended */
211
+ trialEnd: string | null;
212
+ /** When the trial converted to paid (null if not converted) */
213
+ trialConvertedAt: string | null;
214
+ /** Days remaining in trial (null if not trialing) */
215
+ daysRemaining: number | null;
216
+ /** Whether the trial has converted to paid */
217
+ hasConverted: boolean;
218
+ }
219
+ interface DunningStatus {
220
+ /** Whether the subscription is past due */
221
+ isPastDue: boolean;
222
+ /** Whether the subscription is in grace period (past due but still has access) */
223
+ isInGracePeriod: boolean;
224
+ /** Number of consecutive failed payment attempts */
225
+ failedPaymentCount: number;
226
+ /** Timestamp of most recent failed payment */
227
+ lastPaymentFailedAt: string | null;
228
+ /** When access will be revoked if payment not recovered */
229
+ gracePeriodEndsAt: string | null;
230
+ /** Days until access is revoked (null if not in grace period) */
231
+ daysUntilAccessRevoked: number | null;
232
+ /** Days since payment failed */
233
+ daysSinceFailure: number | null;
234
+ /** Configured dunning email schedule (days after failure) */
235
+ dunningEmailSchedule: number[];
236
+ /** Which dunning emails have been sent (days) */
237
+ emailsSent: number[];
238
+ /** Whether the customer still has access (considering grace period) */
239
+ hasAccess: boolean;
240
+ }
193
241
  interface CustomerWithSubscription extends Customer {
194
242
  subscription?: Subscription;
195
243
  }
@@ -1177,6 +1225,115 @@ declare class SubscriptionsClient {
1177
1225
  * ```
1178
1226
  */
1179
1227
  resume(subscriptionId: string): Promise<Subscription>;
1228
+ /**
1229
+ * Get trial status for a subscription.
1230
+ *
1231
+ * @example
1232
+ * ```typescript
1233
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1234
+ *
1235
+ * if (trial.isTrialing) {
1236
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1237
+ * }
1238
+ *
1239
+ * if (trial.hasConverted) {
1240
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1241
+ * }
1242
+ * ```
1243
+ */
1244
+ getTrialStatus(subscriptionId: string): Promise<TrialStatus>;
1245
+ /**
1246
+ * Extend a trial by a number of days.
1247
+ *
1248
+ * Only works for subscriptions currently in trial.
1249
+ *
1250
+ * @example
1251
+ * ```typescript
1252
+ * // Give the customer 7 more days
1253
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1254
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1255
+ * ```
1256
+ */
1257
+ extendTrial(subscriptionId: string, days: number): Promise<Subscription>;
1258
+ /**
1259
+ * End trial immediately and convert to paid subscription.
1260
+ *
1261
+ * The customer will be charged right away.
1262
+ *
1263
+ * @example
1264
+ * ```typescript
1265
+ * // Customer wants to start paying immediately
1266
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1267
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1268
+ * ```
1269
+ */
1270
+ endTrial(subscriptionId: string): Promise<Subscription>;
1271
+ /**
1272
+ * Get dunning/payment recovery status for a subscription.
1273
+ *
1274
+ * Shows if the subscription is past due, in grace period, and when access
1275
+ * will be revoked if payment isn't recovered.
1276
+ *
1277
+ * @example
1278
+ * ```typescript
1279
+ * const dunning = await stackbe.subscriptions.getDunningStatus('sub_123');
1280
+ *
1281
+ * if (dunning.isPastDue) {
1282
+ * console.log(`Payment failed ${dunning.daysSinceFailure} days ago`);
1283
+ *
1284
+ * if (dunning.isInGracePeriod) {
1285
+ * console.log(`Access ends in ${dunning.daysUntilAccessRevoked} days`);
1286
+ * }
1287
+ * }
1288
+ *
1289
+ * // Check if customer still has access
1290
+ * if (dunning.hasAccess) {
1291
+ * // Allow access
1292
+ * }
1293
+ * ```
1294
+ */
1295
+ getDunningStatus(subscriptionId: string): Promise<DunningStatus>;
1296
+ /**
1297
+ * List all past-due subscriptions.
1298
+ *
1299
+ * Useful for monitoring and recovery efforts.
1300
+ *
1301
+ * @example
1302
+ * ```typescript
1303
+ * // List all past-due subscriptions
1304
+ * const pastDue = await stackbe.subscriptions.listPastDue();
1305
+ *
1306
+ * // List subscriptions losing access within 3 days
1307
+ * const urgent = await stackbe.subscriptions.listPastDue({ gracePeriodExpiringSoon: 3 });
1308
+ *
1309
+ * for (const sub of urgent) {
1310
+ * console.log(`${sub.customer.email} loses access in ${sub.gracePeriodEndsAt}`);
1311
+ * }
1312
+ * ```
1313
+ */
1314
+ listPastDue(options?: {
1315
+ appId?: string;
1316
+ gracePeriodExpiringSoon?: number;
1317
+ }): Promise<Subscription[]>;
1318
+ /**
1319
+ * Check if a subscription still has access (considering grace period).
1320
+ *
1321
+ * Returns true if:
1322
+ * - Subscription is active
1323
+ * - Subscription is trialing
1324
+ * - Subscription is past_due but within grace period
1325
+ *
1326
+ * @example
1327
+ * ```typescript
1328
+ * const { hasAccess } = await stackbe.subscriptions.checkAccess('sub_123');
1329
+ * if (!hasAccess) {
1330
+ * // Show upgrade prompt or block feature
1331
+ * }
1332
+ * ```
1333
+ */
1334
+ checkAccess(subscriptionId: string): Promise<{
1335
+ hasAccess: boolean;
1336
+ }>;
1180
1337
  }
1181
1338
 
1182
1339
  interface AuthClientOptions {
@@ -2368,4 +2525,4 @@ declare class StackBE {
2368
2525
  }): (req: any, res: any, next: any) => Promise<any>;
2369
2526
  }
2370
2527
 
2371
- export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, 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 SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2528
+ export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, type BillingPortalSession, type CancelSubscriptionOptions, type CancelSubscriptionResponse, type CheckEntitlementResponse, type CheckUsageResponse, CheckoutClient, type CheckoutSessionResponse, type Coupon, type CouponDiscountType, type CouponDuration, CouponsClient, type CreateCheckoutOptions, type CreateCouponOptions, type CreateCustomerOptions, type CreateEarlyAccessSignupOptions, type CreateFeatureRequestOptions, type CreateOrganizationOptions, type Customer, type CustomerCreatedEvent, type CustomerFeatureActivity, type CustomerInvoice, type CustomerInvoicesResponse, type CustomerPaymentMethod, type CustomerSubscriptionHistory, type CustomerSubscriptionHistoryResponse, type CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, type DunningStatus, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestImage, type FeatureRequestListResponse, FeatureRequestsClient, type GetSubscriptionOptions, type InterestedCustomer, type InterestedCustomersResponse, type InviteMemberOptions, type ListEarlyAccessOptions, 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 SubscriptionPlan, type SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type TrialStatus, type UpcomingInvoice, type UpdateCouponOptions, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type ValidateCouponResult, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
package/dist/index.js CHANGED
@@ -1027,6 +1027,146 @@ var SubscriptionsClient = class {
1027
1027
  `/v1/subscriptions/${subscriptionId}/resume`
1028
1028
  );
1029
1029
  }
1030
+ // ============================================
1031
+ // Trial Management Methods
1032
+ // ============================================
1033
+ /**
1034
+ * Get trial status for a subscription.
1035
+ *
1036
+ * @example
1037
+ * ```typescript
1038
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
1039
+ *
1040
+ * if (trial.isTrialing) {
1041
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1042
+ * }
1043
+ *
1044
+ * if (trial.hasConverted) {
1045
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1046
+ * }
1047
+ * ```
1048
+ */
1049
+ async getTrialStatus(subscriptionId) {
1050
+ return this.http.get(
1051
+ `/v1/subscriptions/${subscriptionId}/trial`
1052
+ );
1053
+ }
1054
+ /**
1055
+ * Extend a trial by a number of days.
1056
+ *
1057
+ * Only works for subscriptions currently in trial.
1058
+ *
1059
+ * @example
1060
+ * ```typescript
1061
+ * // Give the customer 7 more days
1062
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1063
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1064
+ * ```
1065
+ */
1066
+ async extendTrial(subscriptionId, days) {
1067
+ return this.http.post(
1068
+ `/v1/subscriptions/${subscriptionId}/trial/extend`,
1069
+ { days }
1070
+ );
1071
+ }
1072
+ /**
1073
+ * End trial immediately and convert to paid subscription.
1074
+ *
1075
+ * The customer will be charged right away.
1076
+ *
1077
+ * @example
1078
+ * ```typescript
1079
+ * // Customer wants to start paying immediately
1080
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1081
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1082
+ * ```
1083
+ */
1084
+ async endTrial(subscriptionId) {
1085
+ return this.http.post(
1086
+ `/v1/subscriptions/${subscriptionId}/trial/end`
1087
+ );
1088
+ }
1089
+ // ============================================
1090
+ // Dunning / Payment Recovery Methods
1091
+ // ============================================
1092
+ /**
1093
+ * Get dunning/payment recovery status for a subscription.
1094
+ *
1095
+ * Shows if the subscription is past due, in grace period, and when access
1096
+ * will be revoked if payment isn't recovered.
1097
+ *
1098
+ * @example
1099
+ * ```typescript
1100
+ * const dunning = await stackbe.subscriptions.getDunningStatus('sub_123');
1101
+ *
1102
+ * if (dunning.isPastDue) {
1103
+ * console.log(`Payment failed ${dunning.daysSinceFailure} days ago`);
1104
+ *
1105
+ * if (dunning.isInGracePeriod) {
1106
+ * console.log(`Access ends in ${dunning.daysUntilAccessRevoked} days`);
1107
+ * }
1108
+ * }
1109
+ *
1110
+ * // Check if customer still has access
1111
+ * if (dunning.hasAccess) {
1112
+ * // Allow access
1113
+ * }
1114
+ * ```
1115
+ */
1116
+ async getDunningStatus(subscriptionId) {
1117
+ return this.http.get(
1118
+ `/v1/subscriptions/${subscriptionId}/dunning`
1119
+ );
1120
+ }
1121
+ /**
1122
+ * List all past-due subscriptions.
1123
+ *
1124
+ * Useful for monitoring and recovery efforts.
1125
+ *
1126
+ * @example
1127
+ * ```typescript
1128
+ * // List all past-due subscriptions
1129
+ * const pastDue = await stackbe.subscriptions.listPastDue();
1130
+ *
1131
+ * // List subscriptions losing access within 3 days
1132
+ * const urgent = await stackbe.subscriptions.listPastDue({ gracePeriodExpiringSoon: 3 });
1133
+ *
1134
+ * for (const sub of urgent) {
1135
+ * console.log(`${sub.customer.email} loses access in ${sub.gracePeriodEndsAt}`);
1136
+ * }
1137
+ * ```
1138
+ */
1139
+ async listPastDue(options) {
1140
+ const params = new URLSearchParams();
1141
+ if (options?.appId) params.set("appId", options.appId);
1142
+ if (options?.gracePeriodExpiringSoon) {
1143
+ params.set("gracePeriodExpiringSoon", String(options.gracePeriodExpiringSoon));
1144
+ }
1145
+ const query = params.toString();
1146
+ const path = `/v1/subscriptions/past-due${query ? `?${query}` : ""}`;
1147
+ return this.http.get(path);
1148
+ }
1149
+ /**
1150
+ * Check if a subscription still has access (considering grace period).
1151
+ *
1152
+ * Returns true if:
1153
+ * - Subscription is active
1154
+ * - Subscription is trialing
1155
+ * - Subscription is past_due but within grace period
1156
+ *
1157
+ * @example
1158
+ * ```typescript
1159
+ * const { hasAccess } = await stackbe.subscriptions.checkAccess('sub_123');
1160
+ * if (!hasAccess) {
1161
+ * // Show upgrade prompt or block feature
1162
+ * }
1163
+ * ```
1164
+ */
1165
+ async checkAccess(subscriptionId) {
1166
+ return this.http.get(
1167
+ `/v1/subscriptions/${subscriptionId}/has-access`
1168
+ );
1169
+ }
1030
1170
  };
1031
1171
 
1032
1172
  // src/auth.ts
package/dist/index.mjs CHANGED
@@ -987,6 +987,146 @@ var SubscriptionsClient = class {
987
987
  `/v1/subscriptions/${subscriptionId}/resume`
988
988
  );
989
989
  }
990
+ // ============================================
991
+ // Trial Management Methods
992
+ // ============================================
993
+ /**
994
+ * Get trial status for a subscription.
995
+ *
996
+ * @example
997
+ * ```typescript
998
+ * const trial = await stackbe.subscriptions.getTrialStatus('sub_123');
999
+ *
1000
+ * if (trial.isTrialing) {
1001
+ * console.log(`Trial ends in ${trial.daysRemaining} days`);
1002
+ * }
1003
+ *
1004
+ * if (trial.hasConverted) {
1005
+ * console.log(`Converted to paid on ${trial.trialConvertedAt}`);
1006
+ * }
1007
+ * ```
1008
+ */
1009
+ async getTrialStatus(subscriptionId) {
1010
+ return this.http.get(
1011
+ `/v1/subscriptions/${subscriptionId}/trial`
1012
+ );
1013
+ }
1014
+ /**
1015
+ * Extend a trial by a number of days.
1016
+ *
1017
+ * Only works for subscriptions currently in trial.
1018
+ *
1019
+ * @example
1020
+ * ```typescript
1021
+ * // Give the customer 7 more days
1022
+ * const subscription = await stackbe.subscriptions.extendTrial('sub_123', 7);
1023
+ * console.log(`New trial end: ${subscription.trialEnd}`);
1024
+ * ```
1025
+ */
1026
+ async extendTrial(subscriptionId, days) {
1027
+ return this.http.post(
1028
+ `/v1/subscriptions/${subscriptionId}/trial/extend`,
1029
+ { days }
1030
+ );
1031
+ }
1032
+ /**
1033
+ * End trial immediately and convert to paid subscription.
1034
+ *
1035
+ * The customer will be charged right away.
1036
+ *
1037
+ * @example
1038
+ * ```typescript
1039
+ * // Customer wants to start paying immediately
1040
+ * const subscription = await stackbe.subscriptions.endTrial('sub_123');
1041
+ * console.log(`Converted at: ${subscription.trialConvertedAt}`);
1042
+ * ```
1043
+ */
1044
+ async endTrial(subscriptionId) {
1045
+ return this.http.post(
1046
+ `/v1/subscriptions/${subscriptionId}/trial/end`
1047
+ );
1048
+ }
1049
+ // ============================================
1050
+ // Dunning / Payment Recovery Methods
1051
+ // ============================================
1052
+ /**
1053
+ * Get dunning/payment recovery status for a subscription.
1054
+ *
1055
+ * Shows if the subscription is past due, in grace period, and when access
1056
+ * will be revoked if payment isn't recovered.
1057
+ *
1058
+ * @example
1059
+ * ```typescript
1060
+ * const dunning = await stackbe.subscriptions.getDunningStatus('sub_123');
1061
+ *
1062
+ * if (dunning.isPastDue) {
1063
+ * console.log(`Payment failed ${dunning.daysSinceFailure} days ago`);
1064
+ *
1065
+ * if (dunning.isInGracePeriod) {
1066
+ * console.log(`Access ends in ${dunning.daysUntilAccessRevoked} days`);
1067
+ * }
1068
+ * }
1069
+ *
1070
+ * // Check if customer still has access
1071
+ * if (dunning.hasAccess) {
1072
+ * // Allow access
1073
+ * }
1074
+ * ```
1075
+ */
1076
+ async getDunningStatus(subscriptionId) {
1077
+ return this.http.get(
1078
+ `/v1/subscriptions/${subscriptionId}/dunning`
1079
+ );
1080
+ }
1081
+ /**
1082
+ * List all past-due subscriptions.
1083
+ *
1084
+ * Useful for monitoring and recovery efforts.
1085
+ *
1086
+ * @example
1087
+ * ```typescript
1088
+ * // List all past-due subscriptions
1089
+ * const pastDue = await stackbe.subscriptions.listPastDue();
1090
+ *
1091
+ * // List subscriptions losing access within 3 days
1092
+ * const urgent = await stackbe.subscriptions.listPastDue({ gracePeriodExpiringSoon: 3 });
1093
+ *
1094
+ * for (const sub of urgent) {
1095
+ * console.log(`${sub.customer.email} loses access in ${sub.gracePeriodEndsAt}`);
1096
+ * }
1097
+ * ```
1098
+ */
1099
+ async listPastDue(options) {
1100
+ const params = new URLSearchParams();
1101
+ if (options?.appId) params.set("appId", options.appId);
1102
+ if (options?.gracePeriodExpiringSoon) {
1103
+ params.set("gracePeriodExpiringSoon", String(options.gracePeriodExpiringSoon));
1104
+ }
1105
+ const query = params.toString();
1106
+ const path = `/v1/subscriptions/past-due${query ? `?${query}` : ""}`;
1107
+ return this.http.get(path);
1108
+ }
1109
+ /**
1110
+ * Check if a subscription still has access (considering grace period).
1111
+ *
1112
+ * Returns true if:
1113
+ * - Subscription is active
1114
+ * - Subscription is trialing
1115
+ * - Subscription is past_due but within grace period
1116
+ *
1117
+ * @example
1118
+ * ```typescript
1119
+ * const { hasAccess } = await stackbe.subscriptions.checkAccess('sub_123');
1120
+ * if (!hasAccess) {
1121
+ * // Show upgrade prompt or block feature
1122
+ * }
1123
+ * ```
1124
+ */
1125
+ async checkAccess(subscriptionId) {
1126
+ return this.http.get(
1127
+ `/v1/subscriptions/${subscriptionId}/has-access`
1128
+ );
1129
+ }
990
1130
  };
991
1131
 
992
1132
  // src/auth.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Official JavaScript/TypeScript SDK for StackBE - the billing backend for your side project",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",