@commet/node 4.4.1 → 4.6.0
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 +141 -1
- package/dist/index.d.ts +141 -1
- package/dist/index.js +85 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -516,6 +516,43 @@ interface CancelParams {
|
|
|
516
516
|
reason?: string;
|
|
517
517
|
immediate?: boolean;
|
|
518
518
|
}
|
|
519
|
+
interface UncancelParams {
|
|
520
|
+
subscriptionId: string;
|
|
521
|
+
}
|
|
522
|
+
interface ChangePlanParams {
|
|
523
|
+
subscriptionId: string;
|
|
524
|
+
newPlanId?: string;
|
|
525
|
+
newBillingInterval?: BillingInterval;
|
|
526
|
+
}
|
|
527
|
+
interface ChangePlanResult {
|
|
528
|
+
id: string;
|
|
529
|
+
scheduled: boolean;
|
|
530
|
+
customerId?: string;
|
|
531
|
+
previousPlan?: {
|
|
532
|
+
id: string;
|
|
533
|
+
name: string;
|
|
534
|
+
};
|
|
535
|
+
currentPlan?: {
|
|
536
|
+
id: string;
|
|
537
|
+
name: string;
|
|
538
|
+
price: number;
|
|
539
|
+
};
|
|
540
|
+
billingInterval?: string;
|
|
541
|
+
billing?: {
|
|
542
|
+
credit: number;
|
|
543
|
+
creditsApplied: number;
|
|
544
|
+
charge: number;
|
|
545
|
+
taxAmount: number;
|
|
546
|
+
netAmount: number;
|
|
547
|
+
totalCharged: number;
|
|
548
|
+
remainingCreditBalance: number;
|
|
549
|
+
};
|
|
550
|
+
invoiceId?: string;
|
|
551
|
+
scheduledFor?: string;
|
|
552
|
+
changeType?: string;
|
|
553
|
+
requiresCheckout?: boolean;
|
|
554
|
+
checkoutUrl?: string;
|
|
555
|
+
}
|
|
519
556
|
/**
|
|
520
557
|
* Subscription resource for managing subscriptions (plan-first model)
|
|
521
558
|
*
|
|
@@ -559,6 +596,34 @@ declare class SubscriptionsResource {
|
|
|
559
596
|
* ```
|
|
560
597
|
*/
|
|
561
598
|
cancel(params: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
599
|
+
/**
|
|
600
|
+
* Revert a scheduled cancellation
|
|
601
|
+
*
|
|
602
|
+
* Only works on subscriptions with a pending cancellation (canceledAt is set
|
|
603
|
+
* but status is not yet "canceled"). Cannot revert already-canceled subscriptions.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```typescript
|
|
607
|
+
* await commet.subscriptions.uncancel({
|
|
608
|
+
* subscriptionId: 'sub_xxx',
|
|
609
|
+
* });
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
uncancel(params: UncancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
613
|
+
/**
|
|
614
|
+
* Change the plan of a subscription (upgrade/downgrade)
|
|
615
|
+
*
|
|
616
|
+
* Upgrades execute immediately. Downgrades are scheduled for end of period.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* await commet.subscriptions.changePlan({
|
|
621
|
+
* subscriptionId: 'sub_xxx',
|
|
622
|
+
* newPlanId: 'pln_xxx',
|
|
623
|
+
* });
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
changePlan(params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<ChangePlanResult>>;
|
|
562
627
|
}
|
|
563
628
|
|
|
564
629
|
interface UsageEvent {
|
|
@@ -598,10 +663,55 @@ interface TrackModelTokensParams extends TrackBaseParams {
|
|
|
598
663
|
value?: never;
|
|
599
664
|
}
|
|
600
665
|
type TrackParams = TrackUsageParams | TrackModelTokensParams;
|
|
666
|
+
interface CheckUsageParams {
|
|
667
|
+
customerId: CustomerID;
|
|
668
|
+
featureCode: string;
|
|
669
|
+
quantity: number;
|
|
670
|
+
}
|
|
671
|
+
interface UsageCheckResult {
|
|
672
|
+
allowed: boolean;
|
|
673
|
+
consumptionModel: string;
|
|
674
|
+
feature: string;
|
|
675
|
+
quantity: number;
|
|
676
|
+
current?: number;
|
|
677
|
+
remaining?: number;
|
|
678
|
+
unlimited?: boolean;
|
|
679
|
+
included?: number;
|
|
680
|
+
overageEnabled?: boolean;
|
|
681
|
+
overageUnitPrice?: number | null;
|
|
682
|
+
creditsPerUnit?: number;
|
|
683
|
+
estimatedCredits?: number;
|
|
684
|
+
planCredits?: number;
|
|
685
|
+
purchasedCredits?: number;
|
|
686
|
+
totalCredits?: number;
|
|
687
|
+
unitPrice?: number;
|
|
688
|
+
estimatedAmount?: number;
|
|
689
|
+
currentBalance?: number;
|
|
690
|
+
blockOnExhaustion?: boolean;
|
|
691
|
+
currency?: string;
|
|
692
|
+
reason?: string;
|
|
693
|
+
message?: string;
|
|
694
|
+
}
|
|
601
695
|
declare class UsageResource {
|
|
602
696
|
private httpClient;
|
|
603
697
|
constructor(httpClient: CommetHTTPClient);
|
|
604
698
|
track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
699
|
+
/**
|
|
700
|
+
* Check if a usage event would be allowed before tracking it
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* const { data } = await commet.usage.check({
|
|
705
|
+
* customerId: 'cus_xxx',
|
|
706
|
+
* featureCode: 'api_calls',
|
|
707
|
+
* quantity: 1,
|
|
708
|
+
* });
|
|
709
|
+
* if (data.allowed) {
|
|
710
|
+
* // proceed with the operation
|
|
711
|
+
* }
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
check(params: CheckUsageParams, options?: RequestOptions): Promise<ApiResponse<UsageCheckResult>>;
|
|
605
715
|
}
|
|
606
716
|
|
|
607
717
|
declare class CustomerContext<TConfig = unknown> {
|
|
@@ -641,6 +751,35 @@ declare class CustomerContext<TConfig = unknown> {
|
|
|
641
751
|
};
|
|
642
752
|
}
|
|
643
753
|
|
|
754
|
+
interface ActiveAddon {
|
|
755
|
+
slug: string;
|
|
756
|
+
name: string;
|
|
757
|
+
basePrice: number;
|
|
758
|
+
featureCode: string;
|
|
759
|
+
featureName: string;
|
|
760
|
+
featureType: string;
|
|
761
|
+
consumptionModel: string | null;
|
|
762
|
+
activatedAt: string;
|
|
763
|
+
}
|
|
764
|
+
interface GetActiveAddonsParams {
|
|
765
|
+
customerId: CustomerID;
|
|
766
|
+
}
|
|
767
|
+
declare class AddonsResource {
|
|
768
|
+
private httpClient;
|
|
769
|
+
constructor(httpClient: CommetHTTPClient);
|
|
770
|
+
/**
|
|
771
|
+
* Get active addons for a customer's subscription
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ```typescript
|
|
775
|
+
* const { data } = await commet.addons.getActive({
|
|
776
|
+
* customerId: 'cus_xxx',
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
getActive(params: GetActiveAddonsParams, options?: RequestOptions): Promise<ApiResponse<ActiveAddon[]>>;
|
|
781
|
+
}
|
|
782
|
+
|
|
644
783
|
interface CreditPack {
|
|
645
784
|
id: string;
|
|
646
785
|
name: string;
|
|
@@ -874,6 +1013,7 @@ declare class Webhooks {
|
|
|
874
1013
|
*/
|
|
875
1014
|
declare class Commet<TConfig = unknown> {
|
|
876
1015
|
private httpClient;
|
|
1016
|
+
readonly addons: AddonsResource;
|
|
877
1017
|
readonly customers: CustomersResource;
|
|
878
1018
|
readonly creditPacks: CreditPacksResource;
|
|
879
1019
|
readonly plans: PlansResource;
|
|
@@ -910,4 +1050,4 @@ declare const SDK_VERSION: string;
|
|
|
910
1050
|
* Commet SDK - Billing and usage tracking for SaaS
|
|
911
1051
|
*/
|
|
912
1052
|
|
|
913
|
-
export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetClientOptions, type CommetConfig, CommetError, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureValue, type PlanID, type PlanPrice, type PortalAccess, type PriceDef, type RemoveParams as RemoveSeatsParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
|
1053
|
+
export { API_VERSION, type ActiveAddon, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type ChangePlanParams, type ChangePlanResult, type CheckFeatureParams, type CheckResult, type CheckUsageParams, Commet, CommetAPIError, type CommetClientOptions, type CommetConfig, CommetError, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type GetActiveAddonsParams, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureValue, type PlanID, type PlanPrice, type PortalAccess, type PriceDef, type RemoveParams as RemoveSeatsParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UncancelParams, type UpdateParams as UpdateCustomerParams, type UsageCheckResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
package/dist/index.d.ts
CHANGED
|
@@ -516,6 +516,43 @@ interface CancelParams {
|
|
|
516
516
|
reason?: string;
|
|
517
517
|
immediate?: boolean;
|
|
518
518
|
}
|
|
519
|
+
interface UncancelParams {
|
|
520
|
+
subscriptionId: string;
|
|
521
|
+
}
|
|
522
|
+
interface ChangePlanParams {
|
|
523
|
+
subscriptionId: string;
|
|
524
|
+
newPlanId?: string;
|
|
525
|
+
newBillingInterval?: BillingInterval;
|
|
526
|
+
}
|
|
527
|
+
interface ChangePlanResult {
|
|
528
|
+
id: string;
|
|
529
|
+
scheduled: boolean;
|
|
530
|
+
customerId?: string;
|
|
531
|
+
previousPlan?: {
|
|
532
|
+
id: string;
|
|
533
|
+
name: string;
|
|
534
|
+
};
|
|
535
|
+
currentPlan?: {
|
|
536
|
+
id: string;
|
|
537
|
+
name: string;
|
|
538
|
+
price: number;
|
|
539
|
+
};
|
|
540
|
+
billingInterval?: string;
|
|
541
|
+
billing?: {
|
|
542
|
+
credit: number;
|
|
543
|
+
creditsApplied: number;
|
|
544
|
+
charge: number;
|
|
545
|
+
taxAmount: number;
|
|
546
|
+
netAmount: number;
|
|
547
|
+
totalCharged: number;
|
|
548
|
+
remainingCreditBalance: number;
|
|
549
|
+
};
|
|
550
|
+
invoiceId?: string;
|
|
551
|
+
scheduledFor?: string;
|
|
552
|
+
changeType?: string;
|
|
553
|
+
requiresCheckout?: boolean;
|
|
554
|
+
checkoutUrl?: string;
|
|
555
|
+
}
|
|
519
556
|
/**
|
|
520
557
|
* Subscription resource for managing subscriptions (plan-first model)
|
|
521
558
|
*
|
|
@@ -559,6 +596,34 @@ declare class SubscriptionsResource {
|
|
|
559
596
|
* ```
|
|
560
597
|
*/
|
|
561
598
|
cancel(params: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
599
|
+
/**
|
|
600
|
+
* Revert a scheduled cancellation
|
|
601
|
+
*
|
|
602
|
+
* Only works on subscriptions with a pending cancellation (canceledAt is set
|
|
603
|
+
* but status is not yet "canceled"). Cannot revert already-canceled subscriptions.
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* ```typescript
|
|
607
|
+
* await commet.subscriptions.uncancel({
|
|
608
|
+
* subscriptionId: 'sub_xxx',
|
|
609
|
+
* });
|
|
610
|
+
* ```
|
|
611
|
+
*/
|
|
612
|
+
uncancel(params: UncancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
613
|
+
/**
|
|
614
|
+
* Change the plan of a subscription (upgrade/downgrade)
|
|
615
|
+
*
|
|
616
|
+
* Upgrades execute immediately. Downgrades are scheduled for end of period.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* await commet.subscriptions.changePlan({
|
|
621
|
+
* subscriptionId: 'sub_xxx',
|
|
622
|
+
* newPlanId: 'pln_xxx',
|
|
623
|
+
* });
|
|
624
|
+
* ```
|
|
625
|
+
*/
|
|
626
|
+
changePlan(params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<ChangePlanResult>>;
|
|
562
627
|
}
|
|
563
628
|
|
|
564
629
|
interface UsageEvent {
|
|
@@ -598,10 +663,55 @@ interface TrackModelTokensParams extends TrackBaseParams {
|
|
|
598
663
|
value?: never;
|
|
599
664
|
}
|
|
600
665
|
type TrackParams = TrackUsageParams | TrackModelTokensParams;
|
|
666
|
+
interface CheckUsageParams {
|
|
667
|
+
customerId: CustomerID;
|
|
668
|
+
featureCode: string;
|
|
669
|
+
quantity: number;
|
|
670
|
+
}
|
|
671
|
+
interface UsageCheckResult {
|
|
672
|
+
allowed: boolean;
|
|
673
|
+
consumptionModel: string;
|
|
674
|
+
feature: string;
|
|
675
|
+
quantity: number;
|
|
676
|
+
current?: number;
|
|
677
|
+
remaining?: number;
|
|
678
|
+
unlimited?: boolean;
|
|
679
|
+
included?: number;
|
|
680
|
+
overageEnabled?: boolean;
|
|
681
|
+
overageUnitPrice?: number | null;
|
|
682
|
+
creditsPerUnit?: number;
|
|
683
|
+
estimatedCredits?: number;
|
|
684
|
+
planCredits?: number;
|
|
685
|
+
purchasedCredits?: number;
|
|
686
|
+
totalCredits?: number;
|
|
687
|
+
unitPrice?: number;
|
|
688
|
+
estimatedAmount?: number;
|
|
689
|
+
currentBalance?: number;
|
|
690
|
+
blockOnExhaustion?: boolean;
|
|
691
|
+
currency?: string;
|
|
692
|
+
reason?: string;
|
|
693
|
+
message?: string;
|
|
694
|
+
}
|
|
601
695
|
declare class UsageResource {
|
|
602
696
|
private httpClient;
|
|
603
697
|
constructor(httpClient: CommetHTTPClient);
|
|
604
698
|
track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
699
|
+
/**
|
|
700
|
+
* Check if a usage event would be allowed before tracking it
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```typescript
|
|
704
|
+
* const { data } = await commet.usage.check({
|
|
705
|
+
* customerId: 'cus_xxx',
|
|
706
|
+
* featureCode: 'api_calls',
|
|
707
|
+
* quantity: 1,
|
|
708
|
+
* });
|
|
709
|
+
* if (data.allowed) {
|
|
710
|
+
* // proceed with the operation
|
|
711
|
+
* }
|
|
712
|
+
* ```
|
|
713
|
+
*/
|
|
714
|
+
check(params: CheckUsageParams, options?: RequestOptions): Promise<ApiResponse<UsageCheckResult>>;
|
|
605
715
|
}
|
|
606
716
|
|
|
607
717
|
declare class CustomerContext<TConfig = unknown> {
|
|
@@ -641,6 +751,35 @@ declare class CustomerContext<TConfig = unknown> {
|
|
|
641
751
|
};
|
|
642
752
|
}
|
|
643
753
|
|
|
754
|
+
interface ActiveAddon {
|
|
755
|
+
slug: string;
|
|
756
|
+
name: string;
|
|
757
|
+
basePrice: number;
|
|
758
|
+
featureCode: string;
|
|
759
|
+
featureName: string;
|
|
760
|
+
featureType: string;
|
|
761
|
+
consumptionModel: string | null;
|
|
762
|
+
activatedAt: string;
|
|
763
|
+
}
|
|
764
|
+
interface GetActiveAddonsParams {
|
|
765
|
+
customerId: CustomerID;
|
|
766
|
+
}
|
|
767
|
+
declare class AddonsResource {
|
|
768
|
+
private httpClient;
|
|
769
|
+
constructor(httpClient: CommetHTTPClient);
|
|
770
|
+
/**
|
|
771
|
+
* Get active addons for a customer's subscription
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ```typescript
|
|
775
|
+
* const { data } = await commet.addons.getActive({
|
|
776
|
+
* customerId: 'cus_xxx',
|
|
777
|
+
* });
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
getActive(params: GetActiveAddonsParams, options?: RequestOptions): Promise<ApiResponse<ActiveAddon[]>>;
|
|
781
|
+
}
|
|
782
|
+
|
|
644
783
|
interface CreditPack {
|
|
645
784
|
id: string;
|
|
646
785
|
name: string;
|
|
@@ -874,6 +1013,7 @@ declare class Webhooks {
|
|
|
874
1013
|
*/
|
|
875
1014
|
declare class Commet<TConfig = unknown> {
|
|
876
1015
|
private httpClient;
|
|
1016
|
+
readonly addons: AddonsResource;
|
|
877
1017
|
readonly customers: CustomersResource;
|
|
878
1018
|
readonly creditPacks: CreditPacksResource;
|
|
879
1019
|
readonly plans: PlansResource;
|
|
@@ -910,4 +1050,4 @@ declare const SDK_VERSION: string;
|
|
|
910
1050
|
* Commet SDK - Billing and usage tracking for SaaS
|
|
911
1051
|
*/
|
|
912
1052
|
|
|
913
|
-
export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetClientOptions, type CommetConfig, CommetError, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureValue, type PlanID, type PlanPrice, type PortalAccess, type PriceDef, type RemoveParams as RemoveSeatsParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
|
1053
|
+
export { API_VERSION, type ActiveAddon, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type ChangePlanParams, type ChangePlanResult, type CheckFeatureParams, type CheckResult, type CheckUsageParams, Commet, CommetAPIError, type CommetClientOptions, type CommetConfig, CommetError, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type GetActiveAddonsParams, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureValue, type PlanID, type PlanPrice, type PortalAccess, type PriceDef, type RemoveParams as RemoveSeatsParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UncancelParams, type UpdateParams as UpdateCustomerParams, type UsageCheckResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
package/dist/index.js
CHANGED
|
@@ -99,6 +99,30 @@ var CustomerContext = class {
|
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
// src/resources/addons.ts
|
|
103
|
+
var AddonsResource = class {
|
|
104
|
+
constructor(httpClient) {
|
|
105
|
+
this.httpClient = httpClient;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get active addons for a customer's subscription
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const { data } = await commet.addons.getActive({
|
|
113
|
+
* customerId: 'cus_xxx',
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
async getActive(params, options) {
|
|
118
|
+
return this.httpClient.get(
|
|
119
|
+
"/addons/active",
|
|
120
|
+
{ customerId: params.customerId },
|
|
121
|
+
options
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
102
126
|
// src/resources/credit-packs.ts
|
|
103
127
|
var CreditPacksResource = class {
|
|
104
128
|
constructor(httpClient) {
|
|
@@ -387,6 +411,47 @@ var SubscriptionsResource = class {
|
|
|
387
411
|
options
|
|
388
412
|
);
|
|
389
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Revert a scheduled cancellation
|
|
416
|
+
*
|
|
417
|
+
* Only works on subscriptions with a pending cancellation (canceledAt is set
|
|
418
|
+
* but status is not yet "canceled"). Cannot revert already-canceled subscriptions.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* await commet.subscriptions.uncancel({
|
|
423
|
+
* subscriptionId: 'sub_xxx',
|
|
424
|
+
* });
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
async uncancel(params, options) {
|
|
428
|
+
return this.httpClient.post(
|
|
429
|
+
`/subscriptions/${params.subscriptionId}/uncancel`,
|
|
430
|
+
{},
|
|
431
|
+
options
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Change the plan of a subscription (upgrade/downgrade)
|
|
436
|
+
*
|
|
437
|
+
* Upgrades execute immediately. Downgrades are scheduled for end of period.
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* await commet.subscriptions.changePlan({
|
|
442
|
+
* subscriptionId: 'sub_xxx',
|
|
443
|
+
* newPlanId: 'pln_xxx',
|
|
444
|
+
* });
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
async changePlan(params, options) {
|
|
448
|
+
const { subscriptionId, ...body } = params;
|
|
449
|
+
return this.httpClient.post(
|
|
450
|
+
`/subscriptions/${subscriptionId}/change-plan`,
|
|
451
|
+
body,
|
|
452
|
+
options
|
|
453
|
+
);
|
|
454
|
+
}
|
|
390
455
|
};
|
|
391
456
|
|
|
392
457
|
// src/resources/usage.ts
|
|
@@ -420,6 +485,24 @@ var UsageResource = class {
|
|
|
420
485
|
}
|
|
421
486
|
return this.httpClient.post("/usage/events", eventData, options);
|
|
422
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Check if a usage event would be allowed before tracking it
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* ```typescript
|
|
493
|
+
* const { data } = await commet.usage.check({
|
|
494
|
+
* customerId: 'cus_xxx',
|
|
495
|
+
* featureCode: 'api_calls',
|
|
496
|
+
* quantity: 1,
|
|
497
|
+
* });
|
|
498
|
+
* if (data.allowed) {
|
|
499
|
+
* // proceed with the operation
|
|
500
|
+
* }
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
async check(params, options) {
|
|
504
|
+
return this.httpClient.post("/usage/check", params, options);
|
|
505
|
+
}
|
|
423
506
|
};
|
|
424
507
|
|
|
425
508
|
// src/resources/webhooks.ts
|
|
@@ -544,7 +627,7 @@ var CommetValidationError = class extends CommetError {
|
|
|
544
627
|
|
|
545
628
|
// src/version.ts
|
|
546
629
|
var API_VERSION = "2026-05-18";
|
|
547
|
-
var SDK_VERSION = "4.
|
|
630
|
+
var SDK_VERSION = "4.6.0";
|
|
548
631
|
|
|
549
632
|
// src/utils/telemetry.ts
|
|
550
633
|
var registeredIntegrations = /* @__PURE__ */ new Set();
|
|
@@ -833,6 +916,7 @@ var Commet = class {
|
|
|
833
916
|
);
|
|
834
917
|
}
|
|
835
918
|
this.httpClient = new CommetHTTPClient(config);
|
|
919
|
+
this.addons = new AddonsResource(this.httpClient);
|
|
836
920
|
this.customers = new CustomersResource(this.httpClient);
|
|
837
921
|
this.creditPacks = new CreditPacksResource(this.httpClient);
|
|
838
922
|
this.plans = new PlansResource(this.httpClient);
|