@commet/node 4.5.0 → 5.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.mts +1106 -400
- package/dist/index.d.ts +1106 -400
- package/dist/index.js +450 -304
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +453 -306
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -71,17 +71,21 @@ type CommetClientOptions = {
|
|
|
71
71
|
retries?: number;
|
|
72
72
|
telemetry?: boolean;
|
|
73
73
|
};
|
|
74
|
-
/** @deprecated Use CommetClientOptions */
|
|
75
|
-
type CommetConfig = CommetClientOptions;
|
|
76
74
|
interface ApiResponse<T = unknown> {
|
|
77
75
|
success: boolean;
|
|
78
76
|
data?: T;
|
|
79
|
-
|
|
80
|
-
message?: string;
|
|
81
|
-
details?: unknown;
|
|
77
|
+
error?: ApiErrorDetail;
|
|
82
78
|
hasMore?: boolean;
|
|
83
79
|
nextCursor?: string;
|
|
84
80
|
}
|
|
81
|
+
interface ApiErrorDetail {
|
|
82
|
+
type: string;
|
|
83
|
+
code: string;
|
|
84
|
+
message: string;
|
|
85
|
+
param?: string;
|
|
86
|
+
details?: unknown;
|
|
87
|
+
doc_url?: string;
|
|
88
|
+
}
|
|
85
89
|
interface PaginatedResponse<T> {
|
|
86
90
|
data: T[];
|
|
87
91
|
hasMore: boolean;
|
|
@@ -102,7 +106,10 @@ declare class CommetAPIError extends CommetError {
|
|
|
102
106
|
statusCode: number;
|
|
103
107
|
code?: string | undefined;
|
|
104
108
|
details?: unknown | undefined;
|
|
105
|
-
|
|
109
|
+
type?: string;
|
|
110
|
+
param?: string;
|
|
111
|
+
docUrl?: string;
|
|
112
|
+
constructor(message: string, statusCode: number, code?: string | undefined, details?: unknown | undefined, errorDetail?: ApiErrorDetail);
|
|
106
113
|
}
|
|
107
114
|
declare class CommetValidationError extends CommetError {
|
|
108
115
|
validationErrors: Record<string, string[]>;
|
|
@@ -142,11 +149,12 @@ declare class CommetHTTPClient {
|
|
|
142
149
|
private telemetryEnabled;
|
|
143
150
|
private lastRequestMetrics;
|
|
144
151
|
constructor(config: CommetClientOptions);
|
|
145
|
-
get<T = unknown>(endpoint: string, params?: Record<string, unknown
|
|
152
|
+
get<T = unknown>(endpoint: string, params?: Record<string, unknown> | object, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
146
153
|
post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
147
154
|
put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
148
155
|
delete<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
149
156
|
private resolveApiVersion;
|
|
157
|
+
private static readonly BODY_METHODS;
|
|
150
158
|
private request;
|
|
151
159
|
/**
|
|
152
160
|
* Execute real API request with retry logic
|
|
@@ -156,9 +164,6 @@ declare class CommetHTTPClient {
|
|
|
156
164
|
* Build full URL from endpoint and params
|
|
157
165
|
*/
|
|
158
166
|
private buildURL;
|
|
159
|
-
/**
|
|
160
|
-
* Generate idempotency key
|
|
161
|
-
*/
|
|
162
167
|
private generateIdempotencyKey;
|
|
163
168
|
/**
|
|
164
169
|
* Sleep for specified milliseconds
|
|
@@ -166,14 +171,290 @@ declare class CommetHTTPClient {
|
|
|
166
171
|
private sleep;
|
|
167
172
|
}
|
|
168
173
|
|
|
169
|
-
interface
|
|
174
|
+
interface ActiveAddon {
|
|
175
|
+
object: "addon";
|
|
176
|
+
livemode: boolean;
|
|
177
|
+
slug: string;
|
|
178
|
+
name: string;
|
|
179
|
+
basePrice: number;
|
|
180
|
+
featureCode: string;
|
|
181
|
+
featureName: string;
|
|
182
|
+
featureType: string;
|
|
183
|
+
consumptionModel: string | null;
|
|
184
|
+
activatedAt: string;
|
|
185
|
+
}
|
|
186
|
+
interface ListActiveAddonsParams {
|
|
187
|
+
customerId: CustomerID;
|
|
188
|
+
}
|
|
189
|
+
interface AddonBase {
|
|
190
|
+
id: string;
|
|
191
|
+
object: "addon";
|
|
192
|
+
livemode: boolean;
|
|
193
|
+
name: string;
|
|
194
|
+
slug: string;
|
|
195
|
+
description: string | null;
|
|
196
|
+
basePrice: number;
|
|
197
|
+
featureCode: string;
|
|
198
|
+
featureName: string;
|
|
199
|
+
createdAt: string;
|
|
200
|
+
updatedAt: string;
|
|
201
|
+
}
|
|
202
|
+
interface BooleanAddon extends AddonBase {
|
|
203
|
+
consumptionModel: "boolean";
|
|
204
|
+
includedUnits: null;
|
|
205
|
+
overageRate: null;
|
|
206
|
+
creditCost: null;
|
|
207
|
+
}
|
|
208
|
+
interface MeteredAddon extends AddonBase {
|
|
209
|
+
consumptionModel: "metered";
|
|
210
|
+
includedUnits: number;
|
|
211
|
+
overageRate: number;
|
|
212
|
+
creditCost: null;
|
|
213
|
+
}
|
|
214
|
+
interface CreditsAddon extends AddonBase {
|
|
215
|
+
consumptionModel: "credits";
|
|
216
|
+
includedUnits: null;
|
|
217
|
+
overageRate: null;
|
|
218
|
+
creditCost: number;
|
|
219
|
+
}
|
|
220
|
+
interface BalanceAddon extends AddonBase {
|
|
221
|
+
consumptionModel: "balance";
|
|
222
|
+
includedUnits: null;
|
|
223
|
+
overageRate: number;
|
|
224
|
+
creditCost: null;
|
|
225
|
+
}
|
|
226
|
+
type Addon = BooleanAddon | MeteredAddon | CreditsAddon | BalanceAddon;
|
|
227
|
+
interface ListAddonsParams {
|
|
228
|
+
limit?: number;
|
|
229
|
+
cursor?: string;
|
|
230
|
+
}
|
|
231
|
+
interface GetAddonParams {
|
|
232
|
+
id: string;
|
|
233
|
+
}
|
|
234
|
+
interface CreateAddonBase {
|
|
235
|
+
name: string;
|
|
236
|
+
description?: string;
|
|
237
|
+
basePrice: number;
|
|
238
|
+
featureId: string;
|
|
239
|
+
}
|
|
240
|
+
interface CreateBooleanAddonParams extends CreateAddonBase {
|
|
241
|
+
consumptionModel: "boolean";
|
|
242
|
+
}
|
|
243
|
+
interface CreateMeteredAddonParams extends CreateAddonBase {
|
|
244
|
+
consumptionModel: "metered";
|
|
245
|
+
includedUnits: number;
|
|
246
|
+
overageRate: number;
|
|
247
|
+
}
|
|
248
|
+
interface CreateCreditsAddonParams extends CreateAddonBase {
|
|
249
|
+
consumptionModel: "credits";
|
|
250
|
+
creditCost: number;
|
|
251
|
+
}
|
|
252
|
+
interface CreateBalanceAddonParams extends CreateAddonBase {
|
|
253
|
+
consumptionModel: "balance";
|
|
254
|
+
overageRate: number;
|
|
255
|
+
}
|
|
256
|
+
type CreateAddonParams = CreateBooleanAddonParams | CreateMeteredAddonParams | CreateCreditsAddonParams | CreateBalanceAddonParams;
|
|
257
|
+
interface UpdateAddonParams {
|
|
258
|
+
id: string;
|
|
259
|
+
name?: string;
|
|
260
|
+
description?: string;
|
|
261
|
+
basePrice?: number;
|
|
262
|
+
includedUnits?: number;
|
|
263
|
+
overageRate?: number;
|
|
264
|
+
}
|
|
265
|
+
interface DeleteAddonParams {
|
|
266
|
+
id: string;
|
|
267
|
+
}
|
|
268
|
+
declare class AddonsResource {
|
|
269
|
+
private httpClient;
|
|
270
|
+
constructor(httpClient: CommetHTTPClient);
|
|
271
|
+
listActive(params: ListActiveAddonsParams, options?: RequestOptions): Promise<ApiResponse<ActiveAddon[]>>;
|
|
272
|
+
list(params?: ListAddonsParams, options?: RequestOptions): Promise<ApiResponse<Addon[]>>;
|
|
273
|
+
get(params: GetAddonParams, options?: RequestOptions): Promise<ApiResponse<Addon>>;
|
|
274
|
+
create(params: CreateAddonParams, options?: RequestOptions): Promise<ApiResponse<Addon>>;
|
|
275
|
+
update(params: UpdateAddonParams, options?: RequestOptions): Promise<ApiResponse<Addon>>;
|
|
276
|
+
/** Fails if addon has active subscriptions. */
|
|
277
|
+
delete(params: DeleteAddonParams, options?: RequestOptions): Promise<ApiResponse<{
|
|
278
|
+
id: string;
|
|
279
|
+
deleted: true;
|
|
280
|
+
}>>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
interface ApiKey {
|
|
284
|
+
id: string;
|
|
285
|
+
object: "api_key";
|
|
286
|
+
livemode: boolean;
|
|
287
|
+
name: string;
|
|
288
|
+
prefix: string;
|
|
289
|
+
expiresAt: string | null;
|
|
290
|
+
lastUsedAt: string | null;
|
|
291
|
+
createdAt: string;
|
|
292
|
+
}
|
|
293
|
+
interface ApiKeyCreated extends ApiKey {
|
|
294
|
+
apiKey: string;
|
|
295
|
+
}
|
|
296
|
+
interface ListApiKeysParams {
|
|
297
|
+
limit?: number;
|
|
298
|
+
cursor?: string;
|
|
299
|
+
}
|
|
300
|
+
interface CreateApiKeyParams {
|
|
301
|
+
name: string;
|
|
302
|
+
expiresInDays?: number;
|
|
303
|
+
}
|
|
304
|
+
interface DeleteApiKeyParams {
|
|
305
|
+
id: string;
|
|
306
|
+
}
|
|
307
|
+
declare class ApiKeysResource {
|
|
308
|
+
private httpClient;
|
|
309
|
+
constructor(httpClient: CommetHTTPClient);
|
|
310
|
+
list(params?: ListApiKeysParams): Promise<ApiResponse<ApiKey[]>>;
|
|
311
|
+
/** Response includes full `apiKey` which is only returned once. */
|
|
312
|
+
create(params: CreateApiKeyParams, options?: RequestOptions): Promise<ApiResponse<ApiKeyCreated>>;
|
|
313
|
+
delete(params: DeleteApiKeyParams, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
interface CreditPack {
|
|
317
|
+
id: string;
|
|
318
|
+
object: "credit_pack";
|
|
319
|
+
livemode: boolean;
|
|
320
|
+
name: string;
|
|
321
|
+
description: string | null;
|
|
322
|
+
credits: number;
|
|
323
|
+
price: number;
|
|
324
|
+
currency: string;
|
|
325
|
+
}
|
|
326
|
+
interface CreditPackDetail {
|
|
327
|
+
id: string;
|
|
328
|
+
object: "credit_pack";
|
|
329
|
+
livemode: boolean;
|
|
330
|
+
name: string;
|
|
331
|
+
description: string | null;
|
|
332
|
+
credits: number;
|
|
333
|
+
price: number;
|
|
334
|
+
isActive: boolean;
|
|
335
|
+
createdAt: string;
|
|
336
|
+
updatedAt: string;
|
|
337
|
+
}
|
|
338
|
+
interface CreateCreditPackParams {
|
|
339
|
+
name: string;
|
|
340
|
+
description?: string;
|
|
341
|
+
credits: number;
|
|
342
|
+
price: number;
|
|
343
|
+
isActive?: boolean;
|
|
344
|
+
}
|
|
345
|
+
interface UpdateCreditPackParams {
|
|
346
|
+
id: string;
|
|
347
|
+
name?: string;
|
|
348
|
+
description?: string;
|
|
349
|
+
credits?: number;
|
|
350
|
+
price?: number;
|
|
351
|
+
isActive?: boolean;
|
|
352
|
+
}
|
|
353
|
+
interface DeleteCreditPackParams {
|
|
354
|
+
id: string;
|
|
355
|
+
}
|
|
356
|
+
declare class CreditPacksResource {
|
|
357
|
+
private httpClient;
|
|
358
|
+
constructor(httpClient: CommetHTTPClient);
|
|
359
|
+
list(): Promise<ApiResponse<CreditPack[]>>;
|
|
360
|
+
create(params: CreateCreditPackParams, options?: RequestOptions): Promise<ApiResponse<CreditPackDetail>>;
|
|
361
|
+
update(params: UpdateCreditPackParams, options?: RequestOptions): Promise<ApiResponse<CreditPackDetail>>;
|
|
362
|
+
delete(params: DeleteCreditPackParams, options?: RequestOptions): Promise<ApiResponse<{
|
|
363
|
+
id: string;
|
|
364
|
+
deleted: true;
|
|
365
|
+
}>>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
interface Customer {
|
|
369
|
+
id: CustomerID;
|
|
370
|
+
object: "customer";
|
|
371
|
+
livemode: boolean;
|
|
372
|
+
organizationId: string;
|
|
373
|
+
fullName?: string;
|
|
374
|
+
domain?: string;
|
|
375
|
+
website?: string;
|
|
376
|
+
billingEmail: string;
|
|
377
|
+
timezone?: string;
|
|
378
|
+
language?: string;
|
|
379
|
+
industry?: string;
|
|
380
|
+
employeeCount?: string;
|
|
381
|
+
metadata?: Record<string, unknown>;
|
|
382
|
+
createdAt: string;
|
|
383
|
+
updatedAt: string;
|
|
384
|
+
}
|
|
385
|
+
interface CustomerAddress {
|
|
386
|
+
line1: string;
|
|
387
|
+
line2?: string;
|
|
388
|
+
city: string;
|
|
389
|
+
state?: string;
|
|
390
|
+
postalCode: string;
|
|
391
|
+
country: string;
|
|
392
|
+
}
|
|
393
|
+
interface CreateParams {
|
|
394
|
+
email: string;
|
|
395
|
+
id?: string;
|
|
396
|
+
fullName?: string;
|
|
397
|
+
domain?: string;
|
|
398
|
+
website?: string;
|
|
399
|
+
timezone?: string;
|
|
400
|
+
language?: string;
|
|
401
|
+
industry?: string;
|
|
402
|
+
metadata?: Record<string, unknown>;
|
|
403
|
+
address?: CustomerAddress;
|
|
404
|
+
}
|
|
405
|
+
interface GetCustomerParams {
|
|
406
|
+
id: CustomerID;
|
|
407
|
+
}
|
|
408
|
+
interface UpdateParams {
|
|
409
|
+
id: CustomerID;
|
|
410
|
+
email?: string;
|
|
411
|
+
fullName?: string;
|
|
412
|
+
domain?: string;
|
|
413
|
+
website?: string;
|
|
414
|
+
timezone?: string;
|
|
415
|
+
language?: string;
|
|
416
|
+
industry?: string;
|
|
417
|
+
metadata?: Record<string, unknown>;
|
|
418
|
+
address?: CustomerAddress;
|
|
419
|
+
}
|
|
420
|
+
interface ListCustomersParams extends ListParams {
|
|
421
|
+
search?: string;
|
|
422
|
+
}
|
|
423
|
+
interface BatchResult {
|
|
424
|
+
successful: Customer[];
|
|
425
|
+
failed: Array<{
|
|
426
|
+
index: number;
|
|
427
|
+
error: string;
|
|
428
|
+
data: CreateParams;
|
|
429
|
+
}>;
|
|
430
|
+
}
|
|
431
|
+
declare class CustomersResource {
|
|
432
|
+
private httpClient;
|
|
433
|
+
constructor(httpClient: CommetHTTPClient);
|
|
434
|
+
/** Idempotent when `id` is provided — returns existing customer instead of duplicating. */
|
|
435
|
+
create(params: CreateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
436
|
+
createBatch(params: {
|
|
437
|
+
customers: CreateParams[];
|
|
438
|
+
}, options?: RequestOptions): Promise<ApiResponse<BatchResult>>;
|
|
439
|
+
get(params: GetCustomerParams): Promise<ApiResponse<Customer>>;
|
|
440
|
+
update(params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
441
|
+
list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>>;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
interface GetFeatureParams {
|
|
445
|
+
customerId: CustomerID;
|
|
446
|
+
code: string;
|
|
447
|
+
}
|
|
448
|
+
interface CanUseFeatureParams {
|
|
170
449
|
customerId: CustomerID;
|
|
171
450
|
code: string;
|
|
172
451
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
452
|
+
interface ListFeaturesParams {
|
|
453
|
+
customerId: CustomerID;
|
|
454
|
+
}
|
|
176
455
|
interface FeatureAccess {
|
|
456
|
+
object: "feature";
|
|
457
|
+
livemode: boolean;
|
|
177
458
|
code: string;
|
|
178
459
|
name: string;
|
|
179
460
|
type: "boolean" | "usage" | "seats";
|
|
@@ -192,99 +473,231 @@ interface CanUseResult {
|
|
|
192
473
|
willBeCharged: boolean;
|
|
193
474
|
reason?: string;
|
|
194
475
|
}
|
|
195
|
-
interface
|
|
196
|
-
|
|
476
|
+
interface Feature {
|
|
477
|
+
id: string;
|
|
478
|
+
object: "feature";
|
|
479
|
+
livemode: boolean;
|
|
480
|
+
name: string;
|
|
481
|
+
code: string;
|
|
482
|
+
type: "boolean" | "usage" | "seats";
|
|
483
|
+
description: string | null;
|
|
484
|
+
unitName: string | null;
|
|
485
|
+
createdAt: string;
|
|
486
|
+
updatedAt: string;
|
|
487
|
+
}
|
|
488
|
+
interface CreateFeatureParams {
|
|
489
|
+
code: string;
|
|
490
|
+
name: string;
|
|
491
|
+
type: "boolean" | "usage" | "seats";
|
|
492
|
+
description?: string;
|
|
493
|
+
unitName?: string;
|
|
494
|
+
}
|
|
495
|
+
interface UpdateFeatureParams {
|
|
496
|
+
code: string;
|
|
497
|
+
name?: string;
|
|
498
|
+
description?: string;
|
|
499
|
+
unitName?: string;
|
|
500
|
+
}
|
|
501
|
+
interface DeleteFeatureParams {
|
|
502
|
+
code: string;
|
|
197
503
|
}
|
|
198
504
|
declare class FeaturesResource {
|
|
199
505
|
private httpClient;
|
|
200
506
|
constructor(httpClient: CommetHTTPClient);
|
|
201
507
|
get(params: GetFeatureParams, options?: RequestOptions): Promise<ApiResponse<FeatureAccess>>;
|
|
202
|
-
|
|
508
|
+
/** Checks if the customer can consume one more unit — returns billing impact and reason if blocked. */
|
|
203
509
|
canUse(params: CanUseFeatureParams, options?: RequestOptions): Promise<ApiResponse<CanUseResult>>;
|
|
204
|
-
list(
|
|
510
|
+
list(params: ListFeaturesParams, options?: RequestOptions): Promise<ApiResponse<FeatureAccess[]>>;
|
|
511
|
+
create(params: CreateFeatureParams, options?: RequestOptions): Promise<ApiResponse<Feature>>;
|
|
512
|
+
update(params: UpdateFeatureParams, options?: RequestOptions): Promise<ApiResponse<Feature>>;
|
|
513
|
+
/** Fails if feature is attached to active plans or has an active addon. */
|
|
514
|
+
delete(params: DeleteFeatureParams, options?: RequestOptions): Promise<ApiResponse<{
|
|
515
|
+
id: string;
|
|
516
|
+
deleted: true;
|
|
517
|
+
}>>;
|
|
205
518
|
}
|
|
206
519
|
|
|
207
|
-
interface
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
520
|
+
interface InvoiceLineItem {
|
|
521
|
+
lineType: string;
|
|
522
|
+
featureName: string | null;
|
|
523
|
+
description: string | null;
|
|
524
|
+
quantity: number;
|
|
525
|
+
unitAmount: number;
|
|
526
|
+
amount: number;
|
|
527
|
+
includedAmount: number | null;
|
|
528
|
+
usedAmount: number | null;
|
|
529
|
+
overageAmount: number | null;
|
|
530
|
+
discountType: string | null;
|
|
531
|
+
discountValue: number | null;
|
|
532
|
+
discountName: string | null;
|
|
533
|
+
chargeType: string | null;
|
|
534
|
+
}
|
|
535
|
+
interface InvoiceListItem {
|
|
536
|
+
id: string;
|
|
537
|
+
object: "invoice";
|
|
538
|
+
livemode: boolean;
|
|
539
|
+
customerId: string;
|
|
540
|
+
subscriptionId: string | null;
|
|
541
|
+
invoiceNumber: string;
|
|
542
|
+
status: string;
|
|
543
|
+
invoiceType: string;
|
|
544
|
+
currency: string;
|
|
545
|
+
subtotal: number;
|
|
546
|
+
discountAmount: number;
|
|
547
|
+
taxAmount: number;
|
|
548
|
+
total: number;
|
|
549
|
+
periodStart: string | null;
|
|
550
|
+
periodEnd: string | null;
|
|
551
|
+
issueDate: string;
|
|
552
|
+
dueDate: string | null;
|
|
553
|
+
memo: string | null;
|
|
554
|
+
metadata: Record<string, unknown> | null;
|
|
555
|
+
createdAt: string;
|
|
556
|
+
updatedAt: string;
|
|
211
557
|
}
|
|
212
|
-
interface
|
|
213
|
-
|
|
214
|
-
|
|
558
|
+
interface InvoiceDetail extends InvoiceListItem {
|
|
559
|
+
creditApplied: number;
|
|
560
|
+
planName: string | null;
|
|
561
|
+
poNumber: string | null;
|
|
562
|
+
reference: string | null;
|
|
563
|
+
lineItems: InvoiceLineItem[];
|
|
215
564
|
}
|
|
216
|
-
interface
|
|
217
|
-
|
|
218
|
-
|
|
565
|
+
interface InvoiceDownloadResult {
|
|
566
|
+
url: string;
|
|
567
|
+
expiresAt: string;
|
|
219
568
|
}
|
|
220
|
-
|
|
221
|
-
|
|
569
|
+
interface InvoiceSendResult {
|
|
570
|
+
sent: boolean;
|
|
571
|
+
sentAt: string;
|
|
572
|
+
}
|
|
573
|
+
interface InvoiceStatusResult {
|
|
574
|
+
id: string;
|
|
575
|
+
status: string;
|
|
576
|
+
updatedAt: string;
|
|
577
|
+
}
|
|
578
|
+
interface CreateAdjustmentResult {
|
|
579
|
+
id: string;
|
|
580
|
+
object: "invoice";
|
|
581
|
+
livemode: boolean;
|
|
582
|
+
customerId: string;
|
|
583
|
+
invoiceNumber: string;
|
|
584
|
+
status: string;
|
|
585
|
+
invoiceType: string;
|
|
586
|
+
currency: string;
|
|
587
|
+
subtotal: number;
|
|
588
|
+
taxAmount: number;
|
|
589
|
+
total: number;
|
|
590
|
+
issueDate: string;
|
|
591
|
+
dueDate: string | null;
|
|
592
|
+
memo: string | null;
|
|
593
|
+
metadata: Record<string, unknown> | null;
|
|
594
|
+
createdAt: string;
|
|
595
|
+
updatedAt: string;
|
|
596
|
+
}
|
|
597
|
+
interface ListInvoicesParams {
|
|
598
|
+
customerId?: string;
|
|
599
|
+
status?: string;
|
|
600
|
+
subscriptionId?: string;
|
|
601
|
+
limit?: number;
|
|
602
|
+
cursor?: string;
|
|
603
|
+
}
|
|
604
|
+
interface GetInvoiceParams {
|
|
605
|
+
id: string;
|
|
606
|
+
}
|
|
607
|
+
interface CreateAdjustmentParams {
|
|
608
|
+
customerId: string;
|
|
609
|
+
amount: number;
|
|
610
|
+
description?: string;
|
|
611
|
+
metadata?: Record<string, unknown>;
|
|
612
|
+
}
|
|
613
|
+
interface GetDownloadUrlParams {
|
|
614
|
+
id: string;
|
|
615
|
+
}
|
|
616
|
+
interface SendInvoiceParams {
|
|
617
|
+
id: string;
|
|
618
|
+
}
|
|
619
|
+
interface UpdateInvoiceStatusParams {
|
|
620
|
+
id: string;
|
|
621
|
+
status: string;
|
|
622
|
+
}
|
|
623
|
+
declare class InvoicesResource {
|
|
222
624
|
private httpClient;
|
|
223
625
|
constructor(httpClient: CommetHTTPClient);
|
|
224
|
-
|
|
626
|
+
list(params?: ListInvoicesParams): Promise<ApiResponse<InvoiceListItem[]>>;
|
|
627
|
+
get(params: GetInvoiceParams): Promise<ApiResponse<InvoiceDetail>>;
|
|
628
|
+
/** Negative amount creates a credit. */
|
|
629
|
+
createAdjustment(params: CreateAdjustmentParams, options?: RequestOptions): Promise<ApiResponse<CreateAdjustmentResult>>;
|
|
630
|
+
/** Signed URL, expires after 7 days. */
|
|
631
|
+
getDownloadUrl(params: GetDownloadUrlParams): Promise<ApiResponse<InvoiceDownloadResult>>;
|
|
632
|
+
send(params: SendInvoiceParams, options?: RequestOptions): Promise<ApiResponse<InvoiceSendResult>>;
|
|
633
|
+
/** Only outstanding invoices can be changed to paid or void. */
|
|
634
|
+
updateStatus(params: UpdateInvoiceStatusParams, options?: RequestOptions): Promise<ApiResponse<InvoiceStatusResult>>;
|
|
225
635
|
}
|
|
226
636
|
|
|
227
|
-
interface
|
|
637
|
+
interface PlanGroup {
|
|
228
638
|
id: string;
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
eventType: "add" | "remove" | "set";
|
|
235
|
-
quantity: number;
|
|
236
|
-
previousBalance?: number;
|
|
237
|
-
newBalance: number;
|
|
238
|
-
ts: string;
|
|
639
|
+
object: "plan_group";
|
|
640
|
+
livemode: boolean;
|
|
641
|
+
name: string;
|
|
642
|
+
description: string | null;
|
|
643
|
+
isPublic: boolean;
|
|
239
644
|
createdAt: string;
|
|
645
|
+
updatedAt: string;
|
|
240
646
|
}
|
|
241
|
-
interface
|
|
242
|
-
|
|
243
|
-
|
|
647
|
+
interface PlanGroupDetail extends PlanGroup {
|
|
648
|
+
plans: Array<{
|
|
649
|
+
id: string;
|
|
650
|
+
code: string;
|
|
651
|
+
name: string;
|
|
652
|
+
sortOrder: number;
|
|
653
|
+
}>;
|
|
244
654
|
}
|
|
245
|
-
interface
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
/** @deprecated Use featureCode instead */
|
|
249
|
-
seatType?: string;
|
|
250
|
-
count: number;
|
|
655
|
+
interface ListPlanGroupsParams {
|
|
656
|
+
limit?: number;
|
|
657
|
+
cursor?: string;
|
|
251
658
|
}
|
|
252
|
-
interface
|
|
253
|
-
|
|
254
|
-
featureCode?: string;
|
|
255
|
-
/** @deprecated Use featureCode instead */
|
|
256
|
-
seatType?: string;
|
|
257
|
-
count: number;
|
|
659
|
+
interface GetPlanGroupParams {
|
|
660
|
+
id: string;
|
|
258
661
|
}
|
|
259
|
-
interface
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
seatType?: string;
|
|
264
|
-
count: number;
|
|
662
|
+
interface CreatePlanGroupParams {
|
|
663
|
+
name: string;
|
|
664
|
+
description?: string;
|
|
665
|
+
isPublic?: boolean;
|
|
265
666
|
}
|
|
266
|
-
interface
|
|
267
|
-
|
|
268
|
-
|
|
667
|
+
interface UpdatePlanGroupParams {
|
|
668
|
+
id: string;
|
|
669
|
+
name?: string;
|
|
670
|
+
description?: string;
|
|
671
|
+
isPublic?: boolean;
|
|
269
672
|
}
|
|
270
|
-
interface
|
|
271
|
-
|
|
272
|
-
featureCode?: string;
|
|
273
|
-
/** @deprecated Use featureCode instead */
|
|
274
|
-
seatType?: string;
|
|
673
|
+
interface DeletePlanGroupParams {
|
|
674
|
+
id: string;
|
|
275
675
|
}
|
|
276
|
-
interface
|
|
277
|
-
|
|
676
|
+
interface AddPlanToGroupParams {
|
|
677
|
+
id: string;
|
|
678
|
+
planId: string;
|
|
679
|
+
sortOrder?: number;
|
|
278
680
|
}
|
|
279
|
-
|
|
681
|
+
interface RemovePlanFromGroupParams {
|
|
682
|
+
id: string;
|
|
683
|
+
planId: string;
|
|
684
|
+
}
|
|
685
|
+
interface ReorderPlansParams {
|
|
686
|
+
id: string;
|
|
687
|
+
planIds: string[];
|
|
688
|
+
}
|
|
689
|
+
declare class PlanGroupsResource {
|
|
280
690
|
private httpClient;
|
|
281
691
|
constructor(httpClient: CommetHTTPClient);
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
692
|
+
list(params?: ListPlanGroupsParams): Promise<ApiResponse<PlanGroup[]>>;
|
|
693
|
+
get(params: GetPlanGroupParams): Promise<ApiResponse<PlanGroupDetail>>;
|
|
694
|
+
create(params: CreatePlanGroupParams, options?: RequestOptions): Promise<ApiResponse<PlanGroup>>;
|
|
695
|
+
update(params: UpdatePlanGroupParams, options?: RequestOptions): Promise<ApiResponse<PlanGroup>>;
|
|
696
|
+
/** Plans in the group are unlinked, not deleted. */
|
|
697
|
+
delete(params: DeletePlanGroupParams, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
698
|
+
addPlan(params: AddPlanToGroupParams, options?: RequestOptions): Promise<ApiResponse<PlanGroupDetail>>;
|
|
699
|
+
removePlan(params: RemovePlanFromGroupParams, options?: RequestOptions): Promise<ApiResponse<void>>;
|
|
700
|
+
reorderPlans(params: ReorderPlansParams, options?: RequestOptions): Promise<ApiResponse<PlanGroupDetail>>;
|
|
288
701
|
}
|
|
289
702
|
|
|
290
703
|
type PlanID = `plan_${string}`;
|
|
@@ -309,6 +722,8 @@ interface PlanFeature {
|
|
|
309
722
|
}
|
|
310
723
|
interface Plan {
|
|
311
724
|
id: PlanID;
|
|
725
|
+
object: "plan";
|
|
726
|
+
livemode: boolean;
|
|
312
727
|
code: string;
|
|
313
728
|
name: string;
|
|
314
729
|
description: string | null;
|
|
@@ -341,6 +756,8 @@ interface PlanDetailFeature extends PlanFeature {
|
|
|
341
756
|
}
|
|
342
757
|
interface PlanDetail {
|
|
343
758
|
id: PlanID;
|
|
759
|
+
object: "plan";
|
|
760
|
+
livemode: boolean;
|
|
344
761
|
code: string;
|
|
345
762
|
name: string;
|
|
346
763
|
description: string | null;
|
|
@@ -355,36 +772,334 @@ interface PlanDetail {
|
|
|
355
772
|
interface ListPlansParams extends ListParams {
|
|
356
773
|
includePrivate?: boolean;
|
|
357
774
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
775
|
+
interface PlanManage {
|
|
776
|
+
id: string;
|
|
777
|
+
object: "plan";
|
|
778
|
+
livemode: boolean;
|
|
779
|
+
name: string;
|
|
780
|
+
code: string;
|
|
781
|
+
description: string | null;
|
|
782
|
+
consumptionModel: string | null;
|
|
783
|
+
isPublic: boolean;
|
|
784
|
+
isDefault: boolean;
|
|
785
|
+
isFree: boolean;
|
|
786
|
+
blockOnExhaustion: boolean;
|
|
787
|
+
sortOrder: number;
|
|
788
|
+
planGroupId: string | null;
|
|
789
|
+
metadata: Record<string, unknown> | null;
|
|
790
|
+
createdAt: string;
|
|
791
|
+
updatedAt: string;
|
|
792
|
+
}
|
|
793
|
+
interface PlanFeatureManageBase {
|
|
794
|
+
planId: string;
|
|
795
|
+
featureId: string;
|
|
796
|
+
enabled: boolean;
|
|
797
|
+
includedAmount: number | null;
|
|
798
|
+
unlimited: boolean;
|
|
799
|
+
overageEnabled: boolean;
|
|
800
|
+
creditsPerUnit: number | null;
|
|
801
|
+
}
|
|
802
|
+
interface FixedPricingFeatureManage extends PlanFeatureManageBase {
|
|
803
|
+
pricingMode: "fixed";
|
|
804
|
+
overageUnitPrice: number | null;
|
|
805
|
+
margin: null;
|
|
806
|
+
}
|
|
807
|
+
interface AiModelPricingFeatureManage extends PlanFeatureManageBase {
|
|
808
|
+
pricingMode: "ai_model";
|
|
809
|
+
margin: number;
|
|
810
|
+
overageUnitPrice: null;
|
|
811
|
+
}
|
|
812
|
+
type PlanFeatureManage = FixedPricingFeatureManage | AiModelPricingFeatureManage;
|
|
813
|
+
interface PlanPriceManage {
|
|
814
|
+
id: string;
|
|
815
|
+
object: "plan_price";
|
|
816
|
+
livemode: boolean;
|
|
817
|
+
planId: string;
|
|
818
|
+
billingInterval: BillingInterval;
|
|
819
|
+
price: number;
|
|
820
|
+
isDefault: boolean;
|
|
821
|
+
trialDays: number;
|
|
822
|
+
includedBalance: number | null;
|
|
823
|
+
includedCredits: number | null;
|
|
824
|
+
introOfferEnabled: boolean;
|
|
825
|
+
introOfferDiscountType: "percentage" | "amount" | null;
|
|
826
|
+
introOfferDiscountValue: number | null;
|
|
827
|
+
introOfferDurationCycles: number | null;
|
|
828
|
+
createdAt: string;
|
|
829
|
+
updatedAt: string;
|
|
830
|
+
}
|
|
831
|
+
interface RegionalPriceResult {
|
|
832
|
+
priceId: string;
|
|
833
|
+
overrides: Array<{
|
|
834
|
+
currency: string;
|
|
835
|
+
price: number;
|
|
836
|
+
}>;
|
|
837
|
+
}
|
|
838
|
+
interface DeleteResult {
|
|
839
|
+
id: string;
|
|
840
|
+
deleted: true;
|
|
841
|
+
}
|
|
842
|
+
interface RemoveResult {
|
|
843
|
+
id: string;
|
|
844
|
+
removed: true;
|
|
845
|
+
}
|
|
846
|
+
interface CreatePlanParams {
|
|
847
|
+
name: string;
|
|
848
|
+
code: string;
|
|
849
|
+
description?: string;
|
|
850
|
+
consumptionModel?: "metered" | "credits" | "balance";
|
|
851
|
+
isPublic?: boolean;
|
|
852
|
+
isFree?: boolean;
|
|
853
|
+
blockOnExhaustion?: boolean;
|
|
854
|
+
planGroupId?: string;
|
|
855
|
+
metadata?: Record<string, unknown>;
|
|
856
|
+
}
|
|
857
|
+
interface UpdatePlanParams {
|
|
858
|
+
id: string;
|
|
859
|
+
name?: string;
|
|
860
|
+
description?: string;
|
|
861
|
+
metadata?: Record<string, unknown>;
|
|
862
|
+
isPublic?: boolean;
|
|
863
|
+
}
|
|
864
|
+
interface DeletePlanParams {
|
|
865
|
+
id: string;
|
|
866
|
+
}
|
|
867
|
+
interface SetVisibilityParams {
|
|
868
|
+
id: string;
|
|
869
|
+
isPublic: boolean;
|
|
870
|
+
}
|
|
871
|
+
interface AddPlanFeatureBase {
|
|
872
|
+
planId: string;
|
|
873
|
+
featureId: string;
|
|
874
|
+
enabled?: boolean;
|
|
875
|
+
includedAmount?: number;
|
|
876
|
+
unlimited?: boolean;
|
|
877
|
+
overageEnabled?: boolean;
|
|
878
|
+
creditsPerUnit?: number | null;
|
|
879
|
+
}
|
|
880
|
+
interface AddFixedPricingFeatureParams extends AddPlanFeatureBase {
|
|
881
|
+
pricingMode?: "fixed";
|
|
882
|
+
overageUnitPrice?: number;
|
|
883
|
+
}
|
|
884
|
+
interface AddAiModelPricingFeatureParams extends AddPlanFeatureBase {
|
|
885
|
+
pricingMode: "ai_model";
|
|
886
|
+
margin: number;
|
|
887
|
+
}
|
|
888
|
+
type AddPlanFeatureParams = AddFixedPricingFeatureParams | AddAiModelPricingFeatureParams;
|
|
889
|
+
interface UpdatePlanFeatureBase {
|
|
890
|
+
planId: string;
|
|
891
|
+
featureId: string;
|
|
892
|
+
enabled?: boolean;
|
|
893
|
+
includedAmount?: number;
|
|
894
|
+
unlimited?: boolean;
|
|
895
|
+
overageEnabled?: boolean;
|
|
896
|
+
creditsPerUnit?: number | null;
|
|
897
|
+
}
|
|
898
|
+
interface UpdateFixedPricingFeatureParams extends UpdatePlanFeatureBase {
|
|
899
|
+
pricingMode?: "fixed";
|
|
900
|
+
overageUnitPrice?: number;
|
|
901
|
+
}
|
|
902
|
+
interface UpdateAiModelPricingFeatureParams extends UpdatePlanFeatureBase {
|
|
903
|
+
pricingMode: "ai_model";
|
|
904
|
+
margin?: number;
|
|
905
|
+
}
|
|
906
|
+
type UpdatePlanFeatureParams = UpdateFixedPricingFeatureParams | UpdateAiModelPricingFeatureParams;
|
|
907
|
+
interface RemovePlanFeatureParams {
|
|
908
|
+
planId: string;
|
|
909
|
+
featureId: string;
|
|
910
|
+
}
|
|
911
|
+
interface AddPlanPriceParams {
|
|
912
|
+
planId: string;
|
|
913
|
+
billingInterval: BillingInterval;
|
|
914
|
+
price: number;
|
|
915
|
+
trialDays?: number;
|
|
916
|
+
isDefault?: boolean;
|
|
917
|
+
includedBalance?: number;
|
|
918
|
+
includedCredits?: number;
|
|
919
|
+
introOfferEnabled?: boolean;
|
|
920
|
+
introOfferDiscountType?: "percentage" | "amount";
|
|
921
|
+
introOfferDiscountValue?: number;
|
|
922
|
+
introOfferDurationCycles?: number;
|
|
923
|
+
}
|
|
924
|
+
interface UpdatePlanPriceParams {
|
|
925
|
+
planId: string;
|
|
926
|
+
priceId: string;
|
|
927
|
+
price?: number;
|
|
928
|
+
isDefault?: boolean;
|
|
929
|
+
trialDays?: number;
|
|
930
|
+
includedBalance?: number;
|
|
931
|
+
includedCredits?: number;
|
|
932
|
+
introOfferEnabled?: boolean;
|
|
933
|
+
introOfferDiscountType?: "percentage" | "amount" | null;
|
|
934
|
+
introOfferDiscountValue?: number | null;
|
|
935
|
+
introOfferDurationCycles?: number | null;
|
|
936
|
+
}
|
|
937
|
+
interface DeletePlanPriceParams {
|
|
938
|
+
planId: string;
|
|
939
|
+
priceId: string;
|
|
940
|
+
}
|
|
941
|
+
interface SetDefaultPriceParams {
|
|
942
|
+
planId: string;
|
|
943
|
+
priceId: string;
|
|
944
|
+
}
|
|
945
|
+
interface SetRegionalPricesParams {
|
|
946
|
+
planId: string;
|
|
947
|
+
priceId: string;
|
|
948
|
+
overrides: Array<{
|
|
949
|
+
currency: string;
|
|
950
|
+
price: number;
|
|
951
|
+
}>;
|
|
952
|
+
}
|
|
953
|
+
interface DeleteRegionalPricesParams {
|
|
954
|
+
planId: string;
|
|
955
|
+
priceId: string;
|
|
956
|
+
}
|
|
361
957
|
declare class PlansResource {
|
|
362
958
|
private httpClient;
|
|
363
959
|
constructor(httpClient: CommetHTTPClient);
|
|
364
|
-
/**
|
|
365
|
-
* List all available plans
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* ```typescript
|
|
369
|
-
* // List public plans
|
|
370
|
-
* const plans = await commet.plans.list();
|
|
371
|
-
*
|
|
372
|
-
* // Include private plans
|
|
373
|
-
* const allPlans = await commet.plans.list({ includePrivate: true });
|
|
374
|
-
* ```
|
|
375
|
-
*/
|
|
376
960
|
list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>>;
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
961
|
+
get(params: {
|
|
962
|
+
id: string;
|
|
963
|
+
}): Promise<ApiResponse<PlanDetail>>;
|
|
964
|
+
create(params: CreatePlanParams, options?: RequestOptions): Promise<ApiResponse<PlanManage>>;
|
|
965
|
+
update(params: UpdatePlanParams, options?: RequestOptions): Promise<ApiResponse<PlanManage>>;
|
|
966
|
+
delete(params: DeletePlanParams, options?: RequestOptions): Promise<ApiResponse<DeleteResult>>;
|
|
967
|
+
setVisibility(params: SetVisibilityParams, options?: RequestOptions): Promise<ApiResponse<PlanManage>>;
|
|
968
|
+
addFeature(params: AddPlanFeatureParams, options?: RequestOptions): Promise<ApiResponse<PlanFeatureManage>>;
|
|
969
|
+
updateFeature(params: UpdatePlanFeatureParams, options?: RequestOptions): Promise<ApiResponse<PlanFeatureManage>>;
|
|
970
|
+
removeFeature(params: RemovePlanFeatureParams, options?: RequestOptions): Promise<ApiResponse<RemoveResult>>;
|
|
971
|
+
addPrice(params: AddPlanPriceParams, options?: RequestOptions): Promise<ApiResponse<PlanPriceManage>>;
|
|
972
|
+
updatePrice(params: UpdatePlanPriceParams, options?: RequestOptions): Promise<ApiResponse<PlanPriceManage>>;
|
|
973
|
+
deletePrice(params: DeletePlanPriceParams, options?: RequestOptions): Promise<ApiResponse<DeleteResult>>;
|
|
974
|
+
setDefaultPrice(params: SetDefaultPriceParams, options?: RequestOptions): Promise<ApiResponse<PlanPriceManage>>;
|
|
975
|
+
setRegionalPrices(params: SetRegionalPricesParams, options?: RequestOptions): Promise<ApiResponse<RegionalPriceResult>>;
|
|
976
|
+
deleteRegionalPrices(params: DeleteRegionalPricesParams, options?: RequestOptions): Promise<ApiResponse<DeleteResult>>;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
interface PortalAccess {
|
|
980
|
+
success: boolean;
|
|
981
|
+
message: string;
|
|
982
|
+
portalUrl: string;
|
|
983
|
+
}
|
|
984
|
+
interface GetUrlByCustomerId {
|
|
985
|
+
customerId: CustomerID;
|
|
986
|
+
email?: never;
|
|
987
|
+
}
|
|
988
|
+
interface GetUrlByEmail {
|
|
989
|
+
email: string;
|
|
990
|
+
customerId?: never;
|
|
991
|
+
}
|
|
992
|
+
type GetUrlParams = GetUrlByCustomerId | GetUrlByEmail;
|
|
993
|
+
declare class PortalResource {
|
|
994
|
+
private httpClient;
|
|
995
|
+
constructor(httpClient: CommetHTTPClient);
|
|
996
|
+
getUrl(params: GetUrlParams, options?: RequestOptions): Promise<ApiResponse<PortalAccess>>;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
interface PromoCode {
|
|
1000
|
+
id: string;
|
|
1001
|
+
object: "promo_code";
|
|
1002
|
+
livemode: boolean;
|
|
1003
|
+
code: string;
|
|
1004
|
+
discountType: "percentage" | "amount";
|
|
1005
|
+
discountValue: number;
|
|
1006
|
+
durationCycles: number | null;
|
|
1007
|
+
maxRedemptions: number | null;
|
|
1008
|
+
expiresAt: string | null;
|
|
1009
|
+
active: boolean;
|
|
1010
|
+
redemptionCount: number;
|
|
1011
|
+
createdAt: string;
|
|
1012
|
+
}
|
|
1013
|
+
interface PromoCodeDetail extends PromoCode {
|
|
1014
|
+
updatedAt: string;
|
|
1015
|
+
}
|
|
1016
|
+
interface ListPromoCodesParams {
|
|
1017
|
+
limit?: number;
|
|
1018
|
+
cursor?: string;
|
|
1019
|
+
}
|
|
1020
|
+
interface GetPromoCodeParams {
|
|
1021
|
+
id: string;
|
|
1022
|
+
}
|
|
1023
|
+
interface CreatePromoCodeParams {
|
|
1024
|
+
code: string;
|
|
1025
|
+
discountType: "percentage" | "amount";
|
|
1026
|
+
discountValue: number;
|
|
1027
|
+
durationCycles?: number;
|
|
1028
|
+
maxRedemptions?: number;
|
|
1029
|
+
expiresAt?: string;
|
|
1030
|
+
planIds?: string[];
|
|
1031
|
+
}
|
|
1032
|
+
interface UpdatePromoCodeParams {
|
|
1033
|
+
id: string;
|
|
1034
|
+
maxRedemptions?: number;
|
|
1035
|
+
expiresAt?: string;
|
|
1036
|
+
active?: boolean;
|
|
1037
|
+
planIds?: string[];
|
|
1038
|
+
}
|
|
1039
|
+
declare class PromoCodesResource {
|
|
1040
|
+
private httpClient;
|
|
1041
|
+
constructor(httpClient: CommetHTTPClient);
|
|
1042
|
+
list(params?: ListPromoCodesParams): Promise<ApiResponse<PromoCode[]>>;
|
|
1043
|
+
get(params: GetPromoCodeParams): Promise<ApiResponse<PromoCodeDetail>>;
|
|
1044
|
+
create(params: CreatePromoCodeParams, options?: RequestOptions): Promise<ApiResponse<PromoCode>>;
|
|
1045
|
+
update(params: UpdatePromoCodeParams, options?: RequestOptions): Promise<ApiResponse<PromoCodeDetail>>;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
interface SeatEvent {
|
|
1049
|
+
id: string;
|
|
1050
|
+
object: "seat";
|
|
1051
|
+
livemode: boolean;
|
|
1052
|
+
organizationId: string;
|
|
1053
|
+
customerId: CustomerID;
|
|
1054
|
+
featureCode: string;
|
|
1055
|
+
eventType: "add" | "remove" | "set";
|
|
1056
|
+
quantity: number;
|
|
1057
|
+
previousBalance?: number;
|
|
1058
|
+
newBalance: number;
|
|
1059
|
+
ts: string;
|
|
1060
|
+
createdAt: string;
|
|
1061
|
+
}
|
|
1062
|
+
interface SeatBalance {
|
|
1063
|
+
current: number;
|
|
1064
|
+
asOf: string;
|
|
1065
|
+
}
|
|
1066
|
+
interface AddSeatsParams {
|
|
1067
|
+
customerId: CustomerID;
|
|
1068
|
+
featureCode: string;
|
|
1069
|
+
count?: number;
|
|
1070
|
+
}
|
|
1071
|
+
interface RemoveSeatsParams {
|
|
1072
|
+
customerId: CustomerID;
|
|
1073
|
+
featureCode: string;
|
|
1074
|
+
count?: number;
|
|
1075
|
+
}
|
|
1076
|
+
interface SetSeatsParams {
|
|
1077
|
+
customerId: CustomerID;
|
|
1078
|
+
featureCode: string;
|
|
1079
|
+
count: number;
|
|
1080
|
+
}
|
|
1081
|
+
interface SetAllSeatsParams {
|
|
1082
|
+
customerId: CustomerID;
|
|
1083
|
+
seats: Record<string, number>;
|
|
1084
|
+
}
|
|
1085
|
+
interface GetBalanceParams {
|
|
1086
|
+
customerId: CustomerID;
|
|
1087
|
+
featureCode: string;
|
|
1088
|
+
}
|
|
1089
|
+
interface GetAllBalancesParams {
|
|
1090
|
+
customerId: CustomerID;
|
|
1091
|
+
}
|
|
1092
|
+
declare class SeatsResource {
|
|
1093
|
+
private httpClient;
|
|
1094
|
+
constructor(httpClient: CommetHTTPClient);
|
|
1095
|
+
/** Prorates charges for the current billing period. */
|
|
1096
|
+
add(params: AddSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
1097
|
+
/** Removal takes effect at the end of the billing period. */
|
|
1098
|
+
remove(params: RemoveSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
1099
|
+
set(params: SetSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
1100
|
+
setAll(params: SetAllSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent[]>>;
|
|
1101
|
+
getBalance(params: GetBalanceParams): Promise<ApiResponse<SeatBalance>>;
|
|
1102
|
+
getAllBalances(params: GetAllBalancesParams): Promise<ApiResponse<Record<string, SeatBalance>>>;
|
|
388
1103
|
}
|
|
389
1104
|
|
|
390
1105
|
type SubscriptionStatus = "draft" | "pending_payment" | "trialing" | "active" | "paused" | "past_due" | "canceled" | "expired";
|
|
@@ -424,6 +1139,8 @@ interface DiscountSummary {
|
|
|
424
1139
|
type ConsumptionModel = "metered" | "credits" | "balance";
|
|
425
1140
|
interface ActiveSubscription {
|
|
426
1141
|
id: string;
|
|
1142
|
+
object: "subscription";
|
|
1143
|
+
livemode: boolean;
|
|
427
1144
|
customerId: string;
|
|
428
1145
|
plan: {
|
|
429
1146
|
id: string;
|
|
@@ -456,6 +1173,8 @@ interface ActiveSubscription {
|
|
|
456
1173
|
}
|
|
457
1174
|
interface CreatedSubscription {
|
|
458
1175
|
id: string;
|
|
1176
|
+
object: "subscription";
|
|
1177
|
+
livemode: boolean;
|
|
459
1178
|
customerId: string;
|
|
460
1179
|
planId: string;
|
|
461
1180
|
planName: string;
|
|
@@ -477,6 +1196,8 @@ interface CreatedSubscription {
|
|
|
477
1196
|
}
|
|
478
1197
|
interface Subscription {
|
|
479
1198
|
id: string;
|
|
1199
|
+
object: "subscription";
|
|
1200
|
+
livemode: boolean;
|
|
480
1201
|
customerId: string;
|
|
481
1202
|
planId: string;
|
|
482
1203
|
planName: string;
|
|
@@ -511,75 +1232,213 @@ type CreateSubscriptionParams = PlanIdentifier & {
|
|
|
511
1232
|
startDate?: string;
|
|
512
1233
|
successUrl?: string;
|
|
513
1234
|
};
|
|
1235
|
+
interface GetActiveParams {
|
|
1236
|
+
customerId: string;
|
|
1237
|
+
}
|
|
514
1238
|
interface CancelParams {
|
|
515
|
-
|
|
1239
|
+
id: string;
|
|
516
1240
|
reason?: string;
|
|
517
1241
|
immediate?: boolean;
|
|
518
1242
|
}
|
|
519
1243
|
interface UncancelParams {
|
|
520
|
-
|
|
1244
|
+
id: string;
|
|
521
1245
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
1246
|
+
interface ChangePlanParams {
|
|
1247
|
+
id: string;
|
|
1248
|
+
newPlanId?: string;
|
|
1249
|
+
newBillingInterval?: BillingInterval;
|
|
1250
|
+
}
|
|
1251
|
+
interface ChangePlanResult {
|
|
1252
|
+
id: string;
|
|
1253
|
+
scheduled: boolean;
|
|
1254
|
+
customerId?: string;
|
|
1255
|
+
previousPlan?: {
|
|
1256
|
+
id: string;
|
|
1257
|
+
name: string;
|
|
1258
|
+
};
|
|
1259
|
+
currentPlan?: {
|
|
1260
|
+
id: string;
|
|
1261
|
+
name: string;
|
|
1262
|
+
price: number;
|
|
1263
|
+
};
|
|
1264
|
+
billingInterval?: string;
|
|
1265
|
+
billing?: {
|
|
1266
|
+
credit: number;
|
|
1267
|
+
creditsApplied: number;
|
|
1268
|
+
charge: number;
|
|
1269
|
+
taxAmount: number;
|
|
1270
|
+
netAmount: number;
|
|
1271
|
+
totalCharged: number;
|
|
1272
|
+
remainingCreditBalance: number;
|
|
1273
|
+
};
|
|
1274
|
+
invoiceId?: string;
|
|
1275
|
+
scheduledFor?: string;
|
|
1276
|
+
changeType?: string;
|
|
1277
|
+
requiresCheckout?: boolean;
|
|
1278
|
+
checkoutUrl?: string;
|
|
1279
|
+
}
|
|
1280
|
+
interface ListSubscriptionsParams extends Record<string, unknown> {
|
|
1281
|
+
customerId?: string;
|
|
1282
|
+
status?: SubscriptionStatus;
|
|
1283
|
+
limit?: number;
|
|
1284
|
+
cursor?: string;
|
|
1285
|
+
}
|
|
1286
|
+
interface SubscriptionListItem {
|
|
1287
|
+
id: string;
|
|
1288
|
+
object: "subscription";
|
|
1289
|
+
livemode: boolean;
|
|
1290
|
+
customerId: string;
|
|
1291
|
+
planId: string;
|
|
1292
|
+
planName: string;
|
|
1293
|
+
name: string;
|
|
1294
|
+
status: SubscriptionStatus;
|
|
1295
|
+
startDate: string;
|
|
1296
|
+
endDate: string;
|
|
1297
|
+
billingDayOfMonth: number;
|
|
1298
|
+
createdAt: string;
|
|
1299
|
+
updatedAt: string;
|
|
1300
|
+
}
|
|
1301
|
+
interface PreviewChangeParams {
|
|
1302
|
+
id: string;
|
|
1303
|
+
planId?: string;
|
|
1304
|
+
billingInterval?: BillingInterval;
|
|
1305
|
+
}
|
|
1306
|
+
interface PreviewChangeResult {
|
|
1307
|
+
currentPlanCredit: number;
|
|
1308
|
+
newPlanCharge: number;
|
|
1309
|
+
estimatedTotal: number;
|
|
1310
|
+
effectiveDate: string;
|
|
1311
|
+
daysRemaining: number;
|
|
1312
|
+
totalDays: number;
|
|
1313
|
+
isUpgrade: boolean;
|
|
1314
|
+
}
|
|
1315
|
+
interface ActivateAddonParams {
|
|
1316
|
+
id: string;
|
|
1317
|
+
addonId: string;
|
|
1318
|
+
}
|
|
1319
|
+
interface ActivateAddonResult {
|
|
1320
|
+
addonId: string;
|
|
1321
|
+
status: string;
|
|
1322
|
+
proratedCharge: number;
|
|
1323
|
+
}
|
|
1324
|
+
interface DeactivateAddonParams {
|
|
1325
|
+
id: string;
|
|
1326
|
+
addonId: string;
|
|
1327
|
+
}
|
|
1328
|
+
interface DeactivateAddonResult {
|
|
1329
|
+
id: string;
|
|
1330
|
+
status: string;
|
|
1331
|
+
deactivatedAt: string;
|
|
1332
|
+
}
|
|
1333
|
+
interface AdjustBalanceParams {
|
|
1334
|
+
id: string;
|
|
1335
|
+
amount: number;
|
|
1336
|
+
reason?: string;
|
|
1337
|
+
type?: "balance" | "credits";
|
|
1338
|
+
}
|
|
1339
|
+
interface AdjustBalanceResult {
|
|
1340
|
+
amount: number;
|
|
1341
|
+
newBalance: number;
|
|
1342
|
+
reason: string | null;
|
|
1343
|
+
}
|
|
1344
|
+
interface TopupBalanceParams {
|
|
1345
|
+
id: string;
|
|
1346
|
+
amount: number;
|
|
1347
|
+
}
|
|
1348
|
+
interface TopupBalanceResult {
|
|
1349
|
+
amount: number;
|
|
1350
|
+
}
|
|
1351
|
+
interface PurchaseCreditsParams {
|
|
1352
|
+
id: string;
|
|
1353
|
+
creditPackId: string;
|
|
1354
|
+
}
|
|
1355
|
+
interface PurchaseCreditsResult {
|
|
1356
|
+
credits: number;
|
|
1357
|
+
}
|
|
1358
|
+
/** Each customer can only have one active subscription at a time. */
|
|
527
1359
|
declare class SubscriptionsResource {
|
|
528
1360
|
private httpClient;
|
|
529
1361
|
constructor(httpClient: CommetHTTPClient);
|
|
530
|
-
/**
|
|
531
|
-
* Create a subscription with a plan
|
|
532
|
-
*
|
|
533
|
-
* @example
|
|
534
|
-
* ```typescript
|
|
535
|
-
* await commet.subscriptions.create({
|
|
536
|
-
* externalId: 'user_123',
|
|
537
|
-
* planCode: 'pro', // autocomplete works after `commet pull`
|
|
538
|
-
* billingInterval: 'yearly',
|
|
539
|
-
* initialSeats: { editor: 5 }
|
|
540
|
-
* });
|
|
541
|
-
* ```
|
|
542
|
-
*/
|
|
1362
|
+
/** Returns a `checkoutUrl` when payment is required before activation. */
|
|
543
1363
|
create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<CreatedSubscription>>;
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* ```typescript
|
|
549
|
-
* const sub = await commet.subscriptions.get('user_123');
|
|
550
|
-
* ```
|
|
551
|
-
*/
|
|
552
|
-
get(customerId: string): Promise<ApiResponse<ActiveSubscription | null>>;
|
|
553
|
-
/**
|
|
554
|
-
* Cancel a subscription
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* ```typescript
|
|
558
|
-
* await commet.subscriptions.cancel({
|
|
559
|
-
* subscriptionId: 'sub_xxx',
|
|
560
|
-
* reason: 'switched_to_competitor'
|
|
561
|
-
* });
|
|
562
|
-
* ```
|
|
563
|
-
*/
|
|
1364
|
+
getActive(params: GetActiveParams): Promise<ApiResponse<ActiveSubscription | null>>;
|
|
1365
|
+
/** Schedules cancellation at period end by default. Set `immediate: true` to cancel now. */
|
|
564
1366
|
cancel(params: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
565
|
-
/**
|
|
566
|
-
* Revert a scheduled cancellation
|
|
567
|
-
*
|
|
568
|
-
* Only works on subscriptions with a pending cancellation (canceledAt is set
|
|
569
|
-
* but status is not yet "canceled"). Cannot revert already-canceled subscriptions.
|
|
570
|
-
*
|
|
571
|
-
* @example
|
|
572
|
-
* ```typescript
|
|
573
|
-
* await commet.subscriptions.uncancel({
|
|
574
|
-
* subscriptionId: 'sub_xxx',
|
|
575
|
-
* });
|
|
576
|
-
* ```
|
|
577
|
-
*/
|
|
1367
|
+
/** Only works on subscriptions with a pending cancellation — cannot revert already-canceled. */
|
|
578
1368
|
uncancel(params: UncancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
1369
|
+
/** Upgrades execute immediately with proration. Downgrades are scheduled for end of period. */
|
|
1370
|
+
changePlan(params: ChangePlanParams, options?: RequestOptions): Promise<ApiResponse<ChangePlanResult>>;
|
|
1371
|
+
list(params?: ListSubscriptionsParams): Promise<ApiResponse<SubscriptionListItem[]>>;
|
|
1372
|
+
/** Dry-run: returns proration details without applying the change. */
|
|
1373
|
+
previewChange(params: PreviewChangeParams, options?: RequestOptions): Promise<ApiResponse<PreviewChangeResult>>;
|
|
1374
|
+
/** Prorated charge for the current billing period. */
|
|
1375
|
+
activateAddon(params: ActivateAddonParams, options?: RequestOptions): Promise<ApiResponse<ActivateAddonResult>>;
|
|
1376
|
+
deactivateAddon(params: DeactivateAddonParams, options?: RequestOptions): Promise<ApiResponse<DeactivateAddonResult>>;
|
|
1377
|
+
/** Positive amount adds, negative subtracts. */
|
|
1378
|
+
adjustBalance(params: AdjustBalanceParams, options?: RequestOptions): Promise<ApiResponse<AdjustBalanceResult>>;
|
|
1379
|
+
/** Charges the customer's payment method. */
|
|
1380
|
+
topupBalance(params: TopupBalanceParams, options?: RequestOptions): Promise<ApiResponse<TopupBalanceResult>>;
|
|
1381
|
+
purchaseCredits(params: PurchaseCreditsParams, options?: RequestOptions): Promise<ApiResponse<PurchaseCreditsResult>>;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
interface TransactionListItem {
|
|
1385
|
+
id: string;
|
|
1386
|
+
object: "transaction";
|
|
1387
|
+
livemode: boolean;
|
|
1388
|
+
invoiceId: string;
|
|
1389
|
+
grossAmount: number;
|
|
1390
|
+
subtotal: number;
|
|
1391
|
+
taxAmount: number;
|
|
1392
|
+
currency: string;
|
|
1393
|
+
status: string;
|
|
1394
|
+
customerEmail: string;
|
|
1395
|
+
customerName: string | null;
|
|
1396
|
+
paidAt: string | null;
|
|
1397
|
+
createdAt: string;
|
|
1398
|
+
updatedAt: string;
|
|
1399
|
+
}
|
|
1400
|
+
interface TransactionDetail extends TransactionListItem {
|
|
1401
|
+
availableAt: string | null;
|
|
1402
|
+
}
|
|
1403
|
+
interface TransactionRefundResult {
|
|
1404
|
+
id: string;
|
|
1405
|
+
status: string;
|
|
1406
|
+
}
|
|
1407
|
+
interface TransactionRetryResult {
|
|
1408
|
+
id: string;
|
|
1409
|
+
status: string;
|
|
1410
|
+
retryInvoiceNumber: string;
|
|
1411
|
+
}
|
|
1412
|
+
interface ListTransactionsParams {
|
|
1413
|
+
status?: string;
|
|
1414
|
+
customerEmail?: string;
|
|
1415
|
+
limit?: number;
|
|
1416
|
+
cursor?: string;
|
|
1417
|
+
}
|
|
1418
|
+
interface GetTransactionParams {
|
|
1419
|
+
id: string;
|
|
1420
|
+
}
|
|
1421
|
+
interface RefundTransactionParams {
|
|
1422
|
+
id: string;
|
|
1423
|
+
}
|
|
1424
|
+
interface RetryTransactionParams {
|
|
1425
|
+
id: string;
|
|
1426
|
+
}
|
|
1427
|
+
declare class TransactionsResource {
|
|
1428
|
+
private httpClient;
|
|
1429
|
+
constructor(httpClient: CommetHTTPClient);
|
|
1430
|
+
list(params?: ListTransactionsParams): Promise<ApiResponse<TransactionListItem[]>>;
|
|
1431
|
+
get(params: GetTransactionParams): Promise<ApiResponse<TransactionDetail>>;
|
|
1432
|
+
/** Full refund only. */
|
|
1433
|
+
refund(params: RefundTransactionParams, options?: RequestOptions): Promise<ApiResponse<TransactionRefundResult>>;
|
|
1434
|
+
/** Creates a new invoice and initiates a new payment attempt. */
|
|
1435
|
+
retry(params: RetryTransactionParams, options?: RequestOptions): Promise<ApiResponse<TransactionRetryResult>>;
|
|
579
1436
|
}
|
|
580
1437
|
|
|
581
1438
|
interface UsageEvent {
|
|
582
1439
|
id: EventID;
|
|
1440
|
+
object: "usage_event";
|
|
1441
|
+
livemode: boolean;
|
|
583
1442
|
organizationId: string;
|
|
584
1443
|
customerId: CustomerID;
|
|
585
1444
|
feature: string;
|
|
@@ -615,162 +1474,42 @@ interface TrackModelTokensParams extends TrackBaseParams {
|
|
|
615
1474
|
value?: never;
|
|
616
1475
|
}
|
|
617
1476
|
type TrackParams = TrackUsageParams | TrackModelTokensParams;
|
|
618
|
-
|
|
619
|
-
private httpClient;
|
|
620
|
-
constructor(httpClient: CommetHTTPClient);
|
|
621
|
-
track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
declare class CustomerContext<TConfig = unknown> {
|
|
625
|
-
private readonly customerId;
|
|
626
|
-
private readonly featuresResource;
|
|
627
|
-
private readonly seatsResource;
|
|
628
|
-
private readonly usageResource;
|
|
629
|
-
private readonly subscriptionsResource;
|
|
630
|
-
private readonly portalResource;
|
|
631
|
-
constructor(customerId: string, resources: {
|
|
632
|
-
features: FeaturesResource;
|
|
633
|
-
seats: SeatsResource;
|
|
634
|
-
usage: UsageResource;
|
|
635
|
-
subscriptions: SubscriptionsResource;
|
|
636
|
-
portal: PortalResource;
|
|
637
|
-
});
|
|
638
|
-
features: {
|
|
639
|
-
get: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
|
|
640
|
-
check: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
|
|
641
|
-
canUse: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
|
|
642
|
-
list: (options?: RequestOptions) => Promise<ApiResponse<FeatureAccess[]>>;
|
|
643
|
-
};
|
|
644
|
-
seats: {
|
|
645
|
-
add: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
646
|
-
remove: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
647
|
-
set: (featureCode: ResolvedSeatCode<TConfig>, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
648
|
-
getBalance: (featureCode: ResolvedSeatCode<TConfig>) => Promise<ApiResponse<SeatBalance>>;
|
|
649
|
-
};
|
|
650
|
-
usage: {
|
|
651
|
-
track: (feature: ResolvedUsageCode<TConfig>, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
|
|
652
|
-
};
|
|
653
|
-
subscription: {
|
|
654
|
-
get: () => Promise<ApiResponse<ActiveSubscription | null>>;
|
|
655
|
-
};
|
|
656
|
-
portal: {
|
|
657
|
-
getUrl: (options?: RequestOptions) => Promise<ApiResponse<PortalAccess>>;
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
interface CreditPack {
|
|
662
|
-
id: string;
|
|
663
|
-
name: string;
|
|
664
|
-
description: string | null;
|
|
665
|
-
credits: number;
|
|
666
|
-
price: number;
|
|
667
|
-
currency: string;
|
|
668
|
-
}
|
|
669
|
-
/**
|
|
670
|
-
* Credit Packs resource for listing available credit packs
|
|
671
|
-
*/
|
|
672
|
-
declare class CreditPacksResource {
|
|
673
|
-
private httpClient;
|
|
674
|
-
constructor(httpClient: CommetHTTPClient);
|
|
675
|
-
/**
|
|
676
|
-
* List all active credit packs
|
|
677
|
-
*
|
|
678
|
-
* @example
|
|
679
|
-
* ```typescript
|
|
680
|
-
* const packs = await commet.creditPacks.list();
|
|
681
|
-
* console.log(packs.data); // [{ id: "cp_xxx", name: "100 Credits", ... }]
|
|
682
|
-
* ```
|
|
683
|
-
*/
|
|
684
|
-
list(): Promise<ApiResponse<CreditPack[]>>;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
interface Customer {
|
|
688
|
-
id: CustomerID;
|
|
689
|
-
organizationId: string;
|
|
690
|
-
externalId?: string;
|
|
691
|
-
fullName?: string;
|
|
692
|
-
domain?: string;
|
|
693
|
-
website?: string;
|
|
694
|
-
billingEmail: string;
|
|
695
|
-
timezone?: string;
|
|
696
|
-
language?: string;
|
|
697
|
-
industry?: string;
|
|
698
|
-
employeeCount?: string;
|
|
699
|
-
metadata?: Record<string, unknown>;
|
|
700
|
-
createdAt: string;
|
|
701
|
-
updatedAt: string;
|
|
702
|
-
}
|
|
703
|
-
interface CustomerAddress {
|
|
704
|
-
line1: string;
|
|
705
|
-
line2?: string;
|
|
706
|
-
city: string;
|
|
707
|
-
state?: string;
|
|
708
|
-
postalCode: string;
|
|
709
|
-
country: string;
|
|
710
|
-
}
|
|
711
|
-
interface CreateParams {
|
|
712
|
-
email: string;
|
|
713
|
-
id?: string;
|
|
714
|
-
fullName?: string;
|
|
715
|
-
domain?: string;
|
|
716
|
-
website?: string;
|
|
717
|
-
timezone?: string;
|
|
718
|
-
language?: string;
|
|
719
|
-
industry?: string;
|
|
720
|
-
metadata?: Record<string, unknown>;
|
|
721
|
-
address?: CustomerAddress;
|
|
722
|
-
}
|
|
723
|
-
interface UpdateParams {
|
|
1477
|
+
interface CheckUsageParams {
|
|
724
1478
|
customerId: CustomerID;
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
domain?: string;
|
|
728
|
-
website?: string;
|
|
729
|
-
timezone?: string;
|
|
730
|
-
language?: string;
|
|
731
|
-
industry?: string;
|
|
732
|
-
metadata?: Record<string, unknown>;
|
|
733
|
-
address?: CustomerAddress;
|
|
734
|
-
}
|
|
735
|
-
interface ListCustomersParams extends ListParams {
|
|
736
|
-
search?: string;
|
|
1479
|
+
featureCode: string;
|
|
1480
|
+
quantity: number;
|
|
737
1481
|
}
|
|
738
|
-
interface
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
1482
|
+
interface UsageCheckResult {
|
|
1483
|
+
allowed: boolean;
|
|
1484
|
+
consumptionModel: string;
|
|
1485
|
+
feature: string;
|
|
1486
|
+
quantity: number;
|
|
1487
|
+
current?: number;
|
|
1488
|
+
remaining?: number;
|
|
1489
|
+
unlimited?: boolean;
|
|
1490
|
+
included?: number;
|
|
1491
|
+
overageEnabled?: boolean;
|
|
1492
|
+
overageUnitPrice?: number | null;
|
|
1493
|
+
creditsPerUnit?: number;
|
|
1494
|
+
estimatedCredits?: number;
|
|
1495
|
+
planCredits?: number;
|
|
1496
|
+
purchasedCredits?: number;
|
|
1497
|
+
totalCredits?: number;
|
|
1498
|
+
unitPrice?: number;
|
|
1499
|
+
estimatedAmount?: number;
|
|
1500
|
+
currentBalance?: number;
|
|
1501
|
+
blockOnExhaustion?: boolean;
|
|
1502
|
+
currency?: string;
|
|
1503
|
+
reason?: string;
|
|
1504
|
+
message?: string;
|
|
745
1505
|
}
|
|
746
|
-
|
|
747
|
-
* Customers resource - Manage your customers
|
|
748
|
-
*/
|
|
749
|
-
declare class CustomersResource {
|
|
1506
|
+
declare class UsageResource {
|
|
750
1507
|
private httpClient;
|
|
751
1508
|
constructor(httpClient: CommetHTTPClient);
|
|
752
|
-
/**
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
* Create multiple customers in batch
|
|
758
|
-
*/
|
|
759
|
-
createBatch(params: {
|
|
760
|
-
customers: CreateParams[];
|
|
761
|
-
}, options?: RequestOptions): Promise<ApiResponse<BatchResult>>;
|
|
762
|
-
/**
|
|
763
|
-
* Get a customer by ID
|
|
764
|
-
*/
|
|
765
|
-
get(customerId: CustomerID): Promise<ApiResponse<Customer>>;
|
|
766
|
-
/**
|
|
767
|
-
* Update a customer
|
|
768
|
-
*/
|
|
769
|
-
update(params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
770
|
-
/**
|
|
771
|
-
* List customers with optional filters
|
|
772
|
-
*/
|
|
773
|
-
list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>>;
|
|
1509
|
+
/** Deducts from balance/credits if the plan uses consumption. Duplicate `idempotencyKey` is rejected. */
|
|
1510
|
+
track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
1511
|
+
/** Dry-run: checks if a usage event would be allowed without actually tracking it. */
|
|
1512
|
+
check(params: CheckUsageParams, options?: RequestOptions): Promise<ApiResponse<UsageCheckResult>>;
|
|
774
1513
|
}
|
|
775
1514
|
|
|
776
1515
|
/**
|
|
@@ -795,7 +1534,6 @@ interface WebhookData {
|
|
|
795
1534
|
publicId?: string;
|
|
796
1535
|
subscriptionId?: string;
|
|
797
1536
|
customerId?: string;
|
|
798
|
-
externalId?: string;
|
|
799
1537
|
/**
|
|
800
1538
|
* Subscription status. Present on `subscription.*` events.
|
|
801
1539
|
* Grant access when this is `"active"` or `"trialing"`.
|
|
@@ -819,112 +1557,80 @@ interface VerifyAndParseParams {
|
|
|
819
1557
|
signature: string | null;
|
|
820
1558
|
secret: string;
|
|
821
1559
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1560
|
+
interface WebhookEndpoint {
|
|
1561
|
+
id: string;
|
|
1562
|
+
object: "webhook_endpoint";
|
|
1563
|
+
livemode: boolean;
|
|
1564
|
+
url: string;
|
|
1565
|
+
events: string[];
|
|
1566
|
+
description: string | null;
|
|
1567
|
+
isActive: boolean;
|
|
1568
|
+
createdAt: string;
|
|
1569
|
+
}
|
|
1570
|
+
interface WebhookEndpointCreated extends WebhookEndpoint {
|
|
1571
|
+
secretKey: string;
|
|
1572
|
+
}
|
|
1573
|
+
interface WebhookTestResult {
|
|
1574
|
+
success: boolean;
|
|
1575
|
+
deliveredAt: string;
|
|
1576
|
+
}
|
|
1577
|
+
interface ListWebhooksParams {
|
|
1578
|
+
limit?: number;
|
|
1579
|
+
cursor?: string;
|
|
1580
|
+
}
|
|
1581
|
+
interface CreateWebhookParams {
|
|
1582
|
+
url: string;
|
|
1583
|
+
events: string[];
|
|
1584
|
+
description?: string;
|
|
1585
|
+
}
|
|
1586
|
+
interface DeleteWebhookParams {
|
|
1587
|
+
id: string;
|
|
1588
|
+
}
|
|
1589
|
+
interface TestWebhookParams {
|
|
1590
|
+
id: string;
|
|
1591
|
+
}
|
|
825
1592
|
declare class Webhooks {
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
* Use this method to verify that webhooks are authentically from Commet.
|
|
830
|
-
* The signature is included in the `X-Commet-Signature` header.
|
|
831
|
-
*
|
|
832
|
-
* @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)
|
|
833
|
-
* @param signature - Value from X-Commet-Signature header
|
|
834
|
-
* @param secret - Your webhook secret from Commet dashboard
|
|
835
|
-
* @returns true if signature is valid, false otherwise
|
|
836
|
-
*
|
|
837
|
-
* @example
|
|
838
|
-
* ```typescript
|
|
839
|
-
* // Next.js API route example
|
|
840
|
-
* export async function POST(request: Request) {
|
|
841
|
-
* const rawBody = await request.text();
|
|
842
|
-
* const signature = request.headers.get('x-commet-signature');
|
|
843
|
-
*
|
|
844
|
-
* const isValid = commet.webhooks.verify(
|
|
845
|
-
* rawBody,
|
|
846
|
-
* signature,
|
|
847
|
-
* process.env.COMMET_WEBHOOK_SECRET
|
|
848
|
-
* );
|
|
849
|
-
*
|
|
850
|
-
* if (!isValid) {
|
|
851
|
-
* return new Response('Invalid signature', { status: 401 });
|
|
852
|
-
* }
|
|
853
|
-
*
|
|
854
|
-
* const payload = JSON.parse(rawBody);
|
|
855
|
-
* // Handle webhook event...
|
|
856
|
-
* }
|
|
857
|
-
* ```
|
|
858
|
-
*/
|
|
1593
|
+
private httpClient?;
|
|
1594
|
+
constructor(httpClient?: CommetHTTPClient | undefined);
|
|
1595
|
+
/** HMAC-SHA256 verification. Payload must be the raw request body string, not parsed JSON. */
|
|
859
1596
|
verify(params: VerifyParams): boolean;
|
|
860
|
-
/**
|
|
861
|
-
* Generate HMAC-SHA256 signature (internal use)
|
|
862
|
-
* @internal
|
|
863
|
-
*/
|
|
864
1597
|
private generateSignature;
|
|
865
|
-
/**
|
|
866
|
-
* Parse and verify webhook payload in one step
|
|
867
|
-
*
|
|
868
|
-
* @example
|
|
869
|
-
* ```typescript
|
|
870
|
-
* const payload = commet.webhooks.verifyAndParse({
|
|
871
|
-
* rawBody,
|
|
872
|
-
* signature,
|
|
873
|
-
* secret: process.env.COMMET_WEBHOOK_SECRET
|
|
874
|
-
* });
|
|
875
|
-
*
|
|
876
|
-
* if (!payload) {
|
|
877
|
-
* return new Response('Invalid signature', { status: 401 });
|
|
878
|
-
* }
|
|
879
|
-
*
|
|
880
|
-
* // payload is typed and validated
|
|
881
|
-
* if (payload.event === 'subscription.activated') {
|
|
882
|
-
* // Handle activation...
|
|
883
|
-
* }
|
|
884
|
-
* ```
|
|
885
|
-
*/
|
|
1598
|
+
/** Verifies signature and parses JSON in one step. Returns null if invalid. */
|
|
886
1599
|
verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null;
|
|
1600
|
+
list(params?: ListWebhooksParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpoint[]>>;
|
|
1601
|
+
/** Response includes `secretKey` which is only returned once. */
|
|
1602
|
+
create(params: CreateWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpointCreated>>;
|
|
1603
|
+
delete(params: DeleteWebhookParams, options?: RequestOptions): Promise<ApiResponse<{
|
|
1604
|
+
id: string;
|
|
1605
|
+
deleted: true;
|
|
1606
|
+
}>>;
|
|
1607
|
+
test(params: TestWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookTestResult>>;
|
|
887
1608
|
}
|
|
888
1609
|
|
|
889
|
-
|
|
890
|
-
* Main Commet SDK client
|
|
891
|
-
*/
|
|
892
|
-
declare class Commet<TConfig = unknown> {
|
|
1610
|
+
declare class Commet<_TConfig = unknown> {
|
|
893
1611
|
private httpClient;
|
|
894
|
-
readonly
|
|
1612
|
+
readonly addons: AddonsResource;
|
|
1613
|
+
readonly apiKeys: ApiKeysResource;
|
|
895
1614
|
readonly creditPacks: CreditPacksResource;
|
|
1615
|
+
readonly customers: CustomersResource;
|
|
1616
|
+
readonly features: FeaturesResource;
|
|
1617
|
+
readonly invoices: InvoicesResource;
|
|
1618
|
+
readonly planGroups: PlanGroupsResource;
|
|
896
1619
|
readonly plans: PlansResource;
|
|
897
|
-
readonly
|
|
1620
|
+
readonly portal: PortalResource;
|
|
1621
|
+
readonly promoCodes: PromoCodesResource;
|
|
898
1622
|
readonly seats: SeatsResource;
|
|
899
1623
|
readonly subscriptions: SubscriptionsResource;
|
|
900
|
-
readonly
|
|
901
|
-
readonly
|
|
1624
|
+
readonly transactions: TransactionsResource;
|
|
1625
|
+
readonly usage: UsageResource;
|
|
902
1626
|
readonly webhooks: Webhooks;
|
|
903
1627
|
constructor(config: CommetClientOptions);
|
|
904
|
-
/**
|
|
905
|
-
* Create a customer-scoped context for cleaner API usage
|
|
906
|
-
*
|
|
907
|
-
* @example
|
|
908
|
-
* ```typescript
|
|
909
|
-
* const customer = commet.customer("user_123");
|
|
910
|
-
*
|
|
911
|
-
* // All operations are now scoped to this customer
|
|
912
|
-
* const seats = await customer.features.get("team_members");
|
|
913
|
-
* await customer.seats.add("member");
|
|
914
|
-
* await customer.usage.track("api_call");
|
|
915
|
-
* ```
|
|
916
|
-
*/
|
|
917
|
-
customer(customerId: string): CustomerContext<TConfig>;
|
|
918
1628
|
}
|
|
919
1629
|
declare function createCommet<const TConfig extends BillingConfig>(_billingConfig: TConfig, options: CommetClientOptions): Commet<TConfig>;
|
|
920
1630
|
|
|
921
1631
|
declare function registerIntegration(name: string, version: string): void;
|
|
922
1632
|
|
|
923
|
-
declare const API_VERSION = "2026-05-
|
|
1633
|
+
declare const API_VERSION = "2026-05-25";
|
|
924
1634
|
declare const SDK_VERSION: string;
|
|
925
1635
|
|
|
926
|
-
|
|
927
|
-
* Commet SDK - Billing and usage tracking for SaaS
|
|
928
|
-
*/
|
|
929
|
-
|
|
930
|
-
export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetClientOptions, type CommetConfig, CommetError, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureValue, type PlanID, type PlanPrice, type PortalAccess, type PriceDef, type RemoveParams as RemoveSeatsParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
|
1636
|
+
export { API_VERSION, type ActivateAddonParams, type ActivateAddonResult, type ActiveAddon, type ActiveSubscription, type AddAiModelPricingFeatureParams, type AddFixedPricingFeatureParams, type AddPlanFeatureParams, type AddPlanPriceParams, type AddPlanToGroupParams, type AddSeatsParams, type Addon, type AdjustBalanceParams, type AdjustBalanceResult, type AiModelPricingFeatureManage, type ApiErrorDetail, type ApiKey, type ApiKeyCreated, type ApiResponse, type BalanceAddon, type BillingConfig, type BillingInterval, type BooleanAddon, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type ChangePlanParams, type ChangePlanResult, type CheckUsageParams, Commet, CommetAPIError, type CommetClientOptions, CommetError, CommetValidationError, type CreateAddonParams, type CreateAdjustmentParams, type CreateAdjustmentResult, type CreateApiKeyParams, type CreateBalanceAddonParams, type CreateBooleanAddonParams, type CreateCreditPackParams, type CreateCreditsAddonParams, type CreateParams as CreateCustomerParams, type CreateFeatureParams, type CreateMeteredAddonParams, type CreatePlanGroupParams, type CreatePlanParams, type CreatePromoCodeParams, type CreateSubscriptionParams, type CreateWebhookParams, type CreatedSubscription, type CreditPack, type CreditPackDetail, type CreditsAddon, type Currency, type Customer, type CustomerAddress, type CustomerID, type BatchResult as CustomersBatchResult, type DeactivateAddonParams, type DeactivateAddonResult, type DeleteAddonParams, type DeleteApiKeyParams, type DeleteCreditPackParams, type DeleteFeatureParams, type DeletePlanGroupParams, type DeletePlanParams, type DeletePlanPriceParams, type DeleteRegionalPricesParams, type DeleteResult, type DeleteWebhookParams, type DiscountSummary, type EventID, type Feature, type FeatureAccess, type FeatureDef, type FeatureSummary, type FeatureType, type FixedPricingFeatureManage, type GetActiveParams, type GetAddonParams, type GetAllBalancesParams, type GetBalanceParams, type GetCustomerParams, type GetDownloadUrlParams, type GetFeatureParams, type GetInvoiceParams, type GetPlanGroupParams, type GetPromoCodeParams, type GetTransactionParams, type GetUrlParams, type InferFeatureCodes, type InferPlanCodes, type InferSeatCodes, type InferUsageCodes, type InvoiceDetail, type InvoiceDownloadResult, type InvoiceLineItem, type InvoiceListItem, type InvoiceSendResult, type InvoiceStatusResult, type ListActiveAddonsParams, type ListAddonsParams, type ListApiKeysParams, type ListCustomersParams, type ListFeaturesParams, type ListInvoicesParams, type ListPlanGroupsParams, type ListPlansParams, type ListPromoCodesParams, type ListSubscriptionsParams, type ListTransactionsParams, type ListWebhooksParams, type MeteredAddon, type PaginatedList, type PaginatedResponse, type Plan, type PlanDef, type PlanDetail, type PlanFeature, type PlanFeatureManage, type PlanFeatureValue, type PlanGroup, type PlanGroupDetail, type PlanID, type PlanManage, type PlanPrice, type PlanPriceManage, type PortalAccess, type PreviewChangeParams, type PreviewChangeResult, type PriceDef, type PromoCode, type PromoCodeDetail, type PurchaseCreditsParams, type PurchaseCreditsResult, type RefundTransactionParams, type RegionalPriceResult, type RemovePlanFeatureParams, type RemovePlanFromGroupParams, type RemoveResult, type RemoveSeatsParams, type ReorderPlansParams, type RequestOptions, type ResolvedFeatureCode, type ResolvedPlanCode, type ResolvedSeatCode, type ResolvedUsageCode, type RetryTransactionParams, SDK_VERSION, type SeatBalance, type SeatEvent, type SendInvoiceParams, type SetAllSeatsParams, type SetDefaultPriceParams, type SetRegionalPricesParams, type SetSeatsParams, type SetVisibilityParams, type Subscription, type SubscriptionListItem, type SubscriptionStatus, type TestWebhookParams, type TopupBalanceParams, type TopupBalanceResult, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type TransactionDetail, type TransactionListItem, type TransactionRefundResult, type TransactionRetryResult, type UncancelParams, type UpdateAddonParams, type UpdateCreditPackParams, type UpdateParams as UpdateCustomerParams, type UpdateFeatureParams, type UpdateInvoiceStatusParams, type UpdatePlanFeatureParams, type UpdatePlanGroupParams, type UpdatePlanParams, type UpdatePlanPriceParams, type UpdatePromoCodeParams, type UsageCheckResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEndpoint, type WebhookEndpointCreated, type WebhookEvent, type WebhookPayload, type WebhookTestResult, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|