@webiny/api-websockets 0.0.0-unstable.5387e5f7c8 → 0.0.0-unstable.676006d08e

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 (52) hide show
  1. package/WebsocketsFeature.js +2 -0
  2. package/WebsocketsFeature.js.map +1 -1
  3. package/exports/api.d.ts +0 -8
  4. package/exports/api.js +0 -7
  5. package/features/ConnectionRegistry/abstractions.d.ts +3 -1
  6. package/features/ConnectionRegistry/abstractions.js.map +1 -1
  7. package/features/Disconnect/DisconnectUseCase.js +3 -0
  8. package/features/Disconnect/DisconnectUseCase.js.map +1 -1
  9. package/features/Disconnect/validateDisconnectWhere.d.ts +8 -0
  10. package/features/Disconnect/validateDisconnectWhere.js +12 -0
  11. package/features/Disconnect/validateDisconnectWhere.js.map +1 -0
  12. package/features/ListConnections/ListConnectionsUseCase.d.ts +3 -1
  13. package/features/ListConnections/ListConnectionsUseCase.js +10 -4
  14. package/features/ListConnections/ListConnectionsUseCase.js.map +1 -1
  15. package/features/ListConnections/abstractions.d.ts +0 -1
  16. package/features/ListConnections/abstractions.js.map +1 -1
  17. package/features/Routes/abstractions.d.ts +4 -10
  18. package/features/Routes/abstractions.js.map +1 -1
  19. package/features/SendToConnections/SendToConnectionsUseCase.js +1 -1
  20. package/features/SendToConnections/SendToConnectionsUseCase.js.map +1 -1
  21. package/features/SendToConnections/abstractions.d.ts +1 -1
  22. package/features/SendToConnections/abstractions.js.map +1 -1
  23. package/features/SendToIdentity/SendToIdentityUseCase.d.ts +4 -4
  24. package/features/SendToIdentity/SendToIdentityUseCase.js +2 -3
  25. package/features/SendToIdentity/SendToIdentityUseCase.js.map +1 -1
  26. package/features/shared/errors.d.ts +6 -7
  27. package/features/shared/errors.js +8 -11
  28. package/features/shared/errors.js.map +1 -1
  29. package/graphql/WebsocketsGraphQLFactory.js +0 -23
  30. package/graphql/WebsocketsGraphQLFactory.js.map +1 -1
  31. package/handler/headers.js +4 -3
  32. package/handler/headers.js.map +1 -1
  33. package/handler/types.js.map +1 -1
  34. package/package.json +18 -18
  35. package/runner/WebsocketsRunner.js +8 -8
  36. package/runner/WebsocketsRunner.js.map +1 -1
  37. package/runner/routes/connect.js +32 -14
  38. package/runner/routes/connect.js.map +1 -1
  39. package/runner/routes/default.js +2 -3
  40. package/runner/routes/default.js.map +1 -1
  41. package/runner/routes/index.d.ts +1 -2
  42. package/runner/routes/index.js.map +1 -1
  43. package/transport/abstractions/WebsocketsTransport.d.ts +1 -12
  44. package/transport/abstractions/WebsocketsTransport.js.map +1 -1
  45. package/transport/index.d.ts +1 -1
  46. package/types.d.ts +0 -2
  47. package/features/SendToIdentity/abstractions.d.ts +0 -14
  48. package/features/SendToIdentity/abstractions.js +0 -5
  49. package/features/SendToIdentity/abstractions.js.map +0 -1
  50. package/graphql/feature.d.ts +0 -4
  51. package/graphql/feature.js +0 -11
  52. package/graphql/feature.js.map +0 -1
@@ -6,6 +6,7 @@ import { DisconnectUseCase } from "./features/Disconnect/DisconnectUseCase.js";
6
6
  import { NullWebsocketsTransport } from "./transport/NullWebsocketsTransport.js";
7
7
  import { DefaultWebsocketsResponse } from "./response/WebsocketsResponse.js";
8
8
  import { registerWebsocketsRoutes } from "./runner/routes/index.js";
