@webiny/event-handler-core 6.6.0-alpha.0 → 6.6.0-alpha.2

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 (72) hide show
  1. package/exports/api.d.ts +2 -0
  2. package/exports/api.js +1 -0
  3. package/features/events/ChildContainerFactory.d.ts +11 -0
  4. package/features/events/ChildContainerFactory.js +25 -0
  5. package/features/events/ChildContainerFactory.js.map +1 -0
  6. package/features/events/HandlerApp.d.ts +27 -0
  7. package/features/events/HandlerApp.js +53 -0
  8. package/features/events/HandlerApp.js.map +1 -0
  9. package/features/events/RootContainerFactory.d.ts +12 -0
  10. package/features/events/RootContainerFactory.js +24 -0
  11. package/features/events/RootContainerFactory.js.map +1 -0
  12. package/features/events/abstractions.d.ts +60 -0
  13. package/features/events/abstractions.js +7 -0
  14. package/features/events/abstractions.js.map +1 -0
  15. package/features/events/index.d.ts +4 -4
  16. package/features/events/index.js +4 -4
  17. package/features/http/HttpResponseBuilder.d.ts +36 -0
  18. package/features/http/HttpResponseBuilder.js +133 -0
  19. package/features/http/HttpResponseBuilder.js.map +1 -0
  20. package/features/http/HttpRouter.d.ts +17 -3
  21. package/features/http/HttpRouter.js +24 -17
  22. package/features/http/HttpRouter.js.map +1 -1
  23. package/features/http/HttpStreamBody.d.ts +34 -0
  24. package/features/http/HttpStreamBody.js +44 -0
  25. package/features/http/HttpStreamBody.js.map +1 -0
  26. package/features/http/abstractions.d.ts +154 -3
  27. package/features/http/abstractions.js +3 -2
  28. package/features/http/abstractions.js.map +1 -1
  29. package/features/http/createHttpRouteDefinition.d.ts +17 -0
  30. package/features/http/createHttpRouteDefinition.js +18 -0
  31. package/features/http/createHttpRouteDefinition.js.map +1 -0
  32. package/features/http/decorators/CompressionDecorator.d.ts +28 -0
  33. package/features/http/decorators/CompressionDecorator.js +66 -0
  34. package/features/http/decorators/CompressionDecorator.js.map +1 -0
  35. package/features/http/decorators/SecureHeadersDecorator.js +1 -1
  36. package/features/http/decorators/SecureHeadersDecorator.js.map +1 -1
  37. package/features/http/decorators/index.d.ts +1 -0
  38. package/features/http/decorators/index.js +1 -0
  39. package/features/http/feature.js +2 -2
  40. package/features/http/feature.js.map +1 -1
  41. package/features/http/index.d.ts +5 -0
  42. package/features/http/index.js +5 -0
  43. package/features/http/invokeHttpRoute.d.ts +17 -0
  44. package/features/http/invokeHttpRoute.js +32 -0
  45. package/features/http/invokeHttpRoute.js.map +1 -0
  46. package/features/http/toSseFrame.d.ts +10 -0
  47. package/features/http/toSseFrame.js +6 -0
  48. package/features/http/toSseFrame.js.map +1 -0
  49. package/features/testing/createTestHttpHandler.d.ts +1 -1
  50. package/features/testing/createTestHttpHandler.js +4 -4
  51. package/features/testing/createTestHttpHandler.js.map +1 -1
  52. package/features/testing/index.d.ts +1 -0
  53. package/features/testing/index.js +1 -0
  54. package/features/testing/registerHttpRouteInstance.d.ts +16 -0
  55. package/features/testing/registerHttpRouteInstance.js +27 -0
  56. package/features/testing/registerHttpRouteInstance.js.map +1 -0
  57. package/package.json +6 -6
  58. package/features/events/RequestContextInitializer.d.ts +0 -26
  59. package/features/events/RequestContextInitializer.js +0 -5
  60. package/features/events/RequestContextInitializer.js.map +0 -1
  61. package/features/events/RequestInitializer.d.ts +0 -22
  62. package/features/events/RequestInitializer.js +0 -5
  63. package/features/events/RequestInitializer.js.map +0 -1
  64. package/features/events/createHandler.d.ts +0 -20
  65. package/features/events/createHandler.js +0 -41
  66. package/features/events/createHandler.js.map +0 -1
  67. package/features/events/runRequestContextInitializers.d.ts +0 -20
  68. package/features/events/runRequestContextInitializers.js +0 -16
  69. package/features/events/runRequestContextInitializers.js.map +0 -1
  70. package/features/http/decorators/RequestContextInitializerDecorator.d.ts +0 -20
  71. package/features/http/decorators/RequestContextInitializerDecorator.js +0 -22
  72. package/features/http/decorators/RequestContextInitializerDecorator.js.map +0 -1
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Frame one value as a server-sent-events `data:` record.
3
+ *
4
+ * The SSE wire format, not any one feature's protocol: a record is `data: <payload>` followed by the
5
+ * blank line that terminates it. What goes IN the payload — the event names and their fields — is per
6
+ * feature and belongs with that feature.
7
+ *
8
+ * Counterpart to `readServerSentEvents` in `@webiny/app`, which parses these on the client.
9
+ */
10
+ export declare function toSseFrame(data: unknown): string;
@@ -0,0 +1,6 @@
1
+ function toSseFrame(data) {
2
+ return `data: ${JSON.stringify(data)}\n\n`;
3
+ }
4
+ export { toSseFrame };
5
+
6
+ //# sourceMappingURL=toSseFrame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/http/toSseFrame.js","sources":["../../../src/features/http/toSseFrame.ts"],"sourcesContent":["/**\n * Frame one value as a server-sent-events `data:` record.\n *\n * The SSE wire format, not any one feature's protocol: a record is `data: <payload>` followed by the\n * blank line that terminates it. What goes IN the payload — the event names and their fields — is per\n * feature and belongs with that feature.\n *\n * Counterpart to `readServerSentEvents` in `@webiny/app`, which parses these on the client.\n */\nexport function toSseFrame(data: unknown): string {\n return `data: ${JSON.stringify(data)}\\n\\n`;\n}\n"],"names":["toSseFrame","data","JSON"],"mappings":"AASO,SAASA,WAAWC,IAAa;IACpC,OAAO,CAAC,MAAM,EAAEC,KAAK,SAAS,CAACD,MAAM,IAAI,CAAC;AAC9C"}
@@ -1,7 +1,7 @@
1
1
  import type { HandlerSetup, IHttpRequest, IHttpResponse } from "../../index.js";
