@sapphire/plugin-api 7.0.0-next.41e299d → 7.0.0-next.78dd025
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 +7 -7
package/dist/cjs/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var _load_cjs$2 = require('./middlewares/_load.cjs');
|
|
|
23
23
|
var _load_cjs$3 = require('./routes/_load.cjs');
|
|
24
24
|
|
|
25
25
|
// src/index.ts
|
|
26
|
-
var version = "7.0.0-next.
|
|
26
|
+
var version = "7.0.0-next.78dd025";
|
|
27
27
|
|
|
28
28
|
Object.defineProperty(exports, "loadListeners", {
|
|
29
29
|
enumerable: true,
|
|
@@ -144,5 +144,5 @@ Object.keys(MimeTypes_cjs).forEach(function (k) {
|
|
|
144
144
|
get: function () { return MimeTypes_cjs[k]; }
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
-
//# sourceMappingURL=
|
|
147
|
+
//# sourceMappingURL=index.cjs.map
|
|
148
148
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.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.cjs","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.78dd025';\n"]}
|
package/dist/cjs/index.d.cts
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
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"Augmentations.d.cjs"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParser.ts"],"names":["Piece","createInflate","createGunzip","createBrotliDecompress"],"mappings":";;;;;;;AAWO,IAAe,YAAA,GAAf,MAAe,YAAA,SAA+EA,YAA+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,KAAuB,EAAA;AACrC,IAAA,OAAO,MAAM,wBAA6B,KAAA,IAAA,IAAQ,MAAM,wBAAyB,CAAA,QAAA,CAAS,KAAK,IAAiC,CAAA,CAAA;AAAA,GACjI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAgB,WAAW,OAA+C,EAAA;AACzE,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,aAAA,CAAc,OAAO,CAAA,CAAA;AACzC,IAAI,IAAA,MAAA,KAAW,MAAa,OAAA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AAA,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.cjs","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"]}
|
|
@@ -23,5 +23,5 @@ __name(_MediaParserStore, "MediaParserStore");
|
|
|
23
23
|
var MediaParserStore = _MediaParserStore;
|
|
24
24
|
|
|
25
25
|
exports.MediaParserStore = MediaParserStore;
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=MediaParserStore.cjs.map
|
|
27
27
|
//# sourceMappingURL=MediaParserStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MediaParserStore.ts"],"names":["Store","MediaParser"],"mappings":";;;;;;;AAMO,IAAM,iBAAA,GAAN,MAAM,iBAAA,SAAyBA,YAAmC,CAAA;AAAA,EACjE,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,2BAAa,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.cjs","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"]}
|
|
@@ -5,7 +5,7 @@ var pieces = require('@sapphire/pieces');
|
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
6
6
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
8
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
9
9
|
var _Middleware = class _Middleware extends pieces.Piece {
|
|
10
10
|
constructor(context, options = {}) {
|
|
11
11
|
super(context, options);
|
|
@@ -27,5 +27,5 @@ __name(_Middleware, "Middleware");
|
|
|
27
27
|
var Middleware = _Middleware;
|
|
28
28
|
|
|
29
29
|
exports.Middleware = Middleware;
|
|
30
|
-
//# sourceMappingURL=
|
|
30
|
+
//# sourceMappingURL=Middleware.cjs.map
|
|
31
31
|
//# sourceMappingURL=Middleware.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Middleware.ts"],"names":["Piece"],"mappings":";;;;;;;;AAQO,IAAe,WAAA,GAAf,MAAe,WAAA,SAA4EA,YAA8B,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.cjs","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"]}
|
|
@@ -6,7 +6,7 @@ var Middleware_cjs = require('./Middleware.cjs');
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
9
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
10
10
|
var _MiddlewareStore = class _MiddlewareStore extends pieces.Store {
|
|
11
11
|
constructor() {
|
|
12
12
|
super(Middleware_cjs.Middleware, { name: "middlewares" });
|
|
@@ -41,5 +41,5 @@ __name(_MiddlewareStore, "MiddlewareStore");
|
|
|
41
41
|
var MiddlewareStore = _MiddlewareStore;
|
|
42
42
|
|
|
43
43
|
exports.MiddlewareStore = MiddlewareStore;
|
|
44
|
-
//# sourceMappingURL=
|
|
44
|
+
//# sourceMappingURL=MiddlewareStore.cjs.map
|
|
45
45
|
//# sourceMappingURL=MiddlewareStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/MiddlewareStore.ts"],"names":["Store","Middleware"],"mappings":";;;;;;;;;AAMO,IAAM,gBAAA,GAAN,MAAM,gBAAA,SAAwBA,YAAiC,CAAA;AAAA,EAM9D,WAAc,GAAA;AACpB,IAAA,KAAA,CAAMC,yBAAY,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;A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lewareStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Middleware } from './Middleware';\n\n/**\n * @since 1.0.0\n */\nexport class MiddlewareStore extends Store<Middleware, 'middlewares'> {\n\t/**\n\t * The sorted middlewares, in ascending order of see {@link Middleware.position}.\n\t */\n\tpublic readonly sortedMiddlewares: Middleware[] = [];\n\n\tpublic constructor() {\n\t\tsuper(Middleware, { name: 'middlewares' });\n\t}\n\n\tpublic async run(request: Middleware.Request, response: Middleware.Response): Promise<void> {\n\t\tfor (const middleware of this.sortedMiddlewares) {\n\t\t\tif (response.writableEnded) return;\n\t\t\tif (middleware.enabled) await middleware.run(request, response);\n\t\t}\n\t}\n\n\tpublic override set(key: string, value: Middleware): this {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.position >= value.position);\n\n\t\t// If a middleware with lower priority wasn't found, push to the end of the array\n\t\tif (index === -1) this.sortedMiddlewares.push(value);\n\t\telse this.sortedMiddlewares.splice(index, 0, value);\n\n\t\treturn super.set(key, value);\n\t}\n\n\tpublic override delete(key: string): boolean {\n\t\tconst index = this.sortedMiddlewares.findIndex((middleware) => middleware.name === key);\n\n\t\t// If the middleware was found, remove it\n\t\tif (index !== -1) this.sortedMiddlewares.splice(index, 1);\n\n\t\treturn super.delete(key);\n\t}\n\n\tpublic override clear(): void {\n\t\tthis.sortedMiddlewares.length = 0;\n\t\treturn super.clear();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/Route.ts"],"names":["Piece","RouterRoot","isNullish"],"mappings":";;;;;;;;;;AA6CO,IAAe,MAAA,GAAf,MAAe,MAAA,SAA6DA,YAAyB,CAAA;AAAA,EAqBpG,WAAY,CAAA,OAAA,EAA8B,OAAmB,GAAA,EAAe,EAAA;AAClF,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA,CAAA;AA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C;AAEA,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AACZ,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,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.cjs","sourcesContent":["import { Piece } from '@sapphire/pieces';\nimport { isNullish, type Awaitable } from '@sapphire/utilities';\nimport type { ApiRequest } from './api/ApiRequest';\nimport type { ApiResponse } from './api/ApiResponse';\nimport type { MethodName } from './http/HttpMethods';\nimport 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"]}
|
|
@@ -16,5 +16,5 @@ __name(_RouteLoaderStrategy, "RouteLoaderStrategy");
|
|
|
16
16
|
var RouteLoaderStrategy = _RouteLoaderStrategy;
|
|
17
17
|
|
|
18
18
|
exports.RouteLoaderStrategy = RouteLoaderStrategy;
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=RouteLoaderStrategy.cjs.map
|
|
20
20
|
//# sourceMappingURL=RouteLoaderStrategy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteLoaderStrategy.ts"],"names":["LoaderStrategy"],"mappings":";;;;;;AAIO,IAAM,oBAAA,GAAN,MAAM,oBAAA,SAA4BA,qBAAsB,CAAA;AAAA,EAC9C,MAAA,CAAO,OAAmB,KAAoB,EAAA;AAC7D,IAAM,KAAA,CAAA,MAAA,CAAO,IAAI,KAAK,CAAA,CAAA;AAAA,GACvB;AAAA,EAEgB,QAAA,CAAS,OAAmB,KAAoB,EAAA;AAC/D,IAAM,KAAA,CAAA,MAAA,CAAO,OAAO,KAAK,CAAA,CAAA;AAAA,GAC1B;AACD,CAAA,CAAA;AAR+D,MAAA,CAAA,oBAAA,EAAA,qBAAA,CAAA,CAAA;AAAxD,IAAM,mBAAN,GAAA","file":"RouteLoaderStrategy.cjs","sourcesContent":["import { LoaderStrategy } from '@sapphire/pieces';\nimport type { Route } from './Route';\nimport type { RouteStore } from './RouteStore';\n\nexport class RouteLoaderStrategy extends LoaderStrategy<Route> {\n\tpublic override onLoad(store: RouteStore, piece: Route): void {\n\t\tstore.router.add(piece);\n\t}\n\n\tpublic override onUnload(store: RouteStore, piece: Route): void {\n\t\tstore.router.remove(piece);\n\t}\n}\n"]}
|
|
@@ -8,7 +8,7 @@ var RouterRoot_cjs = require('./router/RouterRoot.cjs');
|
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
9
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
10
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
11
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
11
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
12
12
|
var _RouteStore = class _RouteStore extends pieces.Store {
|
|
13
13
|
constructor() {
|
|
14
14
|
super(Route_cjs.Route, { name: "routes", strategy: new RouteLoaderStrategy_cjs.RouteLoaderStrategy() });
|
|
@@ -19,5 +19,5 @@ __name(_RouteStore, "RouteStore");
|
|
|
19
19
|
var RouteStore = _RouteStore;
|
|
20
20
|
|
|
21
21
|
exports.RouteStore = RouteStore;
|
|
22
|
-
//# sourceMappingURL=
|
|
22
|
+
//# sourceMappingURL=RouteStore.cjs.map
|
|
23
23
|
//# sourceMappingURL=RouteStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/structures/RouteStore.ts"],"names":["Store","Route","RouteLoaderStrategy","RouterRoot"],"mappings":";;;;;;;;;;;AAQO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,YAAuB,CAAA;AAAA,EAG/C,WAAc,GAAA;AACpB,IAAM,KAAA,CAAAC,eAAA,EAAO,EAAE,IAAM,EAAA,QAAA,EAAU,UAAU,IAAIC,2CAAA,IAAuB,CAAA,CAAA;AAHrE,IAAgB,aAAA,CAAA,IAAA,EAAA,QAAA,EAAS,IAAIC,yBAAW,EAAA,CAAA,CAAA;AAAA,GAIxC;AACD,CAAA,CAAA;AANuD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAhD,IAAM,UAAN,GAAA","file":"RouteStore.cjs","sourcesContent":["import { Store } from '@sapphire/pieces';\nimport { Route } from './Route';\nimport { RouteLoaderStrategy } from './RouteLoaderStrategy';\nimport { RouterRoot } from './router/RouterRoot';\n\n/**\n * @since 1.0.0\n */\nexport class RouteStore extends Store<Route, 'routes'> {\n\tpublic readonly router = new RouterRoot();\n\n\tpublic constructor() {\n\t\tsuper(Route, { name: 'routes', strategy: new RouteLoaderStrategy() });\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiRequest.ts"],"names":["IncomingMessage"],"mappings":";;;;;;;;AAKO,IAAM,WAAA,GAAN,MAAM,WAAA,SAAmBA,oBAAgB,CAAA;AAAA,EAAzC,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AAIN;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,SAA2C,EAAC,CAAA,CAAA;AAKnD;AAAA;AAAA;AAAA,IAAA,aAAA,CAAA,IAAA,EAAO,UAAiC,EAAC,CAAA,CAAA;AAKzC;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AASP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,MAAA,CAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,YAAA,CAAA,CAAA;AAcP;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AAAA,GAAA;AACR,CAAA,CAAA;AApDgD,MAAA,CAAA,WAAA,EAAA,YAAA,CAAA,CAAA;AAAzC,IAAM,UAAN,GAAA","file":"ApiRequest.cjs","sourcesContent":["import { IncomingMessage } from 'node:http';\nimport type { Route } from '../Route';\nimport type { AuthData } from '../http/Auth';\nimport type { RouterNode } from '../router/RouterNode';\n\nexport class ApiRequest extends IncomingMessage {\n\t/**\n\t * The query parameters.\n\t */\n\tpublic query: Record<string, string | string[]> = {};\n\n\t/**\n\t * The URI parameters.\n\t */\n\tpublic params: Record<string, string> = {};\n\n\t/**\n\t * The body that was sent by the user.\n\t */\n\tpublic body?: unknown;\n\n\t/**\n\t * The authorization information. This field indicates three possible values:\n\t *\n\t * - `undefined`: The authorization middleware has not been executed yet.\n\t * - `null`: The user is not authorized.\n\t * - `AuthData`: The user is authorized.\n\t */\n\tpublic auth?: AuthData | null;\n\n\t/**\n\t * The router node that matched the request. The field indicates three\n\t * possible values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no node matched the\n\t * request.\n\t * - `RouterNode`: The router handler has been executed and a node matched\n\t * the request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic routerNode?: RouterNode | null;\n\n\t/**\n\t * The route that matched the request. The field indicates three possible\n\t * values:\n\t *\n\t * - `undefined`: The router handler has not been executed yet.\n\t * - `null`: The router handler has been executed, but no route matched the\n\t * request.\n\t * - `Route`: The router handler has been executed and a route matched the\n\t * request.\n\t *\n\t * @since 7.0.0\n\t */\n\tpublic route?: Route | null;\n}\n"]}
|
|
@@ -9,7 +9,7 @@ var HttpCodes_cjs = require('../http/HttpCodes.cjs');
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
10
10
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
11
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj,
|
|
12
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
13
13
|
var _ApiResponse = class _ApiResponse extends http.ServerResponse {
|
|
14
14
|
constructor() {
|
|
15
15
|
super(...arguments);
|
|
@@ -143,5 +143,5 @@ __name(_ApiResponse, "ApiResponse");
|
|
|
143
143
|
var ApiResponse = _ApiResponse;
|
|
144
144
|
|
|
145
145
|
exports.ApiResponse = ApiResponse;
|
|
146
|
-
//# sourceMappingURL=
|
|
146
|
+
//# sourceMappingURL=ApiResponse.cjs.map
|
|
147
147
|
//# sourceMappingURL=ApiResponse.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/ApiResponse.ts"],"names":["ServerResponse","STATUS_CODES","HttpCodes","MimeTypes","Readable"],"mappings":";;;;;;;;;;;;AAUO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAuEA,mBAAwB,CAAA;AAAA,EAArG,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CA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A,cAAA,CAAeE,wBAAU,eAAe,CAAA,CAAE,IAAI,IAAK,CAAA,SAAA,CAAU,IAAI,CAAC,CAAA,CAAA;AAAA,GACxE;AAAA;AAAA;AAAA;AAAA,EAKO,KAAK,IAAoB,EAAA;AAC/B,IAAA,IAAA,CAAK,cAAe,CAAAA,uBAAA,CAAU,SAAS,CAAA,CAAE,IAAI,IAAI,CAAA,CAAA;AAAA,GAClD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUO,KAAA,CACN,MACA,IACO,EAAA;AACP,IAAA,IAAI,gBAAgBC,eAAU,EAAA;AAC7B,MAAA,IAAA,CAAK,eAAe,IAAI,CAAA,CAAA;AACxB,MAAA,IAAA,CAAK,KAAK,IAAI,CAAA,CAAA;AAAA,KACR,MAAA;AACN,MAAA,IAAA,CAAK,cAAe,CAAA,IAAI,CAAE,CAAA,GAAA,CAAI,IAAI,CAAA,CAAA;AAAA,KACnC;AAAA,GACD;AAAA;AAAA;AAAA;AAAA,EAKO,IAAA,CAAK,MAAc,IAAoB,EAAA;AAC7C,IAAK,IAAA,CAAA,cAAA,CAAeD,wBAAU,QAAQ,CAAA,CAAE,OAAO,IAAI,CAAA,CAAE,IAAI,IAAI,CAAA,CAAA;AAAA,GAC9D;AAAA;AAAA;AAAA;AAAA,EAKO,eAAe,WAA8B,EAAA;AACnD,IAAK,IAAA,CAAA,SAAA,CAAU,gBAAgB,WAAW,CAAA,CAAA;AAC1C,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AACD,CAAA,CAAA;AAlJ4G,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAArG,IAAM,WAAN,GAAA","file":"ApiResponse.cjs","sourcesContent":["import { IncomingMessage, ServerResponse, STATUS_CODES } from 'node:http';\nimport { Readable } from 'node:stream';\nimport { ReadableStream } from 'node:stream/web';\nimport { MimeTypes } from '../../utils/MimeTypes';\nimport { HttpCodes } from '../http/HttpCodes';\nimport type { CookieStore } from './CookieStore';\n\n/**\n * @since 1.0.0\n */\nexport class ApiResponse<Request extends IncomingMessage = IncomingMessage> extends ServerResponse<Request> {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic cookies!: CookieStore;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic ok(data: unknown = STATUS_CODES[HttpCodes.OK]): void {\n\t\tthis.status(HttpCodes.OK);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic created(data: unknown = STATUS_CODES[HttpCodes.Created]): void {\n\t\tthis.status(HttpCodes.Created);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic noContent(data: unknown = STATUS_CODES[HttpCodes.NoContent]): void {\n\t\tthis.status(HttpCodes.NoContent);\n\t\treturn this.respond(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic badRequest(data?: unknown): void {\n\t\treturn this.error(HttpCodes.BadRequest, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic unauthorized(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Unauthorized, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic forbidden(data?: unknown): void {\n\t\treturn this.error(HttpCodes.Forbidden, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic notFound(data?: unknown): void {\n\t\treturn this.error(HttpCodes.NotFound, data);\n\t}\n\n\t/**\n\t * @since 7.0.0\n\t */\n\tpublic methodNotAllowed(data?: unknown): void {\n\t\treturn this.error(HttpCodes.MethodNotAllowed, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic conflict(data?: unknown) {\n\t\treturn this.error(HttpCodes.Conflict, data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic error(error: number | string, data?: unknown): void {\n\t\tif (typeof error === 'string') {\n\t\t\treturn this.status(HttpCodes.InternalServerError).json({ error });\n\t\t}\n\n\t\treturn this.status(error).json({ error: data ?? STATUS_CODES[error] });\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic respond(data: unknown): void {\n\t\treturn typeof data === 'string' ? this.text(data) : this.json(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic status(code: number): this {\n\t\tthis.statusCode = code;\n\t\treturn this;\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic json(data: any): void {\n\t\tthis.setContentType(MimeTypes.ApplicationJson).end(JSON.stringify(data));\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic text(data: string): void {\n\t\tthis.setContentType(MimeTypes.TextPlain).end(data);\n\t}\n\n\t/**\n\t * @since 6.1.0\n\t *\n\t * Sets the image content type and sends the image data in the response.\n\t *\n\t * @param type - The MIME type of the image (e.g., {@link MimeTypes.ImagePng}).\n\t * @param data - The image data as a `string`, {@link Buffer}, {@link Uint8Array}, or {@link ReadableStream}.\n\t */\n\tpublic image(\n\t\ttype: MimeTypes.ImageGif | MimeTypes.ImageJpg | MimeTypes.ImagePng | MimeTypes.ImageWebp | MimeTypes.ImageXIcon,\n\t\tdata: string | Buffer | Uint8Array | Readable\n\t): void {\n\t\tif (data instanceof Readable) {\n\t\t\tthis.setContentType(type);\n\t\t\tdata.pipe(this);\n\t\t} else {\n\t\t\tthis.setContentType(type).end(data);\n\t\t}\n\t}\n\n\t/**\n\t * @since 5.1.0\n\t */\n\tpublic html(code: number, data: string): void {\n\t\tthis.setContentType(MimeTypes.TextHtml).status(code).end(data);\n\t}\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic setContentType(contentType: MimeTypes): this {\n\t\tthis.setHeader('Content-Type', contentType);\n\t\treturn this;\n\t}\n}\n"]}
|
|
@@ -97,5 +97,5 @@ __publicField(_CookieStore, "octetRegExp", /[^\x21\x23-\x2B\x2D-\x3A\x3C-\x5B\x5
|
|
|
97
97
|
var CookieStore = _CookieStore;
|
|
98
98
|
|
|
99
99
|
exports.CookieStore = CookieStore;
|
|
100
|
-
//# sourceMappingURL=
|
|
100
|
+
//# sourceMappingURL=CookieStore.cjs.map
|
|
101
101
|
//# sourceMappingURL=CookieStore.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/api/CookieStore.ts"],"names":["getDomain"],"mappings":";;;;;;;;AAOO,IAAM,YAAA,GAAN,MAAM,YAAA,SAAoB,GAAoB,CAAA;AAAA,EAM7C,WAAY,CAAA,OAAA,EAAqB,QAAuB,EAAA,MAAA,EAAiB,eAAiC,EAAA;AAChH,IAAM,KAAA,EAAA,CAAA;AANP,IAAU,aAAA,CAAA,IAAA,EAAA,SAAA,CAAA,CAAA;AACV,IAAU,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AACV,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AACR,IAAQ,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAKP,IAAA,IAAA,CAAK,OAAU,GAAA,OAAA,CAAA;AACf,IAAA,IAAA,CAAK,QAAW,GAAA,QAAA,CAAA;AAGhB,IAAA,MAAM,EAAE,MAAA,GAAS,EAAG,EAAA,GAAI,OAAQ,CAAA,OAAA,CAAA;AAChC,IAAM,MAAA,KAAA,GAAQ,MAAO,CAAA,KAAA,CAAM,GAAG,CAAA,CAAA;AAE9B,IAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACzB,MAAM,MAAA,KAAA,GAAQ,IAAK,CAAA,OAAA,CAAQ,GAAG,CAAA,CAAA;AAC9B,MAAA,IAAI,UAAU,CAAI,CAAA,EAAA,SAAA;AAElB,MAAM,MAAA,GAAA,GAAM,mBAAmB,IAAK,CAAA,KAAA,CAAM,GAAG,KAAK,CAAA,CAAE,MAAM,CAAA,CAAA;AAC1D,MAAM,MAAA,KAAA,GAAQ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AA;AAC3B,IAAS,KAAA,IAAA,CAAA,OAAA,EAAU,QAAQ,GAAG,CAAA,CAAA,CAAA;AAE9B,IAAA,IAAI,KAAK,MAAQ,EAAA;AAChB,MAAS,KAAA,IAAA,CAAA,QAAA,CAAA,CAAA;AAAA,KACV;AAEA,IAAA,IAAI,YAAY,IAAM,EAAA;AACrB,MAAS,KAAA,IAAA,CAAA,UAAA,CAAA,CAAA;AAAA,KACV;AAEA,IAAO,OAAA,KAAA,CAAA;AAAA,GACR;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQQ,cAAc,IAAsB,EAAA;AAE3C,IAAM,MAAA,aAAA,GAAgB,KAAK,WAAY,EAAA,CAAA;AAGvC,IAAM,MAAA,aAAA,GAAgBA,gBAAU,aAAa,CAAA,CAAA;AAG7C,IAAI,IAAA,CAAC,eAAsB,OAAA,aAAA,CAAA;AAG3B,IAAA,OAAO,IAAI,aAAa,CAAA,CAAA,CAAA;AAAA,GACzB;AAAA,EAKA,OAAe,kBAAkB,KAAe,EAAA;AAC/C,IAAA,IAAI,YAAY,CAAA,WAAA,CAAY,IAAK,CAAA,KAAK,CAAG,EAAA;AACxC,MAAM,MAAA,IAAI,MAAM,CAA4B,0BAAA,CAAA,CAAA,CAAA;AAAA,KAC7C;AAEA,IAAA,OAAO,mBAAmB,KAAK,CAAA,CAAA;AAAA,GAChC;AACD,CAAA,CAAA;AA9HqD,MAAA,CAAA,YAAA,EAAA,aAAA,CAAA,CAAA;AAAA;AAqHpD,aAAA,CArHY,cAqHY,aAAc,EAAA,8CAAA,CAAA,CAAA;AArHhC,IAAM,WAAN,GAAA","file":"CookieStore.cjs","sourcesContent":["// Copyright (c) 2018 Stanislav Woodger. All rights reserved. MIT license.\n// Source: https://github.com/woodger/cookie-httponly\n\nimport { getDomain } from 'tldts';\nimport type { ApiRequest } from './ApiRequest';\nimport type { ApiResponse } from './ApiResponse';\n\nexport class CookieStore extends Map<string, string> {\n\tprotected request: ApiRequest;\n\tprotected response: ApiResponse;\n\tprivate domain: string;\n\tprivate secure: boolean;\n\n\tpublic constructor(request: ApiRequest, response: ApiResponse, secure: boolean, domainOverwrite?: string | null) {\n\t\tsuper();\n\n\t\tthis.request = request;\n\t\tthis.response = response;\n\n\t\t// Read cookies\n\t\tconst { cookie = '' } = request.headers;\n\t\tconst pairs = cookie.split(';');\n\n\t\tfor (const pair of pairs) {\n\t\t\tconst index = pair.indexOf('=');\n\t\t\tif (index === -1) continue;\n\n\t\t\tconst key = decodeURIComponent(pair.slice(0, index).trim());\n\t\t\tconst value = decodeURIComponent(pair.slice(index + 1).trim());\n\t\t\tthis.set(key, value);\n\t\t}\n\n\t\tconst [splitHost] = this.request.headers.host?.split(':') ?? [''];\n\n\t\tthis.domain = domainOverwrite ?? this.getHostDomain(splitHost);\n\n\t\tif (this.request.socket.remoteAddress === this.domain) {\n\t\t\tthrow new Error('The connection must be established from the domain name (i.e., not an IP address)');\n\t\t}\n\n\t\t// RFC 6265 4.1.2.5. The Secure Attribute\n\t\tthis.secure = secure;\n\t}\n\n\tpublic add(name: string, value: string, options?: SecureCookieStoreSetOptions) {\n\t\tthis.insert(name, this.prepare(name, value, options));\n\t}\n\n\tpublic remove(name: string) {\n\t\tthis.add(name, '', { expires: new Date(0) });\n\t}\n\n\tprotected insert(name: string, entry: string) {\n\t\tlet set = this.response.getHeader('Set-Cookie');\n\n\t\tif (set === undefined) {\n\t\t\tset = [];\n\t\t} else if (!Array.isArray(set)) {\n\t\t\tset = [set.toString()];\n\t\t}\n\n\t\tset = set.filter((i) => i.slice(0, i.indexOf('=')) !== name);\n\t\tset.push(entry);\n\n\t\tthis.response.setHeader('Set-Cookie', set);\n\t}\n\n\tprotected prepare(name: string, value: string, { expires, maxAge, domain, path, httpOnly }: SecureCookieStoreSetOptions = {}) {\n\t\tconst now = new Date();\n\n\t\tif (expires === undefined) {\n\t\t\texpires = now;\n\t\t}\n\n\t\t// RFC 6265 4.1.1. Syntax\n\t\tname = CookieStore.encodeCookieOctet(name);\n\t\tvalue = CookieStore.encodeCookieOctet(value);\n\n\t\tlet entry = `${name}=${value}`;\n\n\t\tif (expires !== now) {\n\t\t\tentry += `; Expires=${expires.toUTCString()}`;\n\t\t} else if (maxAge) {\n\t\t\tentry += `; Max-Age=${maxAge}`;\n\t\t}\n\n\t\t// RFC 6265 5.1.3 Domain Matching\n\t\tdomain = (domain ?? this.domain).toLowerCase();\n\n\t\tentry += `; Domain=${domain}`;\n\t\tentry += `; Path=${path ?? '/'}`;\n\n\t\tif (this.secure) {\n\t\t\tentry += `; Secure`;\n\t\t}\n\n\t\tif (httpOnly ?? true) {\n\t\t\tentry += `; HttpOnly`;\n\t\t}\n\n\t\treturn entry;\n\t}\n\n\t/**\n\t * Parses a host using the {@linkplain https://github.com/remusao/tldts tldts} library to extract the domain.\n\t * This is used for the domain of the cookie\n\t * @param host The hot to parse\n\t * @returns Either the host in all lower case or the parsed domain, ready for use on cookies\n\t */\n\tprivate getHostDomain(host: string): string {\n\t\t// Transform the host to lower case\n\t\tconst lowercaseHost = host.toLowerCase();\n\n\t\t// Try parsing the host with tldts\n\t\tconst tldParsedInfo = getDomain(lowercaseHost);\n\n\t\t// If the domain is not defined then return the host in lowercase\n\t\tif (!tldParsedInfo) return lowercaseHost;\n\n\t\t// If the domain was found from parsing then prefix it with a . for a cookie that works with subdomains and return it\n\t\treturn `.${tldParsedInfo}`;\n\t}\n\n\t// RFC 6265 4.1.1. Syntax\n\tprivate static readonly octetRegExp = /[^\\x21\\x23-\\x2B\\x2D-\\x3A\\x3C-\\x5B\\x5D-\\x7E]/g;\n\n\tprivate static encodeCookieOctet(value: string) {\n\t\tif (CookieStore.octetRegExp.test(value)) {\n\t\t\tthrow new Error(`Invalid character in value`);\n\t\t}\n\n\t\treturn encodeURIComponent(value);\n\t}\n}\n\nexport interface SecureCookieStoreSetOptions {\n\texpires?: Date;\n\tmaxAge?: number;\n\tdomain?: string;\n\tpath?: string;\n\thttpOnly?: boolean;\n}\n"]}
|
|
@@ -15,7 +15,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
15
15
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
16
16
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
17
17
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
18
|
-
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"),
|
|
18
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
19
19
|
var _secret;
|
|
20
20
|
var _Auth = class _Auth {
|
|
21
21
|
constructor(options) {
|
|
@@ -128,5 +128,5 @@ __name(_Auth, "Auth");
|
|
|
128
128
|
var Auth = _Auth;
|
|
129
129
|
|
|
130
130
|
exports.Auth = Auth;
|
|
131
|
-
//# sourceMappingURL=
|
|
131
|
+
//# sourceMappingURL=Auth.cjs.map
|
|
132
132
|
//# sourceMappingURL=Auth.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,SAAS,kBAAkC;AAC3C,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAKM;AACP,SAAS,aAAa;AAXtB;AAaO,IAAM,QAAN,MAAM,MAAK;AAAA,EAmCT,YAAY,SAA4B;AA9BhD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAEP,wBAAO,mBAAiC;AAExC;A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iBAAoD,aAAa,QAAQ,OAAO,GAAG,WAAW,GAAG,GAAG,OAAO,WAAW,CAAC,EAAE;AAAA,MAC9H,KAAK;AAAA,QACJ,aAAa;AAAA,QACb;AAAA,QACA,GAAG,WAAW,GAAG,GAAG,OAAO,gBAAgB,CAAC;AAAA,MAC7C;AAAA,IACD,CAAC;AAGD,QAAI,OAAkB,EAAE,MAAM,QAAQ,YAAY;AAClD,eAAW,eAAe,KAAK,cAAc;AAC5C,YAAM,SAAS,YAAY,IAAI;AAC/B,UAAI,WAAW,MAAM,EAAG,QAAO,MAAM;AAAA,UAChC,QAAO;AAAA,IACb;AAEA,WAAO;AAAA,EACR;AAAA,EAEA,MAAc,iBAAoB,OAAqB,OAAe,KAA4C;AACjH,QAAI,CAAC,KAAK,OAAO,SAAS,KAAK,EAAG,QAAO;AAEzC,UAAM,SAAS,MAAM,MAAM,KAAK;AAAA,MAC/B,SAAS;AAAA,QACR,eAAe,UAAU,KAAK;AAAA,MAC/B;AAAA,IACD,CAAC;AAED,WAAO,OAAO,KAAO,MAAM,OAAO,KAAK,IAAW;AAAA,EACnD;AAAA,EAEA,OAAc,OAAO,SAA0C;AAC9D,QAAI,CAAC,SAAS,UAAU,CAAC,QAAQ,GAAI,QAAO;AAC5C,WAAO,IAAI,MAAK,OAAO;AAAA,EACxB;AACD;AA7FC;AAjCiB;AAAX,IAAM,OAAN","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id as Snowflake;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/lib/structures/http/Auth.ts"],"names":["OAuth2Scopes","randomBytes","createCipheriv","createDecipheriv","RouteBases","Routes","isThenable","fetch"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAA,OAAA,CAAA;AAaO,IAAM,KAAA,GAAN,MAAM,KAAK,CAAA;AAAA,EAmCT,YAAY,OAA4B,EAAA;AA9BhD;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,IAAA,CAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,QAAA,CAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,cAAA,CAAA,CAAA;AAEP,IAAA,aAAA,CAAA,IAAA,EAAO,iBAAiC,EAAA,IAAA,CAAA,CAAA;AAExC,IAAA,YAAA,CAAA,IAAA,EAAA,OAAA,CAAA,CAAA;AAGC,IAAA,IAAA,CAAK,KAAK,OAAQ,CAAA,EAAA,CAAA;AAClB,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ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,MAAA,MAAA,GAAS,YAAY,IAAI,CAAA,CAAA;AAC/B,MAAA,IAAIC,oBAAW,CAAA,MAAM,CAAG,EAAA,IAAA,GAAO,MAAM,MAAA,CAAA;AAAA,WACzB,IAAA,GAAA,MAAA,CAAA;AAAA,KACb;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACR;AAAA,EAEA,MAAc,gBAAA,CAAoB,KAAqB,EAAA,KAAA,EAAe,GAA4C,EAAA;AACjH,IAAA,IAAI,CAAC,IAAK,CAAA,MAAA,CAAO,QAAS,CAAA,KAAK,GAAU,OAAA,KAAA,CAAA,CAAA;AAEzC,IAAM,MAAA,MAAA,GAAS,MAAMC,YAAA,CAAM,GAAK,EAAA;AAAA,MAC/B,OAAS,EAAA;AAAA,QACR,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA;AAAA,OAC/B;AAAA,KACA,CAAA,CAAA;AAED,IAAA,OAAO,MAAO,CAAA,EAAA,GAAO,MAAM,MAAA,CAAO,MAAgB,GAAA,IAAA,CAAA;AAAA,GACnD;AAAA,EAEA,OAAc,OAAO,OAA0C,EAAA;AAC9D,IAAA,IAAI,CAAC,OAAS,EAAA,MAAA,IAAU,CAAC,OAAA,CAAQ,IAAW,OAAA,IAAA,CAAA;AAC5C,IAAO,OAAA,IAAI,MAAK,OAAO,CAAA,CAAA;AAAA,GACxB;AACD,CAAA,CAAA;AA7FC,OAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AAjCiB,MAAA,CAAA,KAAA,EAAA,MAAA,CAAA,CAAA;AAAX,IAAM,IAAN,GAAA","file":"Auth.cjs","sourcesContent":["import { isThenable, type Awaitable } from '@sapphire/utilities';\nimport { createCipheriv, createDecipheriv, randomBytes } from 'crypto';\nimport {\n\tOAuth2Scopes,\n\tRouteBases,\n\tRoutes,\n\ttype RESTGetAPICurrentUserConnectionsResult,\n\ttype RESTGetAPICurrentUserGuildsResult,\n\ttype RESTGetAPICurrentUserResult,\n\ttype Snowflake\n} from 'discord.js';\nimport { fetch } from 'undici';\n\nexport class Auth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic id: Snowflake;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t */\n\tpublic cookie: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t */\n\tpublic scopes: readonly OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri.\n\t * @since 1.0.0\n\t */\n\tpublic redirect: string | undefined;\n\n\t/**\n\t * The transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t */\n\tpublic transformers: LoginDataTransformer[];\n\n\tpublic domainOverwrite: string | null = null;\n\n\t#secret: string;\n\n\tprivate constructor(options: ServerOptionsAuth) {\n\t\tthis.id = options.id as Snowflake;\n\t\tthis.cookie = options.cookie ?? 'SAPPHIRE_AUTH';\n\t\tthis.scopes = options.scopes ?? [OAuth2Scopes.Identify];\n\t\tthis.redirect = options.redirect;\n\t\tthis.#secret = options.secret;\n\t\tthis.transformers = options.transformers ?? [];\n\t\tthis.domainOverwrite = options.domainOverwrite ?? null;\n\t}\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tpublic get secret() {\n\t\treturn this.#secret;\n\t}\n\n\t/**\n\t * Encrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param data An object to encrypt\n\t */\n\tpublic encrypt(data: AuthData): string {\n\t\tconst iv = randomBytes(16);\n\t\tconst cipher = createCipheriv('aes-256-cbc', this.#secret, iv);\n\t\treturn `${cipher.update(JSON.stringify(data), 'utf8', 'base64') + cipher.final('base64')}.${iv.toString('base64')}`;\n\t}\n\n\t/**\n\t * Decrypts an object with aes-256-cbc to use as a token.\n\t * @since 1.0.0\n\t * @param token An data to decrypt\n\t */\n\tpublic decrypt(token: string): AuthData | null {\n\t\tconst [data, iv] = token.split('.');\n\t\tconst decipher = createDecipheriv('aes-256-cbc', this.#secret, Buffer.from(iv, 'base64'));\n\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(decipher.update(data, 'base64', 'utf8') + decipher.final('utf8')) as AuthData;\n\t\t\t// If the token expired, return null:\n\t\t\treturn parsed.expires >= Date.now() ? parsed : null;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves the data for a specific user.\n\t * @since 1.4.0\n\t * @param token The access token from the user.\n\t */\n\tpublic async fetchData(token: string): Promise<LoginData> {\n\t\t// Fetch the information:\n\t\tconst [user, guilds, connections] = await Promise.all([\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserResult>(OAuth2Scopes.Identify, token, `${RouteBases.api}${Routes.user()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserGuildsResult>(OAuth2Scopes.Guilds, token, `${RouteBases.api}${Routes.userGuilds()}`),\n\t\t\tthis.fetchInformation<RESTGetAPICurrentUserConnectionsResult>(\n\t\t\t\tOAuth2Scopes.Connections,\n\t\t\t\ttoken,\n\t\t\t\t`${RouteBases.api}${Routes.userConnections()}`\n\t\t\t)\n\t\t]);\n\n\t\t// Transform the information:\n\t\tlet data: LoginData = { user, guilds, connections };\n\t\tfor (const transformer of this.transformers) {\n\t\t\tconst result = transformer(data);\n\t\t\tif (isThenable(result)) data = await result;\n\t\t\telse data = result as LoginData;\n\t\t}\n\n\t\treturn data;\n\t}\n\n\tprivate async fetchInformation<T>(scope: OAuth2Scopes, token: string, url: string): Promise<T | null | undefined> {\n\t\tif (!this.scopes.includes(scope)) return undefined;\n\n\t\tconst result = await fetch(url, {\n\t\t\theaders: {\n\t\t\t\tauthorization: `Bearer ${token}`\n\t\t\t}\n\t\t});\n\n\t\treturn result.ok ? ((await result.json()) as T) : null;\n\t}\n\n\tpublic static create(options?: ServerOptionsAuth): Auth | null {\n\t\tif (!options?.secret || !options.id) return null;\n\t\treturn new Auth(options);\n\t}\n}\n\n/**\n * Defines the authentication data, this is to be encrypted and decrypted by the server.\n * @since 1.0.0\n */\nexport interface AuthData {\n\t/**\n\t * The user ID.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The timestamp at which the token expires.\n\t * @since 1.0.0\n\t */\n\texpires: number;\n\n\t/**\n\t * The refresh token.\n\t * @since 1.0.0\n\t */\n\trefresh: string;\n\n\t/**\n\t * The access token.\n\t * @since 1.0.0\n\t */\n\ttoken: string;\n}\n\n/**\n * Defines the authentication options.\n * @since 1.0.0\n */\nexport interface ServerOptionsAuth {\n\t/**\n\t * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tid: string;\n\n\t/**\n\t * The name for the cookie, this will be used to identify a Secure HttpOnly cookie.\n\t * @since 1.0.0\n\t * @default 'SAPPHIRE_AUTH'\n\t */\n\tcookie?: string;\n\n\t/**\n\t * The client secret, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications.\n\t * @since 1.0.0\n\t */\n\tsecret: string;\n\n\t/**\n\t * The scopes defined at https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.\n\t * @since 1.0.0\n\t * @default [OAuth2Scopes.Identify]\n\t */\n\tscopes?: OAuth2Scopes[];\n\n\t/**\n\t * The redirect uri. This will default to {@link OAuth2BodyData.redirectUri} if missing.\n\t * @since 1.0.0\n\t */\n\tredirect?: string;\n\n\t/**\n\t * The login data transformers used for {@link Auth.fetchData}.\n\t * @since 1.4.0\n\t * @default []\n\t */\n\ttransformers?: LoginDataTransformer[];\n\t/**\n\t * The domain that should be used for the cookie. This overwrites the automatic detection of the domain.\n\t * @remark if you want to support subdomains (`one.example.two` and `two.example.com`) then you need to use prefix your domain with a `.`, for example `.example.com`\n\t * @since 2.1.0\n\t * @default undefined\n\t */\n\tdomainOverwrite?: string;\n}\n\n/**\n * The login data sent when fetching data from a user.\n * @since 1.4.0\n */\nexport interface LoginData {\n\t/**\n\t * The user data, defined when the `'identify'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tuser?: RESTGetAPICurrentUserResult | null;\n\n\t/**\n\t * The guilds data, defined when the `'guilds'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tguilds?: RESTGetAPICurrentUserGuildsResult | null;\n\n\t/**\n\t * The connections data, defined when the `'connections'` scope is defined.\n\t * @since 1.4.0\n\t */\n\tconnections?: RESTGetAPICurrentUserConnectionsResult | null;\n}\n\n/**\n * A login data transformer.\n * @since 1.4.0\n */\nexport interface LoginDataTransformer<T extends LoginData = LoginData> {\n\t/**\n\t * Transforms the object by mutating its properties or adding new ones.\n\t * @since 1.4.0\n\t */\n\t(data: LoginData): Awaitable<T>;\n}\n"]}
|