@webiny/handler 6.3.0-beta.4 → 6.4.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/Context.js +10 -23
  2. package/Context.js.map +1 -1
  3. package/PreHandler/IPreHandler.js +5 -4
  4. package/PreHandler/IPreHandler.js.map +1 -1
  5. package/PreHandler/IfNotOptionsRequest.js +12 -15
  6. package/PreHandler/IfNotOptionsRequest.js.map +1 -1
  7. package/PreHandler/IfOptionsRequest.js +12 -15
  8. package/PreHandler/IfOptionsRequest.js.map +1 -1
  9. package/PreHandler/PreHandler.js +11 -12
  10. package/PreHandler/PreHandler.js.map +1 -1
  11. package/PreHandler/ProcessBeforeHandlerPlugins.js +19 -18
  12. package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -1
  13. package/PreHandler/ProcessContextPlugins.js +19 -18
  14. package/PreHandler/ProcessContextPlugins.js.map +1 -1
  15. package/PreHandler/ProcessHandlerOnRequestPlugins.js +18 -19
  16. package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -1
  17. package/PreHandler/RegisterExtensions.js +8 -9
  18. package/PreHandler/RegisterExtensions.js.map +1 -1
  19. package/PreHandler/SendEarlyOptionsResponse.js +20 -25
  20. package/PreHandler/SendEarlyOptionsResponse.js.map +1 -1
  21. package/PreHandler/SetDefaultHeaders.js +37 -48
  22. package/PreHandler/SetDefaultHeaders.js.map +1 -1
  23. package/ResponseHeaders.js +29 -32
  24. package/ResponseHeaders.js.map +1 -1
  25. package/abstractions/Reply.js +2 -1
  26. package/abstractions/Reply.js.map +1 -1
  27. package/abstractions/Request.js +2 -1
  28. package/abstractions/Request.js.map +1 -1
  29. package/abstractions/Route.js +25 -24
  30. package/abstractions/Route.js.map +1 -1
  31. package/exports/api.js +0 -2
  32. package/fastify.js +277 -398
  33. package/fastify.js.map +1 -1
  34. package/index.js +2 -5
  35. package/package.json +9 -9
  36. package/plugins/BeforeHandlerPlugin.js +13 -14
  37. package/plugins/BeforeHandlerPlugin.js.map +1 -1
  38. package/plugins/EventPlugin.js +10 -17
  39. package/plugins/EventPlugin.js.map +1 -1
  40. package/plugins/HandlerErrorPlugin.js +13 -12
  41. package/plugins/HandlerErrorPlugin.js.map +1 -1
  42. package/plugins/HandlerOnRequestPlugin.js +13 -20
  43. package/plugins/HandlerOnRequestPlugin.js.map +1 -1
  44. package/plugins/HandlerResultPlugin.js +13 -12
  45. package/plugins/HandlerResultPlugin.js.map +1 -1
  46. package/plugins/ModifyFastifyPlugin.js +13 -12
  47. package/plugins/ModifyFastifyPlugin.js.map +1 -1
  48. package/plugins/ModifyResponseHeadersPlugin.js +14 -11
  49. package/plugins/ModifyResponseHeadersPlugin.js.map +1 -1
  50. package/plugins/OnRequestResponseSendPlugin.js +13 -27
  51. package/plugins/OnRequestResponseSendPlugin.js.map +1 -1
  52. package/plugins/OnRequestTimeoutPlugin.js +13 -12
  53. package/plugins/OnRequestTimeoutPlugin.js.map +1 -1
  54. package/plugins/RegisterExtensionPlugin.js +12 -12
  55. package/plugins/RegisterExtensionPlugin.js.map +1 -1
  56. package/plugins/RoutePlugin.js +10 -9
  57. package/plugins/RoutePlugin.js.map +1 -1
  58. package/stringifyError.js +12 -17
  59. package/stringifyError.js.map +1 -1
  60. package/suppressPunycodeWarnings.js +3 -6
  61. package/suppressPunycodeWarnings.js.map +1 -1
  62. package/types.js +0 -2
  63. package/exports/api.js.map +0 -1
  64. package/index.js.map +0 -1
  65. package/types.js.map +0 -1