2
2
  export interface createTestHttpHandlerOptions {
3
3
  root: HandlerSetup;
4
- request?: HandlerSetup;
4
+ child?: HandlerSetup;
5
5
  }
6
6
  /**
7
7
  * Test handler that accepts IHttpRequest directly and returns IHttpResponse.
@@ -1,18 +1,18 @@
1
1
  import { HttpFeature } from "../http/feature.js";
2
2
  import { HttpRouterHandler } from "./HttpRouterHandler.js";
3
- import { createHandler } from "../events/createHandler.js";
3
+ import { HandlerApp } from "../events/HandlerApp.js";
4
4
  import { TestHttpEventType } from "./TestHttpEventType.js";
5
5
  function createTestHttpHandler(options) {
6
- const invoke = createHandler({
6
+ const app = HandlerApp.init({
7
7
  root: async (container)=>{
8
8
  container.register(TestHttpEventType);
9
9
  container.register(HttpRouterHandler);
10
10
  HttpFeature.register(container);
11
11
  await options.root(container);
12
12
  },
13
- request: options.request
13
+ child: options.child
14
14
  });
15
- return async (request)=>invoke({
15
+ return async (request)=>app.handle({
16
16
  method: request.method,
17
17
  path: request.path,
18
18
  headers: request.headers ?? {},
@@ -1 +1 @@
1
- {"version":3,"file":"features/testing/createTestHttpHandler.js","sources":["../../../src/features/testing/createTestHttpHandler.ts"],"sourcesContent":["import { HttpFeature } from \"~/features/http/feature.js\";\nimport { HttpRouterHandler } from \"./HttpRouterHandler.js\";\nimport { createHandler } from \"~/features/events/createHandler.js\";\nimport { TestHttpEventType } from \"./TestHttpEventType.js\";\nimport type { HandlerSetup, IHttpRequest, IHttpResponse } from \"~/index.js\";\n\nexport interface createTestHttpHandlerOptions {\n root: HandlerSetup;\n request?: HandlerSetup;\n}\n\n/**\n * Test handler that accepts IHttpRequest directly and returns IHttpResponse.\n * Registers HttpRouterHandler as the base TestHttpEventHandler implementation.\n * Callers layer middleware on top via container.registerDecorator() in options.root.\n */\nexport function createTestHttpHandler(options: createTestHttpHandlerOptions) {\n const invoke = createHandler({\n root: async container => {\n container.register(TestHttpEventType);\n container.register(HttpRouterHandler);\n HttpFeature.register(container);\n await options.root(container);\n },\n request: options.request\n });\n\n return async (\n request: Partial<IHttpRequest> & { method: string; path: string }\n ): Promise<IHttpResponse> => {\n return invoke({\n method: request.method,\n path: request.path,\n headers: request.headers ?? {},\n query: request.query ?? {},\n pathParameters: request.pathParameters ?? {},\n body: request.body\n });\n };\n}\n"],"names":["createTestHttpHandler","options","invoke","createHandler","container","TestHttpEventType","HttpRouterHandler","HttpFeature","request"],"mappings":";;;;AAgBO,SAASA,sBAAsBC,OAAqC;IACvE,MAAMC,SAASC,cAAc;QACzB,MAAM,OAAMC;YACRA,UAAU,QAAQ,CAACC;YACnBD,UAAU,QAAQ,CAACE;YACnBC,YAAY,QAAQ,CAACH;YACrB,MAAMH,QAAQ,IAAI,CAACG;QACvB;QACA,SAASH,QAAQ,OAAO;IAC5B;IAEA,OAAO,OACHO,UAEON,OAAO;YACV,QAAQM,QAAQ,MAAM;YACtB,MAAMA,QAAQ,IAAI;YAClB,SAASA,QAAQ,OAAO,IAAI,CAAC;YAC7B,OAAOA,QAAQ,KAAK,IAAI,CAAC;YACzB,gBAAgBA,QAAQ,cAAc,IAAI,CAAC;YAC3C,MAAMA,QAAQ,IAAI;QACtB;AAER"}
1
+ {"version":3,"file":"features/testing/createTestHttpHandler.js","sources":["../../../src/features/testing/createTestHttpHandler.ts"],"sourcesContent":["import { HttpFeature } from \"~/features/http/feature.js\";\nimport { HttpRouterHandler } from \"./HttpRouterHandler.js\";\nimport { HandlerApp } from \"~/features/events/HandlerApp.js\";\nimport { TestHttpEventType } from \"./TestHttpEventType.js\";\nimport type { HandlerSetup, IHttpRequest, IHttpResponse } from \"~/index.js\";\n\nexport interface createTestHttpHandlerOptions {\n root: HandlerSetup;\n child?: HandlerSetup;\n}\n\n/**\n * Test handler that accepts IHttpRequest directly and returns IHttpResponse.\n * Registers HttpRouterHandler as the base TestHttpEventHandler implementation.\n * Callers layer middleware on top via container.registerDecorator() in options.root.\n */\nexport function createTestHttpHandler(options: createTestHttpHandlerOptions) {\n const app = HandlerApp.init({\n root: async container => {\n container.register(TestHttpEventType);\n container.register(HttpRouterHandler);\n HttpFeature.register(container);\n await options.root(container);\n },\n child: options.child\n });\n\n return async (\n request: Partial<IHttpRequest> & { method: string; path: string }\n ): Promise<IHttpResponse> => {\n return app.handle({\n method: request.method,\n path: request.path,\n headers: request.headers ?? {},\n query: request.query ?? {},\n pathParameters: request.pathParameters ?? {},\n body: request.body\n });\n };\n}\n"],"names":["createTestHttpHandler","options","app","HandlerApp","container","TestHttpEventType","HttpRouterHandler","HttpFeature","request"],"mappings":";;;;AAgBO,SAASA,sBAAsBC,OAAqC;IACvE,MAAMC,MAAMC,WAAW,IAAI,CAAC;QACxB,MAAM,OAAMC;YACRA,UAAU,QAAQ,CAACC;YACnBD,UAAU,QAAQ,CAACE;YACnBC,YAAY,QAAQ,CAACH;YACrB,MAAMH,QAAQ,IAAI,CAACG;QACvB;QACA,OAAOH,QAAQ,KAAK;IACxB;IAEA,OAAO,OACHO,UAEON,IAAI,MAAM,CAAC;YACd,QAAQM,QAAQ,MAAM;YACtB,MAAMA,QAAQ,IAAI;YAClB,SAASA,QAAQ,OAAO,IAAI,CAAC;YAC7B,OAAOA,QAAQ,KAAK,IAAI,CAAC;YACzB,gBAAgBA,QAAQ,cAAc,IAAI,CAAC;YAC3C,MAAMA,QAAQ,IAAI;QACtB;AAER"}
@@ -2,3 +2,4 @@ export * from "./TestHttpEventHandler.js";
2
2
  export * from "./TestHttpEventType.js";
