@commet/node 1.1.1 → 1.2.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/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  <p>TypeScript SDK for Commet billing platform</p>
9
9
 
10
10
  <a href="https://www.npmjs.com/package/@commet/node"><img alt="NPM version" src="https://img.shields.io/npm/v/@commet/node.svg?style=for-the-badge&labelColor=000000"></a>
11
- <a href="https://docs.commet.co/docs/library/quickstart"><img alt="Documentation" src="https://img.shields.io/badge/docs-SDK-blue.svg?style=for-the-badge&labelColor=000000"></a>
11
+ <a href="https://commet.co/docs/library/quickstart"><img alt="Documentation" src="https://img.shields.io/badge/docs-SDK-blue.svg?style=for-the-badge&labelColor=000000"></a>
12
12
  </div>
13
13
 
14
14
  <br/>
@@ -80,7 +80,7 @@ This generates type-safe autocomplete for your event types, seat types, and prod
80
80
 
81
81
  ## Documentation
82
82
 
83
- Visit [docs.commet.co/docs/library/quickstart](https://docs.commet.co/docs/library/quickstart) for:
83
+ Visit [commet.co/docs/library/quickstart](https://commet.co/docs/library/quickstart) for:
84
84
 
85
85
  - Complete API reference
86
86
  - Advanced usage examples
@@ -89,8 +89,8 @@ Visit [docs.commet.co/docs/library/quickstart](https://docs.commet.co/docs/libra
89
89
 
90
90
  ## Resources
91
91
 
92
- - [CLI Documentation](https://docs.commet.co/docs/library/cli/overview)
93
- - [SDK Reference](https://docs.commet.co/docs/library/quickstart)
92
+ - [CLI Documentation](https://commet.co/docs/library/cli/overview)
93
+ - [SDK Reference](https://commet.co/docs/library/quickstart)
94
94
  - [GitHub](https://github.com/commet-labs/commet)
95
95
  - [Issues](https://github.com/commet-labs/commet/issues)
96
96
 
package/dist/index.d.mts CHANGED
@@ -129,6 +129,13 @@ declare class CommetHTTPClient {
129
129
  private sleep;
130
130
  }
131
131
 
132
+ interface FeatureParams {
133
+ externalId: string;
134
+ code: GeneratedFeatureCode;
135
+ }
136
+ type GetFeatureParams = FeatureParams;
137
+ type CheckFeatureParams = FeatureParams;
138
+ type CanUseFeatureParams = FeatureParams;
132
139
  interface FeatureAccess {
133
140
  code: string;
134
141
  name: string;
@@ -165,21 +172,24 @@ declare class FeaturesResource {
165
172
  *
166
173
  * @example
167
174
  * ```typescript
168
- * const seats = await commet.features.get("team_members", "user_123");
175
+ * const seats = await commet.features.get({ code: "team_members", externalId: "user_123" });
169
176
  * console.log(seats.current, seats.included, seats.remaining);
170
177
  * ```
171
178
  */
172
- get(code: GeneratedFeatureCode, externalId: string, options?: RequestOptions): Promise<ApiResponse<FeatureAccess>>;
179
+ get(params: GetFeatureParams, options?: RequestOptions): Promise<ApiResponse<FeatureAccess>>;
173
180
  /**
174
181
  * Check if a boolean feature is enabled for a customer
175
182
  *
176
183
  * @example
177
184
  * ```typescript
178
- * const { allowed } = await commet.features.check("custom_branding", "user_123");
185
+ * const { allowed } = await commet.features.check({
186
+ * code: "custom_branding",
187
+ * externalId: "user_123"
188
+ * });
179
189
  * if (!allowed) redirect("/upgrade");
180
190
  * ```
181
191
  */
182
- check(code: GeneratedFeatureCode, externalId: string, options?: RequestOptions): Promise<ApiResponse<CheckResult>>;
192
+ check(params: CheckFeatureParams, options?: RequestOptions): Promise<ApiResponse<CheckResult>>;
183
193
  /**
184
194
  * Check if customer can use one more unit of a feature
185
195
  *
@@ -188,7 +198,10 @@ declare class FeaturesResource {
188
198
  *
189
199
  * @example
190
200
  * ```typescript
191
- * const { allowed, willBeCharged } = await commet.features.canUse("team_members", "user_123");
201
+ * const { allowed, willBeCharged } = await commet.features.canUse({
202
+ * code: "team_members",
203
+ * externalId: "user_123"
204
+ * });
192
205
  *
193
206
  * if (!allowed) {
194
207
  * return { error: "Upgrade to add more members" };
@@ -199,13 +212,13 @@ declare class FeaturesResource {
199
212
  * }
200
213
  * ```
201
214
  */
202
- canUse(code: GeneratedFeatureCode, externalId: string, options?: RequestOptions): Promise<ApiResponse<CanUseResult>>;
215
+ canUse(params: CanUseFeatureParams, options?: RequestOptions): Promise<ApiResponse<CanUseResult>>;
203
216
  /**
204
217
  * List all features for a customer's active subscription
205
218
  *
206
219
  * @example
207
220
  * ```typescript
208
- * const features = await commet.features.list("user_123");
221
+ * const features = await commet.features.list({ externalId: "user_123" });
209
222
  * for (const feature of features) {
210
223
  * console.log(feature.code, feature.allowed);
211
224
  * }
@@ -214,6 +227,44 @@ declare class FeaturesResource {
214
227
  list(externalId: string, options?: RequestOptions): Promise<ApiResponse<FeatureAccess[]>>;
215
228
  }
216
229
 
230
+ interface PortalAccess {
231
+ success: boolean;
232
+ message: string;
233
+ portalUrl: string;
234
+ }
235
+ interface GetUrlByCustomerId {
236
+ customerId: CustomerID;
237
+ email?: never;
238
+ externalId?: never;
239
+ }
240
+ interface GetUrlByExternalId {
241
+ externalId: string;
242
+ email?: never;
243
+ customerId?: never;
244
+ }
245
+ interface GetUrlByEmail {
246
+ email: string;
247
+ customerId?: never;
248
+ externalId?: never;
249
+ }
250
+ type GetUrlParams = GetUrlByCustomerId | GetUrlByExternalId | GetUrlByEmail;
251
+ /**
252
+ * Portal resource - Generate customer portal access
253
+ */
254
+ declare class PortalResource {
255
+ private httpClient;
256
+ constructor(httpClient: CommetHTTPClient);
257
+ /**
258
+ * Get a portal URL
259
+ *
260
+ * @example
261
+ * ```typescript
262
+ * const portal = await commet.portal.getUrl({ externalId: 'user_123' });
263
+ * ```
264
+ */
265
+ getUrl(params: GetUrlParams, options?: RequestOptions): Promise<ApiResponse<PortalAccess>>;
266
+ }
267
+
217
268
  interface SeatEvent {
218
269
  id: string;
219
270
  organizationId: string;
@@ -344,78 +395,6 @@ declare class SeatsResource {
344
395
  getAllBalances(params: GetAllBalancesParams): Promise<ApiResponse<Record<string, SeatBalance>>>;
345
396
  }
346
397
 
347
- interface UsageEvent {
348
- id: EventID;
349
- organizationId: string;
350
- customerId: CustomerID;
351
- eventType: GeneratedEventType;
352
- idempotencyKey?: string;
353
- ts: string;
354
- properties?: UsageEventProperty[];
355
- createdAt: string;
356
- }
357
- interface UsageEventProperty {
358
- id: string;
359
- usageEventId: EventID;
360
- property: string;
361
- value: string;
362
- createdAt: string;
363
- }
364
- interface BatchResult$1<T> {
365
- successful: T[];
366
- failed: Array<{
367
- index: number;
368
- error: string;
369
- data: TrackParams;
370
- }>;
371
- }
372
- interface TrackParams {
373
- eventType: GeneratedEventType;
374
- customerId?: CustomerID;
375
- externalId?: string;
376
- idempotencyKey?: string;
377
- value?: number;
378
- timestamp?: string;
379
- properties?: Record<string, string>;
380
- }
381
- /**
382
- * Usage resource - Track consumption events for usage-based billing
383
- */
384
- declare class UsageResource {
385
- private httpClient;
386
- constructor(httpClient: CommetHTTPClient);
387
- /**
388
- * Track a usage event
389
- *
390
- * @example
391
- * ```typescript
392
- * await commet.usage.track({
393
- * externalId: 'user_123',
394
- * eventType: 'api_call',
395
- * idempotencyKey: `evt_${requestId}`,
396
- * properties: { endpoint: '/users', method: 'GET' }
397
- * });
398
- * ```
399
- */
400
- track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
401
- /**
402
- * Track multiple usage events in a batch
403
- *
404
- * @example
405
- * ```typescript
406
- * await commet.usage.trackBatch({
407
- * events: [
408
- * { externalId: 'user_123', eventType: 'api_call', idempotencyKey: 'evt_1' },
409
- * { externalId: 'user_456', eventType: 'api_call', idempotencyKey: 'evt_2' }
410
- * ]
411
- * });
412
- * ```
413
- */
414
- trackBatch(params: {
415
- events: TrackParams[];
416
- }, options?: RequestOptions): Promise<ApiResponse<BatchResult$1<UsageEvent>>>;
417
- }
418
-
419
398
  type PlanID = `plan_${string}`;
420
399
  type BillingInterval = "monthly" | "quarterly" | "yearly";
421
400
  type FeatureType = "boolean" | "metered" | "seats";
@@ -579,13 +558,14 @@ type CreateSubscriptionParams = CustomerIdentifier & PlanIdentifier & {
579
558
  startDate?: string;
580
559
  };
581
560
  type ChangePlanParams = PlanIdentifier & {
561
+ subscriptionId: string;
582
562
  billingInterval?: BillingInterval;
583
563
  };
584
564
  interface CancelParams {
565
+ subscriptionId: string;
585
566
  reason?: string;
586
567
  immediate?: boolean;
587
568
  }
588
- type GetSubscriptionParams = CustomerIdentifier;
589
569
  /**
590
570
  * Subscription resource for managing subscriptions (plan-first model)
591
571
  *
@@ -613,70 +593,106 @@ declare class SubscriptionsResource {
613
593
  *
614
594
  * @example
615
595
  * ```typescript
616
- * const sub = await commet.subscriptions.get({ externalId: 'user_123' });
596
+ * const sub = await commet.subscriptions.get('user_123');
617
597
  * ```
618
598
  */
619
- get(params: GetSubscriptionParams): Promise<ApiResponse<ActiveSubscription | null>>;
599
+ get(externalId: string): Promise<ApiResponse<ActiveSubscription | null>>;
620
600
  /**
621
601
  * Change the plan of a subscription (upgrade/downgrade)
622
602
  *
623
603
  * @example
624
604
  * ```typescript
625
- * await commet.subscriptions.changePlan('sub_xxx', {
605
+ * await commet.subscriptions.changePlan({
606
+ * subscriptionId: 'sub_xxx',
626
607
  * planCode: 'enterprise' // autocomplete works after `commet pull`
627
608
  * });
628
609
  * ```
629
610
  */
630
- changePlan(subscriptionId: string, params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
611
+ changePlan(params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
631
612
  /**
632
613
  * Cancel a subscription
633
614
  *
634
615
  * @example
635
616
  * ```typescript
636
- * await commet.subscriptions.cancel('sub_xxx', {
617
+ * await commet.subscriptions.cancel({
618
+ * subscriptionId: 'sub_xxx',
637
619
  * reason: 'switched_to_competitor'
638
620
  * });
639
621
  * ```
640
622
  */
641
- cancel(subscriptionId: string, params?: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
623
+ cancel(params: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
642
624
  }
643
625
 
644
- interface PortalAccess {
645
- success: boolean;
646
- message: string;
647
- portalUrl: string;
648
- }
649
- interface GetUrlByCustomerId {
626
+ interface UsageEvent {
627
+ id: EventID;
628
+ organizationId: string;
650
629
  customerId: CustomerID;
651
- email?: never;
652
- externalId?: never;
630
+ eventType: GeneratedEventType;
631
+ idempotencyKey?: string;
632
+ ts: string;
633
+ properties?: UsageEventProperty[];
634
+ createdAt: string;
653
635
  }
654
- interface GetUrlByExternalId {
655
- externalId: string;
656
- email?: never;
657
- customerId?: never;
636
+ interface UsageEventProperty {
637
+ id: string;
638
+ usageEventId: EventID;
639
+ property: string;
640
+ value: string;
641
+ createdAt: string;
658
642
  }
659
- interface GetUrlByEmail {
660
- email: string;
661
- customerId?: never;
662
- externalId?: never;
643
+ interface BatchResult$1<T> {
644
+ successful: T[];
645
+ failed: Array<{
646
+ index: number;
647
+ error: string;
648
+ data: TrackParams;
649
+ }>;
650
+ }
651
+ interface TrackParams {
652
+ eventType: GeneratedEventType;
653
+ customerId?: CustomerID;
654
+ externalId?: string;
655
+ idempotencyKey?: string;
656
+ value?: number;
657
+ timestamp?: string;
658
+ properties?: Record<string, string>;
663
659
  }
664
- type GetUrlParams = GetUrlByCustomerId | GetUrlByExternalId | GetUrlByEmail;
665
660
  /**
666
- * Portal resource - Generate customer portal access
661
+ * Usage resource - Track consumption events for usage-based billing
667
662
  */
668
- declare class PortalResource {
663
+ declare class UsageResource {
669
664
  private httpClient;
670
665
  constructor(httpClient: CommetHTTPClient);
671
666
  /**
672
- * Get a portal URL
667
+ * Track a usage event
673
668
  *
674
669
  * @example
675
670
  * ```typescript
676
- * const portal = await commet.portal.getUrl({ externalId: 'user_123' });
671
+ * await commet.usage.track({
672
+ * externalId: 'user_123',
673
+ * eventType: 'api_call',
674
+ * idempotencyKey: `evt_${requestId}`,
675
+ * properties: { endpoint: '/users', method: 'GET' }
676
+ * });
677
677
  * ```
678
678
  */
679
- getUrl(params: GetUrlParams, options?: RequestOptions): Promise<ApiResponse<PortalAccess>>;
679
+ track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
680
+ /**
681
+ * Track multiple usage events in a batch
682
+ *
683
+ * @example
684
+ * ```typescript
685
+ * await commet.usage.trackBatch({
686
+ * events: [
687
+ * { externalId: 'user_123', eventType: 'api_call', idempotencyKey: 'evt_1' },
688
+ * { externalId: 'user_456', eventType: 'api_call', idempotencyKey: 'evt_2' }
689
+ * ]
690
+ * });
691
+ * ```
692
+ */
693
+ trackBatch(params: {
694
+ events: TrackParams[];
695
+ }, options?: RequestOptions): Promise<ApiResponse<BatchResult$1<UsageEvent>>>;
680
696
  }
681
697
 
682
698
  /**
@@ -787,6 +803,7 @@ interface CreateParams {
787
803
  address?: CustomerAddress;
788
804
  }
789
805
  interface UpdateParams {
806
+ customerId: CustomerID;
790
807
  externalId?: string;
791
808
  email?: string;
792
809
  legalName?: string;
@@ -834,7 +851,7 @@ declare class CustomersResource {
834
851
  /**
835
852
  * Update a customer
836
853
  */
837
- update(customerId: CustomerID, params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
854
+ update(params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
838
855
  /**
839
856
  * List customers with optional filters
840
857
  */
@@ -872,6 +889,16 @@ interface WebhookData {
872
889
  * Supported webhook events
873
890
  */
874
891
  type WebhookEvent = "subscription.created" | "subscription.activated" | "subscription.canceled" | "subscription.updated";
892
+ interface VerifyParams {
893
+ payload: string;
894
+ signature: string | null;
895
+ secret: string;
896
+ }
897
+ interface VerifyAndParseParams {
898
+ rawBody: string;
899
+ signature: string | null;
900
+ secret: string;
901
+ }
875
902
  /**
876
903
  * Webhooks resource for signature verification
877
904
  */
@@ -909,7 +936,7 @@ declare class Webhooks {
909
936
  * }
910
937
  * ```
911
938
  */
912
- verify(payload: string, signature: string | null, secret: string): boolean;
939
+ verify(params: VerifyParams): boolean;
913
940
  /**
914
941
  * Generate HMAC-SHA256 signature (internal use)
915
942
  * @internal
@@ -918,18 +945,13 @@ declare class Webhooks {
918
945
  /**
919
946
  * Parse and verify webhook payload in one step
920
947
  *
921
- * @param rawBody - Raw request body as string
922
- * @param signature - Value from X-Commet-Signature header
923
- * @param secret - Your webhook secret from Commet dashboard
924
- * @returns Parsed payload if valid, null if invalid
925
- *
926
948
  * @example
927
949
  * ```typescript
928
- * const payload = commet.webhooks.verifyAndParse(
950
+ * const payload = commet.webhooks.verifyAndParse({
929
951
  * rawBody,
930
952
  * signature,
931
- * process.env.COMMET_WEBHOOK_SECRET
932
- * );
953
+ * secret: process.env.COMMET_WEBHOOK_SECRET
954
+ * });
933
955
  *
934
956
  * if (!payload) {
935
957
  * return new Response('Invalid signature', { status: 401 });
@@ -941,7 +963,7 @@ declare class Webhooks {
941
963
  * }
942
964
  * ```
943
965
  */
944
- verifyAndParse(rawBody: string, signature: string | null, secret: string): WebhookPayload | null;
966
+ verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null;
945
967
  }
946
968
 
947
969
  /**
@@ -991,4 +1013,4 @@ declare function isProduction(environment: Environment): boolean;
991
1013
  * Commet SDK - Billing and usage tracking for SaaS
992
1014
  */
993
1015
 
994
- export { type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseResult, type CancelParams, type ChangePlanParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type Environment, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedEventType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetSubscriptionParams, 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, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackParams, type UpdateParams as UpdateCustomerParams, type BatchResult$1 as UsageBatchResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default, isProduction, isSandbox };
1016
+ export { type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type ChangePlanParams, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type Environment, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedEventType, 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, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackParams, type UpdateParams as UpdateCustomerParams, type BatchResult$1 as UsageBatchResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default, isProduction, isSandbox };