@commet/node 4.3.0 → 4.4.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 CHANGED
@@ -1,4 +1,69 @@
1
- type CommetConfig = {
1
+ type FeatureDef = {
2
+ name: string;
3
+ type: "boolean";
4
+ description?: string;
5
+ } | {
6
+ name: string;
7
+ type: "usage";
8
+ unitName?: string;
9
+ description?: string;
10
+ } | {
11
+ name: string;
12
+ type: "seats";
13
+ unitName?: string;
14
+ description?: string;
15
+ };
16
+ interface PriceDef {
17
+ interval: "weekly" | "monthly" | "quarterly" | "yearly" | "one_time";
18
+ /** Rate scale: 10000 = $1.00 */
19
+ amount: number;
20
+ trialDays?: number;
21
+ }
22
+ type PlanFeatureValue = boolean | {
23
+ included?: number;
24
+ unlimited?: boolean;
25
+ overage?: {
26
+ unitPrice: number;
27
+ };
28
+ };
29
+ interface PlanDef {
30
+ name: string;
31
+ description?: string;
32
+ consumptionModel?: "metered" | "credits" | "balance";
33
+ defaultInterval?: PriceDef["interval"];
34
+ isFree?: boolean;
35
+ isPublic?: boolean;
36
+ sortOrder?: number;
37
+ prices: PriceDef[];
38
+ features?: Record<string, PlanFeatureValue>;
39
+ }
40
+ interface BillingConfig {
41
+ features: Record<string, FeatureDef>;
42
+ plans: Record<string, PlanDef>;
43
+ }
44
+ declare function defineConfig<const T extends BillingConfig>(config: T): T;
45
+ type InferFeatureCodes<T> = T extends {
46
+ features: infer F;
47
+ } ? keyof F & string : never;
48
+ type InferPlanCodes<T> = T extends {
49
+ plans: infer P;
50
+ } ? keyof P & string : never;
51
+ type InferSeatCodes<T> = T extends {
52
+ features: infer F;
53
+ } ? {
54
+ [K in keyof F]: F[K] extends {
55
+ type: "seats";
56
+ } ? K & string : never;
57
+ }[keyof F] : never;
58
+ type InferUsageCodes<T> = T extends {
59
+ features: infer F;
60
+ } ? {
61
+ [K in keyof F]: F[K] extends {
62
+ type: "usage";
63
+ } ? K & string : never;
64
+ }[keyof F] : never;
65
+
66
+ type CommetClientOptions = {
2
67
  apiKey: string;
3
68
  apiVersion?: string;
4
69
  debug?: boolean;
@@ -6,6 +71,8 @@ type CommetConfig = {
6
71
  retries?: number;
7
72
  telemetry?: boolean;
8
73
  };
74
+ /** @deprecated Use CommetClientOptions */
75
+ type CommetConfig = CommetClientOptions;
9
76
  interface ApiResponse<T = unknown> {
10
77
  success: boolean;
11
78
  data?: T;
@@ -55,38 +122,26 @@ interface RequestOptions {
55
122
  idempotencyKey?: string;
56
123
  timeout?: number;
57
124
  }
58
- /**
59
- * Generated types interface - augmented by CLI after 'commet pull'
60
- *
61
- * This interface gets filled by module augmentation when you run `commet pull`.
62
- * The CLI generates a .commet/types.d.ts file that augments this interface with your
63
- * organization's specific feature codes, seat types, and plan codes.
64
- *
65
- * @example
66
- * // After running `commet pull`, TypeScript will automatically know your types:
67
- * await commet.usage.track({
68
- * feature: 'api_calls', // Autocomplete works!
69
- * externalId: 'user_123'
70
- * });
71
- */
72
- interface CommetGeneratedTypes {
73
- }
74
- type GeneratedSeatType = CommetGeneratedTypes extends {
75
- seatType: infer T;
76
- } ? T : string;
77
- type GeneratedPlanCode = CommetGeneratedTypes extends {
78
- planCode: infer T;
79
- } ? T : string;
80
- type GeneratedFeatureCode = CommetGeneratedTypes extends {
81
- featureCode: infer T;
82
- } ? T : string;
125
+
126
+ type ResolvedFeatureCode<TConfig> = [
127
+ InferFeatureCodes<TConfig>
128
+ ] extends [never] ? string : InferFeatureCodes<TConfig>;
129
+ type ResolvedSeatCode<TConfig> = [InferSeatCodes<TConfig>] extends [
130
+ never
131
+ ] ? string : InferSeatCodes<TConfig>;
132
+ type ResolvedUsageCode<TConfig> = [InferUsageCodes<TConfig>] extends [
133
+ never
134
+ ] ? string : InferUsageCodes<TConfig>;
135
+ type ResolvedPlanCode<TConfig> = [InferPlanCodes<TConfig>] extends [
136
+ never
137
+ ] ? string : InferPlanCodes<TConfig>;
83
138
 
84
139
  declare class CommetHTTPClient {
85
140
  private config;
86
141
  private retryConfig;
87
142
  private telemetryEnabled;
88
143
  private lastRequestMetrics;
89
- constructor(config: CommetConfig);
144
+ constructor(config: CommetClientOptions);
90
145
  get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
91
146
  post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
92
147
  put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
@@ -113,7 +168,7 @@ declare class CommetHTTPClient {
113
168
 
114
169
  interface FeatureParams {
115
170
  customerId: CustomerID;
116
- code: GeneratedFeatureCode;
171
+ code: string;
117
172
  }
118
173
  type GetFeatureParams = FeatureParams;
119
174
  type CheckFeatureParams = FeatureParams;
@@ -189,23 +244,23 @@ interface SeatBalance {
189
244
  }
190
245
  interface AddParams {
191
246
  customerId: CustomerID;
192
- featureCode?: GeneratedFeatureCode;
247
+ featureCode?: string;
193
248
  /** @deprecated Use featureCode instead */
194
- seatType?: GeneratedSeatType;
249
+ seatType?: string;
195
250
  count: number;
196
251
  }
197
252
  interface RemoveParams {
198
253
  customerId: CustomerID;
199
- featureCode?: GeneratedFeatureCode;
254
+ featureCode?: string;
200
255
  /** @deprecated Use featureCode instead */
201
- seatType?: GeneratedSeatType;
256
+ seatType?: string;
202
257
  count: number;
203
258
  }
204
259
  interface SetParams {
205
260
  customerId: CustomerID;
206
- featureCode?: GeneratedFeatureCode;
261
+ featureCode?: string;
207
262
  /** @deprecated Use featureCode instead */
208
- seatType?: GeneratedSeatType;
263
+ seatType?: string;
209
264
  count: number;
210
265
  }
211
266
  interface SetAllParams {
@@ -214,9 +269,9 @@ interface SetAllParams {
214
269
  }
215
270
  interface GetBalanceParams {
216
271
  customerId: CustomerID;
217
- featureCode?: GeneratedFeatureCode;
272
+ featureCode?: string;
218
273
  /** @deprecated Use featureCode instead */
219
- seatType?: GeneratedSeatType;
274
+ seatType?: string;
220
275
  }
221
276
  interface GetAllBalancesParams {
222
277
  customerId: CustomerID;
@@ -329,7 +384,7 @@ declare class PlansResource {
329
384
  * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]
330
385
  * ```
331
386
  */
332
- get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>>;
387
+ get(planCode: string): Promise<ApiResponse<PlanDetail>>;
333
388
  }
334
389
 
335
390
  type SubscriptionStatus = "draft" | "pending_payment" | "trialing" | "active" | "paused" | "past_due" | "canceled" | "expired";
@@ -440,7 +495,7 @@ interface Subscription {
440
495
  updatedAt: string;
441
496
  }
442
497
  type PlanIdentifier = {
443
- planCode: GeneratedPlanCode;
498
+ planCode: string;
444
499
  planId?: never;
445
500
  } | {
446
501
  planCode?: never;
@@ -524,7 +579,7 @@ interface UsageEventProperty {
524
579
  createdAt: string;
525
580
  }
526
581
  interface TrackBaseParams {
527
- feature: GeneratedFeatureCode;
582
+ feature: string;
528
583
  customerId: CustomerID;
529
584
  idempotencyKey?: string;
530
585
  timestamp?: string;
@@ -549,23 +604,7 @@ declare class UsageResource {
549
604
  track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
550
605
  }
551
606
 
552
- /**
553
- * Customer-scoped API context
554
- *
555
- * Provides a cleaner API where you don't have to pass customerId
556
- * on every call. All operations are scoped to a specific customer.
557
- *
558
- * @example
559
- * ```typescript
560
- * const customer = commet.customer("user_123");
561
- *
562
- * // All operations are now scoped to this customer
563
- * const seats = await customer.features.get("team_members");
564
- * await customer.seats.add("editor_seats");
565
- * await customer.usage.track("api_call");
566
- * ```
567
- */
568
- declare class CustomerContext {
607
+ declare class CustomerContext<TConfig = unknown> {
569
608
  private readonly customerId;
570
609
  private readonly featuresResource;
571
610
  private readonly seatsResource;
@@ -580,19 +619,19 @@ declare class CustomerContext {
580
619
  portal: PortalResource;
581
620
  });
582
621
  features: {
583
- get: (code: string, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
584
- check: (code: string, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
585
- canUse: (code: string, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
622
+ get: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
623
+ check: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
624
+ canUse: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
586
625
  list: (options?: RequestOptions) => Promise<ApiResponse<FeatureAccess[]>>;
587
626
  };
588
627
  seats: {
589
- add: (featureCode: string, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
590
- remove: (featureCode: string, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
591
- set: (featureCode: string, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
592
- getBalance: (featureCode: string) => Promise<ApiResponse<SeatBalance>>;
628
+ add: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
629
+ remove: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
630
+ set: (featureCode: ResolvedSeatCode<TConfig>, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
631
+ getBalance: (featureCode: ResolvedSeatCode<TConfig>) => Promise<ApiResponse<SeatBalance>>;
593
632
  };
594
633
  usage: {
595
- track: (feature: string, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
634
+ track: (feature: ResolvedUsageCode<TConfig>, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
596
635
  };
597
636
  subscription: {
598
637
  get: () => Promise<ApiResponse<ActiveSubscription | null>>;
@@ -833,7 +872,7 @@ declare class Webhooks {
833
872
  /**
834
873
  * Main Commet SDK client
835
874
  */
836
- declare class Commet {
875
+ declare class Commet<TConfig = unknown> {
837
876
  private httpClient;
838
877
  readonly customers: CustomersResource;
839
878
  readonly creditPacks: CreditPacksResource;
@@ -844,7 +883,7 @@ declare class Commet {
844
883
  readonly portal: PortalResource;
845
884
  readonly features: FeaturesResource;
846
885
  readonly webhooks: Webhooks;
847
- constructor(config: CommetConfig);
886
+ constructor(config: CommetClientOptions);
848
887
  /**
849
888
  * Create a customer-scoped context for cleaner API usage
850
889
  *
@@ -858,8 +897,9 @@ declare class Commet {
858
897
  * await customer.usage.track("api_call");
859
898
  * ```
860
899
  */
861
- customer(customerId: string): CustomerContext;
900
+ customer(customerId: string): CustomerContext<TConfig>;
862
901
  }
902
+ declare function createCommet<const TConfig extends BillingConfig>(_billingConfig: TConfig, options: CommetClientOptions): Commet<TConfig>;
863
903
 
864
904
  declare function registerIntegration(name: string, version: string): void;
865
905
 
@@ -870,4 +910,4 @@ declare const SDK_VERSION: string;
870
910
  * Commet SDK - Billing and usage tracking for SaaS
871
911
  */
872
912
 
873
- export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, 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 FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, 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, Commet as default, registerIntegration };
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 };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,69 @@
1
- type CommetConfig = {
1
+ type FeatureDef = {
2
+ name: string;
3
+ type: "boolean";
4
+ description?: string;
5
+ } | {
6
+ name: string;
7
+ type: "usage";
8
+ unitName?: string;
9
+ description?: string;
10
+ } | {
11
+ name: string;
12
+ type: "seats";
13
+ unitName?: string;
14
+ description?: string;
15
+ };
16
+ interface PriceDef {
17
+ interval: "weekly" | "monthly" | "quarterly" | "yearly" | "one_time";
18
+ /** Rate scale: 10000 = $1.00 */
19
+ amount: number;
20
+ trialDays?: number;
21
+ }
22
+ type PlanFeatureValue = boolean | {
23
+ included?: number;
24
+ unlimited?: boolean;
25
+ overage?: {
26
+ unitPrice: number;
27
+ };
28
+ };
29
+ interface PlanDef {
30
+ name: string;
31
+ description?: string;
32
+ consumptionModel?: "metered" | "credits" | "balance";
33
+ defaultInterval?: PriceDef["interval"];
34
+ isFree?: boolean;
35
+ isPublic?: boolean;
36
+ sortOrder?: number;
37
+ prices: PriceDef[];
38
+ features?: Record<string, PlanFeatureValue>;
39
+ }
40
+ interface BillingConfig {
41
+ features: Record<string, FeatureDef>;
42
+ plans: Record<string, PlanDef>;
43
+ }
44
+ declare function defineConfig<const T extends BillingConfig>(config: T): T;
45
+ type InferFeatureCodes<T> = T extends {
46
+ features: infer F;
47
+ } ? keyof F & string : never;
48
+ type InferPlanCodes<T> = T extends {
49
+ plans: infer P;
50
+ } ? keyof P & string : never;
51
+ type InferSeatCodes<T> = T extends {
52
+ features: infer F;
53
+ } ? {
54
+ [K in keyof F]: F[K] extends {
55
+ type: "seats";
56
+ } ? K & string : never;
57
+ }[keyof F] : never;
58
+ type InferUsageCodes<T> = T extends {
59
+ features: infer F;
60
+ } ? {
61
+ [K in keyof F]: F[K] extends {
62
+ type: "usage";
63
+ } ? K & string : never;
64
+ }[keyof F] : never;
65
+
66
+ type CommetClientOptions = {
2
67
  apiKey: string;
3
68
  apiVersion?: string;
4
69
  debug?: boolean;
@@ -6,6 +71,8 @@ type CommetConfig = {
6
71
  retries?: number;
7
72
  telemetry?: boolean;
8
73
  };
74
+ /** @deprecated Use CommetClientOptions */
75
+ type CommetConfig = CommetClientOptions;
9
76
  interface ApiResponse<T = unknown> {
10
77
  success: boolean;
11
78
  data?: T;
@@ -55,38 +122,26 @@ interface RequestOptions {
55
122
  idempotencyKey?: string;
56
123
  timeout?: number;
57
124
  }
58
- /**
59
- * Generated types interface - augmented by CLI after 'commet pull'
60
- *
61
- * This interface gets filled by module augmentation when you run `commet pull`.
62
- * The CLI generates a .commet/types.d.ts file that augments this interface with your
63
- * organization's specific feature codes, seat types, and plan codes.
64
- *
65
- * @example
66
- * // After running `commet pull`, TypeScript will automatically know your types:
67
- * await commet.usage.track({
68
- * feature: 'api_calls', // Autocomplete works!
69
- * externalId: 'user_123'
70
- * });
71
- */
72
- interface CommetGeneratedTypes {
73
- }
74
- type GeneratedSeatType = CommetGeneratedTypes extends {
75
- seatType: infer T;
76
- } ? T : string;
77
- type GeneratedPlanCode = CommetGeneratedTypes extends {
78
- planCode: infer T;
79
- } ? T : string;
80
- type GeneratedFeatureCode = CommetGeneratedTypes extends {
81
- featureCode: infer T;
82
- } ? T : string;
125
+
126
+ type ResolvedFeatureCode<TConfig> = [
127
+ InferFeatureCodes<TConfig>
128
+ ] extends [never] ? string : InferFeatureCodes<TConfig>;
129
+ type ResolvedSeatCode<TConfig> = [InferSeatCodes<TConfig>] extends [
130
+ never
131
+ ] ? string : InferSeatCodes<TConfig>;
132
+ type ResolvedUsageCode<TConfig> = [InferUsageCodes<TConfig>] extends [
133
+ never
134
+ ] ? string : InferUsageCodes<TConfig>;
135
+ type ResolvedPlanCode<TConfig> = [InferPlanCodes<TConfig>] extends [
136
+ never
137
+ ] ? string : InferPlanCodes<TConfig>;
83
138
 
84
139
  declare class CommetHTTPClient {
85
140
  private config;
86
141
  private retryConfig;
87
142
  private telemetryEnabled;
88
143
  private lastRequestMetrics;
89
- constructor(config: CommetConfig);
144
+ constructor(config: CommetClientOptions);
90
145
  get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
91
146
  post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
92
147
  put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
@@ -113,7 +168,7 @@ declare class CommetHTTPClient {
113
168
 
114
169
  interface FeatureParams {
115
170
  customerId: CustomerID;
116
- code: GeneratedFeatureCode;
171
+ code: string;
117
172
  }
118
173
  type GetFeatureParams = FeatureParams;
119
174
  type CheckFeatureParams = FeatureParams;
@@ -189,23 +244,23 @@ interface SeatBalance {
189
244
  }
190
245
  interface AddParams {
191
246
  customerId: CustomerID;
192
- featureCode?: GeneratedFeatureCode;
247
+ featureCode?: string;
193
248
  /** @deprecated Use featureCode instead */
194
- seatType?: GeneratedSeatType;
249
+ seatType?: string;
195
250
  count: number;
196
251
  }
197
252
  interface RemoveParams {
198
253
  customerId: CustomerID;
199
- featureCode?: GeneratedFeatureCode;
254
+ featureCode?: string;
200
255
  /** @deprecated Use featureCode instead */
201
- seatType?: GeneratedSeatType;
256
+ seatType?: string;
202
257
  count: number;
203
258
  }
204
259
  interface SetParams {
205
260
  customerId: CustomerID;
206
- featureCode?: GeneratedFeatureCode;
261
+ featureCode?: string;
207
262
  /** @deprecated Use featureCode instead */
208
- seatType?: GeneratedSeatType;
263
+ seatType?: string;
209
264
  count: number;
210
265
  }
211
266
  interface SetAllParams {
@@ -214,9 +269,9 @@ interface SetAllParams {
214
269
  }
215
270
  interface GetBalanceParams {
216
271
  customerId: CustomerID;
217
- featureCode?: GeneratedFeatureCode;
272
+ featureCode?: string;
218
273
  /** @deprecated Use featureCode instead */
219
- seatType?: GeneratedSeatType;
274
+ seatType?: string;
220
275
  }
221
276
  interface GetAllBalancesParams {
222
277
  customerId: CustomerID;
@@ -329,7 +384,7 @@ declare class PlansResource {
329
384
  * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]
330
385
  * ```
331
386
  */
332
- get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>>;
387
+ get(planCode: string): Promise<ApiResponse<PlanDetail>>;
333
388
  }
334
389
 
335
390
  type SubscriptionStatus = "draft" | "pending_payment" | "trialing" | "active" | "paused" | "past_due" | "canceled" | "expired";
@@ -440,7 +495,7 @@ interface Subscription {
440
495
  updatedAt: string;
441
496
  }
442
497
  type PlanIdentifier = {
443
- planCode: GeneratedPlanCode;
498
+ planCode: string;
444
499
  planId?: never;
445
500
  } | {
446
501
  planCode?: never;
@@ -524,7 +579,7 @@ interface UsageEventProperty {
524
579
  createdAt: string;
525
580
  }
526
581
  interface TrackBaseParams {
527
- feature: GeneratedFeatureCode;
582
+ feature: string;
528
583
  customerId: CustomerID;
529
584
  idempotencyKey?: string;
530
585
  timestamp?: string;
@@ -549,23 +604,7 @@ declare class UsageResource {
549
604
  track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
550
605
  }
551
606
 
552
- /**
553
- * Customer-scoped API context
554
- *
555
- * Provides a cleaner API where you don't have to pass customerId
556
- * on every call. All operations are scoped to a specific customer.
557
- *
558
- * @example
559
- * ```typescript
560
- * const customer = commet.customer("user_123");
561
- *
562
- * // All operations are now scoped to this customer
563
- * const seats = await customer.features.get("team_members");
564
- * await customer.seats.add("editor_seats");
565
- * await customer.usage.track("api_call");
566
- * ```
567
- */
568
- declare class CustomerContext {
607
+ declare class CustomerContext<TConfig = unknown> {
569
608
  private readonly customerId;
570
609
  private readonly featuresResource;
571
610
  private readonly seatsResource;
@@ -580,19 +619,19 @@ declare class CustomerContext {
580
619
  portal: PortalResource;
581
620
  });
582
621
  features: {
583
- get: (code: string, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
584
- check: (code: string, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
585
- canUse: (code: string, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
622
+ get: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
623
+ check: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
624
+ canUse: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
586
625
  list: (options?: RequestOptions) => Promise<ApiResponse<FeatureAccess[]>>;
587
626
  };
588
627
  seats: {
589
- add: (featureCode: string, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
590
- remove: (featureCode: string, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
591
- set: (featureCode: string, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
592
- getBalance: (featureCode: string) => Promise<ApiResponse<SeatBalance>>;
628
+ add: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
629
+ remove: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
630
+ set: (featureCode: ResolvedSeatCode<TConfig>, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
631
+ getBalance: (featureCode: ResolvedSeatCode<TConfig>) => Promise<ApiResponse<SeatBalance>>;
593
632
  };
594
633
  usage: {
595
- track: (feature: string, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
634
+ track: (feature: ResolvedUsageCode<TConfig>, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
596
635
  };
597
636
  subscription: {
598
637
  get: () => Promise<ApiResponse<ActiveSubscription | null>>;
@@ -833,7 +872,7 @@ declare class Webhooks {
833
872
  /**
834
873
  * Main Commet SDK client
835
874
  */
836
- declare class Commet {
875
+ declare class Commet<TConfig = unknown> {
837
876
  private httpClient;
838
877
  readonly customers: CustomersResource;
839
878
  readonly creditPacks: CreditPacksResource;
@@ -844,7 +883,7 @@ declare class Commet {
844
883
  readonly portal: PortalResource;
845
884
  readonly features: FeaturesResource;
846
885
  readonly webhooks: Webhooks;
847
- constructor(config: CommetConfig);
886
+ constructor(config: CommetClientOptions);
848
887
  /**
849
888
  * Create a customer-scoped context for cleaner API usage
850
889
  *
@@ -858,8 +897,9 @@ declare class Commet {
858
897
  * await customer.usage.track("api_call");
859
898
  * ```
860
899
  */
861
- customer(customerId: string): CustomerContext;
900
+ customer(customerId: string): CustomerContext<TConfig>;
862
901
  }
902
+ declare function createCommet<const TConfig extends BillingConfig>(_billingConfig: TConfig, options: CommetClientOptions): Commet<TConfig>;
863
903
 
864
904
  declare function registerIntegration(name: string, version: string): void;
865
905
 
@@ -870,4 +910,4 @@ declare const SDK_VERSION: string;
870
910
  * Commet SDK - Billing and usage tracking for SaaS
871
911
  */
872
912
 
873
- export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, 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 FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, 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, Commet as default, registerIntegration };
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 };
package/dist/index.js CHANGED
@@ -38,7 +38,9 @@ __export(index_exports, {
38
38
  CustomerContext: () => CustomerContext,
39
39
  SDK_VERSION: () => SDK_VERSION,
40
40
  Webhooks: () => Webhooks,
41
+ createCommet: () => createCommet,
41
42
  default: () => index_default,
43
+ defineConfig: () => defineConfig,
42
44
  registerIntegration: () => registerIntegration
43
45
  });
44
46
  module.exports = __toCommonJS(index_exports);
@@ -542,7 +544,7 @@ var CommetValidationError = class extends CommetError {
542
544
 
543
545
  // src/version.ts
544
546
  var API_VERSION = "2026-05-18";
545
- var SDK_VERSION = "4.3.0";
547
+ var SDK_VERSION = "4.4.0";
546
548
 
547
549
  // src/utils/telemetry.ts
548
550
  var registeredIntegrations = /* @__PURE__ */ new Set();
@@ -868,6 +870,14 @@ var Commet = class {
868
870
  });
869
871
  }
870
872
  };
873
+ function createCommet(_billingConfig, options) {
874
+ return new Commet(options);
875
+ }
876
+
877
+ // src/types/config.ts
878
+ function defineConfig(config) {
879
+ return config;
880
+ }
871
881
 
872
882
  // src/index.ts
873
883
  var index_default = Commet;
@@ -881,6 +891,8 @@ var index_default = Commet;
881
891
  CustomerContext,
882
892
  SDK_VERSION,
883
893
  Webhooks,
894
+ createCommet,
895
+ defineConfig,
884
896
  registerIntegration
885
897
  });
886
898
  //# sourceMappingURL=index.js.map