3
3
  export * from "./HttpRouterHandler.js";
4
4
  export * from "./createTestHttpHandler.js";
5
+ export * from "./registerHttpRouteInstance.js";
@@ -2,3 +2,4 @@ export * from "./TestHttpEventHandler.js";
2
2
  export * from "./TestHttpEventType.js";
3
3
  export * from "./HttpRouterHandler.js";
4
4
  export * from "./createTestHttpHandler.js";
5
+ export * from "./registerHttpRouteInstance.js";
@@ -0,0 +1,16 @@
1
+ import type { Container } from "@webiny/di";
2
+ import type { IHttpRoute } from "../../features/http/abstractions.js";
3
+ export interface IRegisterHttpRouteInstanceParams {
4
+ readonly name?: string;
5
+ readonly method: string;
6
+ readonly path: string;
7
+ readonly route: IHttpRoute;
8
+ }
9
+ /**
10
+ * Registers a definition pointing at an ALREADY-BUILT route object.
11
+ *
12
+ * For tests that hand-roll a route as a literal. The router builds routes from a class, so the
13
+ * literal is wrapped in a zero-dependency one that delegates to it. Production code declares its
14
+ * class with `HttpRouteHandler.createImplementation` and points the definition straight at it.
15
+ */
16
+ export declare function registerHttpRouteInstance(container: Container, params: IRegisterHttpRouteInstanceParams): void;
@@ -0,0 +1,27 @@
1
+ import { HttpRouteDefinition, HttpRouteHandler } from "../http/abstractions.js";
2
+ function registerHttpRouteInstance(container, params) {
3
+ class DelegatingRoute {
4
+ handle(request, response) {
5
+ return Promise.resolve(params.route.handle(request, response));
6
+ }
7
+ }
8
+ const handler = HttpRouteHandler.createImplementation({
9
+ implementation: DelegatingRoute,
10
+ dependencies: []
11
+ });
12
+ class DelegatingRouteDefinition {
13
+ constructor(){
14
+ this.name = params.name ?? `test:${params.method}${params.path}`;
15
+ this.method = params.method;
16
+ this.path = params.path;
17
+ this.handler = handler;
18
+ }
19
+ }
20
+ container.register(HttpRouteDefinition.createImplementation({
21
+ implementation: DelegatingRouteDefinition,
22
+ dependencies: []
23
+ }));
24
+ }
25
+ export { registerHttpRouteInstance };
26
+
27
+ //# sourceMappingURL=registerHttpRouteInstance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/testing/registerHttpRouteInstance.js","sources":["../../../src/features/testing/registerHttpRouteInstance.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { HttpRouteDefinition, HttpRouteHandler } from \"~/features/http/abstractions.js\";\nimport type {\n IHttpRequest,\n IHttpResponse,\n IHttpResponseBuilder\n} from \"~/features/http/abstractions.js\";\nimport type { IHttpRoute } from \"~/features/http/abstractions.js\";\n\nexport interface IRegisterHttpRouteInstanceParams {\n readonly name?: string;\n readonly method: string;\n readonly path: string;\n readonly route: IHttpRoute;\n}\n\n/**\n * Registers a definition pointing at an ALREADY-BUILT route object.\n *\n * For tests that hand-roll a route as a literal. The router builds routes from a class, so the\n * literal is wrapped in a zero-dependency one that delegates to it. Production code declares its\n * class with `HttpRouteHandler.createImplementation` and points the definition straight at it.\n */\nexport function registerHttpRouteInstance(\n container: Container,\n params: IRegisterHttpRouteInstanceParams\n): void {\n class DelegatingRoute implements HttpRouteHandler.Interface {\n handle(\n request: IHttpRequest,\n response: IHttpResponseBuilder\n ): Promise<IHttpResponse | IHttpResponseBuilder | void> {\n return Promise.resolve(params.route.handle(request, response));\n }\n }\n\n const handler = HttpRouteHandler.createImplementation({\n implementation: DelegatingRoute,\n dependencies: []\n });\n\n class DelegatingRouteDefinition implements HttpRouteDefinition.Interface {\n readonly name = params.name ?? `test:${params.method}${params.path}`;\n readonly method = params.method;\n readonly path = params.path;\n readonly handler = handler;\n }\n\n container.register(\n HttpRouteDefinition.createImplementation({\n implementation: DelegatingRouteDefinition,\n dependencies: []\n })\n );\n}\n"],"names":["registerHttpRouteInstance","container","params","DelegatingRoute","request","response","Promise","handler","HttpRouteHandler","DelegatingRouteDefinition","HttpRouteDefinition"],"mappings":";AAuBO,SAASA,0BACZC,SAAoB,EACpBC,MAAwC;IAExC,MAAMC;QACF,OACIC,OAAqB,EACrBC,QAA8B,EACsB;YACpD,OAAOC,QAAQ,OAAO,CAACJ,OAAO,KAAK,CAAC,MAAM,CAACE,SAASC;QACxD;IACJ;IAEA,MAAME,UAAUC,iBAAiB,oBAAoB,CAAC;QAClD,gBAAgBL;QAChB,cAAc,EAAE;IACpB;IAEA,MAAMM;;iBACO,IAAI,GAAGP,OAAO,IAAI,IAAI,CAAC,KAAK,EAAEA,OAAO,MAAM,GAAGA,OAAO,IAAI,EAAE;iBAC3D,MAAM,GAAGA,OAAO,MAAM;iBACtB,IAAI,GAAGA,OAAO,IAAI;iBAClB,OAAO,GAAGK;;IACvB;IAEAN,UAAU,QAAQ,CACdS,oBAAoB,oBAAoB,CAAC;QACrC,gBAAgBD;QAChB,cAAc,EAAE;IACpB;AAER"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/event-handler-core",
3
- "version": "6.6.0-alpha.0",
3
+ "version": "6.6.0-alpha.2",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -18,17 +18,17 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@webiny/feature": "6.6.0-alpha.0"
21
+ "@webiny/feature": "6.6.0-alpha.2"
22
22
  },
