@webiny/handler 0.0.0-unstable.085ff6572f β†’ 0.0.0-unstable.0d717d18dd

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 (55) hide show
  1. package/README.md +10 -14
  2. package/ResponseHeaders.d.ts +24 -0
  3. package/ResponseHeaders.js +36 -0
  4. package/ResponseHeaders.js.map +1 -0
  5. package/abstractions/Reply.d.ts +5 -0
  6. package/abstractions/Reply.js +5 -0
  7. package/abstractions/Reply.js.map +1 -0
  8. package/abstractions/Request.d.ts +5 -0
  9. package/abstractions/Request.js +5 -0
  10. package/abstractions/Request.js.map +1 -0
  11. package/exports/api.d.ts +0 -0
  12. package/exports/api.js +0 -0
  13. package/index.d.ts +6 -9
  14. package/index.js +5 -104
  15. package/package.json +18 -28
  16. package/plugins/RegisterExtensionPlugin.d.ts +22 -0
  17. package/plugins/RegisterExtensionPlugin.js +24 -0
  18. package/plugins/RegisterExtensionPlugin.js.map +1 -0
  19. package/stringifyError.d.ts +5 -0
  20. package/stringifyError.js +15 -0
  21. package/stringifyError.js.map +1 -0
  22. package/types.d.ts +21 -46
  23. package/types.js +0 -18
  24. package/Context.d.ts +0 -23
  25. package/Context.js +0 -40
  26. package/Context.js.map +0 -1
  27. package/fastify.d.ts +0 -8
  28. package/fastify.js +0 -427
  29. package/fastify.js.map +0 -1
  30. package/index.js.map +0 -1
  31. package/middleware.d.ts +0 -4
  32. package/middleware.js +0 -45
  33. package/middleware.js.map +0 -1
  34. package/plugins/BeforeHandlerPlugin.d.ts +0 -12
  35. package/plugins/BeforeHandlerPlugin.js +0 -28
  36. package/plugins/BeforeHandlerPlugin.js.map +0 -1
  37. package/plugins/EventPlugin.d.ts +0 -25
  38. package/plugins/EventPlugin.js +0 -31
  39. package/plugins/EventPlugin.js.map +0 -1
  40. package/plugins/HandlerErrorPlugin.d.ts +0 -12
  41. package/plugins/HandlerErrorPlugin.js +0 -25
  42. package/plugins/HandlerErrorPlugin.js.map +0 -1
  43. package/plugins/HandlerOnRequestPlugin.d.ts +0 -20
  44. package/plugins/HandlerOnRequestPlugin.js +0 -25
  45. package/plugins/HandlerOnRequestPlugin.js.map +0 -1
  46. package/plugins/HandlerResultPlugin.d.ts +0 -12
  47. package/plugins/HandlerResultPlugin.js +0 -25
  48. package/plugins/HandlerResultPlugin.js.map +0 -1
  49. package/plugins/ModifyFastifyPlugin.d.ts +0 -13
  50. package/plugins/ModifyFastifyPlugin.js +0 -25
  51. package/plugins/ModifyFastifyPlugin.js.map +0 -1
  52. package/plugins/RoutePlugin.d.ts +0 -23
  53. package/plugins/RoutePlugin.js +0 -22
  54. package/plugins/RoutePlugin.js.map +0 -1
  55. package/types.js.map +0 -1
package/README.md CHANGED
@@ -1,15 +1,11 @@
1
1
  # @webiny/handler
