notte-sdk 1.10.19 → 1.10.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -252,7 +252,7 @@ __export(index_exports, {
252
252
  module.exports = __toCommonJS(index_exports);
253
253
 
254
254
  // src/version.ts
255
- var SDK_VERSION = true ? "1.10.19" : "dev";
255
+ var SDK_VERSION = true ? "1.10.21" : "dev";
256
256
  var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
257
257
 
258
258
  // src/version-check.ts
@@ -3512,6 +3512,7 @@ var RETRY_AFTER_MAX_MS = 2e4;
3512
3512
  var IDEMPOTENT_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS", "PUT", "DELETE"]);
3513
3513
  var REFUSED_STATUSES = /* @__PURE__ */ new Set([503, 529]);
3514
3514
  var GATEWAY_STATUSES = /* @__PURE__ */ new Set([502, 504]);
3515
+ var WORKER_TIMEOUT_ERROR_CLASS = "WorkerRequestTimeout";
3515
3516
  var NOT_SENT_ERROR_CODES = /* @__PURE__ */ new Set([
3516
3517
  "ECONNREFUSED",
3517
3518
  "EAI_AGAIN",
@@ -3529,7 +3530,8 @@ var BROKEN_CONNECTION_ERROR_CODES = /* @__PURE__ */ new Set([
3529
3530
  function isIdempotentMethod(method) {
3530
3531
  return IDEMPOTENT_METHODS.has(method.toUpperCase());
3531
3532
  }
3532
- function isRetryableStatus(status, method) {
3533
+ function isRetryableStatus(status, method, errorClass) {
3534
+ if (status === 529 && errorClass === WORKER_TIMEOUT_ERROR_CLASS) return isIdempotentMethod(method);
3533
3535
  return REFUSED_STATUSES.has(status) || GATEWAY_STATUSES.has(status) && isIdempotentMethod(method);
3534
3536
  }
3535
3537
  function isRetryableNetworkError(error, method) {
@@ -3581,7 +3583,7 @@ function createRetryingFetch(options) {
3581
3583
  await wait2(delay4, signal);
3582
3584
  continue;
3583
3585
  }
3584
- if (last || !isRetryableStatus(response.status, method)) return response;
3586
+ if (last || !isRetryableStatus(response.status, method, response.headers.get("x-error-class"))) return response;
3585
3587
  const delay3 = retryDelayMs(attempt, response.headers.get("retry-after"), options.random);
3586
3588
  if (delay3 === void 0 || !fitsDeadline(delay3)) return response;
3587
3589
  await response.body?.cancel().catch(() => void 0);
@@ -3761,7 +3763,9 @@ var Session = class {
3761
3763
  * (`NotteClientConfig.maxRetries`, honoring `Retry-After`). Other 5xx
3762
3764
  * errors are retried up to `SESSION_START_TRIES` times. With client
3763
3765
  * retries disabled, 529 waits `CLUSTER_OVERLOAD_RETRY_DELAY_MS` instead.
3764
- * 4xx errors are never retried.
3766
+ * 4xx errors are never retried, nor is a 529 marked
3767
+ * `X-Error-Class: WorkerRequestTimeout`: an API worker did not answer in
3768
+ * time and may already have created the session.
3765
3769
  *
3766
3770
  * Managed-auth sessions wait for readiness by default. Pass
3767
3771
  * `{ wait_for_authentication: false }` for an explicit nonblocking start,
@@ -3816,7 +3820,11 @@ var Session = class {
3816
3820
  sessionData = response.data;
3817
3821
  break;
3818
3822
  } catch (error) {
3819
- const transient = error instanceof NotteAPIError ? isRetryableStatus(error.statusCode, "POST") : isRetryableNetworkError(error, "POST");
3823
+ const errorClass = error instanceof NotteAPIError ? error.response?.headers.get("x-error-class") : void 0;
3824
+ if (error instanceof NotteAPIError && error.statusCode === 529 && errorClass === WORKER_TIMEOUT_ERROR_CLASS) {
3825
+ throw error;
3826
+ }
3827
+ const transient = error instanceof NotteAPIError ? isRetryableStatus(error.statusCode, "POST", errorClass) : isRetryableNetworkError(error, "POST");
3820
3828
  if (maxRetries > 0 && transient) {
3821
3829
  const wait2 = transientRetries >= maxRetries ? void 0 : error instanceof NotteAPIError ? retryDelayMs(transientRetries, error.response?.headers.get("retry-after")) : backoffDelayMs(transientRetries);
3822
3830
  if (wait2 === void 0 || !fitsDeadline(wait2)) throw error;