commet 0.0.1 → 0.2.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.
@@ -0,0 +1,353 @@
1
+ type Environment = "development" | "production";
2
+ type CommetConfig = {
3
+ apiKey: string;
4
+ environment?: "auto" | Environment;
5
+ debug?: boolean;
6
+ timeout?: number;
7
+ retries?: number;
8
+ };
9
+ interface ApiResponse<T = unknown> {
10
+ success: boolean;
11
+ data?: T;
12
+ error?: string;
13
+ message?: string;
14
+ devMode?: boolean;
15
+ }
16
+ interface PaginatedResponse<T> {
17
+ data: T[];
18
+ hasMore: boolean;
19
+ nextCursor?: string;
20
+ totalCount?: number;
21
+ }
22
+ interface PaginatedList<T> extends PaginatedResponse<T> {
23
+ next(): Promise<PaginatedList<T>>;
24
+ all(): Promise<T[]>;
25
+ }
26
+ declare class CommetError extends Error {
27
+ code?: string | undefined;
28
+ statusCode?: number | undefined;
29
+ details?: unknown | undefined;
30
+ constructor(message: string, code?: string | undefined, statusCode?: number | undefined, details?: unknown | undefined);
31
+ }
32
+ declare class CommetAPIError extends CommetError {
33
+ statusCode: number;
34
+ code?: string | undefined;
35
+ details?: unknown | undefined;
36
+ constructor(message: string, statusCode: number, code?: string | undefined, details?: unknown | undefined);
37
+ }
38
+ declare class CommetValidationError extends CommetError {
39
+ validationErrors: Record<string, string[]>;
40
+ constructor(message: string, validationErrors: Record<string, string[]>);
41
+ }
42
+ type CustomerID = `cus_${string}`;
43
+ type AgreementID = `agr_${string}`;
44
+ type InvoiceID = `inv_${string}`;
45
+ type PhaseID = `phs_${string}`;
46
+ type ItemID = `itm_${string}`;
47
+ type ProductID = `prd_${string}`;
48
+ type EventID = `evt_${string}`;
49
+ type WebhookID = `wh_${string}`;
50
+ type Currency = "USD" | "EUR" | "GBP" | "CAD" | "AUD" | "JPY" | "ARS" | "BRL" | "MXN" | "CLP";
51
+ interface ListParams extends Record<string, unknown> {
52
+ limit?: number;
53
+ cursor?: string;
54
+ startDate?: string;
55
+ endDate?: string;
56
+ }
57
+ interface RetrieveOptions {
58
+ expand?: string[];
59
+ }
60
+ interface RequestOptions {
61
+ idempotencyKey?: string;
62
+ timeout?: number;
63
+ }
64
+
65
+ declare class CommetHTTPClient {
66
+ private config;
67
+ private environment;
68
+ private retryConfig;
69
+ constructor(config: CommetConfig, environment: Environment);
70
+ get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
71
+ post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
72
+ put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
73
+ delete<T = unknown>(endpoint: string, options?: RequestOptions): Promise<ApiResponse<T>>;
74
+ /**
75
+ * Core request method with retry logic and dev mode support
76
+ */
77
+ private request;
78
+ /**
79
+ * Log request in development mode instead of sending to API
80
+ */
81
+ private logDevRequest;
82
+ /**
83
+ * Execute real API request with retry logic
84
+ */
85
+ private executeRequest;
86
+ /**
87
+ * Build full URL from endpoint and params
88
+ */
89
+ private buildURL;
90
+ /**
91
+ * Generate idempotency key
92
+ */
93
+ private generateIdempotencyKey;
94
+ /**
95
+ * Sleep for specified milliseconds
96
+ */
97
+ private sleep;
98
+ }
99
+
100
+ interface Customer {
101
+ id: CustomerID;
102
+ organizationId: string;
103
+ legalName: string;
104
+ displayName?: string;
105
+ domain?: string;
106
+ website?: string;
107
+ taxStatus: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
108
+ currency: Currency;
109
+ addressId: string;
110
+ billingEmail?: string;
111
+ paymentTerms?: string;
112
+ timezone?: string;
113
+ language?: string;
114
+ industry?: string;
115
+ employeeCount?: string;
116
+ metadata?: Record<string, unknown>;
117
+ isActive: boolean;
118
+ createdAt: string;
119
+ updatedAt: string;
120
+ }
121
+ interface CreateCustomerParams {
122
+ legalName: string;
123
+ displayName?: string;
124
+ domain?: string;
125
+ website?: string;
126
+ taxStatus?: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
127
+ currency?: Currency;
128
+ address: {
129
+ line1: string;
130
+ line2?: string;
131
+ city: string;
132
+ state?: string;
133
+ postalCode: string;
134
+ country: string;
135
+ region?: string;
136
+ };
137
+ billingEmail?: string;
138
+ paymentTerms?: string;
139
+ timezone?: string;
140
+ language?: string;
141
+ industry?: string;
142
+ employeeCount?: string;
143
+ metadata?: Record<string, unknown>;
144
+ }
145
+ interface UpdateCustomerParams {
146
+ legalName?: string;
147
+ displayName?: string;
148
+ domain?: string;
149
+ website?: string;
150
+ taxStatus?: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
151
+ currency?: Currency;
152
+ billingEmail?: string;
153
+ paymentTerms?: string;
154
+ timezone?: string;
155
+ language?: string;
156
+ industry?: string;
157
+ employeeCount?: string;
158
+ metadata?: Record<string, unknown>;
159
+ isActive?: boolean;
160
+ }
161
+ interface ListCustomersParams extends ListParams {
162
+ taxStatus?: "TAXED" | "TAX_EXEMPT" | "REVERSE_CHARGE" | "NOT_APPLICABLE";
163
+ currency?: Currency;
164
+ isActive?: boolean;
165
+ search?: string;
166
+ }
167
+ /**
168
+ * Customer resource for managing customer data
169
+ */
170
+ declare class CustomersResource {
171
+ private httpClient;
172
+ constructor(httpClient: CommetHTTPClient);
173
+ create(params: CreateCustomerParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
174
+ retrieve(customerId: CustomerID, options?: RetrieveOptions): Promise<ApiResponse<Customer>>;
175
+ update(customerId: CustomerID, params: UpdateCustomerParams, options?: RequestOptions): Promise<ApiResponse<Customer>>;
176
+ list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>>;
177
+ /**
178
+ * Deactivate a customer (soft delete)
179
+ */
180
+ deactivate(customerId: CustomerID, options?: RequestOptions): Promise<ApiResponse<Customer>>;
181
+ }
182
+
183
+ interface SeatBalance {
184
+ id: string;
185
+ organizationId: string;
186
+ customerId: CustomerID;
187
+ seatType: string;
188
+ balance: number;
189
+ asOf: string;
190
+ createdAt: string;
191
+ updatedAt: string;
192
+ }
193
+ interface SeatEvent {
194
+ id: string;
195
+ organizationId: string;
196
+ customerId: CustomerID;
197
+ seatType: string;
198
+ eventType: "add" | "remove" | "set";
199
+ quantity: number;
200
+ previousBalance?: number;
201
+ newBalance: number;
202
+ ts: string;
203
+ createdAt: string;
204
+ }
205
+ interface SeatBalanceResponse {
206
+ current: number;
207
+ asOf: string;
208
+ }
209
+ interface BulkSeatUpdate {
210
+ [seatType: string]: number;
211
+ }
212
+ interface ListSeatEventsParams extends ListParams {
213
+ customerId?: CustomerID;
214
+ seatType?: string;
215
+ eventType?: "add" | "remove" | "set";
216
+ }
217
+ /**
218
+ * Seats resource for seat-based billing management
219
+ */
220
+ declare class SeatsResource {
221
+ private httpClient;
222
+ constructor(httpClient: CommetHTTPClient);
223
+ add(customerId: CustomerID, seatType: string, count: number, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
224
+ remove(customerId: CustomerID, seatType: string, count: number, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
225
+ set(customerId: CustomerID, seatType: string, count: number, options?: RequestOptions): Promise<ApiResponse<SeatEvent>>;
226
+ bulkUpdate(customerId: CustomerID, seats: BulkSeatUpdate, options?: RequestOptions): Promise<ApiResponse<SeatEvent[]>>;
227
+ getBalance(customerId: CustomerID, seatType: string): Promise<ApiResponse<SeatBalanceResponse>>;
228
+ getAllBalances(customerId: CustomerID): Promise<ApiResponse<Record<string, SeatBalanceResponse>>>;
229
+ getHistory(customerId: CustomerID, seatType: string, params?: ListSeatEventsParams): Promise<ApiResponse<SeatEvent[]>>;
230
+ listEvents(params?: ListSeatEventsParams): Promise<ApiResponse<SeatEvent[]>>;
231
+ }
232
+
233
+ interface UsageEvent {
234
+ id: EventID;
235
+ organizationId: string;
236
+ customerId: CustomerID;
237
+ eventType: string;
238
+ idempotencyKey?: string;
239
+ ts: string;
240
+ properties?: UsageEventProperty[];
241
+ createdAt: string;
242
+ }
243
+ interface UsageEventProperty {
244
+ id: string;
245
+ usageEventId: EventID;
246
+ property: string;
247
+ value: string;
248
+ createdAt: string;
249
+ }
250
+ interface CreateUsageEventParams {
251
+ eventType: string;
252
+ customerId: CustomerID;
253
+ idempotencyKey?: string;
254
+ timestamp?: string;
255
+ properties?: Array<{
256
+ property: string;
257
+ value: string;
258
+ }>;
259
+ }
260
+ interface CreateBatchUsageEventsParams {
261
+ events: CreateUsageEventParams[];
262
+ }
263
+ interface BatchResult<T> {
264
+ successful: T[];
265
+ failed: Array<{
266
+ index: number;
267
+ error: string;
268
+ data: CreateUsageEventParams;
269
+ }>;
270
+ }
271
+ interface ListUsageEventsParams extends ListParams {
272
+ customerId?: CustomerID;
273
+ eventType?: string;
274
+ idempotencyKey?: string;
275
+ }
276
+ /**
277
+ * Usage Events resource - Track business events for usage-based billing
278
+ */
279
+ declare class UsageEventsResource {
280
+ private httpClient;
281
+ constructor(httpClient: CommetHTTPClient);
282
+ create(params: CreateUsageEventParams, options?: RequestOptions): Promise<ApiResponse<UsageEvent>>;
283
+ createBatch(params: CreateBatchUsageEventsParams, options?: RequestOptions): Promise<ApiResponse<BatchResult<UsageEvent>>>;
284
+ retrieve(eventId: EventID): Promise<ApiResponse<UsageEvent>>;
285
+ list(params?: ListUsageEventsParams): Promise<ApiResponse<UsageEvent[]>>;
286
+ delete(eventId: EventID, options?: RequestOptions): Promise<ApiResponse<{
287
+ deleted: boolean;
288
+ }>>;
289
+ }
290
+ interface UsageMetric {
291
+ id: string;
292
+ organizationId: string;
293
+ name: string;
294
+ eventType: string;
295
+ aggregation: "count" | "unique" | "sum";
296
+ property?: string;
297
+ filters?: UsageMetricFilter[];
298
+ createdAt: string;
299
+ updatedAt: string;
300
+ }
301
+ interface UsageMetricFilter {
302
+ id: string;
303
+ usageMetricId: string;
304
+ property: string;
305
+ operator: "equals" | "not_equals" | "greater_than" | "less_than" | "contains";
306
+ value: string;
307
+ createdAt: string;
308
+ }
309
+ /**
310
+ * Usage Metrics resource - Read-only access to metrics
311
+ */
312
+ declare class UsageMetricsResource {
313
+ private httpClient;
314
+ constructor(httpClient: CommetHTTPClient);
315
+ list(): Promise<ApiResponse<UsageMetric[]>>;
316
+ retrieve(metricId: string): Promise<ApiResponse<UsageMetric>>;
317
+ }
318
+ /**
319
+ * Usage resource combining events and metrics
320
+ */
321
+ declare class UsageResource {
322
+ readonly events: UsageEventsResource;
323
+ readonly metrics: UsageMetricsResource;
324
+ constructor(httpClient: CommetHTTPClient);
325
+ }
326
+
327
+ /**
328
+ * Main Commet SDK client
329
+ */
330
+ declare class Commet {
331
+ private httpClient;
332
+ private environment;
333
+ readonly customers: CustomersResource;
334
+ readonly usage: UsageResource;
335
+ readonly seats: SeatsResource;
336
+ constructor(config: CommetConfig);
337
+ getEnvironment(): Environment;
338
+ isDevelopment(): boolean;
339
+ isProduction(): boolean;
340
+ }
341
+
342
+ /**
343
+ * Detect the current environment based on NODE_ENV and hostname
344
+ */
345
+ declare function detectEnvironment(): Environment;
346
+ declare function isDevelopment(environment: Environment): boolean;
347
+ declare function isProduction(environment: Environment): boolean;
348
+
349
+ /**
350
+ * Commet SDK - Billing and usage tracking SDK
351
+ */
352
+
353
+ 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 UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type UsageMetric, type UsageMetricFilter, type WebhookID, Commet as default, detectEnvironment, isDevelopment, isProduction };