@webiny/handler 0.0.0-unstable.5e7233243f → 0.0.0-unstable.6e5425ee89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Context.js CHANGED
@@ -1,19 +1,17 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.Context = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _api = require("@webiny/api");
13
-
14
10
  class Context extends _api.Context {
15
11
  // @ts-ignore
12
+
16
13
  // @ts-ignore
14
+
17
15
  constructor(params) {
18
16
  super(params);
19
17
  (0, _defineProperty2.default)(this, "server", void 0);
@@ -23,7 +21,5 @@ class Context extends _api.Context {
23
21
  this.server = params.server;
24
22
  this.routes = params.routes;
25
23
  }
26
-
27
24
  }
28
-
29
25
  exports.Context = Context;
package/Context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Context","BaseContext","constructor","params","server","routes"],"sources":["Context.ts"],"sourcesContent":["import { Context as BaseContext, ContextParams as BaseContextParams } from \"@webiny/api\";\nimport { Context as BaseContextType } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n server: BaseContextType[\"server\"];\n routes: BaseContextType[\"routes\"];\n}\n\nexport class Context extends BaseContext implements BaseContextType {\n public readonly server: BaseContextType[\"server\"];\n public readonly routes: BaseContextType[\"routes\"];\n // @ts-ignore\n public handlerClient: BaseContextType[\"handlerClient\"];\n // @ts-ignore\n public request: BaseContextType[\"request\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\n this.routes = params.routes;\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAQO,MAAMA,OAAN,SAAsBC,YAAtB,CAA6D;EAGhE;EAEA;EAGOC,WAAW,CAACC,MAAD,EAAwB;IACtC,MAAMA,MAAN;IADsC;IAAA;IAAA;IAAA;IAEtC,KAAKC,MAAL,GAAcD,MAAM,CAACC,MAArB;IACA,KAAKC,MAAL,GAAcF,MAAM,CAACE,MAArB;EACH;;AAZ+D"}
1
+ {"version":3,"names":["Context","BaseContext","constructor","params","server","routes"],"sources":["Context.ts"],"sourcesContent":["import { Context as BaseContext, ContextParams as BaseContextParams } from \"@webiny/api\";\nimport { Context as BaseContextType } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n server: BaseContextType[\"server\"];\n routes: BaseContextType[\"routes\"];\n}\n\nexport class Context extends BaseContext implements BaseContextType {\n public readonly server: BaseContextType[\"server\"];\n public readonly routes: BaseContextType[\"routes\"];\n // @ts-ignore\n public handlerClient: BaseContextType[\"handlerClient\"];\n // @ts-ignore\n public request: BaseContextType[\"request\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\n this.routes = params.routes;\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAQO,MAAMA,OAAO,SAASC,YAAW,CAA4B;EAGhE;;EAEA;;EAGOC,WAAW,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IAAC;IAAA;IAAA;IAAA;IACd,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC/B;AACJ;AAAC"}
package/fastify.d.ts CHANGED
@@ -5,4 +5,4 @@ export interface CreateHandlerParams {
5
5
  plugins: PluginCollection;
6
6
  options?: ServerOptions;
7
7
  }
8
- export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance, import("fastify").FastifyTypeProviderDefault>>;
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>>;
package/fastify.js CHANGED
@@ -1,81 +1,55 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createHandler = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _fastify = _interopRequireDefault(require("fastify"));
13
-
14
10
  var _utils = require("@webiny/utils");
15
-
16
11
  var _Context = require("./Context");
17
-
18
12
  var _error = _interopRequireDefault(require("@webiny/error"));
19
-
20
13
  var _RoutePlugin = require("./plugins/RoutePlugin");
21
-
22
14
  var _handlerClient = require("@webiny/handler-client");
23
-
24
15
  var _cookie = _interopRequireDefault(require("@fastify/cookie"));
25
-
26
16
  var _middleware = require("./middleware");
27
-
28
17
  var _api = require("@webiny/api");
29
-
30
18
  var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
31
-
32
19
  var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
33
-
34
20
  var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
35
-
36
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
37
-
38
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
39
-
40
- const DEFAULT_HEADERS = _objectSpread({
21
+ const DEFAULT_HEADERS = (0, _objectSpread2.default)({
41
22
  "Cache-Control": "no-store",
42
23
  "Content-Type": "application/json; charset=utf-8",
43
24
  "Access-Control-Allow-Origin": "*",
44
25
  "Access-Control-Allow-Headers": "*",
45
26
  "Access-Control-Allow-Methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH"
46
27
  }, (0, _utils.getWebinyVersionHeaders)());
47
-
48
28
  const getDefaultHeaders = routes => {
49
29
  /**
50
30
  * If we are accepting all headers, just output that one.
51
31
  */
52
32
  const keys = Object.keys(routes);
53
33
  const all = keys.every(key => routes[key].length > 0);
54
-
55
34
  if (all) {
56
- return _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
35
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
57
36
  "Access-Control-Allow-Methods": "*"
58
37
  });
59
38
  }
60
-
61
- return _objectSpread(_objectSpread({}, DEFAULT_HEADERS), {}, {
39
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, DEFAULT_HEADERS), {}, {
62
40
  "Access-Control-Allow-Methods": keys.filter(key => {
63
41
  const type = key;
64
-
65
42
  if (!routes[type] || Array.isArray(routes[type]) === false) {
66
43
  return false;
67
44
  }
68
-
69
45
  return routes[type].length > 0;
70
46
  }).sort().join(",")
71
47
  });
72
48
  };
73
-
74
49
  const OPTIONS_HEADERS = {
75
50
  "Access-Control-Max-Age": "86400",
76
51
  "Cache-Control": "public, max-age=86400"
77
52
  };
78
-
79
53
  const createHandler = params => {
80
54
  const definedRoutes = {
81
55
  POST: [],
@@ -84,20 +58,26 @@ const createHandler = params => {
84
58
  DELETE: [],
85
59
  PATCH: [],
86
60
  PUT: [],
87
- HEAD: []
61
+ HEAD: [],
62
+ COPY: [],
63
+ LOCK: [],
64
+ MKCOL: [],
65
+ MOVE: [],
66
+ PROPFIND: [],
67
+ PROPPATCH: [],
68
+ SEARCH: [],
69
+ TRACE: [],
70
+ UNLOCK: []
88
71
  };
89
-
90
72
  const throwOnDefinedRoute = (type, path, options) => {
91
73
  if (type === "ALL") {
92
74
  const all = Object.keys(definedRoutes).some(key => {
93
75
  const routes = definedRoutes[key];
94
76
  return routes.includes(path);
95
77
  });
96
-
97
78
  if (!all) {
98
79
  return;
99
80
  }
100
-
101
81
  throw new _error.default(`You cannot override a route with onAll() method, please remove unnecessary route from the system.`, "OVERRIDE_ROUTE_ERROR", {
102
82
  type,
103
83
  path
@@ -107,59 +87,46 @@ const createHandler = params => {
107
87
  } else if ((options === null || options === void 0 ? void 0 : options.override) === true) {
108
88
  return;
109
89
  }
110
-
111
90
  throw new _error.default(`When you are trying to override existing route, you must send "override" parameter when adding that route.`, "OVERRIDE_ROUTE_ERROR", {
112
91
  type,
113
92
  path
114
93
  });
115
94
  };
116
-
117
95
  const addDefinedRoute = (inputType, path) => {
118
96
  const type = inputType.toUpperCase();
119
-
120
97
  if (!definedRoutes[type]) {
121
98
  return;
122
99
  } else if (definedRoutes[type].includes(path)) {
123
100
  return;
124
101
  }
125
-
126
102
  definedRoutes[type].push(path);
127
103
  };
128
104
  /**
129
105
  * We must attach the server to our internal context if we want to have it accessible.
130
106
  */
131
-
132
-
133
- const app = (0, _fastify.default)(_objectSpread({}, params.options || {}));
107
+ const app = (0, _fastify.default)((0, _objectSpread2.default)({}, params.options || {}));
134
108
  /**
135
109
  * We need to register routes in our system so we can output headers later on and dissallow overriding routes.
136
110
  */
137
-
138
111
  app.addHook("onRoute", route => {
139
112
  const method = route.method;
140
-
141
113
  if (Array.isArray(method)) {
142
114
  for (const m of method) {
143
115
  addDefinedRoute(m, route.path);
144
116
  }
145
-
146
117
  return;
147
118
  }
148
-
149
119
  addDefinedRoute(method, route.path);
150
120
  });
151
121
  /**
152
122
  *
153
123
  */
154
-
155
124
  app.register(_cookie.default, {
156
125
  parseOptions: {} // options for parsing cookies
157
-
158
126
  });
159
127
  /**
160
128
  * Route helpers - mostly for users.
161
129
  */
162
-
163
130
  const routes = {
164
131
  defined: definedRoutes,
165
132
  onPost: (path, handler, options) => {
@@ -202,7 +169,6 @@ const createHandler = params => {
202
169
  * And it must be one of the first context plugins applied.
203
170
  */
204
171
  (0, _handlerClient.createHandlerClient)(), ...(params.plugins || [])],
205
-
206
172
  /**
207
173
  * Inserted via webpack on build time.
208
174
  */
@@ -213,8 +179,8 @@ const createHandler = params => {
213
179
  /**
214
180
  * We are attaching our custom context to webiny variable on the fastify app so it is accessible everywhere
215
181
  */
216
-
217
182
  app.decorate("webiny", context);
183
+
218
184
  /**
219
185
  * We have few types of triggers:
220
186
  * * Events - EventPlugin
@@ -222,45 +188,37 @@ const createHandler = params => {
222
188
  *
223
189
  * Routes are registered in fastify but events must be handled in package which implements cloud specific methods.
224
190
  */
225
-
226
191
  const routePlugins = app.webiny.plugins.byType(_RoutePlugin.RoutePlugin.type);
192
+
227
193
  /**
228
194
  * Add routes to the system.
229
195
  */
230
-
231
196
  for (const plugin of routePlugins) {
232
- plugin.cb(_objectSpread(_objectSpread({}, app.webiny.routes), {}, {
197
+ plugin.cb((0, _objectSpread2.default)((0, _objectSpread2.default)({}, app.webiny.routes), {}, {
233
198
  context: app.webiny
234
199
  }));
235
200
  }
201
+
236
202
  /**
237
203
  * On every request we add default headers, which can be changed later.
238
204
  * Also, if it is an options request, we skip everything after this hook and output options headers.
239
205
  */
240
-
241
-
242
206
  app.addHook("onRequest", async (request, reply) => {
243
207
  const defaultHeaders = getDefaultHeaders(definedRoutes);
244
208
  reply.headers(defaultHeaders);
245
-
246
209
  if (request.method !== "OPTIONS") {
247
210
  return;
248
211
  }
249
-
250
212
  const raw = reply.code(204).hijack().raw;
251
-
252
- const headers = _objectSpread(_objectSpread({}, defaultHeaders), OPTIONS_HEADERS);
253
-
213
+ const headers = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, defaultHeaders), OPTIONS_HEADERS);
254
214
  for (const key in headers) {
255
215
  raw.setHeader(key, headers[key]);
256
216
  }
257
-
258
217
  raw.end("");
259
218
  });
260
219
  app.addHook("preParsing", async request => {
261
220
  app.webiny.request = request;
262
221
  const plugins = app.webiny.plugins.byType(_api.ContextPlugin.type);
263
-
264
222
  for (const plugin of plugins) {
265
223
  await plugin.apply(app.webiny);
266
224
  }
@@ -268,34 +226,29 @@ const createHandler = params => {
268
226
  /**
269
227
  *
270
228
  */
271
-
272
229
  app.addHook("preHandler", async () => {
273
230
  const plugins = app.webiny.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
274
-
275
231
  for (const plugin of plugins) {
276
232
  await plugin.apply(app.webiny);
277
233
  }
278
234
  });
235
+
279
236
  /**
280
237
  *
281
238
  */
282
-
283
239
  const preSerialization = async (_, __, payload) => {
284
240
  const plugins = app.webiny.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
285
-
286
241
  for (const plugin of plugins) {
287
242
  await plugin.handle(app.webiny, payload);
288
243
  }
289
-
290
244
  return payload;
291
245
  };
292
-
293
246
  app.addHook("preSerialization", preSerialization);
294
247
  app.addHook("onError", async (_, reply, error) => {
295
- const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type); // Log error to cloud, as these can be extremely annoying to debug!
296
-
248
+ const plugins = app.webiny.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
249
+ // Log error to cloud, as these can be extremely annoying to debug!
297
250
  console.log("@webiny/handler");
298
- console.log(JSON.stringify(_objectSpread(_objectSpread({}, error || {}), {}, {
251
+ console.log(JSON.stringify((0, _objectSpread2.default)((0, _objectSpread2.default)({}, error || {}), {}, {
299
252
  message: error === null || error === void 0 ? void 0 : error.message,
300
253
  code: error === null || error === void 0 ? void 0 : error.code
301
254
  })));
@@ -311,5 +264,4 @@ const createHandler = params => {
311
264
  });
312
265
  return app;
313
266
  };
314
-
315
267
  exports.createHandler = createHandler;
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","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","throwOnDefinedRoute","path","options","some","includes","WebinyError","override","addDefinedRoute","inputType","toUpperCase","push","app","fastify","addHook","route","method","m","register","fastifyCookies","parseOptions","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","process","env","server","decorate","routePlugins","webiny","byType","RoutePlugin","plugin","cb","request","reply","defaultHeaders","headers","raw","code","hijack","setHeader","end","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","_","__","payload","HandlerResultPlugin","handle","error","HandlerErrorPlugin","console","log","JSON","stringify","message","middleware","map","pl","next","status"],"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, RouteTypes } from \"~/types\";\nimport { Context } from \"~/Context\";\nimport WebinyError from \"@webiny/error\";\nimport { RoutePlugin } from \"./plugins/RoutePlugin\";\nimport { createHandlerClient } from \"@webiny/handler-client\";\nimport fastifyCookies from \"@fastify/cookie\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\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);\n const all = keys.every(key => routes[key as RouteTypes].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(key => {\n const type = key as unknown as RouteTypes;\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 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: ContextRoutes[\"defined\"] = {\n POST: [],\n GET: [],\n OPTIONS: [],\n DELETE: [],\n PATCH: [],\n PUT: [],\n HEAD: []\n };\n\n const throwOnDefinedRoute = (\n type: RouteTypes | \"ALL\",\n path: string,\n options?: RouteMethodOptions\n ): void => {\n if (type === \"ALL\") {\n const all = Object.keys(definedRoutes).some(key => {\n const routes = definedRoutes[key as RouteTypes];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\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 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 = (inputType: RouteTypes, path: string): void => {\n const type = (inputType as string).toUpperCase() as RouteTypes;\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 */\n app.register(fastifyCookies, {\n parseOptions: {} // options for parsing cookies\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 const 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 /**\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 for (const plugin of routePlugins) {\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\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 const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n if (request.method !== \"OPTIONS\") {\n return;\n }\n const raw = reply.code(204).hijack().raw;\n const headers = { ...defaultHeaders, ...OPTIONS_HEADERS };\n for (const key in headers) {\n raw.setHeader(key, headers[key]);\n }\n\n raw.end(\"\");\n });\n\n app.addHook(\"preParsing\", async request => {\n app.webiny.request = request;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n for (const plugin of plugins) {\n await plugin.handle(app.webiny, payload);\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.addHook(\"onError\", async (_, reply, error) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n // Log error to cloud, as these can be extremely annoying to debug!\n console.log(\"@webiny/handler\");\n console.log(\n JSON.stringify({\n ...(error || {}),\n message: error?.message,\n code: error?.code\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 .headers({\n \"Cache-Control\": \"no-store\"\n })\n .status(500);\n });\n\n return app;\n};\n"],"mappings":";;;;;;;;;;;AACA;;AAIA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,eAAuC;EACzC,iBAAiB,UADwB;EAEzC,gBAAgB,iCAFyB;EAGzC,+BAA+B,GAHU;EAIzC,gCAAgC,GAJS;EAKzC,gCAAgC;AALS,GAMtC,IAAAC,8BAAA,GANsC,CAA7C;;AASA,MAAMC,iBAAiB,GAAIC,MAAD,IAA0D;EAChF;AACJ;AACA;EACI,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAYD,MAAZ,CAAb;EACA,MAAMG,GAAG,GAAGF,IAAI,CAACG,KAAL,CAAWC,GAAG,IAAIL,MAAM,CAACK,GAAD,CAAN,CAA0BC,MAA1B,GAAmC,CAArD,CAAZ;;EACA,IAAIH,GAAJ,EAAS;IACL,uCACON,eADP;MAEI,gCAAgC;IAFpC;EAIH;;EACD,uCACOA,eADP;IAEI,gCAAgCI,IAAI,CAC/BM,MAD2B,CACpBF,GAAG,IAAI;MACX,MAAMG,IAAI,GAAGH,GAAb;;MACA,IAAI,CAACL,MAAM,CAACQ,IAAD,CAAP,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E,CAIK,GAJL,CAAP;EAKH,CAzBD;EA2BA,OAAOrE,GAAP;AACH,CA5OM"}
1
+ {"version":3,"names":["DEFAULT_HEADERS","getWebinyVersionHeaders","getDefaultHeaders","routes","keys","Object","all","every","key","length","filter","type","Array","isArray","sort","join","OPTIONS_HEADERS","createHandler","params","definedRoutes","POST","GET","OPTIONS","DELETE","PATCH","PUT","HEAD","COPY","LOCK","MKCOL","MOVE","PROPFIND","PROPPATCH","SEARCH","TRACE","UNLOCK","throwOnDefinedRoute","path","options","some","includes","WebinyError","override","addDefinedRoute","inputType","toUpperCase","push","app","fastify","addHook","route","method","m","register","fastifyCookies","parseOptions","defined","onPost","handler","post","onGet","get","onOptions","onDelete","delete","onPatch","patch","onPut","put","onAll","onHead","head","context","Context","plugins","createHandlerClient","WEBINY_VERSION","process","env","server","decorate","routePlugins","webiny","byType","RoutePlugin","plugin","cb","request","reply","defaultHeaders","headers","raw","code","hijack","setHeader","end","ContextPlugin","apply","BeforeHandlerPlugin","preSerialization","_","__","payload","HandlerResultPlugin","handle","error","HandlerErrorPlugin","console","log","JSON","stringify","message","middleware","map","pl","next","status"],"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 fastifyCookies from \"@fastify/cookie\";\nimport { middleware } from \"~/middleware\";\nimport { ContextPlugin } from \"@webiny/api\";\nimport { BeforeHandlerPlugin } from \"./plugins/BeforeHandlerPlugin\";\nimport { HandlerResultPlugin } from \"./plugins/HandlerResultPlugin\";\nimport { HandlerErrorPlugin } from \"./plugins/HandlerErrorPlugin\";\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);\n const all = keys.every(key => routes[key as HTTPMethods].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(key => {\n const type = key as unknown as HTTPMethods;\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 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).some(key => {\n const routes = definedRoutes[key as HTTPMethods];\n return routes.includes(path);\n });\n if (!all) {\n return;\n }\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 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 = (inputType: HTTPMethods, path: string): void => {\n const type = (inputType as string).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 * 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 */\n app.register(fastifyCookies, {\n parseOptions: {} // options for parsing cookies\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 const 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 /**\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 for (const plugin of routePlugins) {\n plugin.cb({\n ...app.webiny.routes,\n context: app.webiny\n });\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 const defaultHeaders = getDefaultHeaders(definedRoutes);\n reply.headers(defaultHeaders);\n if (request.method !== \"OPTIONS\") {\n return;\n }\n const raw = reply.code(204).hijack().raw;\n const headers = { ...defaultHeaders, ...OPTIONS_HEADERS };\n for (const key in headers) {\n raw.setHeader(key, headers[key]);\n }\n\n raw.end(\"\");\n });\n\n app.addHook(\"preParsing\", async request => {\n app.webiny.request = request;\n const plugins = app.webiny.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n /**\n *\n */\n app.addHook(\"preHandler\", async () => {\n const plugins = app.webiny.plugins.byType<BeforeHandlerPlugin>(BeforeHandlerPlugin.type);\n for (const plugin of plugins) {\n await plugin.apply(app.webiny);\n }\n });\n\n /**\n *\n */\n const preSerialization: preSerializationAsyncHookHandler<any> = async (_, __, payload) => {\n const plugins = app.webiny.plugins.byType<HandlerResultPlugin>(HandlerResultPlugin.type);\n for (const plugin of plugins) {\n await plugin.handle(app.webiny, payload);\n }\n return payload;\n };\n\n app.addHook(\"preSerialization\", preSerialization);\n\n app.addHook(\"onError\", async (_, reply, error) => {\n const plugins = app.webiny.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n // Log error to cloud, as these can be extremely annoying to debug!\n console.log(\"@webiny/handler\");\n console.log(\n JSON.stringify({\n ...(error || {}),\n message: error?.message,\n code: error?.code\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 .headers({\n \"Cache-Control\": \"no-store\"\n })\n .status(500);\n });\n\n return app;\n};\n"],"mappings":";;;;;;;;AACA;AAIA;AAEA;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,CAAC;EAChC,MAAMG,GAAG,GAAGF,IAAI,CAACG,KAAK,CAACC,GAAG,IAAIL,MAAM,CAACK,GAAG,CAAgB,CAACC,MAAM,GAAG,CAAC,CAAC;EACpE,IAAIH,GAAG,EAAE;IACL,mEACON,eAAe;MAClB,8BAA8B,EAAE;IAAG;EAE3C;EACA,mEACOA,eAAe;IAClB,8BAA8B,EAAEI,IAAI,CAC/BM,MAAM,CAACF,GAAG,IAAI;MACX,MAAMG,IAAI,GAAGH,GAA6B;MAC1C,IAAI,CAACL,MAAM,CAACQ,IAAI,CAAC,IAAIC,KAAK,CAACC,OAAO,CAACV,MAAM,CAACQ,IAAI,CAAC,CAAC,KAA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Ae,EAAE;IACrB,CAAC,CAAC,CACD0B,MAAM,CAAC,GAAG,CAAC;EACpB,CAAC,CAAC;EAEF,OAAOrE,GAAG;AACd,CAAC;AAAC"}
package/index.js CHANGED
@@ -3,9 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  var _fastify = require("./fastify");
8
-
9
7
  Object.keys(_fastify).forEach(function (key) {
10
8
  if (key === "default" || key === "__esModule") return;
11
9
  if (key in exports && exports[key] === _fastify[key]) return;
@@ -16,9 +14,7 @@ Object.keys(_fastify).forEach(function (key) {
16
14
  }
17
15
  });
18
16
  });
19
-
20
17
  var _ContextPlugin = require("@webiny/api/plugins/ContextPlugin");
21
-
22
18
  Object.keys(_ContextPlugin).forEach(function (key) {
23
19
  if (key === "default" || key === "__esModule") return;
24
20
  if (key in exports && exports[key] === _ContextPlugin[key]) return;
@@ -29,9 +25,7 @@ Object.keys(_ContextPlugin).forEach(function (key) {
29
25
  }
30
26
  });
31
27
  });
32
-
33
28
  var _Context = require("./Context");
34
-
35
29
  Object.keys(_Context).forEach(function (key) {
36
30
  if (key === "default" || key === "__esModule") return;
37
31
  if (key in exports && exports[key] === _Context[key]) return;
@@ -42,9 +36,7 @@ Object.keys(_Context).forEach(function (key) {
42
36
  }
43
37
  });
44
38
  });
45
-
46
39
  var _EventPlugin = require("./plugins/EventPlugin");
47
-
48
40
  Object.keys(_EventPlugin).forEach(function (key) {
49
41
  if (key === "default" || key === "__esModule") return;
50
42
  if (key in exports && exports[key] === _EventPlugin[key]) return;
@@ -55,9 +47,7 @@ Object.keys(_EventPlugin).forEach(function (key) {
55
47
  }
56
48
  });
57
49
  });
58
-
59
50
  var _RoutePlugin = require("./plugins/RoutePlugin");
60
-
61
51
  Object.keys(_RoutePlugin).forEach(function (key) {
62
52
  if (key === "default" || key === "__esModule") return;
63
53
  if (key in exports && exports[key] === _RoutePlugin[key]) return;
@@ -68,9 +58,7 @@ Object.keys(_RoutePlugin).forEach(function (key) {
68
58
  }
69
59
  });
70
60
  });
71
-
72
61
  var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
73
-
74
62
  Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
75
63
  if (key === "default" || key === "__esModule") return;
76
64
  if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
@@ -81,9 +69,7 @@ Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
81
69
  }
82
70
  });
83
71
  });
84
-
85
72
  var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
86
-
87
73
  Object.keys(_HandlerErrorPlugin).forEach(function (key) {
88
74
  if (key === "default" || key === "__esModule") return;
89
75
  if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
@@ -94,9 +80,7 @@ Object.keys(_HandlerErrorPlugin).forEach(function (key) {
94
80
  }
95
81
  });
96
82
  });
97
-
98
83
  var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
99
-
100
84
  Object.keys(_HandlerResultPlugin).forEach(function (key) {
101
85
  if (key === "default" || key === "__esModule") return;
102
86
  if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/fastify\";\nexport * from \"@webiny/api/plugins/ContextPlugin\";\nexport * from \"~/Context\";\nexport * from \"~/plugins/EventPlugin\";\nexport * from \"~/plugins/RoutePlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/fastify\";\nexport * from \"@webiny/api/plugins/ContextPlugin\";\nexport * from \"~/Context\";\nexport * from \"~/plugins/EventPlugin\";\nexport * from \"~/plugins/RoutePlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
package/middleware.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.middleware = void 0;
7
-
8
7
  /**
9
8
  * Compose a single middleware from the array of middleware functions
10
9
  */
@@ -12,22 +11,19 @@ const middleware = (functions = []) => {
12
11
  return (...args) => {
13
12
  if (!functions.length) {
14
13
  return Promise.resolve();
15
- } // Create a clone of function chain to prevent modifying the original array with `shift()`
16
-
14
+ }
17
15
 
16
+ // Create a clone of function chain to prevent modifying the original array with `shift()`
18
17
  const chain = [...functions];
19
18
  return new Promise((parentResolve, parentReject) => {
20
19
  const next = async () => {
21
20
  const fn = chain.shift();
22
-
23
21
  if (!fn) {
24
22
  return Promise.resolve();
25
23
  }
26
-
27
24
  return new Promise(async (resolve, reject) => {
28
25
  try {
29
26
  const result = await fn(...args, resolve);
30
-
31
27
  if (typeof result !== "undefined") {
32
28
  return parentResolve(result);
33
29
  }
@@ -42,10 +38,8 @@ const middleware = (functions = []) => {
42
38
  parentReject(e);
43
39
  });
44
40
  };
45
-
46
41
  return next();
47
42
  });
48
43
  };
49
44
  };
50
-
51
45
  exports.middleware = middleware;
package/middleware.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["middleware","functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport const middleware = (functions: Function[] = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,CAACC,SAAqB,GAAG,EAAzB,KAA0C;EAChE,OAAO,CAAC,GAAGC,IAAJ,KAAqC;IACxC,IAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;MACnB,OAAOC,OAAO,CAACC,OAAR,EAAP;IACH,CAHuC,CAKxC;;;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;IACA,OAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;QACA,IAAI,CAACD,EAAL,EAAS;UACL,OAAON,OAAO,CAACC,OAAR,EAAP;QACH;;QAED,OAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;YACA,IAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;cAC/B,OAAON,aAAa,CAACM,MAAD,CAApB;YACH;UACJ,CALD,CAKE,OAAOC,CAAP,EAAU;YACRF,MAAM,CAACE,CAAD,CAAN;UACH;QACJ,CATM,EAUFC,IAVE,CAUG,MAAM;UACR,OAAON,IAAI,EAAX;QACH,CAZE,EAaFM,IAbE,CAaG,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAJ,CAAb;QACH,CAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAD,CAAZ;QACH,CAlBE,CAAP;MAmBH,CAzBD;;MA2BA,OAAOL,IAAI,EAAX;IACH,CA7BM,CAAP;EA8BH,CArCD;AAsCH,CAvCM"}
1
+ {"version":3,"names":["middleware","functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport const middleware = (functions: Function[] = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,CAACC,SAAqB,GAAG,EAAE,KAAe;EAChE,OAAO,CAAC,GAAGC,IAAc,KAAmB;IACxC,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOC,OAAO,CAACC,OAAO,EAAE;IAC5B;;IAEA;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAS,CAAC;IAC5B,OAAO,IAAIG,OAAO,CAAC,CAACG,aAAkB,EAAEC,YAAY,KAAK;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAK,EAAE;QACxB,IAAI,CAACD,EAAE,EAAE;UACL,OAAON,OAAO,CAACC,OAAO,EAAE;QAC5B;QAEA,OAAO,IAAID,OAAO,CAAC,OAAOC,OAAO,EAAEO,MAAM,KAAK;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAI,EAAEG,OAAO,CAAC;YACzC,IAAI,OAAOQ,MAAM,KAAK,WAAW,EAAE;cAC/B,OAAON,aAAa,CAACM,MAAM,CAAC;YAChC;UACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;YACRF,MAAM,CAACE,CAAC,CAAC;UACb;QACJ,CAAC,CAAC,CACGC,IAAI,CAAC,MAAM;UACR,OAAON,IAAI,EAAE;QACjB,CAAC,CAAC,CACDM,IAAI,CAAC,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAI,CAAC;QAC1B,CAAC,CAAC,CACDc,KAAK,CAACF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAC,CAAC;QACnB,CAAC,CAAC;MACV,CAAC;MAED,OAAOL,IAAI,EAAE;IACjB,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/handler",
3
- "version": "0.0.0-unstable.5e7233243f",
3
+ "version": "0.0.0-unstable.6e5425ee89",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,22 +12,22 @@
12
12
  ],
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
- "@babel/runtime": "7.18.9",
16
- "@fastify/cookie": "7.3.1",
17
- "@webiny/api": "0.0.0-unstable.5e7233243f",
18
- "@webiny/error": "0.0.0-unstable.5e7233243f",
19
- "@webiny/handler-client": "0.0.0-unstable.5e7233243f",
20
- "@webiny/plugins": "0.0.0-unstable.5e7233243f",
21
- "@webiny/utils": "0.0.0-unstable.5e7233243f",
22
- "fastify": "4.3.0"
15
+ "@babel/runtime": "7.20.1",
16
+ "@fastify/cookie": "8.3.0",
17
+ "@webiny/api": "0.0.0-unstable.6e5425ee89",
18
+ "@webiny/error": "0.0.0-unstable.6e5425ee89",
19
+ "@webiny/handler-client": "0.0.0-unstable.6e5425ee89",
20
+ "@webiny/plugins": "0.0.0-unstable.6e5425ee89",
21
+ "@webiny/utils": "0.0.0-unstable.6e5425ee89",
22
+ "fastify": "4.10.2"
23
23
  },
24
24
  "devDependencies": {
25
- "@babel/cli": "^7.16.0",
26
- "@babel/core": "^7.16.0",
27
- "@babel/preset-env": "^7.16.4",
28
- "@babel/preset-typescript": "^7.16.0",
29
- "@webiny/cli": "^0.0.0-unstable.5e7233243f",
30
- "@webiny/project-utils": "^0.0.0-unstable.5e7233243f",
25
+ "@babel/cli": "^7.19.3",
26
+ "@babel/core": "^7.19.3",
27
+ "@babel/preset-env": "^7.19.4",
28
+ "@babel/preset-typescript": "^7.18.6",
29
+ "@webiny/cli": "^0.0.0-unstable.6e5425ee89",
30
+ "@webiny/project-utils": "^0.0.0-unstable.6e5425ee89",
31
31
  "babel-plugin-lodash": "^3.3.4",
32
32
  "merge": "^1.2.1",
33
33
  "rimraf": "^3.0.2",
@@ -42,5 +42,5 @@
42
42
  "build": "yarn webiny run build",
43
43
  "watch": "yarn webiny run watch"
44
44
  },
45
- "gitHead": "995a4b337db9b8497c6615e335dcd206afe26f8f"
45
+ "gitHead": "1e49c5d4b72b2f00661572464188f53b42ed7745"
46
46
  }
@@ -1,38 +1,28 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createBeforeHandlerPlugin = exports.BeforeHandlerPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class BeforeHandlerPlugin extends _plugins.Plugin {
15
11
  constructor(callable) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "_callable", void 0);
18
14
  this._callable = callable;
19
15
  }
20
-
21
16
  async apply(context) {
22
17
  if (typeof this._callable !== "function") {
23
18
  throw Error(`Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the "apply" method.`);
24
19
  }
25
-
26
20
  return this._callable(context);
27
21
  }
28
-
29
22
  }
30
-
31
23
  exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
32
24
  (0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
33
-
34
25
  const createBeforeHandlerPlugin = callable => {
35
26
  return new BeforeHandlerPlugin(callable);
36
27
  };
37
-
38
28
  exports.createBeforeHandlerPlugin = createBeforeHandlerPlugin;
@@ -1 +1 @@
1
- {"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createBeforeHandlerPlugin"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB;;AAmB5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
1
+ {"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createBeforeHandlerPlugin"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;AAAA;AAOO,MAAMA,mBAAmB,SAAsCC,eAAM,CAAC;EAIzEC,WAAW,CAACC,QAAkC,EAAE;IAC5C,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,KAAK,CAACC,OAAU,EAAiB;IAC1C,IAAI,OAAO,IAAI,CAACF,SAAS,KAAK,UAAU,EAAE;MACtC,MAAMG,KAAK,CACN,6IAA4I,CAChJ;IACL;IAEA,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,CAAC;EAClC;AACJ;AAAC;AAAA,8BAlBYN,mBAAmB,UACmB,gBAAgB;AAmB5D,MAAMQ,yBAAyB,GAClCL,QAAkC,IACT;EACzB,OAAO,IAAIH,mBAAmB,CAAIG,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createEvent = exports.EventPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
10
  /**
15
11
  * EventPlugin must be handled in the package which implements fastify for certain cloud.
16
12
  * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
@@ -19,20 +15,17 @@ var _Plugin = require("@webiny/plugins/Plugin");
19
15
  * Note that only one EventPlugin can be defined per fastify initialisation.
20
16
  * If more is needed, check ~/fastify.ts and implement that possibility.
21
17
  */
18
+
22
19
  class EventPlugin extends _Plugin.Plugin {
23
20
  constructor(cb) {
24
21
  super();
25
22
  (0, _defineProperty2.default)(this, "cb", void 0);
26
23
  this.cb = cb;
27
24
  }
28
-
29
25
  }
30
-
31
26
  exports.EventPlugin = EventPlugin;
32
27
  (0, _defineProperty2.default)(EventPlugin, "type", "handler.fastify.event");
33
-
34
28
  const createEvent = cb => {
35
29
  return new EventPlugin(cb);
36
30
  };
37
-
38
31
  exports.createEvent = createEvent;
@@ -1 +1 @@
1
- {"version":3,"names":["EventPlugin","Plugin","constructor","cb","createEvent"],"sources":["EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Context as BaseContext, Reply } from \"~/types\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeO,MAAMA,WAAN,SAIGC,cAJH,CAIU;EAKNC,WAAW,CAACC,EAAD,EAAsD;IACpE;IADoE;IAEpE,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARY;;;8BAJJH,W,UAKqB,uB;;AAU3B,MAAMI,WAAW,GAKpBD,EALuB,IAMtB;EACD,OAAO,IAAIH,WAAJ,CAA4CG,EAA5C,CAAP;AACH,CARM"}
1
+ {"version":3,"names":["EventPlugin","Plugin","constructor","cb","createEvent"],"sources":["EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Context as BaseContext, Reply } from \"~/types\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"mappings":";;;;;;;;AAQA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeO,MAAMA,WAAW,SAIdC,cAAM,CAAC;EAKNC,WAAW,CAACC,EAAmD,EAAE;IACpE,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BAbYH,WAAW,UAKU,uBAAuB;AAUlD,MAAMI,WAAW,GAKpBD,EAAmD,IAClD;EACD,OAAO,IAAIH,WAAW,CAA6BG,EAAE,CAAC;AAC1D,CAAC;AAAC"}
@@ -1,34 +1,25 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createHandlerErrorPlugin = exports.HandlerErrorPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class HandlerErrorPlugin extends _plugins.Plugin {
15
11
  constructor(callable) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "_callable", void 0);
18
14
  this._callable = callable;
19
15
  }
20
-
21
16
  async handle(context, error, next) {
22
17
  return this._callable(context, error, next);
23
18
  }
24
-
25
19
  }
26
-
27
20
  exports.HandlerErrorPlugin = HandlerErrorPlugin;
28
21
  (0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
29
-
30
22
  const createHandlerErrorPlugin = callable => {
31
23
  return new HandlerErrorPlugin(callable);
32
24
  };
33
-
34
25
  exports.createHandlerErrorPlugin = createHandlerErrorPlugin;
@@ -1 +1 @@
1
- {"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next","createHandlerErrorPlugin"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e;;AAc5C,MAAMS,wBAAwB,GACjCN,QADoC,IAEZ;EACxB,OAAO,IAAIH,kBAAJ,CAA0BG,QAA1B,CAAP;AACH,CAJM"}
1
+ {"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next","createHandlerErrorPlugin"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;AAAA;AAOO,MAAMA,kBAAkB,SAAsCC,eAAM,CAAC;EAKjEC,WAAW,CAACC,QAAiC,EAAE;IAClD,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,MAAM,CAACC,OAAU,EAAEC,KAAY,EAAEC,IAAc,EAAgB;IACxE,OAAO,IAAI,CAACJ,SAAS,CAACE,OAAO,EAAEC,KAAK,EAAEC,IAAI,CAAC;EAC/C;AACJ;AAAC;AAAA,8BAbYR,kBAAkB,UACoB,eAAe;AAc3D,MAAMS,wBAAwB,GACjCN,QAAiC,IACT;EACxB,OAAO,IAAIH,kBAAkB,CAAIG,QAAQ,CAAC;AAC9C,CAAC;AAAC"}
@@ -1,34 +1,25 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createHandlerResultPlugin = exports.HandlerResultPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _plugins = require("@webiny/plugins");
13
-
14
10
  class HandlerResultPlugin extends _plugins.Plugin {
15
11
  constructor(callable) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "_callable", void 0);
18
14
  this._callable = callable;
19
15
  }
20
-
21
16
  async handle(context, result) {
22
17
  return this._callable(context, result);
23
18
  }
24
-
25
19
  }
26
-
27
20
  exports.HandlerResultPlugin = HandlerResultPlugin;
28
21
  (0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
29
-
30
22
  const createHandlerResultPlugin = callable => {
31
23
  return new HandlerResultPlugin(callable);
32
24
  };
33
-
34
25
  exports.createHandlerResultPlugin = createHandlerResultPlugin;
@@ -1 +1 @@
1
- {"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result","createHandlerResultPlugin"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n\nexport const createHandlerResultPlugin = <T extends Context = Context>(\n callable: HandlerResultCallable<T>\n): HandlerResultPlugin<T> => {\n return new HandlerResultPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAKlEC,WAAW,CAACC,QAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;IACvD,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;EACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB;;AAc5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
1
+ {"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result","createHandlerResultPlugin"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n\nexport const createHandlerResultPlugin = <T extends Context = Context>(\n callable: HandlerResultCallable<T>\n): HandlerResultPlugin<T> => {\n return new HandlerResultPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;AAAA;AAOO,MAAMA,mBAAmB,SAAsCC,eAAM,CAAC;EAKlEC,WAAW,CAACC,QAAkC,EAAE;IACnD,KAAK,EAAE;IAAC;IACR,IAAI,CAACC,SAAS,GAAGD,QAAQ;EAC7B;EAEA,MAAaE,MAAM,CAACC,OAAU,EAAEC,MAAW,EAAgB;IACvD,OAAO,IAAI,CAACH,SAAS,CAACE,OAAO,EAAEC,MAAM,CAAC;EAC1C;AACJ;AAAC;AAAA,8BAbYP,mBAAmB,UACmB,gBAAgB;AAc5D,MAAMQ,yBAAyB,GAClCL,QAAkC,IACT;EACzB,OAAO,IAAIH,mBAAmB,CAAIG,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
@@ -1,30 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createRoute = exports.RoutePlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _Plugin = require("@webiny/plugins/Plugin");
13
-
14
10
  class RoutePlugin extends _Plugin.Plugin {
15
11
  constructor(cb) {
16
12
  super();
17
13
  (0, _defineProperty2.default)(this, "cb", void 0);
18
14
  this.cb = cb;
19
15
  }
20
-
21
16
  }
22
-
23
17
  exports.RoutePlugin = RoutePlugin;
24
18
  (0, _defineProperty2.default)(RoutePlugin, "type", "handler.fastify.route");
25
-
26
19
  const createRoute = cb => {
27
20
  return new RoutePlugin(cb);
28
21
  };
29
-
30
22
  exports.createRoute = createRoute;
@@ -1 +1 @@
1
- {"version":3,"names":["RoutePlugin","Plugin","constructor","cb","createRoute"],"sources":["RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, RouteMethod } from \"~/types\";\n\ninterface RoutePluginCbParams<T extends Context> {\n context: T;\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}\nexport interface RoutePluginCb<T extends Context> {\n (params: RoutePluginCbParams<T>): void;\n}\n\nexport class RoutePlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.fastify.route\";\n\n public readonly cb: RoutePluginCb<T>;\n\n public constructor(cb: RoutePluginCb<T>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createRoute = <T extends Context = Context>(cb: RoutePluginCb<T>): RoutePlugin<T> => {\n return new RoutePlugin<T>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAkBO,MAAMA,WAAN,SAAuDC,cAAvD,CAA8D;EAK1DC,WAAW,CAACC,EAAD,EAAuB;IACrC;IADqC;IAErC,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARgE;;;8BAAxDH,W,UACsC,uB;;AAU5C,MAAMI,WAAW,GAAiCD,EAA9B,IAAuE;EAC9F,OAAO,IAAIH,WAAJ,CAAmBG,EAAnB,CAAP;AACH,CAFM"}
1
+ {"version":3,"names":["RoutePlugin","Plugin","constructor","cb","createRoute"],"sources":["RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, RouteMethod } from \"~/types\";\n\ninterface RoutePluginCbParams<T extends Context> {\n context: T;\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}\nexport interface RoutePluginCb<T extends Context> {\n (params: RoutePluginCbParams<T>): void;\n}\n\nexport class RoutePlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.fastify.route\";\n\n public readonly cb: RoutePluginCb<T>;\n\n public constructor(cb: RoutePluginCb<T>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createRoute = <T extends Context = Context>(cb: RoutePluginCb<T>): RoutePlugin<T> => {\n return new RoutePlugin<T>(cb);\n};\n"],"mappings":";;;;;;;;AAAA;AAkBO,MAAMA,WAAW,SAAsCC,cAAM,CAAC;EAK1DC,WAAW,CAACC,EAAoB,EAAE;IACrC,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,EAAE,GAAGA,EAAE;EAChB;AACJ;AAAC;AAAA,8BATYH,WAAW,UAC2B,uBAAuB;AAUnE,MAAMI,WAAW,GAAiCD,EAAoB,IAAqB;EAC9F,OAAO,IAAIH,WAAW,CAAIG,EAAE,CAAC;AACjC,CAAC;AAAC"}
package/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
2
2
  export { FastifyInstance, HTTPMethods } from "fastify";
3
3
  import { ClientContext } from "@webiny/handler-client/types";
4
- export declare type RouteTypes = HTTPMethods;
5
4
  export interface RouteMethodOptions {
6
5
  override?: boolean;
7
6
  }
@@ -11,7 +10,7 @@ export interface RouteMethod {
11
10
  }
12
11
  export declare type Request = FastifyRequest;
13
12
  export declare type Reply = FastifyReply;
14
- export declare type DefinedContextRoutes = Record<RouteTypes, string[]>;
13
+ export declare type DefinedContextRoutes = Record<HTTPMethods, string[]>;
15
14
  export interface ContextRoutes {
16
15
  defined: DefinedContextRoutes;
17
16
  onGet: RouteMethod;
package/types.js CHANGED
@@ -15,5 +15,4 @@ Object.defineProperty(exports, "HTTPMethods", {
15
15
  return _fastify.HTTPMethods;
16
16
  }
17
17
  });
18
-
19
18
  var _fastify = require("fastify");
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n HTTPMethods,\n RouteHandlerMethod\n} from \"fastify\";\n\nexport { FastifyInstance, HTTPMethods } from \"fastify\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nexport type RouteTypes = HTTPMethods;\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<RouteTypes, 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 * An instance of fastify server.\n * Use at your own risk.\n * @instance\n */\n server: FastifyInstance;\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA"}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n HTTPMethods,\n RouteHandlerMethod\n} from \"fastify\";\n\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 * An instance of fastify server.\n * Use at your own risk.\n * @instance\n */\n server: FastifyInstance;\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA"}