@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/index.mjs CHANGED
@@ -98,7 +98,7 @@ import { CDNRoutes } from "discord-api-types/v10";
98
98
  // src/lib/utils/constants.ts
99
99
  import { getUserAgentAppendix } from "@discordjs/util";
100
100
  import { APIVersion } from "discord-api-types/v10";
101
- var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1757160090-352c9819b)`;
101
+ var DefaultUserAgent = `DiscordBot (https://discord.js.org, 3.0.0-dev.1757505703-f1bcff46b)`;
102
102
  var DefaultUserAgentAppendix = getUserAgentAppendix();
103
103
  var DefaultRestOptions = {
104
104
  agent: null,
@@ -111,6 +111,7 @@ var DefaultRestOptions = {
111
111
  offset: 50,
112
112
  rejectOnRateLimit: null,
113
113
  retries: 3,
114
+ retryBackoff: 0,
114
115
  timeout: 15e3,
115
116
  userAgentAppendix: DefaultUserAgentAppendix,
116
117
  version: APIVersion,
@@ -640,6 +641,21 @@ function normalizeRateLimitOffset(offset, route) {
640
641
  return Math.max(0, result);
641
642
  }
642
643
  __name(normalizeRateLimitOffset, "normalizeRateLimitOffset");
644
+ function normalizeRetryBackoff(retryBackoff, route, statusCode, retryCount, requestBody) {
645
+ if (typeof retryBackoff === "number") {
646
+ return Math.max(0, retryBackoff) * (1 << retryCount);
647
+ }
648
+ return retryBackoff(route, statusCode, retryCount, requestBody);
649
+ }
650
+ __name(normalizeRetryBackoff, "normalizeRetryBackoff");
651
+ function normalizeTimeout(timeout, route, requestBody) {
652
+ if (typeof timeout === "number") {
653
+ return Math.max(0, timeout);
654
+ }
655
+ const result = timeout(route, requestBody);
656
+ return Math.max(0, result);
657
+ }
658
+ __name(normalizeTimeout, "normalizeTimeout");
643
659
 
644
660
  // src/lib/handlers/Shared.ts
645
661
  var authFalseWarningEmitted = false;
@@ -662,7 +678,10 @@ function incrementInvalidCount(manager) {
662
678
  __name(incrementInvalidCount, "incrementInvalidCount");
663
679
  async function makeNetworkRequest(manager, routeId, url, options, requestData, retries) {
664
680
  const controller = new AbortController();
665
- const timeout = setTimeout(() => controller.abort(), manager.options.timeout);
681
+ const timeout = setTimeout(
682
+ () => controller.abort(),
683
+ normalizeTimeout(manager.options.timeout, routeId.bucketRoute, requestData.body)
684
+ );
666
685
  if (requestData.signal) {
667
686
  if (requestData.signal.aborted) controller.abort();
668
687
  else requestData.signal.addEventListener("abort", () => controller.abort());
@@ -673,6 +692,19 @@ async function makeNetworkRequest(manager, routeId, url, options, requestData, r
673
692
  } catch (error) {
674
693
  if (!(error instanceof Error)) throw error;
675
694
  if (shouldRetry(error) && retries !== manager.options.retries) {
695
+ const backoff = normalizeRetryBackoff(
696
+ manager.options.retryBackoff,
697
+ routeId.bucketRoute,
698
+ null,
699
+ retries,
700
+ requestData.body
701
+ );
702
+ if (backoff === null) {
703
+ throw error;
704
+ }
705
+ if (backoff > 0) {
706
+ await sleep(backoff);
707
+ }
676
708
  return null;
677
709
  }
678
710
  throw error;
@@ -696,10 +728,23 @@ async function makeNetworkRequest(manager, routeId, url, options, requestData, r
696
728
  return res;
697
729
  }
698
730
  __name(makeNetworkRequest, "makeNetworkRequest");
699
- async function handleErrors(manager, res, method, url, requestData, retries) {
731
+ async function handleErrors(manager, res, method, url, requestData, retries, routeId) {
700
732
  const status = res.status;
701
733
  if (status >= 500 && status < 600) {
702
734
  if (retries !== manager.options.retries) {
735
+ const backoff = normalizeRetryBackoff(
736
+ manager.options.retryBackoff,
737
+ routeId.bucketRoute,
738
+ status,
739
+ retries,
740
+ requestData.body
741
+ );
742
+ if (backoff === null) {
743
+ throw new HTTPError(status, res.statusText, method, url, requestData);
744
+ }
745
+ if (backoff > 0) {
746
+ await sleep(backoff);
747
+ }
703
748
  return null;
704
749
  }
705
750
  throw new HTTPError(status, res.statusText, method, url, requestData);
@@ -823,7 +868,7 @@ var BurstHandler = class {
823
868
  await sleep(retryAfter);
824
869
  return this.runRequest(routeId, url, options, requestData, retries);
825
870
  } else {
826
- const handled = await handleErrors(this.manager, res, method, url, requestData, retries);
871
+ const handled = await handleErrors(this.manager, res, method, url, requestData, retries, routeId);
827
872
  if (handled === null) {
828
873
  return this.runRequest(routeId, url, options, requestData, ++retries);
829
874
  }
@@ -1125,7 +1170,7 @@ var SequentialHandler = class {
1125
1170
  }
1126
1171
  return this.runRequest(routeId, url, options, requestData, retries);
1127
1172
  } else {
1128
- const handled = await handleErrors(this.manager, res, method, url, requestData, retries);
1173
+ const handled = await handleErrors(this.manager, res, method, url, requestData, retries, routeId);
1129
1174
  if (handled === null) {
1130
1175
  return this.runRequest(routeId, url, options, requestData, ++retries);
1131
1176
  }
@@ -1454,7 +1499,7 @@ var REST = class _REST extends AsyncEventEmitter {
1454
1499
  };
1455
1500
 
1456
1501
  // src/shared.ts
1457
- var version = "3.0.0-dev.1757160090-352c9819b";
1502
+ var version = "3.0.0-dev.1757505703-f1bcff46b";
1458
1503
 
1459
1504
  // src/index.ts
1460
1505
  setDefaultStrategy(shouldUseGlobalFetchAndWebSocket() ? fetch : makeRequest);