@webiny/api-websockets 6.3.0-beta.4 → 6.4.0-beta.0

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 (88) hide show
  1. package/context/WebsocketsContext.js +57 -72
  2. package/context/WebsocketsContext.js.map +1 -1
  3. package/context/abstractions/IWebsocketsContext.js +0 -3
  4. package/context/index.js +12 -15
  5. package/context/index.js.map +1 -1
  6. package/exports/api.d.ts +1 -0
  7. package/exports/api.js +5 -0
  8. package/exports/api.js.map +1 -0
  9. package/features/WebsocketService/abstractions.js +2 -1
  10. package/features/WebsocketService/abstractions.js.map +1 -1
  11. package/features/WebsocketService/errors.js +28 -30
  12. package/features/WebsocketService/errors.js.map +1 -1
  13. package/features/WebsocketService/index.js +0 -2
  14. package/graphql/checkPermissions.js +5 -11
  15. package/graphql/checkPermissions.js.map +1 -1
  16. package/graphql/createResolvers.js +55 -76
  17. package/graphql/createResolvers.js.map +1 -1
  18. package/graphql/createTypeDefs.js +2 -3
  19. package/graphql/createTypeDefs.js.map +1 -1
  20. package/graphql/index.js +8 -7
  21. package/graphql/index.js.map +1 -1
  22. package/graphql/utils.js +8 -7
  23. package/graphql/utils.js.map +1 -1
  24. package/handler/handler.js +58 -66
  25. package/handler/handler.js.map +1 -1
  26. package/handler/headers.js +21 -28
  27. package/handler/headers.js.map +1 -1
  28. package/handler/register.js +9 -19
  29. package/handler/register.js.map +1 -1
  30. package/handler/types.js +11 -10
  31. package/handler/types.js.map +1 -1
  32. package/index.js +5 -3
  33. package/index.js.map +1 -1
  34. package/package.json +20 -20
  35. package/plugins/WebsocketsActionPlugin.js +14 -13
  36. package/plugins/WebsocketsActionPlugin.js.map +1 -1
  37. package/plugins/WebsocketsRoutePlugin.js +14 -13
  38. package/plugins/WebsocketsRoutePlugin.js.map +1 -1
  39. package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -3
  40. package/plugins/index.js +0 -2
  41. package/registry/WebsocketsConnectionRegistry.js +107 -146
  42. package/registry/WebsocketsConnectionRegistry.js.map +1 -1
  43. package/registry/abstractions/IWebsocketsConnectionRegistry.js +0 -3
  44. package/registry/entity.js +44 -43
  45. package/registry/entity.js.map +1 -1
  46. package/registry/index.js +0 -2
  47. package/response/WebsocketsResponse.js +20 -19
  48. package/response/WebsocketsResponse.js.map +1 -1
  49. package/response/abstractions/IWebsocketsResponse.js +0 -3
  50. package/response/index.js +0 -2
  51. package/runner/WebsocketsRunner.js +137 -164
  52. package/runner/WebsocketsRunner.js.map +1 -1
  53. package/runner/abstractions/IWebsocketsRunner.js +0 -3
  54. package/runner/index.js +0 -2
  55. package/runner/routes/connect.js +30 -40
  56. package/runner/routes/connect.js.map +1 -1
  57. package/runner/routes/default.js +16 -22
  58. package/runner/routes/default.js.map +1 -1
  59. package/runner/routes/disconnect.js +10 -13
  60. package/runner/routes/disconnect.js.map +1 -1
  61. package/runner/routes/index.js +6 -3
  62. package/runner/routes/index.js.map +1 -1
  63. package/transport/WebsocketsTransport.js +36 -39
  64. package/transport/WebsocketsTransport.js.map +1 -1
  65. package/transport/abstractions/IWebsocketsTransport.js +0 -3
  66. package/transport/index.js +0 -2
  67. package/types.js +0 -3
  68. package/utils/middleware.js +9 -14
  69. package/utils/middleware.js.map +1 -1
  70. package/validator/WebsocketsEventValidator.js +55 -63
  71. package/validator/WebsocketsEventValidator.js.map +1 -1
  72. package/validator/abstractions/IWebsocketsEventValidator.js +0 -3
  73. package/validator/index.js +0 -2
  74. package/context/abstractions/IWebsocketsContext.js.map +0 -1
  75. package/features/WebsocketService/index.js.map +0 -1
  76. package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
  77. package/plugins/index.js.map +0 -1
  78. package/registry/abstractions/IWebsocketsConnectionRegistry.js.map +0 -1
  79. package/registry/index.js.map +0 -1
  80. package/response/abstractions/IWebsocketsResponse.js.map +0 -1
  81. package/response/index.js.map +0 -1
  82. package/runner/abstractions/IWebsocketsRunner.js.map +0 -1
  83. package/runner/index.js.map +0 -1
  84. package/transport/abstractions/IWebsocketsTransport.js.map +0 -1
  85. package/transport/index.js.map +0 -1
  86. package/types.js.map +0 -1
  87. package/validator/abstractions/IWebsocketsEventValidator.js.map +0 -1
  88. package/validator/index.js.map +0 -1
