@sapphire/plugin-api 6.1.2-next.43df709.0 → 6.1.2-next.4ab5259.0

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.
Files changed (97) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/lib/structures/MediaParser.cjs +4 -8
  4. package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
  5. package/dist/cjs/lib/structures/Middleware.cjs +1 -4
  6. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  7. package/dist/cjs/lib/structures/MiddlewareStore.cjs +6 -14
  8. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  9. package/dist/cjs/lib/structures/Route.cjs +2 -6
  10. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/RouteStore.cjs +5 -12
  12. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  13. package/dist/cjs/lib/structures/api/ApiRequest.cjs +1 -4
  14. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  15. package/dist/cjs/lib/structures/api/ApiResponse.cjs +1 -4
  16. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  17. package/dist/cjs/lib/structures/api/CookieStore.cjs +3 -8
  18. package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
  19. package/dist/cjs/lib/structures/http/Auth.cjs +13 -31
  20. package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
  21. package/dist/cjs/lib/structures/http/Server.cjs +1 -4
  22. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  23. package/dist/cjs/lib/utils/RouteData.cjs +8 -18
  24. package/dist/cjs/lib/utils/RouteData.cjs.map +1 -1
  25. package/dist/cjs/listeners/PluginRouteError.cjs +1 -2
  26. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  27. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +1 -2
  28. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  29. package/dist/cjs/listeners/PluginServerNoMatch.cjs +1 -2
  30. package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +1 -1
  31. package/dist/cjs/middlewares/auth.cjs +2 -6
  32. package/dist/cjs/middlewares/auth.cjs.map +1 -1
  33. package/dist/cjs/middlewares/body.cjs +3 -8
  34. package/dist/cjs/middlewares/body.cjs.map +1 -1
  35. package/dist/cjs/middlewares/cookies.cjs +1 -4
  36. package/dist/cjs/middlewares/cookies.cjs.map +1 -1
  37. package/dist/cjs/middlewares/headers.cjs +1 -4
  38. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  39. package/dist/cjs/routes/oauth/callback.cjs +2 -6
  40. package/dist/cjs/routes/oauth/callback.cjs.map +1 -1
  41. package/dist/cjs/routes/oauth/logout.cjs +3 -6
  42. package/dist/cjs/routes/oauth/logout.cjs.map +1 -1
  43. package/dist/esm/chunk-JTFKMR4I.mjs +15 -0
  44. package/dist/esm/index.mjs +2 -2
  45. package/dist/esm/index.mjs.map +1 -1
  46. package/dist/esm/lib/structures/MediaParser.mjs +5 -9
  47. package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
  48. package/dist/esm/lib/structures/MediaParserStore.mjs +1 -1
  49. package/dist/esm/lib/structures/Middleware.mjs +1 -1
  50. package/dist/esm/lib/structures/MiddlewareStore.mjs +6 -11
  51. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  52. package/dist/esm/lib/structures/Route.mjs +2 -3
  53. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  54. package/dist/esm/lib/structures/RouteStore.mjs +5 -9
  55. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  56. package/dist/esm/lib/structures/api/ApiRequest.mjs +1 -1
  57. package/dist/esm/lib/structures/api/ApiResponse.mjs +1 -1
  58. package/dist/esm/lib/structures/api/CookieStore.mjs +3 -5
  59. package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
  60. package/dist/esm/lib/structures/http/Auth.mjs +6 -10
  61. package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
  62. package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
  63. package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -1
  64. package/dist/esm/lib/structures/http/Server.mjs +1 -1
  65. package/dist/esm/lib/utils/MimeTypes.mjs +1 -1
  66. package/dist/esm/lib/utils/RouteData.mjs +8 -15
  67. package/dist/esm/lib/utils/RouteData.mjs.map +1 -1
  68. package/dist/esm/listeners/PluginRouteError.mjs +2 -3
  69. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  70. package/dist/esm/listeners/PluginServerMatch.mjs +1 -1
  71. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +2 -3
  72. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  73. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +1 -1
  74. package/dist/esm/listeners/PluginServerNoMatch.mjs +2 -3
  75. package/dist/esm/listeners/PluginServerNoMatch.mjs.map +1 -1
  76. package/dist/esm/listeners/PluginServerRequest.mjs +1 -1
  77. package/dist/esm/listeners/_load.mjs +1 -1
  78. package/dist/esm/mediaParsers/_load.mjs +1 -1
  79. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -1
  80. package/dist/esm/mediaParsers/applicationJson.mjs +1 -1
  81. package/dist/esm/mediaParsers/textPlain.mjs +1 -1
  82. package/dist/esm/middlewares/_load.mjs +1 -1
  83. package/dist/esm/middlewares/auth.mjs +2 -3
  84. package/dist/esm/middlewares/auth.mjs.map +1 -1
  85. package/dist/esm/middlewares/body.mjs +3 -5
  86. package/dist/esm/middlewares/body.mjs.map +1 -1
  87. package/dist/esm/middlewares/cookies.mjs +1 -1
  88. package/dist/esm/middlewares/headers.mjs +1 -1
  89. package/dist/esm/register.mjs +1 -1
  90. package/dist/esm/routes/_load.mjs +1 -1
  91. package/dist/esm/routes/oauth/callback.mjs +2 -3
  92. package/dist/esm/routes/oauth/callback.mjs.map +1 -1
  93. package/dist/esm/routes/oauth/logout.mjs +4 -7
  94. package/dist/esm/routes/oauth/logout.mjs.map +1 -1
  95. package/package.json +5 -5
  96. package/dist/esm/chunk-PYETHG4R.mjs +0 -29
  97. /package/dist/esm/{chunk-PYETHG4R.mjs.map → chunk-JTFKMR4I.mjs.map} +0 -0
@@ -21,7 +21,7 @@ var _load_cjs$2 = require('./middlewares/_load.cjs');
21
21
  var _load_cjs$3 = require('./routes/_load.cjs');
22
22
 
23
23
  // src/index.ts
24
- var version = "6.1.2-next.43df709.0";
24
+ var version = "6.1.2-next.4ab5259.0";
25
25
 
