@webiny/api-websockets 0.0.0-unstable.e6f0dc8ca7 → 0.0.0-unstable.e9333b3f0b

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 (180) 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 +11 -0
  5. package/exports/api.js +10 -0
  6. package/{registry/abstractions/IWebsocketsConnectionRegistry.d.ts → features/ConnectionRegistry/abstractions.d.ts} +13 -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 +42 -0
  32. package/features/SendToIdentity/SendToIdentityUseCase.js.map +1 -0
  33. package/features/SendToIdentity/abstractions.d.ts +14 -0
  34. package/features/SendToIdentity/abstractions.js +5 -0
  35. package/features/SendToIdentity/abstractions.js.map +1 -0
  36. package/features/feature.d.ts +1 -0
  37. package/features/feature.js +1 -0
  38. package/features/{WebsocketService → shared}/errors.d.ts +1 -0
  39. package/features/shared/errors.js +34 -0
  40. package/features/shared/errors.js.map +1 -0
  41. package/graphql/WebsocketsGraphQLFactory.d.ts +10 -0
  42. package/graphql/WebsocketsGraphQLFactory.js +196 -0
  43. package/graphql/WebsocketsGraphQLFactory.js.map +1 -0
  44. package/graphql/feature.d.ts +4 -0
  45. package/graphql/feature.js +11 -0
  46. package/graphql/feature.js.map +1 -0
  47. package/graphql/index.d.ts +1 -2
  48. package/graphql/index.js +1 -13
  49. package/handler/headers.js +25 -27
  50. package/handler/headers.js.map +1 -1
  51. package/handler/types.d.ts +6 -17
  52. package/handler/types.js +11 -10
  53. package/handler/types.js.map +1 -1
  54. package/index.d.ts +4 -5
  55. package/index.js +3 -10
  56. package/package.json +23 -24
  57. package/registry/index.d.ts +1 -2
  58. package/registry/index.js +0 -3
  59. package/response/WebsocketsResponse.d.ts +8 -4
  60. package/response/WebsocketsResponse.js +25 -19
  61. package/response/WebsocketsResponse.js.map +1 -1
  62. package/response/abstractions/{IWebsocketsResponse.d.ts → WebsocketsResponse.d.ts} +9 -0
  63. package/response/abstractions/WebsocketsResponse.js +5 -0
  64. package/response/abstractions/WebsocketsResponse.js.map +1 -0
  65. package/response/index.d.ts +5 -2
  66. package/response/index.js +2 -3
  67. package/runner/WebsocketsRunner.d.ts +16 -10
  68. package/runner/WebsocketsRunner.js +111 -166
  69. package/runner/WebsocketsRunner.js.map +1 -1
  70. package/runner/abstractions/{IWebsocketsRunner.d.ts → WebsocketsRunner.d.ts} +2 -2
  71. package/runner/abstractions/WebsocketsRunner.js +0 -0
  72. package/runner/index.d.ts +2 -1
  73. package/runner/index.js +1 -2
  74. package/runner/routes/connect.d.ts +2 -1
  75. package/runner/routes/connect.js +28 -42
  76. package/runner/routes/connect.js.map +1 -1
  77. package/runner/routes/default.d.ts +2 -1
  78. package/runner/routes/default.js +14 -23
  79. package/runner/routes/default.js.map +1 -1
  80. package/runner/routes/disconnect.d.ts +2 -1
  81. package/runner/routes/disconnect.js +10 -16
  82. package/runner/routes/disconnect.js.map +1 -1
  83. package/runner/routes/index.d.ts +11 -1
  84. package/runner/routes/index.js +9 -5
  85. package/runner/routes/index.js.map +1 -1
  86. package/transport/NullWebsocketsTransport.d.ts +9 -0
  87. package/transport/NullWebsocketsTransport.js +12 -0
  88. package/transport/NullWebsocketsTransport.js.map +1 -0
  89. package/transport/abstractions/{IWebsocketsTransport.d.ts → WebsocketsTransport.d.ts} +15 -3
  90. package/transport/abstractions/WebsocketsTransport.js +5 -0
  91. package/transport/abstractions/WebsocketsTransport.js.map +1 -0
  92. package/transport/index.d.ts +1 -2
  93. package/transport/index.js +1 -3
  94. package/types.d.ts +26 -5
  95. package/types.js +0 -3
  96. package/utils/middleware.js +9 -14
  97. package/utils/middleware.js.map +1 -1
  98. package/validator/abstractions/WebsocketsEventValidator.d.ts +8 -0
  99. package/validator/abstractions/WebsocketsEventValidator.js +5 -0
  100. package/validator/abstractions/WebsocketsEventValidator.js.map +1 -0
  101. package/validator/index.d.ts +2 -2
  102. package/validator/index.js +1 -3
  103. package/context/WebsocketsContext.d.ts +0 -15
  104. package/context/WebsocketsContext.js +0 -86
  105. package/context/WebsocketsContext.js.map +0 -1
  106. package/context/abstractions/IWebsocketsContext.d.ts +0 -23
  107. package/context/abstractions/IWebsocketsContext.js +0 -3
  108. package/context/abstractions/IWebsocketsContext.js.map +0 -1
  109. package/context/index.d.ts +0 -4
  110. package/context/index.js +0 -22
  111. package/context/index.js.map +0 -1
  112. package/features/WebsocketService/abstractions.d.ts +0 -9
  113. package/features/WebsocketService/abstractions.js +0 -4
  114. package/features/WebsocketService/abstractions.js.map +0 -1
  115. package/features/WebsocketService/errors.js +0 -36
  116. package/features/WebsocketService/errors.js.map +0 -1
  117. package/features/WebsocketService/index.d.ts +0 -1
  118. package/features/WebsocketService/index.js +0 -3
  119. package/features/WebsocketService/index.js.map +0 -1
  120. package/graphql/checkPermissions.d.ts +0 -7
  121. package/graphql/checkPermissions.js +0 -16
  122. package/graphql/checkPermissions.js.map +0 -1
  123. package/graphql/createResolvers.d.ts +0 -12
  124. package/graphql/createResolvers.js +0 -80
  125. package/graphql/createResolvers.js.map +0 -1
  126. package/graphql/createTypeDefs.d.ts +0 -1
  127. package/graphql/createTypeDefs.js +0 -69
  128. package/graphql/createTypeDefs.js.map +0 -1
  129. package/graphql/index.js.map +0 -1
  130. package/graphql/utils.d.ts +0 -7
  131. package/graphql/utils.js +0 -11
  132. package/graphql/utils.js.map +0 -1
  133. package/handler/handler.d.ts +0 -2
  134. package/handler/handler.js +0 -81
  135. package/handler/handler.js.map +0 -1
  136. package/handler/register.d.ts +0 -1
  137. package/handler/register.js +0 -26
  138. package/handler/register.js.map +0 -1
  139. package/index.js.map +0 -1
  140. package/plugins/WebsocketsActionPlugin.d.ts +0 -11
  141. package/plugins/WebsocketsActionPlugin.js +0 -17
  142. package/plugins/WebsocketsActionPlugin.js.map +0 -1
  143. package/plugins/WebsocketsRoutePlugin.d.ts +0 -27
  144. package/plugins/WebsocketsRoutePlugin.js +0 -17
  145. package/plugins/WebsocketsRoutePlugin.js.map +0 -1
  146. package/plugins/abstrations/IWebsocketsActionPlugin.d.ts +0 -34
  147. package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -3
  148. package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
  149. package/plugins/index.d.ts +0 -3
  150. package/plugins/index.js +0 -4
  151. package/plugins/index.js.map +0 -1
  152. package/registry/WebsocketsConnectionRegistry.d.ts +0 -23
  153. package/registry/WebsocketsConnectionRegistry.js +0 -157
  154. package/registry/WebsocketsConnectionRegistry.js.map +0 -1
  155. package/registry/abstractions/IWebsocketsConnectionRegistry.js +0 -3
  156. package/registry/abstractions/IWebsocketsConnectionRegistry.js.map +0 -1
  157. package/registry/entity.d.ts +0 -3
  158. package/registry/entity.js +0 -47
  159. package/registry/entity.js.map +0 -1
  160. package/registry/index.js.map +0 -1
  161. package/response/abstractions/IWebsocketsResponse.js +0 -3
  162. package/response/abstractions/IWebsocketsResponse.js.map +0 -1
  163. package/response/index.js.map +0 -1
  164. package/runner/abstractions/IWebsocketsRunner.js +0 -3
  165. package/runner/abstractions/IWebsocketsRunner.js.map +0 -1
  166. package/runner/index.js.map +0 -1
  167. package/transport/WebsocketsTransport.d.ts +0 -8
  168. package/transport/WebsocketsTransport.js +0 -47
  169. package/transport/WebsocketsTransport.js.map +0 -1
  170. package/transport/abstractions/IWebsocketsTransport.js +0 -3
  171. package/transport/abstractions/IWebsocketsTransport.js.map +0 -1
  172. package/transport/index.js.map +0 -1
  173. package/types.js.map +0 -1
  174. package/validator/WebsocketsEventValidator.d.ts +0 -5
  175. package/validator/WebsocketsEventValidator.js +0 -76
  176. package/validator/WebsocketsEventValidator.js.map +0 -1
  177. package/validator/abstractions/IWebsocketsEventValidator.d.ts +0 -8
  178. package/validator/abstractions/IWebsocketsEventValidator.js +0 -3
  179. package/validator/abstractions/IWebsocketsEventValidator.js.map +0 -1
  180. package/validator/index.js.map +0 -1
