@discordjs/proxy 3.0.0-move-client-init.1761650119-a4c0a246f → 3.0.0-pr-11006.1765450794-e636950b2

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
@@ -31,9 +31,6 @@ __export(index_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(index_exports);
33
33
 
34
- // src/handlers/proxyRequests.ts
35
- var import_node_url = require("url");
36
-
37
34
  // src/util/responseHelpers.ts
38
35
  var import_node_stream = require("stream");
39
36
  var import_promises = require("stream/promises");
@@ -92,7 +89,7 @@ function proxyRequests(rest) {
92
89
  "Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage"
93
90
  );
94
91
  }
95
- const parsedUrl = new import_node_url.URL(url, "http://noop");
92
+ const parsedUrl = new URL(url, "http://noop");
96
93
  const fullRoute = parsedUrl.pathname.replace(/^\/api(\/v\d+)?/, "");
97
94
  const headers = {
98
95
  "Content-Type": req.headers["content-type"]
@@ -129,7 +126,7 @@ function proxyRequests(rest) {
129
126
  __name(proxyRequests, "proxyRequests");
130
127
 
131
128
  // src/index.ts
132
- var version = "3.0.0-move-client-init.1761650119-a4c0a246f";
129
+ var version = "3.0.0-pr-11006.1765450794-e636950b2";
133
130
  // Annotate the CommonJS export names for ESM import in node:
134
131
  0 && (module.exports = {
135
132
  populateAbortErrorResponse,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/handlers/proxyRequests.ts","../src/util/responseHelpers.ts"],"sourcesContent":["export * from './handlers/proxyRequests.js';\nexport * from './util/responseHelpers.js';\nexport type { RequestHandler } from './util/util.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/proxy#readme | @discordjs/proxy} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '3.0.0-move-client-init.1761650119-a4c0a246f' as string;\n","import { URL } from 'node:url';\nimport type { RequestMethod, REST, RouteLike } from '@discordjs/rest';\nimport { populateSuccessfulResponse, populateErrorResponse } from '../util/responseHelpers.js';\nimport type { RequestHandler } from '../util/util.js';\n\n/**\n * Creates an HTTP handler used to forward requests to Discord\n *\n * @param rest - REST instance to use for the requests\n */\nexport function proxyRequests(rest: REST): RequestHandler {\n\treturn async (req, res) => {\n\t\tconst { method, url } = req;\n\n\t\tif (!method || !url) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage',\n\t\t\t);\n\t\t}\n\n\t\t// The 2nd parameter is here so the URL constructor doesn't complain about an \"invalid url\" when the origin is missing\n\t\t// we don't actually care about the origin and the value passed is irrelevant\n\t\tconst parsedUrl = new URL(url, 'http://noop');\n\t\t// eslint-disable-next-line prefer-named-capture-group\n\t\tconst fullRoute = parsedUrl.pathname.replace(/^\\/api(\\/v\\d+)?/, '') as RouteLike;\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Content-Type': req.headers['content-type']!,\n\t\t};\n\n\t\tif (req.headers.authorization) {\n\t\t\theaders.authorization = req.headers.authorization;\n\t\t}\n\n\t\tif (req.headers['x-audit-log-reason']) {\n\t\t\theaders['x-audit-log-reason'] = req.headers['x-audit-log-reason'] as string;\n\t\t}\n\n\t\ttry {\n\t\t\tconst discordResponse = await rest.queueRequest({\n\t\t\t\tbody: req,\n\t\t\t\tfullRoute,\n\t\t\t\t// This type cast is technically incorrect, but we want Discord to throw Method Not Allowed for us\n\t\t\t\tmethod: method as RequestMethod,\n\t\t\t\t// We forward the auth header anyway\n\t\t\t\tauth: false,\n\t\t\t\tpassThroughBody: true,\n\t\t\t\tquery: parsedUrl.searchParams,\n\t\t\t\theaders,\n\t\t\t});\n\n\t\t\tawait populateSuccessfulResponse(res, discordResponse);\n\t\t} catch (error) {\n\t\t\tconst knownError = populateErrorResponse(res, error);\n\t\t\tif (!knownError) {\n\t\t\t\t// Unclear if there's better course of action here for unknown errors.\n\t\t\t\t// Any web framework allows to pass in an error handler for something like this\n\t\t\t\t// at which point the user could dictate what to do with the error - otherwise we could just 500\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} finally {\n\t\t\tres.end();\n\t\t}\n\t};\n}\n","import type { ServerResponse } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport { DiscordAPIError, HTTPError, RateLimitError, type ResponseLike } from '@discordjs/rest';\n\n/**\n * Populates a server response with the data from a Discord 2xx REST response\n *\n * @param res - The server response to populate\n * @param data - The data to populate the response with\n */\nexport async function populateSuccessfulResponse(res: ServerResponse, data: ResponseLike): Promise<void> {\n\tres.statusCode = data.status;\n\n\tfor (const [header, value] of data.headers) {\n\t\t// Strip ratelimit headers\n\t\tif (/^x-ratelimit/i.test(header)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tres.setHeader(header, value);\n\t}\n\n\tif (data.body) {\n\t\tawait pipeline(data.body instanceof Readable ? data.body : Readable.fromWeb(data.body), res);\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord non-2xx REST response that is NOT a 429\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateGeneralErrorResponse(res: ServerResponse, error: DiscordAPIError | HTTPError): void {\n\tres.statusCode = error.status;\n\n\tif ('rawError' in error) {\n\t\tres.setHeader('Content-Type', 'application/json');\n\t\tres.write(JSON.stringify(error.rawError));\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord 429 REST response\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateRatelimitErrorResponse(res: ServerResponse, error: RateLimitError): void {\n\tres.statusCode = 429;\n\tres.setHeader('Retry-After', error.timeToReset / 1_000);\n}\n\n/**\n * Populates a server response with data relevant for a timeout\n *\n * @param res - The sever response to populate\n */\nexport function populateAbortErrorResponse(res: ServerResponse): void {\n\tres.statusCode = 504;\n\tres.statusMessage = 'Upstream timed out';\n}\n\n/**\n * Tries to populate a server response from an error object\n *\n * @param res - The server response to populate\n * @param error - The error to check and use\n * @returns `true` if the error is known and the response object was populated, otherwise `false`\n */\nexport function populateErrorResponse(res: ServerResponse, error: unknown): boolean {\n\tif (error instanceof DiscordAPIError || error instanceof HTTPError) {\n\t\tpopulateGeneralErrorResponse(res, error);\n\t} else if (error instanceof RateLimitError) {\n\t\tpopulateRatelimitErrorResponse(res, error);\n\t} else if (error instanceof Error && error.name === 'AbortError') {\n\t\tpopulateAbortErrorResponse(res);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAAoB;;;ACCpB,yBAAyB;AACzB,sBAAyB;AACzB,kBAA8E;AAQ9E,eAAsB,2BAA2B,KAAqB,MAAmC;AACxG,MAAI,aAAa,KAAK;AAEtB,aAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,SAAS;AAE3C,QAAI,gBAAgB,KAAK,MAAM,GAAG;AACjC;AAAA,IACD;AAEA,QAAI,UAAU,QAAQ,KAAK;AAAA,EAC5B;AAEA,MAAI,KAAK,MAAM;AACd,cAAM,0BAAS,KAAK,gBAAgB,8BAAW,KAAK,OAAO,4BAAS,QAAQ,KAAK,IAAI,GAAG,GAAG;AAAA,EAC5F;AACD;AAfsB;AAuBf,SAAS,6BAA6B,KAAqB,OAA0C;AAC3G,MAAI,aAAa,MAAM;AAEvB,MAAI,cAAc,OAAO;AACxB,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,MAAM,KAAK,UAAU,MAAM,QAAQ,CAAC;AAAA,EACzC;AACD;AAPgB;AAeT,SAAS,+BAA+B,KAAqB,OAA6B;AAChG,MAAI,aAAa;AACjB,MAAI,UAAU,eAAe,MAAM,cAAc,GAAK;AACvD;AAHgB;AAUT,SAAS,2BAA2B,KAA2B;AACrE,MAAI,aAAa;AACjB,MAAI,gBAAgB;A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AAA,EACD;AACD;AAtDgB;;;ADAT,IAAM,UAAU;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/util/responseHelpers.ts","../src/handlers/proxyRequests.ts"],"sourcesContent":["export * from './handlers/proxyRequests.js';\nexport * from './util/responseHelpers.js';\nexport type { RequestHandler } from './util/util.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/proxy#readme | @discordjs/proxy} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '3.0.0-pr-11006.1765450794-e636950b2' as string;\n","import type { ServerResponse } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport { DiscordAPIError, HTTPError, RateLimitError, type ResponseLike } from '@discordjs/rest';\n\n/**\n * Populates a server response with the data from a Discord 2xx REST response\n *\n * @param res - The server response to populate\n * @param data - The data to populate the response with\n */\nexport async function populateSuccessfulResponse(res: ServerResponse, data: ResponseLike): Promise<void> {\n\tres.statusCode = data.status;\n\n\tfor (const [header, value] of data.headers) {\n\t\t// Strip ratelimit headers\n\t\tif (/^x-ratelimit/i.test(header)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tres.setHeader(header, value);\n\t}\n\n\tif (data.body) {\n\t\tawait pipeline(data.body instanceof Readable ? data.body : Readable.fromWeb(data.body), res);\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord non-2xx REST response that is NOT a 429\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateGeneralErrorResponse(res: ServerResponse, error: DiscordAPIError | HTTPError): void {\n\tres.statusCode = error.status;\n\n\tif ('rawError' in error) {\n\t\tres.setHeader('Content-Type', 'application/json');\n\t\tres.write(JSON.stringify(error.rawError));\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord 429 REST response\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateRatelimitErrorResponse(res: ServerResponse, error: RateLimitError): void {\n\tres.statusCode = 429;\n\tres.setHeader('Retry-After', error.timeToReset / 1_000);\n}\n\n/**\n * Populates a server response with data relevant for a timeout\n *\n * @param res - The sever response to populate\n */\nexport function populateAbortErrorResponse(res: ServerResponse): void {\n\tres.statusCode = 504;\n\tres.statusMessage = 'Upstream timed out';\n}\n\n/**\n * Tries to populate a server response from an error object\n *\n * @param res - The server response to populate\n * @param error - The error to check and use\n * @returns `true` if the error is known and the response object was populated, otherwise `false`\n */\nexport function populateErrorResponse(res: ServerResponse, error: unknown): boolean {\n\tif (error instanceof DiscordAPIError || error instanceof HTTPError) {\n\t\tpopulateGeneralErrorResponse(res, error);\n\t} else if (error instanceof RateLimitError) {\n\t\tpopulateRatelimitErrorResponse(res, error);\n\t} else if (error instanceof Error && error.name === 'AbortError') {\n\t\tpopulateAbortErrorResponse(res);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { RequestMethod, REST, RouteLike } from '@discordjs/rest';\nimport { populateSuccessfulResponse, populateErrorResponse } from '../util/responseHelpers.js';\nimport type { RequestHandler } from '../util/util.js';\n\n/**\n * Creates an HTTP handler used to forward requests to Discord\n *\n * @param rest - REST instance to use for the requests\n */\nexport function proxyRequests(rest: REST): RequestHandler {\n\treturn async (req, res) => {\n\t\tconst { method, url } = req;\n\n\t\tif (!method || !url) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage',\n\t\t\t);\n\t\t}\n\n\t\t// The 2nd parameter is here so the URL constructor doesn't complain about an \"invalid url\" when the origin is missing\n\t\t// we don't actually care about the origin and the value passed is irrelevant\n\t\tconst parsedUrl = new URL(url, 'http://noop');\n\t\t// eslint-disable-next-line prefer-named-capture-group\n\t\tconst fullRoute = parsedUrl.pathname.replace(/^\\/api(\\/v\\d+)?/, '') as RouteLike;\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Content-Type': req.headers['content-type']!,\n\t\t};\n\n\t\tif (req.headers.authorization) {\n\t\t\theaders.authorization = req.headers.authorization;\n\t\t}\n\n\t\tif (req.headers['x-audit-log-reason']) {\n\t\t\theaders['x-audit-log-reason'] = req.headers['x-audit-log-reason'] as string;\n\t\t}\n\n\t\ttry {\n\t\t\tconst discordResponse = await rest.queueRequest({\n\t\t\t\tbody: req,\n\t\t\t\tfullRoute,\n\t\t\t\t// This type cast is technically incorrect, but we want Discord to throw Method Not Allowed for us\n\t\t\t\tmethod: method as RequestMethod,\n\t\t\t\t// We forward the auth header anyway\n\t\t\t\tauth: false,\n\t\t\t\tpassThroughBody: true,\n\t\t\t\tquery: parsedUrl.searchParams,\n\t\t\t\theaders,\n\t\t\t});\n\n\t\t\tawait populateSuccessfulResponse(res, discordResponse);\n\t\t} catch (error) {\n\t\t\tconst knownError = populateErrorResponse(res, error);\n\t\t\tif (!knownError) {\n\t\t\t\t// Unclear if there's better course of action here for unknown errors.\n\t\t\t\t// Any web framework allows to pass in an error handler for something like this\n\t\t\t\t// at which point the user could dictate what to do with the error - otherwise we could just 500\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} finally {\n\t\t\tres.end();\n\t\t}\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,yBAAyB;AACzB,sBAAyB;AACzB,kBAA8E;AAQ9E,eAAsB,2BAA2B,KAAqB,MAAmC;AACxG,MAAI,aAAa,KAAK;AAEtB,aAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,SAAS;AAE3C,QAAI,gBAAgB,KAAK,MAAM,GAAG;AACjC;AAAA,IACD;AAEA,QAAI,UAAU,QAAQ,KAAK;AAAA,EAC5B;AAEA,MAAI,KAAK,MAAM;AACd,cAAM,0BAAS,KAAK,gBAAgB,8BAAW,KAAK,OAAO,4BAAS,QAAQ,KAAK,IAAI,GAAG,GAAG;AAAA,EAC5F;AACD;AAfsB;AAuBf,SAAS,6BAA6B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MAAM,KAAK,aAAa;AAAA,QAC/C,MAAM;AAAA,QACN;AAAA;AAAA,QAEA;AAAA;AAAA,QAEA,MAAM;AAAA,QACN,iBAAiB;AAAA,QACjB,OAAO,UAAU;AAAA,QACjB;AAAA,MACD,CAAC;AAED,YAAM,2BAA2B,KAAK,eAAe;AAAA,IACtD,SAAS,OAAO;AACf,YAAM,aAAa,sBAAsB,KAAK,KAAK;AACnD,UAAI,CAAC,YAAY;AAIhB,cAAM;AAAA,MACP;AAAA,IACD,UAAE;AACD,UAAI,IAAI;AAAA,IACT;AAAA,EACD;AACD;AAtDgB;;;AFCT,IAAM,UAAU;","names":[]}
package/dist/index.mjs CHANGED
@@ -1,9 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // src/handlers/proxyRequests.ts
5
- import { URL } from "url";
6
-
7
4
  // src/util/responseHelpers.ts
8
5
  import { Readable } from "stream";
9
6
  import { pipeline } from "stream/promises";
@@ -99,7 +96,7 @@ function proxyRequests(rest) {
99
96
  __name(proxyRequests, "proxyRequests");
100
97
 
101
98
  // src/index.ts
102
- var version = "3.0.0-move-client-init.1761650119-a4c0a246f";
99
+ var version = "3.0.0-pr-11006.1765450794-e636950b2";
103
100
  export {
104
101
  populateAbortErrorResponse,
105
102
  populateErrorResponse,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/handlers/proxyRequests.ts","../src/util/responseHelpers.ts","../src/index.ts"],"sourcesContent":["import { URL } from 'node:url';\nimport type { RequestMethod, REST, RouteLike } from '@discordjs/rest';\nimport { populateSuccessfulResponse, populateErrorResponse } from '../util/responseHelpers.js';\nimport type { RequestHandler } from '../util/util.js';\n\n/**\n * Creates an HTTP handler used to forward requests to Discord\n *\n * @param rest - REST instance to use for the requests\n */\nexport function proxyRequests(rest: REST): RequestHandler {\n\treturn async (req, res) => {\n\t\tconst { method, url } = req;\n\n\t\tif (!method || !url) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage',\n\t\t\t);\n\t\t}\n\n\t\t// The 2nd parameter is here so the URL constructor doesn't complain about an \"invalid url\" when the origin is missing\n\t\t// we don't actually care about the origin and the value passed is irrelevant\n\t\tconst parsedUrl = new URL(url, 'http://noop');\n\t\t// eslint-disable-next-line prefer-named-capture-group\n\t\tconst fullRoute = parsedUrl.pathname.replace(/^\\/api(\\/v\\d+)?/, '') as RouteLike;\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Content-Type': req.headers['content-type']!,\n\t\t};\n\n\t\tif (req.headers.authorization) {\n\t\t\theaders.authorization = req.headers.authorization;\n\t\t}\n\n\t\tif (req.headers['x-audit-log-reason']) {\n\t\t\theaders['x-audit-log-reason'] = req.headers['x-audit-log-reason'] as string;\n\t\t}\n\n\t\ttry {\n\t\t\tconst discordResponse = await rest.queueRequest({\n\t\t\t\tbody: req,\n\t\t\t\tfullRoute,\n\t\t\t\t// This type cast is technically incorrect, but we want Discord to throw Method Not Allowed for us\n\t\t\t\tmethod: method as RequestMethod,\n\t\t\t\t// We forward the auth header anyway\n\t\t\t\tauth: false,\n\t\t\t\tpassThroughBody: true,\n\t\t\t\tquery: parsedUrl.searchParams,\n\t\t\t\theaders,\n\t\t\t});\n\n\t\t\tawait populateSuccessfulResponse(res, discordResponse);\n\t\t} catch (error) {\n\t\t\tconst knownError = populateErrorResponse(res, error);\n\t\t\tif (!knownError) {\n\t\t\t\t// Unclear if there's better course of action here for unknown errors.\n\t\t\t\t// Any web framework allows to pass in an error handler for something like this\n\t\t\t\t// at which point the user could dictate what to do with the error - otherwise we could just 500\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} finally {\n\t\t\tres.end();\n\t\t}\n\t};\n}\n","import type { ServerResponse } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport { DiscordAPIError, HTTPError, RateLimitError, type ResponseLike } from '@discordjs/rest';\n\n/**\n * Populates a server response with the data from a Discord 2xx REST response\n *\n * @param res - The server response to populate\n * @param data - The data to populate the response with\n */\nexport async function populateSuccessfulResponse(res: ServerResponse, data: ResponseLike): Promise<void> {\n\tres.statusCode = data.status;\n\n\tfor (const [header, value] of data.headers) {\n\t\t// Strip ratelimit headers\n\t\tif (/^x-ratelimit/i.test(header)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tres.setHeader(header, value);\n\t}\n\n\tif (data.body) {\n\t\tawait pipeline(data.body instanceof Readable ? data.body : Readable.fromWeb(data.body), res);\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord non-2xx REST response that is NOT a 429\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateGeneralErrorResponse(res: ServerResponse, error: DiscordAPIError | HTTPError): void {\n\tres.statusCode = error.status;\n\n\tif ('rawError' in error) {\n\t\tres.setHeader('Content-Type', 'application/json');\n\t\tres.write(JSON.stringify(error.rawError));\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord 429 REST response\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateRatelimitErrorResponse(res: ServerResponse, error: RateLimitError): void {\n\tres.statusCode = 429;\n\tres.setHeader('Retry-After', error.timeToReset / 1_000);\n}\n\n/**\n * Populates a server response with data relevant for a timeout\n *\n * @param res - The sever response to populate\n */\nexport function populateAbortErrorResponse(res: ServerResponse): void {\n\tres.statusCode = 504;\n\tres.statusMessage = 'Upstream timed out';\n}\n\n/**\n * Tries to populate a server response from an error object\n *\n * @param res - The server response to populate\n * @param error - The error to check and use\n * @returns `true` if the error is known and the response object was populated, otherwise `false`\n */\nexport function populateErrorResponse(res: ServerResponse, error: unknown): boolean {\n\tif (error instanceof DiscordAPIError || error instanceof HTTPError) {\n\t\tpopulateGeneralErrorResponse(res, error);\n\t} else if (error instanceof RateLimitError) {\n\t\tpopulateRatelimitErrorResponse(res, error);\n\t} else if (error instanceof Error && error.name === 'AbortError') {\n\t\tpopulateAbortErrorResponse(res);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","export * from './handlers/proxyRequests.js';\nexport * from './util/responseHelpers.js';\nexport type { RequestHandler } from './util/util.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/proxy#readme | @discordjs/proxy} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '3.0.0-move-client-init.1761650119-a4c0a246f' as string;\n"],"mappings":";;;;AAAA,SAAS,WAAW;;;ACCpB,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,sBAAyC;AAQ9E,eAAsB,2BAA2B,KAAqB,MAAmC;AACxG,MAAI,aAAa,KAAK;AAEtB,aAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,SAAS;AAE3C,QAAI,gBAAgB,KAAK,MAAM,GAAG;AACjC;AAAA,IACD;AAEA,QAAI,UAAU,QAAQ,KAAK;AAAA,EAC5B;AAEA,MAAI,KAAK,MAAM;AACd,UAAM,SAAS,KAAK,gBAAgB,WAAW,KAAK,OAAO,SAAS,QAAQ,KAAK,IAAI,GAAG,GAAG;AAAA,EAC5F;AACD;AAfsB;AAuBf,SAAS,6BAA6B,KAAqB,OAA0C;AAC3G,MAAI,aAAa,MAAM;AAEvB,MAAI,cAAc,OAAO;AACxB,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,MAAM,KAAK,UAAU,MAAM,QAAQ,CAAC;AAAA,EACzC;AACD;AAPgB;AAeT,SAAS,+BAA+B,KAAqB,OAA6B;AAChG,MAAI,aAAa;AACjB,MAAI,UAAU,eAAe,MAAM,cAAc,GAAK;AACvD;AAHgB;AAUT,SAAS,2BAA2B,KAA2B;AACrE,MAAI,aAAa;AACjB,MAAI,gBAAgB;AACrB;AAHgB;AAYT,SAAS,sBAAsB,KAAqB,OAAyB;AACnF,MAAI,iBAAiB,mBAAmB,iBAAiB,WAAW;AACnE,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yRequests.ts","../src/index.ts"],"sourcesContent":["import type { ServerResponse } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { pipeline } from 'node:stream/promises';\nimport { DiscordAPIError, HTTPError, RateLimitError, type ResponseLike } from '@discordjs/rest';\n\n/**\n * Populates a server response with the data from a Discord 2xx REST response\n *\n * @param res - The server response to populate\n * @param data - The data to populate the response with\n */\nexport async function populateSuccessfulResponse(res: ServerResponse, data: ResponseLike): Promise<void> {\n\tres.statusCode = data.status;\n\n\tfor (const [header, value] of data.headers) {\n\t\t// Strip ratelimit headers\n\t\tif (/^x-ratelimit/i.test(header)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tres.setHeader(header, value);\n\t}\n\n\tif (data.body) {\n\t\tawait pipeline(data.body instanceof Readable ? data.body : Readable.fromWeb(data.body), res);\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord non-2xx REST response that is NOT a 429\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateGeneralErrorResponse(res: ServerResponse, error: DiscordAPIError | HTTPError): void {\n\tres.statusCode = error.status;\n\n\tif ('rawError' in error) {\n\t\tres.setHeader('Content-Type', 'application/json');\n\t\tres.write(JSON.stringify(error.rawError));\n\t}\n}\n\n/**\n * Populates a server response with the data from a Discord 429 REST response\n *\n * @param res - The server response to populate\n * @param error - The error to populate the response with\n */\nexport function populateRatelimitErrorResponse(res: ServerResponse, error: RateLimitError): void {\n\tres.statusCode = 429;\n\tres.setHeader('Retry-After', error.timeToReset / 1_000);\n}\n\n/**\n * Populates a server response with data relevant for a timeout\n *\n * @param res - The sever response to populate\n */\nexport function populateAbortErrorResponse(res: ServerResponse): void {\n\tres.statusCode = 504;\n\tres.statusMessage = 'Upstream timed out';\n}\n\n/**\n * Tries to populate a server response from an error object\n *\n * @param res - The server response to populate\n * @param error - The error to check and use\n * @returns `true` if the error is known and the response object was populated, otherwise `false`\n */\nexport function populateErrorResponse(res: ServerResponse, error: unknown): boolean {\n\tif (error instanceof DiscordAPIError || error instanceof HTTPError) {\n\t\tpopulateGeneralErrorResponse(res, error);\n\t} else if (error instanceof RateLimitError) {\n\t\tpopulateRatelimitErrorResponse(res, error);\n\t} else if (error instanceof Error && error.name === 'AbortError') {\n\t\tpopulateAbortErrorResponse(res);\n\t} else {\n\t\treturn false;\n\t}\n\n\treturn true;\n}\n","import type { RequestMethod, REST, RouteLike } from '@discordjs/rest';\nimport { populateSuccessfulResponse, populateErrorResponse } from '../util/responseHelpers.js';\nimport type { RequestHandler } from '../util/util.js';\n\n/**\n * Creates an HTTP handler used to forward requests to Discord\n *\n * @param rest - REST instance to use for the requests\n */\nexport function proxyRequests(rest: REST): RequestHandler {\n\treturn async (req, res) => {\n\t\tconst { method, url } = req;\n\n\t\tif (!method || !url) {\n\t\t\tthrow new TypeError(\n\t\t\t\t'Invalid request. Missing method and/or url, implying that this is not a Server IncomingMessage',\n\t\t\t);\n\t\t}\n\n\t\t// The 2nd parameter is here so the URL constructor doesn't complain about an \"invalid url\" when the origin is missing\n\t\t// we don't actually care about the origin and the value passed is irrelevant\n\t\tconst parsedUrl = new URL(url, 'http://noop');\n\t\t// eslint-disable-next-line prefer-named-capture-group\n\t\tconst fullRoute = parsedUrl.pathname.replace(/^\\/api(\\/v\\d+)?/, '') as RouteLike;\n\n\t\tconst headers: Record<string, string> = {\n\t\t\t'Content-Type': req.headers['content-type']!,\n\t\t};\n\n\t\tif (req.headers.authorization) {\n\t\t\theaders.authorization = req.headers.authorization;\n\t\t}\n\n\t\tif (req.headers['x-audit-log-reason']) {\n\t\t\theaders['x-audit-log-reason'] = req.headers['x-audit-log-reason'] as string;\n\t\t}\n\n\t\ttry {\n\t\t\tconst discordResponse = await rest.queueRequest({\n\t\t\t\tbody: req,\n\t\t\t\tfullRoute,\n\t\t\t\t// This type cast is technically incorrect, but we want Discord to throw Method Not Allowed for us\n\t\t\t\tmethod: method as RequestMethod,\n\t\t\t\t// We forward the auth header anyway\n\t\t\t\tauth: false,\n\t\t\t\tpassThroughBody: true,\n\t\t\t\tquery: parsedUrl.searchParams,\n\t\t\t\theaders,\n\t\t\t});\n\n\t\t\tawait populateSuccessfulResponse(res, discordResponse);\n\t\t} catch (error) {\n\t\t\tconst knownError = populateErrorResponse(res, error);\n\t\t\tif (!knownError) {\n\t\t\t\t// Unclear if there's better course of action here for unknown errors.\n\t\t\t\t// Any web framework allows to pass in an error handler for something like this\n\t\t\t\t// at which point the user could dictate what to do with the error - otherwise we could just 500\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t} finally {\n\t\t\tres.end();\n\t\t}\n\t};\n}\n","export * from './handlers/proxyRequests.js';\nexport * from './util/responseHelpers.js';\nexport type { RequestHandler } from './util/util.js';\n\n/**\n * The {@link https://github.com/discordjs/discord.js/blob/main/packages/proxy#readme | @discordjs/proxy} version\n * that you are currently using.\n *\n * @privateRemarks This needs to explicitly be `string` so it is not typed as a \"const string\" that gets injected by esbuild.\n */\nexport const version = '3.0.0-pr-11006.1765450794-e636950b2' as string;\n"],"mappings":";;;;AACA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,sBAAyC;AAQ9E,eAAsB,2BAA2B,KAAqB,MAAmC;AACxG,MAAI,aAAa,KAAK;AAEtB,aAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,SAAS;AAE3C,QAAI,gBAAgB,KAAK,MAAM,GAAG;AACjC;AAAA,IACD;AAEA,QAAI,UAAU,QAAQ,KAAK;AAAA,EAC5B;AAEA,MAAI,KAAK,MAAM;AACd,UAAM,SAAS,KAAK,gBAAgB,WAAW,KAAK,OAAO,SAAS,QAAQ,KAAK,IAAI,GAAG,GAAG;AAAA,EAC5F;AACD;AAfsB;AAuBf,SAAS,6BAA6B,KAAqB,OAA0C;AAC3G,MAAI,aAAa,MAAM;AAEvB,MAAI,cAAc,OAAO;AACxB,QAAI,UAAU,gBAAgB,kBAAkB;AAChD,QAAI,MAAM,KAAK,UAAU,MAAM,QAAQ,CAAC;AAAA,EACz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;AAED,YAAM,2BAA2B,KAAK,eAAe;AAAA,IACtD,SAAS,OAAO;AACf,YAAM,aAAa,sBAAsB,KAAK,KAAK;AACnD,UAAI,CAAC,YAAY;AAIhB,cAAM;AAAA,MACP;AAAA,IACD,UAAE;AACD,UAAI,IAAI;AAAA,IACT;AAAA,EACD;AACD;AAtDgB;;;ACCT,IAAM,UAAU;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@discordjs/proxy",
4
- "version": "3.0.0-move-client-init.1761650119-a4c0a246f",
4
+ "version": "3.0.0-pr-11006.1765450794-e636950b2",
5
5
  "description": "Tools for running an HTTP proxy for Discord's API",
6
6
  "exports": {
7
7
  ".": {
@@ -55,28 +55,28 @@
55
55
  "dependencies": {
56
56
  "tslib": "^2.8.1",
57
57
  "undici": "7.16.0",
58
- "@discordjs/rest": "^3.0.0-move-client-init.1761650119-a4c0a246f",
59
- "@discordjs/util": "^2.0.0-move-client-init.1761650119-a4c0a246f"
58
+ "@discordjs/rest": "3.0.0-pr-11006.1765450794-e636950b2",
59
+ "@discordjs/util": "2.0.0-pr-11006.1765450794-e636950b2"
60
60
  },
61
61
  "devDependencies": {
62
- "@favware/cliff-jumper": "^4.1.0",
63
- "@types/node": "^22.18.8",
62
+ "@favware/cliff-jumper": "^6.0.0",
63
+ "@types/node": "^22.19.1",
64
64
  "@types/supertest": "^6.0.3",
65
- "@vitest/coverage-v8": "^3.2.4",
65
+ "@vitest/coverage-v8": "^4.0.15",
66
66
  "cross-env": "^10.1.0",
67
67
  "esbuild-plugin-version-injector": "^1.2.1",
68
- "eslint": "^9.37.0",
69
- "eslint-config-neon": "^0.2.7",
70
- "eslint-formatter-compact": "^8.40.0",
68
+ "eslint": "^9.39.1",
69
+ "eslint-config-neon": "^0.2.9",
70
+ "eslint-formatter-compact": "^9.0.1",
71
71
  "eslint-formatter-pretty": "^7.0.0",
72
- "prettier": "^3.6.2",
72
+ "prettier": "^3.7.4",
73
73
  "supertest": "^7.1.4",
74
- "tsup": "^8.5.0",
75
- "turbo": "^2.5.8",
74
+ "tsup": "^8.5.1",
75
+ "turbo": "^2.6.3",
76
76
  "typescript": "~5.9.3",
77
- "vitest": "^3.2.4",
78
- "@discordjs/api-extractor": "^7.52.7",
79
- "@discordjs/scripts": "^0.1.0"
77
+ "vitest": "^4.0.15",
78
+ "@discordjs/api-extractor": "7.52.7",
79
+ "@discordjs/scripts": "0.1.0"
80
80
  },
81
81
  "engines": {
82
82
  "node": ">=22.12.0"