@claritylabs/cl-sdk 3.1.17 → 3.1.19

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.
@@ -111,17 +111,19 @@ function isRetryableError(error) {
111
111
  }
112
112
  return false;
113
113
  }
114
- async function withRetry(fn, log) {
114
+ async function withRetry(fn, log, options) {
115
+ const maxRetries = options?.maxRetries ?? MAX_RETRIES;
116
+ const baseDelayMs = options?.baseDelayMs ?? BASE_DELAY_MS;
115
117
  for (let attempt = 0; ; attempt++) {
116
118
  try {
117
119
  return await fn();
118
120
  } catch (error) {
119
- if (!isRetryableError(error) || attempt >= MAX_RETRIES) {
121
+ if (!isRetryableError(error) || attempt >= maxRetries) {
120
122
  throw error;
121
123
  }
122
124
  const jitter = Math.random() * 1e3;
123
- const delay = BASE_DELAY_MS * Math.pow(2, attempt) + jitter;
124
- await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
125
+ const delay = baseDelayMs * Math.pow(2, attempt) + jitter;
126
+ await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${maxRetries})...`);
125
127
  await new Promise((resolve) => setTimeout(resolve, delay));
126
128
  }
127
129
  }