@@ -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 {};
@@ -0,0 +1,196 @@
1
+ import { staticSchemaKey } from "@webiny/api-graphql/graphql/staticSchemaKey.js";
2
+ import { CoreGraphQLSchemaFactory } from "@webiny/api-graphql/graphql/abstractions.core.js";
3
+ import { ErrorResponse, Response } from "@webiny/api-graphql/responses.js";
4
+ import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
5
+ import { NotAuthorizedError } from "@webiny/api-core/features/security/shared/index.js";
6
+ import { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
7
+ import { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
8
+ const checkPermissions = async (identityContext)=>{
9
+ const permissions = await identityContext.getPermissions("websockets");
10
+ if (0 === permissions.length) throw new NotAuthorizedError();
11
+ };
12
+ class WebsocketsGraphQL {
13
+ async execute(builder) {
14
+ builder.addTypeDefs(`
15
+ type WebsocketsIdentity {
16
+ id: String!
17
+ type: String
18
+ displayName: String
19
+ }
20
+
21
+ type WebsocketsConnection {
22
+ connectionId: String!
23
+ endpoint: String!
24
+ identity: WebsocketsIdentity!
25
+ connectedOn: DateTime!
26
+ tenant: String!
27
+ }
28
+
29
+ type WebsocketsError {
30
+ message: String!
31
+ code: String!
32
+ data: JSON
33
+ }
34
+
35
+ type WebsocketsListConnectionsResponse {
36
+ data: [WebsocketsConnection!]
37
+ error: WebsocketsError
38
+ }
39
+
40
+ input WebsocketsListConnectionsWhereInput {
41
+ identityId: String
42
+ tenant: String
43
+ }
44
+
45
+ type WebsocketsDisconnectResponse {
46
+ data: [WebsocketsConnection!]
47
+ error: WebsocketsError
48
+ }
49
+
50
+ type WebsocketsQuery {
51
+ _empty: String
52
+ }
53
+
54
+ type WebsocketsMutation {
55
+ _empty: String
56
+ }
57
+
58
+ extend type Query {
59
+ websockets: WebsocketsQuery
60
+ }
61
+
62
+ extend type Mutation {
63
+ websockets: WebsocketsMutation
64
+ }
65
+
66
+ extend type WebsocketsQuery {
67
+ listConnections(
68
+ where: WebsocketsListConnectionsWhereInput
69
+ ): WebsocketsListConnectionsResponse!
70
+ }
71
+
72
+ extend type WebsocketsMutation {
73
+ disconnect(connections: [String!]!): WebsocketsDisconnectResponse!
74
+ disconnectIdentity(identityId: String!): WebsocketsDisconnectResponse!
75
+ disconnectTenant(tenant: String!): WebsocketsDisconnectResponse!
76
+ disconnectAll: WebsocketsDisconnectResponse!
77
+ }
78
+ `);
79
+ builder.addResolver({
80
+ path: "Query.websockets",
81
+ resolver: ()=>async ()=>({})
82
+ });
83
+ builder.addResolver({
84
+ path: "Mutation.websockets",
85
+ resolver: ()=>async ()=>({})
86
+ });
87
+ builder.addResolver({
88
+ path: "WebsocketsQuery.listConnections",
89
+ dependencies: [
90
+ IdentityContext,
91
+ WebsocketsListConnectionsUseCase
92
+ ],
93
+ resolver: (identityContext, listConnections)=>async ({ args })=>{
94
+ try {
95
+ await checkPermissions(identityContext);
96
+ const result = await listConnections.execute(args);
97
+ if (result.isFail()) return new ErrorResponse(result.error);
98
+ return new Response(result.value);
99
+ } catch (ex) {
100
+ return new ErrorResponse(ex);
101
+ }
102
+ }
103
+ });
104
+ builder.addResolver({
105
+ path: "WebsocketsMutation.disconnect",
106
+ dependencies: [
107
+ IdentityContext,
108
+ WebsocketsDisconnectUseCase
109
+ ],
110
+ resolver: (identityContext, disconnect)=>async ({ args })=>{
111
+ try {
112
+ await checkPermissions(identityContext);
113
+ const result = await disconnect.execute({
114
+ where: {
115
+ connections: args.connections
116
+ }
117
+ });
118
+ if (result.isFail()) return new ErrorResponse(result.error);
119
+ return new Response(result.value);
120
+ } catch (ex) {
121
+ return new ErrorResponse(ex);
122
+ }
123
+ }
124
+ });
125
+ builder.addResolver({
126
+ path: "WebsocketsMutation.disconnectIdentity",
127
+ dependencies: [
128
+ IdentityContext,
129
+ WebsocketsDisconnectUseCase
130
+ ],
131
+ resolver: (identityContext, disconnect)=>async ({ args })=>{
132
+ try {
133
+ await checkPermissions(identityContext);
134
+ const result = await disconnect.execute({
135
+ where: {
136
+ identityId: args.identityId
137
+ }
138
+ });
139
+ if (result.isFail()) return new ErrorResponse(result.error);
140
+ return new Response(result.value);
141
+ } catch (ex) {
142
+ return new ErrorResponse(ex);
143
+ }
144
+ }
145
+ });
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
+ builder.addResolver({
168
+ path: "WebsocketsMutation.disconnectAll",
169
+ dependencies: [
170
+ IdentityContext,
171
+ WebsocketsDisconnectUseCase
172
+ ],
173
+ resolver: (identityContext, disconnect)=>async ()=>{
174
+ try {
175
+ await checkPermissions(identityContext);
176
+ const result = await disconnect.execute();
177
+ if (result.isFail()) return new ErrorResponse(result.error);
178
+ return new Response(result.value);
179
+ } catch (ex) {
180
+ return new ErrorResponse(ex);
181
+ }
182
+ }
183
+ });
184
+ return builder;
185
+ }
186
+ constructor(){
187
+ this.getSchemaKey = staticSchemaKey("api-websockets/WebsocketsGraphQL");
188
+ }
189
+ }
190
+ const WebsocketsGraphQLFactory = CoreGraphQLSchemaFactory.createImplementation({
191
+ dependencies: [],
192
+ implementation: WebsocketsGraphQL
193
+ });
194
+ export { WebsocketsGraphQLFactory };
195
+
196
+ //# sourceMappingURL=WebsocketsGraphQLFactory.js.map
@@ -0,0 +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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"}
@@ -0,0 +1,4 @@
1
+ export declare const WebsocketsGraphQLFactoryFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -1,2 +1 @@
1
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
- export declare const createWebsocketsGraphQL: () => GraphQLSchemaPlugin<import("../types.js").Context>;
1
+ export { WebsocketsGraphQLFactory } from "./WebsocketsGraphQLFactory.js";
package/graphql/index.js CHANGED
@@ -1,13 +1 @@
1
- import { GraphQLSchemaPlugin } from "@webiny/handler-graphql";
2
- import { createTypeDefs } from "./createTypeDefs.js";
3
- import { createResolvers } from "./createResolvers.js";
4
- export const createWebsocketsGraphQL = () => {
5
- const plugin = new GraphQLSchemaPlugin({
6
- typeDefs: createTypeDefs(),
7
- resolvers: createResolvers()
8
- });
9
- plugin.name = "websockets.graphql";
10
- return plugin;
11
- };
12
-
13
- //# sourceMappingURL=index.js.map
1
+ export { WebsocketsGraphQLFactory } from "./WebsocketsGraphQLFactory.js";
@@ -1,34 +1,32 @@
1
- const getEventBody = event => {
2
- if (!event.body) {
3
- return {};
4
- } else if (typeof event.body === "object") {
5
- return event.body;
6
- } else if (typeof event.body === "string") {
7
- try {
8
- return JSON.parse(event.body);
1
+ const getEventBody = (event)=>{
2
+ if (!event.body) return {};
3
+ if ("object" == typeof event.body) return event.body;
4
+ if ("string" == typeof event.body) try {
5
+ return JSON.parse(event.body);
9
6
  } catch (ex) {
10
- console.log(ex.message);
11
- return {};
7
+ console.log(ex.message);
8
+ return {};
12
9
  }
13
- }
14
- console.log("Unexpected event.body type:", typeof event.body);
15
- return {};
16
- };
17
- const getToken = (body, event) => {
18
- return body?.token || event.queryStringParameters?.token || null;
10
+ console.log("Unexpected event.body type:", typeof event.body);
11
+ return {};
19
12
  };
20
- const getTenant = (body, event) => {
21
- return body?.tenant || event.queryStringParameters?.tenant || "root";
13
+ const getToken = (body, event)=>body?.token || event.queryStringParameters?.token || null;
14
+ const getTenant = (body, event)=>body?.tenant || event.queryStringParameters?.tenant || "root";
15
+ const getEndpoint = (event)=>{
16
+ const rc = event.requestContext;
17
+ if (rc?.domainName && rc?.stage) return `https://${rc.domainName}/${rc.stage}`;
18
+ return "manage";
22
19
  };
23
- export const getEventValues = event => {
24
- const body = getEventBody(event);
25
- const token = getToken(body, event);
26
- const tenant = getTenant(body, event);
27
- return {
28
- tenant,
29
- token,
30
- endpoint: "manage"
31
- };
20
+ const getEventValues = (event)=>{
21
+ const body = getEventBody(event);
22
+ const token = getToken(body, event);
23
+ const tenant = getTenant(body, event);
24
+ return {
25
+ tenant,
26
+ token,
27
+ endpoint: getEndpoint(event)
28
+ };
32
29
  };
30
+ export { getEventValues };
33
31
 
34
32
  //# sourceMappingURL=headers.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getEventBody","event","body","JSON","parse","ex","console","log","message","getToken","token","queryStringParameters","getTenant","tenant","getEventValues","endpoint"],"sources":["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\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: \"manage\"\n };\n};\n"],"mappings":"AAEA,MAAMA,YAAY,GAAIC,KAA+B,IAA2B;EAC5E,IAAI,CAACA,KAAK,CAACC,IAAI,EAAE;IACb,OAAO,CAAC,CAAC;EACb,CAAC,MAAM,IAAI,OAAOD,KAAK,CAACC,IAAI,KAAK,QAAQ,EAAE;IACvC,OAAOD,KAAK,CAACC,IAAI;EACrB,CAAC,MAAM,IAAI,OAAOD,KAAK,CAACC,IAAI,KAAK,QAAQ,EAAE;IACvC,IAAI;MACA,OAAOC,IAAI,CAACC,KAAK,CAACH,KAAK,CAACC,IAAI,CAAC;IACjC,CAAC,CAAC,OAAOG,EAAE,EAAE;MACTC,OAAO,CAACC,GAAG,CAACF,EAAE,CAACG,OAAO,CAAC;MACvB,OAAO,CAAC,CAAC;IACb;EACJ;EACAF,OAAO,CAACC,GAAG,CAAC,6BAA6B,EAAE,OAAON,KAAK,CAACC,IAAI,CAAC;EAC7D,OAAO,CAAC,CAAC;AACb,CAAC;AAED,MAAMO,QAAQ,GAAGA,CAACP,IAA0B,EAAED,KAA+B,KAAoB;EAC7F,OAAOC,IAAI,EAAEQ,KAAK,IAAIT,KAAK,CAACU,qBAAqB,EAAED,KAAK,IAAI,IAAI;AACpE,CAAC;AAED,MAAME,SAAS,GAAGA,CAACV,IAA0B,EAAED,KAA+B,KAAa;EACvF,OAAOC,IAAI,EAAEW,MAAM,IAAIZ,KAAK,CAACU,qBAAqB,EAAEE,MAAM,IAAI,MAAM;AACxE,CAAC;AAED,OAAO,MAAMC,cAAc,GAAIb,KAA+B,IAAK;EAC/D,MAAMC,IAAI,GAAGF,YAAY,CAACC,KAAK,CAAC;EAEhC,MAAMS,KAAK,GAAGD,QAAQ,CAACP,IAAI,EAAED,KAAK,CAAC;EACnC,MAAMY,MAAM,GAAGD,SAAS,CAACV,IAAI,EAAED,KAAK,CAAC;EACrC,OAAO;IACHY,MAAM;IACNH,KAAK;IACLK,QAAQ,EAAE;EACd,CAAC;AACL,CAAC","ignoreList":[]}
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,20 +1,9 @@
1
- import type { HandlerFactoryParams } from "@webiny/handler-aws/types.js";
2
- import type { IWebsocketsEventValidator } from "../validator/index.js";
3
- import type { IWebsocketsResponse } from "../response/index.js";
4
- import type { APIGatewayProxyResult, Context as LambdaContext } from "@webiny/aws-sdk/types/index.js";
5
1
  import type { GenericRecord } from "@webiny/api/types.js";
6
2
  import type { PartialDeep } from "type-fest";
7
- export interface HandlerCallable {
8
- (event: IWebsocketsIncomingEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;
9
- }
10
- export interface HandlerParams extends HandlerFactoryParams {
11
- validator?: IWebsocketsEventValidator;
12
- response?: IWebsocketsResponse;
13
- }
14
3
  export declare enum WebsocketsEventRoute {
15
- "connect" = "$connect",
16
- "disconnect" = "$disconnect",
17
- "default" = "$default"
4
+ connect = "$connect",
5
+ disconnect = "$disconnect",
6
+ default = "$default"
18
7
  }
19
8
  export interface IWebsocketsEventData {
20
9
  token?: string;
@@ -24,9 +13,9 @@ export interface IWebsocketsEventData {
24
13
  data?: GenericRecord;
25
14
  }
26
15
  export declare enum WebsocketsEventRequestContextEventType {
27
- "message" = "MESSAGE",
28
- "connect" = "CONNECT",
29
- "disconnect" = "DISCONNECT"
16
+ message = "MESSAGE",
17
+ connect = "CONNECT",
18
+ disconnect = "DISCONNECT"
30
19
  }
31
20
  export interface IWebsocketsEventRequestContext {
32
21
  connectionId: string;
package/handler/types.js CHANGED
@@ -1,14 +1,15 @@
1
- export let WebsocketsEventRoute = /*#__PURE__*/function (WebsocketsEventRoute) {
2
- WebsocketsEventRoute["connect"] = "$connect";
3
- WebsocketsEventRoute["disconnect"] = "$disconnect";
4
- WebsocketsEventRoute["default"] = "$default";
5
- return WebsocketsEventRoute;
1
+ var types_WebsocketsEventRoute = /*#__PURE__*/ function(WebsocketsEventRoute) {
2
+ WebsocketsEventRoute["connect"] = "$connect";
3
+ WebsocketsEventRoute["disconnect"] = "$disconnect";
4
+ WebsocketsEventRoute["default"] = "$default";
5
+ return WebsocketsEventRoute;
6
6
  }({});
7
- export let WebsocketsEventRequestContextEventType = /*#__PURE__*/function (WebsocketsEventRequestContextEventType) {
8
- WebsocketsEventRequestContextEventType["message"] = "MESSAGE";
9
- WebsocketsEventRequestContextEventType["connect"] = "CONNECT";
10
- WebsocketsEventRequestContextEventType["disconnect"] = "DISCONNECT";
11
- return WebsocketsEventRequestContextEventType;
7
+ var types_WebsocketsEventRequestContextEventType = /*#__PURE__*/ function(WebsocketsEventRequestContextEventType) {
8
+ WebsocketsEventRequestContextEventType["message"] = "MESSAGE";
9
+ WebsocketsEventRequestContextEventType["connect"] = "CONNECT";
10
+ WebsocketsEventRequestContextEventType["disconnect"] = "DISCONNECT";
11
+ return WebsocketsEventRequestContextEventType;
12
12
  }({});
13
+ export { types_WebsocketsEventRequestContextEventType as WebsocketsEventRequestContextEventType, types_WebsocketsEventRoute as WebsocketsEventRoute };
13
14
 
14
15
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WebsocketsEventRoute","WebsocketsEventRequestContextEventType"],"sources":["types.ts"],"sourcesContent":["import type { HandlerFactoryParams } from \"@webiny/handler-aws/types.js\";\nimport type { IWebsocketsEventValidator } from \"~/validator/index.js\";\nimport type { IWebsocketsResponse } from \"~/response/index.js\";\nimport type {\n APIGatewayProxyResult,\n Context as LambdaContext\n} from \"@webiny/aws-sdk/types/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { PartialDeep } from \"type-fest\";\n\nexport interface HandlerCallable {\n (event: IWebsocketsIncomingEvent, context: LambdaContext): Promise<APIGatewayProxyResult>;\n}\n\nexport interface HandlerParams extends HandlerFactoryParams {\n validator?: IWebsocketsEventValidator;\n response?: IWebsocketsResponse;\n}\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"],"mappings":"AAmBA,WAAYA,oBAAoB,0BAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;AAchC,WAAYC,sCAAsC,0BAAtCA,sCAAsC;EAAtCA,sCAAsC;EAAtCA,sCAAsC;EAAtCA,sCAAsC;EAAA,OAAtCA,sCAAsC;AAAA","ignoreList":[]}
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"}
package/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import "./handler/register.js";
2
- import type { Plugin } from "@webiny/plugins/types.js";
3
- export declare const createWebsockets: () => Plugin[];
4
1
  export * from "./validator/index.js";
5
2
  export * from "./transport/index.js";
6
3
  export * from "./runner/index.js";
7
4
  export * from "./registry/index.js";
8
- export * from "./context/index.js";
9
- export * from "./plugins/index.js";
5
+ export * from "./features/ConnectionRegistry/abstractions.js";
6
+ export { WebsocketsRouteHandler } from "./features/Routes/abstractions.js";
7
+ export type { IWebsocketsRouteHandler, IWebsocketsRouteHandlerParams } from "./features/Routes/abstractions.js";
10
8
  export type * from "./types.js";
9
+ export { WebsocketsFeature } from "./WebsocketsFeature.js";
package/index.js CHANGED
@@ -1,14 +1,7 @@
1
- import "./handler/register.js";
2
- import { createWebsocketsContext } from "./context/index.js";
3
- import { createWebsocketsGraphQL } from "./graphql/index.js";
4
- export const createWebsockets = () => {
5
- return [createWebsocketsContext(), createWebsocketsGraphQL()];
6
- };
7
1
  export * from "./validator/index.js";
8
2
  export * from "./transport/index.js";
9
3
  export * from "./runner/index.js";
10
4
  export * from "./registry/index.js";
11
- export * from "./context/index.js";
12
- export * from "./plugins/index.js";
13
-
14
- //# sourceMappingURL=index.js.map
5
+ export * from "./features/ConnectionRegistry/abstractions.js";
6
+ export { WebsocketsRouteHandler } from "./features/Routes/abstractions.js";
7
+ export { WebsocketsFeature } from "./WebsocketsFeature.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-websockets",
3
- "version": "0.0.0-unstable.e6f0dc8ca7",
3
+ "version": "0.0.0-unstable.e9333b3f0b",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,33 +16,32 @@
16
16
  },
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@webiny/api": "0.0.0-unstable.e6f0dc8ca7",
20
- "@webiny/api-core": "0.0.0-unstable.e6f0dc8ca7",
21
- "@webiny/aws-sdk": "0.0.0-unstable.e6f0dc8ca7",
22
- "@webiny/db-dynamodb": "0.0.0-unstable.e6f0dc8ca7",
23
- "@webiny/error": "0.0.0-unstable.e6f0dc8ca7",
24
- "@webiny/feature": "0.0.0-unstable.e6f0dc8ca7",
25
- "@webiny/handler": "0.0.0-unstable.e6f0dc8ca7",
26
- "@webiny/handler-aws": "0.0.0-unstable.e6f0dc8ca7",
27
- "@webiny/plugins": "0.0.0-unstable.e6f0dc8ca7",
28
- "@webiny/utils": "0.0.0-unstable.e6f0dc8ca7",
29
- "type-fest": "5.6.0",
30
- "zod": "4.4.3"
19
+ "@webiny/api": "0.0.0-unstable.e9333b3f0b",
20
+ "@webiny/api-core": "0.0.0-unstable.e9333b3f0b",
21
+ "@webiny/api-graphql": "0.0.0-unstable.e9333b3f0b",
22
+ "@webiny/error": "0.0.0-unstable.e9333b3f0b",
23
+ "@webiny/feature": "0.0.0-unstable.e9333b3f0b",
24
+ "@webiny/handler": "0.0.0-unstable.e9333b3f0b",
25
+ "type-fest": "5.8.0"
31
26
  },
32
27
  "devDependencies": {
33
- "@webiny/api-headless-cms": "0.0.0-unstable.e6f0dc8ca7",
34
- "@webiny/build-tools": "0.0.0-unstable.e6f0dc8ca7",
35
- "@webiny/handler-db": "0.0.0-unstable.e6f0dc8ca7",
36
- "@webiny/handler-graphql": "0.0.0-unstable.e6f0dc8ca7",
37
- "@webiny/project-utils": "0.0.0-unstable.e6f0dc8ca7",
38
- "graphql": "16.14.0",
28
+ "@webiny/api-core-testing": "0.0.0-unstable.e9333b3f0b",
29
+ "@webiny/api-graphql": "0.0.0-unstable.e9333b3f0b",
30
+ "@webiny/api-headless-cms": "0.0.0-unstable.e9333b3f0b",
31
+ "@webiny/build-tools": "0.0.0-unstable.e9333b3f0b",
32
+ "@webiny/di": "1.1.0",
33
+ "@webiny/event-handler-core": "0.0.0-unstable.e9333b3f0b",
34
+ "@webiny/wcp": "0.0.0-unstable.e9333b3f0b",
35
+ "graphql": "16.14.2",
39
36
  "rimraf": "6.1.3",
40
- "typescript": "6.0.3",
41
- "vitest": "4.1.5"
37
+ "type-fest": "5.8.0",
38
+ "typescript": "7.0.2",
39
+ "vitest": "4.1.11"
42
40
  },
43
41
  "publishConfig": {
44
- "access": "public",
45
- "directory": "dist"
42
+ "access": "public"
46
43
  },
47
- "gitHead": "e6f0dc8ca741c1fcc3fec9a5b9e86fdd49544641"
44
+ "webiny": {
45
+ "publishFrom": "dist"
46
+ }
48
47
  }
@@ -1,2 +1 @@
1
- export type * from "./abstractions/IWebsocketsConnectionRegistry.js";
2
- export * from "./WebsocketsConnectionRegistry.js";
1
+ export type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData, IWebsocketsConnectionRegistryRegisterParams, IWebsocketsConnectionRegistryUnregisterParams } from "../features/ConnectionRegistry/abstractions.js";
package/registry/index.js CHANGED
@@ -1,3 +0,0 @@
1
- export * from "./WebsocketsConnectionRegistry.js";
2
-
3
- //# sourceMappingURL=index.js.map
@@ -1,5 +1,9 @@
1
- import type { IWebsocketsResponse, IWebsocketsResponseErrorParams, IWebsocketsResponseErrorResult, IWebsocketsResponseOkParams, IWebsocketsResponseOkResult } from "./abstractions/IWebsocketsResponse.js";
2
- export declare class WebsocketsResponse implements IWebsocketsResponse {
3
- ok(params?: IWebsocketsResponseOkParams): IWebsocketsResponseOkResult;
4
- error(params: IWebsocketsResponseErrorParams): IWebsocketsResponseErrorResult;
1
+ import { WebsocketsResponse as WebsocketsResponseAbstraction } from "./abstractions/WebsocketsResponse.js";
2
+ declare class WebsocketsResponse implements WebsocketsResponseAbstraction.Interface {
3
+ ok(params?: WebsocketsResponseAbstraction.OkParams): WebsocketsResponseAbstraction.OkResult;
4
+ error(params: WebsocketsResponseAbstraction.ErrorParams): WebsocketsResponseAbstraction.ErrorResult;
5
5
  }
6
+ export declare const DefaultWebsocketsResponse: typeof WebsocketsResponse & {
7
+ __abstraction: import("@webiny/di").Abstraction<import("./index.js").IWebsocketsResponse>;
8
+ };
9
+ export {};
@@ -1,22 +1,28 @@
1
- export class WebsocketsResponse {
2
- ok(params) {
3
- return {
4
- statusCode: 200,
5
- ...params
6
- };
7
- }
8
- error(params) {
9
- return {
10
- ...params,
11
- statusCode: params.statusCode || 200,
12
- error: {
13
- ...params.error,
14
- message: params.error?.message || params.message,
15
- code: params.error?.code || "UNKNOWN_ERROR",
16
- data: params.error?.data || {}
17
- }
18
- };
19
- }
1
+ import { WebsocketsResponse } from "./abstractions/WebsocketsResponse.js";
2
+ class WebsocketsResponse_WebsocketsResponse {
3
+ ok(params) {
4
+ return {
5
+ statusCode: 200,
6
+ ...params
7
+ };
8
+ }
9
+ error(params) {
10
+ return {
11
+ ...params,
12
+ statusCode: params.statusCode || 200,
13
+ error: {
14
+ ...params.error,
15
+ message: params.error?.message || params.message,
16
+ code: params.error?.code || "UNKNOWN_ERROR",
17
+ data: params.error?.data || {}
18
+ }
19
+ };
20
+ }
20
21
  }
22
+ const DefaultWebsocketsResponse = WebsocketsResponse.createImplementation({
23
+ implementation: WebsocketsResponse_WebsocketsResponse,
24
+ dependencies: []
25
+ });
26
+ export { DefaultWebsocketsResponse };
21
27
 
22
28
  //# sourceMappingURL=WebsocketsResponse.js.map