@webiny/api-websockets 6.3.0-beta.4 → 6.4.0-beta.0
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/context/WebsocketsContext.js +57 -72
- package/context/WebsocketsContext.js.map +1 -1
- package/context/abstractions/IWebsocketsContext.js +0 -3
- package/context/index.js +12 -15
- package/context/index.js.map +1 -1
- package/exports/api.d.ts +1 -0
- package/exports/api.js +5 -0
- package/exports/api.js.map +1 -0
- package/features/WebsocketService/abstractions.js +2 -1
- package/features/WebsocketService/abstractions.js.map +1 -1
- package/features/WebsocketService/errors.js +28 -30
- package/features/WebsocketService/errors.js.map +1 -1
- package/features/WebsocketService/index.js +0 -2
- package/graphql/checkPermissions.js +5 -11
- package/graphql/checkPermissions.js.map +1 -1
- package/graphql/createResolvers.js +55 -76
- package/graphql/createResolvers.js.map +1 -1
- package/graphql/createTypeDefs.js +2 -3
- package/graphql/createTypeDefs.js.map +1 -1
- package/graphql/index.js +8 -7
- package/graphql/index.js.map +1 -1
- package/graphql/utils.js +8 -7
- package/graphql/utils.js.map +1 -1
- package/handler/handler.js +58 -66
- package/handler/handler.js.map +1 -1
- package/handler/headers.js +21 -28
- package/handler/headers.js.map +1 -1
- package/handler/register.js +9 -19
- package/handler/register.js.map +1 -1
- package/handler/types.js +11 -10
- package/handler/types.js.map +1 -1
- package/index.js +5 -3
- package/index.js.map +1 -1
- package/package.json +20 -20
- package/plugins/WebsocketsActionPlugin.js +14 -13
- package/plugins/WebsocketsActionPlugin.js.map +1 -1
- package/plugins/WebsocketsRoutePlugin.js +14 -13
- package/plugins/WebsocketsRoutePlugin.js.map +1 -1
- package/plugins/abstrations/IWebsocketsActionPlugin.js +0 -3
- package/plugins/index.js +0 -2
- package/registry/WebsocketsConnectionRegistry.js +107 -146
- package/registry/WebsocketsConnectionRegistry.js.map +1 -1
- package/registry/abstractions/IWebsocketsConnectionRegistry.js +0 -3
- package/registry/entity.js +44 -43
- package/registry/entity.js.map +1 -1
- package/registry/index.js +0 -2
- package/response/WebsocketsResponse.js +20 -19
- package/response/WebsocketsResponse.js.map +1 -1
- package/response/abstractions/IWebsocketsResponse.js +0 -3
- package/response/index.js +0 -2
- package/runner/WebsocketsRunner.js +137 -164
- package/runner/WebsocketsRunner.js.map +1 -1
- package/runner/abstractions/IWebsocketsRunner.js +0 -3
- package/runner/index.js +0 -2
- package/runner/routes/connect.js +30 -40
- package/runner/routes/connect.js.map +1 -1
- package/runner/routes/default.js +16 -22
- package/runner/routes/default.js.map +1 -1
- package/runner/routes/disconnect.js +10 -13
- package/runner/routes/disconnect.js.map +1 -1
- package/runner/routes/index.js +6 -3
- package/runner/routes/index.js.map +1 -1
- package/transport/WebsocketsTransport.js +36 -39
- package/transport/WebsocketsTransport.js.map +1 -1
- package/transport/abstractions/IWebsocketsTransport.js +0 -3
- package/transport/index.js +0 -2
- package/types.js +0 -3
- package/utils/middleware.js +9 -14
- package/utils/middleware.js.map +1 -1
- package/validator/WebsocketsEventValidator.js +55 -63
- package/validator/WebsocketsEventValidator.js.map +1 -1
- package/validator/abstractions/IWebsocketsEventValidator.js +0 -3
- package/validator/index.js +0 -2
- package/context/abstractions/IWebsocketsContext.js.map +0 -1
- package/features/WebsocketService/index.js.map +0 -1
- package/plugins/abstrations/IWebsocketsActionPlugin.js.map +0 -1
- package/plugins/index.js.map +0 -1
- package/registry/abstractions/IWebsocketsConnectionRegistry.js.map +0 -1
- package/registry/index.js.map +0 -1
- package/response/abstractions/IWebsocketsResponse.js.map +0 -1
- package/response/index.js.map +0 -1
- package/runner/abstractions/IWebsocketsRunner.js.map +0 -1
- package/runner/index.js.map +0 -1
- package/transport/abstractions/IWebsocketsTransport.js.map +0 -1
- package/transport/index.js.map +0 -1
- package/types.js.map +0 -1
- package/validator/abstractions/IWebsocketsEventValidator.js.map +0 -1
- package/validator/index.js.map +0 -1
|
@@ -1,47 +1,44 @@
|
|
|
1
1
|
import { ApiGatewayManagementApiClient, DeleteConnectionCommand, PostToConnectionCommand } from "@webiny/aws-sdk/client-apigatewaymanagementapi/index.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
2
|
+
class WebsocketsTransport {
|
|
3
|
+
async send(connections, data) {
|
|
4
|
+
for (const connection of connections)try {
|
|
5
|
+
const client = this.getClient(connection);
|
|
6
|
+
const command = new PostToConnectionCommand({
|
|
7
|
+
ConnectionId: connection.connectionId,
|
|
8
|
+
Data: JSON.stringify(data)
|
|
9
|
+
});
|
|
10
|
+
await client.send(command);
|
|
11
|
+
} catch (ex) {
|
|
12
|
+
console.error(`Failed to send message to connection "${connection.connectionId}". Check logs for more information.`);
|
|
13
|
+
console.log(ex);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
async disconnect(connections) {
|
|
17
|
+
for (const connection of connections)try {
|
|
18
|
+
const client = this.getClient(connection);
|
|
19
|
+
const command = new DeleteConnectionCommand({
|
|
20
|
+
ConnectionId: connection.connectionId
|
|
21
|
+
});
|
|
22
|
+
await client.send(command);
|
|
23
|
+
} catch (ex) {
|
|
24
|
+
console.error(`Failed to disconnect connection "${connection.connectionId}". Check logs for more information.`);
|
|
25
|
+
console.log(ex);
|
|
26
|
+
}
|
|
17
27
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
ConnectionId: connection.connectionId
|
|
28
|
+
getClient(connection) {
|
|
29
|
+
const endpoint = `https://${connection.domainName}/${connection.stage}`;
|
|
30
|
+
const client = this.clients.get(endpoint);
|
|
31
|
+
if (client) return client;
|
|
32
|
+
const newClient = new ApiGatewayManagementApiClient({
|
|
33
|
+
endpoint
|
|
25
34
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.error(`Failed to disconnect connection "${connection.connectionId}". Check logs for more information.`);
|
|
29
|
-
console.log(ex);
|
|
30
|
-
}
|
|
35
|
+
this.clients.set(endpoint, newClient);
|
|
36
|
+
return newClient;
|
|
31
37
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const endpoint = `https://${connection.domainName}/${connection.stage}`;
|
|
35
|
-
const client = this.clients.get(endpoint);
|
|
36
|
-
if (client) {
|
|
37
|
-
return client;
|
|
38
|
+
constructor(){
|
|
39
|
+
this.clients = new Map();
|
|
38
40
|
}
|
|
39
|
-
const newClient = new ApiGatewayManagementApiClient({
|
|
40
|
-
endpoint
|
|
41
|
-
});
|
|
42
|
-
this.clients.set(endpoint, newClient);
|
|
43
|
-
return newClient;
|
|
44
|
-
}
|
|
45
41
|
}
|
|
42
|
+
export { WebsocketsTransport };
|
|
46
43
|
|
|
47
44
|
//# sourceMappingURL=WebsocketsTransport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"transport/WebsocketsTransport.js","sources":["../../src/transport/WebsocketsTransport.ts"],"sourcesContent":["import {\n ApiGatewayManagementApiClient,\n DeleteConnectionCommand,\n PostToConnectionCommand\n} from \"@webiny/aws-sdk/client-apigatewaymanagementapi/index.js\";\nimport type {\n IWebsocketsTransport,\n IWebsocketsTransportDisconnectConnection,\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"./abstractions/IWebsocketsTransport.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport class WebsocketsTransport implements IWebsocketsTransport {\n private readonly clients = new Map<string, ApiGatewayManagementApiClient>();\n\n public async send<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<void> {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\n\n const command = new PostToConnectionCommand({\n ConnectionId: connection.connectionId,\n Data: JSON.stringify(data)\n });\n await client.send(command);\n } catch (ex) {\n console.error(\n `Failed to send message to connection \"${connection.connectionId}\". Check logs for more information.`\n );\n console.log(ex);\n }\n }\n }\n\n public async disconnect(connections: IWebsocketsTransportDisconnectConnection[]) {\n for (const connection of connections) {\n try {\n const client = this.getClient(connection);\n const command = new DeleteConnectionCommand({\n ConnectionId: connection.connectionId\n });\n await client.send(command);\n } catch (ex) {\n console.error(\n `Failed to disconnect connection \"${connection.connectionId}\". Check logs for more information.`\n );\n console.log(ex);\n }\n }\n }\n\n private getClient(\n connection: IWebsocketsTransportSendConnection\n ): ApiGatewayManagementApiClient {\n const endpoint = `https://${connection.domainName}/${connection.stage}`;\n const client = this.clients.get(endpoint);\n if (client) {\n return client;\n }\n const newClient = new ApiGatewayManagementApiClient({\n endpoint\n });\n this.clients.set(endpoint, newClient);\n return newClient;\n }\n}\n"],"names":["WebsocketsTransport","connections","data","connection","client","command","PostToConnectionCommand","JSON","ex","console","DeleteConnectionCommand","endpoint","newClient","ApiGatewayManagementApiClient","Map"],"mappings":";AAaO,MAAMA;IAGT,MAAa,KACTC,WAAiD,EACjDC,IAAqC,EACxB;QACb,KAAK,MAAMC,cAAcF,YACrB,IAAI;YACA,MAAMG,SAAS,IAAI,CAAC,SAAS,CAACD;YAE9B,MAAME,UAAU,IAAIC,wBAAwB;gBACxC,cAAcH,WAAW,YAAY;gBACrC,MAAMI,KAAK,SAAS,CAACL;YACzB;YACA,MAAME,OAAO,IAAI,CAACC;QACtB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CACT,CAAC,sCAAsC,EAAEN,WAAW,YAAY,CAAC,mCAAmC,CAAC;YAEzGM,QAAQ,GAAG,CAACD;QAChB;IAER;IAEA,MAAa,WAAWP,WAAuD,EAAE;QAC7E,KAAK,MAAME,cAAcF,YACrB,IAAI;YACA,MAAMG,SAAS,IAAI,CAAC,SAAS,CAACD;YAC9B,MAAME,UAAU,IAAIK,wBAAwB;gBACxC,cAAcP,WAAW,YAAY;YACzC;YACA,MAAMC,OAAO,IAAI,CAACC;QACtB,EAAE,OAAOG,IAAI;YACTC,QAAQ,KAAK,CACT,CAAC,iCAAiC,EAAEN,WAAW,YAAY,CAAC,mCAAmC,CAAC;YAEpGM,QAAQ,GAAG,CAACD;QAChB;IAER;IAEQ,UACJL,UAA8C,EACjB;QAC7B,MAAMQ,WAAW,CAAC,QAAQ,EAAER,WAAW,UAAU,CAAC,CAAC,EAAEA,WAAW,KAAK,EAAE;QACvE,MAAMC,SAAS,IAAI,CAAC,OAAO,CAAC,GAAG,CAACO;QAChC,IAAIP,QACA,OAAOA;QAEX,MAAMQ,YAAY,IAAIC,8BAA8B;YAChDF;QACJ;QACA,IAAI,CAAC,OAAO,CAAC,GAAG,CAACA,UAAUC;QAC3B,OAAOA;IACX;;aAtDiB,OAAO,GAAG,IAAIE;;AAuDnC"}
|
package/transport/index.js
CHANGED
package/types.js
CHANGED
package/utils/middleware.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
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
|
+
};
|
|
10
9
|
return exec();
|
|
11
|
-
};
|
|
12
|
-
return fn(input, next);
|
|
13
10
|
};
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
};
|
|
11
|
+
export { middleware };
|
|
17
12
|
|
|
18
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"}
|
|
@@ -2,75 +2,67 @@ import zod from "zod";
|
|
|
2
2
|
import { WebsocketsEventRequestContextEventType } from "../handler/types.js";
|
|
3
3
|
import { createZodError } from "@webiny/utils";
|
|
4
4
|
const validation = zod.object({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
headers: zod.looseObject({}).optional(),
|
|
6
|
+
requestContext: zod.object({
|
|
7
|
+
connectionId: zod.string(),
|
|
8
|
+
stage: zod.string(),
|
|
9
|
+
connectedAt: zod.number(),
|
|
10
|
+
domainName: zod.string(),
|
|
11
|
+
eventType: zod["enum"]([
|
|
12
|
+
WebsocketsEventRequestContextEventType.connect,
|
|
13
|
+
WebsocketsEventRequestContextEventType.message,
|
|
14
|
+
WebsocketsEventRequestContextEventType.disconnect
|
|
15
|
+
]),
|
|
16
|
+
routeKey: zod.string()
|
|
17
|
+
}),
|
|
18
|
+
body: zod.string().transform((value, context)=>{
|
|
19
|
+
if (!value) return;
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(value);
|
|
22
|
+
} catch (ex) {
|
|
23
|
+
console.error(`Failed body validation: ${ex.message}`);
|
|
24
|
+
console.log(`Body: ${value}`);
|
|
25
|
+
context.addIssue({
|
|
26
|
+
path: [],
|
|
27
|
+
message: `Invalid JSON: ${ex.message}`,
|
|
28
|
+
code: zod.ZodIssueCode.custom,
|
|
29
|
+
fatal: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}).optional()
|
|
33
|
+
}).superRefine((output, context)=>{
|
|
34
|
+
if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) return;
|
|
35
|
+
if (output.body) return;
|
|
36
|
+
context.addIssue({
|
|
37
|
+
path: [
|
|
38
|
+
"body"
|
|
39
|
+
],
|
|
40
|
+
message: "There must be a body defined when having a message event.",
|
|
32
41
|
code: zod.ZodIssueCode.custom,
|
|
33
42
|
fatal: true
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}).optional()
|
|
37
|
-
}).superRefine((output, context) => {
|
|
38
|
-
if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) {
|
|
39
|
-
return;
|
|
40
|
-
} else if (output.body) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
context.addIssue({
|
|
44
|
-
path: ["body"],
|
|
45
|
-
message: "There must be a body defined when having a message event.",
|
|
46
|
-
code: zod.ZodIssueCode.custom,
|
|
47
|
-
fatal: true
|
|
48
|
-
});
|
|
43
|
+
});
|
|
49
44
|
});
|
|
50
45
|
const bodyValidation = zod.looseObject({
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
token: zod.string(),
|
|
47
|
+
tenant: zod.string(),
|
|
48
|
+
messageId: zod.string().nullish(),
|
|
49
|
+
action: zod.string(),
|
|
50
|
+
data: zod.looseObject({}).nullish()
|
|
56
51
|
}).optional();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
class WebsocketsEventValidator {
|
|
53
|
+
async validate(input) {
|
|
54
|
+
const result = await validation.safeParseAsync(input);
|
|
55
|
+
if (!result.success) throw createZodError(result.error);
|
|
56
|
+
const bodyResult = await bodyValidation.safeParseAsync(result.data.body);
|
|
57
|
+
if (!bodyResult.success) throw createZodError(bodyResult.error);
|
|
58
|
+
return {
|
|
59
|
+
...result.data,
|
|
60
|
+
body: {
|
|
61
|
+
...bodyResult.data || {}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
66
64
|
}
|
|
67
|
-
return {
|
|
68
|
-
...result.data,
|
|
69
|
-
body: {
|
|
70
|
-
...(bodyResult.data || {})
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
65
|
}
|
|
66
|
+
export { WebsocketsEventValidator };
|
|
75
67
|
|
|
76
68
|
//# sourceMappingURL=WebsocketsEventValidator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"validator/WebsocketsEventValidator.js","sources":["../../src/validator/WebsocketsEventValidator.ts"],"sourcesContent":["import zod from \"zod\";\nimport type { IWebsocketsEvent, IWebsocketsEventData } from \"~/handler/types.js\";\nimport { WebsocketsEventRequestContextEventType } from \"~/handler/types.js\";\nimport type {\n IWebsocketsEventValidator,\n IWebsocketsEventValidatorValidateParams\n} from \"./abstractions/IWebsocketsEventValidator.js\";\nimport { createZodError } from \"@webiny/utils\";\n\nconst validation = zod\n .object({\n headers: zod.looseObject({}).optional(),\n requestContext: zod.object({\n connectionId: zod.string(),\n stage: zod.string(),\n connectedAt: zod.number(),\n domainName: zod.string(),\n eventType: zod.enum([\n WebsocketsEventRequestContextEventType.connect,\n WebsocketsEventRequestContextEventType.message,\n WebsocketsEventRequestContextEventType.disconnect\n ]),\n routeKey: zod.string()\n }),\n body: zod\n .string()\n .transform<IWebsocketsEventData>((value, context) => {\n if (!value) {\n return undefined;\n }\n try {\n return JSON.parse(value);\n } catch (ex) {\n /**\n * We want to log the error, for easier debugging.\n */\n console.error(`Failed body validation: ${ex.message}`);\n console.log(`Body: ${value}`);\n /**\n * And we want to add an issue to the context, so that the user knows what went wrong.\n */\n context.addIssue({\n path: [],\n message: `Invalid JSON: ${ex.message}`,\n code: zod.ZodIssueCode.custom,\n fatal: true\n });\n }\n })\n .optional()\n })\n .superRefine((output, context) => {\n if (output.requestContext.eventType !== WebsocketsEventRequestContextEventType.message) {\n return;\n } else if (output.body) {\n return;\n }\n context.addIssue({\n path: [\"body\"],\n message: \"There must be a body defined when having a message event.\",\n code: zod.ZodIssueCode.custom,\n fatal: true\n });\n });\n\nconst bodyValidation = zod\n .looseObject({\n token: zod.string(),\n tenant: zod.string(),\n messageId: zod.string().nullish(),\n action: zod.string(),\n data: zod.looseObject({}).nullish()\n })\n .optional();\n\nexport class WebsocketsEventValidator implements IWebsocketsEventValidator {\n public async validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n input: IWebsocketsEventValidatorValidateParams\n ): Promise<IWebsocketsEvent<T>> {\n const result = await validation.safeParseAsync(input);\n if (!result.success) {\n throw createZodError(result.error);\n }\n const bodyResult = await bodyValidation.safeParseAsync(result.data.body);\n if (!bodyResult.success) {\n throw createZodError(bodyResult.error);\n }\n return {\n ...result.data,\n body: {\n ...((bodyResult.data || {}) as T)\n }\n };\n }\n}\n"],"names":["validation","zod","WebsocketsEventRequestContextEventType","value","context","JSON","ex","console","output","bodyValidation","WebsocketsEventValidator","input","result","createZodError","bodyResult"],"mappings":";;;AASA,MAAMA,aAAaC,IAAAA,MACR,CAAC;IACJ,SAASA,IAAI,WAAW,CAAC,CAAC,GAAG,QAAQ;IACrC,gBAAgBA,IAAI,MAAM,CAAC;QACvB,cAAcA,IAAI,MAAM;QACxB,OAAOA,IAAI,MAAM;QACjB,aAAaA,IAAI,MAAM;QACvB,YAAYA,IAAI,MAAM;QACtB,WAAWA,GAAG,CAAHA,OAAQ,CAAC;YAChBC,uCAAuC,OAAO;YAC9CA,uCAAuC,OAAO;YAC9CA,uCAAuC,UAAU;SACpD;QACD,UAAUD,IAAI,MAAM;IACxB;IACA,MAAMA,IAAAA,MACK,GACN,SAAS,CAAuB,CAACE,OAAOC;QACrC,IAAI,CAACD,OACD;QAEJ,IAAI;YACA,OAAOE,KAAK,KAAK,CAACF;QACtB,EAAE,OAAOG,IAAI;YAITC,QAAQ,KAAK,CAAC,CAAC,wBAAwB,EAAED,GAAG,OAAO,EAAE;YACrDC,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAEJ,OAAO;YAI5BC,QAAQ,QAAQ,CAAC;gBACb,MAAM,EAAE;gBACR,SAAS,CAAC,cAAc,EAAEE,GAAG,OAAO,EAAE;gBACtC,MAAML,IAAI,YAAY,CAAC,MAAM;gBAC7B,OAAO;YACX;QACJ;IACJ,GACC,QAAQ;AACjB,GACC,WAAW,CAAC,CAACO,QAAQJ;IAClB,IAAII,OAAO,cAAc,CAAC,SAAS,KAAKN,uCAAuC,OAAO,EAClF;IACG,IAAIM,OAAO,IAAI,EAClB;IAEJJ,QAAQ,QAAQ,CAAC;QACb,MAAM;YAAC;SAAO;QACd,SAAS;QACT,MAAMH,IAAI,YAAY,CAAC,MAAM;QAC7B,OAAO;IACX;AACJ;AAEJ,MAAMQ,iBAAiBR,IAAAA,WACP,CAAC;IACT,OAAOA,IAAI,MAAM;IACjB,QAAQA,IAAI,MAAM;IAClB,WAAWA,IAAI,MAAM,GAAG,OAAO;IAC/B,QAAQA,IAAI,MAAM;IAClB,MAAMA,IAAI,WAAW,CAAC,CAAC,GAAG,OAAO;AACrC,GACC,QAAQ;AAEN,MAAMS;IACT,MAAa,SACTC,KAA8C,EAClB;QAC5B,MAAMC,SAAS,MAAMZ,WAAW,cAAc,CAACW;QAC/C,IAAI,CAACC,OAAO,OAAO,EACf,MAAMC,eAAeD,OAAO,KAAK;QAErC,MAAME,aAAa,MAAML,eAAe,cAAc,CAACG,OAAO,IAAI,CAAC,IAAI;QACvE,IAAI,CAACE,WAAW,OAAO,EACnB,MAAMD,eAAeC,WAAW,KAAK;QAEzC,OAAO;YACH,GAAGF,OAAO,IAAI;YACd,MAAM;gBACF,GAAKE,WAAW,IAAI,IAAI,CAAC,CAAC;YAC9B;QACJ;IACJ;AACJ"}
|
package/validator/index.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsContext.ts"],"sourcesContent":["import type {\n IWebsocketsConnectionRegistry,\n IWebsocketsConnectionRegistryData\n} from \"~/registry/index.js\";\nimport type {\n IWebsocketsTransportSendConnection,\n IWebsocketsTransportSendData\n} from \"~/transport/index.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { SecurityIdentity } from \"@webiny/api-core/types/security.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { WebsocketService } from \"~/features/WebsocketService/abstractions.js\";\n\nexport type IWebsocketsIdentity = Pick<SecurityIdentity, \"id\" | \"displayName\" | \"type\">;\n\nexport interface IWebsocketsContextListConnectionsParamsWhere {\n identityId?: string;\n tenant?: 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<Result<void, WebsocketService.Error>>;\n sendToConnections<T extends GenericRecord = GenericRecord>(\n connections: IWebsocketsTransportSendConnection[],\n data: IWebsocketsTransportSendData<T>\n ): Promise<Result<void, WebsocketService.Error>>;\n listConnections(\n params?: IWebsocketsContextListConnectionsParams\n ): Promise<Result<IWebsocketsConnectionRegistryData[], WebsocketService.Error>>;\n disconnect(\n params?: IWebsocketsContextDisconnectConnectionsParams,\n notify?: boolean\n ): Promise<Result<IWebsocketsConnectionRegistryData[], WebsocketService.Error>>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["WebsocketService"],"sources":["index.ts"],"sourcesContent":["export { WebsocketService } from \"./abstractions.js\";\n"],"mappings":"AAAA,SAASA,gBAAgB","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsActionPlugin.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { Context } from \"~/types.js\";\n\nexport interface IWebsocketsActionPluginCallableParamsSend {\n toConnection<T extends GenericRecord = GenericRecord>(\n connectionId: string,\n data: T\n ): Promise<void>;\n toTenant<T extends GenericRecord = GenericRecord>(tenant: string, data: T): Promise<void>;\n toIdentity<T extends GenericRecord = GenericRecord>(identity: string, data: T): Promise<void>;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondError<\n T extends GenericRecord = GenericRecord\n> {\n message: string;\n code: string;\n data: T;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondOkResponse<\n T extends GenericRecord = GenericRecord\n> {\n data: T;\n error?: never;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespondErrorResponse<\n T extends GenericRecord = GenericRecord\n> {\n error: IWebsocketsActionPluginCallableParamsRespondError<T>;\n data?: never;\n}\n\nexport interface IWebsocketsActionPluginCallableParamsRespond {\n ok<T extends GenericRecord = GenericRecord>(\n data: T\n ): Promise<IWebsocketsActionPluginCallableParamsRespondOkResponse<T>>;\n error<T extends GenericRecord = GenericRecord>(\n error: IWebsocketsActionPluginCallableParamsRespondError<T>\n ): Promise<IWebsocketsActionPluginCallableParamsRespondErrorResponse<T>>;\n}\n\nexport interface IWebsocketsActionPluginCallableParams<C extends Context = Context> {\n context: C;\n next(): Promise<void>;\n send: IWebsocketsActionPluginCallableParamsSend;\n respond: IWebsocketsActionPluginCallableParamsRespond;\n}\n\nexport type WebsocketsActionPluginCallableResponse<T extends GenericRecord = GenericRecord> =\n | IWebsocketsActionPluginCallableParamsRespondOkResponse<T>\n | IWebsocketsActionPluginCallableParamsRespondErrorResponse<T>;\n\nexport interface IWebsocketsActionPluginCallable<T extends GenericRecord = GenericRecord> {\n (\n params: IWebsocketsActionPluginCallableParams\n ): Promise<WebsocketsActionPluginCallableResponse<T>>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/plugins/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./WebsocketsRoutePlugin.js\";\nexport * from \"./WebsocketsActionPlugin.js\";\nexport type * from \"./abstrations/IWebsocketsActionPlugin.js\";\n"],"mappings":"AAAA;AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsConnectionRegistry.ts"],"sourcesContent":["import type { IWebsocketsIdentity } from \"~/context/abstractions/IWebsocketsContext.js\";\n\nexport interface IWebsocketsConnectionRegistryData {\n connectionId: string;\n identity: IWebsocketsIdentity;\n tenant: string;\n connectedOn: string;\n domainName: string;\n stage: string;\n}\n\nexport interface IWebsocketsConnectionRegistryRegisterParams {\n connectionId: string;\n tenant: string;\n identity: IWebsocketsIdentity;\n domainName: string;\n stage: string;\n /**\n * A DateTime.toISOString() format.\n */\n connectedOn: string;\n}\n\nexport interface IWebsocketsConnectionRegistryUnregisterParams {\n connectionId: string;\n}\n\nexport interface IWebsocketsConnectionRegistry {\n register(\n event: IWebsocketsConnectionRegistryRegisterParams\n ): Promise<IWebsocketsConnectionRegistryData>;\n unregister(event: IWebsocketsConnectionRegistryUnregisterParams): Promise<void>;\n\n listViaConnections(connections: string[]): Promise<IWebsocketsConnectionRegistryData[]>;\n listViaIdentity(identity: string): Promise<IWebsocketsConnectionRegistryData[]>;\n listViaTenant(tenant: string): Promise<IWebsocketsConnectionRegistryData[]>;\n listAll(): Promise<IWebsocketsConnectionRegistryData[]>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/registry/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsConnectionRegistry.js\";\nexport * from \"./WebsocketsConnectionRegistry.js\";\n"],"mappings":"AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsResponse.ts"],"sourcesContent":["import 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"],"mappings":"","ignoreList":[]}
|
package/response/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsResponse.js\";\nexport * from \"./WebsocketsResponse.js\";\n"],"mappings":"AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsRunner.ts"],"sourcesContent":["import type { IWebsocketsIncomingEvent } from \"~/handler/types.js\";\nimport type { GenericRecord } from \"@webiny/api/types.js\";\n\nexport interface IWebsocketsResponseError {\n message: string;\n code: string;\n data?: GenericRecord<string> | null;\n stack?: string;\n}\nexport interface IWebsocketsRunnerResponse {\n statusCode: number;\n message?: string;\n error?: IWebsocketsResponseError;\n}\n\nexport interface IWebsocketsRunner {\n run(params: IWebsocketsIncomingEvent): Promise<IWebsocketsRunnerResponse>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/runner/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsRunner.js\";\nexport * from \"./WebsocketsRunner.js\";\n"],"mappings":"AACA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsTransport.ts"],"sourcesContent":["import type { GenericRecord } from \"@webiny/api/types.js\";\nimport type { IWebsocketsConnectionRegistryData } from \"~/registry/index.js\";\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 type IWebsocketsTransportSendConnection = Pick<\n IWebsocketsConnectionRegistryData,\n \"connectionId\" | \"domainName\" | \"stage\"\n>;\n\nexport type IWebsocketsTransportDisconnectConnection = Pick<\n IWebsocketsConnectionRegistryData,\n \"connectionId\" | \"domainName\" | \"stage\"\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"],"mappings":"","ignoreList":[]}
|
package/transport/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./WebsocketsTransport.js\";\nexport type * from \"./abstractions/IWebsocketsTransport.js\";\n"],"mappings":"AAAA","ignoreList":[]}
|
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type { DbContext } from \"@webiny/handler-db/types.js\";\nimport type { IWebsocketsContextObject } from \"./context/abstractions/IWebsocketsContext.js\";\nimport type { ApiCoreContext } from \"@webiny/api-core/types/core.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\n\nexport type { IWebsocketsContextObject };\n\nexport interface Context extends DbContext, ApiCoreContext {\n websockets: IWebsocketsContextObject;\n}\n\nexport interface WebsocketsPermission extends SecurityPermission {\n name: \"websockets\";\n rwd?: string;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["IWebsocketsEventValidator.ts"],"sourcesContent":["import type {\n IWebsocketsEvent,\n IWebsocketsEventData,\n IWebsocketsIncomingEvent\n} from \"~/handler/types.js\";\n\nexport type IWebsocketsEventValidatorValidateParams = IWebsocketsIncomingEvent;\n\nexport interface IWebsocketsEventValidator {\n /**\n * @throws {Error}\n */\n validate<T extends IWebsocketsEventData = IWebsocketsEventData>(\n params: IWebsocketsEventValidatorValidateParams\n ): Promise<IWebsocketsEvent<T>>;\n}\n"],"mappings":"","ignoreList":[]}
|
package/validator/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export type * from \"./abstractions/IWebsocketsEventValidator.js\";\nexport * from \"./WebsocketsEventValidator.js\";\n"],"mappings":"AACA","ignoreList":[]}
|