@webiny/api-websockets 6.5.2-beta.0 → 6.5.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/features/Disconnect/DisconnectUseCase.js +3 -0
- package/features/Disconnect/DisconnectUseCase.js.map +1 -1
- package/features/Disconnect/validateDisconnectWhere.d.ts +8 -0
- package/features/Disconnect/validateDisconnectWhere.js +13 -0
- package/features/Disconnect/validateDisconnectWhere.js.map +1 -0
- package/features/shared/errors.d.ts +5 -1
- package/features/shared/errors.js +8 -1
- package/features/shared/errors.js.map +1 -1
- package/graphql/WebsocketsGraphQLFactory.js +77 -29
- package/graphql/WebsocketsGraphQLFactory.js.map +1 -1
- package/package.json +17 -17
- package/runner/routes/connect.js +1 -1
- package/runner/routes/connect.js.map +1 -1
- package/runner/routes/default.js +1 -1
- package/runner/routes/default.js.map +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Result } from "@webiny/feature/api";
|
|
2
2
|
import { WebsocketsDisconnectUseCase } from "./abstractions.js";
|
|
3
3
|
import { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError } from "../shared/errors.js";
|
|
4
|
+
import { validateDisconnectWhere } from "./validateDisconnectWhere.js";
|
|
4
5
|
import { WebsocketsListConnectionsUseCase } from "../ListConnections/abstractions.js";
|
|
5
6
|
import { ConnectionRegistry } from "../ConnectionRegistry/abstractions.js";
|
|
6
7
|
import { WebsocketsTransport } from "../../transport/index.js";
|
|
@@ -11,6 +12,8 @@ class DisconnectUseCaseImpl {
|
|
|
11
12
|
this.transport = transport;
|
|
12
13
|
}
|
|
13
14
|
async execute(params, notify = true) {
|
|
15
|
+
const validationError = validateDisconnectWhere(params?.where);
|
|
16
|
+
if (validationError) return Result.fail(validationError);
|
|
14
17
|
const result = await this.listConnections.execute(params);
|
|
15
18
|
if (result.isFail()) return Result.fail(result.error);
|
|
16
19
|
const connections = result.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/Disconnect/DisconnectUseCase.js","sources":["../../../src/features/Disconnect/DisconnectUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsDisconnectUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectNotificationError } from \"~/features/shared/errors.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\n\nclass DisconnectUseCaseImpl implements WebsocketsDisconnectUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly registry: ConnectionRegistry.Interface,\n private readonly transport: WebsocketsTransport.Interface\n ) {}\n\n public async execute(\n params?: WebsocketsDisconnectUseCase.Params,\n notify = true\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n const result = await this.listConnections.execute(params);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const connections = result.value;\n\n for (const connection of connections) {\n try {\n await this.registry.unregister(connection);\n } catch {\n /* Intentional: failed unregister for one connection must not prevent disconnecting others. */\n }\n }\n\n if (notify) {\n try {\n await this.transport.send(connections, {\n action: \"forcedDisconnect\"\n });\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectNotificationError(error));\n }\n }\n\n try {\n await this.transport.disconnect(connections);\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectError(error));\n }\n\n return Result.ok(connections);\n }\n}\n\nexport const DisconnectUseCase = WebsocketsDisconnectUseCase.createImplementation({\n implementation: DisconnectUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, ConnectionRegistry, WebsocketsTransport]\n});\n"],"names":["DisconnectUseCaseImpl","listConnections","registry","transport","params","notify","
|
|
1
|
+
{"version":3,"file":"features/Disconnect/DisconnectUseCase.js","sources":["../../../src/features/Disconnect/DisconnectUseCase.ts"],"sourcesContent":["import { Result } from \"@webiny/feature/api\";\nimport { WebsocketsDisconnectUseCase } from \"./abstractions.js\";\nimport type { WebsocketsError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectError } from \"~/features/shared/errors.js\";\nimport { WebsocketForceDisconnectNotificationError } from \"~/features/shared/errors.js\";\nimport { validateDisconnectWhere } from \"./validateDisconnectWhere.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsTransport } from \"~/transport/index.js\";\n\nclass DisconnectUseCaseImpl implements WebsocketsDisconnectUseCase.Interface {\n public constructor(\n private readonly listConnections: WebsocketsListConnectionsUseCase.Interface,\n private readonly registry: ConnectionRegistry.Interface,\n private readonly transport: WebsocketsTransport.Interface\n ) {}\n\n public async execute(\n params?: WebsocketsDisconnectUseCase.Params,\n notify = true\n ): Promise<Result<WebsocketsListConnectionsUseCase.RegistryData[], WebsocketsError>> {\n const validationError = validateDisconnectWhere(params?.where);\n if (validationError) {\n return Result.fail(validationError);\n }\n\n const result = await this.listConnections.execute(params);\n if (result.isFail()) {\n return Result.fail(result.error);\n }\n\n const connections = result.value;\n\n for (const connection of connections) {\n try {\n await this.registry.unregister(connection);\n } catch {\n /* Intentional: failed unregister for one connection must not prevent disconnecting others. */\n }\n }\n\n if (notify) {\n try {\n await this.transport.send(connections, {\n action: \"forcedDisconnect\"\n });\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectNotificationError(error));\n }\n }\n\n try {\n await this.transport.disconnect(connections);\n } catch (error) {\n return Result.fail(new WebsocketForceDisconnectError(error));\n }\n\n return Result.ok(connections);\n }\n}\n\nexport const DisconnectUseCase = WebsocketsDisconnectUseCase.createImplementation({\n implementation: DisconnectUseCaseImpl,\n dependencies: [WebsocketsListConnectionsUseCase, ConnectionRegistry, WebsocketsTransport]\n});\n"],"names":["DisconnectUseCaseImpl","listConnections","registry","transport","params","notify","validationError","validateDisconnectWhere","Result","result","connections","connection","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError","DisconnectUseCase","WebsocketsDisconnectUseCase","WebsocketsListConnectionsUseCase","ConnectionRegistry","WebsocketsTransport"],"mappings":";;;;;;;AAUA,MAAMA;IACF,YACqBC,eAA2D,EAC3DC,QAAsC,EACtCC,SAAwC,CAC3D;aAHmBF,eAAe,GAAfA;aACAC,QAAQ,GAARA;aACAC,SAAS,GAATA;IAClB;IAEH,MAAa,QACTC,MAA2C,EAC3CC,SAAS,IAAI,EACoE;QACjF,MAAMC,kBAAkBC,wBAAwBH,QAAQ;QACxD,IAAIE,iBACA,OAAOE,OAAO,IAAI,CAACF;QAGvB,MAAMG,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAACL;QAClD,IAAIK,OAAO,MAAM,IACb,OAAOD,OAAO,IAAI,CAACC,OAAO,KAAK;QAGnC,MAAMC,cAAcD,OAAO,KAAK;QAEhC,KAAK,MAAME,cAAcD,YACrB,IAAI;YACA,MAAM,IAAI,CAAC,QAAQ,CAAC,UAAU,CAACC;QACnC,EAAE,OAAM,CAER;QAGJ,IAAIN,QACA,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAACK,aAAa;gBACnC,QAAQ;YACZ;QACJ,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIK,0CAA0CD;QACrE;QAGJ,IAAI;YACA,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAACF;QACpC,EAAE,OAAOE,OAAO;YACZ,OAAOJ,OAAO,IAAI,CAAC,IAAIM,8BAA8BF;QACzD;QAEA,OAAOJ,OAAO,EAAE,CAACE;IACrB;AACJ;AAEO,MAAMK,oBAAoBC,4BAA4B,oBAAoB,CAAC;IAC9E,gBAAgBhB;IAChB,cAAc;QAACiB;QAAkCC;QAAoBC;KAAoB;AAC7F"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebsocketsValidationError } from "../../features/shared/errors.js";
|
|
2
|
+
import type { WebsocketsListConnectionsUseCase } from "../../features/ListConnections/abstractions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Security: an empty `identityId` / `tenant` / `connections` is falsy in the list use case and
|
|
5
|
+
* would fall through to "list all", turning a targeted disconnect into disconnect-all.
|
|
6
|
+
* Only a call without `where` may disconnect everything.
|
|
7
|
+
*/
|
|
8
|
+
export declare const validateDisconnectWhere: (where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined) => WebsocketsValidationError | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WebsocketsValidationError } from "../shared/errors.js";
|
|
2
|
+
const validateDisconnectWhere = (where)=>{
|
|
3
|
+
if (!where) return null;
|
|
4
|
+
const { identityId, tenant, connections } = where;
|
|
5
|
+
if (void 0 === identityId && void 0 === tenant && void 0 === connections) return new WebsocketsValidationError("Disconnect filter must not be empty.");
|
|
6
|
+
if (void 0 !== identityId && ("string" != typeof identityId || !identityId.trim())) return new WebsocketsValidationError("Identity ID must not be empty.");
|
|
7
|
+
if (void 0 !== tenant && ("string" != typeof tenant || !tenant.trim())) return new WebsocketsValidationError("Tenant must not be empty.");
|
|
8
|
+
if (void 0 !== connections && (!Array.isArray(connections) || 0 === connections.length || connections.some((id)=>"string" != typeof id || !id.trim()))) return new WebsocketsValidationError("Connections must be a non-empty list of IDs.");
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
export { validateDisconnectWhere };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=validateDisconnectWhere.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/Disconnect/validateDisconnectWhere.js","sources":["../../../src/features/Disconnect/validateDisconnectWhere.ts"],"sourcesContent":["import { WebsocketsValidationError } from \"~/features/shared/errors.js\";\nimport type { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\n\n/**\n * Security: an empty `identityId` / `tenant` / `connections` is falsy in the list use case and\n * would fall through to \"list all\", turning a targeted disconnect into disconnect-all.\n * Only a call without `where` may disconnect everything.\n */\nexport const validateDisconnectWhere = (\n where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined\n): WebsocketsValidationError | null => {\n if (!where) {\n return null;\n }\n const { identityId, tenant, connections } = where;\n if (identityId === undefined && tenant === undefined && connections === undefined) {\n return new WebsocketsValidationError(\"Disconnect filter must not be empty.\");\n }\n if (identityId !== undefined && (typeof identityId !== \"string\" || !identityId.trim())) {\n return new WebsocketsValidationError(\"Identity ID must not be empty.\");\n }\n if (tenant !== undefined && (typeof tenant !== \"string\" || !tenant.trim())) {\n return new WebsocketsValidationError(\"Tenant must not be empty.\");\n }\n if (\n connections !== undefined &&\n (!Array.isArray(connections) ||\n connections.length === 0 ||\n connections.some(id => typeof id !== \"string\" || !id.trim()))\n ) {\n return new WebsocketsValidationError(\"Connections must be a non-empty list of IDs.\");\n }\n return null;\n};\n"],"names":["validateDisconnectWhere","where","identityId","tenant","connections","undefined","WebsocketsValidationError","Array","id"],"mappings":";AAQO,MAAMA,0BAA0B,CACnCC;IAEA,IAAI,CAACA,OACD,OAAO;IAEX,MAAM,EAAEC,UAAU,EAAEC,MAAM,EAAEC,WAAW,EAAE,GAAGH;IAC5C,IAAIC,AAAeG,WAAfH,cAA4BC,AAAWE,WAAXF,UAAwBC,AAAgBC,WAAhBD,aACpD,OAAO,IAAIE,0BAA0B;IAEzC,IAAIJ,AAAeG,WAAfH,cAA6B,CAAsB,YAAtB,OAAOA,cAA2B,CAACA,WAAW,IAAI,EAAC,GAChF,OAAO,IAAII,0BAA0B;IAEzC,IAAIH,AAAWE,WAAXF,UAAyB,CAAkB,YAAlB,OAAOA,UAAuB,CAACA,OAAO,IAAI,EAAC,GACpE,OAAO,IAAIG,0BAA0B;IAEzC,IACIF,AAAgBC,WAAhBD,eACC,EAACG,MAAM,OAAO,CAACH,gBACZA,AAAuB,MAAvBA,YAAY,MAAM,IAClBA,YAAY,IAAI,CAACI,CAAAA,KAAM,AAAc,YAAd,OAAOA,MAAmB,CAACA,GAAG,IAAI,GAAE,GAE/D,OAAO,IAAIF,0BAA0B;IAEzC,OAAO;AACX"}
|
|
@@ -17,4 +17,8 @@ export declare class WebsocketForceDisconnectError extends BaseError<{
|
|
|
17
17
|
readonly code: "Websocket/Service/ForceDisconnect";
|
|
18
18
|
constructor(error: Error);
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export declare class WebsocketsValidationError extends BaseError {
|
|
21
|
+
readonly code: "Websocket/Validation";
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export type WebsocketsError = WebsocketsValidationError | WebsocketServiceError | WebsocketForceDisconnectNotificationError | WebsocketForceDisconnectError;
|
|
@@ -29,6 +29,13 @@ class WebsocketForceDisconnectError extends BaseError {
|
|
|
29
29
|
}), this.code = "Websocket/Service/ForceDisconnect";
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
class WebsocketsValidationError extends BaseError {
|
|
33
|
+
constructor(message){
|
|
34
|
+
super({
|
|
35
|
+
message
|
|
36
|
+
}), this.code = "Websocket/Validation";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export { WebsocketForceDisconnectError, WebsocketForceDisconnectNotificationError, WebsocketServiceError, WebsocketsValidationError };
|
|
33
40
|
|
|
34
41
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/shared/errors.js","sources":["../../../src/features/shared/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class WebsocketServiceError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service\" as const;\n\n constructor(error: Error) {\n super({\n message: \"WebsocketService encountered an error.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectNotificationError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnectNotification\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to notify the clients about the forced disconnect.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnect\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to forcefully disconnect the Websocket clients.\",\n data: { error }\n });\n }\n}\n\nexport type WebsocketsError =\n | WebsocketServiceError\n | WebsocketForceDisconnectNotificationError\n | WebsocketForceDisconnectError;\n"],"names":["WebsocketServiceError","BaseError","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError"],"mappings":";AAEO,MAAMA,8BAA8BC;IAGvC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,kDAAkDF;IAG3D,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,sCAAsCH;IAG/C,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ"}
|
|
1
|
+
{"version":3,"file":"features/shared/errors.js","sources":["../../../src/features/shared/errors.ts"],"sourcesContent":["import { BaseError } from \"@webiny/feature/api\";\n\nexport class WebsocketServiceError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service\" as const;\n\n constructor(error: Error) {\n super({\n message: \"WebsocketService encountered an error.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectNotificationError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnectNotification\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to notify the clients about the forced disconnect.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketForceDisconnectError extends BaseError<{ error: Error }> {\n override readonly code = \"Websocket/Service/ForceDisconnect\" as const;\n\n constructor(error: Error) {\n super({\n message: \"Failed to forcefully disconnect the Websocket clients.\",\n data: { error }\n });\n }\n}\n\nexport class WebsocketsValidationError extends BaseError {\n override readonly code = \"Websocket/Validation\" as const;\n\n constructor(message: string) {\n super({\n message\n });\n }\n}\n\nexport type WebsocketsError =\n | WebsocketsValidationError\n | WebsocketServiceError\n | WebsocketForceDisconnectNotificationError\n | WebsocketForceDisconnectError;\n"],"names":["WebsocketServiceError","BaseError","error","WebsocketForceDisconnectNotificationError","WebsocketForceDisconnectError","WebsocketsValidationError","message"],"mappings":";AAEO,MAAMA,8BAA8BC;IAGvC,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMC,kDAAkDF;IAG3D,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAME,sCAAsCH;IAG/C,YAAYC,KAAY,CAAE;QACtB,KAAK,CAAC;YACF,SAAS;YACT,MAAM;gBAAEA;YAAM;QAClB,SANc,IAAI,GAAG;IAOzB;AACJ;AAEO,MAAMG,kCAAkCJ;IAG3C,YAAYK,OAAe,CAAE;QACzB,KAAK,CAAC;YACFA;QACJ,SALc,IAAI,GAAG;IAMzB;AACJ"}
|
|
@@ -2,12 +2,41 @@ import { CoreGraphQLSchemaFactory } from "@webiny/handler-graphql/graphql/abstra
|
|
|
2
2
|
import { ErrorResponse, Response } from "@webiny/handler-graphql/responses.js";
|
|
3
3
|
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
4
|
import { NotAuthorizedError } from "@webiny/api-core/features/security/shared/index.js";
|
|
5
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
5
6
|
import { WebsocketsListConnectionsUseCase } from "../features/ListConnections/abstractions.js";
|
|
6
7
|
import { WebsocketsDisconnectUseCase } from "../features/Disconnect/abstractions.js";
|
|
8
|
+
import { validateDisconnectWhere } from "../features/Disconnect/validateDisconnectWhere.js";
|
|
7
9
|
const checkPermissions = async (identityContext)=>{
|
|
8
10
|
const permissions = await identityContext.getPermissions("websockets");
|
|
9
11
|
if (0 === permissions.length) throw new NotAuthorizedError();
|
|
10
12
|
};
|
|
13
|
+
const canAccessAllTenants = async (scope)=>{
|
|
14
|
+
const tenant = scope.tenantContext.getTenant();
|
|
15
|
+
if ("root" !== tenant.id) return false;
|
|
16
|
+
return scope.identityContext.hasFullAccess();
|
|
17
|
+
};
|
|
18
|
+
const listScopedConnections = async (scope, listConnections, where)=>{
|
|
19
|
+
const result = await listConnections.execute({
|
|
20
|
+
where
|
|
21
|
+
});
|
|
22
|
+
if (result.isFail()) throw result.error;
|
|
23
|
+
if (await canAccessAllTenants(scope)) return result.value;
|
|
24
|
+
const tenantId = scope.tenantContext.getTenant().id;
|
|
25
|
+
return result.value.filter((connection)=>connection.tenant === tenantId);
|
|
26
|
+
};
|
|
27
|
+
const disconnectScopedConnections = async (scope, listConnections, disconnect, where)=>{
|
|
28
|
+
const validationError = validateDisconnectWhere(where);
|
|
29
|
+
if (validationError) throw validationError;
|
|
30
|
+
const connections = await listScopedConnections(scope, listConnections, where);
|
|
31
|
+
if (0 === connections.length) return [];
|
|
32
|
+
const result = await disconnect.execute({
|
|
33
|
+
where: {
|
|
34
|
+
connections: connections.map((connection)=>connection.connectionId)
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
if (result.isFail()) throw result.error;
|
|
38
|
+
return result.value;
|
|
39
|
+
};
|
|
11
40
|
class WebsocketsGraphQL {
|
|
12
41
|
async execute(builder) {
|
|
13
42
|
builder.addTypeDefs(`
|
|
@@ -87,14 +116,17 @@ class WebsocketsGraphQL {
|
|
|
87
116
|
path: "WebsocketsQuery.listConnections",
|
|
88
117
|
dependencies: [
|
|
89
118
|
IdentityContext,
|
|
119
|
+
TenantContext,
|
|
90
120
|
WebsocketsListConnectionsUseCase
|
|
91
121
|
],
|
|
92
|
-
resolver: (identityContext, listConnections)=>async ({ args })=>{
|
|
122
|
+
resolver: (identityContext, tenantContext, listConnections)=>async ({ args })=>{
|
|
93
123
|
try {
|
|
94
124
|
await checkPermissions(identityContext);
|
|
95
|
-
const result = await
|
|
96
|
-
|
|
97
|
-
|
|
125
|
+
const result = await listScopedConnections({
|
|
126
|
+
identityContext,
|
|
127
|
+
tenantContext
|
|
128
|
+
}, listConnections, args.where);
|
|
129
|
+
return new Response(result);
|
|
98
130
|
} catch (ex) {
|
|
99
131
|
return new ErrorResponse(ex);
|
|
100
132
|
}
|
|
@@ -104,18 +136,20 @@ class WebsocketsGraphQL {
|
|
|
104
136
|
path: "WebsocketsMutation.disconnect",
|
|
105
137
|
dependencies: [
|
|
106
138
|
IdentityContext,
|
|
139
|
+
TenantContext,
|
|
140
|
+
WebsocketsListConnectionsUseCase,
|
|
107
141
|
WebsocketsDisconnectUseCase
|
|
108
142
|
],
|
|
109
|
-
resolver: (identityContext, disconnect)=>async ({ args })=>{
|
|
143
|
+
resolver: (identityContext, tenantContext, listConnections, disconnect)=>async ({ args })=>{
|
|
110
144
|
try {
|
|
111
145
|
await checkPermissions(identityContext);
|
|
112
|
-
const result = await
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
146
|
+
const result = await disconnectScopedConnections({
|
|
147
|
+
identityContext,
|
|
148
|
+
tenantContext
|
|
149
|
+
}, listConnections, disconnect, {
|
|
150
|
+
connections: args.connections
|
|
116
151
|
});
|
|
117
|
-
|
|
118
|
-
return new Response(result.value);
|
|
152
|
+
return new Response(result);
|
|
119
153
|
} catch (ex) {
|
|
120
154
|
return new ErrorResponse(ex);
|
|
121
155
|
}
|
|
@@ -125,18 +159,20 @@ class WebsocketsGraphQL {
|
|
|
125
159
|
path: "WebsocketsMutation.disconnectIdentity",
|
|
126
160
|
dependencies: [
|
|
127
161
|
IdentityContext,
|
|
162
|
+
TenantContext,
|
|
163
|
+
WebsocketsListConnectionsUseCase,
|
|
128
164
|
WebsocketsDisconnectUseCase
|
|
129
165
|
],
|
|
130
|
-
resolver: (identityContext, disconnect)=>async ({ args })=>{
|
|
166
|
+
resolver: (identityContext, tenantContext, listConnections, disconnect)=>async ({ args })=>{
|
|
131
167
|
try {
|
|
132
168
|
await checkPermissions(identityContext);
|
|
133
|
-
const result = await
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
169
|
+
const result = await disconnectScopedConnections({
|
|
170
|
+
identityContext,
|
|
171
|
+
tenantContext
|
|
172
|
+
}, listConnections, disconnect, {
|
|
173
|
+
identityId: args.identityId
|
|
137
174
|
});
|
|
138
|
-
|
|
139
|
-
return new Response(result.value);
|
|
175
|
+
return new Response(result);
|
|
140
176
|
} catch (ex) {
|
|
141
177
|
return new ErrorResponse(ex);
|
|
142
178
|
}
|
|
@@ -146,18 +182,26 @@ class WebsocketsGraphQL {
|
|
|
146
182
|
path: "WebsocketsMutation.disconnectTenant",
|
|
147
183
|
dependencies: [
|
|
148
184
|
IdentityContext,
|
|
185
|
+
TenantContext,
|
|
186
|
+
WebsocketsListConnectionsUseCase,
|
|
149
187
|
WebsocketsDisconnectUseCase
|
|
150
188
|
],
|
|
151
|
-
resolver: (identityContext, disconnect)=>async ({ args })=>{
|
|
189
|
+
resolver: (identityContext, tenantContext, listConnections, disconnect)=>async ({ args })=>{
|
|
152
190
|
try {
|
|
153
191
|
await checkPermissions(identityContext);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
192
|
+
const scope = {
|
|
193
|
+
identityContext,
|
|
194
|
+
tenantContext
|
|
195
|
+
};
|
|
196
|
+
const currentTenant = tenantContext.getTenant();
|
|
197
|
+
if (args.tenant !== currentTenant.id && !await canAccessAllTenants(scope)) throw new NotAuthorizedError();
|
|
198
|
+
const result = await disconnectScopedConnections({
|
|
199
|
+
identityContext,
|
|
200
|
+
tenantContext
|
|
201
|
+
}, listConnections, disconnect, {
|
|
202
|
+
tenant: args.tenant
|
|
158
203
|
});
|
|
159
|
-
|
|
160
|
-
return new Response(result.value);
|
|
204
|
+
return new Response(result);
|
|
161
205
|
} catch (ex) {
|
|
162
206
|
return new ErrorResponse(ex);
|
|
163
207
|
}
|
|
@@ -167,14 +211,18 @@ class WebsocketsGraphQL {
|
|
|
167
211
|
path: "WebsocketsMutation.disconnectAll",
|
|
168
212
|
dependencies: [
|
|
169
213
|
IdentityContext,
|
|
214
|
+
TenantContext,
|
|
215
|
+
WebsocketsListConnectionsUseCase,
|
|
170
216
|
WebsocketsDisconnectUseCase
|
|
171
217
|
],
|
|
172
|
-
resolver: (identityContext, disconnect)=>async ()=>{
|
|
218
|
+
resolver: (identityContext, tenantContext, listConnections, disconnect)=>async ()=>{
|
|
173
219
|
try {
|
|
174
220
|
await checkPermissions(identityContext);
|
|
175
|
-
const result = await
|
|
176
|
-
|
|
177
|
-
|
|
221
|
+
const result = await disconnectScopedConnections({
|
|
222
|
+
identityContext,
|
|
223
|
+
tenantContext
|
|
224
|
+
}, listConnections, disconnect, void 0);
|
|
225
|
+
return new Response(result);
|
|
178
226
|
} catch (ex) {
|
|
179
227
|
return new ErrorResponse(ex);
|
|
180
228
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql/WebsocketsGraphQLFactory.js","sources":["../../src/graphql/WebsocketsGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/handler-graphql/features/GraphQLSchemaBuilder/abstractions\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.core.js\";\nimport { ErrorResponse, Response } from \"@webiny/handler-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 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 }) => {\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 }) => {\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 }) => {\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 }) => {\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","WebsocketsGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"graphql/WebsocketsGraphQLFactory.js","sources":["../../src/graphql/WebsocketsGraphQLFactory.ts"],"sourcesContent":["import { GraphQLSchemaBuilder } from \"@webiny/handler-graphql/features/GraphQLSchemaBuilder/abstractions\";\nimport { CoreGraphQLSchemaFactory } from \"@webiny/handler-graphql/graphql/abstractions.core.js\";\nimport { ErrorResponse, Response } from \"@webiny/handler-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 { TenantContext } from \"@webiny/api-core/features/tenancy/TenantContext/index.js\";\nimport { WebsocketsListConnectionsUseCase } from \"~/features/ListConnections/abstractions.js\";\nimport { WebsocketsDisconnectUseCase } from \"~/features/Disconnect/abstractions.js\";\nimport { validateDisconnectWhere } from \"~/features/Disconnect/validateDisconnectWhere.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\ninterface IScope {\n identityContext: IdentityContext.Interface;\n tenantContext: TenantContext.Interface;\n}\n\n/**\n * Only a full-access identity in the root tenant may see and disconnect connections of all\n * tenants. Everyone else is limited to the current tenant's connections.\n */\nconst canAccessAllTenants = async (scope: IScope): Promise<boolean> => {\n const tenant = scope.tenantContext.getTenant();\n if (tenant.id !== \"root\") {\n return false;\n }\n return scope.identityContext.hasFullAccess();\n};\n\nconst listScopedConnections = async (\n scope: IScope,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined\n): Promise<WebsocketsListConnectionsUseCase.RegistryData[]> => {\n const result = await listConnections.execute({ where });\n if (result.isFail()) {\n throw result.error;\n }\n if (await canAccessAllTenants(scope)) {\n return result.value;\n }\n const tenantId = scope.tenantContext.getTenant().id;\n return result.value.filter(connection => connection.tenant === tenantId);\n};\n\nconst disconnectScopedConnections = async (\n scope: IScope,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface,\n where: WebsocketsListConnectionsUseCase.ParamsWhere | undefined\n): Promise<WebsocketsListConnectionsUseCase.RegistryData[]> => {\n // Security: an empty `identityId` / `tenant` / `connections` must not fall through to \"list all\".\n const validationError = validateDisconnectWhere(where);\n if (validationError) {\n throw validationError;\n }\n const connections = await listScopedConnections(scope, listConnections, where);\n if (connections.length === 0) {\n return [];\n }\n const result = await disconnect.execute({\n where: { connections: connections.map(connection => connection.connectionId) }\n });\n if (result.isFail()) {\n throw result.error;\n }\n return result.value;\n};\n\nclass WebsocketsGraphQL implements CoreGraphQLSchemaFactory.Interface {\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, TenantContext, WebsocketsListConnectionsUseCase],\n resolver: (\n identityContext: IdentityContext.Interface,\n tenantContext: TenantContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface\n ) => {\n return async ({ args }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await listScopedConnections(\n { identityContext, tenantContext },\n listConnections,\n args.where\n );\n\n return new Response(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectConnectionsArgs>({\n path: \"WebsocketsMutation.disconnect\",\n dependencies: [\n IdentityContext,\n TenantContext,\n WebsocketsListConnectionsUseCase,\n WebsocketsDisconnectUseCase\n ],\n resolver: (\n identityContext: IdentityContext.Interface,\n tenantContext: TenantContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnectScopedConnections(\n { identityContext, tenantContext },\n listConnections,\n disconnect,\n { connections: args.connections }\n );\n\n return new Response(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectIdentityArgs>({\n path: \"WebsocketsMutation.disconnectIdentity\",\n dependencies: [\n IdentityContext,\n TenantContext,\n WebsocketsListConnectionsUseCase,\n WebsocketsDisconnectUseCase\n ],\n resolver: (\n identityContext: IdentityContext.Interface,\n tenantContext: TenantContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }) => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnectScopedConnections(\n { identityContext, tenantContext },\n listConnections,\n disconnect,\n { identityId: args.identityId }\n );\n\n return new Response(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver<IDisconnectTenantArgs>({\n path: \"WebsocketsMutation.disconnectTenant\",\n dependencies: [\n IdentityContext,\n TenantContext,\n WebsocketsListConnectionsUseCase,\n WebsocketsDisconnectUseCase\n ],\n resolver: (\n identityContext: IdentityContext.Interface,\n tenantContext: TenantContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async ({ args }) => {\n try {\n await checkPermissions(identityContext);\n\n const scope = { identityContext, tenantContext };\n const currentTenant = tenantContext.getTenant();\n if (\n args.tenant !== currentTenant.id &&\n !(await canAccessAllTenants(scope))\n ) {\n throw new NotAuthorizedError();\n }\n\n const result = await disconnectScopedConnections(\n { identityContext, tenantContext },\n listConnections,\n disconnect,\n { tenant: args.tenant }\n );\n\n return new Response(result);\n } catch (ex) {\n return new ErrorResponse(ex);\n }\n };\n }\n });\n\n builder.addResolver({\n path: \"WebsocketsMutation.disconnectAll\",\n dependencies: [\n IdentityContext,\n TenantContext,\n WebsocketsListConnectionsUseCase,\n WebsocketsDisconnectUseCase\n ],\n resolver: (\n identityContext: IdentityContext.Interface,\n tenantContext: TenantContext.Interface,\n listConnections: WebsocketsListConnectionsUseCase.Interface,\n disconnect: WebsocketsDisconnectUseCase.Interface\n ) => {\n return async () => {\n try {\n await checkPermissions(identityContext);\n\n const result = await disconnectScopedConnections(\n { identityContext, tenantContext },\n listConnections,\n disconnect,\n undefined\n );\n\n return new Response(result);\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","canAccessAllTenants","scope","tenant","listScopedConnections","listConnections","where","result","tenantId","connection","disconnectScopedConnections","disconnect","validationError","validateDisconnectWhere","connections","WebsocketsGraphQL","builder","IdentityContext","TenantContext","WebsocketsListConnectionsUseCase","tenantContext","args","Response","ex","ErrorResponse","WebsocketsDisconnectUseCase","currentTenant","undefined","WebsocketsGraphQLFactory","CoreGraphQLSchemaFactory"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-websockets",
|
|
3
|
-
"version": "6.5.2-beta.
|
|
3
|
+
"version": "6.5.2-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,26 +16,26 @@
|
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@webiny/api": "6.5.2-beta.
|
|
20
|
-
"@webiny/api-core": "6.5.2-beta.
|
|
21
|
-
"@webiny/error": "6.5.2-beta.
|
|
22
|
-
"@webiny/feature": "6.5.2-beta.
|
|
23
|
-
"@webiny/handler": "6.5.2-beta.
|
|
24
|
-
"@webiny/plugins": "6.5.2-beta.
|
|
19
|
+
"@webiny/api": "6.5.2-beta.2",
|
|
20
|
+
"@webiny/api-core": "6.5.2-beta.2",
|
|
21
|
+
"@webiny/error": "6.5.2-beta.2",
|
|
22
|
+
"@webiny/feature": "6.5.2-beta.2",
|
|
23
|
+
"@webiny/handler": "6.5.2-beta.2",
|
|
24
|
+
"@webiny/plugins": "6.5.2-beta.2"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@webiny/api-headless-cms": "6.5.2-beta.
|
|
28
|
-
"@webiny/aws-sdk": "6.5.2-beta.
|
|
29
|
-
"@webiny/build-tools": "6.5.2-beta.
|
|
30
|
-
"@webiny/handler-aws": "6.5.2-beta.
|
|
31
|
-
"@webiny/handler-db": "6.5.2-beta.
|
|
32
|
-
"@webiny/handler-graphql": "6.5.2-beta.
|
|
33
|
-
"@webiny/project-utils": "6.5.2-beta.
|
|
34
|
-
"graphql": "16.
|
|
35
|
-
"rimraf": "6.1.
|
|
27
|
+
"@webiny/api-headless-cms": "6.5.2-beta.2",
|
|
28
|
+
"@webiny/aws-sdk": "6.5.2-beta.2",
|
|
29
|
+
"@webiny/build-tools": "6.5.2-beta.2",
|
|
30
|
+
"@webiny/handler-aws": "6.5.2-beta.2",
|
|
31
|
+
"@webiny/handler-db": "6.5.2-beta.2",
|
|
32
|
+
"@webiny/handler-graphql": "6.5.2-beta.2",
|
|
33
|
+
"@webiny/project-utils": "6.5.2-beta.2",
|
|
34
|
+
"graphql": "16.15.0",
|
|
35
|
+
"rimraf": "6.1.4",
|
|
36
36
|
"type-fest": "5.10.0",
|
|
37
37
|
"typescript": "7.0.2",
|
|
38
|
-
"vitest": "5.0
|
|
38
|
+
"vitest": "5.1.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
package/runner/routes/connect.js
CHANGED
|
@@ -12,7 +12,7 @@ const createWebsocketsRouteConnectPlugin = ()=>{
|
|
|
12
12
|
if (!tenant) return response.error({
|
|
13
13
|
message: "Missing tenant."
|
|
14
14
|
});
|
|
15
|
-
else if (!identity) return response.error({
|
|
15
|
+
else if (!identity?.id) return response.error({
|
|
16
16
|
message: "Missing identity."
|
|
17
17
|
});
|
|
18
18
|
await registry.register({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner/routes/connect.js","sources":["../../../src/runner/routes/connect.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport { createWebsocketsRoutePlugin } from \"~/plugins/WebsocketsRoutePlugin.js\";\n\nconst CONNECT: WebsocketsRoute = \"connect\";\n\nconst getConnectedOn = (connectedAt?: number) => {\n if (!connectedAt) {\n return new Date().toISOString();\n }\n return new Date(connectedAt).toISOString();\n};\n\nexport const createWebsocketsRouteConnectPlugin = () => {\n const plugin = createWebsocketsRoutePlugin(CONNECT, async params => {\n const { registry, event, response, getTenant, getIdentity } = params;\n\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n await registry.register({\n identity: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n connectionId: event.context.connectionId,\n tenant,\n endpoint: event.context.endpoint,\n connectedOn: getConnectedOn(event.context.connectedAt)\n });\n\n return response.ok();\n });\n plugin.name = \"websockets.route.connect.default\";\n return plugin;\n};\n"],"names":["CONNECT","getConnectedOn","connectedAt","Date","createWebsocketsRouteConnectPlugin","plugin","createWebsocketsRoutePlugin","params","registry","event","response","getTenant","getIdentity","tenant","identity"],"mappings":";AAGA,MAAMA,UAA2B;AAEjC,MAAMC,iBAAiB,CAACC;IACpB,IAAI,CAACA,aACD,OAAO,IAAIC,OAAO,WAAW;IAEjC,OAAO,IAAIA,KAAKD,aAAa,WAAW;AAC5C;AAEO,MAAME,qCAAqC;IAC9C,MAAMC,SAASC,4BAA4BN,SAAS,OAAMO;QACtD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,WAAW,EAAE,GAAGL;QAE9D,MAAMM,SAASF;QACf,MAAMG,WAAWF;QACjB,IAAI,CAACC,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;aACG,IAAI,CAACI,
|
|
1
|
+
{"version":3,"file":"runner/routes/connect.js","sources":["../../../src/runner/routes/connect.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport { createWebsocketsRoutePlugin } from \"~/plugins/WebsocketsRoutePlugin.js\";\n\nconst CONNECT: WebsocketsRoute = \"connect\";\n\nconst getConnectedOn = (connectedAt?: number) => {\n if (!connectedAt) {\n return new Date().toISOString();\n }\n return new Date(connectedAt).toISOString();\n};\n\nexport const createWebsocketsRouteConnectPlugin = () => {\n const plugin = createWebsocketsRoutePlugin(CONNECT, async params => {\n const { registry, event, response, getTenant, getIdentity } = params;\n\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity?.id) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n await registry.register({\n identity: {\n id: identity.id,\n displayName: identity.displayName,\n type: identity.type\n },\n connectionId: event.context.connectionId,\n tenant,\n endpoint: event.context.endpoint,\n connectedOn: getConnectedOn(event.context.connectedAt)\n });\n\n return response.ok();\n });\n plugin.name = \"websockets.route.connect.default\";\n return plugin;\n};\n"],"names":["CONNECT","getConnectedOn","connectedAt","Date","createWebsocketsRouteConnectPlugin","plugin","createWebsocketsRoutePlugin","params","registry","event","response","getTenant","getIdentity","tenant","identity"],"mappings":";AAGA,MAAMA,UAA2B;AAEjC,MAAMC,iBAAiB,CAACC;IACpB,IAAI,CAACA,aACD,OAAO,IAAIC,OAAO,WAAW;IAEjC,OAAO,IAAIA,KAAKD,aAAa,WAAW;AAC5C;AAEO,MAAME,qCAAqC;IAC9C,MAAMC,SAASC,4BAA4BN,SAAS,OAAMO;QACtD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,WAAW,EAAE,GAAGL;QAE9D,MAAMM,SAASF;QACf,MAAMG,WAAWF;QACjB,IAAI,CAACC,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;aACG,IAAI,CAACI,UAAU,IAClB,OAAOJ,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QAGJ,MAAMF,SAAS,QAAQ,CAAC;YACpB,UAAU;gBACN,IAAIM,SAAS,EAAE;gBACf,aAAaA,SAAS,WAAW;gBACjC,MAAMA,SAAS,IAAI;YACvB;YACA,cAAcL,MAAM,OAAO,CAAC,YAAY;YACxCI;YACA,UAAUJ,MAAM,OAAO,CAAC,QAAQ;YAChC,aAAaR,eAAeQ,MAAM,OAAO,CAAC,WAAW;QACzD;QAEA,OAAOC,SAAS,EAAE;IACtB;IACAL,OAAO,IAAI,GAAG;IACd,OAAOA;AACX"}
|
package/runner/routes/default.js
CHANGED
|
@@ -8,7 +8,7 @@ const createWebsocketsRouteDefaultPlugin = ()=>{
|
|
|
8
8
|
if (!tenant) return response.error({
|
|
9
9
|
message: "Missing tenant."
|
|
10
10
|
});
|
|
11
|
-
else if (!identity) return response.error({
|
|
11
|
+
else if (!identity?.id) return response.error({
|
|
12
12
|
message: "Missing identity."
|
|
13
13
|
});
|
|
14
14
|
return response.ok();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner/routes/default.js","sources":["../../../src/runner/routes/default.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport { createWebsocketsRoutePlugin } from \"~/plugins/WebsocketsRoutePlugin.js\";\n\nconst DEFAULT: WebsocketsRoute = \"default\";\n\nexport const createWebsocketsRouteDefaultPlugin = () => {\n const plugin = createWebsocketsRoutePlugin(DEFAULT, async params => {\n const { response, getIdentity, getTenant } = params;\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n return response.ok();\n });\n\n plugin.name = \"websockets.route.default.default\";\n return plugin;\n};\n"],"names":["DEFAULT","createWebsocketsRouteDefaultPlugin","plugin","createWebsocketsRoutePlugin","params","response","getIdentity","getTenant","tenant","identity"],"mappings":";AAGA,MAAMA,UAA2B;AAE1B,MAAMC,qCAAqC;IAC9C,MAAMC,SAASC,4BAA4BH,SAAS,OAAMI;QACtD,MAAM,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGH;QAC7C,MAAMI,SAASD;QACf,MAAME,WAAWH;QACjB,IAAI,CAACE,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;aACG,IAAI,CAACI,
|
|
1
|
+
{"version":3,"file":"runner/routes/default.js","sources":["../../../src/runner/routes/default.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport { createWebsocketsRoutePlugin } from \"~/plugins/WebsocketsRoutePlugin.js\";\n\nconst DEFAULT: WebsocketsRoute = \"default\";\n\nexport const createWebsocketsRouteDefaultPlugin = () => {\n const plugin = createWebsocketsRoutePlugin(DEFAULT, async params => {\n const { response, getIdentity, getTenant } = params;\n const tenant = getTenant();\n const identity = getIdentity();\n if (!tenant) {\n return response.error({\n message: \"Missing tenant.\"\n });\n } else if (!identity?.id) {\n return response.error({\n message: \"Missing identity.\"\n });\n }\n\n return response.ok();\n });\n\n plugin.name = \"websockets.route.default.default\";\n return plugin;\n};\n"],"names":["DEFAULT","createWebsocketsRouteDefaultPlugin","plugin","createWebsocketsRoutePlugin","params","response","getIdentity","getTenant","tenant","identity"],"mappings":";AAGA,MAAMA,UAA2B;AAE1B,MAAMC,qCAAqC;IAC9C,MAAMC,SAASC,4BAA4BH,SAAS,OAAMI;QACtD,MAAM,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGH;QAC7C,MAAMI,SAASD;QACf,MAAME,WAAWH;QACjB,IAAI,CAACE,QACD,OAAOH,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;aACG,IAAI,CAACI,UAAU,IAClB,OAAOJ,SAAS,KAAK,CAAC;YAClB,SAAS;QACb;QAGJ,OAAOA,SAAS,EAAE;IACtB;IAEAH,OAAO,IAAI,GAAG;IACd,OAAOA;AACX"}
|