@commet/node 7.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.d.mts CHANGED
@@ -957,6 +957,8 @@ declare class CommetHTTPClient {
957
957
  * Build full URL from endpoint and params
958
958
  */
959
959
  private buildURL;
960
+ private retryDelayMs;
961
+ private backoffDelayMs;
960
962
  private generateIdempotencyKey;
961
963
  /**
962
964
  * Sleep for specified milliseconds
package/dist/index.d.ts CHANGED
@@ -957,6 +957,8 @@ declare class CommetHTTPClient {
957
957
  * Build full URL from endpoint and params
958
958
  */
959
959
  private buildURL;
960
+ private retryDelayMs;
961
+ private backoffDelayMs;
960
962
  private generateIdempotencyKey;
961
963
  /**
962
964
  * Sleep for specified milliseconds
package/dist/index.js CHANGED
@@ -810,7 +810,7 @@ var CommetValidationError = class extends CommetError {
810
810
 
811
811
  // src/version.ts
812
812
  var API_VERSION = "2026-06-10";
813
- var SDK_VERSION = "7.0.0";
813
+ var SDK_VERSION = "7.1.0";
814
814
 
815
815
  // src/utils/telemetry.ts
816
816
  var registeredIntegrations = /* @__PURE__ */ new Set();
@@ -894,6 +894,7 @@ var DEFAULT_RETRY_CONFIG = {
894
894
  // 8s
895
895
  retryableStatusCodes: [408, 429, 500, 502, 503, 504]
896
896
  };
897
+ var RETRY_AFTER_CAP_MS = 3e4;
897
898
  var _CommetHTTPClient = class _CommetHTTPClient {
898
899
  constructor(config) {
899
900
  this.lastRequestMetrics = null;
@@ -1005,17 +1006,16 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1005
1006
  }
1006
1007
  if (!response.ok) {
1007
1008
  if (attempt <= this.retryConfig.maxRetries && this.retryConfig.retryableStatusCodes.includes(response.status)) {
1008
- const delay = Math.min(
1009
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
1010
- this.retryConfig.maxDelay
1011
- );
1012
- if (this.config.debug) {
1013
- console.log(
1014
- `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
1015
- );
1009
+ const delay = this.retryDelayMs(attempt, response);
1010
+ if (delay !== null) {
1011
+ if (this.config.debug) {
1012
+ console.log(
1013
+ `[Commet SDK] Retrying in ${delay}ms (attempt ${attempt}/${this.retryConfig.maxRetries})`
1014
+ );
1015
+ }
1016
+ await this.sleep(delay);
1017
+ return this.executeRequest(method, url, data, options, attempt + 1);
1016
1018
  }
1017
- await this.sleep(delay);
1018
- return this.executeRequest(method, url, data, options, attempt + 1);
1019
1019
  }
1020
1020
  if (this.config.debug) {
1021
1021
  console.log(
@@ -1065,10 +1065,7 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1065
1065
  const isTimeoutErrorModern = typeof globalThis.DOMException !== "undefined" && error instanceof DOMException && error.name === "TimeoutError";
1066
1066
  if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {
1067
1067
  if (attempt <= this.retryConfig.maxRetries) {
1068
- const delay = Math.min(
1069
- this.retryConfig.baseDelay * 2 ** (attempt - 1),
1070
- this.retryConfig.maxDelay
1071
- );
1068
+ const delay = this.backoffDelayMs(attempt);
1072
1069
  if (this.config.debug) {
1073
1070
  console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);
1074
1071
  }
@@ -1104,6 +1101,26 @@ var _CommetHTTPClient = class _CommetHTTPClient {
1104
1101
  }
1105
1102
  return finalUrl;
1106
1103
  }
1104
+ // 429 retries wait exactly what the rate limiter reports in Retry-After
1105
+ // (seconds until the window resets); a 429 without the header did not come
1106
+ // from the rate limiter, so it is not retried (returns null). Exponential
1107
+ // backoff only applies to statuses that carry no server-provided wait.
1108
+ retryDelayMs(attempt, response) {
1109
+ if (response.status === 429) {
1110
+ const retryAfterSeconds = Number(response.headers.get("retry-after"));
1111
+ if (Number.isFinite(retryAfterSeconds) && retryAfterSeconds > 0) {
1112
+ return Math.min(retryAfterSeconds * 1e3, RETRY_AFTER_CAP_MS);
1113
+ }
1114
+ return null;
1115
+ }
1116
+ return this.backoffDelayMs(attempt);
1117
+ }
1118
+ backoffDelayMs(attempt) {
1119
+ return Math.min(
1120
+ this.retryConfig.baseDelay * 2 ** (attempt - 1),
1121
+ this.retryConfig.maxDelay
1122
+ );
1123
+ }
1107
1124
  generateIdempotencyKey() {
1108
1125
  return `commet-node-retry-${crypto.randomUUID()}`;
1109
1126
  }