@commet/node 4.6.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.d.mts +1059 -460
- package/dist/index.d.ts +1059 -460
- package/dist/index.js +439 -350
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +442 -352
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
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,16 +1232,19 @@ 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
1246
|
interface ChangePlanParams {
|
|
523
|
-
|
|
1247
|
+
id: string;
|
|
524
1248
|
newPlanId?: string;
|
|
525
1249
|
newBillingInterval?: BillingInterval;
|
|
526
1250
|
}
|
|
@@ -553,81 +1277,168 @@ interface ChangePlanResult {
|
|
|
553
1277
|
requiresCheckout?: boolean;
|
|
554
1278
|
checkoutUrl?: string;
|
|
555
1279
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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. */
|
|
561
1359
|
declare class SubscriptionsResource {
|
|
562
1360
|
private httpClient;
|
|
563
1361
|
constructor(httpClient: CommetHTTPClient);
|
|
564
|
-
/**
|
|
565
|
-
* Create a subscription with a plan
|
|
566
|
-
*
|
|
567
|
-
* @example
|
|
568
|
-
* ```typescript
|
|
569
|
-
* await commet.subscriptions.create({
|
|
570
|
-
* externalId: 'user_123',
|
|
571
|
-
* planCode: 'pro', // autocomplete works after `commet pull`
|
|
572
|
-
* billingInterval: 'yearly',
|
|
573
|
-
* initialSeats: { editor: 5 }
|
|
574
|
-
* });
|
|
575
|
-
* ```
|
|
576
|
-
*/
|
|
1362
|
+
/** Returns a `checkoutUrl` when payment is required before activation. */
|
|
577
1363
|
create(params: CreateSubscriptionParams, options?: RequestOptions): Promise<ApiResponse<CreatedSubscription>>;
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
*
|
|
581
|
-
* @example
|
|
582
|
-
* ```typescript
|
|
583
|
-
* const sub = await commet.subscriptions.get('user_123');
|
|
584
|
-
* ```
|
|
585
|
-
*/
|
|
586
|
-
get(customerId: string): Promise<ApiResponse<ActiveSubscription | null>>;
|
|
587
|
-
/**
|
|
588
|
-
* Cancel a subscription
|
|
589
|
-
*
|
|
590
|
-
* @example
|
|
591
|
-
* ```typescript
|
|
592
|
-
* await commet.subscriptions.cancel({
|
|
593
|
-
* subscriptionId: 'sub_xxx',
|
|
594
|
-
* reason: 'switched_to_competitor'
|
|
595
|
-
* });
|
|
596
|
-
* ```
|
|
597
|
-
*/
|
|
1364
|
+
getActive(params: GetActiveParams): Promise<ApiResponse<ActiveSubscription | null>>;
|
|
1365
|
+
/** Schedules cancellation at period end by default. Set `immediate: true` to cancel now. */
|
|
598
1366
|
cancel(params: CancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
599
|
-
/**
|
|
600
|
-
* Revert a scheduled cancellation
|
|
601
|
-
*
|
|
602
|
-
* Only works on subscriptions with a pending cancellation (canceledAt is set
|
|
603
|
-
* but status is not yet "canceled"). Cannot revert already-canceled subscriptions.
|
|
604
|
-
*
|
|
605
|
-
* @example
|
|
606
|
-
* ```typescript
|
|
607
|
-
* await commet.subscriptions.uncancel({
|
|
608
|
-
* subscriptionId: 'sub_xxx',
|
|
609
|
-
* });
|
|
610
|
-
* ```
|
|
611
|
-
*/
|
|
1367
|
+
/** Only works on subscriptions with a pending cancellation — cannot revert already-canceled. */
|
|
612
1368
|
uncancel(params: UncancelParams, options?: RequestOptions): Promise<ApiResponse<Subscription>>;
|
|
613
|
-
/**
|
|
614
|
-
* Change the plan of a subscription (upgrade/downgrade)
|
|
615
|
-
*
|
|
616
|
-
* Upgrades execute immediately. Downgrades are scheduled for end of period.
|
|
617
|
-
*
|
|
618
|
-
* @example
|
|
619
|
-
* ```typescript
|
|
620
|
-
* await commet.subscriptions.changePlan({
|
|
621
|
-
* subscriptionId: 'sub_xxx',
|
|
622
|
-
* newPlanId: 'pln_xxx',
|
|
623
|
-
* });
|
|
624
|
-
* ```
|
|
625
|
-
*/
|
|
1369
|
+
/** Upgrades execute immediately with proration. Downgrades are scheduled for end of period. */
|
|
626
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>>;
|
|
627
1436
|
}
|
|
628
1437
|
|
|
629
1438
|
interface UsageEvent {
|
|
630
1439
|
id: EventID;
|
|
1440
|
+
object: "usage_event";
|
|
1441
|
+
livemode: boolean;
|
|
631
1442
|
organizationId: string;
|
|
632
1443
|
customerId: CustomerID;
|
|
633
1444
|
feature: string;
|
|
@@ -695,206 +1506,12 @@ interface UsageCheckResult {
|
|
|
695
1506
|
declare class UsageResource {
|
|
696
1507
|
private httpClient;
|
|
697
1508
|
constructor(httpClient: CommetHTTPClient);
|
|
1509
|
+
/** Deducts from balance/credits if the plan uses consumption. Duplicate `idempotencyKey` is rejected. */
|
|
698
1510
|
track(params: TrackParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
699
|
-
/**
|
|
700
|
-
* Check if a usage event would be allowed before tracking it
|
|
701
|
-
*
|
|
702
|
-
* @example
|
|
703
|
-
* ```typescript
|
|
704
|
-
* const { data } = await commet.usage.check({
|
|
705
|
-
* customerId: 'cus_xxx',
|
|
706
|
-
* featureCode: 'api_calls',
|
|
707
|
-
* quantity: 1,
|
|
708
|
-
* });
|
|
709
|
-
* if (data.allowed) {
|
|
710
|
-
* // proceed with the operation
|
|
711
|
-
* }
|
|
712
|
-
* ```
|
|
713
|
-
*/
|
|
1511
|
+
/** Dry-run: checks if a usage event would be allowed without actually tracking it. */
|
|
714
1512
|
check(params: CheckUsageParams, options?: RequestOptions): Promise<ApiResponse<UsageCheckResult>>;
|
|
715
1513
|
}
|
|
716
1514
|
|
|
717
|
-
declare class CustomerContext<TConfig = unknown> {
|
|
718
|
-
private readonly customerId;
|
|
719
|
-
private readonly featuresResource;
|
|
720
|
-
private readonly seatsResource;
|
|
721
|
-
private readonly usageResource;
|
|
722
|
-
private readonly subscriptionsResource;
|
|
723
|
-
private readonly portalResource;
|
|
724
|
-
constructor(customerId: string, resources: {
|
|
725
|
-
features: FeaturesResource;
|
|
726
|
-
seats: SeatsResource;
|
|
727
|
-
usage: UsageResource;
|
|
728
|
-
subscriptions: SubscriptionsResource;
|
|
729
|
-
portal: PortalResource;
|
|
730
|
-
});
|
|
731
|
-
features: {
|
|
732
|
-
get: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<FeatureAccess>>;
|
|
733
|
-
check: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CheckResult>>;
|
|
734
|
-
canUse: (code: ResolvedFeatureCode<TConfig>, options?: RequestOptions) => Promise<ApiResponse<CanUseResult>>;
|
|
735
|
-
list: (options?: RequestOptions) => Promise<ApiResponse<FeatureAccess[]>>;
|
|
736
|
-
};
|
|
737
|
-
seats: {
|
|
738
|
-
add: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
739
|
-
remove: (featureCode: ResolvedSeatCode<TConfig>, count?: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
740
|
-
set: (featureCode: ResolvedSeatCode<TConfig>, count: number, options?: RequestOptions) => Promise<ApiResponse<SeatEvent>>;
|
|
741
|
-
getBalance: (featureCode: ResolvedSeatCode<TConfig>) => Promise<ApiResponse<SeatBalance>>;
|
|
742
|
-
};
|
|
743
|
-
usage: {
|
|
744
|
-
track: (feature: ResolvedUsageCode<TConfig>, value?: number, properties?: Record<string, string>, options?: RequestOptions) => Promise<ApiResponse<UsageEvent>>;
|
|
745
|
-
};
|
|
746
|
-
subscription: {
|
|
747
|
-
get: () => Promise<ApiResponse<ActiveSubscription | null>>;
|
|
748
|
-
};
|
|
749
|
-
portal: {
|
|
750
|
-
getUrl: (options?: RequestOptions) => Promise<ApiResponse<PortalAccess>>;
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
interface ActiveAddon {
|
|
755
|
-
slug: string;
|
|
756
|
-
name: string;
|
|
757
|
-
basePrice: number;
|
|
758
|
-
featureCode: string;
|
|
759
|
-
featureName: string;
|
|
760
|
-
featureType: string;
|
|
761
|
-
consumptionModel: string | null;
|
|
762
|
-
activatedAt: string;
|
|
763
|
-
}
|
|
764
|
-
interface GetActiveAddonsParams {
|
|
765
|
-
customerId: CustomerID;
|
|
766
|
-
}
|
|
767
|
-
declare class AddonsResource {
|
|
768
|
-
private httpClient;
|
|
769
|
-
constructor(httpClient: CommetHTTPClient);
|
|
770
|
-
/**
|
|
771
|
-
* Get active addons for a customer's subscription
|
|
772
|
-
*
|
|
773
|
-
* @example
|
|
774
|
-
* ```typescript
|
|
775
|
-
* const { data } = await commet.addons.getActive({
|
|
776
|
-
* customerId: 'cus_xxx',
|
|
777
|
-
* });
|
|
778
|
-
* ```
|
|
779
|
-
*/
|
|
780
|
-
getActive(params: GetActiveAddonsParams, options?: RequestOptions): Promise<ApiResponse<ActiveAddon[]>>;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
interface CreditPack {
|
|
784
|
-
id: string;
|
|
785
|
-
name: string;
|
|
786
|
-
description: string | null;
|
|
787
|
-
credits: number;
|
|
788
|
-
price: number;
|
|
789
|
-
currency: string;
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Credit Packs resource for listing available credit packs
|
|
793
|
-
*/
|
|
794
|
-
declare class CreditPacksResource {
|
|
795
|
-
private httpClient;
|
|
796
|
-
constructor(httpClient: CommetHTTPClient);
|
|
797
|
-
/**
|
|
798
|
-
* List all active credit packs
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* ```typescript
|
|
802
|
-
* const packs = await commet.creditPacks.list();
|
|
803
|
-
* console.log(packs.data); // [{ id: "cp_xxx", name: "100 Credits", ... }]
|
|
804
|
-
* ```
|
|
805
|
-
*/
|
|
806
|
-
list(): Promise<ApiResponse<CreditPack[]>>;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
interface Customer {
|
|
810
|
-
id: CustomerID;
|
|
811
|
-
organizationId: string;
|
|
812
|
-
externalId?: string;
|
|
813
|
-
fullName?: string;
|
|
814
|
-
domain?: string;
|
|
815
|
-
website?: string;
|
|
816
|
-
billingEmail: string;
|
|
817
|
-
timezone?: string;
|
|
818
|
-
language?: string;
|
|
819
|
-
industry?: string;
|
|
820
|
-
employeeCount?: string;
|
|
821
|
-
metadata?: Record<string, unknown>;
|
|
822
|
-
createdAt: string;
|
|
823
|
-
updatedAt: string;
|
|
824
|
-
}
|
|
825
|
-
interface CustomerAddress {
|
|
826
|
-
line1: string;
|
|
827
|
-
line2?: string;
|
|
828
|
-
city: string;
|
|
829
|
-
state?: string;
|
|
830
|
-
postalCode: string;
|
|
831
|
-
country: string;
|
|
832
|
-
}
|
|
833
|
-
interface CreateParams {
|
|
834
|
-
email: string;
|
|
835
|
-
id?: string;
|
|
836
|
-
fullName?: string;
|
|
837
|
-
domain?: string;
|
|
838
|
-
website?: string;
|
|
839
|
-
timezone?: string;
|
|
840
|
-
language?: string;
|
|
841
|
-
industry?: string;
|
|
842
|
-
metadata?: Record<string, unknown>;
|
|
843
|
-
address?: CustomerAddress;
|
|
844
|
-
}
|
|
845
|
-
interface UpdateParams {
|
|
846
|
-
customerId: CustomerID;
|
|
847
|
-
email?: string;
|
|
848
|
-
fullName?: string;
|
|
849
|
-
domain?: string;
|
|
850
|
-
website?: string;
|
|
851
|
-
timezone?: string;
|
|
852
|
-
language?: string;
|
|
853
|
-
industry?: string;
|
|
854
|
-
metadata?: Record<string, unknown>;
|
|
855
|
-
address?: CustomerAddress;
|
|
856
|
-
}
|
|
857
|
-
interface ListCustomersParams extends ListParams {
|
|
858
|
-
search?: string;
|
|
859
|
-
}
|
|
860
|
-
interface BatchResult {
|
|
861
|
-
successful: Customer[];
|
|
862
|
-
failed: Array<{
|
|
863
|
-
index: number;
|
|
864
|
-
error: string;
|
|
865
|
-
data: CreateParams;
|
|
866
|
-
}>;
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Customers resource - Manage your customers
|
|
870
|
-
*/
|
|
871
|
-
declare class CustomersResource {
|
|
872
|
-
private httpClient;
|
|
873
|
-
constructor(httpClient: CommetHTTPClient);
|
|
874
|
-
/**
|
|
875
|
-
* Create a customer (idempotent when id is provided)
|
|
876
|
-
*/
|
|
877
|
-
create(params: CreateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
878
|
-
/**
|
|
879
|
-
* Create multiple customers in batch
|
|
880
|
-
*/
|
|
881
|
-
createBatch(params: {
|
|
882
|
-
customers: CreateParams[];
|
|
883
|
-
}, options?: RequestOptions): Promise<ApiResponse<BatchResult>>;
|
|
884
|
-
/**
|
|
885
|
-
* Get a customer by ID
|
|
886
|
-
*/
|
|
887
|
-
get(customerId: CustomerID): Promise<ApiResponse<Customer>>;
|
|
888
|
-
/**
|
|
889
|
-
* Update a customer
|
|
890
|
-
*/
|
|
891
|
-
update(params: UpdateParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
|
|
892
|
-
/**
|
|
893
|
-
* List customers with optional filters
|
|
894
|
-
*/
|
|
895
|
-
list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>>;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
1515
|
/**
|
|
899
1516
|
* Webhook payload structure from Commet
|
|
900
1517
|
*/
|
|
@@ -902,6 +1519,8 @@ interface WebhookPayload {
|
|
|
902
1519
|
event: WebhookEvent;
|
|
903
1520
|
timestamp: string;
|
|
904
1521
|
organizationId: string;
|
|
1522
|
+
mode: "live" | "sandbox";
|
|
1523
|
+
apiVersion: string;
|
|
905
1524
|
data: WebhookData;
|
|
906
1525
|
}
|
|
907
1526
|
/**
|
|
@@ -913,11 +1532,9 @@ interface WebhookPayload {
|
|
|
913
1532
|
* granting access.
|
|
914
1533
|
*/
|
|
915
1534
|
interface WebhookData {
|
|
916
|
-
id?: string;
|
|
917
1535
|
publicId?: string;
|
|
918
1536
|
subscriptionId?: string;
|
|
919
1537
|
customerId?: string;
|
|
920
|
-
externalId?: string;
|
|
921
1538
|
/**
|
|
922
1539
|
* Subscription status. Present on `subscription.*` events.
|
|
923
1540
|
* Grant access when this is `"active"` or `"trialing"`.
|
|
@@ -941,113 +1558,95 @@ interface VerifyAndParseParams {
|
|
|
941
1558
|
signature: string | null;
|
|
942
1559
|
secret: string;
|
|
943
1560
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1561
|
+
interface WebhookEndpoint {
|
|
1562
|
+
id: string;
|
|
1563
|
+
object: "webhook";
|
|
1564
|
+
livemode: boolean;
|
|
1565
|
+
url: string;
|
|
1566
|
+
events: string[];
|
|
1567
|
+
description: string | null;
|
|
1568
|
+
isActive: boolean;
|
|
1569
|
+
apiVersion: string | null;
|
|
1570
|
+
createdAt: string;
|
|
1571
|
+
}
|
|
1572
|
+
interface WebhookEndpointCreated extends WebhookEndpoint {
|
|
1573
|
+
secretKey: string;
|
|
1574
|
+
}
|
|
1575
|
+
interface WebhookTestResult {
|
|
1576
|
+
success: boolean;
|
|
1577
|
+
deliveryId: string;
|
|
1578
|
+
deliveredAt: string;
|
|
1579
|
+
}
|
|
1580
|
+
interface ListWebhooksParams {
|
|
1581
|
+
limit?: number;
|
|
1582
|
+
cursor?: string;
|
|
1583
|
+
}
|
|
1584
|
+
interface CreateWebhookParams {
|
|
1585
|
+
url: string;
|
|
1586
|
+
events: string[];
|
|
1587
|
+
description?: string;
|
|
1588
|
+
apiVersion?: string;
|
|
1589
|
+
}
|
|
1590
|
+
interface GetWebhookParams {
|
|
1591
|
+
id: string;
|
|
1592
|
+
}
|
|
1593
|
+
interface UpdateWebhookParams {
|
|
1594
|
+
id: string;
|
|
1595
|
+
url?: string;
|
|
1596
|
+
events?: string[];
|
|
1597
|
+
description?: string | null;
|
|
1598
|
+
isActive?: boolean;
|
|
1599
|
+
apiVersion?: string;
|
|
1600
|
+
}
|
|
1601
|
+
interface DeleteWebhookParams {
|
|
1602
|
+
id: string;
|
|
1603
|
+
}
|
|
1604
|
+
interface TestWebhookParams {
|
|
1605
|
+
id: string;
|
|
1606
|
+
}
|
|
947
1607
|
declare class Webhooks {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
* Use this method to verify that webhooks are authentically from Commet.
|
|
952
|
-
* The signature is included in the `X-Commet-Signature` header.
|
|
953
|
-
*
|
|
954
|
-
* @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)
|
|
955
|
-
* @param signature - Value from X-Commet-Signature header
|
|
956
|
-
* @param secret - Your webhook secret from Commet dashboard
|
|
957
|
-
* @returns true if signature is valid, false otherwise
|
|
958
|
-
*
|
|
959
|
-
* @example
|
|
960
|
-
* ```typescript
|
|
961
|
-
* // Next.js API route example
|
|
962
|
-
* export async function POST(request: Request) {
|
|
963
|
-
* const rawBody = await request.text();
|
|
964
|
-
* const signature = request.headers.get('x-commet-signature');
|
|
965
|
-
*
|
|
966
|
-
* const isValid = commet.webhooks.verify(
|
|
967
|
-
* rawBody,
|
|
968
|
-
* signature,
|
|
969
|
-
* process.env.COMMET_WEBHOOK_SECRET
|
|
970
|
-
* );
|
|
971
|
-
*
|
|
972
|
-
* if (!isValid) {
|
|
973
|
-
* return new Response('Invalid signature', { status: 401 });
|
|
974
|
-
* }
|
|
975
|
-
*
|
|
976
|
-
* const payload = JSON.parse(rawBody);
|
|
977
|
-
* // Handle webhook event...
|
|
978
|
-
* }
|
|
979
|
-
* ```
|
|
980
|
-
*/
|
|
1608
|
+
private httpClient?;
|
|
1609
|
+
constructor(httpClient?: CommetHTTPClient | undefined);
|
|
1610
|
+
/** HMAC-SHA256 verification. Payload must be the raw request body string, not parsed JSON. */
|
|
981
1611
|
verify(params: VerifyParams): boolean;
|
|
982
|
-
/**
|
|
983
|
-
* Generate HMAC-SHA256 signature (internal use)
|
|
984
|
-
* @internal
|
|
985
|
-
*/
|
|
986
1612
|
private generateSignature;
|
|
987
|
-
/**
|
|
988
|
-
* Parse and verify webhook payload in one step
|
|
989
|
-
*
|
|
990
|
-
* @example
|
|
991
|
-
* ```typescript
|
|
992
|
-
* const payload = commet.webhooks.verifyAndParse({
|
|
993
|
-
* rawBody,
|
|
994
|
-
* signature,
|
|
995
|
-
* secret: process.env.COMMET_WEBHOOK_SECRET
|
|
996
|
-
* });
|
|
997
|
-
*
|
|
998
|
-
* if (!payload) {
|
|
999
|
-
* return new Response('Invalid signature', { status: 401 });
|
|
1000
|
-
* }
|
|
1001
|
-
*
|
|
1002
|
-
* // payload is typed and validated
|
|
1003
|
-
* if (payload.event === 'subscription.activated') {
|
|
1004
|
-
* // Handle activation...
|
|
1005
|
-
* }
|
|
1006
|
-
* ```
|
|
1007
|
-
*/
|
|
1613
|
+
/** Verifies signature and parses JSON in one step. Returns null if invalid. */
|
|
1008
1614
|
verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null;
|
|
1615
|
+
list(params?: ListWebhooksParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpoint[]>>;
|
|
1616
|
+
create(params: CreateWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpointCreated>>;
|
|
1617
|
+
get(params: GetWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpoint>>;
|
|
1618
|
+
update(params: UpdateWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookEndpoint>>;
|
|
1619
|
+
delete(params: DeleteWebhookParams, options?: RequestOptions): Promise<ApiResponse<{
|
|
1620
|
+
id: string;
|
|
1621
|
+
deleted: true;
|
|
1622
|
+
}>>;
|
|
1623
|
+
test(params: TestWebhookParams, options?: RequestOptions): Promise<ApiResponse<WebhookTestResult>>;
|
|
1009
1624
|
}
|
|
1010
1625
|
|
|
1011
|
-
|
|
1012
|
-
* Main Commet SDK client
|
|
1013
|
-
*/
|
|
1014
|
-
declare class Commet<TConfig = unknown> {
|
|
1626
|
+
declare class Commet<_TConfig = unknown> {
|
|
1015
1627
|
private httpClient;
|
|
1016
1628
|
readonly addons: AddonsResource;
|
|
1017
|
-
readonly
|
|
1629
|
+
readonly apiKeys: ApiKeysResource;
|
|
1018
1630
|
readonly creditPacks: CreditPacksResource;
|
|
1631
|
+
readonly customers: CustomersResource;
|
|
1632
|
+
readonly features: FeaturesResource;
|
|
1633
|
+
readonly invoices: InvoicesResource;
|
|
1634
|
+
readonly planGroups: PlanGroupsResource;
|
|
1019
1635
|
readonly plans: PlansResource;
|
|
1020
|
-
readonly
|
|
1636
|
+
readonly portal: PortalResource;
|
|
1637
|
+
readonly promoCodes: PromoCodesResource;
|
|
1021
1638
|
readonly seats: SeatsResource;
|
|
1022
1639
|
readonly subscriptions: SubscriptionsResource;
|
|
1023
|
-
readonly
|
|
1024
|
-
readonly
|
|
1640
|
+
readonly transactions: TransactionsResource;
|
|
1641
|
+
readonly usage: UsageResource;
|
|
1025
1642
|
readonly webhooks: Webhooks;
|
|
1026
1643
|
constructor(config: CommetClientOptions);
|
|
1027
|
-
/**
|
|
1028
|
-
* Create a customer-scoped context for cleaner API usage
|
|
1029
|
-
*
|
|
1030
|
-
* @example
|
|
1031
|
-
* ```typescript
|
|
1032
|
-
* const customer = commet.customer("user_123");
|
|
1033
|
-
*
|
|
1034
|
-
* // All operations are now scoped to this customer
|
|
1035
|
-
* const seats = await customer.features.get("team_members");
|
|
1036
|
-
* await customer.seats.add("member");
|
|
1037
|
-
* await customer.usage.track("api_call");
|
|
1038
|
-
* ```
|
|
1039
|
-
*/
|
|
1040
|
-
customer(customerId: string): CustomerContext<TConfig>;
|
|
1041
1644
|
}
|
|
1042
1645
|
declare function createCommet<const TConfig extends BillingConfig>(_billingConfig: TConfig, options: CommetClientOptions): Commet<TConfig>;
|
|
1043
1646
|
|
|
1044
1647
|
declare function registerIntegration(name: string, version: string): void;
|
|
1045
1648
|
|
|
1046
|
-
declare const API_VERSION = "2026-05-
|
|
1649
|
+
declare const API_VERSION = "2026-05-25";
|
|
1047
1650
|
declare const SDK_VERSION: string;
|
|
1048
1651
|
|
|
1049
|
-
|
|
1050
|
-
* Commet SDK - Billing and usage tracking for SaaS
|
|
1051
|
-
*/
|
|
1052
|
-
|
|
1053
|
-
export { API_VERSION, type ActiveAddon, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingConfig, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type ChangePlanParams, type ChangePlanResult, type CheckFeatureParams, type CheckResult, type CheckUsageParams, 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 GetActiveAddonsParams, 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 UncancelParams, type UpdateParams as UpdateCustomerParams, type UsageCheckResult, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, createCommet, Commet as default, defineConfig, registerIntegration };
|
|
1652
|
+
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 GetWebhookParams, 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 UpdateWebhookParams, 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 };
|