package/Context.js CHANGED
@@ -1,26 +1,13 @@
1
- import { Context as BaseContext, ContextPlugin as BaseContextPlugin, createContextPlugin as baseCreateContextPlugin } from "@webiny/api";
2
- export class Context extends BaseContext {
3
- // @ts-expect-error
4
-
5
- // @ts-expect-error
6
-
7
- // @ts-expect-error
8
-
9
- constructor(params) {
10
- super(params);
11
- this.routes = params.routes;
12
- }
1
+ import { Context, ContextPlugin, createContextPlugin } from "@webiny/api";
2
+ class Context_Context extends Context {
3
+ constructor(params){
4
+ super(params);
5
+ this.routes = params.routes;
6
+ }
13
7
  }
14
-
15
- /**
16
- * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
17
- *
18
- * This can be removed when we introduce the type augmentation.
19
- */
20
-
21
- export class ContextPlugin extends BaseContextPlugin {}
22
- export const createContextPlugin = callable => {
23
- return baseCreateContextPlugin(callable);
24
- };
8
+ class Context_ContextPlugin extends ContextPlugin {
9
+ }
10
+ const Context_createContextPlugin = (callable)=>createContextPlugin(callable);
11
+ export { Context_Context as Context, Context_ContextPlugin as ContextPlugin, Context_createContextPlugin as createContextPlugin };
25
12
 
26
13
  //# sourceMappingURL=Context.js.map
package/Context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["Context","BaseContext","ContextPlugin","BaseContextPlugin","createContextPlugin","baseCreateContextPlugin","constructor","params","routes","callable"],"sources":["Context.ts"],"sourcesContent":["import type {\n ContextParams as BaseContextParams,\n ContextPluginCallable as BaseContextPluginCallable\n} from \"@webiny/api\";\nimport {\n Context as BaseContext,\n ContextPlugin as BaseContextPlugin,\n createContextPlugin as baseCreateContextPlugin\n} from \"@webiny/api\";\nimport type { Context as ContextInterface } from \"~/types.js\";\n\nexport interface ContextParams extends BaseContextParams {\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-expect-error\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-expect-error\n public request: ContextInterface[\"request\"];\n // @ts-expect-error\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.routes = params.routes;\n }\n}\n\n/**\n * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.\n *\n * This can be removed when we introduce the type augmentation.\n */\nexport type ContextPluginCallable<T extends ContextInterface = ContextInterface> =\n BaseContextPluginCallable<T>;\n\nexport class ContextPlugin<\n T extends ContextInterface = ContextInterface\n> extends BaseContextPlugin<T> {}\n\nexport const createContextPlugin = <T extends ContextInterface = ContextInterface>(\n callable: ContextPluginCallable<T>\n) => {\n return baseCreateContextPlugin<T>(callable);\n};\n"],"mappings":"AAIA,SACIA,OAAO,IAAIC,WAAW,EACtBC,aAAa,IAAIC,iBAAiB,EAClCC,mBAAmB,IAAIC,uBAAuB,QAC3C,aAAa;AAOpB,OAAO,MAAML,OAAO,SAASC,WAAW,CAA6B;EAEjE;;EAEA;;EAEA;;EAGOK,WAAWA,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IACb,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;EAC/B;AACJ;;AAEA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMN,aAAa,SAEhBC,iBAAiB,CAAI;AAE/B,OAAO,MAAMC,mBAAmB,GAC5BK,QAAkC,IACjC;EACD,OAAOJ,uBAAuB,CAAII,QAAQ,CAAC;AAC/C,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"Context.js","sources":["../src/Context.ts"],"sourcesContent":["import type {\n ContextParams as BaseContextParams,\n ContextPluginCallable as BaseContextPluginCallable\n} from \"@webiny/api\";\nimport {\n Context as BaseContext,\n ContextPlugin as BaseContextPlugin,\n createContextPlugin as baseCreateContextPlugin\n} from \"@webiny/api\";\nimport type { Context as ContextInterface } from \"~/types.js\";\n\nexport interface ContextParams extends BaseContextParams {\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-expect-error\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-expect-error\n public request: ContextInterface[\"request\"];\n // @ts-expect-error\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.routes = params.routes;\n }\n}\n\n/**\n * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.\n *\n * This can be removed when we introduce the type augmentation.\n */\nexport type ContextPluginCallable<T extends ContextInterface = ContextInterface> =\n BaseContextPluginCallable<T>;\n\nexport class ContextPlugin<\n T extends ContextInterface = ContextInterface\n> extends BaseContextPlugin<T> {}\n\nexport const createContextPlugin = <T extends ContextInterface = ContextInterface>(\n callable: ContextPluginCallable<T>\n) => {\n return baseCreateContextPlugin<T>(callable);\n};\n"],"names":["Context","BaseContext","params","ContextPlugin","BaseContextPlugin","createContextPlugin","callable","baseCreateContextPlugin"],"mappings":";AAeO,MAAMA,wBAAgBC;IASzB,YAAmBC,MAAqB,CAAE;QACtC,KAAK,CAACA;QACN,IAAI,CAAC,MAAM,GAAGA,OAAO,MAAM;IAC/B;AACJ;AAUO,MAAMC,8BAEHC;AAAsB;AAEzB,MAAMC,8BAAsB,CAC/BC,WAEOC,oBAA2BD"}
@@ -1,7 +1,8 @@
1
- export let Action = /*#__PURE__*/function (Action) {
2
- Action["CONTINUE"] = "continue";
3
- Action["DONE"] = "done";
4
- return Action;
1
+ var IPreHandler_Action = /*#__PURE__*/ function(Action) {
2
+ Action["CONTINUE"] = "continue";
3
+ Action["DONE"] = "done";
4
+ return Action;
5
5
  }({});
6
+ export { IPreHandler_Action as Action };
6
7
 
7
8
  //# sourceMappingURL=IPreHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action"],"sources":["IPreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { Context } from \"~/types.js\";\n\nexport enum Action {\n CONTINUE = \"continue\",\n DONE = \"done\"\n}\n\nexport interface IPreHandler {\n execute(\n request: FastifyRequest,\n reply: FastifyReply,\n context: Context\n ): Promise<Action> | Action;\n}\n"],"mappings":"AAGA,WAAYA,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/IPreHandler.js","sources":["../../src/PreHandler/IPreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { Context } from \"~/types.js\";\n\nexport enum Action {\n CONTINUE = \"continue\",\n DONE = \"done\"\n}\n\nexport interface IPreHandler {\n execute(\n request: FastifyRequest,\n reply: FastifyReply,\n context: Context\n ): Promise<Action> | Action;\n}\n"],"names":["Action"],"mappings":"AAGO,IAAKA,qBAAMA,WAAAA,GAAAA,SAANA,MAAM;;;WAANA"}
@@ -1,21 +1,18 @@
1
1
  import { Action } from "./IPreHandler.js";
2
- export class IfNotOptionsRequest {
3
- constructor(handlers) {
4
- this.handlers = handlers;
5
- }
6
- async execute(request, reply, context) {
7
- const isOptionsRequest = request.method === "OPTIONS";
8
- if (isOptionsRequest) {
9
- return Action.CONTINUE;
2
+ class IfNotOptionsRequest {
3
+ constructor(handlers){
4
+ this.handlers = handlers;
10
5
  }
11
- for (const handler of this.handlers) {
12
- const action = await handler.execute(request, reply, context);
13
- if (action === Action.DONE) {
14
- return Action.DONE;
15
- }
6
+ async execute(request, reply, context) {
7
+ const isOptionsRequest = "OPTIONS" === request.method;
8
+ if (isOptionsRequest) return Action.CONTINUE;
9
+ for (const handler of this.handlers){
10
+ const action = await handler.execute(request, reply, context);
11
+ if (action === Action.DONE) return Action.DONE;
12
+ }
13
+ return Action.CONTINUE;
16
14
  }
17
- return Action.CONTINUE;
18
- }
19
15
  }
16
+ export { IfNotOptionsRequest };
20
17
 
21
18
  //# sourceMappingURL=IfNotOptionsRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","IfNotOptionsRequest","constructor","handlers","execute","request","reply","context","isOptionsRequest","method","CONTINUE","handler","action","DONE"],"sources":["IfNotOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfNotOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,OAAO,MAAMC,mBAAmB,CAAwB;EAGpDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,MAAMC,gBAAgB,GAAGH,OAAO,CAACI,MAAM,KAAK,SAAS;IACrD,IAAID,gBAAgB,EAAE;MAClB,OAAOR,MAAM,CAACU,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;MAC7D,IAAIK,MAAM,KAAKZ,MAAM,CAACa,IAAI,EAAE;QACxB,OAAOb,MAAM,CAACa,IAAI;MACtB;IACJ;IAEA,OAAOb,MAAM,CAACU,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/IfNotOptionsRequest.js","sources":["../../src/PreHandler/IfNotOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfNotOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["IfNotOptionsRequest","handlers","request","reply","context","isOptionsRequest","Action","handler","action"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;QAC3F,MAAMC,mBAAmBH,AAAmB,cAAnBA,QAAQ,MAAM;QACvC,IAAIG,kBACA,OAAOC,OAAO,QAAQ;QAG1B,KAAK,MAAMC,WAAW,IAAI,CAAC,QAAQ,CAAE;YACjC,MAAMC,SAAS,MAAMD,QAAQ,OAAO,CAACL,SAASC,OAAOC;YACrD,IAAII,WAAWF,OAAO,IAAI,EACtB,OAAOA,OAAO,IAAI;QAE1B;QAEA,OAAOA,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,21 +1,18 @@
1
1
  import { Action } from "./IPreHandler.js";
2
- export class IfOptionsRequest {
3
- constructor(handlers) {
4
- this.handlers = handlers;
5
- }
6
- async execute(request, reply, context) {
7
- const isOptionsRequest = request.method === "OPTIONS";
8
- if (!isOptionsRequest) {
9
- return Action.CONTINUE;
2
+ class IfOptionsRequest {
3
+ constructor(handlers){
4
+ this.handlers = handlers;
10
5
  }
11
- for (const handler of this.handlers) {
12
- const action = await handler.execute(request, reply, context);
13
- if (action === Action.DONE) {
14
- return Action.DONE;
15
- }
6
+ async execute(request, reply, context) {
7
+ const isOptionsRequest = "OPTIONS" === request.method;
8
+ if (!isOptionsRequest) return Action.CONTINUE;
9
+ for (const handler of this.handlers){
10
+ const action = await handler.execute(request, reply, context);
11
+ if (action === Action.DONE) return Action.DONE;
12
+ }
13
+ return Action.CONTINUE;
16
14
  }
17
- return Action.CONTINUE;
18
- }
19
15
  }
16
+ export { IfOptionsRequest };
20
17
 
21
18
  //# sourceMappingURL=IfOptionsRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","IfOptionsRequest","constructor","handlers","execute","request","reply","context","isOptionsRequest","method","CONTINUE","handler","action","DONE"],"sources":["IfOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (!isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,OAAO,MAAMC,gBAAgB,CAAwB;EAGjDC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,MAAMC,gBAAgB,GAAGH,OAAO,CAACI,MAAM,KAAK,SAAS;IACrD,IAAI,CAACD,gBAAgB,EAAE;MACnB,OAAOR,MAAM,CAACU,QAAQ;IAC1B;IAEA,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACR,QAAQ,EAAE;MACjC,MAAMS,MAAM,GAAG,MAAMD,OAAO,CAACP,OAAO,CAACC,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;MAC7D,IAAIK,MAAM,KAAKZ,MAAM,CAACa,IAAI,EAAE;QACxB,OAAOb,MAAM,CAACa,IAAI;MACtB;IACJ;IAEA,OAAOb,MAAM,CAACU,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/IfOptionsRequest.js","sources":["../../src/PreHandler/IfOptionsRequest.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class IfOptionsRequest implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n const isOptionsRequest = request.method === \"OPTIONS\";\n if (!isOptionsRequest) {\n return Action.CONTINUE;\n }\n\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["IfOptionsRequest","handlers","request","reply","context","isOptionsRequest","Action","handler","action"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;QAC3F,MAAMC,mBAAmBH,AAAmB,cAAnBA,QAAQ,MAAM;QACvC,IAAI,CAACG,kBACD,OAAOC,OAAO,QAAQ;QAG1B,KAAK,MAAMC,WAAW,IAAI,CAAC,QAAQ,CAAE;YACjC,MAAMC,SAAS,MAAMD,QAAQ,OAAO,CAACL,SAASC,OAAOC;YACrD,IAAII,WAAWF,OAAO,IAAI,EACtB,OAAOA,OAAO,IAAI;QAE1B;QAEA,OAAOA,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,17 +1,16 @@
1
1
  import { Action } from "./IPreHandler.js";
2
- export class PreHandler {
3
- constructor(handlers) {
4
- this.handlers = handlers;
5
- }
6
- async execute(request, reply, context) {
7
- for (const handler of this.handlers) {
8
- const action = await handler.execute(request, reply, context);
9
- if (action === Action.DONE) {
10
- return Action.DONE;
11
- }
2
+ class PreHandler {
3
+ constructor(handlers){
4
+ this.handlers = handlers;
5
+ }
6
+ async execute(request, reply, context) {
7
+ for (const handler of this.handlers){
8
+ const action = await handler.execute(request, reply, context);
9
+ if (action === Action.DONE) return Action.DONE;
10
+ }
11
+ return Action.CONTINUE;
12
12
  }
13
- return Action.CONTINUE;
14
- }
15
13
  }
14
+ export { PreHandler };
16
15
 
17
16
  //# sourceMappingURL=PreHandler.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","PreHandler","constructor","handlers","execute","request","reply","context","handler","action","DONE","CONTINUE"],"sources":["PreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class PreHandler implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,OAAO,MAAMC,UAAU,CAAwB;EAG3CC,WAAWA,CAACC,QAAuB,EAAE;IACjC,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,KAAK,MAAMC,OAAO,IAAI,IAAI,CAACL,QAAQ,EAAE;MACjC,MAAMM,MAAM,GAAG,MAAMD,OAAO,CAACJ,OAAO,CAACC,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;MAC7D,IAAIE,MAAM,KAAKT,MAAM,CAACU,IAAI,EAAE;QACxB,OAAOV,MAAM,CAACU,IAAI;MACtB;IACJ;IAEA,OAAOV,MAAM,CAACW,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/PreHandler.js","sources":["../../src/PreHandler/PreHandler.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class PreHandler implements IPreHandler {\n private readonly handlers: IPreHandler[];\n\n constructor(handlers: IPreHandler[]) {\n this.handlers = handlers;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n for (const handler of this.handlers) {\n const action = await handler.execute(request, reply, context);\n if (action === Action.DONE) {\n return Action.DONE;\n }\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["PreHandler","handlers","request","reply","context","handler","action","Action"],"mappings":";AAKO,MAAMA;IAGT,YAAYC,QAAuB,CAAE;QACjC,IAAI,CAAC,QAAQ,GAAGA;IACpB;IAEA,MAAM,QAAQC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;QAC3F,KAAK,MAAMC,WAAW,IAAI,CAAC,QAAQ,CAAE;YACjC,MAAMC,SAAS,MAAMD,QAAQ,OAAO,CAACH,SAASC,OAAOC;YACrD,IAAIE,WAAWC,OAAO,IAAI,EACtB,OAAOA,OAAO,IAAI;QAE1B;QAEA,OAAOA,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,24 +1,25 @@
1
1
  import { Action } from "./IPreHandler.js";
2
2
  import { stringifyError } from "../stringifyError.js";
3
- export class ProcessBeforeHandlerPlugins {
4
- constructor(context, plugins) {
5
- this.context = context;
6
- this.plugins = plugins;
7
- }
8
- async execute() {
9
- let name;
10
- try {
11
- for (const plugin of this.plugins) {
12
- name = plugin.name;
13
- await plugin.apply(this.context);
14
- }
15
- } catch (ex) {
16
- console.error(`Error running BeforeHandlerPlugin "${name}".`);
17
- console.error(stringifyError(ex));
18
- throw ex;
3
+ class ProcessBeforeHandlerPlugins {
4
+ constructor(context, plugins){
5
+ this.context = context;
6
+ this.plugins = plugins;
7
+ }
8
+ async execute() {
9
+ let name;
10
+ try {
11
+ for (const plugin of this.plugins){
12
+ name = plugin.name;
13
+ await plugin.apply(this.context);
14
+ }
15
+ } catch (ex) {
16
+ console.error(`Error running BeforeHandlerPlugin "${name}".`);
17
+ console.error(stringifyError(ex));
18
+ throw ex;
19
+ }
20
+ return Action.CONTINUE;
19
21
  }
20
- return Action.CONTINUE;
21
- }
22
22
  }
23
+ export { ProcessBeforeHandlerPlugins };
23
24
 
24
25
  //# sourceMappingURL=ProcessBeforeHandlerPlugins.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","stringifyError","ProcessBeforeHandlerPlugins","constructor","context","plugins","execute","name","plugin","apply","ex","console","error","CONTINUE"],"sources":["ProcessBeforeHandlerPlugins.ts"],"sourcesContent":["import type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { Context } from \"~/types.js\";\nimport type { BeforeHandlerPlugin } from \"~/plugins/BeforeHandlerPlugin.js\";\n\nexport class ProcessBeforeHandlerPlugins implements IPreHandler {\n private readonly plugins: BeforeHandlerPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: BeforeHandlerPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running BeforeHandlerPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AACA,SAASA,MAAM;AACf,SAASC,cAAc;AAIvB,OAAO,MAAMC,2BAA2B,CAAwB;EAI5DC,WAAWA,CAACC,OAAgB,EAAEC,OAA8B,EAAE;IAC1D,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAAA,EAAoB;IAC7B,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QAC/BE,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAMC,MAAM,CAACC,KAAK,CAAC,IAAI,CAACL,OAAO,CAAC;MACpC;IACJ,CAAC,CAAC,OAAOM,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,sCAAsCL,IAAI,IAAI,CAAC;MAC7DI,OAAO,CAACC,KAAK,CAACX,cAAc,CAACS,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOV,MAAM,CAACa,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/ProcessBeforeHandlerPlugins.js","sources":["../../src/PreHandler/ProcessBeforeHandlerPlugins.ts"],"sourcesContent":["import type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { Context } from \"~/types.js\";\nimport type { BeforeHandlerPlugin } from \"~/plugins/BeforeHandlerPlugin.js\";\n\nexport class ProcessBeforeHandlerPlugins implements IPreHandler {\n private readonly plugins: BeforeHandlerPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: BeforeHandlerPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running BeforeHandlerPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["ProcessBeforeHandlerPlugins","context","plugins","name","plugin","ex","console","stringifyError","Action"],"mappings":";;AAMO,MAAMA;IAIT,YAAYC,OAAgB,EAAEC,OAA8B,CAAE;QAC1D,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,MAAM,UAA2B;QAC7B,IAAIC;QACJ,IAAI;YACA,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAE;gBAC/BD,OAAOC,OAAO,IAAI;gBAClB,MAAMA,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO;YACnC;QACJ,EAAE,OAAOC,IAAI;YACTC,QAAQ,KAAK,CAAC,CAAC,mCAAmC,EAAEH,KAAK,EAAE,CAAC;YAC5DG,QAAQ,KAAK,CAACC,eAAeF;YAC7B,MAAMA;QACV;QAEA,OAAOG,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,24 +1,25 @@
1
1
  import { Action } from "./IPreHandler.js";
2
2
  import { stringifyError } from "../stringifyError.js";
3
- export class ProcessContextPlugins {
4
- constructor(context, plugins) {
5
- this.context = context;
6
- this.plugins = plugins;
7
- }
8
- async execute() {
9
- let name;
10
- try {
11
- for (const plugin of this.plugins) {
12
- name = plugin.name;
13
- await plugin.apply(this.context);
14
- }
15
- } catch (ex) {
16
- console.error(`Error running ContextPlugin "${name}".`);
17
- console.error(stringifyError(ex));
18
- throw ex;
3
+ class ProcessContextPlugins {
4
+ constructor(context, plugins){
5
+ this.context = context;
6
+ this.plugins = plugins;
7
+ }
8
+ async execute() {
9
+ let name;
10
+ try {
11
+ for (const plugin of this.plugins){
12
+ name = plugin.name;
13
+ await plugin.apply(this.context);
14
+ }
15
+ } catch (ex) {
16
+ console.error(`Error running ContextPlugin "${name}".`);
17
+ console.error(stringifyError(ex));
18
+ throw ex;
19
+ }
20
+ return Action.CONTINUE;
19
21
  }
20
- return Action.CONTINUE;
21
- }
22
22
  }
23
+ export { ProcessContextPlugins };
23
24
 
24
25
  //# sourceMappingURL=ProcessContextPlugins.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","stringifyError","ProcessContextPlugins","constructor","context","plugins","execute","name","plugin","apply","ex","console","error","CONTINUE"],"sources":["ProcessContextPlugins.ts"],"sourcesContent":["import type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { ContextPlugin } from \"~/Context.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class ProcessContextPlugins implements IPreHandler {\n private readonly plugins: ContextPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: ContextPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running ContextPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AACA,SAASA,MAAM;AACf,SAASC,cAAc;AAIvB,OAAO,MAAMC,qBAAqB,CAAwB;EAItDC,WAAWA,CAACC,OAAgB,EAAEC,OAAwB,EAAE;IACpD,IAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,IAAI,CAACC,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAAA,EAAoB;IAC7B,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACH,OAAO,EAAE;QAC/BE,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAMC,MAAM,CAACC,KAAK,CAAC,IAAI,CAACL,OAAO,CAAC;MACpC;IACJ,CAAC,CAAC,OAAOM,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CAAC,gCAAgCL,IAAI,IAAI,CAAC;MACvDI,OAAO,CAACC,KAAK,CAACX,cAAc,CAACS,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOV,MAAM,CAACa,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/ProcessContextPlugins.js","sources":["../../src/PreHandler/ProcessContextPlugins.ts"],"sourcesContent":["import type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { ContextPlugin } from \"~/Context.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class ProcessContextPlugins implements IPreHandler {\n private readonly plugins: ContextPlugin[];\n private readonly context: Context;\n\n constructor(context: Context, plugins: ContextPlugin[]) {\n this.context = context;\n this.plugins = plugins;\n }\n\n async execute(): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n await plugin.apply(this.context);\n }\n } catch (ex) {\n console.error(`Error running ContextPlugin \"${name}\".`);\n console.error(stringifyError(ex));\n throw ex;\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["ProcessContextPlugins","context","plugins","name","plugin","ex","console","stringifyError","Action"],"mappings":";;AAMO,MAAMA;IAIT,YAAYC,OAAgB,EAAEC,OAAwB,CAAE;QACpD,IAAI,CAAC,OAAO,GAAGD;QACf,IAAI,CAAC,OAAO,GAAGC;IACnB;IAEA,MAAM,UAA2B;QAC7B,IAAIC;QACJ,IAAI;YACA,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAE;gBAC/BD,OAAOC,OAAO,IAAI;gBAClB,MAAMA,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO;YACnC;QACJ,EAAE,OAAOC,IAAI;YACTC,QAAQ,KAAK,CAAC,CAAC,6BAA6B,EAAEH,KAAK,EAAE,CAAC;YACtDG,QAAQ,KAAK,CAACC,eAAeF;YAC7B,MAAMA;QACV;QAEA,OAAOG,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,26 +1,25 @@
1
1
  import { Action } from "./IPreHandler.js";
2
2
  import { stringifyError } from "../stringifyError.js";
3
- export class ProcessHandlerOnRequestPlugins {
4
- constructor(plugins) {
5
- this.plugins = plugins;
6
- }
7
- async execute(request, reply, context) {
8
- let name;
9
- try {
10
- for (const plugin of this.plugins) {
11
- name = plugin.name;
12
- const result = await plugin.exec(request, reply, context);
13
- if (result === false) {
14
- return Action.DONE;
3
+ class ProcessHandlerOnRequestPlugins {
4
+ constructor(plugins){
5
+ this.plugins = plugins;
6
+ }
7
+ async execute(request, reply, context) {
8
+ let name;
9
+ try {
10
+ for (const plugin of this.plugins){
11
+ name = plugin.name;
12
+ const result = await plugin.exec(request, reply, context);
13
+ if (false === result) return Action.DONE;
14
+ }
15
+ } catch (ex) {
16
+ console.error(`Error while running the "HandlerOnRequestPlugin" ${name ? `(${name})` : ""} plugin in the onRequest hook.`);
17
+ console.error(stringifyError(ex));
18
+ throw ex;
15
19
  }
16
- }
17
- } catch (ex) {
18
- console.error(`Error while running the "HandlerOnRequestPlugin" ${name ? `(${name})` : ""} plugin in the onRequest hook.`);
19
- console.error(stringifyError(ex));
20
- throw ex;
20
+ return Action.CONTINUE;
21
21
  }
22
- return Action.CONTINUE;
23
- }
24
22
  }
23
+ export { ProcessHandlerOnRequestPlugins };
25
24
 
26
25
  //# sourceMappingURL=ProcessHandlerOnRequestPlugins.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","stringifyError","ProcessHandlerOnRequestPlugins","constructor","plugins","execute","request","reply","context","name","plugin","result","exec","DONE","ex","console","error","CONTINUE"],"sources":["ProcessHandlerOnRequestPlugins.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class ProcessHandlerOnRequestPlugins implements IPreHandler {\n private readonly plugins: HandlerOnRequestPlugin[];\n\n constructor(plugins: HandlerOnRequestPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply, context);\n if (result === false) {\n return Action.DONE;\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 return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAEf,SAASC,cAAc;AAGvB,OAAO,MAAMC,8BAA8B,CAAwB;EAG/DC,WAAWA,CAACC,OAAiC,EAAE;IAC3C,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;IAC3F,IAAIC,IAAwB;IAC5B,IAAI;MACA,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACN,OAAO,EAAE;QAC/BK,IAAI,GAAGC,MAAM,CAACD,IAAI;QAClB,MAAME,MAAM,GAAG,MAAMD,MAAM,CAACE,IAAI,CAACN,OAAO,EAAEC,KAAK,EAAEC,OAAO,CAAC;QACzD,IAAIG,MAAM,KAAK,KAAK,EAAE;UAClB,OAAOX,MAAM,CAACa,IAAI;QACtB;MACJ;IACJ,CAAC,CAAC,OAAOC,EAAE,EAAE;MACTC,OAAO,CAACC,KAAK,CACT,oDACIP,IAAI,GAAG,IAAIA,IAAI,GAAG,GAAG,EAAE,gCAE/B,CAAC;MACDM,OAAO,CAACC,KAAK,CAACf,cAAc,CAACa,EAAE,CAAC,CAAC;MACjC,MAAMA,EAAE;IACZ;IAEA,OAAOd,MAAM,CAACiB,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/ProcessHandlerOnRequestPlugins.js","sources":["../../src/PreHandler/ProcessHandlerOnRequestPlugins.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { HandlerOnRequestPlugin } from \"~/plugins/HandlerOnRequestPlugin.js\";\nimport { stringifyError } from \"~/stringifyError.js\";\nimport type { Context } from \"~/types.js\";\n\nexport class ProcessHandlerOnRequestPlugins implements IPreHandler {\n private readonly plugins: HandlerOnRequestPlugin[];\n\n constructor(plugins: HandlerOnRequestPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> {\n let name: string | undefined;\n try {\n for (const plugin of this.plugins) {\n name = plugin.name;\n const result = await plugin.exec(request, reply, context);\n if (result === false) {\n return Action.DONE;\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 return Action.CONTINUE;\n }\n}\n"],"names":["ProcessHandlerOnRequestPlugins","plugins","request","reply","context","name","plugin","result","Action","ex","console","stringifyError"],"mappings":";;AAOO,MAAMA;IAGT,YAAYC,OAAiC,CAAE;QAC3C,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,MAAM,QAAQC,OAAuB,EAAEC,KAAmB,EAAEC,OAAgB,EAAmB;QAC3F,IAAIC;QACJ,IAAI;YACA,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAAE;gBAC/BD,OAAOC,OAAO,IAAI;gBAClB,MAAMC,SAAS,MAAMD,OAAO,IAAI,CAACJ,SAASC,OAAOC;gBACjD,IAAIG,AAAW,UAAXA,QACA,OAAOC,OAAO,IAAI;YAE1B;QACJ,EAAE,OAAOC,IAAI;YACTC,QAAQ,KAAK,CACT,CAAC,iDAAiD,EAC9CL,OAAO,CAAC,CAAC,EAAEA,KAAK,CAAC,CAAC,GAAG,GACxB,8BAA8B,CAAC;YAEpCK,QAAQ,KAAK,CAACC,eAAeF;YAC7B,MAAMA;QACV;QAEA,OAAOD,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,14 +1,13 @@
1
1
  import { Action } from "./IPreHandler.js";
2
- export class RegisterExtensions {
3
- constructor(plugins) {
4
- this.plugins = plugins;
5
- }
6
- async execute(_, __, context) {
7
- for (const plugin of this.plugins) {
8
- await plugin.apply(context);
2
+ class RegisterExtensions {
3
+ constructor(plugins){
4
+ this.plugins = plugins;
5
+ }
6
+ async execute(_, __, context) {
7
+ for (const plugin of this.plugins)await plugin.apply(context);
8
+ return Action.CONTINUE;
9
9
  }
10
- return Action.CONTINUE;
11
- }
12
10
  }
11
+ export { RegisterExtensions };
13
12
 
14
13
  //# sourceMappingURL=RegisterExtensions.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","RegisterExtensions","constructor","plugins","execute","_","__","context","plugin","apply","CONTINUE"],"sources":["RegisterExtensions.ts"],"sourcesContent":["import { FastifyRequest, FastifyReply } from \"fastify\";\nimport type { Context } from \"~/types.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { RegisterExtensionPlugin } from \"~/plugins/RegisterExtensionPlugin.js\";\n\nexport class RegisterExtensions implements IPreHandler {\n public constructor(private readonly plugins: RegisterExtensionPlugin[]) {}\n\n public async execute<C extends Context = Context>(\n _: FastifyRequest,\n __: FastifyReply,\n context: C\n ): Promise<Action> {\n for (const plugin of this.plugins) {\n await plugin.apply(context);\n }\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAIf,OAAO,MAAMC,kBAAkB,CAAwB;EAC5CC,WAAWA,CAAkBC,OAAkC,EAAE;IAAA,KAApCA,OAAkC,GAAlCA,OAAkC;EAAG;EAEzE,MAAaC,OAAOA,CAChBC,CAAiB,EACjBC,EAAgB,EAChBC,OAAU,EACK;IACf,KAAK,MAAMC,MAAM,IAAI,IAAI,CAACL,OAAO,EAAE;MAC/B,MAAMK,MAAM,CAACC,KAAK,CAACF,OAAO,CAAC;IAC/B;IAEA,OAAOP,MAAM,CAACU,QAAQ;EAC1B;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/RegisterExtensions.js","sources":["../../src/PreHandler/RegisterExtensions.ts"],"sourcesContent":["import { FastifyRequest, FastifyReply } from \"fastify\";\nimport type { Context } from \"~/types.js\";\nimport { Action } from \"./IPreHandler.js\";\nimport type { IPreHandler } from \"./IPreHandler.js\";\nimport { RegisterExtensionPlugin } from \"~/plugins/RegisterExtensionPlugin.js\";\n\nexport class RegisterExtensions implements IPreHandler {\n public constructor(private readonly plugins: RegisterExtensionPlugin[]) {}\n\n public async execute<C extends Context = Context>(\n _: FastifyRequest,\n __: FastifyReply,\n context: C\n ): Promise<Action> {\n for (const plugin of this.plugins) {\n await plugin.apply(context);\n }\n\n return Action.CONTINUE;\n }\n}\n"],"names":["RegisterExtensions","plugins","_","__","context","plugin","Action"],"mappings":";AAMO,MAAMA;IACT,YAAoCC,OAAkC,CAAE;aAApCA,OAAO,GAAPA;IAAqC;IAEzE,MAAa,QACTC,CAAiB,EACjBC,EAAgB,EAChBC,OAAU,EACK;QACf,KAAK,MAAMC,UAAU,IAAI,CAAC,OAAO,CAC7B,MAAMA,OAAO,KAAK,CAACD;QAGvB,OAAOE,OAAO,QAAQ;IAC1B;AACJ"}
@@ -1,31 +1,26 @@
1
1
  import { Action } from "./IPreHandler.js";
2
2
  import { ResponseHeaders } from "../ResponseHeaders.js";
3
- export class SendEarlyOptionsResponse {
4
- constructor(plugins) {
5
- this.plugins = plugins;
6
- }
7
- async execute(request, reply) {
8
- /**
9
- * IMPORTANT! Do not send anything if reply was already sent.
10
- */
11
- if (reply.sent) {
12
- /**
13
- * At this point throwing an exception will not do anything with the response. So just log it.
14
- */
15
- console.error(JSON.stringify({
16
- message: `Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".`,
17
- explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
18
- }));
19
- return Action.DONE;
3
+ class SendEarlyOptionsResponse {
4
+ constructor(plugins){
5
+ this.plugins = plugins;
6
+ }
7
+ async execute(request, reply) {
8
+ if (reply.sent) {
9
+ console.error(JSON.stringify({
10
+ message: 'Output was already sent. Please check custom plugins of type "HandlerOnRequestPlugin".',
11
+ explanation: "This error can happen if the user plugin ended the reply, but did not return false as response."
12
+ }));
13
+ return Action.DONE;
14
+ }
15
+ const headers = ResponseHeaders.create(reply.getHeaders());
16
+ this.plugins.forEach((plugin)=>{
17
+ plugin.modify(request, headers);
18
+ });
19
+ reply.headers(headers.getHeaders());
20
+ reply.code(204).send("").hijack();
21
+ return Action.DONE;
20
22
  }
21
- const headers = ResponseHeaders.create(reply.getHeaders());
22
- this.plugins.forEach(plugin => {
23
- plugin.modify(request, headers);
24
- });
25
- reply.headers(headers.getHeaders());
26
- reply.code(204).send("").hijack();
27
- return Action.DONE;
28
- }
29
23
  }
24
+ export { SendEarlyOptionsResponse };
30
25
 
31
26
  //# sourceMappingURL=SendEarlyOptionsResponse.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Action","ResponseHeaders","SendEarlyOptionsResponse","constructor","plugins","execute","request","reply","sent","console","error","JSON","stringify","message","explanation","DONE","headers","create","getHeaders","forEach","plugin","modify","code","send","hijack"],"sources":["SendEarlyOptionsResponse.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin.js\";\nimport type { StandardHeaders } from \"~/ResponseHeaders.js\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\n\nexport class SendEarlyOptionsResponse implements IPreHandler {\n private readonly plugins: ModifyResponseHeadersPlugin[];\n\n constructor(plugins: ModifyResponseHeadersPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return Action.DONE;\n }\n\n const headers = ResponseHeaders.create(reply.getHeaders() as StandardHeaders);\n\n this.plugins.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n\n reply.code(204).send(\"\").hijack();\n\n return Action.DONE;\n }\n}\n"],"mappings":"AAEA,SAASA,MAAM;AAGf,SAASC,eAAe;AAExB,OAAO,MAAMC,wBAAwB,CAAwB;EAGzDC,WAAWA,CAACC,OAAsC,EAAE;IAChD,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B;EAEA,MAAMC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAmB;IACzE;AACR;AACA;IACQ,IAAIA,KAAK,CAACC,IAAI,EAAE;MACZ;AACZ;AACA;MACYC,OAAO,CAACC,KAAK,CACTC,IAAI,CAACC,SAAS,CAAC;QACXC,OAAO,EAAE,wFAAwF;QACjGC,WAAW,EACP;MACR,CAAC,CACL,CAAC;MACD,OAAOd,MAAM,CAACe,IAAI;IACtB;IAEA,MAAMC,OAAO,GAAGf,eAAe,CAACgB,MAAM,CAACV,KAAK,CAACW,UAAU,CAAC,CAAoB,CAAC;IAE7E,IAAI,CAACd,OAAO,CAACe,OAAO,CAACC,MAAM,IAAI;MAC3BA,MAAM,CAACC,MAAM,CAACf,OAAO,EAAEU,OAAO,CAAC;IACnC,CAAC,CAAC;IAEFT,KAAK,CAACS,OAAO,CAACA,OAAO,CAACE,UAAU,CAAC,CAAC,CAAC;IAEnCX,KAAK,CAACe,IAAI,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC;IAEjC,OAAOxB,MAAM,CAACe,IAAI;EACtB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"PreHandler/SendEarlyOptionsResponse.js","sources":["../../src/PreHandler/SendEarlyOptionsResponse.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\nimport type { ModifyResponseHeadersPlugin } from \"~/plugins/ModifyResponseHeadersPlugin.js\";\nimport type { StandardHeaders } from \"~/ResponseHeaders.js\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\n\nexport class SendEarlyOptionsResponse implements IPreHandler {\n private readonly plugins: ModifyResponseHeadersPlugin[];\n\n constructor(plugins: ModifyResponseHeadersPlugin[]) {\n this.plugins = plugins;\n }\n\n async execute(request: FastifyRequest, reply: FastifyReply): Promise<Action> {\n /**\n * IMPORTANT! Do not send anything if reply was already sent.\n */\n if (reply.sent) {\n /**\n * At this point throwing an exception will not do anything with the response. So just log it.\n */\n console.error(\n JSON.stringify({\n message: `Output was already sent. Please check custom plugins of type \"HandlerOnRequestPlugin\".`,\n explanation:\n \"This error can happen if the user plugin ended the reply, but did not return false as response.\"\n })\n );\n return Action.DONE;\n }\n\n const headers = ResponseHeaders.create(reply.getHeaders() as StandardHeaders);\n\n this.plugins.forEach(plugin => {\n plugin.modify(request, headers);\n });\n\n reply.headers(headers.getHeaders());\n\n reply.code(204).send(\"\").hijack();\n\n return Action.DONE;\n }\n}\n"],"names":["SendEarlyOptionsResponse","plugins","request","reply","console","JSON","Action","headers","ResponseHeaders","plugin"],"mappings":";;AAOO,MAAMA;IAGT,YAAYC,OAAsC,CAAE;QAChD,IAAI,CAAC,OAAO,GAAGA;IACnB;IAEA,MAAM,QAAQC,OAAuB,EAAEC,KAAmB,EAAmB;QAIzE,IAAIA,MAAM,IAAI,EAAE;YAIZC,QAAQ,KAAK,CACTC,KAAK,SAAS,CAAC;gBACX,SAAS;gBACT,aACI;YACR;YAEJ,OAAOC,OAAO,IAAI;QACtB;QAEA,MAAMC,UAAUC,gBAAgB,MAAM,CAACL,MAAM,UAAU;QAEvD,IAAI,CAAC,OAAO,CAAC,OAAO,CAACM,CAAAA;YACjBA,OAAO,MAAM,CAACP,SAASK;QAC3B;QAEAJ,MAAM,OAAO,CAACI,QAAQ,UAAU;QAEhCJ,MAAM,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,MAAM;QAE/B,OAAOG,OAAO,IAAI;IACtB;AACJ"}
@@ -2,56 +2,45 @@ import { getWebinyVersionHeaders } from "@webiny/utils";
2
2
  import { ResponseHeaders } from "../ResponseHeaders.js";
3
3
  import { Action } from "./IPreHandler.js";
4
4
  function createDefaultHeaders() {
5
- return ResponseHeaders.create({
6
- "content-type": "application/json; charset=utf-8",
7
- "cache-control": "no-store",
8
- "access-control-allow-origin": "*",
9
- "access-control-allow-headers": "*",
10
- "access-control-allow-methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH",
11
- ...getWebinyVersionHeaders()
12
- });
5
+ return ResponseHeaders.create({
6
+ "content-type": "application/json; charset=utf-8",
7
+ "cache-control": "no-store",
8
+ "access-control-allow-origin": "*",
9
+ "access-control-allow-headers": "*",
10
+ "access-control-allow-methods": "OPTIONS,POST,GET,DELETE,PUT,PATCH",
11
+ ...getWebinyVersionHeaders()
12
+ });
13
13
  }
14
- const getDefaultOptionsHeaders = () => {
15
- return ResponseHeaders.create({
16
- "access-control-max-age": "86400",
17
- "cache-control": "public, max-age=86400"
18
- });
14
+ const getDefaultOptionsHeaders = ()=>ResponseHeaders.create({
15
+ "access-control-max-age": "86400",
16
+ "cache-control": "public, max-age=86400"
17
+ });
18
+ const getDefaultHeaders = (routes)=>{
19
+ const headers = createDefaultHeaders();
20
+ const keys = Object.keys(routes);
21
+ const all = keys.every((key)=>routes[key].length > 0);
22
+ if (all) headers.set("access-control-allow-methods", "*");
23
+ else {
24
+ const allowedMethods = keys.filter((type)=>{
25
+ if (!routes[type] || !Array.isArray(routes[type])) return false;
26
+ return routes[type].length > 0;
27
+ }).sort().join(",");
28
+ headers.set("access-control-allow-methods", allowedMethods);
29
+ }
30
+ return headers;
19
31
  };
20
- const getDefaultHeaders = routes => {
21
- const headers = createDefaultHeaders();
22
-
23
- /**
24
- * If we are accepting all headers, just output that one.
25
- */
26
- const keys = Object.keys(routes);
27
- const all = keys.every(key => routes[key].length > 0);
28
- if (all) {
29
- headers.set("access-control-allow-methods", "*");
30
- } else {
31
- const allowedMethods = keys.filter(type => {
32
- if (!routes[type] || !Array.isArray(routes[type])) {
33
- return false;
34
- }
35
- return routes[type].length > 0;
36
- }).sort().join(",");
37
- headers.set("access-control-allow-methods", allowedMethods);
38
- }
39
- return headers;
40
- };
41
- export class SetDefaultHeaders {
42
- constructor(definedRoutes) {
43
- this.definedRoutes = definedRoutes;
44
- }
45
- execute(request, reply) {
46
- const isOptionsRequest = request.method === "OPTIONS";
47
- /**
48
- * Our default headers are always set. Users can override them.
49
- */
50
- const defaultHeaders = getDefaultHeaders(this.definedRoutes);
51
- const initialHeaders = isOptionsRequest ? defaultHeaders.merge(getDefaultOptionsHeaders()) : defaultHeaders;
52
- reply.headers(initialHeaders.getHeaders());
53
- return Action.CONTINUE;
54
- }
32
+ class SetDefaultHeaders {
33
+ constructor(definedRoutes){
34
+ this.definedRoutes = definedRoutes;
35
+ }
36
+ execute(request, reply) {
37
+ const isOptionsRequest = "OPTIONS" === request.method;
38
+ const defaultHeaders = getDefaultHeaders(this.definedRoutes);
39
+ const initialHeaders = isOptionsRequest ? defaultHeaders.merge(getDefaultOptionsHeaders()) : defaultHeaders;
40
+ reply.headers(initialHeaders.getHeaders());
41
+ return Action.CONTINUE;
42
+ }
55
43
  }
44
+ export { SetDefaultHeaders };
56
45
 
57
46
  //# sourceMappingURL=SetDefaultHeaders.js.map