@sapphire/plugin-api 7.0.0-next.d27dc1c → 7.0.0-next.d2c9aaa

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 (206) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/index.cjs +21 -33
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs/index.d.cts +318 -212
  5. package/dist/cjs/lib/structures/Augmentations.d.cjs +1 -1
  6. package/dist/cjs/lib/structures/Augmentations.d.cjs.map +1 -1
  7. package/dist/cjs/lib/structures/Middleware.cjs +2 -2
  8. package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
  9. package/dist/cjs/lib/structures/MiddlewareStore.cjs +4 -4
  10. package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
  11. package/dist/cjs/lib/structures/Route.cjs +18 -40
  12. package/dist/cjs/lib/structures/Route.cjs.map +1 -1
  13. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +20 -0
  14. package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -0
  15. package/dist/cjs/lib/structures/RouteStore.cjs +6 -44
  16. package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
  17. package/dist/cjs/lib/structures/api/ApiRequest.cjs +155 -5
  18. package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
  19. package/dist/cjs/lib/structures/api/ApiResponse.cjs +12 -7
  20. package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
  21. package/dist/cjs/lib/structures/api/CookieStore.cjs +4 -4
  22. package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
  23. package/dist/cjs/lib/structures/http/Auth.cjs +2 -2
  24. package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
  25. package/dist/cjs/lib/structures/http/HttpCodes.cjs +1 -1
  26. package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
  27. package/dist/cjs/lib/structures/http/HttpMethods.cjs +39 -7
  28. package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
  29. package/dist/cjs/lib/structures/http/Server.cjs +17 -23
  30. package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
  31. package/dist/cjs/lib/structures/router/RouterBranch.cjs +184 -0
  32. package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -0
  33. package/dist/cjs/lib/structures/router/RouterNode.cjs +67 -0
  34. package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -0
  35. package/dist/cjs/lib/structures/router/RouterRoot.cjs +81 -0
  36. package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -0
  37. package/dist/cjs/lib/utils/MimeType.cjs +4 -0
  38. package/dist/cjs/lib/utils/MimeType.cjs.map +1 -0
  39. package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs +100 -0
  40. package/dist/cjs/lib/utils/_body/RequestHeadersProxy.cjs.map +1 -0
  41. package/dist/cjs/lib/utils/_body/RequestProxy.cjs +123 -0
  42. package/dist/cjs/lib/utils/_body/RequestProxy.cjs.map +1 -0
  43. package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs +179 -0
  44. package/dist/cjs/lib/utils/_body/RequestURLProxy.cjs.map +1 -0
  45. package/dist/cjs/lib/utils/constants.cjs +8 -0
  46. package/dist/cjs/lib/utils/constants.cjs.map +1 -0
  47. package/dist/cjs/listeners/PluginRouteError.cjs +3 -3
  48. package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
  49. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +3 -3
  50. package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
  51. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +5 -5
  52. package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
  53. package/dist/cjs/listeners/PluginServerRequest.cjs +42 -8
  54. package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
  55. package/dist/cjs/listeners/{PluginServerMatch.cjs → PluginServerRouterBranchMethodNotAllowed.cjs} +5 -10
  56. package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -0
  57. package/dist/cjs/listeners/{PluginServerNoMatch.cjs → PluginServerRouterBranchNotFound.cjs} +3 -3
  58. package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -0
  59. package/dist/cjs/listeners/PluginServerRouterFound.cjs +22 -0
  60. package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -0
  61. package/dist/cjs/listeners/_load.cjs +7 -5
  62. package/dist/cjs/listeners/_load.cjs.map +1 -1
  63. package/dist/cjs/middlewares/_load.cjs +1 -1
  64. package/dist/cjs/middlewares/_load.cjs.map +1 -1
  65. package/dist/cjs/middlewares/auth.cjs +2 -2
  66. package/dist/cjs/middlewares/auth.cjs.map +1 -1
  67. package/dist/cjs/middlewares/body.cjs +4 -19
  68. package/dist/cjs/middlewares/body.cjs.map +1 -1
  69. package/dist/cjs/middlewares/cookies.cjs +1 -1
  70. package/dist/cjs/middlewares/cookies.cjs.map +1 -1
  71. package/dist/cjs/middlewares/headers.cjs +19 -9
  72. package/dist/cjs/middlewares/headers.cjs.map +1 -1
  73. package/dist/cjs/register.cjs +3 -4
  74. package/dist/cjs/register.cjs.map +1 -1
  75. package/dist/cjs/register.d.cts +0 -1
  76. package/dist/cjs/routes/_load.cjs +5 -5
  77. package/dist/cjs/routes/_load.cjs.map +1 -1
  78. package/dist/cjs/routes/oauth/{callback.cjs → callback.post.cjs} +6 -7
  79. package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -0
  80. package/dist/cjs/routes/oauth/{logout.cjs → logout.post.cjs} +6 -8
  81. package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -0
  82. package/dist/esm/{chunk-JTFKMR4I.mjs → chunk-S573YWRP.mjs} +4 -3
  83. package/dist/esm/chunk-S573YWRP.mjs.map +1 -0
  84. package/dist/esm/index.d.mts +318 -212
  85. package/dist/esm/index.mjs +6 -8
  86. package/dist/esm/index.mjs.map +1 -1
  87. package/dist/esm/lib/structures/Augmentations.d.mjs +1 -1
  88. package/dist/esm/lib/structures/Augmentations.d.mjs.map +1 -1
  89. package/dist/esm/lib/structures/Middleware.mjs +2 -2
  90. package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
  91. package/dist/esm/lib/structures/MiddlewareStore.mjs +4 -4
  92. package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
  93. package/dist/esm/lib/structures/Route.mjs +19 -41
  94. package/dist/esm/lib/structures/Route.mjs.map +1 -1
  95. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +17 -0
  96. package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -0
  97. package/dist/esm/lib/structures/RouteStore.mjs +6 -44
  98. package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
  99. package/dist/esm/lib/structures/api/ApiRequest.mjs +149 -6
  100. package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
  101. package/dist/esm/lib/structures/api/ApiResponse.mjs +12 -7
  102. package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
  103. package/dist/esm/lib/structures/api/CookieStore.mjs +5 -5
  104. package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
  105. package/dist/esm/lib/structures/http/Auth.mjs +2 -2
  106. package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
  107. package/dist/esm/lib/structures/http/HttpCodes.mjs +2 -2
  108. package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
  109. package/dist/esm/lib/structures/http/HttpMethods.mjs +41 -6
  110. package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
  111. package/dist/esm/lib/structures/http/Server.mjs +18 -24
  112. package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
  113. package/dist/esm/lib/structures/router/RouterBranch.mjs +179 -0
  114. package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -0
  115. package/dist/esm/lib/structures/router/RouterNode.mjs +56 -0
  116. package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -0
  117. package/dist/esm/lib/structures/router/RouterRoot.mjs +78 -0
  118. package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -0
  119. package/dist/esm/lib/utils/MimeType.mjs +3 -0
  120. package/dist/esm/lib/utils/MimeType.mjs.map +1 -0
  121. package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs +95 -0
  122. package/dist/esm/lib/utils/_body/RequestHeadersProxy.mjs.map +1 -0
  123. package/dist/esm/lib/utils/_body/RequestProxy.mjs +111 -0
  124. package/dist/esm/lib/utils/_body/RequestProxy.mjs.map +1 -0
  125. package/dist/esm/lib/utils/_body/RequestURLProxy.mjs +167 -0
  126. package/dist/esm/lib/utils/_body/RequestURLProxy.mjs.map +1 -0
  127. package/dist/esm/lib/utils/constants.mjs +8 -0
  128. package/dist/esm/lib/utils/constants.mjs.map +1 -0
  129. package/dist/esm/listeners/PluginRouteError.mjs +5 -5
  130. package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
  131. package/dist/esm/listeners/PluginServerMiddlewareError.mjs +5 -5
  132. package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
  133. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +7 -7
  134. package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
  135. package/dist/esm/listeners/PluginServerRequest.mjs +38 -10
  136. package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
  137. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +18 -0
  138. package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -0
  139. package/dist/esm/listeners/{PluginServerNoMatch.mjs → PluginServerRouterBranchNotFound.mjs} +5 -5
  140. package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -0
  141. package/dist/esm/listeners/PluginServerRouterFound.mjs +19 -0
  142. package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -0
  143. package/dist/esm/listeners/_load.mjs +14 -12
  144. package/dist/esm/listeners/_load.mjs.map +1 -1
  145. package/dist/esm/middlewares/_load.mjs +2 -2
  146. package/dist/esm/middlewares/_load.mjs.map +1 -1
  147. package/dist/esm/middlewares/auth.mjs +2 -2
  148. package/dist/esm/middlewares/auth.mjs.map +1 -1
  149. package/dist/esm/middlewares/body.mjs +5 -18
  150. package/dist/esm/middlewares/body.mjs.map +1 -1
  151. package/dist/esm/middlewares/cookies.mjs +2 -2
  152. package/dist/esm/middlewares/cookies.mjs.map +1 -1
  153. package/dist/esm/middlewares/headers.mjs +20 -10
  154. package/dist/esm/middlewares/headers.mjs.map +1 -1
  155. package/dist/esm/register.d.mts +0 -1
  156. package/dist/esm/register.mjs +4 -5
  157. package/dist/esm/register.mjs.map +1 -1
  158. package/dist/esm/routes/_load.mjs +4 -4
  159. package/dist/esm/routes/_load.mjs.map +1 -1
  160. package/dist/esm/routes/oauth/{callback.mjs → callback.post.mjs} +6 -7
  161. package/dist/esm/routes/oauth/callback.post.mjs.map +1 -0
  162. package/dist/esm/routes/oauth/{logout.mjs → logout.post.mjs} +6 -8
  163. package/dist/esm/routes/oauth/logout.post.mjs.map +1 -0
  164. package/package.json +11 -8
  165. package/dist/cjs/lib/structures/MediaParser.cjs +0 -79
  166. package/dist/cjs/lib/structures/MediaParser.cjs.map +0 -1
  167. package/dist/cjs/lib/structures/MediaParserStore.cjs +0 -27
  168. package/dist/cjs/lib/structures/MediaParserStore.cjs.map +0 -1
  169. package/dist/cjs/lib/utils/MimeTypes.cjs +0 -26
  170. package/dist/cjs/lib/utils/MimeTypes.cjs.map +0 -1
  171. package/dist/cjs/lib/utils/RouteData.cjs +0 -62
  172. package/dist/cjs/lib/utils/RouteData.cjs.map +0 -1
  173. package/dist/cjs/listeners/PluginServerMatch.cjs.map +0 -1
  174. package/dist/cjs/listeners/PluginServerNoMatch.cjs.map +0 -1
  175. package/dist/cjs/mediaParsers/_load.cjs +0 -20
  176. package/dist/cjs/mediaParsers/_load.cjs.map +0 -1
  177. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +0 -23
  178. package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +0 -1
  179. package/dist/cjs/mediaParsers/applicationJson.cjs +0 -22
  180. package/dist/cjs/mediaParsers/applicationJson.cjs.map +0 -1
  181. package/dist/cjs/mediaParsers/textPlain.cjs +0 -22
  182. package/dist/cjs/mediaParsers/textPlain.cjs.map +0 -1
  183. package/dist/cjs/routes/oauth/callback.cjs.map +0 -1
  184. package/dist/cjs/routes/oauth/logout.cjs.map +0 -1
  185. package/dist/esm/chunk-JTFKMR4I.mjs.map +0 -1
  186. package/dist/esm/lib/structures/MediaParser.mjs +0 -76
  187. package/dist/esm/lib/structures/MediaParser.mjs.map +0 -1
  188. package/dist/esm/lib/structures/MediaParserStore.mjs +0 -24
  189. package/dist/esm/lib/structures/MediaParserStore.mjs.map +0 -1
  190. package/dist/esm/lib/utils/MimeTypes.mjs +0 -26
  191. package/dist/esm/lib/utils/MimeTypes.mjs.map +0 -1
  192. package/dist/esm/lib/utils/RouteData.mjs +0 -56
  193. package/dist/esm/lib/utils/RouteData.mjs.map +0 -1
  194. package/dist/esm/listeners/PluginServerMatch.mjs +0 -23
  195. package/dist/esm/listeners/PluginServerMatch.mjs.map +0 -1
  196. package/dist/esm/listeners/PluginServerNoMatch.mjs.map +0 -1
  197. package/dist/esm/mediaParsers/_load.mjs +0 -17
  198. package/dist/esm/mediaParsers/_load.mjs.map +0 -1
  199. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +0 -20
  200. package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +0 -1
  201. package/dist/esm/mediaParsers/applicationJson.mjs +0 -19
  202. package/dist/esm/mediaParsers/applicationJson.mjs.map +0 -1
  203. package/dist/esm/mediaParsers/textPlain.mjs +0 -19
  204. package/dist/esm/mediaParsers/textPlain.mjs.map +0 -1
  205. package/dist/esm/routes/oauth/callback.mjs.map +0 -1
  206. package/dist/esm/routes/oauth/logout.mjs.map +0 -1
