@stackbe/sdk 0.8.6 → 0.9.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.mts CHANGED
@@ -353,6 +353,8 @@ interface CreateCheckoutOptions {
353
353
  cancelUrl?: string;
354
354
  /** Organization ID for org-level subscriptions. Customer must be owner/admin of the org. */
355
355
  organizationId?: string;
356
+ /** Coupon/promo code to apply (e.g., "SAVE20") */
357
+ couponCode?: string;
356
358
  /** Allow promotion codes */
357
359
  allowPromotionCodes?: boolean;
358
360
  /** Trial period in days */
@@ -378,6 +380,8 @@ interface SubscriptionPlan {
378
380
  priceCents: number;
379
381
  currency: string;
380
382
  interval: 'month' | 'year';
383
+ /** Plan entitlements (feature flags) - included when using expand=plan */
384
+ entitlements?: Record<string, unknown>;
381
385
  }
382
386
  interface SubscriptionWithPlan extends Subscription {
383
387
  plan: SubscriptionPlan;
@@ -2089,6 +2093,137 @@ declare class EarlyAccessClient {
2089
2093
  updateStatus(signupId: string, status: 'new' | 'invited' | 'converted' | 'archived'): Promise<EarlyAccessSignup>;
2090
2094
  }
2091
2095
 
2096
+ type CouponDiscountType = 'percentage' | 'fixed_amount';
2097
+ interface Coupon {
2098
+ id: string;
2099
+ code: string;
2100
+ name?: string;
2101
+ discountType: CouponDiscountType;
2102
+ discountValue: number;
2103
+ currency?: string;
2104
+ maxRedemptions?: number;
2105
+ timesRedeemed: number;
2106
+ expiresAt?: string;
2107
+ validPlanIds: string[];
2108
+ active: boolean;
2109
+ createdAt: string;
2110
+ updatedAt: string;
2111
+ }
2112
+ interface CreateCouponOptions {
2113
+ /** Coupon code (alphanumeric, will be uppercased) */
2114
+ code: string;
2115
+ /** Internal name for dashboard */
2116
+ name?: string;
2117
+ /** Type of discount */
2118
+ discountType: CouponDiscountType;
2119
+ /** Discount value (percentage 1-100, or cents for fixed_amount) */
2120
+ discountValue: number;
2121
+ /** Currency code (required for fixed_amount) */
2122
+ currency?: string;
2123
+ /** Maximum number of times this coupon can be used */
2124
+ maxRedemptions?: number;
2125
+ /** When the coupon expires (ISO date string) */
2126
+ expiresAt?: string;
2127
+ /** Restrict to specific plan IDs (empty = valid for all plans) */
2128
+ validPlanIds?: string[];
2129
+ /** Whether the coupon is active */
2130
+ active?: boolean;
2131
+ }
2132
+ interface UpdateCouponOptions {
2133
+ name?: string;
2134
+ maxRedemptions?: number;
2135
+ expiresAt?: string;
2136
+ validPlanIds?: string[];
2137
+ active?: boolean;
2138
+ }
2139
+ interface ValidateCouponResult {
2140
+ valid: boolean;
2141
+ coupon?: {
2142
+ id: string;
2143
+ code: string;
2144
+ discountType: CouponDiscountType;
2145
+ discountValue: number;
2146
+ currency?: string;
2147
+ };
2148
+ error?: string;
2149
+ }
2150
+ declare class CouponsClient {
2151
+ private http;
2152
+ private appId;
2153
+ constructor(http: HttpClient, appId: string);
2154
+ /**
2155
+ * Create a new coupon/promo code.
2156
+ *
2157
+ * @example
2158
+ * ```typescript
2159
+ * const coupon = await stackbe.coupons.create({
2160
+ * code: 'SAVE20',
2161
+ * discountType: 'percentage',
2162
+ * discountValue: 20,
2163
+ * maxRedemptions: 100,
2164
+ * expiresAt: '2026-12-31T23:59:59Z',
2165
+ * });
2166
+ * ```
2167
+ */
2168
+ create(options: CreateCouponOptions): Promise<Coupon>;
2169
+ /**
2170
+ * List all coupons for your app.
2171
+ *
2172
+ * @example
2173
+ * ```typescript
2174
+ * const coupons = await stackbe.coupons.list();
2175
+ * const activeCoupons = await stackbe.coupons.list({ active: true });
2176
+ * ```
2177
+ */
2178
+ list(options?: {
2179
+ active?: boolean;
2180
+ }): Promise<Coupon[]>;
2181
+ /**
2182
+ * Get a specific coupon by ID.
2183
+ *
2184
+ * @example
2185
+ * ```typescript
2186
+ * const coupon = await stackbe.coupons.get('coupon_abc123');
2187
+ * ```
2188
+ */
2189
+ get(couponId: string): Promise<Coupon>;
2190
+ /**
2191
+ * Validate a coupon code before checkout.
2192
+ *
2193
+ * @example
2194
+ * ```typescript
2195
+ * const result = await stackbe.coupons.validate('SAVE20', 'plan_pro');
2196
+ *
2197
+ * if (result.valid) {
2198
+ * console.log(`${result.coupon.discountValue}% off!`);
2199
+ * } else {
2200
+ * console.log(result.error); // "Coupon has expired"
2201
+ * }
2202
+ * ```
2203
+ */
2204
+ validate(code: string, planId?: string): Promise<ValidateCouponResult>;
2205
+ /**
2206
+ * Update a coupon.
2207
+ *
2208
+ * @example
2209
+ * ```typescript
2210
+ * const coupon = await stackbe.coupons.update('coupon_abc123', {
2211
+ * active: false,
2212
+ * });
2213
+ * ```
2214
+ */
2215
+ update(couponId: string, options: UpdateCouponOptions): Promise<Coupon>;
2216
+ /**
2217
+ * Delete a coupon.
2218
+ *
2219
+ * @example
2220
+ * ```typescript
2221
+ * await stackbe.coupons.delete('coupon_abc123');
2222
+ * ```
2223
+ */
2224
+ delete(couponId: string): Promise<void>;
2225
+ }
2226
+
2092
2227
  declare class StackBE {
2093
2228
  private http;
2094
2229
  private appId;
@@ -2116,6 +2251,8 @@ declare class StackBE {
2116
2251
  readonly affiliates: AffiliatesClient;
2117
2252
  /** Early access / waitlist signups */
2118
2253
  readonly earlyAccess: EarlyAccessClient;
2254
+ /** Coupon/promo code management */
2255
+ readonly coupons: CouponsClient;
2119
2256
  /**
2120
2257
  * Create a new StackBE client.
2121
2258
  *
@@ -2216,4 +2353,4 @@ declare class StackBE {
2216
2353
  }): (req: any, res: any, next: any) => Promise<any>;
2217
2354
  }
2218
2355
 
2219
- 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 CreateCheckoutOptions, 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 UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2356
+ 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 };
package/dist/index.d.ts CHANGED
@@ -353,6 +353,8 @@ interface CreateCheckoutOptions {
353
353
  cancelUrl?: string;
354
354
  /** Organization ID for org-level subscriptions. Customer must be owner/admin of the org. */
355
355
  organizationId?: string;
356
+ /** Coupon/promo code to apply (e.g., "SAVE20") */
357
+ couponCode?: string;
356
358
  /** Allow promotion codes */
357
359
  allowPromotionCodes?: boolean;
358
360
  /** Trial period in days */
@@ -378,6 +380,8 @@ interface SubscriptionPlan {
378
380
  priceCents: number;
379
381
  currency: string;
380
382
  interval: 'month' | 'year';
383
+ /** Plan entitlements (feature flags) - included when using expand=plan */
384
+ entitlements?: Record<string, unknown>;
381
385
  }
382
386
  interface SubscriptionWithPlan extends Subscription {
383
387
  plan: SubscriptionPlan;
@@ -2089,6 +2093,137 @@ declare class EarlyAccessClient {
2089
2093
  updateStatus(signupId: string, status: 'new' | 'invited' | 'converted' | 'archived'): Promise<EarlyAccessSignup>;
2090
2094
  }
2091
2095
 
2096
+ type CouponDiscountType = 'percentage' | 'fixed_amount';
2097
+ interface Coupon {
2098
+ id: string;
2099
+ code: string;
2100
+ name?: string;
2101
+ discountType: CouponDiscountType;
2102
+ discountValue: number;
2103
+ currency?: string;
2104
+ maxRedemptions?: number;
2105
+ timesRedeemed: number;
2106
+ expiresAt?: string;
2107
+ validPlanIds: string[];
2108
+ active: boolean;
2109
+ createdAt: string;
2110
+ updatedAt: string;
2111
+ }
2112
+ interface CreateCouponOptions {
2113
+ /** Coupon code (alphanumeric, will be uppercased) */
2114
+ code: string;
2115
+ /** Internal name for dashboard */
2116
+ name?: string;
2117
+ /** Type of discount */
2118
+ discountType: CouponDiscountType;
2119
+ /** Discount value (percentage 1-100, or cents for fixed_amount) */
2120
+ discountValue: number;
2121
+ /** Currency code (required for fixed_amount) */
2122
+ currency?: string;
2123
+ /** Maximum number of times this coupon can be used */
2124
+ maxRedemptions?: number;
2125
+ /** When the coupon expires (ISO date string) */
2126
+ expiresAt?: string;
2127
+ /** Restrict to specific plan IDs (empty = valid for all plans) */
2128
+ validPlanIds?: string[];
2129
+ /** Whether the coupon is active */
2130
+ active?: boolean;
2131
+ }
2132
+ interface UpdateCouponOptions {
2133
+ name?: string;
2134
+ maxRedemptions?: number;
2135
+ expiresAt?: string;
2136
+ validPlanIds?: string[];
2137
+ active?: boolean;
2138
+ }
2139
+ interface ValidateCouponResult {
2140
+ valid: boolean;
2141
+ coupon?: {
2142
+ id: string;
2143
+ code: string;
2144
+ discountType: CouponDiscountType;
2145
+ discountValue: number;
2146
+ currency?: string;
2147
+ };
2148
+ error?: string;
2149
+ }
2150
+ declare class CouponsClient {
2151
+ private http;
2152
+ private appId;
2153
+ constructor(http: HttpClient, appId: string);
2154
+ /**
2155
+ * Create a new coupon/promo code.
2156
+ *
2157
+ * @example
2158
+ * ```typescript
2159
+ * const coupon = await stackbe.coupons.create({
2160
+ * code: 'SAVE20',
2161
+ * discountType: 'percentage',
2162
+ * discountValue: 20,
2163
+ * maxRedemptions: 100,
2164
+ * expiresAt: '2026-12-31T23:59:59Z',
2165
+ * });
2166
+ * ```
2167
+ */
2168
+ create(options: CreateCouponOptions): Promise<Coupon>;
2169
+ /**
2170
+ * List all coupons for your app.
2171
+ *
2172
+ * @example
2173
+ * ```typescript
2174
+ * const coupons = await stackbe.coupons.list();
2175
+ * const activeCoupons = await stackbe.coupons.list({ active: true });
2176
+ * ```
2177
+ */
2178
+ list(options?: {
2179
+ active?: boolean;
2180
+ }): Promise<Coupon[]>;
2181
+ /**
2182
+ * Get a specific coupon by ID.
2183
+ *
2184
+ * @example
2185
+ * ```typescript
2186
+ * const coupon = await stackbe.coupons.get('coupon_abc123');
2187
+ * ```
2188
+ */
2189
+ get(couponId: string): Promise<Coupon>;
2190
+ /**
2191
+ * Validate a coupon code before checkout.
2192
+ *
2193
+ * @example
2194
+ * ```typescript
2195
+ * const result = await stackbe.coupons.validate('SAVE20', 'plan_pro');
2196
+ *
2197
+ * if (result.valid) {
2198
+ * console.log(`${result.coupon.discountValue}% off!`);
2199
+ * } else {
2200
+ * console.log(result.error); // "Coupon has expired"
2201
+ * }
2202
+ * ```
2203
+ */
2204
+ validate(code: string, planId?: string): Promise<ValidateCouponResult>;
2205
+ /**
2206
+ * Update a coupon.
2207
+ *
2208
+ * @example
2209
+ * ```typescript
2210
+ * const coupon = await stackbe.coupons.update('coupon_abc123', {
2211
+ * active: false,
2212
+ * });
2213
+ * ```
2214
+ */
2215
+ update(couponId: string, options: UpdateCouponOptions): Promise<Coupon>;
2216
+ /**
2217
+ * Delete a coupon.
2218
+ *
2219
+ * @example
2220
+ * ```typescript
2221
+ * await stackbe.coupons.delete('coupon_abc123');
2222
+ * ```
2223
+ */
2224
+ delete(couponId: string): Promise<void>;
2225
+ }
2226
+
2092
2227
  declare class StackBE {
2093
2228
  private http;
2094
2229
  private appId;
@@ -2116,6 +2251,8 @@ declare class StackBE {
2116
2251
  readonly affiliates: AffiliatesClient;
2117
2252
  /** Early access / waitlist signups */
2118
2253
  readonly earlyAccess: EarlyAccessClient;
2254
+ /** Coupon/promo code management */
2255
+ readonly coupons: CouponsClient;
2119
2256
  /**
2120
2257
  * Create a new StackBE client.
2121
2258
  *
@@ -2216,4 +2353,4 @@ declare class StackBE {
2216
2353
  }): (req: any, res: any, next: any) => Promise<any>;
2217
2354
  }
2218
2355
 
2219
- 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 CreateCheckoutOptions, 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 UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
2356
+ 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 };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  AffiliatesClient: () => AffiliatesClient,
24
24
  AuthClient: () => AuthClient,
25
25
  CheckoutClient: () => CheckoutClient,
26
+ CouponsClient: () => CouponsClient,
26
27
  CustomersClient: () => CustomersClient,
27
28
  EarlyAccessClient: () => EarlyAccessClient,
28
29
  EntitlementsClient: () => EntitlementsClient,
@@ -768,6 +769,7 @@ var CheckoutClient = class {
768
769
  successUrl: options.successUrl,
769
770
  cancelUrl: options.cancelUrl,
770
771
  organizationId: options.organizationId,
772
+ couponCode: options.couponCode,
771
773
  allowPromotionCodes: options.allowPromotionCodes,
772
774
  trialDays: options.trialDays,
773
775
  metadata: options.metadata
@@ -2039,6 +2041,102 @@ var EarlyAccessClient = class {
2039
2041
  }
2040
2042
  };
2041
2043
 
2044
+ // src/coupons.ts
2045
+ var CouponsClient = class {
2046
+ constructor(http, appId) {
2047
+ this.http = http;
2048
+ this.appId = appId;
2049
+ }
2050
+ /**
2051
+ * Create a new coupon/promo code.
2052
+ *
2053
+ * @example
2054
+ * ```typescript
2055
+ * const coupon = await stackbe.coupons.create({
2056
+ * code: 'SAVE20',
2057
+ * discountType: 'percentage',
2058
+ * discountValue: 20,
2059
+ * maxRedemptions: 100,
2060
+ * expiresAt: '2026-12-31T23:59:59Z',
2061
+ * });
2062
+ * ```
2063
+ */
2064
+ async create(options) {
2065
+ return this.http.post(`/v1/apps/${this.appId}/coupons`, options);
2066
+ }
2067
+ /**
2068
+ * List all coupons for your app.
2069
+ *
2070
+ * @example
2071
+ * ```typescript
2072
+ * const coupons = await stackbe.coupons.list();
2073
+ * const activeCoupons = await stackbe.coupons.list({ active: true });
2074
+ * ```
2075
+ */
2076
+ async list(options) {
2077
+ const params = {};
2078
+ if (options?.active !== void 0) {
2079
+ params.active = String(options.active);
2080
+ }
2081
+ return this.http.get(`/v1/apps/${this.appId}/coupons`, params);
2082
+ }
2083
+ /**
2084
+ * Get a specific coupon by ID.
2085
+ *
2086
+ * @example
2087
+ * ```typescript
2088
+ * const coupon = await stackbe.coupons.get('coupon_abc123');
2089
+ * ```
2090
+ */
2091
+ async get(couponId) {
2092
+ return this.http.get(`/v1/apps/${this.appId}/coupons/${couponId}`);
2093
+ }
2094
+ /**
2095
+ * Validate a coupon code before checkout.
2096
+ *
2097
+ * @example
2098
+ * ```typescript
2099
+ * const result = await stackbe.coupons.validate('SAVE20', 'plan_pro');
2100
+ *
2101
+ * if (result.valid) {
2102
+ * console.log(`${result.coupon.discountValue}% off!`);
2103
+ * } else {
2104
+ * console.log(result.error); // "Coupon has expired"
2105
+ * }
2106
+ * ```
2107
+ */
2108
+ async validate(code, planId) {
2109
+ return this.http.post(`/v1/apps/${this.appId}/coupons/validate`, {
2110
+ code,
2111
+ planId
2112
+ });
2113
+ }
2114
+ /**
2115
+ * Update a coupon.
2116
+ *
2117
+ * @example
2118
+ * ```typescript
2119
+ * const coupon = await stackbe.coupons.update('coupon_abc123', {
2120
+ * active: false,
2121
+ * });
2122
+ * ```
2123
+ */
2124
+ async update(couponId, options) {
2125
+ return this.http.patch(`/v1/apps/${this.appId}/coupons/${couponId}`, options);
2126
+ }
2127
+ /**
2128
+ * Delete a coupon.
2129
+ *
2130
+ * @example
2131
+ * ```typescript
2132
+ * await stackbe.coupons.delete('coupon_abc123');
2133
+ * ```
2134
+ */
2135
+ async delete(couponId) {
2136
+ await this.http.delete(`/v1/apps/${this.appId}/coupons/${couponId}`);
2137
+ }
2138
+ };
2139
+
2042
2140
  // src/client.ts
2043
2141
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
2044
2142
  var DEFAULT_TIMEOUT = 3e4;
@@ -2104,6 +2202,7 @@ var StackBE = class {
2104
2202
  this.featureRequests = new FeatureRequestsClient(this.http, config.appId);
2105
2203
  this.affiliates = new AffiliatesClient(this.http);
2106
2204
  this.earlyAccess = new EarlyAccessClient(this.http, config.appId);
2205
+ this.coupons = new CouponsClient(this.http, config.appId);
2107
2206
  }
2108
2207
  /**
2109
2208
  * Create a middleware for Express that tracks usage automatically.
@@ -2240,6 +2339,7 @@ var StackBE = class {
2240
2339
  AffiliatesClient,
2241
2340
  AuthClient,
2242
2341
  CheckoutClient,
2342
+ CouponsClient,
2243
2343
  CustomersClient,
2244
2344
  EarlyAccessClient,
2245
2345
  EntitlementsClient,
package/dist/index.mjs CHANGED
@@ -729,6 +729,7 @@ var CheckoutClient = class {
729
729
  successUrl: options.successUrl,
730
730
  cancelUrl: options.cancelUrl,
731
731
  organizationId: options.organizationId,
732
+ couponCode: options.couponCode,
732
733
  allowPromotionCodes: options.allowPromotionCodes,
733
734
  trialDays: options.trialDays,
734
735
  metadata: options.metadata
@@ -2000,6 +2001,102 @@ var EarlyAccessClient = class {
2000
2001
  }
2001
2002
  };
2002
2003
 
2004
+ // src/coupons.ts
2005
+ var CouponsClient = class {
2006
+ constructor(http, appId) {
2007
+ this.http = http;
2008
+ this.appId = appId;
2009
+ }
2010
+ /**
2011
+ * Create a new coupon/promo code.
2012
+ *
2013
+ * @example
2014
+ * ```typescript
2015
+ * const coupon = await stackbe.coupons.create({
2016
+ * code: 'SAVE20',
2017
+ * discountType: 'percentage',
2018
+ * discountValue: 20,
2019
+ * maxRedemptions: 100,
2020
+ * expiresAt: '2026-12-31T23:59:59Z',
2021
+ * });
2022
+ * ```
2023
+ */
2024
+ async create(options) {
2025
+ return this.http.post(`/v1/apps/${this.appId}/coupons`, options);
2026
+ }
2027
+ /**
2028
+ * List all coupons for your app.
2029
+ *
2030
+ * @example
2031
+ * ```typescript
2032
+ * const coupons = await stackbe.coupons.list();
2033
+ * const activeCoupons = await stackbe.coupons.list({ active: true });
2034
+ * ```
2035
+ */
2036
+ async list(options) {
2037
+ const params = {};
2038
+ if (options?.active !== void 0) {
2039
+ params.active = String(options.active);
2040
+ }
2041
+ return this.http.get(`/v1/apps/${this.appId}/coupons`, params);
2042
+ }
2043
+ /**
2044
+ * Get a specific coupon by ID.
2045
+ *
2046
+ * @example
2047
+ * ```typescript
2048
+ * const coupon = await stackbe.coupons.get('coupon_abc123');
2049
+ * ```
2050
+ */
2051
+ async get(couponId) {
2052
+ return this.http.get(`/v1/apps/${this.appId}/coupons/${couponId}`);
2053
+ }
2054
+ /**
2055
+ * Validate a coupon code before checkout.
2056
+ *
2057
+ * @example
2058
+ * ```typescript
2059
+ * const result = await stackbe.coupons.validate('SAVE20', 'plan_pro');
2060
+ *
2061
+ * if (result.valid) {
2062
+ * console.log(`${result.coupon.discountValue}% off!`);
2063
+ * } else {
2064
+ * console.log(result.error); // "Coupon has expired"
2065
+ * }
2066
+ * ```
2067
+ */
2068
+ async validate(code, planId) {
2069
+ return this.http.post(`/v1/apps/${this.appId}/coupons/validate`, {
2070
+ code,
2071
+ planId
2072
+ });
2073
+ }
2074
+ /**
2075
+ * Update a coupon.
2076
+ *
2077
+ * @example
2078
+ * ```typescript
2079
+ * const coupon = await stackbe.coupons.update('coupon_abc123', {
2080
+ * active: false,
2081
+ * });
2082
+ * ```
2083
+ */
2084
+ async update(couponId, options) {
2085
+ return this.http.patch(`/v1/apps/${this.appId}/coupons/${couponId}`, options);
2086
+ }
2087
+ /**
2088
+ * Delete a coupon.
2089
+ *
2090
+ * @example
2091
+ * ```typescript
2092
+ * await stackbe.coupons.delete('coupon_abc123');
2093
+ * ```
2094
+ */
2095
+ async delete(couponId) {
2096
+ await this.http.delete(`/v1/apps/${this.appId}/coupons/${couponId}`);
2097
+ }
2098
+ };
2099
+
2003
2100
  // src/client.ts
2004
2101
  var DEFAULT_BASE_URL = "https://api.stackbe.io";
2005
2102
  var DEFAULT_TIMEOUT = 3e4;
@@ -2065,6 +2162,7 @@ var StackBE = class {
2065
2162
  this.featureRequests = new FeatureRequestsClient(this.http, config.appId);
2066
2163
  this.affiliates = new AffiliatesClient(this.http);
2067
2164
  this.earlyAccess = new EarlyAccessClient(this.http, config.appId);
2165
+ this.coupons = new CouponsClient(this.http, config.appId);
2068
2166
  }
2069
2167
  /**
2070
2168
  * Create a middleware for Express that tracks usage automatically.
@@ -2200,6 +2298,7 @@ export {
2200
2298
  AffiliatesClient,
2201
2299
  AuthClient,
2202
2300
  CheckoutClient,
2301
+ CouponsClient,
2203
2302
  CustomersClient,
2204
2303
  EarlyAccessClient,
2205
2304
  EntitlementsClient,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbe/sdk",
3
- "version": "0.8.6",
3
+ "version": "0.9.1",
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",