26
26
  Object.defineProperty(exports, "loadListeners", {
27
27
  enumerable: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AA+BpB,IAAM,UAAkB","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/RouteStore';\nexport * from './lib/utils/MimeTypes';\nexport * from './lib/utils/RouteData';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '6.1.2-next.43df709.0';\n"]}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEd,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AA+BpB,IAAM,UAAkB","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/RouteStore';\nexport * from './lib/utils/MimeTypes';\nexport * from './lib/utils/RouteData';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '6.1.2-next.4ab5259.0';\n"]}
@@ -24,11 +24,9 @@ var _MediaParser = class _MediaParser extends pieces.Piece {
24
24
  */
25
25
  async readString(request) {
26
26
  const stream = this.contentStream(request);
27
- if (stream === null)
28
- return "";
27
+ if (stream === null) return "";
29
28
  let body = "";
30
- for await (const chunk of stream)
31
- body += chunk;
29
+ for await (const chunk of stream) body += chunk;
32
30
  return body;
33
31
  }
34
32
  /**
@@ -38,11 +36,9 @@ var _MediaParser = class _MediaParser extends pieces.Piece {
38
36
  */
39
37
  async readBuffer(request) {
40
38
  const stream = this.contentStream(request);
41
- if (stream === null)
42
- return Buffer.alloc(0);
39
+ if (stream === null) return Buffer.alloc(0);
43
40
  const bodies = [];
44
- for await (const chunk of stream)
45
- bodies.push(chunk);
41
+ for await (const chunk of stream) bodies.push(chunk);
46
42
  return Buffer.concat(bodies);
47
43
  }
48
44
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;AAAA,SAAS,aAAa;AAEtB,SAAS,wBAAwB,cAAc,qBAAkC;AAS1E,IAAe,eAAf,MAAe,qBAA+E,MAA+B;AAAA,EAC5H,YAAY,SAAoC,UAAmB,CAAC,GAAc;AACxF,UAAM,SAAS,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,OAAuB;AACrC,WAAO,MAAM,6BAA6B,QAAQ,MAAM,yBAAyB,SAAS,KAAK,IAAiC;AAAA,EACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW;AAAM,aAAO;AAE5B,QAAI,OAAO;AACX,qBAAiB,SAAS;AAAQ,cAAQ;AAE1C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW;AAAM,aAAO,OAAO,MAAM,CAAC;AAE1C,UAAM,SAAmB,CAAC;AAC1B,qBAAiB,SAAS;AAAQ,aAAO,KAAK,KAAK;AAEnD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,SAAiD;AACxE,aAAS,QAAQ,QAAQ,kBAAkB,KAAK,YAAY,YAAY,GAAG;AAAA,MAK1E,KAAK,WAAW;AACf,cAAM,SAAS,cAAc;AAC7B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAMA,KAAK;AAAA,MACL,KAAK,QAAQ;AACZ,cAAM,SAAS,aAAa;AAC5B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAKA,KAAK,MAAM;AACV,cAAM,SAAS,uBAAuB;AACtC,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAIA,KAAK,YAAY;AAChB,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;AAhGoI;AAA7H,IAAe,cAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: ApiRequest): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: ApiRequest): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: ApiRequest): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: ApiRequest): ApiRequest | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;AAAA,SAAS,aAAa;AAEtB,SAAS,wBAAwB,cAAc,qBAAkC;AAS1E,IAAe,eAAf,MAAe,qBAA+E,MAA+B;AAAA,EAC5H,YAAY,SAAoC,UAAmB,CAAC,GAAc;AACxF,UAAM,SAAS,OAAO;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,OAAuB;AACrC,WAAO,MAAM,6BAA6B,QAAQ,MAAM,yBAAyB,SAAS,KAAK,IAAiC;AAAA,EACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW,KAAM,QAAO;AAE5B,QAAI,OAAO;AACX,qBAAiB,SAAS,OAAQ,SAAQ;AAE1C,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,SAAsC;AAChE,UAAM,SAAS,KAAK,cAAc,OAAO;AACzC,QAAI,WAAW,KAAM,QAAO,OAAO,MAAM,CAAC;AAE1C,UAAM,SAAmB,CAAC;AAC1B,qBAAiB,SAAS,OAAQ,QAAO,KAAK,KAAK;AAEnD,WAAO,OAAO,OAAO,MAAM;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,cAAc,SAAiD;AACxE,aAAS,QAAQ,QAAQ,kBAAkB,KAAK,YAAY,YAAY,GAAG;AAAA,MAK1E,KAAK,WAAW;AACf,cAAM,SAAS,cAAc;AAC7B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAMA,KAAK;AAAA,MACL,KAAK,QAAQ;AACZ,cAAM,SAAS,aAAa;AAC5B,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAKA,KAAK,MAAM;AACV,cAAM,SAAS,uBAAuB;AACtC,gBAAQ,KAAK,MAAM;AACnB,eAAO;AAAA,MACR;AAAA,MAIA,KAAK,YAAY;AAChB,eAAO;AAAA,MACR;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;AAhGoI;AAA7H,IAAe,cAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: ApiRequest): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: ApiRequest): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: ApiRequest): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: ApiRequest): ApiRequest | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -5,10 +5,7 @@ var pieces = require('@sapphire/pieces');
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- return value;
11
- };
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
9
  var _Middleware = class _Middleware extends pieces.Piece {
13
10
  constructor(context, options = {}) {
14
11
  super(context, options);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,aAAa;AASf,IAAe,cAAf,MAAe,oBAA4E,MAA8B;AAAA,EAaxH,YAAY,SAAmC,UAAmB,CAAC,GAAc;AACvF,UAAM,SAAS,OAAO;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,WAAW,QAAQ,YAAY;AAAA,EACrC;AASD;AAzBgI;AAAzH,IAAe,aAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: ApiRequest, response: ApiResponse, route: Route | null): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AASf,IAAe,cAAf,MAAe,oBAA4E,MAA8B;AAAA,EAaxH,YAAY,SAAmC,UAAmB,CAAC,GAAc;AACvF,UAAM,SAAS,OAAO;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAIf,SAAK,WAAW,QAAQ,YAAY;AAAA,EACrC;AASD;AAzBgI;AAAzH,IAAe,aAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: ApiRequest, response: ApiResponse, route: Route | null): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -6,10 +6,7 @@ var Middleware_cjs = require('./Middleware.cjs');
6
6
  var __defProp = Object.defineProperty;
7
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __publicField = (obj, key, value) => {
10
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
- return value;
12
- };
9
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
10
  var _MiddlewareStore = class _MiddlewareStore extends pieces.Store {
14
11
  constructor() {
15
12
  super(Middleware_cjs.Middleware, { name: "middlewares" });
@@ -20,24 +17,19 @@ var _MiddlewareStore = class _MiddlewareStore extends pieces.Store {
20
17
  }
21
18
  async run(request, response, route) {
22
19
  for (const middleware of this.sortedMiddlewares) {
23
- if (response.writableEnded)
24
- return;
25
- if (middleware.enabled)
26
- await middleware.run(request, response, route);
20
+ if (response.writableEnded) return;
21
+ if (middleware.enabled) await middleware.run(request, response, route);
27
22
  }
28
23
  }
29
24
  set(key, value) {
30
25
  const index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);
31
- if (index === -1)
32
- this.sortedMiddlewares.push(value);
33
- else
34
- this.sortedMiddlewares.splice(index, 0, value);
26
+ if (index === -1) this.sortedMiddlewares.push(value);
27
+ else this.sortedMiddlewares.splice(index, 0, value);
35
28
  return super.set(key, value);
36
29
  }
37
30
  delete(key) {
38
31
  const index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);
39
- if (index !== -1)
40
- this.sortedMiddlewares.splice(index, 1);
32
+ if (index !== -1) this.sortedMiddlewares.splice(index, 1);
41
33
  return super.delete(key);
42
34
  }
