@webiny/api-websockets 0.0.0-unstable.9bd236cf5e → 0.0.0-unstable.9f53ea597d
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/README.md +10 -9
- package/exports/api.d.ts +12 -0
- package/exports/api.js +11 -0
- package/{registry/abstractions/IWebsocketsConnectionRegistry.d.ts → features/ConnectionRegistry/abstractions.d.ts} +14 -11
- package/features/ConnectionRegistry/abstractions.js +5 -0
- package/features/ConnectionRegistry/abstractions.js.map +1 -0
- package/features/Disconnect/DisconnectUseCase.d.ts +17 -0
- package/features/Disconnect/DisconnectUseCase.js +45 -0
- package/features/Disconnect/DisconnectUseCase.js.map +1 -0
- package/features/Disconnect/abstractions.d.ts +13 -0
- package/features/Disconnect/abstractions.js +5 -0
- package/features/Disconnect/abstractions.js.map +1 -0
- package/features/ListConnections/ListConnectionsUseCase.d.ts +13 -0
- package/features/ListConnections/ListConnectionsUseCase.js +30 -0
- package/features/ListConnections/ListConnectionsUseCase.js.map +1 -0
- package/features/ListConnections/abstractions.d.ts +21 -0
- package/features/ListConnections/abstractions.js +5 -0
- package/features/ListConnections/abstractions.js.map +1 -0
- package/features/SendToConnections/SendToConnectionsUseCase.d.ts +14 -0
- package/features/SendToConnections/SendToConnectionsUseCase.js +26 -0
- package/features/SendToConnections/SendToConnectionsUseCase.js.map +1 -0
- package/features/SendToConnections/abstractions.d.ts +14 -0
- package/features/SendToConnections/abstractions.js +5 -0
- package/features/SendToConnections/abstractions.js.map +1 -0
- package/features/SendToIdentity/SendToIdentityUseCase.d.ts +16 -0
- package/features/SendToIdentity/SendToIdentityUseCase.js +35 -0
- package/features/SendToIdentity/SendToIdentityUseCase.js.map +1 -0
- package/features/SendToIdentity/abstractions.d.ts +14 -0
- package/features/SendToIdentity/abstractions.js +5 -0
- package/features/SendToIdentity/abstractions.js.map +1 -0
- package/features/feature.d.ts +4 -0
- package/features/feature.js +21 -0
- package/features/feature.js.map +1 -0
- package/features/shared/errors.d.ts +20 -0
- package/features/shared/errors.js +34 -0
- package/features/shared/errors.js.map +1 -0
- package/graphql/WebsocketsGraphQLFactory.d.ts +9 -0
- package/graphql/WebsocketsGraphQLFactory.js +192 -0
- package/graphql/WebsocketsGraphQLFactory.js.map +1 -0
- package/graphql/feature.d.ts +4 -0
- package/graphql/feature.js +11 -0
- package/graphql/feature.js.map +1 -0
- package/graphql/index.d.ts +1 -2
- package/graphql/index.js +1 -20
- package/index.d.ts +1 -9
- package/index.js +13 -98
- package/index.js.map +1 -1
- package/package.json +28 -30
- package/plugins/WebsocketsActionPlugin.d.ts +2 -2
- package/plugins/WebsocketsActionPlugin.js +15 -22
- package/plugins/WebsocketsActionPlugin.js.map +1 -1
- package/plugins/WebsocketsRoutePlugin.d.ts +11 -13
- package/plugins/WebsocketsRoutePlugin.js +15 -22
- package/plugins/WebsocketsRoutePlugin.js.map +1 -1
- package/plugins/abstrations/{IWebsocketsActionPlugin.d.ts → WebsocketsActionPlugin.d.ts} +2 -3
- package/plugins/abstrations/WebsocketsActionPlugin.js +0 -0
- package/plugins/index.d.ts +3 -3
- package/plugins/index.js +2 -40
- package/registry/index.d.ts +1 -2
- package/registry/index.js +0 -29
- package/response/WebsocketsResponse.d.ts +8 -4
- package/response/WebsocketsResponse.js +25 -26
- package/response/WebsocketsResponse.js.map +1 -1
- package/response/abstractions/{IWebsocketsResponse.d.ts → WebsocketsResponse.d.ts} +10 -1
- package/response/abstractions/WebsocketsResponse.js +5 -0
- package/response/abstractions/WebsocketsResponse.js.map +1 -0
- package/response/index.d.ts +5 -2
- package/response/index.js +2 -29
- package/runner/WebsocketsRunner.d.ts +15 -9
- package/runner/WebsocketsRunner.js +109 -179
- package/runner/WebsocketsRunner.js.map +1 -1
- package/runner/abstractions/{IWebsocketsRunner.d.ts → WebsocketsRunner.d.ts} +3 -3
- package/runner/abstractions/WebsocketsRunner.js +0 -0
- package/runner/index.d.ts +3 -2
- package/runner/index.js +2 -29
- package/runner/routes/connect.d.ts +1 -1
- package/runner/routes/connect.js +31 -52
- package/runner/routes/connect.js.map +1 -1
- package/runner/routes/default.d.ts +1 -1
- package/runner/routes/default.js +18 -37
- package/runner/routes/default.js.map +1 -1
- package/runner/routes/disconnect.d.ts +1 -1
- package/runner/routes/disconnect.js +12 -22
- package/runner/routes/disconnect.js.map +1 -1
- package/runner/routes/index.d.ts +1 -1
- package/runner/routes/index.js +9 -13
- package/runner/routes/index.js.map +1 -1
- package/transport/NullWebsocketsTransport.d.ts +9 -0
- package/transport/NullWebsocketsTransport.js +12 -0
- package/transport/NullWebsocketsTransport.js.map +1 -0
- package/transport/abstractions/WebsocketsTransport.d.ts +32 -0
- package/transport/abstractions/WebsocketsTransport.js +5 -0
- package/transport/abstractions/WebsocketsTransport.js.map +1 -0
- package/transport/index.d.ts +1 -2
- package/transport/index.js +1 -29
- package/types.d.ts +29 -7
- package/types.js +0 -7
- package/utils/middleware.d.ts +1 -1
- package/utils/middleware.js +9 -21
- package/utils/middleware.js.map +1 -1
- package/validator/abstractions/WebsocketsEventValidator.d.ts +8 -0
- package/validator/abstractions/WebsocketsEventValidator.js +5 -0
- package/validator/abstractions/WebsocketsEventValidator.js.map +1 -0
- package/validator/index.d.ts +2 -2
- package/validator/index.js +1 -29
- package/context/WebsocketsContext.d.ts +0 -13
- package/context/WebsocketsContext.js +0 -70
- package/context/WebsocketsContext.js.map +0 -1
- package/context/abstractions/IWebsocketsContext.d.ts +0 -22
- package/context/abstractions/IWebsocketsContext.js +0 -7
- package/context/abstractions/IWebsocketsContext.js.map +0 -1
- package/context/index.d.ts +0 -5
- package/context/index.js +0 -53
- package/context/index.js.map +0 -1
- package/graphql/checkPermissions.d.ts +0 -7
- package/graphql/checkPermissions.js +0 -21
- package/graphql/checkPermissions.js.map +0 -1
- package/graphql/createResolvers.d.ts +0 -13
- package/graphql/createResolvers.js +0 -68
- package/graphql/createResolvers.js.map +0 -1
- package/graphql/createTypeDefs.d.ts +0 -1
- package/graphql/createTypeDefs.js +0 -78
- package/graphql/createTypeDefs.js.map +0 -1
- package/graphql/index.js.map +0 -1
- package/graphql/utils.d.ts +0 -7
- package/graphql/utils.js +0 -19
- package/graphql/utils.js.map +0 -1
- package/handler/handler.d.ts +0 -2
- package/handler/handler.js +0 -84
- package/handler/handler.js.map +0 -1
- package/handler/headers.d.ts +0 -7
- package/handler/headers.js +0 -46
- package/handler/headers.js.map +0 -1
- package/handler/register.d.ts +0 -1
- package/handler/register.js +0 -28
- package/handler/register.js.map +0 -1
- package/handler/types.d.ts +0 -73
- package/handler/types.js +0 -20
- package/handler/types.js.map +0 -1
- package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -7
- package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/registry/WebsocketsConnectionRegistry.d.ts +0 -23
- package/registry/WebsocketsConnectionRegistry.js +0 -182
- package/registry/WebsocketsConnectionRegistry.js.map +0 -1
- package/registry/abstractions/IWebsocketsConnectionRegistry.js +0 -7
- package/registry/abstractions/IWebsocketsConnectionRegistry.js.map +0 -1
- package/registry/entity.d.ts +0 -108
- package/registry/entity.js +0 -62
- package/registry/entity.js.map +0 -1
- package/registry/index.js.map +0 -1
- package/response/abstractions/IWebsocketsResponse.js +0 -7
- package/response/abstractions/IWebsocketsResponse.js.map +0 -1
- package/response/index.js.map +0 -1
- package/runner/abstractions/IWebsocketsRunner.js +0 -7
- package/runner/abstractions/IWebsocketsRunner.js.map +0 -1
- package/runner/index.js.map +0 -1
- package/transport/WebsocketsTransport.d.ts +0 -8
- package/transport/WebsocketsTransport.js +0 -54
- package/transport/WebsocketsTransport.js.map +0 -1
- package/transport/abstractions/IWebsocketsTransport.d.ts +0 -20
- package/transport/abstractions/IWebsocketsTransport.js +0 -7
- package/transport/abstractions/IWebsocketsTransport.js.map +0 -1
- package/transport/index.js.map +0 -1
- package/types.js.map +0 -1
- package/validator/WebsocketsEventValidator.d.ts +0 -5
- package/validator/WebsocketsEventValidator.js +0 -85
- package/validator/WebsocketsEventValidator.js.map +0 -1
- package/validator/abstractions/IWebsocketsEventValidator.d.ts +0 -8
- package/validator/abstractions/IWebsocketsEventValidator.js +0 -7
- package/validator/abstractions/IWebsocketsEventValidator.js.map +0 -1
- package/validator/index.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/WebsocketsRoutePlugin.js","sources":["../../src/plugins/WebsocketsRoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\nimport type { IWebsocketsRunnerResponse } from \"~/runner/index.js\";\nimport { ConnectionRegistry } from \"~/features/ConnectionRegistry/abstractions.js\";\nimport { WebsocketsResponse } from \"~/response/index.js\";\nimport type { IWebsocketsEvent, IWebsocketsEventData, WebsocketsRoute } from \"~/types.js\";\n\nexport interface IWebsocketsRoutePluginCallableParams<\n C extends Context = Context,\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n event: IWebsocketsEvent<T>;\n registry: ConnectionRegistry.Interface;\n context: C;\n response: WebsocketsResponse.Interface;\n getTenant: () => string | null;\n getIdentity: () => ConnectionRegistry.Identity | null;\n next: () => Promise<R>;\n}\n\nexport interface IWebsocketsRoutePluginCallable<\n C extends Context = Context,\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> {\n (params: IWebsocketsRoutePluginCallableParams<C, R, T>): Promise<R>;\n}\n\nexport class WebsocketsRoutePlugin<\n C extends Context = Context,\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n> extends Plugin {\n public static override readonly type: string = \"websockets.route\";\n\n public readonly route: WebsocketsRoute | string;\n private readonly cb: IWebsocketsRoutePluginCallable<C, R, T>;\n\n public constructor(\n route: WebsocketsRoute | string,\n cb: IWebsocketsRoutePluginCallable<C, R, T>\n ) {\n super();\n this.route = route;\n this.cb = cb;\n }\n\n public async run(params: IWebsocketsRoutePluginCallableParams<C, R, T>): Promise<R> {\n return this.cb(params);\n }\n}\n\nexport const createWebsocketsRoutePlugin = <\n C extends Context = Context,\n R extends IWebsocketsRunnerResponse = IWebsocketsRunnerResponse,\n T extends IWebsocketsEventData = IWebsocketsEventData\n>(\n route: WebsocketsRoute | string,\n cb: IWebsocketsRoutePluginCallable<C, R, T>\n) => {\n return new WebsocketsRoutePlugin<C, R, T>(route, cb);\n};\n"],"names":["WebsocketsRoutePlugin","Plugin","route","cb","params","createWebsocketsRoutePlugin"],"mappings":";AA6BO,MAAMA,8BAIHC;;aAC0B,IAAI,GAAW;;IAK/C,YACIC,KAA+B,EAC/BC,EAA2C,CAC7C;QACE,KAAK;QACL,IAAI,CAAC,KAAK,GAAGD;QACb,IAAI,CAAC,EAAE,GAAGC;IACd;IAEA,MAAa,IAAIC,MAAqD,EAAc;QAChF,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAEO,MAAMC,8BAA8B,CAKvCH,OACAC,KAEO,IAAIH,sBAA+BE,OAAOC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
2
|
-
import type { Context } from "../../types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
import type { Context } from "../../types.js";
|
|
3
3
|
export interface IWebsocketsActionPluginCallableParamsSend {
|
|
4
4
|
toConnection<T extends GenericRecord = GenericRecord>(connectionId: string, data: T): Promise<void>;
|
|
5
5
|
toTenant<T extends GenericRecord = GenericRecord>(tenant: string, data: T): Promise<void>;
|
|
6
|
-
toTenantAndLocale<T extends GenericRecord = GenericRecord>(tenant: string, locale: string, data: T): Promise<void>;
|
|
7
6
|
toIdentity<T extends GenericRecord = GenericRecord>(identity: string, data: T): Promise<void>;
|
|
8
7
|
}
|
|
9
8
|
export interface IWebsocketsActionPluginCallableParamsRespondError<T extends GenericRecord = GenericRecord> {
|
|
File without changes
|
package/plugins/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./WebsocketsRoutePlugin";
|
|
2
|
-
export * from "./WebsocketsActionPlugin";
|
|
3
|
-
export * from "./abstrations/
|
|
1
|
+
export * from "./WebsocketsRoutePlugin.js";
|
|
2
|
+
export * from "./WebsocketsActionPlugin.js";
|
|
3
|
+
export type * from "./abstrations/WebsocketsActionPlugin.js";
|
package/plugins/index.js
CHANGED
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _WebsocketsRoutePlugin = require("./WebsocketsRoutePlugin");
|
|
7
|
-
Object.keys(_WebsocketsRoutePlugin).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _WebsocketsRoutePlugin[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _WebsocketsRoutePlugin[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _WebsocketsActionPlugin = require("./WebsocketsActionPlugin");
|
|
18
|
-
Object.keys(_WebsocketsActionPlugin).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _WebsocketsActionPlugin[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _WebsocketsActionPlugin[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
var _IWebsocketsActionPlugin = require("./abstrations/IWebsocketsActionPlugin");
|
|
29
|
-
Object.keys(_IWebsocketsActionPlugin).forEach(function (key) {
|
|
30
|
-
if (key === "default" || key === "__esModule") return;
|
|
31
|
-
if (key in exports && exports[key] === _IWebsocketsActionPlugin[key]) return;
|
|
32
|
-
Object.defineProperty(exports, key, {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return _IWebsocketsActionPlugin[key];
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from "./WebsocketsRoutePlugin.js";
|
|
2
|
+
export * from "./WebsocketsActionPlugin.js";
|
package/registry/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./WebsocketsConnectionRegistry";
|
|
1
|
+
export type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData, IWebsocketsConnectionRegistryRegisterParams, IWebsocketsConnectionRegistryUnregisterParams } from "../features/ConnectionRegistry/abstractions.js";
|
package/registry/index.js
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _IWebsocketsConnectionRegistry = require("./abstractions/IWebsocketsConnectionRegistry");
|
|
7
|
-
Object.keys(_IWebsocketsConnectionRegistry).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _IWebsocketsConnectionRegistry[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _IWebsocketsConnectionRegistry[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _WebsocketsConnectionRegistry = require("./WebsocketsConnectionRegistry");
|
|
18
|
-
Object.keys(_WebsocketsConnectionRegistry).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _WebsocketsConnectionRegistry[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _WebsocketsConnectionRegistry[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
ok(params?:
|
|
4
|
-
error(params:
|
|
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,29 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
code: params.error?.code || "UNKNOWN_ERROR",
|
|
22
|
-
data: params.error?.data || {}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
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
|
+
}
|
|
26
21
|
}
|
|
27
|
-
|
|
22
|
+
const DefaultWebsocketsResponse = WebsocketsResponse.createImplementation({
|
|
23
|
+
implementation: WebsocketsResponse_WebsocketsResponse,
|
|
24
|
+
dependencies: []
|
|
25
|
+
});
|
|
26
|
+
export { DefaultWebsocketsResponse };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=WebsocketsResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"response/WebsocketsResponse.js","sources":["../../src/response/WebsocketsResponse.ts"],"sourcesContent":["import { WebsocketsResponse as WebsocketsResponseAbstraction } from \"./abstractions/WebsocketsResponse.js\";\n\nclass WebsocketsResponse implements WebsocketsResponseAbstraction.Interface {\n public ok(\n params?: WebsocketsResponseAbstraction.OkParams\n ): WebsocketsResponseAbstraction.OkResult {\n return {\n statusCode: 200,\n ...params\n };\n }\n\n public error(\n params: WebsocketsResponseAbstraction.ErrorParams\n ): WebsocketsResponseAbstraction.ErrorResult {\n return {\n ...params,\n statusCode: params.statusCode || 200,\n error: {\n ...params.error,\n message: params.error?.message || params.message,\n code: params.error?.code || \"UNKNOWN_ERROR\",\n data: params.error?.data || {}\n }\n };\n }\n}\n\nexport const DefaultWebsocketsResponse = WebsocketsResponseAbstraction.createImplementation({\n implementation: WebsocketsResponse,\n dependencies: []\n});\n"],"names":["WebsocketsResponse","params","DefaultWebsocketsResponse","WebsocketsResponseAbstraction"],"mappings":";AAEA,MAAMA;IACK,GACHC,MAA+C,EACT;QACtC,OAAO;YACH,YAAY;YACZ,GAAGA,MAAM;QACb;IACJ;IAEO,MACHA,MAAiD,EACR;QACzC,OAAO;YACH,GAAGA,MAAM;YACT,YAAYA,OAAO,UAAU,IAAI;YACjC,OAAO;gBACH,GAAGA,OAAO,KAAK;gBACf,SAASA,OAAO,KAAK,EAAE,WAAWA,OAAO,OAAO;gBAChD,MAAMA,OAAO,KAAK,EAAE,QAAQ;gBAC5B,MAAMA,OAAO,KAAK,EAAE,QAAQ,CAAC;YACjC;QACJ;IACJ;AACJ;AAEO,MAAMC,4BAA4BC,mBAAAA,oBAAkD,CAAC;IACxF,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
2
|
export interface IWebsocketsResponseOkParams {
|
|
3
3
|
message?: string;
|
|
4
4
|
data?: GenericRecord<string>;
|
|
@@ -27,3 +27,12 @@ export interface IWebsocketsResponse {
|
|
|
27
27
|
ok(params?: IWebsocketsResponseOkParams): IWebsocketsResponseOkResult;
|
|
28
28
|
error(params: IWebsocketsResponseErrorParams): IWebsocketsResponseErrorResult;
|
|
29
29
|
}
|
|
30
|
+
export declare const WebsocketsResponse: import("@webiny/di").Abstraction<IWebsocketsResponse>;
|
|
31
|
+
export declare namespace WebsocketsResponse {
|
|
32
|
+
type Interface = IWebsocketsResponse;
|
|
33
|
+
type OkParams = IWebsocketsResponseOkParams;
|
|
34
|
+
type OkResult = IWebsocketsResponseOkResult;
|
|
35
|
+
type ErrorParams = IWebsocketsResponseErrorParams;
|
|
36
|
+
type ErrorResult = IWebsocketsResponseErrorResult;
|
|
37
|
+
type ErrorResultError = IWebsocketsResponseErrorResultError;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response/abstractions/WebsocketsResponse.js","sources":["../../../src/response/abstractions/WebsocketsResponse.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IWebsocketsResponseOkParams {\n message?: string;\n data?: GenericRecord<string>;\n}\n\nexport interface IWebsocketsResponseOkResult {\n statusCode: number;\n data?: GenericRecord<string>;\n message?: string;\n}\n\nexport interface IWebsocketsResponseErrorParams {\n statusCode?: number;\n error?: Omit<IWebsocketsResponseErrorResultError, \"data\"> &\n Partial<Pick<IWebsocketsResponseErrorResultError, \"data\">>;\n message: string;\n}\n\nexport interface IWebsocketsResponseErrorResultError {\n message: string;\n code: string;\n data: GenericRecord<string>;\n stack?: string;\n}\n\nexport interface IWebsocketsResponseErrorResult {\n statusCode: number;\n error: IWebsocketsResponseErrorResultError;\n}\n\nexport interface IWebsocketsResponse {\n ok(params?: IWebsocketsResponseOkParams): IWebsocketsResponseOkResult;\n error(params: IWebsocketsResponseErrorParams): IWebsocketsResponseErrorResult;\n}\n\nexport const WebsocketsResponse = createAbstraction<IWebsocketsResponse>(\"WebsocketsResponse\");\n\nexport namespace WebsocketsResponse {\n export type Interface = IWebsocketsResponse;\n export type OkParams = IWebsocketsResponseOkParams;\n export type OkResult = IWebsocketsResponseOkResult;\n export type ErrorParams = IWebsocketsResponseErrorParams;\n export type ErrorResult = IWebsocketsResponseErrorResult;\n export type ErrorResultError = IWebsocketsResponseErrorResultError;\n}\n"],"names":["WebsocketsResponse","createAbstraction"],"mappings":";AAsCO,MAAMA,qBAAqBC,kBAAuC"}
|
package/response/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { WebsocketsResponse } from "./abstractions/WebsocketsResponse.js";
|
|
2
|
+
export type { IWebsocketsResponse } from "./abstractions/WebsocketsResponse.js";
|
|
3
|
+
export type { IWebsocketsResponseOkResult } from "./abstractions/WebsocketsResponse.js";
|
|
4
|
+
export type { IWebsocketsResponseErrorResult } from "./abstractions/WebsocketsResponse.js";
|
|
5
|
+
export { DefaultWebsocketsResponse } from "./WebsocketsResponse.js";
|
package/response/index.js
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _IWebsocketsResponse = require("./abstractions/IWebsocketsResponse");
|
|
7
|
-
Object.keys(_IWebsocketsResponse).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _IWebsocketsResponse[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _IWebsocketsResponse[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _WebsocketsResponse = require("./WebsocketsResponse");
|
|
18
|
-
Object.keys(_WebsocketsResponse).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _WebsocketsResponse[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _WebsocketsResponse[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { WebsocketsResponse } from "./abstractions/WebsocketsResponse.js";
|
|
2
|
+
export { DefaultWebsocketsResponse } from "./WebsocketsResponse.js";
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
-
import type { IWebsocketsEventData,
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import
|
|
5
|
-
import type { IWebsocketsConnectionRegistry } from "../registry";
|
|
6
|
-
import type { IWebsocketsResponse } from "../response";
|
|
1
|
+
import type { IWebsocketsEvent, IWebsocketsEventContext, IWebsocketsEventData, WebsocketsRoute, WebsocketsEventType, Context } from "../types.js";
|
|
2
|
+
import type { IWebsocketsRunner } from "./abstractions/WebsocketsRunner.js";
|
|
3
|
+
import type { IWebsocketsRunnerResponse } from "./abstractions/WebsocketsRunner.js";
|
|
4
|
+
import { WebsocketsResponse } from "../response/index.js";
|
|
7
5
|
export declare class WebsocketsRunner implements IWebsocketsRunner {
|
|
8
6
|
private readonly context;
|
|
9
7
|
private readonly registry;
|
|
10
|
-
private readonly validator;
|
|
11
8
|
private readonly response;
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
private readonly sendToConnections;
|
|
10
|
+
constructor(context: Context, response: WebsocketsResponse.Interface);
|
|
11
|
+
run<T extends IWebsocketsEventData = IWebsocketsEventData>(event: IWebsocketsEvent<T>): Promise<IWebsocketsRunnerResponse>;
|
|
14
12
|
private getRoutePlugins;
|
|
15
13
|
private executeRoute;
|
|
16
14
|
private respond;
|
|
17
15
|
}
|
|
16
|
+
export declare namespace WebsocketsRunner {
|
|
17
|
+
type Event<T extends IWebsocketsEventData = IWebsocketsEventData> = IWebsocketsEvent<T>;
|
|
18
|
+
type EventData = IWebsocketsEventData;
|
|
19
|
+
type EventContext = IWebsocketsEventContext;
|
|
20
|
+
type EventType = WebsocketsEventType;
|
|
21
|
+
type Route = WebsocketsRoute;
|
|
22
|
+
type Response = IWebsocketsRunnerResponse;
|
|
23
|
+
}
|
|
@@ -1,191 +1,121 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
exports.WebsocketsRunner = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _types = require("../handler/types");
|
|
10
|
-
var _plugins = require("../plugins");
|
|
11
|
-
var _middleware = require("../utils/middleware");
|
|
1
|
+
import error from "@webiny/error";
|
|
2
|
+
import { ConnectionRegistry } from "../features/ConnectionRegistry/abstractions.js";
|
|
3
|
+
import { WebsocketsRoutePlugin } from "../plugins/index.js";
|
|
4
|
+
import { middleware } from "../utils/middleware.js";
|
|
5
|
+
import { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
|
|
12
6
|
class WebsocketsRunner {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
async run(input) {
|
|
20
|
-
let event;
|
|
21
|
-
try {
|
|
22
|
-
event = await this.validator.validate(input);
|
|
23
|
-
} catch (ex) {
|
|
24
|
-
const result = this.response.error({
|
|
25
|
-
message: "Validation failed.",
|
|
26
|
-
error: {
|
|
27
|
-
message: ex.message,
|
|
28
|
-
code: ex.code,
|
|
29
|
-
data: ex.data,
|
|
30
|
-
stack: ex.stack
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
const {
|
|
34
|
-
connectionId,
|
|
35
|
-
domainName,
|
|
36
|
-
stage,
|
|
37
|
-
eventType
|
|
38
|
-
} = input.requestContext || {};
|
|
39
|
-
let messageId;
|
|
40
|
-
try {
|
|
41
|
-
const body = typeof input.body === "string" ? input.body : JSON.stringify(input.body || {});
|
|
42
|
-
const json = JSON.parse(body);
|
|
43
|
-
messageId = json.messageId;
|
|
44
|
-
} catch {
|
|
45
|
-
// Do nothing
|
|
46
|
-
}
|
|
47
|
-
if (!connectionId || !stage || !domainName || !eventType) {
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
await this.respond({
|
|
51
|
-
connectionId,
|
|
52
|
-
domainName,
|
|
53
|
-
stage,
|
|
54
|
-
eventType,
|
|
55
|
-
messageId,
|
|
56
|
-
result
|
|
57
|
-
});
|
|
58
|
-
return result;
|
|
7
|
+
constructor(context, response){
|
|
8
|
+
this.context = context;
|
|
9
|
+
this.registry = context.container.resolve(ConnectionRegistry);
|
|
10
|
+
this.response = response;
|
|
11
|
+
this.sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);
|
|
59
12
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
13
|
+
async run(event) {
|
|
14
|
+
let result;
|
|
15
|
+
try {
|
|
16
|
+
result = await this.executeRoute(event);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
result = this.response.error({
|
|
19
|
+
message: `Route "${event.context.route}" action failed.`,
|
|
20
|
+
error: {
|
|
21
|
+
message: ex.message,
|
|
22
|
+
code: ex.code,
|
|
23
|
+
data: ex.data,
|
|
24
|
+
stack: ex.stack
|
|
25
|
+
}
|
|
26
|
+
});
|
|
71
27
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
28
|
+
try {
|
|
29
|
+
await this.respond({
|
|
30
|
+
connectionId: event.context.connectionId,
|
|
31
|
+
endpoint: event.context.endpoint,
|
|
32
|
+
eventType: event.context.eventType,
|
|
33
|
+
messageId: event.body?.messageId,
|
|
34
|
+
result
|
|
35
|
+
});
|
|
36
|
+
return result;
|
|
37
|
+
} catch (ex) {
|
|
38
|
+
return this.response.error({
|
|
39
|
+
message: "Failed to respond to the request.",
|
|
40
|
+
error: {
|
|
41
|
+
message: ex.message,
|
|
42
|
+
code: ex.code,
|
|
43
|
+
data: {
|
|
44
|
+
...ex.data,
|
|
45
|
+
result
|
|
46
|
+
},
|
|
47
|
+
stack: ex.stack
|
|
48
|
+
}
|
|
49
|
+
});
|
|
92
50
|
}
|
|
93
|
-
});
|
|
94
51
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
throw new _error.default(`There are no plugins for the route: ${route}.`, "NO_ROUTE_PLUGINS", {
|
|
102
|
-
route
|
|
103
|
-
});
|
|
52
|
+
getRoutePlugins(route) {
|
|
53
|
+
const plugins = this.context.plugins.byType(WebsocketsRoutePlugin.type).filter((plugin)=>plugin.route === route);
|
|
54
|
+
if (0 === plugins.length) throw new error(`There are no plugins for the route: ${route}.`, "NO_ROUTE_PLUGINS", {
|
|
55
|
+
route
|
|
56
|
+
});
|
|
57
|
+
return plugins;
|
|
104
58
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
59
|
+
async executeRoute(event) {
|
|
60
|
+
const plugins = this.getRoutePlugins(event.context.route).reverse();
|
|
61
|
+
const getTenant = ()=>{
|
|
62
|
+
const tenant = this.context.tenancy.getCurrentTenant();
|
|
63
|
+
return tenant?.id || null;
|
|
64
|
+
};
|
|
65
|
+
const getIdentity = ()=>{
|
|
66
|
+
const identity = this.context.security.getIdentity();
|
|
67
|
+
return identity || null;
|
|
68
|
+
};
|
|
69
|
+
const action = middleware(plugins.map((plugin)=>async (params, next)=>plugin.run({
|
|
70
|
+
registry: params.registry,
|
|
71
|
+
event: params.event,
|
|
72
|
+
context: params.context,
|
|
73
|
+
getTenant,
|
|
74
|
+
getIdentity,
|
|
75
|
+
response: this.response,
|
|
76
|
+
next
|
|
77
|
+
})));
|
|
78
|
+
const result = await action({
|
|
79
|
+
event,
|
|
80
|
+
registry: this.registry,
|
|
81
|
+
context: this.context
|
|
82
|
+
});
|
|
83
|
+
if (result) return result;
|
|
84
|
+
const message = "No response from the route action.";
|
|
85
|
+
return this.response.error({
|
|
86
|
+
message,
|
|
87
|
+
error: {
|
|
88
|
+
message,
|
|
89
|
+
code: "NO_RESPONSE"
|
|
90
|
+
},
|
|
91
|
+
statusCode: 404
|
|
135
92
|
});
|
|
136
|
-
};
|
|
137
|
-
}));
|
|
138
|
-
const result = await action({
|
|
139
|
-
event,
|
|
140
|
-
registry: this.registry,
|
|
141
|
-
context: this.context
|
|
142
|
-
});
|
|
143
|
-
if (result) {
|
|
144
|
-
return result;
|
|
145
93
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const data = {
|
|
170
|
-
connectionId,
|
|
171
|
-
domainName,
|
|
172
|
-
stage
|
|
173
|
-
};
|
|
174
|
-
console.error(message, JSON.stringify(data));
|
|
175
|
-
throw new _error.default(message, "GENERAL_ERROR", data);
|
|
94
|
+
async respond(params) {
|
|
95
|
+
const { connectionId, endpoint, eventType, result, messageId } = params;
|
|
96
|
+
if ("message" !== eventType) return;
|
|
97
|
+
if (!connectionId || !endpoint) {
|
|
98
|
+
const message = "No connectionId or endpoint.";
|
|
99
|
+
const data = {
|
|
100
|
+
connectionId,
|
|
101
|
+
endpoint
|
|
102
|
+
};
|
|
103
|
+
console.error(message, JSON.stringify(data));
|
|
104
|
+
throw new error(message, "GENERAL_ERROR", data);
|
|
105
|
+
}
|
|
106
|
+
const connection = {
|
|
107
|
+
connectionId,
|
|
108
|
+
endpoint
|
|
109
|
+
};
|
|
110
|
+
const dataToSend = {
|
|
111
|
+
...result,
|
|
112
|
+
messageId
|
|
113
|
+
};
|
|
114
|
+
await this.sendToConnections.execute([
|
|
115
|
+
connection
|
|
116
|
+
], dataToSend);
|
|
176
117
|
}
|
|
177
|
-
const connection = {
|
|
178
|
-
connectionId,
|
|
179
|
-
domainName,
|
|
180
|
-
stage
|
|
181
|
-
};
|
|
182
|
-
const dataToSend = {
|
|
183
|
-
...result,
|
|
184
|
-
messageId
|
|
185
|
-
};
|
|
186
|
-
await this.context.websockets.sendToConnections([connection], dataToSend);
|
|
187
|
-
}
|
|
188
118
|
}
|
|
189
|
-
|
|
119
|
+
export { WebsocketsRunner };
|
|
190
120
|
|
|
191
121
|
//# sourceMappingURL=WebsocketsRunner.js.map
|