@sapphire/plugin-api 7.0.0-next.ce675e0 → 7.0.0-next.d6024cd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/lib/structures/Augmentations.d.cjs +1 -1
- package/dist/cjs/lib/structures/Augmentations.d.cjs.map +1 -1
- package/dist/cjs/lib/structures/MediaParser.cjs +1 -1
- package/dist/cjs/lib/structures/MediaParser.cjs.map +1 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs +1 -1
- package/dist/cjs/lib/structures/MediaParserStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Middleware.cjs +2 -2
- package/dist/cjs/lib/structures/Middleware.cjs.map +1 -1
- package/dist/cjs/lib/structures/MiddlewareStore.cjs +2 -2
- package/dist/cjs/lib/structures/MiddlewareStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/Route.cjs +1 -1
- package/dist/cjs/lib/structures/Route.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs +1 -1
- package/dist/cjs/lib/structures/RouteLoaderStrategy.cjs.map +1 -1
- package/dist/cjs/lib/structures/RouteStore.cjs +2 -2
- package/dist/cjs/lib/structures/RouteStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs +1 -1
- package/dist/cjs/lib/structures/api/ApiRequest.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/ApiResponse.cjs +2 -2
- package/dist/cjs/lib/structures/api/ApiResponse.cjs.map +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs +1 -1
- package/dist/cjs/lib/structures/api/CookieStore.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Auth.cjs +2 -2
- package/dist/cjs/lib/structures/http/Auth.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpCodes.cjs +1 -1
- package/dist/cjs/lib/structures/http/HttpCodes.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs +1 -1
- package/dist/cjs/lib/structures/http/HttpMethods.cjs.map +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs +1 -1
- package/dist/cjs/lib/structures/http/Server.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterBranch.cjs +1 -1
- package/dist/cjs/lib/structures/router/RouterBranch.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterNode.cjs +2 -2
- package/dist/cjs/lib/structures/router/RouterNode.cjs.map +1 -1
- package/dist/cjs/lib/structures/router/RouterRoot.cjs +1 -1
- package/dist/cjs/lib/structures/router/RouterRoot.cjs.map +1 -1
- package/dist/cjs/lib/utils/MimeTypes.cjs +1 -1
- package/dist/cjs/lib/utils/MimeTypes.cjs.map +1 -1
- package/dist/cjs/listeners/PluginRouteError.cjs +1 -1
- package/dist/cjs/listeners/PluginRouteError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareError.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs +1 -1
- package/dist/cjs/listeners/PluginServerMiddlewareSuccess.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRequest.cjs +2 -2
- package/dist/cjs/listeners/PluginServerRequest.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchMethodNotAllowed.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs +1 -1
- package/dist/cjs/listeners/PluginServerRouterBranchNotFound.cjs.map +1 -1
- package/dist/cjs/listeners/PluginServerRouterFound.cjs +3 -2
- package/dist/cjs/listeners/PluginServerRouterFound.cjs.map +1 -1
- package/dist/cjs/listeners/_load.cjs +1 -1
- package/dist/cjs/listeners/_load.cjs.map +1 -1
- package/dist/cjs/mediaParsers/_load.cjs +1 -1
- package/dist/cjs/mediaParsers/_load.cjs.map +1 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs +1 -1
- package/dist/cjs/mediaParsers/applicationFormUrlEncoded.cjs.map +1 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs +1 -1
- package/dist/cjs/mediaParsers/applicationJson.cjs.map +1 -1
- package/dist/cjs/mediaParsers/textPlain.cjs +1 -1
- package/dist/cjs/mediaParsers/textPlain.cjs.map +1 -1
- package/dist/cjs/middlewares/_load.cjs +1 -1
- package/dist/cjs/middlewares/_load.cjs.map +1 -1
- package/dist/cjs/middlewares/auth.cjs +2 -2
- package/dist/cjs/middlewares/auth.cjs.map +1 -1
- package/dist/cjs/middlewares/body.cjs +2 -2
- package/dist/cjs/middlewares/body.cjs.map +1 -1
- package/dist/cjs/middlewares/cookies.cjs +1 -1
- package/dist/cjs/middlewares/cookies.cjs.map +1 -1
- package/dist/cjs/middlewares/headers.cjs +1 -1
- package/dist/cjs/middlewares/headers.cjs.map +1 -1
- package/dist/cjs/register.cjs +1 -1
- package/dist/cjs/register.cjs.map +1 -1
- package/dist/cjs/routes/_load.cjs +1 -1
- package/dist/cjs/routes/_load.cjs.map +1 -1
- package/dist/cjs/routes/oauth/callback.post.cjs +2 -2
- package/dist/cjs/routes/oauth/callback.post.cjs.map +1 -1
- package/dist/cjs/routes/oauth/logout.post.cjs +1 -1
- package/dist/cjs/routes/oauth/logout.post.cjs.map +1 -1
- package/dist/esm/chunk-S573YWRP.mjs +1 -1
- package/dist/esm/chunk-S573YWRP.mjs.map +1 -1
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/lib/structures/Augmentations.d.mjs +1 -1
- package/dist/esm/lib/structures/Augmentations.d.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParser.mjs +1 -1
- package/dist/esm/lib/structures/MediaParser.mjs.map +1 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs +1 -1
- package/dist/esm/lib/structures/MediaParserStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Middleware.mjs +1 -1
- package/dist/esm/lib/structures/Middleware.mjs.map +1 -1
- package/dist/esm/lib/structures/MiddlewareStore.mjs +1 -1
- package/dist/esm/lib/structures/MiddlewareStore.mjs.map +1 -1
- package/dist/esm/lib/structures/Route.mjs +1 -1
- package/dist/esm/lib/structures/Route.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs +1 -1
- package/dist/esm/lib/structures/RouteLoaderStrategy.mjs.map +1 -1
- package/dist/esm/lib/structures/RouteStore.mjs +1 -1
- package/dist/esm/lib/structures/RouteStore.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs +1 -1
- package/dist/esm/lib/structures/api/ApiRequest.mjs.map +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs +1 -1
- package/dist/esm/lib/structures/api/ApiResponse.mjs.map +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs +1 -1
- package/dist/esm/lib/structures/api/CookieStore.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs +1 -1
- package/dist/esm/lib/structures/http/Auth.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpCodes.mjs +1 -1
- package/dist/esm/lib/structures/http/HttpCodes.mjs.map +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs +1 -1
- package/dist/esm/lib/structures/http/HttpMethods.mjs.map +1 -1
- package/dist/esm/lib/structures/http/Server.mjs +1 -1
- package/dist/esm/lib/structures/http/Server.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterBranch.mjs +1 -1
- package/dist/esm/lib/structures/router/RouterBranch.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterNode.mjs +1 -1
- package/dist/esm/lib/structures/router/RouterNode.mjs.map +1 -1
- package/dist/esm/lib/structures/router/RouterRoot.mjs +1 -1
- package/dist/esm/lib/structures/router/RouterRoot.mjs.map +1 -1
- package/dist/esm/lib/utils/MimeTypes.mjs +1 -1
- package/dist/esm/lib/utils/MimeTypes.mjs.map +1 -1
- package/dist/esm/listeners/PluginRouteError.mjs +1 -1
- package/dist/esm/listeners/PluginRouteError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareError.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs +1 -1
- package/dist/esm/listeners/PluginServerMiddlewareSuccess.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRequest.mjs +2 -2
- package/dist/esm/listeners/PluginServerRequest.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchMethodNotAllowed.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs +1 -1
- package/dist/esm/listeners/PluginServerRouterBranchNotFound.mjs.map +1 -1
- package/dist/esm/listeners/PluginServerRouterFound.mjs +3 -2
- package/dist/esm/listeners/PluginServerRouterFound.mjs.map +1 -1
- package/dist/esm/listeners/_load.mjs +1 -1
- package/dist/esm/listeners/_load.mjs.map +1 -1
- package/dist/esm/mediaParsers/_load.mjs +1 -1
- package/dist/esm/mediaParsers/_load.mjs.map +1 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs +1 -1
- package/dist/esm/mediaParsers/applicationFormUrlEncoded.mjs.map +1 -1
- package/dist/esm/mediaParsers/applicationJson.mjs +1 -1
- package/dist/esm/mediaParsers/applicationJson.mjs.map +1 -1
- package/dist/esm/mediaParsers/textPlain.mjs +1 -1
- package/dist/esm/mediaParsers/textPlain.mjs.map +1 -1
- package/dist/esm/middlewares/_load.mjs +1 -1
- package/dist/esm/middlewares/_load.mjs.map +1 -1
- package/dist/esm/middlewares/auth.mjs +1 -1
- package/dist/esm/middlewares/auth.mjs.map +1 -1
- package/dist/esm/middlewares/body.mjs +1 -1
- package/dist/esm/middlewares/body.mjs.map +1 -1
- package/dist/esm/middlewares/cookies.mjs +1 -1
- package/dist/esm/middlewares/cookies.mjs.map +1 -1
- package/dist/esm/middlewares/headers.mjs +1 -1
- package/dist/esm/middlewares/headers.mjs.map +1 -1
- package/dist/esm/register.mjs +1 -1
- package/dist/esm/register.mjs.map +1 -1
- package/dist/esm/routes/_load.mjs +1 -1
- package/dist/esm/routes/_load.mjs.map +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs +1 -1
- package/dist/esm/routes/oauth/callback.post.mjs.map +1 -1
- package/dist/esm/routes/oauth/logout.post.mjs +1 -1
- package/dist/esm/routes/oauth/logout.post.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -18,5 +18,5 @@ __name(_PluginMediaParser, "PluginMediaParser");
|
|
|
18
18
|
var PluginMediaParser = _PluginMediaParser;
|
|
19
19
|
|
|
20
20
|
exports.PluginMediaParser = PluginMediaParser;
|
|
21
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=applicationJson.cjs.map
|
|
22
22
|
//# sourceMappingURL=applicationJson.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/mediaParsers/applicationJson.ts"],"names":["MediaParser","MimeTypes"],"mappings":";;;;;;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0BA,2BAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAAC,uBAAA,CAAU,iBAAiB,CAAA,CAAA;AAAA,GACnD;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAA,OAAO,KAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAAA,GAClD;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"applicationJson.cjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport { MimeTypes } from '../lib/utils/MimeTypes';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: MimeTypes.ApplicationJson });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : JSON.parse(body);\n\t}\n}\n"]}
|
|
@@ -18,5 +18,5 @@ __name(_PluginMediaParser, "PluginMediaParser");
|
|
|
18
18
|
var PluginMediaParser = _PluginMediaParser;
|
|
19
19
|
|
|
20
20
|
exports.PluginMediaParser = PluginMediaParser;
|
|
21
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=textPlain.cjs.map
|
|
22
22
|
//# sourceMappingURL=textPlain.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/mediaParsers/textPlain.ts"],"names":["MediaParser","MimeTypes"],"mappings":";;;;;;;AAGO,IAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0BA,2BAAY,CAAA;AAAA,EAC3C,YAAY,OAAoC,EAAA;AACtD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,IAAM,EAAAC,uBAAA,CAAU,WAAW,CAAA,CAAA;AAAA,GAC7C;AAAA,EAEA,MAAsB,IAAI,OAAgD,EAAA;AACzE,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,UAAA,CAAW,OAAO,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAK,MAAW,KAAA,CAAA,GAAI,IAAO,GAAA,IAAA,CAAA;AAAA,GACnC;AACD,CAAA,CAAA;AATmD,MAAA,CAAA,kBAAA,EAAA,mBAAA,CAAA,CAAA;AAA5C,IAAM,iBAAN,GAAA","file":"textPlain.cjs","sourcesContent":["import { MediaParser } from '../lib/structures/MediaParser';\nimport { MimeTypes } from '../lib/utils/MimeTypes';\n\nexport class PluginMediaParser extends MediaParser {\n\tpublic constructor(context: MediaParser.LoaderContext) {\n\t\tsuper(context, { name: MimeTypes.TextPlain });\n\t}\n\n\tpublic override async run(request: MediaParser.Request): Promise<unknown> {\n\t\tconst body = await this.readString(request);\n\t\treturn body.length === 0 ? null : body;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/_load.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/_load.ts"],"names":["container","PluginAuth","PluginBody","PluginCookies","PluginHeaders"],"mappings":";;;;;;;;;;AAMO,SAAS,eAAkB,GAAA;AACjC,EAAA,MAAM,KAAQ,GAAA,aAAA,CAAA;AACd,EAAK,KAAAA,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOC,yBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAAD,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,MAAQ,EAAA,KAAA,EAAOE,yBAAY,EAAA,KAAA,EAAO,CAAA,CAAA;AAC1E,EAAK,KAAAF,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOG,4BAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AAChF,EAAK,KAAAH,gBAAA,CAAU,OAAO,SAAU,CAAA,EAAE,MAAM,SAAW,EAAA,KAAA,EAAOI,4BAAe,EAAA,KAAA,EAAO,CAAA,CAAA;AACjF,CAAA;AANgB,MAAA,CAAA,eAAA,EAAA,iBAAA,CAAA","file":"_load.cjs","sourcesContent":["import { container } from '@sapphire/pieces';\nimport { PluginMiddleware as PluginAuth } from './auth';\nimport { PluginMiddleware as PluginBody } from './body';\nimport { PluginMiddleware as PluginCookies } from './cookies';\nimport { PluginMiddleware as PluginHeaders } from './headers';\n\nexport function loadMiddlewares() {\n\tconst store = 'middlewares' as const;\n\tvoid container.stores.loadPiece({ name: 'auth', piece: PluginAuth, store });\n\tvoid container.stores.loadPiece({ name: 'body', piece: PluginBody, store });\n\tvoid container.stores.loadPiece({ name: 'cookies', piece: PluginCookies, store });\n\tvoid container.stores.loadPiece({ name: 'headers', piece: PluginHeaders, store });\n}\n"]}
|
|
@@ -5,7 +5,7 @@ var Middleware_cjs = require('../lib/structures/Middleware.cjs');
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
9
9
|
var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.Middleware {
|
|
10
10
|
constructor(context) {
|
|
11
11
|
super(context, { position: 40 });
|
|
@@ -28,5 +28,5 @@ __name(_PluginMiddleware, "PluginMiddleware");
|
|
|
28
28
|
var PluginMiddleware = _PluginMiddleware;
|
|
29
29
|
|
|
30
30
|
exports.PluginMiddleware = PluginMiddleware;
|
|
31
|
-
//# sourceMappingURL=
|
|
31
|
+
//# sourceMappingURL=auth.cjs.map
|
|
32
32
|
//# sourceMappingURL=auth.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/auth.ts"],"names":["Middleware"],"mappings":";;;;;;;;AAEO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,yBAAW,CAAA;AAAA,EAGzC,YAAY,OAAmC,EAAA;AACrD,IAAA,KAAA,CAAM,OAAS,EAAA,EAAE,QAAU,EAAA,EAAA,EAAI,CAAA,CAAA;AAHhC,IAAiB,aAAA,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAKhB,IAAM,MAAA,EAAE,MAAO,EAAA,GAAI,IAAK,CAAA,SAAA,CAAA;AACxB,IAAK,IAAA,CAAA,UAAA,GAAa,MAAO,CAAA,IAAA,EAAM,MAAU,IAAA,eAAA,CAAA;AACzC,IAAK,IAAA,CAAA,OAAA,GAAU,OAAO,IAAS,KAAA,IAAA,CAAA;AAAA,GAChC;AAAA,EAEgB,GAAA,CAAI,SAA6B,QAA+B,EAAA;AAE/E,IAAA,MAAM,aAAgB,GAAA,QAAA,CAAS,OAAQ,CAAA,GAAA,CAAI,KAAK,UAAU,CAAA,CAAA;AAC1D,IAAA,IAAI,CAAC,aAAe,EAAA;AACnB,MAAA,OAAA,CAAQ,IAAO,GAAA,IAAA,CAAA;AACf,MAAA,OAAA;AAAA,KACD;AAGA,IAAA,OAAA,CAAQ,OAAO,IAAK,CAAA,SAAA,CAAU,MAAO,CAAA,IAAA,CAAM,QAAQ,aAAa,CAAA,CAAA;AAChE,IAAA,IAAI,QAAQ,IAAS,KAAA,IAAA,WAAe,OAAQ,CAAA,MAAA,CAAO,KAAK,UAAU,CAAA,CAAA;AAAA,GACnE;AACD,CAAA,CAAA;AAvBiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"auth.cjs","sourcesContent":["import { Middleware } from '../lib/structures/Middleware';\n\nexport class PluginMiddleware extends Middleware {\n\tprivate readonly cookieName: string;\n\n\tpublic constructor(context: Middleware.LoaderContext) {\n\t\tsuper(context, { position: 40 });\n\n\t\tconst { server } = this.container;\n\t\tthis.cookieName = server.auth?.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.enabled = server.auth !== null;\n\t}\n\n\tpublic override run(request: Middleware.Request, response: Middleware.Response) {\n\t\t// If there are no cookies, set auth as null:\n\t\tconst authorization = response.cookies.get(this.cookieName);\n\t\tif (!authorization) {\n\t\t\trequest.auth = null;\n\t\t\treturn;\n\t\t}\n\n\t\t// Decrypt the cookie, and if the token is invalid, remove the cookie:\n\t\trequest.auth = this.container.server.auth!.decrypt(authorization);\n\t\tif (request.auth === null) response.cookies.remove(this.cookieName);\n\t}\n}\n"]}
|
|
@@ -6,7 +6,7 @@ var Middleware_cjs = require('../lib/structures/Middleware.cjs');
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
10
10
|
var _PluginMiddleware = class _PluginMiddleware extends Middleware_cjs.Middleware {
|
|
11
11
|
constructor(context) {
|
|
12
12
|
super(context, { position: 20 });
|
|
@@ -42,5 +42,5 @@ __name(_PluginMiddleware, "PluginMiddleware");
|
|
|
42
42
|
var PluginMiddleware = _PluginMiddleware;
|
|
43
43
|
|
|
44
44
|
exports.PluginMiddleware = PluginMiddleware;
|
|
45
|
-
//# sourceMappingURL=
|
|
45
|
+
//# sourceMappingURL=body.cjs.map
|
|
46
46
|
//# sourceMappingURL=body.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/body.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/middlewares/body.ts"],"names":["Middleware","HttpCodes"],"mappings":";;;;;;;;;AAIO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,yBAA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,uBAAU,CAAA,oBAAoB,CAAE,CAAA,IAAA,CAAK,EAAE,KAAO,EAAA,CAAA,iBAAA,EAAoB,IAAI,CAAA,CAAA,CAAA,EAAK,CAAA,CAAA;AAC3F,MAAA,OAAA;AAAA,KACD;AAEA,IAAI,IAAA;AAEH,MAAA,OAAA,CAAQ,IAAO,GAAA,MAAM,MAAO,CAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AAAA,KAChC,CAAA,MAAA;AACP,MAAS,QAAA,CAAA,MAAA,CAAOA,uBAAU,CAAA,UAAU,CAAE,CAAA,IAAA,CAAK,EAAE,KAAO,EAAA,CAAA,aAAA,EAAgB,IAAI,CAAA,MAAA,CAAA,EAAU,CAAA,CAAA;AAAA,KACnF;AAAA,GACD;AACD,CAAA,CAAA;AA1CiD,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAA1C,IAAM,gBAAN,GAAA","file":"body.cjs","sourcesContent":["import { HttpCodes } from '../lib/structures/http/HttpCodes';\nimport type { MediaParserStore } from '../lib/structures/MediaParserStore';\nimport { Middleware } from '../lib/structures/Middleware';\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: 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\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(request.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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/cookies.ts"],"names":[],"mappings":"
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/middlewares/headers.ts"],"names":[],"mappings":"
|
|
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,M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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"]}
|
package/dist/cjs/register.cjs
CHANGED
|
@@ -33,5 +33,5 @@ framework.SapphireClient.plugins.registerPostInitializationHook(Api[framework.po
|
|
|
33
33
|
framework.SapphireClient.plugins.registerPreLoginHook(Api[framework.preLogin], "API-PreLogin");
|
|
34
34
|
|
|
35
35
|
exports.Api = Api;
|
|
36
|
-
//# sourceMappingURL=
|
|
36
|
+
//# sourceMappingURL=register.cjs.map
|
|
37
37
|
//# sourceMappingURL=register.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/register.ts"],"names":[
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":["Plugin","postInitialization","Server","loadListeners","loadMediaParsers","loadMiddlewares","loadRoutes","preLogin","SapphireClient"],"mappings":";;;;;;;AASO,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,IAAA,IAAA,CAAK,MACH,CAAA,QAAA,CAAS,IAAK,CAAA,MAAA,CAAO,MAAM,CAC3B,CAAA,QAAA,CAAS,IAAK,CAAA,MAAA,CAAO,YAAY,CAAA,CACjC,QAAS,CAAA,IAAA,CAAK,OAAO,WAAW,CAAA,CAAA;AAElC,IAAcC,uBAAA,EAAA,CAAA;AACd,IAAiBC,0BAAA,EAAA,CAAA;AACjB,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;AA3BgC,MAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AAAzB,IAAM,GAAN,GAAA,KAAA;AA6BPC,wBAAA,CAAe,OAAQ,CAAA,8BAAA,CAA+B,GAAI,CAAAP,4BAAkB,GAAG,wBAAwB,CAAA,CAAA;AACvGO,wBAAA,CAAe,OAAQ,CAAA,oBAAA,CAAqB,GAAI,CAAAD,kBAAQ,GAAG,cAAc,CAAA","file":"register.cjs","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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/_load.ts"],"names":[],"mappings":"
|
|
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' as const;\n\tvoid container.stores.loadPiece({ name: 'callback', piece: PluginOAuthCallback, store });\n\tvoid container.stores.loadPiece({ name: 'logout', piece: PluginOAuthLogout, store });\n}\n"]}
|
|
@@ -9,7 +9,7 @@ var HttpCodes_cjs = require('../../lib/structures/http/HttpCodes.cjs');
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
12
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
13
13
|
var _PluginRoute = class _PluginRoute extends Route_cjs.Route {
|
|
14
14
|
constructor(context) {
|
|
15
15
|
super(context, { route: "oauth/callback", methods: ["POST"] });
|
|
@@ -70,5 +70,5 @@ __name(_PluginRoute, "PluginRoute");
|
|
|
70
70
|
var PluginRoute = _PluginRoute;
|
|
71
71
|
|
|
72
72
|
exports.PluginRoute = PluginRoute;
|
|
73
|
-
//# sourceMappingURL=
|
|
73
|
+
//# sourceMappingURL=callback.post.cjs.map
|
|
74
74
|
//# sourceMappingURL=callback.post.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/oauth/callback.post.ts"],"names":[],"mappings":"
|
|
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,EA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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 = request.body 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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/oauth/logout.post.ts"],"names":["
|
|
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,Y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AAC,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"]}
|
|
@@ -12,5 +12,5 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
12
12
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
13
13
|
|
|
14
14
|
export { __name, __privateAdd, __privateGet, __privateMethod, __privateSet, __publicField };
|
|
15
|
-
//# sourceMappingURL=
|
|
15
|
+
//# sourceMappingURL=chunk-S573YWRP.mjs.map
|
|
16
16
|
//# sourceMappingURL=chunk-S573YWRP.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-S573YWRP.mjs"}
|
package/dist/esm/index.d.mts
CHANGED
|
@@ -712,7 +712,7 @@ interface ServerEvents {
|
|
|
712
712
|
[ServerEvent.RouterBranchMethodNotAllowed]: [request: ApiRequest, response: ApiResponse, node: RouterBranch];
|
|
713
713
|
[ServerEvent.RouterFound]: [request: ApiRequest, response: ApiResponse];
|
|
714
714
|
[ServerEvent.RouteError]: [error: Error, request: ApiRequest, response: ApiResponse];
|
|
715
|
-
[ServerEvent.MiddlewareFailure]: [
|
|
715
|
+
[ServerEvent.MiddlewareFailure]: [request: ApiRequest, response: ApiResponse];
|
|
716
716
|
[ServerEvent.MiddlewareSuccess]: [request: Route.Request, response: Route.Response, route: Route];
|
|
717
717
|
[ServerEvent.MiddlewareError]: [error: Error, request: ApiRequest, response: ApiResponse];
|
|
718
718
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -21,8 +21,8 @@ export { loadMediaParsers } from './mediaParsers/_load.mjs';
|
|
|
21
21
|
export { loadMiddlewares } from './middlewares/_load.mjs';
|
|
22
22
|
export { loadRoutes } from './routes/_load.mjs';
|
|
23
23
|
|
|
24
|
-
var version = "7.0.0-next.
|
|
24
|
+
var version = "7.0.0-next.d6024cd";
|
|
25
25
|
|
|
26
26
|
export { version };
|
|
27
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=index.mjs.map
|
|
28
28
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAyDO,IAAM,OAAkB,GAAA","file":"index.mjs","sourcesContent":["import type { Server, ServerOptions } from './lib/structures/http/Server';\nimport type { MediaParserStore } from './lib/structures/MediaParserStore';\nimport type { MiddlewareStore } from './lib/structures/MiddlewareStore';\nimport type { RouteStore } from './lib/structures/RouteStore';\n\nexport * from './lib/structures/api/ApiRequest';\nexport * from './lib/structures/api/ApiResponse';\nexport * from './lib/structures/api/CookieStore';\nexport * from './lib/structures/http/Auth';\nexport * from './lib/structures/http/HttpCodes';\nexport * from './lib/structures/http/HttpMethods';\nexport * from './lib/structures/http/Server';\nexport * from './lib/structures/MediaParser';\nexport * from './lib/structures/MediaParserStore';\nexport * from './lib/structures/Middleware';\nexport * from './lib/structures/MiddlewareStore';\nexport * from './lib/structures/Route';\nexport * from './lib/structures/router/RouterBranch';\nexport * from './lib/structures/router/RouterNode';\nexport * from './lib/structures/router/RouterRoot';\nexport * from './lib/structures/RouteStore';\nexport * from './lib/utils/MimeTypes';\n\nexport { loadListeners } from './listeners/_load';\nexport { loadMediaParsers } from './mediaParsers/_load';\nexport { loadMiddlewares } from './middlewares/_load';\nexport { loadRoutes } from './routes/_load';\n\ndeclare module 'discord.js' {\n\tinterface Client {\n\t\tserver: Server;\n\t}\n\n\tinterface ClientOptions {\n\t\tapi?: ServerOptions;\n\t}\n}\n\ndeclare module '@sapphire/pieces' {\n\tinterface StoreRegistryEntries {\n\t\troutes: RouteStore;\n\t\tmediaParsers: MediaParserStore;\n\t\tmiddlewares: MiddlewareStore;\n\t}\n\n\tinterface Container {\n\t\tserver: Server;\n\t}\n}\n\n/**\n * The [@sapphire/plugin-api](https://github.com/sapphiredev/plugins/blob/main/packages/api) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '7.0.0-next.d6024cd';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.mjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":";;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+E,KAA+B,CAAA;AAAA,EAC5H,WAAY,CAAA,OAAA,EAAoC,OAAmB,GAAA,EAAe,EAAA;AACxF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAAA,GACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaO,QAAQ,K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,QAAA,CAAA;AAAA,MACL,KAAK,MAAQ,EAAA;AACZ,QAAA,MAAM,SAAS,YAAa,EAAA,CAAA;AAC5B,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAKA,KAAK,IAAM,EAAA;AACV,QAAA,MAAM,SAAS,sBAAuB,EAAA,CAAA;AACtC,QAAA,OAAA,CAAQ,KAAK,MAAM,CAAA,CAAA;AACnB,QAAO,OAAA,MAAA,CAAA;AAAA,OACR;AAAA,MAIA,KAAK,UAAY,EAAA;AAChB,QAAO,OAAA,OAAA,CAAA;AAAA,OACR;AAAA,KACD;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAhGoI,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAA7H,IAAe,WAAf,GAAA","file":"MediaParser.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport { createBrotliDecompress, createGunzip, createInflate, type Gunzip } from 'zlib';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { MimeTypeWithoutParameters } from './http/Server';\nimport type { Route } from './Route';\n\n/**\n * A media parser\n * @since 1.3.0\n */\nexport abstract class MediaParser<Options extends MediaParser.Options = MediaParser.Options> extends Piece<Options, 'mediaParsers'> {\n\tpublic constructor(context: MediaParser.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t}\n\n\t/**\n\t * Parses the body data from an API request.\n\t * @since 1.3.0\n\t */\n\tpublic abstract run(request: MediaParser.Request): Awaitable<unknown>;\n\n\t/**\n\t * Checks if a route accepts the media type from this parser.\n\t * @since 1.3.0\n\t * @param route The route to be checked.\n\t */\n\tpublic accepts(route: Route): boolean {\n\t\treturn route.acceptedContentMimeTypes === null || route.acceptedContentMimeTypes.includes(this.name as MimeTypeWithoutParameters);\n\t}\n\n\t/**\n\t * Reads the content body as a string, this is useful for parsing/reading plain-text data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readString(request: MediaParser.Request): Promise<string> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return '';\n\n\t\tlet body = '';\n\t\tfor await (const chunk of stream) body += chunk;\n\n\t\treturn body;\n\t}\n\n\t/**\n\t * Reads the content body as a buffer, this is useful for parsing/reading binary data.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected async readBuffer(request: MediaParser.Request): Promise<Buffer> {\n\t\tconst stream = this.contentStream(request);\n\t\tif (stream === null) return Buffer.alloc(0);\n\n\t\tconst bodies: Buffer[] = [];\n\t\tfor await (const chunk of stream) bodies.push(chunk);\n\n\t\treturn Buffer.concat(bodies);\n\t}\n\n\t/**\n\t * Reads the content stream from a request, piping the data through a transformer stream.\n\t * @since 1.3.0\n\t * @param request The request to read the body from.\n\t */\n\tprotected contentStream(request: MediaParser.Request): MediaParser.Request | Gunzip | null {\n\t\tswitch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) {\n\t\t\t// RFC 7230 4.2.2:\n\t\t\t//\n\t\t\t// The \"deflate\" coding is a \"zlib\" data format (RFC 1950) containing a \"deflate\" compressed data stream\n\t\t\t// (RFC 1951) that uses a combination of the Lempel-Ziv (LZ77) compression algorithm and Huffman coding.\n\t\t\tcase 'deflate': {\n\t\t\t\tconst stream = createInflate();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7230 4.2.3\n\t\t\t//\n\t\t\t// The \"gzip\" coding is an LZ77 coding with a 32-bit Cyclic Redundancy Check (CRC) that is commonly produced\n\t\t\t// by the gzip file compression program (RFC 1952).\n\t\t\tcase 'x-gzip':\n\t\t\tcase 'gzip': {\n\t\t\t\tconst stream = createGunzip();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// RFC 7932\n\t\t\t//\n\t\t\t// A format using the Brotli algorithm.\n\t\t\tcase 'br': {\n\t\t\t\tconst stream = createBrotliDecompress();\n\t\t\t\trequest.pipe(stream);\n\t\t\t\treturn stream;\n\t\t\t}\n\n\t\t\t// An \"identity\" token is used as a synonym for \"no encoding\" in order to communicate when no encoding is\n\t\t\t// preferred.\n\t\t\tcase 'identity': {\n\t\t\t\treturn request;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n}\n\nexport namespace MediaParser {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'mediaParsers'>;\n\texport type Options = Piece.Options;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":";;;;AAMO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyB,KAAmC,CAAA;AAAA,EACjE,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,WAAa,EAAA,EAAE,IAAM,EAAA,cAAA,EAAgB,CAAA,CAAA;AAAA,GAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,iBAAiB,WAA6B,EAAA;AACpD,IAAM,MAAA,KAAA,GAAQ,WAAY,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AACrC,IAAA,OAAO,UAAU,CAAK,CAAA,GAAA,WAAA,GAAc,WAAY,CAAA,KAAA,CAAM,GAAG,KAAK,CAAA,CAAA;AAAA,GAC/D;AACD,CAAA,CAAA;AAdyE,MAAA,CAAA,iBAAA,EAAA,kBAAA,CAAA,CAAA;AAAlE,IAAM,gBAAN,GAAA","file":"MediaParserStore.mjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { MediaParser } from './MediaParser';\n\n/**\n * @since 1.3.0\n */\nexport class MediaParserStore extends Store<MediaParser, 'mediaParsers'> {\n\tpublic constructor() {\n\t\tsuper(MediaParser, { name: 'mediaParsers' });\n\t}\n\n\t/**\n\t * Parses a content type by getting the relevant information inside.\n\t * @since 1.3.0\n\t * @param contentType The content type to parse.\n\t */\n\tpublic parseContentType(contentType: string): string {\n\t\tconst index = contentType.indexOf(';');\n\t\treturn index === -1 ? contentType : contentType.slice(0, index);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":";;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4E,KAA8B,CAAA;AAAA,EAaxH,WAAY,CAAA,OAAA,EAAmC,OAAmB,GAAA,EAAe,EAAA;AACvF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAHvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAIf,IAAK,IAAA,CAAA,QAAA,GAAW,QAAQ,QAAY,IAAA,GAAA,CAAA;AAAA,GACrC;AASD,CAAA,CAAA;AAzBgI,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAzH,IAAe,UAAf,GAAA","file":"Middleware.mjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport type { Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\n\n/**\n * @since 1.0.0\n */\nexport abstract class Middleware<Options extends Middleware.Options = Middleware.Options> extends Piece<Options, 'middlewares'> {\n\t/**\n\t * The position the middleware has. The {@link MiddlewareStore} will run all middlewares with lower position than\n\t * this one.\n\t *\n\t * The built-in middlewares follow the following positions:\n\t * - headers: 10\n\t * - body: 20\n\t * - cookies: 30\n\t * - auth: 40\n\t */\n\tpublic readonly position: number;\n\n\tpublic constructor(context: Middleware.LoaderContext, options: Options = {} as Options) {\n\t\tsuper(context, options);\n\t\tthis.position = options.position ?? 1000;\n\t}\n\n\t/**\n\t * The method to be overridden by other middlewares.\n\t * @param request The client's request.\n\t * @param response The server's response.\n\t * @param route The route that matched this request, will be `null` if none matched.\n\t */\n\tpublic abstract run(request: Middleware.Request, response: Middleware.Response): Awaitable<unknown>;\n}\n\n/**\n * The options for all middlewares.\n */\nexport interface MiddlewareOptions extends Piece.Options {\n\t/**\n\t * The position to insert the middleware at.\n\t * @see Middleware#position\n\t * @default 1000\n\t */\n\tposition?: number;\n}\n\nexport namespace Middleware {\n\t/** @deprecated Use {@linkcode LoaderContext} instead. */\n\texport type Context = LoaderContext;\n\texport type LoaderContext = Piece.LoaderContext<'middlewares'>;\n\texport type Options = MiddlewareOptions;\n\texport type JSON = Piece.JSON;\n\texport type LocationJSON = Piece.LocationJSON;\n\n\texport type Request = ApiRequest;\n\texport type Response = ApiResponse;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":";;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwB,KAAiC,CAAA;AAAA,EAM9D,WAAc,GAAA;AACpB,IAAA,KAAA,CAAM,UAAY,EAAA,EAAE,IAAM,EAAA,aAAA,EAAe,CAAA,CAAA;AAH1C;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAgB,qBAAkC,EAAC,CAAA,CAAA;AAAA,GAInD;AAAA,EAEA,MAAa,GAAI,CAAA,OAAA,EAA6B,QAA8C,EAAA;AAC3F,IAAW,KAAA,MAAA,UAAA,IAAc,KAAK,iBAAmB,EAAA;AAChD,MAA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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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":";;;;;AA6CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6D,KAAyB,CAAA;AAAA,EAqBpG,WAAY,CAAA,OAAA,EAA8B,OAAmB,GAAA,EAAe,EAAA;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AAlBvB;AAAA;AAAA;AAAA,IAAgB,aAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,CAAA;AAKhB;AAAA;AAAA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f,IAAA,IAAA,CAAK,oBAAoB,OAAQ,CAAA,iBAAA,IAAqB,GAAI,CAAA,iBAAA,IAAqB,OAAO,IAAO,GAAA,EAAA,CAAA;AAC7F,IAAA,IAAA,CAAK,wBAA2B,GAAA,OAAA,CAAQ,wBAA4B,IAAA,GAAA,CAAI,wBAA4B,IAAA,IAAA,CAAA;AAAA,GACrG;AAGD,CAAA,CAAA;AA7C4G,MAAA,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;AAArG,IAAe,KAAf,GAAA","file":"Route.mjs","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"]}
|
|
@@ -13,5 +13,5 @@ __name(_RouteLoaderStrategy, "RouteLoaderStrategy");
|
|
|
13
13
|
var RouteLoaderStrategy = _RouteLoaderStrategy;
|
|
14
14
|
|
|
15
15
|
export { RouteLoaderStrategy };
|
|
16
|
-
//# sourceMappingURL=
|
|
16
|
+
//# sourceMappingURL=RouteLoaderStrategy.mjs.map
|
|
17
17
|
//# sourceMappingURL=RouteLoaderStrategy.mjs.map
|