@webiny/api-websockets 0.0.0-unstable.3c5210ad37 → 0.0.0-unstable.3fddf667ea

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 (178) hide show
  1. package/WebsocketsFeature.d.ts +4 -0
  2. package/WebsocketsFeature.js +23 -0
  3. package/WebsocketsFeature.js.map +1 -0
  4. package/exports/api.d.ts +10 -0
  5. package/exports/api.js +9 -0
  6. package/{registry/abstractions/IWebsocketsConnectionRegistry.d.ts → features/ConnectionRegistry/abstractions.d.ts} +15 -8
  7. package/features/ConnectionRegistry/abstractions.js +5 -0
  8. package/features/ConnectionRegistry/abstractions.js.map +1 -0
  9. package/features/Disconnect/DisconnectUseCase.d.ts +17 -0
  10. package/features/Disconnect/DisconnectUseCase.js +45 -0
  11. package/features/Disconnect/DisconnectUseCase.js.map +1 -0
  12. package/features/Disconnect/abstractions.d.ts +13 -0
  13. package/features/Disconnect/abstractions.js +5 -0
  14. package/features/Disconnect/abstractions.js.map +1 -0
  15. package/features/ListConnections/ListConnectionsUseCase.d.ts +13 -0
  16. package/features/ListConnections/ListConnectionsUseCase.js +30 -0
  17. package/features/ListConnections/ListConnectionsUseCase.js.map +1 -0
  18. package/features/ListConnections/abstractions.d.ts +21 -0
  19. package/features/ListConnections/abstractions.js +5 -0
  20. package/features/ListConnections/abstractions.js.map +1 -0
  21. package/features/Routes/abstractions.d.ts +38 -0
  22. package/features/Routes/abstractions.js +5 -0
  23. package/features/Routes/abstractions.js.map +1 -0
  24. package/features/SendToConnections/SendToConnectionsUseCase.d.ts +14 -0
  25. package/features/SendToConnections/SendToConnectionsUseCase.js +26 -0
  26. package/features/SendToConnections/SendToConnectionsUseCase.js.map +1 -0
  27. package/features/SendToConnections/abstractions.d.ts +14 -0
  28. package/features/SendToConnections/abstractions.js +5 -0
  29. package/features/SendToConnections/abstractions.js.map +1 -0
  30. package/features/SendToIdentity/SendToIdentityUseCase.d.ts +18 -0
  31. package/features/SendToIdentity/SendToIdentityUseCase.js +41 -0
  32. package/features/SendToIdentity/SendToIdentityUseCase.js.map +1 -0
  33. package/features/feature.d.ts +1 -0
  34. package/features/feature.js +1 -0
  35. package/features/{WebsocketService → shared}/errors.d.ts +2 -6
  36. package/features/shared/errors.js +24 -0
  37. package/features/shared/errors.js.map +1 -0
  38. package/graphql/WebsocketsGraphQLFactory.d.ts +10 -0
  39. package/graphql/WebsocketsGraphQLFactory.js +196 -0
  40. package/graphql/WebsocketsGraphQLFactory.js.map +1 -0
  41. package/graphql/feature.d.ts +4 -0
  42. package/graphql/feature.js +11 -0
  43. package/graphql/feature.js.map +1 -0
  44. package/graphql/index.d.ts +1 -2
  45. package/graphql/index.js +1 -13
  46. package/handler/headers.js +25 -27
  47. package/handler/headers.js.map +1 -1
  48. package/handler/types.d.ts +6 -17
  49. package/handler/types.js +11 -10
  50. package/handler/types.js.map +1 -1
  51. package/index.d.ts +4 -5
  52. package/index.js +3 -10
  53. package/package.json +23 -25
  54. package/registry/index.d.ts +1 -2
  55. package/registry/index.js +0 -3
  56. package/response/WebsocketsResponse.d.ts +8 -4
  57. package/response/WebsocketsResponse.js +25 -19
  58. package/response/WebsocketsResponse.js.map +1 -1
  59. package/response/abstractions/{IWebsocketsResponse.d.ts → WebsocketsResponse.d.ts} +9 -0
  60. package/response/abstractions/WebsocketsResponse.js +5 -0
  61. package/response/abstractions/WebsocketsResponse.js.map +1 -0
  62. package/response/index.d.ts +5 -2
  63. package/response/index.js +2 -3
  64. package/runner/WebsocketsRunner.d.ts +16 -10
  65. package/runner/WebsocketsRunner.js +111 -166
  66. package/runner/WebsocketsRunner.js.map +1 -1
  67. package/runner/abstractions/{IWebsocketsRunner.d.ts → WebsocketsRunner.d.ts} +2 -2
  68. package/runner/abstractions/WebsocketsRunner.js +0 -0
  69. package/runner/index.d.ts +2 -1
  70. package/runner/index.js +1 -2
  71. package/runner/routes/connect.d.ts +2 -1
  72. package/runner/routes/connect.js +28 -42
  73. package/runner/routes/connect.js.map +1 -1
  74. package/runner/routes/default.d.ts +2 -1
  75. package/runner/routes/default.js +14 -23
  76. package/runner/routes/default.js.map +1 -1
  77. package/runner/routes/disconnect.d.ts +2 -1
  78. package/runner/routes/disconnect.js +10 -16
  79. package/runner/routes/disconnect.js.map +1 -1
  80. package/runner/routes/index.d.ts +11 -1
  81. package/runner/routes/index.js +9 -5
  82. package/runner/routes/index.js.map +1 -1
  83. package/transport/NullWebsocketsTransport.d.ts +9 -0
  84. package/transport/NullWebsocketsTransport.js +12 -0
  85. package/transport/NullWebsocketsTransport.js.map +1 -0
  86. package/transport/abstractions/WebsocketsTransport.d.ts +21 -0
  87. package/transport/abstractions/WebsocketsTransport.js +5 -0
  88. package/transport/abstractions/WebsocketsTransport.js.map +1 -0
  89. package/transport/index.d.ts +1 -2
  90. package/transport/index.js +1 -3
  91. package/types.d.ts +24 -5
  92. package/types.js +0 -3
  93. package/utils/middleware.js +9 -14
  94. package/utils/middleware.js.map +1 -1
  95. package/validator/abstractions/WebsocketsEventValidator.d.ts +8 -0
  96. package/validator/abstractions/WebsocketsEventValidator.js +5 -0
  97. package/validator/abstractions/WebsocketsEventValidator.js.map +1 -0
  98. package/validator/index.d.ts +2 -2
  99. package/validator/index.js +1 -3
  100. package/context/WebsocketsContext.d.ts +0 -15
  101. package/context/WebsocketsContext.js +0 -81
  102. package/context/WebsocketsContext.js.map +0 -1
  103. package/context/abstractions/IWebsocketsContext.d.ts +0 -23
  104. package/context/abstractions/IWebsocketsContext.js +0 -3
  105. package/context/abstractions/IWebsocketsContext.js.map +0 -1
  106. package/context/index.d.ts +0 -4
  107. package/context/index.js +0 -22
  108. package/context/index.js.map +0 -1
  109. package/features/WebsocketService/abstractions.d.ts +0 -9
  110. package/features/WebsocketService/abstractions.js +0 -4
  111. package/features/WebsocketService/abstractions.js.map +0 -1
  112. package/features/WebsocketService/errors.js +0 -36
  113. package/features/WebsocketService/errors.js.map +0 -1
  114. package/features/WebsocketService/index.d.ts +0 -1
  115. package/features/WebsocketService/index.js +0 -3
  116. package/features/WebsocketService/index.js.map +0 -1
  117. package/graphql/checkPermissions.d.ts +0 -7
  118. package/graphql/checkPermissions.js +0 -16
  119. package/graphql/checkPermissions.js.map +0 -1
  120. package/graphql/createResolvers.d.ts +0 -12
  121. package/graphql/createResolvers.js +0 -80
  122. package/graphql/createResolvers.js.map +0 -1
  123. package/graphql/createTypeDefs.d.ts +0 -1
  124. package/graphql/createTypeDefs.js +0 -69
  125. package/graphql/createTypeDefs.js.map +0 -1
  126. package/graphql/index.js.map +0 -1
  127. package/graphql/utils.d.ts +0 -7
  128. package/graphql/utils.js +0 -11
  129. package/graphql/utils.js.map +0 -1
  130. package/handler/handler.d.ts +0 -2
  131. package/handler/handler.js +0 -81
  132. package/handler/handler.js.map +0 -1
  133. package/handler/register.d.ts +0 -1
  134. package/handler/register.js +0 -26
  135. package/handler/register.js.map +0 -1
  136. package/index.js.map +0 -1
  137. package/plugins/WebsocketsActionPlugin.d.ts +0 -11
  138. package/plugins/WebsocketsActionPlugin.js +0 -17
  139. package/plugins/WebsocketsActionPlugin.js.map +0 -1
  140. package/plugins/WebsocketsRoutePlugin.d.ts +0 -27
  141. package/plugins/WebsocketsRoutePlugin.js +0 -17
  142. package/plugins/WebsocketsRoutePlugin.js.map +0 -1
  143. package/plugins/abstrations/IWebsocketsActionPlugin.d.ts +0 -34
  144. package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -3
  145. package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
  146. package/plugins/index.d.ts +0 -3
  147. package/plugins/index.js +0 -4
  148. package/plugins/index.js.map +0 -1
  149. package/registry/WebsocketsConnectionRegistry.d.ts +0 -23
  150. package/registry/WebsocketsConnectionRegistry.js +0 -157
  151. package/registry/WebsocketsConnectionRegistry.js.map +0 -1
  152. package/registry/abstractions/IWebsocketsConnectionRegistry.js +0 -3
  153. package/registry/abstractions/IWebsocketsConnectionRegistry.js.map +0 -1
  154. package/registry/entity.d.ts +0 -3
  155. package/registry/entity.js +0 -47
  156. package/registry/entity.js.map +0 -1
  157. package/registry/index.js.map +0 -1
  158. package/response/abstractions/IWebsocketsResponse.js +0 -3
  159. package/response/abstractions/IWebsocketsResponse.js.map +0 -1
  160. package/response/index.js.map +0 -1
  161. package/runner/abstractions/IWebsocketsRunner.js +0 -3
  162. package/runner/abstractions/IWebsocketsRunner.js.map +0 -1
  163. package/runner/index.js.map +0 -1
  164. package/transport/WebsocketsTransport.d.ts +0 -8
  165. package/transport/WebsocketsTransport.js +0 -47
  166. package/transport/WebsocketsTransport.js.map +0 -1
  167. package/transport/abstractions/IWebsocketsTransport.d.ts +0 -20
  168. package/transport/abstractions/IWebsocketsTransport.js +0 -3
  169. package/transport/abstractions/IWebsocketsTransport.js.map +0 -1
  170. package/transport/index.js.map +0 -1
  171. package/types.js.map +0 -1
  172. package/validator/WebsocketsEventValidator.d.ts +0 -5
  173. package/validator/WebsocketsEventValidator.js +0 -76
  174. package/validator/WebsocketsEventValidator.js.map +0 -1
  175. package/validator/abstractions/IWebsocketsEventValidator.d.ts +0 -8
  176. package/validator/abstractions/IWebsocketsEventValidator.js +0 -3
  177. package/validator/abstractions/IWebsocketsEventValidator.js.map +0 -1
  178. package/validator/index.js.map +0 -1
