@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/dist/index.d.ts 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 };
package/dist/index.js CHANGED
@@ -49,9 +49,15 @@ var CustomerContext = class {
49
49
  * Feature access methods - delegates to FeaturesResource
50
50
  */
51
51
  this.features = {
52
- get: (code, options) => this.featuresResource.get(code, this.externalId, options),
53
- check: (code, options) => this.featuresResource.check(code, this.externalId, options),
54
- canUse: (code, options) => this.featuresResource.canUse(code, this.externalId, options),
52
+ get: (code, options) => this.featuresResource.get({ code, externalId: this.externalId }, options),
53
+ check: (code, options) => this.featuresResource.check(
54
+ { code, externalId: this.externalId },
55
+ options
56
+ ),
57
+ canUse: (code, options) => this.featuresResource.canUse(
58
+ { code, externalId: this.externalId },
59
+ options
60
+ ),
55
61
  list: (options) => this.featuresResource.list(this.externalId, options)
56
62
  };
57
63
  /**
@@ -85,7 +91,7 @@ var CustomerContext = class {
85
91
  * Subscription methods - delegates to SubscriptionsResource
86
92
  */
87
93
  this.subscription = {
88
- get: () => this.subscriptionsResource.get({ externalId: this.externalId })
94
+ get: () => this.subscriptionsResource.get(this.externalId)
89
95
  };
90
96
  /**
91
97
  * Portal methods - delegates to PortalResource
@@ -157,9 +163,9 @@ var CustomersResource = class {
157
163
  /**
158
164
  * Update a customer
159
165
  */
160
- async update(customerId, params, options) {
166
+ async update(params, options) {
161
167
  return this.httpClient.put(
162
- `/customers/${customerId}`,
168
+ `/customers/${params.customerId}`,
163
169
  {
164
170
  billingEmail: params.email,
165
171
  externalId: params.externalId,
@@ -203,11 +209,12 @@ var FeaturesResource = class {
203
209
  *
204
210
  * @example
205
211
  * ```typescript
206
- * const seats = await commet.features.get("team_members", "user_123");
212
+ * const seats = await commet.features.get({ code: "team_members", externalId: "user_123" });
207
213
  * console.log(seats.current, seats.included, seats.remaining);
208
214
  * ```
209
215
  */
210
- async get(code, externalId, options) {
216
+ async get(params, options) {
217
+ const { code, externalId } = params;
211
218
  return this.httpClient.get(
212
219
  `/features/${code}`,
213
220
  { externalId },
@@ -219,11 +226,15 @@ var FeaturesResource = class {
219
226
  *
220
227
  * @example
221
228
  * ```typescript
222
- * const { allowed } = await commet.features.check("custom_branding", "user_123");
229
+ * const { allowed } = await commet.features.check({
230
+ * code: "custom_branding",
231
+ * externalId: "user_123"
232
+ * });
223
233
  * if (!allowed) redirect("/upgrade");
224
234
  * ```
225
235
  */
226
- async check(code, externalId, options) {
236
+ async check(params, options) {
237
+ const { code, externalId } = params;
227
238
  const result = await this.httpClient.get(
228
239
  `/features/${code}`,
229
240
  { externalId },
@@ -250,7 +261,10 @@ var FeaturesResource = class {
250
261
  *
251
262
  * @example
252
263
  * ```typescript
253
- * const { allowed, willBeCharged } = await commet.features.canUse("team_members", "user_123");
264
+ * const { allowed, willBeCharged } = await commet.features.canUse({
265
+ * code: "team_members",
266
+ * externalId: "user_123"
267
+ * });
254
268
  *
255
269
  * if (!allowed) {
256
270
  * return { error: "Upgrade to add more members" };
@@ -261,7 +275,8 @@ var FeaturesResource = class {
261
275
  * }
262
276
  * ```
263
277
  */
264
- async canUse(code, externalId, options) {
278
+ async canUse(params, options) {
279
+ const { code, externalId } = params;
265
280
  return this.httpClient.get(
266
281
  `/features/${code}`,
267
282
  { externalId, action: "canUse" },
@@ -273,7 +288,7 @@ var FeaturesResource = class {
273
288
  *
274
289
  * @example
275
290
  * ```typescript
276
- * const features = await commet.features.list("user_123");
291
+ * const features = await commet.features.list({ externalId: "user_123" });
277
292
  * for (const feature of features) {
278
293
  * console.log(feature.code, feature.allowed);
279
294
  * }
@@ -413,10 +428,11 @@ var SeatsResource = class {
413
428
  * ```
414
429
  */
415
430
  async getBalance(params) {
431
+ const { customerId, externalId, seatType } = params;
416
432
  return this.httpClient.get("/seats/balance", {
417
- customerId: params.customerId,
418
- externalId: params.externalId,
419
- seatType: params.seatType
433
+ customerId,
434
+ externalId,
435
+ seatType
420
436
  });
421
437
  }
422
438
  /**
@@ -430,9 +446,10 @@ var SeatsResource = class {
430
446
  * ```
431
447
  */
432
448
  async getAllBalances(params) {
449
+ const { customerId, externalId } = params;
433
450
  return this.httpClient.get("/seats/balances", {
434
- customerId: params.customerId,
435
- externalId: params.externalId
451
+ customerId,
452
+ externalId
436
453
  });
437
454
  }
438
455
  };
@@ -463,25 +480,26 @@ var SubscriptionsResource = class {
463
480
  *
464
481
  * @example
465
482
  * ```typescript
466
- * const sub = await commet.subscriptions.get({ externalId: 'user_123' });
483
+ * const sub = await commet.subscriptions.get('user_123');
467
484
  * ```
468
485
  */
469
- async get(params) {
470
- return this.httpClient.get("/subscriptions/active", params);
486
+ async get(externalId) {
487
+ return this.httpClient.get("/subscriptions/active", { externalId });
471
488
  }
472
489
  /**
473
490
  * Change the plan of a subscription (upgrade/downgrade)
474
491
  *
475
492
  * @example
476
493
  * ```typescript
477
- * await commet.subscriptions.changePlan('sub_xxx', {
494
+ * await commet.subscriptions.changePlan({
495
+ * subscriptionId: 'sub_xxx',
478
496
  * planCode: 'enterprise' // autocomplete works after `commet pull`
479
497
  * });
480
498
  * ```
481
499
  */
482
- async changePlan(subscriptionId, params, options) {
500
+ async changePlan(params, options) {
483
501
  return this.httpClient.post(
484
- `/subscriptions/${subscriptionId}/change-plan`,
502
+ `/subscriptions/${params.subscriptionId}/change-plan`,
485
503
  params,
486
504
  options
487
505
  );
@@ -491,14 +509,15 @@ var SubscriptionsResource = class {
491
509
  *
492
510
  * @example
493
511
  * ```typescript
494
- * await commet.subscriptions.cancel('sub_xxx', {
512
+ * await commet.subscriptions.cancel({
513
+ * subscriptionId: 'sub_xxx',
495
514
  * reason: 'switched_to_competitor'
496
515
  * });
497
516
  * ```
498
517
  */
499
- async cancel(subscriptionId, params, options) {
518
+ async cancel(params, options) {
500
519
  return this.httpClient.post(
501
- `/subscriptions/${subscriptionId}/cancel`,
520
+ `/subscriptions/${params.subscriptionId}/cancel`,
502
521
  params || {},
503
522
  options
504
523
  );
@@ -602,12 +621,13 @@ var Webhooks = class {
602
621
  * }
603
622
  * ```
604
623
  */
605
- verify(payload, signature, secret) {
624
+ verify(params) {
625
+ const { payload, signature, secret } = params;
606
626
  if (!signature || !secret || !payload) {
607
627
  return false;
608
628
  }
609
629
  try {
610
- const expectedSignature = this.generateSignature(payload, secret);
630
+ const expectedSignature = this.generateSignature({ payload, secret });
611
631
  return import_node_crypto.default.timingSafeEqual(
612
632
  Buffer.from(signature, "hex"),
613
633
  Buffer.from(expectedSignature, "hex")
@@ -620,24 +640,20 @@ var Webhooks = class {
620
640
  * Generate HMAC-SHA256 signature (internal use)
621
641
  * @internal
622
642
  */
623
- generateSignature(payload, secret) {
643
+ generateSignature(params) {
644
+ const { payload, secret } = params;
624
645
  return import_node_crypto.default.createHmac("sha256", secret).update(payload).digest("hex");
625
646
  }
626
647
  /**
627
648
  * Parse and verify webhook payload in one step
628
649
  *
629
- * @param rawBody - Raw request body as string
630
- * @param signature - Value from X-Commet-Signature header
631
- * @param secret - Your webhook secret from Commet dashboard
632
- * @returns Parsed payload if valid, null if invalid
633
- *
634
650
  * @example
635
651
  * ```typescript
636
- * const payload = commet.webhooks.verifyAndParse(
652
+ * const payload = commet.webhooks.verifyAndParse({
637
653
  * rawBody,
638
654
  * signature,
639
- * process.env.COMMET_WEBHOOK_SECRET
640
- * );
655
+ * secret: process.env.COMMET_WEBHOOK_SECRET
656
+ * });
641
657
  *
642
658
  * if (!payload) {
643
659
  * return new Response('Invalid signature', { status: 401 });
@@ -649,12 +665,13 @@ var Webhooks = class {
649
665
  * }
650
666
  * ```
651
667
  */
652
- verifyAndParse(rawBody, signature, secret) {
653
- if (!this.verify(rawBody, signature, secret)) {
668
+ verifyAndParse(params) {
669
+ const { rawBody, signature, secret } = params;
670
+ if (!this.verify({ payload: rawBody, signature, secret })) {
654
671
  return null;
655
672
  }
656
673
  try {
657
- return JSON.parse(rawBody);
674
+ return JSON.parse(params.rawBody);
658
675
  } catch {
659
676
  return null;
660
677
  }