23
23
  "peerDependencies": {
24
- "@webiny/di": "1.0.2"
24
+ "@webiny/di": "1.1.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@webiny/build-tools": "6.6.0-alpha.0",
28
- "@webiny/di": "1.0.2",
27
+ "@webiny/build-tools": "6.6.0-alpha.2",
28
+ "@webiny/di": "1.1.0",
29
29
  "rimraf": "6.1.3",
30
30
  "typescript": "7.0.2",
31
- "vitest": "4.1.10"
31
+ "vitest": "4.1.11"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -1,26 +0,0 @@
1
- import { Abstraction } from "@webiny/di";
2
- /**
3
- * Per-request, POST-auth initialization hook. Runs after the request's tenant/identity have been
4
- * established (in the route, before the schema is built and before resolvers), so unlike
5
- * {@link RequestInitializer} (which runs pre-auth) it can do tenant/identity-dependent setup.
6
- *
7
- * Use it for per-request work that must happen before resolvers and that genuinely can't be a lazy
8
- * DI factory — e.g. resolving a per-tenant content model (async), registering decorators that must
9
- * precede the resolvers they wrap, or building a dynamic, model-derived GraphQL schema.
10
- *
11
- * - For pre-auth, tenant-agnostic per-request setup, use {@link RequestInitializer}.
12
- * - For tenant/identity-dependent capabilities that can be built on demand, prefer a lazy DI factory.
13
- *
14
- * It contributes no schema content; its only product is the side effect of init(ctx). Multiple
15
- * initializers may be registered; they run in registration order.
16
- *
17
- * NOTE: despite living in event-handler-core, the current runners are the GraphQL routes
18
- * (GraphQLEngine + the CMS route). Making it run for non-GraphQL transports is a separate step.
19
- */
20
- export interface IRequestContextInitializer {
21
- init(ctx: Record<string, any>): void | Promise<void>;
22
- }
23
- export declare const RequestContextInitializer: Abstraction<IRequestContextInitializer>;
24
- export declare namespace RequestContextInitializer {
25
- type Interface = IRequestContextInitializer;
26
- }
@@ -1,5 +0,0 @@
1
- import { Abstraction } from "@webiny/di";
2
- const RequestContextInitializer = new Abstraction("RequestContextInitializer");
3
- export { RequestContextInitializer };
4
-
5
- //# sourceMappingURL=RequestContextInitializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/events/RequestContextInitializer.js","sources":["../../../src/features/events/RequestContextInitializer.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\n/**\n * Per-request, POST-auth initialization hook. Runs after the request's tenant/identity have been\n * established (in the route, before the schema is built and before resolvers), so unlike\n * {@link RequestInitializer} (which runs pre-auth) it can do tenant/identity-dependent setup.\n *\n * Use it for per-request work that must happen before resolvers and that genuinely can't be a lazy\n * DI factory — e.g. resolving a per-tenant content model (async), registering decorators that must\n * precede the resolvers they wrap, or building a dynamic, model-derived GraphQL schema.\n *\n * - For pre-auth, tenant-agnostic per-request setup, use {@link RequestInitializer}.\n * - For tenant/identity-dependent capabilities that can be built on demand, prefer a lazy DI factory.\n *\n * It contributes no schema content; its only product is the side effect of init(ctx). Multiple\n * initializers may be registered; they run in registration order.\n *\n * NOTE: despite living in event-handler-core, the current runners are the GraphQL routes\n * (GraphQLEngine + the CMS route). Making it run for non-GraphQL transports is a separate step.\n */\nexport interface IRequestContextInitializer {\n init(ctx: Record<string, any>): void | Promise<void>;\n}\n\nexport const RequestContextInitializer = new Abstraction<IRequestContextInitializer>(\n \"RequestContextInitializer\"\n);\n\nexport namespace RequestContextInitializer {\n export type Interface = IRequestContextInitializer;\n}\n"],"names":["RequestContextInitializer","Abstraction"],"mappings":";AAwBO,MAAMA,4BAA4B,IAAIC,YACzC"}
@@ -1,22 +0,0 @@
1
- import { Abstraction } from "@webiny/di";
2
- /**
3
- * Per-request async initialization hook. Runs once per request, after the request container is set
4
- * up (options.request) and BEFORE the event is dispatched to its handler chain — i.e. before
5
- * auth/tenant are established.
6
- *
7
- * Use it for async, tenant-agnostic, per-request setup that must be ready before synchronous
8
- * consumers run, and that can change between requests (e.g. loading the WCP project license).
9
- *
10
- * - For tenant/identity-dependent state, use a lazy DI factory instead (resolved during request
11
- * handling, after auth has run).
12
- * - For build-once async setup (a process-lifetime singleton), use a RootInitializer.
13
- *
14
- * Multiple initializers may be registered; they run in registration order.
15
- */
16
- export interface IRequestInitializer {
17
- init(): void | Promise<void>;
18
- }
19
- export declare const RequestInitializer: Abstraction<IRequestInitializer>;
20
- export declare namespace RequestInitializer {
21
- type Interface = IRequestInitializer;
22
- }
@@ -1,5 +0,0 @@
1
- import { Abstraction } from "@webiny/di";
2
- const RequestInitializer = new Abstraction("RequestInitializer");
3
- export { RequestInitializer };
4
-
5
- //# sourceMappingURL=RequestInitializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/events/RequestInitializer.js","sources":["../../../src/features/events/RequestInitializer.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\n\n/**\n * Per-request async initialization hook. Runs once per request, after the request container is set\n * up (options.request) and BEFORE the event is dispatched to its handler chain — i.e. before\n * auth/tenant are established.\n *\n * Use it for async, tenant-agnostic, per-request setup that must be ready before synchronous\n * consumers run, and that can change between requests (e.g. loading the WCP project license).\n *\n * - For tenant/identity-dependent state, use a lazy DI factory instead (resolved during request\n * handling, after auth has run).\n * - For build-once async setup (a process-lifetime singleton), use a RootInitializer.\n *\n * Multiple initializers may be registered; they run in registration order.\n */\nexport interface IRequestInitializer {\n init(): void | Promise<void>;\n}\n\nexport const RequestInitializer = new Abstraction<IRequestInitializer>(\"RequestInitializer\");\n\nexport namespace RequestInitializer {\n export type Interface = IRequestInitializer;\n}\n"],"names":["RequestInitializer","Abstraction"],"mappings":";AAoBO,MAAMA,qBAAqB,IAAIC,YAAiC"}
@@ -1,20 +0,0 @@
1
- import { Container } from "@webiny/di";
2
- import type { Transport } from "../../features/events/Transport.js";
3
- import type { HandlerSetup } from "../../features/events/types.js";
4
- export interface CreateHandlerOptions {
5
- root: HandlerSetup;
6
- request?: HandlerSetup;
7
- /**
8
- * Transport-specific extract step: binds the raw platform arguments (e.g. the AWS Lambda
9
- * event + context) into the per-request container. Defaults to a no-op, which leaves the
10
- * event to pass straight through — the plain server/HTTP behavior.
11
- */
12
- transport?: Transport;
13
- /**
14
- * A pre-built, already root-initialized container. When provided, `root` is NOT called again —
15
- * used by transports that must build the root eagerly at startup (e.g. the Node server, which
16
- * needs the root container ready to attach a WebSockets upgrade handler before the first request).
17
- */
18
- rootContainer?: Container;
19
- }
20
- export declare function createHandler(options: CreateHandlerOptions): (...rawArgs: any[]) => Promise<any>;
@@ -1,41 +0,0 @@
1
- import { Container } from "@webiny/di";
2
- import { EventType } from "./EventType.js";
3
- import { RequestContainer } from "./RequestContainer.js";
4
- import { RequestInitializer } from "./RequestInitializer.js";
5
- import { executeChain } from "./chain.js";
6
- import { noopTransport } from "./Transport.js";
7
- function createHandler(options) {
8
- let rootContainer = options.rootContainer ?? null;
9
- const transport = options.transport ?? noopTransport;
10
- return async (...rawArgs)=>{
11
- if (!rootContainer) {
12
- rootContainer = new Container();
13
- await options.root(rootContainer);
14
- }
15
- const child = rootContainer.createChildContainer();
16
- child.registerInstance(RequestContainer, child);
17
- await transport.bind(child, ...rawArgs);
18
- if (options.request) await options.request(child);
19
- for (const initializer of child.resolveAll(RequestInitializer))await initializer.init();
20
- const event = rawArgs[0];
21
- const eventTypes = child.resolveAll(EventType);
22
- const matched = eventTypes.find((et)=>et.canHandle(event));
23
- if (!matched) {
24
- const shape = event && "object" == typeof event ? {
25
- keys: Object.keys(event),
26
- source: event.source,
27
- detailType: event["detail-type"]
28
- } : {
29
- type: typeof event
30
- };
31
- const registered = eventTypes.map((et)=>et?.constructor?.name);
32
- throw new Error(`No event type matched the incoming event. Event shape: ${JSON.stringify(shape)}; registered event types: ${JSON.stringify(registered)}`);
33
- }
34
- const abstraction = matched.getHandlerAbstraction();
35
- const handlers = child.resolveAll(abstraction);
36
- return executeChain(handlers, event);
37
- };
38
- }
39
- export { createHandler };
40
-
41
- //# sourceMappingURL=createHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/events/createHandler.js","sources":["../../../src/features/events/createHandler.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\nimport { EventType } from \"~/features/events/EventType.js\";\nimport { RequestContainer } from \"~/features/events/RequestContainer.js\";\nimport { RequestInitializer } from \"~/features/events/RequestInitializer.js\";\nimport { executeChain } from \"~/features/events/chain.js\";\nimport { noopTransport } from \"~/features/events/Transport.js\";\nimport type { Transport } from \"~/features/events/Transport.js\";\nimport type { HandlerSetup } from \"~/features/events/types.js\";\n\nexport interface CreateHandlerOptions {\n root: HandlerSetup;\n request?: HandlerSetup;\n /**\n * Transport-specific extract step: binds the raw platform arguments (e.g. the AWS Lambda\n * event + context) into the per-request container. Defaults to a no-op, which leaves the\n * event to pass straight through — the plain server/HTTP behavior.\n */\n transport?: Transport;\n /**\n * A pre-built, already root-initialized container. When provided, `root` is NOT called again —\n * used by transports that must build the root eagerly at startup (e.g. the Node server, which\n * needs the root container ready to attach a WebSockets upgrade handler before the first request).\n */\n rootContainer?: Container;\n}\n\nexport function createHandler(options: CreateHandlerOptions) {\n let rootContainer: Container | null = options.rootContainer ?? null;\n const transport = options.transport ?? noopTransport;\n\n return async (...rawArgs: any[]): Promise<any> => {\n if (!rootContainer) {\n rootContainer = new Container();\n await options.root(rootContainer);\n }\n\n const child = rootContainer.createChildContainer();\n child.registerInstance(RequestContainer, child);\n\n // Transport-specific bind: register the raw platform arguments into the request container\n // before request setup runs. The default transport binds nothing.\n await transport.bind(child, ...rawArgs);\n\n if (options.request) {\n await options.request(child);\n }\n\n // Per-request async initialization (tenant-agnostic), before the event is dispatched and\n // before auth/tenant are established. For tenant-dependent setup use lazy DI factories.\n for (const initializer of child.resolveAll(RequestInitializer)) {\n await initializer.init();\n }\n\n // The event to match on is always the first raw argument (transports never change this).\n const event = rawArgs[0];\n const eventTypes = child.resolveAll(EventType);\n const matched = eventTypes.find(et => et.canHandle(event));\n\n if (!matched) {\n // Include a non-sensitive shape summary so this is debuggable: which event types were\n // registered vs. what the event actually looks like (keys + EventBridge discriminators).\n const shape =\n event && typeof event === \"object\"\n ? {\n keys: Object.keys(event),\n source: (event as any).source,\n detailType: (event as any)[\"detail-type\"]\n }\n : { type: typeof event };\n const registered = eventTypes.map(et => (et as any)?.constructor?.name);\n throw new Error(\n `No event type matched the incoming event. Event shape: ${JSON.stringify(\n shape\n )}; registered event types: ${JSON.stringify(registered)}`\n );\n }\n\n const abstraction = matched.getHandlerAbstraction();\n const handlers = child.resolveAll(abstraction);\n\n return executeChain(handlers, event);\n };\n}\n"],"names":["createHandler","options","rootContainer","transport","noopTransport","rawArgs","Container","child","RequestContainer","initializer","RequestInitializer","event","eventTypes","EventType","matched","et","shape","Object","registered","Error","JSON","abstraction","handlers","executeChain"],"mappings":";;;;;;AA0BO,SAASA,cAAcC,OAA6B;IACvD,IAAIC,gBAAkCD,QAAQ,aAAa,IAAI;IAC/D,MAAME,YAAYF,QAAQ,SAAS,IAAIG;IAEvC,OAAO,OAAO,GAAGC;QACb,IAAI,CAACH,eAAe;YAChBA,gBAAgB,IAAII;YACpB,MAAML,QAAQ,IAAI,CAACC;QACvB;QAEA,MAAMK,QAAQL,cAAc,oBAAoB;QAChDK,MAAM,gBAAgB,CAACC,kBAAkBD;QAIzC,MAAMJ,UAAU,IAAI,CAACI,UAAUF;QAE/B,IAAIJ,QAAQ,OAAO,EACf,MAAMA,QAAQ,OAAO,CAACM;QAK1B,KAAK,MAAME,eAAeF,MAAM,UAAU,CAACG,oBACvC,MAAMD,YAAY,IAAI;QAI1B,MAAME,QAAQN,OAAO,CAAC,EAAE;QACxB,MAAMO,aAAaL,MAAM,UAAU,CAACM;QACpC,MAAMC,UAAUF,WAAW,IAAI,CAACG,CAAAA,KAAMA,GAAG,SAAS,CAACJ;QAEnD,IAAI,CAACG,SAAS;YAGV,MAAME,QACFL,SAAS,AAAiB,YAAjB,OAAOA,QACV;gBACI,MAAMM,OAAO,IAAI,CAACN;gBAClB,QAASA,MAAc,MAAM;gBAC7B,YAAaA,KAAa,CAAC,cAAc;YAC7C,IACA;gBAAE,MAAM,OAAOA;YAAM;YAC/B,MAAMO,aAAaN,WAAW,GAAG,CAACG,CAAAA,KAAOA,IAAY,aAAa;YAClE,MAAM,IAAII,MACN,CAAC,uDAAuD,EAAEC,KAAK,SAAS,CACpEJ,OACF,0BAA0B,EAAEI,KAAK,SAAS,CAACF,aAAa;QAElE;QAEA,MAAMG,cAAcP,QAAQ,qBAAqB;QACjD,MAAMQ,WAAWf,MAAM,UAAU,CAACc;QAElC,OAAOE,aAAaD,UAAUX;IAClC;AACJ"}
@@ -1,20 +0,0 @@
1
- import type { Container } from "@webiny/di";
2
- export interface RunRequestContextInitializersOptions {
3
- /**
4
- * When true, a failing initializer is logged and skipped instead of aborting the whole run.
5
- * Use for event categories (e.g. background tasks) that register the full HTTP initializer set
6
- * but don't need every one — a side-effect initializer that doesn't apply shouldn't fail the task.
7
- * HTTP keeps the default (fail-fast) so a broken critical initializer surfaces.
8
- */
9
- continueOnError?: boolean;
10
- }
11
- /**
12
- * Runs all registered {@link RequestContextInitializer}s (post-auth per-request setup) against the
13
- * given container. Call this once per request, AFTER the request's identity/tenant have been
14
- * established, and BEFORE dispatching to the handler that needs them.
15
- *
16
- * Context establishment differs per event category (HTTP establishers, a background task's payload,
17
- * etc.), but the initializer run itself is identical — so each category invokes this at its own
18
- * "context established" point (the HTTP layer for all HTTP routes; the bg-task handler for tasks).
19
- */
20
- export declare const runRequestContextInitializers: (container: Container, options?: RunRequestContextInitializersOptions) => Promise<void>;
@@ -1,16 +0,0 @@
1
- import { RequestContextInitializer } from "./RequestContextInitializer.js";
2
- const runRequestContextInitializers = async (container, options = {})=>{
3
- const ctx = {
4
- container
5
- };
6
- for (const initializer of container.resolveAll(RequestContextInitializer))try {
7
- await initializer.init(ctx);
8
- } catch (err) {
9
- if (!options.continueOnError) throw err;
10
- const name = initializer?.constructor?.name ?? "RequestContextInitializer";
11
- console.error(`[runRequestContextInitializers] "${name}" failed (continuing):`, err);
12
- }
13
- };
14
- export { runRequestContextInitializers };
15
-
16
- //# sourceMappingURL=runRequestContextInitializers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/events/runRequestContextInitializers.js","sources":["../../../src/features/events/runRequestContextInitializers.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { RequestContextInitializer } from \"./RequestContextInitializer.js\";\n\nexport interface RunRequestContextInitializersOptions {\n /**\n * When true, a failing initializer is logged and skipped instead of aborting the whole run.\n * Use for event categories (e.g. background tasks) that register the full HTTP initializer set\n * but don't need every one — a side-effect initializer that doesn't apply shouldn't fail the task.\n * HTTP keeps the default (fail-fast) so a broken critical initializer surfaces.\n */\n continueOnError?: boolean;\n}\n\n/**\n * Runs all registered {@link RequestContextInitializer}s (post-auth per-request setup) against the\n * given container. Call this once per request, AFTER the request's identity/tenant have been\n * established, and BEFORE dispatching to the handler that needs them.\n *\n * Context establishment differs per event category (HTTP establishers, a background task's payload,\n * etc.), but the initializer run itself is identical — so each category invokes this at its own\n * \"context established\" point (the HTTP layer for all HTTP routes; the bg-task handler for tasks).\n */\nexport const runRequestContextInitializers = async (\n container: Container,\n options: RunRequestContextInitializersOptions = {}\n): Promise<void> => {\n const ctx: Record<string, any> = { container };\n for (const initializer of container.resolveAll(RequestContextInitializer)) {\n try {\n await initializer.init(ctx);\n } catch (err) {\n if (!options.continueOnError) {\n throw err;\n }\n const name = (initializer as any)?.constructor?.name ?? \"RequestContextInitializer\";\n console.error(`[runRequestContextInitializers] \"${name}\" failed (continuing):`, err);\n }\n }\n};\n"],"names":["runRequestContextInitializers","container","options","ctx","initializer","RequestContextInitializer","err","name","console"],"mappings":";AAsBO,MAAMA,gCAAgC,OACzCC,WACAC,UAAgD,CAAC,CAAC;IAElD,MAAMC,MAA2B;QAAEF;IAAU;IAC7C,KAAK,MAAMG,eAAeH,UAAU,UAAU,CAACI,2BAC3C,IAAI;QACA,MAAMD,YAAY,IAAI,CAACD;IAC3B,EAAE,OAAOG,KAAK;QACV,IAAI,CAACJ,QAAQ,eAAe,EACxB,MAAMI;QAEV,MAAMC,OAAQH,aAAqB,aAAa,QAAQ;QACxDI,QAAQ,KAAK,CAAC,CAAC,iCAAiC,EAAED,KAAK,sBAAsB,CAAC,EAAED;IACpF;AAER"}
@@ -1,20 +0,0 @@
1
- import type { Container } from "@webiny/di";
2
- import type { IHttpRouter, IHttpRequest, IHttpResponse } from "../../../features/http/abstractions.js";
3
- /**
4
- * Runs the post-auth {@link RequestContextInitializer}s once per request, for EVERY HTTP route
5
- * (graphql, cms, /files/* asset delivery, ...) — not just the GraphQL engine. It's transport-
6
- * agnostic: it lives in event-handler-core and depends only on DI abstractions. The transport's
7
- * auth decorators (e.g. ApiGatewayIdentityLoaderDecorator / ApiGatewayTenantLoaderDecorator)
8
- * establish identity/tenant BEFORE control reaches HttpRouter, so by the time this runs, the request
9
- * context is established.
10
- */
11
- declare class RequestContextInitializerDecoratorImpl implements IHttpRouter {
12
- private container;
13
- private decoratee;
14
- constructor(container: Container, decoratee: IHttpRouter);
15
- route(request: IHttpRequest): Promise<IHttpResponse>;
16
- }
17
- export declare const RequestContextInitializerDecorator: typeof RequestContextInitializerDecoratorImpl & {
18
- __abstraction: import("@webiny/di").Abstraction<IHttpRouter>;
19
- };
20
- export {};
@@ -1,22 +0,0 @@
1
- import { HttpRouter } from "../abstractions.js";
2
- import { RequestContainer } from "../../events/RequestContainer.js";
3
- import { runRequestContextInitializers } from "../../events/runRequestContextInitializers.js";
4
- class RequestContextInitializerDecoratorImpl {
5
- constructor(container, decoratee){
6
- this.container = container;
7
- this.decoratee = decoratee;
8
- }
9
- async route(request) {
10
- await runRequestContextInitializers(this.container);
11
- return this.decoratee.route(request);
12
- }
13
- }
14
- const RequestContextInitializerDecorator = HttpRouter.createDecorator({
15
- decorator: RequestContextInitializerDecoratorImpl,
16
- dependencies: [
17
- RequestContainer
18
- ]
19
- });
20
- export { RequestContextInitializerDecorator };
21
-
22
- //# sourceMappingURL=RequestContextInitializerDecorator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/http/decorators/RequestContextInitializerDecorator.js","sources":["../../../../src/features/http/decorators/RequestContextInitializerDecorator.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { HttpRouter } from \"~/features/http/abstractions.js\";\nimport type { IHttpRouter, IHttpRequest, IHttpResponse } from \"~/features/http/abstractions.js\";\nimport { RequestContainer } from \"~/features/events/RequestContainer.js\";\nimport { runRequestContextInitializers } from \"~/features/events/runRequestContextInitializers.js\";\n\n/**\n * Runs the post-auth {@link RequestContextInitializer}s once per request, for EVERY HTTP route\n * (graphql, cms, /files/* asset delivery, ...) — not just the GraphQL engine. It's transport-\n * agnostic: it lives in event-handler-core and depends only on DI abstractions. The transport's\n * auth decorators (e.g. ApiGatewayIdentityLoaderDecorator / ApiGatewayTenantLoaderDecorator)\n * establish identity/tenant BEFORE control reaches HttpRouter, so by the time this runs, the request\n * context is established.\n */\nclass RequestContextInitializerDecoratorImpl implements IHttpRouter {\n constructor(\n private container: Container,\n private decoratee: IHttpRouter\n ) {}\n\n async route(request: IHttpRequest): Promise<IHttpResponse> {\n await runRequestContextInitializers(this.container);\n return this.decoratee.route(request);\n }\n}\n\nexport const RequestContextInitializerDecorator = HttpRouter.createDecorator({\n decorator: RequestContextInitializerDecoratorImpl,\n dependencies: [RequestContainer]\n});\n"],"names":["RequestContextInitializerDecoratorImpl","container","decoratee","request","runRequestContextInitializers","RequestContextInitializerDecorator","HttpRouter","RequestContainer"],"mappings":";;;AAcA,MAAMA;IACF,YACYC,SAAoB,EACpBC,SAAsB,CAChC;aAFUD,SAAS,GAATA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,MAAMC,OAAqB,EAA0B;QACvD,MAAMC,8BAA8B,IAAI,CAAC,SAAS;QAClD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAACD;IAChC;AACJ;AAEO,MAAME,qCAAqCC,WAAW,eAAe,CAAC;IACzE,WAAWN;IACX,cAAc;QAACO;KAAiB;AACpC"}