@discordjs/rest 3.0.0-dev.1757160090-352c9819b → 3.0.0-dev.1757505703-f1bcff46b

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/web.mjs CHANGED
@@ -18,7 +18,7 @@ import { CDNRoutes } from "discord-api-types/v10";
18
18
  // src/lib/utils/constants.ts
19
19
  import { getUserAgentAppendix } from "@discordjs/util";
20
20
  import { APIVersion } from "discord-api-types/v10";
21
- var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1757160090-352c9819b)`;
21
+ var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1757505703-f1bcff46b)`;
22
22
  var DefaultUserAgentAppendix = getUserAgentAppendix();
23
23
  var DefaultRestOptions = {
24
24
  agent: null,
@@ -31,6 +31,7 @@ var DefaultRestOptions = {
31
31
  offset: 50,
32
32
  rejectOnRateLimit: null,
33
33
  retries: 3,
34
+ retryBackoff: 0,
34
35
  timeout: 15e3,
35
36
  userAgentAppendix: DefaultUserAgentAppendix,
36
37
  version: APIVersion,
@@ -560,6 +561,21 @@ function normalizeRateLimitOffset(offset, route) {
560
561
  return Math.max(0, result);
561
562
  }
562
563
  __name(normalizeRateLimitOffset, "normalizeRateLimitOffset");
564
+ function normalizeRetryBackoff(retryBackoff, route, statusCode, retryCount, requestBody) {
565
+ if (typeof retryBackoff === "number") {
566
+ return Math.max(0, retryBackoff) * (1 << retryCount);
567
+ }
568
+ return retryBackoff(route, statusCode, retryCount, requestBody);
569
+ }
570
+ __name(normalizeRetryBackoff, "normalizeRetryBackoff");
571
+ function normalizeTimeout(timeout, route, requestBody) {
572
+ if (typeof timeout === "number") {
573
+ return Math.max(0, timeout);
574
+ }
575
+ const result = timeout(route, requestBody);
576
+ return Math.max(0, result);
577
+ }
578
+ __name(normalizeTimeout, "normalizeTimeout");
563
579
 
564
580
  // src/lib/handlers/Shared.ts
565
581
  var authFalseWarningEmitted = false;
@@ -582,7 +598,10 @@ function incrementInvalidCount(manager) {
582
598
  __name(incrementInvalidCount, "incrementInvalidCount");
583
599
  async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) {
584
600
  const controller = new AbortController();
585
- const timeout = setTimeout(() => controller.abort(), manager.options.timeout);
601
+ const timeout = setTimeout(
602
+ () => controller.abort(),
603
+ normalizeTimeout(manager.options.timeout, routeId.bucketRoute, requestData.body)
604
+ );
586
605
  if (requestData.signal) {
587
606
  if (requestData.signal.aborted) controller.abort();
588
607
  else requestData.signal.addEventListener("abort", () => controller.abort());
@@ -593,6 +612,19 @@ async function makeNetworkRequest(manager, routeId, url, options, requestData, r
593
612
  } catch (error) {
594
613
  if (!(error instanceof Error)) throw error;
595
614
  if (shouldRetry(error) && retries !== manager.options.retries) {
615
+ const backoff = normalizeRetryBackoff(
616
+ manager.options.retryBackoff,
617
+ routeId.bucketRoute,
618
+ null,
619
+ retries,
620
+ requestData.body
621
+ );
622
+ if (backoff === null) {
623
+ throw error;
624
+ }
625
+ if (backoff > 0) {
626
+ await sleep(backoff);
627
+ }
596
628
  return null;
597
629
  }
598
630
  throw error;
@@ -616,10 +648,23 @@ async function makeNetworkRequest(manager, routeId, url, options, requestData, r
616
648
  return res;
617
649
  }
618
650
  __name(makeNetworkRequest, "makeNetworkRequest");
619
- async function handleErrors(manager, res, method, url, requestData, retries) {
651
+ async function handleErrors(manager, res, method, url, requestData, retries, routeId) {
620
652
  const status = res.status;
621
653
  if (status >= 500 && status < 600) {
622
654
  if (retries !== manager.options.retries) {
655
+ const backoff = normalizeRetryBackoff(
656
+ manager.options.retryBackoff,
657
+ routeId.bucketRoute,
658
+ status,
659
+ retries,
660
+ requestData.body
661
+ );
662
+ if (backoff === null) {
663
+ throw new HTTPError(status, res.statusText, method, url, requestData);
664
+ }
665
+ if (backoff > 0) {
666
+ await sleep(backoff);
667
+ }
623
668
  return null;
624
669
  }
625
670
  throw new HTTPError(status, res.statusText, method, url, requestData);
@@ -743,7 +788,7 @@ var BurstHandler = class {
743
788
  await sleep(retryAfter);
744
789
  return this.runRequest(routeId, url, options, requestData, retries);
745
790
  } else {
746
- const handled = await handleErrors(this.manager, res, method, url, requestData, retries);
791
+ const handled = await handleErrors(this.manager, res, method, url, requestData, retries, routeId);
747
792
  if (handled === null) {
748
793
  return this.runRequest(routeId, url, options, requestData, ++retries);
749
794
  }
@@ -1045,7 +1090,7 @@ var SequentialHandler = class {
1045
1090
  }
1046
1091
  return this.runRequest(routeId, url, options, requestData, retries);
1047
1092
  } else {
1048
- const handled = await handleErrors(this.manager, res, method, url, requestData, retries);
1093
+ const handled = await handleErrors(this.manager, res, method, url, requestData, retries, routeId);
1049
1094
  if (handled === null) {
1050
1095
  return this.runRequest(routeId, url, options, requestData, ++retries);
1051
1096
  }
@@ -1374,7 +1419,7 @@ var REST = class _REST extends AsyncEventEmitter {
1374
1419
  };
1375
1420
 
1376
1421
  // src/shared.ts
1377
- var version = "3.0.0-dev.1757160090-352c9819b";
1422
+ var version = "3.0.0-dev.1757505703-f1bcff46b";
1378
1423
 
1379
1424
  // src/web.ts
1380
1425
  setDefaultStrategy(fetch);