@webiny/handler 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.9bd236cf5e

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.
Files changed (82) hide show
  1. package/Context.d.ts +4 -5
  2. package/Context.js +6 -12
  3. package/Context.js.map +1 -1
  4. package/PreHandler/IPreHandler.d.ts +9 -0
  5. package/PreHandler/IPreHandler.js +13 -0
  6. package/PreHandler/IPreHandler.js.map +1 -0
  7. package/PreHandler/IfNotOptionsRequest.d.ts +9 -0
  8. package/PreHandler/IfNotOptionsRequest.js +28 -0
  9. package/PreHandler/IfNotOptionsRequest.js.map +1 -0
  10. package/PreHandler/IfOptionsRequest.d.ts +9 -0
  11. package/PreHandler/IfOptionsRequest.js +28 -0
  12. package/PreHandler/IfOptionsRequest.js.map +1 -0
  13. package/PreHandler/PreHandler.d.ts +9 -0
  14. package/PreHandler/PreHandler.js +24 -0
  15. package/PreHandler/PreHandler.js.map +1 -0
  16. package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +10 -0
  17. package/PreHandler/ProcessBeforeHandlerPlugins.js +31 -0
  18. package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -0
  19. package/PreHandler/ProcessContextPlugins.d.ts +10 -0
  20. package/PreHandler/ProcessContextPlugins.js +31 -0
  21. package/PreHandler/ProcessContextPlugins.js.map +1 -0
  22. package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +10 -0
  23. package/PreHandler/ProcessHandlerOnRequestPlugins.js +33 -0
  24. package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -0
  25. package/PreHandler/SendEarlyOptionsResponse.d.ts +9 -0
  26. package/PreHandler/SendEarlyOptionsResponse.js +38 -0
  27. package/PreHandler/SendEarlyOptionsResponse.js.map +1 -0
  28. package/PreHandler/SetDefaultHeaders.d.ts +9 -0
  29. package/PreHandler/SetDefaultHeaders.js +64 -0
  30. package/PreHandler/SetDefaultHeaders.js.map +1 -0
  31. package/ResponseHeaders.d.ts +25 -0
  32. package/ResponseHeaders.js +46 -0
  33. package/ResponseHeaders.js.map +1 -0
  34. package/fastify.d.ts +6 -4
  35. package/fastify.js +159 -185
  36. package/fastify.js.map +1 -1
  37. package/index.d.ts +6 -0
  38. package/index.js +48 -1
  39. package/index.js.map +1 -1
  40. package/package.json +15 -23
  41. package/plugins/BeforeHandlerPlugin.d.ts +1 -1
  42. package/plugins/BeforeHandlerPlugin.js +4 -5
  43. package/plugins/BeforeHandlerPlugin.js.map +1 -1
  44. package/plugins/EventPlugin.d.ts +1 -1
  45. package/plugins/EventPlugin.js +4 -5
  46. package/plugins/EventPlugin.js.map +1 -1
  47. package/plugins/HandlerErrorPlugin.d.ts +6 -3
  48. package/plugins/HandlerErrorPlugin.js +4 -5
  49. package/plugins/HandlerErrorPlugin.js.map +1 -1
  50. package/plugins/HandlerOnRequestPlugin.d.ts +9 -8
  51. package/plugins/HandlerOnRequestPlugin.js +13 -7
  52. package/plugins/HandlerOnRequestPlugin.js.map +1 -1
  53. package/plugins/HandlerResultPlugin.d.ts +1 -1
  54. package/plugins/HandlerResultPlugin.js +4 -5
  55. package/plugins/HandlerResultPlugin.js.map +1 -1
  56. package/plugins/ModifyFastifyPlugin.d.ts +1 -1
  57. package/plugins/ModifyFastifyPlugin.js +4 -5
  58. package/plugins/ModifyFastifyPlugin.js.map +1 -1
  59. package/plugins/ModifyResponseHeadersPlugin.d.ts +14 -0
  60. package/plugins/ModifyResponseHeadersPlugin.js +24 -0
  61. package/plugins/ModifyResponseHeadersPlugin.js.map +1 -0
  62. package/plugins/OnRequestResponseSendPlugin.d.ts +26 -0
  63. package/plugins/OnRequestResponseSendPlugin.js +40 -0
  64. package/plugins/OnRequestResponseSendPlugin.js.map +1 -0
  65. package/plugins/OnRequestTimeoutPlugin.d.ts +12 -0
  66. package/plugins/OnRequestTimeoutPlugin.js +24 -0
  67. package/plugins/OnRequestTimeoutPlugin.js.map +1 -0
  68. package/plugins/RoutePlugin.d.ts +1 -1
  69. package/plugins/RoutePlugin.js +4 -5
  70. package/plugins/RoutePlugin.js.map +1 -1
  71. package/stringifyError.d.ts +5 -0
  72. package/stringifyError.js +27 -0
  73. package/stringifyError.js.map +1 -0
  74. package/suppressPunycodeWarnings.d.ts +4 -0
  75. package/suppressPunycodeWarnings.js +11 -0
  76. package/suppressPunycodeWarnings.js.map +1 -0
  77. package/types.d.ts +10 -13
  78. package/types.js +4 -7
  79. package/types.js.map +1 -1
  80. package/middleware.d.ts +0 -4
  81. package/middleware.js +0 -45
  82. package/middleware.js.map +0 -1
