@sapphire/plugin-api 7.0.0-next.fc8e636 → 7.0.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 (193) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +0 -1
  3. package/dist/cjs/index.cjs +6 -32
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/index.d.cts +91 -109
  6. package/dist/cjs/lib/structures/Augmentations.d.cjs +1 -1
  7. package/dist/cjs/lib/structures/Augmentations.d.cjs.map +1 -1
  8. package/dist/cjs/lib/structures/Middleware.cjs +2 -2
  9. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  10. package/dist/cjs/lib/structures/MiddlewareStore.cjs +2 -2
  11. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  12. package/dist/cjs/lib/structures/Route.cjs +5 -10
  13. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  14. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +1 -1
  15. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
  16. package/dist/cjs/lib/structures/RouteStore.cjs +2 -2
  17. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  18. package/dist/cjs/lib/structures/api/ApiRequest.cjs +129 -5
  19. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  20. package/dist/cjs/lib/structures/api/ApiResponse.cjs +6 -7
  21. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  22. package/dist/cjs/lib/structures/api/CookieStore.cjs +1 -1
  23. package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
  24. package/dist/cjs/lib/structures/http/Auth.cjs +2 -2
  25. package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
  26. package/dist/cjs/lib/structures/http/HttpCodes.cjs +1 -1
  27. package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
  28. package/dist/cjs/lib/structures/http/HttpMethods.cjs +2 -1
  29. package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
  30. package/dist/cjs/lib/structures/http/Server.cjs +2 -9
  31. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  32. package/dist/cjs/lib/structures/router/RouterBranch.cjs +1 -1
  33. package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -1
  34. package/dist/cjs/lib/structures/router/RouterNode.cjs +2 -2
  35. package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -1
  36. package/dist/cjs/lib/structures/router/RouterRoot.cjs +12 -2
  37. package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -1
  38. package/dist/cjs/lib/utils/MimeType.cjs +4 -0
  39. package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
  40. package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs +100 -0
  41. package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs.map +1 -0
  42. package/dist/cjs/lib/utils/_body/RequestProxy.cjs +124 -0
  43. package/dist/cjs/lib/utils/_body/RequestProxy.cjs.map +1 -0
  44. package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs +179 -0
  45. package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs.map +1 -0
  46. package/dist/cjs/lib/utils/constants.cjs +8 -0
  47. package/dist/cjs/lib/utils/constants.cjs.map +1 -0
  48. package/dist/cjs/listeners/PluginRouteError.cjs +1 -1
  49. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  50. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +1 -1
  51. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  52. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +1 -1
  53. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
  54. package/dist/cjs/listeners/PluginServerRequest.cjs +2 -2
  55. package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
  56. package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs +1 -1
  57. package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -1
  58. package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs +1 -1
  59. package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -1
  60. package/dist/cjs/listeners/PluginServerRouterFound.cjs +3 -2
  61. package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -1
  62. package/dist/cjs/listeners/_load.cjs +1 -1
  63. package/dist/cjs/listeners/_load.cjs.map +1 -1
  64. package/dist/cjs/middlewares/_load.cjs +1 -1
  65. package/dist/cjs/middlewares/_load.cjs.map +1 -1
  66. package/dist/cjs/middlewares/auth.cjs +2 -2
  67. package/dist/cjs/middlewares/auth.cjs.map +1 -1
  68. package/dist/cjs/middlewares/body.cjs +2 -18
  69. package/dist/cjs/middlewares/body.cjs.map +1 -1
  70. package/dist/cjs/middlewares/cookies.cjs +1 -1
  71. package/dist/cjs/middlewares/cookies.cjs.map +1 -1
  72. package/dist/cjs/middlewares/headers.cjs +1 -1
  73. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  74. package/dist/cjs/register.cjs +3 -4
  75. package/dist/cjs/register.cjs.map +1 -1
  76. package/dist/cjs/register.d.cts +0 -1
  77. package/dist/cjs/routes/_load.cjs +1 -1
  78. package/dist/cjs/routes/_load.cjs.map +1 -1
  79. package/dist/cjs/routes/oauth/callback.post.cjs +3 -3
  80. package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -1
  81. package/dist/cjs/routes/oauth/logout.post.cjs +1 -1
  82. package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -1
  83. package/dist/esm/chunk-S573YWRP.mjs +1 -1
  84. package/dist/esm/chunk-S573YWRP.mjs.map +1 -1
  85. package/dist/esm/index.d.mts +91 -109
  86. package/dist/esm/index.mjs +2 -6
  87. package/dist/esm/index.mjs.map +1 -1
  88. package/dist/esm/lib/structures/Augmentations.d.mjs +1 -1
  89. package/dist/esm/lib/structures/Augmentations.d.mjs.map +1 -1
  90. package/dist/esm/lib/structures/Middleware.mjs +1 -1
  91. package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
  92. package/dist/esm/lib/structures/MiddlewareStore.mjs +1 -1
  93. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  94. package/dist/esm/lib/structures/Route.mjs +5 -10
  95. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  96. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +1 -1
  97. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
  98. package/dist/esm/lib/structures/RouteStore.mjs +1 -1
  99. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  100. package/dist/esm/lib/structures/api/ApiRequest.mjs +123 -6
  101. package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
  102. package/dist/esm/lib/structures/api/ApiResponse.mjs +5 -6
  103. package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
  104. package/dist/esm/lib/structures/api/CookieStore.mjs +1 -1
  105. package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
  106. package/dist/esm/lib/structures/http/Auth.mjs +1 -1
  107. package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
  108. package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
  109. package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
  110. package/dist/esm/lib/structures/http/HttpMethods.mjs +2 -1
  111. package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
  112. package/dist/esm/lib/structures/http/Server.mjs +2 -9
  113. package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
  114. package/dist/esm/lib/structures/router/RouterBranch.mjs +1 -1
  115. package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -1
  116. package/dist/esm/lib/structures/router/RouterNode.mjs +1 -1
  117. package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -1
  118. package/dist/esm/lib/structures/router/RouterRoot.mjs +12 -2
  119. package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -1
  120. package/dist/esm/lib/utils/MimeType.mjs +3 -0
  121. package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
  122. package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs +95 -0
  123. package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs.map +1 -0
  124. package/dist/esm/lib/utils/_body/RequestProxy.mjs +112 -0
  125. package/dist/esm/lib/utils/_body/RequestProxy.mjs.map +1 -0
  126. package/dist/esm/lib/utils/_body/RequestURLProxy.mjs +167 -0
  127. package/dist/esm/lib/utils/_body/RequestURLProxy.mjs.map +1 -0
  128. package/dist/esm/lib/utils/constants.mjs +8 -0
  129. package/dist/esm/lib/utils/constants.mjs.map +1 -0
  130. package/dist/esm/listeners/PluginRouteError.mjs +1 -1
  131. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  132. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +1 -1
  133. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  134. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +1 -1
  135. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
  136. package/dist/esm/listeners/PluginServerRequest.mjs +2 -2
  137. package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
  138. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +1 -1
  139. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -1
  140. package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs +1 -1
  141. package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -1
  142. package/dist/esm/listeners/PluginServerRouterFound.mjs +3 -2
  143. package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -1
  144. package/dist/esm/listeners/_load.mjs +1 -1
  145. package/dist/esm/listeners/_load.mjs.map +1 -1
  146. package/dist/esm/middlewares/_load.mjs +1 -1
  147. package/dist/esm/middlewares/_load.mjs.map +1 -1
  148. package/dist/esm/middlewares/auth.mjs +1 -1
  149. package/dist/esm/middlewares/auth.mjs.map +1 -1
  150. package/dist/esm/middlewares/body.mjs +3 -17
  151. package/dist/esm/middlewares/body.mjs.map +1 -1
  152. package/dist/esm/middlewares/cookies.mjs +1 -1
  153. package/dist/esm/middlewares/cookies.mjs.map +1 -1
  154. package/dist/esm/middlewares/headers.mjs +1 -1
  155. package/dist/esm/middlewares/headers.mjs.map +1 -1
  156. package/dist/esm/register.d.mts +0 -1
  157. package/dist/esm/register.mjs +3 -4
  158. package/dist/esm/register.mjs.map +1 -1
  159. package/dist/esm/routes/_load.mjs +1 -1
  160. package/dist/esm/routes/_load.mjs.map +1 -1
  161. package/dist/esm/routes/oauth/callback.post.mjs +2 -2
  162. package/dist/esm/routes/oauth/callback.post.mjs.map +1 -1
  163. package/dist/esm/routes/oauth/logout.post.mjs +1 -1
  164. package/dist/esm/routes/oauth/logout.post.mjs.map +1 -1
  165. package/package.json +14 -12
  166. package/dist/cjs/lib/structures/MediaParser.cjs +0 -79
  167. package/dist/cjs/lib/structures/MediaParser.cjs.map +0 -1
  168. package/dist/cjs/lib/structures/MediaParserStore.cjs +0 -27
  169. package/dist/cjs/lib/structures/MediaParserStore.cjs.map +0 -1
  170. package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
  171. package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
  172. package/dist/cjs/mediaParsers/_load.cjs +0 -20
  173. package/dist/cjs/mediaParsers/_load.cjs.map +0 -1
  174. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +0 -23
  175. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +0 -1
  176. package/dist/cjs/mediaParsers/applicationJson.cjs +0 -22
  177. package/dist/cjs/mediaParsers/applicationJson.cjs.map +0 -1
  178. package/dist/cjs/mediaParsers/textPlain.cjs +0 -22
  179. package/dist/cjs/mediaParsers/textPlain.cjs.map +0 -1
  180. package/dist/esm/lib/structures/MediaParser.mjs +0 -76
  181. package/dist/esm/lib/structures/MediaParser.mjs.map +0 -1
  182. package/dist/esm/lib/structures/MediaParserStore.mjs +0 -24
  183. package/dist/esm/lib/structures/MediaParserStore.mjs.map +0 -1
  184. package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
  185. package/dist/esm/lib/utils/MimeTypes.mjs.map +0 -1
  186. package/dist/esm/mediaParsers/_load.mjs +0 -17
  187. package/dist/esm/mediaParsers/_load.mjs.map +0 -1
  188. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +0 -20
  189. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +0 -1
  190. package/dist/esm/mediaParsers/applicationJson.mjs +0 -19
  191. package/dist/esm/mediaParsers/applicationJson.mjs.map +0 -1
  192. package/dist/esm/mediaParsers/textPlain.mjs +0 -19
  193. package/dist/esm/mediaParsers/textPlain.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,kBAAkB;AAKpB,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,SAA6B,UAA8C;AAC3F,eAAW,cAAc,KAAK,mBAAmB;AAChD,UAAI,SAAS,cAAe;AAC5B,UAAI,WAAW,QAAS,OAAM,WAAW,IAAI,SAAS,QAAQ;AAAA,IAC/D;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';\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: Middleware.Request, response: Middleware.Response): 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);\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.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AK,iBAAkB,CAAA,MAAA,CAAO,OAAO,CAAC,CAAA;AAExD,IAAO,OAAA,KAAA,CAAM,OAAO,GAAG,CAAA;AAAA;AACxB,EAEgB,KAAc,GAAA;AAC7B,IAAA,IAAA,CAAK,kBAAkB,MAAS,GAAA,CAAA;AAChC,IAAA,OAAO,MAAM,KAAM,EAAA;AAAA;AAErB,CAAA;AAxCsE,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAA/D,IAAM,eAAN,GAAA","file":"MiddlewareStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\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: Middleware.Request, response: Middleware.Response): 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);\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"]}
