@webiny/handler 5.43.0-beta.0 → 5.43.0-beta.2

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.
@@ -11,6 +11,9 @@ class SendEarlyOptionsResponse {
11
11
  this.plugins = plugins;
12
12
  }
13
13
  async execute(request, reply) {
14
+ /**
15
+ * IMPORTANT! Do not send anything if reply was already sent.
16
+ */
14
17
  if (reply.sent) {
15
18
  /**
16
19
  * At this point throwing an exception will not do anything with the response. So just log it.
@@ -1 +1 @@
1
- {"version":3,"names":["_IPreHandler","require","_ResponseHeaders","SendEarlyOptionsResponse","constructor","plugins","execute","request","reply","sent","console","error","JSON","stringify","message","explanation","Action","DONE","headers","ResponseHeaders","create","getHeaders","forEach","plugin","modify","code","send","hijack","exports"],"sources":["SendEarlyOptionsResponse.ts"],"sourcesContent":["import { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\n\nexport class SendEarlyOptionsResponse implements IPreHandler {\n private readonly plugins: ModifyResponseHeadersPlugin[];\n\n constructor(plugins: ModifyResponseHeadersPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return Action.DONE;\n }\n\n const headers = ResponseHeaders.create(reply.getHeaders());\n\n this.plugins.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n\n reply.code(204).send(\"\").hijack();\n\n return Action.DONE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEO,MAAME,wBAAwB,CAAwB;EAGzDC,WAAWA,CAACC,OAAsC,EAAE;IAChD,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE,IAAIA,KAAK,CAACC,IAAI,EAAE;MACZ;AACZ;AACA;MACYC,OAAO,CAACC,KAAK,CACTC,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAE,wFAAwF;QACjGC,WAAW,EACP;MACR,CAAC,CACL,CAAC;MACD,OAAOC,mBAAM,CAACC,IAAI;IACtB;IAEA,MAAMC,OAAO,GAAGC,gCAAe,CAACC,MAAM,CAACZ,KAAK,CAACa,UAAU,CAAC,CAAC,CAAC;IAE1D,IAAI,CAAChB,OAAO,CAACiB,OAAO,CAACC,MAAM,IAAI;MAC3BA,MAAM,CAACC,MAAM,CAACjB,OAAO,EAAEW,OAAO,CAAC;IACnC,CAAC,CAAC;IAEFV,KAAK,CAACU,OAAO,CAACA,OAAO,CAACG,UAAU,CAAC,CAAC,CAAC;IAEnCb,KAAK,CAACiB,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC;IAEjC,OAAOX,mBAAM,CAACC,IAAI;EACtB;AACJ;AAACW,OAAA,CAAAzB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_IPreHandler","require","_ResponseHeaders","SendEarlyOptionsResponse","constructor","plugins","execute","request","reply","sent","console","error","JSON","stringify","message","explanation","Action","DONE","headers","ResponseHeaders","create","getHeaders","forEach","plugin","modify","code","send","hijack","exports"],"sources":["SendEarlyOptionsResponse.ts"],"sourcesContent":["import { FastifyReply, FastifyRequest } from \"fastify\";\nimport { Action, IPreHandler } from \"~/PreHandler/IPreHandler\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { ResponseHeaders, StandardHeaders } from \"~/ResponseHeaders\";\n\nexport class SendEarlyOptionsResponse implements IPreHandler {\n private readonly plugins: ModifyResponseHeadersPlugin[];\n\n constructor(plugins: ModifyResponseHeadersPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return Action.DONE;\n }\n\n const headers = ResponseHeaders.create(reply.getHeaders() as StandardHeaders);\n\n this.plugins.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n\n reply.code(204).send(\"\").hijack();\n\n return Action.DONE;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEO,MAAME,wBAAwB,CAAwB;EAGzDC,WAAWA,CAACC,OAAsC,EAAE;IAChD,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE;AACR;AACA;IACQ,IAAIA,KAAK,CAACC,IAAI,EAAE;MACZ;AACZ;AACA;MACYC,OAAO,CAACC,KAAK,CACTC,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAE,wFAAwF;QACjGC,WAAW,EACP;MACR,CAAC,CACL,CAAC;MACD,OAAOC,mBAAM,CAACC,IAAI;IACtB;IAEA,MAAMC,OAAO,GAAGC,gCAAe,CAACC,MAAM,CAACZ,KAAK,CAACa,UAAU,CAAC,CAAoB,CAAC;IAE7E,IAAI,CAAChB,OAAO,CAACiB,OAAO,CAACC,MAAM,IAAI;MAC3BA,MAAM,CAACC,MAAM,CAACjB,OAAO,EAAEW,OAAO,CAAC;IACnC,CAAC,CAAC;IAEFV,KAAK,CAACU,OAAO,CAACA,OAAO,CAACG,UAAU,CAAC,CAAC,CAAC;IAEnCb,KAAK,CAACiB,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC;IAEjC,OAAOX,mBAAM,CAACC,IAAI;EACtB;AACJ;AAACW,OAAA,CAAAzB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -5,7 +5,7 @@ type ExtraHeaders = {
5
5
  "x-webiny-version"?: http.OutgoingHttpHeader | undefined;
6
6
  };
7
7
  type AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;
8
- export type StandardHeaderValue = http.OutgoingHttpHeader | boolean | undefined;
8
+ export type StandardHeaderValue = http.OutgoingHttpHeader | undefined;
9
9
  export type StandardHeaders = {
10
10
  [K in keyof AllHeaders as string extends K ? never : number extends K ? never : K]: http.OutgoingHttpHeaders[K];
11
11
  } & {
@@ -1 +1 @@
1
- {"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries","exports"],"sources":["ResponseHeaders.ts"],"sourcesContent":["import * 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 | boolean | 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"],"mappings":";;;;;;AAWA;;AAWA,SAASA,UAAUA,CAAIC,MAAe,EAA6B;EAC/D,OAAO,OAAOA,MAAM,KAAK,UAAU;AACvC;AAIO,MAAMC,eAAe,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAA6C,CAAC;EAExEC,WAAWA,CAACC,cAAgC,EAAE;IAClD,IAAIA,cAAc,EAAE;MACfC,MAAM,CAACC,IAAI,CAACF,cAAc,CAAC,CAAkCG,OAAO,CAACC,GAAG,IAAI;QACzE,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACD,GAAG,EAAEJ,cAAc,CAACI,GAAG,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;EAEAC,GAAGA,CAAkCC,MAAS,EAAEX,MAAkC,EAAE;IAChF,IAAID,UAAU,CAAqBC,MAAM,CAAC,EAAE;MACxC,MAAMY,aAAa,GAAG,IAAI,CAACV,OAAO,CAACW,GAAG,CAACF,MAAM,CAAuB;MACpE,MAAMG,QAAQ,GAAGd,MAAM,CAACY,aAAa,CAAC;MACtC,IAAI,CAACV,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEG,QAAQ,CAAC;MAClC,OAAO,IAAI;IACf;IAEA,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEX,MAAM,CAAC;IAEhC,OAAO,IAAI;EACf;EAEAe,KAAKA,CAACb,OAAwB,EAAE;IAC5B,OAAOD,eAAe,CAACe,MAAM,CAAC;MAAE,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;MAAE,GAAGf,OAAO,CAACe,UAAU,CAAC;IAAE,CAAC,CAAC;EACpF;EAEAA,UAAUA,CAAA,EAAG;IACT,OAAOX,MAAM,CAACY,WAAW,CAAC,IAAI,CAAChB,OAAO,CAAC;EAC3C;EAEA,OAAOc,MAAMA,CAACX,cAAgC,EAAE;IAC5C,OAAO,IAAIJ,eAAe,CAACI,cAAc,CAAC;EAC9C;AACJ;AAACc,OAAA,CAAAlB,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries","exports"],"sources":["ResponseHeaders.ts"],"sourcesContent":["import * 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"],"mappings":";;;;;;AAWA;;AAWA,SAASA,UAAUA,CAAIC,MAAe,EAA6B;EAC/D,OAAO,OAAOA,MAAM,KAAK,UAAU;AACvC;AAIO,MAAMC,eAAe,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAA6C,CAAC;EAExEC,WAAWA,CAACC,cAAgC,EAAE;IAClD,IAAIA,cAAc,EAAE;MACfC,MAAM,CAACC,IAAI,CAACF,cAAc,CAAC,CAAkCG,OAAO,CAACC,GAAG,IAAI;QACzE,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACD,GAAG,EAAEJ,cAAc,CAACI,GAAG,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;EAEAC,GAAGA,CAAkCC,MAAS,EAAEX,MAAkC,EAAE;IAChF,IAAID,UAAU,CAAqBC,MAAM,CAAC,EAAE;MACxC,MAAMY,aAAa,GAAG,IAAI,CAACV,OAAO,CAACW,GAAG,CAACF,MAAM,CAAuB;MACpE,MAAMG,QAAQ,GAAGd,MAAM,CAACY,aAAa,CAAC;MACtC,IAAI,CAACV,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEG,QAAQ,CAAC;MAClC,OAAO,IAAI;IACf;IAEA,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEX,MAAM,CAAC;IAEhC,OAAO,IAAI;EACf;EAEAe,KAAKA,CAACb,OAAwB,EAAE;IAC5B,OAAOD,eAAe,CAACe,MAAM,CAAC;MAAE,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;MAAE,GAAGf,OAAO,CAACe,UAAU,CAAC;IAAE,CAAC,CAAC;EACpF;EAEAA,UAAUA,CAAA,EAAG;IACT,OAAOX,MAAM,CAACY,WAAW,CAAC,IAAI,CAAChB,OAAO,CAAC;EAC3C;EAEA,OAAOc,MAAMA,CAACX,cAAgC,EAAE;IAC5C,OAAO,IAAIJ,eAAe,CAACI,cAAc,CAAC;EAC9C;AACJ;AAACc,OAAA,CAAAlB,eAAA,GAAAA,eAAA","ignoreList":[]}
package/fastify.js CHANGED
@@ -33,7 +33,8 @@ var _IfOptionsRequest = require("./PreHandler/IfOptionsRequest");
33
33
  var _SendEarlyOptionsResponse = require("./PreHandler/SendEarlyOptionsResponse");
34
34
  const modifyResponseHeaders = (app, request, reply) => {
35
35
  const modifyHeaders = app.webiny.plugins.byType(_ModifyResponseHeadersPlugin.ModifyResponseHeadersPlugin.type);
36
- const headers = _ResponseHeaders.ResponseHeaders.create(reply.getHeaders());
36
+ const replyHeaders = reply.getHeaders();
37
+ const headers = _ResponseHeaders.ResponseHeaders.create(replyHeaders);
37
38
  modifyHeaders.forEach(plugin => {
38
39
  plugin.modify(request, headers);
39
40
  });
@@ -56,11 +57,14 @@ const createHandler = params => {
56
57
  PROPPATCH: [],
57
58
  SEARCH: [],
58
59
  TRACE: [],
59
- UNLOCK: []
60
+ UNLOCK: [],
61
+ REPORT: [],
62
+ MKCALENDAR: []
60
63
  };
61
64
  const throwOnDefinedRoute = (type, path, options) => {
62
65
  if (type === "ALL") {
63
- const all = Object.keys(definedRoutes).find(key => {
66
+ const all = Object.keys(definedRoutes).find(k => {
67
+ const key = k.toUpperCase();
64
68
  const routes = definedRoutes[key];
65
69
  return routes.includes(path);
66
70
  });
@@ -84,7 +88,8 @@ const createHandler = params => {
84
88
  path
85
89
  });
86
90
  };
87
- const addDefinedRoute = (type, path) => {
91
+ const addDefinedRoute = (input, path) => {
92
+ const type = input.toUpperCase();
88
93
  if (!definedRoutes[type]) {
89
94
  return;
90
95
  } else if (definedRoutes[type].includes(path)) {
@@ -231,6 +236,11 @@ const createHandler = params => {
231
236
  app.addHook("preHandler", async (request, reply) => {
232
237
  app.webiny.request = request;
233
238
  app.webiny.reply = reply;
239
+ /**
240
+ * Default code to 200 - so we do not need to set it again.
241
+ * Usually we set errors manually when we use reply.send.
242
+ */
243
+ reply.code(200);
234
244
  const handlerOnRequestPlugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
235
245
  const contextPlugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
236
246
  const beforeHandlerPlugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
@@ -253,7 +263,14 @@ const createHandler = params => {
253
263
  }
254
264
  return payload;
255
265
  });
