@commet/node 0.11.0 → 1.0.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
@@ -41,13 +41,7 @@ declare class CommetValidationError extends CommetError {
41
41
  constructor(message: string, validationErrors: Record<string, string[]>);
42
42
  }
43
43
  type CustomerID = `cus_${string}`;
44
- type AgreementID = `agr_${string}`;
45
- type InvoiceID = `inv_${string}`;
46
- type PhaseID = `phs_${string}`;
47
- type ItemID = `itm_${string}`;
48
- type ProductID = `prd_${string}`;
49
44
  type EventID = `evt_${string}`;
50
- type WebhookID = `wh_${string}`;
51
45
  type Currency = "USD" | "EUR" | "GBP" | "CAD" | "AUD" | "JPY" | "ARS" | "BRL" | "MXN" | "CLP";
52
46
  interface ListParams extends Record<string, unknown> {
53
47
  limit?: number;
@@ -55,9 +49,6 @@ interface ListParams extends Record<string, unknown> {
55
49
  startDate?: string;
56
50
  endDate?: string;
57
51
  }
58
- interface RetrieveOptions {
59
- expand?: string[];
60
- }
61
52
  interface RequestOptions {
62
53
  idempotencyKey?: string;
63
54
  timeout?: number;
@@ -93,8 +84,14 @@ type GeneratedSeatType = CommetGeneratedTypes extends {
93
84
  /**
94
85
  * Helper type that provides fallback to string if types are not generated
95
86
  */
96
- type GeneratedProductId = CommetGeneratedTypes extends {
97
- productId: infer T;
87
+ type GeneratedPlanCode = CommetGeneratedTypes extends {
88
+ planCode: infer T;
89
+ } ? T : string;
90
+ /**
91
+ * Helper type that provides fallback to string if types are not generated
92
+ */
93
+ type GeneratedFeatureCode = CommetGeneratedTypes extends {
94
+ featureCode: infer T;
98
95
  } ? T : string;
99
96
 
100
97
  declare class CommetHTTPClient {
@@ -136,15 +133,11 @@ interface Customer {
136
133
  id: CustomerID;
137
134
  organizationId: string;
138
135
  externalId?: string;
139
- legalName: string;
136
+ legalName?: string;
140
137
  displayName?: string;
141
138
  domain?: string;
142
139
  website?: string;
143
- taxStatus: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
144
- currency: Currency;
145
- addressId: string;
146
- billingEmail?: string;
147
- paymentTerms?: string;
140
+ billingEmail: string;
148
141
  timezone?: string;
149
142
  language?: string;
150
143
  industry?: string;
@@ -154,21 +147,6 @@ interface Customer {
154
147
  createdAt: string;
155
148
  updatedAt: string;
156
149
  }
157
- interface CreateCustomerBaseParams {
158
- externalId?: string;
159
- legalName: string;
160
- displayName?: string;
161
- domain?: string;
162
- website?: string;
163
- currency?: Currency;
164
- billingEmail?: string;
165
- paymentTerms?: string;
166
- timezone?: string;
167
- language?: string;
168
- industry?: string;
169
- employeeCount?: string;
170
- metadata?: Record<string, unknown>;
171
- }
172
150
  interface CustomerAddress {
173
151
  line1: string;
174
152
  line2?: string;
@@ -176,140 +154,199 @@ interface CustomerAddress {
176
154
  state?: string;
177
155
  postalCode: string;
178
156
  country: string;
179
- region?: string;
180
157
  }
181
- interface CreateCustomerTaxed extends CreateCustomerBaseParams {
182
- taxStatus: "TAXED";
183
- address: CustomerAddress;
184
- }
185
- interface CreateCustomerOtherTaxStatus extends CreateCustomerBaseParams {
186
- taxStatus?: "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
158
+ interface CreateParams {
159
+ email: string;
160
+ externalId?: string;
161
+ legalName?: string;
162
+ displayName?: string;
163
+ domain?: string;
164
+ website?: string;
165
+ timezone?: string;
166
+ language?: string;
167
+ industry?: string;
168
+ metadata?: Record<string, unknown>;
187
169
  address?: CustomerAddress;
188
170
  }
189
- type CreateCustomerParams = CreateCustomerTaxed | CreateCustomerOtherTaxStatus;
190
- interface UpdateCustomerParams {
171
+ interface UpdateParams {
191
172
  externalId?: string;
173
+ email?: string;
192
174
  legalName?: string;
193
175
  displayName?: string;
194
176
  domain?: string;
195
177
  website?: string;
196
- taxStatus?: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
197
- currency?: Currency;
198
- billingEmail?: string;
199
- paymentTerms?: string;
200
178
  timezone?: string;
201
179
  language?: string;
202
180
  industry?: string;
203
- employeeCount?: string;
204
181
  metadata?: Record<string, unknown>;
205
- isActive?: boolean;
206
182
  }
207
183
  interface ListCustomersParams extends ListParams {
208
184
  externalId?: string;
209
- taxStatus?: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
210
- currency?: Currency;
211
185
  isActive?: boolean;
212
186
  search?: string;
213
187
  }
188
+ interface BatchResult$1 {
189
+ successful: Customer[];
190
+ failed: Array<{
191
+ index: number;
192
+ error: string;
193
+ data: CreateParams;
194
+ }>;
195
+ }
214
196
  /**
215
- * Customer resource for managing customer data
197
+ * Customers resource - Manage your customers
216
198
  */
217
199
  declare class CustomersResource {
218
200
  private httpClient;
219
201
  constructor(httpClient: CommetHTTPClient);
220
- create(params: CreateCustomerParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
221
- retrieve(customerId: CustomerID, options?: RetrieveOptions): Promise<ApiResponse<Customer>>;
222
- update(customerId: CustomerID, params: UpdateCustomerParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
202
+ /**
203
+ * Create a customer (idempotent with externalId)
204
+ */
205
+ create(params: CreateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
206
+ /**
207
+ * Create multiple customers in batch
208
+ */
209
+ createBatch(params: {
210
+ customers: CreateParams[];
211
+ }, options?: RequestOptions): Promise<ApiResponse<BatchResult$1>>;
212
+ /**
213
+ * Get a customer by ID
214
+ */
215
+ get(customerId: CustomerID): Promise<ApiResponse<Customer>>;
216
+ /**
217
+ * Update a customer
218
+ */
219
+ update(customerId: CustomerID, params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
220
+ /**
221
+ * List customers with optional filters
222
+ */
223
223
  list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>>;
224
224
  /**
225
- * Deactivate a customer (soft delete)
225
+ * Archive a customer
226
226
  */
227
- deactivate(customerId: CustomerID, options?: RequestOptions): Promise<ApiResponse<Customer>>;
227
+ archive(customerId: CustomerID, options?: RequestOptions): Promise<ApiResponse<Customer>>;
228
228
  }
229
229
 
230
+ type PlanID = `plan_${string}`;
231
+ type BillingInterval = "monthly" | "quarterly" | "yearly";
232
+ type FeatureType = "boolean" | "metered" | "seats";
233
+ interface PlanPrice {
234
+ billingInterval: BillingInterval;
235
+ price: number;
236
+ isDefault: boolean;
237
+ }
238
+ interface PlanFeature {
239
+ code: string;
240
+ name: string;
241
+ type: FeatureType;
242
+ enabled?: boolean;
243
+ includedAmount?: number;
244
+ unlimited?: boolean;
245
+ overageEnabled?: boolean;
246
+ overageUnitPrice?: number;
247
+ }
248
+ interface Plan {
249
+ id: PlanID;
250
+ name: string;
251
+ description?: string;
252
+ isPublic: boolean;
253
+ isDefault: boolean;
254
+ trialDays: number;
255
+ sortOrder: number;
256
+ prices: PlanPrice[];
257
+ features: PlanFeature[];
258
+ createdAt: string;
259
+ }
260
+ interface PlanDetail extends Plan {
261
+ features: Array<PlanFeature & {
262
+ unitName?: string;
263
+ overage?: {
264
+ enabled: boolean;
265
+ model: "per_unit" | "tiered";
266
+ unitPrice: number;
267
+ tiers?: Array<{
268
+ order: number;
269
+ upTo: number | null;
270
+ unitAmount: number;
271
+ flatFee: number;
272
+ }>;
273
+ } | null;
274
+ }>;
275
+ updatedAt: string;
276
+ }
277
+ interface ListPlansParams extends ListParams {
278
+ includePrivate?: boolean;
279
+ }
230
280
  /**
231
- * Portal access response
281
+ * Plans resource for listing available plans
232
282
  */
283
+ declare class PlansResource {
284
+ private httpClient;
285
+ constructor(httpClient: CommetHTTPClient);
286
+ /**
287
+ * List all available plans
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * // List public plans
292
+ * const plans = await commet.plans.list();
293
+ *
294
+ * // Include private plans
295
+ * const allPlans = await commet.plans.list({ includePrivate: true });
296
+ * ```
297
+ */
298
+ list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>>;
299
+ /**
300
+ * Get a specific plan by ID
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const plan = await commet.plans.get('plan_xxx');
305
+ * console.log(plan.data.name); // "Pro"
306
+ * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]
307
+ * ```
308
+ */
309
+ get(planId: string): Promise<ApiResponse<PlanDetail>>;
310
+ }
311
+
233
312
  interface PortalAccess {
234
313
  success: boolean;
235
314
  message: string;
236
315
  portalUrl: string;
237
316
  }
238
- /**
239
- * Request portal access by customer ID
240
- */
241
- interface RequestAccessByCustomerId {
317
+ interface GetUrlByCustomerId {
242
318
  customerId: CustomerID;
243
319
  email?: never;
244
320
  externalId?: never;
245
321
  }
246
- /**
247
- * Request portal access by external ID
248
- */
249
- interface RequestAccessByExternalId {
322
+ interface GetUrlByExternalId {
250
323
  externalId: string;
251
324
  email?: never;
252
325
  customerId?: never;
253
326
  }
254
- /**
255
- * Request portal access by email
256
- */
257
- interface RequestAccessByEmail {
327
+ interface GetUrlByEmail {
258
328
  email: string;
259
329
  customerId?: never;
260
330
  externalId?: never;
261
331
  }
332
+ type GetUrlParams = GetUrlByCustomerId | GetUrlByExternalId | GetUrlByEmail;
262
333
  /**
263
- * Portal access parameters
264
- */
265
- type RequestAccessParams = RequestAccessByCustomerId | RequestAccessByExternalId | RequestAccessByEmail;
266
- /**
267
- * Customer Portal resource for generating customer portal access
334
+ * Portal resource - Generate customer portal access
268
335
  */
269
336
  declare class PortalResource {
270
337
  private httpClient;
271
338
  constructor(httpClient: CommetHTTPClient);
272
339
  /**
273
- * Request portal access for a customer
274
- *
275
- * Generates a secure portal URL that can be sent to the customer via email or used directly.
276
- * The URL contains a time-limited token for secure access to the customer portal.
277
- *
278
- * @param params - customerId, externalId, or email
279
- * @param options - Request options (idempotency, timeout)
280
- * @returns Portal access response with URL
340
+ * Get a portal URL
281
341
  *
282
342
  * @example
283
- * // External ID (recommended)
284
- * const portal = await commet.portal.requestAccess({
285
- * externalId: 'my-customer-123'
286
- * });
287
- *
288
- * @example
289
- * // Customer ID
290
- * const portal = await commet.portal.requestAccess({
291
- * customerId: 'cus_123'
292
- * });
293
- *
294
- * @example
295
- * // Email
296
- * const portal = await commet.portal.requestAccess({
297
- * email: 'customer@example.com'
298
- * });
343
+ * ```typescript
344
+ * const portal = await commet.portal.getUrl({ externalId: 'user_123' });
345
+ * ```
299
346
  */
300
- requestAccess(params: RequestAccessParams, options?: RequestOptions): Promise<ApiResponse<PortalAccess>>;
347
+ getUrl(params: GetUrlParams, options?: RequestOptions): Promise<ApiResponse<PortalAccess>>;
301
348
  }
302
349
 
303
- interface SeatBalance {
304
- id: string;
305
- organizationId: string;
306
- customerId: CustomerID;
307
- seatType: GeneratedSeatType;
308
- balance: number;
309
- asOf: string;
310
- createdAt: string;
311
- updatedAt: string;
312
- }
313
350
  interface SeatEvent {
314
351
  id: string;
315
352
  organizationId: string;
@@ -322,35 +359,32 @@ interface SeatEvent {
322
359
  ts: string;
323
360
  createdAt: string;
324
361
  }
325
- interface SeatBalanceResponse {
362
+ interface SeatBalance {
326
363
  current: number;
327
364
  asOf: string;
328
365
  }
329
- interface BulkSeatUpdate {
330
- [seatType: string]: number;
331
- }
332
- interface AddSeatsParams {
366
+ interface AddParams {
333
367
  customerId?: CustomerID;
334
368
  externalId?: string;
335
369
  seatType: GeneratedSeatType;
336
370
  count: number;
337
371
  }
338
- interface RemoveSeatsParams {
372
+ interface RemoveParams {
339
373
  customerId?: CustomerID;
340
374
  externalId?: string;
341
375
  seatType: GeneratedSeatType;
342
376
  count: number;
343
377
  }
344
- interface SetSeatsParams {
378
+ interface SetParams {
345
379
  customerId?: CustomerID;
346
380
  externalId?: string;
347
381
  seatType: GeneratedSeatType;
348
382
  count: number;
349
383
  }
350
- interface BulkUpdateSeatsParams {
384
+ interface SetAllParams {
351
385
  customerId?: CustomerID;
352
386
  externalId?: string;
353
- seats: BulkSeatUpdate;
387
+ seats: Record<string, number>;
354
388
  }
355
389
  interface GetBalanceParams {
356
390
  customerId?: CustomerID;
@@ -361,45 +395,145 @@ interface GetAllBalancesParams {
361
395
  customerId?: CustomerID;
362
396
  externalId?: string;
363
397
  }
364
- interface ListSeatEventsParams extends ListParams {
365
- customerId?: CustomerID;
366
- externalId?: string;
367
- seatType?: GeneratedSeatType;
368
- eventType?: "add" | "remove" | "set";
369
- }
370
398
  /**
371
- * Seats resource for seat-based billing management
399
+ * Seats resource - Manage seat-based licenses
372
400
  */
373
401
  declare class SeatsResource {
374
402
  private httpClient;
375
403
  constructor(httpClient: CommetHTTPClient);
376
- add(params: AddSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
377
- remove(params: RemoveSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
378
- set(params: SetSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
379
- bulkUpdate(params: BulkUpdateSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent[]>>;
380
- getBalance(params: GetBalanceParams): Promise<ApiResponse<SeatBalanceResponse>>;
381
- getAllBalances(params: GetAllBalancesParams): Promise<ApiResponse<Record<string, SeatBalanceResponse>>>;
382
- listEvents(params?: ListSeatEventsParams): Promise<ApiResponse<SeatEvent[]>>;
404
+ /**
405
+ * Add seats
406
+ *
407
+ * @example
408
+ * ```typescript
409
+ * await commet.seats.add({
410
+ * externalId: 'user_123',
411
+ * seatType: 'editor',
412
+ * count: 5
413
+ * });
414
+ * ```
415
+ */
416
+ add(params: AddParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
417
+ /**
418
+ * Remove seats
419
+ *
420
+ * @example
421
+ * ```typescript
422
+ * await commet.seats.remove({
423
+ * externalId: 'user_123',
424
+ * seatType: 'editor',
425
+ * count: 2
426
+ * });
427
+ * ```
428
+ */
429
+ remove(params: RemoveParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
430
+ /**
431
+ * Set seats to a specific count
432
+ *
433
+ * @example
434
+ * ```typescript
435
+ * await commet.seats.set({
436
+ * externalId: 'user_123',
437
+ * seatType: 'editor',
438
+ * count: 10
439
+ * });
440
+ * ```
441
+ */
442
+ set(params: SetParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
443
+ /**
444
+ * Set all seat types
445
+ *
446
+ * @example
447
+ * ```typescript
448
+ * await commet.seats.setAll({
449
+ * externalId: 'user_123',
450
+ * seats: { editor: 10, viewer: 50 }
451
+ * });
452
+ * ```
453
+ */
454
+ setAll(params: SetAllParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent[]>>;
455
+ /**
456
+ * Get balance for a seat type
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * const balance = await commet.seats.getBalance({
461
+ * externalId: 'user_123',
462
+ * seatType: 'editor'
463
+ * });
464
+ * ```
465
+ */
466
+ getBalance(params: GetBalanceParams): Promise<ApiResponse<SeatBalance>>;
467
+ /**
468
+ * Get all seat balances
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * const balances = await commet.seats.getAllBalances({
473
+ * externalId: 'user_123'
474
+ * });
475
+ * ```
476
+ */
477
+ getAllBalances(params: GetAllBalancesParams): Promise<ApiResponse<Record<string, SeatBalance>>>;
383
478
  }
384
479
 
385
- interface Subscription {
480
+ type SubscriptionStatus = "draft" | "pending_payment" | "trialing" | "active" | "paused" | "past_due" | "canceled" | "expired";
481
+ interface FeatureSummary {
482
+ code: string;
483
+ name: string;
484
+ type: "boolean" | "metered" | "seats";
485
+ enabled?: boolean;
486
+ usage?: {
487
+ current: number;
488
+ included: number;
489
+ overage: number;
490
+ };
491
+ }
492
+ interface ActiveSubscription {
386
493
  id: string;
387
494
  customerId: string;
495
+ plan: {
496
+ id: string;
497
+ name: string;
498
+ basePrice: number;
499
+ billingInterval: BillingInterval;
500
+ };
388
501
  name: string;
389
502
  description?: string;
390
- status: "draft" | "pending_payment" | "active" | "completed" | "canceled";
503
+ status: SubscriptionStatus;
504
+ trialEndsAt?: string;
505
+ currentPeriod: {
506
+ start: string;
507
+ end: string;
508
+ daysRemaining: number;
509
+ };
510
+ features: FeatureSummary[];
391
511
  startDate: string;
392
512
  endDate?: string;
393
513
  billingDayOfMonth: number;
394
- isTemplate?: boolean;
514
+ nextBillingDate: string;
395
515
  checkoutUrl?: string;
396
516
  createdAt: string;
397
517
  updatedAt: string;
398
518
  }
399
- interface SubscriptionItem {
400
- priceId: string;
401
- quantity?: number;
402
- initialSeats?: number;
519
+ interface Subscription {
520
+ id: string;
521
+ customerId: string;
522
+ planId: string;
523
+ planName: string;
524
+ name: string;
525
+ description?: string;
526
+ status: SubscriptionStatus;
527
+ billingInterval: BillingInterval;
528
+ trialEndsAt?: string;
529
+ startDate: string;
530
+ endDate?: string;
531
+ currentPeriodStart?: string;
532
+ currentPeriodEnd?: string;
533
+ billingDayOfMonth: number;
534
+ checkoutUrl?: string;
535
+ createdAt: string;
536
+ updatedAt: string;
403
537
  }
404
538
  type CustomerIdentifier = {
405
539
  customerId: string;
@@ -408,82 +542,81 @@ type CustomerIdentifier = {
408
542
  customerId?: never;
409
543
  externalId: string;
410
544
  };
411
- type CreateSubscriptionParams = CustomerIdentifier & {
412
- items: SubscriptionItem[];
545
+ type PlanIdentifier = {
546
+ planCode: GeneratedPlanCode;
547
+ planId?: never;
548
+ } | {
549
+ planCode?: never;
550
+ planId: string;
551
+ };
552
+ type CreateSubscriptionParams = CustomerIdentifier & PlanIdentifier & {
553
+ billingInterval?: BillingInterval;
554
+ initialSeats?: Record<string, number>;
555
+ skipTrial?: boolean;
413
556
  name?: string;
414
557
  startDate?: string;
415
- status?: "draft" | "pending_payment" | "active";
416
558
  };
417
- interface ListSubscriptionsParams extends ListParams {
418
- customerId?: string;
419
- externalId?: string;
420
- status?: "draft" | "pending_payment" | "active" | "completed" | "canceled";
559
+ type ChangePlanParams = PlanIdentifier & {
560
+ billingInterval?: BillingInterval;
561
+ };
562
+ interface CancelParams {
563
+ reason?: string;
564
+ immediate?: boolean;
421
565
  }
566
+ type GetSubscriptionParams = CustomerIdentifier;
422
567
  /**
423
- * Subscription resource for managing subscriptions
568
+ * Subscription resource for managing subscriptions (plan-first model)
569
+ *
570
+ * Each customer can only have ONE active subscription at a time.
424
571
  */
425
572
  declare class SubscriptionsResource {
426
573
  private httpClient;
427
574
  constructor(httpClient: CommetHTTPClient);
428
575
  /**
429
- * Create a subscription with multiple items (products)
576
+ * Create a subscription with a plan
430
577
  *
431
578
  * @example
432
579
  * ```typescript
433
- * // Free plan - Multiple products
434
- * await commet.subscriptions.create({
435
- * externalId: "org_123",
436
- * items: [
437
- * { priceId: "price_tasks_free", quantity: 1 },
438
- * { priceId: "price_usage_free" },
439
- * { priceId: "price_seats_free", initialSeats: 1 }
440
- * ]
441
- * });
442
- *
443
- * // Pro plan upgrade
444
580
  * await commet.subscriptions.create({
445
- * customerId: "cus_xxx",
446
- * items: [
447
- * { priceId: "price_tasks_pro" },
448
- * { priceId: "price_usage_pro" },
449
- * { priceId: "price_seats_pro", initialSeats: 5 }
450
- * ],
451
- * status: "active"
581
+ * externalId: 'user_123',
582
+ * planCode: 'pro', // autocomplete works after `commet pull`
583
+ * billingInterval: 'yearly',
584
+ * initialSeats: { editor: 5 }
452
585
  * });
453
586
  * ```
454
587
  */
455
588
  create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
456
589
  /**
457
- * Retrieve a subscription by ID
590
+ * Get the active subscription for a customer
591
+ *
592
+ * @example
593
+ * ```typescript
594
+ * const sub = await commet.subscriptions.get({ externalId: 'user_123' });
595
+ * ```
458
596
  */
459
- retrieve(subscriptionId: string, options?: RetrieveOptions): Promise<ApiResponse<Subscription>>;
597
+ get(params: GetSubscriptionParams): Promise<ApiResponse<ActiveSubscription | null>>;
460
598
  /**
461
- * List subscriptions with optional filters
599
+ * Change the plan of a subscription (upgrade/downgrade)
462
600
  *
463
601
  * @example
464
602
  * ```typescript
465
- * // List all active subscriptions for a customer
466
- * await commet.subscriptions.list({
467
- * customerId: "cus_xxx",
468
- * status: "active"
469
- * });
470
- *
471
- * // Using externalId
472
- * await commet.subscriptions.list({
473
- * externalId: "my-customer-123"
603
+ * await commet.subscriptions.changePlan('sub_xxx', {
604
+ * planCode: 'enterprise' // autocomplete works after `commet pull`
474
605
  * });
475
606
  * ```
476
607
  */
477
- list(params?: ListSubscriptionsParams): Promise<ApiResponse<Subscription[]>>;
608
+ changePlan(subscriptionId: string, params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
478
609
  /**
479
610
  * Cancel a subscription
480
611
  *
481
612
  * @example
482
613
  * ```typescript
483
- * await commet.subscriptions.cancel("sub_xxx");
614
+ * await commet.subscriptions.cancel('sub_xxx', {
615
+ * reason: 'switched_to_competitor'
616
+ * });
484
617
  * ```
485
618
  */
486
- cancel(subscriptionId: string, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
619
+ cancel(subscriptionId: string, params?: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
487
620
  }
488
621
 
489
622
  interface UsageEvent {
@@ -503,47 +636,59 @@ interface UsageEventProperty {
503
636
  value: string;
504
637
  createdAt: string;
505
638
  }
506
- interface CreateUsageEventParams {
507
- eventType: GeneratedEventType;
508
- customerId?: CustomerID;
509
- externalId?: string;
510
- idempotencyKey?: string;
511
- timestamp?: string;
512
- properties?: Array<{
513
- property: string;
514
- value: string;
515
- }>;
516
- }
517
- interface CreateBatchUsageEventsParams {
518
- events: CreateUsageEventParams[];
519
- }
520
639
  interface BatchResult<T> {
521
640
  successful: T[];
522
641
  failed: Array<{
523
642
  index: number;
524
643
  error: string;
525
- data: CreateUsageEventParams;
644
+ data: TrackParams;
526
645
  }>;
527
646
  }
528
- interface ListUsageEventsParams extends ListParams {
647
+ interface TrackParams {
648
+ eventType: GeneratedEventType;
529
649
  customerId?: CustomerID;
530
650
  externalId?: string;
531
- eventType?: GeneratedEventType;
532
651
  idempotencyKey?: string;
652
+ value?: number;
653
+ timestamp?: string;
654
+ properties?: Record<string, string>;
533
655
  }
534
656
  /**
535
- * Usage Events resource - Track business events for usage-based billing
657
+ * Usage resource - Track consumption events for usage-based billing
536
658
  */
537
659
  declare class UsageResource {
538
660
  private httpClient;
539
661
  constructor(httpClient: CommetHTTPClient);
540
- create(params: CreateUsageEventParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
541
- createBatch(params: CreateBatchUsageEventsParams, options?: RequestOptions): Promise<ApiResponse<BatchResult<UsageEvent>>>;
542
- retrieve(eventId: EventID): Promise<ApiResponse<UsageEvent>>;
543
- list(params?: ListUsageEventsParams): Promise<ApiResponse<UsageEvent[]>>;
544
- delete(eventId: EventID, options?: RequestOptions): Promise<ApiResponse<{
545
- deleted: boolean;
546
- }>>;
662
+ /**
663
+ * Track a usage event
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * await commet.usage.track({
668
+ * externalId: 'user_123',
669
+ * eventType: 'api_call',
670
+ * idempotencyKey: `evt_${requestId}`,
671
+ * properties: { endpoint: '/users', method: 'GET' }
672
+ * });
673
+ * ```
674
+ */
675
+ track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
676
+ /**
677
+ * Track multiple usage events in a batch
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * await commet.usage.trackBatch({
682
+ * events: [
683
+ * { externalId: 'user_123', eventType: 'api_call', idempotencyKey: 'evt_1' },
684
+ * { externalId: 'user_456', eventType: 'api_call', idempotencyKey: 'evt_2' }
685
+ * ]
686
+ * });
687
+ * ```
688
+ */
689
+ trackBatch(params: {
690
+ events: TrackParams[];
691
+ }, options?: RequestOptions): Promise<ApiResponse<BatchResult<UsageEvent>>>;
547
692
  }
548
693
 
549
694
  /**
@@ -652,6 +797,7 @@ declare class Commet {
652
797
  private httpClient;
653
798
  private environment;
654
799
  readonly customers: CustomersResource;
800
+ readonly plans: PlansResource;
655
801
  readonly usage: UsageResource;
656
802
  readonly seats: SeatsResource;
657
803
  readonly subscriptions: SubscriptionsResource;
@@ -673,7 +819,7 @@ declare function isSandbox(environment: Environment): boolean;
673
819
  declare function isProduction(environment: Environment): boolean;
674
820
 
675
821
  /**
676
- * Commet SDK - Billing and usage tracking SDK
822
+ * Commet SDK - Billing and usage tracking for SaaS
677
823
  */
678
824
 
679
- export { type AddSeatsParams, type AgreementID, type ApiResponse, type BatchResult, type BulkSeatUpdate, type BulkUpdateSeatsParams, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateBatchUsageEventsParams, type CreateCustomerParams, type CreateSubscriptionParams, type CreateUsageEventParams, type Currency, type Customer, type CustomerID, type Environment, type EventID, type GeneratedEventType, type GeneratedProductId, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type InvoiceID, type ItemID, type ListCustomersParams, type ListParams, type ListSeatEventsParams, type ListSubscriptionsParams, type ListUsageEventsParams, type PaginatedList, type PaginatedResponse, type PhaseID, type PortalAccess, type ProductID, type RemoveSeatsParams, type RequestAccessParams, type RequestOptions, type RetrieveOptions, type SeatBalance, type SeatBalanceResponse, type SeatEvent, type SetSeatsParams, type Subscription, type SubscriptionItem, type UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookID, type WebhookPayload, Webhooks, Commet as default, isProduction, isSandbox };
825
+ export { type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CancelParams, type ChangePlanParams, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type Currency, type Customer, type CustomerAddress, type CustomerID, type BatchResult$1 as CustomersBatchResult, type Environment, type EventID, 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 as UsageBatchResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default, isProduction, isSandbox };