@@ -15,10 +15,6 @@ var _Route = class _Route extends pieces.Piece {
15
15
  * (RFC 7230 3.3.2) The maximum decimal number of octets.
16
16
  */
17
17
  __publicField(this, "maximumBodyLength");
18
- /**
19
- * The accepted content types.
20
- */
21
- __publicField(this, "acceptedContentMimeTypes");
22
18
  /**
23
19
  * The path this route represents.
24
20
  */
@@ -28,10 +24,10 @@ var _Route = class _Route extends pieces.Piece {
28
24
  */
29
25
  __publicField(this, "methods");
30
26
  const api = this.container.server.options;
31
- const path = [].concat(
32
- RouterRoot_cjs.RouterRoot.normalize(api.prefix),
33
- RouterRoot_cjs.RouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join("/")))
34
- );
27
+ const path = [
28
+ ...RouterRoot_cjs.RouterRoot.normalize(api.prefix),
29
+ ...RouterRoot_cjs.RouterRoot.normalize(options.route ?? RouterRoot_cjs.RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))
30
+ ];
35
31
  const methods = new Set(options.methods);
36
32
  const implied = RouterRoot_cjs.RouterRoot.extractMethod(path);
37
33
  if (!utilities.isNullish(implied)) {
@@ -42,12 +38,11 @@ var _Route = class _Route extends pieces.Piece {
42
38
  this.path = path;
43
39
  this.methods = methods;
44
40
  this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;
45
- this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;
46
41
  }
47
42
  };
