@webiny/api-websockets 0.0.0-unstable.eb196ccd2f → 0.0.0-unstable.eb81deee7e
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 +23 -0
- package/WebsocketsFeature.js.map +1 -0
- package/exports/api.d.ts +11 -0
- package/exports/api.js +10 -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/Routes/abstractions.d.ts +38 -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 +42 -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 +1 -0
- package/features/feature.js +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 +10 -0
- package/graphql/WebsocketsGraphQLFactory.js +196 -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/handler/headers.d.ts +1 -2
- package/handler/headers.js +25 -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 +28 -52
- package/runner/routes/connect.js.map +1 -1
- package/runner/routes/default.d.ts +2 -1
- package/runner/routes/default.js +14 -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 +11 -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 +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 +28 -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
|
@@ -1,26 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const plugin = (0, _WebsocketsRoutePlugin.createWebsocketsRoutePlugin)(_types.WebsocketsEventRoute.disconnect, async params => {
|
|
11
|
-
const {
|
|
12
|
-
registry,
|
|
13
|
-
event,
|
|
14
|
-
response
|
|
15
|
-
} = params;
|
|
16
|
-
await registry.unregister({
|
|
17
|
-
connectionId: event.requestContext.connectionId
|
|
18
|
-
});
|
|
19
|
-
return response.ok();
|
|
20
|
-
});
|
|
21
|
-
plugin.name = "websockets.route.disconnect.default";
|
|
22
|
-
return plugin;
|
|
1
|
+
const DISCONNECT = "disconnect";
|
|
2
|
+
const websocketsRouteDisconnect = {
|
|
3
|
+
route: DISCONNECT,
|
|
4
|
+
async run ({ registry, event, response }) {
|
|
5
|
+
await registry.unregister({
|
|
6
|
+
connectionId: event.context.connectionId
|
|
7
|
+
});
|
|
8
|
+
return response.ok();
|
|
9
|
+
}
|
|
23
10
|
};
|
|
24
|
-
|
|
11
|
+
export { websocketsRouteDisconnect };
|
|
25
12
|
|
|
26
13
|
//# sourceMappingURL=disconnect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"runner/routes/disconnect.js","sources":["../../../src/runner/routes/disconnect.ts"],"sourcesContent":["import type { WebsocketsRoute } from \"~/types.js\";\nimport type { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\n\nconst DISCONNECT: WebsocketsRoute = \"disconnect\";\n\nexport const websocketsRouteDisconnect: WebsocketsRouteHandler.Interface = {\n route: DISCONNECT,\n async run({ registry, event, response }) {\n await registry.unregister({\n connectionId: event.context.connectionId\n });\n\n return response.ok();\n }\n};\n"],"names":["DISCONNECT","websocketsRouteDisconnect","registry","event","response"],"mappings":"AAGA,MAAMA,aAA8B;AAE7B,MAAMC,4BAA8D;IACvE,OAAOD;IACP,MAAM,KAAI,EAAEE,QAAQ,EAAEC,KAAK,EAAEC,QAAQ,EAAE;QACnC,MAAMF,SAAS,UAAU,CAAC;YACtB,cAAcC,MAAM,OAAO,CAAC,YAAY;QAC5C;QAEA,OAAOC,SAAS,EAAE;IACtB;AACJ"}
|
package/runner/routes/index.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Container } from "@webiny/di";
|
|
2
|
+
import { websocketsRouteConnect } from "./connect.js";
|
|
3
|
+
import { websocketsRouteDisconnect } from "./disconnect.js";
|
|
4
|
+
import { websocketsRouteDefault } from "./default.js";
|
|
5
|
+
export { websocketsRouteConnect, websocketsRouteDisconnect, websocketsRouteDefault };
|
|
6
|
+
/**
|
|
7
|
+
* Registers the built-in WebSocket route handlers (connect, disconnect, default) as
|
|
8
|
+
* WebsocketsRouteHandler implementations. Custom routes can be added the same way:
|
|
9
|
+
* `container.registerInstance(WebsocketsRouteHandler, { route, run })`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const registerWebsocketsRoutes: (container: Container) => void;
|
package/runner/routes/index.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _disconnect = require("./disconnect");
|
|
10
|
-
const createWebsocketsRoutePlugins = () => {
|
|
11
|
-
return [(0, _connect.createWebsocketsRouteConnectPlugin)(), (0, _disconnect.createWebsocketsRouteDisconnectPlugin)(), (0, _default.createWebsocketsRouteDefaultPlugin)()];
|
|
1
|
+
import { WebsocketsRouteHandler } from "../../features/Routes/abstractions.js";
|
|
2
|
+
import { websocketsRouteConnect } from "./connect.js";
|
|
3
|
+
import { websocketsRouteDisconnect } from "./disconnect.js";
|
|
4
|
+
import { websocketsRouteDefault } from "./default.js";
|
|
5
|
+
const registerWebsocketsRoutes = (container)=>{
|
|
6
|
+
container.registerInstance(WebsocketsRouteHandler, websocketsRouteConnect);
|
|
7
|
+
container.registerInstance(WebsocketsRouteHandler, websocketsRouteDisconnect);
|
|
8
|
+
container.registerInstance(WebsocketsRouteHandler, websocketsRouteDefault);
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export { registerWebsocketsRoutes, websocketsRouteConnect, websocketsRouteDefault, websocketsRouteDisconnect };
|
|
14
11
|
|
|
15
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"runner/routes/index.js","sources":["../../../src/runner/routes/index.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { WebsocketsRouteHandler } from \"~/features/Routes/abstractions.js\";\nimport { websocketsRouteConnect } from \"./connect.js\";\nimport { websocketsRouteDisconnect } from \"./disconnect.js\";\nimport { websocketsRouteDefault } from \"./default.js\";\n\nexport { websocketsRouteConnect, websocketsRouteDisconnect, websocketsRouteDefault };\n\n/**\n * Registers the built-in WebSocket route handlers (connect, disconnect, default) as\n * WebsocketsRouteHandler implementations. Custom routes can be added the same way:\n * `container.registerInstance(WebsocketsRouteHandler, { route, run })`.\n */\nexport const registerWebsocketsRoutes = (container: Container): void => {\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteConnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDisconnect);\n container.registerInstance(WebsocketsRouteHandler, websocketsRouteDefault);\n};\n"],"names":["registerWebsocketsRoutes","container","WebsocketsRouteHandler","websocketsRouteConnect","websocketsRouteDisconnect","websocketsRouteDefault"],"mappings":";;;;AAaO,MAAMA,2BAA2B,CAACC;IACrCA,UAAU,gBAAgB,CAACC,wBAAwBC;IACnDF,UAAU,gBAAgB,CAACC,wBAAwBE;IACnDH,UAAU,gBAAgB,CAACC,wBAAwBG;AACvD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebsocketsTransport } from "./abstractions/WebsocketsTransport.js";
|
|
2
|
+
declare class NullWebsocketsTransportImpl implements WebsocketsTransport.Interface {
|
|
3
|
+
send(): Promise<void>;
|
|
4
|
+
disconnect(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export declare const NullWebsocketsTransport: typeof NullWebsocketsTransportImpl & {
|
|
7
|
+
__abstraction: import("@webiny/di").Abstraction<import("./index.js").IWebsocketsTransport>;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebsocketsTransport } from "./abstractions/WebsocketsTransport.js";
|
|
2
|
+
class NullWebsocketsTransportImpl {
|
|
3
|
+
async send() {}
|
|
4
|
+
async disconnect() {}
|
|
5
|
+
}
|
|
6
|
+
const NullWebsocketsTransport = WebsocketsTransport.createImplementation({
|
|
7
|
+
implementation: NullWebsocketsTransportImpl,
|
|
8
|
+
dependencies: []
|
|
9
|
+
});
|
|
10
|
+
export { NullWebsocketsTransport };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=NullWebsocketsTransport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport/NullWebsocketsTransport.js","sources":["../../src/transport/NullWebsocketsTransport.ts"],"sourcesContent":["import { WebsocketsTransport } from \"./abstractions/WebsocketsTransport.js\";\n\nclass NullWebsocketsTransportImpl implements WebsocketsTransport.Interface {\n public async send(): Promise<void> {\n return;\n }\n\n public async disconnect(): Promise<void> {\n return;\n }\n}\n\nexport const NullWebsocketsTransport = WebsocketsTransport.createImplementation({\n implementation: NullWebsocketsTransportImpl,\n dependencies: []\n});\n"],"names":["NullWebsocketsTransportImpl","NullWebsocketsTransport","WebsocketsTransport"],"mappings":";AAEA,MAAMA;IACF,MAAa,OAAsB,CAEnC;IAEA,MAAa,aAA4B,CAEzC;AACJ;AAEO,MAAMC,0BAA0BC,oBAAoB,oBAAoB,CAAC;IAC5E,gBAAgBF;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
2
|
+
export interface IWebsocketsTransportSendDataError {
|
|
3
|
+
message: string;
|
|
4
|
+
code: string;
|
|
5
|
+
data?: GenericRecord;
|
|
6
|
+
stack?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface IWebsocketsTransportSendData<T extends GenericRecord> {
|
|
9
|
+
messageId?: string;
|
|
10
|
+
action?: string;
|
|
11
|
+
data?: T;
|
|
12
|
+
error?: IWebsocketsTransportSendDataError;
|
|
13
|
+
}
|
|
14
|
+
export interface IWebsocketsTransportSendConnection {
|
|
15
|
+
connectionId: string;
|
|
16
|
+
endpoint: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IWebsocketsTransportDisconnectConnection {
|
|
19
|
+
connectionId: string;
|
|
20
|
+
endpoint: string;
|
|
21
|
+
}
|
|
22
|
+
export interface IWebsocketsTransport {
|
|
23
|
+
send<T extends GenericRecord = GenericRecord>(connections: IWebsocketsTransportSendConnection[], data: IWebsocketsTransportSendData<T>): Promise<void>;
|
|
24
|
+
disconnect(connections: IWebsocketsTransportDisconnectConnection[]): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare const WebsocketsTransport: import("@webiny/di").Abstraction<IWebsocketsTransport>;
|
|
27
|
+
export declare namespace WebsocketsTransport {
|
|
28
|
+
type Interface = IWebsocketsTransport;
|
|
29
|
+
type SendConnection = IWebsocketsTransportSendConnection;
|
|
30
|
+
type SendData<T extends GenericRecord> = IWebsocketsTransportSendData<T>;
|
|
31
|
+
type DisconnectConnection = IWebsocketsTransportDisconnectConnection;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport/abstractions/WebsocketsTransport.js","sources":["../../../src/transport/abstractions/WebsocketsTransport.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface IWebsocketsTransportSendDataError {\n message: string;\n code: string;\n data?: GenericRecord;\n stack?: string;\n}\n\nexport interface IWebsocketsTransportSendData<T extends GenericRecord> {\n messageId?: string;\n action?: string;\n data?: T;\n error?: IWebsocketsTransportSendDataError;\n}\n\nexport interface IWebsocketsTransportSendConnection {\n connectionId: string;\n endpoint: string;\n}\n\nexport interface IWebsocketsTransportDisconnectConnection {\n connectionId: string;\n endpoint: string;\n}\n\nexport interface IWebsocketsTransport {\n send<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void>;\n\n disconnect(connections: IWebsocketsTransportDisconnectConnection[]): Promise<void>;\n}\n\nexport const WebsocketsTransport = createAbstraction<IWebsocketsTransport>(\"WebsocketsTransport\");\n\nexport namespace WebsocketsTransport {\n export type Interface = IWebsocketsTransport;\n export type SendConnection = IWebsocketsTransportSendConnection;\n export type SendData<T extends GenericRecord> = IWebsocketsTransportSendData<T>;\n export type DisconnectConnection = IWebsocketsTransportDisconnectConnection;\n}\n"],"names":["WebsocketsTransport","createAbstraction"],"mappings":";AAoCO,MAAMA,sBAAsBC,kBAAwC"}
|
package/transport/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./abstractions/IWebsocketsTransport";
|
|
1
|
+
export { WebsocketsTransport, type IWebsocketsTransport, type IWebsocketsTransportSendConnection, type IWebsocketsTransportSendData, type IWebsocketsTransportSendDataError, type IWebsocketsTransportDisconnectConnection } from "./abstractions/WebsocketsTransport.js";
|
package/transport/index.js
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _WebsocketsTransport = require("./WebsocketsTransport");
|
|
7
|
-
Object.keys(_WebsocketsTransport).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _WebsocketsTransport[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _WebsocketsTransport[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _IWebsocketsTransport = require("./abstractions/IWebsocketsTransport");
|
|
18
|
-
Object.keys(_IWebsocketsTransport).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _IWebsocketsTransport[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _IWebsocketsTransport[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { WebsocketsTransport } from "./abstractions/WebsocketsTransport.js";
|
package/types.d.ts
CHANGED
|
@@ -1,12 +1,33 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
export type
|
|
6
|
-
export interface Context extends
|
|
7
|
-
websockets: IWebsocketsContextObject;
|
|
1
|
+
import type { ApiCoreContext } from "@webiny/api-core/types/core.js";
|
|
2
|
+
import type { SecurityPermission } from "@webiny/api-core/types/security.js";
|
|
3
|
+
import type { SecurityIdentity } from "@webiny/api-core/types/security.js";
|
|
4
|
+
import type { GenericRecord } from "@webiny/api/types.js";
|
|
5
|
+
export type IWebsocketsIdentity = Pick<SecurityIdentity, "id" | "displayName" | "type">;
|
|
6
|
+
export interface Context extends ApiCoreContext {
|
|
8
7
|
}
|
|
9
8
|
export interface WebsocketsPermission extends SecurityPermission {
|
|
10
9
|
name: "websockets";
|
|
11
10
|
rwd?: string;
|
|
12
11
|
}
|
|
12
|
+
export type WebsocketsRoute = "connect" | "disconnect" | "default";
|
|
13
|
+
export type WebsocketsEventType = "message" | "connect" | "disconnect";
|
|
14
|
+
export interface IWebsocketsEventData {
|
|
15
|
+
token?: string;
|
|
16
|
+
tenant?: string;
|
|
17
|
+
messageId?: string;
|
|
18
|
+
action?: string;
|
|
19
|
+
data?: GenericRecord;
|
|
20
|
+
}
|
|
21
|
+
export interface IWebsocketsEventContext {
|
|
22
|
+
connectionId: string;
|
|
23
|
+
connectedAt: number;
|
|
24
|
+
host: string;
|
|
25
|
+
eventType: WebsocketsEventType;
|
|
26
|
+
route: WebsocketsRoute | string;
|
|
27
|
+
endpoint: string;
|
|
28
|
+
}
|
|
29
|
+
export interface IWebsocketsEvent<T extends IWebsocketsEventData = IWebsocketsEventData> {
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
context: IWebsocketsEventContext;
|
|
32
|
+
body?: T;
|
|
33
|
+
}
|
package/types.js
CHANGED
package/utils/middleware.d.ts
CHANGED
|
@@ -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 MiddlewareCallable<I extends GenericRecord = GenericRecord, O extends GenericRecord = GenericRecord> {
|
|
3
3
|
(input: I, next: () => Promise<O>): Promise<O>;
|
|
4
4
|
}
|
package/utils/middleware.js
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const chain = Array.from(functions);
|
|
10
|
-
const exec = async () => {
|
|
11
|
-
const fn = chain.shift();
|
|
12
|
-
if (!fn) {
|
|
13
|
-
return {};
|
|
14
|
-
}
|
|
15
|
-
const next = async () => {
|
|
1
|
+
const middleware = (functions)=>async (input)=>{
|
|
2
|
+
const chain = Array.from(functions);
|
|
3
|
+
const exec = async ()=>{
|
|
4
|
+
const fn = chain.shift();
|
|
5
|
+
if (!fn) return {};
|
|
6
|
+
const next = async ()=>exec();
|
|
7
|
+
return fn(input, next);
|
|
8
|
+
};
|
|
16
9
|
return exec();
|
|
17
|
-
};
|
|
18
|
-
return fn(input, next);
|
|
19
10
|
};
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
exports.middleware = middleware;
|
|
11
|
+
export { middleware };
|
|
24
12
|
|
|
25
13
|
//# sourceMappingURL=middleware.js.map
|
package/utils/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils/middleware.js","sources":["../../src/utils/middleware.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface MiddlewareCallable<\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n> {\n (input: I, next: () => Promise<O>): Promise<O>;\n}\n\nexport const middleware = <\n I extends GenericRecord = GenericRecord,\n O extends GenericRecord = GenericRecord\n>(\n functions: MiddlewareCallable<I, O>[]\n) => {\n return async (input: I): Promise<O> => {\n const chain = Array.from(functions);\n const exec = async (): Promise<O> => {\n const fn = chain.shift();\n if (!fn) {\n return {} as O;\n }\n const next = async () => {\n return exec();\n };\n return fn(input, next);\n };\n return exec();\n };\n};\n"],"names":["middleware","functions","input","chain","Array","exec","fn","next"],"mappings":"AASO,MAAMA,aAAa,CAItBC,YAEO,OAAOC;QACV,MAAMC,QAAQC,MAAM,IAAI,CAACH;QACzB,MAAMI,OAAO;YACT,MAAMC,KAAKH,MAAM,KAAK;YACtB,IAAI,CAACG,IACD,OAAO,CAAC;YAEZ,MAAMC,OAAO,UACFF;YAEX,OAAOC,GAAGJ,OAAOK;QACrB;QACA,OAAOF;IACX"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IWebsocketsEvent, IWebsocketsEventData } from "../../types.js";
|
|
2
|
+
export interface IWebsocketsEventValidator {
|
|
3
|
+
validate<T extends IWebsocketsEventData = IWebsocketsEventData>(input: unknown): Promise<IWebsocketsEvent<T>>;
|
|
4
|
+
}
|
|
5
|
+
export declare const WebsocketsEventValidator: import("@webiny/di").Abstraction<IWebsocketsEventValidator>;
|
|
6
|
+
export declare namespace WebsocketsEventValidator {
|
|
7
|
+
type Interface = IWebsocketsEventValidator;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator/abstractions/WebsocketsEventValidator.js","sources":["../../../src/validator/abstractions/WebsocketsEventValidator.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/types.js\";\n\nexport interface IWebsocketsEventValidator {\n validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n input: unknown\n ): Promise<IWebsocketsEvent<T>>;\n}\n\nexport const WebsocketsEventValidator = createAbstraction<IWebsocketsEventValidator>(\n \"WebsocketsEventValidator\"\n);\n\nexport namespace WebsocketsEventValidator {\n export type Interface = IWebsocketsEventValidator;\n}\n"],"names":["WebsocketsEventValidator","createAbstraction"],"mappings":";AASO,MAAMA,2BAA2BC,kBACpC"}
|
package/validator/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { WebsocketsEventValidator } from "./abstractions/WebsocketsEventValidator.js";
|
|
2
|
+
export type { IWebsocketsEventValidator } from "./abstractions/WebsocketsEventValidator.js";
|
package/validator/index.js
CHANGED
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _IWebsocketsEventValidator = require("./abstractions/IWebsocketsEventValidator");
|
|
7
|
-
Object.keys(_IWebsocketsEventValidator).forEach(function (key) {
|
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
|
9
|
-
if (key in exports && exports[key] === _IWebsocketsEventValidator[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function () {
|
|
13
|
-
return _IWebsocketsEventValidator[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _WebsocketsEventValidator = require("./WebsocketsEventValidator");
|
|
18
|
-
Object.keys(_WebsocketsEventValidator).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _WebsocketsEventValidator[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _WebsocketsEventValidator[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export { WebsocketsEventValidator } from "./abstractions/WebsocketsEventValidator.js";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData } from "../registry";
|
|
2
|
-
import type { IWebsocketsContextObject, IWebsocketsContextDisconnectConnectionsParams, IWebsocketsContextListConnectionsParams, IWebsocketsIdentity } from "./abstractions/IWebsocketsContext";
|
|
3
|
-
import type { IWebsocketsTransport, IWebsocketsTransportSendConnection, IWebsocketsTransportSendData } from "../transport";
|
|
4
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
5
|
-
export declare class WebsocketsContext implements IWebsocketsContextObject {
|
|
6
|
-
readonly registry: IWebsocketsConnectionRegistry;
|
|
7
|
-
private readonly transport;
|
|
8
|
-
constructor(registry: IWebsocketsConnectionRegistry, transport: IWebsocketsTransport);
|
|
9
|
-
send<T extends GenericRecord = GenericRecord>(identity: Pick<IWebsocketsIdentity, "id">, data: IWebsocketsTransportSendData<T>): Promise<void>;
|
|
10
|
-
sendToConnections<T extends GenericRecord = GenericRecord>(connections: IWebsocketsTransportSendConnection[], data: IWebsocketsTransportSendData<T>): Promise<void>;
|
|
11
|
-
listConnections(params?: IWebsocketsContextListConnectionsParams): Promise<IWebsocketsConnectionRegistryData[]>;
|
|
12
|
-
disconnect(params?: IWebsocketsContextDisconnectConnectionsParams, notify?: boolean): Promise<IWebsocketsConnectionRegistryData[]>;
|
|
13
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.WebsocketsContext = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
class WebsocketsContext {
|
|
10
|
-
constructor(registry, transport) {
|
|
11
|
-
this.registry = registry;
|
|
12
|
-
this.transport = transport;
|
|
13
|
-
}
|
|
14
|
-
async send(identity, data) {
|
|
15
|
-
const connections = await this.listConnections({
|
|
16
|
-
where: {
|
|
17
|
-
identityId: identity.id
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
return this.transport.send(connections, data);
|
|
21
|
-
}
|
|
22
|
-
async sendToConnections(connections, data) {
|
|
23
|
-
return this.transport.send(connections, data);
|
|
24
|
-
}
|
|
25
|
-
async listConnections(params) {
|
|
26
|
-
const where = params?.where || {};
|
|
27
|
-
if (where.identityId) {
|
|
28
|
-
return await this.registry.listViaIdentity(where.identityId);
|
|
29
|
-
} else if (where.connections) {
|
|
30
|
-
return await this.registry.listViaConnections(where.connections);
|
|
31
|
-
} else if (where.tenant) {
|
|
32
|
-
return await this.registry.listViaTenant(where.tenant, where.locale);
|
|
33
|
-
}
|
|
34
|
-
return await this.registry.listAll();
|
|
35
|
-
}
|
|
36
|
-
async disconnect(params, notify = true) {
|
|
37
|
-
const connections = await this.listConnections(params);
|
|
38
|
-
for (const connection of connections) {
|
|
39
|
-
try {
|
|
40
|
-
await this.registry.unregister(connection);
|
|
41
|
-
} catch {
|
|
42
|
-
// do nothing
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (notify) {
|
|
46
|
-
try {
|
|
47
|
-
await this.transport.send(connections, {
|
|
48
|
-
action: "forcedDisconnect"
|
|
49
|
-
});
|
|
50
|
-
} catch (ex) {
|
|
51
|
-
throw new _error.default("Failed to notify the clients about the forced disconnect.", "FORCED_DISCONNECT_NOTIFICATION_ERROR", {
|
|
52
|
-
connections,
|
|
53
|
-
error: ex
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
try {
|
|
58
|
-
await this.transport.disconnect(connections);
|
|
59
|
-
} catch (ex) {
|
|
60
|
-
throw new _error.default("Failed to forcefully disconnect the Websocket clients.", "FORCED_DISCONNECT_ERROR", {
|
|
61
|
-
connections,
|
|
62
|
-
error: ex
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
return connections;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.WebsocketsContext = WebsocketsContext;
|
|
69
|
-
|
|
70
|
-
//# sourceMappingURL=WebsocketsContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_error","_interopRequireDefault","require","WebsocketsContext","constructor","registry","transport","send","identity","data","connections","listConnections","where","identityId","id","sendToConnections","params","listViaIdentity","listViaConnections","tenant","listViaTenant","locale","listAll","disconnect","notify","connection","unregister","action","ex","WebinyError","error","exports"],"sources":["WebsocketsContext.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData } from \"~/registry\";\nimport type {\n IWebsocketsContextObject,\n IWebsocketsContextDisconnectConnectionsParams,\n IWebsocketsContextListConnectionsParams,\n IWebsocketsIdentity\n} from \"./abstractions/IWebsocketsContext\";\nimport type {\n IWebsocketsTransport,\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"~/transport\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport class WebsocketsContext implements IWebsocketsContextObject {\n public readonly registry: IWebsocketsConnectionRegistry;\n private readonly transport: IWebsocketsTransport;\n\n constructor(registry: IWebsocketsConnectionRegistry, transport: IWebsocketsTransport) {\n this.registry = registry;\n this.transport = transport;\n }\n\n public async send<T extends GenericRecord = GenericRecord>(\n identity: Pick<IWebsocketsIdentity, \"id\">,\n data: IWebsocketsTransportSendData<T>\n ): Promise<void> {\n const connections = await this.listConnections({\n where: {\n identityId: identity.id\n }\n });\n return this.transport.send<T>(connections, data);\n }\n\n public async sendToConnections<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void> {\n return this.transport.send<T>(connections, data);\n }\n\n public async listConnections(\n params?: IWebsocketsContextListConnectionsParams\n ): Promise<IWebsocketsConnectionRegistryData[]> {\n const where = params?.where || {};\n if (where.identityId) {\n return await this.registry.listViaIdentity(where.identityId);\n } else if (where.connections) {\n return await this.registry.listViaConnections(where.connections);\n } else if (where.tenant) {\n return await this.registry.listViaTenant(where.tenant, where.locale);\n }\n return await this.registry.listAll();\n }\n\n public async disconnect(\n params?: IWebsocketsContextDisconnectConnectionsParams,\n notify = true\n ): Promise<IWebsocketsConnectionRegistryData[]> {\n const connections = await this.listConnections(params);\n\n for (const connection of connections) {\n try {\n await this.registry.unregister(connection);\n } catch {\n // do nothing\n }\n }\n if (notify) {\n try {\n await this.transport.send(connections, {\n action: \"forcedDisconnect\"\n });\n } catch (ex) {\n throw new WebinyError(\n \"Failed to notify the clients about the forced disconnect.\",\n \"FORCED_DISCONNECT_NOTIFICATION_ERROR\",\n {\n connections,\n error: ex\n }\n );\n }\n }\n try {\n await this.transport.disconnect(connections);\n } catch (ex) {\n throw new WebinyError(\n \"Failed to forcefully disconnect the Websocket clients.\",\n \"FORCED_DISCONNECT_ERROR\",\n {\n connections,\n error: ex\n }\n );\n }\n\n return connections;\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAeO,MAAMC,iBAAiB,CAAqC;EAI/DC,WAAWA,CAACC,QAAuC,EAAEC,SAA+B,EAAE;IAClF,IAAI,CAACD,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,SAAS,GAAGA,SAAS;EAC9B;EAEA,MAAaC,IAAIA,CACbC,QAAyC,EACzCC,IAAqC,EACxB;IACb,MAAMC,WAAW,GAAG,MAAM,IAAI,CAACC,eAAe,CAAC;MAC3CC,KAAK,EAAE;QACHC,UAAU,EAAEL,QAAQ,CAACM;MACzB;IACJ,CAAC,CAAC;IACF,OAAO,IAAI,CAACR,SAAS,CAACC,IAAI,CAAIG,WAAW,EAAED,IAAI,CAAC;EACpD;EAEA,MAAaM,iBAAiBA,CAC1BL,WAAiD,EACjDD,IAAqC,EACxB;IACb,OAAO,IAAI,CAACH,SAAS,CAACC,IAAI,CAAIG,WAAW,EAAED,IAAI,CAAC;EACpD;EAEA,MAAaE,eAAeA,CACxBK,MAAgD,EACJ;IAC5C,MAAMJ,KAAK,GAAGI,MAAM,EAAEJ,KAAK,IAAI,CAAC,CAAC;IACjC,IAAIA,KAAK,CAACC,UAAU,EAAE;MAClB,OAAO,MAAM,IAAI,CAACR,QAAQ,CAACY,eAAe,CAACL,KAAK,CAACC,UAAU,CAAC;IAChE,CAAC,MAAM,IAAID,KAAK,CAACF,WAAW,EAAE;MAC1B,OAAO,MAAM,IAAI,CAACL,QAAQ,CAACa,kBAAkB,CAACN,KAAK,CAACF,WAAW,CAAC;IACpE,CAAC,MAAM,IAAIE,KAAK,CAACO,MAAM,EAAE;MACrB,OAAO,MAAM,IAAI,CAACd,QAAQ,CAACe,aAAa,CAACR,KAAK,CAACO,MAAM,EAAEP,KAAK,CAACS,MAAM,CAAC;IACxE;IACA,OAAO,MAAM,IAAI,CAAChB,QAAQ,CAACiB,OAAO,CAAC,CAAC;EACxC;EAEA,MAAaC,UAAUA,CACnBP,MAAsD,EACtDQ,MAAM,GAAG,IAAI,EAC+B;IAC5C,MAAMd,WAAW,GAAG,MAAM,IAAI,CAACC,eAAe,CAACK,MAAM,CAAC;IAEtD,KAAK,MAAMS,UAAU,IAAIf,WAAW,EAAE;MAClC,IAAI;QACA,MAAM,IAAI,CAACL,QAAQ,CAACqB,UAAU,CAACD,UAAU,CAAC;MAC9C,CAAC,CAAC,MAAM;QACJ;MAAA;IAER;IACA,IAAID,MAAM,EAAE;MACR,IAAI;QACA,MAAM,IAAI,CAAClB,SAAS,CAACC,IAAI,CAACG,WAAW,EAAE;UACnCiB,MAAM,EAAE;QACZ,CAAC,CAAC;MACN,CAAC,CAAC,OAAOC,EAAE,EAAE;QACT,MAAM,IAAIC,cAAW,CACjB,2DAA2D,EAC3D,sCAAsC,EACtC;UACInB,WAAW;UACXoB,KAAK,EAAEF;QACX,CACJ,CAAC;MACL;IACJ;IACA,IAAI;MACA,MAAM,IAAI,CAACtB,SAAS,CAACiB,UAAU,CAACb,WAAW,CAAC;IAChD,CAAC,CAAC,OAAOkB,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjB,wDAAwD,EACxD,yBAAyB,EACzB;QACInB,WAAW;QACXoB,KAAK,EAAEF;MACX,CACJ,CAAC;IACL;IAEA,OAAOlB,WAAW;EACtB;AACJ;AAACqB,OAAA,CAAA5B,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData } from "../../registry";
|
|
2
|
-
import type { IWebsocketsTransportSendConnection, IWebsocketsTransportSendData } from "../../transport";
|
|
3
|
-
import type { SecurityIdentity } from "@webiny/api-security/types";
|
|
4
|
-
import type { GenericRecord } from "@webiny/api/types";
|
|
5
|
-
export type IWebsocketsIdentity = Pick<SecurityIdentity, "id" | "displayName" | "type">;
|
|
6
|
-
export interface IWebsocketsContextListConnectionsParamsWhere {
|
|
7
|
-
identityId?: string;
|
|
8
|
-
tenant?: string;
|
|
9
|
-
locale?: string;
|
|
10
|
-
connections?: string[];
|
|
11
|
-
}
|
|
12
|
-
export interface IWebsocketsContextListConnectionsParams {
|
|
13
|
-
where?: IWebsocketsContextListConnectionsParamsWhere;
|
|
14
|
-
}
|
|
15
|
-
export type IWebsocketsContextDisconnectConnectionsParams = IWebsocketsContextListConnectionsParams;
|
|
16
|
-
export interface IWebsocketsContextObject {
|
|
17
|
-
readonly registry: IWebsocketsConnectionRegistry;
|
|
18
|
-
send<T extends GenericRecord = GenericRecord>(identity: Pick<IWebsocketsIdentity, "id">, data: IWebsocketsTransportSendData<T>): Promise<void>;
|
|
19
|
-
sendToConnections<T extends GenericRecord = GenericRecord>(connections: IWebsocketsTransportSendConnection[], data: IWebsocketsTransportSendData<T>): Promise<void>;
|
|
20
|
-
listConnections(params?: IWebsocketsContextListConnectionsParams): Promise<IWebsocketsConnectionRegistryData[]>;
|
|
21
|
-
disconnect(params?: IWebsocketsContextDisconnectConnectionsParams, notify?: boolean): Promise<IWebsocketsConnectionRegistryData[]>;
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsContext.ts"],"sourcesContent":["import type { IWebsocketsConnectionRegistry, IWebsocketsConnectionRegistryData } from \"~/registry\";\nimport type { IWebsocketsTransportSendConnection, IWebsocketsTransportSendData } from \"~/transport\";\nimport type { SecurityIdentity } from \"@webiny/api-security/types\";\nimport type { GenericRecord } from \"@webiny/api/types\";\n\nexport type IWebsocketsIdentity = Pick<SecurityIdentity, \"id\" | \"displayName\" | \"type\">;\n\nexport interface IWebsocketsContextListConnectionsParamsWhere {\n identityId?: string;\n tenant?: string;\n locale?: string;\n connections?: string[];\n}\n\nexport interface IWebsocketsContextListConnectionsParams {\n where?: IWebsocketsContextListConnectionsParamsWhere;\n}\n\nexport type IWebsocketsContextDisconnectConnectionsParams = IWebsocketsContextListConnectionsParams;\n\nexport interface IWebsocketsContextObject {\n readonly registry: IWebsocketsConnectionRegistry;\n\n send<T extends GenericRecord = GenericRecord>(\n identity: Pick<IWebsocketsIdentity, \"id\">,\n data: IWebsocketsTransportSendData<T>\n ): Promise<void>;\n sendToConnections<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void>;\n listConnections(\n params?: IWebsocketsContextListConnectionsParams\n ): Promise<IWebsocketsConnectionRegistryData[]>;\n disconnect(\n params?: IWebsocketsContextDisconnectConnectionsParams,\n notify?: boolean\n ): Promise<IWebsocketsConnectionRegistryData[]>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/context/index.d.ts
DELETED
package/context/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
createWebsocketsContext: true
|
|
8
|
-
};
|
|
9
|
-
exports.createWebsocketsContext = void 0;
|
|
10
|
-
var _handler = require("@webiny/handler");
|
|
11
|
-
var _WebsocketsContext = require("./WebsocketsContext");
|
|
12
|
-
Object.keys(_WebsocketsContext).forEach(function (key) {
|
|
13
|
-
if (key === "default" || key === "__esModule") return;
|
|
14
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
-
if (key in exports && exports[key] === _WebsocketsContext[key]) return;
|
|
16
|
-
Object.defineProperty(exports, key, {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () {
|
|
19
|
-
return _WebsocketsContext[key];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
var _registry = require("../registry");
|
|
24
|
-
var _transport = require("../transport");
|
|
25
|
-
var _IWebsocketsContext = require("./abstractions/IWebsocketsContext");
|
|
26
|
-
Object.keys(_IWebsocketsContext).forEach(function (key) {
|
|
27
|
-
if (key === "default" || key === "__esModule") return;
|
|
28
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
29
|
-
if (key in exports && exports[key] === _IWebsocketsContext[key]) return;
|
|
30
|
-
Object.defineProperty(exports, key, {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _IWebsocketsContext[key];
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
const createWebsocketsContext = () => {
|
|
38
|
-
const plugin = new _handler.ContextPlugin(async context => {
|
|
39
|
-
/**
|
|
40
|
-
* TODO Find a better way to send the documentClient to the registry.
|
|
41
|
-
*/
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
const documentClient = context.db.driver.documentClient;
|
|
44
|
-
const registry = new _registry.WebsocketsConnectionRegistry(documentClient);
|
|
45
|
-
const transport = new _transport.WebsocketsTransport();
|
|
46
|
-
context.websockets = new _WebsocketsContext.WebsocketsContext(registry, transport);
|
|
47
|
-
});
|
|
48
|
-
plugin.name = "websockets.context";
|
|
49
|
-
return plugin;
|
|
50
|
-
};
|
|
51
|
-
exports.createWebsocketsContext = createWebsocketsContext;
|
|
52
|
-
|
|
53
|
-
//# sourceMappingURL=index.js.map
|
package/context/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_handler","require","_WebsocketsContext","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_registry","_transport","_IWebsocketsContext","createWebsocketsContext","plugin","ContextPlugin","context","documentClient","db","driver","registry","WebsocketsConnectionRegistry","transport","WebsocketsTransport","websockets","WebsocketsContext","name"],"sources":["index.ts"],"sourcesContent":["import { ContextPlugin } from \"@webiny/handler\";\nimport type { Context } from \"~/types\";\nimport { WebsocketsContext } from \"./WebsocketsContext\";\nimport { WebsocketsConnectionRegistry } from \"~/registry\";\nimport { WebsocketsTransport } from \"~/transport\";\n\nexport * from \"./WebsocketsContext\";\nexport * from \"./abstractions/IWebsocketsContext\";\n\nexport const createWebsocketsContext = () => {\n const plugin = new ContextPlugin<Context>(async context => {\n /**\n * TODO Find a better way to send the documentClient to the registry.\n */\n // @ts-expect-error\n const documentClient = context.db.driver.documentClient;\n const registry = new WebsocketsConnectionRegistry(documentClient);\n const transport = new WebsocketsTransport();\n context.websockets = new WebsocketsContext(registry, transport);\n });\n\n plugin.name = \"websockets.context\";\n\n return plugin;\n};\n"],"mappings":";;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,kBAAA,GAAAD,OAAA;AAIAE,MAAA,CAAAC,IAAA,CAAAF,kBAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,kBAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,kBAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAHA,IAAAS,SAAA,GAAAd,OAAA;AACA,IAAAe,UAAA,GAAAf,OAAA;AAGA,IAAAgB,mBAAA,GAAAhB,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAa,mBAAA,EAAAZ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAW,mBAAA,CAAAX,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,mBAAA,CAAAX,GAAA;IAAA;EAAA;AAAA;AAEO,MAAMY,uBAAuB,GAAGA,CAAA,KAAM;EACzC,MAAMC,MAAM,GAAG,IAAIC,sBAAa,CAAU,MAAMC,OAAO,IAAI;IACvD;AACR;AACA;IACQ;IACA,MAAMC,cAAc,GAAGD,OAAO,CAACE,EAAE,CAACC,MAAM,CAACF,cAAc;IACvD,MAAMG,QAAQ,GAAG,IAAIC,sCAA4B,CAACJ,cAAc,CAAC;IACjE,MAAMK,SAAS,GAAG,IAAIC,8BAAmB,CAAC,CAAC;IAC3CP,OAAO,CAACQ,UAAU,GAAG,IAAIC,oCAAiB,CAACL,QAAQ,EAAEE,SAAS,CAAC;EACnE,CAAC,CAAC;EAEFR,MAAM,CAACY,IAAI,GAAG,oBAAoB;EAElC,OAAOZ,MAAM;AACjB,CAAC;AAACR,OAAA,CAAAO,uBAAA,GAAAA,uBAAA","ignoreList":[]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.checkPermissions = void 0;
|
|
7
|
-
var _apiSecurity = require("@webiny/api-security");
|
|
8
|
-
/**
|
|
9
|
-
* Simple permission check. Only full access can access the websockets API via GraphQL - ({name: "*"})
|
|
10
|
-
*
|
|
11
|
-
* @throws
|
|
12
|
-
*/
|
|
13
|
-
const checkPermissions = async context => {
|
|
14
|
-
const permissions = await context.security.getPermissions("websockets");
|
|
15
|
-
if (permissions.length === 0) {
|
|
16
|
-
throw new _apiSecurity.NotAuthorizedError();
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
exports.checkPermissions = checkPermissions;
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=checkPermissions.js.map
|