@@ -1,47 +1,44 @@
1
1
  import { ApiGatewayManagementApiClient, DeleteConnectionCommand, PostToConnectionCommand } from "@webiny/aws-sdk/client-apigatewaymanagementapi/index.js";
2
- export class WebsocketsTransport {
3
- clients = new Map();
4
- async send(connections, data) {
5
- for (const connection of connections) {
6
- try {
7
- const client = this.getClient(connection);
8
- const command = new PostToConnectionCommand({
9
- ConnectionId: connection.connectionId,
10
- Data: JSON.stringify(data)
11
- });
12
- await client.send(command);
13
- } catch (ex) {
14
- console.error(`Failed to send message to connection "${connection.connectionId}". Check logs for more information.`);
15
- console.log(ex);
16
- }
2
+ class WebsocketsTransport {
3
+ async send(connections, data) {
4
+ for (const connection of connections)try {
5
+ const client = this.getClient(connection);
6
+ const command = new PostToConnectionCommand({
7
+ ConnectionId: connection.connectionId,
8
+ Data: JSON.stringify(data)
9
+ });
10
+ await client.send(command);
11
+ } catch (ex) {
12
+ console.error(`Failed to send message to connection "${connection.connectionId}". Check logs for more information.`);
13
+ console.log(ex);
14
+ }
15
+ }
16
+ async disconnect(connections) {
17
+ for (const connection of connections)try {
18
+ const client = this.getClient(connection);
19
+ const command = new DeleteConnectionCommand({
20
+ ConnectionId: connection.connectionId
21
+ });
22
+ await client.send(command);
23
+ } catch (ex) {
24
+ console.error(`Failed to disconnect connection "${connection.connectionId}". Check logs for more information.`);
25
+ console.log(ex);
26
+ }
17
27
  }
18
- }
19
- async disconnect(connections) {
20
- for (const connection of connections) {
21
- try {
22
- const client = this.getClient(connection);
23
- const command = new DeleteConnectionCommand({
24
- ConnectionId: connection.connectionId
28
+ getClient(connection) {
29
+ const endpoint = `https://${connection.domainName}/${connection.stage}`;
30
+ const client = this.clients.get(endpoint);
31
+ if (client) return client;
32
+ const newClient = new ApiGatewayManagementApiClient({
33
+ endpoint
25
34
  });
26
- await client.send(command);
27
- } catch (ex) {
28
- console.error(`Failed to disconnect connection "${connection.connectionId}". Check logs for more information.`);
29
- console.log(ex);
30
- }
35
+ this.clients.set(endpoint, newClient);
36
+ return newClient;
31
37
  }
32
- }
33
- getClient(connection) {
34
- const endpoint = `https://${connection.domainName}/${connection.stage}`;
35
- const client = this.clients.get(endpoint);
36
- if (client) {
37
- return client;
38
+ constructor(){
39
+ this.clients = new Map();
38
40
  }
39
- const newClient = new ApiGatewayManagementApiClient({
40
- endpoint
41
- });
42
- this.clients.set(endpoint, newClient);
43
- return newClient;
44
- }
45
41
  }
42
+ export { WebsocketsTransport };
46
43
 
47
44
  //# sourceMappingURL=WebsocketsTransport.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["ApiGatewayManagementApiClient","DeleteConnectionCommand","PostToConnectionCommand","WebsocketsTransport","clients","Map","send","connections","data","connection","client","getClient","command","ConnectionId","connectionId","Data","JSON","stringify","ex","console","error","log","disconnect","endpoint","domainName","stage","get","newClient","set"],"sources":["WebsocketsTransport.ts"],"sourcesContent":["import {\n ApiGatewayManagementApiClient,\n DeleteConnectionCommand,\n PostToConnectionCommand\n} from \"@webiny/aws-sdk/client-apigatewaymanagementapi/index.js\";\nimport type {\n IWebsocketsTransport,\n IWebsocketsTransportDisconnectConnection,\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"./abstractions/IWebsocketsTransport.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport class WebsocketsTransport implements IWebsocketsTransport {\n private readonly clients = new Map<string, ApiGatewayManagementApiClient>();\n\n public async send<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void> {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\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: IWebsocketsTransportDisconnectConnection[]) {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\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(\n connection: IWebsocketsTransportSendConnection\n ): ApiGatewayManagementApiClient {\n const endpoint = `https://${connection.domainName}/${connection.stage}`;\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"],"mappings":"AAAA,SACIA,6BAA6B,EAC7BC,uBAAuB,EACvBC,uBAAuB,QACpB,yDAAyD;AAShE,OAAO,MAAMC,mBAAmB,CAAiC;EAC5CC,OAAO,GAAG,IAAIC,GAAG,CAAwC,CAAC;EAE3E,MAAaC,IAAIA,CACbC,WAAiD,EACjDC,IAAqC,EACxB;IACb,KAAK,MAAMC,UAAU,IAAIF,WAAW,EAAE;MAClC,IAAI;QACA,MAAMG,MAAM,GAAG,IAAI,CAACC,SAAS,CAACF,UAAU,CAAC;QAEzC,MAAMG,OAAO,GAAG,IAAIV,uBAAuB,CAAC;UACxCW,YAAY,EAAEJ,UAAU,CAACK,YAAY;UACrCC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACT,IAAI;QAC7B,CAAC,CAAC;QACF,MAAME,MAAM,CAACJ,IAAI,CAACM,OAAO,CAAC;MAC9B,CAAC,CAAC,OAAOM,EAAE,EAAE;QACTC,OAAO,CAACC,KAAK,CACT,yCAAyCX,UAAU,CAACK,YAAY,qCACpE,CAAC;QACDK,OAAO,CAACE,GAAG,CAACH,EAAE,CAAC;MACnB;IACJ;EACJ;EAEA,MAAaI,UAAUA,CAACf,WAAuD,EAAE;IAC7E,KAAK,MAAME,UAAU,IAAIF,WAAW,EAAE;MAClC,IAAI;QACA,MAAMG,MAAM,GAAG,IAAI,CAACC,SAAS,CAACF,UAAU,CAAC;QACzC,MAAMG,OAAO,GAAG,IAAIX,uBAAuB,CAAC;UACxCY,YAAY,EAAEJ,UAAU,CAACK;QAC7B,CAAC,CAAC;QACF,MAAMJ,MAAM,CAACJ,IAAI,CAACM,OAAO,CAAC;MAC9B,CAAC,CAAC,OAAOM,EAAE,EAAE;QACTC,OAAO,CAACC,KAAK,CACT,oCAAoCX,UAAU,CAACK,YAAY,qCAC/D,CAAC;QACDK,OAAO,CAACE,GAAG,CAACH,EAAE,CAAC;MACnB;IACJ;EACJ;EAEQP,SAASA,CACbF,UAA8C,EACjB;IAC7B,MAAMc,QAAQ,GAAG,WAAWd,UAAU,CAACe,UAAU,IAAIf,UAAU,CAACgB,KAAK,EAAE;IACvE,MAAMf,MAAM,GAAG,IAAI,CAACN,OAAO,CAACsB,GAAG,CAACH,QAAQ,CAAC;IACzC,IAAIb,MAAM,EAAE;MACR,OAAOA,MAAM;IACjB;IACA,MAAMiB,SAAS,GAAG,IAAI3B,6BAA6B,CAAC;MAChDuB;IACJ,CAAC,CAAC;IACF,IAAI,CAACnB,OAAO,CAACwB,GAAG,CAACL,QAAQ,EAAEI,SAAS,CAAC;IACrC,OAAOA,SAAS;EACpB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"transport/WebsocketsTransport.js","sources":["../../src/transport/WebsocketsTransport.ts"],"sourcesContent":["import {\n ApiGatewayManagementApiClient,\n DeleteConnectionCommand,\n PostToConnectionCommand\n} from \"@webiny/aws-sdk/client-apigatewaymanagementapi/index.js\";\nimport type {\n IWebsocketsTransport,\n IWebsocketsTransportDisconnectConnection,\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"./abstractions/IWebsocketsTransport.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport class WebsocketsTransport implements IWebsocketsTransport {\n private readonly clients = new Map<string, ApiGatewayManagementApiClient>();\n\n public async send<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void> {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\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: IWebsocketsTransportDisconnectConnection[]) {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\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(\n connection: IWebsocketsTransportSendConnection\n ): ApiGatewayManagementApiClient {\n const endpoint = `https://${connection.domainName}/${connection.stage}`;\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"],"names":["WebsocketsTransport","connections","data","connection","client","command","PostToConnectionCommand","JSON","ex","console","DeleteConnectionCommand","endpoint","newClient","ApiGatewayManagementApiClient","Map"],"mappings":";AAaO,MAAMA;IAGT,MAAa,KACTC,WAAiD,EACjDC,IAAqC,EACxB;QACb,KAAK,MAAMC,cAAcF,YACrB,IAAI;YACA,MAAMG,SAAS,IAAI,CAAC,SAAS,CAACD;YAE9B,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;YAC9B,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,UACJL,UAA8C,EACjB;QAC7B,MAAMQ,WAAW,CAAC,QAAQ,EAAER,WAAW,UAAU,CAAC,CAAC,EAAEA,WAAW,KAAK,EAAE;QACvE,MAAMC,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;;aAtDiB,OAAO,GAAG,IAAIE;;AAuDnC"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=IWebsocketsTransport.js.map
@@ -1,3 +1 @@
1
1
  export * from "./WebsocketsTransport.js";
2
-
3
- //# sourceMappingURL=index.js.map
package/types.js CHANGED
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=types.js.map
@@ -1,18 +1,13 @@
1
- export const middleware = functions => {
2
- return async input => {
3
- const chain = Array.from(functions);
4
- const exec = async () => {
5
- const fn = chain.shift();
6
- if (!fn) {
7
- return {};
8
- }
9
- const next = async () => {
1
+ const middleware = (functions)=>async (input)=>{
2
+ const chain = Array.from(functions);
3
+ const exec = async ()=>{
4
+ const fn = chain.shift();
5
+ if (!fn) return {};
6
+ const next = async ()=>exec();
7
+ return fn(input, next);
8
+ };
10
9
  return exec();
11
- };
12
- return fn(input, next);
13
10
  };
14
- return exec();
15
- };
16
- };
11
+ export { middleware };
17
12
 
18
13
  //# sourceMappingURL=middleware.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["middleware","functions","input","chain","Array","from","exec","fn","shift","next"],"sources":["middleware.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface MiddlewareCallable<\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n> {\n (input: I, next: () => Promise<O>): Promise<O>;\n}\n\nexport const middleware = <\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n>(\n functions: MiddlewareCallable<I, O>[]\n) => {\n return async (input: I): Promise<O> => {\n const chain = Array.from(functions);\n const exec = async (): Promise<O> => {\n const fn = chain.shift();\n if (!fn) {\n return {} as O;\n }\n const next = async () => {\n return exec();\n };\n return fn(input, next);\n };\n return exec();\n };\n};\n"],"mappings":"AASA,OAAO,MAAMA,UAAU,GAInBC,SAAqC,IACpC;EACD,OAAO,MAAOC,KAAQ,IAAiB;IACnC,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAACJ,SAAS,CAAC;IACnC,MAAMK,IAAI,GAAG,MAAAA,CAAA,KAAwB;MACjC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAK,CAAC,CAAC;MACxB,IAAI,CAACD,EAAE,EAAE;QACL,OAAO,CAAC,CAAC;MACb;MACA,MAAME,IAAI,GAAG,MAAAA,CAAA,KAAY;QACrB,OAAOH,IAAI,CAAC,CAAC;MACjB,CAAC;MACD,OAAOC,EAAE,CAACL,KAAK,EAAEO,IAAI,CAAC;IAC1B,CAAC;IACD,OAAOH,IAAI,CAAC,CAAC;EACjB,CAAC;AACL,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils/middleware.js","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface MiddlewareCallable<\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n> {\n (input: I, next: () => Promise<O>): Promise<O>;\n}\n\nexport const middleware = <\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n>(\n functions: MiddlewareCallable<I, O>[]\n) => {\n return async (input: I): Promise<O> => {\n const chain = Array.from(functions);\n const exec = async (): Promise<O> => {\n const fn = chain.shift();\n if (!fn) {\n return {} as O;\n }\n const next = async () => {\n return exec();\n };\n return fn(input, next);\n };\n return exec();\n };\n};\n"],"names":["middleware","functions","input","chain","Array","exec","fn","next"],"mappings":"AASO,MAAMA,aAAa,CAItBC,YAEO,OAAOC;QACV,MAAMC,QAAQC,MAAM,IAAI,CAACH;QACzB,MAAMI,OAAO;YACT,MAAMC,KAAKH,MAAM,KAAK;YACtB,IAAI,CAACG,IACD,OAAO,CAAC;YAEZ,MAAMC,OAAO,UACFF;YAEX,OAAOC,GAAGJ,OAAOK;QACrB;QACA,OAAOF;IACX"}
@@ -2,75 +2,67 @@ import zod from "zod";
2
2
  import { WebsocketsEventRequestContextEventType } from "../handler/types.js";
3
3
  import { createZodError } from "@webiny/utils";
4
4
  const validation = zod.object({
5
- headers: zod.looseObject({}).optional(),
6
- requestContext: zod.object({
7
- connectionId: zod.string(),
8
- stage: zod.string(),
9
- connectedAt: zod.number(),
10
- domainName: zod.string(),
11
- eventType: zod.enum([WebsocketsEventRequestContextEventType.connect, WebsocketsEventRequestContextEventType.message, WebsocketsEventRequestContextEventType.disconnect]),
12
- routeKey: zod.string()
13
- }),
14
- body: zod.string().transform((value, context) => {
15
- if (!value) {
16
- return undefined;
17
- }
18
- try {
19
- return JSON.parse(value);
20
- } catch (ex) {
21
- /**
22
- * We want to log the error, for easier debugging.
23
- */
24
- console.error(`Failed body validation: ${ex.message}`);
25
- console.log(`Body: ${value}`);
26
- /**
27
- * And we want to add an issue to the context, so that the user knows what went wrong.
28
- */
29
- context.addIssue({
30
- path: [],
31
- message: `Invalid JSON: ${ex.message}`,
5
+ headers: zod.looseObject({}).optional(),
6
+ requestContext: zod.object({
7
+ connectionId: zod.string(),
8
+ stage: zod.string(),
9
+ connectedAt: zod.number(),
10
+ domainName: zod.string(),
11
+ eventType: zod["enum"]([
12
+ WebsocketsEventRequestContextEventType.connect,
13
+ WebsocketsEventRequestContextEventType.message,
14
+ WebsocketsEventRequestContextEventType.disconnect
15
+ ]),
16
+ routeKey: zod.string()
17
+ }),
18
+ body: zod.string().transform((value, context)=>{
19
+ if (!value) return;
20
+ try {
21
+ return JSON.parse(value);
22
+ } catch (ex) {
23
+ console.error(`Failed body validation: ${ex.message}`);
24
+ console.log(`Body: ${value}`);
25
+ context.addIssue({
26
+ path: [],
27
+ message: `Invalid JSON: ${ex.message}`,
28
+ code: zod.ZodIssueCode.custom,
29
+ fatal: true
30
+ });
31
+ }
32
+ }).optional()
33
+ }).superRefine((output, context)=>{
34
+ if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) return;
35
+ if (output.body) return;
36
+ context.addIssue({
37
+ path: [
38
+ "body"
39
+ ],
40
+ message: "There must be a body defined when having a message event.",
32
41
  code: zod.ZodIssueCode.custom,
33
42
  fatal: true
34
- });
35
- }
36
- }).optional()
37
- }).superRefine((output, context) => {
38
- if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) {
39
- return;
40
- } else if (output.body) {
41
- return;
42
- }
43
- context.addIssue({
44
- path: ["body"],
45
- message: "There must be a body defined when having a message event.",
46
- code: zod.ZodIssueCode.custom,
47
- fatal: true
48
- });
43
+ });
49
44
  });
50
45
  const bodyValidation = zod.looseObject({
51
- token: zod.string(),
52
- tenant: zod.string(),
53
- messageId: zod.string().nullish(),
54
- action: zod.string(),
55
- data: zod.looseObject({}).nullish()
46
+ token: zod.string(),
47
+ tenant: zod.string(),
48
+ messageId: zod.string().nullish(),
49
+ action: zod.string(),
50
+ data: zod.looseObject({}).nullish()
56
51
  }).optional();
57
- export class WebsocketsEventValidator {
58
- async validate(input) {
59
- const result = await validation.safeParseAsync(input);
60
- if (!result.success) {
61
- throw createZodError(result.error);
62
- }
63
- const bodyResult = await bodyValidation.safeParseAsync(result.data.body);
64
- if (!bodyResult.success) {
65
- throw createZodError(bodyResult.error);
52
+ class WebsocketsEventValidator {
53
+ async validate(input) {
54
+ const result = await validation.safeParseAsync(input);
55
+ if (!result.success) throw createZodError(result.error);
56
+ const bodyResult = await bodyValidation.safeParseAsync(result.data.body);
57
+ if (!bodyResult.success) throw createZodError(bodyResult.error);
58
+ return {
59
+ ...result.data,
60
+ body: {
61
+ ...bodyResult.data || {}
62
+ }
63
+ };
66
64
  }
67
- return {
68
- ...result.data,
69
- body: {
70
- ...(bodyResult.data || {})
71
- }
72
- };
73
- }
74
65
  }
66
+ export { WebsocketsEventValidator };
75
67
 
76
68
  //# sourceMappingURL=WebsocketsEventValidator.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["zod","WebsocketsEventRequestContextEventType","createZodError","validation","object","headers","looseObject","optional","requestContext","connectionId","string","stage","connectedAt","number","domainName","eventType","enum","connect","message","disconnect","routeKey","body","transform","value","context","undefined","JSON","parse","ex","console","error","log","addIssue","path","code","ZodIssueCode","custom","fatal","superRefine","output","bodyValidation","token","tenant","messageId","nullish","action","data","WebsocketsEventValidator","validate","input","result","safeParseAsync","success","bodyResult"],"sources":["WebsocketsEventValidator.ts"],"sourcesContent":["import zod from \"zod\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/handler/types.js\";\nimport { WebsocketsEventRequestContextEventType } from \"~/handler/types.js\";\nimport type {\n IWebsocketsEventValidator,\n IWebsocketsEventValidatorValidateParams\n} from \"./abstractions/IWebsocketsEventValidator.js\";\nimport { createZodError } from \"@webiny/utils\";\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<IWebsocketsEventData>((value, context) => {\n if (!value) {\n return undefined;\n }\n try {\n return JSON.parse(value);\n } catch (ex) {\n /**\n * We want to log the error, for easier debugging.\n */\n console.error(`Failed body validation: ${ex.message}`);\n console.log(`Body: ${value}`);\n /**\n * And we want to add an issue to the context, so that the user knows what went wrong.\n */\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 WebsocketsEventValidator implements IWebsocketsEventValidator {\n public async validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n input: IWebsocketsEventValidatorValidateParams\n ): Promise<IWebsocketsEvent<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 return {\n ...result.data,\n body: {\n ...((bodyResult.data || {}) as T)\n }\n };\n }\n}\n"],"mappings":"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","ignoreList":[]}
1
+ {"version":3,"file":"validator/WebsocketsEventValidator.js","sources":["../../src/validator/WebsocketsEventValidator.ts"],"sourcesContent":["import zod from \"zod\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/handler/types.js\";\nimport { WebsocketsEventRequestContextEventType } from \"~/handler/types.js\";\nimport type {\n IWebsocketsEventValidator,\n IWebsocketsEventValidatorValidateParams\n} from \"./abstractions/IWebsocketsEventValidator.js\";\nimport { createZodError } from \"@webiny/utils\";\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<IWebsocketsEventData>((value, context) => {\n if (!value) {\n return undefined;\n }\n try {\n return JSON.parse(value);\n } catch (ex) {\n /**\n * We want to log the error, for easier debugging.\n */\n console.error(`Failed body validation: ${ex.message}`);\n console.log(`Body: ${value}`);\n /**\n * And we want to add an issue to the context, so that the user knows what went wrong.\n */\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 WebsocketsEventValidator implements IWebsocketsEventValidator {\n public async validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n input: IWebsocketsEventValidatorValidateParams\n ): Promise<IWebsocketsEvent<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 return {\n ...result.data,\n body: {\n ...((bodyResult.data || {}) as T)\n }\n };\n }\n}\n"],"names":["validation","zod","WebsocketsEventRequestContextEventType","value","context","JSON","ex","console","output","bodyValidation","WebsocketsEventValidator","input","result","createZodError","bodyResult"],"mappings":";;;AASA,MAAMA,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;YAChBC,uCAAuC,OAAO;YAC9CA,uCAAuC,OAAO;YAC9CA,uCAAuC,UAAU;SACpD;QACD,UAAUD,IAAI,MAAM;IACxB;IACA,MAAMA,IAAAA,MACK,GACN,SAAS,CAAuB,CAACE,OAAOC;QACrC,IAAI,CAACD,OACD;QAEJ,IAAI;YACA,OAAOE,KAAK,KAAK,CAACF;QACtB,EAAE,OAAOG,IAAI;YAITC,QAAQ,KAAK,CAAC,CAAC,wBAAwB,EAAED,GAAG,OAAO,EAAE;YACrDC,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAEJ,OAAO;YAI5BC,QAAQ,QAAQ,CAAC;gBACb,MAAM,EAAE;gBACR,SAAS,CAAC,cAAc,EAAEE,GAAG,OAAO,EAAE;gBACtC,MAAML,IAAI,YAAY,CAAC,MAAM;gBAC7B,OAAO;YACX;QACJ;IACJ,GACC,QAAQ;AACjB,GACC,WAAW,CAAC,CAACO,QAAQJ;IAClB,IAAII,OAAO,cAAc,CAAC,SAAS,KAAKN,uCAAuC,OAAO,EAClF;IACG,IAAIM,OAAO,IAAI,EAClB;IAEJJ,QAAQ,QAAQ,CAAC;QACb,MAAM;YAAC;SAAO;QACd,SAAS;QACT,MAAMH,IAAI,YAAY,CAAC,MAAM;QAC7B,OAAO;IACX;AACJ;AAEJ,MAAMQ,iBAAiBR,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,MAAMS;IACT,MAAa,SACTC,KAA8C,EAClB;QAC5B,MAAMC,SAAS,MAAMZ,WAAW,cAAc,CAACW;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;QAEzC,OAAO;YACH,GAAGF,OAAO,IAAI;YACd,MAAM;gBACF,GAAKE,WAAW,IAAI,IAAI,CAAC,CAAC;YAC9B;QACJ;IACJ;AACJ"}
@@ -1,3 +0,0 @@
1
- export {};
2
-
3
- //# sourceMappingURL=IWebsocketsEventValidator.js.map
@@ -1,3 +1 @@
1
1
  export * from "./WebsocketsEventValidator.js";
2
-
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsContext.ts"],"sourcesContent":["import type {\n IWebsocketsConnectionRegistry,\n IWebsocketsConnectionRegistryData\n} from \"~/registry/index.js\";\nimport type {\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"~/transport/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { SecurityIdentity } from \"@webiny/api-core/types/security.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { WebsocketService } from \"~/features/WebsocketService/abstractions.js\";\n\nexport type IWebsocketsIdentity = Pick<SecurityIdentity, \"id\" | \"displayName\" | \"type\">;\n\nexport interface IWebsocketsContextListConnectionsParamsWhere {\n identityId?: string;\n tenant?: string;\n connections?: string[];\n}\n\nexport interface IWebsocketsContextListConnectionsParams {\n where?: IWebsocketsContextListConnectionsParamsWhere;\n}\n\nexport type IWebsocketsContextDisconnectConnectionsParams = IWebsocketsContextListConnectionsParams;\n\nexport interface IWebsocketsContextObject {\n readonly registry: IWebsocketsConnectionRegistry;\n\n send<T extends GenericRecord = GenericRecord>(\n identity: Pick<IWebsocketsIdentity, \"id\">,\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketService.Error>>;\n sendToConnections<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketService.Error>>;\n listConnections(\n params?: IWebsocketsContextListConnectionsParams\n ): Promise<Result<IWebsocketsConnectionRegistryData[], WebsocketService.Error>>;\n disconnect(\n params?: IWebsocketsContextDisconnectConnectionsParams,\n notify?: boolean\n ): Promise<Result<IWebsocketsConnectionRegistryData[], WebsocketService.Error>>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":["WebsocketService"],"sources":["index.ts"],"sourcesContent":["export { WebsocketService } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,gBAAgB","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsActionPlugin.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { Context } from \"~/types.js\";\n\nexport interface IWebsocketsActionPluginCallableParamsSend {\n toConnection<T extends GenericRecord = GenericRecord>(\n connectionId: string,\n data: T\n ): Promise<void>;\n toTenant<T extends GenericRecord = GenericRecord>(tenant: string, data: T): Promise<void>;\n toIdentity<T extends GenericRecord = GenericRecord>(identity: string, data: T): Promise<void>;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondError<\n T extends GenericRecord = GenericRecord\n> {\n message: string;\n code: string;\n data: T;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondOkResponse<\n T extends GenericRecord = GenericRecord\n> {\n data: T;\n error?: never;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondErrorResponse<\n T extends GenericRecord = GenericRecord\n> {\n error: IWebsocketsActionPluginCallableParamsRespondError<T>;\n data?: never;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespond {\n ok<T extends GenericRecord = GenericRecord>(\n data: T\n ): Promise<IWebsocketsActionPluginCallableParamsRespondOkResponse<T>>;\n error<T extends GenericRecord = GenericRecord>(\n error: IWebsocketsActionPluginCallableParamsRespondError<T>\n ): Promise<IWebsocketsActionPluginCallableParamsRespondErrorResponse<T>>;\n}\n\nexport interface IWebsocketsActionPluginCallableParams<C extends Context = Context> {\n context: C;\n next(): Promise<void>;\n send: IWebsocketsActionPluginCallableParamsSend;\n respond: IWebsocketsActionPluginCallableParamsRespond;\n}\n\nexport type WebsocketsActionPluginCallableResponse<T extends GenericRecord = GenericRecord> =\n | IWebsocketsActionPluginCallableParamsRespondOkResponse<T>\n | IWebsocketsActionPluginCallableParamsRespondErrorResponse<T>;\n\nexport interface IWebsocketsActionPluginCallable<T extends GenericRecord = GenericRecord> {\n (\n params: IWebsocketsActionPluginCallableParams\n ): Promise<WebsocketsActionPluginCallableResponse<T>>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./WebsocketsRoutePlugin.js\";\nexport * from \"./WebsocketsActionPlugin.js\";\nexport type * from \"./abstrations/IWebsocketsActionPlugin.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsConnectionRegistry.ts"],"sourcesContent":["import type { IWebsocketsIdentity } from \"~/context/abstractions/IWebsocketsContext.js\";\n\nexport interface IWebsocketsConnectionRegistryData {\n connectionId: string;\n identity: IWebsocketsIdentity;\n tenant: string;\n connectedOn: string;\n domainName: string;\n stage: string;\n}\n\nexport interface IWebsocketsConnectionRegistryRegisterParams {\n connectionId: string;\n tenant: string;\n identity: IWebsocketsIdentity;\n domainName: string;\n stage: string;\n /**\n * A DateTime.toISOString() format.\n */\n connectedOn: string;\n}\n\nexport interface IWebsocketsConnectionRegistryUnregisterParams {\n connectionId: string;\n}\n\nexport interface IWebsocketsConnectionRegistry {\n register(\n event: IWebsocketsConnectionRegistryRegisterParams\n ): Promise<IWebsocketsConnectionRegistryData>;\n unregister(event: IWebsocketsConnectionRegistryUnregisterParams): Promise<void>;\n\n listViaConnections(connections: string[]): Promise<IWebsocketsConnectionRegistryData[]>;\n listViaIdentity(identity: string): Promise<IWebsocketsConnectionRegistryData[]>;\n listViaTenant(tenant: string): Promise<IWebsocketsConnectionRegistryData[]>;\n listAll(): Promise<IWebsocketsConnectionRegistryData[]>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsConnectionRegistry.js\";\nexport * from \"./WebsocketsConnectionRegistry.js\";\n"],"mappings":"AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsResponse.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IWebsocketsResponseOkParams {\n message?: string;\n data?: GenericRecord<string>;\n}\n\nexport interface IWebsocketsResponseOkResult {\n statusCode: number;\n data?: GenericRecord<string>;\n message?: string;\n}\n\nexport interface IWebsocketsResponseErrorParams {\n statusCode?: number;\n error?: Omit<IWebsocketsResponseErrorResultError, \"data\"> &\n Partial<Pick<IWebsocketsResponseErrorResultError, \"data\">>;\n message: string;\n}\n\nexport interface IWebsocketsResponseErrorResultError {\n message: string;\n code: string;\n data: GenericRecord<string>;\n stack?: string;\n}\n\nexport interface IWebsocketsResponseErrorResult {\n statusCode: number;\n error: IWebsocketsResponseErrorResultError;\n}\n\nexport interface IWebsocketsResponse {\n ok(params?: IWebsocketsResponseOkParams): IWebsocketsResponseOkResult;\n error(params: IWebsocketsResponseErrorParams): IWebsocketsResponseErrorResult;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsResponse.js\";\nexport * from \"./WebsocketsResponse.js\";\n"],"mappings":"AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsRunner.ts"],"sourcesContent":["import type { IWebsocketsIncomingEvent } from \"~/handler/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IWebsocketsResponseError {\n message: string;\n code: string;\n data?: GenericRecord<string> | null;\n stack?: string;\n}\nexport interface IWebsocketsRunnerResponse {\n statusCode: number;\n message?: string;\n error?: IWebsocketsResponseError;\n}\n\nexport interface IWebsocketsRunner {\n run(params: IWebsocketsIncomingEvent): Promise<IWebsocketsRunnerResponse>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsRunner.js\";\nexport * from \"./WebsocketsRunner.js\";\n"],"mappings":"AACA","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsTransport.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IWebsocketsConnectionRegistryData } from \"~/registry/index.js\";\n\nexport interface IWebsocketsTransportSendDataError {\n message: string;\n code: string;\n data?: GenericRecord;\n stack?: string;\n}\n\nexport interface IWebsocketsTransportSendData<T extends GenericRecord> {\n messageId?: string;\n action?: string;\n data?: T;\n error?: IWebsocketsTransportSendDataError;\n}\n\nexport type IWebsocketsTransportSendConnection = Pick<\n IWebsocketsConnectionRegistryData,\n \"connectionId\" | \"domainName\" | \"stage\"\n>;\n\nexport type IWebsocketsTransportDisconnectConnection = Pick<\n IWebsocketsConnectionRegistryData,\n \"connectionId\" | \"domainName\" | \"stage\"\n>;\n\nexport interface IWebsocketsTransport {\n send<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void>;\n\n disconnect(connections: IWebsocketsTransportDisconnectConnection[]): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./WebsocketsTransport.js\";\nexport type * from \"./abstractions/IWebsocketsTransport.js\";\n"],"mappings":"AAAA","ignoreList":[]}
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { IWebsocketsContextObject } from \"./context/abstractions/IWebsocketsContext.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\nexport type { IWebsocketsContextObject };\n\nexport interface Context extends DbContext, ApiCoreContext {\n websockets: IWebsocketsContextObject;\n}\n\nexport interface WebsocketsPermission extends SecurityPermission {\n name: \"websockets\";\n rwd?: string;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["IWebsocketsEventValidator.ts"],"sourcesContent":["import type {\n IWebsocketsEvent,\n IWebsocketsEventData,\n IWebsocketsIncomingEvent\n} from \"~/handler/types.js\";\n\nexport type IWebsocketsEventValidatorValidateParams = IWebsocketsIncomingEvent;\n\nexport interface IWebsocketsEventValidator {\n /**\n * @throws {Error}\n */\n validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n params: IWebsocketsEventValidatorValidateParams\n ): Promise<IWebsocketsEvent<T>>;\n}\n"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsEventValidator.js\";\nexport * from \"./WebsocketsEventValidator.js\";\n"],"mappings":"AACA","ignoreList":[]}