9
+ import { WebsocketsGraphQLFactory } from "./graphql/WebsocketsGraphQLFactory.js";
9
10
  const WebsocketsFeature = createFeature({
10
11
  name: "Websockets",
11
12
  register (container) {
@@ -16,6 +17,7 @@ const WebsocketsFeature = createFeature({
16
17
  container.register(SendToIdentityUseCase);
17
18
  container.register(DisconnectUseCase);
18
19
  registerWebsocketsRoutes(container);
20
+ container.register(WebsocketsGraphQLFactory);
19
21
  }
20
22
  });
21
23
  export { WebsocketsFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"WebsocketsFeature.js","sources":["../src/WebsocketsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListConnectionsUseCase } from \"~/features/ListConnections/ListConnectionsUseCase.js\";\nimport { SendToConnectionsUseCase } from \"~/features/SendToConnections/SendToConnectionsUseCase.js\";\nimport { SendToIdentityUseCase } from \"~/features/SendToIdentity/SendToIdentityUseCase.js\";\nimport { DisconnectUseCase } from \"~/features/Disconnect/DisconnectUseCase.js\";\nimport { NullWebsocketsTransport } from \"~/transport/NullWebsocketsTransport.js\";\nimport { DefaultWebsocketsResponse } from \"~/response/WebsocketsResponse.js\";\nimport { registerWebsocketsRoutes } from \"~/runner/routes/index.js\";\n\nexport const WebsocketsFeature = createFeature({\n name: \"Websockets\",\n register(container) {\n container.register(NullWebsocketsTransport);\n container.register(DefaultWebsocketsResponse);\n container.register(ListConnectionsUseCase);\n container.register(SendToConnectionsUseCase);\n container.register(SendToIdentityUseCase);\n container.register(DisconnectUseCase);\n registerWebsocketsRoutes(container);\n }\n});\n"],"names":["WebsocketsFeature","createFeature","container","NullWebsocketsTransport","DefaultWebsocketsResponse","ListConnectionsUseCase","SendToConnectionsUseCase","SendToIdentityUseCase","DisconnectUseCase","registerWebsocketsRoutes"],"mappings":";;;;;;;;AASO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBC,yBAAyBP;IAC7B;AACJ"}
1
+ {"version":3,"file":"WebsocketsFeature.js","sources":["../src/WebsocketsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { ListConnectionsUseCase } from \"~/features/ListConnections/ListConnectionsUseCase.js\";\nimport { SendToConnectionsUseCase } from \"~/features/SendToConnections/SendToConnectionsUseCase.js\";\nimport { SendToIdentityUseCase } from \"~/features/SendToIdentity/SendToIdentityUseCase.js\";\nimport { DisconnectUseCase } from \"~/features/Disconnect/DisconnectUseCase.js\";\nimport { NullWebsocketsTransport } from \"~/transport/NullWebsocketsTransport.js\";\nimport { DefaultWebsocketsResponse } from \"~/response/WebsocketsResponse.js\";\nimport { registerWebsocketsRoutes } from \"~/runner/routes/index.js\";\nimport { WebsocketsGraphQLFactory } from \"~/graphql/WebsocketsGraphQLFactory.js\";\n\nexport const WebsocketsFeature = createFeature({\n name: \"Websockets\",\n register(container) {\n container.register(NullWebsocketsTransport);\n container.register(DefaultWebsocketsResponse);\n container.register(ListConnectionsUseCase);\n container.register(SendToConnectionsUseCase);\n container.register(SendToIdentityUseCase);\n container.register(DisconnectUseCase);\n registerWebsocketsRoutes(container);\n container.register(WebsocketsGraphQLFactory);\n }\n});\n"],"names":["WebsocketsFeature","createFeature","container","NullWebsocketsTransport","DefaultWebsocketsResponse","ListConnectionsUseCase","SendToConnectionsUseCase","SendToIdentityUseCase","DisconnectUseCase","registerWebsocketsRoutes","WebsocketsGraphQLFactory"],"mappings":";;;;;;;;;AAUO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;QACnBJ,UAAU,QAAQ,CAACK;QACnBL,UAAU,QAAQ,CAACM;QACnBC,yBAAyBP;QACzBA,UAAU,QAAQ,CAACQ;IACvB;AACJ"}
package/exports/api.d.ts CHANGED
@@ -1,11 +1,3 @@
1
- export { WebsocketsTransport } from "../transport/index.js";
2
1
  export { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
3
- export { WebsocketsSendToIdentityUseCase } from "../features/SendToIdentity/abstractions.js";
4
2
  export { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
5
3
  export { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
6
- export { ConnectionRegistry } from "../features/ConnectionRegistry/abstractions.js";
7
- export { WebsocketsEventValidator } from "../validator/index.js";
8
- export { WebsocketsRunner } from "../runner/WebsocketsRunner.js";
9
- export { WebsocketsRouteHandler } from "../features/Routes/abstractions.js";
10
- export { WebsocketsResponse } from "../response/index.js";
11
- export type { WebsocketsError } from "../features/shared/errors.js";
package/exports/api.js CHANGED
@@ -1,10 +1,3 @@
1
- export { WebsocketsTransport } from "../transport/index.js";
2
1
  export { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
3
- export { WebsocketsSendToIdentityUseCase } from "../features/SendToIdentity/abstractions.js";
4
2
  export { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
5
3
  export { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
6
- export { ConnectionRegistry } from "../features/ConnectionRegistry/abstractions.js";
7
- export { WebsocketsEventValidator } from "../validator/index.js";
8
- export { WebsocketsRunner } from "../runner/WebsocketsRunner.js";
9
- export { WebsocketsRouteHandler } from "../features/Routes/abstractions.js";
10
- export { WebsocketsResponse } from "../response/index.js";
@@ -1,10 +1,11 @@
1
- import type { IWebsocketsIdentity } from "../../types.js";
1
+ import type { IWebsocketsIdentity } from "@webiny/api-core/features/websockets/index.js";
2
2
  export interface IWebsocketsConnectionRegistryData {
3
3
  connectionId: string;
4
4
  identity: IWebsocketsIdentity;
5
5
  tenant: string;
6
6
  connectedOn: string;
7
7
  endpoint: string;
8
+ owner?: string;
8
9
  }
9
10
  export interface IWebsocketsConnectionRegistryRegisterParams {
10
11
  connectionId: string;
@@ -12,6 +13,7 @@ export interface IWebsocketsConnectionRegistryRegisterParams {
12
13
  identity: IWebsocketsIdentity;
13
14
  endpoint: string;
14
15
  connectedOn: string;
16
+ owner?: string;
15
17
  }
16
18
  export interface IWebsocketsConnectionRegistryUnregisterParams {
17
19
  connectionId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"features/ConnectionRegistry/abstractions.js","sources":["../../../src/features/ConnectionRegistry/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { IWebsocketsIdentity } from \"~/types.js\";\n\nexport interface IWebsocketsConnectionRegistryData {\n connectionId: string;\n identity: IWebsocketsIdentity;\n tenant: string;\n connectedOn: string;\n endpoint: string;\n}\n\nexport interface IWebsocketsConnectionRegistryRegisterParams {\n connectionId: string;\n tenant: string;\n identity: IWebsocketsIdentity;\n endpoint: string;\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 updateLastSeen(connectionId: string): Promise<void>;\n listStale(olderThan: Date): Promise<IWebsocketsConnectionRegistryData[]>;\n}\n\nexport const ConnectionRegistry =\n createAbstraction<IWebsocketsConnectionRegistry>(\"ConnectionRegistry\");\n\nexport namespace ConnectionRegistry {\n export type Interface = IWebsocketsConnectionRegistry;\n export type Identity = IWebsocketsIdentity;\n export type Data = IWebsocketsConnectionRegistryData;\n export type RegisterParams = IWebsocketsConnectionRegistryRegisterParams;\n export type UnregisterParams = IWebsocketsConnectionRegistryUnregisterParams;\n}\n"],"names":["ConnectionRegistry","createAbstraction"],"mappings":";AAsCO,MAAMA,qBACTC,kBAAiD"}
1
+ {"version":3,"file":"features/ConnectionRegistry/abstractions.js","sources":["../../../src/features/ConnectionRegistry/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { IWebsocketsIdentity } from \"@webiny/api-core/features/websockets/index.js\";\n\nexport interface IWebsocketsConnectionRegistryData {\n connectionId: string;\n identity: IWebsocketsIdentity;\n tenant: string;\n connectedOn: string;\n endpoint: string;\n /*\n * The process holding the live socket, on a server that runs several processes. Absent where\n * one service holds every socket (API Gateway on AWS) and on rows written before it existed.\n */\n owner?: string;\n}\n\nexport interface IWebsocketsConnectionRegistryRegisterParams {\n connectionId: string;\n tenant: string;\n identity: IWebsocketsIdentity;\n endpoint: string;\n connectedOn: string;\n owner?: 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 updateLastSeen(connectionId: string): Promise<void>;\n listStale(olderThan: Date): Promise<IWebsocketsConnectionRegistryData[]>;\n}\n\nexport const ConnectionRegistry =\n createAbstraction<IWebsocketsConnectionRegistry>(\"ConnectionRegistry\");\n\nexport namespace ConnectionRegistry {\n export type Interface = IWebsocketsConnectionRegistry;\n export type Identity = IWebsocketsIdentity;\n export type Data = IWebsocketsConnectionRegistryData;\n export type RegisterParams = IWebsocketsConnectionRegistryRegisterParams;\n export type UnregisterParams = IWebsocketsConnectionRegistryUnregisterParams;\n}\n"],"names":["ConnectionRegistry","createAbstraction"],"mappings":";AA4CO,MAAMA,qBACTC,kBAAiD"}
@@ -1,6 +1,7 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { WebsocketsDisconnectUseCase } from "./abstractions.js";
3
3
  import { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError } from "../shared/errors.js";
4
+ import { validateDisconnectWhere } from "./validateDisconnectWhere.js";
4
5
  import { WebsocketsListConnectionsUseCase } from "../ListConnections/abstractions.js";
5
6
  import { ConnectionRegistry } from "../ConnectionRegistry/abstractions.js";
6
7
  import { WebsocketsTransport } from "../../transport/index.js";
@@ -11,6 +12,8 @@ class DisconnectUseCaseImpl {
11
12
  this.transport = transport;
12
13
  }
13
14
  async execute(params, notify = true) {
15
+ const validationError = validateDisconnectWhere(params?.where);
16
+ if (validationError) return Result.fail(validationError);
14
17
  const result = await this.listConnections.execute(params);
15
18
  if (result.isFail()) return Result.fail(result.error);
16
19
  const connections = result.value;
@@ -1 +1 @@
1
- {"version":3,"file":"features/Disconnect/DisconnectUseCase.js","sources":["../../../src/features/Disconnect/DisconnectUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsDisconnectUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectNotificationError } from \"~/features/shared/errors.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\n\nclass DisconnectUseCaseImpl implements WebsocketsDisconnectUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly registry: ConnectionRegistry.Interface,\n private readonly transport: WebsocketsTransport.Interface\n ) {}\n\n public async execute(\n params?: WebsocketsDisconnectUseCase.Params,\n notify = true\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n const result = await this.listConnections.execute(params);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const connections = result.value;\n\n for (const connection of connections) {\n try {\n await this.registry.unregister(connection);\n } catch {\n /* Intentional: failed unregister for one connection must not prevent disconnecting others. */\n }\n }\n\n if (notify) {\n try {\n await this.transport.send(connections, {\n action: \"forcedDisconnect\"\n });\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectNotificationError(error));\n }\n }\n\n try {\n await this.transport.disconnect(connections);\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectError(error));\n }\n\n return Result.ok(connections);\n }\n}\n\nexport const DisconnectUseCase = WebsocketsDisconnectUseCase.createImplementation({\n implementation: DisconnectUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, ConnectionRegistry, WebsocketsTransport]\n});\n"],"names":["DisconnectUseCaseImpl","listConnections","registry","transport","params","notify","result","Result","connections","connection","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError","DisconnectUseCase","WebsocketsDisconnectUseCase","WebsocketsListConnectionsUseCase","ConnectionRegistry","WebsocketsTransport"],"mappings":";;;;;;AASA,MAAMA;IACF,YACqBC,eAA2D,EAC3DC,QAAsC,EACtCC,SAAwC,CAC3D;aAHmBF,eAAe,GAAfA;aACAC,QAAQ,GAARA;aACAC,SAAS,GAATA;IAClB;IAEH,MAAa,QACTC,MAA2C,EAC3CC,SAAS,IAAI,EACoE;QACjF,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACF;QAClD,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAACD,OAAO,KAAK;QAGnC,MAAME,cAAcF,OAAO,KAAK;QAEhC,KAAK,MAAMG,cAAcD,YACrB,IAAI;YACA,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAACC;QACnC,EAAE,OAAM,CAER;QAGJ,IAAIJ,QACA,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAACG,aAAa;gBACnC,QAAQ;YACZ;QACJ,EAAE,OAAOE,OAAO;YACZ,OAAOH,OAAO,IAAI,CAAC,IAAII,0CAA0CD;QACrE;QAGJ,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAACF;QACpC,EAAE,OAAOE,OAAO;YACZ,OAAOH,OAAO,IAAI,CAAC,IAAIK,8BAA8BF;QACzD;QAEA,OAAOH,OAAO,EAAE,CAACC;IACrB;AACJ;AAEO,MAAMK,oBAAoBC,4BAA4B,oBAAoB,CAAC;IAC9E,gBAAgBd;IAChB,cAAc;QAACe;QAAkCC;QAAoBC;KAAoB;AAC7F"}
1
+ {"version":3,"file":"features/Disconnect/DisconnectUseCase.js","sources":["../../../src/features/Disconnect/DisconnectUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsDisconnectUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectNotificationError } from \"~/features/shared/errors.js\";\nimport { validateDisconnectWhere } from \"./validateDisconnectWhere.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\n\nclass DisconnectUseCaseImpl implements WebsocketsDisconnectUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly registry: ConnectionRegistry.Interface,\n private readonly transport: WebsocketsTransport.Interface\n ) {}\n\n public async execute(\n params?: WebsocketsDisconnectUseCase.Params,\n notify = true\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n const validationError = validateDisconnectWhere(params?.where);\n if (validationError) {\n return Result.fail(validationError);\n }\n\n const result = await this.listConnections.execute(params);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const connections = result.value;\n\n for (const connection of connections) {\n try {\n await this.registry.unregister(connection);\n } catch {\n /* Intentional: failed unregister for one connection must not prevent disconnecting others. */\n }\n }\n\n if (notify) {\n try {\n await this.transport.send(connections, {\n action: \"forcedDisconnect\"\n });\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectNotificationError(error));\n }\n }\n\n try {\n await this.transport.disconnect(connections);\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectError(error));\n }\n\n return Result.ok(connections);\n }\n}\n\nexport const DisconnectUseCase = WebsocketsDisconnectUseCase.createImplementation({\n implementation: DisconnectUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, ConnectionRegistry, WebsocketsTransport]\n});\n"],"names":["DisconnectUseCaseImpl","listConnections","registry","transport","params","notify","validationError","validateDisconnectWhere","Result","result","connections","connection","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError","DisconnectUseCase","WebsocketsDisconnectUseCase","WebsocketsListConnectionsUseCase","ConnectionRegistry","WebsocketsTransport"],"mappings":";;;;;;;AAUA,MAAMA;IACF,YACqBC,eAA2D,EAC3DC,QAAsC,EACtCC,SAAwC,CAC3D;aAHmBF,eAAe,GAAfA;aACAC,QAAQ,GAARA;aACAC,SAAS,GAATA;IAClB;IAEH,MAAa,QACTC,MAA2C,EAC3CC,SAAS,IAAI,EACoE;QACjF,MAAMC,kBAAkBC,wBAAwBH,QAAQ;QACxD,IAAIE,iBACA,OAAOE,OAAO,IAAI,CAACF;QAGvB,MAAMG,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QAClD,IAAIK,OAAO,MAAM,IACb,OAAOD,OAAO,IAAI,CAACC,OAAO,KAAK;QAGnC,MAAMC,cAAcD,OAAO,KAAK;QAEhC,KAAK,MAAME,cAAcD,YACrB,IAAI;YACA,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAACC;QACnC,EAAE,OAAM,CAER;QAGJ,IAAIN,QACA,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAACK,aAAa;gBACnC,QAAQ;YACZ;QACJ,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIK,0CAA0CD;QACrE;QAGJ,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAACF;QACpC,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIM,8BAA8BF;QACzD;QAEA,OAAOJ,OAAO,EAAE,CAACE;IACrB;AACJ;AAEO,MAAMK,oBAAoBC,4BAA4B,oBAAoB,CAAC;IAC9E,gBAAgBhB;IAChB,cAAc;QAACiB;QAAkCC;QAAoBC;KAAoB;AAC7F"}
@@ -0,0 +1,8 @@
1
+ import { WebsocketsValidationError } from "../../features/shared/errors.js";
2
+ import type { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
3
+ /**
4
+ * Security: an empty `identityId` / `connections` is falsy in the list use case and would fall
5
+ * through to "list all", turning a targeted disconnect into disconnect-all.
6
+ * Only a call without `where` may disconnect everything.
7
+ */
8
+ export declare const validateDisconnectWhere: (where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined) => WebsocketsValidationError | null;
@@ -0,0 +1,12 @@
1
+ import { WebsocketsValidationError } from "../shared/errors.js";
2
+ const validateDisconnectWhere = (where)=>{
3
+ if (!where) return null;
4
+ const { identityId, connections } = where;
5
+ if (void 0 === identityId && void 0 === connections) return new WebsocketsValidationError("Disconnect filter must not be empty.");
6
+ if (void 0 !== identityId && ("string" != typeof identityId || !identityId.trim())) return new WebsocketsValidationError("Identity ID must not be empty.");
7
+ if (void 0 !== connections && (!Array.isArray(connections) || 0 === connections.length || connections.some((id)=>"string" != typeof id || !id.trim()))) return new WebsocketsValidationError("Connections must be a non-empty list of IDs.");
8
+ return null;
9
+ };
10
+ export { validateDisconnectWhere };
11
+
12
+ //# sourceMappingURL=validateDisconnectWhere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/Disconnect/validateDisconnectWhere.js","sources":["../../../src/features/Disconnect/validateDisconnectWhere.ts"],"sourcesContent":["import { WebsocketsValidationError } from \"~/features/shared/errors.js\";\nimport type { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\n\n/**\n * Security: an empty `identityId` / `connections` is falsy in the list use case and would fall\n * through to \"list all\", turning a targeted disconnect into disconnect-all.\n * Only a call without `where` may disconnect everything.\n */\nexport const validateDisconnectWhere = (\n where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined\n): WebsocketsValidationError | null => {\n if (!where) {\n return null;\n }\n const { identityId, connections } = where;\n if (identityId === undefined && connections === undefined) {\n return new WebsocketsValidationError(\"Disconnect filter must not be empty.\");\n }\n if (identityId !== undefined && (typeof identityId !== \"string\" || !identityId.trim())) {\n return new WebsocketsValidationError(\"Identity ID must not be empty.\");\n }\n if (\n connections !== undefined &&\n (!Array.isArray(connections) ||\n connections.length === 0 ||\n connections.some(id => typeof id !== \"string\" || !id.trim()))\n ) {\n return new WebsocketsValidationError(\"Connections must be a non-empty list of IDs.\");\n }\n return null;\n};\n"],"names":["validateDisconnectWhere","where","identityId","connections","undefined","WebsocketsValidationError","Array","id"],"mappings":";AAQO,MAAMA,0BAA0B,CACnCC;IAEA,IAAI,CAACA,OACD,OAAO;IAEX,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAE,GAAGF;IACpC,IAAIC,AAAeE,WAAfF,cAA4BC,AAAgBC,WAAhBD,aAC5B,OAAO,IAAIE,0BAA0B;IAEzC,IAAIH,AAAeE,WAAfF,cAA6B,CAAsB,YAAtB,OAAOA,cAA2B,CAACA,WAAW,IAAI,EAAC,GAChF,OAAO,IAAIG,0BAA0B;IAEzC,IACIF,AAAgBC,WAAhBD,eACC,EAACG,MAAM,OAAO,CAACH,gBACZA,AAAuB,MAAvBA,YAAY,MAAM,IAClBA,YAAY,IAAI,CAACI,CAAAA,KAAM,AAAc,YAAd,OAAOA,MAAmB,CAACA,GAAG,IAAI,GAAE,GAE/D,OAAO,IAAIF,0BAA0B;IAEzC,OAAO;AACX"}
@@ -1,10 +1,12 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { WebsocketsListConnectionsUseCase } from "./abstractions.js";
3
3
  import type { WebsocketsError } from "../../features/shared/errors.js";
4
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
5
  import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
5
6
  declare class ListConnectionsUseCaseImpl implements WebsocketsListConnectionsUseCase.Interface {
6
7
  private readonly registry;
7
- constructor(registry: ConnectionRegistry.Interface);
8
+ private readonly tenantContext;
9
+ constructor(registry: ConnectionRegistry.Interface, tenantContext: TenantContext.Interface);
8
10
  execute(params?: WebsocketsListConnectionsUseCase.Params): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>>;
9
11
  }
10
12
  export declare const ListConnectionsUseCase: typeof ListConnectionsUseCaseImpl & {
@@ -1,16 +1,21 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { WebsocketsListConnectionsUseCase } from "./abstractions.js";
3
- import { WebsocketServiceError } from "../shared/errors.js";
3
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
4
+ import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
4
5
  import { ConnectionRegistry } from "../ConnectionRegistry/abstractions.js";
5
6
  class ListConnectionsUseCaseImpl {
6
- constructor(registry){
7
+ constructor(registry, tenantContext){
7
8
  this.registry = registry;
9
+ this.tenantContext = tenantContext;
8
10
  }
9
11
  async execute(params) {
10
12
  let connections = [];
11
13
  try {
14
+ const tenant = this.tenantContext.getTenant()?.id;
15
+ if (!tenant) throw new Error("Cannot list websocket connections without a current tenant.");
12
16
  const where = params?.where || {};
13
- connections = where.identityId ? await this.registry.listViaIdentity(where.identityId) : where.connections ? await this.registry.listViaConnections(where.connections) : where.tenant ? await this.registry.listViaTenant(where.tenant) : await this.registry.listAll();
17
+ connections = where.identityId ? await this.registry.listViaIdentity(where.identityId) : where.connections ? await this.registry.listViaConnections(where.connections) : await this.registry.listViaTenant(tenant);
18
+ connections = connections.filter((c)=>c.tenant === tenant);
14
19
  } catch (error) {
15
20
  return Result.fail(new WebsocketServiceError(error));
16
21
  }
@@ -22,7 +27,8 @@ class ListConnectionsUseCaseImpl {
22
27
  const ListConnectionsUseCase = WebsocketsListConnectionsUseCase.createImplementation({
23
28
  implementation: ListConnectionsUseCaseImpl,
24
29
  dependencies: [
25
- ConnectionRegistry
30
+ ConnectionRegistry,
31
+ TenantContext
26
32
  ]
27
33
  });
28
34
  export { ListConnectionsUseCase };
@@ -1 +1 @@
1
- {"version":3,"file":"features/ListConnections/ListConnectionsUseCase.js","sources":["../../../src/features/ListConnections/ListConnectionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsListConnectionsUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketServiceError } from \"~/features/shared/errors.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\n\nclass ListConnectionsUseCaseImpl implements WebsocketsListConnectionsUseCase.Interface {\n public constructor(private readonly registry: ConnectionRegistry.Interface) {}\n\n public async execute(\n params?: WebsocketsListConnectionsUseCase.Params\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n let connections: WebsocketsListConnectionsUseCase.RegistryData[] = [];\n\n try {\n const where = params?.where || {};\n if (where.identityId) {\n connections = await this.registry.listViaIdentity(where.identityId);\n } else if (where.connections) {\n connections = await this.registry.listViaConnections(where.connections);\n } else if (where.tenant) {\n connections = await this.registry.listViaTenant(where.tenant);\n } else {\n connections = await this.registry.listAll();\n }\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n const threeHoursAgo = new Date(Date.now() - 3 * 60 * 60 * 1000).toISOString();\n connections = connections.filter(c => c.connectedOn >= threeHoursAgo);\n\n return Result.ok(connections);\n }\n}\n\nexport const ListConnectionsUseCase = WebsocketsListConnectionsUseCase.createImplementation({\n implementation: ListConnectionsUseCaseImpl,\n dependencies: [ConnectionRegistry]\n});\n"],"names":["ListConnectionsUseCaseImpl","registry","params","connections","where","error","Result","WebsocketServiceError","threeHoursAgo","Date","c","ListConnectionsUseCase","WebsocketsListConnectionsUseCase","ConnectionRegistry"],"mappings":";;;;AAMA,MAAMA;IACF,YAAoCC,QAAsC,CAAE;aAAxCA,QAAQ,GAARA;IAAyC;IAE7E,MAAa,QACTC,MAAgD,EACiC;QACjF,IAAIC,cAA+D,EAAE;QAErE,IAAI;YACA,MAAMC,QAAQF,QAAQ,SAAS,CAAC;YAE5BC,cADAC,MAAM,UAAU,GACF,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAACA,MAAM,UAAU,IAC3DA,MAAM,WAAW,GACV,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAACA,MAAM,WAAW,IAC/DA,MAAM,MAAM,GACL,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAACA,MAAM,MAAM,IAE9C,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO;QAEjD,EAAE,OAAOC,OAAO;YACZ,OAAOC,OAAO,IAAI,CAAC,IAAIC,sBAAsBF;QACjD;QAEA,MAAMG,gBAAgB,IAAIC,KAAKA,KAAK,GAAG,KAAK,UAAoB,WAAW;QAC3EN,cAAcA,YAAY,MAAM,CAACO,CAAAA,IAAKA,EAAE,WAAW,IAAIF;QAEvD,OAAOF,OAAO,EAAE,CAACH;IACrB;AACJ;AAEO,MAAMQ,yBAAyBC,iCAAiC,oBAAoB,CAAC;IACxF,gBAAgBZ;IAChB,cAAc;QAACa;KAAmB;AACtC"}
1
+ {"version":3,"file":"features/ListConnections/ListConnectionsUseCase.js","sources":["../../../src/features/ListConnections/ListConnectionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsListConnectionsUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketServiceError } from \"@webiny/api-core/features/websockets/index.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\n\n/*\n * Lists the current tenant's connections only, whatever the filter. Every caller (GraphQL queries\n * and mutations, sends to an identity, disconnects) acts on what this returns, so another tenant's\n * connection ids, or an identity also connected elsewhere, never reach outside the tenant. An admin\n * who manages another tenant sends the request to that tenant.\n */\nclass ListConnectionsUseCaseImpl implements WebsocketsListConnectionsUseCase.Interface {\n public constructor(\n private readonly registry: ConnectionRegistry.Interface,\n private readonly tenantContext: TenantContext.Interface\n ) {}\n\n public async execute(\n params?: WebsocketsListConnectionsUseCase.Params\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n let connections: WebsocketsListConnectionsUseCase.RegistryData[] = [];\n\n try {\n const tenant = this.tenantContext.getTenant()?.id;\n if (!tenant) {\n throw new Error(\"Cannot list websocket connections without a current tenant.\");\n }\n\n const where = params?.where || {};\n if (where.identityId) {\n connections = await this.registry.listViaIdentity(where.identityId);\n } else if (where.connections) {\n connections = await this.registry.listViaConnections(where.connections);\n } else {\n connections = await this.registry.listViaTenant(tenant);\n }\n\n connections = connections.filter(c => c.tenant === tenant);\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n const threeHoursAgo = new Date(Date.now() - 3 * 60 * 60 * 1000).toISOString();\n connections = connections.filter(c => c.connectedOn >= threeHoursAgo);\n\n return Result.ok(connections);\n }\n}\n\nexport const ListConnectionsUseCase = WebsocketsListConnectionsUseCase.createImplementation({\n implementation: ListConnectionsUseCaseImpl,\n dependencies: [ConnectionRegistry, TenantContext]\n});\n"],"names":["ListConnectionsUseCaseImpl","registry","tenantContext","params","connections","tenant","Error","where","c","error","Result","WebsocketServiceError","threeHoursAgo","Date","ListConnectionsUseCase","WebsocketsListConnectionsUseCase","ConnectionRegistry","TenantContext"],"mappings":";;;;;AAaA,MAAMA;IACF,YACqBC,QAAsC,EACtCC,aAAsC,CACzD;aAFmBD,QAAQ,GAARA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QACTC,MAAgD,EACiC;QACjF,IAAIC,cAA+D,EAAE;QAErE,IAAI;YACA,MAAMC,SAAS,IAAI,CAAC,aAAa,CAAC,SAAS,IAAI;YAC/C,IAAI,CAACA,QACD,MAAM,IAAIC,MAAM;YAGpB,MAAMC,QAAQJ,QAAQ,SAAS,CAAC;YAE5BC,cADAG,MAAM,UAAU,GACF,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAACA,MAAM,UAAU,IAC3DA,MAAM,WAAW,GACV,MAAM,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAACA,MAAM,WAAW,IAExD,MAAM,IAAI,CAAC,QAAQ,CAAC,aAAa,CAACF;YAGpDD,cAAcA,YAAY,MAAM,CAACI,CAAAA,IAAKA,EAAE,MAAM,KAAKH;QACvD,EAAE,OAAOI,OAAO;YACZ,OAAOC,OAAO,IAAI,CAAC,IAAIC,sBAAsBF;QACjD;QAEA,MAAMG,gBAAgB,IAAIC,KAAKA,KAAK,GAAG,KAAK,UAAoB,WAAW;QAC3ET,cAAcA,YAAY,MAAM,CAACI,CAAAA,IAAKA,EAAE,WAAW,IAAII;QAEvD,OAAOF,OAAO,EAAE,CAACN;IACrB;AACJ;AAEO,MAAMU,yBAAyBC,iCAAiC,oBAAoB,CAAC;IACxF,gBAAgBf;IAChB,cAAc;QAACgB;QAAoBC;KAAc;AACrD"}
@@ -3,7 +3,6 @@ import type { WebsocketsError } from "../../features/shared/errors.js";
3
3
  import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
4
4
  export interface IWebsocketsListConnectionsParamsWhere {
5
5
  identityId?: string;
6
- tenant?: string;
7
6
  connections?: string[];
8
7
  }
9
8
  export interface IWebsocketsListConnectionsParams {
@@ -1 +1 @@
1
- {"version":3,"file":"features/ListConnections/abstractions.js","sources":["../../../src/features/ListConnections/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\n\nexport interface IWebsocketsListConnectionsParamsWhere {\n identityId?: string;\n tenant?: string;\n connections?: string[];\n}\n\nexport interface IWebsocketsListConnectionsParams {\n where?: IWebsocketsListConnectionsParamsWhere;\n}\n\nexport interface IListConnectionsUseCase {\n execute(\n params?: IWebsocketsListConnectionsParams\n ): Promise<Result<ConnectionRegistry.Data[], WebsocketsError>>;\n}\n\nexport const WebsocketsListConnectionsUseCase = createAbstraction<IListConnectionsUseCase>(\n \"Websockets/ListConnections\"\n);\n\nexport namespace WebsocketsListConnectionsUseCase {\n export type Interface = IListConnectionsUseCase;\n export type Params = IWebsocketsListConnectionsParams;\n export type ParamsWhere = IWebsocketsListConnectionsParamsWhere;\n export type RegistryData = ConnectionRegistry.Data;\n}\n"],"names":["WebsocketsListConnectionsUseCase","createAbstraction"],"mappings":";AAqBO,MAAMA,mCAAmCC,kBAC5C"}
1
+ {"version":3,"file":"features/ListConnections/abstractions.js","sources":["../../../src/features/ListConnections/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\n\nexport interface IWebsocketsListConnectionsParamsWhere {\n identityId?: string;\n connections?: string[];\n}\n\nexport interface IWebsocketsListConnectionsParams {\n where?: IWebsocketsListConnectionsParamsWhere;\n}\n\nexport interface IListConnectionsUseCase {\n execute(\n params?: IWebsocketsListConnectionsParams\n ): Promise<Result<ConnectionRegistry.Data[], WebsocketsError>>;\n}\n\nexport const WebsocketsListConnectionsUseCase = createAbstraction<IListConnectionsUseCase>(\n \"Websockets/ListConnections\"\n);\n\nexport namespace WebsocketsListConnectionsUseCase {\n export type Interface = IListConnectionsUseCase;\n export type Params = IWebsocketsListConnectionsParams;\n export type ParamsWhere = IWebsocketsListConnectionsParamsWhere;\n export type RegistryData = ConnectionRegistry.Data;\n}\n"],"names":["WebsocketsListConnectionsUseCase","createAbstraction"],"mappings":";AAoBO,MAAMA,mCAAmCC,kBAC5C"}
@@ -1,4 +1,5 @@
1
1
  import type { Container } from "@webiny/di";
2
+ import type { Identity } from "@webiny/api-core/features/security/IdentityContext/index.js";
2
3
  import type { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
3
4
  import type { WebsocketsResponse } from "../../response/index.js";
4
5
  import type { IWebsocketsRunnerResponse } from "../../runner/abstractions/WebsocketsRunner.js";
@@ -13,19 +14,12 @@ export interface IWebsocketsRouteHandlerParams<R extends IWebsocketsRunnerRespon
13
14
  container: Container;
14
15
  response: WebsocketsResponse.Interface;
15
16
  getTenant: () => string | null;
16
- getIdentity: () => ConnectionRegistry.Identity | null;
17
+ identity: Identity;
17
18
  next: () => Promise<R>;
18
19
  }
19
20
  /**
20
- * A handler for a single WebSocket route (e.g. "connect", "disconnect", "default", or a
21
- * custom route key). Register built-in and custom routes as multiple implementations:
22
- *
23
- * container.registerInstance(WebsocketsRouteHandler, {
24
- * route: "myRoute",
25
- * async run({ response }) { return response.ok(); }
26
- * });
27
- *
28
- * The runner resolves all handlers via `resolveAll` and runs the ones matching the event route.
21
+ * A handler for a single WebSocket route: "connect", "disconnect" or "default". The runner
22
+ * resolves all handlers via `resolveAll` and runs the ones matching the event route.
29
23
  */
30
24
  export interface IWebsocketsRouteHandler<R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse, T extends IWebsocketsEventData = IWebsocketsEventData> {
31
25
  route: string;
@@ -1 +1 @@
1
- {"version":3,"file":"features/Routes/abstractions.js","sources":["../../../src/features/Routes/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport type { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport type { WebsocketsResponse } from \"~/response/index.js\";\nimport type { IWebsocketsRunnerResponse } from \"~/runner/abstractions/WebsocketsRunner.js\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/types.js\";\n\n/**\n * Parameters passed to a route handler's `run` method. Route handlers for the same\n * `route` are chained middleware-style via `next`.\n */\nexport interface IWebsocketsRouteHandlerParams<\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n event: IWebsocketsEvent<T>;\n registry: ConnectionRegistry.Interface;\n container: Container;\n response: WebsocketsResponse.Interface;\n getTenant: () => string | null;\n getIdentity: () => ConnectionRegistry.Identity | null;\n next: () => Promise<R>;\n}\n\n/**\n * A handler for a single WebSocket route (e.g. \"connect\", \"disconnect\", \"default\", or a\n * custom route key). Register built-in and custom routes as multiple implementations:\n *\n * container.registerInstance(WebsocketsRouteHandler, {\n * route: \"myRoute\",\n * async run({ response }) { return response.ok(); }\n * });\n *\n * The runner resolves all handlers via `resolveAll` and runs the ones matching the event route.\n */\nexport interface IWebsocketsRouteHandler<\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n route: string;\n run(params: IWebsocketsRouteHandlerParams<R, T>): Promise<R>;\n}\n\nexport const WebsocketsRouteHandler =\n createAbstraction<IWebsocketsRouteHandler>(\"WebsocketsRouteHandler\");\n\nexport namespace WebsocketsRouteHandler {\n export type Interface = IWebsocketsRouteHandler;\n export type Params = IWebsocketsRouteHandlerParams;\n}\n"],"names":["WebsocketsRouteHandler","createAbstraction"],"mappings":";AA2CO,MAAMA,yBACTC,kBAA2C"}
1
+ {"version":3,"file":"features/Routes/abstractions.js","sources":["../../../src/features/Routes/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/di\";\nimport type { Identity } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport type { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport type { WebsocketsResponse } from \"~/response/index.js\";\nimport type { IWebsocketsRunnerResponse } from \"~/runner/abstractions/WebsocketsRunner.js\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/types.js\";\n\n/**\n * Parameters passed to a route handler's `run` method. Route handlers for the same\n * `route` are chained middleware-style via `next`.\n */\nexport interface IWebsocketsRouteHandlerParams<\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n event: IWebsocketsEvent<T>;\n registry: ConnectionRegistry.Interface;\n container: Container;\n response: WebsocketsResponse.Interface;\n getTenant: () => string | null;\n /*\n * Always set. A request without a valid token gets the anonymous identity, so a handler that\n * must refuse anonymous users checks `identity.isAnonymous()`.\n */\n identity: Identity;\n next: () => Promise<R>;\n}\n\n/**\n * A handler for a single WebSocket route: \"connect\", \"disconnect\" or \"default\". The runner\n * resolves all handlers via `resolveAll` and runs the ones matching the event route.\n */\nexport interface IWebsocketsRouteHandler<\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n route: string;\n run(params: IWebsocketsRouteHandlerParams<R, T>): Promise<R>;\n}\n\nexport const WebsocketsRouteHandler =\n createAbstraction<IWebsocketsRouteHandler>(\"WebsocketsRouteHandler\");\n\nexport namespace WebsocketsRouteHandler {\n export type Interface = IWebsocketsRouteHandler;\n export type Params = IWebsocketsRouteHandlerParams;\n}\n"],"names":["WebsocketsRouteHandler","createAbstraction"],"mappings":";AAyCO,MAAMA,yBACTC,kBAA2C"}
@@ -1,7 +1,7 @@
1
1
  import { Result } from "@webiny/feature/api";
2
2
  import { WebsocketsTransport } from "../../transport/index.js";
3
3
  import { WebsocketsSendToConnectionsUseCase } from "./abstractions.js";
4
- import { WebsocketServiceError } from "../shared/errors.js";
4
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
5
5
  class SendToConnectionsUseCaseImpl {
6
6
  constructor(transport){
7
7
  this.transport = transport;
@@ -1 +1 @@
1
- {"version":3,"file":"features/SendToConnections/SendToConnectionsUseCase.js","sources":["../../../src/features/SendToConnections/SendToConnectionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { WebsocketsSendToConnectionsUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketServiceError } from \"~/features/shared/errors.js\";\n\nclass SendToConnectionsUseCaseImpl implements WebsocketsSendToConnectionsUseCase.Interface {\n public constructor(private readonly transport: WebsocketsTransport.Interface) {}\n\n public async execute<T extends GenericRecord = GenericRecord>(\n connections: WebsocketsSendToConnectionsUseCase.Connection[],\n data: WebsocketsSendToConnectionsUseCase.Data<T>\n ): Promise<Result<void, WebsocketsError>> {\n try {\n await this.transport.send<T>(connections, data);\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n return Result.ok();\n }\n}\n\nexport const SendToConnectionsUseCase = WebsocketsSendToConnectionsUseCase.createImplementation({\n implementation: SendToConnectionsUseCaseImpl,\n dependencies: [WebsocketsTransport]\n});\n"],"names":["SendToConnectionsUseCaseImpl","transport","connections","data","error","Result","WebsocketServiceError","SendToConnectionsUseCase","WebsocketsSendToConnectionsUseCase","WebsocketsTransport"],"mappings":";;;;AAOA,MAAMA;IACF,YAAoCC,SAAwC,CAAE;aAA1CA,SAAS,GAATA;IAA2C;IAE/E,MAAa,QACTC,WAA4D,EAC5DC,IAAgD,EACV;QACtC,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAID,aAAaC;QAC9C,EAAE,OAAOC,OAAO;YACZ,OAAOC,OAAO,IAAI,CAAC,IAAIC,sBAAsBF;QACjD;QAEA,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAME,2BAA2BC,mCAAmC,oBAAoB,CAAC;IAC5F,gBAAgBR;IAChB,cAAc;QAACS;KAAoB;AACvC"}
1
+ {"version":3,"file":"features/SendToConnections/SendToConnectionsUseCase.js","sources":["../../../src/features/SendToConnections/SendToConnectionsUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { WebsocketsSendToConnectionsUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketServiceError } from \"@webiny/api-core/features/websockets/index.js\";\n\nclass SendToConnectionsUseCaseImpl implements WebsocketsSendToConnectionsUseCase.Interface {\n public constructor(private readonly transport: WebsocketsTransport.Interface) {}\n\n public async execute<T extends GenericRecord = GenericRecord>(\n connections: WebsocketsSendToConnectionsUseCase.Connection[],\n data: WebsocketsSendToConnectionsUseCase.Data<T>\n ): Promise<Result<void, WebsocketsError>> {\n try {\n await this.transport.send<T>(connections, data);\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n return Result.ok();\n }\n}\n\nexport const SendToConnectionsUseCase = WebsocketsSendToConnectionsUseCase.createImplementation({\n implementation: SendToConnectionsUseCaseImpl,\n dependencies: [WebsocketsTransport]\n});\n"],"names":["SendToConnectionsUseCaseImpl","transport","connections","data","error","Result","WebsocketServiceError","SendToConnectionsUseCase","WebsocketsSendToConnectionsUseCase","WebsocketsTransport"],"mappings":";;;;AAOA,MAAMA;IACF,YAAoCC,SAAwC,CAAE;aAA1CA,SAAS,GAATA;IAA2C;IAE/E,MAAa,QACTC,WAA4D,EAC5DC,IAAgD,EACV;QACtC,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAID,aAAaC;QAC9C,EAAE,OAAOC,OAAO;YACZ,OAAOC,OAAO,IAAI,CAAC,IAAIC,sBAAsBF;QACjD;QAEA,OAAOC,OAAO,EAAE;IACpB;AACJ;AAEO,MAAME,2BAA2BC,mCAAmC,oBAAoB,CAAC;IAC5F,gBAAgBR;IAChB,cAAc;QAACS;KAAoB;AACvC"}
@@ -1,7 +1,7 @@
1
1
  import type { Result } from "@webiny/feature/api";
2
2
  import type { GenericRecord } from "@webiny/api/types.js";
3
3
  import type { IWebsocketsTransportSendConnection } from "../../transport/index.js";
4
- import type { IWebsocketsTransportSendData } from "../../transport/index.js";
4
+ import type { IWebsocketsTransportSendData } from "@webiny/api-core/features/websockets/index.js";
5
5
  import type { WebsocketsError } from "../../features/shared/errors.js";
6
6
  export interface ISendToConnectionsUseCase {
7
7
  execute<T extends GenericRecord = GenericRecord>(connections: IWebsocketsTransportSendConnection[], data: IWebsocketsTransportSendData<T>): Promise<Result<void, WebsocketsError>>;
@@ -1 +1 @@
1
- {"version":3,"file":"features/SendToConnections/abstractions.js","sources":["../../../src/features/SendToConnections/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IWebsocketsTransportSendConnection } from \"~/transport/index.js\";\nimport type { IWebsocketsTransportSendData } from \"~/transport/index.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\n\nexport interface ISendToConnectionsUseCase {\n execute<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketsError>>;\n}\n\nexport const WebsocketsSendToConnectionsUseCase = createAbstraction<ISendToConnectionsUseCase>(\n \"Websockets/SendToConnections\"\n);\n\nexport namespace WebsocketsSendToConnectionsUseCase {\n export type Interface = ISendToConnectionsUseCase;\n export type Connection = IWebsocketsTransportSendConnection;\n export type Data<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n}\n"],"names":["WebsocketsSendToConnectionsUseCase","createAbstraction"],"mappings":";AAcO,MAAMA,qCAAqCC,kBAC9C"}
1
+ {"version":3,"file":"features/SendToConnections/abstractions.js","sources":["../../../src/features/SendToConnections/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IWebsocketsTransportSendConnection } from \"~/transport/index.js\";\nimport type { IWebsocketsTransportSendData } from \"@webiny/api-core/features/websockets/index.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\n\nexport interface ISendToConnectionsUseCase {\n execute<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketsError>>;\n}\n\nexport const WebsocketsSendToConnectionsUseCase = createAbstraction<ISendToConnectionsUseCase>(\n \"Websockets/SendToConnections\"\n);\n\nexport namespace WebsocketsSendToConnectionsUseCase {\n export type Interface = ISendToConnectionsUseCase;\n export type Connection = IWebsocketsTransportSendConnection;\n export type Data<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n}\n"],"names":["WebsocketsSendToConnectionsUseCase","createAbstraction"],"mappings":";AAcO,MAAMA,qCAAqCC,kBAC9C"}
@@ -3,16 +3,16 @@ import type { GenericRecord } from "@webiny/api/types.js";
3
3
  import { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
4
4
  import { WebsocketsTransport } from "../../transport/index.js";
5
5
  import { Logger } from "@webiny/api-core/features/logger/index.js";
6
- import { WebsocketsSendToIdentityUseCase } from "./abstractions.js";
7
- import type { WebsocketsError } from "../../features/shared/errors.js";
6
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
8
8
  declare class SendToIdentityUseCaseImpl implements WebsocketsSendToIdentityUseCase.Interface {
9
9
  private readonly listConnections;
10
10
  private readonly transport;
11
11
  private readonly logger;
12
12
  constructor(listConnections: WebsocketsListConnectionsUseCase.Interface, transport: WebsocketsTransport.Interface, logger: Logger.Interface);
13
- execute<T extends GenericRecord = GenericRecord>(identity: WebsocketsSendToIdentityUseCase.Identity, data: WebsocketsSendToIdentityUseCase.Data<T>): Promise<Result<void, WebsocketsError>>;
13
+ execute<T extends GenericRecord = GenericRecord>(identity: WebsocketsSendToIdentityUseCase.Identity, data: WebsocketsSendToIdentityUseCase.Data<T>): Promise<Result<void, WebsocketServiceError>>;
14
14
  }
15
15
  export declare const SendToIdentityUseCase: typeof SendToIdentityUseCaseImpl & {
16
- __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendToIdentityUseCase>;
16
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/websockets/SendToIdentity/abstractions").ISendToIdentityUseCase>;
17
17
  };
18
18
  export {};
@@ -2,8 +2,7 @@ import { Result } from "@webiny/feature/api";
2
2
  import { WebsocketsListConnectionsUseCase } from "../ListConnections/abstractions.js";
3
3
  import { WebsocketsTransport } from "../../transport/index.js";
4
4
  import { Logger } from "@webiny/api-core/features/logger/index.js";
5
- import { WebsocketsSendToIdentityUseCase } from "./abstractions.js";
6
- import { WebsocketServiceError } from "../shared/errors.js";
5
+ import { WebsocketServiceError, WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
7
6
  class SendToIdentityUseCaseImpl {
8
7
  constructor(listConnections, transport, logger){
9
8
  this.listConnections = listConnections;
@@ -16,7 +15,7 @@ class SendToIdentityUseCaseImpl {
16
15
  identityId: identity.id
17
16
  }
18
17
  });
19
- if (result.isFail()) return Result.fail(result.error);
18
+ if (result.isFail()) return Result.fail(new WebsocketServiceError(result.error));
20
19
  if (0 === result.value.length) this.logger.warn({
21
20
  identityId: identity.id,
22
21
  action: data.action
@@ -1 +1 @@
1
- {"version":3,"file":"features/SendToIdentity/SendToIdentityUseCase.js","sources":["../../../src/features/SendToIdentity/SendToIdentityUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { WebsocketsSendToIdentityUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketServiceError } from \"~/features/shared/errors.js\";\n\nclass SendToIdentityUseCaseImpl implements WebsocketsSendToIdentityUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly transport: WebsocketsTransport.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n public async execute<T extends GenericRecord = GenericRecord>(\n identity: WebsocketsSendToIdentityUseCase.Identity,\n data: WebsocketsSendToIdentityUseCase.Data<T>\n ): Promise<Result<void, WebsocketsError>> {\n const result = await this.listConnections.execute({\n where: {\n identityId: identity.id\n }\n });\n\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n if (result.value.length === 0) {\n // Not an error for the caller (the user may simply have no tab open), but without this\n // an identity mismatch between sender and connection is indistinguishable from success.\n this.logger.warn(\n { identityId: identity.id, action: data.action },\n \"No websocket connections found for identity; message not sent.\"\n );\n }\n\n try {\n await this.transport.send<T>(result.value, data);\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n return Result.ok();\n }\n}\n\nexport const SendToIdentityUseCase = WebsocketsSendToIdentityUseCase.createImplementation({\n implementation: SendToIdentityUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, WebsocketsTransport, Logger]\n});\n"],"names":["SendToIdentityUseCaseImpl","listConnections","transport","logger","identity","data","result","Result","error","WebsocketServiceError","SendToIdentityUseCase","WebsocketsSendToIdentityUseCase","WebsocketsListConnectionsUseCase","WebsocketsTransport","Logger"],"mappings":";;;;;;AASA,MAAMA;IACF,YACqBC,eAA2D,EAC3DC,SAAwC,EACxCC,MAAwB,CAC3C;aAHmBF,eAAe,GAAfA;aACAC,SAAS,GAATA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAa,QACTC,QAAkD,EAClDC,IAA6C,EACP;QACtC,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAC9C,OAAO;gBACH,YAAYF,SAAS,EAAE;YAC3B;QACJ;QAEA,IAAIE,OAAO,MAAM,IACb,OAAOC,OAAO,IAAI,CAACD,OAAO,KAAK;QAGnC,IAAIA,AAAwB,MAAxBA,OAAO,KAAK,CAAC,MAAM,EAGnB,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ;YAAE,YAAYF,SAAS,EAAE;YAAE,QAAQC,KAAK,MAAM;QAAC,GAC/C;QAIR,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAIC,OAAO,KAAK,EAAED;QAC/C,EAAE,OAAOG,OAAO;YACZ,OAAOD,OAAO,IAAI,CAAC,IAAIE,sBAAsBD;QACjD;QAEA,OAAOD,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMG,wBAAwBC,gCAAgC,oBAAoB,CAAC;IACtF,gBAAgBX;IAChB,cAAc;QAACY;QAAkCC;QAAqBC;KAAO;AACjF"}
1
+ {"version":3,"file":"features/SendToIdentity/SendToIdentityUseCase.js","sources":["../../../src/features/SendToIdentity/SendToIdentityUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { Logger } from \"@webiny/api-core/features/logger/index.js\";\nimport { WebsocketsSendToIdentityUseCase } from \"@webiny/api-core/features/websockets/index.js\";\nimport { WebsocketServiceError } from \"@webiny/api-core/features/websockets/index.js\";\n\nclass SendToIdentityUseCaseImpl implements WebsocketsSendToIdentityUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly transport: WebsocketsTransport.Interface,\n private readonly logger: Logger.Interface\n ) {}\n\n public async execute<T extends GenericRecord = GenericRecord>(\n identity: WebsocketsSendToIdentityUseCase.Identity,\n data: WebsocketsSendToIdentityUseCase.Data<T>\n ): Promise<Result<void, WebsocketServiceError>> {\n const result = await this.listConnections.execute({\n where: {\n identityId: identity.id\n }\n });\n\n if (result.isFail()) {\n // The send declares one error, so a listing failure is carried inside it.\n return Result.fail(new WebsocketServiceError(result.error));\n }\n\n if (result.value.length === 0) {\n // Not an error for the caller (the user may simply have no tab open), but without this\n // an identity mismatch between sender and connection is indistinguishable from success.\n this.logger.warn(\n { identityId: identity.id, action: data.action },\n \"No websocket connections found for identity; message not sent.\"\n );\n }\n\n try {\n await this.transport.send<T>(result.value, data);\n } catch (error) {\n return Result.fail(new WebsocketServiceError(error as Error));\n }\n\n return Result.ok();\n }\n}\n\nexport const SendToIdentityUseCase = WebsocketsSendToIdentityUseCase.createImplementation({\n implementation: SendToIdentityUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, WebsocketsTransport, Logger]\n});\n"],"names":["SendToIdentityUseCaseImpl","listConnections","transport","logger","identity","data","result","Result","WebsocketServiceError","error","SendToIdentityUseCase","WebsocketsSendToIdentityUseCase","WebsocketsListConnectionsUseCase","WebsocketsTransport","Logger"],"mappings":";;;;;AAQA,MAAMA;IACF,YACqBC,eAA2D,EAC3DC,SAAwC,EACxCC,MAAwB,CAC3C;aAHmBF,eAAe,GAAfA;aACAC,SAAS,GAATA;aACAC,MAAM,GAANA;IAClB;IAEH,MAAa,QACTC,QAAkD,EAClDC,IAA6C,EACD;QAC5C,MAAMC,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC;YAC9C,OAAO;gBACH,YAAYF,SAAS,EAAE;YAC3B;QACJ;QAEA,IAAIE,OAAO,MAAM,IAEb,OAAOC,OAAO,IAAI,CAAC,IAAIC,sBAAsBF,OAAO,KAAK;QAG7D,IAAIA,AAAwB,MAAxBA,OAAO,KAAK,CAAC,MAAM,EAGnB,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ;YAAE,YAAYF,SAAS,EAAE;YAAE,QAAQC,KAAK,MAAM;QAAC,GAC/C;QAIR,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAIC,OAAO,KAAK,EAAED;QAC/C,EAAE,OAAOI,OAAO;YACZ,OAAOF,OAAO,IAAI,CAAC,IAAIC,sBAAsBC;QACjD;QAEA,OAAOF,OAAO,EAAE;IACpB;AACJ;AAEO,MAAMG,wBAAwBC,gCAAgC,oBAAoB,CAAC;IACtF,gBAAgBX;IAChB,cAAc;QAACY;QAAkCC;QAAqBC;KAAO;AACjF"}
@@ -1,10 +1,5 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
- export declare class WebsocketServiceError extends BaseError<{
3
- error: Error;
4
- }> {
5
- readonly code: "Websocket/Service";
6
- constructor(error: Error);
7
- }
2
+ import type { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
8
3
  export declare class WebsocketForceDisconnectNotificationError extends BaseError<{
9
4
  error: Error;
10
5
  }> {
@@ -17,4 +12,8 @@ export declare class WebsocketForceDisconnectError extends BaseError<{
17
12
  readonly code: "Websocket/Service/ForceDisconnect";
18
13
  constructor(error: Error);
19
14
  }
20
- export type WebsocketsError = WebsocketServiceError | WebsocketForceDisconnectNotificationError | WebsocketForceDisconnectError;
15
+ export declare class WebsocketsValidationError extends BaseError {
16
+ readonly code: "Websocket/Validation";
17
+ constructor(message: string);
18
+ }
19
+ export type WebsocketsError = WebsocketsValidationError | WebsocketServiceError | WebsocketForceDisconnectNotificationError | WebsocketForceDisconnectError;
@@ -1,14 +1,4 @@
1
1
  import { BaseError } from "@webiny/feature/api";
2
- class WebsocketServiceError extends BaseError {
3
- constructor(error){
4
- super({
5
- message: "WebsocketService encountered an error.",
6
- data: {
7
- error
8
- }
9
- }), this.code = "Websocket/Service";
10
- }
11
- }
12
2
  class WebsocketForceDisconnectNotificationError extends BaseError {
13
3
  constructor(error){
14
4
  super({
@@ -29,6 +19,13 @@ class WebsocketForceDisconnectError extends BaseError {
29
19
  }), this.code = "Websocket/Service/ForceDisconnect";
30
20
  }
31
21
  }
32
- export { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError, WebsocketServiceError };
22
+ class WebsocketsValidationError extends BaseError {
23
+ constructor(message){
24
+ super({
25
+ message
26
+ }), this.code = "Websocket/Validation";
27
+ }
28
+ }
29
+ export { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError, WebsocketsValidationError };
33
30
 
34
31
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"features/shared/errors.js","sources":["../../../src/features/shared/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class WebsocketServiceError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service\" as const;\n\n constructor(error: Error) {\n super({\n message: \"WebsocketService encountered an error.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectNotificationError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnectNotification\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to notify the clients about the forced disconnect.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnect\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to forcefully disconnect the Websocket clients.\",\n data: { error }\n });\n }\n}\n\nexport type WebsocketsError =\n | WebsocketServiceError\n | WebsocketForceDisconnectNotificationError\n | WebsocketForceDisconnectError;\n"],"names":["WebsocketServiceError","BaseError","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError"],"mappings":";AAEO,MAAMA,8BAA8BC;IAGvC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,kDAAkDF;IAG3D,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,sCAAsCH;IAG/C,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ"}
1
+ {"version":3,"file":"features/shared/errors.js","sources":["../../../src/features/shared/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\nimport type { WebsocketServiceError } from \"@webiny/api-core/features/websockets/index.js\";\n\nexport class WebsocketForceDisconnectNotificationError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnectNotification\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to notify the clients about the forced disconnect.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnect\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to forcefully disconnect the Websocket clients.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketsValidationError extends BaseError {\n override readonly code = \"Websocket/Validation\" as const;\n\n constructor(message: string) {\n super({\n message\n });\n }\n}\n\nexport type WebsocketsError =\n | WebsocketsValidationError\n | WebsocketServiceError\n | WebsocketForceDisconnectNotificationError\n | WebsocketForceDisconnectError;\n"],"names":["WebsocketForceDisconnectNotificationError","BaseError","error","WebsocketForceDisconnectError","WebsocketsValidationError","message"],"mappings":";AAGO,MAAMA,kDAAkDC;IAG3D,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,sCAAsCF;IAG/C,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,kCAAkCH;IAG3C,YAAYI,OAAe,CAAE;QACzB,KAAK,CAAC;YACFA;QACJ,SALc,IAAI,GAAG;IAMzB;AACJ"}
@@ -39,7 +39,6 @@ class WebsocketsGraphQL {
39
39
 
40
40
  input WebsocketsListConnectionsWhereInput {
41
41
  identityId: String
42
- tenant: String
43
42
  }
44
43
 
45
44
  type WebsocketsDisconnectResponse {
@@ -72,7 +71,6 @@ class WebsocketsGraphQL {
72
71
  extend type WebsocketsMutation {
73
72
  disconnect(connections: [String!]!): WebsocketsDisconnectResponse!
74
73
  disconnectIdentity(identityId: String!): WebsocketsDisconnectResponse!
75
- disconnectTenant(tenant: String!): WebsocketsDisconnectResponse!
76
74
  disconnectAll: WebsocketsDisconnectResponse!
77
75
  }
78
76
  `);
@@ -143,27 +141,6 @@ class WebsocketsGraphQL {
143
141
  }
144
142
  }
145
143
  });
146
- builder.addResolver({
147
- path: "WebsocketsMutation.disconnectTenant",
148
- dependencies: [
149
- IdentityContext,
150
- WebsocketsDisconnectUseCase
151
- ],
152
- resolver: (identityContext, disconnect)=>async ({ args })=>{
153
- try {
154
- await checkPermissions(identityContext);
155
- const result = await disconnect.execute({
156
- where: {
157
- tenant: args.tenant
158
- }
159
- });
160
- if (result.isFail()) return new ErrorResponse(result.error);
161
- return new Response(result.value);
162
- } catch (ex) {
163
- return new ErrorResponse(ex);
164
- }
165
- }
166
- });
167
144
  builder.addResolver({
168
145
  path: "WebsocketsMutation.disconnectAll",
169
146
  dependencies: [
@@ -1 +1 @@
1
- {"version":3,"file":"graphql/WebsocketsGraphQLFactory.js","sources":["../../src/graphql/WebsocketsGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.core.js\";\nimport { ErrorResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { WebsocketsDisconnectUseCase } from \"~/features/Disconnect/abstractions.js\";\nimport type { WebsocketsPermission } from \"~/types.js\";\n\ninterface IDisconnectConnectionsArgs {\n connections: string[];\n}\n\ninterface IDisconnectIdentityArgs {\n identityId: string;\n}\n\ninterface IDisconnectTenantArgs {\n tenant: string;\n}\n\nconst checkPermissions = async (identityContext: IdentityContext.Interface): Promise<void> => {\n const permissions = await identityContext.getPermissions<WebsocketsPermission>(\"websockets\");\n\n if (permissions.length === 0) {\n throw new NotAuthorizedError();\n }\n};\n\nclass WebsocketsGraphQL implements CoreGraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-websockets/WebsocketsGraphQL\");\n\n public async execute(\n builder: GraphQLSchemaBuilder.Interface\n ): Promise<GraphQLSchemaBuilder.Interface> {\n builder.addTypeDefs(`\n type WebsocketsIdentity {\n id: String!\n type: String\n displayName: String\n }\n\n type WebsocketsConnection {\n connectionId: String!\n endpoint: String!\n identity: WebsocketsIdentity!\n connectedOn: DateTime!\n tenant: String!\n }\n\n type WebsocketsError {\n message: String!\n code: String!\n data: JSON\n }\n\n type WebsocketsListConnectionsResponse {\n data: [WebsocketsConnection!]\n error: WebsocketsError\n }\n\n input WebsocketsListConnectionsWhereInput {\n identityId: String\n tenant: String\n }\n\n type WebsocketsDisconnectResponse {\n data: [WebsocketsConnection!]\n error: WebsocketsError\n }\n\n type WebsocketsQuery {\n _empty: String\n }\n\n type WebsocketsMutation {\n _empty: String\n }\n\n extend type Query {\n websockets: WebsocketsQuery\n }\n\n extend type Mutation {\n websockets: WebsocketsMutation\n }\n\n extend type WebsocketsQuery {\n listConnections(\n where: WebsocketsListConnectionsWhereInput\n ): WebsocketsListConnectionsResponse!\n }\n\n extend type WebsocketsMutation {\n disconnect(connections: [String!]!): WebsocketsDisconnectResponse!\n disconnectIdentity(identityId: String!): WebsocketsDisconnectResponse!\n disconnectTenant(tenant: String!): WebsocketsDisconnectResponse!\n disconnectAll: WebsocketsDisconnectResponse!\n }\n `);\n\n builder.addResolver({\n path: \"Query.websockets\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver({\n path: \"Mutation.websockets\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver<WebsocketsListConnectionsUseCase.Params>({\n path: \"WebsocketsQuery.listConnections\",\n dependencies: [IdentityContext, WebsocketsListConnectionsUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface\n ) => {\n return async ({ args }: { args: WebsocketsListConnectionsUseCase.Params }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await listConnections.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectConnectionsArgs>({\n path: \"WebsocketsMutation.disconnect\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }: { args: IDisconnectConnectionsArgs }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute({\n where: {\n connections: args.connections\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectIdentityArgs>({\n path: \"WebsocketsMutation.disconnectIdentity\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }: { args: IDisconnectIdentityArgs }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute({\n where: {\n identityId: args.identityId\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectTenantArgs>({\n path: \"WebsocketsMutation.disconnectTenant\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }: { args: IDisconnectTenantArgs }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute({\n where: {\n tenant: args.tenant\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver({\n path: \"WebsocketsMutation.disconnectAll\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async () => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute();\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebsocketsGraphQLFactory = CoreGraphQLSchemaFactory.createImplementation({\n dependencies: [],\n implementation: WebsocketsGraphQL\n});\n"],"names":["checkPermissions","identityContext","permissions","NotAuthorizedError","WebsocketsGraphQL","builder","IdentityContext","WebsocketsListConnectionsUseCase","listConnections","args","result","ErrorResponse","Response","ex","WebsocketsDisconnectUseCase","disconnect","staticSchemaKey","WebsocketsGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":"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"}
1
+ {"version":3,"file":"graphql/WebsocketsGraphQLFactory.js","sources":["../../src/graphql/WebsocketsGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js\";\nimport { staticSchemaKey } from \"@webiny/api-graphql/graphql/staticSchemaKey.js\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/api-graphql/graphql/abstractions.core.js\";\nimport { ErrorResponse, Response } from \"@webiny/api-graphql/responses.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { NotAuthorizedError } from \"@webiny/api-core/features/security/shared/index.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { WebsocketsDisconnectUseCase } from \"~/features/Disconnect/abstractions.js\";\nimport type { WebsocketsPermission } from \"~/types.js\";\n\ninterface IDisconnectConnectionsArgs {\n connections: string[];\n}\n\ninterface IDisconnectIdentityArgs {\n identityId: string;\n}\n\nconst checkPermissions = async (identityContext: IdentityContext.Interface): Promise<void> => {\n const permissions = await identityContext.getPermissions<WebsocketsPermission>(\"websockets\");\n\n if (permissions.length === 0) {\n throw new NotAuthorizedError();\n }\n};\n\nclass WebsocketsGraphQL implements CoreGraphQLSchemaFactory.Interface {\n public getSchemaKey = staticSchemaKey(\"api-websockets/WebsocketsGraphQL\");\n\n public async execute(\n builder: GraphQLSchemaBuilder.Interface\n ): Promise<GraphQLSchemaBuilder.Interface> {\n builder.addTypeDefs(`\n type WebsocketsIdentity {\n id: String!\n type: String\n displayName: String\n }\n\n type WebsocketsConnection {\n connectionId: String!\n endpoint: String!\n identity: WebsocketsIdentity!\n connectedOn: DateTime!\n tenant: String!\n }\n\n type WebsocketsError {\n message: String!\n code: String!\n data: JSON\n }\n\n type WebsocketsListConnectionsResponse {\n data: [WebsocketsConnection!]\n error: WebsocketsError\n }\n\n input WebsocketsListConnectionsWhereInput {\n identityId: String\n }\n\n type WebsocketsDisconnectResponse {\n data: [WebsocketsConnection!]\n error: WebsocketsError\n }\n\n type WebsocketsQuery {\n _empty: String\n }\n\n type WebsocketsMutation {\n _empty: String\n }\n\n extend type Query {\n websockets: WebsocketsQuery\n }\n\n extend type Mutation {\n websockets: WebsocketsMutation\n }\n\n extend type WebsocketsQuery {\n listConnections(\n where: WebsocketsListConnectionsWhereInput\n ): WebsocketsListConnectionsResponse!\n }\n\n extend type WebsocketsMutation {\n disconnect(connections: [String!]!): WebsocketsDisconnectResponse!\n disconnectIdentity(identityId: String!): WebsocketsDisconnectResponse!\n disconnectAll: WebsocketsDisconnectResponse!\n }\n `);\n\n builder.addResolver({\n path: \"Query.websockets\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver({\n path: \"Mutation.websockets\",\n resolver: () => {\n return async () => {\n return {};\n };\n }\n });\n\n builder.addResolver<WebsocketsListConnectionsUseCase.Params>({\n path: \"WebsocketsQuery.listConnections\",\n dependencies: [IdentityContext, WebsocketsListConnectionsUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface\n ) => {\n return async ({ args }: { args: WebsocketsListConnectionsUseCase.Params }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await listConnections.execute(args);\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectConnectionsArgs>({\n path: \"WebsocketsMutation.disconnect\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }: { args: IDisconnectConnectionsArgs }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute({\n where: {\n connections: args.connections\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectIdentityArgs>({\n path: \"WebsocketsMutation.disconnectIdentity\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }: { args: IDisconnectIdentityArgs }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute({\n where: {\n identityId: args.identityId\n }\n });\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver({\n path: \"WebsocketsMutation.disconnectAll\",\n dependencies: [IdentityContext, WebsocketsDisconnectUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async () => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnect.execute();\n\n if (result.isFail()) {\n return new ErrorResponse(result.error);\n }\n\n return new Response(result.value);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n return builder;\n }\n}\n\nexport const WebsocketsGraphQLFactory = CoreGraphQLSchemaFactory.createImplementation({\n dependencies: [],\n implementation: WebsocketsGraphQL\n});\n"],"names":["checkPermissions","identityContext","permissions","NotAuthorizedError","WebsocketsGraphQL","builder","IdentityContext","WebsocketsListConnectionsUseCase","listConnections","args","result","ErrorResponse","Response","ex","WebsocketsDisconnectUseCase","disconnect","staticSchemaKey","WebsocketsGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":";;;;;;;AAkBA,MAAMA,mBAAmB,OAAOC;IAC5B,MAAMC,cAAc,MAAMD,gBAAgB,cAAc,CAAuB;IAE/E,IAAIC,AAAuB,MAAvBA,YAAY,MAAM,EAClB,MAAM,IAAIC;AAElB;AAEA,MAAMC;IAGF,MAAa,QACTC,OAAuC,EACA;QACvCA,QAAQ,WAAW,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA8DrB,CAAC;QAEDA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QAEAA,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,UAAU,IACC,UACI,EAAC;QAGpB;QAEAA,QAAQ,WAAW,CAA0C;YACzD,MAAM;YACN,cAAc;gBAACC;gBAAiBC;aAAiC;YACjE,UAAU,CACNN,iBACAO,kBAEO,OAAO,EAAEC,IAAI,EAAqD;oBACrE,IAAI;wBACA,MAAMT,iBAAiBC;wBAEvB,MAAMS,SAAS,MAAMF,gBAAgB,OAAO,CAACC;wBAE7C,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO,IAAIE,SAASF,OAAO,KAAK;oBACpC,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAIF,cAAcE;oBAC7B;gBACJ;QAER;QAEAR,QAAQ,WAAW,CAA6B;YAC5C,MAAM;YACN,cAAc;gBAACC;gBAAiBQ;aAA4B;YAC5D,UAAU,CACNb,iBACAc,aAEO,OAAO,EAAEN,IAAI,EAAwC;oBACxD,IAAI;wBACA,MAAMT,iBAAiBC;wBAEvB,MAAMS,SAAS,MAAMK,WAAW,OAAO,CAAC;4BACpC,OAAO;gCACH,aAAaN,KAAK,WAAW;4BACjC;wBACJ;wBAEA,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO,IAAIE,SAASF,OAAO,KAAK;oBACpC,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAIF,cAAcE;oBAC7B;gBACJ;QAER;QAEAR,QAAQ,WAAW,CAA0B;YACzC,MAAM;YACN,cAAc;gBAACC;gBAAiBQ;aAA4B;YAC5D,UAAU,CACNb,iBACAc,aAEO,OAAO,EAAEN,IAAI,EAAqC;oBACrD,IAAI;wBACA,MAAMT,iBAAiBC;wBAEvB,MAAMS,SAAS,MAAMK,WAAW,OAAO,CAAC;4BACpC,OAAO;gCACH,YAAYN,KAAK,UAAU;4BAC/B;wBACJ;wBAEA,IAAIC,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO,IAAIE,SAASF,OAAO,KAAK;oBACpC,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAIF,cAAcE;oBAC7B;gBACJ;QAER;QAEAR,QAAQ,WAAW,CAAC;YAChB,MAAM;YACN,cAAc;gBAACC;gBAAiBQ;aAA4B;YAC5D,UAAU,CACNb,iBACAc,aAEO;oBACH,IAAI;wBACA,MAAMf,iBAAiBC;wBAEvB,MAAMS,SAAS,MAAMK,WAAW,OAAO;wBAEvC,IAAIL,OAAO,MAAM,IACb,OAAO,IAAIC,cAAcD,OAAO,KAAK;wBAGzC,OAAO,IAAIE,SAASF,OAAO,KAAK;oBACpC,EAAE,OAAOG,IAAI;wBACT,OAAO,IAAIF,cAAcE;oBAC7B;gBACJ;QAER;QAEA,OAAOR;IACX;;aApMO,YAAY,GAAGW,gBAAgB;;AAqM1C;AAEO,MAAMC,2BAA2BC,yBAAyB,oBAAoB,CAAC;IAClF,cAAc,EAAE;IAChB,gBAAgBd;AACpB"}
@@ -1,8 +1,9 @@
1
+ import { parseJsonBody } from "@webiny/api-kernel-core";
1
2
  const getEventBody = (event)=>{
2
3
  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);
4
+ else if ("object" == typeof event.body) return event.body;
5
+ else if ("string" == typeof event.body) try {
6
+ return parseJsonBody(event.body);
6
7
  } catch (ex) {
7
8
  console.log(ex.message);
8
9
  return {};
@@ -1 +1 @@
1
- {"version":3,"file":"handler/headers.js","sources":["../../src/handler/headers.ts"],"sourcesContent":["import type { IWebsocketsEventData, IWebsocketsIncomingEvent } from \"~/handler/types.js\";\n\nconst getEventBody = (event: IWebsocketsIncomingEvent): IWebsocketsEventData => {\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 = (body: IWebsocketsEventData, event: IWebsocketsIncomingEvent): string | null => {\n return body?.token || event.queryStringParameters?.token || null;\n};\n\nconst getTenant = (body: IWebsocketsEventData, event: IWebsocketsIncomingEvent): string => {\n return body?.tenant || event.queryStringParameters?.tenant || \"root\";\n};\n\nconst getEndpoint = (event: IWebsocketsIncomingEvent): string => {\n // The API Gateway Management API endpoint used to post messages back to a connection. It MUST be\n // the real WS API endpoint (https://<domainName>/<stage>); \"manage\" was a placeholder that made\n // every server→client send() target an invalid endpoint and silently fail.\n const rc = event.requestContext;\n if (rc?.domainName && rc?.stage) {\n return `https://${rc.domainName}/${rc.stage}`;\n }\n return \"manage\";\n};\n\nexport const getEventValues = (event: IWebsocketsIncomingEvent) => {\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: getEndpoint(event)\n };\n};\n"],"names":["getEventBody","event","JSON","ex","console","getToken","body","getTenant","getEndpoint","rc","getEventValues","token","tenant"],"mappings":"AAEA,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,CAACC,MAA4BL,QACnCK,MAAM,SAASL,MAAM,qBAAqB,EAAE,SAAS;AAGhE,MAAMM,YAAY,CAACD,MAA4BL,QACpCK,MAAM,UAAUL,MAAM,qBAAqB,EAAE,UAAU;AAGlE,MAAMO,cAAc,CAACP;IAIjB,MAAMQ,KAAKR,MAAM,cAAc;IAC/B,IAAIQ,IAAI,cAAcA,IAAI,OACtB,OAAO,CAAC,QAAQ,EAAEA,GAAG,UAAU,CAAC,CAAC,EAAEA,GAAG,KAAK,EAAE;IAEjD,OAAO;AACX;AAEO,MAAMC,iBAAiB,CAACT;IAC3B,MAAMK,OAAON,aAAaC;IAE1B,MAAMU,QAAQN,SAASC,MAAML;IAC7B,MAAMW,SAASL,UAAUD,MAAML;IAC/B,OAAO;QACHW;QACAD;QACA,UAAUH,YAAYP;IAC1B;AACJ"}
1
+ {"version":3,"file":"handler/headers.js","sources":["../../src/handler/headers.ts"],"sourcesContent":["import { parseJsonBody } from \"@webiny/api-kernel-core\";\nimport type { IWebsocketsEventData, IWebsocketsIncomingEvent } from \"~/handler/types.js\";\n\nconst getEventBody = (event: IWebsocketsIncomingEvent): IWebsocketsEventData => {\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 parseJsonBody(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 = (body: IWebsocketsEventData, event: IWebsocketsIncomingEvent): string | null => {\n return body?.token || event.queryStringParameters?.token || null;\n};\n\nconst getTenant = (body: IWebsocketsEventData, event: IWebsocketsIncomingEvent): string => {\n return body?.tenant || event.queryStringParameters?.tenant || \"root\";\n};\n\nconst getEndpoint = (event: IWebsocketsIncomingEvent): string => {\n // The API Gateway Management API endpoint used to post messages back to a connection. It MUST be\n // the real WS API endpoint (https://<domainName>/<stage>); \"manage\" was a placeholder that made\n // every server→client send() target an invalid endpoint and silently fail.\n const rc = event.requestContext;\n if (rc?.domainName && rc?.stage) {\n return `https://${rc.domainName}/${rc.stage}`;\n }\n return \"manage\";\n};\n\nexport const getEventValues = (event: IWebsocketsIncomingEvent) => {\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: getEndpoint(event)\n };\n};\n"],"names":["getEventBody","event","parseJsonBody","ex","console","getToken","body","getTenant","getEndpoint","rc","getEventValues","token","tenant"],"mappings":";AAGA,MAAMA,eAAe,CAACC;IAClB,IAAI,CAACA,MAAM,IAAI,EACX,OAAO,CAAC;SACL,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACxB,OAAOA,MAAM,IAAI;SACd,IAAI,AAAsB,YAAtB,OAAOA,MAAM,IAAI,EACxB,IAAI;QACA,OAAOC,cAAcD,MAAM,IAAI;IACnC,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,CAACC,MAA4BL,QACnCK,MAAM,SAASL,MAAM,qBAAqB,EAAE,SAAS;AAGhE,MAAMM,YAAY,CAACD,MAA4BL,QACpCK,MAAM,UAAUL,MAAM,qBAAqB,EAAE,UAAU;AAGlE,MAAMO,cAAc,CAACP;IAIjB,MAAMQ,KAAKR,MAAM,cAAc;IAC/B,IAAIQ,IAAI,cAAcA,IAAI,OACtB,OAAO,CAAC,QAAQ,EAAEA,GAAG,UAAU,CAAC,CAAC,EAAEA,GAAG,KAAK,EAAE;IAEjD,OAAO;AACX;AAEO,MAAMC,iBAAiB,CAACT;IAC3B,MAAMK,OAAON,aAAaC;IAE1B,MAAMU,QAAQN,SAASC,MAAML;IAC7B,MAAMW,SAASL,UAAUD,MAAML;IAC/B,OAAO;QACHW;QACAD;QACA,UAAUH,YAAYP;IAC1B;AACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"handler/types.js","sources":["../../src/handler/types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { PartialDeep } from \"type-fest\";\n\nexport enum WebsocketsEventRoute {\n connect = \"$connect\",\n disconnect = \"$disconnect\",\n default = \"$default\"\n}\n\nexport interface IWebsocketsEventData {\n token?: string;\n tenant?: string;\n messageId?: string;\n action?: string;\n data?: GenericRecord;\n}\n\nexport enum WebsocketsEventRequestContextEventType {\n message = \"MESSAGE\",\n connect = \"CONNECT\",\n disconnect = \"DISCONNECT\"\n}\n\nexport interface IWebsocketsEventRequestContext {\n connectionId: string;\n connectedAt: number;\n domainName: string;\n eventType: WebsocketsEventRequestContextEventType;\n routeKey: WebsocketsEventRoute | string;\n stage: string;\n}\n\nexport interface IWebsocketsEventHeaders {\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 IWebsocketsEventQueryStringParameters {\n tenant?: string;\n token?: string;\n}\n\nexport interface IWebsocketsEvent<T extends IWebsocketsEventData = IWebsocketsEventData> {\n headers?: IWebsocketsEventHeaders;\n queryStringParameters?: IWebsocketsEventQueryStringParameters;\n requestContext: IWebsocketsEventRequestContext;\n body?: T;\n}\n\nexport interface IWebsocketsIncomingEvent extends PartialDeep<Omit<IWebsocketsEvent, \"body\">> {\n body?: string | GenericRecord;\n}\n"],"names":["WebsocketsEventRoute","WebsocketsEventRequestContextEventType"],"mappings":"AAGO,IAAKA,6BAAoBA,WAAAA,GAAAA,SAApBA,oBAAoB;;;;WAApBA;;AAcL,IAAKC,+CAAsCA,WAAAA,GAAAA,SAAtCA,sCAAsC;;;;WAAtCA"}
1
+ {"version":3,"file":"handler/types.js","sources":["../../src/handler/types.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { PartialDeep } from \"type-fest\";\n\nexport enum WebsocketsEventRoute {\n connect = \"$connect\",\n disconnect = \"$disconnect\",\n default = \"$default\"\n}\n\nexport interface IWebsocketsEventData {\n token?: string;\n tenant?: string;\n messageId?: string;\n action?: string;\n data?: GenericRecord;\n}\n\nexport enum WebsocketsEventRequestContextEventType {\n message = \"MESSAGE\",\n connect = \"CONNECT\",\n disconnect = \"DISCONNECT\"\n}\n\nexport interface IWebsocketsEventRequestContext {\n connectionId: string;\n connectedAt: number;\n domainName: string;\n eventType: WebsocketsEventRequestContextEventType;\n routeKey: WebsocketsEventRoute | string;\n stage: string;\n}\n\nexport interface IWebsocketsEventHeaders {\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 IWebsocketsEventQueryStringParameters {\n tenant?: string;\n token?: string;\n}\n\nexport interface IWebsocketsEvent<T extends IWebsocketsEventData = IWebsocketsEventData> {\n headers?: IWebsocketsEventHeaders;\n queryStringParameters?: IWebsocketsEventQueryStringParameters;\n requestContext: IWebsocketsEventRequestContext;\n body?: T;\n}\n\nexport interface IWebsocketsIncomingEvent extends PartialDeep<Omit<IWebsocketsEvent, \"body\">> {\n body?: string | GenericRecord;\n}\n"],"names":["WebsocketsEventRoute","WebsocketsEventRequestContextEventType"],"mappings":"AAGO,IAAKA,6BAAoBA,WAAAA,GAAAA,SAAAA,oBAAAA;;;;;;AAczB,IAAKC,+CAAsCA,WAAAA,GAAAA,SAAAA,sCAAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-websockets",
3
- "version": "0.0.0-unstable.5387e5f7c8",
3
+ "version": "0.0.0-unstable.676006d08e",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,27 +16,27 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@webiny/api": "0.0.0-unstable.5387e5f7c8",
20
- "@webiny/api-core": "0.0.0-unstable.5387e5f7c8",
21
- "@webiny/api-graphql": "0.0.0-unstable.5387e5f7c8",
22
- "@webiny/error": "0.0.0-unstable.5387e5f7c8",
23
- "@webiny/feature": "0.0.0-unstable.5387e5f7c8",
24
- "@webiny/handler": "0.0.0-unstable.5387e5f7c8",
25
- "type-fest": "5.8.0"
19
+ "@webiny/api": "0.0.0-unstable.676006d08e",
20
+ "@webiny/api-core": "0.0.0-unstable.676006d08e",
21
+ "@webiny/api-graphql": "0.0.0-unstable.676006d08e",
22
+ "@webiny/error": "0.0.0-unstable.676006d08e",
23
+ "@webiny/feature": "0.0.0-unstable.676006d08e",
24
+ "@webiny/handler": "0.0.0-unstable.676006d08e",
25
+ "type-fest": "6.0.3"
26
26
  },
27
27
  "devDependencies": {
28
- "@webiny/api-core-testing": "0.0.0-unstable.5387e5f7c8",
29
- "@webiny/api-graphql": "0.0.0-unstable.5387e5f7c8",
30
- "@webiny/api-headless-cms": "0.0.0-unstable.5387e5f7c8",
31
- "@webiny/build-tools": "0.0.0-unstable.5387e5f7c8",
28
+ "@webiny/api-core-testing": "0.0.0-unstable.676006d08e",
29
+ "@webiny/api-graphql": "0.0.0-unstable.676006d08e",
30
+ "@webiny/api-headless-cms": "0.0.0-unstable.676006d08e",
31
+ "@webiny/api-kernel-core": "0.0.0-unstable.676006d08e",
32
+ "@webiny/build-tools": "0.0.0-unstable.676006d08e",
32
33
  "@webiny/di": "2.0.0",
33
- "@webiny/event-handler-core": "0.0.0-unstable.5387e5f7c8",
34
- "@webiny/wcp": "0.0.0-unstable.5387e5f7c8",
35
- "graphql": "16.14.2",
36
- "rimraf": "6.1.3",
37
- "type-fest": "5.8.0",
34
+ "@webiny/wcp": "0.0.0-unstable.676006d08e",
35
+ "graphql": "16.15.0",
36
+ "rimraf": "6.1.4",
37
+ "type-fest": "6.0.3",
38
38
  "typescript": "7.0.2",
39
- "vitest": "4.1.11"
39
+ "vitest": "5.1.1"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
@@ -64,19 +64,19 @@ class WebsocketsRunner {
64
64
  const tenant = this.context.container.resolve(TenantContext).getTenant();
65
65
  return tenant?.id || null;
66
66
  };
67
- const getIdentity = ()=>{
68
- const identity = this.context.container.resolve(IdentityContext).getIdentity();
69
- return identity || null;
70
- };
71
- const action = middleware(handlers.map((handler)=>async (params, next)=>handler.run({
67
+ const identityContext = this.context.container.resolve(IdentityContext);
68
+ const action = middleware(handlers.map((handler)=>async (params, next)=>{
69
+ const identity = identityContext.getIdentity();
70
+ return handler.run({
72
71
  registry: params.registry,
73
72
  event: params.event,
74
73
  container: params.container,
75
74
  getTenant,
76
- getIdentity,
75
+ identity,
77
76
  response: this.response,
78
77
  next
79
- })));
78
+ });
79
+ }));
80
80
  const result = await action({
81
81
  event,
82
82
  registry: this.registry,
@@ -96,7 +96,7 @@ class WebsocketsRunner {
96
96
  async respond(params) {
97
97
  const { connectionId, endpoint, eventType, result, messageId } = params;
98
98
  if ("message" !== eventType) return;
99
- if (!connectionId || !endpoint) {
99
+ else if (!connectionId || !endpoint) {
100
100
  const message = "No connectionId or endpoint.";
101
101
  const data = {
102
102
  connectionId,
@@ -1 +1 @@
1
- {"version":3,"file":"runner/WebsocketsRunner.js","sources":["../../src/runner/WebsocketsRunner.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n IWebsocketsEvent,\n IWebsocketsEventContext,\n IWebsocketsEventData,\n WebsocketsRoute,\n WebsocketsEventType,\n Context\n} from \"~/types.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport type { IWebsocketsRunner } from \"./abstractions/WebsocketsRunner.js\";\nimport type { IWebsocketsRunnerResponse } from \"./abstractions/WebsocketsRunner.js\";\nimport { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { middleware } from \"~/utils/middleware.js\";\nimport { WebsocketsResponse } from \"~/response/index.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { WebsocketsSendToConnectionsUseCase } from \"~/features/SendToConnections/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\ntype MiddlewareParams = Pick<WebsocketsRouteHandler.Params, \"event\" | \"registry\" | \"container\">;\n\ninterface IWebsocketsRunnerRespondParams extends Pick<\n IWebsocketsEventContext,\n \"connectionId\" | \"endpoint\" | \"eventType\"\n> {\n messageId?: string;\n result: WebsocketsResponse.OkResult | WebsocketsResponse.ErrorResult;\n}\n\nexport class WebsocketsRunner implements IWebsocketsRunner {\n private readonly context: Context;\n private readonly registry: ConnectionRegistry.Interface;\n private readonly response: WebsocketsResponse.Interface;\n private readonly sendToConnections: WebsocketsSendToConnectionsUseCase.Interface;\n\n public constructor(context: Context, response: WebsocketsResponse.Interface) {\n this.context = context;\n this.registry = context.container.resolve(ConnectionRegistry);\n this.response = response;\n this.sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);\n }\n\n public async run<T extends IWebsocketsEventData = IWebsocketsEventData>(\n event: IWebsocketsEvent<T>\n ): Promise<IWebsocketsRunnerResponse> {\n let result: WebsocketsResponse.OkResult | WebsocketsResponse.ErrorResult;\n try {\n result = await this.executeRoute(event);\n } catch (ex) {\n result = this.response.error({\n message: `Route \"${event.context.route}\" action failed.`,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n });\n }\n try {\n await this.respond({\n connectionId: event.context.connectionId,\n endpoint: event.context.endpoint,\n eventType: event.context.eventType,\n messageId: event.body?.messageId,\n result\n });\n return result;\n } catch (ex) {\n return this.response.error({\n message: \"Failed to respond to the request.\",\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...ex.data,\n result\n },\n stack: ex.stack\n }\n });\n }\n }\n\n private getRouteHandlers(route: WebsocketsRoute | string): WebsocketsRouteHandler.Interface[] {\n const handlers = this.context.container\n .resolveAll(WebsocketsRouteHandler)\n .filter(handler => handler.route === route);\n if (handlers.length === 0) {\n throw new WebinyError(\n `There are no handlers for the route: ${route}.`,\n \"NO_ROUTE_HANDLERS\",\n {\n route\n }\n );\n }\n return handlers;\n }\n\n private async executeRoute(event: IWebsocketsEvent): Promise<IWebsocketsRunnerResponse> {\n const handlers = this.getRouteHandlers(event.context.route).reverse();\n\n const getTenant = () => {\n const tenant = this.context.container.resolve(TenantContext).getTenant();\n return tenant?.id || null;\n };\n\n const getIdentity = (): ConnectionRegistry.Identity | null => {\n const identity = this.context.container.resolve(IdentityContext).getIdentity();\n return identity || null;\n };\n\n const action = middleware<MiddlewareParams, IWebsocketsRunnerResponse>(\n handlers.map(handler => {\n return async (params, next) => {\n return handler.run({\n registry: params.registry,\n event: params.event,\n container: params.container,\n getTenant,\n getIdentity,\n response: this.response,\n next\n });\n };\n })\n );\n\n const result = await action({\n event,\n registry: this.registry,\n container: this.context.container\n });\n if (result) {\n return result;\n }\n const message = \"No response from the route action.\";\n return this.response.error({\n message,\n error: {\n message,\n code: \"NO_RESPONSE\"\n },\n statusCode: 404\n });\n }\n\n private async respond(params: IWebsocketsRunnerRespondParams): Promise<void> {\n const { connectionId, endpoint, eventType, result, messageId } = params;\n if (eventType !== \"message\") {\n return;\n } else if (!connectionId || !endpoint) {\n const message = \"No connectionId or endpoint.\";\n const data = {\n connectionId,\n endpoint\n };\n console.error(message, JSON.stringify(data));\n throw new WebinyError(message, \"GENERAL_ERROR\", data);\n }\n const connection: WebsocketsTransport.SendConnection = {\n connectionId,\n endpoint\n };\n\n const dataToSend = {\n ...result,\n messageId\n };\n await this.sendToConnections.execute([connection], dataToSend);\n }\n}\n\nexport namespace WebsocketsRunner {\n export type Event<T extends IWebsocketsEventData = IWebsocketsEventData> = IWebsocketsEvent<T>;\n export type EventData = IWebsocketsEventData;\n export type EventContext = IWebsocketsEventContext;\n export type EventType = WebsocketsEventType;\n export type Route = WebsocketsRoute;\n export type Response = IWebsocketsRunnerResponse;\n}\n"],"names":["WebsocketsRunner","context","response","ConnectionRegistry","WebsocketsSendToConnectionsUseCase","event","result","ex","route","handlers","WebsocketsRouteHandler","handler","WebinyError","getTenant","tenant","TenantContext","getIdentity","identity","IdentityContext","action","middleware","params","next","message","connectionId","endpoint","eventType","messageId","data","console","JSON","connection","dataToSend"],"mappings":"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"}
1
+ {"version":3,"file":"runner/WebsocketsRunner.js","sources":["../../src/runner/WebsocketsRunner.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type {\n IWebsocketsEvent,\n IWebsocketsEventContext,\n IWebsocketsEventData,\n WebsocketsRoute,\n WebsocketsEventType,\n Context\n} from \"~/types.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport type { IWebsocketsRunner } from \"./abstractions/WebsocketsRunner.js\";\nimport type { IWebsocketsRunnerResponse } from \"./abstractions/WebsocketsRunner.js\";\nimport { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { middleware } from \"~/utils/middleware.js\";\nimport { WebsocketsResponse } from \"~/response/index.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\nimport { WebsocketsSendToConnectionsUseCase } from \"~/features/SendToConnections/abstractions.js\";\nimport { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { IdentityContext } from \"@webiny/api-core/features/security/IdentityContext/abstractions.js\";\n\ntype MiddlewareParams = Pick<WebsocketsRouteHandler.Params, \"event\" | \"registry\" | \"container\">;\n\ninterface IWebsocketsRunnerRespondParams extends Pick<\n IWebsocketsEventContext,\n \"connectionId\" | \"endpoint\" | \"eventType\"\n> {\n messageId?: string;\n result: WebsocketsResponse.OkResult | WebsocketsResponse.ErrorResult;\n}\n\nexport class WebsocketsRunner implements IWebsocketsRunner {\n private readonly context: Context;\n private readonly registry: ConnectionRegistry.Interface;\n private readonly response: WebsocketsResponse.Interface;\n private readonly sendToConnections: WebsocketsSendToConnectionsUseCase.Interface;\n\n public constructor(context: Context, response: WebsocketsResponse.Interface) {\n this.context = context;\n this.registry = context.container.resolve(ConnectionRegistry);\n this.response = response;\n this.sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);\n }\n\n public async run<T extends IWebsocketsEventData = IWebsocketsEventData>(\n event: IWebsocketsEvent<T>\n ): Promise<IWebsocketsRunnerResponse> {\n let result: WebsocketsResponse.OkResult | WebsocketsResponse.ErrorResult;\n try {\n result = await this.executeRoute(event);\n } catch (ex) {\n result = this.response.error({\n message: `Route \"${event.context.route}\" action failed.`,\n error: {\n message: ex.message,\n code: ex.code,\n data: ex.data,\n stack: ex.stack\n }\n });\n }\n try {\n await this.respond({\n connectionId: event.context.connectionId,\n endpoint: event.context.endpoint,\n eventType: event.context.eventType,\n messageId: event.body?.messageId,\n result\n });\n return result;\n } catch (ex) {\n return this.response.error({\n message: \"Failed to respond to the request.\",\n error: {\n message: ex.message,\n code: ex.code,\n data: {\n ...ex.data,\n result\n },\n stack: ex.stack\n }\n });\n }\n }\n\n private getRouteHandlers(route: WebsocketsRoute | string): WebsocketsRouteHandler.Interface[] {\n const handlers = this.context.container\n .resolveAll(WebsocketsRouteHandler)\n .filter(handler => handler.route === route);\n if (handlers.length === 0) {\n throw new WebinyError(\n `There are no handlers for the route: ${route}.`,\n \"NO_ROUTE_HANDLERS\",\n {\n route\n }\n );\n }\n return handlers;\n }\n\n private async executeRoute(event: IWebsocketsEvent): Promise<IWebsocketsRunnerResponse> {\n const handlers = this.getRouteHandlers(event.context.route).reverse();\n\n const getTenant = () => {\n const tenant = this.context.container.resolve(TenantContext).getTenant();\n return tenant?.id || null;\n };\n\n const identityContext = this.context.container.resolve(IdentityContext);\n\n const action = middleware<MiddlewareParams, IWebsocketsRunnerResponse>(\n handlers.map(handler => {\n return async (params, next) => {\n const identity = identityContext.getIdentity();\n return handler.run({\n registry: params.registry,\n event: params.event,\n container: params.container,\n getTenant,\n identity,\n response: this.response,\n next\n });\n };\n })\n );\n\n const result = await action({\n event,\n registry: this.registry,\n container: this.context.container\n });\n if (result) {\n return result;\n }\n const message = \"No response from the route action.\";\n return this.response.error({\n message,\n error: {\n message,\n code: \"NO_RESPONSE\"\n },\n statusCode: 404\n });\n }\n\n private async respond(params: IWebsocketsRunnerRespondParams): Promise<void> {\n const { connectionId, endpoint, eventType, result, messageId } = params;\n if (eventType !== \"message\") {\n return;\n } else if (!connectionId || !endpoint) {\n const message = \"No connectionId or endpoint.\";\n const data = {\n connectionId,\n endpoint\n };\n console.error(message, JSON.stringify(data));\n throw new WebinyError(message, \"GENERAL_ERROR\", data);\n }\n const connection: WebsocketsTransport.SendConnection = {\n connectionId,\n endpoint\n };\n\n const dataToSend = {\n ...result,\n messageId\n };\n await this.sendToConnections.execute([connection], dataToSend);\n }\n}\n\nexport namespace WebsocketsRunner {\n export type Event<T extends IWebsocketsEventData = IWebsocketsEventData> = IWebsocketsEvent<T>;\n export type EventData = IWebsocketsEventData;\n export type EventContext = IWebsocketsEventContext;\n export type EventType = WebsocketsEventType;\n export type Route = WebsocketsRoute;\n export type Response = IWebsocketsRunnerResponse;\n}\n"],"names":["WebsocketsRunner","context","response","ConnectionRegistry","WebsocketsSendToConnectionsUseCase","event","result","ex","route","handlers","WebsocketsRouteHandler","handler","WebinyError","getTenant","tenant","TenantContext","identityContext","IdentityContext","action","middleware","params","next","identity","message","connectionId","endpoint","eventType","messageId","data","console","JSON","connection","dataToSend"],"mappings":"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"}
@@ -1,3 +1,4 @@
1
+ import { CanAccessCurrentTenantUseCase } from "@webiny/api-core/features/security/CanAccessCurrentTenant/index.js";
1
2
  const CONNECT = "connect";
2
3
  const getConnectedOn = (connectedAt)=>{
3
4
  if (!connectedAt) return new Date().toISOString();
@@ -5,26 +6,43 @@ const getConnectedOn = (connectedAt)=>{
5
6
  };
6
7
  const websocketsRouteConnect = {
7
8
  route: CONNECT,
8
- async run ({ registry, event, response, getTenant, getIdentity }) {
9
+ async run ({ registry, event, container, response, getTenant, identity }) {
9
10
  const tenant = getTenant();
10
- const identity = getIdentity();
11
11
  if (!tenant) return response.error({
12
+ statusCode: 400,
12
13
  message: "Missing tenant."
13
14
  });
14
- if (!identity) return response.error({
15
+ else if (identity.isAnonymous()) return response.error({
16
+ statusCode: 401,
15
17
  message: "Missing identity."
16
18
  });
17
- await registry.register({
18
- identity: {
19
- id: identity.id,
20
- displayName: identity.displayName,
21
- type: identity.type
22
- },
23
- connectionId: event.context.connectionId,
24
- tenant,
25
- endpoint: event.context.endpoint,
26
- connectedOn: getConnectedOn(event.context.connectedAt)
27
- });
19
+ try {
20
+ const canAccessTenant = await container.resolve(CanAccessCurrentTenantUseCase).execute();
21
+ if (!canAccessTenant) return response.error({
22
+ statusCode: 403,
23
+ message: "No access to this tenant."
24
+ });
25
+ await registry.register({
26
+ identity: {
27
+ id: identity.id,
28
+ displayName: identity.displayName,
29
+ type: identity.type
30
+ },
31
+ connectionId: event.context.connectionId,
32
+ tenant,
33
+ endpoint: event.context.endpoint,
34
+ connectedOn: getConnectedOn(event.context.connectedAt)
35
+ });
36
+ } catch (ex) {
37
+ return response.error({
38
+ statusCode: 500,
39
+ message: "Could not accept the connection.",
40
+ error: {
41
+ message: ex.message,
42
+ code: ex.code
43
+ }
44
+ });
45
+ }
28
46
  return response.ok();
29
47
  }
30
48
  };
@@ -1 +1 @@
1
- {"version":3,"file":"runner/routes/connect.js","sources":["../../../src/runner/routes/connect.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport type { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\n\nconst CONNECT: WebsocketsRoute = \"connect\";\n\nconst getConnectedOn = (connectedAt?: number) => {\n if (!connectedAt) {\n return new Date().toISOString();\n }\n return new Date(connectedAt).toISOString();\n};\n\nexport const websocketsRouteConnect: WebsocketsRouteHandler.Interface = {\n route: CONNECT,\n async run({ registry, event, response, getTenant, getIdentity }) {\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n await registry.register({\n identity: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n connectionId: event.context.connectionId,\n tenant,\n endpoint: event.context.endpoint,\n connectedOn: getConnectedOn(event.context.connectedAt)\n });\n\n return response.ok();\n }\n};\n"],"names":["CONNECT","getConnectedOn","connectedAt","Date","websocketsRouteConnect","registry","event","response","getTenant","getIdentity","tenant","identity"],"mappings":"AAGA,MAAMA,UAA2B;AAEjC,MAAMC,iBAAiB,CAACC;IACpB,IAAI,CAACA,aACD,OAAO,IAAIC,OAAO,WAAW;IAEjC,OAAO,IAAIA,KAAKD,aAAa,WAAW;AAC5C;AAEO,MAAME,yBAA2D;IACpE,OAAOJ;IACP,MAAM,KAAI,EAAEK,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,WAAW,EAAE;QAC3D,MAAMC,SAASF;QACf,MAAMG,WAAWF;QACjB,IAAI,CAACC,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QACG,IAAI,CAACI,UACR,OAAOJ,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QAGJ,MAAMF,SAAS,QAAQ,CAAC;YACpB,UAAU;gBACN,IAAIM,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;YACA,cAAcL,MAAM,OAAO,CAAC,YAAY;YACxCI;YACA,UAAUJ,MAAM,OAAO,CAAC,QAAQ;YAChC,aAAaL,eAAeK,MAAM,OAAO,CAAC,WAAW;QACzD;QAEA,OAAOC,SAAS,EAAE;IACtB;AACJ"}
1
+ {"version":3,"file":"runner/routes/connect.js","sources":["../../../src/runner/routes/connect.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport type { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { CanAccessCurrentTenantUseCase } from \"@webiny/api-core/features/security/CanAccessCurrentTenant/index.js\";\n\nconst CONNECT: WebsocketsRoute = \"connect\";\n\nconst getConnectedOn = (connectedAt?: number) => {\n if (!connectedAt) {\n return new Date().toISOString();\n }\n return new Date(connectedAt).toISOString();\n};\n\nexport const websocketsRouteConnect: WebsocketsRouteHandler.Interface = {\n route: CONNECT,\n async run({ registry, event, container, response, getTenant, identity }) {\n const tenant = getTenant();\n // On `$connect`, API Gateway accepts the socket on any 2xx, so every refusal needs a status.\n if (!tenant) {\n return response.error({\n statusCode: 400,\n message: \"Missing tenant.\"\n });\n } else if (identity.isAnonymous()) {\n return response.error({\n statusCode: 401,\n message: \"Missing identity.\"\n });\n }\n\n /*\n * Caught here rather than left to the runner, which answers a thrown error with a 200 and\n * would open the socket.\n */\n try {\n /*\n * The tenant is whatever the client names, so a valid token alone would let a user of one\n * tenant receive another tenant's messages.\n */\n const canAccessTenant = await container\n .resolve(CanAccessCurrentTenantUseCase)\n .execute();\n if (!canAccessTenant) {\n return response.error({\n statusCode: 403,\n message: \"No access to this tenant.\"\n });\n }\n\n await registry.register({\n identity: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n connectionId: event.context.connectionId,\n tenant,\n endpoint: event.context.endpoint,\n connectedOn: getConnectedOn(event.context.connectedAt)\n });\n } catch (ex) {\n return response.error({\n statusCode: 500,\n message: \"Could not accept the connection.\",\n error: {\n message: ex.message,\n code: ex.code\n }\n });\n }\n\n return response.ok();\n }\n};\n"],"names":["CONNECT","getConnectedOn","connectedAt","Date","websocketsRouteConnect","registry","event","container","response","getTenant","identity","tenant","canAccessTenant","CanAccessCurrentTenantUseCase","ex"],"mappings":";AAIA,MAAMA,UAA2B;AAEjC,MAAMC,iBAAiB,CAACC;IACpB,IAAI,CAACA,aACD,OAAO,IAAIC,OAAO,WAAW;IAEjC,OAAO,IAAIA,KAAKD,aAAa,WAAW;AAC5C;AAEO,MAAME,yBAA2D;IACpE,OAAOJ;IACP,MAAM,KAAI,EAAEK,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,EAAE;QACnE,MAAMC,SAASF;QAEf,IAAI,CAACE,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,YAAY;YACZ,SAAS;QACb;aACG,IAAIE,SAAS,WAAW,IAC3B,OAAOF,SAAS,KAAK,CAAC;YAClB,YAAY;YACZ,SAAS;QACb;QAOJ,IAAI;YAKA,MAAMI,kBAAkB,MAAML,UACzB,OAAO,CAACM,+BACR,OAAO;YACZ,IAAI,CAACD,iBACD,OAAOJ,SAAS,KAAK,CAAC;gBAClB,YAAY;gBACZ,SAAS;YACb;YAGJ,MAAMH,SAAS,QAAQ,CAAC;gBACpB,UAAU;oBACN,IAAIK,SAAS,EAAE;oBACf,aAAaA,SAAS,WAAW;oBACjC,MAAMA,SAAS,IAAI;gBACvB;gBACA,cAAcJ,MAAM,OAAO,CAAC,YAAY;gBACxCK;gBACA,UAAUL,MAAM,OAAO,CAAC,QAAQ;gBAChC,aAAaL,eAAeK,MAAM,OAAO,CAAC,WAAW;YACzD;QACJ,EAAE,OAAOQ,IAAI;YACT,OAAON,SAAS,KAAK,CAAC;gBAClB,YAAY;gBACZ,SAAS;gBACT,OAAO;oBACH,SAASM,GAAG,OAAO;oBACnB,MAAMA,GAAG,IAAI;gBACjB;YACJ;QACJ;QAEA,OAAON,SAAS,EAAE;IACtB;AACJ"}
@@ -1,13 +1,12 @@
1
1
  const DEFAULT = "default";
2
2
  const websocketsRouteDefault = {
3
3
  route: DEFAULT,
4
- async run ({ response, getIdentity, getTenant }) {
4
+ async run ({ response, identity, getTenant }) {
5
5
  const tenant = getTenant();
6
- const identity = getIdentity();
7
6
  if (!tenant) return response.error({
8
7
  message: "Missing tenant."
9
8
  });
10
- if (!identity) return response.error({
9
+ else if (identity.isAnonymous()) return response.error({
11
10
  message: "Missing identity."
12
11
  });
13
12
  return response.ok();
@@ -1 +1 @@
1
- {"version":3,"file":"runner/routes/default.js","sources":["../../../src/runner/routes/default.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport type { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\n\nconst DEFAULT: WebsocketsRoute = \"default\";\n\nexport const websocketsRouteDefault: WebsocketsRouteHandler.Interface = {\n route: DEFAULT,\n async run({ response, getIdentity, getTenant }) {\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n return response.ok();\n }\n};\n"],"names":["DEFAULT","websocketsRouteDefault","response","getIdentity","getTenant","tenant","identity"],"mappings":"AAGA,MAAMA,UAA2B;AAE1B,MAAMC,yBAA2D;IACpE,OAAOD;IACP,MAAM,KAAI,EAAEE,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAE;QAC1C,MAAMC,SAASD;QACf,MAAME,WAAWH;QACjB,IAAI,CAACE,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QACG,IAAI,CAACI,UACR,OAAOJ,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QAGJ,OAAOA,SAAS,EAAE;IACtB;AACJ"}
1
+ {"version":3,"file":"runner/routes/default.js","sources":["../../../src/runner/routes/default.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport type { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\n\nconst DEFAULT: WebsocketsRoute = \"default\";\n\nexport const websocketsRouteDefault: WebsocketsRouteHandler.Interface = {\n route: DEFAULT,\n async run({ response, identity, getTenant }) {\n const tenant = getTenant();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (identity.isAnonymous()) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n return response.ok();\n }\n};\n"],"names":["DEFAULT","websocketsRouteDefault","response","identity","getTenant","tenant"],"mappings":"AAGA,MAAMA,UAA2B;AAE1B,MAAMC,yBAA2D;IACpE,OAAOD;IACP,MAAM,KAAI,EAAEE,QAAQ,EAAEC,QAAQ,EAAEC,SAAS,EAAE;QACvC,MAAMC,SAASD;QACf,IAAI,CAACC,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;aACG,IAAIC,SAAS,WAAW,IAC3B,OAAOD,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QAGJ,OAAOA,SAAS,EAAE;IACtB;AACJ"}
@@ -5,7 +5,6 @@ import { websocketsRouteDefault } from "./default.js";
5
5
  export { websocketsRouteConnect, websocketsRouteDisconnect, websocketsRouteDefault };
6
6
  /**
7
7
  * Registers the built-in WebSocket route handlers (connect, disconnect, default) as
8
- * WebsocketsRouteHandler implementations. Custom routes can be added the same way:
9
- * `container.registerInstance(WebsocketsRouteHandler, { route, run })`.
8
+ * WebsocketsRouteHandler implementations.
10
9
  */
11
10
  export declare const registerWebsocketsRoutes: (container: Container) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"runner/routes/index.js","sources":["../../../src/runner/routes/index.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { websocketsRouteConnect } from \"./connect.js\";\nimport { websocketsRouteDisconnect } from \"./disconnect.js\";\nimport { websocketsRouteDefault } from \"./default.js\";\n\nexport { websocketsRouteConnect, websocketsRouteDisconnect, websocketsRouteDefault };\n\n/**\n * Registers the built-in WebSocket route handlers (connect, disconnect, default) as\n * WebsocketsRouteHandler implementations. Custom routes can be added the same way:\n * `container.registerInstance(WebsocketsRouteHandler, { route, run })`.\n */\nexport const registerWebsocketsRoutes = (container: Container): void => {\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteConnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDisconnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDefault);\n};\n"],"names":["registerWebsocketsRoutes","container","WebsocketsRouteHandler","websocketsRouteConnect","websocketsRouteDisconnect","websocketsRouteDefault"],"mappings":";;;;AAaO,MAAMA,2BAA2B,CAACC;IACrCA,UAAU,gBAAgB,CAACC,wBAAwBC;IACnDF,UAAU,gBAAgB,CAACC,wBAAwBE;IACnDH,UAAU,gBAAgB,CAACC,wBAAwBG;AACvD"}
1
+ {"version":3,"file":"runner/routes/index.js","sources":["../../../src/runner/routes/index.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { websocketsRouteConnect } from \"./connect.js\";\nimport { websocketsRouteDisconnect } from \"./disconnect.js\";\nimport { websocketsRouteDefault } from \"./default.js\";\n\nexport { websocketsRouteConnect, websocketsRouteDisconnect, websocketsRouteDefault };\n\n/**\n * Registers the built-in WebSocket route handlers (connect, disconnect, default) as\n * WebsocketsRouteHandler implementations.\n */\nexport const registerWebsocketsRoutes = (container: Container): void => {\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteConnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDisconnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDefault);\n};\n"],"names":["registerWebsocketsRoutes","container","WebsocketsRouteHandler","websocketsRouteConnect","websocketsRouteDisconnect","websocketsRouteDefault"],"mappings":";;;;AAYO,MAAMA,2BAA2B,CAACC;IACrCA,UAAU,gBAAgB,CAACC,wBAAwBC;IACnDF,UAAU,gBAAgB,CAACC,wBAAwBE;IACnDH,UAAU,gBAAgB,CAACC,wBAAwBG;AACvD"}
@@ -1,16 +1,5 @@
1
1
  import type { GenericRecord } from "@webiny/api/types.js";
2
- export interface IWebsocketsTransportSendDataError {
3
- message: string;
4
- code: string;
5
- data?: GenericRecord;
6
- stack?: string;
7
- }
8
- export interface IWebsocketsTransportSendData<T extends GenericRecord> {
9
- messageId?: string;
10
- action?: string;
11
- data?: T;
12
- error?: IWebsocketsTransportSendDataError;
13
- }
2
+ import type { IWebsocketsTransportSendData } from "@webiny/api-core/features/websockets/index.js";
14
3
  export interface IWebsocketsTransportSendConnection {
15
4
  connectionId: string;
16
5
  endpoint: string;
@@ -1 +1 @@
1
- {"version":3,"file":"transport/abstractions/WebsocketsTransport.js","sources":["../../../src/transport/abstractions/WebsocketsTransport.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\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 interface IWebsocketsTransportSendConnection {\n connectionId: string;\n endpoint: string;\n}\n\nexport interface IWebsocketsTransportDisconnectConnection {\n connectionId: string;\n endpoint: string;\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\nexport const WebsocketsTransport = createAbstraction<IWebsocketsTransport>(\"WebsocketsTransport\");\n\nexport namespace WebsocketsTransport {\n export type Interface = IWebsocketsTransport;\n export type SendConnection = IWebsocketsTransportSendConnection;\n export type SendData<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n export type DisconnectConnection = IWebsocketsTransportDisconnectConnection;\n}\n"],"names":["WebsocketsTransport","createAbstraction"],"mappings":";AAoCO,MAAMA,sBAAsBC,kBAAwC"}
1
+ {"version":3,"file":"transport/abstractions/WebsocketsTransport.js","sources":["../../../src/transport/abstractions/WebsocketsTransport.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\nimport type { IWebsocketsTransportSendData } from \"@webiny/api-core/features/websockets/index.js\";\n\nexport interface IWebsocketsTransportSendConnection {\n connectionId: string;\n endpoint: string;\n}\n\nexport interface IWebsocketsTransportDisconnectConnection {\n connectionId: string;\n endpoint: string;\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\nexport const WebsocketsTransport = createAbstraction<IWebsocketsTransport>(\"WebsocketsTransport\");\n\nexport namespace WebsocketsTransport {\n export type Interface = IWebsocketsTransport;\n export type SendConnection = IWebsocketsTransportSendConnection;\n export type SendData<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n export type DisconnectConnection = IWebsocketsTransportDisconnectConnection;\n}\n"],"names":["WebsocketsTransport","createAbstraction"],"mappings":";AAuBO,MAAMA,sBAAsBC,kBAAwC"}
@@ -1 +1 @@
1
- export { WebsocketsTransport, type IWebsocketsTransport, type IWebsocketsTransportSendConnection, type IWebsocketsTransportSendData, type IWebsocketsTransportSendDataError, type IWebsocketsTransportDisconnectConnection } from "./abstractions/WebsocketsTransport.js";
1
+ export { WebsocketsTransport, type IWebsocketsTransport, type IWebsocketsTransportSendConnection, type IWebsocketsTransportDisconnectConnection } from "./abstractions/WebsocketsTransport.js";
package/types.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
2
2
  import type { SecurityPermission } from "@webiny/api-core/types/security.js";
3
- import type { SecurityIdentity } from "@webiny/api-core/types/security.js";
4
3
  import type { GenericRecord } from "@webiny/api/types.js";
5
- export type IWebsocketsIdentity = Pick<SecurityIdentity, "id" | "displayName" | "type">;
6
4
  export interface Context extends ApiCoreContext {
7
5
  }
8
6
  export interface WebsocketsPermission extends SecurityPermission {
@@ -1,14 +0,0 @@
1
- import type { Result } from "@webiny/feature/api";
2
- import type { GenericRecord } from "@webiny/api/types.js";
3
- import type { IWebsocketsIdentity } from "../../types.js";
4
- import type { IWebsocketsTransportSendData } from "../../transport/index.js";
5
- import type { WebsocketsError } from "../../features/shared/errors.js";
6
- export interface ISendToIdentityUseCase {
7
- execute<T extends GenericRecord = GenericRecord>(identity: Pick<IWebsocketsIdentity, "id">, data: IWebsocketsTransportSendData<T>): Promise<Result<void, WebsocketsError>>;
8
- }
9
- export declare const WebsocketsSendToIdentityUseCase: import("@webiny/di").Abstraction<ISendToIdentityUseCase>;
10
- export declare namespace WebsocketsSendToIdentityUseCase {
11
- type Interface = ISendToIdentityUseCase;
12
- type Identity = Pick<IWebsocketsIdentity, "id">;
13
- type Data<T extends GenericRecord> = IWebsocketsTransportSendData<T>;
14
- }
@@ -1,5 +0,0 @@
1
- import { createAbstraction } from "@webiny/feature/api";
2
- const WebsocketsSendToIdentityUseCase = createAbstraction("Websockets/SendToIdentity");
3
- export { WebsocketsSendToIdentityUseCase };
4
-
5
- //# sourceMappingURL=abstractions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"features/SendToIdentity/abstractions.js","sources":["../../../src/features/SendToIdentity/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Result } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IWebsocketsIdentity } from \"~/types.js\";\nimport type { IWebsocketsTransportSendData } from \"~/transport/index.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\n\nexport interface ISendToIdentityUseCase {\n execute<T extends GenericRecord = GenericRecord>(\n identity: Pick<IWebsocketsIdentity, \"id\">,\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketsError>>;\n}\n\nexport const WebsocketsSendToIdentityUseCase = createAbstraction<ISendToIdentityUseCase>(\n \"Websockets/SendToIdentity\"\n);\n\nexport namespace WebsocketsSendToIdentityUseCase {\n export type Interface = ISendToIdentityUseCase;\n export type Identity = Pick<IWebsocketsIdentity, \"id\">;\n export type Data<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n}\n"],"names":["WebsocketsSendToIdentityUseCase","createAbstraction"],"mappings":";AAcO,MAAMA,kCAAkCC,kBAC3C"}
@@ -1,4 +0,0 @@
1
- export declare const WebsocketsGraphQLFactoryFeature: {
2
- name: string;
3
- register(container: import("@webiny/di").Container): void;
4
- };
@@ -1,11 +0,0 @@
1
- import { createFeature } from "@webiny/feature/api";
2
- import { WebsocketsGraphQLFactory } from "./WebsocketsGraphQLFactory.js";
3
- const WebsocketsGraphQLFactoryFeature = createFeature({
4
- name: "WebsocketsGraphQLFactory",
5
- register (container) {
6
- container.register(WebsocketsGraphQLFactory);
7
- }
8
- });
9
- export { WebsocketsGraphQLFactoryFeature };
10
-
11
- //# sourceMappingURL=feature.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"graphql/feature.js","sources":["../../src/graphql/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { WebsocketsGraphQLFactory } from \"./WebsocketsGraphQLFactory.js\";\n\nexport const WebsocketsGraphQLFactoryFeature = createFeature({\n name: \"WebsocketsGraphQLFactory\",\n register(container) {\n container.register(WebsocketsGraphQLFactory);\n }\n});\n"],"names":["WebsocketsGraphQLFactoryFeature","createFeature","container","WebsocketsGraphQLFactory"],"mappings":";;AAGO,MAAMA,kCAAkCC,cAAc;IACzD,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;IACvB;AACJ"}