48
43
  __name(_Route, "Route");
49
44
  var Route = _Route;
50
45
 
51
46
  exports.Route = Route;
52
- //# sourceMappingURL=out.js.map
47
+ //# sourceMappingURL=Route.cjs.map
53
48
  //# sourceMappingURL=Route.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,iBAAiC;AAK1C,SAAS,kBAAkB;AAuCpB,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;AAKf,UAAM,MAAM,KAAK,UAAU,OAAO;AAClC,UAAM,OAAQ,CAAC,EAAe;AAAA,MAC7B,WAAW,UAAU,IAAI,MAAM;AAAA,MAC/B,WAAW,UAAU,QAAQ,UAAU,KAAK,SAAS,UAAU,KAAK,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,IAAI,EAAE,KAAK,GAAG,EAAE;AAAA,IAClI;AAEA,UAAM,UAAU,IAAI,IAAI,QAAQ,OAAO;AACvC,UAAM,UAAU,WAAW,cAAc,IAAI;AAC7C,QAAI,CAAC,UAAU,OAAO,GAAG;AACxB,YAAM,YAAY,KAAK,SAAS;AAChC,WAAK,SAAS,IAAI,KAAK,SAAS,EAAE,MAAM,GAAG,KAAK,SAAS,EAAE,SAAS,QAAQ,SAAS,CAAC;AACtF,cAAQ,IAAI,OAAqB;AAAA,IAClC;AAEA,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,oBAAoB,QAAQ,qBAAqB,IAAI,qBAAqB,OAAO,OAAO;AAC7F,SAAK,2BAA2B,QAAQ,4BAA4B,IAAI,4BAA4B;AAAA,EACrG;AAGD;AA7C4G;AAArG,IAAe,QAAf","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n *\n * @example A simple GET route that returns a JSON response:\n * ```typescript\n * // hello.get.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json({ message: 'Hello, World!' });\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl http://localhost:4000/hello\n * {\"message\":\"Hello, World!\"}\n * ```\n *\n * @example A simple POST route that reads the body and returns it:\n * ```typescript\n * // echo.post.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json(request.params);\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\":\"world\"}' http://localhost:4000/echo\n * {\"hello\":\"world\"}\n * ```\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 path this route represents.\n\t */\n\tpublic readonly path: readonly string[];\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods: ReadonlySet<MethodName>;\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\tconst path = ([] as string[]).concat(\n\t\t\tRouterRoot.normalize(api.prefix),\n\t\t\tRouterRoot.normalize(options.route ?? (this.location.virtual ? this.name : this.location.directories.concat(this.name).join('/')))\n\t\t);\n\n\t\tconst methods = new Set(options.methods);\n\t\tconst implied = RouterRoot.extractMethod(path);\n\t\tif (!isNullish(implied)) {\n\t\t\tconst lastIndex = path.length - 1;\n\t\t\tpath[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);\n\t\t\tmethods.add(implied as MethodName);\n\t\t}\n\n\t\tthis.path = path;\n\t\tthis.methods = methods;\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t\tthis.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null;\n\t}\n\n\tpublic abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;\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 *\n\t * @defaultValue The filesystem-based path, or the name if the location is virtual.\n\t *\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 *\n\t * @defaultValue 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 *\n\t * @defaultValue this.context.server.options.acceptedContentMimeTypes ?? null\n\t */\n\tacceptedContentMimeTypes?: readonly MimeTypeWithoutParameters[] | null;\n\n\t/**\n\t * The methods this route accepts.\n\t * @since 7.0.0\n\t *\n\t * @defaultValue The method defined in the piece name, or none if not set.\n\t */\n\tmethods?: readonly MethodName[];\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\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":["Piece","RouterRoot","isNullish"],"mappings":";;;;;;;;;;AA4CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6DA,YAAyB,CAAA;AAAA,EAgBpG,WAAY,CAAA,OAAA,EA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AqB,GAAI,CAAA,iBAAA,IAAqB,OAAO,IAAO,GAAA,EAAA;AAAA;AAI/F,CAAA;AAvC4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA;AAArG,IAAe,KAAf,GAAA","file":"Route.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n *\n * @example A simple GET route that returns a JSON response:\n * ```typescript\n * // hello.get.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json({ message: 'Hello, World!' });\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl http://localhost:4000/hello\n * {\"message\":\"Hello, World!\"}\n * ```\n *\n * @example A simple POST route that reads the body and returns it:\n * ```typescript\n * // echo.post.ts\n * import { Route } from '@sapphire/plugin-api';\n *\n * export class MyRoute extends Route {\n * public run(request: Route.Request, response: Route.Response) {\n * return response.json(request.params);\n * }\n * }\n * ```\n *\n * ```bash\n * $ curl -X POST -H \"Content-Type: application/json\" -d '{\"hello\":\"world\"}' http://localhost:4000/echo\n * {\"hello\":\"world\"}\n * ```\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 path this route represents.\n\t */\n\tpublic readonly path: readonly string[];\n\n\t/**\n\t * The methods this route accepts.\n\t */\n\tpublic readonly methods: ReadonlySet<MethodName>;\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\tconst path = [\n\t\t\t...RouterRoot.normalize(api.prefix),\n\t\t\t...RouterRoot.normalize(options.route ?? RouterRoot.makeRoutePathForPiece(this.location.directories, this.name))\n\t\t];\n\n\t\tconst methods = new Set(options.methods);\n\t\tconst implied = RouterRoot.extractMethod(path);\n\t\tif (!isNullish(implied)) {\n\t\t\tconst lastIndex = path.length - 1;\n\t\t\tpath[lastIndex] = path[lastIndex].slice(0, path[lastIndex].length - implied.length - 1);\n\t\t\tmethods.add(implied);\n\t\t}\n\n\t\tthis.path = path;\n\t\tthis.methods = methods;\n\t\tthis.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50;\n\t}\n\n\tpublic abstract run(request: Route.Request, response: Route.Response): Awaitable<unknown>;\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 *\n\t * @defaultValue The filesystem-based path, or the name if the location is virtual.\n\t *\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 *\n\t * @defaultValue this.context.server.options.maximumBodyLength ?? 1024 * 1024 * 50\n\t */\n\tmaximumBodyLength?: number;\n\n\t/**\n\t * The methods this route accepts.\n\t * @since 7.0.0\n\t *\n\t * @defaultValue The method defined in the piece name, or none if not set.\n\t */\n\tmethods?: readonly MethodName[];\n}\n\nexport namespace Route {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext; // NOSONAR\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\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