package/fastify.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /// <reference types="node" />
2
- import { PluginCollection } from "@webiny/plugins/types";
3
- import { FastifyServerOptions as ServerOptions } from "fastify";
2
+ import type { PluginCollection } from "@webiny/plugins/types";
3
+ import { PluginsContainer } from "@webiny/plugins/types";
4
+ import type { FastifyInstance, FastifyServerOptions as ServerOptions } from "fastify";
4
5
  export interface CreateHandlerParams {
5
- plugins: PluginCollection;
6
+ plugins: PluginCollection | PluginsContainer;
6
7
  options?: ServerOptions;
8
+ debug?: boolean;
7
9
  }
8
- export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
10
+ export declare const createHandler: (params: CreateHandlerParams) => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;
package/fastify.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createHandler = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
8
+ var _types = require("@webiny/plugins/types");
9
9
  var _fastify = _interopRequireDefault(require("fastify"));
10
10
  var _utils = require("@webiny/utils");
11
11
  var _Context = require("./Context");
@@ -14,61 +14,33 @@ var _RoutePlugin = require("./plugins/RoutePlugin");
14
14
  var _handlerClient = require("@webiny/handler-client");
15
15
  var _cookie = _interopRequireDefault(require("@fastify/cookie"));
16
16
  var _compress = _interopRequireDefault(require("@fastify/compress"));
17
- var _middleware = require("./middleware");
18
17
  var _api = require("@webiny/api");
19
18
  var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
20
19
  var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
21
20
  var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
22
21
  var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
23
22
  var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
24
- const DEFAULT_HEADERS = (0, _objectSpread2.default)({
25
- "Cache-Control": "no-store",
26
- "Content-Type": "application/json; charset=utf-8",
27
- "Access-Control-Allow-Origin": "*",
28
- "Access-Control-Allow-Headers": "*",
29
- "Access-Control-Allow-Methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH"
30
- }, (0, _utils.getWebinyVersionHeaders)());
31
- const getDefaultHeaders = routes => {
32
- /**
33
- * If we are accepting all headers, just output that one.
34
- */
35
- const keys = Object.keys(routes);
36
- const all = keys.every(key => routes[key].length > 0);
37
- if (all) {
38
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
39
- "Access-Control-Allow-Methods": "*"
40
- });
41
- }
42
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
43
- "Access-Control-Allow-Methods": keys.filter(type => {
44
- if (!routes[type] || Array.isArray(routes[type]) === false) {
45
- return false;
46
- }
47
- return routes[type].length > 0;
48
- }).sort().join(",")
23
+ var _ResponseHeaders = require("./ResponseHeaders");
24
+ var _ModifyResponseHeadersPlugin = require("./plugins/ModifyResponseHeadersPlugin");
25
+ var _SetDefaultHeaders = require("./PreHandler/SetDefaultHeaders");
26
+ var _PreHandler = require("./PreHandler/PreHandler");
27
+ var _stringifyError = require("./stringifyError");
28
+ var _ProcessHandlerOnRequestPlugins = require("./PreHandler/ProcessHandlerOnRequestPlugins");
29
+ var _ProcessContextPlugins = require("./PreHandler/ProcessContextPlugins");
30
+ var _IfNotOptionsRequest = require("./PreHandler/IfNotOptionsRequest");
31
+ var _ProcessBeforeHandlerPlugins = require("./PreHandler/ProcessBeforeHandlerPlugins");
32
+ var _IfOptionsRequest = require("./PreHandler/IfOptionsRequest");
33
+ var _SendEarlyOptionsResponse = require("./PreHandler/SendEarlyOptionsResponse");
34
+ var _OnRequestTimeoutPlugin = require("./plugins/OnRequestTimeoutPlugin.js");
35
+ var _OnRequestResponseSendPlugin = require("./plugins/OnRequestResponseSendPlugin.js");
36
+ const modifyResponseHeaders = (app, request, reply) => {
37
+ const modifyHeaders = app.webiny.plugins.byType(_ModifyResponseHeadersPlugin.ModifyResponseHeadersPlugin.type);
38
+ const replyHeaders = reply.getHeaders();
39
+ const headers = _ResponseHeaders.ResponseHeaders.create(replyHeaders);
40
+ modifyHeaders.forEach(plugin => {
41
+ plugin.modify(request, headers);
49
42
  });
50
- };
51
- const stringifyError = error => {
52
- var _error$constructor;
53
- const {
54
- name,
55
- message,
56
- code,
57
- stack,
58
- data
59
- } = error;
60
- return JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, error), {}, {
61
- constructorName: ((_error$constructor = error.constructor) === null || _error$constructor === void 0 ? void 0 : _error$constructor.name) || "UnknownError",
62
- name: name || "No error name",
63
- message: message || "No error message",
64
- code: code || "NO_CODE",
65
- data,
66
- stack: process.env.DEBUG === "true" ? stack : "Turn on the debug flag to see the stack."
67
- }));
68
- };
69
- const OPTIONS_HEADERS = {
70
- "Access-Control-Max-Age": "86400",
71
- "Cache-Control": "public, max-age=86400"
43
+ reply.headers(headers.getHeaders());
72
44
  };
