@webiny/handler 6.4.11 → 6.4.12-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.
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseHeaders.js","sources":["../src/ResponseHeaders.ts"],"sourcesContent":["import type * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [K in keyof AllHeaders as string extends K\n ? never\n : number extends K\n ? never\n : K]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"names":["isFunction","setter","ResponseHeaders","initialHeaders","Map","Object","key","header","previousValue","newValue","headers"],"mappings":"AAsBA,SAASA,WAAcC,MAAe;IAClC,OAAO,AAAkB,cAAlB,OAAOA;AAClB;AAIO,MAAMC;IAGT,YAAoBC,cAAgC,CAAE;aAFrC,OAAO,GAAG,IAAIC;QAG3B,IAAID,gBACCE,OAAO,IAAI,CAACF,gBAAiD,OAAO,CAACG,CAAAA;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,KAAKH,cAAc,CAACG,IAAI;QAC7C;IAER;IAEA,IAAqCC,MAAS,EAAEN,MAAkC,EAAE;QAChF,IAAID,WAA+BC,SAAS;YACxC,MAAMO,gBAAgB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD;YACvC,MAAME,WAAWR,OAAOO;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,QAAQE;YACzB,OAAO,IAAI;QACf;QAEA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF,QAAQN;QAEzB,OAAO,IAAI;IACf;IAEA,MAAMS,OAAwB,EAAE;QAC5B,OAAOR,gBAAgB,MAAM,CAAC;YAAE,GAAG,IAAI,CAAC,UAAU,EAAE;YAAE,GAAGQ,QAAQ,UAAU,EAAE;QAAC;IAClF;IAEA,aAAa;QACT,OAAOL,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,OAAOF,cAAgC,EAAE;QAC5C,OAAO,IAAID,gBAAgBC;IAC/B;AACJ"}
1
+ {"version":3,"file":"ResponseHeaders.js","sources":["../src/ResponseHeaders.ts"],"sourcesContent":["import type * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [\n K in keyof AllHeaders as string extends K ? never : number extends K ? never : K\n ]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"names":["isFunction","setter","ResponseHeaders","initialHeaders","Map","Object","key","header","previousValue","newValue","headers"],"mappings":"AAoBA,SAASA,WAAcC,MAAe;IAClC,OAAO,AAAkB,cAAlB,OAAOA;AAClB;AAIO,MAAMC;IAGT,YAAoBC,cAAgC,CAAE;aAFrC,OAAO,GAAG,IAAIC;QAG3B,IAAID,gBACCE,OAAO,IAAI,CAACF,gBAAiD,OAAO,CAACG,CAAAA;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,KAAKH,cAAc,CAACG,IAAI;QAC7C;IAER;IAEA,IAAqCC,MAAS,EAAEN,MAAkC,EAAE;QAChF,IAAID,WAA+BC,SAAS;YACxC,MAAMO,gBAAgB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD;YACvC,MAAME,WAAWR,OAAOO;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,QAAQE;YACzB,OAAO,IAAI;QACf;QAEA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF,QAAQN;QAEzB,OAAO,IAAI;IACf;IAEA,MAAMS,OAAwB,EAAE;QAC5B,OAAOR,gBAAgB,MAAM,CAAC;YAAE,GAAG,IAAI,CAAC,UAAU,EAAE;YAAE,GAAGQ,QAAQ,UAAU,EAAE;QAAC;IAClF;IAEA,aAAa;QACT,OAAOL,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,OAAOF,cAAgC,EAAE;QAC5C,OAAO,IAAID,gBAAgBC;IAC/B;AACJ"}
@@ -0,0 +1,14 @@
1
+ export interface IRequestId {
2
+ value: string;
3
+ }
4
+ /**
5
+ * Identifier for the current request.
6
+ *
7
+ * `@webiny/handler` registers a generated value; runtimes that have a meaningful id of their own -
8
+ * AWS Lambda, for instance - override it with theirs, so that a value reported to a client can be
9
+ * correlated with the platform's own logs.
10
+ */
11
+ export declare const RequestId: import("@webiny/di").Abstraction<IRequestId>;
12
+ export declare namespace RequestId {
13
+ type Interface = IRequestId;
14
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const RequestId = createAbstraction("RequestId");
3
+ export { RequestId };
4
+
5
+ //# sourceMappingURL=RequestId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractions/RequestId.js","sources":["../../src/abstractions/RequestId.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IRequestId {\n value: string;\n}\n\n/**\n * Identifier for the current request.\n *\n * `@webiny/handler` registers a generated value; runtimes that have a meaningful id of their own -\n * AWS Lambda, for instance - override it with theirs, so that a value reported to a client can be\n * correlated with the platform's own logs.\n */\nexport const RequestId = createAbstraction<IRequestId>(\"RequestId\");\n\nexport namespace RequestId {\n export type Interface = IRequestId;\n}\n"],"names":["RequestId","createAbstraction"],"mappings":";AAaO,MAAMA,YAAYC,kBAA8B"}
package/fastify.js CHANGED
@@ -26,6 +26,8 @@ import { SendEarlyOptionsResponse } from "./PreHandler/SendEarlyOptionsResponse.
26
26
  import { OnRequestTimeoutPlugin } from "./plugins/OnRequestTimeoutPlugin.js";
27
27
  import { OnRequestResponseSendPlugin } from "./plugins/OnRequestResponseSendPlugin.js";
28
28
  import { Request } from "./abstractions/Request.js";
29
+ import { randomUUID } from "node:crypto";
30
+ import { RequestId } from "./abstractions/RequestId.js";
29
31
  import { Reply } from "./abstractions/Reply.js";
30
32
  import { RegisterExtensionPlugin } from "./plugins/RegisterExtensionPlugin.js";
31
33
  import { RegisterExtensions } from "./PreHandler/RegisterExtensions.js";
@@ -75,9 +77,8 @@ const createHandler = (params)=>{
75
77
  type,
76
78
  path
77
79
  });
78
- }
79
- if (false === definedRoutes[type].includes(path)) return;
80
- if (options?.override === true) return;
80
+ } else if (false === definedRoutes[type].includes(path)) return;
81
+ else if (options?.override === true) return;
81
82
  console.error(`Error while trying to override route: [${type}] ${path}`);
