@commet/node 6.0.0 → 7.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.mjs CHANGED
@@ -5,7 +5,7 @@ var AddonsResource = class {
5
5
  }
6
6
  /** List all active add-ons for a customer's subscription. */
7
7
  async listActive(params, options) {
8
- return this.httpClient.get("/addons/active", params, options);
8
+ return this.httpClient.get("/active-addons", params, options);
9
9
  }
10
10
  /** List all add-ons with cursor-based pagination. */
11
11
  async list(params, options) {
@@ -106,29 +106,45 @@ var CustomersResource = class {
106
106
  }
107
107
  };
108
108
 
109
- // src/resources/features.ts
110
- var FeaturesResource = class {
109
+ // src/resources/feature-access.ts
110
+ var FeatureAccessResource = class {
111
111
  constructor(httpClient) {
112
112
  this.httpClient = httpClient;
113
113
  }
114
- /** List all features for a customer's active subscription. */
114
+ /** List all features for a customer's active subscription, scoped by the customerId query parameter. */
115
115
  async list(params, options) {
116
- return this.httpClient.get("/features", params, options);
116
+ return this.httpClient.get("/feature-access", params, options);
117
117
  }
118
- /** Get feature access details. Use action=canUse to check if customer can consume one more unit. */
118
+ /** Get feature access details for a customer. Use action=canUse to check if the customer can consume one more unit. */
119
119
  async get(params, options) {
120
120
  const { code, ...rest } = params;
121
- return this.httpClient.get(`/features/${code}`, rest, options);
121
+ return this.httpClient.get(`/feature-access/${code}`, rest, options);
122
122
  }
123
- /** Get feature access details. Use action=canUse to check if customer can consume one more unit. */
123
+ /** Get feature access details for a customer. Use action=canUse to check if the customer can consume one more unit. */
124
124
  async canUse(params, options) {
125
125
  const { code, ...rest } = params;
126
126
  return this.httpClient.get(
127
- `/features/${code}`,
127
+ `/feature-access/${code}`,
128
128
  { ...rest, action: "canUse" },
129
129
  options
130
130
  );
131
131
  }
132
+ };
133
+
134
+ // src/resources/features.ts
135
+ var FeaturesResource = class {
136
+ constructor(httpClient) {
137
+ this.httpClient = httpClient;
138
+ }
139
+ /** List every feature defined in the organization. This is the organization's feature catalog (definitions), not a customer's feature access. */
140
+ async list() {
141
+ return this.httpClient.get("/features");
142
+ }
143
+ /** Get a single feature definition by code from the organization's feature catalog. */
144
+ async get(params, options) {
145
+ const { code } = params;
146
+ return this.httpClient.get(`/features/${code}`, void 0, options);
147
+ }
132
148
  /** Create a new feature. Code must be lowercase alphanumeric with underscores. */
133
149
  async create(params, options) {
134
150
  return this.httpClient.post("/features/manage", params, options);
@@ -600,6 +616,7 @@ var GeneratedResources = class {
600
616
  this.apiKeys = new ApiKeysResource(http);
601
617
  this.creditPacks = new CreditPacksResource(http);
602
618
  this.customers = new CustomersResource(http);
619
+ this.featureAccess = new FeatureAccessResource(http);
603
620
  this.features = new FeaturesResource(http);
604
621
  this.invoices = new InvoicesResource(http);
605
622
  this.payouts = new PayoutsResource(http);
@@ -746,8 +763,8 @@ var CommetValidationError = class extends CommetError {
746
763
  };
747
764
 
748
765
  // src/version.ts
749
- var API_VERSION = "2026-06-07";
750
- var SDK_VERSION = "6.0.0";
766
+ var API_VERSION = "2026-06-10";
767
+ var SDK_VERSION = "7.1.0";
751
768
 
752
769
  // src/utils/telemetry.ts
753
770
  var registeredIntegrations = /* @__PURE__ */ new Set();
@@ -831,6 +848,7 @@ var DEFAULT_RETRY_CONFIG = {
831
848
  // 8s
832
849
  retryableStatusCodes: [408, 429, 500, 502, 503, 504]
833
850
  };
851
+ var RETRY_AFTER_CAP_MS = 3e4;
834
852
  var _CommetHTTPClient = class _CommetHTTPClient {
835
853
  constructor(config) {
836
854
  this.lastRequestMetrics = null;
@@ -942,17 +960,16 @@ var _CommetHTTPClient = class _CommetHTTPClient {
942
960
  }
943
961
  if (!response.ok) {
944
962
  if (attempt <= this.retryConfig.maxRetries && this.retryConfig.retryableStatusCodes.includes(response.status)) {
945
- const delay = Math.min(
946
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
947
- this.retryConfig.maxDelay
948
- );
949
- if (this.config.debug) {
950
- console.log(
951
- `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
952
- );
963
+ const delay = this.retryDelayMs(attempt, response);
964
+ if (delay !== null) {
965
+ if (this.config.debug) {
966
+ console.log(
967
+ `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
968
+ );
969
+ }
970
+ await this.sleep(delay);
971
+ return this.executeRequest(method, url, data, options, attempt + 1);
953
972
  }
954
- await this.sleep(delay);
955
- return this.executeRequest(method, url, data, options, attempt + 1);
956
973
  }
957
974
  if (this.config.debug) {
958
975
  console.log(
@@ -1002,10 +1019,7 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1002
1019
  const isTimeoutErrorModern = typeof globalThis.DOMException !== "undefined" && error instanceof DOMException && error.name === "TimeoutError";
1003
1020
  if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {
1004
1021
  if (attempt <= this.retryConfig.maxRetries) {
1005
- const delay = Math.min(
1006
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
1007
- this.retryConfig.maxDelay
1008
- );
1022
+ const delay = this.backoffDelayMs(attempt);
1009
1023
  if (this.config.debug) {
1010
1024
  console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);
1011
1025
  }
@@ -1041,6 +1055,26 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1041
1055
  }
1042
1056
  return finalUrl;
1043
1057
  }
1058
+ // 429 retries wait exactly what the rate limiter reports in Retry-After
1059
+ // (seconds until the window resets); a 429 without the header did not come
1060
+ // from the rate limiter, so it is not retried (returns null). Exponential
1061
+ // backoff only applies to statuses that carry no server-provided wait.
1062
+ retryDelayMs(attempt, response) {
1063
+ if (response.status === 429) {
1064
+ const retryAfterSeconds = Number(response.headers.get("retry-after"));
1065
+ if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0) {
1066
+ return Math.min(retryAfterSeconds * 1e3, RETRY_AFTER_CAP_MS);
1067
+ }
1068
+ return null;
1069
+ }
1070
+ return this.backoffDelayMs(attempt);
1071
+ }
1072
+ backoffDelayMs(attempt) {
1073
+ return Math.min(
1074
+ this.retryConfig.baseDelay * 2 ** (attempt - 1),
1075
+ this.retryConfig.maxDelay
1076
+ );
1077
+ }
1044
1078
  generateIdempotencyKey() {
1045
1079
  return `commet-node-retry-${crypto.randomUUID()}`;
1046
1080
  }