@claritylabs/cl-sdk 3.1.18 → 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.
@@ -178,17 +178,19 @@ function isRetryableError(error) {
178
178
  }
179
179
  return false;
180
180
  }
181
- async function withRetry(fn, log) {
181
+ async function withRetry(fn, log, options) {
182
+ const maxRetries = options?.maxRetries ?? MAX_RETRIES;
183
+ const baseDelayMs = options?.baseDelayMs ?? BASE_DELAY_MS;
182
184
  for (let attempt = 0; ; attempt++) {
183
185
  try {
184
186
  return await fn();
185
187
  } catch (error) {
186
- if (!isRetryableError(error) || attempt >= MAX_RETRIES) {
188
+ if (!isRetryableError(error) || attempt >= maxRetries) {
187
189
  throw error;
188
190
  }
189
191
  const jitter = Math.random() * 1e3;
190
- const delay = BASE_DELAY_MS * Math.pow(2, attempt) + jitter;
191
- await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${MAX_RETRIES})...`);
192
+ const delay = baseDelayMs * Math.pow(2, attempt) + jitter;
193
+ await log?.(`Retryable error, retrying in ${(delay / 1e3).toFixed(1)}s (attempt ${attempt + 1}/${maxRetries})...`);
192
194
  await new Promise((resolve) => setTimeout(resolve, delay));
193
195
  }
194
196
  }