@commet/node 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  type CommetConfig = {
2
2
  apiKey: string;
3
+ apiVersion?: string;
3
4
  debug?: boolean;
4
5
  timeout?: number;
5
6
  retries?: number;
7
+ telemetry?: boolean;
6
8
  };
7
9
  interface ApiResponse<T = unknown> {
8
10
  success: boolean;
@@ -49,6 +51,7 @@ interface ListParams extends Record<string, unknown> {
49
51
  endDate?: string;
50
52
  }
51
53
  interface RequestOptions {
54
+ apiVersion?: string;
52
55
  idempotencyKey?: string;
53
56
  timeout?: number;
54
57
  }
@@ -81,14 +84,14 @@ type GeneratedFeatureCode = CommetGeneratedTypes extends {
81
84
  declare class CommetHTTPClient {
82
85
  private config;
83
86
  private retryConfig;
87
+ private telemetryEnabled;
88
+ private lastRequestMetrics;
84
89
  constructor(config: CommetConfig);
85
90
  get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
86
91
  post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
87
92
  put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
88
93
  delete<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
89
- /**
90
- * Core request method with retry logic
91
- */
94
+ private resolveApiVersion;
92
95
  private request;
93
96
  /**
94
97
  * Execute real API request with retry logic
@@ -220,7 +223,7 @@ declare class SeatsResource {
220
223
  }
221
224
 
222
225
  type PlanID = `plan_${string}`;
223
- type BillingInterval = "monthly" | "quarterly" | "yearly";
226
+ type BillingInterval = "weekly" | "monthly" | "quarterly" | "yearly";
224
227
  type FeatureType = "boolean" | "metered" | "seats";
225
228
  interface PlanPrice {
226
229
  billingInterval: BillingInterval;
@@ -342,6 +345,17 @@ interface BalanceSummary {
342
345
  included: number;
343
346
  currency: string;
344
347
  }
348
+ interface CancellationSummary {
349
+ scheduledAt: string;
350
+ reason: string | null;
351
+ effectiveAt: string;
352
+ }
353
+ interface DiscountSummary {
354
+ type: "percentage" | "amount";
355
+ value: number;
356
+ name: string | null;
357
+ endsAt: string | null;
358
+ }
345
359
  type ConsumptionModel = "metered" | "credits" | "balance";
346
360
  interface ActiveSubscription {
347
361
  id: string;
@@ -365,6 +379,8 @@ interface ActiveSubscription {
365
379
  features: FeatureSummary[];
366
380
  credits: CreditsSummary | null;
367
381
  balance: BalanceSummary | null;
382
+ cancellation: CancellationSummary | null;
383
+ discount: DiscountSummary | null;
368
384
  startDate: string;
369
385
  endDate: string | null;
370
386
  billingDayOfMonth: number;
@@ -841,8 +857,11 @@ declare class Commet {
841
857
  customer(customerId: string): CustomerContext;
842
858
  }
843
859
 
860
+ declare const API_VERSION = "2026-05-01";
861
+ declare const SDK_VERSION: string;
862
+
844
863
  /**
845
864
  * Commet SDK - Billing and usage tracking for SaaS
846
865
  */
847
866
 
848
- export { type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default };
867
+ export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  type CommetConfig = {
2
2
  apiKey: string;
3
+ apiVersion?: string;
3
4
  debug?: boolean;
4
5
  timeout?: number;
5
6
  retries?: number;
7
+ telemetry?: boolean;
6
8
  };
7
9
  interface ApiResponse<T = unknown> {
8
10
  success: boolean;
@@ -49,6 +51,7 @@ interface ListParams extends Record<string, unknown> {
49
51
  endDate?: string;
50
52
  }
51
53
  interface RequestOptions {
54
+ apiVersion?: string;
52
55
  idempotencyKey?: string;
53
56
  timeout?: number;
54
57
  }
@@ -81,14 +84,14 @@ type GeneratedFeatureCode = CommetGeneratedTypes extends {
81
84
  declare class CommetHTTPClient {
82
85
  private config;
83
86
  private retryConfig;
87
+ private telemetryEnabled;
88
+ private lastRequestMetrics;
84
89
  constructor(config: CommetConfig);
85
90
  get<T = unknown>(endpoint: string, params?: Record<string, unknown>, options?: RequestOptions): Promise<ApiResponse<T>>;
86
91
  post<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
87
92
  put<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
88
93
  delete<T = unknown>(endpoint: string, data?: unknown, options?: RequestOptions): Promise<ApiResponse<T>>;
89
- /**
90
- * Core request method with retry logic
91
- */
94
+ private resolveApiVersion;
92
95
  private request;
93
96
  /**
94
97
  * Execute real API request with retry logic
@@ -220,7 +223,7 @@ declare class SeatsResource {
220
223
  }
221
224
 
222
225
  type PlanID = `plan_${string}`;
223
- type BillingInterval = "monthly" | "quarterly" | "yearly";
226
+ type BillingInterval = "weekly" | "monthly" | "quarterly" | "yearly";
224
227
  type FeatureType = "boolean" | "metered" | "seats";
225
228
  interface PlanPrice {
226
229
  billingInterval: BillingInterval;
@@ -342,6 +345,17 @@ interface BalanceSummary {
342
345
  included: number;
343
346
  currency: string;
344
347
  }
348
+ interface CancellationSummary {
349
+ scheduledAt: string;
350
+ reason: string | null;
351
+ effectiveAt: string;
352
+ }
353
+ interface DiscountSummary {
354
+ type: "percentage" | "amount";
355
+ value: number;
356
+ name: string | null;
357
+ endsAt: string | null;
358
+ }
345
359
  type ConsumptionModel = "metered" | "credits" | "balance";
346
360
  interface ActiveSubscription {
347
361
  id: string;
@@ -365,6 +379,8 @@ interface ActiveSubscription {
365
379
  features: FeatureSummary[];
366
380
  credits: CreditsSummary | null;
367
381
  balance: BalanceSummary | null;
382
+ cancellation: CancellationSummary | null;
383
+ discount: DiscountSummary | null;
368
384
  startDate: string;
369
385
  endDate: string | null;
370
386
  billingDayOfMonth: number;
@@ -841,8 +857,11 @@ declare class Commet {
841
857
  customer(customerId: string): CustomerContext;
842
858
  }
843
859
 
860
+ declare const API_VERSION = "2026-05-01";
861
+ declare const SDK_VERSION: string;
862
+
844
863
  /**
845
864
  * Commet SDK - Billing and usage tracking for SaaS
846
865
  */
847
866
 
848
- export { type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default };
867
+ export { API_VERSION, type ActiveSubscription, type AddParams as AddSeatsParams, type ApiResponse, type BillingInterval, type CanUseFeatureParams, type CanUseResult, type CancelParams, type CancellationSummary, type CheckFeatureParams, type CheckResult, Commet, CommetAPIError, type CommetConfig, CommetError, type CommetGeneratedTypes, CommetValidationError, type CreateParams as CreateCustomerParams, type CreateSubscriptionParams, type CreatedSubscription, type CreditPack, type Currency, type Customer, type CustomerAddress, CustomerContext, type CustomerID, type BatchResult as CustomersBatchResult, type DiscountSummary, type EventID, type FeatureAccess, type FeatureSummary, type FeatureType, type GeneratedFeatureCode, type GeneratedPlanCode, type GeneratedSeatType, type GetAllBalancesParams, type GetBalanceParams, type GetFeatureParams, type GetUrlParams, type ListCustomersParams, type ListPlansParams, type PaginatedList, type PaginatedResponse, type Plan, type PlanDetail, type PlanFeature, type PlanID, type PlanPrice, type PortalAccess, type RemoveParams as RemoveSeatsParams, type RequestOptions, SDK_VERSION, type SeatBalance, type SeatEvent, type SetAllParams as SetAllSeatsParams, type SetParams as SetSeatsParams, type Subscription, type SubscriptionStatus, type TrackModelTokensParams, type TrackParams, type TrackUsageParams, type UpdateParams as UpdateCustomerParams, type UsageEvent, type UsageEventProperty, type WebhookData, type WebhookEvent, type WebhookPayload, Webhooks, Commet as default };
package/dist/index.js CHANGED
@@ -30,11 +30,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ API_VERSION: () => API_VERSION,
33
34
  Commet: () => Commet,
34
35
  CommetAPIError: () => CommetAPIError,
35
36
  CommetError: () => CommetError,
36
37
  CommetValidationError: () => CommetValidationError,
37
38
  CustomerContext: () => CustomerContext,
39
+ SDK_VERSION: () => SDK_VERSION,
38
40
  Webhooks: () => Webhooks,
39
41
  default: () => index_default
40
42
  });
@@ -521,6 +523,56 @@ var CommetValidationError = class extends CommetError {
521
523
  }
522
524
  };
523
525
 
526
+ // src/version.ts
527
+ var API_VERSION = "2026-05-01";
528
+ var SDK_VERSION = "3.1.0";
529
+
530
+ // src/utils/telemetry.ts
531
+ function detectRuntime() {
532
+ const g = globalThis;
533
+ const bun = g.Bun;
534
+ if (bun) return { name: "bun", version: bun.version };
535
+ const deno = g.Deno;
536
+ if (deno) return { name: "deno", version: deno.version.deno };
537
+ return { name: "node", version: process.versions.node };
538
+ }
539
+ var cachedClientInfo = null;
540
+ var cachedUserAgent = null;
541
+ function collectClientInfo() {
542
+ const runtime = detectRuntime();
543
+ return {
544
+ sdk: "commet-node",
545
+ sdkVersion: SDK_VERSION,
546
+ lang: "node",
547
+ langVersion: process.versions.node,
548
+ platform: process.platform,
549
+ arch: process.arch,
550
+ runtime: runtime.name,
551
+ runtimeVersion: runtime.version
552
+ };
553
+ }
554
+ function getClientInfoHeader() {
555
+ if (!cachedClientInfo) {
556
+ cachedClientInfo = JSON.stringify(collectClientInfo());
557
+ }
558
+ return cachedClientInfo;
559
+ }
560
+ function getUserAgent() {
561
+ if (!cachedUserAgent) {
562
+ const runtime = detectRuntime();
563
+ cachedUserAgent = `commet-node/${SDK_VERSION} ${runtime.name}/${runtime.version} ${process.platform}/${process.arch}`;
564
+ }
565
+ return cachedUserAgent;
566
+ }
567
+ function formatRequestMetrics(metrics) {
568
+ return JSON.stringify({
569
+ last_request_metrics: {
570
+ request_id: metrics.requestId,
571
+ duration_ms: metrics.durationMs
572
+ }
573
+ });
574
+ }
575
+
524
576
  // src/utils/http.ts
525
577
  var BASE_URL = "https://commet.co";
526
578
  var DEFAULT_RETRY_CONFIG = {
@@ -533,7 +585,9 @@ var DEFAULT_RETRY_CONFIG = {
533
585
  };
534
586
  var CommetHTTPClient = class {
535
587
  constructor(config) {
588
+ this.lastRequestMetrics = null;
536
589
  this.config = config;
590
+ this.telemetryEnabled = config.telemetry !== false;
537
591
  this.retryConfig = {
538
592
  ...DEFAULT_RETRY_CONFIG,
539
593
  maxRetries: config.retries ?? DEFAULT_RETRY_CONFIG.maxRetries
@@ -551,9 +605,9 @@ var CommetHTTPClient = class {
551
605
  async delete(endpoint, data, options) {
552
606
  return this.request("DELETE", endpoint, data, options);
553
607
  }
554
- /**
555
- * Core request method with retry logic
556
- */
608
+ resolveApiVersion(options) {
609
+ return options?.apiVersion ?? this.config.apiVersion ?? API_VERSION;
610
+ }
557
611
  async request(method, endpoint, data, options, params) {
558
612
  const url = this.buildURL(endpoint, params);
559
613
  return this.executeRequest(method, url, data, options);
@@ -563,11 +617,22 @@ var CommetHTTPClient = class {
563
617
  */
564
618
  async executeRequest(method, url, data, options, attempt = 1) {
565
619
  try {
620
+ const apiVersion = this.resolveApiVersion(options);
566
621
  const headers = {
567
622
  "x-api-key": this.config.apiKey,
623
+ "commet-version": apiVersion,
568
624
  "Content-Type": "application/json",
569
- "User-Agent": "commet-node/2.0.0"
625
+ "User-Agent": getUserAgent()
570
626
  };
627
+ if (this.telemetryEnabled) {
628
+ headers["commet-client-info"] = getClientInfoHeader();
629
+ if (this.lastRequestMetrics) {
630
+ headers["commet-client-telemetry"] = formatRequestMetrics(
631
+ this.lastRequestMetrics
632
+ );
633
+ this.lastRequestMetrics = null;
634
+ }
635
+ }
571
636
  if (options?.idempotencyKey) {
572
637
  headers["Idempotency-Key"] = options.idempotencyKey;
573
638
  } else if (method === "POST" && data) {
@@ -589,6 +654,7 @@ var CommetHTTPClient = class {
589
654
  console.log("Request data:", JSON.stringify(data, null, 2));
590
655
  }
591
656
  }
657
+ const requestStart = Date.now();
592
658
  const response = await fetch(url, requestConfig);
593
659
  if (this.config.debug) {
594
660
  console.log(
@@ -664,6 +730,12 @@ var CommetHTTPClient = class {
664
730
  if (this.config.debug) {
665
731
  console.log("[Commet SDK] Response:", responseData);
666
732
  }
733
+ if (this.telemetryEnabled) {
734
+ this.lastRequestMetrics = {
735
+ requestId: response.headers.get("x-request-id") ?? `req_${Date.now()}`,
736
+ durationMs: Date.now() - requestStart
737
+ };
738
+ }
667
739
  return responseData;
668
740
  } catch (error) {
669
741
  const isNetworkError = error instanceof TypeError && error.message.includes("fetch");
@@ -690,7 +762,7 @@ var CommetHTTPClient = class {
690
762
  */
691
763
  buildURL(endpoint, params) {
692
764
  const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
693
- const fullPath = `/api${normalizedEndpoint}`;
765
+ const fullPath = `/api/v1${normalizedEndpoint}`;
694
766
  if (this.config.debug) {
695
767
  console.log(
696
768
  `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`
@@ -778,11 +850,13 @@ var Commet = class {
778
850
  var index_default = Commet;
779
851
  // Annotate the CommonJS export names for ESM import in node:
780
852
  0 && (module.exports = {
853
+ API_VERSION,
781
854
  Commet,
782
855
  CommetAPIError,
783
856
  CommetError,
784
857
  CommetValidationError,
785
858
  CustomerContext,
859
+ SDK_VERSION,
786
860
  Webhooks
787
861
  });
788
862
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/customer.ts","../src/resources/credit-packs.ts","../src/resources/customers.ts","../src/resources/features.ts","../src/resources/plans.ts","../src/resources/portal.ts","../src/resources/seats.ts","../src/resources/subscriptions.ts","../src/resources/usage.ts","../src/resources/webhooks.ts","../src/types/common.ts","../src/utils/http.ts","../src/client.ts"],"sourcesContent":["/**\n * Commet SDK - Billing and usage tracking for SaaS\n */\nexport { Commet } from \"./client\";\nexport { CustomerContext } from \"./customer\";\n// Credit Packs\nexport type { CreditPack } from \"./resources/credit-packs\";\n// Customers\nexport type {\n BatchResult as CustomersBatchResult,\n CreateParams as CreateCustomerParams,\n Customer,\n CustomerAddress,\n ListCustomersParams,\n UpdateParams as UpdateCustomerParams,\n} from \"./resources/customers\";\n// Features\nexport type {\n CanUseFeatureParams,\n CanUseResult,\n CheckFeatureParams,\n CheckResult,\n FeatureAccess,\n GetFeatureParams,\n} from \"./resources/features\";\n// Plans\nexport type {\n BillingInterval,\n FeatureType,\n ListPlansParams,\n Plan,\n PlanDetail,\n PlanFeature,\n PlanID,\n PlanPrice,\n} from \"./resources/plans\";\n// Portal\nexport type { GetUrlParams, PortalAccess } from \"./resources/portal\";\n// Seats\nexport type {\n AddParams as AddSeatsParams,\n GetAllBalancesParams,\n GetBalanceParams,\n RemoveParams as RemoveSeatsParams,\n SeatBalance,\n SeatEvent,\n SetAllParams as SetAllSeatsParams,\n SetParams as SetSeatsParams,\n} from \"./resources/seats\";\n// Subscriptions\nexport type {\n ActiveSubscription,\n CancelParams,\n CreatedSubscription,\n CreateSubscriptionParams,\n FeatureSummary,\n Subscription,\n SubscriptionStatus,\n} from \"./resources/subscriptions\";\n// Usage\nexport type {\n TrackModelTokensParams,\n TrackParams,\n TrackUsageParams,\n UsageEvent,\n UsageEventProperty,\n} from \"./resources/usage\";\nexport type {\n WebhookData,\n WebhookEvent,\n WebhookPayload,\n} from \"./resources/webhooks\";\n// Webhooks\nexport { Webhooks } from \"./resources/webhooks\";\n// Type exports\nexport type {\n ApiResponse,\n CommetConfig,\n CommetGeneratedTypes,\n Currency,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\n GeneratedPlanCode,\n GeneratedSeatType,\n PaginatedList,\n PaginatedResponse,\n RequestOptions,\n} from \"./types/common\";\n// Error exports\nexport {\n CommetAPIError,\n CommetError,\n CommetValidationError,\n} from \"./types/common\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n","import type { FeaturesResource } from \"./resources/features\";\nimport type { PortalResource } from \"./resources/portal\";\nimport type { SeatsResource } from \"./resources/seats\";\nimport type { SubscriptionsResource } from \"./resources/subscriptions\";\nimport type { UsageResource } from \"./resources/usage\";\nimport type { RequestOptions } from \"./types/common\";\n\n/**\n * Customer-scoped API context\n *\n * Provides a cleaner API where you don't have to pass customerId\n * on every call. All operations are scoped to a specific customer.\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\nexport class CustomerContext {\n private readonly customerId: string;\n private readonly featuresResource: FeaturesResource;\n private readonly seatsResource: SeatsResource;\n private readonly usageResource: UsageResource;\n private readonly subscriptionsResource: SubscriptionsResource;\n private readonly portalResource: PortalResource;\n\n constructor(\n customerId: string,\n resources: {\n features: FeaturesResource;\n seats: SeatsResource;\n usage: UsageResource;\n subscriptions: SubscriptionsResource;\n portal: PortalResource;\n },\n ) {\n this.customerId = customerId;\n this.featuresResource = resources.features;\n this.seatsResource = resources.seats;\n this.usageResource = resources.usage;\n this.subscriptionsResource = resources.subscriptions;\n this.portalResource = resources.portal;\n }\n\n features = {\n get: (code: string, options?: RequestOptions) =>\n this.featuresResource.get({ code, customerId: this.customerId }, options),\n\n check: (code: string, options?: RequestOptions) =>\n this.featuresResource.check(\n { code, customerId: this.customerId },\n options,\n ),\n\n canUse: (code: string, options?: RequestOptions) =>\n this.featuresResource.canUse(\n { code, customerId: this.customerId },\n options,\n ),\n\n list: (options?: RequestOptions) =>\n this.featuresResource.list(this.customerId, options),\n };\n\n seats = {\n add: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.add(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n remove: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.remove(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n set: (seatType: string, count: number, options?: RequestOptions) =>\n this.seatsResource.set(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n getBalance: (seatType: string) =>\n this.seatsResource.getBalance({ customerId: this.customerId, seatType }),\n };\n\n usage = {\n track: (\n feature: string,\n value?: number,\n properties?: Record<string, string>,\n options?: RequestOptions,\n ) =>\n this.usageResource.track(\n { customerId: this.customerId, feature, value, properties },\n options,\n ),\n };\n\n subscription = {\n get: () => this.subscriptionsResource.get(this.customerId),\n };\n\n portal = {\n getUrl: (options?: RequestOptions) =>\n this.portalResource.getUrl({ customerId: this.customerId }, options),\n };\n}\n","import type { ApiResponse } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface CreditPack {\n id: string;\n name: string;\n description: string | null;\n credits: number;\n price: number;\n currency: string;\n}\n\n/**\n * Credit Packs resource for listing available credit packs\n */\nexport class CreditPacksResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all active credit packs\n *\n * @example\n * ```typescript\n * const packs = await commet.creditPacks.list();\n * console.log(packs.data); // [{ id: \"cp_xxx\", name: \"100 Credits\", ... }]\n * ```\n */\n async list(): Promise<ApiResponse<CreditPack[]>> {\n return this.httpClient.get(\"/credit-packs\");\n }\n}\n","import type {\n ApiResponse,\n ListParams as BaseListParams,\n CustomerID,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n billingEmail: 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\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n}\n\nexport interface CreateParams {\n email: string; // billingEmail - the only required field\n id?: string; // Your user ID — stored as externalId, used to identify the customer in all SDK methods\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface UpdateParams {\n customerId: CustomerID;\n email?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface ListCustomersParams extends BaseListParams {\n isActive?: boolean;\n search?: string;\n}\n\nexport interface BatchResult {\n successful: Customer[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateParams;\n }>;\n}\n\n/**\n * Customers resource - Manage your customers\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a customer (idempotent when id is provided)\n */\n async create(\n params: CreateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\n \"/customers\",\n {\n billingEmail: params.email,\n externalId: params.id,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * Create multiple customers in batch\n */\n async createBatch(\n params: { customers: CreateParams[] },\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult>> {\n const customers = params.customers.map((c) => ({\n billingEmail: c.email,\n externalId: c.id,\n fullName: c.fullName,\n domain: c.domain,\n website: c.website,\n timezone: c.timezone,\n language: c.language,\n industry: c.industry,\n metadata: c.metadata,\n address: c.address,\n }));\n return this.httpClient.post(\"/customers/batch\", { customers }, options);\n }\n\n /**\n * Get a customer by ID\n */\n async get(customerId: CustomerID): Promise<ApiResponse<Customer>> {\n return this.httpClient.get(`/customers/${customerId}`);\n }\n\n /**\n * Update a customer\n */\n async update(\n params: UpdateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${params.customerId}`,\n {\n billingEmail: params.email,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * List customers with optional filters\n */\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params as Record<string, unknown>);\n }\n\n /**\n * Archive a customer\n */\n async archive(\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 GeneratedFeatureCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface FeatureParams {\n customerId: CustomerID;\n code: GeneratedFeatureCode;\n}\n\nexport type GetFeatureParams = FeatureParams;\nexport type CheckFeatureParams = FeatureParams;\nexport type CanUseFeatureParams = FeatureParams;\n\nexport interface FeatureAccess {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n allowed: boolean;\n enabled?: boolean;\n current?: number;\n included?: number;\n remaining?: number;\n overage?: number;\n overageUnitPrice?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n}\n\nexport interface CanUseResult {\n allowed: boolean;\n willBeCharged: boolean;\n reason?: string;\n}\n\nexport interface CheckResult {\n allowed: boolean;\n}\n\nexport class FeaturesResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async get(\n params: GetFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n }\n\n async check(\n params: CheckFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CheckResult>> {\n const result = await this.httpClient.get<FeatureAccess>(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n\n if (!result.success || !result.data) {\n return {\n success: false,\n code: result.code,\n message: result.message,\n details: result.details,\n };\n }\n\n return {\n success: true,\n data: { allowed: result.data.allowed },\n };\n }\n\n async canUse(\n params: CanUseFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CanUseResult>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId, action: \"canUse\" },\n options,\n );\n }\n\n async list(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess[]>> {\n return this.httpClient.get(\"/features\", { customerId }, options);\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n ListParams,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport type PlanID = `plan_${string}`;\nexport type BillingInterval = \"monthly\" | \"quarterly\" | \"yearly\";\nexport type FeatureType = \"boolean\" | \"metered\" | \"seats\";\n\nexport interface PlanPrice {\n billingInterval: BillingInterval;\n price: number; // in cents\n isDefault: boolean;\n trialDays: number;\n}\n\nexport interface PlanFeature {\n code: string;\n name: string;\n type: FeatureType;\n unitName: string | null;\n enabled?: boolean;\n includedAmount?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n overageUnitPrice?: number;\n}\n\nexport interface Plan {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isFree: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanPrice[];\n features: PlanFeature[];\n createdAt: string;\n}\n\nexport interface PlanDetailPrice {\n billingInterval: BillingInterval;\n price: number;\n isDefault: boolean;\n trialDays: number;\n introOffer: {\n enabled: boolean;\n discountType: \"percentage\" | \"amount\" | null;\n discountValue: number | null;\n durationCycles: number | null;\n } | null;\n}\n\nexport interface PlanDetailFeature extends PlanFeature {\n overage: {\n enabled: boolean;\n model: \"per_unit\" | \"tiered\" | null;\n unitPrice: number | null;\n } | null;\n}\n\nexport interface PlanDetail {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanDetailPrice[];\n features: PlanDetailFeature[];\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ListPlansParams extends ListParams {\n includePrivate?: boolean;\n}\n\n/**\n * Plans resource for listing available plans\n */\nexport class PlansResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all available plans\n *\n * @example\n * ```typescript\n * // List public plans\n * const plans = await commet.plans.list();\n *\n * // Include private plans\n * const allPlans = await commet.plans.list({ includePrivate: true });\n * ```\n */\n async list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>> {\n return this.httpClient.get(\"/plans\", params);\n }\n\n /**\n * Get a specific plan by code\n *\n * @example\n * ```typescript\n * const plan = await commet.plans.get('pro');\n * console.log(plan.data.name); // \"Pro\"\n * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]\n * ```\n */\n async get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>> {\n return this.httpClient.get(`/plans/${planCode}`);\n }\n}\n","import type { ApiResponse, CustomerID, RequestOptions } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface PortalAccess {\n success: boolean;\n message: string;\n portalUrl: string;\n}\n\ninterface GetUrlByCustomerId {\n customerId: CustomerID;\n email?: never;\n}\n\ninterface GetUrlByEmail {\n email: string;\n customerId?: never;\n}\n\nexport type GetUrlParams = GetUrlByCustomerId | GetUrlByEmail;\n\nexport class PortalResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async getUrl(\n params: GetUrlParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<PortalAccess>> {\n return this.httpClient.post(\"/portal/request-access\", params, options);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n GeneratedSeatType,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\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 SeatBalance {\n current: number;\n asOf: string;\n}\n\nexport interface AddParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface RemoveParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetAllParams {\n customerId: CustomerID;\n seats: Record<string, number>;\n}\n\nexport interface GetBalanceParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n}\n\nexport interface GetAllBalancesParams {\n customerId: CustomerID;\n}\n\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n params: AddParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\"/seats\", params, options);\n }\n\n async remove(\n params: RemoveParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.delete(\"/seats\", params, options);\n }\n\n async set(\n params: SetParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.put(\"/seats\", params, options);\n }\n\n async setAll(\n params: SetAllParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.put(\"/seats/bulk\", params, options);\n }\n\n async getBalance(\n params: GetBalanceParams,\n ): Promise<ApiResponse<SeatBalance>> {\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, SeatBalance>>> {\n return this.httpClient.get(\"/seats/balances\", {\n customerId: params.customerId,\n });\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\nimport type { BillingInterval } from \"./plans\";\n\nexport type SubscriptionStatus =\n | \"draft\"\n | \"pending_payment\"\n | \"trialing\"\n | \"active\"\n | \"paused\"\n | \"past_due\"\n | \"canceled\"\n | \"expired\";\n\nexport interface FeatureSummary {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n enabled?: boolean;\n usage?: {\n current: number;\n included: number;\n overage: number;\n overageUnitPrice?: number;\n };\n}\n\nexport interface CreditsSummary {\n remaining: number;\n included: number;\n purchased: number;\n}\n\nexport interface BalanceSummary {\n remaining: number;\n included: number;\n currency: string;\n}\n\nexport type ConsumptionModel = \"metered\" | \"credits\" | \"balance\";\n\nexport interface ActiveSubscription {\n id: string;\n customerId: string;\n plan: {\n id: string;\n name: string;\n basePrice: number;\n billingInterval: BillingInterval | null;\n };\n name: string;\n description: string | null;\n status: SubscriptionStatus;\n consumptionModel: ConsumptionModel | null;\n trialEndsAt: string | null;\n currentPeriod: {\n start: string;\n end: string;\n daysRemaining: number;\n };\n features: FeatureSummary[];\n credits: CreditsSummary | null;\n balance: BalanceSummary | null;\n startDate: string;\n endDate: string | null;\n billingDayOfMonth: number;\n nextBillingDate: string;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface CreatedSubscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval | null;\n trialEndsAt: string | null;\n startDate: string;\n endDate: string | null;\n currentPeriodStart: string | null;\n currentPeriodEnd: string | null;\n billingDayOfMonth: number;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n introOfferEndsAt: string | null;\n introOfferDiscountType: \"percentage\" | \"amount\" | null;\n introOfferDiscountValue: number | null;\n}\n\nexport interface Subscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n description?: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval;\n trialEndsAt?: string;\n startDate: string;\n endDate?: string;\n currentPeriodStart?: string;\n currentPeriodEnd?: string;\n billingDayOfMonth: number;\n checkoutUrl?: string;\n createdAt: string;\n updatedAt: string;\n}\n\ntype PlanIdentifier =\n | { planCode: GeneratedPlanCode; planId?: never }\n | { planCode?: never; planId: string };\n\nexport type CreateSubscriptionParams = PlanIdentifier & {\n customerId: string;\n} & {\n billingInterval?: BillingInterval;\n initialSeats?: Record<string, number>;\n skipTrial?: boolean;\n name?: string;\n startDate?: string;\n successUrl?: string;\n};\n\nexport interface CancelParams {\n subscriptionId: string;\n reason?: string;\n immediate?: boolean;\n}\n\n/**\n * Subscription resource for managing subscriptions (plan-first model)\n *\n * Each customer can only have ONE active subscription at a time.\n */\nexport class SubscriptionsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a subscription with a plan\n *\n * @example\n * ```typescript\n * await commet.subscriptions.create({\n * externalId: 'user_123',\n * planCode: 'pro', // autocomplete works after `commet pull`\n * billingInterval: 'yearly',\n * initialSeats: { editor: 5 }\n * });\n * ```\n */\n async create(\n params: CreateSubscriptionParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CreatedSubscription>> {\n return this.httpClient.post(\"/subscriptions\", params, options);\n }\n\n /**\n * Get the active subscription for a customer\n *\n * @example\n * ```typescript\n * const sub = await commet.subscriptions.get('user_123');\n * ```\n */\n async get(\n customerId: string,\n ): Promise<ApiResponse<ActiveSubscription | null>> {\n return this.httpClient.get(\"/subscriptions/active\", { customerId });\n }\n\n /**\n * Cancel a subscription\n *\n * @example\n * ```typescript\n * await commet.subscriptions.cancel({\n * subscriptionId: 'sub_xxx',\n * reason: 'switched_to_competitor'\n * });\n * ```\n */\n async cancel(\n params: CancelParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Subscription>> {\n return this.httpClient.post(\n `/subscriptions/${params.subscriptionId}/cancel`,\n params || {},\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\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 feature: 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\ninterface TrackBaseParams {\n feature: GeneratedFeatureCode;\n customerId: CustomerID;\n idempotencyKey?: string;\n timestamp?: string;\n properties?: Record<string, string>;\n}\n\nexport interface TrackUsageParams extends TrackBaseParams {\n value?: number;\n model?: never;\n}\n\nexport interface TrackModelTokensParams extends TrackBaseParams {\n model: string;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens?: number;\n cacheWriteTokens?: number;\n value?: never;\n}\n\nexport type TrackParams = TrackUsageParams | TrackModelTokensParams;\n\nexport class UsageResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async track(\n params: TrackParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData: Record<string, unknown> = {\n feature: params.feature,\n customerId: params.customerId,\n idempotencyKey: params.idempotencyKey,\n timestamp: params.timestamp || new Date().toISOString(),\n properties: params.properties\n ? Object.entries(params.properties).map(([property, value]) => ({\n property,\n value,\n }))\n : undefined,\n };\n\n if (\"model\" in params && params.model) {\n eventData.model = params.model;\n eventData.inputTokens = params.inputTokens;\n eventData.outputTokens = params.outputTokens;\n if (params.cacheReadTokens) {\n eventData.cacheReadTokens = params.cacheReadTokens;\n }\n if (params.cacheWriteTokens) {\n eventData.cacheWriteTokens = params.cacheWriteTokens;\n }\n } else {\n eventData.value = (params as TrackUsageParams).value;\n }\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n}\n","import crypto from \"node:crypto\";\nimport type { SubscriptionStatus } from \"./subscriptions\";\n\n/**\n * Webhook payload structure from Commet\n */\nexport interface WebhookPayload {\n event: WebhookEvent;\n timestamp: string;\n organizationId: string;\n data: WebhookData;\n}\n\n/**\n * Webhook data structure (subscription-related fields).\n *\n * The `status` field is present on `subscription.*` events. Grant access only\n * when it is `\"active\"` or `\"trialing\"`. `\"pending_payment\"` means the first\n * charge has not been confirmed yet — wait for `subscription.activated` before\n * granting access.\n */\nexport interface WebhookData {\n id?: string;\n publicId?: string;\n subscriptionId?: string;\n customerId?: string;\n externalId?: string;\n /**\n * Subscription status. Present on `subscription.*` events.\n * Grant access when this is `\"active\"` or `\"trialing\"`.\n */\n status?: SubscriptionStatus;\n name?: string;\n canceledAt?: string;\n [key: string]: unknown;\n}\n\n/**\n * Supported webhook events\n */\nexport type WebhookEvent =\n | \"subscription.created\"\n | \"subscription.activated\"\n | \"subscription.canceled\"\n | \"subscription.updated\"\n | \"subscription.plan_changed\"\n | \"payment.received\"\n | \"payment.failed\"\n | \"invoice.created\";\n\nexport interface VerifyParams {\n payload: string;\n signature: string | null;\n secret: string;\n}\n\nexport interface GenerateSignatureParams {\n payload: string;\n secret: string;\n}\n\nexport interface VerifyAndParseParams {\n rawBody: string;\n signature: string | null;\n secret: string;\n}\n\n/**\n * Webhooks resource for signature verification\n */\nexport class Webhooks {\n /**\n * Verify HMAC-SHA256 webhook signature\n *\n * Use this method to verify that webhooks are authentically from Commet.\n * The signature is included in the `X-Commet-Signature` header.\n *\n * @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)\n * @param signature - Value from X-Commet-Signature header\n * @param secret - Your webhook secret from Commet dashboard\n * @returns true if signature is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Next.js API route example\n * export async function POST(request: Request) {\n * const rawBody = await request.text();\n * const signature = request.headers.get('x-commet-signature');\n *\n * const isValid = commet.webhooks.verify(\n * rawBody,\n * signature,\n * process.env.COMMET_WEBHOOK_SECRET\n * );\n *\n * if (!isValid) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * const payload = JSON.parse(rawBody);\n * // Handle webhook event...\n * }\n * ```\n */\n verify(params: VerifyParams): boolean {\n const { payload, signature, secret } = params;\n\n if (!signature || !secret || !payload) {\n return false;\n }\n\n try {\n const expectedSignature = this.generateSignature({ payload, secret });\n\n // Use timing-safe comparison to prevent timing attacks\n return crypto.timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n );\n } catch (_error) {\n // timingSafeEqual throws if lengths don't match\n return false;\n }\n }\n\n /**\n * Generate HMAC-SHA256 signature (internal use)\n * @internal\n */\n private generateSignature(params: GenerateSignatureParams): string {\n const { payload, secret } = params;\n return crypto.createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n }\n\n /**\n * Parse and verify webhook payload in one step\n *\n * @example\n * ```typescript\n * const payload = commet.webhooks.verifyAndParse({\n * rawBody,\n * signature,\n * secret: process.env.COMMET_WEBHOOK_SECRET\n * });\n *\n * if (!payload) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * // payload is typed and validated\n * if (payload.event === 'subscription.activated') {\n * // Handle activation...\n * }\n * ```\n */\n verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null {\n const { rawBody, signature, secret } = params;\n\n if (!this.verify({ payload: rawBody, signature, secret })) {\n return null;\n }\n\n try {\n return JSON.parse(params.rawBody) as WebhookPayload;\n } catch {\n return null;\n }\n }\n}\n","export type CommetConfig = {\n apiKey: string;\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 code?: string;\n message?: string;\n details?: unknown;\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 = 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/types.d.ts file that augments this interface with your\n * organization's specific feature codes, seat types, and plan codes.\n *\n * @example\n * // After running `commet pull`, TypeScript will automatically know your types:\n * await commet.usage.track({\n * feature: 'api_calls', // Autocomplete works!\n * externalId: 'user_123'\n * });\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by CLI-generated .commet/types.d.ts\nexport interface CommetGeneratedTypes {}\n\nexport type GeneratedSeatType = CommetGeneratedTypes extends {\n seatType: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedPlanCode = CommetGeneratedTypes extends {\n planCode: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedFeatureCode = CommetGeneratedTypes extends {\n featureCode: infer T;\n}\n ? T\n : string;\n","import type {\n ApiResponse,\n CommetConfig,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\n\nconst BASE_URL = \"https://commet.co\";\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 retryConfig: RetryConfig;\n\n constructor(config: CommetConfig) {\n this.config = config;\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-node/2.0.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 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\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 code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle validation errors (new normalized shape)\n if (\n errorData.code === \"validation_error\" &&\n Array.isArray(errorData.details)\n ) {\n const errors: Record<string, string[]> = {};\n for (const detail of errorData.details as Array<{\n field: string;\n message: string;\n }>) {\n if (!errors[detail.field]) errors[detail.field] = [];\n errors[detail.field].push(detail.message);\n }\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n 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 const isNetworkError =\n error instanceof TypeError && error.message.includes(\"fetch\");\n const isTimeoutError =\n error instanceof DOMException && error.name === \"AbortError\";\n const isTimeoutErrorModern =\n typeof globalThis.DOMException !== \"undefined\" &&\n error instanceof DOMException &&\n error.name === \"TimeoutError\";\n\n if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {\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 * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n // Construct full path with /api prefix\n const normalizedEndpoint = endpoint.startsWith(\"/\")\n ? endpoint\n : `/${endpoint}`;\n const fullPath = `/api${normalizedEndpoint}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, BASE_URL);\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 { CustomerContext } from \"./customer\";\nimport { CreditPacksResource } from \"./resources/credit-packs\";\nimport { CustomersResource } from \"./resources/customers\";\nimport { FeaturesResource } from \"./resources/features\";\nimport { PlansResource } from \"./resources/plans\";\nimport { PortalResource } from \"./resources/portal\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { SubscriptionsResource } from \"./resources/subscriptions\";\nimport { UsageResource } from \"./resources/usage\";\nimport { Webhooks } from \"./resources/webhooks\";\nimport type { CommetConfig } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n\n public readonly customers: CustomersResource;\n public readonly creditPacks: CreditPacksResource;\n public readonly plans: PlansResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n public readonly subscriptions: SubscriptionsResource;\n public readonly portal: PortalResource;\n public readonly features: FeaturesResource;\n public readonly webhooks: Webhooks;\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 this.httpClient = new CommetHTTPClient(config);\n this.customers = new CustomersResource(this.httpClient);\n this.creditPacks = new CreditPacksResource(this.httpClient);\n this.plans = new PlansResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n this.subscriptions = new SubscriptionsResource(this.httpClient);\n this.portal = new PortalResource(this.httpClient);\n this.features = new FeaturesResource(this.httpClient);\n this.webhooks = new Webhooks();\n\n if (config.debug) {\n console.log(\"[Commet SDK] Initialized\");\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n }\n }\n\n /**\n * Create a customer-scoped context for cleaner API usage\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\n customer(customerId: string): CustomerContext {\n return new CustomerContext(customerId, {\n features: this.features,\n seats: this.seats,\n usage: this.usage,\n subscriptions: this.subscriptions,\n portal: this.portal,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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AAe,KAAK;AAAA,MACpB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AACF;;;AbmBA,IAAO,gBAAQ;","names":["crypto","data"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/customer.ts","../src/resources/credit-packs.ts","../src/resources/customers.ts","../src/resources/features.ts","../src/resources/plans.ts","../src/resources/portal.ts","../src/resources/seats.ts","../src/resources/subscriptions.ts","../src/resources/usage.ts","../src/resources/webhooks.ts","../src/types/common.ts","../src/version.ts","../src/utils/telemetry.ts","../src/utils/http.ts","../src/client.ts"],"sourcesContent":["/**\n * Commet SDK - Billing and usage tracking for SaaS\n */\nexport { Commet } from \"./client\";\nexport { CustomerContext } from \"./customer\";\n// Credit Packs\nexport type { CreditPack } from \"./resources/credit-packs\";\n// Customers\nexport type {\n BatchResult as CustomersBatchResult,\n CreateParams as CreateCustomerParams,\n Customer,\n CustomerAddress,\n ListCustomersParams,\n UpdateParams as UpdateCustomerParams,\n} from \"./resources/customers\";\n// Features\nexport type {\n CanUseFeatureParams,\n CanUseResult,\n CheckFeatureParams,\n CheckResult,\n FeatureAccess,\n GetFeatureParams,\n} from \"./resources/features\";\n// Plans\nexport type {\n BillingInterval,\n FeatureType,\n ListPlansParams,\n Plan,\n PlanDetail,\n PlanFeature,\n PlanID,\n PlanPrice,\n} from \"./resources/plans\";\n// Portal\nexport type { GetUrlParams, PortalAccess } from \"./resources/portal\";\n// Seats\nexport type {\n AddParams as AddSeatsParams,\n GetAllBalancesParams,\n GetBalanceParams,\n RemoveParams as RemoveSeatsParams,\n SeatBalance,\n SeatEvent,\n SetAllParams as SetAllSeatsParams,\n SetParams as SetSeatsParams,\n} from \"./resources/seats\";\n// Subscriptions\nexport type {\n ActiveSubscription,\n CancellationSummary,\n CancelParams,\n CreatedSubscription,\n CreateSubscriptionParams,\n DiscountSummary,\n FeatureSummary,\n Subscription,\n SubscriptionStatus,\n} from \"./resources/subscriptions\";\n// Usage\nexport type {\n TrackModelTokensParams,\n TrackParams,\n TrackUsageParams,\n UsageEvent,\n UsageEventProperty,\n} from \"./resources/usage\";\nexport type {\n WebhookData,\n WebhookEvent,\n WebhookPayload,\n} from \"./resources/webhooks\";\n// Webhooks\nexport { Webhooks } from \"./resources/webhooks\";\n// Type exports\nexport type {\n ApiResponse,\n CommetConfig,\n CommetGeneratedTypes,\n Currency,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\n GeneratedPlanCode,\n GeneratedSeatType,\n PaginatedList,\n PaginatedResponse,\n RequestOptions,\n} from \"./types/common\";\n// Error exports\nexport {\n CommetAPIError,\n CommetError,\n CommetValidationError,\n} from \"./types/common\";\nexport { API_VERSION, SDK_VERSION } from \"./version\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n","import type { FeaturesResource } from \"./resources/features\";\nimport type { PortalResource } from \"./resources/portal\";\nimport type { SeatsResource } from \"./resources/seats\";\nimport type { SubscriptionsResource } from \"./resources/subscriptions\";\nimport type { UsageResource } from \"./resources/usage\";\nimport type { RequestOptions } from \"./types/common\";\n\n/**\n * Customer-scoped API context\n *\n * Provides a cleaner API where you don't have to pass customerId\n * on every call. All operations are scoped to a specific customer.\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\nexport class CustomerContext {\n private readonly customerId: string;\n private readonly featuresResource: FeaturesResource;\n private readonly seatsResource: SeatsResource;\n private readonly usageResource: UsageResource;\n private readonly subscriptionsResource: SubscriptionsResource;\n private readonly portalResource: PortalResource;\n\n constructor(\n customerId: string,\n resources: {\n features: FeaturesResource;\n seats: SeatsResource;\n usage: UsageResource;\n subscriptions: SubscriptionsResource;\n portal: PortalResource;\n },\n ) {\n this.customerId = customerId;\n this.featuresResource = resources.features;\n this.seatsResource = resources.seats;\n this.usageResource = resources.usage;\n this.subscriptionsResource = resources.subscriptions;\n this.portalResource = resources.portal;\n }\n\n features = {\n get: (code: string, options?: RequestOptions) =>\n this.featuresResource.get({ code, customerId: this.customerId }, options),\n\n check: (code: string, options?: RequestOptions) =>\n this.featuresResource.check(\n { code, customerId: this.customerId },\n options,\n ),\n\n canUse: (code: string, options?: RequestOptions) =>\n this.featuresResource.canUse(\n { code, customerId: this.customerId },\n options,\n ),\n\n list: (options?: RequestOptions) =>\n this.featuresResource.list(this.customerId, options),\n };\n\n seats = {\n add: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.add(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n remove: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.remove(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n set: (seatType: string, count: number, options?: RequestOptions) =>\n this.seatsResource.set(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n getBalance: (seatType: string) =>\n this.seatsResource.getBalance({ customerId: this.customerId, seatType }),\n };\n\n usage = {\n track: (\n feature: string,\n value?: number,\n properties?: Record<string, string>,\n options?: RequestOptions,\n ) =>\n this.usageResource.track(\n { customerId: this.customerId, feature, value, properties },\n options,\n ),\n };\n\n subscription = {\n get: () => this.subscriptionsResource.get(this.customerId),\n };\n\n portal = {\n getUrl: (options?: RequestOptions) =>\n this.portalResource.getUrl({ customerId: this.customerId }, options),\n };\n}\n","import type { ApiResponse } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface CreditPack {\n id: string;\n name: string;\n description: string | null;\n credits: number;\n price: number;\n currency: string;\n}\n\n/**\n * Credit Packs resource for listing available credit packs\n */\nexport class CreditPacksResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all active credit packs\n *\n * @example\n * ```typescript\n * const packs = await commet.creditPacks.list();\n * console.log(packs.data); // [{ id: \"cp_xxx\", name: \"100 Credits\", ... }]\n * ```\n */\n async list(): Promise<ApiResponse<CreditPack[]>> {\n return this.httpClient.get(\"/credit-packs\");\n }\n}\n","import type {\n ApiResponse,\n ListParams as BaseListParams,\n CustomerID,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n billingEmail: 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\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n}\n\nexport interface CreateParams {\n email: string; // billingEmail - the only required field\n id?: string; // Your user ID — stored as externalId, used to identify the customer in all SDK methods\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface UpdateParams {\n customerId: CustomerID;\n email?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface ListCustomersParams extends BaseListParams {\n isActive?: boolean;\n search?: string;\n}\n\nexport interface BatchResult {\n successful: Customer[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateParams;\n }>;\n}\n\n/**\n * Customers resource - Manage your customers\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a customer (idempotent when id is provided)\n */\n async create(\n params: CreateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\n \"/customers\",\n {\n billingEmail: params.email,\n externalId: params.id,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * Create multiple customers in batch\n */\n async createBatch(\n params: { customers: CreateParams[] },\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult>> {\n const customers = params.customers.map((c) => ({\n billingEmail: c.email,\n externalId: c.id,\n fullName: c.fullName,\n domain: c.domain,\n website: c.website,\n timezone: c.timezone,\n language: c.language,\n industry: c.industry,\n metadata: c.metadata,\n address: c.address,\n }));\n return this.httpClient.post(\"/customers/batch\", { customers }, options);\n }\n\n /**\n * Get a customer by ID\n */\n async get(customerId: CustomerID): Promise<ApiResponse<Customer>> {\n return this.httpClient.get(`/customers/${customerId}`);\n }\n\n /**\n * Update a customer\n */\n async update(\n params: UpdateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${params.customerId}`,\n {\n billingEmail: params.email,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * List customers with optional filters\n */\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params as Record<string, unknown>);\n }\n\n /**\n * Archive a customer\n */\n async archive(\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 GeneratedFeatureCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface FeatureParams {\n customerId: CustomerID;\n code: GeneratedFeatureCode;\n}\n\nexport type GetFeatureParams = FeatureParams;\nexport type CheckFeatureParams = FeatureParams;\nexport type CanUseFeatureParams = FeatureParams;\n\nexport interface FeatureAccess {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n allowed: boolean;\n enabled?: boolean;\n current?: number;\n included?: number;\n remaining?: number;\n overage?: number;\n overageUnitPrice?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n}\n\nexport interface CanUseResult {\n allowed: boolean;\n willBeCharged: boolean;\n reason?: string;\n}\n\nexport interface CheckResult {\n allowed: boolean;\n}\n\nexport class FeaturesResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async get(\n params: GetFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n }\n\n async check(\n params: CheckFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CheckResult>> {\n const result = await this.httpClient.get<FeatureAccess>(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n\n if (!result.success || !result.data) {\n return {\n success: false,\n code: result.code,\n message: result.message,\n details: result.details,\n };\n }\n\n return {\n success: true,\n data: { allowed: result.data.allowed },\n };\n }\n\n async canUse(\n params: CanUseFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CanUseResult>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId, action: \"canUse\" },\n options,\n );\n }\n\n async list(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess[]>> {\n return this.httpClient.get(\"/features\", { customerId }, options);\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n ListParams,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport type PlanID = `plan_${string}`;\nexport type BillingInterval = \"weekly\" | \"monthly\" | \"quarterly\" | \"yearly\";\nexport type FeatureType = \"boolean\" | \"metered\" | \"seats\";\n\nexport interface PlanPrice {\n billingInterval: BillingInterval;\n price: number; // in cents\n isDefault: boolean;\n trialDays: number;\n}\n\nexport interface PlanFeature {\n code: string;\n name: string;\n type: FeatureType;\n unitName: string | null;\n enabled?: boolean;\n includedAmount?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n overageUnitPrice?: number;\n}\n\nexport interface Plan {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isFree: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanPrice[];\n features: PlanFeature[];\n createdAt: string;\n}\n\nexport interface PlanDetailPrice {\n billingInterval: BillingInterval;\n price: number;\n isDefault: boolean;\n trialDays: number;\n introOffer: {\n enabled: boolean;\n discountType: \"percentage\" | \"amount\" | null;\n discountValue: number | null;\n durationCycles: number | null;\n } | null;\n}\n\nexport interface PlanDetailFeature extends PlanFeature {\n overage: {\n enabled: boolean;\n model: \"per_unit\" | \"tiered\" | null;\n unitPrice: number | null;\n } | null;\n}\n\nexport interface PlanDetail {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanDetailPrice[];\n features: PlanDetailFeature[];\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ListPlansParams extends ListParams {\n includePrivate?: boolean;\n}\n\n/**\n * Plans resource for listing available plans\n */\nexport class PlansResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all available plans\n *\n * @example\n * ```typescript\n * // List public plans\n * const plans = await commet.plans.list();\n *\n * // Include private plans\n * const allPlans = await commet.plans.list({ includePrivate: true });\n * ```\n */\n async list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>> {\n return this.httpClient.get(\"/plans\", params);\n }\n\n /**\n * Get a specific plan by code\n *\n * @example\n * ```typescript\n * const plan = await commet.plans.get('pro');\n * console.log(plan.data.name); // \"Pro\"\n * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]\n * ```\n */\n async get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>> {\n return this.httpClient.get(`/plans/${planCode}`);\n }\n}\n","import type { ApiResponse, CustomerID, RequestOptions } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface PortalAccess {\n success: boolean;\n message: string;\n portalUrl: string;\n}\n\ninterface GetUrlByCustomerId {\n customerId: CustomerID;\n email?: never;\n}\n\ninterface GetUrlByEmail {\n email: string;\n customerId?: never;\n}\n\nexport type GetUrlParams = GetUrlByCustomerId | GetUrlByEmail;\n\nexport class PortalResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async getUrl(\n params: GetUrlParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<PortalAccess>> {\n return this.httpClient.post(\"/portal/request-access\", params, options);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n GeneratedSeatType,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\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 SeatBalance {\n current: number;\n asOf: string;\n}\n\nexport interface AddParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface RemoveParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetAllParams {\n customerId: CustomerID;\n seats: Record<string, number>;\n}\n\nexport interface GetBalanceParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n}\n\nexport interface GetAllBalancesParams {\n customerId: CustomerID;\n}\n\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n params: AddParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\"/seats\", params, options);\n }\n\n async remove(\n params: RemoveParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.delete(\"/seats\", params, options);\n }\n\n async set(\n params: SetParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.put(\"/seats\", params, options);\n }\n\n async setAll(\n params: SetAllParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.put(\"/seats/bulk\", params, options);\n }\n\n async getBalance(\n params: GetBalanceParams,\n ): Promise<ApiResponse<SeatBalance>> {\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, SeatBalance>>> {\n return this.httpClient.get(\"/seats/balances\", {\n customerId: params.customerId,\n });\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\nimport type { BillingInterval } from \"./plans\";\n\nexport type SubscriptionStatus =\n | \"draft\"\n | \"pending_payment\"\n | \"trialing\"\n | \"active\"\n | \"paused\"\n | \"past_due\"\n | \"canceled\"\n | \"expired\";\n\nexport interface FeatureSummary {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n enabled?: boolean;\n usage?: {\n current: number;\n included: number;\n overage: number;\n overageUnitPrice?: number;\n };\n}\n\nexport interface CreditsSummary {\n remaining: number;\n included: number;\n purchased: number;\n}\n\nexport interface BalanceSummary {\n remaining: number;\n included: number;\n currency: string;\n}\n\nexport interface CancellationSummary {\n scheduledAt: string;\n reason: string | null;\n effectiveAt: string;\n}\n\nexport interface DiscountSummary {\n type: \"percentage\" | \"amount\";\n value: number;\n name: string | null;\n endsAt: string | null;\n}\n\nexport type ConsumptionModel = \"metered\" | \"credits\" | \"balance\";\n\nexport interface ActiveSubscription {\n id: string;\n customerId: string;\n plan: {\n id: string;\n name: string;\n basePrice: number;\n billingInterval: BillingInterval | null;\n };\n name: string;\n description: string | null;\n status: SubscriptionStatus;\n consumptionModel: ConsumptionModel | null;\n trialEndsAt: string | null;\n currentPeriod: {\n start: string;\n end: string;\n daysRemaining: number;\n };\n features: FeatureSummary[];\n credits: CreditsSummary | null;\n balance: BalanceSummary | null;\n cancellation: CancellationSummary | null;\n discount: DiscountSummary | null;\n startDate: string;\n endDate: string | null;\n billingDayOfMonth: number;\n nextBillingDate: string;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface CreatedSubscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval | null;\n trialEndsAt: string | null;\n startDate: string;\n endDate: string | null;\n currentPeriodStart: string | null;\n currentPeriodEnd: string | null;\n billingDayOfMonth: number;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n introOfferEndsAt: string | null;\n introOfferDiscountType: \"percentage\" | \"amount\" | null;\n introOfferDiscountValue: number | null;\n}\n\nexport interface Subscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n description?: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval;\n trialEndsAt?: string;\n startDate: string;\n endDate?: string;\n currentPeriodStart?: string;\n currentPeriodEnd?: string;\n billingDayOfMonth: number;\n checkoutUrl?: string;\n createdAt: string;\n updatedAt: string;\n}\n\ntype PlanIdentifier =\n | { planCode: GeneratedPlanCode; planId?: never }\n | { planCode?: never; planId: string };\n\nexport type CreateSubscriptionParams = PlanIdentifier & {\n customerId: string;\n} & {\n billingInterval?: BillingInterval;\n initialSeats?: Record<string, number>;\n skipTrial?: boolean;\n name?: string;\n startDate?: string;\n successUrl?: string;\n};\n\nexport interface CancelParams {\n subscriptionId: string;\n reason?: string;\n immediate?: boolean;\n}\n\n/**\n * Subscription resource for managing subscriptions (plan-first model)\n *\n * Each customer can only have ONE active subscription at a time.\n */\nexport class SubscriptionsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a subscription with a plan\n *\n * @example\n * ```typescript\n * await commet.subscriptions.create({\n * externalId: 'user_123',\n * planCode: 'pro', // autocomplete works after `commet pull`\n * billingInterval: 'yearly',\n * initialSeats: { editor: 5 }\n * });\n * ```\n */\n async create(\n params: CreateSubscriptionParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CreatedSubscription>> {\n return this.httpClient.post(\"/subscriptions\", params, options);\n }\n\n /**\n * Get the active subscription for a customer\n *\n * @example\n * ```typescript\n * const sub = await commet.subscriptions.get('user_123');\n * ```\n */\n async get(\n customerId: string,\n ): Promise<ApiResponse<ActiveSubscription | null>> {\n return this.httpClient.get(\"/subscriptions/active\", { customerId });\n }\n\n /**\n * Cancel a subscription\n *\n * @example\n * ```typescript\n * await commet.subscriptions.cancel({\n * subscriptionId: 'sub_xxx',\n * reason: 'switched_to_competitor'\n * });\n * ```\n */\n async cancel(\n params: CancelParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Subscription>> {\n return this.httpClient.post(\n `/subscriptions/${params.subscriptionId}/cancel`,\n params || {},\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\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 feature: 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\ninterface TrackBaseParams {\n feature: GeneratedFeatureCode;\n customerId: CustomerID;\n idempotencyKey?: string;\n timestamp?: string;\n properties?: Record<string, string>;\n}\n\nexport interface TrackUsageParams extends TrackBaseParams {\n value?: number;\n model?: never;\n}\n\nexport interface TrackModelTokensParams extends TrackBaseParams {\n model: string;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens?: number;\n cacheWriteTokens?: number;\n value?: never;\n}\n\nexport type TrackParams = TrackUsageParams | TrackModelTokensParams;\n\nexport class UsageResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async track(\n params: TrackParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData: Record<string, unknown> = {\n feature: params.feature,\n customerId: params.customerId,\n idempotencyKey: params.idempotencyKey,\n timestamp: params.timestamp || new Date().toISOString(),\n properties: params.properties\n ? Object.entries(params.properties).map(([property, value]) => ({\n property,\n value,\n }))\n : undefined,\n };\n\n if (\"model\" in params && params.model) {\n eventData.model = params.model;\n eventData.inputTokens = params.inputTokens;\n eventData.outputTokens = params.outputTokens;\n if (params.cacheReadTokens) {\n eventData.cacheReadTokens = params.cacheReadTokens;\n }\n if (params.cacheWriteTokens) {\n eventData.cacheWriteTokens = params.cacheWriteTokens;\n }\n } else {\n eventData.value = (params as TrackUsageParams).value;\n }\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n}\n","import crypto from \"node:crypto\";\nimport type { SubscriptionStatus } from \"./subscriptions\";\n\n/**\n * Webhook payload structure from Commet\n */\nexport interface WebhookPayload {\n event: WebhookEvent;\n timestamp: string;\n organizationId: string;\n data: WebhookData;\n}\n\n/**\n * Webhook data structure (subscription-related fields).\n *\n * The `status` field is present on `subscription.*` events. Grant access only\n * when it is `\"active\"` or `\"trialing\"`. `\"pending_payment\"` means the first\n * charge has not been confirmed yet — wait for `subscription.activated` before\n * granting access.\n */\nexport interface WebhookData {\n id?: string;\n publicId?: string;\n subscriptionId?: string;\n customerId?: string;\n externalId?: string;\n /**\n * Subscription status. Present on `subscription.*` events.\n * Grant access when this is `\"active\"` or `\"trialing\"`.\n */\n status?: SubscriptionStatus;\n name?: string;\n canceledAt?: string;\n [key: string]: unknown;\n}\n\n/**\n * Supported webhook events\n */\nexport type WebhookEvent =\n | \"subscription.created\"\n | \"subscription.activated\"\n | \"subscription.canceled\"\n | \"subscription.updated\"\n | \"subscription.plan_changed\"\n | \"payment.received\"\n | \"payment.failed\"\n | \"invoice.created\";\n\nexport interface VerifyParams {\n payload: string;\n signature: string | null;\n secret: string;\n}\n\nexport interface GenerateSignatureParams {\n payload: string;\n secret: string;\n}\n\nexport interface VerifyAndParseParams {\n rawBody: string;\n signature: string | null;\n secret: string;\n}\n\n/**\n * Webhooks resource for signature verification\n */\nexport class Webhooks {\n /**\n * Verify HMAC-SHA256 webhook signature\n *\n * Use this method to verify that webhooks are authentically from Commet.\n * The signature is included in the `X-Commet-Signature` header.\n *\n * @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)\n * @param signature - Value from X-Commet-Signature header\n * @param secret - Your webhook secret from Commet dashboard\n * @returns true if signature is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Next.js API route example\n * export async function POST(request: Request) {\n * const rawBody = await request.text();\n * const signature = request.headers.get('x-commet-signature');\n *\n * const isValid = commet.webhooks.verify(\n * rawBody,\n * signature,\n * process.env.COMMET_WEBHOOK_SECRET\n * );\n *\n * if (!isValid) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * const payload = JSON.parse(rawBody);\n * // Handle webhook event...\n * }\n * ```\n */\n verify(params: VerifyParams): boolean {\n const { payload, signature, secret } = params;\n\n if (!signature || !secret || !payload) {\n return false;\n }\n\n try {\n const expectedSignature = this.generateSignature({ payload, secret });\n\n // Use timing-safe comparison to prevent timing attacks\n return crypto.timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n );\n } catch (_error) {\n // timingSafeEqual throws if lengths don't match\n return false;\n }\n }\n\n /**\n * Generate HMAC-SHA256 signature (internal use)\n * @internal\n */\n private generateSignature(params: GenerateSignatureParams): string {\n const { payload, secret } = params;\n return crypto.createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n }\n\n /**\n * Parse and verify webhook payload in one step\n *\n * @example\n * ```typescript\n * const payload = commet.webhooks.verifyAndParse({\n * rawBody,\n * signature,\n * secret: process.env.COMMET_WEBHOOK_SECRET\n * });\n *\n * if (!payload) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * // payload is typed and validated\n * if (payload.event === 'subscription.activated') {\n * // Handle activation...\n * }\n * ```\n */\n verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null {\n const { rawBody, signature, secret } = params;\n\n if (!this.verify({ payload: rawBody, signature, secret })) {\n return null;\n }\n\n try {\n return JSON.parse(params.rawBody) as WebhookPayload;\n } catch {\n return null;\n }\n }\n}\n","export type CommetConfig = {\n apiKey: string;\n apiVersion?: string;\n debug?: boolean;\n timeout?: number;\n retries?: number;\n telemetry?: boolean;\n};\n\n// API Response types\nexport interface ApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n code?: string;\n message?: string;\n details?: unknown;\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 = 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 apiVersion?: string;\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/types.d.ts file that augments this interface with your\n * organization's specific feature codes, seat types, and plan codes.\n *\n * @example\n * // After running `commet pull`, TypeScript will automatically know your types:\n * await commet.usage.track({\n * feature: 'api_calls', // Autocomplete works!\n * externalId: 'user_123'\n * });\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by CLI-generated .commet/types.d.ts\nexport interface CommetGeneratedTypes {}\n\nexport type GeneratedSeatType = CommetGeneratedTypes extends {\n seatType: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedPlanCode = CommetGeneratedTypes extends {\n planCode: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedFeatureCode = CommetGeneratedTypes extends {\n featureCode: infer T;\n}\n ? T\n : string;\n","export const API_VERSION = \"2026-05-01\";\n\ndeclare const __SDK_VERSION__: string;\nexport const SDK_VERSION: string = __SDK_VERSION__;\n","import { SDK_VERSION } from \"../version\";\n\ninterface RequestMetrics {\n requestId: string;\n durationMs: number;\n}\n\ninterface ClientInfo {\n sdk: string;\n sdkVersion: string;\n lang: string;\n langVersion: string;\n platform: string;\n arch: string;\n runtime: string;\n runtimeVersion: string;\n}\n\nfunction detectRuntime(): { name: string; version: string } {\n const g = globalThis as Record<string, unknown>;\n const bun = g.Bun as { version: string } | undefined;\n if (bun) return { name: \"bun\", version: bun.version };\n const deno = g.Deno as { version: { deno: string } } | undefined;\n if (deno) return { name: \"deno\", version: deno.version.deno };\n return { name: \"node\", version: process.versions.node };\n}\n\nlet cachedClientInfo: string | null = null;\nlet cachedUserAgent: string | null = null;\n\nfunction collectClientInfo(): ClientInfo {\n const runtime = detectRuntime();\n return {\n sdk: \"commet-node\",\n sdkVersion: SDK_VERSION,\n lang: \"node\",\n langVersion: process.versions.node,\n platform: process.platform,\n arch: process.arch,\n runtime: runtime.name,\n runtimeVersion: runtime.version,\n };\n}\n\nexport function getClientInfoHeader(): string {\n if (!cachedClientInfo) {\n cachedClientInfo = JSON.stringify(collectClientInfo());\n }\n return cachedClientInfo;\n}\n\nexport function getUserAgent(): string {\n if (!cachedUserAgent) {\n const runtime = detectRuntime();\n cachedUserAgent = `commet-node/${SDK_VERSION} ${runtime.name}/${runtime.version} ${process.platform}/${process.arch}`;\n }\n return cachedUserAgent;\n}\n\nexport function formatRequestMetrics(metrics: RequestMetrics): string {\n return JSON.stringify({\n last_request_metrics: {\n request_id: metrics.requestId,\n duration_ms: metrics.durationMs,\n },\n });\n}\n","import type {\n ApiResponse,\n CommetConfig,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\nimport { API_VERSION } from \"../version\";\nimport {\n formatRequestMetrics,\n getClientInfoHeader,\n getUserAgent,\n} from \"./telemetry\";\n\nconst BASE_URL = \"https://commet.co\";\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 retryConfig: RetryConfig;\n private telemetryEnabled: boolean;\n private lastRequestMetrics: { requestId: string; durationMs: number } | null =\n null;\n\n constructor(config: CommetConfig) {\n this.config = config;\n this.telemetryEnabled = config.telemetry !== false;\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 private resolveApiVersion(options?: RequestOptions): string {\n return options?.apiVersion ?? this.config.apiVersion ?? API_VERSION;\n }\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 apiVersion = this.resolveApiVersion(options);\n\n const headers: Record<string, string> = {\n \"x-api-key\": this.config.apiKey,\n \"commet-version\": apiVersion,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": getUserAgent(),\n };\n\n if (this.telemetryEnabled) {\n headers[\"commet-client-info\"] = getClientInfoHeader();\n if (this.lastRequestMetrics) {\n headers[\"commet-client-telemetry\"] = formatRequestMetrics(\n this.lastRequestMetrics,\n );\n this.lastRequestMetrics = null;\n }\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 requestStart = Date.now();\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 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\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 code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle validation errors (new normalized shape)\n if (\n errorData.code === \"validation_error\" &&\n Array.isArray(errorData.details)\n ) {\n const errors: Record<string, string[]> = {};\n for (const detail of errorData.details as Array<{\n field: string;\n message: string;\n }>) {\n if (!errors[detail.field]) errors[detail.field] = [];\n errors[detail.field].push(detail.message);\n }\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n 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 if (this.telemetryEnabled) {\n this.lastRequestMetrics = {\n requestId:\n response.headers.get(\"x-request-id\") ?? `req_${Date.now()}`,\n durationMs: Date.now() - requestStart,\n };\n }\n\n return responseData as ApiResponse<T>;\n } catch (error) {\n // Handle network errors and timeouts\n const isNetworkError =\n error instanceof TypeError && error.message.includes(\"fetch\");\n const isTimeoutError =\n error instanceof DOMException && error.name === \"AbortError\";\n const isTimeoutErrorModern =\n typeof globalThis.DOMException !== \"undefined\" &&\n error instanceof DOMException &&\n error.name === \"TimeoutError\";\n\n if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {\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 * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n // Construct full path with /api prefix\n const normalizedEndpoint = endpoint.startsWith(\"/\")\n ? endpoint\n : `/${endpoint}`;\n const fullPath = `/api/v1${normalizedEndpoint}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, BASE_URL);\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 { CustomerContext } from \"./customer\";\nimport { CreditPacksResource } from \"./resources/credit-packs\";\nimport { CustomersResource } from \"./resources/customers\";\nimport { FeaturesResource } from \"./resources/features\";\nimport { PlansResource } from \"./resources/plans\";\nimport { PortalResource } from \"./resources/portal\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { SubscriptionsResource } from \"./resources/subscriptions\";\nimport { UsageResource } from \"./resources/usage\";\nimport { Webhooks } from \"./resources/webhooks\";\nimport type { CommetConfig } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n\n public readonly customers: CustomersResource;\n public readonly creditPacks: CreditPacksResource;\n public readonly plans: PlansResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n public readonly subscriptions: SubscriptionsResource;\n public readonly portal: PortalResource;\n public readonly features: FeaturesResource;\n public readonly webhooks: Webhooks;\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 this.httpClient = new CommetHTTPClient(config);\n this.customers = new CustomersResource(this.httpClient);\n this.creditPacks = new CreditPacksResource(this.httpClient);\n this.plans = new PlansResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n this.subscriptions = new SubscriptionsResource(this.httpClient);\n this.portal = new PortalResource(this.httpClient);\n this.features = new FeaturesResource(this.httpClient);\n this.webhooks = new Webhooks();\n\n if (config.debug) {\n console.log(\"[Commet SDK] Initialized\");\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n }\n }\n\n /**\n * Create a customer-scoped context for cleaner API usage\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\n customer(customerId: string): CustomerContext {\n return new CustomerContext(customerId, {\n features: this.features,\n seats: this.seats,\n usage: this.usage,\n subscriptions: this.subscriptions,\n portal: this.portal,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACuBO,IAAM,kBAAN,MAAsB;AAAA,EAQ3B,YACE,YACA,WAOA;AASF,oBAAW;AAAA,MACT,KAAK,CAAC,MAAc,YAClB,KAAK,iBAAiB,IAAI,EAAE,MAAM,YAAY,KAAK,WAAW,GAAG,OAAO;AAAA,MAE1E,OAAO,CAAC,MAAc,YACpB,KAAK,iBAAiB;AAAA,QACpB,EAAE,MAAM,YAAY,KAAK,WAAW;AAAA,QACpC;AAAA,MACF;AAAA,MAEF,QAAQ,CAAC,MAAc,YACrB,KAAK,iBAAiB;AAAA,QACpB,EAAE,MAAM,YAAY,KAAK,WAAW;AAAA,QACpC;AAAA,MACF;AAAA,MAEF,MAAM,CAAC,YACL,KAAK,iBAAiB,KAAK,KAAK,YAAY,OAAO;AAAA,IACvD;AAEA,iBAAQ;AAAA,MACN,KAAK,CAAC,UAAkB,QAAQ,GAAG,YACjC,KAAK,cAAc;AAAA,QACjB,EAAE,YAAY,KAAK,YAAY,UAAU,MAAM;AAAA,QAC/C;AAAA,MACF;AAAA,MAEF,QAAQ,CAAC,UAAkB,QAAQ,GAAG,YACpC,KAAK,cAAc;AAAA,QACjB,EAAE,YAAY,KAAK,YAAY,UAAU,MAAM;AAAA,QAC/C;AAAA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AC,OAAO,OAAO,WAAW,KAAK,GAAG;AACpC,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,SAAK,aAAa,IAAI,iBAAiB,MAAM;AAC7C,SAAK,YAAY,IAAI,kBAAkB,KAAK,UAAU;AACtD,SAAK,cAAc,IAAI,oBAAoB,KAAK,UAAU;AAC1D,SAAK,QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,gBAAgB,IAAI,sBAAsB,KAAK,UAAU;AAC9D,SAAK,SAAS,IAAI,eAAe,KAAK,UAAU;AAChD,SAAK,WAAW,IAAI,iBAAiB,KAAK,UAAU;AACpD,SAAK,WAAW,IAAI,SAAS;AAE7B,QAAI,OAAO,OAAO;AAChB,cAAQ,IAAI,0BAA0B;AACtC,cAAQ,IAAI,YAAY,GAAG,OAAO,OAAO,UAAU,GAAG,EAAE,CAAC,KAAK;AAAA,IAChE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,SAAS,YAAqC;AAC5C,WAAO,IAAI,gBAAgB,YAAY;AAAA,MACrC,UAAU,KAAK;AAAA,MACf,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,MACZ,eAAe,KAAK;AAAA,MACpB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AACF;;;AfsBA,IAAO,gBAAQ;","names":["crypto","data"]}
package/dist/index.mjs CHANGED
@@ -479,6 +479,56 @@ var CommetValidationError = class extends CommetError {
479
479
  }
480
480
  };
481
481
 
482
+ // src/version.ts
483
+ var API_VERSION = "2026-05-01";
484
+ var SDK_VERSION = "3.1.0";
485
+
486
+ // src/utils/telemetry.ts
487
+ function detectRuntime() {
488
+ const g = globalThis;
489
+ const bun = g.Bun;
490
+ if (bun) return { name: "bun", version: bun.version };
491
+ const deno = g.Deno;
492
+ if (deno) return { name: "deno", version: deno.version.deno };
493
+ return { name: "node", version: process.versions.node };
494
+ }
495
+ var cachedClientInfo = null;
496
+ var cachedUserAgent = null;
497
+ function collectClientInfo() {
498
+ const runtime = detectRuntime();
499
+ return {
500
+ sdk: "commet-node",
501
+ sdkVersion: SDK_VERSION,
502
+ lang: "node",
503
+ langVersion: process.versions.node,
504
+ platform: process.platform,
505
+ arch: process.arch,
506
+ runtime: runtime.name,
507
+ runtimeVersion: runtime.version
508
+ };
509
+ }
510
+ function getClientInfoHeader() {
511
+ if (!cachedClientInfo) {
512
+ cachedClientInfo = JSON.stringify(collectClientInfo());
513
+ }
514
+ return cachedClientInfo;
515
+ }
516
+ function getUserAgent() {
517
+ if (!cachedUserAgent) {
518
+ const runtime = detectRuntime();
519
+ cachedUserAgent = `commet-node/${SDK_VERSION} ${runtime.name}/${runtime.version} ${process.platform}/${process.arch}`;
520
+ }
521
+ return cachedUserAgent;
522
+ }
523
+ function formatRequestMetrics(metrics) {
524
+ return JSON.stringify({
525
+ last_request_metrics: {
526
+ request_id: metrics.requestId,
527
+ duration_ms: metrics.durationMs
528
+ }
529
+ });
530
+ }
531
+
482
532
  // src/utils/http.ts
483
533
  var BASE_URL = "https://commet.co";
484
534
  var DEFAULT_RETRY_CONFIG = {
@@ -491,7 +541,9 @@ var DEFAULT_RETRY_CONFIG = {
491
541
  };
492
542
  var CommetHTTPClient = class {
493
543
  constructor(config) {
544
+ this.lastRequestMetrics = null;
494
545
  this.config = config;
546
+ this.telemetryEnabled = config.telemetry !== false;
495
547
  this.retryConfig = {
496
548
  ...DEFAULT_RETRY_CONFIG,
497
549
  maxRetries: config.retries ?? DEFAULT_RETRY_CONFIG.maxRetries
@@ -509,9 +561,9 @@ var CommetHTTPClient = class {
509
561
  async delete(endpoint, data, options) {
510
562
  return this.request("DELETE", endpoint, data, options);
511
563
  }
512
- /**
513
- * Core request method with retry logic
514
- */
564
+ resolveApiVersion(options) {
565
+ return options?.apiVersion ?? this.config.apiVersion ?? API_VERSION;
566
+ }
515
567
  async request(method, endpoint, data, options, params) {
516
568
  const url = this.buildURL(endpoint, params);
517
569
  return this.executeRequest(method, url, data, options);
@@ -521,11 +573,22 @@ var CommetHTTPClient = class {
521
573
  */
522
574
  async executeRequest(method, url, data, options, attempt = 1) {
523
575
  try {
576
+ const apiVersion = this.resolveApiVersion(options);
524
577
  const headers = {
525
578
  "x-api-key": this.config.apiKey,
579
+ "commet-version": apiVersion,
526
580
  "Content-Type": "application/json",
527
- "User-Agent": "commet-node/2.0.0"
581
+ "User-Agent": getUserAgent()
528
582
  };
583
+ if (this.telemetryEnabled) {
584
+ headers["commet-client-info"] = getClientInfoHeader();
585
+ if (this.lastRequestMetrics) {
586
+ headers["commet-client-telemetry"] = formatRequestMetrics(
587
+ this.lastRequestMetrics
588
+ );
589
+ this.lastRequestMetrics = null;
590
+ }
591
+ }
529
592
  if (options?.idempotencyKey) {
530
593
  headers["Idempotency-Key"] = options.idempotencyKey;
531
594
  } else if (method === "POST" && data) {
@@ -547,6 +610,7 @@ var CommetHTTPClient = class {
547
610
  console.log("Request data:", JSON.stringify(data, null, 2));
548
611
  }
549
612
  }
613
+ const requestStart = Date.now();
550
614
  const response = await fetch(url, requestConfig);
551
615
  if (this.config.debug) {
552
616
  console.log(
@@ -622,6 +686,12 @@ var CommetHTTPClient = class {
622
686
  if (this.config.debug) {
623
687
  console.log("[Commet SDK] Response:", responseData);
624
688
  }
689
+ if (this.telemetryEnabled) {
690
+ this.lastRequestMetrics = {
691
+ requestId: response.headers.get("x-request-id") ?? `req_${Date.now()}`,
692
+ durationMs: Date.now() - requestStart
693
+ };
694
+ }
625
695
  return responseData;
626
696
  } catch (error) {
627
697
  const isNetworkError = error instanceof TypeError && error.message.includes("fetch");
@@ -648,7 +718,7 @@ var CommetHTTPClient = class {
648
718
  */
649
719
  buildURL(endpoint, params) {
650
720
  const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
651
- const fullPath = `/api${normalizedEndpoint}`;
721
+ const fullPath = `/api/v1${normalizedEndpoint}`;
652
722
  if (this.config.debug) {
653
723
  console.log(
654
724
  `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`
@@ -735,11 +805,13 @@ var Commet = class {
735
805
  // src/index.ts
736
806
  var index_default = Commet;
737
807
  export {
808
+ API_VERSION,
738
809
  Commet,
739
810
  CommetAPIError,
740
811
  CommetError,
741
812
  CommetValidationError,
742
813
  CustomerContext,
814
+ SDK_VERSION,
743
815
  Webhooks,
744
816
  index_default as default
745
817
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/customer.ts","../src/resources/credit-packs.ts","../src/resources/customers.ts","../src/resources/features.ts","../src/resources/plans.ts","../src/resources/portal.ts","../src/resources/seats.ts","../src/resources/subscriptions.ts","../src/resources/usage.ts","../src/resources/webhooks.ts","../src/types/common.ts","../src/utils/http.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["import type { FeaturesResource } from \"./resources/features\";\nimport type { PortalResource } from \"./resources/portal\";\nimport type { SeatsResource } from \"./resources/seats\";\nimport type { SubscriptionsResource } from \"./resources/subscriptions\";\nimport type { UsageResource } from \"./resources/usage\";\nimport type { RequestOptions } from \"./types/common\";\n\n/**\n * Customer-scoped API context\n *\n * Provides a cleaner API where you don't have to pass customerId\n * on every call. All operations are scoped to a specific customer.\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\nexport class CustomerContext {\n private readonly customerId: string;\n private readonly featuresResource: FeaturesResource;\n private readonly seatsResource: SeatsResource;\n private readonly usageResource: UsageResource;\n private readonly subscriptionsResource: SubscriptionsResource;\n private readonly portalResource: PortalResource;\n\n constructor(\n customerId: string,\n resources: {\n features: FeaturesResource;\n seats: SeatsResource;\n usage: UsageResource;\n subscriptions: SubscriptionsResource;\n portal: PortalResource;\n },\n ) {\n this.customerId = customerId;\n this.featuresResource = resources.features;\n this.seatsResource = resources.seats;\n this.usageResource = resources.usage;\n this.subscriptionsResource = resources.subscriptions;\n this.portalResource = resources.portal;\n }\n\n features = {\n get: (code: string, options?: RequestOptions) =>\n this.featuresResource.get({ code, customerId: this.customerId }, options),\n\n check: (code: string, options?: RequestOptions) =>\n this.featuresResource.check(\n { code, customerId: this.customerId },\n options,\n ),\n\n canUse: (code: string, options?: RequestOptions) =>\n this.featuresResource.canUse(\n { code, customerId: this.customerId },\n options,\n ),\n\n list: (options?: RequestOptions) =>\n this.featuresResource.list(this.customerId, options),\n };\n\n seats = {\n add: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.add(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n remove: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.remove(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n set: (seatType: string, count: number, options?: RequestOptions) =>\n this.seatsResource.set(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n getBalance: (seatType: string) =>\n this.seatsResource.getBalance({ customerId: this.customerId, seatType }),\n };\n\n usage = {\n track: (\n feature: string,\n value?: number,\n properties?: Record<string, string>,\n options?: RequestOptions,\n ) =>\n this.usageResource.track(\n { customerId: this.customerId, feature, value, properties },\n options,\n ),\n };\n\n subscription = {\n get: () => this.subscriptionsResource.get(this.customerId),\n };\n\n portal = {\n getUrl: (options?: RequestOptions) =>\n this.portalResource.getUrl({ customerId: this.customerId }, options),\n };\n}\n","import type { ApiResponse } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface CreditPack {\n id: string;\n name: string;\n description: string | null;\n credits: number;\n price: number;\n currency: string;\n}\n\n/**\n * Credit Packs resource for listing available credit packs\n */\nexport class CreditPacksResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all active credit packs\n *\n * @example\n * ```typescript\n * const packs = await commet.creditPacks.list();\n * console.log(packs.data); // [{ id: \"cp_xxx\", name: \"100 Credits\", ... }]\n * ```\n */\n async list(): Promise<ApiResponse<CreditPack[]>> {\n return this.httpClient.get(\"/credit-packs\");\n }\n}\n","import type {\n ApiResponse,\n ListParams as BaseListParams,\n CustomerID,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n billingEmail: 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\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n}\n\nexport interface CreateParams {\n email: string; // billingEmail - the only required field\n id?: string; // Your user ID — stored as externalId, used to identify the customer in all SDK methods\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface UpdateParams {\n customerId: CustomerID;\n email?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface ListCustomersParams extends BaseListParams {\n isActive?: boolean;\n search?: string;\n}\n\nexport interface BatchResult {\n successful: Customer[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateParams;\n }>;\n}\n\n/**\n * Customers resource - Manage your customers\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a customer (idempotent when id is provided)\n */\n async create(\n params: CreateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\n \"/customers\",\n {\n billingEmail: params.email,\n externalId: params.id,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * Create multiple customers in batch\n */\n async createBatch(\n params: { customers: CreateParams[] },\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult>> {\n const customers = params.customers.map((c) => ({\n billingEmail: c.email,\n externalId: c.id,\n fullName: c.fullName,\n domain: c.domain,\n website: c.website,\n timezone: c.timezone,\n language: c.language,\n industry: c.industry,\n metadata: c.metadata,\n address: c.address,\n }));\n return this.httpClient.post(\"/customers/batch\", { customers }, options);\n }\n\n /**\n * Get a customer by ID\n */\n async get(customerId: CustomerID): Promise<ApiResponse<Customer>> {\n return this.httpClient.get(`/customers/${customerId}`);\n }\n\n /**\n * Update a customer\n */\n async update(\n params: UpdateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${params.customerId}`,\n {\n billingEmail: params.email,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * List customers with optional filters\n */\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params as Record<string, unknown>);\n }\n\n /**\n * Archive a customer\n */\n async archive(\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 GeneratedFeatureCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface FeatureParams {\n customerId: CustomerID;\n code: GeneratedFeatureCode;\n}\n\nexport type GetFeatureParams = FeatureParams;\nexport type CheckFeatureParams = FeatureParams;\nexport type CanUseFeatureParams = FeatureParams;\n\nexport interface FeatureAccess {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n allowed: boolean;\n enabled?: boolean;\n current?: number;\n included?: number;\n remaining?: number;\n overage?: number;\n overageUnitPrice?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n}\n\nexport interface CanUseResult {\n allowed: boolean;\n willBeCharged: boolean;\n reason?: string;\n}\n\nexport interface CheckResult {\n allowed: boolean;\n}\n\nexport class FeaturesResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async get(\n params: GetFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n }\n\n async check(\n params: CheckFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CheckResult>> {\n const result = await this.httpClient.get<FeatureAccess>(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n\n if (!result.success || !result.data) {\n return {\n success: false,\n code: result.code,\n message: result.message,\n details: result.details,\n };\n }\n\n return {\n success: true,\n data: { allowed: result.data.allowed },\n };\n }\n\n async canUse(\n params: CanUseFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CanUseResult>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId, action: \"canUse\" },\n options,\n );\n }\n\n async list(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess[]>> {\n return this.httpClient.get(\"/features\", { customerId }, options);\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n ListParams,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport type PlanID = `plan_${string}`;\nexport type BillingInterval = \"monthly\" | \"quarterly\" | \"yearly\";\nexport type FeatureType = \"boolean\" | \"metered\" | \"seats\";\n\nexport interface PlanPrice {\n billingInterval: BillingInterval;\n price: number; // in cents\n isDefault: boolean;\n trialDays: number;\n}\n\nexport interface PlanFeature {\n code: string;\n name: string;\n type: FeatureType;\n unitName: string | null;\n enabled?: boolean;\n includedAmount?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n overageUnitPrice?: number;\n}\n\nexport interface Plan {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isFree: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanPrice[];\n features: PlanFeature[];\n createdAt: string;\n}\n\nexport interface PlanDetailPrice {\n billingInterval: BillingInterval;\n price: number;\n isDefault: boolean;\n trialDays: number;\n introOffer: {\n enabled: boolean;\n discountType: \"percentage\" | \"amount\" | null;\n discountValue: number | null;\n durationCycles: number | null;\n } | null;\n}\n\nexport interface PlanDetailFeature extends PlanFeature {\n overage: {\n enabled: boolean;\n model: \"per_unit\" | \"tiered\" | null;\n unitPrice: number | null;\n } | null;\n}\n\nexport interface PlanDetail {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanDetailPrice[];\n features: PlanDetailFeature[];\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ListPlansParams extends ListParams {\n includePrivate?: boolean;\n}\n\n/**\n * Plans resource for listing available plans\n */\nexport class PlansResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all available plans\n *\n * @example\n * ```typescript\n * // List public plans\n * const plans = await commet.plans.list();\n *\n * // Include private plans\n * const allPlans = await commet.plans.list({ includePrivate: true });\n * ```\n */\n async list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>> {\n return this.httpClient.get(\"/plans\", params);\n }\n\n /**\n * Get a specific plan by code\n *\n * @example\n * ```typescript\n * const plan = await commet.plans.get('pro');\n * console.log(plan.data.name); // \"Pro\"\n * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]\n * ```\n */\n async get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>> {\n return this.httpClient.get(`/plans/${planCode}`);\n }\n}\n","import type { ApiResponse, CustomerID, RequestOptions } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface PortalAccess {\n success: boolean;\n message: string;\n portalUrl: string;\n}\n\ninterface GetUrlByCustomerId {\n customerId: CustomerID;\n email?: never;\n}\n\ninterface GetUrlByEmail {\n email: string;\n customerId?: never;\n}\n\nexport type GetUrlParams = GetUrlByCustomerId | GetUrlByEmail;\n\nexport class PortalResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async getUrl(\n params: GetUrlParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<PortalAccess>> {\n return this.httpClient.post(\"/portal/request-access\", params, options);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n GeneratedSeatType,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\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 SeatBalance {\n current: number;\n asOf: string;\n}\n\nexport interface AddParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface RemoveParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetAllParams {\n customerId: CustomerID;\n seats: Record<string, number>;\n}\n\nexport interface GetBalanceParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n}\n\nexport interface GetAllBalancesParams {\n customerId: CustomerID;\n}\n\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n params: AddParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\"/seats\", params, options);\n }\n\n async remove(\n params: RemoveParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.delete(\"/seats\", params, options);\n }\n\n async set(\n params: SetParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.put(\"/seats\", params, options);\n }\n\n async setAll(\n params: SetAllParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.put(\"/seats/bulk\", params, options);\n }\n\n async getBalance(\n params: GetBalanceParams,\n ): Promise<ApiResponse<SeatBalance>> {\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, SeatBalance>>> {\n return this.httpClient.get(\"/seats/balances\", {\n customerId: params.customerId,\n });\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\nimport type { BillingInterval } from \"./plans\";\n\nexport type SubscriptionStatus =\n | \"draft\"\n | \"pending_payment\"\n | \"trialing\"\n | \"active\"\n | \"paused\"\n | \"past_due\"\n | \"canceled\"\n | \"expired\";\n\nexport interface FeatureSummary {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n enabled?: boolean;\n usage?: {\n current: number;\n included: number;\n overage: number;\n overageUnitPrice?: number;\n };\n}\n\nexport interface CreditsSummary {\n remaining: number;\n included: number;\n purchased: number;\n}\n\nexport interface BalanceSummary {\n remaining: number;\n included: number;\n currency: string;\n}\n\nexport type ConsumptionModel = \"metered\" | \"credits\" | \"balance\";\n\nexport interface ActiveSubscription {\n id: string;\n customerId: string;\n plan: {\n id: string;\n name: string;\n basePrice: number;\n billingInterval: BillingInterval | null;\n };\n name: string;\n description: string | null;\n status: SubscriptionStatus;\n consumptionModel: ConsumptionModel | null;\n trialEndsAt: string | null;\n currentPeriod: {\n start: string;\n end: string;\n daysRemaining: number;\n };\n features: FeatureSummary[];\n credits: CreditsSummary | null;\n balance: BalanceSummary | null;\n startDate: string;\n endDate: string | null;\n billingDayOfMonth: number;\n nextBillingDate: string;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface CreatedSubscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval | null;\n trialEndsAt: string | null;\n startDate: string;\n endDate: string | null;\n currentPeriodStart: string | null;\n currentPeriodEnd: string | null;\n billingDayOfMonth: number;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n introOfferEndsAt: string | null;\n introOfferDiscountType: \"percentage\" | \"amount\" | null;\n introOfferDiscountValue: number | null;\n}\n\nexport interface Subscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n description?: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval;\n trialEndsAt?: string;\n startDate: string;\n endDate?: string;\n currentPeriodStart?: string;\n currentPeriodEnd?: string;\n billingDayOfMonth: number;\n checkoutUrl?: string;\n createdAt: string;\n updatedAt: string;\n}\n\ntype PlanIdentifier =\n | { planCode: GeneratedPlanCode; planId?: never }\n | { planCode?: never; planId: string };\n\nexport type CreateSubscriptionParams = PlanIdentifier & {\n customerId: string;\n} & {\n billingInterval?: BillingInterval;\n initialSeats?: Record<string, number>;\n skipTrial?: boolean;\n name?: string;\n startDate?: string;\n successUrl?: string;\n};\n\nexport interface CancelParams {\n subscriptionId: string;\n reason?: string;\n immediate?: boolean;\n}\n\n/**\n * Subscription resource for managing subscriptions (plan-first model)\n *\n * Each customer can only have ONE active subscription at a time.\n */\nexport class SubscriptionsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a subscription with a plan\n *\n * @example\n * ```typescript\n * await commet.subscriptions.create({\n * externalId: 'user_123',\n * planCode: 'pro', // autocomplete works after `commet pull`\n * billingInterval: 'yearly',\n * initialSeats: { editor: 5 }\n * });\n * ```\n */\n async create(\n params: CreateSubscriptionParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CreatedSubscription>> {\n return this.httpClient.post(\"/subscriptions\", params, options);\n }\n\n /**\n * Get the active subscription for a customer\n *\n * @example\n * ```typescript\n * const sub = await commet.subscriptions.get('user_123');\n * ```\n */\n async get(\n customerId: string,\n ): Promise<ApiResponse<ActiveSubscription | null>> {\n return this.httpClient.get(\"/subscriptions/active\", { customerId });\n }\n\n /**\n * Cancel a subscription\n *\n * @example\n * ```typescript\n * await commet.subscriptions.cancel({\n * subscriptionId: 'sub_xxx',\n * reason: 'switched_to_competitor'\n * });\n * ```\n */\n async cancel(\n params: CancelParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Subscription>> {\n return this.httpClient.post(\n `/subscriptions/${params.subscriptionId}/cancel`,\n params || {},\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\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 feature: 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\ninterface TrackBaseParams {\n feature: GeneratedFeatureCode;\n customerId: CustomerID;\n idempotencyKey?: string;\n timestamp?: string;\n properties?: Record<string, string>;\n}\n\nexport interface TrackUsageParams extends TrackBaseParams {\n value?: number;\n model?: never;\n}\n\nexport interface TrackModelTokensParams extends TrackBaseParams {\n model: string;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens?: number;\n cacheWriteTokens?: number;\n value?: never;\n}\n\nexport type TrackParams = TrackUsageParams | TrackModelTokensParams;\n\nexport class UsageResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async track(\n params: TrackParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData: Record<string, unknown> = {\n feature: params.feature,\n customerId: params.customerId,\n idempotencyKey: params.idempotencyKey,\n timestamp: params.timestamp || new Date().toISOString(),\n properties: params.properties\n ? Object.entries(params.properties).map(([property, value]) => ({\n property,\n value,\n }))\n : undefined,\n };\n\n if (\"model\" in params && params.model) {\n eventData.model = params.model;\n eventData.inputTokens = params.inputTokens;\n eventData.outputTokens = params.outputTokens;\n if (params.cacheReadTokens) {\n eventData.cacheReadTokens = params.cacheReadTokens;\n }\n if (params.cacheWriteTokens) {\n eventData.cacheWriteTokens = params.cacheWriteTokens;\n }\n } else {\n eventData.value = (params as TrackUsageParams).value;\n }\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n}\n","import crypto from \"node:crypto\";\nimport type { SubscriptionStatus } from \"./subscriptions\";\n\n/**\n * Webhook payload structure from Commet\n */\nexport interface WebhookPayload {\n event: WebhookEvent;\n timestamp: string;\n organizationId: string;\n data: WebhookData;\n}\n\n/**\n * Webhook data structure (subscription-related fields).\n *\n * The `status` field is present on `subscription.*` events. Grant access only\n * when it is `\"active\"` or `\"trialing\"`. `\"pending_payment\"` means the first\n * charge has not been confirmed yet — wait for `subscription.activated` before\n * granting access.\n */\nexport interface WebhookData {\n id?: string;\n publicId?: string;\n subscriptionId?: string;\n customerId?: string;\n externalId?: string;\n /**\n * Subscription status. Present on `subscription.*` events.\n * Grant access when this is `\"active\"` or `\"trialing\"`.\n */\n status?: SubscriptionStatus;\n name?: string;\n canceledAt?: string;\n [key: string]: unknown;\n}\n\n/**\n * Supported webhook events\n */\nexport type WebhookEvent =\n | \"subscription.created\"\n | \"subscription.activated\"\n | \"subscription.canceled\"\n | \"subscription.updated\"\n | \"subscription.plan_changed\"\n | \"payment.received\"\n | \"payment.failed\"\n | \"invoice.created\";\n\nexport interface VerifyParams {\n payload: string;\n signature: string | null;\n secret: string;\n}\n\nexport interface GenerateSignatureParams {\n payload: string;\n secret: string;\n}\n\nexport interface VerifyAndParseParams {\n rawBody: string;\n signature: string | null;\n secret: string;\n}\n\n/**\n * Webhooks resource for signature verification\n */\nexport class Webhooks {\n /**\n * Verify HMAC-SHA256 webhook signature\n *\n * Use this method to verify that webhooks are authentically from Commet.\n * The signature is included in the `X-Commet-Signature` header.\n *\n * @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)\n * @param signature - Value from X-Commet-Signature header\n * @param secret - Your webhook secret from Commet dashboard\n * @returns true if signature is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Next.js API route example\n * export async function POST(request: Request) {\n * const rawBody = await request.text();\n * const signature = request.headers.get('x-commet-signature');\n *\n * const isValid = commet.webhooks.verify(\n * rawBody,\n * signature,\n * process.env.COMMET_WEBHOOK_SECRET\n * );\n *\n * if (!isValid) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * const payload = JSON.parse(rawBody);\n * // Handle webhook event...\n * }\n * ```\n */\n verify(params: VerifyParams): boolean {\n const { payload, signature, secret } = params;\n\n if (!signature || !secret || !payload) {\n return false;\n }\n\n try {\n const expectedSignature = this.generateSignature({ payload, secret });\n\n // Use timing-safe comparison to prevent timing attacks\n return crypto.timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n );\n } catch (_error) {\n // timingSafeEqual throws if lengths don't match\n return false;\n }\n }\n\n /**\n * Generate HMAC-SHA256 signature (internal use)\n * @internal\n */\n private generateSignature(params: GenerateSignatureParams): string {\n const { payload, secret } = params;\n return crypto.createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n }\n\n /**\n * Parse and verify webhook payload in one step\n *\n * @example\n * ```typescript\n * const payload = commet.webhooks.verifyAndParse({\n * rawBody,\n * signature,\n * secret: process.env.COMMET_WEBHOOK_SECRET\n * });\n *\n * if (!payload) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * // payload is typed and validated\n * if (payload.event === 'subscription.activated') {\n * // Handle activation...\n * }\n * ```\n */\n verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null {\n const { rawBody, signature, secret } = params;\n\n if (!this.verify({ payload: rawBody, signature, secret })) {\n return null;\n }\n\n try {\n return JSON.parse(params.rawBody) as WebhookPayload;\n } catch {\n return null;\n }\n }\n}\n","export type CommetConfig = {\n apiKey: string;\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 code?: string;\n message?: string;\n details?: unknown;\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 = 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/types.d.ts file that augments this interface with your\n * organization's specific feature codes, seat types, and plan codes.\n *\n * @example\n * // After running `commet pull`, TypeScript will automatically know your types:\n * await commet.usage.track({\n * feature: 'api_calls', // Autocomplete works!\n * externalId: 'user_123'\n * });\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by CLI-generated .commet/types.d.ts\nexport interface CommetGeneratedTypes {}\n\nexport type GeneratedSeatType = CommetGeneratedTypes extends {\n seatType: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedPlanCode = CommetGeneratedTypes extends {\n planCode: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedFeatureCode = CommetGeneratedTypes extends {\n featureCode: infer T;\n}\n ? T\n : string;\n","import type {\n ApiResponse,\n CommetConfig,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\n\nconst BASE_URL = \"https://commet.co\";\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 retryConfig: RetryConfig;\n\n constructor(config: CommetConfig) {\n this.config = config;\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-node/2.0.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 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\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 code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle validation errors (new normalized shape)\n if (\n errorData.code === \"validation_error\" &&\n Array.isArray(errorData.details)\n ) {\n const errors: Record<string, string[]> = {};\n for (const detail of errorData.details as Array<{\n field: string;\n message: string;\n }>) {\n if (!errors[detail.field]) errors[detail.field] = [];\n errors[detail.field].push(detail.message);\n }\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n 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 const isNetworkError =\n error instanceof TypeError && error.message.includes(\"fetch\");\n const isTimeoutError =\n error instanceof DOMException && error.name === \"AbortError\";\n const isTimeoutErrorModern =\n typeof globalThis.DOMException !== \"undefined\" &&\n error instanceof DOMException &&\n error.name === \"TimeoutError\";\n\n if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {\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 * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n // Construct full path with /api prefix\n const normalizedEndpoint = endpoint.startsWith(\"/\")\n ? endpoint\n : `/${endpoint}`;\n const fullPath = `/api${normalizedEndpoint}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, BASE_URL);\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 { CustomerContext } from \"./customer\";\nimport { CreditPacksResource } from \"./resources/credit-packs\";\nimport { CustomersResource } from \"./resources/customers\";\nimport { FeaturesResource } from \"./resources/features\";\nimport { PlansResource } from \"./resources/plans\";\nimport { PortalResource } from \"./resources/portal\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { SubscriptionsResource } from \"./resources/subscriptions\";\nimport { UsageResource } from \"./resources/usage\";\nimport { Webhooks } from \"./resources/webhooks\";\nimport type { CommetConfig } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n\n public readonly customers: CustomersResource;\n public readonly creditPacks: CreditPacksResource;\n public readonly plans: PlansResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n public readonly subscriptions: SubscriptionsResource;\n public readonly portal: PortalResource;\n public readonly features: FeaturesResource;\n public readonly webhooks: Webhooks;\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 this.httpClient = new CommetHTTPClient(config);\n this.customers = new CustomersResource(this.httpClient);\n this.creditPacks = new CreditPacksResource(this.httpClient);\n this.plans = new PlansResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n this.subscriptions = new SubscriptionsResource(this.httpClient);\n this.portal = new PortalResource(this.httpClient);\n this.features = new FeaturesResource(this.httpClient);\n this.webhooks = new Webhooks();\n\n if (config.debug) {\n console.log(\"[Commet SDK] Initialized\");\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n }\n }\n\n /**\n * Create a customer-scoped context for cleaner API usage\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\n customer(customerId: string): CustomerContext {\n return new CustomerContext(customerId, {\n features: this.features,\n seats: this.seats,\n usage: this.usage,\n subscriptions: this.subscriptions,\n portal: this.portal,\n });\n }\n}\n","/**\n * Commet SDK - Billing and usage tracking for SaaS\n */\nexport { Commet } from \"./client\";\nexport { CustomerContext } from \"./customer\";\n// Credit Packs\nexport type { CreditPack } from \"./resources/credit-packs\";\n// Customers\nexport type {\n BatchResult as CustomersBatchResult,\n CreateParams as CreateCustomerParams,\n Customer,\n CustomerAddress,\n ListCustomersParams,\n UpdateParams as UpdateCustomerParams,\n} from \"./resources/customers\";\n// Features\nexport type {\n CanUseFeatureParams,\n CanUseResult,\n CheckFeatureParams,\n CheckResult,\n FeatureAccess,\n GetFeatureParams,\n} from \"./resources/features\";\n// Plans\nexport type {\n BillingInterval,\n FeatureType,\n ListPlansParams,\n Plan,\n PlanDetail,\n PlanFeature,\n PlanID,\n PlanPrice,\n} from \"./resources/plans\";\n// Portal\nexport type { GetUrlParams, PortalAccess } from \"./resources/portal\";\n// Seats\nexport type {\n AddParams as AddSeatsParams,\n GetAllBalancesParams,\n GetBalanceParams,\n RemoveParams as RemoveSeatsParams,\n SeatBalance,\n SeatEvent,\n SetAllParams as SetAllSeatsParams,\n SetParams as SetSeatsParams,\n} from \"./resources/seats\";\n// Subscriptions\nexport type {\n ActiveSubscription,\n CancelParams,\n CreatedSubscription,\n CreateSubscriptionParams,\n FeatureSummary,\n Subscription,\n SubscriptionStatus,\n} from \"./resources/subscriptions\";\n// Usage\nexport type {\n TrackModelTokensParams,\n TrackParams,\n TrackUsageParams,\n UsageEvent,\n UsageEventProperty,\n} from \"./resources/usage\";\nexport type {\n WebhookData,\n WebhookEvent,\n WebhookPayload,\n} from \"./resources/webhooks\";\n// Webhooks\nexport { Webhooks } from \"./resources/webhooks\";\n// Type exports\nexport type {\n ApiResponse,\n CommetConfig,\n CommetGeneratedTypes,\n Currency,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\n GeneratedPlanCode,\n GeneratedSeatType,\n PaginatedList,\n PaginatedResponse,\n RequestOptions,\n} from \"./types/common\";\n// Error exports\nexport {\n CommetAPIError,\n CommetError,\n CommetValidationError,\n} from \"./types/common\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n"],"mappings":";AAuBO,IAAM,kBAAN,MAAsB;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","names":["data"]}
1
+ {"version":3,"sources":["../src/customer.ts","../src/resources/credit-packs.ts","../src/resources/customers.ts","../src/resources/features.ts","../src/resources/plans.ts","../src/resources/portal.ts","../src/resources/seats.ts","../src/resources/subscriptions.ts","../src/resources/usage.ts","../src/resources/webhooks.ts","../src/types/common.ts","../src/version.ts","../src/utils/telemetry.ts","../src/utils/http.ts","../src/client.ts","../src/index.ts"],"sourcesContent":["import type { FeaturesResource } from \"./resources/features\";\nimport type { PortalResource } from \"./resources/portal\";\nimport type { SeatsResource } from \"./resources/seats\";\nimport type { SubscriptionsResource } from \"./resources/subscriptions\";\nimport type { UsageResource } from \"./resources/usage\";\nimport type { RequestOptions } from \"./types/common\";\n\n/**\n * Customer-scoped API context\n *\n * Provides a cleaner API where you don't have to pass customerId\n * on every call. All operations are scoped to a specific customer.\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\nexport class CustomerContext {\n private readonly customerId: string;\n private readonly featuresResource: FeaturesResource;\n private readonly seatsResource: SeatsResource;\n private readonly usageResource: UsageResource;\n private readonly subscriptionsResource: SubscriptionsResource;\n private readonly portalResource: PortalResource;\n\n constructor(\n customerId: string,\n resources: {\n features: FeaturesResource;\n seats: SeatsResource;\n usage: UsageResource;\n subscriptions: SubscriptionsResource;\n portal: PortalResource;\n },\n ) {\n this.customerId = customerId;\n this.featuresResource = resources.features;\n this.seatsResource = resources.seats;\n this.usageResource = resources.usage;\n this.subscriptionsResource = resources.subscriptions;\n this.portalResource = resources.portal;\n }\n\n features = {\n get: (code: string, options?: RequestOptions) =>\n this.featuresResource.get({ code, customerId: this.customerId }, options),\n\n check: (code: string, options?: RequestOptions) =>\n this.featuresResource.check(\n { code, customerId: this.customerId },\n options,\n ),\n\n canUse: (code: string, options?: RequestOptions) =>\n this.featuresResource.canUse(\n { code, customerId: this.customerId },\n options,\n ),\n\n list: (options?: RequestOptions) =>\n this.featuresResource.list(this.customerId, options),\n };\n\n seats = {\n add: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.add(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n remove: (seatType: string, count = 1, options?: RequestOptions) =>\n this.seatsResource.remove(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n set: (seatType: string, count: number, options?: RequestOptions) =>\n this.seatsResource.set(\n { customerId: this.customerId, seatType, count },\n options,\n ),\n\n getBalance: (seatType: string) =>\n this.seatsResource.getBalance({ customerId: this.customerId, seatType }),\n };\n\n usage = {\n track: (\n feature: string,\n value?: number,\n properties?: Record<string, string>,\n options?: RequestOptions,\n ) =>\n this.usageResource.track(\n { customerId: this.customerId, feature, value, properties },\n options,\n ),\n };\n\n subscription = {\n get: () => this.subscriptionsResource.get(this.customerId),\n };\n\n portal = {\n getUrl: (options?: RequestOptions) =>\n this.portalResource.getUrl({ customerId: this.customerId }, options),\n };\n}\n","import type { ApiResponse } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface CreditPack {\n id: string;\n name: string;\n description: string | null;\n credits: number;\n price: number;\n currency: string;\n}\n\n/**\n * Credit Packs resource for listing available credit packs\n */\nexport class CreditPacksResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all active credit packs\n *\n * @example\n * ```typescript\n * const packs = await commet.creditPacks.list();\n * console.log(packs.data); // [{ id: \"cp_xxx\", name: \"100 Credits\", ... }]\n * ```\n */\n async list(): Promise<ApiResponse<CreditPack[]>> {\n return this.httpClient.get(\"/credit-packs\");\n }\n}\n","import type {\n ApiResponse,\n ListParams as BaseListParams,\n CustomerID,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface Customer {\n id: CustomerID;\n organizationId: string;\n externalId?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n billingEmail: 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\nexport interface CustomerAddress {\n line1: string;\n line2?: string;\n city: string;\n state?: string;\n postalCode: string;\n country: string; // ISO-2\n}\n\nexport interface CreateParams {\n email: string; // billingEmail - the only required field\n id?: string; // Your user ID — stored as externalId, used to identify the customer in all SDK methods\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface UpdateParams {\n customerId: CustomerID;\n email?: string;\n fullName?: string;\n domain?: string;\n website?: string;\n timezone?: string;\n language?: string;\n industry?: string;\n metadata?: Record<string, unknown>;\n address?: CustomerAddress;\n}\n\nexport interface ListCustomersParams extends BaseListParams {\n isActive?: boolean;\n search?: string;\n}\n\nexport interface BatchResult {\n successful: Customer[];\n failed: Array<{\n index: number;\n error: string;\n data: CreateParams;\n }>;\n}\n\n/**\n * Customers resource - Manage your customers\n */\nexport class CustomersResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a customer (idempotent when id is provided)\n */\n async create(\n params: CreateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.post(\n \"/customers\",\n {\n billingEmail: params.email,\n externalId: params.id,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * Create multiple customers in batch\n */\n async createBatch(\n params: { customers: CreateParams[] },\n options?: RequestOptions,\n ): Promise<ApiResponse<BatchResult>> {\n const customers = params.customers.map((c) => ({\n billingEmail: c.email,\n externalId: c.id,\n fullName: c.fullName,\n domain: c.domain,\n website: c.website,\n timezone: c.timezone,\n language: c.language,\n industry: c.industry,\n metadata: c.metadata,\n address: c.address,\n }));\n return this.httpClient.post(\"/customers/batch\", { customers }, options);\n }\n\n /**\n * Get a customer by ID\n */\n async get(customerId: CustomerID): Promise<ApiResponse<Customer>> {\n return this.httpClient.get(`/customers/${customerId}`);\n }\n\n /**\n * Update a customer\n */\n async update(\n params: UpdateParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Customer>> {\n return this.httpClient.put(\n `/customers/${params.customerId}`,\n {\n billingEmail: params.email,\n fullName: params.fullName,\n domain: params.domain,\n website: params.website,\n timezone: params.timezone,\n language: params.language,\n industry: params.industry,\n metadata: params.metadata,\n address: params.address,\n },\n options,\n );\n }\n\n /**\n * List customers with optional filters\n */\n async list(params?: ListCustomersParams): Promise<ApiResponse<Customer[]>> {\n return this.httpClient.get(\"/customers\", params as Record<string, unknown>);\n }\n\n /**\n * Archive a customer\n */\n async archive(\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 GeneratedFeatureCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface FeatureParams {\n customerId: CustomerID;\n code: GeneratedFeatureCode;\n}\n\nexport type GetFeatureParams = FeatureParams;\nexport type CheckFeatureParams = FeatureParams;\nexport type CanUseFeatureParams = FeatureParams;\n\nexport interface FeatureAccess {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n allowed: boolean;\n enabled?: boolean;\n current?: number;\n included?: number;\n remaining?: number;\n overage?: number;\n overageUnitPrice?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n}\n\nexport interface CanUseResult {\n allowed: boolean;\n willBeCharged: boolean;\n reason?: string;\n}\n\nexport interface CheckResult {\n allowed: boolean;\n}\n\nexport class FeaturesResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async get(\n params: GetFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n }\n\n async check(\n params: CheckFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CheckResult>> {\n const result = await this.httpClient.get<FeatureAccess>(\n `/features/${params.code}`,\n { customerId: params.customerId },\n options,\n );\n\n if (!result.success || !result.data) {\n return {\n success: false,\n code: result.code,\n message: result.message,\n details: result.details,\n };\n }\n\n return {\n success: true,\n data: { allowed: result.data.allowed },\n };\n }\n\n async canUse(\n params: CanUseFeatureParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CanUseResult>> {\n return this.httpClient.get(\n `/features/${params.code}`,\n { customerId: params.customerId, action: \"canUse\" },\n options,\n );\n }\n\n async list(\n customerId: CustomerID,\n options?: RequestOptions,\n ): Promise<ApiResponse<FeatureAccess[]>> {\n return this.httpClient.get(\"/features\", { customerId }, options);\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n ListParams,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport type PlanID = `plan_${string}`;\nexport type BillingInterval = \"weekly\" | \"monthly\" | \"quarterly\" | \"yearly\";\nexport type FeatureType = \"boolean\" | \"metered\" | \"seats\";\n\nexport interface PlanPrice {\n billingInterval: BillingInterval;\n price: number; // in cents\n isDefault: boolean;\n trialDays: number;\n}\n\nexport interface PlanFeature {\n code: string;\n name: string;\n type: FeatureType;\n unitName: string | null;\n enabled?: boolean;\n includedAmount?: number;\n unlimited?: boolean;\n overageEnabled?: boolean;\n overageUnitPrice?: number;\n}\n\nexport interface Plan {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isFree: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanPrice[];\n features: PlanFeature[];\n createdAt: string;\n}\n\nexport interface PlanDetailPrice {\n billingInterval: BillingInterval;\n price: number;\n isDefault: boolean;\n trialDays: number;\n introOffer: {\n enabled: boolean;\n discountType: \"percentage\" | \"amount\" | null;\n discountValue: number | null;\n durationCycles: number | null;\n } | null;\n}\n\nexport interface PlanDetailFeature extends PlanFeature {\n overage: {\n enabled: boolean;\n model: \"per_unit\" | \"tiered\" | null;\n unitPrice: number | null;\n } | null;\n}\n\nexport interface PlanDetail {\n id: PlanID;\n code: string;\n name: string;\n description: string | null;\n isPublic: boolean;\n isDefault: boolean;\n sortOrder: number;\n prices: PlanDetailPrice[];\n features: PlanDetailFeature[];\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface ListPlansParams extends ListParams {\n includePrivate?: boolean;\n}\n\n/**\n * Plans resource for listing available plans\n */\nexport class PlansResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * List all available plans\n *\n * @example\n * ```typescript\n * // List public plans\n * const plans = await commet.plans.list();\n *\n * // Include private plans\n * const allPlans = await commet.plans.list({ includePrivate: true });\n * ```\n */\n async list(params?: ListPlansParams): Promise<ApiResponse<Plan[]>> {\n return this.httpClient.get(\"/plans\", params);\n }\n\n /**\n * Get a specific plan by code\n *\n * @example\n * ```typescript\n * const plan = await commet.plans.get('pro');\n * console.log(plan.data.name); // \"Pro\"\n * console.log(plan.data.prices); // [{ billingInterval: 'monthly', price: 9900 }]\n * ```\n */\n async get(planCode: GeneratedPlanCode): Promise<ApiResponse<PlanDetail>> {\n return this.httpClient.get(`/plans/${planCode}`);\n }\n}\n","import type { ApiResponse, CustomerID, RequestOptions } from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\n\nexport interface PortalAccess {\n success: boolean;\n message: string;\n portalUrl: string;\n}\n\ninterface GetUrlByCustomerId {\n customerId: CustomerID;\n email?: never;\n}\n\ninterface GetUrlByEmail {\n email: string;\n customerId?: never;\n}\n\nexport type GetUrlParams = GetUrlByCustomerId | GetUrlByEmail;\n\nexport class PortalResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async getUrl(\n params: GetUrlParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<PortalAccess>> {\n return this.httpClient.post(\"/portal/request-access\", params, options);\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n GeneratedSeatType,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\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 SeatBalance {\n current: number;\n asOf: string;\n}\n\nexport interface AddParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface RemoveParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n count: number;\n}\n\nexport interface SetAllParams {\n customerId: CustomerID;\n seats: Record<string, number>;\n}\n\nexport interface GetBalanceParams {\n customerId: CustomerID;\n seatType: GeneratedSeatType;\n}\n\nexport interface GetAllBalancesParams {\n customerId: CustomerID;\n}\n\nexport class SeatsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async add(\n params: AddParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.post(\"/seats\", params, options);\n }\n\n async remove(\n params: RemoveParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.delete(\"/seats\", params, options);\n }\n\n async set(\n params: SetParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent>> {\n return this.httpClient.put(\"/seats\", params, options);\n }\n\n async setAll(\n params: SetAllParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<SeatEvent[]>> {\n return this.httpClient.put(\"/seats/bulk\", params, options);\n }\n\n async getBalance(\n params: GetBalanceParams,\n ): Promise<ApiResponse<SeatBalance>> {\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, SeatBalance>>> {\n return this.httpClient.get(\"/seats/balances\", {\n customerId: params.customerId,\n });\n }\n}\n","import type {\n ApiResponse,\n GeneratedPlanCode,\n RequestOptions,\n} from \"../types/common\";\nimport type { CommetHTTPClient } from \"../utils/http\";\nimport type { BillingInterval } from \"./plans\";\n\nexport type SubscriptionStatus =\n | \"draft\"\n | \"pending_payment\"\n | \"trialing\"\n | \"active\"\n | \"paused\"\n | \"past_due\"\n | \"canceled\"\n | \"expired\";\n\nexport interface FeatureSummary {\n code: string;\n name: string;\n type: \"boolean\" | \"metered\" | \"seats\";\n enabled?: boolean;\n usage?: {\n current: number;\n included: number;\n overage: number;\n overageUnitPrice?: number;\n };\n}\n\nexport interface CreditsSummary {\n remaining: number;\n included: number;\n purchased: number;\n}\n\nexport interface BalanceSummary {\n remaining: number;\n included: number;\n currency: string;\n}\n\nexport interface CancellationSummary {\n scheduledAt: string;\n reason: string | null;\n effectiveAt: string;\n}\n\nexport interface DiscountSummary {\n type: \"percentage\" | \"amount\";\n value: number;\n name: string | null;\n endsAt: string | null;\n}\n\nexport type ConsumptionModel = \"metered\" | \"credits\" | \"balance\";\n\nexport interface ActiveSubscription {\n id: string;\n customerId: string;\n plan: {\n id: string;\n name: string;\n basePrice: number;\n billingInterval: BillingInterval | null;\n };\n name: string;\n description: string | null;\n status: SubscriptionStatus;\n consumptionModel: ConsumptionModel | null;\n trialEndsAt: string | null;\n currentPeriod: {\n start: string;\n end: string;\n daysRemaining: number;\n };\n features: FeatureSummary[];\n credits: CreditsSummary | null;\n balance: BalanceSummary | null;\n cancellation: CancellationSummary | null;\n discount: DiscountSummary | null;\n startDate: string;\n endDate: string | null;\n billingDayOfMonth: number;\n nextBillingDate: string;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface CreatedSubscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval | null;\n trialEndsAt: string | null;\n startDate: string;\n endDate: string | null;\n currentPeriodStart: string | null;\n currentPeriodEnd: string | null;\n billingDayOfMonth: number;\n checkoutUrl: string | null;\n createdAt: string;\n updatedAt: string;\n introOfferEndsAt: string | null;\n introOfferDiscountType: \"percentage\" | \"amount\" | null;\n introOfferDiscountValue: number | null;\n}\n\nexport interface Subscription {\n id: string;\n customerId: string;\n planId: string;\n planName: string;\n name: string;\n description?: string;\n status: SubscriptionStatus;\n billingInterval: BillingInterval;\n trialEndsAt?: string;\n startDate: string;\n endDate?: string;\n currentPeriodStart?: string;\n currentPeriodEnd?: string;\n billingDayOfMonth: number;\n checkoutUrl?: string;\n createdAt: string;\n updatedAt: string;\n}\n\ntype PlanIdentifier =\n | { planCode: GeneratedPlanCode; planId?: never }\n | { planCode?: never; planId: string };\n\nexport type CreateSubscriptionParams = PlanIdentifier & {\n customerId: string;\n} & {\n billingInterval?: BillingInterval;\n initialSeats?: Record<string, number>;\n skipTrial?: boolean;\n name?: string;\n startDate?: string;\n successUrl?: string;\n};\n\nexport interface CancelParams {\n subscriptionId: string;\n reason?: string;\n immediate?: boolean;\n}\n\n/**\n * Subscription resource for managing subscriptions (plan-first model)\n *\n * Each customer can only have ONE active subscription at a time.\n */\nexport class SubscriptionsResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n /**\n * Create a subscription with a plan\n *\n * @example\n * ```typescript\n * await commet.subscriptions.create({\n * externalId: 'user_123',\n * planCode: 'pro', // autocomplete works after `commet pull`\n * billingInterval: 'yearly',\n * initialSeats: { editor: 5 }\n * });\n * ```\n */\n async create(\n params: CreateSubscriptionParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<CreatedSubscription>> {\n return this.httpClient.post(\"/subscriptions\", params, options);\n }\n\n /**\n * Get the active subscription for a customer\n *\n * @example\n * ```typescript\n * const sub = await commet.subscriptions.get('user_123');\n * ```\n */\n async get(\n customerId: string,\n ): Promise<ApiResponse<ActiveSubscription | null>> {\n return this.httpClient.get(\"/subscriptions/active\", { customerId });\n }\n\n /**\n * Cancel a subscription\n *\n * @example\n * ```typescript\n * await commet.subscriptions.cancel({\n * subscriptionId: 'sub_xxx',\n * reason: 'switched_to_competitor'\n * });\n * ```\n */\n async cancel(\n params: CancelParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<Subscription>> {\n return this.httpClient.post(\n `/subscriptions/${params.subscriptionId}/cancel`,\n params || {},\n options,\n );\n }\n}\n","import type {\n ApiResponse,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\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 feature: 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\ninterface TrackBaseParams {\n feature: GeneratedFeatureCode;\n customerId: CustomerID;\n idempotencyKey?: string;\n timestamp?: string;\n properties?: Record<string, string>;\n}\n\nexport interface TrackUsageParams extends TrackBaseParams {\n value?: number;\n model?: never;\n}\n\nexport interface TrackModelTokensParams extends TrackBaseParams {\n model: string;\n inputTokens: number;\n outputTokens: number;\n cacheReadTokens?: number;\n cacheWriteTokens?: number;\n value?: never;\n}\n\nexport type TrackParams = TrackUsageParams | TrackModelTokensParams;\n\nexport class UsageResource {\n constructor(private httpClient: CommetHTTPClient) {}\n\n async track(\n params: TrackParams,\n options?: RequestOptions,\n ): Promise<ApiResponse<UsageEvent>> {\n const eventData: Record<string, unknown> = {\n feature: params.feature,\n customerId: params.customerId,\n idempotencyKey: params.idempotencyKey,\n timestamp: params.timestamp || new Date().toISOString(),\n properties: params.properties\n ? Object.entries(params.properties).map(([property, value]) => ({\n property,\n value,\n }))\n : undefined,\n };\n\n if (\"model\" in params && params.model) {\n eventData.model = params.model;\n eventData.inputTokens = params.inputTokens;\n eventData.outputTokens = params.outputTokens;\n if (params.cacheReadTokens) {\n eventData.cacheReadTokens = params.cacheReadTokens;\n }\n if (params.cacheWriteTokens) {\n eventData.cacheWriteTokens = params.cacheWriteTokens;\n }\n } else {\n eventData.value = (params as TrackUsageParams).value;\n }\n\n return this.httpClient.post(\"/usage/events\", eventData, options);\n }\n}\n","import crypto from \"node:crypto\";\nimport type { SubscriptionStatus } from \"./subscriptions\";\n\n/**\n * Webhook payload structure from Commet\n */\nexport interface WebhookPayload {\n event: WebhookEvent;\n timestamp: string;\n organizationId: string;\n data: WebhookData;\n}\n\n/**\n * Webhook data structure (subscription-related fields).\n *\n * The `status` field is present on `subscription.*` events. Grant access only\n * when it is `\"active\"` or `\"trialing\"`. `\"pending_payment\"` means the first\n * charge has not been confirmed yet — wait for `subscription.activated` before\n * granting access.\n */\nexport interface WebhookData {\n id?: string;\n publicId?: string;\n subscriptionId?: string;\n customerId?: string;\n externalId?: string;\n /**\n * Subscription status. Present on `subscription.*` events.\n * Grant access when this is `\"active\"` or `\"trialing\"`.\n */\n status?: SubscriptionStatus;\n name?: string;\n canceledAt?: string;\n [key: string]: unknown;\n}\n\n/**\n * Supported webhook events\n */\nexport type WebhookEvent =\n | \"subscription.created\"\n | \"subscription.activated\"\n | \"subscription.canceled\"\n | \"subscription.updated\"\n | \"subscription.plan_changed\"\n | \"payment.received\"\n | \"payment.failed\"\n | \"invoice.created\";\n\nexport interface VerifyParams {\n payload: string;\n signature: string | null;\n secret: string;\n}\n\nexport interface GenerateSignatureParams {\n payload: string;\n secret: string;\n}\n\nexport interface VerifyAndParseParams {\n rawBody: string;\n signature: string | null;\n secret: string;\n}\n\n/**\n * Webhooks resource for signature verification\n */\nexport class Webhooks {\n /**\n * Verify HMAC-SHA256 webhook signature\n *\n * Use this method to verify that webhooks are authentically from Commet.\n * The signature is included in the `X-Commet-Signature` header.\n *\n * @param payload - Raw request body as string (IMPORTANT: Do not parse JSON first)\n * @param signature - Value from X-Commet-Signature header\n * @param secret - Your webhook secret from Commet dashboard\n * @returns true if signature is valid, false otherwise\n *\n * @example\n * ```typescript\n * // Next.js API route example\n * export async function POST(request: Request) {\n * const rawBody = await request.text();\n * const signature = request.headers.get('x-commet-signature');\n *\n * const isValid = commet.webhooks.verify(\n * rawBody,\n * signature,\n * process.env.COMMET_WEBHOOK_SECRET\n * );\n *\n * if (!isValid) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * const payload = JSON.parse(rawBody);\n * // Handle webhook event...\n * }\n * ```\n */\n verify(params: VerifyParams): boolean {\n const { payload, signature, secret } = params;\n\n if (!signature || !secret || !payload) {\n return false;\n }\n\n try {\n const expectedSignature = this.generateSignature({ payload, secret });\n\n // Use timing-safe comparison to prevent timing attacks\n return crypto.timingSafeEqual(\n Buffer.from(signature, \"hex\"),\n Buffer.from(expectedSignature, \"hex\"),\n );\n } catch (_error) {\n // timingSafeEqual throws if lengths don't match\n return false;\n }\n }\n\n /**\n * Generate HMAC-SHA256 signature (internal use)\n * @internal\n */\n private generateSignature(params: GenerateSignatureParams): string {\n const { payload, secret } = params;\n return crypto.createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n }\n\n /**\n * Parse and verify webhook payload in one step\n *\n * @example\n * ```typescript\n * const payload = commet.webhooks.verifyAndParse({\n * rawBody,\n * signature,\n * secret: process.env.COMMET_WEBHOOK_SECRET\n * });\n *\n * if (!payload) {\n * return new Response('Invalid signature', { status: 401 });\n * }\n *\n * // payload is typed and validated\n * if (payload.event === 'subscription.activated') {\n * // Handle activation...\n * }\n * ```\n */\n verifyAndParse(params: VerifyAndParseParams): WebhookPayload | null {\n const { rawBody, signature, secret } = params;\n\n if (!this.verify({ payload: rawBody, signature, secret })) {\n return null;\n }\n\n try {\n return JSON.parse(params.rawBody) as WebhookPayload;\n } catch {\n return null;\n }\n }\n}\n","export type CommetConfig = {\n apiKey: string;\n apiVersion?: string;\n debug?: boolean;\n timeout?: number;\n retries?: number;\n telemetry?: boolean;\n};\n\n// API Response types\nexport interface ApiResponse<T = unknown> {\n success: boolean;\n data?: T;\n code?: string;\n message?: string;\n details?: unknown;\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 = 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 apiVersion?: string;\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/types.d.ts file that augments this interface with your\n * organization's specific feature codes, seat types, and plan codes.\n *\n * @example\n * // After running `commet pull`, TypeScript will automatically know your types:\n * await commet.usage.track({\n * feature: 'api_calls', // Autocomplete works!\n * externalId: 'user_123'\n * });\n */\n\n// biome-ignore lint/suspicious/noEmptyInterface: augmented by CLI-generated .commet/types.d.ts\nexport interface CommetGeneratedTypes {}\n\nexport type GeneratedSeatType = CommetGeneratedTypes extends {\n seatType: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedPlanCode = CommetGeneratedTypes extends {\n planCode: infer T;\n}\n ? T\n : string;\n\nexport type GeneratedFeatureCode = CommetGeneratedTypes extends {\n featureCode: infer T;\n}\n ? T\n : string;\n","export const API_VERSION = \"2026-05-01\";\n\ndeclare const __SDK_VERSION__: string;\nexport const SDK_VERSION: string = __SDK_VERSION__;\n","import { SDK_VERSION } from \"../version\";\n\ninterface RequestMetrics {\n requestId: string;\n durationMs: number;\n}\n\ninterface ClientInfo {\n sdk: string;\n sdkVersion: string;\n lang: string;\n langVersion: string;\n platform: string;\n arch: string;\n runtime: string;\n runtimeVersion: string;\n}\n\nfunction detectRuntime(): { name: string; version: string } {\n const g = globalThis as Record<string, unknown>;\n const bun = g.Bun as { version: string } | undefined;\n if (bun) return { name: \"bun\", version: bun.version };\n const deno = g.Deno as { version: { deno: string } } | undefined;\n if (deno) return { name: \"deno\", version: deno.version.deno };\n return { name: \"node\", version: process.versions.node };\n}\n\nlet cachedClientInfo: string | null = null;\nlet cachedUserAgent: string | null = null;\n\nfunction collectClientInfo(): ClientInfo {\n const runtime = detectRuntime();\n return {\n sdk: \"commet-node\",\n sdkVersion: SDK_VERSION,\n lang: \"node\",\n langVersion: process.versions.node,\n platform: process.platform,\n arch: process.arch,\n runtime: runtime.name,\n runtimeVersion: runtime.version,\n };\n}\n\nexport function getClientInfoHeader(): string {\n if (!cachedClientInfo) {\n cachedClientInfo = JSON.stringify(collectClientInfo());\n }\n return cachedClientInfo;\n}\n\nexport function getUserAgent(): string {\n if (!cachedUserAgent) {\n const runtime = detectRuntime();\n cachedUserAgent = `commet-node/${SDK_VERSION} ${runtime.name}/${runtime.version} ${process.platform}/${process.arch}`;\n }\n return cachedUserAgent;\n}\n\nexport function formatRequestMetrics(metrics: RequestMetrics): string {\n return JSON.stringify({\n last_request_metrics: {\n request_id: metrics.requestId,\n duration_ms: metrics.durationMs,\n },\n });\n}\n","import type {\n ApiResponse,\n CommetConfig,\n RequestOptions,\n} from \"../types/common\";\nimport { CommetAPIError, CommetValidationError } from \"../types/common\";\nimport { API_VERSION } from \"../version\";\nimport {\n formatRequestMetrics,\n getClientInfoHeader,\n getUserAgent,\n} from \"./telemetry\";\n\nconst BASE_URL = \"https://commet.co\";\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 retryConfig: RetryConfig;\n private telemetryEnabled: boolean;\n private lastRequestMetrics: { requestId: string; durationMs: number } | null =\n null;\n\n constructor(config: CommetConfig) {\n this.config = config;\n this.telemetryEnabled = config.telemetry !== false;\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 private resolveApiVersion(options?: RequestOptions): string {\n return options?.apiVersion ?? this.config.apiVersion ?? API_VERSION;\n }\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 apiVersion = this.resolveApiVersion(options);\n\n const headers: Record<string, string> = {\n \"x-api-key\": this.config.apiKey,\n \"commet-version\": apiVersion,\n \"Content-Type\": \"application/json\",\n \"User-Agent\": getUserAgent(),\n };\n\n if (this.telemetryEnabled) {\n headers[\"commet-client-info\"] = getClientInfoHeader();\n if (this.lastRequestMetrics) {\n headers[\"commet-client-telemetry\"] = formatRequestMetrics(\n this.lastRequestMetrics,\n );\n this.lastRequestMetrics = null;\n }\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 requestStart = Date.now();\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 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\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 code?: string;\n details?: unknown;\n } => {\n return typeof data === \"object\" && data !== null;\n };\n\n const errorData = isErrorResponse(responseData) ? responseData : {};\n\n // Handle validation errors (new normalized shape)\n if (\n errorData.code === \"validation_error\" &&\n Array.isArray(errorData.details)\n ) {\n const errors: Record<string, string[]> = {};\n for (const detail of errorData.details as Array<{\n field: string;\n message: string;\n }>) {\n if (!errors[detail.field]) errors[detail.field] = [];\n errors[detail.field].push(detail.message);\n }\n throw new CommetValidationError(\n errorData.message || \"Validation failed\",\n 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 if (this.telemetryEnabled) {\n this.lastRequestMetrics = {\n requestId:\n response.headers.get(\"x-request-id\") ?? `req_${Date.now()}`,\n durationMs: Date.now() - requestStart,\n };\n }\n\n return responseData as ApiResponse<T>;\n } catch (error) {\n // Handle network errors and timeouts\n const isNetworkError =\n error instanceof TypeError && error.message.includes(\"fetch\");\n const isTimeoutError =\n error instanceof DOMException && error.name === \"AbortError\";\n const isTimeoutErrorModern =\n typeof globalThis.DOMException !== \"undefined\" &&\n error instanceof DOMException &&\n error.name === \"TimeoutError\";\n\n if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {\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 * Build full URL from endpoint and params\n */\n private buildURL(endpoint: string, params?: Record<string, unknown>): string {\n // Construct full path with /api prefix\n const normalizedEndpoint = endpoint.startsWith(\"/\")\n ? endpoint\n : `/${endpoint}`;\n const fullPath = `/api/v1${normalizedEndpoint}`;\n\n // Debug logging\n if (this.config.debug) {\n console.log(\n `[Commet SDK] Building URL - endpoint: ${endpoint}, fullPath: ${fullPath}`,\n );\n }\n\n const url = new URL(fullPath, BASE_URL);\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 { CustomerContext } from \"./customer\";\nimport { CreditPacksResource } from \"./resources/credit-packs\";\nimport { CustomersResource } from \"./resources/customers\";\nimport { FeaturesResource } from \"./resources/features\";\nimport { PlansResource } from \"./resources/plans\";\nimport { PortalResource } from \"./resources/portal\";\nimport { SeatsResource } from \"./resources/seats\";\nimport { SubscriptionsResource } from \"./resources/subscriptions\";\nimport { UsageResource } from \"./resources/usage\";\nimport { Webhooks } from \"./resources/webhooks\";\nimport type { CommetConfig } from \"./types/common\";\nimport { CommetHTTPClient } from \"./utils/http\";\n\n/**\n * Main Commet SDK client\n */\nexport class Commet {\n private httpClient: CommetHTTPClient;\n\n public readonly customers: CustomersResource;\n public readonly creditPacks: CreditPacksResource;\n public readonly plans: PlansResource;\n public readonly usage: UsageResource;\n public readonly seats: SeatsResource;\n public readonly subscriptions: SubscriptionsResource;\n public readonly portal: PortalResource;\n public readonly features: FeaturesResource;\n public readonly webhooks: Webhooks;\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 this.httpClient = new CommetHTTPClient(config);\n this.customers = new CustomersResource(this.httpClient);\n this.creditPacks = new CreditPacksResource(this.httpClient);\n this.plans = new PlansResource(this.httpClient);\n this.usage = new UsageResource(this.httpClient);\n this.seats = new SeatsResource(this.httpClient);\n this.subscriptions = new SubscriptionsResource(this.httpClient);\n this.portal = new PortalResource(this.httpClient);\n this.features = new FeaturesResource(this.httpClient);\n this.webhooks = new Webhooks();\n\n if (config.debug) {\n console.log(\"[Commet SDK] Initialized\");\n console.log(\"API Key:\", `${config.apiKey.substring(0, 12)}...`);\n }\n }\n\n /**\n * Create a customer-scoped context for cleaner API usage\n *\n * @example\n * ```typescript\n * const customer = commet.customer(\"user_123\");\n *\n * // All operations are now scoped to this customer\n * const seats = await customer.features.get(\"team_members\");\n * await customer.seats.add(\"member\");\n * await customer.usage.track(\"api_call\");\n * ```\n */\n customer(customerId: string): CustomerContext {\n return new CustomerContext(customerId, {\n features: this.features,\n seats: this.seats,\n usage: this.usage,\n subscriptions: this.subscriptions,\n portal: this.portal,\n });\n }\n}\n","/**\n * Commet SDK - Billing and usage tracking for SaaS\n */\nexport { Commet } from \"./client\";\nexport { CustomerContext } from \"./customer\";\n// Credit Packs\nexport type { CreditPack } from \"./resources/credit-packs\";\n// Customers\nexport type {\n BatchResult as CustomersBatchResult,\n CreateParams as CreateCustomerParams,\n Customer,\n CustomerAddress,\n ListCustomersParams,\n UpdateParams as UpdateCustomerParams,\n} from \"./resources/customers\";\n// Features\nexport type {\n CanUseFeatureParams,\n CanUseResult,\n CheckFeatureParams,\n CheckResult,\n FeatureAccess,\n GetFeatureParams,\n} from \"./resources/features\";\n// Plans\nexport type {\n BillingInterval,\n FeatureType,\n ListPlansParams,\n Plan,\n PlanDetail,\n PlanFeature,\n PlanID,\n PlanPrice,\n} from \"./resources/plans\";\n// Portal\nexport type { GetUrlParams, PortalAccess } from \"./resources/portal\";\n// Seats\nexport type {\n AddParams as AddSeatsParams,\n GetAllBalancesParams,\n GetBalanceParams,\n RemoveParams as RemoveSeatsParams,\n SeatBalance,\n SeatEvent,\n SetAllParams as SetAllSeatsParams,\n SetParams as SetSeatsParams,\n} from \"./resources/seats\";\n// Subscriptions\nexport type {\n ActiveSubscription,\n CancellationSummary,\n CancelParams,\n CreatedSubscription,\n CreateSubscriptionParams,\n DiscountSummary,\n FeatureSummary,\n Subscription,\n SubscriptionStatus,\n} from \"./resources/subscriptions\";\n// Usage\nexport type {\n TrackModelTokensParams,\n TrackParams,\n TrackUsageParams,\n UsageEvent,\n UsageEventProperty,\n} from \"./resources/usage\";\nexport type {\n WebhookData,\n WebhookEvent,\n WebhookPayload,\n} from \"./resources/webhooks\";\n// Webhooks\nexport { Webhooks } from \"./resources/webhooks\";\n// Type exports\nexport type {\n ApiResponse,\n CommetConfig,\n CommetGeneratedTypes,\n Currency,\n CustomerID,\n EventID,\n GeneratedFeatureCode,\n GeneratedPlanCode,\n GeneratedSeatType,\n PaginatedList,\n PaginatedResponse,\n RequestOptions,\n} from \"./types/common\";\n// Error exports\nexport {\n CommetAPIError,\n CommetError,\n CommetValidationError,\n} from \"./types/common\";\nexport { API_VERSION, SDK_VERSION } from \"./version\";\n\n// Default export\nimport { Commet } from \"./client\";\nexport default Commet;\n"],"mappings":";AAuBO,IAAM,kBAAN,MAAsB;AAAA,EAQ3B,YACE,YACA,WAOA;AASF,oBAAW;AAAA,MACT,KAAK,CAAC,MAAc,YAClB,KAAK,iBAAiB,IAAI,EAAE,MAAM,YAAY,KAAK,WAAW,GAAG,OAAO;AAAA,MAE1E,OAAO,CAAC,MAAc,YACpB,KAAK,iBAAiB;AAAA,QACpB,EAAE,MAAM,YAAY,KAAK,WAAW;AAAA,QACpC;AAAA,MACF;AAAA,MAEF,QAAQ,CAAC,MAAc,YACrB,KAAK,iBAAiB;AAAA,QACpB,EAAE,MAAM,YAAY,KAAK,WAAW;AAAA,QACpC;AAAA,MACF;AAAA,MAEF,MAAM,CAAC,YACL,KAAK,iBAAiB,KAAK,KAAK,YAAY,OAAO;AAAA,IACvD;AAEA,iBAAQ;AAAA,MACN,KAAK,CAAC,UAAkB,QAAQ,GAAG,YACjC,KAAK,cAAc;AAAA,QACjB,EAAE,YAAY,KAAK,YAAY,UAAU,MAAM;AAAA,QAC/C;AAAA,MACF;AAAA,MAEF,QAAQ,CAAC,UAAkB,QAAQ,GAAG,YACpC,KAAK,cAAc;AAAA,QACjB,EAAE,YAAY,KAAK,YAAY,UAAU,MAAM;AAAA,QAC/C;AAAA,MACF;AAAA,MAEF,KAAK,CAAC,UAAkB,OAAe,YACrC,KAAK,cAAc;AAAA,QACjB,EAAE,YAAY,KAAK,YAAY,UAAU,MAAM;AAAA,QAC/C;AAAA,MACF;AAAA,MAEF,YAAY,CAAC,aACX,KAAK,cAAc,WAAW,EAAE,YAAY,KAAK,YAAY,SAAS,CA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QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,QAAQ,IAAI,cAAc,KAAK,UAAU;AAC9C,SAAK,gBAAgB,IAAI,sBAAsB,KAAK,UAAU;AAC9D,SAAK,SAAS,IAAI,eAAe,KAAK,UAAU;AAChD,SAAK,WAAW,IAAI,iBAAiB,KAAK,UAAU;AACpD,SAAK,WAAW,IAAI,SAAS;AAE7B,QAAI,OAAO,OAAO;AAChB,cAAQ,IAAI,0BAA0B;AACtC,cAAQ,IAAI,YAAY,GAAG,OAAO,OAAO,UAAU,GAAG,EAAE,CAAC,KAAK;AAAA,IAChE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,SAAS,YAAqC;AAC5C,WAAO,IAAI,gBAAgB,YAAY;AAAA,MACrC,UAAU,KAAK;AAAA,MACf,OAAO,KAAK;AAAA,MACZ,OAAO,KAAK;AAAA,MACZ,eAAe,KAAK;AAAA,MACpB,QAAQ,KAAK;AAAA,IACf,CAAC;AAAA,EACH;AACF;;;ACsBA,IAAO,gBAAQ;","names":["data"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commet/node",
3
- "version": "2.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "Commet SDK for Node.js - Billing and usage tracking",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",