@@ -4,36 +4,21 @@ var HttpCodes_cjs = require('../lib/structures/http/HttpCodes.cjs');
4
4
  var Middleware_cjs = require('../lib/structures/Middleware.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
10
8
  var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.Middleware {
11
9
  constructor(context) {
12
10
  super(context, { position: 20 });
13
- __publicField(this, "mediaParsers");
14
- this.mediaParsers = this.container.server.mediaParsers;
15
11
  }
16
- async run(request, response, route) {
12
+ run(request, response) {
13
+ if (!request.route) return;
17
14
  const contentType = request.headers["content-type"];
18
15
  if (typeof contentType !== "string") return;
19
16
  const lengthString = request.headers["content-length"];
20
17
  if (typeof lengthString !== "string") return;
21
18
  const length = Number(lengthString);
22
- const maximumLength = route.maximumBodyLength;
19
+ const maximumLength = request.route.maximumBodyLength;
23
20
  if (length > maximumLength) {
24
21
  response.status(HttpCodes_cjs.HttpCodes.PayloadTooLarge).json({ error: "Exceeded maximum content length." });
25
- return;
26
- }
27
- const type = this.mediaParsers.parseContentType(contentType);
28
- const parser = this.mediaParsers.get(type);
29
- if (!parser || !parser.accepts(route)) {
30
- response.status(HttpCodes_cjs.HttpCodes.UnsupportedMediaType).json({ error: `Unsupported type ${type}.` });
31
- return;
32
- }
33
- try {
34
- request.body = await parser.run(request);
35
- } catch {
36
- response.status(HttpCodes_cjs.HttpCodes.BadRequest).json({ error: `Cannot parse ${type} data.` });
37
22
  }
38
23
  }
39
24
  };
@@ -41,5 +26,5 @@ __name(_PluginMiddleware, "PluginMiddleware");
41
26
  var PluginMiddleware = _PluginMiddleware;
42
27
 
43
28
  exports.PluginMiddleware = PluginMiddleware;
44
- //# sourceMappingURL=out.js.map
29
+ //# sourceMappingURL=body.cjs.map
45
30
  //# sourceMappingURL=body.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/body.ts"],"names":[],"mappings":";;;;;;AAEA,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB;AAGpB,IAAM,oBAAN,MAAM,0BAAyB,WAAW;AAAA,EAGzC,YAAY,SAAmC;AACrD,UAAM,SAAS,EAAE,UAAU,GAAG,CAAC;AAHhC,wBAAiB;AAIhB,SAAK,eAAe,KAAK,UAAU,OAAO;AAAA,EAC3C;AAAA,EAEA,MAAsB,IAAI,SAAqB,UAAuB,OAAc;AAEnF,UAAM,cAAc,QAAQ,QAAQ,cAAc;AAClD,QAAI,OAAO,gBAAgB,SAAU;AAGrC,UAAM,eAAe,QAAQ,QAAQ,gBAAgB;AACrD,QAAI,OAAO,iBAAiB,SAAU;AAGtC,UAAM,SAAS,OAAO,YAAY;AAClC,UAAM,gBAAgB,MAAM;AAC5B,QAAI,SAAS,eAAe;AAC3B,eAAS,OAAO,UAAU,eAAe,EAAE,KAAK,EAAE,OAAO,mCAAmC,CAAC;AAC7F;AAAA,IACD;AAGA,UAAM,OAAO,KAAK,aAAa,iBAAiB,WAAW;AAC3D,UAAM,SAAS,KAAK,aAAa,IAAI,IAAI;AACzC,QAAI,CAAC,UAAU,CAAC,OAAO,QAAQ,KAAK,GAAG;AACtC,eAAS,OAAO,UAAU,oBAAoB,EAAE,KAAK,EAAE,OAAO,oBAAoB,IAAI,IAAI,CAAC;AAC3F;AAAA,IACD;AAEA,QAAI;AAEH,cAAQ,OAAO,MAAM,OAAO,IAAI,OAAO;AAAA,IACxC,QAAQ;AACP,eAAS,OAAO,UAAU,UAAU,EAAE,KAAK,EAAE,OAAO,gBAAgB,IAAI,SAAS,CAAC;AAAA,IACnF;AAAA,EACD;AACD;AAxCiD;AAA1C,IAAM,mBAAN","sourcesContent":["import type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport type { ApiResponse } from '../lib/structures/api/ApiResponse';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport type { MediaParserStore } from '../lib/structures/MediaParserStore';\nimport { Middleware } from '../lib/structures/Middleware';\nimport type { Route } from '../lib/structures/Route';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly mediaParsers: MediaParserStore;\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 20 });\n\t\tthis.mediaParsers = this.container.server.mediaParsers;\n\t}\n\n\tpublic override async run(request: ApiRequest, response: ApiResponse, route: Route) {\n\t\t// RFC 1341 4.\n\t\tconst contentType = request.headers['content-type'];\n\t\tif (typeof contentType !== 'string') return;\n\n\t\t// RFC 7230 3.3.2.\n\t\tconst lengthString = request.headers['content-length'];\n\t\tif (typeof lengthString !== 'string') return;\n\n\t\t// Verify if the content length is lower than accepted:\n\t\tconst length = Number(lengthString);\n\t\tconst maximumLength = route.maximumBodyLength;\n\t\tif (length > maximumLength) {\n\t\t\tresponse.status(HttpCodes.PayloadTooLarge).json({ error: 'Exceeded maximum content length.' });\n\t\t\treturn;\n\t\t}\n\n\t\t// Verify if the content type is supported by the parser:\n\t\tconst type = this.mediaParsers.parseContentType(contentType);\n\t\tconst parser = this.mediaParsers.get(type);\n\t\tif (!parser || !parser.accepts(route)) {\n\t\t\tresponse.status(HttpCodes.UnsupportedMediaType).json({ error: `Unsupported type ${type}.` });\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Parse the content body:\n\t\t\trequest.body = await parser.run(request);\n\t\t} catch {\n\t\t\tresponse.status(HttpCodes.BadRequest).json({ error: `Cannot parse ${type} data.` });\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/middlewares/body.ts"],"names":["Middleware","HttpCodes"],"mappings":";;;;;;;AAGO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,yBAAW,CAAA;AAAA,EACzC,YAAY,OAAmC,EAAA;AACrD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,QAAU,EAAA,EAAA,EAAI,CAAA,CAAA;AAAA,GAChC;AAAA,EAEgB,GAAA,CAAI,SAA6B,QAA+B,EAAA;AAC/E,IAAI,IAAA,CAAC,QAAQ,KAAO,EAAA,OAAA;AAGpB,IAAM,MAAA,WAAA,GAAc,OAAQ,CAAA,OAAA,CAAQ,cAAc,CAAA,CAAA;AAClD,IAAI,IAAA,OAAO,gBAAgB,QAAU,EAAA,OAAA;AAGrC,IAAM,MAAA,YAAA,GAAe,OAAQ,CAAA,OAAA,CAAQ,gBAAgB,CAAA,CAAA;AACrD,IAAI,IAAA,OAAO,iBAAiB,QAAU,EAAA,OAAA;AAGtC,IAAM,MAAA,MAAA,GAAS,OAAO,YAAY,CAAA,CAAA;AAClC,IAAM,MAAA,aAAA,GAAgB,QAAQ,KAAM,CAAA,iBAAA,CAAA;AACpC,IAAA,IAAI,SAAS,aAAe,EAAA;AAC3B,MAAS,QAAA,CAAA,MAAA,CAAOC,wBAAU,eAAe,CAAA,CAAE,KAAK,EAAE,KAAA,EAAO,oCAAoC,CAAA,CAAA;AAAA,KAC9F;AAAA,GACD;AACD,CAAA,CAAA;AAvBiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"body.cjs","sourcesContent":["import { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport { Middleware } from '../lib/structures/Middleware';\n\nexport class PluginMiddleware extends Middleware {\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 20 });\n\t}\n\n\tpublic override run(request: Middleware.Request, response: Middleware.Response) {\n\t\tif (!request.route) return;\n\n\t\t// RFC 1341 4.\n\t\tconst contentType = request.headers['content-type'];\n\t\tif (typeof contentType !== 'string') return;\n\n\t\t// RFC 7230 3.3.2.\n\t\tconst lengthString = request.headers['content-length'];\n\t\tif (typeof lengthString !== 'string') return;\n\n\t\t// Verify if the content length is lower than accepted:\n\t\tconst length = Number(lengthString);\n\t\tconst maximumLength = request.route.maximumBodyLength;\n\t\tif (length > maximumLength) {\n\t\t\tresponse.status(HttpCodes.PayloadTooLarge).json({ error: 'Exceeded maximum content length.' });\n\t\t}\n\t}\n}\n"]}
@@ -23,5 +23,5 @@ __name(_PluginMiddleware, "PluginMiddleware");
23
23
  var PluginMiddleware = _PluginMiddleware;
24
24
 
25
25
  exports.PluginMiddleware = PluginMiddleware;
26
- //# sourceMappingURL=out.js.map
26
+ //# sourceMappingURL=cookies.cjs.map
27
27
  //# sourceMappingURL=cookies.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/cookies.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,kBAAkB;AAG3B,SAAS,mBAAmB;AAErB,IAAM,oBAAN,MAAM,0BAAyB,WAAW;AAAA,EAIzC,YAAY,SAAmC;AACrD,UAAM,SAAS,EAAE,UAAU,GAAG,CAAC;AAJhC,wBAAiB,cAAsB,QAAQ,IAAI,aAAa;AAChE,wBAAQ,mBAAiC;AAKxC,UAAM,EAAE,OAAO,IAAI,KAAK;AACxB,SAAK,kBAAkB,OAAO,MAAM,mBAAmB;AAAA,EACxD;AAAA,EAEgB,IAAI,SAAqB,UAAuB;AAC/D,aAAS,UAAU,IAAI,YAAY,SAAS,UAAU,KAAK,YAAY,KAAK,eAAe;AAAA,EAC5F;AACD;AAdiD;AAA1C,IAAM,mBAAN","sourcesContent":["import { Middleware } from '../lib/structures/Middleware';\nimport type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport type { ApiResponse } from '../lib/structures/api/ApiResponse';\nimport { CookieStore } from '../lib/structures/api/CookieStore';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly production: boolean = process.env.NODE_ENV === 'production';\n\tprivate domainOverwrite: string | null = null;\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 30 });\n\n\t\tconst { server } = this.container;\n\t\tthis.domainOverwrite = server.auth?.domainOverwrite ?? null;\n\t}\n\n\tpublic override run(request: ApiRequest, response: ApiResponse) {\n\t\tresponse.cookies = new CookieStore(request, response, this.production, this.domainOverwrite);\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/middlewares/cookies.ts"],"names":["Middleware","CookieStore"],"mappings":";;;;;;;;;AAGO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,yBAAW,CAAA;AAAA,EAIzC,YAAY,OAAmC,EAAA;AACrD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,QAAU,EAAA,EAAA,EAAI,CAAA,CAAA;AAJhC,IAAiB,aAAA,CAAA,IAAA,EAAA,YAAA,EAAsB,OAAQ,CAAA,GAAA,CAAI,QAAa,KAAA,YAAA,CAAA,CAAA;AAChE,IAAA,aAAA,CAAA,IAAA,EAAQ,iBAAiC,EAAA,IAAA,CAAA,CAAA;AAKxC,IAAM,MAAA,EAAE,MAAO,EAAA,GAAI,IAAK,CAAA,SAAA,CAAA;AACxB,IAAK,IAAA,CAAA,eAAA,GAAkB,MAAO,CAAA,IAAA,EAAM,eAAmB,IAAA,IAAA,CAAA;AAAA,GACxD;AAAA,EAEgB,GAAA,CAAI,SAA6B,QAA+B,EAAA;AAC/E,IAAS,QAAA,CAAA,OAAA,GAAU,IAAIC,2BAAY,CAAA,OAAA,EAAS,UAAU,IAAK,CAAA,UAAA,EAAY,KAAK,eAAe,CAAA,CAAA;AAAA,GAC5F;AACD,CAAA,CAAA;AAdiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"cookies.cjs","sourcesContent":["import { Middleware } from '../lib/structures/Middleware';\nimport { CookieStore } from '../lib/structures/api/CookieStore';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly production: boolean = process.env.NODE_ENV === 'production';\n\tprivate domainOverwrite: string | null = null;\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 30 });\n\n\t\tconst { server } = this.container;\n\t\tthis.domainOverwrite = server.auth?.domainOverwrite ?? null;\n\t}\n\n\tpublic override run(request: Middleware.Request, response: Middleware.Response) {\n\t\tresponse.cookies = new CookieStore(request, response, this.production, this.domainOverwrite);\n\t}\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var http = require('http');
4
3
  var Middleware_cjs = require('../lib/structures/Middleware.cjs');
5
4
  var HttpCodes_cjs = require('../lib/structures/http/HttpCodes.cjs');
6
5
 
@@ -12,16 +11,25 @@ var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.Middlewar
12
11
  constructor(context) {
13
12
  super(context, { position: 10 });
14
13
  __publicField(this, "origin");
15
- __publicField(this, "methods", http.METHODS.join(", "));
14
+ __publicField(this, "routes");
16
15
  this.origin = this.container.server.options.origin ?? "*";
16
+ this.routes = this.container.stores.get("routes");
17
17
  }
18
- run(request, response, route) {
18
+ run(request, response) {
19
19
  response.setHeader("Date", (/* @__PURE__ */ new Date()).toUTCString());
20
20
  response.setHeader("Access-Control-Allow-Credentials", "true");
21
21
  response.setHeader("Access-Control-Allow-Origin", this.origin);
22
22
  response.setHeader("Access-Control-Allow-Headers", "Authorization, User-Agent, Content-Type");
23
- response.setHeader("Access-Control-Allow-Methods", this.methods);
24
- this.ensurePotentialEarlyExit(request, response, route);
23
+ response.setHeader("Access-Control-Allow-Methods", this.getMethods(request.route ?? null));
24
+ this.ensurePotentialEarlyExit(request, response);
25
+ }
26
+ getMethods(route) {
27
+ if (route === null) {
28
+ return this.routes.router.supportedMethods.join(", ");
29
+ }
30
+ if (route.methods.size === 0) return "";
31
+ if (route.methods.size === 1) return route.methods.keys().next().value;
32
+ return [...route.methods].join(", ");
25
33
  }
26
34
  /**
27
35
  * **RFC 7231 4.3.7.**
@@ -38,13 +46,15 @@ var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.Middlewar
38
46
  * @param response The API response that will go out
39
47
  * @param route The route being requested by the request
40
48
  */
41
- ensurePotentialEarlyExit(request, response, route) {
42
- if (request.method === "OPTIONS") {
49
+ ensurePotentialEarlyExit({ method, route, routerNode }, response) {
50
+ if (method === "OPTIONS") {
43
51
  if (!route || !route.methods.has("OPTIONS")) {
44
52
  response.end();
45
53
  }
46
- } else if (route === null) {
54
+ } else if (routerNode === null) {
47
55
  response.status(HttpCodes_cjs.HttpCodes.NotFound).end();
56
+ } else if (route === null) {
57
+ response.status(HttpCodes_cjs.HttpCodes.MethodNotAllowed).end();
48
58
  }
49
59
  }
50
60
  };
@@ -52,5 +62,5 @@ __name(_PluginMiddleware, "PluginMiddleware");
52
62
  var PluginMiddleware = _PluginMiddleware;
53
63
 
54
64
  exports.PluginMiddleware = PluginMiddleware;
55
- //# sourceMappingURL=out.js.map
65
+ //# sourceMappingURL=headers.cjs.map
56
66
  //# sourceMappingURL=headers.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/middlewares/headers.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAI3B,SAAS,iBAAiB;AAEnB,IAAM,oBAAN,MAAM,0BAAyB,WAAW;AAAA,EAIzC,YAAY,SAAmC;AACrD,UAAM,SAAS,EAAE,UAAU,GAAG,CAAC;AAJhC,wBAAiB;AACjB,wBAAiB,WAAkB,QAAQ,KAAK,IAAI;AAInD,SAAK,SAAS,KAAK,UAAU,OAAO,QAAQ,UAAU;AAAA,EACvD;AAAA,EAEgB,IAAI,SAAqB,UAAuB,OAAqB;AACpF,aAAS,UAAU,SAAQ,oBAAI,KAAK,GAAE,YAAY,CAAC;AACnD,aAAS,UAAU,oCAAoC,MAAM;AAC7D,aAAS,UAAU,+BAA+B,KAAK,MAAM;AAC7D,aAAS,UAAU,gCAAgC,yCAAyC;AAC5F,aAAS,UAAU,gCAAgC,KAAK,OAAO;AAE/D,SAAK,yBAAyB,SAAS,UAAU,KAAK;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,yBAAyB,SAAqB,UAAuB,OAAqB;AACjG,QAAI,QAAQ,WAAW,WAAW;AACjC,UAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,IAAI,SAAS,GAAG;AAC5C,iBAAS,IAAI;AAAA,MACd;AAAA,IACD,WAAW,UAAU,MAAM;AAC1B,eAAS,OAAO,UAAU,QAAQ,EAAE,IAAI;AAAA,IACzC;AAAA,EACD;AACD;AA3CiD;AAA1C,IAAM,mBAAN","sourcesContent":["import { METHODS } from 'node:http';\nimport { Middleware } from '../lib/structures/Middleware';\nimport type { Route } from '../lib/structures/Route';\nimport type { ApiRequest } from '../lib/structures/api/ApiRequest';\nimport type { ApiResponse } from '../lib/structures/api/ApiResponse';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly origin: string;\n\tprivate readonly methods: string = METHODS.join(', ');\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 10 });\n\t\tthis.origin = this.container.server.options.origin ?? '*';\n\t}\n\n\tpublic override run(request: ApiRequest, response: ApiResponse, route: Route | null) {\n\t\tresponse.setHeader('Date', new Date().toUTCString());\n\t\tresponse.setHeader('Access-Control-Allow-Credentials', 'true');\n\t\tresponse.setHeader('Access-Control-Allow-Origin', this.origin);\n\t\tresponse.setHeader('Access-Control-Allow-Headers', 'Authorization, User-Agent, Content-Type');\n\t\tresponse.setHeader('Access-Control-Allow-Methods', this.methods);\n\n\t\tthis.ensurePotentialEarlyExit(request, response, route);\n\t}\n\n\t/**\n\t * **RFC 7231 4.3.7.**\n\t * > This method allows a client to determine the options and/or requirements associated with a\n\t * > resource, or the capabilities of a server, without implying a resource action.\n\t *\n\t * This method ensures that the request is exited early in case required\n\t * The conditions in which an early exit is required are:\n\t * 1. If the request method is 'OPTIONS'. In this case the request is returned with status code 200\n\t * 2. If the requested route isn't matched with any existing route in the RouteStore.\n\t * In this case the request is returned with a status code 404.\n\t *\n\t * @param request The API Request coming in\n\t * @param response The API response that will go out\n\t * @param route The route being requested by the request\n\t */\n\tprivate ensurePotentialEarlyExit(request: ApiRequest, response: ApiResponse, route: Route | null) {\n\t\tif (request.method === 'OPTIONS') {\n\t\t\tif (!route || !route.methods.has('OPTIONS')) {\n\t\t\t\tresponse.end();\n\t\t\t}\n\t\t} else if (route === null) {\n\t\t\tresponse.status(HttpCodes.NotFound).end();\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../../../src/middlewares/headers.ts"],"names":["Middleware","HttpCodes"],"mappings":";;;;;;;;;AAKO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,yBAAW,CAAA;AAAA,EAIzC,YAAY,OAAmC,EAAA;AACrD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,QAAU,EAAA,EAAA,EAAI,CAAA,CAAA;AAJhC,IAAiB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACjB,IAAiB,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAIhB,IAAA,IAAA,CAAK,MAAS,GAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,QAAQ,MAAU,IAAA,GAAA,CAAA;AACtD,IAAA,IAAA,CAAK,MAAS,GAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAI,QAAQ,CAAA,CAAA;AAAA,GACjD;AAAA,EAEgB,GAAA,CAAI,SAA6B,QAA+B,EAAA;AAC/E,IAAA,QAAA,CAAS,UAAU,MAAQ,EAAA,iBAAA,IAAI,IAAK,EAAA,EAAE,aAAa,CAAA,CAAA;AACnD,IAAS,QAAA,CAAA,SAAA,CAAU,oCAAoC,MAAM,CAAA,CAAA;AAC7D,IAAS,QAAA,CAAA,SAAA,CAAU,6BAA+B,EAAA,IAAA,CAAK,MAAM,CAAA,CAAA;AAC7D,IAAS,QAAA,CAAA,SAAA,CAAU,gCAAgC,yCAAyC,CAAA,CAAA;AAC5F,IAAA,QAAA,CAAS,UAAU,8BAAgC,EAAA,IAAA,CAAK,WAAW,OAAQ,CAAA,KAAA,IAAS,IAAI,CAAC,CAAA,CAAA;AAEzF,IAAK,IAAA,CAAA,wBAAA,CAAyB,SAAS,QAAQ,CAAA,CAAA;AAAA,GAChD;AAAA,EAEQ,WAAW,KAAqB,EAAA;AACvC,IAAA,IAAI,UAAU,IAAM,EAAA;AACnB,MAAA,OAAO,IAAK,CAAA,MAAA,CAAO,MAAO,CAAA,gBAAA,CAAiB,KAAK,IAAI,CAAA,CAAA;AAAA,KACrD;AAEA,IAAA,IAAI,KAAM,CAAA,OAAA,CAAQ,IAAS,KAAA,CAAA,EAAU,OAAA,EAAA,CAAA;AACrC,IAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,IAAA,KAAS,CAAG,EAAA,OAAO,MAAM,OAAQ,CAAA,IAAA,EAAO,CAAA,IAAA,EAAO,CAAA,KAAA,CAAA;AACjE,IAAA,OAAO,CAAC,GAAG,KAAA,CAAM,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA,CAAA;AAAA,GACpC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBQ,yBAAyB,EAAE,MAAA,EAAQ,KAAO,EAAA,UAAA,IAAkC,QAA+B,EAAA;AAClH,IAAA,IAAI,WAAW,SAAW,EAAA;AACzB,MAAA,IAAI,CAAC,KAAS,IAAA,CAAC,MAAM,OAAQ,CAAA,GAAA,CAAI,SAAS,CAAG,EAAA;AAC5C,QAAA,QAAA,CAAS,GAAI,EAAA,CAAA;AAAA,OACd;AAAA,KACD,MAAA,IAAW,eAAe,IAAM,EAAA;AAC/B,MAAA,QAAA,CAAS,MAAO,CAAAC,uBAAA,CAAU,QAAQ,CAAA,CAAE,GAAI,EAAA,CAAA;AAAA,KACzC,MAAA,IAAW,UAAU,IAAM,EAAA;AAC1B,MAAA,QAAA,CAAS,MAAO,CAAAA,uBAAA,CAAU,gBAAgB,CAAA,CAAE,GAAI,EAAA,CAAA;AAAA,KACjD;AAAA,GACD;AACD,CAAA,CAAA;AAxDiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"headers.cjs","sourcesContent":["import { Middleware } from '../lib/structures/Middleware';\nimport type { Route } from '../lib/structures/Route';\nimport type { RouteStore } from '../lib/structures/RouteStore';\nimport { HttpCodes } from '../lib/structures/http/HttpCodes';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly origin: string;\n\tprivate readonly routes: RouteStore;\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 10 });\n\t\tthis.origin = this.container.server.options.origin ?? '*';\n\t\tthis.routes = this.container.stores.get('routes');\n\t}\n\n\tpublic override run(request: Middleware.Request, response: Middleware.Response) {\n\t\tresponse.setHeader('Date', new Date().toUTCString());\n\t\tresponse.setHeader('Access-Control-Allow-Credentials', 'true');\n\t\tresponse.setHeader('Access-Control-Allow-Origin', this.origin);\n\t\tresponse.setHeader('Access-Control-Allow-Headers', 'Authorization, User-Agent, Content-Type');\n\t\tresponse.setHeader('Access-Control-Allow-Methods', this.getMethods(request.route ?? null));\n\n\t\tthis.ensurePotentialEarlyExit(request, response);\n\t}\n\n\tprivate getMethods(route: Route | null) {\n\t\tif (route === null) {\n\t\t\treturn this.routes.router.supportedMethods.join(', ');\n\t\t}\n\n\t\tif (route.methods.size === 0) return '';\n\t\tif (route.methods.size === 1) return route.methods.keys().next().value;\n\t\treturn [...route.methods].join(', ');\n\t}\n\n\t/**\n\t * **RFC 7231 4.3.7.**\n\t * > This method allows a client to determine the options and/or requirements associated with a\n\t * > resource, or the capabilities of a server, without implying a resource action.\n\t *\n\t * This method ensures that the request is exited early in case required\n\t * The conditions in which an early exit is required are:\n\t * 1. If the request method is 'OPTIONS'. In this case the request is returned with status code 200\n\t * 2. If the requested route isn't matched with any existing route in the RouteStore.\n\t * In this case the request is returned with a status code 404.\n\t *\n\t * @param request The API Request coming in\n\t * @param response The API response that will go out\n\t * @param route The route being requested by the request\n\t */\n\tprivate ensurePotentialEarlyExit({ method, route, routerNode }: Middleware.Request, response: Middleware.Response) {\n\t\tif (method === 'OPTIONS') {\n\t\t\tif (!route || !route.methods.has('OPTIONS')) {\n\t\t\t\tresponse.end();\n\t\t\t}\n\t\t} else if (routerNode === null) {\n\t\t\tresponse.status(HttpCodes.NotFound).end();\n\t\t} else if (route === null) {\n\t\t\tresponse.status(HttpCodes.MethodNotAllowed).end();\n\t\t}\n\t}\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var index_cjs = require('./index.cjs');
4
3
  var framework = require('@sapphire/framework');
4
+ var index_cjs = require('./index.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -11,9 +11,8 @@ var _Api = class _Api extends framework.Plugin {
11
11
  */
12
12
  static [framework.postInitialization](options) {
13
13
  this.server = new index_cjs.Server(options.api);
14
- this.stores.register(this.server.routes).register(this.server.mediaParsers).register(this.server.middlewares);
14
+ this.stores.register(this.server.routes).register(this.server.middlewares);
15
15
  index_cjs.loadListeners();
16
- index_cjs.loadMediaParsers();
17
16
  index_cjs.loadMiddlewares();
18
17
  index_cjs.loadRoutes();
19
18
  }
@@ -33,5 +32,5 @@ framework.SapphireClient.plugins.registerPostInitializationHook(Api[framework.po
33
32
  framework.SapphireClient.plugins.registerPreLoginHook(Api[framework.preLogin], "API-PreLogin");
34
33
 
35
34
  exports.Api = Api;
36
- //# sourceMappingURL=out.js.map
35
+ //# sourceMappingURL=register.cjs.map
37
36
  //# sourceMappingURL=register.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;AAAA,OAAO;AAEP,SAAS,QAAQ,oBAAoB,UAAU,sBAAsB;AAErE,SAAS,eAAe,kBAAkB,iBAAiB,YAAY,cAAc;AAK9E,IAAM,OAAN,MAAM,aAAY,OAAO;AAAA;AAAA;AAAA;AAAA,EAI/B,QAAe,kBAAkB,EAAwB,SAA8B;AACtF,SAAK,SAAS,IAAI,OAAO,QAAQ,GAAG;AACpC,SAAK,OACH,SAAS,KAAK,OAAO,MAAM,EAC3B,SAAS,KAAK,OAAO,YAAY,EACjC,SAAS,KAAK,OAAO,WAAW;AAElC,kBAAc;AACd,qBAAiB;AACjB,oBAAgB;AAChB,eAAW;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA,EAKA,cAAqB,QAAQ,IAAuC;AACnE,QAAI,EAAE,KAAK,OAAO,QAAQ,wBAAwB,OAAO;AACxD;AAAA,IACD;AAEA,UAAM,KAAK,OAAO,QAAQ;AAAA,EAC3B;AACD;AA3BgC;AAAzB,IAAM,MAAN;AA6BP,eAAe,QAAQ,+BAA+B,IAAI,kBAAkB,GAAG,wBAAwB;AACvG,eAAe,QAAQ,qBAAqB,IAAI,QAAQ,GAAG,cAAc","sourcesContent":["import './index';\n\nimport { Plugin, postInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { loadListeners, loadMediaParsers, loadMiddlewares, loadRoutes, Server } from './index';\n\n/**\n * @since 1.0.0\n */\nexport class Api extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [postInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\tthis.server = new Server(options.api);\n\t\tthis.stores\n\t\t\t.register(this.server.routes) //\n\t\t\t.register(this.server.mediaParsers)\n\t\t\t.register(this.server.middlewares);\n\n\t\tloadListeners();\n\t\tloadMediaParsers();\n\t\tloadMiddlewares();\n\t\tloadRoutes();\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static async [preLogin](this: SapphireClient): Promise<void> {\n\t\tif (!(this.server.options.automaticallyConnect ?? true)) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.server.connect();\n\t}\n}\n\nSapphireClient.plugins.registerPostInitializationHook(Api[postInitialization], 'API-PostInitialization');\nSapphireClient.plugins.registerPreLoginHook(Api[preLogin], 'API-PreLogin');\n"]}
1
+ {"version":3,"sources":["../../src/register.ts"],"names":["Plugin","postInitialization","Server","loadListeners","loadMiddlewares","loadRoutes","preLogin","SapphireClient"],"mappings":";;;;;;;AAOO,IAAM,IAAA,GAAN,MAAM,IAAA,SAAYA,gBAAO,CAAA;AAAA;AAAA;AAAA;AAAA,EAI/B,QAAeC,4BAAkB,CAAA,CAAwB,OAA8B,EAAA;AACtF,IAAA,IAAA,CAAK,MAAS,GAAA,IAAIC,gBAAO,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AACpC,IAAK,IAAA,CAAA,MAAA,CACH,SAAS,IAAK,CAAA,MAAA,CAAO,MAAM,CAC3B,CAAA,QAAA,CAAS,IAAK,CAAA,MAAA,CAAO,WAAW,CAAA,CAAA;AAElC,IAAcC,uBAAA,EAAA,CAAA;AACd,IAAgBC,yBAAA,EAAA,CAAA;AAChB,IAAWC,oBAAA,EAAA,CAAA;AAAA,GACZ;AAAA;AAAA;AAAA;AAAA,EAKA,cAAqBC,kBAAQ,CAAuC,GAAA;AACnE,IAAA,IAAI,EAAE,IAAA,CAAK,MAAO,CAAA,OAAA,CAAQ,wBAAwB,IAAO,CAAA,EAAA;AACxD,MAAA,OAAA;AAAA,KACD;AAEA,IAAM,MAAA,IAAA,CAAK,OAAO,OAAQ,EAAA,CAAA;AAAA,GAC3B;AACD,CAAA,CAAA;AAzBgC,MAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AAAzB,IAAM,GAAN,GAAA,KAAA;AA2BPC,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,GAAI,CAAAN,4BAAkB,GAAG,wBAAwB,CAAA,CAAA;AACvGM,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,GAAI,CAAAD,kBAAQ,GAAG,cAAc,CAAA","file":"register.cjs","sourcesContent":["import { Plugin, postInitialization, preLogin, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { loadListeners, loadMiddlewares, loadRoutes, Server } from './index';\n\n/**\n * @since 1.0.0\n */\nexport class Api extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [postInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\tthis.server = new Server(options.api);\n\t\tthis.stores\n\t\t\t.register(this.server.routes) //\n\t\t\t.register(this.server.middlewares);\n\n\t\tloadListeners();\n\t\tloadMiddlewares();\n\t\tloadRoutes();\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static async [preLogin](this: SapphireClient): Promise<void> {\n\t\tif (!(this.server.options.automaticallyConnect ?? true)) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.server.connect();\n\t}\n}\n\nSapphireClient.plugins.registerPostInitializationHook(Api[postInitialization], 'API-PostInitialization');\nSapphireClient.plugins.registerPreLoginHook(Api[preLogin], 'API-PreLogin');\n"]}
@@ -1,4 +1,3 @@
1
- import './index.cjs';
2
1
  import { Plugin, postInitialization, SapphireClient, preLogin } from '@sapphire/framework';
3
2
  import { ClientOptions } from 'discord.js';
4
3
 
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  var pieces = require('@sapphire/pieces');
4
- var callback_cjs = require('./oauth/callback.cjs');
5
- var logout_cjs = require('./oauth/logout.cjs');
4
+ var callback_post_cjs = require('./oauth/callback.post.cjs');
5
+ var logout_post_cjs = require('./oauth/logout.post.cjs');
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
9
  function loadRoutes() {
10
10
  const store = "routes";
11
- void pieces.container.stores.loadPiece({ name: "callback", piece: callback_cjs.PluginRoute, store });
12
- void pieces.container.stores.loadPiece({ name: "logout", piece: logout_cjs.PluginRoute, store });
11
+ void pieces.container.stores.loadPiece({ name: "callback", piece: callback_post_cjs.PluginRoute, store });
12
+ void pieces.container.stores.loadPiece({ name: "logout", piece: logout_post_cjs.PluginRoute, store });
13
13
  }
14
14
  __name(loadRoutes, "loadRoutes");
15
15
 
16
16
  exports.loadRoutes = loadRoutes;
17
- //# sourceMappingURL=out.js.map
17
+ //# sourceMappingURL=_load.cjs.map
18
18
  //# sourceMappingURL=_load.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/routes/_load.ts"],"names":[],"mappings":";;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe,2BAA2B;AACnD,SAAS,eAAe,yBAAyB;AAE1C,SAAS,aAAa;AAC5B,QAAM,QAAQ;AACd,OAAK,UAAU,OAAO,UAAU,EAAE,MAAM,YAAY,OAAO,qBAAqB,MAAM,CAAC;AACvF,OAAK,UAAU,OAAO,UAAU,EAAE,MAAM,UAAU,OAAO,mBAAmB,MAAM,CAAC;AACpF;AAJgB","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginRoute as PluginOAuthCallback } from './oauth/callback';\nimport { PluginRoute as PluginOAuthLogout } from './oauth/logout';\n\nexport function loadRoutes() {\n\tconst store = 'routes' as const;\n\tvoid container.stores.loadPiece({ name: 'callback', piece: PluginOAuthCallback, store });\n\tvoid container.stores.loadPiece({ name: 'logout', piece: PluginOAuthLogout, store });\n}\n"]}
1
+ {"version":3,"sources":["../../../src/routes/_load.ts"],"names":["container","PluginOAuthCallback","PluginOAuthLogout"],"mappings":";;;;;;;;AAIO,SAAS,UAAa,GAAA;AAC5B,EAAA,MAAM,KAAQ,GAAA,QAAA,CAAA;AACd,EAAK,KAAAA,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,UAAY,EAAA,KAAA,EAAOC,6BAAqB,EAAA,KAAA,EAAO,CAAA,CAAA;AACvF,EAAK,KAAAD,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,QAAU,EAAA,KAAA,EAAOE,2BAAmB,EAAA,KAAA,EAAO,CAAA,CAAA;AACpF,CAAA;AAJgB,MAAA,CAAA,UAAA,EAAA,YAAA,CAAA","file":"_load.cjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginRoute as PluginOAuthCallback } from './oauth/callback.post';\nimport { PluginRoute as PluginOAuthLogout } from './oauth/logout.post';\n\nexport function loadRoutes() {\n\tconst store = 'routes';\n\tvoid container.stores.loadPiece({ name: 'callback', piece: PluginOAuthCallback, store });\n\tvoid container.stores.loadPiece({ name: 'logout', piece: PluginOAuthLogout, store });\n}\n"]}
@@ -5,22 +5,21 @@ var querystring = require('querystring');
5
5
  var undici = require('undici');
6
6
  var Route_cjs = require('../../lib/structures/Route.cjs');
7
7
  var HttpCodes_cjs = require('../../lib/structures/http/HttpCodes.cjs');
8
- var HttpMethods_cjs = require('../../lib/structures/http/HttpMethods.cjs');
9
8
 
10
9
  var __defProp = Object.defineProperty;
11
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
14
13
  var _PluginRoute = class _PluginRoute extends Route_cjs.Route {
15
14
  constructor(context) {
16
- super(context, { route: "oauth/callback" });
15
+ super(context, { route: "oauth/callback", methods: ["POST"] });
17
16
  __publicField(this, "redirectUri");
18
17
  const { server } = this.container;
19
18
  this.enabled = server.auth !== null;
20
19
  this.redirectUri = server.auth?.redirect;
21
20
  }
22
- async [HttpMethods_cjs.methods.POST](request, response) {
23
- const body = request.body;
21
+ async run(request, response) {
22
+ const body = await request.readBodyJson();
24
23
  if (typeof body?.code !== "string") {
25
24
  return response.badRequest();
26
25
  }
@@ -71,5 +70,5 @@ __name(_PluginRoute, "PluginRoute");
71
70
  var PluginRoute = _PluginRoute;
72
71
 
73
72
  exports.PluginRoute = PluginRoute;
74
- //# sourceMappingURL=out.js.map
75
- //# sourceMappingURL=callback.cjs.map
73
+ //# sourceMappingURL=callback.post.cjs.map
74
+ //# sourceMappingURL=callback.post.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/routes/oauth/callback.post.ts"],"names":["Route","HttpCodes","fetch","OAuth2Routes","stringify"],"mappings":";;;;;;;;;;;;AAMO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoBA,eAAM,CAAA;AAAA,EAG/B,YAAY,OAA8B,EAAA;AAChD,IAAM,KAAA,CAAA,OAAA,EAAS,EAAE,KAAO,EAAA,gBAAA,EAAkB,SAAS,CAAC,MAAM,GAAG,CAAA,CAAA;AAH9D,IAAiB,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AAKhB,IAAM,MAAA,EAAE,MAAO,EAAA,GAAI,IAAK,CAAA,SAAA,CAAA;AACxB,IAAK,IAAA,CAAA,OAAA,GAAU,OAAO,IAAS,KAAA,IAAA,CAAA;AAC/B,IAAK,IAAA,CAAA,WAAA,GAAc,OAAO,IAAM,EAAA,QAAA,CAAA;AAAA,GACjC;AAAA,EAEA,MAAsB,GAAI,CAAA,OAAA,EAAwB,QAA0B,EAAA;AAC3E,IAAM,MAAA,IAAA,GAAQ,MAAM,OAAA,CAAQ,YAAa,EAAA,CAAA;AACzC,IAAI,IAAA,OAAO,IAAM,EAAA,IAAA,KAAS,QAAU,EAAA;AACnC,MAAA,OAAO,SAAS,UAAW,EAAA,CAAA;AAAA,KAC5B;AAEA,IAAA,MAAM,KAAQ,GAAA,MAAM,IAAK,CAAA,SAAA,CAAU,IAAI,CAAA,CAAA;AACvC,IAAA,IAAI,UAAU,IAAM,EAAA;AACnB,MAAO,OAAA,QAAA,CAAS,OAAOC,uBAAU,CAAA,mBAAmB,EAAE,IAAK,CAAA,EAAE,KAAO,EAAA,4BAAA,EAA8B,CAAA,CAAA;AAAA,KACnG;AAEA,IAAM,MAAA,GAAA,GAAM,KAAK,GAAI,EAAA,CAAA;AACrB,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAA;AACnC,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,SAAA,CAAU,MAAM,YAAY,CAAA,CAAA;AACpD,IAAI,IAAA,CAAC,KAAK,IAAM,EAAA;AACf,MAAO,OAAA,QAAA,CAAS,OAAOA,uBAAU,CAAA,mBAAmB,EAAE,IAAK,CAAA,EAAE,KAAO,EAAA,2BAAA,EAA6B,CAAA,CAAA;AAAA,KAClG;AAEA,IAAM,MAAA,KAAA,GAAQ,KAAK,OAAQ,CAAA;AAAA,MAC1B,EAAA,EAAI,KAAK,IAAK,CAAA,EAAA;AAAA,MACd,OAAA,EAAS,GAAM,GAAA,KAAA,CAAM,UAAa,GAAA,GAAA;AAAA,MAClC,SAAS,KAAM,CAAA,aAAA;AAAA,MACf,OAAO,KAAM,CAAA,YAAA;AAAA,KACb,CAAA,CAAA;AAED,IAAS,QAAA,CAAA,OAAA,CAAQ,IAAI,IAAK,CAAA,MAAA,EAAQ,OAAO,EAAE,MAAA,EAAQ,KAAM,CAAA,UAAA,EAAY,CAAA,CAAA;AACrE,IAAO,OAAA,QAAA,CAAS,KAAK,IAAI,CAAA,CAAA;AAAA,GAC1B;AAAA,EAEA,MAAc,UAAU,IAAsB,EAAA;AAC7C,IAAA,MAAM,EAAE,EAAI,EAAA,MAAA,EAAW,GAAA,IAAA,CAAK,UAAU,MAAO,CAAA,IAAA,CAAA;AAE7C,IAAA,MAAM,IAAgD,GAAA;AAAA;AAAA,MAErD,SAAW,EAAA,EAAA;AAAA,MACX,aAAe,EAAA,MAAA;AAAA,MACf,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,UAAY,EAAA,oBAAA;AAAA,MACZ,YAAA,EAAc,IAAK,CAAA,WAAA,IAAe,IAAK,CAAA,WAAA;AAAA;AAAA,KAExC,CAAA;AAEA,IAAA,MAAM,MAAS,GAAA,MAAMC,YAAM,CAAAC,uBAAA,CAAa,QAAU,EAAA;AAAA,MACjD,MAAQ,EAAA,MAAA;AAAA,MACR,IAAA,EAAMC,sBAAU,IAAW,CAAA;AAAA,MAC3B,OAAS,EAAA;AAAA,QACR,cAAgB,EAAA,mCAAA;AAAA,OACjB;AAAA,KACA,CAAA,CAAA;AAED,IAAM,MAAA,IAAA,GAAO,MAAM,MAAA,CAAO,IAAK,EAAA,CAAA;AAC/B,IAAI,IAAA,MAAA,CAAO,IAAW,OAAA,IAAA,CAAA;AAEtB,IAAK,IAAA,CAAA,SAAA,CAAU,MAAO,CAAA,KAAA,CAAM,IAAI,CAAA,CAAA;AAChC,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAnEuC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"callback.post.cjs","sourcesContent":["import { OAuth2Routes, type RESTPostOAuth2AccessTokenResult, type RESTPostOAuth2AccessTokenURLEncodedData } from 'discord.js';\nimport { stringify } from 'querystring';\nimport { fetch } from 'undici';\nimport { Route } from '../../lib/structures/Route';\nimport { HttpCodes } from '../../lib/structures/http/HttpCodes';\n\nexport class PluginRoute extends Route {\n\tprivate readonly redirectUri: string | undefined;\n\n\tpublic constructor(context: Route.LoaderContext) {\n\t\tsuper(context, { route: 'oauth/callback', methods: ['POST'] });\n\n\t\tconst { server } = this.container;\n\t\tthis.enabled = server.auth !== null;\n\t\tthis.redirectUri = server.auth?.redirect;\n\t}\n\n\tpublic override async run(request: Route.Request, response: Route.Response) {\n\t\tconst body = (await request.readBodyJson()) as OAuth2BodyData;\n\t\tif (typeof body?.code !== 'string') {\n\t\t\treturn response.badRequest();\n\t\t}\n\n\t\tconst value = await this.fetchAuth(body);\n\t\tif (value === null) {\n\t\t\treturn response.status(HttpCodes.InternalServerError).json({ error: 'Failed to fetch the token.' });\n\t\t}\n\n\t\tconst now = Date.now();\n\t\tconst auth = this.container.server.auth!;\n\t\tconst data = await auth.fetchData(value.access_token);\n\t\tif (!data.user) {\n\t\t\treturn response.status(HttpCodes.InternalServerError).json({ error: 'Failed to fetch the user.' });\n\t\t}\n\n\t\tconst token = auth.encrypt({\n\t\t\tid: data.user.id,\n\t\t\texpires: now + value.expires_in * 1000,\n\t\t\trefresh: value.refresh_token,\n\t\t\ttoken: value.access_token\n\t\t});\n\n\t\tresponse.cookies.add(auth.cookie, token, { maxAge: value.expires_in });\n\t\treturn response.json(data);\n\t}\n\n\tprivate async fetchAuth(body: OAuth2BodyData) {\n\t\tconst { id, secret } = this.container.server.auth!;\n\n\t\tconst data: RESTPostOAuth2AccessTokenURLEncodedData = {\n\t\t\t/* eslint-disable @typescript-eslint/naming-convention */\n\t\t\tclient_id: id,\n\t\t\tclient_secret: secret,\n\t\t\tcode: body.code,\n\t\t\tgrant_type: 'authorization_code',\n\t\t\tredirect_uri: this.redirectUri ?? body.redirectUri\n\t\t\t/* eslint-enable @typescript-eslint/naming-convention */\n\t\t};\n\n\t\tconst result = await fetch(OAuth2Routes.tokenURL, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: stringify(data as any),\n\t\t\theaders: {\n\t\t\t\t'content-type': 'application/x-www-form-urlencoded'\n\t\t\t}\n\t\t});\n\n\t\tconst json = await result.json();\n\t\tif (result.ok) return json as RESTPostOAuth2AccessTokenResult;\n\n\t\tthis.container.logger.error(json);\n\t\treturn null;\n\t}\n}\n\n/**\n * The OAuth2 body data sent to the callback.\n * @since 1.2.0\n */\nexport interface OAuth2BodyData {\n\t/**\n\t * The code sent by the client.\n\t * @since 1.2.0\n\t */\n\tcode: string;\n\n\t/**\n\t * The client's ID.\n\t * @since 1.2.0\n\t */\n\tclientId: string;\n\n\t/**\n\t * The redirect URI.\n\t * @since 1.2.0\n\t */\n\tredirectUri: string;\n}\n"]}
@@ -1,29 +1,27 @@
1
1
  'use strict';
2
2
 
3
+ var utilities = require('@sapphire/utilities');
3
4
  var discord_js = require('discord.js');
4
5
  var querystring = require('querystring');
5
6
  var undici = require('undici');
6
- var util = require('util');
7
7
  var Route_cjs = require('../../lib/structures/Route.cjs');
8
8
  var HttpCodes_cjs = require('../../lib/structures/http/HttpCodes.cjs');
9
- var HttpMethods_cjs = require('../../lib/structures/http/HttpMethods.cjs');
10
9
 
11
10
  var __defProp = Object.defineProperty;
12
11
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
13
- var sleep = util.promisify(setTimeout);
14
12
  var _PluginRoute = class _PluginRoute extends Route_cjs.Route {
15
13
  constructor(context) {
16
- super(context, { route: "oauth/logout" });
14
+ super(context, { route: "oauth/logout", methods: ["POST"] });
17
15
  this.enabled = this.container.server.auth !== null;
18
16
  }
19
- async [HttpMethods_cjs.methods.POST](request, response) {
17
+ async run(request, response) {
20
18
  if (!request.auth) return response.status(HttpCodes_cjs.HttpCodes.Unauthorized).json({ error: "Unauthorized." });
21
19
  const result = await this.revoke(request.auth.token);
22
20
  if (result.ok) return this.success(response);
23
21
  if (result.status === HttpCodes_cjs.HttpCodes.ServiceUnavailable) {
24
22
  const retryAfter = this.processRetryAfter(result.headers.get("Retry-After"));
25
23
  if (retryAfter) {
26
- await sleep(retryAfter);
24
+ await utilities.sleep(retryAfter);
27
25
  const result2 = await this.revoke(request.auth.token);
28
26
  if (result2.ok) return this.success(response);
29
27
  }
@@ -59,5 +57,5 @@ __name(_PluginRoute, "PluginRoute");
59
57
  var PluginRoute = _PluginRoute;
60
58
 
61
59
  exports.PluginRoute = PluginRoute;
62
- //# sourceMappingURL=out.js.map
63
- //# sourceMappingURL=logout.cjs.map
60
+ //# sourceMappingURL=logout.post.cjs.map
61
+ //# sourceMappingURL=logout.post.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/routes/oauth/logout.post.ts"],"names":["Route","HttpCodes","sleep","result","fetch","OAuth2Routes","stringify"],"mappings":";;;;;;;;;;;AAOO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoBA,eAAM,CAAA;AAAA,EAC/B,YAAY,OAA8B,EAAA;AAChD,IAAM,KAAA,CAAA,OAAA,EAAS,EAAE,KAAO,EAAA,cAAA,EAAgB,SAAS,CAAC,MAAM,GAAG,CAAA,CAAA;AAC3D,IAAA,IAAA,CAAK,OAAU,GAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,IAAS,KAAA,IAAA,CAAA;AAAA,GAC/C;AAAA,EAEA,MAAsB,GAAI,CAAA,OAAA,EAAwB,QAA0B,EAAA;AAC3E,IAAA,IAAI,CAAC,OAAA,CAAQ,IAAM,EAAA,OAAO,QAAS,CAAA,MAAA,CAAOC,uBAAU,CAAA,YAAY,CAAE,CAAA,IAAA,CAAK,EAAE,KAAA,EAAO,iBAAiB,CAAA,CAAA;AAEjG,IAAA,MAAM,SAAS,MAAM,IAAA,CAAK,MAAO,CAAA,OAAA,CAAQ,KAAK,KAAK,CAAA,CAAA;AACnD,IAAA,IAAI,MAAO,CAAA,EAAA,EAAW,OAAA,IAAA,CAAK,QAAQ,QAAQ,CAAA,CAAA;AAM3C,IAAI,IAAA,MAAA,CAAO,MAAW,KAAAA,uBAAA,CAAU,kBAAoB,EAAA;AAMnD,MAAA,MAAM,aAAa,IAAK,CAAA,iBAAA,CAAkB,OAAO,OAAQ,CAAA,GAAA,CAAI,aAAa,CAAC,CAAA,CAAA;AAC3E,MAAA,IAAI,UAAY,EAAA;AACf,QAAA,MAAMC,gBAAM,UAAU,CAAA,CAAA;AAEtB,QAAA,MAAMC,UAAS,MAAM,IAAA,CAAK,MAAO,CAAA,OAAA,CAAQ,KAAK,KAAK,CAAA,CAAA;AACnD,QAAA,IAAIA,OAAO,CAAA,EAAA,EAAW,OAAA,IAAA,CAAK,QAAQ,QAAQ,CAAA,CAAA;AAAA,OAC5C;AAAA,KACD;AAQA,IAAO,OAAA,QAAA,CAAS,OAAOF,uBAAU,CAAA,mBAAmB,EAAE,IAAK,CAAA,EAAE,KAAO,EAAA,+BAAA,EAAiC,CAAA,CAAA;AAAA,GACtG;AAAA,EAEQ,QAAQ,QAA0B,EAAA;AAEzC,IAAA,QAAA,CAAS,QAAQ,MAAO,CAAA,IAAA,CAAK,SAAU,CAAA,MAAA,CAAO,KAAM,MAAM,CAAA,CAAA;AAC1D,IAAA,OAAO,QAAS,CAAA,IAAA,CAAK,EAAE,OAAA,EAAS,MAAM,CAAA,CAAA;AAAA,GACvC;AAAA,EAEA,MAAc,OAAO,KAAe,EAAA;AACnC,IAAM,MAAA,IAAA,GAAO,IAAK,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAA;AAkBnC,IAAA,MAAM,MAAS,GAAA,MAAMG,YAAM,CAAAC,uBAAA,CAAa,kBAAoB,EAAA;AAAA,MAC3D,MAAQ,EAAA,MAAA;AAAA,MACR,MAAMC,qBAAU,CAAA;AAAA,QACf,KAAA;AAAA;AAAA,QAEA,WAAW,IAAK,CAAA,EAAA;AAAA,QAChB,eAAe,IAAK,CAAA,MAAA;AAAA;AAAA,OAEpB,CAAA;AAAA,MACD,OAAS,EAAA;AAAA,QACR,cAAgB,EAAA,mCAAA;AAAA,OACjB;AAAA,KACA,CAAA,CAAA;AAED,IAAO,OAAA,MAAA,CAAA;AAAA,GACR;AAAA,EAEQ,kBAAkB,UAA2B,EAAA;AAGpD,IAAA,OAAO,UAAe,KAAA,IAAA,GAAO,GAAO,GAAA,MAAA,CAAO,UAAU,CAAI,GAAA,GAAA,CAAA;AAAA,GAC1D;AACD,CAAA,CAAA;AAvFuC,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAAhC,IAAM,WAAN,GAAA","file":"logout.post.cjs","sourcesContent":["import { sleep } from '@sapphire/utilities';\nimport { OAuth2Routes } from 'discord.js';\nimport { stringify } from 'querystring';\nimport { fetch } from 'undici';\nimport { Route } from '../../lib/structures/Route';\nimport { HttpCodes } from '../../lib/structures/http/HttpCodes';\n\nexport class PluginRoute extends Route {\n\tpublic constructor(context: Route.LoaderContext) {\n\t\tsuper(context, { route: 'oauth/logout', methods: ['POST'] });\n\t\tthis.enabled = this.container.server.auth !== null;\n\t}\n\n\tpublic override async run(request: Route.Request, response: Route.Response) {\n\t\tif (!request.auth) return response.status(HttpCodes.Unauthorized).json({ error: 'Unauthorized.' });\n\n\t\tconst result = await this.revoke(request.auth.token);\n\t\tif (result.ok) return this.success(response);\n\n\t\t// RFC 7009 2.2.1. If the server responds with HTTP status code 503, the client must assume the token still\n\t\t// exists and may retry after a reasonable delay.\n\t\t// The server may include a \"Retry-After\" header in the response to indicate how long the service is expected to\n\t\t// be unavailable to the requesting client.\n\t\tif (result.status === HttpCodes.ServiceUnavailable) {\n\t\t\t// RFC 7231 7.1.3. Servers send the \"Retry-After\" header field to indicate how long the user agent ought to\n\t\t\t// wait before making a follow-up request.\n\t\t\t//\n\t\t\t// The value of this field can be either an HTTP-date or a number of seconds to delay after the response is\n\t\t\t// received.\n\t\t\tconst retryAfter = this.processRetryAfter(result.headers.get('Retry-After'));\n\t\t\tif (retryAfter) {\n\t\t\t\tawait sleep(retryAfter);\n\n\t\t\t\tconst result = await this.revoke(request.auth.token);\n\t\t\t\tif (result.ok) return this.success(response);\n\t\t\t}\n\t\t}\n\n\t\t// RFC 7009 2.2. The authorization server responds with HTTP status code 200 if the token has been revoked\n\t\t// successfully or if the client submitted an invalid token.\n\t\t//\n\t\t// Note: invalid tokens do not cause an error response since the client cannot handle such an error in a\n\t\t// reasonable way. Moreover, the purpose of the revocation request, invalidating the particular token, is\n\t\t// already achieved.\n\t\treturn response.status(HttpCodes.InternalServerError).json({ error: 'Unexpected error from server.' });\n\t}\n\n\tprivate success(response: Route.Response) {\n\t\t// Sending an empty cookie with \"expires\" set to 1970-01-01 makes the browser instantly remove the cookie.\n\t\tresponse.cookies.remove(this.container.server.auth!.cookie);\n\t\treturn response.json({ success: true });\n\t}\n\n\tprivate async revoke(token: string) {\n\t\tconst auth = this.container.server.auth!;\n\n\t\t// RFC 7009 2.1.\n\t\t// The following parameters must be formatted as \"application/x-www-form-urlencoded\" in the HTTP request-body:\n\t\t//\n\t\t// - token: The token the client wants to be revoked.\n\t\t// - token_type_hint: [Optional]: `access_token` (RFC 6749 1.4), `refresh_token` (RFC 6749 1.5)\n\t\t//\n\t\t// The client also includes its authentication credentials, as described in RFC 6749 2.3.\n\t\t//\n\t\t// RFC 6749 2.3.1.\n\t\t// The authorization server MAY include the client credentials in the request - body using the following parameters:\n\t\t//\n\t\t// - client_id: The client identifier issued to the client during the registration process (RFC 6749 2.2)\n\t\t// - client_secret: The client secret.\n\t\t//\n\t\t// RFC 7009 2.2.\n\t\t// The content of the response body is ignored by the client as all necessary information is conveyed in the response code.\n\t\tconst result = await fetch(OAuth2Routes.tokenRevocationURL, {\n\t\t\tmethod: 'POST',\n\t\t\tbody: stringify({\n\t\t\t\ttoken,\n\t\t\t\t/* eslint-disable @typescript-eslint/naming-convention */\n\t\t\t\tclient_id: auth.id,\n\t\t\t\tclient_secret: auth.secret\n\t\t\t\t/* eslint-enable @typescript-eslint/naming-convention */\n\t\t\t}),\n\t\t\theaders: {\n\t\t\t\t'content-type': 'application/x-www-form-urlencoded'\n\t\t\t}\n\t\t});\n\n\t\treturn result;\n\t}\n\n\tprivate processRetryAfter(retryAfter: string | null) {\n\t\t// Discord sends Retry-After in seconds, never an HTTP-date, therefore, we will assume this behaviour.\n\t\t// Either way, if it's not present, we will retry in 5 seconds.\n\t\treturn retryAfter === null ? 5000 : Number(retryAfter) * 1000;\n\t}\n}\n"]}
@@ -9,7 +9,8 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
9
9
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
10
  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);
11
11
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
13
 
13
- export { __name, __privateAdd, __privateGet, __privateSet, __publicField };
14
- //# sourceMappingURL=out.js.map
15
- //# sourceMappingURL=chunk-JTFKMR4I.mjs.map
14
+ export { __name, __privateAdd, __privateGet, __privateMethod, __privateSet, __publicField };
15
+ //# sourceMappingURL=chunk-S573YWRP.mjs.map
16
+ //# sourceMappingURL=chunk-S573YWRP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-S573YWRP.mjs"}