@stackbe/sdk 0.8.2 → 0.8.3
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 +26 -11
- package/dist/index.d.ts +26 -11
- package/dist/index.js +23 -5
- package/dist/index.mjs +23 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -372,14 +372,19 @@ interface CheckoutSessionResponse {
|
|
|
372
372
|
/** Expiration time */
|
|
373
373
|
expiresAt: string;
|
|
374
374
|
}
|
|
375
|
+
interface SubscriptionPlan {
|
|
376
|
+
id: string;
|
|
377
|
+
name: string;
|
|
378
|
+
priceCents: number;
|
|
379
|
+
currency: string;
|
|
380
|
+
interval: 'month' | 'year';
|
|
381
|
+
}
|
|
375
382
|
interface SubscriptionWithPlan extends Subscription {
|
|
376
|
-
plan:
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
currency: string;
|
|
382
|
-
};
|
|
383
|
+
plan: SubscriptionPlan;
|
|
384
|
+
}
|
|
385
|
+
interface GetSubscriptionOptions {
|
|
386
|
+
/** Related objects to expand inline. Supported: plan */
|
|
387
|
+
expand?: ('plan')[];
|
|
383
388
|
}
|
|
384
389
|
interface CancelSubscriptionOptions {
|
|
385
390
|
/** Cancel immediately or at end of billing period */
|
|
@@ -899,24 +904,34 @@ declare class SubscriptionsClient {
|
|
|
899
904
|
* const subscription = await stackbe.subscriptions.get('cust_123');
|
|
900
905
|
*
|
|
901
906
|
* if (subscription) {
|
|
902
|
-
* console.log(`Plan: ${subscription.plan.name}`);
|
|
903
907
|
* console.log(`Status: ${subscription.status}`);
|
|
904
908
|
* console.log(`Renews: ${subscription.currentPeriodEnd}`);
|
|
905
909
|
* } else {
|
|
906
910
|
* console.log('No active subscription');
|
|
907
911
|
* }
|
|
912
|
+
*
|
|
913
|
+
* // With expanded plan details
|
|
914
|
+
* const sub = await stackbe.subscriptions.get('cust_123', { expand: ['plan'] });
|
|
915
|
+
* if (sub) {
|
|
916
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
917
|
+
* console.log(`Price: $${sub.plan.priceCents / 100}/${sub.plan.interval}`);
|
|
918
|
+
* }
|
|
908
919
|
* ```
|
|
909
920
|
*/
|
|
910
|
-
get(customerId: string): Promise<SubscriptionWithPlan | null>;
|
|
921
|
+
get(customerId: string, options?: GetSubscriptionOptions): Promise<SubscriptionWithPlan | null>;
|
|
911
922
|
/**
|
|
912
923
|
* Get a subscription by ID.
|
|
913
924
|
*
|
|
914
925
|
* @example
|
|
915
926
|
* ```typescript
|
|
916
927
|
* const subscription = await stackbe.subscriptions.getById('sub_123');
|
|
928
|
+
*
|
|
929
|
+
* // With expanded plan details
|
|
930
|
+
* const sub = await stackbe.subscriptions.getById('sub_123', { expand: ['plan'] });
|
|
931
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
917
932
|
* ```
|
|
918
933
|
*/
|
|
919
|
-
getById(subscriptionId: string): Promise<SubscriptionWithPlan>;
|
|
934
|
+
getById(subscriptionId: string, options?: GetSubscriptionOptions): Promise<SubscriptionWithPlan>;
|
|
920
935
|
/**
|
|
921
936
|
* List all subscriptions for a customer.
|
|
922
937
|
*
|
|
@@ -2058,4 +2073,4 @@ declare class StackBE {
|
|
|
2058
2073
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2059
2074
|
}
|
|
2060
2075
|
|
|
2061
|
-
export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, 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 CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestListResponse, FeatureRequestsClient, 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 SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
|
2076
|
+
export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, 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 CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, 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 UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
package/dist/index.d.ts
CHANGED
|
@@ -372,14 +372,19 @@ interface CheckoutSessionResponse {
|
|
|
372
372
|
/** Expiration time */
|
|
373
373
|
expiresAt: string;
|
|
374
374
|
}
|
|
375
|
+
interface SubscriptionPlan {
|
|
376
|
+
id: string;
|
|
377
|
+
name: string;
|
|
378
|
+
priceCents: number;
|
|
379
|
+
currency: string;
|
|
380
|
+
interval: 'month' | 'year';
|
|
381
|
+
}
|
|
375
382
|
interface SubscriptionWithPlan extends Subscription {
|
|
376
|
-
plan:
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
currency: string;
|
|
382
|
-
};
|
|
383
|
+
plan: SubscriptionPlan;
|
|
384
|
+
}
|
|
385
|
+
interface GetSubscriptionOptions {
|
|
386
|
+
/** Related objects to expand inline. Supported: plan */
|
|
387
|
+
expand?: ('plan')[];
|
|
383
388
|
}
|
|
384
389
|
interface CancelSubscriptionOptions {
|
|
385
390
|
/** Cancel immediately or at end of billing period */
|
|
@@ -899,24 +904,34 @@ declare class SubscriptionsClient {
|
|
|
899
904
|
* const subscription = await stackbe.subscriptions.get('cust_123');
|
|
900
905
|
*
|
|
901
906
|
* if (subscription) {
|
|
902
|
-
* console.log(`Plan: ${subscription.plan.name}`);
|
|
903
907
|
* console.log(`Status: ${subscription.status}`);
|
|
904
908
|
* console.log(`Renews: ${subscription.currentPeriodEnd}`);
|
|
905
909
|
* } else {
|
|
906
910
|
* console.log('No active subscription');
|
|
907
911
|
* }
|
|
912
|
+
*
|
|
913
|
+
* // With expanded plan details
|
|
914
|
+
* const sub = await stackbe.subscriptions.get('cust_123', { expand: ['plan'] });
|
|
915
|
+
* if (sub) {
|
|
916
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
917
|
+
* console.log(`Price: $${sub.plan.priceCents / 100}/${sub.plan.interval}`);
|
|
918
|
+
* }
|
|
908
919
|
* ```
|
|
909
920
|
*/
|
|
910
|
-
get(customerId: string): Promise<SubscriptionWithPlan | null>;
|
|
921
|
+
get(customerId: string, options?: GetSubscriptionOptions): Promise<SubscriptionWithPlan | null>;
|
|
911
922
|
/**
|
|
912
923
|
* Get a subscription by ID.
|
|
913
924
|
*
|
|
914
925
|
* @example
|
|
915
926
|
* ```typescript
|
|
916
927
|
* const subscription = await stackbe.subscriptions.getById('sub_123');
|
|
928
|
+
*
|
|
929
|
+
* // With expanded plan details
|
|
930
|
+
* const sub = await stackbe.subscriptions.getById('sub_123', { expand: ['plan'] });
|
|
931
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
917
932
|
* ```
|
|
918
933
|
*/
|
|
919
|
-
getById(subscriptionId: string): Promise<SubscriptionWithPlan>;
|
|
934
|
+
getById(subscriptionId: string, options?: GetSubscriptionOptions): Promise<SubscriptionWithPlan>;
|
|
920
935
|
/**
|
|
921
936
|
* List all subscriptions for a customer.
|
|
922
937
|
*
|
|
@@ -2058,4 +2073,4 @@ declare class StackBE {
|
|
|
2058
2073
|
}): (req: any, res: any, next: any) => Promise<any>;
|
|
2059
2074
|
}
|
|
2060
2075
|
|
|
2061
|
-
export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, 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 CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, type FeatureRequestListResponse, FeatureRequestsClient, 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 SubscriptionRenewedEvent, type SubscriptionUpdatedEvent, type SubscriptionWebhookPayload, type SubscriptionWithPlan, SubscriptionsClient, type TrackReferralResponse, type TrackUsageOptions, type TrackUsageResponse, type TrialEndedEvent, type TrialStartedEvent, type UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
|
2076
|
+
export { type AddMemberOptions, type AffiliateCommission, type AffiliateCommissionsResponse, type AffiliateEnrollment, type AffiliateInfo, type AffiliateStats, AffiliatesClient, type AnyWebhookEvent, AuthClient, 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 CustomerUpdatedEvent, type CustomerUsageResponse, type CustomerWebhookPayload, type CustomerWithSubscription, CustomersClient, EarlyAccessClient, type EarlyAccessSignup, type EarlyAccessSignupListResponse, type EnrollOptions, EntitlementsClient, type EntitlementsResponse, type FeatureRequest, type FeatureRequestComment, 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 UpdateCustomerOptions, type UpdateOrganizationOptions, type UpdateSubscriptionOptions, UsageClient, type UsageMetric, type VerifyTokenResponse, type WebhookEvent, type WebhookEventType };
|
package/dist/index.js
CHANGED
|
@@ -738,19 +738,29 @@ var SubscriptionsClient = class {
|
|
|
738
738
|
* const subscription = await stackbe.subscriptions.get('cust_123');
|
|
739
739
|
*
|
|
740
740
|
* if (subscription) {
|
|
741
|
-
* console.log(`Plan: ${subscription.plan.name}`);
|
|
742
741
|
* console.log(`Status: ${subscription.status}`);
|
|
743
742
|
* console.log(`Renews: ${subscription.currentPeriodEnd}`);
|
|
744
743
|
* } else {
|
|
745
744
|
* console.log('No active subscription');
|
|
746
745
|
* }
|
|
746
|
+
*
|
|
747
|
+
* // With expanded plan details
|
|
748
|
+
* const sub = await stackbe.subscriptions.get('cust_123', { expand: ['plan'] });
|
|
749
|
+
* if (sub) {
|
|
750
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
751
|
+
* console.log(`Price: $${sub.plan.priceCents / 100}/${sub.plan.interval}`);
|
|
752
|
+
* }
|
|
747
753
|
* ```
|
|
748
754
|
*/
|
|
749
|
-
async get(customerId) {
|
|
755
|
+
async get(customerId, options) {
|
|
750
756
|
try {
|
|
757
|
+
const params = { customerId };
|
|
758
|
+
if (options?.expand?.length) {
|
|
759
|
+
params.expand = options.expand.join(",");
|
|
760
|
+
}
|
|
751
761
|
return await this.http.get(
|
|
752
762
|
`/v1/subscriptions/current`,
|
|
753
|
-
|
|
763
|
+
params
|
|
754
764
|
);
|
|
755
765
|
} catch (error) {
|
|
756
766
|
if (error instanceof Error && "statusCode" in error && error.statusCode === 404) {
|
|
@@ -765,10 +775,18 @@ var SubscriptionsClient = class {
|
|
|
765
775
|
* @example
|
|
766
776
|
* ```typescript
|
|
767
777
|
* const subscription = await stackbe.subscriptions.getById('sub_123');
|
|
778
|
+
*
|
|
779
|
+
* // With expanded plan details
|
|
780
|
+
* const sub = await stackbe.subscriptions.getById('sub_123', { expand: ['plan'] });
|
|
781
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
768
782
|
* ```
|
|
769
783
|
*/
|
|
770
|
-
async getById(subscriptionId) {
|
|
771
|
-
|
|
784
|
+
async getById(subscriptionId, options) {
|
|
785
|
+
const params = {};
|
|
786
|
+
if (options?.expand?.length) {
|
|
787
|
+
params.expand = options.expand.join(",");
|
|
788
|
+
}
|
|
789
|
+
return this.http.get(`/v1/subscriptions/${subscriptionId}`, params);
|
|
772
790
|
}
|
|
773
791
|
/**
|
|
774
792
|
* List all subscriptions for a customer.
|
package/dist/index.mjs
CHANGED
|
@@ -699,19 +699,29 @@ var SubscriptionsClient = class {
|
|
|
699
699
|
* const subscription = await stackbe.subscriptions.get('cust_123');
|
|
700
700
|
*
|
|
701
701
|
* if (subscription) {
|
|
702
|
-
* console.log(`Plan: ${subscription.plan.name}`);
|
|
703
702
|
* console.log(`Status: ${subscription.status}`);
|
|
704
703
|
* console.log(`Renews: ${subscription.currentPeriodEnd}`);
|
|
705
704
|
* } else {
|
|
706
705
|
* console.log('No active subscription');
|
|
707
706
|
* }
|
|
707
|
+
*
|
|
708
|
+
* // With expanded plan details
|
|
709
|
+
* const sub = await stackbe.subscriptions.get('cust_123', { expand: ['plan'] });
|
|
710
|
+
* if (sub) {
|
|
711
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
712
|
+
* console.log(`Price: $${sub.plan.priceCents / 100}/${sub.plan.interval}`);
|
|
713
|
+
* }
|
|
708
714
|
* ```
|
|
709
715
|
*/
|
|
710
|
-
async get(customerId) {
|
|
716
|
+
async get(customerId, options) {
|
|
711
717
|
try {
|
|
718
|
+
const params = { customerId };
|
|
719
|
+
if (options?.expand?.length) {
|
|
720
|
+
params.expand = options.expand.join(",");
|
|
721
|
+
}
|
|
712
722
|
return await this.http.get(
|
|
713
723
|
`/v1/subscriptions/current`,
|
|
714
|
-
|
|
724
|
+
params
|
|
715
725
|
);
|
|
716
726
|
} catch (error) {
|
|
717
727
|
if (error instanceof Error && "statusCode" in error && error.statusCode === 404) {
|
|
@@ -726,10 +736,18 @@ var SubscriptionsClient = class {
|
|
|
726
736
|
* @example
|
|
727
737
|
* ```typescript
|
|
728
738
|
* const subscription = await stackbe.subscriptions.getById('sub_123');
|
|
739
|
+
*
|
|
740
|
+
* // With expanded plan details
|
|
741
|
+
* const sub = await stackbe.subscriptions.getById('sub_123', { expand: ['plan'] });
|
|
742
|
+
* console.log(`Plan: ${sub.plan.name}`);
|
|
729
743
|
* ```
|
|
730
744
|
*/
|
|
731
|
-
async getById(subscriptionId) {
|
|
732
|
-
|
|
745
|
+
async getById(subscriptionId, options) {
|
|
746
|
+
const params = {};
|
|
747
|
+
if (options?.expand?.length) {
|
|
748
|
+
params.expand = options.expand.join(",");
|
|
749
|
+
}
|
|
750
|
+
return this.http.get(`/v1/subscriptions/${subscriptionId}`, params);
|
|
733
751
|
}
|
|
734
752
|
/**
|
|
735
753
|
* List all subscriptions for a customer.
|
package/package.json
CHANGED