@commet/node 1.1.1 → 1.3.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
  /**
@@ -751,8 +767,7 @@ interface Customer {
751
767
  id: CustomerID;
752
768
  organizationId: string;
753
769
  externalId?: string;
754
- legalName?: string;
755
- displayName?: string;
770
+ fullName?: string;
756
771
  domain?: string;
757
772
  website?: string;
758
773
  billingEmail: string;
@@ -776,8 +791,7 @@ interface CustomerAddress {
776
791
  interface CreateParams {
777
792
  email: string;
778
793
  externalId?: string;
779
- legalName?: string;
780
- displayName?: string;
794
+ fullName?: string;
781
795
  domain?: string;
782
796
  website?: string;
783
797
  timezone?: string;
@@ -787,10 +801,10 @@ interface CreateParams {
787
801
  address?: CustomerAddress;
788
802
  }
789
803
  interface UpdateParams {
804
+ customerId: CustomerID;
790
805
  externalId?: string;
791
806
  email?: string;
792
- legalName?: string;
793
- displayName?: string;
807
+ fullName?: string;
794
808
  domain?: string;
795
809
  website?: string;
796
810
  timezone?: string;
@@ -834,7 +848,7 @@ declare class CustomersResource {
834
848
  /**
835
849
  * Update a customer
836
850
  */
837
- update(customerId: CustomerID, params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
851
+ update(params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
838
852
  /**
839
853
  * List customers with optional filters
840
854
  */
@@ -872,6 +886,16 @@ interface WebhookData {
872
886
  * Supported webhook events
873
887
  */
874
888
  type WebhookEvent = "subscription.created" | "subscription.activated" | "subscription.canceled" | "subscription.updated";
889
+ interface VerifyParams {
890
+ payload: string;
891
+ signature: string | null;
892
+ secret: string;
893
+ }
894
+ interface VerifyAndParseParams {
895
+ rawBody: string;
896
+ signature: string | null;
897
+ secret: string;
898
+ }
875
899
  /**
876
900
  * Webhooks resource for signature verification
877
901
  */
@@ -909,7 +933,7 @@ declare class Webhooks {
909
933
  * }
910
934
  * ```
911
935
  */
912
- verify(payload: string, signature: string | null, secret: string): boolean;
936
+ verify(params: VerifyParams): boolean;
913
937
  /**
914
938
  * Generate HMAC-SHA256 signature (internal use)
915
939
  * @internal
@@ -918,18 +942,13 @@ declare class Webhooks {
918
942
  /**
919
943
  * Parse and verify webhook payload in one step
920
944
  *
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
945
  * @example
927
946
  * ```typescript
928
- * const payload = commet.webhooks.verifyAndParse(
947
+ * const payload = commet.webhooks.verifyAndParse({
929
948
  * rawBody,
930
949
  * signature,
931
- * process.env.COMMET_WEBHOOK_SECRET
932
- * );
950
+ * secret: process.env.COMMET_WEBHOOK_SECRET
951
+ * });
933
952
  *
934
953
  * if (!payload) {
935
954
  * return new Response('Invalid signature', { status: 401 });
@@ -941,7 +960,7 @@ declare class Webhooks {
941
960
  * }
942
961
  * ```
943
962
  */
944
- verifyAndParse(rawBody: string, signature: string | null, secret: string): WebhookPayload | null;
963
+ verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null;
945
964
  }
946
965
 
947
966
  /**
@@ -991,4 +1010,4 @@ declare function isProduction(environment: Environment): boolean;
991
1010
  * Commet SDK - Billing and usage tracking for SaaS
992
1011
  */
993
1012
 
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 };
1013
+ 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 };