@commet/node 1.7.1 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -44,62 +44,47 @@ module.exports = __toCommonJS(index_exports);
44
44
 
45
45
  // src/customer.ts
46
46
  var CustomerContext = class {
47
- constructor(externalId, resources) {
48
- /**
49
- * Feature access methods - delegates to FeaturesResource
50
- */
47
+ constructor(customerId, resources) {
51
48
  this.features = {
52
- get: (code, options) => this.featuresResource.get({ code, externalId: this.externalId }, options),
49
+ get: (code, options) => this.featuresResource.get({ code, customerId: this.customerId }, options),
53
50
  check: (code, options) => this.featuresResource.check(
54
- { code, externalId: this.externalId },
51
+ { code, customerId: this.customerId },
55
52
  options
56
53
  ),
57
54
  canUse: (code, options) => this.featuresResource.canUse(
58
- { code, externalId: this.externalId },
55
+ { code, customerId: this.customerId },
59
56
  options
60
57
  ),
61
- list: (options) => this.featuresResource.list(this.externalId, options)
58
+ list: (options) => this.featuresResource.list(this.customerId, options)
62
59
  };
63
- /**
64
- * Seat management methods - delegates to SeatsResource
65
- */
66
60
  this.seats = {
67
61
  add: (seatType, count = 1, options) => this.seatsResource.add(
68
- { externalId: this.externalId, seatType, count },
62
+ { customerId: this.customerId, seatType, count },
69
63
  options
70
64
  ),
71
65
  remove: (seatType, count = 1, options) => this.seatsResource.remove(
72
- { externalId: this.externalId, seatType, count },
66
+ { customerId: this.customerId, seatType, count },
73
67
  options
74
68
  ),
75
69
  set: (seatType, count, options) => this.seatsResource.set(
76
- { externalId: this.externalId, seatType, count },
70
+ { customerId: this.customerId, seatType, count },
77
71
  options
78
72
  ),
79
- getBalance: (seatType) => this.seatsResource.getBalance({ externalId: this.externalId, seatType })
73
+ getBalance: (seatType) => this.seatsResource.getBalance({ customerId: this.customerId, seatType })
80
74
  };
81
- /**
82
- * Usage tracking methods - delegates to UsageResource
83
- */
84
75
  this.usage = {
85
76
  track: (feature, value, properties, options) => this.usageResource.track(
86
- { externalId: this.externalId, feature, value, properties },
77
+ { customerId: this.customerId, feature, value, properties },
87
78
  options
88
79
  )
89
80
  };
90
- /**
91
- * Subscription methods - delegates to SubscriptionsResource
92
- */
93
81
  this.subscription = {
94
- get: () => this.subscriptionsResource.get(this.externalId)
82
+ get: () => this.subscriptionsResource.get(this.customerId)
95
83
  };
96
- /**
97
- * Portal methods - delegates to PortalResource
98
- */
99
84
  this.portal = {
100
- getUrl: (options) => this.portalResource.getUrl({ externalId: this.externalId }, options)
85
+ getUrl: (options) => this.portalResource.getUrl({ customerId: this.customerId }, options)
101
86
  };
102
- this.externalId = externalId;
87
+ this.customerId = customerId;
103
88
  this.featuresResource = resources.features;
104
89
  this.seatsResource = resources.seats;
105
90
  this.usageResource = resources.usage;
@@ -133,14 +118,14 @@ var CustomersResource = class {
133
118
  this.httpClient = httpClient;
134
119
  }
135
120
  /**
136
- * Create a customer (idempotent with externalId)
121
+ * Create a customer (idempotent when id is provided)
137
122
  */
138
123
  async create(params, options) {
139
124
  return this.httpClient.post(
140
125
  "/customers",
141
126
  {
142
127
  billingEmail: params.email,
143
- externalId: params.externalId,
128
+ externalId: params.id,
144
129
  fullName: params.fullName,
145
130
  domain: params.domain,
146
131
  website: params.website,
@@ -159,7 +144,7 @@ var CustomersResource = class {
159
144
  async createBatch(params, options) {
160
145
  const customers = params.customers.map((c) => ({
161
146
  billingEmail: c.email,
162
- externalId: c.externalId,
147
+ externalId: c.id,
163
148
  fullName: c.fullName,
164
149
  domain: c.domain,
165
150
  website: c.website,
@@ -185,14 +170,14 @@ var CustomersResource = class {
185
170
  `/customers/${params.customerId}`,
186
171
  {
187
172
  billingEmail: params.email,
188
- externalId: params.externalId,
189
173
  fullName: params.fullName,
190
174
  domain: params.domain,
191
175
  website: params.website,
192
176
  timezone: params.timezone,
193
177
  language: params.language,
194
178
  industry: params.industry,
195
- metadata: params.metadata
179
+ metadata: params.metadata,
180
+ address: params.address
196
181
  },
197
182
  options
198
183
  );
@@ -220,40 +205,17 @@ var FeaturesResource = class {
220
205
  constructor(httpClient) {
221
206
  this.httpClient = httpClient;
222
207
  }
223
- /**
224
- * Get detailed feature access/usage for a customer
225
- *
226
- * @example
227
- * ```typescript
228
- * const seats = await commet.features.get({ code: "team_members", externalId: "user_123" });
229
- * console.log(seats.current, seats.included, seats.remaining);
230
- * ```
231
- */
232
208
  async get(params, options) {
233
- const { code, externalId } = params;
234
209
  return this.httpClient.get(
235
- `/features/${code}`,
236
- { externalId },
210
+ `/features/${params.code}`,
211
+ { customerId: params.customerId },
237
212
  options
238
213
  );
239
214
  }
240
- /**
241
- * Check if a boolean feature is enabled for a customer
242
- *
243
- * @example
244
- * ```typescript
245
- * const { allowed } = await commet.features.check({
246
- * code: "custom_branding",
247
- * externalId: "user_123"
248
- * });
249
- * if (!allowed) redirect("/upgrade");
250
- * ```
251
- */
252
215
  async check(params, options) {
253
- const { code, externalId } = params;
254
216
  const result = await this.httpClient.get(
255
- `/features/${code}`,
256
- { externalId },
217
+ `/features/${params.code}`,
218
+ { customerId: params.customerId },
257
219
  options
258
220
  );
259
221
  if (!result.success || !result.data) {
@@ -269,49 +231,15 @@ var FeaturesResource = class {
269
231
  message: result.message
270
232
  };
271
233
  }
272
- /**
273
- * Check if customer can use one more unit of a feature
274
- *
275
- * Returns whether the customer can add one more (allowed)
276
- * and whether they'll be charged extra (willBeCharged).
277
- *
278
- * @example
279
- * ```typescript
280
- * const { allowed, willBeCharged } = await commet.features.canUse({
281
- * code: "team_members",
282
- * externalId: "user_123"
283
- * });
284
- *
285
- * if (!allowed) {
286
- * return { error: "Upgrade to add more members" };
287
- * }
288
- *
289
- * if (willBeCharged) {
290
- * // Show confirmation: "This will cost $10/month extra"
291
- * }
292
- * ```
293
- */
294
234
  async canUse(params, options) {
295
- const { code, externalId } = params;
296
235
  return this.httpClient.get(
297
- `/features/${code}`,
298
- { externalId, action: "canUse" },
236
+ `/features/${params.code}`,
237
+ { customerId: params.customerId, action: "canUse" },
299
238
  options
300
239
  );
301
240
  }
302
- /**
303
- * List all features for a customer's active subscription
304
- *
305
- * @example
306
- * ```typescript
307
- * const features = await commet.features.list({ externalId: "user_123" });
308
- * for (const feature of features) {
309
- * console.log(feature.code, feature.allowed);
310
- * }
311
- * ```
312
- */
313
- async list(externalId, options) {
314
- return this.httpClient.get("/features", { externalId }, options);
241
+ async list(customerId, options) {
242
+ return this.httpClient.get("/features", { customerId }, options);
315
243
  }
316
244
  };
317
245
 
@@ -355,14 +283,6 @@ var PortalResource = class {
355
283
  constructor(httpClient) {
356
284
  this.httpClient = httpClient;
357
285
  }
358
- /**
359
- * Get a portal URL
360
- *
361
- * @example
362
- * ```typescript
363
- * const portal = await commet.portal.getUrl({ externalId: 'user_123' });
364
- * ```
365
- */
366
286
  async getUrl(params, options) {
367
287
  return this.httpClient.post("/portal/request-access", params, options);
368
288
  }
@@ -373,99 +293,27 @@ var SeatsResource = class {
373
293
  constructor(httpClient) {
374
294
  this.httpClient = httpClient;
375
295
  }
376
- /**
377
- * Add seats
378
- *
379
- * @example
380
- * ```typescript
381
- * await commet.seats.add({
382
- * externalId: 'user_123',
383
- * seatType: 'editor',
384
- * count: 5
385
- * });
386
- * ```
387
- */
388
296
  async add(params, options) {
389
297
  return this.httpClient.post("/seats", params, options);
390
298
  }
391
- /**
392
- * Remove seats
393
- *
394
- * @example
395
- * ```typescript
396
- * await commet.seats.remove({
397
- * externalId: 'user_123',
398
- * seatType: 'editor',
399
- * count: 2
400
- * });
401
- * ```
402
- */
403
299
  async remove(params, options) {
404
300
  return this.httpClient.delete("/seats", params, options);
405
301
  }
406
- /**
407
- * Set seats to a specific count
408
- *
409
- * @example
410
- * ```typescript
411
- * await commet.seats.set({
412
- * externalId: 'user_123',
413
- * seatType: 'editor',
414
- * count: 10
415
- * });
416
- * ```
417
- */
418
302
  async set(params, options) {
419
303
  return this.httpClient.put("/seats", params, options);
420
304
  }
421
- /**
422
- * Set all seat types
423
- *
424
- * @example
425
- * ```typescript
426
- * await commet.seats.setAll({
427
- * externalId: 'user_123',
428
- * seats: { editor: 10, viewer: 50 }
429
- * });
430
- * ```
431
- */
432
305
  async setAll(params, options) {
433
306
  return this.httpClient.put("/seats/bulk", params, options);
434
307
  }
435
- /**
436
- * Get balance for a seat type
437
- *
438
- * @example
439
- * ```typescript
440
- * const balance = await commet.seats.getBalance({
441
- * externalId: 'user_123',
442
- * seatType: 'editor'
443
- * });
444
- * ```
445
- */
446
308
  async getBalance(params) {
447
- const { customerId, externalId, seatType } = params;
448
309
  return this.httpClient.get("/seats/balance", {
449
- customerId,
450
- externalId,
451
- seatType
310
+ customerId: params.customerId,
311
+ seatType: params.seatType
452
312
  });
453
313
  }
454
- /**
455
- * Get all seat balances
456
- *
457
- * @example
458
- * ```typescript
459
- * const balances = await commet.seats.getAllBalances({
460
- * externalId: 'user_123'
461
- * });
462
- * ```
463
- */
464
314
  async getAllBalances(params) {
465
- const { customerId, externalId } = params;
466
315
  return this.httpClient.get("/seats/balances", {
467
- customerId,
468
- externalId
316
+ customerId: params.customerId
469
317
  });
470
318
  }
471
319
  };
@@ -499,8 +347,8 @@ var SubscriptionsResource = class {
499
347
  * const sub = await commet.subscriptions.get('user_123');
500
348
  * ```
501
349
  */
502
- async get(externalId) {
503
- return this.httpClient.get("/subscriptions/active", { externalId });
350
+ async get(customerId) {
351
+ return this.httpClient.get("/subscriptions/active", { customerId });
504
352
  }
505
353
  /**
506
354
  * Cancel a subscription
@@ -531,7 +379,6 @@ var UsageResource = class {
531
379
  const eventData = {
532
380
  feature: params.feature,
533
381
  customerId: params.customerId,
534
- externalId: params.externalId,
535
382
  idempotencyKey: params.idempotencyKey,
536
383
  timestamp: params.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
537
384
  properties: params.properties ? Object.entries(params.properties).map(([property, value]) => ({
@@ -554,36 +401,6 @@ var UsageResource = class {
554
401
  }
555
402
  return this.httpClient.post("/usage/events", eventData, options);
556
403
  }
557
- async trackBatch(params, options) {
558
- const events = params.events.map((event) => {
559
- const eventData = {
560
- feature: event.feature,
561
- customerId: event.customerId,
562
- externalId: event.externalId,
563
- idempotencyKey: event.idempotencyKey,
564
- timestamp: event.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
565
- properties: event.properties ? Object.entries(event.properties).map(([property, value]) => ({
566
- property,
567
- value
568
- })) : void 0
569
- };
570
- if ("model" in event && event.model) {
571
- eventData.model = event.model;
572
- eventData.inputTokens = event.inputTokens;
573
- eventData.outputTokens = event.outputTokens;
574
- if (event.cacheReadTokens) {
575
- eventData.cacheReadTokens = event.cacheReadTokens;
576
- }
577
- if (event.cacheWriteTokens) {
578
- eventData.cacheWriteTokens = event.cacheWriteTokens;
579
- }
580
- } else {
581
- eventData.value = event.value;
582
- }
583
- return eventData;
584
- });
585
- return this.httpClient.post("/usage/events/batch", { events }, options);
586
- }
587
404
  };
588
405
 
589
406
  // src/resources/webhooks.ts
@@ -962,8 +779,8 @@ var Commet = class {
962
779
  * await customer.usage.track("api_call");
963
780
  * ```
964
781
  */
965
- customer(externalId) {
966
- return new CustomerContext(externalId, {
782
+ customer(customerId) {
783
+ return new CustomerContext(customerId, {
967
784
  features: this.features,
968
785
  seats: this.seats,
969
786
  usage: this.usage,