82
83
  throw new _webiny_error('When you are trying to override existing route, you must send "override" parameter when adding that route.', "OVERRIDE_ROUTE_ERROR", {
83
84
  type,
@@ -87,7 +88,7 @@ const createHandler = (params)=>{
87
88
  const addDefinedRoute = (input, path)=>{
88
89
  const type = input.toUpperCase();
89
90
  if (!definedRoutes[type]) return;
90
- if (definedRoutes[type].includes(path)) return;
91
+ else if (definedRoutes[type].includes(path)) return;
91
92
  definedRoutes[type].push(path);
92
93
  };
93
94
  const app = fastify({
@@ -189,6 +190,9 @@ const createHandler = (params)=>{
189
190
  if (app.webiny.container) {
190
191
  app.webiny.container.registerInstance(Request, request);
191
192
  app.webiny.container.registerInstance(Reply, reply);
193
+ app.webiny.container.registerInstance(RequestId, {
194
+ value: randomUUID()
195
+ });
192
196
  }
193
197
  reply.code(200);
194
198
  const handlerOnRequestPlugins = app.webiny.plugins.byType(HandlerOnRequestPlugin.type);
package/fastify.js.map CHANGED
@@ -1 +1 @@
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 {\n type FastifyInstance,\n type FastifyServerOptions as ServerOptions,\n LogController\n} 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 logController: new LogController({\n disableRequestLogging: true\n }),\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","LogController","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,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,YA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AC,OAAO,CAAC,MAAM,CAAsBoF,oBAAoB,IAAI;IAE7F,IAAIC;IACJ,IAAI;QACA,KAAK,MAAM7E,UAAU2E,cAAe;YAChCE,0BAA0B7E,OAAO,IAAI;YACrCA,OAAO,MAAM,CAACR;QAClB;IACJ,EAAE,OAAO2C,IAAI;QACTrB,QAAQ,KAAK,CACT,CAAC,8CAA8C,EAC3C+D,0BAA0B,CAAC,CAAC,EAAEA,wBAAwB,CAAC,CAAC,GAAG,GAC9D,mDAAmD,CAAC;QAEzD/D,QAAQ,KAAK,CAACsB,eAAeD;QAC7B,MAAMA;IACV;IASA,MAAM2C,eAAetF,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAcuF,YAAY,IAAI;IAK5E,IAAIC;IACJ,IAAI;QACA,KAAK,MAAMhF,UAAU8E,aAAc;YAC/BE,kBAAkBhF,OAAO,IAAI;YAC7BA,OAAO,EAAE,CAAC;gBACN,GAAGR,IAAI,MAAM,CAAC,MAAM;gBACpB,SAASA,IAAI,MAAM;YACvB;QACJ;IACJ,EAAE,OAAO2C,IAAI;QACTrB,QAAQ,KAAK,CACT,CAAC,sCAAsC,EACnCkE,kBAAkB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,CAAC,GAAG,GAC9C,yDAAyD,CAAC;QAE/DlE,QAAQ,KAAK,CAACsB,eAAeD;QAC7B,MAAMA;IACV;IAEA,OAAO3C;AACX"}
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 {\n type FastifyInstance,\n type FastifyServerOptions as ServerOptions,\n LogController\n} 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 { randomUUID } from \"node:crypto\";\nimport { RequestId } from \"./abstractions/RequestId.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 logController: new LogController({\n disableRequestLogging: true\n }),\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 * A default so the abstraction always resolves. Runtimes with a meaningful id of their\n * own override this from a `HandlerOnRequestPlugin`, which runs later in this same hook.\n */\n app.webiny.container.registerInstance(RequestId, { value: randomUUID() });\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","LogController","route","method","Array","m","fastifyCookie","fastifyCompress","encoding","_","handler","context","plugins","PluginsContainer","Context","process","ex","stringifyError","req","body","done","undefined","json","err","Request","Reply","RequestId","randomUUID","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,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,K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B,IAAI;IAE7F,IAAIC;IACJ,IAAI;QACA,KAAK,MAAM/E,UAAU6E,cAAe;YAChCE,0BAA0B/E,OAAO,IAAI;YACrCA,OAAO,MAAM,CAACR;QAClB;IACJ,EAAE,OAAO2C,IAAI;QACTrB,QAAQ,KAAK,CACT,CAAC,8CAA8C,EAC3CiE,0BAA0B,CAAC,CAAC,EAAEA,wBAAwB,CAAC,CAAC,GAAG,GAC9D,mDAAmD,CAAC;QAEzDjE,QAAQ,KAAK,CAACsB,eAAeD;QAC7B,MAAMA;IACV;IASA,MAAM6C,eAAexF,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAcyF,YAAY,IAAI;IAK5E,IAAIC;IACJ,IAAI;QACA,KAAK,MAAMlF,UAAUgF,aAAc;YAC/BE,kBAAkBlF,OAAO,IAAI;YAC7BA,OAAO,EAAE,CAAC;gBACN,GAAGR,IAAI,MAAM,CAAC,MAAM;gBACpB,SAASA,IAAI,MAAM;YACvB;QACJ;IACJ,EAAE,OAAO2C,IAAI;QACTrB,QAAQ,KAAK,CACT,CAAC,sCAAsC,EACnCoE,kBAAkB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,CAAC,GAAG,GAC9C,yDAAyD,CAAC;QAE/DpE,QAAQ,KAAK,CAACsB,eAAeD;QAC7B,MAAMA;IACV;IAEA,OAAO3C;AACX"}
package/index.d.ts CHANGED
@@ -16,4 +16,5 @@ export { RegisterExtensionPlugin, createRegisterExtensionPlugin } from "./plugin
16
16
  export * from "./ResponseHeaders.js";
17
17
  export { Request } from "./abstractions/Request.js";
18
18
  export { Reply } from "./abstractions/Reply.js";
19
+ export { RequestId } from "./abstractions/RequestId.js";
19
20
  export { Route, toRouteRequest, toRouteReply } from "./abstractions/Route.js";
package/index.js CHANGED
@@ -16,4 +16,5 @@ export * from "./ResponseHeaders.js";
16
16
  export { RegisterExtensionPlugin, createRegisterExtensionPlugin } from "./plugins/RegisterExtensionPlugin.js";
17
17
  export { Request } from "./abstractions/Request.js";
18
18
  export { Reply } from "./abstractions/Reply.js";
19
+ export { RequestId } from "./abstractions/RequestId.js";
19
20
  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.4.11",
3
+ "version": "6.4.12-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -16,20 +16,20 @@
16
16
  ],
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@fastify/compress": "9.0.0",
20
- "@fastify/cookie": "11.1.0",
21
- "@webiny/api": "6.4.11",
22
- "@webiny/error": "6.4.11",
23
- "@webiny/feature": "6.4.11",
24
- "@webiny/plugins": "6.4.11",
25
- "@webiny/utils": "6.4.11",
26
- "fastify": "5.10.0"
19
+ "@fastify/compress": "9.2.0",
20
+ "@fastify/cookie": "11.1.2",
21
+ "@webiny/api": "6.4.12-beta.0",
22
+ "@webiny/error": "6.4.12-beta.0",
23
+ "@webiny/feature": "6.4.12-beta.0",
24
+ "@webiny/plugins": "6.4.12-beta.0",
25
+ "@webiny/utils": "6.4.12-beta.0",
26
+ "fastify": "5.12.5"
27
27
  },
28
28
  "devDependencies": {
29
- "@webiny/build-tools": "6.4.11",
29
+ "@webiny/build-tools": "6.4.12-beta.0",
30
30
  "rimraf": "6.1.3",
31
31
  "typescript": "6.0.3",
32
- "vitest": "4.1.10"
32
+ "vitest": "5.0.1"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"