73
45
  const createHandler = params => {
74
46
  const definedRoutes = {
@@ -87,11 +59,14 @@ const createHandler = params => {
87
59
  PROPPATCH: [],
88
60
  SEARCH: [],
89
61
  TRACE: [],
90
- UNLOCK: []
62
+ UNLOCK: [],
63
+ REPORT: [],
64
+ MKCALENDAR: []
91
65
  };
92
66
  const throwOnDefinedRoute = (type, path, options) => {
93
67
  if (type === "ALL") {
94
- const all = Object.keys(definedRoutes).find(key => {
68
+ const all = Object.keys(definedRoutes).find(k => {
69
+ const key = k.toUpperCase();
95
70
  const routes = definedRoutes[key];
96
71
  return routes.includes(path);
97
72
  });
@@ -106,7 +81,7 @@ const createHandler = params => {
106
81
  });
107
82
  } else if (definedRoutes[type].includes(path) === false) {
108
83
  return;
109
- } else if ((options === null || options === void 0 ? void 0 : options.override) === true) {
84
+ } else if (options?.override === true) {
110
85
  return;
111
86
  }
112
87
  console.error(`Error while trying to override route: [${type}] ${path}`);
@@ -115,7 +90,8 @@ const createHandler = params => {
115
90
  path
116
91
  });
117
92
  };
118
- const addDefinedRoute = (type, path) => {
93
+ const addDefinedRoute = (input, path) => {
94
+ const type = input.toUpperCase();
119
95
  if (!definedRoutes[type]) {
120
96
  return;
121
97
  } else if (definedRoutes[type].includes(path)) {
@@ -123,12 +99,19 @@ const createHandler = params => {
123
99
  }
124
100
  definedRoutes[type].push(path);
125
101
  };
102
+
126
103
  /**
127
104
  * We must attach the server to our internal context if we want to have it accessible.
128
105
  */
129
- const app = (0, _fastify.default)((0, _objectSpread2.default)({}, params.options || {}));
106
+ const app = (0, _fastify.default)({
107
+ bodyLimit: 536870912,
108
+ // 512MB
109
+ disableRequestLogging: true,
110
+ ...(params.options || {})
111
+ });
112
+
130
113
  /**
131
- * We need to register routes in our system so we can output headers later on and dissallow overriding routes.
114
+ * We need to register routes in our system to output headers later on, and disallow route overriding.
132
115
  */
133
116
  app.addHook("onRoute", route => {
134
117
  const method = route.method;
@@ -205,24 +188,25 @@ const createHandler = params => {
205
188
  }
206
189
  };
207
190
  let context;
191
+ const plugins = new _types.PluginsContainer([
192
+ /**
193
+ * We must have handlerClient by default.
194
+ * And it must be one of the first context plugins applied.
195
+ */
196
+ (0, _handlerClient.createHandlerClient)()]);
197
+ plugins.merge(params.plugins || []);
208
198
  try {
209
199
  context = new _Context.Context({
210
- plugins: [
211
- /**
212
- * We must have handlerClient by default.
213
- * And it must be one of the first context plugins applied.
214
- */
215
- (0, _handlerClient.createHandlerClient)(), ...(params.plugins || [])],
200
+ plugins,
216
201
  /**
217
- * Inserted via webpack on build time.
202
+ * Inserted via webpack at build time.
218
203
  */
219
204
  WEBINY_VERSION: process.env.WEBINY_VERSION,
220
- server: app,
221
205
  routes
222
206
  });
223
207
  } catch (ex) {
224
208
  console.error(`Error while constructing the Context.`);
225
- console.error(stringifyError(ex));
209
+ console.error((0, _stringifyError.stringifyError)(ex));
226
210
  throw ex;
227
211
  }
228
212
 
@@ -232,117 +216,41 @@ const createHandler = params => {
232
216
  app.decorate("webiny", context);
233
217
 
234
218
  /**
235
- * We have few types of triggers:
236
- * * Events - EventPlugin
237
- * * Routes - RoutePlugin
219
+ * With this we ensure that an undefined request body is not parsed on OPTIONS requests,
220
+ * in case there's a `content-type` header set for whatever reason.
238
221
  *
239
- * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
222
+ * @see https://fastify.dev/docs/latest/Reference/ContentTypeParser/#content-type-parser
240
223
  */
241
- const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
242
-
243
- /**
244
- * Add routes to the system.
245
- */
246
- let routePluginName;
247
- try {
248
- for (const plugin of routePlugins) {
249
- routePluginName = plugin.name;
250
- plugin.cb((0, _objectSpread2.default)((0, _objectSpread2.default)({}, app.webiny.routes), {}, {
251
- context: app.webiny
252
- }));
224
+ app.addHook("onRequest", async request => {
225
+ if (request.method === "OPTIONS" && request.body === undefined) {
226
+ request.headers["content-type"] = undefined;
253
227
  }
254
- } catch (ex) {
255
- console.error(`Error while running the "RoutePlugin" ${routePluginName ? `(${routePluginName})` : ""} plugin in the beginning of the "createHandler" callable.`);
256
- console.error(stringifyError(ex));
257
- throw ex;
258
- }
228
+ });
259
229
 
260
230
  /**
261
- * On every request we add default headers, which can be changed later.
262
- * Also, if it is an options request, we skip everything after this hook and output options headers.
231
+ * At this point, request body is properly parsed, and we can execute Webiny business logic.
232
+ * - set default headers
233
+ * - process `HandlerOnRequestPlugin`
234
+ * - if OPTIONS request, exit early
235
+ * - process `ContextPlugin`
236
+ * - process `BeforeHandlerPlugin`
263
237
  */
264
- app.addHook("onRequest", async (request, reply) => {
265
- /**
266
- * Our default headers are always set. Users can override them.
267
- */
268
- const defaultHeaders = getDefaultHeaders(definedRoutes);
269
- reply.headers(defaultHeaders);
270
- /**
271
- * Users can define their own custom handlers for the onRequest event - so let's run them first.
272
- */
273
- const plugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
274
- let name;
275
- try {
276
- for (const plugin of plugins) {
277
- name = plugin.name;
278
- const result = await plugin.exec(request, reply);
279
- if (result === false) {
280
- return;
281
- }
282
- }
283
- } catch (ex) {
284
- console.error(`Error while running the "HandlerOnRequestPlugin" ${name ? `(${name})` : ""} plugin in the onRequest hook.`);
285
- console.error(stringifyError(ex));
286
- throw ex;
287
- }
288
- /**
289
- * When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.
290
- *
291
- * Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.
292
- */
293
- if (request.method !== "OPTIONS") {
294
- return;
295
- }
296
- if (reply.sent) {
297
- /**
298
- * At this point throwing an exception will not do anything with the response. So just log it.
299
- */
300
- console.error(JSON.stringify({
301
- message: `Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".`,
302
- explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
303
- }));
304
- return;
305
- }
306
- reply.headers((0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultHeaders), OPTIONS_HEADERS)).code(204).send("").hijack();
307
- });
308
- app.addHook("preParsing", async (request, reply) => {
238
+ app.addHook("preHandler", async (request, reply) => {
309
239
  app.webiny.request = request;
310
240
  app.webiny.reply = reply;
311
- const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
312
- let name;
313
- try {
314
- for (const plugin of plugins) {
315
- name = plugin.name;
316
- await plugin.apply(app.webiny);
317
- }
318
- } catch (ex) {
319
- console.error(`Error while running the "ContextPlugin" ${name ? `(${name})` : ""} plugin in the preParsing hook.`);
320
- console.error(stringifyError(ex));
321
- throw ex;
322
- }
323
- });
324
- /**
325
- *
326
- */
327
- app.addHook("preHandler", async () => {
328
- const plugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
329
- let name;
330
- try {
331
- for (const plugin of plugins) {
332
- name = plugin.name;
333
- await plugin.apply(app.webiny);
334
- }
335
- } catch (ex) {
336
- console.error(`Error while running the "BeforeHandlerPlugin" ${name ? `(${name})` : ""} plugin in the preHandler hook.`);
337
- console.error(stringifyError(ex));
338
- throw ex;
339
- }
241
+ /**
242
+ * Default code to 200 - so we do not need to set it again.
243
+ * Usually we set errors manually when we use reply.send.
244
+ */
245
+ reply.code(200);
246
+ const handlerOnRequestPlugins = app.webiny.plugins.byType(_HandlerOnRequestPlugin.HandlerOnRequestPlugin.type);
247
+ const contextPlugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
248
+ const beforeHandlerPlugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
249
+ const modifyHeadersPlugins = app.webiny.plugins.byType(_ModifyResponseHeadersPlugin.ModifyResponseHeadersPlugin.type);
250
+ const preHandler = new _PreHandler.PreHandler([new _SetDefaultHeaders.SetDefaultHeaders(definedRoutes), new _ProcessHandlerOnRequestPlugins.ProcessHandlerOnRequestPlugins(handlerOnRequestPlugins), new _IfNotOptionsRequest.IfNotOptionsRequest([new _ProcessContextPlugins.ProcessContextPlugins(app.webiny, contextPlugins), new _ProcessBeforeHandlerPlugins.ProcessBeforeHandlerPlugins(app.webiny, beforeHandlerPlugins)]), new _IfOptionsRequest.IfOptionsRequest([new _SendEarlyOptionsResponse.SendEarlyOptionsResponse(modifyHeadersPlugins)])]);
251
+ await preHandler.execute(request, reply, app.webiny);
340
252
  });
341
-
342
- /**
343
- *
344
- */
345
- const preSerialization = async (_, __, payload) => {
253
+ app.addHook("preSerialization", async (_, __, payload) => {
346
254
  const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
347
255
  let name;
348
256
  try {
@@ -352,13 +260,19 @@ const createHandler = params => {
352
260
  }
353
261
  } catch (ex) {
354
262
  console.error(`Error while running the "HandlerResultPlugin" ${name ? `(${name})` : ""} plugin in the preSerialization hook.`);
355
- console.error(stringifyError(ex));
263
+ console.error((0, _stringifyError.stringifyError)(ex));
356
264
  throw ex;
357
265
  }
358
266
  return payload;
359
- };
360
- app.addHook("preSerialization", preSerialization);
361
- app.setErrorHandler(async (error, request, reply) => {
267
+ });
268
+ app.setErrorHandler(async (error, _, reply) => {
269
+ /**
270
+ * IMPORTANT! Do not send anything if reply was already sent.
271
+ */
272
+ if (reply.sent) {
273
+ console.warn("Reply already sent, cannot send the result (handler:setErrorHandler).");
274
+ return reply;
275
+ }
362
276
  return reply.status(500).headers({
363
277
  "Cache-Control": "no-store"
364
278
  }).send(
@@ -376,20 +290,33 @@ const createHandler = params => {
376
290
  /**
377
291
  * Log error to cloud, as these can be extremely annoying to debug!
378
292
  */
379
- console.error("@webiny/handler");
380
- console.error(stringifyError(error));
381
- reply.status(500).headers({
382
- "Cache-Control": "no-store"
383
- }).send(
293
+ console.error("Logging error in @webiny/handler");
294
+ try {
295
+ console.error((0, _stringifyError.stringifyError)(error));
296
+ } catch (ex) {
297
+ console.warn("Could not stringify error:");
298
+ console.log(error);
299
+ console.error("Stringify error:", ex);
300
+ }
384
301
  /**
385
- * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.
302
+ * IMPORTANT! Do not send anything if reply was already sent.
386
303
  */
387
- JSON.stringify({
388
- message: error.message,
389
- code: error.code,
390
- data: error.data
391
- }));
392
- const handler = (0, _middleware.middleware)(plugins.map(pl => {
304
+ if (!reply.sent) {
305
+ reply.status(500).headers({
306
+ "Cache-Control": "no-store"
307
+ }).send(
308
+ /**
309
+ * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.
310
+ */
311
+ JSON.stringify({
312
+ message: error.message,
313
+ code: error.code,
314
+ data: error.data
315
+ }));
316
+ } else {
317
+ console.warn("Reply already sent, cannot send the result (handler:addHook:onError).");
318
+ }
319
+ const handler = (0, _utils.middleware)(plugins.map(pl => {
393
320
  return (context, error, next) => {
394
321
  return pl.handle(context, error, next);
395
322
  };
@@ -397,13 +324,31 @@ const createHandler = params => {
397
324
  await handler(app.webiny, error);
398
325
  return reply;
399
326
  });
327
+
328
+ /**
329
+ * Apply response headers modifier plugins.
330
+ */
331
+ app.addHook("onSend", async (request, reply, input) => {
332
+ modifyResponseHeaders(app, request, reply);
333
+ const plugins = app.webiny.plugins.byType(_OnRequestResponseSendPlugin.OnRequestResponseSendPlugin.type);
334
+ let payload = input;
335
+ for (const plugin of plugins) {
336
+ payload = await plugin.exec(request, reply, payload);
337
+ }
338
+ return payload;
339
+ });
340
+
400
341
  /**
401
342
  * We need to output the benchmark results at the end of the request in both response and timeout cases
402
343
  */
403
344
  app.addHook("onResponse", async () => {
404
345
  await context.benchmark.output();
405
346
  });
406
- app.addHook("onTimeout", async () => {
347
+ app.addHook("onTimeout", async (request, reply) => {
348
+ const plugins = app.webiny.plugins.byType(_OnRequestTimeoutPlugin.OnRequestTimeoutPlugin.type);
349
+ for (const plugin of plugins) {
350
+ await plugin.exec(request, reply);
351
+ }
407
352
  await context.benchmark.output();
408
353
  });
409
354
 
@@ -419,9 +364,38 @@ const createHandler = params => {
419
364
  }
420
365
  } catch (ex) {
421
366
  console.error(`Error while running the "ModifyFastifyPlugin" ${modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : ""} plugin in the end of the "createHandler" callable.`);
422
- console.error(stringifyError(ex));
367
+ console.error((0, _stringifyError.stringifyError)(ex));
368
+ throw ex;
369
+ }
370
+
371
+ /**
372
+ * We have few types of triggers:
373
+ * * Events - EventPlugin
374
+ * * Routes - RoutePlugin
375
+ *
376
+ * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
377
+ */
378
+ const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
379
+
380
+ /**
381
+ * Add routes to the system.
382
+ */
383
+ let routePluginName;
384
+ try {
385
+ for (const plugin of routePlugins) {
386
+ routePluginName = plugin.name;
387
+ plugin.cb({
388
+ ...app.webiny.routes,
389
+ context: app.webiny
390
+ });
391
+ }
392
+ } catch (ex) {
393
+ console.error(`Error while running the "RoutePlugin" ${routePluginName ? `(${routePluginName})` : ""} plugin in the beginning of the "createHandler" callable.`);
394
+ console.error((0, _stringifyError.stringifyError)(ex));
423
395
  throw ex;
424
396
  }
425
397
  return app;
426
398
  };
427
- exports.createHandler = createHandler;
399
+ exports.createHandler = createHandler;
400
+
401
+ //# sourceMappingURL=fastify.js.map
package/fastify.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","stringifyError","error","name","message","code","stack","data","JSON","stringify","constructorName","constructor","process","env","DEBUG","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","find","includes","console","WebinyError","override","addDefinedRoute","push","app","fastify","addHook","route","method","m","register","fastifyCookie","parseOptions","fastifyCompress","global","threshold","onUnsupportedEncoding","encoding","_","reply","inflateIfDeflated","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","server","ex","decorate","routePlugins","webiny","byType","RoutePlugin","routePluginName","plugin","cb","request","defaultHeaders","headers","HandlerOnRequestPlugin","result","exec","sent","explanation","send","hijack","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","__","payload","HandlerResultPlugin","handle","setErrorHandler","status","HandlerErrorPlugin","middleware","map","pl","next","benchmark","output","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","modify"],"sources":["fastify.ts"],"sourcesContent":["import { PluginCollection } from \"@webiny/plugins/types\";\nimport fastify, {\n FastifyServerOptions as ServerOptions,\n preSerializationAsyncHookHandler\n} from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ContextRoutes, DefinedContextRoutes, RouteMethodOptions, HTTPMethods } 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 { middleware } from \"~/middleware\";\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\";\n\nconst DEFAULT_HEADERS: Record<string, string> = {\n \"Cache-Control\": \"no-store\",\n \"Content-Type\": \"application/json; charset=utf-8\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"*\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET,DELETE,PUT,PATCH\",\n ...getWebinyVersionHeaders()\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): Record<string, string> => {\n /**\n * If we are accepting all headers, just output that one.\n */\n const keys = Object.keys(routes) as HTTPMethods[];\n const all = keys.every(key => routes[key].length > 0);\n if (all) {\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": \"*\"\n };\n }\n return {\n ...DEFAULT_HEADERS,\n \"Access-Control-Allow-Methods\": keys\n .filter(type => {\n if (!routes[type] || Array.isArray(routes[type]) === false) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\")\n };\n};\n\nconst stringifyError = (error: Error) => {\n const { name, message, code, stack, data } = error as any;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n\nconst OPTIONS_HEADERS: Record<string, string> = {\n \"Access-Control-Max-Age\": \"86400\",\n \"Cache-Control\": \"public, max-age=86400\"\n};\n\nexport interface CreateHandlerParams {\n plugins: PluginCollection;\n options?: ServerOptions;\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 * We must attach the server to our internal context if we want to have it accessible.\n */\n const app = fastify({\n ...(params.options || {})\n });\n /**\n * We need to register routes in our system so we can output headers later on and dissallow overriding routes.\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 try {\n context = new Context({\n plugins: [\n /**\n * We must have handlerClient by default.\n * And it must be one of the first context plugins applied.\n */\n createHandlerClient(),\n ...(params.plugins || [])\n ],\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string,\n server: app,\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 * 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 /**\n * On every request we add default headers, which can be changed later.\n * Also, if it is an options request, we skip everything after this hook and output options headers.\n */\n app.addHook(\"onRequest\", async (request, reply) => {\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n /**\n * Users can define their own custom handlers for the onRequest event - so let's run them first.\n */\n const plugins = app.webiny.plugins.byType<HandlerOnRequestPlugin>(\n HandlerOnRequestPlugin.type\n );\n\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply);\n if (result === false) {\n return;\n }\n }\n } catch (ex) {\n console.error(\n `Error while running the \"HandlerOnRequestPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the onRequest hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n /**\n * When we receive the OPTIONS request, we end it before it goes any further as there is no need for anything to run after this - at least for our use cases.\n *\n * Users can prevent this by creating their own HandlerOnRequestPlugin and returning false as the result of the callable.\n */\n if (request.method !== \"OPTIONS\") {\n return;\n }\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;\n }\n\n reply\n .headers({ ...defaultHeaders, ...OPTIONS_HEADERS })\n .code(204)\n .send(\"\")\n .hijack();\n });\n\n app.addHook(\"preParsing\", async (request, reply) => {\n app.webiny.request = request;\n app.webiny.reply = reply;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ContextPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preParsing hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n let name: string | undefined;\n try {\n for (const plugin of plugins) {\n name = plugin.name;\n await plugin.apply(app.webiny);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"BeforeHandlerPlugin\" ${\n name ? `(${name})` : \"\"\n } plugin in the preHandler hook.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = 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.addHook(\"preSerialization\", preSerialization);\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 (_, 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.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: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\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 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 return app;\n};\n"],"mappings":";;;;;;;;AACA;AAIA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,eAAuC;EACzC,eAAe,EAAE,UAAU;EAC3B,cAAc,EAAE,iCAAiC;EACjD,6BAA6B,EAAE,GAAG;EAClC,8BAA8B,EAAE,GAAG;EACnC,8BAA8B,EAAE;AAAmC,GAChE,IAAAC,8BAAuB,GAAE,CAC/B;AAED,MAAMC,iBAAiB,GAAIC,MAA4B,IAA6B;EAChF;AACJ;AACA;EACI,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACD,MAAM,CAAkB;EACjD,MAAMG,GAAG,GAAGF,IAAI,CAACG,KAAK,CAACC,GAAG,IAAIL,MAAM,CAACK,GAAG,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;EACrD,IAAIH,GAAG,EAAE;IACL,mEACON,eAAe;MAClB,8BAA8B,EAAE;IAAG;EAE3C;EACA,mEACOA,eAAe;IAClB,8BAA8B,EAAEI,IAAI,CAC/BM,MAAM,CAACC,IAAI,IAAI;MACZ,IAAI,CAACR,MAAM,CAACQ,IAAI,CAAC,IAA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AAMrD,OAAO,CAACnB,GAAG,CAAC0C,MAAM,EAAErF,KAAK,CAAC;IAEhC,OAAO0D,KAAK;EAChB,CAAC,CAAC;EACF;AACJ;AACA;EACIf,GAAG,CAACE,OAAO,CAAC,YAAY,EAAE,YAAY;IAClC,MAAM+B,OAAO,CAACwC,SAAS,CAACC,MAAM,EAAE;EACpC,CAAC,CAAC;EACF1E,GAAG,CAACE,OAAO,CAAC,WAAW,EAAE,YAAY;IACjC,MAAM+B,OAAO,CAACwC,SAAS,CAACC,MAAM,EAAE;EACpC,CAAC,CAAC;;EAEF;AACJ;AACA;EACI,MAAMC,aAAa,GAAG3E,GAAG,CAAC0C,MAAM,CAACP,OAAO,CAACQ,MAAM,CAAsBiC,wCAAmB,CAAC7H,IAAI,CAAC;EAE9F,IAAI8H,uBAA2C;EAC/C,IAAI;IACA,KAAK,MAAM/B,MAAM,IAAI6B,aAAa,EAAE;MAChCE,uBAAuB,GAAG/B,MAAM,CAACxF,IAAI;MACrCwF,MAAM,CAACgC,MAAM,CAAC9E,GAAG,CAAC;IACtB;EACJ,CAAC,CAAC,OAAOuC,EAAE,EAAE;IACT5C,OAAO,CAACtC,KAAK,CACR,iDACGwH,uBAAuB,GAAI,IAAGA,uBAAwB,GAAE,GAAG,EAC9D,qDAAoD,CACxD;IACDlF,OAAO,CAACtC,KAAK,CAACD,cAAc,CAACmF,EAAE,CAAC,CAAC;IACjC,MAAMA,EAAE;EACZ;EAEA,OAAOvC,GAAG;AACd,CAAC;AAAC"}
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","_OnRequestTimeoutPlugin","_OnRequestResponseSendPlugin","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","OnRequestResponseSendPlugin","exec","benchmark","output","OnRequestTimeoutPlugin","modifyPlugins","ModifyFastifyPlugin","modifyFastifyPluginName","routePlugins","RoutePlugin","routePluginName","cb","exports"],"sources":["fastify.ts"],"sourcesContent":["import type { PluginCollection } from \"@webiny/plugins/types\";\nimport { PluginsContainer } from \"@webiny/plugins/types\";\nimport type { FastifyInstance, FastifyServerOptions as ServerOptions } from \"fastify\";\nimport fastify from \"fastify\";\nimport type { MiddlewareCallable } from \"@webiny/utils\";\nimport { middleware } from \"@webiny/utils\";\nimport type {\n ContextRoutes,\n DefinedContextRoutes,\n HTTPMethods,\n 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 type { StandardHeaders } from \"~/ResponseHeaders\";\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\";\nimport { OnRequestTimeoutPlugin } from \"~/plugins/OnRequestTimeoutPlugin.js\";\nimport { OnRequestResponseSendPlugin } from \"~/plugins/OnRequestResponseSendPlugin.js\";\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, 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 return reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n });\n\n app.addHook(\"onError\", async (_, reply, error: any) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n /**\n * Log error to cloud, as these can be extremely annoying to debug!\n */\n console.error(\"Logging error in @webiny/handler\");\n try {\n console.error(stringifyError(error));\n } catch (ex) {\n console.warn(\"Could not stringify error:\");\n console.log(error);\n console.error(\"Stringify error:\", ex);\n }\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (!reply.sent) {\n reply\n .status(500)\n .headers({\n \"Cache-Control\": \"no-store\"\n })\n .send(\n /**\n * When we are sending the error in the response, we cannot send the whole error object, as it might contain some sensitive data.\n */\n JSON.stringify({\n message: error.message,\n code: error.code,\n data: error.data\n })\n );\n } else {\n console.warn(\"Reply already sent, cannot send the result (handler:addHook:onError).\");\n }\n\n const handler = middleware(\n plugins.map(pl => {\n return (context: Context, error: Error, next: MiddlewareCallable) => {\n return pl.handle(context, error, next);\n };\n })\n );\n await handler(app.webiny, error);\n\n return reply;\n });\n\n /**\n * Apply response headers modifier plugins.\n */\n app.addHook(\"onSend\", async (request, reply, input) => {\n modifyResponseHeaders(app, request, reply);\n const plugins = app.webiny.plugins.byType<OnRequestResponseSendPlugin>(\n OnRequestResponseSendPlugin.type\n );\n let payload = input;\n for (const plugin of plugins) {\n payload = await plugin.exec(request, reply, payload);\n }\n return payload;\n });\n\n /**\n * We need to output the benchmark results at the end of the request in both response and timeout cases\n */\n app.addHook(\"onResponse\", async () => {\n await context.benchmark.output();\n });\n\n app.addHook(\"onTimeout\", async (request, reply) => {\n const plugins = app.webiny.plugins.byType<OnRequestTimeoutPlugin>(\n OnRequestTimeoutPlugin.type\n );\n for (const plugin of plugins) {\n await plugin.exec(request, reply);\n }\n await context.benchmark.output();\n });\n\n /**\n * With these plugins we give users possibility to do anything they want on our fastify instance.\n */\n const modifyPlugins = app.webiny.plugins.byType<ModifyFastifyPlugin>(ModifyFastifyPlugin.type);\n\n let modifyFastifyPluginName: string | undefined;\n try {\n for (const plugin of modifyPlugins) {\n modifyFastifyPluginName = plugin.name;\n plugin.modify(app);\n }\n } catch (ex) {\n console.error(\n `Error while running the \"ModifyFastifyPlugin\" ${\n modifyFastifyPluginName ? `(${modifyFastifyPluginName})` : \"\"\n } plugin in the end of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n /**\n * We have few types of triggers:\n * * Events - EventPlugin\n * * Routes - RoutePlugin\n *\n * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.\n */\n const routePlugins = app.webiny.plugins.byType<RoutePlugin>(RoutePlugin.type);\n\n /**\n * Add routes to the system.\n */\n let routePluginName: string | undefined;\n try {\n for (const plugin of routePlugins) {\n routePluginName = plugin.name;\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\n }\n } catch (ex) {\n console.error(\n `Error while running the \"RoutePlugin\" ${\n routePluginName ? `(${routePluginName})` : \"\"\n } plugin in the beginning of the \"createHandler\" callable.`\n );\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return app;\n};\n"],"mappings":";;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,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;AAEA,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,GAAA1B,OAAA;AACA,IAAA2B,uBAAA,GAAA3B,OAAA;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