@webiny/handler 6.3.0-beta.4 → 6.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Context.js +10 -23
- package/Context.js.map +1 -1
- package/PreHandler/IPreHandler.js +5 -4
- package/PreHandler/IPreHandler.js.map +1 -1
- package/PreHandler/IfNotOptionsRequest.js +12 -15
- package/PreHandler/IfNotOptionsRequest.js.map +1 -1
- package/PreHandler/IfOptionsRequest.js +12 -15
- package/PreHandler/IfOptionsRequest.js.map +1 -1
- package/PreHandler/PreHandler.js +11 -12
- package/PreHandler/PreHandler.js.map +1 -1
- package/PreHandler/ProcessBeforeHandlerPlugins.js +19 -18
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -1
- package/PreHandler/ProcessContextPlugins.js +19 -18
- package/PreHandler/ProcessContextPlugins.js.map +1 -1
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +18 -19
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -1
- package/PreHandler/RegisterExtensions.js +8 -9
- package/PreHandler/RegisterExtensions.js.map +1 -1
- package/PreHandler/SendEarlyOptionsResponse.js +20 -25
- package/PreHandler/SendEarlyOptionsResponse.js.map +1 -1
- package/PreHandler/SetDefaultHeaders.js +37 -48
- package/PreHandler/SetDefaultHeaders.js.map +1 -1
- package/ResponseHeaders.js +29 -32
- package/ResponseHeaders.js.map +1 -1
- package/abstractions/Reply.js +2 -1
- package/abstractions/Reply.js.map +1 -1
- package/abstractions/Request.js +2 -1
- package/abstractions/Request.js.map +1 -1
- package/abstractions/Route.js +25 -24
- package/abstractions/Route.js.map +1 -1
- package/exports/api.js +0 -2
- package/fastify.js +277 -398
- package/fastify.js.map +1 -1
- package/index.js +2 -5
- package/package.json +9 -9
- package/plugins/BeforeHandlerPlugin.js +13 -14
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.js +10 -17
- package/plugins/EventPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.js +13 -12
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerOnRequestPlugin.js +13 -20
- package/plugins/HandlerOnRequestPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.js +13 -12
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/ModifyFastifyPlugin.js +13 -12
- package/plugins/ModifyFastifyPlugin.js.map +1 -1
- package/plugins/ModifyResponseHeadersPlugin.js +14 -11
- package/plugins/ModifyResponseHeadersPlugin.js.map +1 -1
- package/plugins/OnRequestResponseSendPlugin.js +13 -27
- package/plugins/OnRequestResponseSendPlugin.js.map +1 -1
- package/plugins/OnRequestTimeoutPlugin.js +13 -12
- package/plugins/OnRequestTimeoutPlugin.js.map +1 -1
- package/plugins/RegisterExtensionPlugin.js +12 -12
- package/plugins/RegisterExtensionPlugin.js.map +1 -1
- package/plugins/RoutePlugin.js +10 -9
- package/plugins/RoutePlugin.js.map +1 -1
- package/stringifyError.js +12 -17
- package/stringifyError.js.map +1 -1
- package/suppressPunycodeWarnings.js +3 -6
- package/suppressPunycodeWarnings.js.map +1 -1
- package/types.js +0 -2
- package/exports/api.js.map +0 -1
- package/index.js.map +0 -1
- package/types.js.map +0 -1
package/fastify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["PluginsContainer","fastify","middleware","Context","WebinyError","RoutePlugin","fastifyCookie","fastifyCompress","ContextPlugin","BeforeHandlerPlugin","HandlerResultPlugin","HandlerErrorPlugin","ModifyFastifyPlugin","HandlerOnRequestPlugin","ResponseHeaders","ModifyResponseHeadersPlugin","SetDefaultHeaders","PreHandler","stringifyError","ProcessHandlerOnRequestPlugins","ProcessContextPlugins","IfNotOptionsRequest","ProcessBeforeHandlerPlugins","IfOptionsRequest","SendEarlyOptionsResponse","OnRequestTimeoutPlugin","OnRequestResponseSendPlugin","Request","Reply","RegisterExtensionPlugin","RegisterExtensions","modifyResponseHeaders","app","request","reply","modifyHeaders","webiny","plugins","byType","type","replyHeaders","getHeaders","headers","create","forEach","plugin","modify","headersToSet","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","REPORT","MKCALENDAR","throwOnDefinedRoute","path","options","all","Object","keys","find","k","key","toUpperCase","routes","includes","console","error","JSON","stringify","override","addDefinedRoute","input","push","bodyLimit","disableRequestLogging","allowErrorHandlerOverride","addHook","route","method","Array","isArray","m","register","parseOptions","global","threshold","onUnsupportedEncoding","encoding","_","code","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","merge","WEBINY_VERSION","process","env","ex","decorate","addContentTypeParser","parseAs","req","body","done","undefined","json","toString","parse","err","container","registerInstance","handlerOnRequestPlugins","contextPlugins","beforeHandlerPlugins","modifyHeadersPlugins","registerExtensionPlugins","preHandler","execute","__","payload","name","handle","setErrorHandler","sent","warn","startsWith","status","send","message","data","log","map","pl","next","exec","benchmark","output","modifyPlugins","modifyFastifyPluginName","routePlugins","routePluginName","cb"],"sources":["fastify.ts"],"sourcesContent":["import type { PluginCollection } from \"@webiny/plugins/types.js\";\nimport { PluginsContainer } from \"@webiny/plugins/types.js\";\nimport type { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport fastify from \"fastify\";\nimport type { MiddlewareCallable } from \"@webiny/utils\";\nimport { middleware } from \"@webiny/utils\";\nimport type {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n RouteMethodOptions\n} from \"~/types.js\";\nimport { Context } from \"~/Context.js\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin.js\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin.js\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin.js\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin.js\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin.js\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin.js\";\nimport type { StandardHeaders } from \"~/ResponseHeaders.js\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin.js\";\nimport { SetDefaultHeaders } from \"./PreHandler/SetDefaultHeaders.js\";\nimport { PreHandler } from \"./PreHandler/PreHandler.js\";\nimport { stringifyError } from \"./stringifyError.js\";\nimport { ProcessHandlerOnRequestPlugins } from \"./PreHandler/ProcessHandlerOnRequestPlugins.js\";\nimport { ProcessContextPlugins } from \"./PreHandler/ProcessContextPlugins.js\";\nimport { IfNotOptionsRequest } from \"./PreHandler/IfNotOptionsRequest.js\";\nimport { ProcessBeforeHandlerPlugins } from \"./PreHandler/ProcessBeforeHandlerPlugins.js\";\nimport { IfOptionsRequest } from \"./PreHandler/IfOptionsRequest.js\";\nimport { SendEarlyOptionsResponse } from \"./PreHandler/SendEarlyOptionsResponse.js\";\nimport { OnRequestTimeoutPlugin } from \"~/plugins/OnRequestTimeoutPlugin.js\";\nimport { OnRequestResponseSendPlugin } from \"~/plugins/OnRequestResponseSendPlugin.js\";\nimport { Request } from \"./abstractions/Request.js\";\nimport { Reply } from \"./abstractions/Reply.js\";\nimport { RegisterExtensionPlugin } from \"~/plugins/RegisterExtensionPlugin.js\";\nimport { RegisterExtensions } from \"~/PreHandler/RegisterExtensions.js\";\n\nconst modifyResponseHeaders = (\n app: FastifyInstance,\n request: Request.Interface,\n reply: Reply.Interface\n) => {\n const modifyHeaders = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const replyHeaders = reply.getHeaders() as StandardHeaders;\n const headers = ResponseHeaders.create(replyHeaders);\n\n modifyHeaders.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n // Exclude 'set-cookie' header to avoid duplication.\n // Cookies are managed by @fastify/cookie and calling reply.headers() with 'set-cookie' duplicates them.\n const headersToSet = headers.getHeaders();\n delete headersToSet[\"set-cookie\"];\n\n reply.headers(headersToSet);\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection | PluginsContainer;\n options?: ServerOptions;\n debug?: boolean;\n}\n\nexport const createHandler = (params: CreateHandlerParams) => {\n const definedRoutes: DefinedContextRoutes = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: [],\n COPY: [],\n LOCK: [],\n MKCOL: [],\n MOVE: [],\n PROPFIND: [],\n PROPPATCH: [],\n SEARCH: [],\n TRACE: [],\n UNLOCK: [],\n REPORT: [],\n MKCALENDAR: []\n };\n\n const throwOnDefinedRoute = (\n type: HTTPMethods | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).find(k => {\n const key = k.toUpperCase() as HTTPMethods;\n const routes = definedRoutes[key];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\n throw new WebinyError(\n `You cannot override a route with onAll() method, please remove unnecessary route from the system.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n } else if (definedRoutes[type].includes(path) === false) {\n return;\n } else if (options?.override === true) {\n return;\n }\n console.error(`Error while trying to override route: [${type}] ${path}`);\n throw new WebinyError(\n `When you are trying to override existing route, you must send \"override\" parameter when adding that route.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n };\n\n const addDefinedRoute = (input: HTTPMethods, path: string): void => {\n const type = input.toUpperCase() as HTTPMethods;\n if (!definedRoutes[type]) {\n return;\n } else if (definedRoutes[type].includes(path)) {\n return;\n }\n definedRoutes[type].push(path);\n };\n\n /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n bodyLimit: 536870912, // 512MB\n disableRequestLogging: true,\n allowErrorHandlerOverride: true,\n ...(params.options || {})\n });\n\n /**\n * We need to register routes in our system to output headers later on, and disallow route overriding.\n */\n app.addHook(\"onRoute\", route => {\n const method = route.method as HTTPMethods | HTTPMethods[];\n if (Array.isArray(method)) {\n for (const m of method) {\n addDefinedRoute(m, route.path);\n }\n return;\n }\n addDefinedRoute(method, route.path);\n });\n /**\n * ############################\n * Register the Fastify plugins.\n */\n /**\n * Package @fastify/cookie\n *\n * https://github.com/fastify/fastify-cookie\n */\n app.register(fastifyCookie, {\n parseOptions: {} // options for parsing cookies\n });\n /**\n * Package @fastify/compress\n *\n * https://github.com/fastify/fastify-compress\n */\n app.register(fastifyCompress, {\n global: true,\n threshold: 1024,\n onUnsupportedEncoding: (encoding, _, reply) => {\n reply.code(406);\n return `We do not support the ${encoding} encoding.`;\n },\n inflateIfDeflated: true\n });\n /**\n * Route helpers - mostly for users.\n */\n const routes: ContextRoutes = {\n defined: definedRoutes,\n onPost: (path, handler, options) => {\n throwOnDefinedRoute(\"POST\", path, options);\n app.post(path, handler);\n },\n onGet: (path, handler, options) => {\n throwOnDefinedRoute(\"GET\", path, options);\n app.get(path, handler);\n },\n onOptions: (path, handler, options) => {\n throwOnDefinedRoute(\"OPTIONS\", path, options);\n app.options(path, handler);\n },\n onDelete: (path, handler, options) => {\n throwOnDefinedRoute(\"DELETE\", path, options);\n app.delete(path, handler);\n },\n onPatch: (path, handler, options) => {\n throwOnDefinedRoute(\"PATCH\", path, options);\n app.patch(path, handler);\n },\n onPut: (path, handler, options) => {\n throwOnDefinedRoute(\"PUT\", path, options);\n app.put(path, handler);\n },\n onAll: (path, handler, options) => {\n throwOnDefinedRoute(\"ALL\", path, options);\n app.all(path, handler);\n },\n onHead: (path, handler, options) => {\n throwOnDefinedRoute(\"HEAD\", path, options);\n app.head(path, handler);\n }\n };\n let context: Context;\n\n const plugins = new PluginsContainer([]);\n plugins.merge(params.plugins || []);\n\n try {\n context = new Context({\n plugins,\n /**\n * Inserted via webpack at build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.\n */\n app.decorate(\"webiny\", context);\n\n /**\n * To prevent Unsupported Media Type errors on OPTIONS requests with a body,\n * we need to have a custom parser\n */\n app.addContentTypeParser(\n \"application/json\",\n { parseAs: \"string\", bodyLimit: 1024 * 1024 },\n (req, body, done) => {\n if (req.method === \"OPTIONS\") {\n done(null, undefined);\n return;\n }\n\n try {\n const json = typeof body === \"string\" ? body : body.toString(\"utf8\");\n done(null, JSON.parse(json));\n } catch (err) {\n done(err as Error);\n }\n }\n );\n\n /**\n * With this we ensure that an undefined request body is not parsed on OPTIONS requests,\n * in case there's a `content-type` header set for whatever reason.\n *\n * @see https://fastify.dev/docs/latest/Reference/ContentTypeParser/#content-type-parser\n */\n app.addHook(\"onRequest\", async request => {\n if (request.method === \"OPTIONS\" && request.body === undefined) {\n request.headers[\"content-type\"] = undefined;\n }\n });\n\n /**\n * At this point, request body is properly parsed, and we can execute Webiny business logic.\n * - set default headers\n * - process `HandlerOnRequestPlugin`\n * - if OPTIONS request, exit early\n * - process `ContextPlugin`\n * - process `BeforeHandlerPlugin`\n */\n app.addHook(\"preHandler\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n\n // Bind request and reply to DI container for runtime access\n if (app.webiny.container) {\n app.webiny.container.registerInstance(Request, request);\n app.webiny.container.registerInstance(Reply, reply);\n }\n /**\n * Default code to 200 - so we do not need to set it again.\n * Usually we set errors manually when we use reply.send.\n */\n reply.code(200);\n\n const handlerOnRequestPlugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n const contextPlugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n\n const beforeHandlerPlugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(\n BeforeHandlerPlugin.type\n );\n\n const modifyHeadersPlugins = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const registerExtensionPlugins = app.webiny.plugins.byType<RegisterExtensionPlugin>(\n RegisterExtensionPlugin.type\n );\n\n const preHandler = new PreHandler([\n new RegisterExtensions(registerExtensionPlugins),\n new SetDefaultHeaders(definedRoutes),\n new ProcessHandlerOnRequestPlugins(handlerOnRequestPlugins),\n new IfNotOptionsRequest([\n new ProcessContextPlugins(app.webiny, contextPlugins),\n new ProcessBeforeHandlerPlugins(app.webiny, beforeHandlerPlugins)\n ]),\n new IfOptionsRequest([new SendEarlyOptionsResponse(modifyHeadersPlugins)])\n ]);\n\n await preHandler.execute(request, reply, app.webiny);\n });\n\n app.addHook(\"preSerialization\", async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n return payload;\n });\n\n app.setErrorHandler<WebinyError>(async (error, _, reply) => {\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler:setErrorHandler).\");\n return reply;\n }\n\n if (error.code?.startsWith(\"Authentication/\")) {\n return reply\n .status(401)\n .headers({ \"Cache-Control\": \"no-store\" })\n .send(\n JSON.stringify({\n message: error.message,\n code: error.code\n })\n );\n }\n\n if (error.code === \"Tenancy/TenantDisabled\") {\n return reply\n .status(503)\n .headers({ \"Cache-Control\": \"no-store\" })\n .send(\n JSON.stringify({\n message: error.message,\n code: error.code\n })\n );\n }\n\n return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.error(\"Logging error in @webiny/handler\");\n try {\n console.error(stringifyError(error));\n } catch (ex) {\n console.warn(\"Could not stringify error:\");\n console.log(error);\n console.error(\"Stringify error:\", ex);\n }\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (!reply.sent) {\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n } else {\n console.warn(\"Reply already sent, cannot send the result (handler:addHook:onError).\");\n }\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: MiddlewareCallable) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * Apply response headers modifier plugins.\n */\n app.addHook(\"onSend\", async (request, reply, input) => {\n modifyResponseHeaders(app, request, reply);\n const plugins = app.webiny.plugins.byType<OnRequestResponseSendPlugin>(\n OnRequestResponseSendPlugin.type\n );\n let payload = input;\n for (const plugin of plugins) {\n payload = await plugin.exec(request, reply, payload);\n }\n return payload;\n });\n\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n\n app.addHook(\"onTimeout\", async (request, reply) => {\n const plugins = app.webiny.plugins.byType<OnRequestTimeoutPlugin>(\n OnRequestTimeoutPlugin.type\n );\n for (const plugin of plugins) {\n await plugin.exec(request, reply);\n }\n await context.benchmark.output();\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,0BAA0B;AAE3D,OAAOC,OAAO,MAAM,SAAS;AAE7B,SAASC,UAAU,QAAQ,eAAe;AAO1C,SAASC,OAAO;AAChB,OAAOC,WAAW,MAAM,eAAe;AACvC,SAASC,WAAW;AACpB,OAAOC,aAAa,MAAM,iBAAiB;AAC3C,OAAOC,eAAe,MAAM,mBAAmB;AAC/C,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,mBAAmB;AAC5B,SAASC,mBAAmB;AAC5B,SAASC,kBAAkB;AA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C,OAAO,CAACC,MAAM,CAAcjC,WAAW,CAACkC,IAAI,CAAC;;EAE7E;AACJ;AACA;EACI,IAAIoI,eAAmC;EACvC,IAAI;IACA,KAAK,MAAM9H,MAAM,IAAI6H,YAAY,EAAE;MAC/BC,eAAe,GAAG9H,MAAM,CAAC0G,IAAI;MAC7B1G,MAAM,CAAC+H,EAAE,CAAC;QACN,GAAG5I,GAAG,CAACI,MAAM,CAAC2C,MAAM;QACpB4C,OAAO,EAAE3F,GAAG,CAACI;MACjB,CAAC,CAAC;IACN;EACJ,CAAC,CAAC,OAAO4F,EAAE,EAAE;IACT/C,OAAO,CAACC,KAAK,CACT,yCACIyF,eAAe,GAAG,IAAIA,eAAe,GAAG,GAAG,EAAE,2DAErD,CAAC;IACD1F,OAAO,CAACC,KAAK,CAAChE,cAAc,CAAC8G,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOhG,GAAG;AACd,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fastify.js","sources":["../src/fastify.ts"],"sourcesContent":["import type { PluginCollection } from \"@webiny/plugins/types.js\";\nimport { PluginsContainer } from \"@webiny/plugins/types.js\";\nimport type { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport fastify from \"fastify\";\nimport type { MiddlewareCallable } from \"@webiny/utils\";\nimport { middleware } from \"@webiny/utils\";\nimport type {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n RouteMethodOptions\n} from \"~/types.js\";\nimport { Context } from \"~/Context.js\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin.js\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin.js\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin.js\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin.js\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin.js\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin.js\";\nimport type { StandardHeaders } from \"~/ResponseHeaders.js\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin.js\";\nimport { SetDefaultHeaders } from \"./PreHandler/SetDefaultHeaders.js\";\nimport { PreHandler } from \"./PreHandler/PreHandler.js\";\nimport { stringifyError } from \"./stringifyError.js\";\nimport { ProcessHandlerOnRequestPlugins } from \"./PreHandler/ProcessHandlerOnRequestPlugins.js\";\nimport { ProcessContextPlugins } from \"./PreHandler/ProcessContextPlugins.js\";\nimport { IfNotOptionsRequest } from \"./PreHandler/IfNotOptionsRequest.js\";\nimport { ProcessBeforeHandlerPlugins } from \"./PreHandler/ProcessBeforeHandlerPlugins.js\";\nimport { IfOptionsRequest } from \"./PreHandler/IfOptionsRequest.js\";\nimport { SendEarlyOptionsResponse } from \"./PreHandler/SendEarlyOptionsResponse.js\";\nimport { OnRequestTimeoutPlugin } from \"~/plugins/OnRequestTimeoutPlugin.js\";\nimport { OnRequestResponseSendPlugin } from \"~/plugins/OnRequestResponseSendPlugin.js\";\nimport { Request } from \"./abstractions/Request.js\";\nimport { Reply } from \"./abstractions/Reply.js\";\nimport { RegisterExtensionPlugin } from \"~/plugins/RegisterExtensionPlugin.js\";\nimport { RegisterExtensions } from \"~/PreHandler/RegisterExtensions.js\";\n\nconst modifyResponseHeaders = (\n app: FastifyInstance,\n request: Request.Interface,\n reply: Reply.Interface\n) => {\n const modifyHeaders = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const replyHeaders = reply.getHeaders() as StandardHeaders;\n const headers = ResponseHeaders.create(replyHeaders);\n\n modifyHeaders.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n // Exclude 'set-cookie' header to avoid duplication.\n // Cookies are managed by @fastify/cookie and calling reply.headers() with 'set-cookie' duplicates them.\n const headersToSet = headers.getHeaders();\n delete headersToSet[\"set-cookie\"];\n\n reply.headers(headersToSet);\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection | PluginsContainer;\n options?: ServerOptions;\n debug?: boolean;\n}\n\nexport const createHandler = (params: CreateHandlerParams) => {\n const definedRoutes: DefinedContextRoutes = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: [],\n COPY: [],\n LOCK: [],\n MKCOL: [],\n MOVE: [],\n PROPFIND: [],\n PROPPATCH: [],\n SEARCH: [],\n TRACE: [],\n UNLOCK: [],\n REPORT: [],\n MKCALENDAR: []\n };\n\n const throwOnDefinedRoute = (\n type: HTTPMethods | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).find(k => {\n const key = k.toUpperCase() as HTTPMethods;\n const routes = definedRoutes[key];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\n console.error(\n `Error while registering onAll route. One of the routes is already defined.`\n );\n console.error(JSON.stringify(all));\n throw new WebinyError(\n `You cannot override a route with onAll() method, please remove unnecessary route from the system.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n } else if (definedRoutes[type].includes(path) === false) {\n return;\n } else if (options?.override === true) {\n return;\n }\n console.error(`Error while trying to override route: [${type}] ${path}`);\n throw new WebinyError(\n `When you are trying to override existing route, you must send \"override\" parameter when adding that route.`,\n \"OVERRIDE_ROUTE_ERROR\",\n {\n type,\n path\n }\n );\n };\n\n const addDefinedRoute = (input: HTTPMethods, path: string): void => {\n const type = input.toUpperCase() as HTTPMethods;\n if (!definedRoutes[type]) {\n return;\n } else if (definedRoutes[type].includes(path)) {\n return;\n }\n definedRoutes[type].push(path);\n };\n\n /**\n * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n bodyLimit: 536870912, // 512MB\n disableRequestLogging: true,\n allowErrorHandlerOverride: true,\n ...(params.options || {})\n });\n\n /**\n * We need to register routes in our system to output headers later on, and disallow route overriding.\n */\n app.addHook(\"onRoute\", route => {\n const method = route.method as HTTPMethods | HTTPMethods[];\n if (Array.isArray(method)) {\n for (const m of method) {\n addDefinedRoute(m, route.path);\n }\n return;\n }\n addDefinedRoute(method, route.path);\n });\n /**\n * ############################\n * Register the Fastify plugins.\n */\n /**\n * Package @fastify/cookie\n *\n * https://github.com/fastify/fastify-cookie\n */\n app.register(fastifyCookie, {\n parseOptions: {} // options for parsing cookies\n });\n /**\n * Package @fastify/compress\n *\n * https://github.com/fastify/fastify-compress\n */\n app.register(fastifyCompress, {\n global: true,\n threshold: 1024,\n onUnsupportedEncoding: (encoding, _, reply) => {\n reply.code(406);\n return `We do not support the ${encoding} encoding.`;\n },\n inflateIfDeflated: true\n });\n /**\n * Route helpers - mostly for users.\n */\n const routes: ContextRoutes = {\n defined: definedRoutes,\n onPost: (path, handler, options) => {\n throwOnDefinedRoute(\"POST\", path, options);\n app.post(path, handler);\n },\n onGet: (path, handler, options) => {\n throwOnDefinedRoute(\"GET\", path, options);\n app.get(path, handler);\n },\n onOptions: (path, handler, options) => {\n throwOnDefinedRoute(\"OPTIONS\", path, options);\n app.options(path, handler);\n },\n onDelete: (path, handler, options) => {\n throwOnDefinedRoute(\"DELETE\", path, options);\n app.delete(path, handler);\n },\n onPatch: (path, handler, options) => {\n throwOnDefinedRoute(\"PATCH\", path, options);\n app.patch(path, handler);\n },\n onPut: (path, handler, options) => {\n throwOnDefinedRoute(\"PUT\", path, options);\n app.put(path, handler);\n },\n onAll: (path, handler, options) => {\n throwOnDefinedRoute(\"ALL\", path, options);\n app.all(path, handler);\n },\n onHead: (path, handler, options) => {\n throwOnDefinedRoute(\"HEAD\", path, options);\n app.head(path, handler);\n }\n };\n let context: Context;\n\n const plugins = new PluginsContainer([]);\n plugins.merge(params.plugins || []);\n\n try {\n context = new Context({\n plugins,\n /**\n * Inserted via webpack at build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n routes\n });\n } catch (ex) {\n console.error(`Error while constructing the Context.`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We are attaching our custom context to webiny variable on the fastify app, so it is accessible everywhere.\n */\n app.decorate(\"webiny\", context);\n\n /**\n * To prevent Unsupported Media Type errors on OPTIONS requests with a body,\n * we need to have a custom parser\n */\n app.addContentTypeParser(\n \"application/json\",\n { parseAs: \"string\", bodyLimit: 1024 * 1024 },\n (req, body, done) => {\n if (req.method === \"OPTIONS\") {\n done(null, undefined);\n return;\n }\n\n try {\n const json = typeof body === \"string\" ? body : body.toString(\"utf8\");\n done(null, JSON.parse(json));\n } catch (err) {\n done(err as Error);\n }\n }\n );\n\n /**\n * With this we ensure that an undefined request body is not parsed on OPTIONS requests,\n * in case there's a `content-type` header set for whatever reason.\n *\n * @see https://fastify.dev/docs/latest/Reference/ContentTypeParser/#content-type-parser\n */\n app.addHook(\"onRequest\", async request => {\n if (request.method === \"OPTIONS\" && request.body === undefined) {\n request.headers[\"content-type\"] = undefined;\n }\n });\n\n /**\n * At this point, request body is properly parsed, and we can execute Webiny business logic.\n * - set default headers\n * - process `HandlerOnRequestPlugin`\n * - if OPTIONS request, exit early\n * - process `ContextPlugin`\n * - process `BeforeHandlerPlugin`\n */\n app.addHook(\"preHandler\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n\n // Bind request and reply to DI container for runtime access\n if (app.webiny.container) {\n app.webiny.container.registerInstance(Request, request);\n app.webiny.container.registerInstance(Reply, reply);\n }\n /**\n * Default code to 200 - so we do not need to set it again.\n * Usually we set errors manually when we use reply.send.\n */\n reply.code(200);\n\n const handlerOnRequestPlugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n const contextPlugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n\n const beforeHandlerPlugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(\n BeforeHandlerPlugin.type\n );\n\n const modifyHeadersPlugins = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const registerExtensionPlugins = app.webiny.plugins.byType<RegisterExtensionPlugin>(\n RegisterExtensionPlugin.type\n );\n\n const preHandler = new PreHandler([\n new RegisterExtensions(registerExtensionPlugins),\n new SetDefaultHeaders(definedRoutes),\n new ProcessHandlerOnRequestPlugins(handlerOnRequestPlugins),\n new IfNotOptionsRequest([\n new ProcessContextPlugins(app.webiny, contextPlugins),\n new ProcessBeforeHandlerPlugins(app.webiny, beforeHandlerPlugins)\n ]),\n new IfOptionsRequest([new SendEarlyOptionsResponse(modifyHeadersPlugins)])\n ]);\n\n await preHandler.execute(request, reply, app.webiny);\n });\n\n app.addHook(\"preSerialization\", async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.handle(app.webiny, payload);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerResultPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preSerialization hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n return payload;\n });\n\n app.setErrorHandler<WebinyError>(async (error, _, reply) => {\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n console.warn(\"Reply already sent, cannot send the result (handler:setErrorHandler).\");\n return reply;\n }\n\n if (error.code?.startsWith(\"Authentication/\")) {\n return reply\n .status(401)\n .headers({ \"Cache-Control\": \"no-store\" })\n .send(\n JSON.stringify({\n message: error.message,\n code: error.code\n })\n );\n }\n\n if (error.code === \"Tenancy/TenantDisabled\") {\n return reply\n .status(503)\n .headers({ \"Cache-Control\": \"no-store\" })\n .send(\n JSON.stringify({\n message: error.message,\n code: error.code\n })\n );\n }\n\n return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.error(\"Logging error in @webiny/handler\");\n try {\n console.error(stringifyError(error));\n } catch (ex) {\n console.warn(\"Could not stringify error:\");\n console.log(error);\n console.error(\"Stringify error:\", ex);\n }\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (!reply.sent) {\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n } else {\n console.warn(\"Reply already sent, cannot send the result (handler:addHook:onError).\");\n }\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: MiddlewareCallable) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * Apply response headers modifier plugins.\n */\n app.addHook(\"onSend\", async (request, reply, input) => {\n modifyResponseHeaders(app, request, reply);\n const plugins = app.webiny.plugins.byType<OnRequestResponseSendPlugin>(\n OnRequestResponseSendPlugin.type\n );\n let payload = input;\n for (const plugin of plugins) {\n payload = await plugin.exec(request, reply, payload);\n }\n return payload;\n });\n\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n\n app.addHook(\"onTimeout\", async (request, reply) => {\n const plugins = app.webiny.plugins.byType<OnRequestTimeoutPlugin>(\n OnRequestTimeoutPlugin.type\n );\n for (const plugin of plugins) {\n await plugin.exec(request, reply);\n }\n await context.benchmark.output();\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"names":["modifyResponseHeaders","app","request","reply","modifyHeaders","ModifyResponseHeadersPlugin","replyHeaders","headers","ResponseHeaders","plugin","headersToSet","createHandler","params","definedRoutes","throwOnDefinedRoute","type","path","options","all","Object","k","key","routes","console","JSON","WebinyError","addDefinedRoute","input","fastify","route","method","Array","m","fastifyCookie","fastifyCompress","encoding","_","handler","context","plugins","PluginsContainer","Context","process","ex","stringifyError","req","body","done","undefined","json","err","Request","Reply","handlerOnRequestPlugins","HandlerOnRequestPlugin","contextPlugins","ContextPlugin","beforeHandlerPlugins","BeforeHandlerPlugin","modifyHeadersPlugins","registerExtensionPlugins","RegisterExtensionPlugin","preHandler","PreHandler","RegisterExtensions","SetDefaultHeaders","ProcessHandlerOnRequestPlugins","IfNotOptionsRequest","ProcessContextPlugins","ProcessBeforeHandlerPlugins","IfOptionsRequest","SendEarlyOptionsResponse","__","payload","HandlerResultPlugin","name","error","HandlerErrorPlugin","middleware","pl","next","OnRequestResponseSendPlugin","OnRequestTimeoutPlugin","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAMA,wBAAwB,CAC1BC,KACAC,SACAC;IAEA,MAAMC,gBAAgBH,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAC3CI,4BAA4B,IAAI;IAGpC,MAAMC,eAAeH,MAAM,UAAU;IACrC,MAAMI,UAAUC,gBAAgB,MAAM,CAACF;IAEvCF,cAAc,OAAO,CAACK,CAAAA;QAClBA,OAAO,MAAM,CAACP,SAASK;IAC3B;IAIA,MAAMG,eAAeH,QAAQ,UAAU;IACvC,OAAOG,YAAY,CAAC,aAAa;IAEjCP,MAAM,OAAO,CAACO;AAClB;AAQO,MAAMC,gBAAgB,CAACC;IAC1B,MAAMC,gBAAsC;QACxC,MAAM,EAAE;QACR,KAAK,EAAE;QACP,SAAS,EAAE;QACX,QAAQ,EAAE;QACV,OAAO,EAAE;QACT,KAAK,EAAE;QACP,MAAM,EAAE;QACR,MAAM,EAAE;QACR,MAAM,EAAE;QACR,OAAO,EAAE;QACT,MAAM,EAAE;QACR,UAAU,EAAE;QACZ,WAAW,EAAE;QACb,QAAQ,EAAE;QACV,OAAO,EAAE;QACT,QAAQ,EAAE;QACV,QAAQ,EAAE;QACV,YAAY,EAAE;IAClB;IAEA,MAAMC,sBAAsB,CACxBC,MACAC,MACAC;QAEA,IAAIF,AAAS,UAATA,MAAgB;YAChB,MAAMG,MAAMC,OAAO,IAAI,CAACN,eAAe,IAAI,CAACO,CAAAA;gBACxC,MAAMC,MAAMD,EAAE,WAAW;gBACzB,MAAME,SAAST,aAAa,CAACQ,I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,OAAO0C,IAAI;QACTpB,QAAQ,KAAK,CACT,CAAC,sCAAsC,EACnCiE,kBAAkB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,CAAC,GAAG,GAC9C,yDAAyD,CAAC;QAE/DjE,QAAQ,KAAK,CAACqB,eAAeD;QAC7B,MAAMA;IACV;IAEA,OAAO1C;AACX"}
|
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// Suppress punycode warnings. This is a known issue which we can't fix.
|
|
2
1
|
import "./suppressPunycodeWarnings.js";
|
|
3
2
|
export * from "./fastify.js";
|
|
4
3
|
export * from "./Context.js";
|
|
@@ -13,10 +12,8 @@ export * from "./plugins/ModifyFastifyPlugin.js";
|
|
|
13
12
|
export * from "./plugins/ModifyResponseHeadersPlugin.js";
|
|
14
13
|
export * from "./plugins/OnRequestResponseSendPlugin.js";
|
|
15
14
|
export * from "./plugins/OnRequestTimeoutPlugin.js";
|
|
16
|
-
export { RegisterExtensionPlugin, createRegisterExtensionPlugin } from "./plugins/RegisterExtensionPlugin.js";
|
|
17
15
|
export * from "./ResponseHeaders.js";
|
|
16
|
+
export { RegisterExtensionPlugin, createRegisterExtensionPlugin } from "./plugins/RegisterExtensionPlugin.js";
|
|
18
17
|
export { Request } from "./abstractions/Request.js";
|
|
19
18
|
export { Reply } from "./abstractions/Reply.js";
|
|
20
|
-
export { Route,
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
|
19
|
+
export { Route, toRouteReply, toRouteRequest } from "./abstractions/Route.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0-beta.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@fastify/compress": "8.3.1",
|
|
20
20
|
"@fastify/cookie": "11.0.2",
|
|
21
|
-
"@webiny/api": "6.
|
|
22
|
-
"@webiny/error": "6.
|
|
23
|
-
"@webiny/feature": "6.
|
|
24
|
-
"@webiny/plugins": "6.
|
|
25
|
-
"@webiny/utils": "6.
|
|
21
|
+
"@webiny/api": "6.4.0-beta.0",
|
|
22
|
+
"@webiny/error": "6.4.0-beta.0",
|
|
23
|
+
"@webiny/feature": "6.4.0-beta.0",
|
|
24
|
+
"@webiny/plugins": "6.4.0-beta.0",
|
|
25
|
+
"@webiny/utils": "6.4.0-beta.0",
|
|
26
26
|
"fastify": "5.8.5"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@webiny/build-tools": "6.
|
|
29
|
+
"@webiny/build-tools": "6.4.0-beta.0",
|
|
30
30
|
"rimraf": "6.1.3",
|
|
31
31
|
"typescript": "6.0.3",
|
|
32
|
-
"vitest": "4.1.
|
|
32
|
+
"vitest": "4.1.6"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public",
|
|
36
36
|
"directory": "dist"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
|
|
39
39
|
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
class BeforeHandlerPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "before-handler";
|
|
5
|
+
}
|
|
6
|
+
constructor(callable){
|
|
7
|
+
super();
|
|
8
|
+
this._callable = callable;
|
|
9
|
+
}
|
|
10
|
+
async apply(context) {
|
|
11
|
+
if ("function" != typeof this._callable) throw Error('Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.');
|
|
12
|
+
return this._callable(context);
|
|
11
13
|
}
|
|
12
|
-
return this._callable(context);
|
|
13
|
-
}
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
15
|
+
const createBeforeHandlerPlugin = (callable)=>new BeforeHandlerPlugin(callable);
|
|
16
|
+
export { BeforeHandlerPlugin, createBeforeHandlerPlugin };
|
|
18
17
|
|
|
19
18
|
//# sourceMappingURL=BeforeHandlerPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/BeforeHandlerPlugin.js","sources":["../../src/plugins/BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"names":["BeforeHandlerPlugin","Plugin","callable","context","Error","createBeforeHandlerPlugin"],"mappings":";AAOO,MAAMA,4BAAyDC;;aAClC,IAAI,GAAW;;IAG/C,YAAYC,QAAkC,CAAE;QAC5C,KAAK;QACL,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,MAAMC,OAAU,EAAiB;QAC1C,IAAI,AAA0B,cAA1B,OAAO,IAAI,CAAC,SAAS,EACrB,MAAMC,MACF;QAIR,OAAO,IAAI,CAAC,SAAS,CAACD;IAC1B;AACJ;AAEO,MAAME,4BAA4B,CACrCH,WAEO,IAAIF,oBAAuBE"}
|
package/plugins/EventPlugin.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EventPlugin must be handled in the package which implements fastify for certain cloud.
|
|
3
|
-
* There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
|
|
4
|
-
* to be sorted out in the implementation package.
|
|
5
|
-
*
|
|
6
|
-
* Note that only one EventPlugin can be defined per fastify initialisation.
|
|
7
|
-
* If more is needed, check ~/fastify.ts and implement that possibility.
|
|
8
|
-
*/
|
|
9
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
class EventPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.event";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
11
|
+
const createEvent = (cb)=>new EventPlugin(cb);
|
|
12
|
+
export { EventPlugin, createEvent };
|
|
20
13
|
|
|
21
14
|
//# sourceMappingURL=EventPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/EventPlugin.js","sources":["../../src/plugins/EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Request, Context as BaseContext, Reply } from \"~/types.js\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"names":["EventPlugin","Plugin","cb","createEvent"],"mappings":";AAsBO,MAAMA,oBAIHC;;aACiB,IAAI,GAAG;;IAI9B,YAAmBC,EAAmD,CAAE;QACpE,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,cAAc,CAKvBD,KAEO,IAAIF,YAAwCE"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
class HandlerErrorPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler-error";
|
|
5
|
+
}
|
|
6
|
+
constructor(callable){
|
|
7
|
+
super();
|
|
8
|
+
this._callable = callable;
|
|
9
|
+
}
|
|
10
|
+
async handle(context, error, next) {
|
|
11
|
+
return this._callable(context, error, next);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
14
|
+
const createHandlerErrorPlugin = (callable)=>new HandlerErrorPlugin(callable);
|
|
15
|
+
export { HandlerErrorPlugin, createHandlerErrorPlugin };
|
|
15
16
|
|
|
16
17
|
//# sourceMappingURL=HandlerErrorPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/HandlerErrorPlugin.js","sources":["../../src/plugins/HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface NextCallable {\n (): Promise<any>;\n}\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: NextCallable): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: NextCallable): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"names":["HandlerErrorPlugin","Plugin","callable","context","error","next","createHandlerErrorPlugin"],"mappings":";AAWO,MAAMA,2BAAwDC;;aACjC,IAAI,GAAW;;IAI/C,YAAmBC,QAAiC,CAAE;QAClD,KAAK;QACL,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,OAAOC,OAAU,EAAEC,KAAY,EAAEC,IAAkB,EAAgB;QAC5E,OAAO,IAAI,CAAC,SAAS,CAACF,SAASC,OAAOC;IAC1C;AACJ;AAEO,MAAMC,2BAA2B,CACpCJ,WAEO,IAAIF,mBAAsBE"}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
super();
|
|
14
|
-
this.cb = cb;
|
|
15
|
-
}
|
|
16
|
-
async exec(request, reply, context) {
|
|
17
|
-
return this.cb(request, reply, context);
|
|
18
|
-
}
|
|
2
|
+
class HandlerOnRequestPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.event.onRequest";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
async exec(request, reply, context) {
|
|
11
|
+
return this.cb(request, reply, context);
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
14
|
+
const createHandlerOnRequest = (cb)=>new HandlerOnRequestPlugin(cb);
|
|
15
|
+
export { HandlerOnRequestPlugin, createHandlerOnRequest };
|
|
23
16
|
|
|
24
17
|
//# sourceMappingURL=HandlerOnRequestPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/HandlerOnRequestPlugin.js","sources":["../../src/plugins/HandlerOnRequestPlugin.ts"],"sourcesContent":["import type { Context } from \"~/types.js\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FastifyReply, FastifyRequest } from \"fastify\";\n\n/**\n * If the execution of the callable returns false, no more plugins will be executed after the given one.\n * Nor it will execute our default OPTIONS code.\n *\n * This way users can prevent stopping of the request on our built-in OPTIONS request.\n */\nexport type HandlerOnRequestPluginCallableResponse = false | undefined | null | void;\ninterface HandlerOnRequestPluginCallable<C extends Context = Context> {\n (\n request: FastifyRequest,\n reply: FastifyReply,\n context: C\n ): Promise<HandlerOnRequestPluginCallableResponse>;\n}\n\nexport class HandlerOnRequestPlugin<C extends Context = Context> extends Plugin {\n public static override type = \"handler.event.onRequest\";\n\n private readonly cb: HandlerOnRequestPluginCallable<C>;\n\n public constructor(cb: HandlerOnRequestPluginCallable<C>) {\n super();\n this.cb = cb;\n }\n\n public async exec(\n request: FastifyRequest,\n reply: FastifyReply,\n context: C\n ): Promise<HandlerOnRequestPluginCallableResponse> {\n return this.cb(request, reply, context);\n }\n}\n\nexport const createHandlerOnRequest = <C extends Context = Context>(\n cb: HandlerOnRequestPluginCallable<C>\n) => {\n return new HandlerOnRequestPlugin<C>(cb);\n};\n"],"names":["HandlerOnRequestPlugin","Plugin","cb","request","reply","context","createHandlerOnRequest"],"mappings":";AAmBO,MAAMA,+BAA4DC;;aAC9C,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,MAAa,KACTC,OAAuB,EACvBC,KAAmB,EACnBC,OAAU,EACqC;QAC/C,OAAO,IAAI,CAAC,EAAE,CAACF,SAASC,OAAOC;IACnC;AACJ;AAEO,MAAMC,yBAAyB,CAClCJ,KAEO,IAAIF,uBAA0BE"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
class HandlerResultPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler-result";
|
|
5
|
+
}
|
|
6
|
+
constructor(callable){
|
|
7
|
+
super();
|
|
8
|
+
this._callable = callable;
|
|
9
|
+
}
|
|
10
|
+
async handle(context, result) {
|
|
11
|
+
return this._callable(context, result);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
14
|
+
const createHandlerResultPlugin = (callable)=>new HandlerResultPlugin(callable);
|
|
15
|
+
export { HandlerResultPlugin, createHandlerResultPlugin };
|
|
15
16
|
|
|
16
17
|
//# sourceMappingURL=HandlerResultPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/HandlerResultPlugin.js","sources":["../../src/plugins/HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n\nexport const createHandlerResultPlugin = <T extends Context = Context>(\n callable: HandlerResultCallable<T>\n): HandlerResultPlugin<T> => {\n return new HandlerResultPlugin<T>(callable);\n};\n"],"names":["HandlerResultPlugin","Plugin","callable","context","result","createHandlerResultPlugin"],"mappings":";AAOO,MAAMA,4BAAyDC;;aAClC,IAAI,GAAW;;IAI/C,YAAmBC,QAAkC,CAAE;QACnD,KAAK;QACL,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,OAAOC,OAAU,EAAEC,MAAW,EAAgB;QACvD,OAAO,IAAI,CAAC,SAAS,CAACD,SAASC;IACnC;AACJ;AAEO,MAAMC,4BAA4B,CACrCH,WAEO,IAAIF,oBAAuBE"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
class ModifyFastifyPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.modify";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
modify(app) {
|
|
11
|
+
this.cb(app);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
14
|
+
const createModifyFastifyPlugin = (cb)=>new ModifyFastifyPlugin(cb);
|
|
15
|
+
export { ModifyFastifyPlugin, createModifyFastifyPlugin };
|
|
15
16
|
|
|
16
17
|
//# sourceMappingURL=ModifyFastifyPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/ModifyFastifyPlugin.js","sources":["../../src/plugins/ModifyFastifyPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { FastifyInstance } from \"fastify\";\n\ninterface ModifyFastifyPluginCallable {\n (app: FastifyInstance): void;\n}\n\nexport class ModifyFastifyPlugin extends Plugin {\n public static override type = \"handler.fastify.modify\";\n\n private readonly cb: ModifyFastifyPluginCallable;\n\n public constructor(cb: ModifyFastifyPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public modify(app: FastifyInstance): void {\n this.cb(app);\n }\n}\n\nexport const createModifyFastifyPlugin = (cb: ModifyFastifyPluginCallable) => {\n return new ModifyFastifyPlugin(cb);\n};\n"],"names":["ModifyFastifyPlugin","Plugin","cb","app","createModifyFastifyPlugin"],"mappings":";AAOO,MAAMA,4BAA4BC;;aACd,IAAI,GAAG;;IAI9B,YAAmBC,EAA+B,CAAE;QAChD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEO,OAAOC,GAAoB,EAAQ;QACtC,IAAI,CAAC,EAAE,CAACA;IACZ;AACJ;AAEO,MAAMC,4BAA4B,CAACF,KAC/B,IAAIF,oBAAoBE"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
class ModifyResponseHeadersPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.response.modifyHeaders";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
modify(request, headers) {
|
|
11
|
+
this.cb(request, headers);
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
function createModifyResponseHeaders(cb) {
|
|
15
|
+
return new ModifyResponseHeadersPlugin(cb);
|
|
14
16
|
}
|
|
17
|
+
export { ModifyResponseHeadersPlugin, createModifyResponseHeaders };
|
|
15
18
|
|
|
16
19
|
//# sourceMappingURL=ModifyResponseHeadersPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/ModifyResponseHeadersPlugin.js","sources":["../../src/plugins/ModifyResponseHeadersPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport type { Request } from \"~/types.js\";\n\ninterface ModifyResponseHeadersCallable {\n (request: Request, headers: ResponseHeaders): void;\n}\n\nexport class ModifyResponseHeadersPlugin extends Plugin {\n public static override type = \"handler.response.modifyHeaders\";\n private readonly cb: ModifyResponseHeadersCallable;\n\n constructor(cb: ModifyResponseHeadersCallable) {\n super();\n this.cb = cb;\n }\n\n modify(request: Request, headers: ResponseHeaders) {\n this.cb(request, headers);\n }\n}\n\nexport function createModifyResponseHeaders(cb: ModifyResponseHeadersCallable) {\n return new ModifyResponseHeadersPlugin(cb);\n}\n"],"names":["ModifyResponseHeadersPlugin","Plugin","cb","request","headers","createModifyResponseHeaders"],"mappings":";AAQO,MAAMA,oCAAoCC;;aACtB,IAAI,GAAG;;IAG9B,YAAYC,EAAiC,CAAE;QAC3C,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,OAAOC,OAAgB,EAAEC,OAAwB,EAAE;QAC/C,IAAI,CAAC,EAAE,CAACD,SAASC;IACrB;AACJ;AAEO,SAASC,4BAA4BH,EAAiC;IACzE,OAAO,IAAIF,4BAA4BE;AAC3C"}
|
|
@@ -1,31 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* !!!!!!!!!!!!!!
|
|
3
|
-
* !!! DANGER !!!
|
|
4
|
-
* !!!!!!!!!!!!!!
|
|
5
|
-
*
|
|
6
|
-
* Using this plugin can cause slowdowns in your application response times.
|
|
7
|
-
* Also, if you do not return payload from the plugin callback, there will be nothing to send in the response.
|
|
8
|
-
*/
|
|
9
1
|
import { Plugin } from "@webiny/plugins";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
2
|
+
class OnRequestResponseSendPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.onRequestResponseSend";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
async exec(request, reply, payload) {
|
|
11
|
+
return await this.cb(request, reply, payload);
|
|
12
|
+
}
|
|
22
13
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @description Read info in the class file.
|
|
26
|
-
*/
|
|
27
|
-
export const createOnRequestResponseSend = cb => {
|
|
28
|
-
return new OnRequestResponseSendPlugin(cb);
|
|
29
|
-
};
|
|
14
|
+
const createOnRequestResponseSend = (cb)=>new OnRequestResponseSendPlugin(cb);
|
|
15
|
+
export { OnRequestResponseSendPlugin, createOnRequestResponseSend };
|
|
30
16
|
|
|
31
17
|
//# sourceMappingURL=OnRequestResponseSendPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/OnRequestResponseSendPlugin.js","sources":["../../src/plugins/OnRequestResponseSendPlugin.ts"],"sourcesContent":["/**\n * !!!!!!!!!!!!!!\n * !!! DANGER !!!\n * !!!!!!!!!!!!!!\n *\n * Using this plugin can cause slowdowns in your application response times.\n * Also, if you do not return payload from the plugin callback, there will be nothing to send in the response.\n */\nimport { Plugin } from \"@webiny/plugins\";\nimport type { Reply as FastifyReply, Request as FastifyRequest } from \"~/types.js\";\n\nexport interface IOnResponseSendPluginCallable {\n <T = unknown>(request: FastifyRequest, reply: FastifyReply, payload: T): Promise<T>;\n}\n\n/**\n * @description Read info in the class file.\n */\nexport class OnRequestResponseSendPlugin extends Plugin {\n public static override type: string = \"handler.onRequestResponseSend\";\n\n private readonly cb: IOnResponseSendPluginCallable;\n\n public constructor(cb: IOnResponseSendPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec<T = unknown>(\n request: FastifyRequest,\n reply: FastifyReply,\n payload: T\n ): Promise<unknown> {\n return await this.cb<T>(request, reply, payload);\n }\n}\n\n/**\n * @description Read info in the class file.\n */\nexport const createOnRequestResponseSend = (cb: IOnResponseSendPluginCallable) => {\n return new OnRequestResponseSendPlugin(cb);\n};\n"],"names":["OnRequestResponseSendPlugin","Plugin","cb","request","reply","payload","createOnRequestResponseSend"],"mappings":";AAkBO,MAAMA,oCAAoCC;;aACtB,IAAI,GAAW;;IAItC,YAAmBC,EAAiC,CAAE;QAClD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,MAAa,KACTC,OAAuB,EACvBC,KAAmB,EACnBC,OAAU,EACM;QAChB,OAAO,MAAM,IAAI,CAAC,EAAE,CAAIF,SAASC,OAAOC;IAC5C;AACJ;AAKO,MAAMC,8BAA8B,CAACJ,KACjC,IAAIF,4BAA4BE"}
|