@@ -16,5 +16,5 @@ __name(_RouteLoaderStrategy, "RouteLoaderStrategy");
16
16
  var RouteLoaderStrategy = _RouteLoaderStrategy;
17
17
 
18
18
  exports.RouteLoaderStrategy = RouteLoaderStrategy;
19
- //# sourceMappingURL=out.js.map
19
+ //# sourceMappingURL=RouteLoaderStrategy.cjs.map
20
20
  //# sourceMappingURL=RouteLoaderStrategy.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":[],"mappings":";;;;AAAA,SAAS,sBAAsB;AAIxB,IAAM,uBAAN,MAAM,6BAA4B,eAAsB;AAAA,EAC9C,OAAO,OAAmB,OAAoB;AAC7D,UAAM,OAAO,IAAI,KAAK;AAAA,EACvB;AAAA,EAEgB,SAAS,OAAmB,OAAoB;AAC/D,UAAM,OAAO,OAAO,KAAK;AAAA,EAC1B;AACD;AAR+D;AAAxD,IAAM,sBAAN","sourcesContent":["import { LoaderStrategy } from '@sapphire/pieces';\nimport type { Route } from './Route';\nimport type { RouteStore } from './RouteStore';\n\nexport class RouteLoaderStrategy extends LoaderStrategy<Route> {\n\tpublic override onLoad(store: RouteStore, piece: Route): void {\n\t\tstore.router.add(piece);\n\t}\n\n\tpublic override onUnload(store: RouteStore, piece: Route): void {\n\t\tstore.router.remove(piece);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":["LoaderStrategy"],"mappings":";;;;;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,qBAAsB,CAAA;AAAA,EAC9C,MAAA,CAAO,OAAmB,KAAoB,EAAA;AAC7D,IAAM,KAAA,CAAA,MAAA,CAAO,IAAI,KAAK,CAAA;AAAA;AACvB,EAEgB,QAAA,CAAS,OAAmB,KAAoB,EAAA;AAC/D,IAAM,KAAA,CAAA,MAAA,CAAO,OAAO,KAAK,CAAA;AAAA;AAE3B,CAAA;AAR+D,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA;AAAxD,IAAM,mBAAN,GAAA","file":"RouteLoaderStrategy.cjs","sourcesContent":["import { LoaderStrategy } from '@sapphire/pieces';\nimport type { Route } from './Route';\nimport type { RouteStore } from './RouteStore';\n\nexport class RouteLoaderStrategy extends LoaderStrategy<Route> {\n\tpublic override onLoad(store: RouteStore, piece: Route): void {\n\t\tstore.router.add(piece);\n\t}\n\n\tpublic override onUnload(store: RouteStore, piece: Route): void {\n\t\tstore.router.remove(piece);\n\t}\n}\n"]}