256
- app.setErrorHandler(async (error, request, reply) => {
266
+ app.setErrorHandler(async (error, _, reply) => {
267
+ /**
268
+ * IMPORTANT! Do not send anything if reply was already sent.
269
+ */
270
+ if (reply.sent) {
271
+ console.warn("Reply already sent, cannot send the result (handler:setErrorHandler).");
272
+ return reply;
273
+ }
257
274
  return reply.status(500).headers({
258
275
  "Cache-Control": "no-store"
259
276
  }).send(
@@ -266,30 +283,37 @@ const createHandler = params => {
266
283
  data: error.data
267
284
  }));
268
285
  });
269
- app.addHook("onError", async (request, reply, error) => {
286
+ app.addHook("onError", async (_, reply, error) => {
270
287
  const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
271
288
  /**
272
289
  * Log error to cloud, as these can be extremely annoying to debug!
273
290
  */
274
- console.error("@webiny/handler");
275
- console.log({
276
- url: request.url,
277
- method: request.method,
278
- headers: request.headers,
279
- body: request.body
280
- });
281
- console.error((0, _stringifyError.stringifyError)(error));
282
- reply.status(500).headers({
283
- "Cache-Control": "no-store"
284
- }).send(
291
+ console.error("Logging error in @webiny/handler");
292
+ try {
293
+ console.error((0, _stringifyError.stringifyError)(error));
294
+ } catch (ex) {
295
+ console.warn("Could not stringify error:");
296
+ console.log(error);
297
+ console.error("Stringify error:", ex);
298
+ }
285
299
  /**
286
- * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.
300
+ * IMPORTANT! Do not send anything if reply was already sent.
287
301
  */
288
- JSON.stringify({
289
- message: error.message,
290
- code: error.code,
291
- data: error.data
292
- }));
302
+ if (!reply.sent) {
303
+ reply.status(500).headers({
304
+ "Cache-Control": "no-store"
305
+ }).send(
306
+ /**
307
+ * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.
308
+ */
309
+ JSON.stringify({
310
+ message: error.message,
311
+ code: error.code,
312
+ data: error.data
313
+ }));
314
+ } else {
315
+ console.warn("Reply already sent, cannot send the result (handler:addHook:onError).");
316
+ }
293
317
  const handler = (0, _utils.middleware)(plugins.map(pl => {
294
318
  return (context, error, next) => {
295
319
  return pl.handle(context, error, next);
package/fastify.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_types","require","_fastify","_interopRequireDefault","_utils","_Context","_error","_RoutePlugin","_handlerClient","_cookie","_compress","_api","_BeforeHandlerPlugin","_HandlerResultPlugin","_HandlerErrorPlugin","_ModifyFastifyPlugin","_HandlerOnRequestPlugin","_ResponseHeaders","_ModifyResponseHeadersPlugin","_SetDefaultHeaders","_PreHandler","_stringifyError","_ProcessHandlerOnRequestPlugins","_ProcessContextPlugins","_IfNotOptionsRequest","_ProcessBeforeHandlerPlugins","_IfOptionsRequest","_SendEarlyOptionsResponse","modifyResponseHeaders","app","request","reply","modifyHeaders","webiny","plugins","byType","ModifyResponseHeadersPlugin","type","headers","ResponseHeaders","create","getHeaders","forEach","plugin","modify","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","all","Object","keys","find","key","routes","includes","console","error","JSON","stringify","WebinyError","override","addDefinedRoute","push","fastify","bodyLimit","disableRequestLogging","addHook","route","method","Array","isArray","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","code","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","PluginsContainer","createHandlerClient","merge","Context","WEBINY_VERSION","process","env","ex","stringifyError","decorate","body","undefined","handlerOnRequestPlugins","HandlerOnRequestPlugin","contextPlugins","ContextPlugin","beforeHandlerPlugins","BeforeHandlerPlugin","modifyHeadersPlugins","preHandler","PreHandler","SetDefaultHeaders","ProcessHandlerOnRequestPlugins","IfNotOptionsRequest","ProcessContextPlugins","ProcessBeforeHandlerPlugins","IfOptionsRequest","SendEarlyOptionsResponse","execute","__","payload","HandlerResultPlugin","name","handle","setErrorHandler","status","send","message","data","HandlerErrorPlugin","log","url","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName","cb","exports"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection, PluginsContainer } from \"@webiny/plugins/types\";\nimport fastify, { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport { middleware, MiddlewareCallable } from \"@webiny/utils\";\nimport {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n Reply,\n Request,\n RouteMethodOptions\n} from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\nimport { ResponseHeaders } from \"~/ResponseHeaders\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { SetDefaultHeaders } from \"./PreHandler/SetDefaultHeaders\";\nimport { PreHandler } from \"./PreHandler/PreHandler\";\nimport { stringifyError } from \"./stringifyError\";\nimport { ProcessHandlerOnRequestPlugins } from \"./PreHandler/ProcessHandlerOnRequestPlugins\";\nimport { ProcessContextPlugins } from \"./PreHandler/ProcessContextPlugins\";\nimport { IfNotOptionsRequest } from \"./PreHandler/IfNotOptionsRequest\";\nimport { ProcessBeforeHandlerPlugins } from \"./PreHandler/ProcessBeforeHandlerPlugins\";\nimport { IfOptionsRequest } from \"./PreHandler/IfOptionsRequest\";\nimport { SendEarlyOptionsResponse } from \"./PreHandler/SendEarlyOptionsResponse\";\n\nconst modifyResponseHeaders = (app: FastifyInstance, request: Request, reply: Reply) => {\n const modifyHeaders = app.webiny.plugins.byType<ModifyResponseHeadersPlugin>(\n ModifyResponseHeadersPlugin.type\n );\n\n const headers = ResponseHeaders.create(reply.getHeaders());\n\n modifyHeaders.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\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 };\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(key => {\n const routes = definedRoutes[key as HTTPMethods];\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 = (type: HTTPMethods, path: string): void => {\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 ...(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;\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 /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient()\n ]);\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 * 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 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 preHandler = new PreHandler([\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);\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, request, reply) => {\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 (request, 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(\"@webiny/handler\");\n console.log({\n url: request.url,\n method: request.method,\n headers: request.headers,\n body: request.body\n });\n console.error(stringifyError(error));\n\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\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, payload) => {\n modifyResponseHeaders(app, request, reply);\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 () => {\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":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AASA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAN,sBAAA,CAAAF,OAAA;AACA,IAAAS,SAAA,GAAAP,sBAAA,CAAAF,OAAA;AACA,IAAAU,IAAA,GAAAV,OAAA;AACA,IAAAW,oBAAA,GAAAX,OAAA;AACA,IAAAY,oBAAA,GAAAZ,OAAA;AACA,IAAAa,mBAAA,GAAAb,OAAA;AACA,IAAAc,oBAAA,GAAAd,OAAA;AACA,IAAAe,uBAAA,GAAAf,OAAA;AACA,IAAAgB,gBAAA,GAAAhB,OAAA;AACA,IAAAiB,4BAAA,GAAAjB,OAAA;AACA,IAAAkB,kBAAA,GAAAlB,OAAA;AACA,IAAAmB,WAAA,GAAAnB,OAAA;AACA,IAAAoB,eAAA,GAAApB,OAAA;AACA,IAAAqB,+BAAA,GAAArB,OAAA;AACA,IAAAsB,sBAAA,GAAAtB,OAAA;AACA,IAAAuB,oBAAA,GAAAvB,OAAA;AACA,IAAAwB,4BAAA,GAAAxB,OAAA;AACA,IAAAyB,iBAAA,GAAAzB,OAAA;AACA,IAAA0B,yBAAA,GAA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Default","_utils","_Context","_error","_RoutePlugin","_handlerClient","_cookie","_compress","_api","_BeforeHandlerPlugin","_HandlerResultPlugin","_HandlerErrorPlugin","_ModifyFastifyPlugin","_HandlerOnRequestPlugin","_ResponseHeaders","_ModifyResponseHeadersPlugin","_SetDefaultHeaders","_PreHandler","_stringifyError","_ProcessHandlerOnRequestPlugins","_ProcessContextPlugins","_IfNotOptionsRequest","_ProcessBeforeHandlerPlugins","_IfOptionsRequest","_SendEarlyOptionsResponse","modifyResponseHeaders","app","request","reply","modifyHeaders","webiny","plugins","byType","ModifyResponseHeadersPlugin","type","replyHeaders","getHeaders","headers","ResponseHeaders","create","forEach","plugin","modify","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","WebinyError","override","addDefinedRoute","input","push","fastify","bodyLimit","disableRequestLogging","addHook","route","method","Array","isArray","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","code","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","PluginsContainer","createHandlerClient","merge","Context","WEBINY_VERSION","process","env","ex","stringifyError","decorate","body","undefined","handlerOnRequestPlugins","HandlerOnRequestPlugin","contextPlugins","ContextPlugin","beforeHandlerPlugins","BeforeHandlerPlugin","modifyHeadersPlugins","preHandler","PreHandler","SetDefaultHeaders","ProcessHandlerOnRequestPlugins","IfNotOptionsRequest","ProcessContextPlugins","ProcessBeforeHandlerPlugins","IfOptionsRequest","SendEarlyOptionsResponse","execute","__","payload","HandlerResultPlugin","name","handle","setErrorHandler","sent","warn","status","send","message","data","HandlerErrorPlugin","log","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName","cb","exports"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection, PluginsContainer } from \"@webiny/plugins/types\";\nimport fastify, { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport { middleware, MiddlewareCallable } from \"@webiny/utils\";\nimport {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n Reply,\n Request,\n RouteMethodOptions\n} from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookie from \"@fastify/cookie\";\nimport fastifyCompress from \"@fastify/compress\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\nimport { ModifyFastifyPlugin } from \"~/plugins/ModifyFastifyPlugin\";\nimport { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin\";\nimport { ResponseHeaders, StandardHeaders } from \"~/ResponseHeaders\";\nimport { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin\";\nimport { SetDefaultHeaders } from \"./PreHandler/SetDefaultHeaders\";\nimport { PreHandler } from \"./PreHandler/PreHandler\";\nimport { stringifyError } from \"./stringifyError\";\nimport { ProcessHandlerOnRequestPlugins } from \"./PreHandler/ProcessHandlerOnRequestPlugins\";\nimport { ProcessContextPlugins } from \"./PreHandler/ProcessContextPlugins\";\nimport { IfNotOptionsRequest } from \"./PreHandler/IfNotOptionsRequest\";\nimport { ProcessBeforeHandlerPlugins } from \"./PreHandler/ProcessBeforeHandlerPlugins\";\nimport { IfOptionsRequest } from \"./PreHandler/IfOptionsRequest\";\nimport { SendEarlyOptionsResponse } from \"./PreHandler/SendEarlyOptionsResponse\";\n\nconst modifyResponseHeaders = (app: FastifyInstance, request: Request, reply: Reply) => {\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 reply.headers(headers.getHeaders());\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 ...(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 /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient()\n ]);\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 * 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 * 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 preHandler = new PreHandler([\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);\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 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, payload) => {\n modifyResponseHeaders(app, request, reply);\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 () => {\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;\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D,CAAC;IACDpG,OAAO,CAACC,KAAK,CAAC,IAAAqD,8BAAc,EAACD,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOvG,GAAG;AACd,CAAC;AAACwJ,OAAA,CAAAvI,aAAA,GAAAA,aAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler",
3
- "version": "5.43.0-beta.0",
3
+ "version": "5.43.0-beta.2",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,20 +12,19 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@fastify/compress": "6.2.0",
16
- "@fastify/cookie": "8.3.0",
17
- "@webiny/api": "5.43.0-beta.0",
18
- "@webiny/error": "5.43.0-beta.0",
19
- "@webiny/handler-client": "5.43.0-beta.0",
20
- "@webiny/plugins": "5.43.0-beta.0",
21
- "@webiny/utils": "5.43.0-beta.0",
22
- "fastify": "4.15.0"
15
+ "@fastify/compress": "7.0.3",
16
+ "@fastify/cookie": "9.4.0",
17
+ "@webiny/api": "5.43.0-beta.2",
18
+ "@webiny/error": "5.43.0-beta.2",
19
+ "@webiny/handler-client": "5.43.0-beta.2",
20
+ "@webiny/plugins": "5.43.0-beta.2",
21
+ "@webiny/utils": "5.43.0-beta.2",
22
+ "fastify": "4.29.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@webiny/project-utils": "5.43.0-beta.0",
25
+ "@webiny/project-utils": "5.43.0-beta.2",
26
26
  "rimraf": "6.0.1",
27
- "ttypescript": "1.5.15",
28
- "typescript": "4.9.5"
27
+ "typescript": "5.3.3"
29
28
  },
30
29
  "publishConfig": {
31
30
  "access": "public",
@@ -35,5 +34,5 @@
35
34
  "build": "node ../cli/bin.js run build",
36
35
  "watch": "node ../cli/bin.js run watch"
37
36
  },
38
- "gitHead": "abfb4ec7b4391f2414cd22f2c5539c84b6c8abbf"
37
+ "gitHead": "dbed8c263df662358aca18c3cf452cd280f2dfd9"
39
38
  }
package/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import "@fastify/cookie";
2
- import { FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
3
- export { FastifyInstance, HTTPMethods } from "fastify";
2
+ import { FastifyRequest, FastifyReply, HTTPMethods as BaseHttpMethods, RouteHandlerMethod } from "fastify";
3
+ export { FastifyInstance } from "fastify";
4
4
  import { ClientContext } from "@webiny/handler-client/types";
5
5
  export interface RouteMethodOptions {
6
6
  override?: boolean;
@@ -11,6 +11,7 @@ export interface RouteMethod {
11
11
  }
12
12
  export type Request = FastifyRequest;
13
13
  export type Reply = FastifyReply;
14
+ export type HTTPMethods = Uppercase<BaseHttpMethods>;
14
15
  export type DefinedContextRoutes = Record<HTTPMethods, string[]>;
15
16
  export interface ContextRoutes {
16
17
  defined: DefinedContextRoutes;
package/types.js CHANGED
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "FastifyInstance", {
9
9
  return _fastify.FastifyInstance;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "HTTPMethods", {
13
- enumerable: true,
14
- get: function () {
15
- return _fastify.HTTPMethods;
16
- }
17
- });
18
12
  require("@fastify/cookie");
19
13
  var _fastify = require("fastify");
20
14
 
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["require","_fastify"],"sources":["types.ts"],"sourcesContent":["import \"@fastify/cookie\";\nimport { FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from \"fastify\";\nexport { FastifyInstance, HTTPMethods } from \"fastify\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nexport interface RouteMethodOptions {\n override?: boolean;\n}\n\nexport type RouteMethodPath = `/${string}` | \"*\";\nexport interface RouteMethod {\n (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;\n}\n\nexport type Request = FastifyRequest;\nexport type Reply = FastifyReply;\n\nexport type DefinedContextRoutes = Record<HTTPMethods, string[]>;\nexport interface ContextRoutes {\n defined: DefinedContextRoutes;\n onGet: RouteMethod;\n onPost: RouteMethod;\n onPut: RouteMethod;\n onPatch: RouteMethod;\n onDelete: RouteMethod;\n onOptions: RouteMethod;\n onAll: RouteMethod;\n onHead: RouteMethod;\n}\n\nexport interface Context extends ClientContext {\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * Current reply. Must be set only once!\n */\n reply: FastifyReply;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAAA,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["require","_fastify"],"sources":["types.ts"],"sourcesContent":["import \"@fastify/cookie\";\nimport {\n FastifyRequest,\n FastifyReply,\n HTTPMethods as BaseHttpMethods,\n RouteHandlerMethod\n} from \"fastify\";\nexport { FastifyInstance } from \"fastify\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nexport interface RouteMethodOptions {\n override?: boolean;\n}\n\nexport type RouteMethodPath = `/${string}` | \"*\";\nexport interface RouteMethod {\n (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;\n}\n\nexport type Request = FastifyRequest;\nexport type Reply = FastifyReply;\n\nexport type HTTPMethods = Uppercase<BaseHttpMethods>;\n\nexport type DefinedContextRoutes = Record<HTTPMethods, string[]>;\n\nexport interface ContextRoutes {\n defined: DefinedContextRoutes;\n onGet: RouteMethod;\n onPost: RouteMethod;\n onPut: RouteMethod;\n onPatch: RouteMethod;\n onDelete: RouteMethod;\n onOptions: RouteMethod;\n onAll: RouteMethod;\n onHead: RouteMethod;\n}\n\nexport interface Context extends ClientContext {\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * Current reply. Must be set only once!\n */\n reply: FastifyReply;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAAA,OAAA;AAOA,IAAAC,QAAA,GAAAD,OAAA","ignoreList":[]}