@@ -0,0 +1,4 @@
1
+ export declare const WebsocketsFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,23 @@
1
+ import { createFeature } from "@webiny/feature/api";
2
+ import { ListConnectionsUseCase } from "./features/ListConnections/ListConnectionsUseCase.js";
3
+ import { SendToConnectionsUseCase } from "./features/SendToConnections/SendToConnectionsUseCase.js";
4
+ import { SendToIdentityUseCase } from "./features/SendToIdentity/SendToIdentityUseCase.js";
5
+ import { DisconnectUseCase } from "./features/Disconnect/DisconnectUseCase.js";
6
+ import { NullWebsocketsTransport } from "./transport/NullWebsocketsTransport.js";
7
+ import { DefaultWebsocketsResponse } from "./response/WebsocketsResponse.js";
8
+ import { registerWebsocketsRoutes } from "./runner/routes/index.js";
9
+ const WebsocketsFeature = createFeature({
10
+ name: "Websockets",
11
+ register (container) {
12
+ container.register(NullWebsocketsTransport);
13
+ container.register(DefaultWebsocketsResponse);
14
+ container.register(ListConnectionsUseCase);
15
+ container.register(SendToConnectionsUseCase);
16
+ container.register(SendToIdentityUseCase);
17
+ container.register(DisconnectUseCase);
18
+ registerWebsocketsRoutes(container);
19
+ }
20
+ });
21
+ export { WebsocketsFeature };
22
+
23
+ //# sourceMappingURL=WebsocketsFeature.js.map
@@ -0,0 +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"}
@@ -0,0 +1,10 @@
1
+ export { WebsocketsTransport } from "../transport/index.js";
2
+ export { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
3
+ export { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
4
+ export { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
5
+ export { ConnectionRegistry } from "../features/ConnectionRegistry/abstractions.js";
6
+ export { WebsocketsEventValidator } from "../validator/index.js";
7
+ export { WebsocketsRunner } from "../runner/WebsocketsRunner.js";
8
+ export { WebsocketsRouteHandler } from "../features/Routes/abstractions.js";
9
+ export { WebsocketsResponse } from "../response/index.js";
10
+ export type { WebsocketsError } from "../features/shared/errors.js";
package/exports/api.js ADDED
@@ -0,0 +1,9 @@
1
+ export { WebsocketsTransport } from "../transport/index.js";
2
+ export { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
3
+ export { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
4
+ export { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
5
+ export { ConnectionRegistry } from "../features/ConnectionRegistry/abstractions.js";
6
+ export { WebsocketsEventValidator } from "../validator/index.js";
7
+ export { WebsocketsRunner } from "../runner/WebsocketsRunner.js";
8
+ export { WebsocketsRouteHandler } from "../features/Routes/abstractions.js";
9
+ export { WebsocketsResponse } from "../response/index.js";
@@ -1,22 +1,19 @@
1
- import type { IWebsocketsIdentity } from "../../context/abstractions/IWebsocketsContext.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
- domainName: string;
8
- stage: string;
7
+ endpoint: string;
8
+ owner?: string;
9
9
  }
10
10
  export interface IWebsocketsConnectionRegistryRegisterParams {
11
11
  connectionId: string;
12
12
  tenant: string;
13
13
  identity: IWebsocketsIdentity;
14
- domainName: string;
15
- stage: string;
16
- /**
17
- * A DateTime.toISOString() format.
18
- */
14
+ endpoint: string;
19
15
  connectedOn: string;
16
+ owner?: string;
20
17
  }
21
18
  export interface IWebsocketsConnectionRegistryUnregisterParams {
22
19
  connectionId: string;
@@ -28,4 +25,14 @@ export interface IWebsocketsConnectionRegistry {
28
25
  listViaIdentity(identity: string): Promise<IWebsocketsConnectionRegistryData[]>;
29
26
  listViaTenant(tenant: string): Promise<IWebsocketsConnectionRegistryData[]>;
30
27
  listAll(): Promise<IWebsocketsConnectionRegistryData[]>;
28
+ updateLastSeen(connectionId: string): Promise<void>;
29
+ listStale(olderThan: Date): Promise<IWebsocketsConnectionRegistryData[]>;
30
+ }
31
+ export declare const ConnectionRegistry: import("@webiny/di").Abstraction<IWebsocketsConnectionRegistry>;
32
+ export declare namespace ConnectionRegistry {
33
+ type Interface = IWebsocketsConnectionRegistry;
34
+ type Identity = IWebsocketsIdentity;
35
+ type Data = IWebsocketsConnectionRegistryData;
36
+ type RegisterParams = IWebsocketsConnectionRegistryRegisterParams;
37
+ type UnregisterParams = IWebsocketsConnectionRegistryUnregisterParams;
31
38
  }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const ConnectionRegistry = createAbstraction("ConnectionRegistry");
3
+ export { ConnectionRegistry };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +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 \"@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"}
@@ -0,0 +1,17 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsDisconnectUseCase } from "./abstractions.js";
3
+ import type { WebsocketsError } from "../../features/shared/errors.js";
4
+ import { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
5
+ import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
6
+ import { WebsocketsTransport } from "../../transport/index.js";
7
+ declare class DisconnectUseCaseImpl implements WebsocketsDisconnectUseCase.Interface {
8
+ private readonly listConnections;
9
+ private readonly registry;
10
+ private readonly transport;
11
+ constructor(listConnections: WebsocketsListConnectionsUseCase.Interface, registry: ConnectionRegistry.Interface, transport: WebsocketsTransport.Interface);
12
+ execute(params?: WebsocketsDisconnectUseCase.Params, notify?: boolean): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>>;
13
+ }
14
+ export declare const DisconnectUseCase: typeof DisconnectUseCaseImpl & {
15
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IDisconnectUseCase>;
16
+ };
17
+ export {};
@@ -0,0 +1,45 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsDisconnectUseCase } from "./abstractions.js";
3
+ import { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError } from "../shared/errors.js";
4
+ import { WebsocketsListConnectionsUseCase } from "../ListConnections/abstractions.js";
5
+ import { ConnectionRegistry } from "../ConnectionRegistry/abstractions.js";
6
+ import { WebsocketsTransport } from "../../transport/index.js";
7
+ class DisconnectUseCaseImpl {
8
+ constructor(listConnections, registry, transport){
9
+ this.listConnections = listConnections;
10
+ this.registry = registry;
11
+ this.transport = transport;
12
+ }
13
+ async execute(params, notify = true) {
14
+ const result = await this.listConnections.execute(params);
15
+ if (result.isFail()) return Result.fail(result.error);
16
+ const connections = result.value;
17
+ for (const connection of connections)try {
18
+ await this.registry.unregister(connection);
19
+ } catch {}
20
+ if (notify) try {
21
+ await this.transport.send(connections, {
22
+ action: "forcedDisconnect"
23
+ });
24
+ } catch (error) {
25
+ return Result.fail(new WebsocketForceDisconnectNotificationError(error));
26
+ }
27
+ try {
28
+ await this.transport.disconnect(connections);
29
+ } catch (error) {
30
+ return Result.fail(new WebsocketForceDisconnectError(error));
31
+ }
32
+ return Result.ok(connections);
33
+ }
34
+ }
35
+ const DisconnectUseCase = WebsocketsDisconnectUseCase.createImplementation({
36
+ implementation: DisconnectUseCaseImpl,
37
+ dependencies: [
38
+ WebsocketsListConnectionsUseCase,
39
+ ConnectionRegistry,
40
+ WebsocketsTransport
41
+ ]
42
+ });
43
+ export { DisconnectUseCase };
44
+
45
+ //# sourceMappingURL=DisconnectUseCase.js.map
@@ -0,0 +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"}
@@ -0,0 +1,13 @@
1
+ import type { Result } from "@webiny/feature/api";
2
+ import type { WebsocketsError } from "../../features/shared/errors.js";
3
+ import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
4
+ import { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
5
+ export type IWebsocketsDisconnectParams = WebsocketsListConnectionsUseCase.Params;
6
+ export interface IDisconnectUseCase {
7
+ execute(params?: IWebsocketsDisconnectParams, notify?: boolean): Promise<Result<ConnectionRegistry.Data[], WebsocketsError>>;
8
+ }
9
+ export declare const WebsocketsDisconnectUseCase: import("@webiny/di").Abstraction<IDisconnectUseCase>;
10
+ export declare namespace WebsocketsDisconnectUseCase {
11
+ type Interface = IDisconnectUseCase;
12
+ type Params = IWebsocketsDisconnectParams;
13
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const WebsocketsDisconnectUseCase = createAbstraction("Websockets/Disconnect");
3
+ export { WebsocketsDisconnectUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/Disconnect/abstractions.js","sources":["../../../src/features/Disconnect/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\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\n\nexport type IWebsocketsDisconnectParams = WebsocketsListConnectionsUseCase.Params;\n\nexport interface IDisconnectUseCase {\n execute(\n params?: IWebsocketsDisconnectParams,\n notify?: boolean\n ): Promise<Result<ConnectionRegistry.Data[], WebsocketsError>>;\n}\n\nexport const WebsocketsDisconnectUseCase =\n createAbstraction<IDisconnectUseCase>(\"Websockets/Disconnect\");\n\nexport namespace WebsocketsDisconnectUseCase {\n export type Interface = IDisconnectUseCase;\n export type Params = IWebsocketsDisconnectParams;\n}\n"],"names":["WebsocketsDisconnectUseCase","createAbstraction"],"mappings":";AAeO,MAAMA,8BACTC,kBAAsC"}
@@ -0,0 +1,13 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsListConnectionsUseCase } from "./abstractions.js";
3
+ import type { WebsocketsError } from "../../features/shared/errors.js";
4
+ import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
5
+ declare class ListConnectionsUseCaseImpl implements WebsocketsListConnectionsUseCase.Interface {
6
+ private readonly registry;
7
+ constructor(registry: ConnectionRegistry.Interface);
8
+ execute(params?: WebsocketsListConnectionsUseCase.Params): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>>;
9
+ }
10
+ export declare const ListConnectionsUseCase: typeof ListConnectionsUseCaseImpl & {
11
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").IListConnectionsUseCase>;
12
+ };
13
+ export {};
@@ -0,0 +1,30 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsListConnectionsUseCase } from "./abstractions.js";
3
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
4
+ import { ConnectionRegistry } from "../ConnectionRegistry/abstractions.js";
5
+ class ListConnectionsUseCaseImpl {
6
+ constructor(registry){
7
+ this.registry = registry;
8
+ }
9
+ async execute(params) {
10
+ let connections = [];
11
+ try {
12
+ 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();
14
+ } catch (error) {
15
+ return Result.fail(new WebsocketServiceError(error));
16
+ }
17
+ const threeHoursAgo = new Date(Date.now() - 10800000).toISOString();
18
+ connections = connections.filter((c)=>c.connectedOn >= threeHoursAgo);
19
+ return Result.ok(connections);
20
+ }
21
+ }
22
+ const ListConnectionsUseCase = WebsocketsListConnectionsUseCase.createImplementation({
23
+ implementation: ListConnectionsUseCaseImpl,
24
+ dependencies: [
25
+ ConnectionRegistry
26
+ ]
27
+ });
28
+ export { ListConnectionsUseCase };
29
+
30
+ //# sourceMappingURL=ListConnectionsUseCase.js.map
@@ -0,0 +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 \"@webiny/api-core/features/websockets/index.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"}
@@ -0,0 +1,21 @@
1
+ import type { Result } from "@webiny/feature/api";
2
+ import type { WebsocketsError } from "../../features/shared/errors.js";
3
+ import { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
4
+ export interface IWebsocketsListConnectionsParamsWhere {
5
+ identityId?: string;
6
+ tenant?: string;
7
+ connections?: string[];
8
+ }
9
+ export interface IWebsocketsListConnectionsParams {
10
+ where?: IWebsocketsListConnectionsParamsWhere;
11
+ }
12
+ export interface IListConnectionsUseCase {
13
+ execute(params?: IWebsocketsListConnectionsParams): Promise<Result<ConnectionRegistry.Data[], WebsocketsError>>;
14
+ }
15
+ export declare const WebsocketsListConnectionsUseCase: import("@webiny/di").Abstraction<IListConnectionsUseCase>;
16
+ export declare namespace WebsocketsListConnectionsUseCase {
17
+ type Interface = IListConnectionsUseCase;
18
+ type Params = IWebsocketsListConnectionsParams;
19
+ type ParamsWhere = IWebsocketsListConnectionsParamsWhere;
20
+ type RegistryData = ConnectionRegistry.Data;
21
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const WebsocketsListConnectionsUseCase = createAbstraction("Websockets/ListConnections");
3
+ export { WebsocketsListConnectionsUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +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"}
@@ -0,0 +1,38 @@
1
+ import type { Container } from "@webiny/di";
2
+ import type { ConnectionRegistry } from "../../features/ConnectionRegistry/abstractions.js";
3
+ import type { WebsocketsResponse } from "../../response/index.js";
4
+ import type { IWebsocketsRunnerResponse } from "../../runner/abstractions/WebsocketsRunner.js";
5
+ import type { IWebsocketsEvent, IWebsocketsEventData } from "../../types.js";
6
+ /**
7
+ * Parameters passed to a route handler's `run` method. Route handlers for the same
8
+ * `route` are chained middleware-style via `next`.
9
+ */
10
+ export interface IWebsocketsRouteHandlerParams<R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse, T extends IWebsocketsEventData = IWebsocketsEventData> {
11
+ event: IWebsocketsEvent<T>;
12
+ registry: ConnectionRegistry.Interface;
13
+ container: Container;
14
+ response: WebsocketsResponse.Interface;
15
+ getTenant: () => string | null;
16
+ getIdentity: () => ConnectionRegistry.Identity | null;
17
+ next: () => Promise<R>;
18
+ }
19
+ /**
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.
29
+ */
30
+ export interface IWebsocketsRouteHandler<R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse, T extends IWebsocketsEventData = IWebsocketsEventData> {
31
+ route: string;
32
+ run(params: IWebsocketsRouteHandlerParams<R, T>): Promise<R>;
33
+ }
34
+ export declare const WebsocketsRouteHandler: import("@webiny/di").Abstraction<IWebsocketsRouteHandler<IWebsocketsRunnerResponse, IWebsocketsEventData>>;
35
+ export declare namespace WebsocketsRouteHandler {
36
+ type Interface = IWebsocketsRouteHandler;
37
+ type Params = IWebsocketsRouteHandlerParams;
38
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const WebsocketsRouteHandler = createAbstraction("WebsocketsRouteHandler");
3
+ export { WebsocketsRouteHandler };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +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"}
@@ -0,0 +1,14 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ import { WebsocketsTransport } from "../../transport/index.js";
4
+ import { WebsocketsSendToConnectionsUseCase } from "./abstractions.js";
5
+ import type { WebsocketsError } from "../../features/shared/errors.js";
6
+ declare class SendToConnectionsUseCaseImpl implements WebsocketsSendToConnectionsUseCase.Interface {
7
+ private readonly transport;
8
+ constructor(transport: WebsocketsTransport.Interface);
9
+ execute<T extends GenericRecord = GenericRecord>(connections: WebsocketsSendToConnectionsUseCase.Connection[], data: WebsocketsSendToConnectionsUseCase.Data<T>): Promise<Result<void, WebsocketsError>>;
10
+ }
11
+ export declare const SendToConnectionsUseCase: typeof SendToConnectionsUseCaseImpl & {
12
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ISendToConnectionsUseCase>;
13
+ };
14
+ export {};
@@ -0,0 +1,26 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsTransport } from "../../transport/index.js";
3
+ import { WebsocketsSendToConnectionsUseCase } from "./abstractions.js";
4
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
5
+ class SendToConnectionsUseCaseImpl {
6
+ constructor(transport){
7
+ this.transport = transport;
8
+ }
9
+ async execute(connections, data) {
10
+ try {
11
+ await this.transport.send(connections, data);
12
+ } catch (error) {
13
+ return Result.fail(new WebsocketServiceError(error));
14
+ }
15
+ return Result.ok();
16
+ }
17
+ }
18
+ const SendToConnectionsUseCase = WebsocketsSendToConnectionsUseCase.createImplementation({
19
+ implementation: SendToConnectionsUseCaseImpl,
20
+ dependencies: [
21
+ WebsocketsTransport
22
+ ]
23
+ });
24
+ export { SendToConnectionsUseCase };
25
+
26
+ //# sourceMappingURL=SendToConnectionsUseCase.js.map
@@ -0,0 +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 \"@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"}
@@ -0,0 +1,14 @@
1
+ import type { Result } from "@webiny/feature/api";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ import type { IWebsocketsTransportSendConnection } from "../../transport/index.js";
4
+ import type { IWebsocketsTransportSendData } from "@webiny/api-core/features/websockets/index.js";
5
+ import type { WebsocketsError } from "../../features/shared/errors.js";
6
+ export interface ISendToConnectionsUseCase {
7
+ execute<T extends GenericRecord = GenericRecord>(connections: IWebsocketsTransportSendConnection[], data: IWebsocketsTransportSendData<T>): Promise<Result<void, WebsocketsError>>;
8
+ }
9
+ export declare const WebsocketsSendToConnectionsUseCase: import("@webiny/di").Abstraction<ISendToConnectionsUseCase>;
10
+ export declare namespace WebsocketsSendToConnectionsUseCase {
11
+ type Interface = ISendToConnectionsUseCase;
12
+ type Connection = IWebsocketsTransportSendConnection;
13
+ type Data<T extends GenericRecord> = IWebsocketsTransportSendData<T>;
14
+ }
@@ -0,0 +1,5 @@
1
+ import { createAbstraction } from "@webiny/feature/api";
2
+ const WebsocketsSendToConnectionsUseCase = createAbstraction("Websockets/SendToConnections");
3
+ export { WebsocketsSendToConnectionsUseCase };
4
+
5
+ //# sourceMappingURL=abstractions.js.map
@@ -0,0 +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 \"@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"}
@@ -0,0 +1,18 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import type { GenericRecord } from "@webiny/api/types.js";
3
+ import { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
4
+ import { WebsocketsTransport } from "../../transport/index.js";
5
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
6
+ import { WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
7
+ import { WebsocketServiceError } from "@webiny/api-core/features/websockets/index.js";
8
+ declare class SendToIdentityUseCaseImpl implements WebsocketsSendToIdentityUseCase.Interface {
9
+ private readonly listConnections;
10
+ private readonly transport;
11
+ private readonly logger;
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, WebsocketServiceError>>;
14
+ }
15
+ export declare const SendToIdentityUseCase: typeof SendToIdentityUseCaseImpl & {
16
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/websockets/SendToIdentity/abstractions").ISendToIdentityUseCase>;
17
+ };
18
+ export {};
@@ -0,0 +1,41 @@
1
+ import { Result } from "@webiny/feature/api";
2
+ import { WebsocketsListConnectionsUseCase } from "../ListConnections/abstractions.js";
3
+ import { WebsocketsTransport } from "../../transport/index.js";
4
+ import { Logger } from "@webiny/api-core/features/logger/index.js";
5
+ import { WebsocketServiceError, WebsocketsSendToIdentityUseCase } from "@webiny/api-core/features/websockets/index.js";
6
+ class SendToIdentityUseCaseImpl {
7
+ constructor(listConnections, transport, logger){
8
+ this.listConnections = listConnections;
9
+ this.transport = transport;
10
+ this.logger = logger;
11
+ }
12
+ async execute(identity, data) {
13
+ const result = await this.listConnections.execute({
14
+ where: {
15
+ identityId: identity.id
16
+ }
17
+ });
18
+ if (result.isFail()) return Result.fail(new WebsocketServiceError(result.error));
19
+ if (0 === result.value.length) this.logger.warn({
20
+ identityId: identity.id,
21
+ action: data.action
22
+ }, "No websocket connections found for identity; message not sent.");
23
+ try {
24
+ await this.transport.send(result.value, data);
25
+ } catch (error) {
26
+ return Result.fail(new WebsocketServiceError(error));
27
+ }
28
+ return Result.ok();
29
+ }
30
+ }
31
+ const SendToIdentityUseCase = WebsocketsSendToIdentityUseCase.createImplementation({
32
+ implementation: SendToIdentityUseCaseImpl,
33
+ dependencies: [
34
+ WebsocketsListConnectionsUseCase,
35
+ WebsocketsTransport,
36
+ Logger
37
+ ]
38
+ });
39
+ export { SendToIdentityUseCase };
40
+
41
+ //# sourceMappingURL=SendToIdentityUseCase.js.map
@@ -0,0 +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 \"@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"}
@@ -0,0 +1 @@
1
+ export { WebsocketsFeature } from "../WebsocketsFeature.js";
@@ -0,0 +1 @@
1
+ export { WebsocketsFeature } from "../WebsocketsFeature.js";
@@ -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,3 +12,4 @@ export declare class WebsocketForceDisconnectError extends BaseError<{
17
12
  readonly code: "Websocket/Service/ForceDisconnect";
18
13
  constructor(error: Error);
19
14
  }
15
+ export type WebsocketsError = WebsocketServiceError | WebsocketForceDisconnectNotificationError | WebsocketForceDisconnectError;
@@ -0,0 +1,24 @@
1
+ import { BaseError } from "@webiny/feature/api";
2
+ class WebsocketForceDisconnectNotificationError extends BaseError {
3
+ constructor(error){
4
+ super({
5
+ message: "Failed to notify the clients about the forced disconnect.",
6
+ data: {
7
+ error
8
+ }
9
+ }), this.code = "Websocket/Service/ForceDisconnectNotification";
10
+ }
11
+ }
12
+ class WebsocketForceDisconnectError extends BaseError {
13
+ constructor(error){
14
+ super({
15
+ message: "Failed to forcefully disconnect the Websocket clients.",
16
+ data: {
17
+ error
18
+ }
19
+ }), this.code = "Websocket/Service/ForceDisconnect";
20
+ }
21
+ }
22
+ export { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError };
23
+
24
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
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 type WebsocketsError =\n | WebsocketServiceError\n | WebsocketForceDisconnectNotificationError\n | WebsocketForceDisconnectError;\n"],"names":["WebsocketForceDisconnectNotificationError","BaseError","error","WebsocketForceDisconnectError"],"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"}
@@ -0,0 +1,10 @@
1
+ import { GraphQLSchemaBuilder } from "@webiny/api-graphql/features/GraphQLSchemaBuilder/abstractions.js";
2
+ import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.core.js";
3
+ declare class WebsocketsGraphQL implements CoreGraphQLSchemaFactory.Interface {
4
+ getSchemaKey: () => string;
5
+ execute(builder: GraphQLSchemaBuilder.Interface): Promise<GraphQLSchemaBuilder.Interface>;
6
+ }
7
+ export declare const WebsocketsGraphQLFactory: typeof WebsocketsGraphQL & {
8
+ __abstraction: import("@webiny/di").Abstraction<import("@webiny/api-graphql/graphql/abstractions.core.js").ICoreGraphQLSchemaFactory>;
9
+ };
10
+ export {};