@webiny/handler 6.0.0-beta.0 β 6.0.0-rc.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.
- package/Context.d.ts +4 -3
- package/Context.js +6 -14
- package/Context.js.map +1 -1
- package/PreHandler/IPreHandler.d.ts +9 -0
- package/PreHandler/IPreHandler.js +7 -0
- package/PreHandler/IPreHandler.js.map +1 -0
- package/PreHandler/IfNotOptionsRequest.d.ts +9 -0
- package/PreHandler/IfNotOptionsRequest.js +21 -0
- package/PreHandler/IfNotOptionsRequest.js.map +1 -0
- package/PreHandler/IfOptionsRequest.d.ts +9 -0
- package/PreHandler/IfOptionsRequest.js +21 -0
- package/PreHandler/IfOptionsRequest.js.map +1 -0
- package/PreHandler/PreHandler.d.ts +9 -0
- package/PreHandler/PreHandler.js +17 -0
- package/PreHandler/PreHandler.js.map +1 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +10 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js +24 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -0
- package/PreHandler/ProcessContextPlugins.d.ts +10 -0
- package/PreHandler/ProcessContextPlugins.js +24 -0
- package/PreHandler/ProcessContextPlugins.js.map +1 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +10 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +26 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -0
- package/PreHandler/SendEarlyOptionsResponse.d.ts +9 -0
- package/PreHandler/SendEarlyOptionsResponse.js +31 -0
- package/PreHandler/SendEarlyOptionsResponse.js.map +1 -0
- package/PreHandler/SetDefaultHeaders.d.ts +9 -0
- package/PreHandler/SetDefaultHeaders.js +57 -0
- package/PreHandler/SetDefaultHeaders.js.map +1 -0
- package/README.md +10 -14
- package/ResponseHeaders.d.ts +6 -7
- package/ResponseHeaders.js +1 -8
- package/ResponseHeaders.js.map +1 -1
- package/abstractions/Reply.d.ts +5 -0
- package/abstractions/Reply.js +4 -0
- package/abstractions/Reply.js.map +1 -0
- package/abstractions/Request.d.ts +5 -0
- package/abstractions/Request.js +4 -0
- package/abstractions/Request.js.map +1 -0
- package/fastify.d.ts +6 -4
- package/fastify.js +170 -194
- package/fastify.js.map +1 -1
- package/index.d.ts +17 -12
- package/index.js +18 -126
- package/index.js.map +1 -1
- package/package.json +16 -24
- package/plugins/BeforeHandlerPlugin.d.ts +1 -1
- package/plugins/BeforeHandlerPlugin.js +3 -11
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.d.ts +3 -3
- package/plugins/EventPlugin.js +3 -12
- package/plugins/EventPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.d.ts +1 -1
- package/plugins/HandlerErrorPlugin.js +3 -11
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerOnRequestPlugin.d.ts +9 -8
- package/plugins/HandlerOnRequestPlugin.js +5 -12
- package/plugins/HandlerOnRequestPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.d.ts +1 -1
- package/plugins/HandlerResultPlugin.js +3 -11
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/ModifyFastifyPlugin.d.ts +2 -2
- package/plugins/ModifyFastifyPlugin.js +3 -11
- package/plugins/ModifyFastifyPlugin.js.map +1 -1
- package/plugins/ModifyResponseHeadersPlugin.d.ts +3 -3
- package/plugins/ModifyResponseHeadersPlugin.js +3 -11
- package/plugins/ModifyResponseHeadersPlugin.js.map +1 -1
- package/plugins/OnRequestResponseSendPlugin.d.ts +26 -0
- package/plugins/OnRequestResponseSendPlugin.js +31 -0
- package/plugins/OnRequestResponseSendPlugin.js.map +1 -0
- package/plugins/OnRequestTimeoutPlugin.d.ts +12 -0
- package/plugins/OnRequestTimeoutPlugin.js +16 -0
- package/plugins/OnRequestTimeoutPlugin.js.map +1 -0
- package/plugins/RoutePlugin.d.ts +2 -2
- package/plugins/RoutePlugin.js +3 -11
- package/plugins/RoutePlugin.js.map +1 -1
- package/stringifyError.d.ts +5 -0
- package/stringifyError.js +20 -0
- package/stringifyError.js.map +1 -0
- package/suppressPunycodeWarnings.d.ts +1 -0
- package/suppressPunycodeWarnings.js +10 -0
- package/suppressPunycodeWarnings.js.map +1 -0
- package/types.d.ts +9 -7
- package/types.js +1 -19
- package/types.js.map +1 -1
package/Context.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Context as
|
|
1
|
+
import type { ContextParams as BaseContextParams, ContextPluginCallable as BaseContextPluginCallable } from "@webiny/api";
|
|
2
|
+
import { Context as BaseContext, ContextPlugin as BaseContextPlugin } from "@webiny/api";
|
|
3
|
+
import type { Context as ContextInterface } from "./types.js";
|
|
3
4
|
export interface ContextParams extends BaseContextParams {
|
|
4
5
|
routes: ContextInterface["routes"];
|
|
5
6
|
}
|
|
@@ -15,7 +16,7 @@ export declare class Context extends BaseContext implements ContextInterface {
|
|
|
15
16
|
*
|
|
16
17
|
* This can be removed when we introduce the type augmentation.
|
|
17
18
|
*/
|
|
18
|
-
export
|
|
19
|
+
export type ContextPluginCallable<T extends ContextInterface = ContextInterface> = BaseContextPluginCallable<T>;
|
|
19
20
|
export declare class ContextPlugin<T extends ContextInterface = ContextInterface> extends BaseContextPlugin<T> {
|
|
20
21
|
}
|
|
21
22
|
export declare const createContextPlugin: <T extends ContextInterface = ContextInterface>(callable: ContextPluginCallable<T>) => BaseContextPlugin<T>;
|
package/Context.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createContextPlugin = exports.ContextPlugin = exports.Context = void 0;
|
|
7
|
-
var _api = require("@webiny/api");
|
|
8
|
-
class Context extends _api.Context {
|
|
1
|
+
import { Context as BaseContext, ContextPlugin as BaseContextPlugin, createContextPlugin as baseCreateContextPlugin } from "@webiny/api";
|
|
2
|
+
export class Context extends BaseContext {
|
|
9
3
|
// @ts-expect-error
|
|
10
4
|
|
|
11
5
|
// @ts-expect-error
|
|
@@ -23,12 +17,10 @@ class Context extends _api.Context {
|
|
|
23
17
|
*
|
|
24
18
|
* This can be removed when we introduce the type augmentation.
|
|
25
19
|
*/
|
|
26
|
-
|
|
27
|
-
class ContextPlugin extends
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return (0, _api.createContextPlugin)(callable);
|
|
20
|
+
|
|
21
|
+
export class ContextPlugin extends BaseContextPlugin {}
|
|
22
|
+
export const createContextPlugin = callable => {
|
|
23
|
+
return baseCreateContextPlugin(callable);
|
|
31
24
|
};
|
|
32
|
-
exports.createContextPlugin = createContextPlugin;
|
|
33
25
|
|
|
34
26
|
//# sourceMappingURL=Context.js.map
|
package/Context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { Context } from "../types.js";
|
|
3
|
+
export declare enum Action {
|
|
4
|
+
CONTINUE = "continue",
|
|
5
|
+
DONE = "done"
|
|
6
|
+
}
|
|
7
|
+
export interface IPreHandler {
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action> | Action;
|
|
9
|
+
}
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { IPreHandler } from "./IPreHandler.js";
|
|
3
|
+
import { Action } from "./IPreHandler.js";
|
|
4
|
+
import type { Context } from "../types.js";
|
|
5
|
+
export declare class IfNotOptionsRequest implements IPreHandler {
|
|
6
|
+
private readonly handlers;
|
|
7
|
+
constructor(handlers: IPreHandler[]);
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
10
|
+
}
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return Action.CONTINUE;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=IfNotOptionsRequest.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { IPreHandler } from "./IPreHandler.js";
|
|
3
|
+
import { Action } from "./IPreHandler.js";
|
|
4
|
+
import type { Context } from "../types.js";
|
|
5
|
+
export declare class IfOptionsRequest implements IPreHandler {
|
|
6
|
+
private readonly handlers;
|
|
7
|
+
constructor(handlers: IPreHandler[]);
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
10
|
+
}
|
|
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
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return Action.CONTINUE;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=IfOptionsRequest.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
3
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
4
|
+
import type { Context } from "../types.js";
|
|
5
|
+
export declare class PreHandler implements IPreHandler {
|
|
6
|
+
private readonly handlers;
|
|
7
|
+
constructor(handlers: IPreHandler[]);
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return Action.CONTINUE;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=PreHandler.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
2
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
3
|
+
import type { Context } from "../types.js";
|
|
4
|
+
import type { BeforeHandlerPlugin } from "../plugins/BeforeHandlerPlugin.js";
|
|
5
|
+
export declare class ProcessBeforeHandlerPlugins implements IPreHandler {
|
|
6
|
+
private readonly plugins;
|
|
7
|
+
private readonly context;
|
|
8
|
+
constructor(context: Context, plugins: BeforeHandlerPlugin[]);
|
|
9
|
+
execute(): Promise<Action>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Action } from "./IPreHandler.js";
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
return Action.CONTINUE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=ProcessBeforeHandlerPlugins.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
2
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
3
|
+
import type { ContextPlugin } from "../Context.js";
|
|
4
|
+
import type { Context } from "../types.js";
|
|
5
|
+
export declare class ProcessContextPlugins implements IPreHandler {
|
|
6
|
+
private readonly plugins;
|
|
7
|
+
private readonly context;
|
|
8
|
+
constructor(context: Context, plugins: ContextPlugin[]);
|
|
9
|
+
execute(): Promise<Action>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Action } from "./IPreHandler.js";
|
|
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;
|
|
19
|
+
}
|
|
20
|
+
return Action.CONTINUE;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=ProcessContextPlugins.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
3
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
4
|
+
import type { HandlerOnRequestPlugin } from "../plugins/HandlerOnRequestPlugin.js";
|
|
5
|
+
import type { Context } from "../types.js";
|
|
6
|
+
export declare class ProcessHandlerOnRequestPlugins implements IPreHandler {
|
|
7
|
+
private readonly plugins;
|
|
8
|
+
constructor(plugins: HandlerOnRequestPlugin[]);
|
|
9
|
+
execute(request: FastifyRequest, reply: FastifyReply, context: Context): Promise<Action>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Action } from "./IPreHandler.js";
|
|
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;
|
|
15
|
+
}
|
|
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;
|
|
21
|
+
}
|
|
22
|
+
return Action.CONTINUE;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=ProcessHandlerOnRequestPlugins.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
3
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
4
|
+
import type { ModifyResponseHeadersPlugin } from "../plugins/ModifyResponseHeadersPlugin.js";
|
|
5
|
+
export declare class SendEarlyOptionsResponse implements IPreHandler {
|
|
6
|
+
private readonly plugins;
|
|
7
|
+
constructor(plugins: ModifyResponseHeadersPlugin[]);
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply): Promise<Action>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Action } from "./IPreHandler.js";
|
|
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;
|
|
20
|
+
}
|
|
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
|
+
}
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=SendEarlyOptionsResponse.js.map
|
|
@@ -0,0 +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":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
2
|
+
import type { DefinedContextRoutes } from "../types.js";
|
|
3
|
+
import type { IPreHandler } from "../PreHandler/IPreHandler.js";
|
|
4
|
+
import { Action } from "../PreHandler/IPreHandler.js";
|
|
5
|
+
export declare class SetDefaultHeaders implements IPreHandler {
|
|
6
|
+
private readonly definedRoutes;
|
|
7
|
+
constructor(definedRoutes: DefinedContextRoutes);
|
|
8
|
+
execute(request: FastifyRequest, reply: FastifyReply): Action;
|
|
9
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getWebinyVersionHeaders } from "@webiny/utils";
|
|
2
|
+
import { ResponseHeaders } from "../ResponseHeaders.js";
|
|
3
|
+
import { Action } from "./IPreHandler.js";
|
|
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
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const getDefaultOptionsHeaders = () => {
|
|
15
|
+
return ResponseHeaders.create({
|
|
16
|
+
"access-control-max-age": "86400",
|
|
17
|
+
"cache-control": "public, max-age=86400"
|
|
18
|
+
});
|
|
19
|
+
};
|
|
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
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=SetDefaultHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getWebinyVersionHeaders","ResponseHeaders","Action","createDefaultHeaders","create","getDefaultOptionsHeaders","getDefaultHeaders","routes","headers","keys","Object","all","every","key","length","set","allowedMethods","filter","type","Array","isArray","sort","join","SetDefaultHeaders","constructor","definedRoutes","execute","request","reply","isOptionsRequest","method","defaultHeaders","initialHeaders","merge","getHeaders","CONTINUE"],"sources":["SetDefaultHeaders.ts"],"sourcesContent":["import type { FastifyReply, FastifyRequest } from \"fastify\";\nimport { getWebinyVersionHeaders } from \"@webiny/utils\";\nimport { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport type { DefinedContextRoutes, HTTPMethods } from \"~/types.js\";\nimport type { IPreHandler } from \"~/PreHandler/IPreHandler.js\";\nimport { Action } from \"~/PreHandler/IPreHandler.js\";\n\nfunction createDefaultHeaders() {\n return ResponseHeaders.create({\n \"content-type\": \"application/json; charset=utf-8\",\n \"cache-control\": \"no-store\",\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}\n\nconst getDefaultOptionsHeaders = () => {\n return ResponseHeaders.create({\n \"access-control-max-age\": \"86400\",\n \"cache-control\": \"public, max-age=86400\"\n });\n};\n\nconst getDefaultHeaders = (routes: DefinedContextRoutes): ResponseHeaders => {\n const headers = createDefaultHeaders();\n\n /**\n * If we are accepting all headers, just output that one.\n */\n const keys = Object.keys(routes) as HTTPMethods[];\n const all = keys.every(key => routes[key].length > 0);\n if (all) {\n headers.set(\"access-control-allow-methods\", \"*\");\n } else {\n const allowedMethods = keys\n .filter(type => {\n if (!routes[type] || !Array.isArray(routes[type])) {\n return false;\n }\n return routes[type].length > 0;\n })\n .sort()\n .join(\",\");\n\n headers.set(\"access-control-allow-methods\", allowedMethods);\n }\n\n return headers;\n};\n\nexport class SetDefaultHeaders implements IPreHandler {\n private readonly definedRoutes: DefinedContextRoutes;\n\n constructor(definedRoutes: DefinedContextRoutes) {\n this.definedRoutes = definedRoutes;\n }\n\n execute(request: FastifyRequest, reply: FastifyReply) {\n const isOptionsRequest = request.method === \"OPTIONS\";\n /**\n * Our default headers are always set. Users can override them.\n */\n const defaultHeaders = getDefaultHeaders(this.definedRoutes);\n\n const initialHeaders = isOptionsRequest\n ? defaultHeaders.merge(getDefaultOptionsHeaders())\n : defaultHeaders;\n\n reply.headers(initialHeaders.getHeaders());\n\n return Action.CONTINUE;\n }\n}\n"],"mappings":"AACA,SAASA,uBAAuB,QAAQ,eAAe;AACvD,SAASC,eAAe;AAGxB,SAASC,MAAM;AAEf,SAASC,oBAAoBA,CAAA,EAAG;EAC5B,OAAOF,eAAe,CAACG,MAAM,CAAC;IAC1B,cAAc,EAAE,iCAAiC;IACjD,eAAe,EAAE,UAAU;IAC3B,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,GAAG;IACnC,8BAA8B,EAAE,mCAAmC;IACnE,GAAGJ,uBAAuB,CAAC;EAC/B,CAAC,CAAC;AACN;AAEA,MAAMK,wBAAwB,GAAGA,CAAA,KAAM;EACnC,OAAOJ,eAAe,CAACG,MAAM,CAAC;IAC1B,wBAAwB,EAAE,OAAO;IACjC,eAAe,EAAE;EACrB,CAAC,CAAC;AACN,CAAC;AAED,MAAME,iBAAiB,GAAIC,MAA4B,IAAsB;EACzE,MAAMC,OAAO,GAAGL,oBAAoB,CAAC,CAAC;;EAEtC;AACJ;AACA;EACI,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACF,MAAM,CAAkB;EACjD,MAAMI,GAAG,GAAGF,IAAI,CAACG,KAAK,CAACC,GAAG,IAAIN,MAAM,CAACM,GAAG,CAAC,CAACC,MAAM,GAAG,CAAC,CAAC;EACrD,IAAIH,GAAG,EAAE;IACLH,OAAO,CAACO,GAAG,CAAC,8BAA8B,EAAE,GAAG,CAAC;EACpD,CAAC,MAAM;IACH,MAAMC,cAAc,GAAGP,IAAI,CACtBQ,MAAM,CAACC,IAAI,IAAI;MACZ,IAAI,CAACX,MAAM,CAACW,IAAI,CAAC,IAAI,CAACC,KAAK,CAACC,OAAO,CAACb,MAAM,CAACW,IAAI,CAAC,CAAC,EAAE;QAC/C,OAAO,KAAK;MAChB;MACA,OAAOX,MAAM,CAACW,IAAI,CAAC,CAACJ,MAAM,GAAG,CAAC;IAClC,CAAC,CAAC,CACDO,IAAI,CAAC,CAAC,CACNC,IAAI,CAAC,GAAG,CAAC;IAEdd,OAAO,CAACO,GAAG,CAAC,8BAA8B,EAAEC,cAAc,CAAC;EAC/D;EAEA,OAAOR,OAAO;AAClB,CAAC;AAED,OAAO,MAAMe,iBAAiB,CAAwB;EAGlDC,WAAWA,CAACC,aAAmC,EAAE;IAC7C,IAAI,CAACA,aAAa,GAAGA,aAAa;EACtC;EAEAC,OAAOA,CAACC,OAAuB,EAAEC,KAAmB,EAAE;IAClD,MAAMC,gBAAgB,GAAGF,OAAO,CAACG,MAAM,KAAK,SAAS;IACrD;AACR;AACA;IACQ,MAAMC,cAAc,GAAGzB,iBAAiB,CAAC,IAAI,CAACmB,aAAa,CAAC;IAE5D,MAAMO,cAAc,GAAGH,gBAAgB,GACjCE,cAAc,CAACE,KAAK,CAAC5B,wBAAwB,CAAC,CAAC,CAAC,GAChD0B,cAAc;IAEpBH,KAAK,CAACpB,OAAO,CAACwB,cAAc,CAACE,UAAU,CAAC,CAAC,CAAC;IAE1C,OAAOhC,MAAM,CAACiC,QAAQ;EAC1B;AACJ","ignoreList":[]}
|
package/README.md
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
# @webiny/handler
|
|
2
|
-
|
|
3
|
-
[!
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
Or if you prefer yarn:
|
|
13
|
-
```
|
|
14
|
-
yarn add @webiny/handler
|
|
15
|
-
```
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> Itβs **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
6
|
+
|
|
7
|
+
π **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/ResponseHeaders.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
declare type ExtraHeaders = {
|
|
1
|
+
import type * as http from "http";
|
|
2
|
+
type ExtraHeaders = {
|
|
4
3
|
"content-type"?: string | undefined;
|
|
5
4
|
"x-webiny-version"?: http.OutgoingHttpHeader | undefined;
|
|
6
5
|
};
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
export
|
|
6
|
+
type AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;
|
|
7
|
+
export type StandardHeaderValue = http.OutgoingHttpHeader | undefined;
|
|
8
|
+
export type StandardHeaders = {
|
|
10
9
|
[K in keyof AllHeaders as string extends K ? never : number extends K ? never : K]: http.OutgoingHttpHeaders[K];
|
|
11
10
|
} & {
|
|
12
11
|
[name: string]: StandardHeaderValue;
|
|
13
12
|
};
|
|
14
|
-
|
|
13
|
+
type Setter<T> = ((value: T) => T) | T;
|
|
15
14
|
export declare class ResponseHeaders {
|
|
16
15
|
private readonly headers;
|
|
17
16
|
private constructor();
|
package/ResponseHeaders.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ResponseHeaders = void 0;
|
|
7
1
|
// Extract known standard headers, and remove all non-string keys.
|
|
8
2
|
|
|
9
3
|
function isFunction(setter) {
|
|
10
4
|
return typeof setter === "function";
|
|
11
5
|
}
|
|
12
|
-
class ResponseHeaders {
|
|
6
|
+
export class ResponseHeaders {
|
|
13
7
|
headers = new Map();
|
|
14
8
|
constructor(initialHeaders) {
|
|
15
9
|
if (initialHeaders) {
|
|
@@ -41,6 +35,5 @@ class ResponseHeaders {
|
|
|
41
35
|
return new ResponseHeaders(initialHeaders);
|
|
42
36
|
}
|
|
43
37
|
}
|
|
44
|
-
exports.ResponseHeaders = ResponseHeaders;
|
|
45
38
|
|
|
46
39
|
//# sourceMappingURL=ResponseHeaders.js.map
|
package/ResponseHeaders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries"
|
|
1
|
+
{"version":3,"names":["isFunction","setter","ResponseHeaders","headers","Map","constructor","initialHeaders","Object","keys","forEach","key","set","header","previousValue","get","newValue","merge","create","getHeaders","fromEntries"],"sources":["ResponseHeaders.ts"],"sourcesContent":["import type * as http from \"http\";\n\ntype ExtraHeaders = {\n \"content-type\"?: string | undefined;\n \"x-webiny-version\"?: http.OutgoingHttpHeader | undefined;\n};\n\ntype AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;\n\nexport type StandardHeaderValue = http.OutgoingHttpHeader | undefined;\n\n// Extract known standard headers, and remove all non-string keys.\nexport type StandardHeaders = {\n [K in keyof AllHeaders as string extends K\n ? never\n : number extends K\n ? never\n : K]: http.OutgoingHttpHeaders[K];\n} & {\n [name: string]: StandardHeaderValue;\n};\n\nfunction isFunction<T>(setter: unknown): setter is (value: T) => T {\n return typeof setter === \"function\";\n}\n\ntype Setter<T> = ((value: T) => T) | T;\n\nexport class ResponseHeaders {\n private readonly headers = new Map<keyof StandardHeaders, StandardHeaderValue>();\n\n private constructor(initialHeaders?: StandardHeaders) {\n if (initialHeaders) {\n (Object.keys(initialHeaders) as Array<keyof StandardHeaders>).forEach(key => {\n this.headers.set(key, initialHeaders[key]);\n });\n }\n }\n\n set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>) {\n if (isFunction<StandardHeaders[T]>(setter)) {\n const previousValue = this.headers.get(header) as StandardHeaders[T];\n const newValue = setter(previousValue);\n this.headers.set(header, newValue);\n return this;\n }\n\n this.headers.set(header, setter);\n\n return this;\n }\n\n merge(headers: ResponseHeaders) {\n return ResponseHeaders.create({ ...this.getHeaders(), ...headers.getHeaders() });\n }\n\n getHeaders() {\n return Object.fromEntries(this.headers);\n }\n\n static create(initialHeaders?: StandardHeaders) {\n return new ResponseHeaders(initialHeaders);\n }\n}\n"],"mappings":"AAWA;;AAWA,SAASA,UAAUA,CAAIC,MAAe,EAA6B;EAC/D,OAAO,OAAOA,MAAM,KAAK,UAAU;AACvC;AAIA,OAAO,MAAMC,eAAe,CAAC;EACRC,OAAO,GAAG,IAAIC,GAAG,CAA6C,CAAC;EAExEC,WAAWA,CAACC,cAAgC,EAAE;IAClD,IAAIA,cAAc,EAAE;MACfC,MAAM,CAACC,IAAI,CAACF,cAAc,CAAC,CAAkCG,OAAO,CAACC,GAAG,IAAI;QACzE,IAAI,CAACP,OAAO,CAACQ,GAAG,CAACD,GAAG,EAAEJ,cAAc,CAACI,GAAG,CAAC,CAAC;MAC9C,CAAC,CAAC;IACN;EACJ;EAEAC,GAAGA,CAAkCC,MAAS,EAAEX,MAAkC,EAAE;IAChF,IAAID,UAAU,CAAqBC,MAAM,CAAC,EAAE;MACxC,MAAMY,aAAa,GAAG,IAAI,CAACV,OAAO,CAACW,GAAG,CAACF,MAAM,CAAuB;MACpE,MAAMG,QAAQ,GAAGd,MAAM,CAACY,aAAa,CAAC;MACtC,IAAI,CAACV,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEG,QAAQ,CAAC;MAClC,OAAO,IAAI;IACf;IAEA,IAAI,CAACZ,OAAO,CAACQ,GAAG,CAACC,MAAM,EAAEX,MAAM,CAAC;IAEhC,OAAO,IAAI;EACf;EAEAe,KAAKA,CAACb,OAAwB,EAAE;IAC5B,OAAOD,eAAe,CAACe,MAAM,CAAC;MAAE,GAAG,IAAI,CAACC,UAAU,CAAC,CAAC;MAAE,GAAGf,OAAO,CAACe,UAAU,CAAC;IAAE,CAAC,CAAC;EACpF;EAEAA,UAAUA,CAAA,EAAG;IACT,OAAOX,MAAM,CAACY,WAAW,CAAC,IAAI,CAAChB,OAAO,CAAC;EAC3C;EAEA,OAAOc,MAAMA,CAACX,cAAgC,EAAE;IAC5C,OAAO,IAAIJ,eAAe,CAACI,cAAc,CAAC;EAC9C;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","Reply"],"sources":["Reply.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Reply as IReply } from \"~/types.js\";\n\nexport const Reply = createAbstraction<IReply>(\"Reply\");\n\nexport namespace Reply {\n export type Interface = IReply;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAGvD,OAAO,MAAMC,KAAK,GAAGD,iBAAiB,CAAS,OAAO,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createAbstraction","Request"],"sources":["Request.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Request as IRequest } from \"~/types.js\";\n\nexport const Request = createAbstraction<IRequest>(\"Request\");\n\nexport namespace Request {\n export type Interface = IRequest;\n}\n"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAGvD,OAAO,MAAMC,OAAO,GAAGD,iBAAiB,CAAW,SAAS,CAAC","ignoreList":[]}
|