@thecorporation/corp-tools 26.3.49 → 26.3.51

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
@@ -309,6 +309,20 @@ var CorpAPIClient = class {
309
309
  const url = `${this.apiUrl}${fullPath}`;
310
310
  const opts = { method, headers: this.headers() };
311
311
  if (body !== void 0) opts.body = JSON.stringify(body);
312
+ const MAX_RETRIES = 3;
313
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
314
+ const resp = await fetch(url, opts);
315
+ if (resp.status !== 429 || attempt === MAX_RETRIES) return resp;
316
+ const retryAfter = resp.headers.get("retry-after");
317
+ let waitMs;
318
+ if (retryAfter) {
319
+ const secs = parseInt(retryAfter, 10);
320
+ waitMs = Number.isFinite(secs) ? secs * 1e3 : (attempt + 1) * 2e3;
321
+ } else {
322
+ waitMs = Math.min((attempt + 1) * 2e3, 1e4);
323
+ }
324
+ await new Promise((resolve2) => setTimeout(resolve2, waitMs));
325
+ }
312
326
  return fetch(url, opts);
313
327
  }
314
328
  async throwIfError(resp) {