@webiny/api-websockets-aws 0.0.0-unstable.9f53ea597d

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/api-websockets-aws
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,2 @@
1
+ import type { HandlerCallable, HandlerParams } from "./types.js";
2
+ export declare const createHandler: (params: HandlerParams) => HandlerCallable;
@@ -0,0 +1,105 @@
1
+ import { createHandler } from "@webiny/handler";
2
+ import { registerDefaultPlugins } from "@webiny/handler-aws/plugins/index.js";
3
+ import { execute } from "@webiny/handler-aws/execute.js";
4
+ import { PluginsContainer } from "@webiny/plugins";
5
+ import { WebsocketsResponse, WebsocketsRunner, WebsocketsTransport, createWebsocketsRoutePlugins } from "@webiny/api-websockets/exports/api.js";
6
+ import { getEventValues } from "./headers.js";
7
+ import { AwsWebsocketsEventValidator } from "../validator/AwsWebsocketsEventValidator.js";
8
+ const url = "/webiny-websockets";
9
+ const createPluginsContainer = (plugins)=>{
10
+ if (plugins instanceof PluginsContainer) return plugins;
11
+ return new PluginsContainer(plugins || []);
12
+ };
13
+ const handler_createHandler = (params)=>{
14
+ const plugins = createPluginsContainer(params.plugins);
15
+ plugins.register(...createWebsocketsRoutePlugins());
16
+ const validator = new AwsWebsocketsEventValidator();
17
+ return async (event)=>{
18
+ const app = createHandler({
19
+ ...params,
20
+ plugins,
21
+ options: {
22
+ logger: true === params.debug,
23
+ ...params.options || {}
24
+ }
25
+ });
26
+ registerDefaultPlugins(app.webiny);
27
+ await app.register(async (wsApp)=>{
28
+ wsApp.setErrorHandler(async (error, _, reply)=>{
29
+ app.__webiny_raw_result = {
30
+ error: {
31
+ message: error.message,
32
+ code: error.code,
33
+ data: error.data
34
+ },
35
+ statusCode: 200
36
+ };
37
+ return reply.send({});
38
+ });
39
+ wsApp.post(url, async (_, reply)=>{
40
+ const { response } = params;
41
+ const context = app.webiny;
42
+ const responseObj = response || context.container.resolve(WebsocketsResponse);
43
+ const runner = new WebsocketsRunner(context, responseObj);
44
+ let validatedEvent;
45
+ try {
46
+ validatedEvent = await validator.validate(event);
47
+ } catch (ex) {
48
+ const errorResult = responseObj.error({
49
+ message: "Validation failed.",
50
+ error: {
51
+ message: ex.message,
52
+ code: ex.code,
53
+ data: ex.data,
54
+ stack: ex.stack
55
+ }
56
+ });
57
+ const { connectionId, domainName, stage, eventType } = event.requestContext || {};
58
+ if (connectionId && domainName && stage && "MESSAGE" === eventType) try {
59
+ const transport = context.container.resolve(WebsocketsTransport);
60
+ const endpoint = `https://${domainName}/${stage}`;
61
+ await transport.send([
62
+ {
63
+ connectionId,
64
+ endpoint
65
+ }
66
+ ], errorResult);
67
+ } catch {}
68
+ app.__webiny_raw_result = {
69
+ statusCode: errorResult.statusCode,
70
+ headers: {
71
+ "sec-websocket-protocol": "webiny-ws-v1"
72
+ }
73
+ };
74
+ return reply.send();
75
+ }
76
+ const result = await runner.run(validatedEvent);
77
+ app.__webiny_raw_result = {
78
+ statusCode: result.statusCode,
79
+ headers: {
80
+ "sec-websocket-protocol": "webiny-ws-v1"
81
+ }
82
+ };
83
+ return reply.send();
84
+ });
85
+ });
86
+ const { tenant, endpoint, token } = getEventValues(event);
87
+ const headers = {
88
+ Authorization: `Bearer ${token}`,
89
+ ["x-tenant"]: tenant,
90
+ ["x-webiny-cms-endpoint"]: endpoint,
91
+ ...event.headers
92
+ };
93
+ return execute({
94
+ app,
95
+ url: url,
96
+ payload: {
97
+ ...event,
98
+ headers
99
+ }
100
+ });
101
+ };
102
+ };
103
+ export { handler_createHandler as createHandler };
104
+
105
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler/handler.js","sources":["../../src/handler/handler.ts"],"sourcesContent":["import type WebinyError from \"@webiny/error\";\nimport { createHandler as createBaseHandler } from \"@webiny/handler\";\nimport { registerDefaultPlugins } from \"@webiny/handler-aws/plugins/index.js\";\nimport { execute } from \"@webiny/handler-aws/execute.js\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n createWebsocketsRoutePlugins,\n WebsocketsRunner,\n WebsocketsTransport,\n WebsocketsResponse\n} from \"@webiny/api-websockets/exports/api.js\";\nimport type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\n\ntype Context = DbContext & ApiCoreContext;\nimport type { PluginCollection } from \"@webiny/plugins/types.js\";\nimport type { HandlerCallable, HandlerParams } from \"./types.js\";\nimport { getEventValues } from \"./headers.js\";\nimport { AwsWebsocketsEventValidator } from \"~/validator/AwsWebsocketsEventValidator.js\";\n\nconst url = \"/webiny-websockets\";\n\nconst createPluginsContainer = (\n plugins?: PluginsContainer | PluginCollection\n): PluginsContainer => {\n if (plugins instanceof PluginsContainer) {\n return plugins;\n }\n return new PluginsContainer(plugins || []);\n};\n\nexport const createHandler = (params: HandlerParams): HandlerCallable => {\n const plugins = createPluginsContainer(params.plugins);\n plugins.register(...createWebsocketsRoutePlugins());\n\n const validator = new AwsWebsocketsEventValidator();\n\n return async event => {\n const app = createBaseHandler({\n ...params,\n plugins,\n options: {\n logger: params.debug === true,\n ...(params.options || {})\n }\n });\n\n registerDefaultPlugins(app.webiny);\n\n await app.register(async wsApp => {\n wsApp.setErrorHandler<WebinyError>(async (error, _, reply) => {\n app.__webiny_raw_result = {\n error: {\n message: error.message,\n code: error.code,\n data: error.data\n },\n statusCode: 200\n };\n return reply.send({});\n });\n\n wsApp.post(url, async (_, reply) => {\n const { response } = params;\n const context = app.webiny as Context;\n\n const responseObj = response || context.container.resolve(WebsocketsResponse);\n const runner = new WebsocketsRunner(context, responseObj);\n\n let validatedEvent;\n try {\n validatedEvent = await validator.validate(event);\n } catch (ex) {\n const errorResult = responseObj.error({\n message: \"Validation failed.\",\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n });\n\n const { connectionId, domainName, stage, eventType } =\n event.requestContext || {};\n if (connectionId && domainName && stage && eventType === \"MESSAGE\") {\n try {\n const transport = context.container.resolve(WebsocketsTransport);\n const endpoint = `https://${domainName}/${stage}`;\n await transport.send([{ connectionId, endpoint }], errorResult);\n } catch {\n /* best effort. */\n }\n }\n\n app.__webiny_raw_result = {\n statusCode: errorResult.statusCode,\n headers: {\n \"sec-websocket-protocol\": \"webiny-ws-v1\"\n }\n };\n return reply.send();\n }\n\n const result = await runner.run(validatedEvent);\n\n app.__webiny_raw_result = {\n statusCode: result.statusCode,\n headers: {\n \"sec-websocket-protocol\": \"webiny-ws-v1\"\n }\n };\n\n return reply.send();\n });\n });\n\n const { tenant, endpoint, token } = getEventValues(event);\n\n const headers = {\n Authorization: `Bearer ${token}`,\n [\"x-tenant\"]: tenant,\n [\"x-webiny-cms-endpoint\"]: endpoint,\n ...event.headers\n };\n\n return execute({\n app,\n url,\n payload: {\n ...event,\n headers\n }\n });\n };\n};\n"],"names":["url","createPluginsContainer","plugins","PluginsContainer","createHandler","params","createWebsocketsRoutePlugins","validator","AwsWebsocketsEventValidator","event","app","createBaseHandler","registerDefaultPlugins","wsApp","error","_","reply","response","context","responseObj","WebsocketsResponse","runner","WebsocketsRunner","validatedEvent","ex","errorResult","connectionId","domainName","stage","eventType","transport","WebsocketsTransport","endpoint","result","tenant","token","getEventValues","headers","execute"],"mappings":";;;;;;;AAoBA,MAAMA,MAAM;AAEZ,MAAMC,yBAAyB,CAC3BC;IAEA,IAAIA,mBAAmBC,kBACnB,OAAOD;IAEX,OAAO,IAAIC,iBAAiBD,WAAW,EAAE;AAC7C;AAEO,MAAME,wBAAgB,CAACC;IAC1B,MAAMH,UAAUD,uBAAuBI,OAAO,OAAO;IACrDH,QAAQ,QAAQ,IAAII;IAEpB,MAAMC,YAAY,IAAIC;IAEtB,OAAO,OAAMC;QACT,MAAMC,MAAMC,cAAkB;YAC1B,GAAGN,MAAM;YACTH;YACA,SAAS;gBACL,QAAQG,AAAiB,SAAjBA,OAAO,KAAK;gBACpB,GAAIA,OAAO,OAAO,IAAI,CAAC,CAAC;YAC5B;QACJ;QAEAO,uBAAuBF,IAAI,MAAM;QAEjC,MAAMA,IAAI,QAAQ,CAAC,OAAMG;YACrBA,MAAM,eAAe,CAAc,OAAOC,OAAOC,GAAGC;gBAChDN,IAAI,mBAAmB,GAAG;oBACtB,OAAO;wBACH,SAASI,MAAM,OAAO;wBACtB,MAAMA,MAAM,IAAI;wBAChB,MAAMA,MAAM,IAAI;oBACpB;oBACA,YAAY;gBAChB;gBACA,OAAOE,MAAM,IAAI,CAAC,CAAC;YACvB;YAEAH,MAAM,IAAI,CAACb,KAAK,OAAOe,GAAGC;gBACtB,MAAM,EAAEC,QAAQ,EAAE,GAAGZ;gBACrB,MAAMa,UAAUR,IAAI,MAAM;gBAE1B,MAAMS,cAAcF,YAAYC,QAAQ,SAAS,CAAC,OAAO,CAACE;gBAC1D,MAAMC,SAAS,IAAIC,iBAAiBJ,SAASC;gBAE7C,IAAII;gBACJ,IAAI;oBACAA,iBAAiB,MAAMhB,UAAU,QAAQ,CAACE;gBAC9C,EAAE,OAAOe,IAAI;oBACT,MAAMC,cAAcN,YAAY,KAAK,CAAC;wBAClC,SAAS;wBACT,OAAO;4BACH,SAASK,GAAG,OAAO;4BACnB,MAAMA,GAAG,IAAI;4BACb,MAAMA,GAAG,IAAI;4BACb,OAAOA,GAAG,KAAK;wBACnB;oBACJ;oBAEA,MAAM,EAAEE,YAAY,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,EAAE,GAChDpB,MAAM,cAAc,IAAI,CAAC;oBAC7B,IAAIiB,gBAAgBC,cAAcC,SAASC,AAAc,cAAdA,WACvC,IAAI;wBACA,MAAMC,YAAYZ,QAAQ,SAAS,CAAC,OAAO,CAACa;wBAC5C,MAAMC,WAAW,CAAC,QAAQ,EAAEL,WAAW,CAAC,EAAEC,OAAO;wBACjD,MAAME,UAAU,IAAI,CAAC;4BAAC;gCAAEJ;gCAAcM;4BAAS;yBAAE,EAAEP;oBACvD,EAAE,OAAM,CAER;oBAGJf,IAAI,mBAAmB,GAAG;wBACtB,YAAYe,YAAY,UAAU;wBAClC,SAAS;4BACL,0BAA0B;wBAC9B;oBACJ;oBACA,OAAOT,MAAM,IAAI;gBACrB;gBAEA,MAAMiB,SAAS,MAAMZ,OAAO,GAAG,CAACE;gBAEhCb,IAAI,mBAAmB,GAAG;oBACtB,YAAYuB,OAAO,UAAU;oBAC7B,SAAS;wBACL,0BAA0B;oBAC9B;gBACJ;gBAEA,OAAOjB,MAAM,IAAI;YACrB;QACJ;QAEA,MAAM,EAAEkB,MAAM,EAAEF,QAAQ,EAAEG,KAAK,EAAE,GAAGC,eAAe3B;QAEnD,MAAM4B,UAAU;YACZ,eAAe,CAAC,OAAO,EAAEF,OAAO;YAChC,CAAC,WAAW,EAAED;YACd,CAAC,wBAAwB,EAAEF;YAC3B,GAAGvB,MAAM,OAAO;QACpB;QAEA,OAAO6B,QAAQ;YACX5B;YACAV,KAAAA;YACA,SAAS;gBACL,GAAGS,KAAK;gBACR4B;YACJ;QACJ;IACJ;AACJ"}
@@ -0,0 +1,6 @@
1
+ import type { IAwsWebsocketsIncomingEvent } from "../handler/types.js";
2
+ export declare const getEventValues: (event: IAwsWebsocketsIncomingEvent) => {
3
+ tenant: string;
4
+ token: string | null;
5
+ endpoint: string;
6
+ };
@@ -0,0 +1,27 @@
1
+ const getEventBody = (event)=>{
2
+ if (!event.body) return {};
3
+ if ("object" == typeof event.body) return event.body;
4
+ if ("string" == typeof event.body) try {
5
+ return JSON.parse(event.body);
6
+ } catch (ex) {
7
+ console.log(ex.message);
8
+ return {};
9
+ }
10
+ console.log("Unexpected event.body type:", typeof event.body);
11
+ return {};
12
+ };
13
+ const getToken = (body, event)=>body?.token || event.queryStringParameters?.token || null;
14
+ const getTenant = (body, event)=>body?.tenant || event.queryStringParameters?.tenant || "root";
15
+ const getEventValues = (event)=>{
16
+ const body = getEventBody(event);
17
+ const token = getToken(body, event);
18
+ const tenant = getTenant(body, event);
19
+ return {
20
+ tenant,
21
+ token,
22
+ endpoint: "manage"
23
+ };
24
+ };
25
+ export { getEventValues };
26
+
27
+ //# sourceMappingURL=headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler/headers.js","sources":["../../src/handler/headers.ts"],"sourcesContent":["import type { WebsocketsRunner } from \"@webiny/api-websockets/exports/api.js\";\nimport type { IAwsWebsocketsIncomingEvent } from \"~/handler/types.js\";\n\nconst getEventBody = (event: IAwsWebsocketsIncomingEvent): WebsocketsRunner.EventData => {\n if (!event.body) {\n return {};\n } else if (typeof event.body === \"object\") {\n return event.body;\n } else if (typeof event.body === \"string\") {\n try {\n return JSON.parse(event.body);\n } catch (ex) {\n console.log(ex.message);\n return {};\n }\n }\n console.log(\"Unexpected event.body type:\", typeof event.body);\n return {};\n};\n\nconst getToken = (\n body: WebsocketsRunner.EventData,\n event: IAwsWebsocketsIncomingEvent\n): string | null => {\n return body?.token || event.queryStringParameters?.token || null;\n};\n\nconst getTenant = (\n body: WebsocketsRunner.EventData,\n event: IAwsWebsocketsIncomingEvent\n): string => {\n return body?.tenant || event.queryStringParameters?.tenant || \"root\";\n};\n\nexport const getEventValues = (event: IAwsWebsocketsIncomingEvent) => {\n const body = getEventBody(event);\n\n const token = getToken(body, event);\n const tenant = getTenant(body, event);\n return {\n tenant,\n token,\n endpoint: \"manage\"\n };\n};\n"],"names":["getEventBody","event","JSON","ex","console","getToken","body","getTenant","getEventValues","token","tenant"],"mappings":"AAGA,MAAMA,eAAe,CAACC;IAClB,IAAI,CAACA,MAAM,IAAI,EACX,OAAO,CAAC;IACL,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACxB,OAAOA,MAAM,IAAI;IACd,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACxB,IAAI;QACA,OAAOC,KAAK,KAAK,CAACD,MAAM,IAAI;IAChC,EAAE,OAAOE,IAAI;QACTC,QAAQ,GAAG,CAACD,GAAG,OAAO;QACtB,OAAO,CAAC;IACZ;IAEJC,QAAQ,GAAG,CAAC,+BAA+B,OAAOH,MAAM,IAAI;IAC5D,OAAO,CAAC;AACZ;AAEA,MAAMI,WAAW,CACbC,MACAL,QAEOK,MAAM,SAASL,MAAM,qBAAqB,EAAE,SAAS;AAGhE,MAAMM,YAAY,CACdD,MACAL,QAEOK,MAAM,UAAUL,MAAM,qBAAqB,EAAE,UAAU;AAG3D,MAAMO,iBAAiB,CAACP;IAC3B,MAAMK,OAAON,aAAaC;IAE1B,MAAMQ,QAAQJ,SAASC,MAAML;IAC7B,MAAMS,SAASH,UAAUD,MAAML;IAC/B,OAAO;QACHS;QACAD;QACA,UAAU;IACd;AACJ"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,16 @@
1
+ import { registry } from "@webiny/handler-aws/registry.js";
2
+ import { createSourceHandler } from "@webiny/handler-aws";
3
+ const handler = createSourceHandler({
4
+ name: "handler-webiny-websockets",
5
+ canUse: (event)=>{
6
+ const { routeKey, connectionId, eventType } = event.requestContext || {};
7
+ return !!routeKey && !!connectionId && !!eventType;
8
+ },
9
+ handle: async ({ params, event, context })=>{
10
+ const { createHandler } = await import("./handler.js");
11
+ return createHandler(params)(event, context);
12
+ }
13
+ });
14
+ registry.register(handler);
15
+
16
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler/register.js","sources":["../../src/handler/register.ts"],"sourcesContent":["import { registry } from \"@webiny/handler-aws/registry.js\";\nimport { createSourceHandler } from \"@webiny/handler-aws\";\nimport type { HandlerParams, IAwsWebsocketsIncomingEvent } from \"./types.js\";\n\nconst handler = createSourceHandler<IAwsWebsocketsIncomingEvent, HandlerParams>({\n name: \"handler-webiny-websockets\",\n canUse: event => {\n const { routeKey, connectionId, eventType } = event.requestContext || {};\n return !!routeKey && !!connectionId && !!eventType;\n },\n handle: async ({ params, event, context }) => {\n const { createHandler } = await import(\n /* webpackChunkName: \"SocketsHandler\" */\n \"./handler.js\"\n );\n return createHandler(params)(event, context);\n }\n});\n\nregistry.register(handler);\n"],"names":["handler","createSourceHandler","event","routeKey","connectionId","eventType","params","context","createHandler","registry"],"mappings":";;AAIA,MAAMA,UAAUC,oBAAgE;IAC5E,MAAM;IACN,QAAQC,CAAAA;QACJ,MAAM,EAAEC,QAAQ,EAAEC,YAAY,EAAEC,SAAS,EAAE,GAAGH,MAAM,cAAc,IAAI,CAAC;QACvE,OAAO,CAAC,CAACC,YAAY,CAAC,CAACC,gBAAgB,CAAC,CAACC;IAC7C;IACA,QAAQ,OAAO,EAAEC,MAAM,EAAEJ,KAAK,EAAEK,OAAO,EAAE;QACrC,MAAM,EAAEC,aAAa,EAAE,GAAG,MAAM,MAAM,CAAN;QAIhC,OAAOA,cAAcF,QAAQJ,OAAOK;IACxC;AACJ;AAEAE,SAAS,QAAQ,CAACT"}
@@ -0,0 +1,62 @@
1
+ import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
2
+ import type { WebsocketsResponse } from "@webiny/api-websockets/exports/api.js";
3
+ import type { APIGatewayProxyResult, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
4
+ import type { WebsocketsRunner } from "@webiny/api-websockets/exports/api.js";
5
+ import type { GenericRecord } from "@webiny/api/types.js";
6
+ import type { PartialDeep } from "type-fest";
7
+ export interface HandlerCallable {
8
+ (event: IAwsWebsocketsIncomingEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
9
+ }
10
+ export interface HandlerParams extends HandlerFactoryParams {
11
+ response?: WebsocketsResponse.Interface;
12
+ }
13
+ export declare enum WebsocketsEventRoute {
14
+ connect = "$connect",
15
+ disconnect = "$disconnect",
16
+ default = "$default"
17
+ }
18
+ export declare enum WebsocketsEventRequestContextEventType {
19
+ message = "MESSAGE",
20
+ connect = "CONNECT",
21
+ disconnect = "DISCONNECT"
22
+ }
23
+ export interface IAwsWebsocketsEventRequestContext {
24
+ connectionId: string;
25
+ connectedAt: number;
26
+ domainName: string;
27
+ eventType: WebsocketsEventRequestContextEventType;
28
+ routeKey: WebsocketsEventRoute | string;
29
+ stage: string;
30
+ }
31
+ export interface IAwsWebsocketsEventHeaders {
32
+ "Accept-Encoding"?: string;
33
+ "Accept-Language"?: string;
34
+ "Cache-Control"?: string;
35
+ Host?: string;
36
+ Origin?: string;
37
+ Pragma?: string;
38
+ "Sec-WebSocket-Extensions"?: string;
39
+ "Sec-WebSocket-Key"?: string;
40
+ "Sec-WebSocket-Version"?: string;
41
+ "Sec-WebSocket-Protocol"?: string;
42
+ "User-Agent"?: string;
43
+ "X-Amzn-Trace-Id"?: string;
44
+ "X-Forwarded-For"?: string;
45
+ "X-Forwarded-Port"?: `${number}`;
46
+ "X-Forwarded-Proto"?: "https" | "http";
47
+ ["x-tenant"]?: string;
48
+ ["x-webiny-cms-endpoint"]?: string;
49
+ }
50
+ export interface IAwsWebsocketsEventQueryStringParameters {
51
+ tenant?: string;
52
+ token?: string;
53
+ }
54
+ export interface IAwsWebsocketsEvent<T extends WebsocketsRunner.EventData = WebsocketsRunner.EventData> {
55
+ headers?: IAwsWebsocketsEventHeaders;
56
+ queryStringParameters?: IAwsWebsocketsEventQueryStringParameters;
57
+ requestContext: IAwsWebsocketsEventRequestContext;
58
+ body?: T;
59
+ }
60
+ export interface IAwsWebsocketsIncomingEvent extends PartialDeep<Omit<IAwsWebsocketsEvent, "body">> {
61
+ body?: string | GenericRecord;
62
+ }
@@ -0,0 +1,15 @@
1
+ var types_WebsocketsEventRoute = /*#__PURE__*/ function(WebsocketsEventRoute) {
2
+ WebsocketsEventRoute["connect"] = "$connect";
3
+ WebsocketsEventRoute["disconnect"] = "$disconnect";
4
+ WebsocketsEventRoute["default"] = "$default";
5
+ return WebsocketsEventRoute;
6
+ }({});
7
+ var types_WebsocketsEventRequestContextEventType = /*#__PURE__*/ function(WebsocketsEventRequestContextEventType) {
8
+ WebsocketsEventRequestContextEventType["message"] = "MESSAGE";
9
+ WebsocketsEventRequestContextEventType["connect"] = "CONNECT";
10
+ WebsocketsEventRequestContextEventType["disconnect"] = "DISCONNECT";
11
+ return WebsocketsEventRequestContextEventType;
12
+ }({});
13
+ export { types_WebsocketsEventRequestContextEventType as WebsocketsEventRequestContextEventType, types_WebsocketsEventRoute as WebsocketsEventRoute };
14
+
15
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler/types.js","sources":["../../src/handler/types.ts"],"sourcesContent":["import type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport type { WebsocketsResponse } from \"@webiny/api-websockets/exports/api.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { WebsocketsRunner } from \"@webiny/api-websockets/exports/api.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { PartialDeep } from \"type-fest\";\n\nexport interface HandlerCallable {\n (event: IAwsWebsocketsIncomingEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n response?: WebsocketsResponse.Interface;\n}\n\nexport enum WebsocketsEventRoute {\n connect = \"$connect\",\n disconnect = \"$disconnect\",\n default = \"$default\"\n}\n\nexport enum WebsocketsEventRequestContextEventType {\n message = \"MESSAGE\",\n connect = \"CONNECT\",\n disconnect = \"DISCONNECT\"\n}\n\nexport interface IAwsWebsocketsEventRequestContext {\n connectionId: string;\n connectedAt: number;\n domainName: string;\n eventType: WebsocketsEventRequestContextEventType;\n routeKey: WebsocketsEventRoute | string;\n stage: string;\n}\n\nexport interface IAwsWebsocketsEventHeaders {\n \"Accept-Encoding\"?: string;\n \"Accept-Language\"?: string;\n \"Cache-Control\"?: string;\n Host?: string;\n Origin?: string;\n Pragma?: string;\n \"Sec-WebSocket-Extensions\"?: string;\n \"Sec-WebSocket-Key\"?: string;\n \"Sec-WebSocket-Version\"?: string;\n \"Sec-WebSocket-Protocol\"?: string;\n \"User-Agent\"?: string;\n \"X-Amzn-Trace-Id\"?: string;\n \"X-Forwarded-For\"?: string;\n \"X-Forwarded-Port\"?: `${number}`;\n \"X-Forwarded-Proto\"?: \"https\" | \"http\";\n [\"x-tenant\"]?: string;\n [\"x-webiny-cms-endpoint\"]?: string;\n}\n\nexport interface IAwsWebsocketsEventQueryStringParameters {\n tenant?: string;\n token?: string;\n}\n\nexport interface IAwsWebsocketsEvent<\n T extends WebsocketsRunner.EventData = WebsocketsRunner.EventData\n> {\n headers?: IAwsWebsocketsEventHeaders;\n queryStringParameters?: IAwsWebsocketsEventQueryStringParameters;\n requestContext: IAwsWebsocketsEventRequestContext;\n body?: T;\n}\n\nexport interface IAwsWebsocketsIncomingEvent extends PartialDeep<\n Omit<IAwsWebsocketsEvent, \"body\">\n> {\n body?: string | GenericRecord;\n}\n"],"names":["WebsocketsEventRoute","WebsocketsEventRequestContextEventType"],"mappings":"AAkBO,IAAKA,6BAAoBA,WAAAA,GAAAA,SAApBA,oBAAoB;;;;WAApBA;;AAML,IAAKC,+CAAsCA,WAAAA,GAAAA,SAAtCA,sCAAsC;;;;WAAtCA"}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import "./handler/register.js";
2
+ export declare const createAwsWebsockets: () => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>[];
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ import "./handler/register.js";
2
+ import { createRegisterExtensionPlugin } from "@webiny/handler";
3
+ import { AwsWebsocketsTransport } from "./transport/AwsWebsocketsTransport.js";
4
+ const createAwsWebsockets = ()=>{
5
+ const plugin = createRegisterExtensionPlugin((context)=>{
6
+ context.container.register(AwsWebsocketsTransport).inSingletonScope();
7
+ });
8
+ plugin.name = "websockets.aws.transport";
9
+ return [
10
+ plugin
11
+ ];
12
+ };
13
+ export { createAwsWebsockets };
14
+
15
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import \"./handler/register.js\";\nimport { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport { AwsWebsocketsTransport } from \"~/transport/AwsWebsocketsTransport.js\";\n\nexport const createAwsWebsockets = () => {\n const plugin = createRegisterExtensionPlugin(context => {\n context.container.register(AwsWebsocketsTransport).inSingletonScope();\n });\n plugin.name = \"websockets.aws.transport\";\n return [plugin];\n};\n"],"names":["createAwsWebsockets","plugin","createRegisterExtensionPlugin","context","AwsWebsocketsTransport"],"mappings":";;;AAIO,MAAMA,sBAAsB;IAC/B,MAAMC,SAASC,8BAA8BC,CAAAA;QACzCA,QAAQ,SAAS,CAAC,QAAQ,CAACC,wBAAwB,gBAAgB;IACvE;IACAH,OAAO,IAAI,GAAG;IACd,OAAO;QAACA;KAAO;AACnB"}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@webiny/api-websockets-aws",
3
+ "version": "0.0.0-unstable.9f53ea597d",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/webiny/webiny-js.git"
8
+ },
9
+ "description": "AWS Lambda handler and API Gateway transport for @webiny/api-websockets",
10
+ "contributors": [
11
+ "Bruno Zorić <bruno@webiny.com>"
12
+ ],
13
+ "exports": {
14
+ "./*": "./*",
15
+ ".": "./index.js"
16
+ },
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "@webiny/api": "0.0.0-unstable.9f53ea597d",
20
+ "@webiny/api-websockets": "0.0.0-unstable.9f53ea597d",
21
+ "@webiny/aws-sdk": "0.0.0-unstable.9f53ea597d",
22
+ "@webiny/error": "0.0.0-unstable.9f53ea597d",
23
+ "@webiny/handler": "0.0.0-unstable.9f53ea597d",
24
+ "@webiny/handler-aws": "0.0.0-unstable.9f53ea597d",
25
+ "@webiny/plugins": "0.0.0-unstable.9f53ea597d",
26
+ "@webiny/utils": "0.0.0-unstable.9f53ea597d",
27
+ "type-fest": "5.8.0",
28
+ "zod": "4.4.3"
29
+ },
30
+ "devDependencies": {
31
+ "@webiny/api-core": "0.0.0-unstable.9f53ea597d",
32
+ "@webiny/api-headless-cms": "0.0.0-unstable.9f53ea597d",
33
+ "@webiny/build-tools": "0.0.0-unstable.9f53ea597d",
34
+ "@webiny/handler-db": "0.0.0-unstable.9f53ea597d",
35
+ "@webiny/handler-graphql": "0.0.0-unstable.9f53ea597d",
36
+ "@webiny/project-utils": "0.0.0-unstable.9f53ea597d",
37
+ "graphql": "16.14.2",
38
+ "rimraf": "6.1.3",
39
+ "type-fest": "5.8.0",
40
+ "typescript": "7.0.2",
41
+ "vitest": "4.1.10"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "webiny": {
47
+ "publishFrom": "dist"
48
+ }
49
+ }
@@ -0,0 +1,12 @@
1
+ import { WebsocketsTransport } from "@webiny/api-websockets/exports/api.js";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ declare class AwsWebsocketsTransportImpl implements WebsocketsTransport.Interface {
4
+ private readonly clients;
5
+ send<T extends GenericRecord = GenericRecord>(connections: WebsocketsTransport.SendConnection[], data: WebsocketsTransport.SendData<T>): Promise<void>;
6
+ disconnect(connections: WebsocketsTransport.DisconnectConnection[]): Promise<void>;
7
+ private getClient;
8
+ }
9
+ export declare const AwsWebsocketsTransport: typeof AwsWebsocketsTransportImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-websockets/transport").IWebsocketsTransport>;
11
+ };
12
+ export {};
@@ -0,0 +1,48 @@
1
+ import { ApiGatewayManagementApiClient, DeleteConnectionCommand, PostToConnectionCommand } from "@webiny/aws-sdk/client-apigatewaymanagementapi/index.js";
2
+ import { WebsocketsTransport } from "@webiny/api-websockets/exports/api.js";
3
+ class AwsWebsocketsTransportImpl {
4
+ async send(connections, data) {
5
+ for (const connection of connections)try {
6
+ const client = this.getClient(connection.endpoint);
7
+ const command = new PostToConnectionCommand({
8
+ ConnectionId: connection.connectionId,
9
+ Data: JSON.stringify(data)
10
+ });
11
+ await client.send(command);
12
+ } catch (ex) {
13
+ console.error(`Failed to send message to connection "${connection.connectionId}". Check logs for more information.`);
14
+ console.log(ex);
15
+ }
16
+ }
17
+ async disconnect(connections) {
18
+ for (const connection of connections)try {
19
+ const client = this.getClient(connection.endpoint);
20
+ const command = new DeleteConnectionCommand({
21
+ ConnectionId: connection.connectionId
22
+ });
23
+ await client.send(command);
24
+ } catch (ex) {
25
+ console.error(`Failed to disconnect connection "${connection.connectionId}". Check logs for more information.`);
26
+ console.log(ex);
27
+ }
28
+ }
29
+ getClient(endpoint) {
30
+ const client = this.clients.get(endpoint);
31
+ if (client) return client;
32
+ const newClient = new ApiGatewayManagementApiClient({
33
+ endpoint
34
+ });
35
+ this.clients.set(endpoint, newClient);
36
+ return newClient;
37
+ }
38
+ constructor(){
39
+ this.clients = new Map();
40
+ }
41
+ }
42
+ const AwsWebsocketsTransport = WebsocketsTransport.createImplementation({
43
+ implementation: AwsWebsocketsTransportImpl,
44
+ dependencies: []
45
+ });
46
+ export { AwsWebsocketsTransport };
47
+
48
+ //# sourceMappingURL=AwsWebsocketsTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport/AwsWebsocketsTransport.js","sources":["../../src/transport/AwsWebsocketsTransport.ts"],"sourcesContent":["import {\n ApiGatewayManagementApiClient,\n DeleteConnectionCommand,\n PostToConnectionCommand\n} from \"@webiny/aws-sdk/client-apigatewaymanagementapi/index.js\";\nimport { WebsocketsTransport } from \"@webiny/api-websockets/exports/api.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nclass AwsWebsocketsTransportImpl implements WebsocketsTransport.Interface {\n private readonly clients = new Map<string, ApiGatewayManagementApiClient>();\n\n public async send<T extends GenericRecord = GenericRecord>(\n connections: WebsocketsTransport.SendConnection[],\n data: WebsocketsTransport.SendData<T>\n ): Promise<void> {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection.endpoint);\n\n const command = new PostToConnectionCommand({\n ConnectionId: connection.connectionId,\n Data: JSON.stringify(data)\n });\n await client.send(command);\n } catch (ex) {\n console.error(\n `Failed to send message to connection \"${connection.connectionId}\". Check logs for more information.`\n );\n console.log(ex);\n }\n }\n }\n\n public async disconnect(connections: WebsocketsTransport.DisconnectConnection[]) {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection.endpoint);\n const command = new DeleteConnectionCommand({\n ConnectionId: connection.connectionId\n });\n await client.send(command);\n } catch (ex) {\n console.error(\n `Failed to disconnect connection \"${connection.connectionId}\". Check logs for more information.`\n );\n console.log(ex);\n }\n }\n }\n\n private getClient(endpoint: string): ApiGatewayManagementApiClient {\n const client = this.clients.get(endpoint);\n if (client) {\n return client;\n }\n const newClient = new ApiGatewayManagementApiClient({\n endpoint\n });\n this.clients.set(endpoint, newClient);\n return newClient;\n }\n}\n\nexport const AwsWebsocketsTransport = WebsocketsTransport.createImplementation({\n implementation: AwsWebsocketsTransportImpl,\n dependencies: []\n});\n"],"names":["AwsWebsocketsTransportImpl","connections","data","connection","client","command","PostToConnectionCommand","JSON","ex","console","DeleteConnectionCommand","endpoint","newClient","ApiGatewayManagementApiClient","Map","AwsWebsocketsTransport","WebsocketsTransport"],"mappings":";;AAQA,MAAMA;IAGF,MAAa,KACTC,WAAiD,EACjDC,IAAqC,EACxB;QACb,KAAK,MAAMC,cAAcF,YACrB,IAAI;YACA,MAAMG,SAAS,IAAI,CAAC,SAAS,CAACD,WAAW,QAAQ;YAEjD,MAAME,UAAU,IAAIC,wBAAwB;gBACxC,cAAcH,WAAW,YAAY;gBACrC,MAAMI,KAAK,SAAS,CAACL;YACzB;YACA,MAAME,OAAO,IAAI,CAACC;QACtB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CACT,CAAC,sCAAsC,EAAEN,WAAW,YAAY,CAAC,mCAAmC,CAAC;YAEzGM,QAAQ,GAAG,CAACD;QAChB;IAER;IAEA,MAAa,WAAWP,WAAuD,EAAE;QAC7E,KAAK,MAAME,cAAcF,YACrB,IAAI;YACA,MAAMG,SAAS,IAAI,CAAC,SAAS,CAACD,WAAW,QAAQ;YACjD,MAAME,UAAU,IAAIK,wBAAwB;gBACxC,cAAcP,WAAW,YAAY;YACzC;YACA,MAAMC,OAAO,IAAI,CAACC;QACtB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CACT,CAAC,iCAAiC,EAAEN,WAAW,YAAY,CAAC,mCAAmC,CAAC;YAEpGM,QAAQ,GAAG,CAACD;QAChB;IAER;IAEQ,UAAUG,QAAgB,EAAiC;QAC/D,MAAMP,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAACO;QAChC,IAAIP,QACA,OAAOA;QAEX,MAAMQ,YAAY,IAAIC,8BAA8B;YAChDF;QACJ;QACA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,UAAUC;QAC3B,OAAOA;IACX;;aAnDiB,OAAO,GAAG,IAAIE;;AAoDnC;AAEO,MAAMC,yBAAyBC,oBAAoB,oBAAoB,CAAC;IAC3E,gBAAgBhB;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,4 @@
1
+ import { WebsocketsEventValidator, WebsocketsRunner } from "@webiny/api-websockets/exports/api.js";
2
+ export declare class AwsWebsocketsEventValidator implements WebsocketsEventValidator.Interface {
3
+ validate<T extends WebsocketsRunner.EventData = WebsocketsRunner.EventData>(input: unknown): Promise<WebsocketsRunner.Event<T>>;
4
+ }
@@ -0,0 +1,87 @@
1
+ import zod from "zod";
2
+ import { WebsocketsEventRequestContextEventType } from "../handler/types.js";
3
+ import { createZodError } from "@webiny/utils";
4
+ const eventTypeMap = {
5
+ [WebsocketsEventRequestContextEventType.message]: "message",
6
+ [WebsocketsEventRequestContextEventType.connect]: "connect",
7
+ [WebsocketsEventRequestContextEventType.disconnect]: "disconnect"
8
+ };
9
+ const routeKeyMap = {
10
+ $connect: "connect",
11
+ $disconnect: "disconnect",
12
+ $default: "default"
13
+ };
14
+ const validation = zod.object({
15
+ headers: zod.looseObject({}).optional(),
16
+ requestContext: zod.object({
17
+ connectionId: zod.string(),
18
+ stage: zod.string(),
19
+ connectedAt: zod.number(),
20
+ domainName: zod.string(),
21
+ eventType: zod["enum"]([
22
+ WebsocketsEventRequestContextEventType.connect,
23
+ WebsocketsEventRequestContextEventType.message,
24
+ WebsocketsEventRequestContextEventType.disconnect
25
+ ]),
26
+ routeKey: zod.string()
27
+ }),
28
+ body: zod.string().transform((value, context)=>{
29
+ if (!value) return;
30
+ try {
31
+ return JSON.parse(value);
32
+ } catch (ex) {
33
+ console.error(`Failed body validation: ${ex.message}`);
34
+ console.log(`Body: ${value}`);
35
+ context.addIssue({
36
+ path: [],
37
+ message: `Invalid JSON: ${ex.message}`,
38
+ code: zod.ZodIssueCode.custom,
39
+ fatal: true
40
+ });
41
+ }
42
+ }).optional()
43
+ }).superRefine((output, context)=>{
44
+ if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) return;
45
+ if (output.body) return;
46
+ context.addIssue({
47
+ path: [
48
+ "body"
49
+ ],
50
+ message: "There must be a body defined when having a message event.",
51
+ code: zod.ZodIssueCode.custom,
52
+ fatal: true
53
+ });
54
+ });
55
+ const bodyValidation = zod.looseObject({
56
+ token: zod.string(),
57
+ tenant: zod.string(),
58
+ messageId: zod.string().nullish(),
59
+ action: zod.string(),
60
+ data: zod.looseObject({}).nullish()
61
+ }).optional();
62
+ class AwsWebsocketsEventValidator {
63
+ async validate(input) {
64
+ const result = await validation.safeParseAsync(input);
65
+ if (!result.success) throw createZodError(result.error);
66
+ const bodyResult = await bodyValidation.safeParseAsync(result.data.body);
67
+ if (!bodyResult.success) throw createZodError(bodyResult.error);
68
+ const rc = result.data.requestContext;
69
+ return {
70
+ headers: result.data.headers,
71
+ context: {
72
+ connectionId: rc.connectionId,
73
+ connectedAt: rc.connectedAt,
74
+ host: rc.domainName,
75
+ eventType: eventTypeMap[rc.eventType],
76
+ route: routeKeyMap[rc.routeKey] || rc.routeKey,
77
+ endpoint: `https://${rc.domainName}/${rc.stage}`
78
+ },
79
+ body: {
80
+ ...bodyResult.data || {}
81
+ }
82
+ };
83
+ }
84
+ }
85
+ export { AwsWebsocketsEventValidator };
86
+
87
+ //# sourceMappingURL=AwsWebsocketsEventValidator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator/AwsWebsocketsEventValidator.js","sources":["../../src/validator/AwsWebsocketsEventValidator.ts"],"sourcesContent":["import zod from \"zod\";\nimport { WebsocketsEventValidator, WebsocketsRunner } from \"@webiny/api-websockets/exports/api.js\";\nimport { WebsocketsEventRequestContextEventType } from \"~/handler/types.js\";\nimport { createZodError } from \"@webiny/utils\";\n\nconst eventTypeMap: Record<WebsocketsEventRequestContextEventType, WebsocketsRunner.EventType> = {\n [WebsocketsEventRequestContextEventType.message]: \"message\",\n [WebsocketsEventRequestContextEventType.connect]: \"connect\",\n [WebsocketsEventRequestContextEventType.disconnect]: \"disconnect\"\n};\n\nconst routeKeyMap: Record<string, string> = {\n $connect: \"connect\",\n $disconnect: \"disconnect\",\n $default: \"default\"\n};\n\nconst validation = zod\n .object({\n headers: zod.looseObject({}).optional(),\n requestContext: zod.object({\n connectionId: zod.string(),\n stage: zod.string(),\n connectedAt: zod.number(),\n domainName: zod.string(),\n eventType: zod.enum([\n WebsocketsEventRequestContextEventType.connect,\n WebsocketsEventRequestContextEventType.message,\n WebsocketsEventRequestContextEventType.disconnect\n ]),\n routeKey: zod.string()\n }),\n body: zod\n .string()\n .transform<WebsocketsRunner.EventData>((value, context) => {\n if (!value) {\n return undefined;\n }\n try {\n return JSON.parse(value);\n } catch (ex) {\n console.error(`Failed body validation: ${ex.message}`);\n console.log(`Body: ${value}`);\n context.addIssue({\n path: [],\n message: `Invalid JSON: ${ex.message}`,\n code: zod.ZodIssueCode.custom,\n fatal: true\n });\n }\n })\n .optional()\n })\n .superRefine((output, context) => {\n if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) {\n return;\n } else if (output.body) {\n return;\n }\n context.addIssue({\n path: [\"body\"],\n message: \"There must be a body defined when having a message event.\",\n code: zod.ZodIssueCode.custom,\n fatal: true\n });\n });\n\nconst bodyValidation = zod\n .looseObject({\n token: zod.string(),\n tenant: zod.string(),\n messageId: zod.string().nullish(),\n action: zod.string(),\n data: zod.looseObject({}).nullish()\n })\n .optional();\n\nexport class AwsWebsocketsEventValidator implements WebsocketsEventValidator.Interface {\n public async validate<T extends WebsocketsRunner.EventData = WebsocketsRunner.EventData>(\n input: unknown\n ): Promise<WebsocketsRunner.Event<T>> {\n const result = await validation.safeParseAsync(input);\n if (!result.success) {\n throw createZodError(result.error);\n }\n const bodyResult = await bodyValidation.safeParseAsync(result.data.body);\n if (!bodyResult.success) {\n throw createZodError(bodyResult.error);\n }\n\n const rc = result.data.requestContext;\n\n return {\n headers: result.data.headers as Record<string, string>,\n context: {\n connectionId: rc.connectionId,\n connectedAt: rc.connectedAt,\n host: rc.domainName,\n eventType: eventTypeMap[rc.eventType as WebsocketsEventRequestContextEventType],\n route: routeKeyMap[rc.routeKey] || rc.routeKey,\n endpoint: `https://${rc.domainName}/${rc.stage}`\n },\n body: {\n ...((bodyResult.data || {}) as T)\n }\n };\n }\n}\n"],"names":["eventTypeMap","WebsocketsEventRequestContextEventType","routeKeyMap","validation","zod","value","context","JSON","ex","console","output","bodyValidation","AwsWebsocketsEventValidator","input","result","createZodError","bodyResult","rc"],"mappings":";;;AAKA,MAAMA,eAA2F;IAC7F,CAACC,uCAAuC,OAAO,CAAC,EAAE;IAClD,CAACA,uCAAuC,OAAO,CAAC,EAAE;IAClD,CAACA,uCAAuC,UAAU,CAAC,EAAE;AACzD;AAEA,MAAMC,cAAsC;IACxC,UAAU;IACV,aAAa;IACb,UAAU;AACd;AAEA,MAAMC,aAAaC,IAAAA,MACR,CAAC;IACJ,SAASA,IAAI,WAAW,CAAC,CAAC,GAAG,QAAQ;IACrC,gBAAgBA,IAAI,MAAM,CAAC;QACvB,cAAcA,IAAI,MAAM;QACxB,OAAOA,IAAI,MAAM;QACjB,aAAaA,IAAI,MAAM;QACvB,YAAYA,IAAI,MAAM;QACtB,WAAWA,GAAG,CAAHA,OAAQ,CAAC;YAChBH,uCAAuC,OAAO;YAC9CA,uCAAuC,OAAO;YAC9CA,uCAAuC,UAAU;SACpD;QACD,UAAUG,IAAI,MAAM;IACxB;IACA,MAAMA,IAAAA,MACK,GACN,SAAS,CAA6B,CAACC,OAAOC;QAC3C,IAAI,CAACD,OACD;QAEJ,IAAI;YACA,OAAOE,KAAK,KAAK,CAACF;QACtB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CAAC,CAAC,wBAAwB,EAAED,GAAG,OAAO,EAAE;YACrDC,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAEJ,OAAO;YAC5BC,QAAQ,QAAQ,CAAC;gBACb,MAAM,EAAE;gBACR,SAAS,CAAC,cAAc,EAAEE,GAAG,OAAO,EAAE;gBACtC,MAAMJ,IAAI,YAAY,CAAC,MAAM;gBAC7B,OAAO;YACX;QACJ;IACJ,GACC,QAAQ;AACjB,GACC,WAAW,CAAC,CAACM,QAAQJ;IAClB,IAAII,OAAO,cAAc,CAAC,SAAS,KAAKT,uCAAuC,OAAO,EAClF;IACG,IAAIS,OAAO,IAAI,EAClB;IAEJJ,QAAQ,QAAQ,CAAC;QACb,MAAM;YAAC;SAAO;QACd,SAAS;QACT,MAAMF,IAAI,YAAY,CAAC,MAAM;QAC7B,OAAO;IACX;AACJ;AAEJ,MAAMO,iBAAiBP,IAAAA,WACP,CAAC;IACT,OAAOA,IAAI,MAAM;IACjB,QAAQA,IAAI,MAAM;IAClB,WAAWA,IAAI,MAAM,GAAG,OAAO;IAC/B,QAAQA,IAAI,MAAM;IAClB,MAAMA,IAAI,WAAW,CAAC,CAAC,GAAG,OAAO;AACrC,GACC,QAAQ;AAEN,MAAMQ;IACT,MAAa,SACTC,KAAc,EACoB;QAClC,MAAMC,SAAS,MAAMX,WAAW,cAAc,CAACU;QAC/C,IAAI,CAACC,OAAO,OAAO,EACf,MAAMC,eAAeD,OAAO,KAAK;QAErC,MAAME,aAAa,MAAML,eAAe,cAAc,CAACG,OAAO,IAAI,CAAC,IAAI;QACvE,IAAI,CAACE,WAAW,OAAO,EACnB,MAAMD,eAAeC,WAAW,KAAK;QAGzC,MAAMC,KAAKH,OAAO,IAAI,CAAC,cAAc;QAErC,OAAO;YACH,SAASA,OAAO,IAAI,CAAC,OAAO;YAC5B,SAAS;gBACL,cAAcG,GAAG,YAAY;gBAC7B,aAAaA,GAAG,WAAW;gBAC3B,MAAMA,GAAG,UAAU;gBACnB,WAAWjB,YAAY,CAACiB,GAAG,SAAS,CAA2C;gBAC/E,OAAOf,WAAW,CAACe,GAAG,QAAQ,CAAC,IAAIA,GAAG,QAAQ;gBAC9C,UAAU,CAAC,QAAQ,EAAEA,GAAG,UAAU,CAAC,CAAC,EAAEA,GAAG,KAAK,EAAE;YACpD;YACA,MAAM;gBACF,GAAKD,WAAW,IAAI,IAAI,CAAC,CAAC;YAC9B;QACJ;IACJ;AACJ"}