@webiny/handler 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.3fddf667ea
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/ResponseHeaders.js +29 -32
- package/ResponseHeaders.js.map +1 -1
- package/abstractions/Reply.js +2 -1
- package/abstractions/Reply.js.map +1 -1
- package/abstractions/Request.js +2 -1
- package/abstractions/Request.js.map +1 -1
- package/exports/api.d.ts +0 -0
- package/exports/api.js +0 -0
- package/index.d.ts +4 -15
- package/index.js +3 -18
- package/package.json +16 -17
- package/plugins/RegisterExtensionPlugin.d.ts +36 -0
- package/plugins/RegisterExtensionPlugin.js +38 -0
- package/plugins/RegisterExtensionPlugin.js.map +1 -0
- package/stringifyError.js +12 -17
- package/stringifyError.js.map +1 -1
- package/types.d.ts +21 -43
- package/types.js +0 -3
- package/Context.d.ts +0 -22
- package/Context.js +0 -26
- package/Context.js.map +0 -1
- package/PreHandler/IPreHandler.d.ts +0 -9
- package/PreHandler/IPreHandler.js +0 -7
- package/PreHandler/IPreHandler.js.map +0 -1
- package/PreHandler/IfNotOptionsRequest.d.ts +0 -9
- package/PreHandler/IfNotOptionsRequest.js +0 -21
- package/PreHandler/IfNotOptionsRequest.js.map +0 -1
- package/PreHandler/IfOptionsRequest.d.ts +0 -9
- package/PreHandler/IfOptionsRequest.js +0 -21
- package/PreHandler/IfOptionsRequest.js.map +0 -1
- package/PreHandler/PreHandler.d.ts +0 -9
- package/PreHandler/PreHandler.js +0 -17
- package/PreHandler/PreHandler.js.map +0 -1
- package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +0 -10
- package/PreHandler/ProcessBeforeHandlerPlugins.js +0 -24
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +0 -1
- package/PreHandler/ProcessContextPlugins.d.ts +0 -10
- package/PreHandler/ProcessContextPlugins.js +0 -24
- package/PreHandler/ProcessContextPlugins.js.map +0 -1
- package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +0 -10
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +0 -26
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +0 -1
- package/PreHandler/SendEarlyOptionsResponse.d.ts +0 -9
- package/PreHandler/SendEarlyOptionsResponse.js +0 -31
- package/PreHandler/SendEarlyOptionsResponse.js.map +0 -1
- package/PreHandler/SetDefaultHeaders.d.ts +0 -9
- package/PreHandler/SetDefaultHeaders.js +0 -57
- package/PreHandler/SetDefaultHeaders.js.map +0 -1
- package/fastify.d.ts +0 -11
- package/fastify.js +0 -443
- package/fastify.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/BeforeHandlerPlugin.d.ts +0 -12
- package/plugins/BeforeHandlerPlugin.js +0 -19
- package/plugins/BeforeHandlerPlugin.js.map +0 -1
- package/plugins/EventPlugin.d.ts +0 -25
- package/plugins/EventPlugin.js +0 -21
- package/plugins/EventPlugin.js.map +0 -1
- package/plugins/HandlerErrorPlugin.d.ts +0 -15
- package/plugins/HandlerErrorPlugin.js +0 -16
- package/plugins/HandlerErrorPlugin.js.map +0 -1
- package/plugins/HandlerOnRequestPlugin.d.ts +0 -21
- package/plugins/HandlerOnRequestPlugin.js +0 -24
- package/plugins/HandlerOnRequestPlugin.js.map +0 -1
- package/plugins/HandlerResultPlugin.d.ts +0 -12
- package/plugins/HandlerResultPlugin.js +0 -16
- package/plugins/HandlerResultPlugin.js.map +0 -1
- package/plugins/ModifyFastifyPlugin.d.ts +0 -13
- package/plugins/ModifyFastifyPlugin.js +0 -16
- package/plugins/ModifyFastifyPlugin.js.map +0 -1
- package/plugins/ModifyResponseHeadersPlugin.d.ts +0 -14
- package/plugins/ModifyResponseHeadersPlugin.js +0 -16
- package/plugins/ModifyResponseHeadersPlugin.js.map +0 -1
- package/plugins/OnRequestResponseSendPlugin.d.ts +0 -26
- package/plugins/OnRequestResponseSendPlugin.js +0 -31
- package/plugins/OnRequestResponseSendPlugin.js.map +0 -1
- package/plugins/OnRequestTimeoutPlugin.d.ts +0 -12
- package/plugins/OnRequestTimeoutPlugin.js +0 -16
- package/plugins/OnRequestTimeoutPlugin.js.map +0 -1
- package/plugins/RoutePlugin.d.ts +0 -23
- package/plugins/RoutePlugin.js +0 -13
- package/plugins/RoutePlugin.js.map +0 -1
- package/suppressPunycodeWarnings.d.ts +0 -1
- package/suppressPunycodeWarnings.js +0 -10
- package/suppressPunycodeWarnings.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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/fastify.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { PluginCollection } from "@webiny/plugins/types.js";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins/types.js";
|
|
3
|
-
import type { FastifyInstance, FastifyServerOptions as ServerOptions } from "fastify";
|
|
4
|
-
export interface CreateHandlerParams {
|
|
5
|
-
plugins: PluginCollection | PluginsContainer;
|
|
6
|
-
options?: ServerOptions;
|
|
7
|
-
debug?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare const createHandler: (params: CreateHandlerParams) => FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>> & {
|
|
10
|
-
__linterBrands: "SafePromiseLike";
|
|
11
|
-
};
|