@@ -8,7 +8,7 @@ var RouterRoot_cjs = require('./router/RouterRoot.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) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
12
12
  var _RouteStore = class _RouteStore extends pieces.Store {
13
13
  constructor() {
14
14
  super(Route_cjs.Route, { name: "routes", strategy: new RouteLoaderStrategy_cjs.RouteLoaderStrategy() });
@@ -19,5 +19,5 @@ __name(_RouteStore, "RouteStore");
19
19
  var RouteStore = _RouteStore;
20
20
 
21
21
  exports.RouteStore = RouteStore;
22
- //# sourceMappingURL=out.js.map
22
+ //# sourceMappingURL=RouteStore.cjs.map
23
23
  //# sourceMappingURL=RouteStore.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,2BAA2B;AACpC,SAAS,kBAAkB;AAKpB,IAAM,cAAN,MAAM,oBAAmB,MAAuB;AAAA,EAG/C,cAAc;AACpB,UAAM,OAAO,EAAE,MAAM,UAAU,UAAU,IAAI,oBAAoB,EAAE,CAAC;AAHrE,wBAAgB,UAAS,IAAI,WAAW;AAAA,EAIxC;AACD;AANuD;AAAhD,IAAM,aAAN","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly router = new RouterRoot();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":["Store","Route","RouteLoaderStrategy","RouterRoot"],"mappings":";;;;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,YAAuB,CAAA;AAAA,EAG/C,WAAc,GAAA;AACpB,IAAM,KAAA,CAAAC,eAAA,EAAO,EAAE,IAAM,EAAA,QAAA,EAAU,UAAU,IAAIC,2CAAA,IAAuB,CAAA;AAHrE,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAIC,yBAAW,EAAA,CAAA;AAAA;AAKzC,CAAA;AANuD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAhD,IAAM,UAAN,GAAA","file":"RouteStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly router = new RouterRoot();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n}\n"]}
@@ -1,14 +1,25 @@
1
1
  'use strict';
2
2
 
3
+ var utilities = require('@sapphire/utilities');
3
4
  var http = require('http');
5
+ var RequestProxy_cjs = require('../../utils/_body/RequestProxy.cjs');
4
6
 
5
7
  var __defProp = Object.defineProperty;
8
+ var __typeError = (msg) => {
9
+ throw TypeError(msg);
10
+ };
6
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
12
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
13
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
15
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
16
+ 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);
17
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
18
+ var _cachedRequest, _ApiRequest_instances, isFormContentType_get;
9
19
  var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
10
20
  constructor() {
11
21
  super(...arguments);
22
+ __privateAdd(this, _ApiRequest_instances);
12
23
  /**
13
24
  * The query parameters.
14
25
  */
@@ -17,10 +28,6 @@ var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
17
28
  * The URI parameters.
18
29
  */
19
30
  __publicField(this, "params", {});
20
- /**
21
- * The body that was sent by the user.
22
- */
23
- __publicField(this, "body");
24
31
  /**
25
32
  * The authorization information. This field indicates three possible values:
26
33
  *
@@ -55,11 +62,128 @@ var _ApiRequest = class _ApiRequest extends http.IncomingMessage {
55
62
  * @since 7.0.0
56
63
  */
57
64
  __publicField(this, "route");
65
+ /**
66
+ * The response object. This field is cached to prevent multiple response
67
+ * objects from being created.
68
+ */
69
+ __privateAdd(this, _cachedRequest, null);
70
+ }
71
+ /**
72
+ * The response object, used to validate the request's headers and body.
73
+ */
74
+ asWeb() {
75
+ __privateGet(this, _cachedRequest) ?? __privateSet(this, _cachedRequest, new RequestProxy_cjs.RequestProxy(this));
76
+ return __privateGet(this, _cachedRequest);
77
+ }
78
+ /**
79
+ * Reads the request body and tries to parse using JSON or form-urlencoded.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const body = await request.readBody();
84
+ * ```
85
+ *
86
+ * @returns The result of the body parsing
87
+ */
88
+ readBody() {
89
+ return __privateGet(this, _ApiRequest_instances, isFormContentType_get) ? this.readBodyFormData() : this.readBodyJson();
90
+ }
91
+ /**
92
+ * Reads the request body as an {@link ArrayBuffer}.
93
+ *
94
+ * @returns The result of the body parsing
95
+ */
96
+ readBodyArrayBuffer() {
97
+ return this.asWeb().arrayBuffer();
98
+ }
99
+ /**
100
+ * Reads the request body as a {@link Blob}.
101
+ *
102
+ * @returns The result of the body parsing
103
+ */
104
+ readBodyBlob() {
105
+ return this.asWeb().blob();
106
+ }
107
+ /**
108
+ * Reads the request body as a {@link FormData}.
109
+ *
110
+ * @remarks
111
+ *
112
+ * This will throw an error if the content type is not one of the following:
113
+ *
114
+ * - `application/x-www-form-urlencoded`
115
+ * - `multipart/form-data`
116
+ *
117
+ * @returns The result of the body parsing
118
+ */
119
+ readBodyFormData() {
120
+ return this.asWeb().formData();
121
+ }
122
+ /**
123
+ * Reads the request body as text, using {@link TextDecoder}. Afterward, it
124
+ * parses the body as JSON with {@link JSON.parse}.
125
+ *
126
+ * @returns The result of the body parsing
127
+ */
128
+ readBodyJson() {
129
+ return this.asWeb().json();
130
+ }
131
+ /**
132
+ * Reads the request body as text, using {@link TextDecoder}.
133
+ *
134
+ * @returns The result of the body parsing
135
+ */
136
+ readBodyText() {
137
+ return this.asWeb().text();
138
+ }
139
+ /**
140
+ * Identical to {@link ApiRequest.readBody}, but it validates the result.
141
+ *
142
+ * @param validator The validator function to use on the body parsing result
143
+ * @returns The validated body
144
+ */
145
+ readValidatedBody(validator) {
146
+ return this.readBody().then(validator);
147
+ }
148
+ /**
149
+ * Identical to {@link ApiRequest.readBodyFormData}, but it validates the
150
+ * result.
151
+ *
152
+ * @param validator The validator function to use on the body parsing result
153
+ * @returns The validated body
154
+ */
155
+ readValidatedBodyFormData(validator) {
156
+ return this.readBodyFormData().then(validator);
157
+ }
158
+ /**
159
+ * Identical to {@link ApiRequest.readBodyJson}, but it validates the result.
160
+ *
161
+ * @param validator The validator function to use on the body parsing result
162
+ * @returns The validated body
163
+ */
164
+ readValidatedBodyJson(validator) {
165
+ return this.readBodyJson().then(validator);
166
+ }
167
+ /**
168
+ * Identical to {@link ApiRequest.readBodyText}, but it validates the result.
169
+ *
170
+ * @param validator The validator function to use on the body parsing result
171
+ * @returns The validated body
172
+ */
173
+ readValidatedBodyText(validator) {
174
+ return this.readBodyText().then(validator);
58
175
  }
59
176
  };
177
+ _cachedRequest = new WeakMap();
178
+ _ApiRequest_instances = new WeakSet();
179
+ isFormContentType_get = /* @__PURE__ */ __name(function() {
180
+ const contentType = this.asWeb().headers.get("content-type");
181
+ if (utilities.isNullishOrEmpty(contentType)) return false;
182
+ return contentType.startsWith("application/x-www-form-urlencoded") || contentType.startsWith("multipart/form-data");
183
+ }, "#isFormContentType");
60
184
  __name(_ApiRequest, "ApiRequest");
61
185
  var ApiRequest = _ApiRequest;
62
186
 
63
187
  exports.ApiRequest = ApiRequest;
64
- //# sourceMappingURL=out.js.map
188
+ //# sourceMappingURL=ApiRequest.cjs.map
65
189
  //# sourceMappingURL=ApiRequest.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,uBAAuB;AAKzB,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;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAO;AAAA;AACR;AApDgD;AAAzC,IAAM,aAAN","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { Route } from '../Route';\nimport type { AuthData } from '../http/Auth';\nimport type { RouterNode } from '../router/RouterNode';\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\t/**\n\t * The router node that matched the request. The field indicates three\n\t * possible values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no node matched the\n\t * request.\n\t * - `RouterNode`: The router handler has been executed and a node matched\n\t * the request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic routerNode?: RouterNode | null;\n\n\t/**\n\t * The route that matched the request. The field indicates three possible\n\t * values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no route matched the\n\t * request.\n\t * - `Route`: The router handler has been executed and a route matched the\n\t * request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic route?: Route | null;\n}\n"]}
1
+ {"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":["IncomingMessage","RequestProxy","isNullishOrEmpty"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,EAAA,qBAAA,EAAA,qBAAA;AAUO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,oBAAgB,CAAA;AAAA,EAAzC,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA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xB,EAAA,MAAM,cAAc,IAAK,CAAA,KAAA,EAAQ,CAAA,OAAA,CAAQ,IAAI,cAAc,CAAA;AAG3D,EAAI,IAAAC,0BAAA,CAAiB,WAAW,CAAA,EAAU,OAAA,KAAA;AAG1C,EAAA,OAAO,YAAY,UAAW,CAAA,mCAAmC,CAAK,IAAA,WAAA,CAAY,WAAW,qBAAqB,CAAA;AACnH,CARsB,EAAA,oBAAA,CAAA;AAtDyB,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA;AAAzC,IAAM,UAAN,GAAA","file":"ApiRequest.cjs","sourcesContent":["import { isNullishOrEmpty } from '@sapphire/utilities';\nimport type { Blob } from 'node:buffer';\nimport { IncomingMessage } from 'node:http';\nimport type { FormData, Request } from 'undici';\nimport type { MimeType } from '../../utils/MimeType';\nimport { RequestProxy } from '../../utils/_body/RequestProxy';\nimport type { Route } from '../Route';\nimport type { AuthData } from '../http/Auth';\nimport type { RouterNode } from '../router/RouterNode';\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 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\t/**\n\t * The router node that matched the request. The field indicates three\n\t * possible values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no node matched the\n\t * request.\n\t * - `RouterNode`: The router handler has been executed and a node matched\n\t * the request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic routerNode?: RouterNode | null;\n\n\t/**\n\t * The route that matched the request. The field indicates three possible\n\t * values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no route matched the\n\t * request.\n\t * - `Route`: The router handler has been executed and a route matched the\n\t * request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic route?: Route | null;\n\n\t/**\n\t * The response object. This field is cached to prevent multiple response\n\t * objects from being created.\n\t */\n\t#cachedRequest: Request | null = null;\n\n\tget #isFormContentType() {\n\t\tconst contentType = this.asWeb().headers.get('content-type') as MimeType | null;\n\n\t\t// If Content-Type isn't sent, we can't assume it's a form.\n\t\tif (isNullishOrEmpty(contentType)) return false;\n\n\t\t// If the Content-Type is application/x-www-form-urlencoded or multipart/form-data, it's a form.\n\t\treturn contentType.startsWith('application/x-www-form-urlencoded') || contentType.startsWith('multipart/form-data');\n\t}\n\n\t/**\n\t * The response object, used to validate the request's headers and body.\n\t */\n\tpublic asWeb(): Request {\n\t\tthis.#cachedRequest ??= new RequestProxy(this);\n\t\treturn this.#cachedRequest;\n\t}\n\n\t/**\n\t * Reads the request body and tries to parse using JSON or form-urlencoded.\n\t *\n\t * @example\n\t * ```typescript\n\t * const body = await request.readBody();\n\t * ```\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBody(): Promise<unknown> {\n\t\treturn this.#isFormContentType ? this.readBodyFormData() : this.readBodyJson();\n\t}\n\n\t/**\n\t * Reads the request body as an {@link ArrayBuffer}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyArrayBuffer(): Promise<ArrayBuffer> {\n\t\treturn this.asWeb().arrayBuffer();\n\t}\n\n\t/**\n\t * Reads the request body as a {@link Blob}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyBlob(): Promise<Blob> {\n\t\treturn this.asWeb().blob();\n\t}\n\n\t/**\n\t * Reads the request body as a {@link FormData}.\n\t *\n\t * @remarks\n\t *\n\t * This will throw an error if the content type is not one of the following:\n\t *\n\t * - `application/x-www-form-urlencoded`\n\t * - `multipart/form-data`\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyFormData(): Promise<FormData> {\n\t\treturn this.asWeb().formData(); // NOSONAR\n\t}\n\n\t/**\n\t * Reads the request body as text, using {@link TextDecoder}. Afterward, it\n\t * parses the body as JSON with {@link JSON.parse}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyJson(): Promise<unknown> {\n\t\treturn this.asWeb().json();\n\t}\n\n\t/**\n\t * Reads the request body as text, using {@link TextDecoder}.\n\t *\n\t * @returns The result of the body parsing\n\t */\n\tpublic readBodyText(): Promise<string> {\n\t\treturn this.asWeb().text();\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBody}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBody<Type>(validator: ValidatorFunction<unknown, Type>) {\n\t\treturn this.readBody().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyFormData}, but it validates the\n\t * result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyFormData<Type>(validator: ValidatorFunction<FormData, Type>) {\n\t\treturn this.readBodyFormData().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyJson}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyJson<Type>(validator: ValidatorFunction<unknown, Type>) {\n\t\treturn this.readBodyJson().then(validator);\n\t}\n\n\t/**\n\t * Identical to {@link ApiRequest.readBodyText}, but it validates the result.\n\t *\n\t * @param validator The validator function to use on the body parsing result\n\t * @returns The validated body\n\t */\n\tpublic readValidatedBodyText<Type>(validator: ValidatorFunction<string, Type>) {\n\t\treturn this.readBodyText().then(validator);\n\t}\n}\n\nexport type ValidatorFunction<Data, Type> = (data: Data) => Type;\n"]}
@@ -3,13 +3,12 @@
3
3
  var http = require('http');
4
4
  var stream = require('stream');
5
5
  require('stream/web');
6
- var MimeTypes_cjs = require('../../utils/MimeTypes.cjs');
7
6
  var HttpCodes_cjs = require('../http/HttpCodes.cjs');
8
7
 
9
8
  var __defProp = Object.defineProperty;
10
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
13
12
  var _ApiResponse = class _ApiResponse extends http.ServerResponse {
14
13
  constructor() {
15
14
  super(...arguments);
@@ -101,20 +100,20 @@ var _ApiResponse = class _ApiResponse extends http.ServerResponse {
101
100
  * @since 1.0.0
102
101
  */
103
102
  json(data) {
104
- this.setContentType(MimeTypes_cjs.MimeTypes.ApplicationJson).end(JSON.stringify(data));
103
+ this.setContentType("application/json").end(JSON.stringify(data));
105
104
  }
106
105
  /**
107
106
  * @since 1.0.0
108
107
  */
109
108
  text(data) {
110
- this.setContentType(MimeTypes_cjs.MimeTypes.TextPlain).end(data);
109
+ this.setContentType("text/plain").end(data);
111
110
  }
112
111
  /**
113
112
  * @since 6.1.0
114
113
  *
115
114
  * Sets the image content type and sends the image data in the response.
116
115
  *
117
- * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).
116
+ * @param type - The MIME type of the image (e.g., 'image/png').
118
117
  * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.
119
118
  */
120
119
  image(type, data) {
@@ -129,7 +128,7 @@ var _ApiResponse = class _ApiResponse extends http.ServerResponse {
129
128
  * @since 5.1.0
130
129
  */
131
130
  html(code, data) {
132
- this.setContentType(MimeTypes_cjs.MimeTypes.TextHtml).status(code).end(data);
131
+ this.setContentType("text/html").status(code).end(data);
133
132
  }
134
133
  /**
135
134
  * @since 1.0.0
@@ -143,5 +142,5 @@ __name(_ApiResponse, "ApiResponse");
143
142
  var ApiResponse = _ApiResponse;
144
143
 
145
144
  exports.ApiResponse = ApiResponse;
146
- //# sourceMappingURL=out.js.map
145
+ //# sourceMappingURL=ApiResponse.cjs.map
147
146
  //# sourceMappingURL=ApiResponse.cjs.map
@@ -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,iBAAiB,MAAsB;A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AAA;AAAA,EAKO,eAAe,aAA8B;AACnD,SAAK,UAAU,gBAAgB,WAAW;AAC1C,WAAO;AAAA,EACR;AACD;AAlJ4G;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 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, 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":["ServerResponse","STATUS_CODES","HttpCodes","Readable"],"mappings":";;;;;;;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuEA,mBAAwB,CAAA;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAKA,EAAG,CAAA,IAAA,GAAgBC,iBAAa,CAAAC,uBAAA,CAAU,EAAE,CAAS,EAAA;AAC3D,IAAK,IAAA,CAAA,MAAA,CAAOA,wBAAU,EAAE,CAAA;AACxB,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA;AAAA;AACzB;AAAA;AAAA;AAAA,EAKO,OAAQ,CAAA,IAAA,GAAgBD,iBAAa,CAAAC,uBAAA,CAAU,OAAO,CAAS,EAAA;AACrE,IAAK,IAAA,CAAA,MAAA,CAAOA,wBAAU,OAAO,CAAA;AAC7B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA;AAAA;AACzB;AAAA;AAAA;AAAA,EAKO,SAAU,CAAA,IAAA,GAAgBD,iBAAa,CAAAC,uBAAA,CAAU,SAAS,CAAS,EAAA;AACzE,IAAK,IAAA,CAAA,MAAA,CAAOA,wBAAU,SAAS,CAAA;AAC/B,IAAO,OAAA,IAAA,CAAK,QAAQ,IAAI,CAAA;AAAA;AACzB;AAAA;AAAA;AAAA,EAKO,WAAW,IAAsB,EAAA;AACvC,IAAA,OAAO,IAAK,CAAA,KAAA,CAAMA,uBAAU,CAAA,UAAA,EAAY,IAAI,CAAA;AAAA;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;AAAA;AAAA,EAKO,OAAO,IAAoB,EAAA;AACjC,IAAA,IAAA,CAAK,UAAa,GAAA,IAAA;AAClB,IAAO,OAAA,IAAA;AAAA;AACR;AAAA;AAAA;AAAA,EAKO,KAAK,IAAiB,EAAA;AAC5B,IAAA,IAAA,CAAK,eAAe,kBAAkB,CAAA,CAAE,IAAI,IAAK,CAAA,SAAA,CAAU,IAAI,CAAC,CAAA;AAAA;AACjE;AAAA;AAAA;AAAA,EAKO,KAAK,IAAoB,EAAA;AAC/B,IAAA,IAAA,CAAK,cAAe,CAAA,YAAY,CAAE,CAAA,GAAA,CAAI,IAAI,CAAA;AAAA;AAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,KAAA,CAAM,MAA4C,IAAqD,EAAA;AAC7G,IAAA,IAAI,gBAAgBE,eAAU,EAAA;AAC7B,MAAA,IAAA,CAAK,eAAe,IAAI,CAAA;AACxB,MAAA,IAAA,CAAK,KAAK,IAAI,CAAA;AAAA,KACR,MAAA;AACN,MAAA,IAAA,CAAK,cAAe,CAAA,IAAI,CAAE,CAAA,GAAA,CAAI,IAAI,CAAA;AAAA;AACnC;AACD;AAAA;AAAA;AAAA,EAKO,IAAA,CAAK,MAAc,IAAoB,EAAA;AAC7C,IAAA,IAAA,CAAK,eAAe,WAAW,CAAA,CAAE,OAAO,IAAI,CAAA,CAAE,IAAI,IAAI,CAAA;AAAA;AACvD;AAAA;AAAA;AAAA,EAKO,eAAe,WAA6B,EAAA;AAClD,IAAK,IAAA,CAAA,SAAA,CAAU,gBAAgB,WAAW,CAAA;AAC1C,IAAO,OAAA,IAAA;AAAA;AAET,CAAA;AA/I4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAArG,IAAM,WAAN,GAAA","file":"ApiResponse.cjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport type { MimeType } from '../../utils/MimeType';\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 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, 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('application/json').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('text/plain').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., 'image/png').\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(type: Extract<MimeType, `image/${string}`>, data: string | Buffer | Uint8Array | Readable): 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('text/html').status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeType): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
@@ -97,5 +97,5 @@ __publicField(_CookieStore, "octetRegExp", /[^\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5
97
97
  var CookieStore = _CookieStore;
98
98
 
99
99
  exports.CookieStore = CookieStore;
100
- //# sourceMappingURL=out.js.map
100
+ //# sourceMappingURL=CookieStore.cjs.map
101
101
  //# sourceMappingURL=CookieStore.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WAAO,mBAAmB,KAAK;AAAA,EAChC;AACD;AA9HqD;AAAA;AAqHpD,cArHY,cAqHY,eAAc;AArHhC,IAAM,cAAN","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.slice(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.slice(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.slice(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":["getDomain"],"mappings":";;;;;;;;AAOO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,GAAoB,CAAA;AAAA,EAM7C,WAAY,CAAA,OAAA,EAAqB,QAAuB,EAAA,MAAA,EAAiB,eAAiC,EAAA;AAChH,IAAM,KAAA,EAAA;AANP,IAAU,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA;AACV,IAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AACV,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAKP,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA;AACf,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA;AAGhB,IAAA,MAAM,EAAE,MAAA,GAAS,EAAG,EAAA,GAAI,OAAQ,CAAA,OAAA;AAChC,IAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,KAAA,CAAM,GAAG,CAAA;AAE9B,IAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACzB,MAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,GAAG,CAAA;AAC9B,MAAA,IAAI,UAAU,CAAI,CAAA,EAAA;AAElB,MAAM,MAAA,GAAA,GAAM,mBAAmB,IAAK,CAAA,KAAA,CAAM,GAAG,KAAK,CAAA,CAAE,MAAM,CAAA;AAC1D,MAAM,MAAA,KAAA,G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IAAM,EAAA;AACrB,MAAS,KAAA,IAAA,CAAA,UAAA,CAAA;AAAA;AAGV,IAAO,OAAA,KAAA;AAAA;AACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,cAAc,IAAsB,EAAA;AAE3C,IAAM,MAAA,aAAA,GAAgB,KAAK,WAAY,EAAA;AAGvC,IAAM,MAAA,aAAA,GAAgBA,gBAAU,aAAa,CAAA;AAG7C,IAAI,IAAA,CAAC,eAAsB,OAAA,aAAA;AAG3B,IAAA,OAAO,IAAI,aAAa,CAAA,CAAA;AAAA;AACzB,EAKA,OAAe,kBAAkB,KAAe,EAAA;AAC/C,IAAA,IAAI,YAAY,CAAA,WAAA,CAAY,IAAK,CAAA,KAAK,CAAG,EAAA;AACxC,MAAM,MAAA,IAAI,MAAM,CAA4B,0BAAA,CAAA,CAAA;AAAA;AAG7C,IAAA,OAAO,mBAAmB,KAAK,CAAA;AAAA;AAEjC,CAAA;AA9HqD,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA;AAAA;AAqHpD,aAAA,CArHY,cAqHY,aAAc,EAAA,8CAAA,CAAA;AArHhC,IAAM,WAAN,GAAA","file":"CookieStore.cjs","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.slice(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.slice(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.slice(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"]}
@@ -15,7 +15,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
15
15
  var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
16
16
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
17
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);
18
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
19
19
  var _secret;
20
20
  var _Auth = class _Auth {
21
21
  constructor(options) {
@@ -128,5 +128,5 @@ __name(_Auth, "Auth");
128
128
  var Auth = _Auth;
129
129
 
130
130
  exports.Auth = Auth;
131
- //# sourceMappingURL=out.js.map
131
+ //# sourceMappingURL=Auth.cjs.map
132
132
  //# sourceMappingURL=Auth.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,SAAS,kBAAkC;AAC3C,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,aAAa;AAXtB;AAaO,IAAM,QAAN,MAAM,MAAK;AAAA,EAmCT,YAAY,SAA4B;AA9BhD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAEP,wBAAO,mBAAiC;AAExC;AAGC,SAAK,KAAK,QAAQ;AAClB,SAAK,SAAS,QAAQ,UAAU;AAChC,SAAK,SAAS,QAAQ,UAAU,CAAC,aAAa,QAAQ;AACtD,SAAK,WAAW,QAAQ;AACxB,uBAAK,SAAU,QAAQ;AACvB,SAAK,eAAe,QAAQ,gBAAgB,CAAC;AAC7C,SAAK,kBAAkB,QAAQ,mBAAmB;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,SAAS;AACnB,WAAO,mBAAK;AAAA,EACb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,QAAQ,M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;AAAA,IACb;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,MAAc,iBAAoB,OAAqB,OAAe,KAA4C;AACjH,QAAI,CAAC,KAAK,OAAO,SAAS,KAAK,EAAG,QAAO;AAEzC,UAAM,SAAS,MAAM,MAAM,KAAK;AAAA,MAC/B,SAAS;AAAA,QACR,eAAe,UAAU,KAAK;AAAA,MAC/B;AAAA,IACD,CAAC;AAED,WAAO,OAAO,KAAO,MAAM,OAAO,KAAK,IAAW;AAAA,EACnD;AAAA,EAEA,OAAc,OAAO,SAA0C;AAC9D,QAAI,CAAC,SAAS,UAAU,CAAC,QAAQ,GAAI,QAAO;AAC5C,WAAO,IAAI,MAAK,OAAO;AAAA,EACxB;AACD;AA7FC;AAjCiB;AAAX,IAAM,OAAN","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":["OAuth2Scopes","randomBytes","createCipheriv","createDecipheriv","RouteBases","Routes","isThenable","fetch"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,OAAA;AAaO,IAAM,KAAA,GAAN,MAAM,KAAK,CAAA;AAAA,EAmCT,YAAY,OAA4B,EAAA;AA9BhD;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAEP,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAiC,EAAA,IAAA,CAAA;AAExC,IAAA,YAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAGC,IAAA,IAAA,CAAK,KAAK,OAAQ,CAAA,EAAA;AAClB,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ,MAAU,IAAA,eAAA;AAChC,IAAA,IAAA,CAAK,MAAS,GAAA,OAAA,CAAQ,MAAU,IAAA,CAACA,wBAAa,QAAQ,CAAA;AACtD,IAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,QAAA;AACxB,IAAA,YAAA,CAAA,IAAA,EAAK,SAAU,OAAQ,CAAA,MAAA,CAAA;AACvB,IAAK,IAAA,CAAA,YAAA,GAAe,OAAQ,CAAA,YAAA,IAAgB,EAAC;AAC7C,IAAK,IAAA,CAAA,eAAA,GAAkB,QAAQ,eAAmB,IAAA,IAAA;AAAA;AACnD;AAAA;AAAA;AAAA;AAAA,EAMA,IAAW,MAAS,GAAA;AACnB,IAAA,OAAO,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,EAEA,OAAc,OAAO,OAA0C,EAAA;AAC9D,IAAA,IAAI,CAAC,OAAS,EAAA,MAAA,IAAU,CAAC,OAAA,CAAQ,IAAW,OAAA,IAAA;AAC5C,IAAO,OAAA,IAAI,MAAK,OAAO,CAAA;AAAA;AAEzB,CAAA;AA7FC,OAAA,GAAA,IAAA,OAAA,EAAA;AAjCiB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA;AAAX,IAAM,IAAN,GAAA","file":"Auth.cjs","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;\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: 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 * @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"]}
@@ -66,5 +66,5 @@ var HttpCodes = /* @__PURE__ */ ((HttpCodes2) => {
66
66
  })(HttpCodes || {});
67
67
 
68
68
  exports.HttpCodes = HttpCodes;
69
- //# sourceMappingURL=out.js.map
69
+ //# sourceMappingURL=HttpCodes.cjs.map
70
70
  //# sourceMappingURL=HttpCodes.cjs.map