2
- [![](https://img.shields.io/npm/dw/@webiny/handler.svg)](https://www.npmjs.com/package/@webiny/handler)
3
- [![](https://img.shields.io/npm/v/@webiny/handler.svg)](https://www.npmjs.com/package/@webiny/handler)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
-
7
- ## Install
8
- ```
9
- npm install --save @webiny/handler
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._
@@ -0,0 +1,24 @@
1
+ import type * as http from "http";
2
+ type ExtraHeaders = {
3
+ "content-type"?: string | undefined;
4
+ "x-webiny-version"?: http.OutgoingHttpHeader | undefined;
5
+ };
6
+ type AllHeaders = http.OutgoingHttpHeaders & ExtraHeaders;
7
+ export type StandardHeaderValue = http.OutgoingHttpHeader | undefined;
8
+ export type StandardHeaders = {
9
+ [K in keyof AllHeaders as string extends K ? never : number extends K ? never : K]: http.OutgoingHttpHeaders[K];
10
+ } & {
11
+ [name: string]: StandardHeaderValue;
12
+ };
13
+ type Setter<T> = ((value: T) => T) | T;
14
+ export declare class ResponseHeaders {
15
+ private readonly headers;
16
+ private constructor();
17
+ set<T extends keyof StandardHeaders>(header: T, setter: Setter<StandardHeaders[T]>): this;
18
+ merge(headers: ResponseHeaders): ResponseHeaders;
19
+ getHeaders(): {
20
+ [k: string]: StandardHeaderValue;
21
+ };
22
+ static create(initialHeaders?: StandardHeaders): ResponseHeaders;
23
+ }
24
+ export {};
@@ -0,0 +1,36 @@
1
+ function isFunction(setter) {
2
+ return "function" == typeof setter;
3
+ }
4
+ class ResponseHeaders {
5
+ constructor(initialHeaders){
6
+ this.headers = new Map();
7
+ if (initialHeaders) Object.keys(initialHeaders).forEach((key)=>{
8
+ this.headers.set(key, initialHeaders[key]);
9
+ });
10
+ }
11
+ set(header, setter) {
12
+ if (isFunction(setter)) {
13
+ const previousValue = this.headers.get(header);
14
+ const newValue = setter(previousValue);
15
+ this.headers.set(header, newValue);
16
+ return this;
17
+ }
18
+ this.headers.set(header, setter);
19
+ return this;
20
+ }
21
+ merge(headers) {
22
+ return ResponseHeaders.create({
23
+ ...this.getHeaders(),
24
+ ...headers.getHeaders()
25
+ });
26
+ }
27
+ getHeaders() {
28
+ return Object.fromEntries(this.headers);
29
+ }
30
+ static create(initialHeaders) {
31
+ return new ResponseHeaders(initialHeaders);
32
+ }
33
+ }
34
+ export { ResponseHeaders };
35
+
36
+ //# sourceMappingURL=ResponseHeaders.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponseHeaders.js","sources":["../src/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"],"names":["isFunction","setter","ResponseHeaders","initialHeaders","Map","Object","key","header","previousValue","newValue","headers"],"mappings":"AAsBA,SAASA,WAAcC,MAAe;IAClC,OAAO,AAAkB,cAAlB,OAAOA;AAClB;AAIO,MAAMC;IAGT,YAAoBC,cAAgC,CAAE;aAFrC,OAAO,GAAG,IAAIC;QAG3B,IAAID,gBACCE,OAAO,IAAI,CAACF,gBAAiD,OAAO,CAACG,CAAAA;YAClE,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,KAAKH,cAAc,CAACG,IAAI;QAC7C;IAER;IAEA,IAAqCC,MAAS,EAAEN,MAAkC,EAAE;QAChF,IAAID,WAA+BC,SAAS;YACxC,MAAMO,gBAAgB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD;YACvC,MAAME,WAAWR,OAAOO;YACxB,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,QAAQE;YACzB,OAAO,IAAI;QACf;QAEA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACF,QAAQN;QAEzB,OAAO,IAAI;IACf;IAEA,MAAMS,OAAwB,EAAE;QAC5B,OAAOR,gBAAgB,MAAM,CAAC;YAAE,GAAG,IAAI,CAAC,UAAU,EAAE;YAAE,GAAGQ,QAAQ,UAAU,EAAE;QAAC;IAClF;IAEA,aAAa;QACT,OAAOL,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO;IAC1C;IAEA,OAAO,OAAOF,cAAgC,EAAE;QAC5C,OAAO,IAAID,gBAAgBC;IAC/B;AACJ"}
@@ -0,0 +1,5 @@
1
+ import type { Reply as IReply } from "../types.js";
2
+ export declare const Reply: import("@webiny/di").Abstraction<IReply>;
3
+ export declare namespace Reply {
4
+ type Interface = IReply;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const Reply = createAbstraction("Reply");
3
+ export { Reply };
4
+
5
+ //# sourceMappingURL=Reply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractions/Reply.js","sources":["../../src/abstractions/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"],"names":["Reply","createAbstraction"],"mappings":";AAGO,MAAMA,QAAQC,kBAA0B"}
@@ -0,0 +1,5 @@
1
+ import type { Request as IRequest } from "../types.js";
2
+ export declare const Request: import("@webiny/di").Abstraction<IRequest>;
3
+ export declare namespace Request {
4
+ type Interface = IRequest;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const Request = createAbstraction("Request");
3
+ export { Request };
4
+
5
+ //# sourceMappingURL=Request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstractions/Request.js","sources":["../../src/abstractions/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"],"names":["Request","createAbstraction"],"mappings":";AAGO,MAAMA,UAAUC,kBAA4B"}
File without changes
package/exports/api.js ADDED
File without changes
package/index.d.ts CHANGED
@@ -1,9 +1,6 @@
1
- export * from "./fastify";
2
- export * from "./Context";
3
- export * from "./plugins/EventPlugin";
4
- export * from "./plugins/RoutePlugin";
5
- export * from "./plugins/BeforeHandlerPlugin";
6
- export * from "./plugins/HandlerErrorPlugin";
7
- export * from "./plugins/HandlerResultPlugin";
8
- export * from "./plugins/HandlerOnRequestPlugin";
9
- export * from "./plugins/ModifyFastifyPlugin";
1
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions } from "./plugins/RegisterExtensionPlugin.js";
2
+ export { stringifyError } from "./stringifyError.js";
3
+ export { Request } from "./abstractions/Request.js";
4
+ export { Reply } from "./abstractions/Reply.js";
5
+ export { ResponseHeaders } from "./ResponseHeaders.js";
6
+ export type { StandardHeaders, StandardHeaderValue } from "./ResponseHeaders.js";
package/index.js CHANGED
@@ -1,104 +1,5 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _fastify = require("./fastify");
7
- Object.keys(_fastify).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _fastify[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _fastify[key];
14
- }
15
- });
16
- });
17
- var _Context = require("./Context");
18
- Object.keys(_Context).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Context[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _Context[key];
25
- }
26
- });
27
- });
28
- var _EventPlugin = require("./plugins/EventPlugin");
29
- Object.keys(_EventPlugin).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _EventPlugin[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _EventPlugin[key];
36
- }
37
- });
38
- });
39
- var _RoutePlugin = require("./plugins/RoutePlugin");
40
- Object.keys(_RoutePlugin).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _RoutePlugin[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _RoutePlugin[key];
47
- }
48
- });
49
- });
50
- var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
51
- Object.keys(_BeforeHandlerPlugin).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _BeforeHandlerPlugin[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _BeforeHandlerPlugin[key];
58
- }
59
- });
60
- });
61
- var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
62
- Object.keys(_HandlerErrorPlugin).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _HandlerErrorPlugin[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _HandlerErrorPlugin[key];
69
- }
70
- });
71
- });
72
- var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
73
- Object.keys(_HandlerResultPlugin).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _HandlerResultPlugin[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _HandlerResultPlugin[key];
80
- }
81
- });
82
- });
83
- var _HandlerOnRequestPlugin = require("./plugins/HandlerOnRequestPlugin");
84
- Object.keys(_HandlerOnRequestPlugin).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _HandlerOnRequestPlugin[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _HandlerOnRequestPlugin[key];
91
- }
92
- });
93
- });
94
- var _ModifyFastifyPlugin = require("./plugins/ModifyFastifyPlugin");
95
- Object.keys(_ModifyFastifyPlugin).forEach(function (key) {
96
- if (key === "default" || key === "__esModule") return;
97
- if (key in exports && exports[key] === _ModifyFastifyPlugin[key]) return;
98
- Object.defineProperty(exports, key, {
99
- enumerable: true,
100
- get: function () {
101
- return _ModifyFastifyPlugin[key];
102
- }
103
- });
104
- });
1
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions } from "./plugins/RegisterExtensionPlugin.js";
2
+ export { stringifyError } from "./stringifyError.js";
3
+ export { Request } from "./abstractions/Request.js";
4
+ export { Reply } from "./abstractions/Reply.js";
5
+ export { ResponseHeaders } from "./ResponseHeaders.js";
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/handler",
3
- "version": "0.0.0-unstable.085ff6572f",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -12,35 +16,21 @@
12
16
  ],
13
17
  "license": "MIT",
14
18
  "dependencies": {
15
- "@babel/runtime": "7.20.13",
16
- "@fastify/compress": "6.2.0",
17
- "@fastify/cookie": "8.3.0",
18
- "@webiny/api": "0.0.0-unstable.085ff6572f",
19
- "@webiny/error": "0.0.0-unstable.085ff6572f",
20
- "@webiny/handler-client": "0.0.0-unstable.085ff6572f",
21
- "@webiny/plugins": "0.0.0-unstable.085ff6572f",
22
- "@webiny/utils": "0.0.0-unstable.085ff6572f",
23
- "fastify": "4.11.0"
19
+ "@webiny/di": "1.0.2",
20
+ "@webiny/feature": "0.0.0-unstable.0d717d18dd",
21
+ "@webiny/plugins": "0.0.0-unstable.0d717d18dd"
24
22
  },
25
23
  "devDependencies": {
26
- "@babel/cli": "7.20.7",
27
- "@babel/core": "7.20.12",
28
- "@babel/preset-env": "7.20.2",
29
- "@babel/preset-typescript": "7.18.6",
30
- "@webiny/cli": "0.0.0-unstable.085ff6572f",
31
- "@webiny/project-utils": "0.0.0-unstable.085ff6572f",
32
- "babel-plugin-lodash": "3.3.4",
33
- "rimraf": "3.0.2",
34
- "ttypescript": "1.5.15",
35
- "typescript": "4.7.4"
24
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
25
+ "rimraf": "6.1.3",
26
+ "typescript": "7.0.2",
27
+ "vitest": "4.1.10"
36
28
  },
37
29
  "publishConfig": {
38
- "access": "public",
39
- "directory": "dist"
40
- },
41
- "scripts": {
42
- "build": "yarn webiny run build",
43
- "watch": "yarn webiny run watch"
30
+ "access": "public"
44
31
  },
45
- "gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
32
+ "gitHead": "8476da73b653c89cc1474d968baf55c1b0ae0e5f",
33
+ "webiny": {
34
+ "publishFrom": "dist"
35
+ }
46
36
  }
@@ -0,0 +1,22 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ import type { Container } from "@webiny/di";
3
+ import type { Context } from "../types.js";
4
+ export interface IRegisterExtensionPluginCb<C extends Context = Context> {
5
+ (context: C): Promise<void> | void;
6
+ }
7
+ export declare class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {
8
+ private readonly cb;
9
+ static readonly type: string;
10
+ constructor(cb: IRegisterExtensionPluginCb<C>);
11
+ apply(context: C): Promise<void> | void;
12
+ }
13
+ export declare const createRegisterExtensionPlugin: <C extends Context = Context>(cb: IRegisterExtensionPluginCb<C>) => RegisterExtensionPlugin<C>;
14
+ /**
15
+ * Apply RegisterExtensionPlugins at register() time β€” synchronously with the request container,
16
+ * BEFORE any RequestContextInitializer runs. Each plugin's callback only does DI registration via
17
+ * registerExtension(ctx.container, ...) (feature/decorator/registration), which is register-time
18
+ * safe. Doing this early is important for code-defined CMS models (ModelFactory): a later
19
+ * initializer (e.g. ACO) lists + caches the model set per request, so any model registered after
20
+ * that β€” as happened when extensions ran via the post-auth initializer β€” was silently missing.
21
+ */
22
+ export declare function registerExtensions(container: Container, plugins: unknown | unknown[]): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { Plugin } from "@webiny/plugins";
2
+ class RegisterExtensionPlugin extends Plugin {
3
+ static{
4
+ this.type = "handler.register.extension";
5
+ }
6
+ constructor(cb){
7
+ super(), this.cb = cb;
8
+ }
9
+ apply(context) {
10
+ return this.cb(context);
11
+ }
12
+ }
13
+ const createRegisterExtensionPlugin = (cb)=>new RegisterExtensionPlugin(cb);
14
+ async function registerExtensions(container, plugins) {
15
+ const flat = [
16
+ plugins
17
+ ].flat(1 / 0).filter(Boolean);
18
+ for (const plugin of flat)if (plugin?.type === RegisterExtensionPlugin.type && "function" == typeof plugin.apply) await plugin.apply({
19
+ container
20
+ });
21
+ }
22
+ export { RegisterExtensionPlugin, createRegisterExtensionPlugin, registerExtensions };
23
+
24
+ //# sourceMappingURL=RegisterExtensionPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins/RegisterExtensionPlugin.js","sources":["../../src/plugins/RegisterExtensionPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Container } from \"@webiny/di\";\nimport type { Context } from \"~/types.js\";\n\nexport interface IRegisterExtensionPluginCb<C extends Context = Context> {\n (context: C): Promise<void> | void;\n}\n\nexport class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.register.extension\";\n\n public constructor(private readonly cb: IRegisterExtensionPluginCb<C>) {\n super();\n }\n\n public apply(context: C): Promise<void> | void {\n return this.cb(context);\n }\n}\n\nexport const createRegisterExtensionPlugin = <C extends Context = Context>(\n cb: IRegisterExtensionPluginCb<C>\n) => {\n return new RegisterExtensionPlugin<C>(cb);\n};\n\n/**\n * Apply RegisterExtensionPlugins at register() time β€” synchronously with the request container,\n * BEFORE any RequestContextInitializer runs. Each plugin's callback only does DI registration via\n * registerExtension(ctx.container, ...) (feature/decorator/registration), which is register-time\n * safe. Doing this early is important for code-defined CMS models (ModelFactory): a later\n * initializer (e.g. ACO) lists + caches the model set per request, so any model registered after\n * that β€” as happened when extensions ran via the post-auth initializer β€” was silently missing.\n */\nexport async function registerExtensions(\n container: Container,\n plugins: unknown | unknown[]\n): Promise<void> {\n const flat = [plugins].flat(Infinity as 1).filter(Boolean) as RegisterExtensionPlugin[];\n for (const plugin of flat) {\n if (plugin?.type === RegisterExtensionPlugin.type && typeof plugin.apply === \"function\") {\n await plugin.apply({ container } as unknown as Context);\n }\n }\n}\n"],"names":["RegisterExtensionPlugin","Plugin","cb","context","createRegisterExtensionPlugin","registerExtensions","container","plugins","flat","Infinity","Boolean","plugin"],"mappings":";AAQO,MAAMA,gCAA6DC;;aACtC,IAAI,GAAW;;IAE/C,YAAoCC,EAAiC,CAAE;QACnE,KAAK,SAD2BA,EAAE,GAAFA;IAEpC;IAEO,MAAMC,OAAU,EAAwB;QAC3C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAEO,MAAMC,gCAAgC,CACzCF,KAEO,IAAIF,wBAA2BE;AAWnC,eAAeG,mBAClBC,SAAoB,EACpBC,OAA4B;IAE5B,MAAMC,OAAO;QAACD;KAAQ,CAAC,IAAI,CAACE,OAAe,MAAM,CAACC;IAClD,KAAK,MAAMC,UAAUH,KACjB,IAAIG,QAAQ,SAASX,wBAAwB,IAAI,IAAI,AAAwB,cAAxB,OAAOW,OAAO,KAAK,EACpE,MAAMA,OAAO,KAAK,CAAC;QAAEL;IAAU;AAG3C"}
@@ -0,0 +1,5 @@
1
+ export interface CustomError extends Error {
2
+ code?: string;
3
+ data?: Record<string, any>;
4
+ }
5
+ export declare const stringifyError: (error: CustomError) => string;
@@ -0,0 +1,15 @@
1
+ const stringifyError = (error)=>{
2
+ const { name, message, code, stack, data } = error;
3
+ return JSON.stringify({
4
+ ...error,
5
+ constructorName: error.constructor?.name || "UnknownError",
6
+ name: name || "No error name",
7
+ message: message || "No error message",
8
+ code: code || "NO_CODE",
9
+ data,
10
+ stack: "true" === process.env.DEBUG ? stack : "Turn on the debug flag to see the stack."
11
+ });
12
+ };
13
+ export { stringifyError };
14
+
15
+ //# sourceMappingURL=stringifyError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringifyError.js","sources":["../src/stringifyError.ts"],"sourcesContent":["export interface CustomError extends Error {\n code?: string;\n data?: Record<string, any>;\n}\n\nexport const stringifyError = (error: CustomError) => {\n const { name, message, code, stack, data } = error;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n"],"names":["stringifyError","error","name","message","code","stack","data","JSON","process"],"mappings":"AAKO,MAAMA,iBAAiB,CAACC;IAC3B,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGL;IAC7C,OAAOM,KAAK,SAAS,CAAC;QAClB,GAAGN,KAAK;QACR,iBAAiBA,MAAM,WAAW,EAAE,QAAQ;QAC5C,MAAMC,QAAQ;QACd,SAASC,WAAW;QACpB,MAAMC,QAAQ;QACdE;QACA,OAAOE,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,GAAcH,QAAQ;IAClD;AACJ"}
package/types.d.ts CHANGED
@@ -1,49 +1,24 @@
1
- import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
2
- export { FastifyInstance, HTTPMethods } from "fastify";
3
- import { ClientContext } from "@webiny/handler-client/types";
4
- export interface RouteMethodOptions {
5
- override?: boolean;
1
+ import type { Container } from "@webiny/feature/api";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ export interface Request {
4
+ url?: string;
5
+ method?: string;
6
+ headers: Record<string, string | undefined>;
7
+ body?: unknown;
8
+ params?: Record<string, string>;
9
+ query?: Record<string, string | string[]>;
10
+ path?: string;
11
+ [key: string]: unknown;
6
12
  }
7
- export declare type RouteMethodPath = `/${string}` | "*";
8
- export interface RouteMethod {
9
- (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
13
+ export interface Reply {
14
+ send(data?: unknown): void | Promise<void>;
15
+ code(statusCode: number): Reply;
16
+ headers(headers: Record<string, string>): Reply;
17
+ header(name: string, value: string): Reply;
18
+ setCookie(name: string, value: string, options?: Record<string, unknown>): Reply;
19
+ [key: string]: unknown;
10
20
  }
11
- export declare type Request = FastifyRequest;
12
- export declare type Reply = FastifyReply;
13
- export declare type DefinedContextRoutes = Record<HTTPMethods, string[]>;
14
- export interface ContextRoutes {
15
- defined: DefinedContextRoutes;
16
- onGet: RouteMethod;
17
- onPost: RouteMethod;
18
- onPut: RouteMethod;
19
- onPatch: RouteMethod;
20
- onDelete: RouteMethod;
21
- onOptions: RouteMethod;
22
- onAll: RouteMethod;
23
- onHead: RouteMethod;
24
- }
25
- export interface Context extends ClientContext {
26
- /**
27
- * An instance of fastify server.
28
- * Use at your own risk.
29
- * @instance
30
- */
31
- server: FastifyInstance;
32
- /**
33
- * Current request. Must be set only once!
34
- */
35
- request: FastifyRequest;
36
- /**
37
- * Current reply. Must be set only once!
38
- */
39
- reply: FastifyReply;
40
- /**
41
- * @internal
42
- */
43
- routes: ContextRoutes;
44
- }
45
- declare module "fastify" {
46
- interface FastifyInstance {
47
- webiny: Context;
48
- }
21
+ export interface Context {
22
+ plugins: PluginsContainer;
23
+ container: Container;
49
24
  }
package/types.js CHANGED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "FastifyInstance", {
7
- enumerable: true,
8
- get: function () {
9
- return _fastify.FastifyInstance;
10
- }
11
- });
12
- Object.defineProperty(exports, "HTTPMethods", {
13
- enumerable: true,
14
- get: function () {
15
- return _fastify.HTTPMethods;
16
- }
17
- });
18
- var _fastify = require("fastify");
package/Context.d.ts DELETED
@@ -1,23 +0,0 @@
1
- import { Context as BaseContext, ContextParams as BaseContextParams, ContextPlugin as BaseContextPlugin, ContextPluginCallable as BaseContextPluginCallable } from "@webiny/api";
2
- import { Context as ContextInterface } from "./types";
3
- export interface ContextParams extends BaseContextParams {
4
- server: ContextInterface["server"];
5
- routes: ContextInterface["routes"];
6
- }
7
- export declare class Context extends BaseContext implements ContextInterface {
8
- readonly server: ContextInterface["server"];
9
- readonly routes: ContextInterface["routes"];
10
- handlerClient: ContextInterface["handlerClient"];
11
- request: ContextInterface["request"];
12
- reply: ContextInterface["reply"];
13
- constructor(params: ContextParams);
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
- export declare type ContextPluginCallable<T extends ContextInterface = ContextInterface> = BaseContextPluginCallable<T>;
21
- export declare class ContextPlugin<T extends ContextInterface = ContextInterface> extends BaseContextPlugin<T> {
22
- }
23
- export declare const createContextPlugin: <T extends ContextInterface = ContextInterface>(callable: ContextPluginCallable<T>) => BaseContextPlugin<T>;
package/Context.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createContextPlugin = exports.ContextPlugin = exports.Context = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _api = require("@webiny/api");
10
- class Context extends _api.Context {
11
- // @ts-ignore
12
-
13
- // @ts-ignore
14
-
15
- // @ts-ignore
16
-
17
- constructor(params) {
18
- super(params);
19
- (0, _defineProperty2.default)(this, "server", void 0);
20
- (0, _defineProperty2.default)(this, "routes", void 0);
21
- (0, _defineProperty2.default)(this, "handlerClient", void 0);
22
- (0, _defineProperty2.default)(this, "request", void 0);
23
- (0, _defineProperty2.default)(this, "reply", void 0);
24
- this.server = params.server;
25
- this.routes = params.routes;
26
- }
27
- }
28
-
29
- /**
30
- * We need to extend and reexport the ContextPlugin, ContextPluginCallable and createContextPlugin to support extended context.
31
- *
32
- * This can be removed when we introduce the type augmentation.
33
- */
34
- exports.Context = Context;
35
- class ContextPlugin extends _api.ContextPlugin {}
36
- exports.ContextPlugin = ContextPlugin;
37
- const createContextPlugin = callable => {
38
- return (0, _api.createContextPlugin)(callable);
39
- };
40
- exports.createContextPlugin = createContextPlugin;
package/Context.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["Context","BaseContext","constructor","params","server","routes","ContextPlugin","BaseContextPlugin","createContextPlugin","callable","baseCreateContextPlugin"],"sources":["Context.ts"],"sourcesContent":["import {\n Context as BaseContext,\n ContextParams as BaseContextParams,\n ContextPlugin as BaseContextPlugin,\n ContextPluginCallable as BaseContextPluginCallable,\n createContextPlugin as baseCreateContextPlugin\n} from \"@webiny/api\";\nimport { Context as ContextInterface } from \"~/types\";\n\nexport interface ContextParams extends BaseContextParams {\n server: ContextInterface[\"server\"];\n routes: ContextInterface[\"routes\"];\n}\n\nexport class Context extends BaseContext implements ContextInterface {\n public readonly server: ContextInterface[\"server\"];\n public readonly routes: ContextInterface[\"routes\"];\n // @ts-ignore\n public handlerClient: ContextInterface[\"handlerClient\"];\n // @ts-ignore\n public request: ContextInterface[\"request\"];\n // @ts-ignore\n public reply: ContextInterface[\"reply\"];\n\n public constructor(params: ContextParams) {\n super(params);\n this.server = params.server;\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":";;;;;;;;AAAA;AAcO,MAAMA,OAAO,SAASC,YAAW,CAA6B;EAGjE;;EAEA;;EAEA;;EAGOC,WAAW,CAACC,MAAqB,EAAE;IACtC,KAAK,CAACA,MAAM,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IACd,IAAI,CAACC,MAAM,GAAGD,MAAM,CAACC,MAAM;IAC3B,IAAI,CAACC,MAAM,GAAGF,MAAM,CAACE,MAAM;EAC/B;AACJ;;AAEA;AACA;AACA;AACA;AACA;AAJA;AAQO,MAAMC,aAAa,SAEhBC,kBAAiB,CAAI;AAAE;AAE1B,MAAMC,mBAAmB,GAC5BC,QAAkC,IACjC;EACD,OAAO,IAAAC,wBAAuB,EAAID,QAAQ,CAAC;AAC/C,CAAC;AAAC"}
package/fastify.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { PluginCollection } from "@webiny/plugins/types";
3
- import { FastifyServerOptions as ServerOptions } from "fastify";
4
- export interface CreateHandlerParams {
5
- plugins: PluginCollection;
6
- options?: ServerOptions;
7
- }
8
- export declare const createHandler: (params: CreateHandlerParams) => import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>>;