@commet/node 0.4.0 → 0.6.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/LICENSE +202 -21
- package/README.md +45 -17
- package/dist/index.d.mts +69 -52
- package/dist/index.d.ts +69 -52
- package/dist/index.js +44 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,34 @@ interface RequestOptions {
|
|
|
62
62
|
idempotencyKey?: string;
|
|
63
63
|
timeout?: number;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Generated types interface - augmented by CLI after 'commet pull'
|
|
67
|
+
*
|
|
68
|
+
* This interface gets filled by module augmentation when you run `commet pull`.
|
|
69
|
+
* The CLI generates a .commet.d.ts file that augments this interface with your
|
|
70
|
+
* organization's specific event and seat types.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* // After running `commet pull`, TypeScript will automatically know your types:
|
|
74
|
+
* await commet.usage.events.create({
|
|
75
|
+
* eventType: 'api_call', // Autocomplete works!
|
|
76
|
+
* customerId: 'cus_123'
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
79
|
+
interface CommetGeneratedTypes {
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Helper type that provides fallback to string if types are not generated
|
|
83
|
+
*/
|
|
84
|
+
type GeneratedEventType = CommetGeneratedTypes extends {
|
|
85
|
+
eventType: infer T;
|
|
86
|
+
} ? T : string;
|
|
87
|
+
/**
|
|
88
|
+
* Helper type that provides fallback to string if types are not generated
|
|
89
|
+
*/
|
|
90
|
+
type GeneratedSeatType = CommetGeneratedTypes extends {
|
|
91
|
+
seatType: infer T;
|
|
92
|
+
} ? T : string;
|
|
65
93
|
|
|
66
94
|
declare class CommetHTTPClient {
|
|
67
95
|
private config;
|
|
@@ -71,7 +99,7 @@ declare class CommetHTTPClient {
|
|
|
71
99
|
get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
72
100
|
post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
73
101
|
put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
74
|
-
delete<T = unknown>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
102
|
+
delete<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
75
103
|
/**
|
|
76
104
|
* Core request method with retry logic
|
|
77
105
|
*/
|
|
@@ -197,7 +225,7 @@ interface SeatBalance {
|
|
|
197
225
|
id: string;
|
|
198
226
|
organizationId: string;
|
|
199
227
|
customerId: CustomerID;
|
|
200
|
-
seatType:
|
|
228
|
+
seatType: GeneratedSeatType;
|
|
201
229
|
balance: number;
|
|
202
230
|
asOf: string;
|
|
203
231
|
createdAt: string;
|
|
@@ -207,7 +235,7 @@ interface SeatEvent {
|
|
|
207
235
|
id: string;
|
|
208
236
|
organizationId: string;
|
|
209
237
|
customerId: CustomerID;
|
|
210
|
-
seatType:
|
|
238
|
+
seatType: GeneratedSeatType;
|
|
211
239
|
eventType: "add" | "remove" | "set";
|
|
212
240
|
quantity: number;
|
|
213
241
|
previousBalance?: number;
|
|
@@ -222,9 +250,35 @@ interface SeatBalanceResponse {
|
|
|
222
250
|
interface BulkSeatUpdate {
|
|
223
251
|
[seatType: string]: number;
|
|
224
252
|
}
|
|
253
|
+
interface AddSeatsParams {
|
|
254
|
+
customerId: CustomerID;
|
|
255
|
+
seatType: GeneratedSeatType;
|
|
256
|
+
count: number;
|
|
257
|
+
}
|
|
258
|
+
interface RemoveSeatsParams {
|
|
259
|
+
customerId: CustomerID;
|
|
260
|
+
seatType: GeneratedSeatType;
|
|
261
|
+
count: number;
|
|
262
|
+
}
|
|
263
|
+
interface SetSeatsParams {
|
|
264
|
+
customerId: CustomerID;
|
|
265
|
+
seatType: GeneratedSeatType;
|
|
266
|
+
count: number;
|
|
267
|
+
}
|
|
268
|
+
interface BulkUpdateSeatsParams {
|
|
269
|
+
customerId: CustomerID;
|
|
270
|
+
seats: BulkSeatUpdate;
|
|
271
|
+
}
|
|
272
|
+
interface GetBalanceParams {
|
|
273
|
+
customerId: CustomerID;
|
|
274
|
+
seatType: GeneratedSeatType;
|
|
275
|
+
}
|
|
276
|
+
interface GetAllBalancesParams {
|
|
277
|
+
customerId: CustomerID;
|
|
278
|
+
}
|
|
225
279
|
interface ListSeatEventsParams extends ListParams {
|
|
226
280
|
customerId?: CustomerID;
|
|
227
|
-
seatType?:
|
|
281
|
+
seatType?: GeneratedSeatType;
|
|
228
282
|
eventType?: "add" | "remove" | "set";
|
|
229
283
|
}
|
|
230
284
|
/**
|
|
@@ -233,13 +287,12 @@ interface ListSeatEventsParams extends ListParams {
|
|
|
233
287
|
declare class SeatsResource {
|
|
234
288
|
private httpClient;
|
|
235
289
|
constructor(httpClient: CommetHTTPClient);
|
|
236
|
-
add(
|
|
237
|
-
remove(
|
|
238
|
-
set(
|
|
239
|
-
bulkUpdate(
|
|
240
|
-
getBalance(
|
|
241
|
-
getAllBalances(
|
|
242
|
-
getHistory(customerId: CustomerID, seatType: string, params?: ListSeatEventsParams): Promise<ApiResponse<SeatEvent[]>>;
|
|
290
|
+
add(params: AddSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
291
|
+
remove(params: RemoveSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
292
|
+
set(params: SetSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
|
|
293
|
+
bulkUpdate(params: BulkUpdateSeatsParams, options?: RequestOptions): Promise<ApiResponse<SeatEvent[]>>;
|
|
294
|
+
getBalance(params: GetBalanceParams): Promise<ApiResponse<SeatBalanceResponse>>;
|
|
295
|
+
getAllBalances(params: GetAllBalancesParams): Promise<ApiResponse<Record<string, SeatBalanceResponse>>>;
|
|
243
296
|
listEvents(params?: ListSeatEventsParams): Promise<ApiResponse<SeatEvent[]>>;
|
|
244
297
|
}
|
|
245
298
|
|
|
@@ -247,7 +300,7 @@ interface UsageEvent {
|
|
|
247
300
|
id: EventID;
|
|
248
301
|
organizationId: string;
|
|
249
302
|
customerId: CustomerID;
|
|
250
|
-
eventType:
|
|
303
|
+
eventType: GeneratedEventType;
|
|
251
304
|
idempotencyKey?: string;
|
|
252
305
|
ts: string;
|
|
253
306
|
properties?: UsageEventProperty[];
|
|
@@ -261,7 +314,7 @@ interface UsageEventProperty {
|
|
|
261
314
|
createdAt: string;
|
|
262
315
|
}
|
|
263
316
|
interface CreateUsageEventParams {
|
|
264
|
-
eventType:
|
|
317
|
+
eventType: GeneratedEventType;
|
|
265
318
|
customerId: CustomerID;
|
|
266
319
|
idempotencyKey?: string;
|
|
267
320
|
timestamp?: string;
|
|
@@ -283,13 +336,13 @@ interface BatchResult<T> {
|
|
|
283
336
|
}
|
|
284
337
|
interface ListUsageEventsParams extends ListParams {
|
|
285
338
|
customerId?: CustomerID;
|
|
286
|
-
eventType?:
|
|
339
|
+
eventType?: GeneratedEventType;
|
|
287
340
|
idempotencyKey?: string;
|
|
288
341
|
}
|
|
289
342
|
/**
|
|
290
343
|
* Usage Events resource - Track business events for usage-based billing
|
|
291
344
|
*/
|
|
292
|
-
declare class
|
|
345
|
+
declare class UsageResource {
|
|
293
346
|
private httpClient;
|
|
294
347
|
constructor(httpClient: CommetHTTPClient);
|
|
295
348
|
create(params: CreateUsageEventParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
|
|
@@ -300,42 +353,6 @@ declare class UsageEventsResource {
|
|
|
300
353
|
deleted: boolean;
|
|
301
354
|
}>>;
|
|
302
355
|
}
|
|
303
|
-
interface UsageMetric {
|
|
304
|
-
id: string;
|
|
305
|
-
organizationId: string;
|
|
306
|
-
name: string;
|
|
307
|
-
eventType: string;
|
|
308
|
-
aggregation: "count" | "unique" | "sum";
|
|
309
|
-
property?: string;
|
|
310
|
-
filters?: UsageMetricFilter[];
|
|
311
|
-
createdAt: string;
|
|
312
|
-
updatedAt: string;
|
|
313
|
-
}
|
|
314
|
-
interface UsageMetricFilter {
|
|
315
|
-
id: string;
|
|
316
|
-
usageMetricId: string;
|
|
317
|
-
property: string;
|
|
318
|
-
operator: "equals" | "not_equals" | "greater_than" | "less_than" | "contains";
|
|
319
|
-
value: string;
|
|
320
|
-
createdAt: string;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Usage Metrics resource - Read-only access to metrics
|
|
324
|
-
*/
|
|
325
|
-
declare class UsageMetricsResource {
|
|
326
|
-
private httpClient;
|
|
327
|
-
constructor(httpClient: CommetHTTPClient);
|
|
328
|
-
list(): Promise<ApiResponse<UsageMetric[]>>;
|
|
329
|
-
retrieve(metricId: string): Promise<ApiResponse<UsageMetric>>;
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Usage resource combining events and metrics
|
|
333
|
-
*/
|
|
334
|
-
declare class UsageResource {
|
|
335
|
-
readonly events: UsageEventsResource;
|
|
336
|
-
readonly metrics: UsageMetricsResource;
|
|
337
|
-
constructor(httpClient: CommetHTTPClient);
|
|
338
|
-
}
|
|
339
356
|
|
|
340
357
|
/**
|
|
341
358
|
* Main Commet SDK client
|
|
@@ -365,4 +382,4 @@ declare function isProduction(environment: Environment): boolean;
|
|
|
365
382
|
* Commet SDK - Billing and usage tracking SDK
|
|
366
383
|
*/
|
|
367
384
|
|
|
368
|
-
export { type AgreementID, type ApiResponse, type BatchResult, type BulkSeatUpdate, Commet, CommetAPIError, type CommetConfig, CommetError, CommetValidationError, type CreateBatchUsageEventsParams, type CreateCustomerParams, type CreateUsageEventParams, type Currency, type Customer, type CustomerID, type Environment, type EventID, type InvoiceID, type ItemID, type ListCustomersParams, type ListParams, type ListSeatEventsParams, type ListUsageEventsParams, type PaginatedList, type PaginatedResponse, type PhaseID, type ProductID, type RequestOptions, type RetrieveOptions, type SeatBalance, type SeatBalanceResponse, type SeatEvent, type
|
|
385
|
+
export { type AddSeatsParams, type AgreementID, type ApiResponse, type BatchResult, type BulkSeatUpdate, type BulkUpdateSeatsParams, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateBatchUsageEventsParams, type CreateCustomerParams, type CreateUsageEventParams, type Currency, type Customer, type CustomerID, type Environment, type EventID, type GeneratedEventType, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type InvoiceID, type ItemID, type ListCustomersParams, type ListParams, type ListSeatEventsParams, type ListUsageEventsParams, type PaginatedList, type PaginatedResponse, type PhaseID, type ProductID, type RemoveSeatsParams, type RequestOptions, type RetrieveOptions, type SeatBalance, type SeatBalanceResponse, type SeatEvent, type SetSeatsParams, type UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookID, Commet as default, isProduction, isSandbox };
|
package/dist/index.js
CHANGED
|
@@ -65,52 +65,56 @@ var SeatsResource = class {
|
|
|
65
65
|
constructor(httpClient) {
|
|
66
66
|
this.httpClient = httpClient;
|
|
67
67
|
}
|
|
68
|
-
async add(
|
|
68
|
+
async add(params, options) {
|
|
69
69
|
return this.httpClient.post(
|
|
70
|
-
|
|
71
|
-
{
|
|
70
|
+
"/seats",
|
|
71
|
+
{
|
|
72
|
+
customerId: params.customerId,
|
|
73
|
+
seatType: params.seatType,
|
|
74
|
+
count: params.count
|
|
75
|
+
},
|
|
72
76
|
options
|
|
73
77
|
);
|
|
74
78
|
}
|
|
75
|
-
async remove(
|
|
76
|
-
return this.httpClient.
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
+
async remove(params, options) {
|
|
80
|
+
return this.httpClient.delete(
|
|
81
|
+
"/seats",
|
|
82
|
+
{
|
|
83
|
+
customerId: params.customerId,
|
|
84
|
+
seatType: params.seatType,
|
|
85
|
+
count: params.count
|
|
86
|
+
},
|
|
79
87
|
options
|
|
80
88
|
);
|
|
81
89
|
}
|
|
82
|
-
async set(
|
|
83
|
-
return this.httpClient.
|
|
84
|
-
|
|
85
|
-
{
|
|
90
|
+
async set(params, options) {
|
|
91
|
+
return this.httpClient.put(
|
|
92
|
+
"/seats",
|
|
93
|
+
{
|
|
94
|
+
customerId: params.customerId,
|
|
95
|
+
seatType: params.seatType,
|
|
96
|
+
count: params.count
|
|
97
|
+
},
|
|
86
98
|
options
|
|
87
99
|
);
|
|
88
100
|
}
|
|
89
|
-
async bulkUpdate(
|
|
90
|
-
return this.httpClient.
|
|
91
|
-
|
|
92
|
-
{ seats },
|
|
101
|
+
async bulkUpdate(params, options) {
|
|
102
|
+
return this.httpClient.put(
|
|
103
|
+
"/seats/bulk",
|
|
104
|
+
{ customerId: params.customerId, seats: params.seats },
|
|
93
105
|
options
|
|
94
106
|
);
|
|
95
107
|
}
|
|
96
|
-
async getBalance(
|
|
97
|
-
return this.httpClient.get(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
async getAllBalances(customerId) {
|
|
102
|
-
return this.httpClient.get(`/customers/${customerId}/seats/balances`);
|
|
108
|
+
async getBalance(params) {
|
|
109
|
+
return this.httpClient.get("/seats/balance", {
|
|
110
|
+
customerId: params.customerId,
|
|
111
|
+
seatType: params.seatType
|
|
112
|
+
});
|
|
103
113
|
}
|
|
104
|
-
async
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
seatType
|
|
109
|
-
};
|
|
110
|
-
return this.httpClient.get(
|
|
111
|
-
`/customers/${customerId}/seats/history`,
|
|
112
|
-
queryParams
|
|
113
|
-
);
|
|
114
|
+
async getAllBalances(params) {
|
|
115
|
+
return this.httpClient.get("/seats/balances", {
|
|
116
|
+
customerId: params.customerId
|
|
117
|
+
});
|
|
114
118
|
}
|
|
115
119
|
async listEvents(params) {
|
|
116
120
|
return this.httpClient.get("/seats/events", params);
|
|
@@ -118,7 +122,7 @@ var SeatsResource = class {
|
|
|
118
122
|
};
|
|
119
123
|
|
|
120
124
|
// src/resources/usage.ts
|
|
121
|
-
var
|
|
125
|
+
var UsageResource = class {
|
|
122
126
|
constructor(httpClient) {
|
|
123
127
|
this.httpClient = httpClient;
|
|
124
128
|
}
|
|
@@ -139,24 +143,11 @@ var UsageEventsResource = class {
|
|
|
139
143
|
return this.httpClient.get("/usage/events", params);
|
|
140
144
|
}
|
|
141
145
|
async delete(eventId, options) {
|
|
142
|
-
return this.httpClient.delete(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
this.httpClient = httpClient;
|
|
148
|
-
}
|
|
149
|
-
async list() {
|
|
150
|
-
return this.httpClient.get("/usage/metrics");
|
|
151
|
-
}
|
|
152
|
-
async retrieve(metricId) {
|
|
153
|
-
return this.httpClient.get(`/usage/metrics/${metricId}`);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var UsageResource = class {
|
|
157
|
-
constructor(httpClient) {
|
|
158
|
-
this.events = new UsageEventsResource(httpClient);
|
|
159
|
-
this.metrics = new UsageMetricsResource(httpClient);
|
|
146
|
+
return this.httpClient.delete(
|
|
147
|
+
`/usage/events/${eventId}`,
|
|
148
|
+
void 0,
|
|
149
|
+
options
|
|
150
|
+
);
|
|
160
151
|
}
|
|
161
152
|
};
|
|
162
153
|
|
|
@@ -214,8 +205,8 @@ var CommetHTTPClient = class {
|
|
|
214
205
|
async put(endpoint, data, options) {
|
|
215
206
|
return this.request("PUT", endpoint, data, options);
|
|
216
207
|
}
|
|
217
|
-
async delete(endpoint, options) {
|
|
218
|
-
return this.request("DELETE", endpoint,
|
|
208
|
+
async delete(endpoint, data, options) {
|
|
209
|
+
return this.request("DELETE", endpoint, data, options);
|
|
219
210
|
}
|
|
220
211
|
/**
|
|
221
212
|
* Core request method with retry logic
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/resources/customers.ts","../src/resources/seats.ts","../src/resources/usage.ts","../src/types/common.ts","../src/utils/http.ts","../src/client.ts","../src/utils/environment.ts"],"sourcesContent":["/**\n * Commet SDK - Billing and usage tracking SDK\n */\nexport { Commet } from \"./client\";\n\n// Type exports\nexport type {\n CommetConfig,\n Environment,\n ApiResponse,\n PaginatedResponse,\n PaginatedList,\n Currency,\n CustomerID,\n AgreementID,\n InvoiceID,\n PhaseID,\n ItemID,\n ProductID,\n EventID,\n WebhookID,\n ListParams,\n RetrieveOptions,\n RequestOptions,\n} from \"./types/common\";\n\n// Error exports\nexport {\n CommetError,\n CommetAPIError,\n CommetValidationError,\n} from \"./types/common\";\n\n// Resource type exports\nexport type {\n Customer,\n CreateCustomerParams,\n UpdateCustomerParams,\n ListCustomersParams,\n} from \"./resources/customers\";\n\nexport type {\n UsageEvent,\n UsageEventProperty,\n CreateUsageEventParams,\n CreateBatchUsageEventsParams,\n BatchResult,\n ListUsageEventsParams,\n UsageMetric,\n UsageMetricFilter,\n} from \"./resources/usage\";\n\nexport type {\n SeatBalance,\n SeatEvent,\n SeatBalanceResponse,\n BulkSeatUpdate,\n ListSeatEventsParams,\n} from \"./resources/seats\";\n\n// Utility exports\nexport { isSandbox, isProduction } from \"./utils/environment\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n","import type {\n ApiResponse,\n Currency,\n CustomerID,\n ListParams,\n RequestOptions,\n RetrieveOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n legalName: string;\n displayName?: string;\n domain?: string;\n website?: string;\n taxStatus: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency: Currency;\n addressId: string;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n isActive: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n// Base fields shared by all customer creation scenarios\ninterface CreateCustomerBaseParams {\n externalId?: string;\n legalName: string;\n displayName?: string;\n domain?: string;\n website?: string;\n currency?: Currency;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n}\n\n// Address structure\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n region?: string;\n}\n\n// When taxStatus is TAXED, address is required\ninterface CreateCustomerTaxed extends CreateCustomerBaseParams {\n taxStatus: \"TAXED\";\n address: CustomerAddress;\n}\n\n// For other tax statuses, address is optional\ninterface CreateCustomerOtherTaxStatus extends CreateCustomerBaseParams {\n taxStatus?: \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n address?: CustomerAddress;\n}\n\n// Union type that enforces the constraint\nexport type CreateCustomerParams =\n | CreateCustomerTaxed\n | CreateCustomerOtherTaxStatus;\n\nexport interface UpdateCustomerParams {\n externalId?: string;\n legalName?: string;\n displayName?: string;\n domain?: string;\n website?: string;\n taxStatus?: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency?: Currency;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n isActive?: boolean;\n}\n\nexport interface ListCustomersParams extends ListParams {\n externalId?: string;\n taxStatus?: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency?: Currency;\n isActive?: boolean;\n search?: string;\n}\n\n/**\n * Customer resource for managing customer data\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async create(\n params: CreateCustomerParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\"/customers\", params, options);\n }\n\n async retrieve(\n customerId: CustomerID,\n options?: RetrieveOptions,\n ): Promise<ApiResponse<Customer>> {\n const params = options?.expand\n ? { expand: options.expand.join(\",\") }\n : undefined;\n return this.httpClient.get(`/customers/${customerId}`, params);\n }\n\n async update(\n customerId: CustomerID,\n params: UpdateCustomerParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(`/customers/${customerId}`, params, options);\n }\n\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params);\n }\n\n /**\n * Deactivate a customer (soft delete)\n */\n async deactivate(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${customerId}`,\n { isActive: false },\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n ListParams,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface SeatBalance {\n id: string;\n organizationId: string;\n customerId: CustomerID;\n seatType: string;\n balance: number;\n asOf: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface SeatEvent {\n id: string;\n organizationId: string;\n customerId: CustomerID;\n seatType: string;\n eventType: \"add\" | \"remove\" | \"set\";\n quantity: number;\n previousBalance?: number;\n newBalance: number;\n ts: string;\n createdAt: string;\n}\n\nexport interface SeatBalanceResponse {\n current: number;\n asOf: string;\n}\n\nexport interface BulkSeatUpdate {\n [seatType: string]: number;\n}\n\nexport interface ListSeatEventsParams extends ListParams {\n customerId?: CustomerID;\n seatType?: string;\n eventType?: \"add\" | \"remove\" | \"set\";\n}\n\n/**\n * Seats resource for seat-based billing management\n */\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n customerId: CustomerID,\n seatType: string,\n count: number,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\n `/customers/${customerId}/seats/${seatType}/add`,\n { count },\n options,\n );\n }\n\n async remove(\n customerId: CustomerID,\n seatType: string,\n count: number,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\n `/customers/${customerId}/seats/${seatType}/remove`,\n { count },\n options,\n );\n }\n\n async set(\n customerId: CustomerID,\n seatType: string,\n count: number,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\n `/customers/${customerId}/seats/${seatType}/set`,\n { count },\n options,\n );\n }\n\n async bulkUpdate(\n customerId: CustomerID,\n seats: BulkSeatUpdate,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.post(\n `/customers/${customerId}/seats/bulk-update`,\n { seats },\n options,\n );\n }\n\n async getBalance(\n customerId: CustomerID,\n seatType: string,\n ): Promise<ApiResponse<SeatBalanceResponse>> {\n return this.httpClient.get(\n `/customers/${customerId}/seats/${seatType}/balance`,\n );\n }\n\n async getAllBalances(\n customerId: CustomerID,\n ): Promise<ApiResponse<Record<string, SeatBalanceResponse>>> {\n return this.httpClient.get(`/customers/${customerId}/seats/balances`);\n }\n\n async getHistory(\n customerId: CustomerID,\n seatType: string,\n params?: ListSeatEventsParams,\n ): Promise<ApiResponse<SeatEvent[]>> {\n const queryParams = {\n ...params,\n customerId,\n seatType,\n };\n return this.httpClient.get(\n `/customers/${customerId}/seats/history`,\n queryParams,\n );\n }\n\n async listEvents(\n params?: ListSeatEventsParams,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.get(\"/seats/events\", params);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n ListParams,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface UsageEvent {\n id: EventID;\n organizationId: string;\n customerId: CustomerID;\n eventType: string;\n idempotencyKey?: string;\n ts: string;\n properties?: UsageEventProperty[];\n createdAt: string;\n}\n\nexport interface UsageEventProperty {\n id: string;\n usageEventId: EventID;\n property: string;\n value: string;\n createdAt: string;\n}\n\nexport interface CreateUsageEventParams {\n eventType: string;\n customerId: CustomerID;\n idempotencyKey?: string; // For idempotency\n timestamp?: string; // ISO string, defaults to now\n properties?: Array<{\n property: string;\n value: string;\n }>;\n}\n\nexport interface CreateBatchUsageEventsParams {\n events: CreateUsageEventParams[];\n}\n\nexport interface BatchResult<T> {\n successful: T[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateUsageEventParams;\n }>;\n}\n\nexport interface ListUsageEventsParams extends ListParams {\n customerId?: CustomerID;\n eventType?: string;\n idempotencyKey?: string;\n}\n\n/**\n * Usage Events resource - Track business events for usage-based billing\n */\nexport class UsageEventsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async create(\n params: CreateUsageEventParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData = {\n ...params,\n ts: params.timestamp || new Date().toISOString(),\n };\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n\n async createBatch(\n params: CreateBatchUsageEventsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult<UsageEvent>>> {\n return this.httpClient.post(\"/usage/events/batch\", params, options);\n }\n\n async retrieve(eventId: EventID): Promise<ApiResponse<UsageEvent>> {\n return this.httpClient.get(`/usage/events/${eventId}`);\n }\n\n async list(\n params?: ListUsageEventsParams,\n ): Promise<ApiResponse<UsageEvent[]>> {\n return this.httpClient.get(\"/usage/events\", params);\n }\n\n async delete(\n eventId: EventID,\n options?: RequestOptions,\n ): Promise<ApiResponse<{ deleted: boolean }>> {\n return this.httpClient.delete(`/usage/events/${eventId}`, options);\n }\n}\n\nexport interface UsageMetric {\n id: string;\n organizationId: string;\n name: string;\n eventType: string;\n aggregation: \"count\" | \"unique\" | \"sum\";\n property?: string;\n filters?: UsageMetricFilter[];\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface UsageMetricFilter {\n id: string;\n usageMetricId: string;\n property: string;\n operator: \"equals\" | \"not_equals\" | \"greater_than\" | \"less_than\" | \"contains\";\n value: string;\n createdAt: string;\n}\n\n/**\n * Usage Metrics resource - Read-only access to metrics\n */\nexport class UsageMetricsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async list(): Promise<ApiResponse<UsageMetric[]>> {\n return this.httpClient.get(\"/usage/metrics\");\n }\n\n async retrieve(metricId: string): Promise<ApiResponse<UsageMetric>> {\n return this.httpClient.get(`/usage/metrics/${metricId}`);\n }\n}\n\n/**\n * Usage resource combining events and metrics\n */\nexport class UsageResource {\n public readonly events: UsageEventsResource;\n public readonly metrics: UsageMetricsResource;\n\n constructor(httpClient: CommetHTTPClient) {\n this.events = new UsageEventsResource(httpClient);\n this.metrics = new UsageMetricsResource(httpClient);\n }\n}\n","export type Environment = \"sandbox\" | \"production\";\n\nexport type CommetConfig = {\n apiKey: string;\n environment?: Environment;\n debug?: boolean;\n timeout?: number;\n retries?: number;\n};\n\n// API Response types\nexport interface ApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n error?: string;\n message?: string;\n // Pagination fields (optional, included for list endpoints)\n hasMore?: boolean;\n nextCursor?: string;\n}\n\nexport interface PaginatedResponse<T> {\n data: T[];\n hasMore: boolean;\n nextCursor?: string;\n totalCount?: number;\n}\n\nexport interface PaginatedList<T> extends PaginatedResponse<T> {\n next(): Promise<PaginatedList<T>>;\n all(): Promise<T[]>;\n}\n\n// Error types\nexport class CommetError extends Error {\n constructor(\n message: string,\n public code?: string,\n public statusCode?: number,\n public details?: unknown,\n ) {\n super(message);\n this.name = \"CommetError\";\n }\n}\n\nexport class CommetAPIError extends CommetError {\n constructor(\n message: string,\n public statusCode: number,\n public code?: string,\n public details?: unknown,\n ) {\n super(message, code, statusCode, details);\n this.name = \"CommetAPIError\";\n }\n}\n\nexport class CommetValidationError extends CommetError {\n constructor(\n message: string,\n public validationErrors: Record<string, string[]>,\n ) {\n super(message);\n this.name = \"CommetValidationError\";\n }\n}\n\nexport type CustomerID = `cus_${string}`;\nexport type AgreementID = `agr_${string}`;\nexport type InvoiceID = `inv_${string}`;\nexport type PhaseID = `phs_${string}`;\nexport type ItemID = `itm_${string}`;\nexport type ProductID = `prd_${string}`;\nexport type EventID = `evt_${string}`;\nexport type WebhookID = `wh_${string}`;\n\n// Currency enum\nexport type Currency =\n | \"USD\"\n | \"EUR\"\n | \"GBP\"\n | \"CAD\"\n | \"AUD\"\n | \"JPY\"\n | \"ARS\"\n | \"BRL\"\n | \"MXN\"\n | \"CLP\";\n\n// Common parameters\nexport interface ListParams extends Record<string, unknown> {\n limit?: number;\n cursor?: string;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface RetrieveOptions {\n expand?: string[];\n}\n\n// Request options\nexport interface RequestOptions {\n idempotencyKey?: string;\n timeout?: number;\n}\n","import type {\n ApiResponse,\n CommetConfig,\n Environment,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\n\nexport interface RetryConfig {\n maxRetries: number;\n baseDelay: number;\n maxDelay: number;\n retryableStatusCodes: number[];\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: 3,\n baseDelay: 1000, // 1s\n maxDelay: 8000, // 8s\n retryableStatusCodes: [408, 429, 500, 502, 503, 504],\n};\n\nexport class CommetHTTPClient {\n private config: CommetConfig;\n private environment: Environment;\n private retryConfig: RetryConfig;\n\n constructor(config: CommetConfig, environment: Environment) {\n this.config = config;\n this.environment = environment;\n this.retryConfig = {\n ...DEFAULT_RETRY_CONFIG,\n maxRetries: config.retries ?? DEFAULT_RETRY_CONFIG.maxRetries,\n };\n }\n\n async get<T = unknown>(\n endpoint: string,\n params?: Record<string, unknown>,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"GET\", endpoint, undefined, options, params);\n }\n\n async post<T = unknown>(\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"POST\", endpoint, data, options);\n }\n\n async put<T = unknown>(\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"PUT\", endpoint, data, options);\n }\n\n async delete<T = unknown>(\n endpoint: string,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"DELETE\", endpoint, undefined, options);\n }\n\n /**\n * Core request method with retry logic\n */\n private async request<T = unknown>(\n method: string,\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n params?: Record<string, unknown>,\n ): Promise<ApiResponse<T>> {\n const url = this.buildURL(endpoint, params);\n return this.executeRequest(method, url, data, options);\n }\n\n /**\n * Execute real API request with retry logic\n */\n private async executeRequest<T = unknown>(\n method: string,\n url: string,\n data?: unknown,\n options?: RequestOptions,\n attempt = 1,\n ): Promise<ApiResponse<T>> {\n try {\n const headers: Record<string, string> = {\n \"x-api-key\": this.config.apiKey,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": \"commet/0.1.0\",\n };\n\n if (options?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n } else if (method === \"POST\" && data) {\n headers[\"Idempotency-Key\"] = this.generateIdempotencyKey();\n }\n\n const requestConfig: RequestInit = {\n method,\n headers,\n signal: AbortSignal.timeout(\n options?.timeout ?? this.config.timeout ?? 30000,\n ),\n };\n\n if (data) {\n requestConfig.body = JSON.stringify(data);\n }\n\n if (this.config.debug) {\n console.log(`[Commet SDK] ${method} ${url}`);\n if (data) {\n console.log(\"Request data:\", JSON.stringify(data, null, 2));\n }\n }\n\n const response = await fetch(url, requestConfig);\n\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Response status: ${response.status} ${response.statusText}`,\n );\n }\n\n let responseData: unknown;\n let responseText: string;\n\n try {\n const responseClone = response.clone();\n responseData = await response.json();\n responseText = \"\";\n } catch (jsonError) {\n try {\n responseText = await response.text();\n } catch (textError) {\n responseText = \"Failed to read response body\";\n }\n if (this.config.debug) {\n console.log(\n \"[Commet SDK] Failed to parse JSON response:\",\n responseText,\n );\n }\n throw new CommetAPIError(\n `Invalid JSON response: ${response.status} ${response.statusText}`,\n response.status,\n \"INVALID_JSON\",\n { responseText },\n );\n }\n\n if (!response.ok) {\n // Check if we should retry\n if (\n attempt <= this.retryConfig.maxRetries &&\n this.retryConfig.retryableStatusCodes.includes(response.status)\n ) {\n const delay = Math.min(\n this.retryConfig.baseDelay * 2 ** (attempt - 1),\n this.retryConfig.maxDelay,\n );\n\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`,\n );\n }\n\n await this.sleep(delay);\n return this.executeRequest(method, url, data, options, attempt + 1);\n }\n\n // Log error response for debugging\n if (this.config.debug) {\n console.log(\n \"[Commet SDK] Error response:\",\n JSON.stringify(responseData, null, 2),\n );\n }\n\n // Type guard for error response\n const isErrorResponse = (\n data: unknown,\n ): data is {\n message?: string;\n errors?: Record<string, string[]>;\n code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle different error types\n if (response.status === 400 && errorData.errors) {\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n errorData.errors,\n );\n }\n\n throw new CommetAPIError(\n errorData.message || `Request failed with status ${response.status}`,\n response.status,\n errorData.code,\n errorData.details,\n );\n }\n\n if (this.config.debug) {\n console.log(\"[Commet SDK] Response:\", responseData);\n }\n\n return responseData as ApiResponse<T>;\n } catch (error) {\n // Handle network errors and timeouts\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n if (attempt <= this.retryConfig.maxRetries) {\n const delay = Math.min(\n this.retryConfig.baseDelay * 2 ** (attempt - 1),\n this.retryConfig.maxDelay,\n );\n\n if (this.config.debug) {\n console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);\n }\n\n await this.sleep(delay);\n return this.executeRequest(method, url, data, options, attempt + 1);\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Get base URL based on environment\n */\n private getBaseURL(): string {\n return this.environment === \"production\"\n ? \"https://billing.commet.co\"\n : \"https://sandbox.commet.co\";\n }\n\n /**\n * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n const baseURL = this.getBaseURL();\n\n // Construct full path with /api prefix\n const fullPath = `/api${endpoint.startsWith(\"/\") ? endpoint : `/${endpoint}`}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - baseURL: ${baseURL}, endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, baseURL);\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n url.searchParams.append(key, String(value));\n }\n }\n }\n\n const finalUrl = url.toString();\n\n // Debug final URL\n if (this.config.debug) {\n console.log(`[Commet SDK] Final URL: ${finalUrl}`);\n }\n\n return finalUrl;\n }\n\n /**\n * Generate idempotency key\n */\n private generateIdempotencyKey(): string {\n // Generate UUID-like key for idempotency\n return `sdk_${Date.now()}_${Math.random().toString(36).substring(2)}`;\n }\n\n /**\n * Sleep for specified milliseconds\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","import { CustomersResource } from \"./resources/customers\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { UsageResource } from \"./resources/usage\";\nimport type { CommetConfig, Environment } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n private environment: Environment;\n\n public readonly customers: CustomersResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n\n constructor(config: CommetConfig) {\n if (!config.apiKey) {\n throw new Error(\"Commet SDK: API key is required\");\n }\n\n if (!config.apiKey.startsWith(\"ck_\")) {\n throw new Error(\n \"Commet SDK: Invalid API key format. Expected format: ck_xxx...\",\n );\n }\n\n // Default to sandbox for safety\n this.environment = config.environment || \"sandbox\";\n\n this.httpClient = new CommetHTTPClient(config, this.environment);\n this.customers = new CustomersResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n\n if (config.debug) {\n console.log(`[Commet SDK] Initialized in ${this.environment} mode`);\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n const baseURL =\n this.environment === \"production\"\n ? \"https://billing.commet.co\"\n : \"https://sandbox.commet.co\";\n console.log(\"Base URL:\", baseURL);\n }\n }\n\n getEnvironment(): Environment {\n return this.environment;\n }\n\n isSandbox(): boolean {\n return this.environment === \"sandbox\";\n }\n\n isProduction(): boolean {\n return this.environment === \"production\";\n }\n}\n","import type { Environment } from \"../types/common\";\n\n/**\n * Check if environment is sandbox\n */\nexport function isSandbox(environment: Environment): boolean {\n return environment === \"sandbox\";\n}\n\n/**\n * Check if environment is production\n */\nexport function isProduction(environment: Environment): boolean {\n return environment === \"production\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2GO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAAoB,YAA8B;AAA9B;AAAA,EAA+B;AAAA,EAEnD,MAAM,OACJ,QACA,SACgC;AAChC,WAAO,KAAK,WAAW,KAAK,cAAc,QAAQ,OAAO;AAAA,EAC3D;AAAA,EAEA,MAAM,SACJ,YACA,SACgC;AAChC,UAAM,SAAS,SAAS,SACpB,EAAE,QAAQ,QAAQ,OAAO,KAAK,GAAG,EAAE,IACnC;AACJ,WAAO,KAAK,WAAW,IAAI,cAAc,UAAU,IAAI,MAAM;AAAA,EAC/D;AAAA,EAEA,MAAM,OACJ,YACA,QACA,SACgC;AAChC,WAAO,KAAK,WAAW,IAAI,cAAc,UAAU,IAAI,QAAQ,OAAO;AAAA,EACxE;AAAA,EAEA,MAAM,KAAK,QAAgE;AACzE,WAAO,KAAK,WAAW,IAAI,cAAc,MAAM;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WACJ,YACA,SACgC;AAChC,WAAO,KAAK,WAAW;AAAA,MACrB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src/resources/customers.ts","../src/resources/seats.ts","../src/resources/usage.ts","../src/types/common.ts","../src/utils/http.ts","../src/client.ts","../src/utils/environment.ts"],"sourcesContent":["/**\n * Commet SDK - Billing and usage tracking SDK\n */\nexport { Commet } from \"./client\";\n\n// Type exports\nexport type {\n CommetConfig,\n CommetGeneratedTypes,\n GeneratedEventType,\n GeneratedSeatType,\n Environment,\n ApiResponse,\n PaginatedResponse,\n PaginatedList,\n Currency,\n CustomerID,\n AgreementID,\n InvoiceID,\n PhaseID,\n ItemID,\n ProductID,\n EventID,\n WebhookID,\n ListParams,\n RetrieveOptions,\n RequestOptions,\n} from \"./types/common\";\n\n// Error exports\nexport {\n CommetError,\n CommetAPIError,\n CommetValidationError,\n} from \"./types/common\";\n\n// Resource type exports\nexport type {\n Customer,\n CreateCustomerParams,\n UpdateCustomerParams,\n ListCustomersParams,\n} from \"./resources/customers\";\n\nexport type {\n UsageEvent,\n UsageEventProperty,\n CreateUsageEventParams,\n CreateBatchUsageEventsParams,\n BatchResult,\n ListUsageEventsParams,\n} from \"./resources/usage\";\n\nexport type {\n SeatBalance,\n SeatEvent,\n SeatBalanceResponse,\n BulkSeatUpdate,\n AddSeatsParams,\n RemoveSeatsParams,\n SetSeatsParams,\n BulkUpdateSeatsParams,\n GetBalanceParams,\n GetAllBalancesParams,\n ListSeatEventsParams,\n} from \"./resources/seats\";\n\n// Utility exports\nexport { isSandbox, isProduction } from \"./utils/environment\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n","import type {\n ApiResponse,\n Currency,\n CustomerID,\n ListParams,\n RequestOptions,\n RetrieveOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n legalName: string;\n displayName?: string;\n domain?: string;\n website?: string;\n taxStatus: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency: Currency;\n addressId: string;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n isActive: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\n// Base fields shared by all customer creation scenarios\ninterface CreateCustomerBaseParams {\n externalId?: string;\n legalName: string;\n displayName?: string;\n domain?: string;\n website?: string;\n currency?: Currency;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n}\n\n// Address structure\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n region?: string;\n}\n\n// When taxStatus is TAXED, address is required\ninterface CreateCustomerTaxed extends CreateCustomerBaseParams {\n taxStatus: \"TAXED\";\n address: CustomerAddress;\n}\n\n// For other tax statuses, address is optional\ninterface CreateCustomerOtherTaxStatus extends CreateCustomerBaseParams {\n taxStatus?: \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n address?: CustomerAddress;\n}\n\n// Union type that enforces the constraint\nexport type CreateCustomerParams =\n | CreateCustomerTaxed\n | CreateCustomerOtherTaxStatus;\n\nexport interface UpdateCustomerParams {\n externalId?: string;\n legalName?: string;\n displayName?: string;\n domain?: string;\n website?: string;\n taxStatus?: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency?: Currency;\n billingEmail?: string;\n paymentTerms?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n employeeCount?: string;\n metadata?: Record<string, unknown>;\n isActive?: boolean;\n}\n\nexport interface ListCustomersParams extends ListParams {\n externalId?: string;\n taxStatus?: \"TAXED\" | \"TAX_EXEMPT\" | \"REVERSE_CHARGE\" | \"NOT_APPLICABLE\";\n currency?: Currency;\n isActive?: boolean;\n search?: string;\n}\n\n/**\n * Customer resource for managing customer data\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async create(\n params: CreateCustomerParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\"/customers\", params, options);\n }\n\n async retrieve(\n customerId: CustomerID,\n options?: RetrieveOptions,\n ): Promise<ApiResponse<Customer>> {\n const params = options?.expand\n ? { expand: options.expand.join(\",\") }\n : undefined;\n return this.httpClient.get(`/customers/${customerId}`, params);\n }\n\n async update(\n customerId: CustomerID,\n params: UpdateCustomerParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(`/customers/${customerId}`, params, options);\n }\n\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params);\n }\n\n /**\n * Deactivate a customer (soft delete)\n */\n async deactivate(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${customerId}`,\n { isActive: false },\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n GeneratedSeatType,\n ListParams,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface SeatBalance {\n id: string;\n organizationId: string;\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n balance: number;\n asOf: string;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface SeatEvent {\n id: string;\n organizationId: string;\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n eventType: \"add\" | \"remove\" | \"set\";\n quantity: number;\n previousBalance?: number;\n newBalance: number;\n ts: string;\n createdAt: string;\n}\n\nexport interface SeatBalanceResponse {\n current: number;\n asOf: string;\n}\n\nexport interface BulkSeatUpdate {\n [seatType: string]: number;\n}\n\nexport interface AddSeatsParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface RemoveSeatsParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetSeatsParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface BulkUpdateSeatsParams {\n customerId: CustomerID;\n seats: BulkSeatUpdate;\n}\n\nexport interface GetBalanceParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n}\n\nexport interface GetAllBalancesParams {\n customerId: CustomerID;\n}\n\nexport interface ListSeatEventsParams extends ListParams {\n customerId?: CustomerID;\n seatType?: GeneratedSeatType;\n eventType?: \"add\" | \"remove\" | \"set\";\n}\n\n/**\n * Seats resource for seat-based billing management\n */\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n params: AddSeatsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\n \"/seats\",\n {\n customerId: params.customerId,\n seatType: params.seatType,\n count: params.count,\n },\n options,\n );\n }\n\n async remove(\n params: RemoveSeatsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.delete(\n \"/seats\",\n {\n customerId: params.customerId,\n seatType: params.seatType,\n count: params.count,\n },\n options,\n );\n }\n\n async set(\n params: SetSeatsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.put(\n \"/seats\",\n {\n customerId: params.customerId,\n seatType: params.seatType,\n count: params.count,\n },\n options,\n );\n }\n\n async bulkUpdate(\n params: BulkUpdateSeatsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.put(\n \"/seats/bulk\",\n { customerId: params.customerId, seats: params.seats },\n options,\n );\n }\n\n async getBalance(\n params: GetBalanceParams,\n ): Promise<ApiResponse<SeatBalanceResponse>> {\n return this.httpClient.get(\"/seats/balance\", {\n customerId: params.customerId,\n seatType: params.seatType,\n });\n }\n\n async getAllBalances(\n params: GetAllBalancesParams,\n ): Promise<ApiResponse<Record<string, SeatBalanceResponse>>> {\n return this.httpClient.get(\"/seats/balances\", {\n customerId: params.customerId,\n });\n }\n\n async listEvents(\n params?: ListSeatEventsParams,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.get(\"/seats/events\", params);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n GeneratedEventType,\n ListParams,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface UsageEvent {\n id: EventID;\n organizationId: string;\n customerId: CustomerID;\n eventType: GeneratedEventType;\n idempotencyKey?: string;\n ts: string;\n properties?: UsageEventProperty[];\n createdAt: string;\n}\n\nexport interface UsageEventProperty {\n id: string;\n usageEventId: EventID;\n property: string;\n value: string;\n createdAt: string;\n}\n\nexport interface CreateUsageEventParams {\n eventType: GeneratedEventType;\n customerId: CustomerID;\n idempotencyKey?: string; // For idempotency\n timestamp?: string; // ISO string, defaults to now\n properties?: Array<{\n property: string;\n value: string;\n }>;\n}\n\nexport interface CreateBatchUsageEventsParams {\n events: CreateUsageEventParams[];\n}\n\nexport interface BatchResult<T> {\n successful: T[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateUsageEventParams;\n }>;\n}\n\nexport interface ListUsageEventsParams extends ListParams {\n customerId?: CustomerID;\n eventType?: GeneratedEventType;\n idempotencyKey?: string;\n}\n\n/**\n * Usage Events resource - Track business events for usage-based billing\n */\nexport class UsageResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async create(\n params: CreateUsageEventParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData = {\n ...params,\n ts: params.timestamp || new Date().toISOString(),\n };\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n\n async createBatch(\n params: CreateBatchUsageEventsParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult<UsageEvent>>> {\n return this.httpClient.post(\"/usage/events/batch\", params, options);\n }\n\n async retrieve(eventId: EventID): Promise<ApiResponse<UsageEvent>> {\n return this.httpClient.get(`/usage/events/${eventId}`);\n }\n\n async list(\n params?: ListUsageEventsParams,\n ): Promise<ApiResponse<UsageEvent[]>> {\n return this.httpClient.get(\"/usage/events\", params);\n }\n\n async delete(\n eventId: EventID,\n options?: RequestOptions,\n ): Promise<ApiResponse<{ deleted: boolean }>> {\n return this.httpClient.delete(\n `/usage/events/${eventId}`,\n undefined,\n options,\n );\n }\n}\n","export type Environment = \"sandbox\" | \"production\";\n\nexport type CommetConfig = {\n apiKey: string;\n environment?: Environment;\n debug?: boolean;\n timeout?: number;\n retries?: number;\n};\n\n// API Response types\nexport interface ApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n error?: string;\n message?: string;\n // Pagination fields (optional, included for list endpoints)\n hasMore?: boolean;\n nextCursor?: string;\n}\n\nexport interface PaginatedResponse<T> {\n data: T[];\n hasMore: boolean;\n nextCursor?: string;\n totalCount?: number;\n}\n\nexport interface PaginatedList<T> extends PaginatedResponse<T> {\n next(): Promise<PaginatedList<T>>;\n all(): Promise<T[]>;\n}\n\n// Error types\nexport class CommetError extends Error {\n constructor(\n message: string,\n public code?: string,\n public statusCode?: number,\n public details?: unknown,\n ) {\n super(message);\n this.name = \"CommetError\";\n }\n}\n\nexport class CommetAPIError extends CommetError {\n constructor(\n message: string,\n public statusCode: number,\n public code?: string,\n public details?: unknown,\n ) {\n super(message, code, statusCode, details);\n this.name = \"CommetAPIError\";\n }\n}\n\nexport class CommetValidationError extends CommetError {\n constructor(\n message: string,\n public validationErrors: Record<string, string[]>,\n ) {\n super(message);\n this.name = \"CommetValidationError\";\n }\n}\n\nexport type CustomerID = `cus_${string}`;\nexport type AgreementID = `agr_${string}`;\nexport type InvoiceID = `inv_${string}`;\nexport type PhaseID = `phs_${string}`;\nexport type ItemID = `itm_${string}`;\nexport type ProductID = `prd_${string}`;\nexport type EventID = `evt_${string}`;\nexport type WebhookID = `wh_${string}`;\n\n// Currency enum\nexport type Currency =\n | \"USD\"\n | \"EUR\"\n | \"GBP\"\n | \"CAD\"\n | \"AUD\"\n | \"JPY\"\n | \"ARS\"\n | \"BRL\"\n | \"MXN\"\n | \"CLP\";\n\n// Common parameters\nexport interface ListParams extends Record<string, unknown> {\n limit?: number;\n cursor?: string;\n startDate?: string;\n endDate?: string;\n}\n\nexport interface RetrieveOptions {\n expand?: string[];\n}\n\n// Request options\nexport interface RequestOptions {\n idempotencyKey?: string;\n timeout?: number;\n}\n\n/**\n * Generated types interface - augmented by CLI after 'commet pull'\n *\n * This interface gets filled by module augmentation when you run `commet pull`.\n * The CLI generates a .commet.d.ts file that augments this interface with your\n * organization's specific event and seat types.\n *\n * @example\n * // After running `commet pull`, TypeScript will automatically know your types:\n * await commet.usage.events.create({\n * eventType: 'api_call', // Autocomplete works!\n * customerId: 'cus_123'\n * });\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: <explanation>\nexport interface CommetGeneratedTypes {}\n\n/**\n * Helper type that provides fallback to string if types are not generated\n */\nexport type GeneratedEventType = CommetGeneratedTypes extends {\n eventType: infer T;\n}\n ? T\n : string;\n\n/**\n * Helper type that provides fallback to string if types are not generated\n */\nexport type GeneratedSeatType = CommetGeneratedTypes extends {\n seatType: infer T;\n}\n ? T\n : string;\n","import type {\n ApiResponse,\n CommetConfig,\n Environment,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\n\nexport interface RetryConfig {\n maxRetries: number;\n baseDelay: number;\n maxDelay: number;\n retryableStatusCodes: number[];\n}\n\nconst DEFAULT_RETRY_CONFIG: RetryConfig = {\n maxRetries: 3,\n baseDelay: 1000, // 1s\n maxDelay: 8000, // 8s\n retryableStatusCodes: [408, 429, 500, 502, 503, 504],\n};\n\nexport class CommetHTTPClient {\n private config: CommetConfig;\n private environment: Environment;\n private retryConfig: RetryConfig;\n\n constructor(config: CommetConfig, environment: Environment) {\n this.config = config;\n this.environment = environment;\n this.retryConfig = {\n ...DEFAULT_RETRY_CONFIG,\n maxRetries: config.retries ?? DEFAULT_RETRY_CONFIG.maxRetries,\n };\n }\n\n async get<T = unknown>(\n endpoint: string,\n params?: Record<string, unknown>,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"GET\", endpoint, undefined, options, params);\n }\n\n async post<T = unknown>(\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"POST\", endpoint, data, options);\n }\n\n async put<T = unknown>(\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"PUT\", endpoint, data, options);\n }\n\n async delete<T = unknown>(\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n ): Promise<ApiResponse<T>> {\n return this.request(\"DELETE\", endpoint, data, options);\n }\n\n /**\n * Core request method with retry logic\n */\n private async request<T = unknown>(\n method: string,\n endpoint: string,\n data?: unknown,\n options?: RequestOptions,\n params?: Record<string, unknown>,\n ): Promise<ApiResponse<T>> {\n const url = this.buildURL(endpoint, params);\n return this.executeRequest(method, url, data, options);\n }\n\n /**\n * Execute real API request with retry logic\n */\n private async executeRequest<T = unknown>(\n method: string,\n url: string,\n data?: unknown,\n options?: RequestOptions,\n attempt = 1,\n ): Promise<ApiResponse<T>> {\n try {\n const headers: Record<string, string> = {\n \"x-api-key\": this.config.apiKey,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": \"commet/0.1.0\",\n };\n\n if (options?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = options.idempotencyKey;\n } else if (method === \"POST\" && data) {\n headers[\"Idempotency-Key\"] = this.generateIdempotencyKey();\n }\n\n const requestConfig: RequestInit = {\n method,\n headers,\n signal: AbortSignal.timeout(\n options?.timeout ?? this.config.timeout ?? 30000,\n ),\n };\n\n if (data) {\n requestConfig.body = JSON.stringify(data);\n }\n\n if (this.config.debug) {\n console.log(`[Commet SDK] ${method} ${url}`);\n if (data) {\n console.log(\"Request data:\", JSON.stringify(data, null, 2));\n }\n }\n\n const response = await fetch(url, requestConfig);\n\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Response status: ${response.status} ${response.statusText}`,\n );\n }\n\n let responseData: unknown;\n let responseText: string;\n\n try {\n const responseClone = response.clone();\n responseData = await response.json();\n responseText = \"\";\n } catch (jsonError) {\n try {\n responseText = await response.text();\n } catch (textError) {\n responseText = \"Failed to read response body\";\n }\n if (this.config.debug) {\n console.log(\n \"[Commet SDK] Failed to parse JSON response:\",\n responseText,\n );\n }\n throw new CommetAPIError(\n `Invalid JSON response: ${response.status} ${response.statusText}`,\n response.status,\n \"INVALID_JSON\",\n { responseText },\n );\n }\n\n if (!response.ok) {\n // Check if we should retry\n if (\n attempt <= this.retryConfig.maxRetries &&\n this.retryConfig.retryableStatusCodes.includes(response.status)\n ) {\n const delay = Math.min(\n this.retryConfig.baseDelay * 2 ** (attempt - 1),\n this.retryConfig.maxDelay,\n );\n\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`,\n );\n }\n\n await this.sleep(delay);\n return this.executeRequest(method, url, data, options, attempt + 1);\n }\n\n // Log error response for debugging\n if (this.config.debug) {\n console.log(\n \"[Commet SDK] Error response:\",\n JSON.stringify(responseData, null, 2),\n );\n }\n\n // Type guard for error response\n const isErrorResponse = (\n data: unknown,\n ): data is {\n message?: string;\n errors?: Record<string, string[]>;\n code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle different error types\n if (response.status === 400 && errorData.errors) {\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n errorData.errors,\n );\n }\n\n throw new CommetAPIError(\n errorData.message || `Request failed with status ${response.status}`,\n response.status,\n errorData.code,\n errorData.details,\n );\n }\n\n if (this.config.debug) {\n console.log(\"[Commet SDK] Response:\", responseData);\n }\n\n return responseData as ApiResponse<T>;\n } catch (error) {\n // Handle network errors and timeouts\n if (error instanceof TypeError && error.message.includes(\"fetch\")) {\n if (attempt <= this.retryConfig.maxRetries) {\n const delay = Math.min(\n this.retryConfig.baseDelay * 2 ** (attempt - 1),\n this.retryConfig.maxDelay,\n );\n\n if (this.config.debug) {\n console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);\n }\n\n await this.sleep(delay);\n return this.executeRequest(method, url, data, options, attempt + 1);\n }\n }\n\n throw error;\n }\n }\n\n /**\n * Get base URL based on environment\n */\n private getBaseURL(): string {\n return this.environment === \"production\"\n ? \"https://billing.commet.co\"\n : \"https://sandbox.commet.co\";\n }\n\n /**\n * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n const baseURL = this.getBaseURL();\n\n // Construct full path with /api prefix\n const fullPath = `/api${endpoint.startsWith(\"/\") ? endpoint : `/${endpoint}`}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - baseURL: ${baseURL}, endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, baseURL);\n\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined && value !== null) {\n url.searchParams.append(key, String(value));\n }\n }\n }\n\n const finalUrl = url.toString();\n\n // Debug final URL\n if (this.config.debug) {\n console.log(`[Commet SDK] Final URL: ${finalUrl}`);\n }\n\n return finalUrl;\n }\n\n /**\n * Generate idempotency key\n */\n private generateIdempotencyKey(): string {\n // Generate UUID-like key for idempotency\n return `sdk_${Date.now()}_${Math.random().toString(36).substring(2)}`;\n }\n\n /**\n * Sleep for specified milliseconds\n */\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n","import { CustomersResource } from \"./resources/customers\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { UsageResource } from \"./resources/usage\";\nimport type { CommetConfig, Environment } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n private environment: Environment;\n\n public readonly customers: CustomersResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n\n constructor(config: CommetConfig) {\n if (!config.apiKey) {\n throw new Error(\"Commet SDK: API key is required\");\n }\n\n if (!config.apiKey.startsWith(\"ck_\")) {\n throw new Error(\n \"Commet SDK: Invalid API key format. Expected format: ck_xxx...\",\n );\n }\n\n // Default to sandbox for safety\n this.environment = config.environment || \"sandbox\";\n\n this.httpClient = new CommetHTTPClient(config, this.environment);\n this.customers = new CustomersResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n\n if (config.debug) {\n console.log(`[Commet SDK] Initialized in ${this.environment} mode`);\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n const baseURL =\n this.environment === \"production\"\n ? \"https://billing.commet.co\"\n : \"https://sandbox.commet.co\";\n console.log(\"Base URL:\", baseURL);\n }\n }\n\n getEnvironment(): Environment {\n return this.environment;\n }\n\n isSandbox(): boolean {\n return this.environment === \"sandbox\";\n }\n\n isProduction(): boolean {\n return this.environment === \"production\";\n }\n}\n","import type { Environment } from \"../types/common\";\n\n/**\n * Check if environment is sandbox\n */\nexport function isSandbox(environment: Environment): boolean {\n return environment === \"sandbox\";\n}\n\n/**\n * Check if environment is production\n */\nexport function isProduction(environment: Environment): boolean {\n return environment === \"production\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC2GO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAAoB,YAA8B;AAA9B;AAAA,EAA+B;AAAA,EAEnD,MAAM,OACJ,QACA,SACgC;AAChC,WAAO,KAAK,WAAW,KAAK,cAAc,QAAQ,OAAO;AAAA,EAC3D;AAAA,EAEA,MAAM,SACJ,YACA,SACgC;AAChC,UAAM,SAAS,SAAS,SACpB,EAAE,QAAQ,QAAQ,OAAO,KAAK,GAAG,EAAE,IACnC;AACJ,WAAO,KAAK,WAAW,IAAI,cAAc,UAAU,IAAI,MAAM;AAAA,EAC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36
|
-
async add(
|
|
36
|
+
async add(params, options) {
|
|
37
37
|
return this.httpClient.post(
|
|
38
|
-
|
|
39
|
-
{
|
|
38
|
+
"/seats",
|
|
39
|
+
{
|
|
40
|
+
customerId: params.customerId,
|
|
41
|
+
seatType: params.seatType,
|
|
42
|
+
count: params.count
|
|
43
|
+
},
|
|
40
44
|
options
|
|
41
45
|
);
|
|
42
46
|
}
|
|
43
|
-
async remove(
|
|
44
|
-
return this.httpClient.
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
+
async remove(params, options) {
|
|
48
|
+
return this.httpClient.delete(
|
|
49
|
+
"/seats",
|
|
50
|
+
{
|
|
51
|
+
customerId: params.customerId,
|
|
52
|
+
seatType: params.seatType,
|
|
53
|
+
count: params.count
|
|
54
|
+
},
|
|
47
55
|
options
|
|
48
56
|
);
|
|
49
57
|
}
|
|
50
|
-
async set(
|
|
51
|
-
return this.httpClient.
|
|
52
|
-
|
|
53
|
-
{
|
|
58
|
+
async set(params, options) {
|
|
59
|
+
return this.httpClient.put(
|
|
60
|
+
"/seats",
|
|
61
|
+
{
|
|
62
|
+
customerId: params.customerId,
|
|
63
|
+
seatType: params.seatType,
|
|
64
|
+
count: params.count
|
|
65
|
+
},
|
|
54
66
|
options
|
|
55
67
|
);
|
|
56
68
|
}
|
|
57
|
-
async bulkUpdate(
|
|
58
|
-
return this.httpClient.
|
|
59
|
-
|
|
60
|
-
{ seats },
|
|
69
|
+
async bulkUpdate(params, options) {
|
|
70
|
+
return this.httpClient.put(
|
|
71
|
+
"/seats/bulk",
|
|
72
|
+
{ customerId: params.customerId, seats: params.seats },
|
|
61
73
|
options
|
|
62
74
|
);
|
|
63
75
|
}
|
|
64
|
-
async getBalance(
|
|
65
|
-
return this.httpClient.get(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
async getAllBalances(customerId) {
|
|
70
|
-
return this.httpClient.get(`/customers/${customerId}/seats/balances`);
|
|
76
|
+
async getBalance(params) {
|
|
77
|
+
return this.httpClient.get("/seats/balance", {
|
|
78
|
+
customerId: params.customerId,
|
|
79
|
+
seatType: params.seatType
|
|
80
|
+
});
|
|
71
81
|
}
|
|
72
|
-
async
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
seatType
|
|
77
|
-
};
|
|
78
|
-
return this.httpClient.get(
|
|
79
|
-
`/customers/${customerId}/seats/history`,
|
|
80
|
-
queryParams
|
|
81
|
-
);
|
|
82
|
+
async getAllBalances(params) {
|
|
83
|
+
return this.httpClient.get("/seats/balances", {
|
|
84
|
+
customerId: params.customerId
|
|
85
|
+
});
|
|
82
86
|
}
|
|
83
87
|
async listEvents(params) {
|
|
84
88
|
return this.httpClient.get("/seats/events", params);
|
|
@@ -86,7 +90,7 @@ var SeatsResource = class {
|
|
|
86
90
|
};
|
|
87
91
|
|
|
88
92
|
// src/resources/usage.ts
|
|
89
|
-
var
|
|
93
|
+
var UsageResource = class {
|
|
90
94
|
constructor(httpClient) {
|
|
91
95
|
this.httpClient = httpClient;
|
|
92
96
|
}
|
|
@@ -107,24 +111,11 @@ var UsageEventsResource = class {
|
|
|
107
111
|
return this.httpClient.get("/usage/events", params);
|
|
108
112
|
}
|
|
109
113
|
async delete(eventId, options) {
|
|
110
|
-
return this.httpClient.delete(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.httpClient = httpClient;
|
|
116
|
-
}
|
|
117
|
-
async list() {
|
|
118
|
-
return this.httpClient.get("/usage/metrics");
|
|
119
|
-
}
|
|
120
|
-
async retrieve(metricId) {
|
|
121
|
-
return this.httpClient.get(`/usage/metrics/${metricId}`);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var UsageResource = class {
|
|
125
|
-
constructor(httpClient) {
|
|
126
|
-
this.events = new UsageEventsResource(httpClient);
|
|
127
|
-
this.metrics = new UsageMetricsResource(httpClient);
|
|
114
|
+
return this.httpClient.delete(
|
|
115
|
+
`/usage/events/${eventId}`,
|
|
116
|
+
void 0,
|
|
117
|
+
options
|
|
118
|
+
);
|
|
128
119
|
}
|
|
129
120
|
};
|
|
130
121
|
|
|
@@ -182,8 +173,8 @@ var CommetHTTPClient = class {
|
|
|
182
173
|
async put(endpoint, data, options) {
|
|
183
174
|
return this.request("PUT", endpoint, data, options);
|
|
184
175
|
}
|
|
185
|
-
async delete(endpoint, options) {
|
|
186
|
-
return this.request("DELETE", endpoint,
|
|
176
|
+
async delete(endpoint, data, options) {
|
|
177
|
+
return this.request("DELETE", endpoint, data, options);
|
|
187
178
|
}
|
|
188
179
|
/**
|
|
189
180
|
* Core request method with retry logic
|