@webiny/api-websockets-aws 0.0.0-unstable.7c2def32a7 → 0.0.0-unstable.9609e4e0c9
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-websockets-aws",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.9609e4e0c9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-websockets",
|
|
@@ -23,33 +23,33 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@webiny/api": "0.0.0-unstable.
|
|
27
|
-
"@webiny/api-websockets": "0.0.0-unstable.
|
|
28
|
-
"@webiny/aws-sdk": "0.0.0-unstable.
|
|
29
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
30
|
-
"@webiny/error": "0.0.0-unstable.
|
|
31
|
-
"@webiny/event-handler-aws": "0.0.0-unstable.
|
|
32
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
33
|
-
"@webiny/handler": "0.0.0-unstable.
|
|
34
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
35
|
-
"type-fest": "5.
|
|
36
|
-
"zod": "4.
|
|
26
|
+
"@webiny/api": "0.0.0-unstable.9609e4e0c9",
|
|
27
|
+
"@webiny/api-websockets": "0.0.0-unstable.9609e4e0c9",
|
|
28
|
+
"@webiny/aws-sdk": "0.0.0-unstable.9609e4e0c9",
|
|
29
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.9609e4e0c9",
|
|
30
|
+
"@webiny/error": "0.0.0-unstable.9609e4e0c9",
|
|
31
|
+
"@webiny/event-handler-aws": "0.0.0-unstable.9609e4e0c9",
|
|
32
|
+
"@webiny/feature": "0.0.0-unstable.9609e4e0c9",
|
|
33
|
+
"@webiny/handler": "0.0.0-unstable.9609e4e0c9",
|
|
34
|
+
"@webiny/utils": "0.0.0-unstable.9609e4e0c9",
|
|
35
|
+
"type-fest": "5.10.0",
|
|
36
|
+
"zod": "4.6.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
40
|
-
"@webiny/api-core-testing": "0.0.0-unstable.
|
|
41
|
-
"@webiny/api-graphql": "0.0.0-unstable.
|
|
42
|
-
"@webiny/api-headless-cms": "0.0.0-unstable.
|
|
43
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
39
|
+
"@webiny/api-core": "0.0.0-unstable.9609e4e0c9",
|
|
40
|
+
"@webiny/api-core-testing": "0.0.0-unstable.9609e4e0c9",
|
|
41
|
+
"@webiny/api-graphql": "0.0.0-unstable.9609e4e0c9",
|
|
42
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.9609e4e0c9",
|
|
43
|
+
"@webiny/build-tools": "0.0.0-unstable.9609e4e0c9",
|
|
44
44
|
"@webiny/di": "2.0.0",
|
|
45
|
-
"@webiny/event-handler-core": "0.0.0-unstable.
|
|
46
|
-
"@webiny/wcp": "0.0.0-unstable.
|
|
45
|
+
"@webiny/event-handler-core": "0.0.0-unstable.9609e4e0c9",
|
|
46
|
+
"@webiny/wcp": "0.0.0-unstable.9609e4e0c9",
|
|
47
47
|
"aws-sdk-client-mock": "4.1.0",
|
|
48
48
|
"graphql": "16.14.2",
|
|
49
49
|
"rimraf": "6.1.3",
|
|
50
|
-
"type-fest": "5.
|
|
50
|
+
"type-fest": "5.10.0",
|
|
51
51
|
"typescript": "7.0.2",
|
|
52
|
-
"vitest": "
|
|
52
|
+
"vitest": "5.0.5"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
@@ -42,7 +42,7 @@ const validation = zod.object({
|
|
|
42
42
|
}).optional()
|
|
43
43
|
}).superRefine((output, context)=>{
|
|
44
44
|
if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) return;
|
|
45
|
-
if (output.body) return;
|
|
45
|
+
else if (output.body) return;
|
|
46
46
|
context.addIssue({
|
|
47
47
|
path: [
|
|
48
48
|
"body"
|
|
@@ -1 +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;
|
|
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,CAA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