43
35
  clear() {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAQpB,IAAM,mBAAN,MAAM,yBAAwB,MAAiC;AAAA,EAM9D,cAAc;AACpB,UAAM,YAAY,EAAE,MAAM,cAAc,CAAC;AAH1C;AAAA;AAAA;AAAA,wBAAgB,qBAAkC,CAAC;AAAA,EAInD;AAAA,EAEA,MAAa,IAAI,SAAqB,UAAuB,OAAoC;AAChG,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS;AAAe;AAC5B,UAAI,WAAW;AAAS,cAAM,WAAW,IAAI,SAAS,UAAU,KAAK;AAAA,IACtE;AAAA,EACD;AAAA,EAEgB,IAAI,KAAa,OAAyB;AACzD,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,YAAY,MAAM,QAAQ;AAGpG,QAAI,UAAU;AAAI,WAAK,kBAAkB,KAAK,KAAK;AAAA;AAC9C,WAAK,kBAAkB,OAAO,OAAO,GAAG,KAAK;AAElD,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEgB,OAAO,KAAsB;AAC5C,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,SAAS,GAAG;AAGtF,QAAI,UAAU;AAAI,WAAK,kBAAkB,OAAO,OAAO,CAAC;AAExD,WAAO,MAAM,OAAO,GAAG;AAAA,EACxB;AAAA,EAEgB,QAAc;AAC7B,SAAK,kBAAkB,SAAS;AAChC,WAAO,MAAM,MAAM;AAAA,EACpB;AACD;AAxCsE;AAA/D,IAAM,kBAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport class MiddlewareStore extends Store<Middleware, 'middlewares'> {\n\t/**\n\t * The sorted middlewares, in ascending order of see {@link Middleware.position}.\n\t */\n\tpublic readonly sortedMiddlewares: Middleware[] = [];\n\n\tpublic constructor() {\n\t\tsuper(Middleware, { name: 'middlewares' });\n\t}\n\n\tpublic async run(request: ApiRequest, response: ApiResponse, route: Route | null): Promise<void> {\n\t\tfor (const middleware of this.sortedMiddlewares) {\n\t\t\tif (response.writableEnded) return;\n\t\t\tif (middleware.enabled) await middleware.run(request, response, route);\n\t\t}\n\t}\n\n\tpublic override set(key: string, value: Middleware): this {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);\n\n\t\t// If a middleware with lower priority wasn't found, push to the end of the array\n\t\tif (index === -1) this.sortedMiddlewares.push(value);\n\t\telse this.sortedMiddlewares.splice(index, 0, value);\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string): boolean {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);\n\n\t\t// If the middleware was found, remove it\n\t\tif (index !== -1) this.sortedMiddlewares.splice(index, 1);\n\n\t\treturn super.delete(key);\n\t}\n\n\tpublic override clear(): void {\n\t\tthis.sortedMiddlewares.length = 0;\n\t\treturn super.clear();\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAQpB,IAAM,mBAAN,MAAM,yBAAwB,MAAiC;AAAA,EAM9D,cAAc;AACpB,UAAM,YAAY,EAAE,MAAM,cAAc,CAAC;AAH1C;AAAA;AAAA;AAAA,wBAAgB,qBAAkC,CAAC;AAAA,EAInD;AAAA,EAEA,MAAa,IAAI,SAAqB,UAAuB,OAAoC;AAChG,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS,cAAe;AAC5B,UAAI,WAAW,QAAS,OAAM,WAAW,IAAI,SAAS,UAAU,KAAK;AAAA,IACtE;AAAA,EACD;AAAA,EAEgB,IAAI,KAAa,OAAyB;AACzD,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,YAAY,MAAM,QAAQ;AAGpG,QAAI,UAAU,GAAI,MAAK,kBAAkB,KAAK,KAAK;AAAA,QAC9C,MAAK,kBAAkB,OAAO,OAAO,GAAG,KAAK;AAElD,WAAO,MAAM,IAAI,KAAK,KAAK;AAAA,EAC5B;AAAA,EAEgB,OAAO,KAAsB;AAC5C,UAAM,QAAQ,KAAK,kBAAkB,UAAU,CAAC,eAAe,WAAW,SAAS,GAAG;AAGtF,QAAI,UAAU,GAAI,MAAK,kBAAkB,OAAO,OAAO,CAAC;AAExD,WAAO,MAAM,OAAO,GAAG;AAAA,EACxB;AAAA,EAEgB,QAAc;AAC7B,SAAK,kBAAkB,SAAS;AAChC,WAAO,MAAM,MAAM;AAAA,EACpB;AACD;AAxCsE;AAA/D,IAAM,kBAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\nimport type { Route } from './Route';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport class MiddlewareStore extends Store<Middleware, 'middlewares'> {\n\t/**\n\t * The sorted middlewares, in ascending order of see {@link Middleware.position}.\n\t */\n\tpublic readonly sortedMiddlewares: Middleware[] = [];\n\n\tpublic constructor() {\n\t\tsuper(Middleware, { name: 'middlewares' });\n\t}\n\n\tpublic async run(request: ApiRequest, response: ApiResponse, route: Route | null): Promise<void> {\n\t\tfor (const middleware of this.sortedMiddlewares) {\n\t\t\tif (response.writableEnded) return;\n\t\t\tif (middleware.enabled) await middleware.run(request, response, route);\n\t\t}\n\t}\n\n\tpublic override set(key: string, value: Middleware): this {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);\n\n\t\t// If a middleware with lower priority wasn't found, push to the end of the array\n\t\tif (index === -1) this.sortedMiddlewares.push(value);\n\t\telse this.sortedMiddlewares.splice(index, 0, value);\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string): boolean {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);\n\n\t\t// If the middleware was found, remove it\n\t\tif (index !== -1) this.sortedMiddlewares.splice(index, 1);\n\n\t\treturn super.delete(key);\n\t}\n\n\tpublic override clear(): void {\n\t\tthis.sortedMiddlewares.length = 0;\n\t\treturn super.clear();\n\t}\n}\n"]}
@@ -8,10 +8,7 @@ var HttpMethods_cjs = require('./http/HttpMethods.cjs');
8
8
  var __defProp = Object.defineProperty;
9
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- var __publicField = (obj, key, value) => {
12
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
- return value;
14
- };
11
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
12
  var _Route = class _Route extends pieces.Piece {
16
13
  constructor(context, options = {}) {
17
14
  super(context, options);
@@ -35,8 +32,7 @@ var _Route = class _Route extends pieces.Piece {
35
32
  this.router = new RouteData_cjs.RouteData(`${api.prefix ?? ""}${options.route ?? this.name ?? ""}`);
36
33
  for (const [method, symbol] of HttpMethods_cjs.methodEntries) {
37
34
  const value = Reflect.get(this, symbol);
38
- if (typeof value === "function")
39
- this.methods.set(method, value);
35
+ if (typeof value === "function") this.methods.set(method, value);
40
36
  }
41
37
  this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
42
38
  this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,qBAAmC;AAOrC,IAAe,SAAf,MAAe,eAA6D,MAAyB;AAAA,EAqBpG,YAAY,SAA8B,UAAmB,CAAC,GAAc;AAClF,UAAM,SAAS,OAAO;AAlBvB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB,WAAU,IAAI,WAAoC;AAKjE,UAAM,MAAM,KAAK,UAAU,OAAO;AAClC,SAAK,SAAS,IAAI,UAAU,GAAG,IAAI,UAAU,EAAE,GAAG,QAAQ,SAAS,KAAK,QAAQ,EAAE,EAAE;AAEpF,eAAW,CAAC,QAAQ,MAAM,KAAK,eAAe;AAC7C,YAAM,QAAQ,QAAQ,IAAI,MAAM,MAAM;AACtC,UAAI,OAAO,UAAU;AAAY,aAAK,QAAQ,IAAI,QAAQ,KAAK;AAAA,IAChE;AAEA,SAAK,oBAAoB,QAAQ,qBAAqB,IAAI,qBAAqB,OAAO,OAAO;AAC7F,SAAK,2BAA2B,QAAQ,4BAA4B,IAAI,4BAA4B;AAAA,EACrG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,SAA6B;AAC5C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,QAAQ,EAAE,KAAK,KAAK,SAAS;AACxC,YAAM,MAAM,IAAI,MAAM,EAAG,IAAI,MAAM,GAAG,KAAK,IAAI,CAAC;AAAA,IACjD;AAEA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,WAA+B;AAC9C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,MAAM,KAAK,KAAK,SAAS;AACpC,YAAM,MAAM,IAAI,MAAM,EAAG,OAAO,IAAI;AAAA,IACrC;AAEA,WAAO;AAAA,EACR;AACD;AA/D4G;AAArG,IAAe,QAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { Collection } from 'discord.js';\nimport { RouteData } from '../utils/RouteData';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { MethodCallback, RouteStore } from './RouteStore';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The route information.\n\t */\n\tpublic readonly router: RouteData;\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods = new Collection<Methods, MethodCallback>();\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tthis.router = new RouteData(`${api.prefix ?? ''}${options.route ?? this.name ?? ''}`);\n\n\t\tfor (const [method, symbol] of methodEntries) {\n\t\t\tconst value = Reflect.get(this, symbol) as MethodCallback;\n\t\t\tif (typeof value === 'function') this.methods.set(method, value);\n\t\t}\n\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic override onLoad(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method, cb] of this.methods) {\n\t\t\tstore.table.get(method)!.set(this, cb.bind(this));\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic override onUnload(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method] of this.methods) {\n\t\t\tstore.table.get(method)!.delete(this);\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nexport interface RouteOptions extends Piece.Options {\n\t/**\n\t * The route the piece should represent.\n\t * @since 1.0.0\n\t * @default ''\n\t * @example\n\t * ```typescript\n\t * '/users'\n\t * // request.params -> {}\n\t * ```\n\t * @example\n\t * ```typescript\n\t * '/guilds/:guild/members/:member/'\n\t * // request.params -> { guild: '...', member: '...' }\n\t * ```\n\t */\n\troute?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,qBAAmC;AAOrC,IAAe,SAAf,MAAe,eAA6D,MAAyB;AAAA,EAqBpG,YAAY,SAA8B,UAAmB,CAAC,GAAc;AAClF,UAAM,SAAS,OAAO;AAlBvB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB;AAKhB;AAAA;AAAA;AAAA,wBAAgB,WAAU,IAAI,WAAoC;AAKjE,UAAM,MAAM,KAAK,UAAU,OAAO;AAClC,SAAK,SAAS,IAAI,UAAU,GAAG,IAAI,UAAU,EAAE,GAAG,QAAQ,SAAS,KAAK,QAAQ,EAAE,EAAE;AAEpF,eAAW,CAAC,QAAQ,MAAM,KAAK,eAAe;AAC7C,YAAM,QAAQ,QAAQ,IAAI,MAAM,MAAM;AACtC,UAAI,OAAO,UAAU,WAAY,MAAK,QAAQ,IAAI,QAAQ,KAAK;AAAA,IAChE;AAEA,SAAK,oBAAoB,QAAQ,qBAAqB,IAAI,qBAAqB,OAAO,OAAO;AAC7F,SAAK,2BAA2B,QAAQ,4BAA4B,IAAI,4BAA4B;AAAA,EACrG;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,SAA6B;AAC5C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,QAAQ,EAAE,KAAK,KAAK,SAAS;AACxC,YAAM,MAAM,IAAI,MAAM,EAAG,IAAI,MAAM,GAAG,KAAK,IAAI,CAAC;AAAA,IACjD;AAEA,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA;AAAA,EAMgB,WAA+B;AAC9C,UAAM,QAAQ,KAAK;AAEnB,eAAW,CAAC,MAAM,KAAK,KAAK,SAAS;AACpC,YAAM,MAAM,IAAI,MAAM,EAAG,OAAO,IAAI;AAAA,IACrC;AAEA,WAAO;AAAA,EACR;AACD;AA/D4G;AAArG,IAAe,QAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { Collection } from 'discord.js';\nimport { RouteData } from '../utils/RouteData';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { MethodCallback, RouteStore } from './RouteStore';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Route<Options extends Route.Options = Route.Options> extends Piece<Options, 'routes'> {\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t */\n\tpublic readonly maximumBodyLength: number;\n\n\t/**\n\t * The accepted content types.\n\t */\n\tpublic readonly acceptedContentMimeTypes: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The route information.\n\t */\n\tpublic readonly router: RouteData;\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods = new Collection<Methods, MethodCallback>();\n\n\tpublic constructor(context: Route.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\n\t\tconst api = this.container.server.options;\n\t\tthis.router = new RouteData(`${api.prefix ?? ''}${options.route ?? this.name ?? ''}`);\n\n\t\tfor (const [method, symbol] of methodEntries) {\n\t\t\tconst value = Reflect.get(this, symbol) as MethodCallback;\n\t\t\tif (typeof value === 'function') this.methods.set(method, value);\n\t\t}\n\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is loaded into the store.\n\t * Useful to set-up asynchronous initialization tasks.\n\t */\n\tpublic override onLoad(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method, cb] of this.methods) {\n\t\t\tstore.table.get(method)!.set(this, cb.bind(this));\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t/**\n\t * Per-piece listener that is called when the piece is unloaded from the store.\n\t * Useful to set-up clean-up tasks.\n\t */\n\tpublic override onUnload(): Awaitable<unknown> {\n\t\tconst store = this.store as unknown as RouteStore;\n\n\t\tfor (const [method] of this.methods) {\n\t\t\tstore.table.get(method)!.delete(this);\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nexport interface RouteOptions extends Piece.Options {\n\t/**\n\t * The route the piece should represent.\n\t * @since 1.0.0\n\t * @default ''\n\t * @example\n\t * ```typescript\n\t * '/users'\n\t * // request.params -> {}\n\t * ```\n\t * @example\n\t * ```typescript\n\t * '/guilds/:guild/members/:member/'\n\t * // request.params -> { guild: '...', member: '...' }\n\t * ```\n\t */\n\troute?: string;\n\n\t/**\n\t * (RFC 7230 3.3.2) The maximum decimal number of octets.\n\t * @since 1.0.0\n\t * @default this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The accepted content types for this route. If set to null, the route will accept any data.\n\t * @since 1.3.0\n\t * @default this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: MimeTypeWithoutParameters[] | null;\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'routes'>;\n\texport type Options = RouteOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n}\n"]}
@@ -9,17 +9,13 @@ var Route_cjs = require('./Route.cjs');
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var __publicField = (obj, key, value) => {
13
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
- return value;
15
- };
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
13
  var slash = "/".charCodeAt(0);
17
14
  var _RouteStore = class _RouteStore extends pieces.Store {
18
15
  constructor() {
19
16
  super(Route_cjs.Route, { name: "routes" });
20
17
  __publicField(this, "table", new discord_js.Collection());
21
- for (const [method] of HttpMethods_cjs.methodEntries)
22
- this.table.set(method, new discord_js.Collection());
18
+ for (const [method] of HttpMethods_cjs.methodEntries) this.table.set(method, new discord_js.Collection());
23
19
  }
24
20
  match(request) {
25
21
  const { method } = request;
@@ -33,8 +29,7 @@ var _RouteStore = class _RouteStore extends pieces.Store {
33
29
  const { splits, querystring } = this.parseURL(request.url);
34
30
  for (const [route, cb] of methodTable.entries()) {
35
31
  const result = route.router.match(splits);
36
- if (result === null)
37
- continue;
32
+ if (result === null) continue;
38
33
  request.params = result;
39
34
  request.query = Object.fromEntries(new url.URLSearchParams(querystring).entries());
40
35
  return { route, cb };
@@ -52,10 +47,8 @@ var _RouteStore = class _RouteStore extends pieces.Store {
52
47
  pathname = url.substring(0, index);
53
48
  querystring = url.substring(index + 1);
54
49
  }
55
- if (pathname.charCodeAt(0) === slash)
56
- pathname = pathname.substring(1);
57
- if (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash)
58
- pathname = pathname.substring(0, pathname.length - 1);
50
+ if (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);
51
+ if (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);
59
52
  const splits = pathname.split("/");
60
53
  return { splits, querystring };
61
54
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAGhC,SAAS,qBAAmC;AAC5C,SAAS,aAAa;AAEtB,IAAM,QAAQ,IAAI,WAAW,CAAC;AAcvB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,SAAS,CAAC;AAHhC,wBAAgB,SAAQ,IAAI,WAAuD;AAKlF,eAAW,CAAC,MAAM,KAAK;AAAe,WAAK,MAAM,IAAI,QAAQ,IAAI,WAAW,CAAC;AAAA,EAC9E;AAAA,EAEO,MAAM,SAAwC;AACpD,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,OAAO,WAAW,aAAa;AAClC,aAAO;AAAA,IACR;AAGA,UAAM,cAAc,KAAK,MAAM,IAAI,MAAiB;AAGpD,QAAI,OAAO,gBAAgB,aAAa;AACvC,aAAO;AAAA,IACR;AAEA,UAAM,EAAE,QAAQ,YAAY,IAAI,KAAK,SAAS,QAAQ,GAAG;AAEzD,eAAW,CAAC,OAAO,EAAE,KAAK,YAAY,QAAQ,GAAG;AAChD,YAAM,SAAS,MAAM,OAAO,MAAM,MAAM;AACxC,UAAI,WAAW;AAAM;AAErB,cAAQ,SAAS;AACjB,cAAQ,QAAQ,OAAO,YAAY,IAAI,gBAAgB,WAAW,EAAE,QAAQ,CAAC;AAE7E,aAAO,EAAE,OAAO,GAAG;AAAA,IACpB;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,SAAS,MAAM,IAAI;AAC1B,UAAM,QAAQ,IAAI,QAAQ,GAAG;AAG7B,QAAI;AACJ,QAAI;AAEJ,QAAI,UAAU,IAAI;AACjB,iBAAW;AACX,oBAAc;AAAA,IACf,OAAO;AACN,iBAAW,IAAI,UAAU,GAAG,KAAK;AACjC,oBAAc,IAAI,UAAU,QAAQ,CAAC;AAAA,IACtC;AAEA,QAAI,SAAS,WAAW,CAAC,MAAM;AAAO,iBAAW,SAAS,UAAU,CAAC;AACrE,QAAI,SAAS,SAAS,KAAK,SAAS,WAAW,SAAS,SAAS,CAAC,MAAM;AAAO,iBAAW,SAAS,UAAU,GAAG,SAAS,SAAS,CAAC;AAEnI,UAAM,SAAS,SAAS,MAAM,GAAG;AAEjC,WAAO,EAAE,QAAQ,YAAY;AAAA,EAC9B;AACD;AA9DuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Collection } from 'discord.js';\nimport { URLSearchParams } from 'url';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport { Route } from './Route';\n\nconst slash = '/'.charCodeAt(0);\n\nexport interface MethodCallback {\n\t(request: ApiRequest, response: ApiResponse): unknown;\n}\n\nexport interface RouteMatch {\n\troute: Route;\n\tcb: MethodCallback;\n}\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly table = new Collection<Methods, Collection<Route, MethodCallback>>();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes' });\n\n\t\tfor (const [method] of methodEntries) this.table.set(method, new Collection());\n\t}\n\n\tpublic match(request: ApiRequest): RouteMatch | null {\n\t\tconst { method } = request;\n\n\t\t// If there is no method, we can't match a route so return null\n\t\tif (typeof method === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We get all the methods that are tied to the provided method to have a smaller list to filter through\n\t\tconst methodTable = this.table.get(method as Methods);\n\n\t\t// If there are no methods of the provided type then we won't find any route so we return null\n\t\tif (typeof methodTable === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { splits, querystring } = this.parseURL(request.url);\n\n\t\tfor (const [route, cb] of methodTable.entries()) {\n\t\t\tconst result = route.router.match(splits);\n\t\t\tif (result === null) continue;\n\n\t\t\trequest.params = result;\n\t\t\trequest.query = Object.fromEntries(new URLSearchParams(querystring).entries());\n\n\t\t\treturn { route, cb };\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate parseURL(url = '') {\n\t\tconst index = url.indexOf('?');\n\n\t\t/* eslint-disable @typescript-eslint/init-declarations */\n\t\tlet pathname: string;\n\t\tlet querystring: string;\n\t\t/* eslint-enable @typescript-eslint/init-declarations */\n\t\tif (index === -1) {\n\t\t\tpathname = url;\n\t\t\tquerystring = '';\n\t\t} else {\n\t\t\tpathname = url.substring(0, index);\n\t\t\tquerystring = url.substring(index + 1);\n\t\t}\n\n\t\tif (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);\n\t\tif (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);\n\n\t\tconst splits = pathname.split('/');\n\n\t\treturn { splits, querystring };\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAGhC,SAAS,qBAAmC;AAC5C,SAAS,aAAa;AAEtB,IAAM,QAAQ,IAAI,WAAW,CAAC;AAcvB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,SAAS,CAAC;AAHhC,wBAAgB,SAAQ,IAAI,WAAuD;AAKlF,eAAW,CAAC,MAAM,KAAK,cAAe,MAAK,MAAM,IAAI,QAAQ,IAAI,WAAW,CAAC;AAAA,EAC9E;AAAA,EAEO,MAAM,SAAwC;AACpD,UAAM,EAAE,OAAO,IAAI;AAGnB,QAAI,OAAO,WAAW,aAAa;AAClC,aAAO;AAAA,IACR;AAGA,UAAM,cAAc,KAAK,MAAM,IAAI,MAAiB;AAGpD,QAAI,OAAO,gBAAgB,aAAa;AACvC,aAAO;AAAA,IACR;AAEA,UAAM,EAAE,QAAQ,YAAY,IAAI,KAAK,SAAS,QAAQ,GAAG;AAEzD,eAAW,CAAC,OAAO,EAAE,KAAK,YAAY,QAAQ,GAAG;AAChD,YAAM,SAAS,MAAM,OAAO,MAAM,MAAM;AACxC,UAAI,WAAW,KAAM;AAErB,cAAQ,SAAS;AACjB,cAAQ,QAAQ,OAAO,YAAY,IAAI,gBAAgB,WAAW,EAAE,QAAQ,CAAC;AAE7E,aAAO,EAAE,OAAO,GAAG;AAAA,IACpB;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,SAAS,MAAM,IAAI;AAC1B,UAAM,QAAQ,IAAI,QAAQ,GAAG;AAG7B,QAAI;AACJ,QAAI;AAEJ,QAAI,UAAU,IAAI;AACjB,iBAAW;AACX,oBAAc;AAAA,IACf,OAAO;AACN,iBAAW,IAAI,UAAU,GAAG,KAAK;AACjC,oBAAc,IAAI,UAAU,QAAQ,CAAC;AAAA,IACtC;AAEA,QAAI,SAAS,WAAW,CAAC,MAAM,MAAO,YAAW,SAAS,UAAU,CAAC;AACrE,QAAI,SAAS,SAAS,KAAK,SAAS,WAAW,SAAS,SAAS,CAAC,MAAM,MAAO,YAAW,SAAS,UAAU,GAAG,SAAS,SAAS,CAAC;AAEnI,UAAM,SAAS,SAAS,MAAM,GAAG;AAEjC,WAAO,EAAE,QAAQ,YAAY;AAAA,EAC9B;AACD;AA9DuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Collection } from 'discord.js';\nimport { URLSearchParams } from 'url';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport { methodEntries, type Methods } from './http/HttpMethods';\nimport { Route } from './Route';\n\nconst slash = '/'.charCodeAt(0);\n\nexport interface MethodCallback {\n\t(request: ApiRequest, response: ApiResponse): unknown;\n}\n\nexport interface RouteMatch {\n\troute: Route;\n\tcb: MethodCallback;\n}\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly table = new Collection<Methods, Collection<Route, MethodCallback>>();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes' });\n\n\t\tfor (const [method] of methodEntries) this.table.set(method, new Collection());\n\t}\n\n\tpublic match(request: ApiRequest): RouteMatch | null {\n\t\tconst { method } = request;\n\n\t\t// If there is no method, we can't match a route so return null\n\t\tif (typeof method === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\t// We get all the methods that are tied to the provided method to have a smaller list to filter through\n\t\tconst methodTable = this.table.get(method as Methods);\n\n\t\t// If there are no methods of the provided type then we won't find any route so we return null\n\t\tif (typeof methodTable === 'undefined') {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { splits, querystring } = this.parseURL(request.url);\n\n\t\tfor (const [route, cb] of methodTable.entries()) {\n\t\t\tconst result = route.router.match(splits);\n\t\t\tif (result === null) continue;\n\n\t\t\trequest.params = result;\n\t\t\trequest.query = Object.fromEntries(new URLSearchParams(querystring).entries());\n\n\t\t\treturn { route, cb };\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate parseURL(url = '') {\n\t\tconst index = url.indexOf('?');\n\n\t\t/* eslint-disable @typescript-eslint/init-declarations */\n\t\tlet pathname: string;\n\t\tlet querystring: string;\n\t\t/* eslint-enable @typescript-eslint/init-declarations */\n\t\tif (index === -1) {\n\t\t\tpathname = url;\n\t\t\tquerystring = '';\n\t\t} else {\n\t\t\tpathname = url.substring(0, index);\n\t\t\tquerystring = url.substring(index + 1);\n\t\t}\n\n\t\tif (pathname.charCodeAt(0) === slash) pathname = pathname.substring(1);\n\t\tif (pathname.length > 0 && pathname.charCodeAt(pathname.length - 1) === slash) pathname = pathname.substring(0, pathname.length - 1);\n\n\t\tconst splits = pathname.split('/');\n\n\t\treturn { splits, querystring };\n\t}\n}\n"]}
@@ -5,10 +5,7 @@ var http = require('http');
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- return value;
11
- };
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
9
  var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
13
10
  constructor() {
14
11
  super(...arguments);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,uBAAuB;AAGzB,IAAM,cAAN,MAAM,oBAAmB,gBAAgB;AAAA,EAAzC;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO,SAA2C,CAAC;AAKnD;AAAA;AAAA;AAAA,wBAAO,UAAiC,CAAC;AAKzC;AAAA;AAAA;AAAA,wBAAO;AASP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAAA;AACR;AAxBgD;AAAzC,IAAM,aAAN","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { AuthData } from '../http/Auth';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The body that was sent by the user.\n\t */\n\tpublic body?: unknown;\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,uBAAuB;AAGzB,IAAM,cAAN,MAAM,oBAAmB,gBAAgB;AAAA,EAAzC;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO,SAA2C,CAAC;AAKnD;AAAA;AAAA;AAAA,wBAAO,UAAiC,CAAC;AAKzC;AAAA;AAAA;AAAA,wBAAO;AASP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAAA;AACR;AAxBgD;AAAzC,IAAM,aAAN","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { AuthData } from '../http/Auth';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The body that was sent by the user.\n\t */\n\tpublic body?: unknown;\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n}\n"]}
@@ -9,10 +9,7 @@ var HttpCodes_cjs = require('../http/HttpCodes.cjs');
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var __publicField = (obj, key, value) => {
13
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
- return value;
15
- };
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
13
  var _ApiResponse = class _ApiResponse extends http.ServerResponse {
17
14
  constructor() {
18
15
  super(...arguments);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAA0B,gBAAgB,oBAAoB;AAC9D,SAAS,gBAAgB;AACzB,OAA+B;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAMnB,IAAM,eAAN,MAAM,qBAAuE,eAAwB;AAAA,EAArG;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,GAAG,OAAgB,aAAa,UAAU,EAAE,GAAS;AAC3D,SAAK,OAAO,UAAU,EAAE;AACxB,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,QAAQ,OAAgB,aAAa,UAAU,OAAO,GAAS;AACrE,SAAK,OAAO,UAAU,OAAO;AAC7B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,OAAgB,aAAa,UAAU,SAAS,GAAS;AACzE,SAAK,OAAO,UAAU,SAAS;AAC/B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW,MAAsB;AACvC,WAAO,KAAK,MAAM,UAAU,YAAY,IAAI;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA,EAKO,aAAa,MAAsB;AACzC,WAAO,KAAK,MAAM,UAAU,cAAc,IAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,MAAsB;AACtC,WAAO,KAAK,MAAM,UAAU,WAAW,IAAI;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKO,SAAS,MAAsB;AACrC,WAAO,KAAK,MAAM,UAAU,UAAU,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKO,SAAS,MAAgB;AAC/B,WAAO,KAAK,MAAM,UAAU,UAAU,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKO,MAAM,OAAwB,MAAsB;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC9B,aAAO,KAAK,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,MAAM,CAAC;AAAA,IACjE;AAEA,WAAO,KAAK,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,QAAQ,aAAa,KAAK,EAAE,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA,EAKO,QAAQ,MAAqB;AACnC,WAAO,OAAO,SAAS,WAAW,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKO,OAAO,MAAoB;AACjC,SAAK,aAAa;AAClB,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAiB;AAC5B,SAAK,eAAe,UAAU,eAAe,EAAE,IAAI,KAAK,UAAU,IAAI,CAAC;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAoB;AAC/B,SAAK,eAAe,UAAU,SAAS,EAAE,IAAI,IAAI;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,MACN,MACA,MACO;AACP,QAAI,gBAAgB,UAAU;AAC7B,WAAK,eAAe,IAAI;AACxB,WAAK,KAAK,IAAI;AAAA,IACf,OAAO;AACN,WAAK,eAAe,IAAI,EAAE,IAAI,IAAI;AAAA,IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAc,MAAoB;AAC7C,SAAK,eAAe,UAAU,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,IAAI;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe,aAA8B;AACnD,SAAK,UAAU,gBAAgB,WAAW;AAC1C,WAAO;AAAA,EACR;AACD;AA3I4G;AAArG,IAAM,cAAN","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport { MimeTypes } from '../../utils/MimeTypes';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType(MimeTypes.TextPlain).end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(\n\t\ttype: MimeTypes.ImageGif | MimeTypes.ImageJpg | MimeTypes.ImagePng | MimeTypes.ImageWebp | MimeTypes.ImageXIcon,\n\t\tdata: string | Buffer | Uint8Array | Readable\n\t): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType(MimeTypes.TextHtml).status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeTypes): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":";;;;;;AAAA,SAA0B,gBAAgB,oBAAoB;AAC9D,SAAS,gBAAgB;AACzB,OAA+B;AAC/B,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;AAMnB,IAAM,eAAN,MAAM,qBAAuE,eAAwB;AAAA,EAArG;AAAA;AAIN;AAAA;AAAA;AAAA,wBAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,GAAG,OAAgB,aAAa,UAAU,EAAE,GAAS;AAC3D,SAAK,OAAO,UAAU,EAAE;AACxB,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,QAAQ,OAAgB,aAAa,UAAU,OAAO,GAAS;AACrE,SAAK,OAAO,UAAU,OAAO;AAC7B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,OAAgB,aAAa,UAAU,SAAS,GAAS;AACzE,SAAK,OAAO,UAAU,SAAS;AAC/B,WAAO,KAAK,QAAQ,IAAI;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA,EAKO,WAAW,MAAsB;AACvC,WAAO,KAAK,MAAM,UAAU,YAAY,IAAI;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA,EAKO,aAAa,MAAsB;AACzC,WAAO,KAAK,MAAM,UAAU,cAAc,IAAI;AAAA,EAC/C;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,MAAsB;AACtC,WAAO,KAAK,MAAM,UAAU,WAAW,IAAI;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKO,SAAS,MAAsB;AACrC,WAAO,KAAK,MAAM,UAAU,UAAU,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKO,SAAS,MAAgB;AAC/B,WAAO,KAAK,MAAM,UAAU,UAAU,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKO,MAAM,OAAwB,MAAsB;AAC1D,QAAI,OAAO,UAAU,UAAU;AAC9B,aAAO,KAAK,OAAO,UAAU,mBAAmB,EAAE,KAAK,EAAE,MAAM,CAAC;AAAA,IACjE;AAEA,WAAO,KAAK,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,QAAQ,aAAa,KAAK,EAAE,CAAC;AAAA,EACtE;AAAA;AAAA;AAAA;AAAA,EAKO,QAAQ,MAAqB;AACnC,WAAO,OAAO,SAAS,WAAW,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAKO,OAAO,MAAoB;AACjC,SAAK,aAAa;AAClB,WAAO;AAAA,EACR;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAiB;AAC5B,SAAK,eAAe,UAAU,eAAe,EAAE,IAAI,KAAK,UAAU,IAAI,CAAC;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAoB;AAC/B,SAAK,eAAe,UAAU,SAAS,EAAE,IAAI,IAAI;AAAA,EAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,MACN,MACA,MACO;AACP,QAAI,gBAAgB,UAAU;AAC7B,WAAK,eAAe,IAAI;AACxB,WAAK,KAAK,IAAI;AAAA,IACf,OAAO;AACN,WAAK,eAAe,IAAI,EAAE,IAAI,IAAI;AAAA,IACnC;AAAA,EACD;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,MAAc,MAAoB;AAC7C,SAAK,eAAe,UAAU,QAAQ,EAAE,OAAO,IAAI,EAAE,IAAI,IAAI;AAAA,EAC9D;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe,aAA8B;AACnD,SAAK,UAAU,gBAAgB,WAAW;AAC1C,WAAO;AAAA,EACR;AACD;AA3I4G;AAArG,IAAM,cAAN","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport { MimeTypes } from '../../utils/MimeTypes';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType(MimeTypes.TextPlain).end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(\n\t\ttype: MimeTypes.ImageGif | MimeTypes.ImageJpg | MimeTypes.ImagePng | MimeTypes.ImageWebp | MimeTypes.ImageXIcon,\n\t\tdata: string | Buffer | Uint8Array | Readable\n\t): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType(MimeTypes.TextHtml).status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeTypes): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
@@ -5,10 +5,7 @@ var tldts = require('tldts');
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __publicField = (obj, key, value) => {
9
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
- return value;
11
- };
8
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
9
  var _CookieStore = class _CookieStore extends Map {
13
10
  constructor(request, response, secure, domainOverwrite) {
14
11
  super();
@@ -22,8 +19,7 @@ var _CookieStore = class _CookieStore extends Map {
22
19
  const pairs = cookie.split(";");
23
20
  for (const pair of pairs) {
24
21
  const index = pair.indexOf("=");
25
- if (index === -1)
26
- continue;
22
+ if (index === -1) continue;
27
23
  const key = decodeURIComponent(pair.substr(0, index).trim());
28
24
  const value = decodeURIComponent(pair.substr(index + 1).trim());
29
25
  this.set(key, value);
@@ -85,8 +81,7 @@ var _CookieStore = class _CookieStore extends Map {
85
81
  getHostDomain(host) {
86
82
  const lowercaseHost = host.toLowerCase();
87
83
  const tldParsedInfo = tldts.getDomain(lowercaseHost);
88
- if (!tldParsedInfo)
89
- return lowercaseHost;
84
+ if (!tldParsedInfo) return lowercaseHost;
90
85
  return `.${tldParsedInfo}`;
91
86
  }
92
87
  static encodeCookieOctet(value) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) 2018 Stanislav Woodger. All rights reserved. MIT license.\n// Source: https://github.com/woodger/cookie-httponly\n\nimport { getDomain } from 'tldts';\nimport type { ApiRequest } from './ApiRequest';\nimport type { ApiResponse } from './ApiResponse';\n\nexport class CookieStore extends Map<string, string> {\n\tprotected request: ApiRequest;\n\tprotected response: ApiResponse;\n\tprivate domain: string;\n\tprivate secure: boolean;\n\n\tpublic constructor(request: ApiRequest, response: ApiResponse, secure: boolean, domainOverwrite?: string | null) {\n\t\tsuper();\n\n\t\tthis.request = request;\n\t\tthis.response = response;\n\n\t\t// Read cookies\n\t\tconst { cookie = '' } = request.headers;\n\t\tconst pairs = cookie.split(';');\n\n\t\tfor (const pair of pairs) {\n\t\t\tconst index = pair.indexOf('=');\n\t\t\tif (index === -1) continue;\n\n\t\t\tconst key = decodeURIComponent(pair.substr(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.substr(index + 1).trim());\n\t\t\tthis.set(key, value);\n\t\t}\n\n\t\tconst [splitHost] = this.request.headers.host?.split(':') ?? [''];\n\n\t\tthis.domain = domainOverwrite ?? this.getHostDomain(splitHost);\n\n\t\tif (this.request.socket.remoteAddress === this.domain) {\n\t\t\tthrow new Error('The connection must be established from the domain name (i.e., not an IP address)');\n\t\t}\n\n\t\t// RFC 6265 4.1.2.5. The Secure Attribute\n\t\tthis.secure = secure;\n\t}\n\n\tpublic add(name: string, value: string, options?: SecureCookieStoreSetOptions) {\n\t\tthis.insert(name, this.prepare(name, value, options));\n\t}\n\n\tpublic remove(name: string) {\n\t\tthis.add(name, '', { expires: new Date(0) });\n\t}\n\n\tprotected insert(name: string, entry: string) {\n\t\tlet set = this.response.getHeader('Set-Cookie');\n\n\t\tif (set === undefined) {\n\t\t\tset = [];\n\t\t} else if (!Array.isArray(set)) {\n\t\t\tset = [set.toString()];\n\t\t}\n\n\t\tset = set.filter((i) => i.substr(0, i.indexOf('=')) !== name);\n\t\tset.push(entry);\n\n\t\tthis.response.setHeader('Set-Cookie', set);\n\t}\n\n\tprotected prepare(name: string, value: string, { expires, maxAge, domain, path, httpOnly }: SecureCookieStoreSetOptions = {}) {\n\t\tconst now = new Date();\n\n\t\tif (expires === undefined) {\n\t\t\texpires = now;\n\t\t}\n\n\t\t// RFC 6265 4.1.1. Syntax\n\t\tname = CookieStore.encodeCookieOctet(name);\n\t\tvalue = CookieStore.encodeCookieOctet(value);\n\n\t\tlet entry = `${name}=${value}`;\n\n\t\tif (expires !== now) {\n\t\t\tentry += `; Expires=${expires.toUTCString()}`;\n\t\t} else if (maxAge) {\n\t\t\tentry += `; Max-Age=${maxAge}`;\n\t\t}\n\n\t\t// RFC 6265 5.1.3 Domain Matching\n\t\tdomain = (domain ?? this.domain).toLowerCase();\n\n\t\tentry += `; Domain=${domain}`;\n\t\tentry += `; Path=${path ?? '/'}`;\n\n\t\tif (this.secure) {\n\t\t\tentry += `; Secure`;\n\t\t}\n\n\t\tif (httpOnly ?? true) {\n\t\t\tentry += `; HttpOnly`;\n\t\t}\n\n\t\treturn entry;\n\t}\n\n\t/**\n\t * Parses a host using the {@linkplain https://github.com/remusao/tldts tldts} library to extract the domain.\n\t * This is used for the domain of the cookie\n\t * @param host The hot to parse\n\t * @returns Either the host in all lower case or the parsed domain, ready for use on cookies\n\t */\n\tprivate getHostDomain(host: string): string {\n\t\t// Transform the host to lower case\n\t\tconst lowercaseHost = host.toLowerCase();\n\n\t\t// Try parsing the host with tldts\n\t\tconst tldParsedInfo = getDomain(lowercaseHost);\n\n\t\t// If the domain is not defined then return the host in lowercase\n\t\tif (!tldParsedInfo) return lowercaseHost;\n\n\t\t// If the domain was found from parsing then prefix it with a . for a cookie that works with subdomains and return it\n\t\treturn `.${tldParsedInfo}`;\n\t}\n\n\t// RFC 6265 4.1.1. Syntax\n\tprivate static readonly octetRegExp = /[^\\x21\\x23-\\x2B\\x2D-\\x3A\\x3C-\\x5B\\x5D-\\x7E]/g;\n\n\tprivate static encodeCookieOctet(value: string) {\n\t\tif (CookieStore.octetRegExp.test(value)) {\n\t\t\tthrow new Error(`Invalid character in value`);\n\t\t}\n\n\t\treturn encodeURIComponent(value);\n\t}\n}\n\nexport interface SecureCookieStoreSetOptions {\n\texpires?: Date;\n\tmaxAge?: number;\n\tdomain?: string;\n\tpath?: string;\n\thttpOnly?: boolean;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":[],"mappings":"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","sourcesContent":["// Copyright (c) 2018 Stanislav Woodger. All rights reserved. MIT license.\n// Source: https://github.com/woodger/cookie-httponly\n\nimport { getDomain } from 'tldts';\nimport type { ApiRequest } from './ApiRequest';\nimport type { ApiResponse } from './ApiResponse';\n\nexport class CookieStore extends Map<string, string> {\n\tprotected request: ApiRequest;\n\tprotected response: ApiResponse;\n\tprivate domain: string;\n\tprivate secure: boolean;\n\n\tpublic constructor(request: ApiRequest, response: ApiResponse, secure: boolean, domainOverwrite?: string | null) {\n\t\tsuper();\n\n\t\tthis.request = request;\n\t\tthis.response = response;\n\n\t\t// Read cookies\n\t\tconst { cookie = '' } = request.headers;\n\t\tconst pairs = cookie.split(';');\n\n\t\tfor (const pair of pairs) {\n\t\t\tconst index = pair.indexOf('=');\n\t\t\tif (index === -1) continue;\n\n\t\t\tconst key = decodeURIComponent(pair.substr(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.substr(index + 1).trim());\n\t\t\tthis.set(key, value);\n\t\t}\n\n\t\tconst [splitHost] = this.request.headers.host?.split(':') ?? [''];\n\n\t\tthis.domain = domainOverwrite ?? this.getHostDomain(splitHost);\n\n\t\tif (this.request.socket.remoteAddress === this.domain) {\n\t\t\tthrow new Error('The connection must be established from the domain name (i.e., not an IP address)');\n\t\t}\n\n\t\t// RFC 6265 4.1.2.5. The Secure Attribute\n\t\tthis.secure = secure;\n\t}\n\n\tpublic add(name: string, value: string, options?: SecureCookieStoreSetOptions) {\n\t\tthis.insert(name, this.prepare(name, value, options));\n\t}\n\n\tpublic remove(name: string) {\n\t\tthis.add(name, '', { expires: new Date(0) });\n\t}\n\n\tprotected insert(name: string, entry: string) {\n\t\tlet set = this.response.getHeader('Set-Cookie');\n\n\t\tif (set === undefined) {\n\t\t\tset = [];\n\t\t} else if (!Array.isArray(set)) {\n\t\t\tset = [set.toString()];\n\t\t}\n\n\t\tset = set.filter((i) => i.substr(0, i.indexOf('=')) !== name);\n\t\tset.push(entry);\n\n\t\tthis.response.setHeader('Set-Cookie', set);\n\t}\n\n\tprotected prepare(name: string, value: string, { expires, maxAge, domain, path, httpOnly }: SecureCookieStoreSetOptions = {}) {\n\t\tconst now = new Date();\n\n\t\tif (expires === undefined) {\n\t\t\texpires = now;\n\t\t}\n\n\t\t// RFC 6265 4.1.1. Syntax\n\t\tname = CookieStore.encodeCookieOctet(name);\n\t\tvalue = CookieStore.encodeCookieOctet(value);\n\n\t\tlet entry = `${name}=${value}`;\n\n\t\tif (expires !== now) {\n\t\t\tentry += `; Expires=${expires.toUTCString()}`;\n\t\t} else if (maxAge) {\n\t\t\tentry += `; Max-Age=${maxAge}`;\n\t\t}\n\n\t\t// RFC 6265 5.1.3 Domain Matching\n\t\tdomain = (domain ?? this.domain).toLowerCase();\n\n\t\tentry += `; Domain=${domain}`;\n\t\tentry += `; Path=${path ?? '/'}`;\n\n\t\tif (this.secure) {\n\t\t\tentry += `; Secure`;\n\t\t}\n\n\t\tif (httpOnly ?? true) {\n\t\t\tentry += `; HttpOnly`;\n\t\t}\n\n\t\treturn entry;\n\t}\n\n\t/**\n\t * Parses a host using the {@linkplain https://github.com/remusao/tldts tldts} library to extract the domain.\n\t * This is used for the domain of the cookie\n\t * @param host The hot to parse\n\t * @returns Either the host in all lower case or the parsed domain, ready for use on cookies\n\t */\n\tprivate getHostDomain(host: string): string {\n\t\t// Transform the host to lower case\n\t\tconst lowercaseHost = host.toLowerCase();\n\n\t\t// Try parsing the host with tldts\n\t\tconst tldParsedInfo = getDomain(lowercaseHost);\n\n\t\t// If the domain is not defined then return the host in lowercase\n\t\tif (!tldParsedInfo) return lowercaseHost;\n\n\t\t// If the domain was found from parsing then prefix it with a . for a cookie that works with subdomains and return it\n\t\treturn `.${tldParsedInfo}`;\n\t}\n\n\t// RFC 6265 4.1.1. Syntax\n\tprivate static readonly octetRegExp = /[^\\x21\\x23-\\x2B\\x2D-\\x3A\\x3C-\\x5B\\x5D-\\x7E]/g;\n\n\tprivate static encodeCookieOctet(value: string) {\n\t\tif (CookieStore.octetRegExp.test(value)) {\n\t\t\tthrow new Error(`Invalid character in value`);\n\t\t}\n\n\t\treturn encodeURIComponent(value);\n\t}\n}\n\nexport interface SecureCookieStoreSetOptions {\n\texpires?: Date;\n\tmaxAge?: number;\n\tdomain?: string;\n\tpath?: string;\n\thttpOnly?: boolean;\n}\n"]}
@@ -6,30 +6,16 @@ var discord_js = require('discord.js');
6
6
  var undici = require('undici');
7
7
 
8
8
  var __defProp = Object.defineProperty;
9
+ var __typeError = (msg) => {
10
+ throw TypeError(msg);
11
+ };
9
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
13
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
11
- var __publicField = (obj, key, value) => {
12
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
- return value;
14
- };
15
- var __accessCheck = (obj, member, msg) => {
16
- if (!member.has(obj))
17
- throw TypeError("Cannot " + msg);
18
- };
19
- var __privateGet = (obj, member, getter) => {
20
- __accessCheck(obj, member, "read from private field");
21
- return getter ? getter.call(obj) : member.get(obj);
22
- };
23
- var __privateAdd = (obj, member, value) => {
24
- if (member.has(obj))
25
- throw TypeError("Cannot add the same private member more than once");
26
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
27
- };
28
- var __privateSet = (obj, member, value, setter) => {
29
- __accessCheck(obj, member, "write to private field");
30
- setter ? setter.call(obj, value) : member.set(obj, value);
31
- return value;
32
- };
14
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
15
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
18
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
33
19
  var _secret;
34
20
  var _Auth = class _Auth {
35
21
  constructor(options) {
@@ -59,7 +45,7 @@ var _Auth = class _Auth {
59
45
  */
60
46
  __publicField(this, "transformers");
61
47
  __publicField(this, "domainOverwrite", null);
62
- __privateAdd(this, _secret, void 0);
48
+ __privateAdd(this, _secret);
63
49
  this.id = options.id;
64
50
  this.cookie = options.cookie ?? "SAPPHIRE_AUTH";
65
51
  this.scopes = options.scopes ?? [discord_js.OAuth2Scopes.Identify];
@@ -118,16 +104,13 @@ var _Auth = class _Auth {
118
104
  let data = { user, guilds, connections };
119
105
  for (const transformer of this.transformers) {
120
106
  const result = transformer(data);
121
- if (utilities.isThenable(result))
122
- data = await result;
123
- else
124
- data = result;
107
+ if (utilities.isThenable(result)) data = await result;
108
+ else data = result;
125
109
  }
126
110
  return data;
127
111
  }
128
112
  async fetchInformation(scope, token, url) {
129
- if (!this.scopes.includes(scope))
130
- return void 0;
113
+ if (!this.scopes.includes(scope)) return void 0;
131
114
  const result = await undici.fetch(url, {
132
115
  headers: {
133
116
  authorization: `Bearer ${token}`
@@ -136,8 +119,7 @@ var _Auth = class _Auth {
136
119
  return result.ok ? await result.json() : null;
137
120
  }
138
121
  static create(options) {
139
- if (!options?.secret || !options.id)
140
- return null;
122
+ if (!options?.secret || !options.id) return null;
141
123
  return new _Auth(options);
142
124
  }
143
125
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":[],"mappings":"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","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id as Snowflake;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":[],"mappings":"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","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id as Snowflake;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
@@ -13,10 +13,7 @@ var Auth_cjs = require('./Auth.cjs');
13
13
  var __defProp = Object.defineProperty;
14
14
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
15
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
- var __publicField = (obj, key, value) => {
17
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
18
- return value;
19
- };
16
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
20
17
  var ServerEvents = /* @__PURE__ */ ((ServerEvents2) => {
21
18
  ServerEvents2["Error"] = "error";
22
19
  ServerEvents2["Request"] = "request";