@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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +32 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -764,7 +764,7 @@ var CommetValidationError = class extends CommetError {
|
|
|
764
764
|
|
|
765
765
|
// src/version.ts
|
|
766
766
|
var API_VERSION = "2026-06-10";
|
|
767
|
-
var SDK_VERSION = "7.
|
|
767
|
+
var SDK_VERSION = "7.1.0";
|
|
768
768
|
|
|
769
769
|
// src/utils/telemetry.ts
|
|
770
770
|
var registeredIntegrations = /* @__PURE__ */ new Set();
|
|
@@ -848,6 +848,7 @@ var DEFAULT_RETRY_CONFIG = {
|
|
|
848
848
|
// 8s
|
|
849
849
|
retryableStatusCodes: [408, 429, 500, 502, 503, 504]
|
|
850
850
|
};
|
|
851
|
+
var RETRY_AFTER_CAP_MS = 3e4;
|
|
851
852
|
var _CommetHTTPClient = class _CommetHTTPClient {
|
|
852
853
|
constructor(config) {
|
|
853
854
|
this.lastRequestMetrics = null;
|
|
@@ -959,17 +960,16 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
959
960
|
}
|
|
960
961
|
if (!response.ok) {
|
|
961
962
|
if (attempt <= this.retryConfig.maxRetries && this.retryConfig.retryableStatusCodes.includes(response.status)) {
|
|
962
|
-
const delay =
|
|
963
|
-
|
|
964
|
-
this.
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
);
|
|
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);
|
|
970
972
|
}
|
|
971
|
-
await this.sleep(delay);
|
|
972
|
-
return this.executeRequest(method, url, data, options, attempt + 1);
|
|
973
973
|
}
|
|
974
974
|
if (this.config.debug) {
|
|
975
975
|
console.log(
|
|
@@ -1019,10 +1019,7 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
1019
1019
|
const isTimeoutErrorModern = typeof globalThis.DOMException !== "undefined" && error instanceof DOMException && error.name === "TimeoutError";
|
|
1020
1020
|
if (isNetworkError || isTimeoutError || isTimeoutErrorModern) {
|
|
1021
1021
|
if (attempt <= this.retryConfig.maxRetries) {
|
|
1022
|
-
const delay =
|
|
1023
|
-
this.retryConfig.baseDelay * 2 ** (attempt - 1),
|
|
1024
|
-
this.retryConfig.maxDelay
|
|
1025
|
-
);
|
|
1022
|
+
const delay = this.backoffDelayMs(attempt);
|
|
1026
1023
|
if (this.config.debug) {
|
|
1027
1024
|
console.log(`[Commet SDK] Network error, retrying in ${delay}ms`);
|
|
1028
1025
|
}
|
|
@@ -1058,6 +1055,26 @@ var _CommetHTTPClient = class _CommetHTTPClient {
|
|
|
1058
1055
|
}
|
|
1059
1056
|
return finalUrl;
|
|
1060
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
|
+
}
|
|
1061
1078
|
generateIdempotencyKey() {
|
|
1062
1079
|
return `commet-node-retry-${crypto.randomUUID()}`;
|
|
1063
1080
|
}
|