@stackbe/sdk 0.9.4 → 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
@@ -194,6 +194,12 @@ interface Subscription {
194
194
  pausedAt?: string | null;
195
195
  /** When the subscription will auto-resume (null = indefinite pause) */
196
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;
197
203
  createdAt: string;
198
204
  }
199
205
  interface TrialStatus {
@@ -210,6 +216,28 @@ interface TrialStatus {
210
216
  /** Whether the trial has converted to paid */
211
217
  hasConverted: boolean;
212
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
+ }
213
241
  interface CustomerWithSubscription extends Customer {
214
242
  subscription?: Subscription;
215
243
  }
@@ -1240,6 +1268,72 @@ declare class SubscriptionsClient {
1240
1268
  * ```
1241
1269
  */
1242
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
+ }>;
1243
1337
  }
1244
1338
 
1245
1339
  interface AuthClientOptions {
@@ -2431,4 +2525,4 @@ declare class StackBE {
2431
2525
  }): (req: any, res: any, next: any) => Promise<any>;
2432
2526
  }
2433
2527
 
2434
- 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, 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 };
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
@@ -194,6 +194,12 @@ interface Subscription {
194
194
  pausedAt?: string | null;
195
195
  /** When the subscription will auto-resume (null = indefinite pause) */
196
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;
197
203
  createdAt: string;
198
204
  }
199
205
  interface TrialStatus {
@@ -210,6 +216,28 @@ interface TrialStatus {
210
216
  /** Whether the trial has converted to paid */
211
217
  hasConverted: boolean;
212
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
+ }
213
241
  interface CustomerWithSubscription extends Customer {
214
242
  subscription?: Subscription;
215
243
  }
@@ -1240,6 +1268,72 @@ declare class SubscriptionsClient {
1240
1268
  * ```
1241
1269
  */
1242
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
+ }>;
1243
1337
  }
1244
1338
 
1245
1339
  interface AuthClientOptions {
@@ -2431,4 +2525,4 @@ declare class StackBE {
2431
2525
  }): (req: any, res: any, next: any) => Promise<any>;
2432
2526
  }
2433
2527
 
2434
- 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, 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 };
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
@@ -1086,6 +1086,87 @@ var SubscriptionsClient = class {
1086
1086
  `/v1/subscriptions/${subscriptionId}/trial/end`
1087
1087
  );
1088
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
+ }
1089
1170
  };
1090
1171
 
1091
1172
  // src/auth.ts
package/dist/index.mjs CHANGED
@@ -1046,6 +1046,87 @@ var SubscriptionsClient = class {
1046
1046
  `/v1/subscriptions/${subscriptionId}/trial/end`
1047
1047
  );
1048
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
+ }
1049
1130
  };
1050
1131
 
1051
1132
  // src/auth.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.9.4",
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",