@webiny/api-websockets 0.0.0-unstable.461c047ab7 → 0.0.0-unstable.48a4e5b6c1
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/WebsocketsFeature.d.ts +4 -0
- package/WebsocketsFeature.js +25 -0
- package/WebsocketsFeature.js.map +1 -0
- package/exports/api.d.ts +3 -0
- package/exports/api.js +3 -0
- package/{registry/abstractions/IWebsocketsConnectionRegistry.d.ts → features/ConnectionRegistry/abstractions.d.ts} +16 -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 +48 -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/Disconnect/validateDisconnectWhere.d.ts +8 -0
- package/features/Disconnect/validateDisconnectWhere.js +12 -0
- package/features/Disconnect/validateDisconnectWhere.js.map +1 -0
- package/features/ListConnections/ListConnectionsUseCase.d.ts +15 -0
- package/features/ListConnections/ListConnectionsUseCase.js +36 -0
- package/features/ListConnections/ListConnectionsUseCase.js.map +1 -0
- package/features/ListConnections/abstractions.d.ts +20 -0
- package/features/ListConnections/abstractions.js +5 -0
- package/features/ListConnections/abstractions.js.map +1 -0
- package/features/Routes/abstractions.d.ts +32 -0
- package/features/Routes/abstractions.js +5 -0
- package/features/Routes/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 +18 -0
- package/features/SendToIdentity/SendToIdentityUseCase.js +41 -0
- package/features/SendToIdentity/SendToIdentityUseCase.js.map +1 -0
- package/features/feature.d.ts +1 -0
- package/features/feature.js +1 -0
- package/features/shared/errors.d.ts +19 -0
- package/features/shared/errors.js +31 -0
- package/features/shared/errors.js.map +1 -0
- package/graphql/WebsocketsGraphQLFactory.d.ts +10 -0
- package/graphql/WebsocketsGraphQLFactory.js +173 -0
- package/graphql/WebsocketsGraphQLFactory.js.map +1 -0
- package/graphql/index.d.ts +1 -2
- package/graphql/index.js +1 -20
- package/handler/headers.d.ts +1 -2
- package/handler/headers.js +26 -39
- package/handler/headers.js.map +1 -1
- package/handler/types.d.ts +7 -21
- package/handler/types.js +11 -16
- package/handler/types.js.map +1 -1
- package/index.d.ts +9 -10
- package/index.js +7 -101
- package/package.json +29 -30
- 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 +16 -10
- package/runner/WebsocketsRunner.js +111 -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 +2 -1
- package/runner/routes/connect.js +46 -52
- package/runner/routes/connect.js.map +1 -1
- package/runner/routes/default.d.ts +2 -1
- package/runner/routes/default.js +13 -36
- package/runner/routes/default.js.map +1 -1
- package/runner/routes/disconnect.d.ts +2 -1
- package/runner/routes/disconnect.js +10 -23
- package/runner/routes/disconnect.js.map +1 -1
- package/runner/routes/index.d.ts +10 -1
- package/runner/routes/index.js +9 -12
- 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 +21 -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 +26 -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/register.d.ts +0 -1
- package/handler/register.js +0 -28
- package/handler/register.js.map +0 -1
- package/index.js.map +0 -1
- package/plugins/WebsocketsActionPlugin.d.ts +0 -11
- package/plugins/WebsocketsActionPlugin.js +0 -25
- package/plugins/WebsocketsActionPlugin.js.map +0 -1
- package/plugins/WebsocketsRoutePlugin.d.ts +0 -28
- package/plugins/WebsocketsRoutePlugin.js +0 -25
- package/plugins/WebsocketsRoutePlugin.js.map +0 -1
- package/plugins/abstrations/IWebsocketsActionPlugin.d.ts +0 -35
- package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -7
- package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
- package/plugins/index.d.ts +0 -3
- package/plugins/index.js +0 -40
- 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
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-websockets",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.48a4e5b6c1",
|
|
4
|
+
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -10,39 +10,38 @@
|
|
|
10
10
|
"contributors": [
|
|
11
11
|
"Bruno Zorić <bruno@webiny.com>"
|
|
12
12
|
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./*": "./*",
|
|
15
|
+
".": "./index.js"
|
|
16
|
+
},
|
|
13
17
|
"license": "MIT",
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@webiny/api": "0.0.0-unstable.
|
|
16
|
-
"@webiny/api-
|
|
17
|
-
"@webiny/api-
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/
|
|
21
|
-
"
|
|
22
|
-
"@webiny/handler": "0.0.0-unstable.461c047ab7",
|
|
23
|
-
"@webiny/handler-aws": "0.0.0-unstable.461c047ab7",
|
|
24
|
-
"@webiny/plugins": "0.0.0-unstable.461c047ab7",
|
|
25
|
-
"@webiny/utils": "0.0.0-unstable.461c047ab7",
|
|
26
|
-
"type-fest": "4.14.0",
|
|
27
|
-
"zod": "3.23.8"
|
|
19
|
+
"@webiny/api": "0.0.0-unstable.48a4e5b6c1",
|
|
20
|
+
"@webiny/api-core": "0.0.0-unstable.48a4e5b6c1",
|
|
21
|
+
"@webiny/api-graphql": "0.0.0-unstable.48a4e5b6c1",
|
|
22
|
+
"@webiny/error": "0.0.0-unstable.48a4e5b6c1",
|
|
23
|
+
"@webiny/feature": "0.0.0-unstable.48a4e5b6c1",
|
|
24
|
+
"@webiny/handler": "0.0.0-unstable.48a4e5b6c1",
|
|
25
|
+
"type-fest": "6.0.3"
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
|
-
"@webiny/api-
|
|
31
|
-
"@webiny/api-
|
|
32
|
-
"@webiny/
|
|
33
|
-
"@webiny/
|
|
34
|
-
"@webiny/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
28
|
+
"@webiny/api-core-testing": "0.0.0-unstable.48a4e5b6c1",
|
|
29
|
+
"@webiny/api-graphql": "0.0.0-unstable.48a4e5b6c1",
|
|
30
|
+
"@webiny/api-headless-cms": "0.0.0-unstable.48a4e5b6c1",
|
|
31
|
+
"@webiny/api-kernel-core": "0.0.0-unstable.48a4e5b6c1",
|
|
32
|
+
"@webiny/build-tools": "0.0.0-unstable.48a4e5b6c1",
|
|
33
|
+
"@webiny/di": "2.0.0",
|
|
34
|
+
"@webiny/wcp": "0.0.0-unstable.48a4e5b6c1",
|
|
35
|
+
"graphql": "16.15.0",
|
|
36
|
+
"rimraf": "6.1.4",
|
|
37
|
+
"type-fest": "6.0.3",
|
|
38
|
+
"typescript": "7.0.2",
|
|
39
|
+
"vitest": "5.1.1"
|
|
38
40
|
},
|
|
39
41
|
"publishConfig": {
|
|
40
|
-
"access": "public"
|
|
41
|
-
"directory": "dist"
|
|
42
|
-
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"build": "node ../cli/bin.js run build",
|
|
45
|
-
"watch": "node ../cli/bin.js run watch"
|
|
42
|
+
"access": "public"
|
|
46
43
|
},
|
|
47
|
-
"
|
|
44
|
+
"webiny": {
|
|
45
|
+
"publishFrom": "dist"
|
|
46
|
+
}
|
|
48
47
|
}
|
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
|
-
|
|
14
|
-
|
|
9
|
+
private readonly sendToConnections;
|
|
10
|
+
constructor(context: Context, response: WebsocketsResponse.Interface);
|
|
11
|
+
run<T extends IWebsocketsEventData = IWebsocketsEventData>(event: IWebsocketsEvent<T>): Promise<IWebsocketsRunnerResponse>;
|
|
12
|
+
private getRouteHandlers;
|
|
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,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
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 { WebsocketsRouteHandler } from "../features/Routes/abstractions.js";
|
|
4
|
+
import { middleware } from "../utils/middleware.js";
|
|
5
|
+
import { WebsocketsSendToConnectionsUseCase } from "../features/SendToConnections/abstractions.js";
|
|
6
|
+
import { TenantContext } from "@webiny/api-core/features/tenancy/TenantContext/index.js";
|
|
7
|
+
import { IdentityContext } from "@webiny/api-core/features/security/IdentityContext/abstractions.js";
|
|
12
8
|
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;
|
|
9
|
+
constructor(context, response){
|
|
10
|
+
this.context = context;
|
|
11
|
+
this.registry = context.container.resolve(ConnectionRegistry);
|
|
12
|
+
this.response = response;
|
|
13
|
+
this.sendToConnections = context.container.resolve(WebsocketsSendToConnectionsUseCase);
|
|
59
14
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
15
|
+
async run(event) {
|
|
16
|
+
let result;
|
|
17
|
+
try {
|
|
18
|
+
result = await this.executeRoute(event);
|
|
19
|
+
} catch (ex) {
|
|
20
|
+
result = this.response.error({
|
|
21
|
+
message: `Route "${event.context.route}" action failed.`,
|
|
22
|
+
error: {
|
|
23
|
+
message: ex.message,
|
|
24
|
+
code: ex.code,
|
|
25
|
+
data: ex.data,
|
|
26
|
+
stack: ex.stack
|
|
27
|
+
}
|
|
28
|
+
});
|
|
71
29
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
30
|
+
try {
|
|
31
|
+
await this.respond({
|
|
32
|
+
connectionId: event.context.connectionId,
|
|
33
|
+
endpoint: event.context.endpoint,
|
|
34
|
+
eventType: event.context.eventType,
|
|
35
|
+
messageId: event.body?.messageId,
|
|
36
|
+
result
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
} catch (ex) {
|
|
40
|
+
return this.response.error({
|
|
41
|
+
message: "Failed to respond to the request.",
|
|
42
|
+
error: {
|
|
43
|
+
message: ex.message,
|
|
44
|
+
code: ex.code,
|
|
45
|
+
data: {
|
|
46
|
+
...ex.data,
|
|
47
|
+
result
|
|
48
|
+
},
|
|
49
|
+
stack: ex.stack
|
|
50
|
+
}
|
|
51
|
+
});
|
|
92
52
|
}
|
|
93
|
-
});
|
|
94
53
|
}
|
|
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
|
-
});
|
|
54
|
+
getRouteHandlers(route) {
|
|
55
|
+
const handlers = this.context.container.resolveAll(WebsocketsRouteHandler).filter((handler)=>handler.route === route);
|
|
56
|
+
if (0 === handlers.length) throw new error(`There are no handlers for the route: ${route}.`, "NO_ROUTE_HANDLERS", {
|
|
57
|
+
route
|
|
58
|
+
});
|
|
59
|
+
return handlers;
|
|
104
60
|
}
|
|
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
|
-
|
|
61
|
+
async executeRoute(event) {
|
|
62
|
+
const handlers = this.getRouteHandlers(event.context.route).reverse();
|
|
63
|
+
const getTenant = ()=>{
|
|
64
|
+
const tenant = this.context.container.resolve(TenantContext).getTenant();
|
|
65
|
+
return tenant?.id || null;
|
|
66
|
+
};
|
|
67
|
+
const identityContext = this.context.container.resolve(IdentityContext);
|
|
68
|
+
const action = middleware(handlers.map((handler)=>async (params, next)=>{
|
|
69
|
+
const identity = identityContext.getIdentity();
|
|
70
|
+
return handler.run({
|
|
71
|
+
registry: params.registry,
|
|
72
|
+
event: params.event,
|
|
73
|
+
container: params.container,
|
|
74
|
+
getTenant,
|
|
75
|
+
identity,
|
|
76
|
+
response: this.response,
|
|
77
|
+
next
|
|
78
|
+
});
|
|
79
|
+
}));
|
|
80
|
+
const result = await action({
|
|
81
|
+
event,
|
|
82
|
+
registry: this.registry,
|
|
83
|
+
container: this.context.container
|
|
84
|
+
});
|
|
85
|
+
if (result) return result;
|
|
86
|
+
const message = "No response from the route action.";
|
|
87
|
+
return this.response.error({
|
|
88
|
+
message,
|
|
89
|
+
error: {
|
|
90
|
+
message,
|
|
91
|
+
code: "NO_RESPONSE"
|
|
92
|
+
},
|
|
93
|
+
statusCode: 404
|
|
135
94
|
});
|
|
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
95
|
}
|
|
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);
|
|
96
|
+
async respond(params) {
|
|
97
|
+
const { connectionId, endpoint, eventType, result, messageId } = params;
|
|
98
|
+
if ("message" !== eventType) return;
|
|
99
|
+
else if (!connectionId || !endpoint) {
|
|
100
|
+
const message = "No connectionId or endpoint.";
|
|
101
|
+
const data = {
|
|
102
|
+
connectionId,
|
|
103
|
+
endpoint
|
|
104
|
+
};
|
|
105
|
+
console.error(message, JSON.stringify(data));
|
|
106
|
+
throw new error(message, "GENERAL_ERROR", data);
|
|
107
|
+
}
|
|
108
|
+
const connection = {
|
|
109
|
+
connectionId,
|
|
110
|
+
endpoint
|
|
111
|
+
};
|
|
112
|
+
const dataToSend = {
|
|
113
|
+
...result,
|
|
114
|
+
messageId
|
|
115
|
+
};
|
|
116
|
+
await this.sendToConnections.execute([
|
|
117
|
+
connection
|
|
118
|
+
], dataToSend);
|
|
176
119
|
}
|
|
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
120
|
}
|
|
189
|
-
|
|
121
|
+
export { WebsocketsRunner };
|
|
190
122
|
|
|
191
123
|
//# sourceMappingURL=WebsocketsRunner.js.map
|