@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/browser.js CHANGED
@@ -289,6 +289,20 @@ var CorpAPIClient = class {
289
289
  const url = `${this.apiUrl}${fullPath}`;
290
290
  const opts = { method, headers: this.headers() };
291
291
  if (body !== void 0) opts.body = JSON.stringify(body);
292
+ const MAX_RETRIES = 3;
293
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
294
+ const resp = await fetch(url, opts);
295
+ if (resp.status !== 429 || attempt === MAX_RETRIES) return resp;
296
+ const retryAfter = resp.headers.get("retry-after");
297
+ let waitMs;
298
+ if (retryAfter) {
299
+ const secs = parseInt(retryAfter, 10);
300
+ waitMs = Number.isFinite(secs) ? secs * 1e3 : (attempt + 1) * 2e3;
301
+ } else {
302
+ waitMs = Math.min((attempt + 1) * 2e3, 1e4);
303
+ }
304
+ await new Promise((resolve2) => setTimeout(resolve2, waitMs));
305
+ }
292
306
  return fetch(url, opts);
293
307
  }
294
308
  async throwIfError(resp) {