@privateaim/messenger-kit 0.7.5 → 0.7.7
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/CHANGELOG.md +33 -0
- package/dist/index.cjs +74 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +73 -1
- package/dist/index.mjs.map +1 -1
- package/dist/messaging/index.d.ts +1 -0
- package/dist/messaging/index.d.ts.map +1 -1
- package/dist/messaging/types.d.ts +9 -9
- package/dist/messaging/types.d.ts.map +1 -1
- package/dist/messaging/validators/index.d.ts +3 -0
- package/dist/messaging/validators/index.d.ts.map +1 -0
- package/dist/messaging/validators/message.d.ts +6 -0
- package/dist/messaging/validators/message.d.ts.map +1 -0
- package/dist/messaging/validators/to.d.ts +6 -0
- package/dist/messaging/validators/to.d.ts.map +1 -0
- package/package.json +11 -4
- package/src/messaging/index.ts +1 -0
- package/src/messaging/types.ts +9 -9
- package/src/messaging/validators/index.ts +9 -0
- package/src/messaging/validators/message.ts +54 -0
- package/src/messaging/validators/to.ts +31 -0
- package/test/jest.config.js +33 -0
- package/test/unit/messaging.spec.ts +66 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.7](https://github.com/PrivateAIM/hub/compare/v0.7.6...v0.7.7) (2025-03-04)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* realtime library/service split ([#474](https://github.com/PrivateAIM/hub/issues/474)) ([43c2dfa](https://github.com/PrivateAIM/hub/commit/43c2dfad654cc61ca9784914cbad56c684434088))
|
|
9
|
+
* validate client-to-server messaging message ([a37cbc4](https://github.com/PrivateAIM/hub/commit/a37cbc4582ac66190aa4aad9a78aca58d34526f4))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Dependencies
|
|
13
|
+
|
|
14
|
+
* The following workspace dependencies were updated
|
|
15
|
+
* devDependencies
|
|
16
|
+
* @privateaim/core-kit bumped from ^0.8.5 to ^0.8.6
|
|
17
|
+
* peerDependencies
|
|
18
|
+
* @privateaim/core-kit bumped from ^0.8.5 to ^0.8.6
|
|
19
|
+
|
|
20
|
+
## [0.7.6](https://github.com/PrivateAIM/hub/compare/v0.7.5...v0.7.6) (2025-01-22)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
|
|
25
|
+
* realtime library/service split ([#474](https://github.com/PrivateAIM/hub/issues/474)) ([43c2dfa](https://github.com/PrivateAIM/hub/commit/43c2dfad654cc61ca9784914cbad56c684434088))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
* The following workspace dependencies were updated
|
|
31
|
+
* devDependencies
|
|
32
|
+
* @privateaim/core-kit bumped from ^0.8.4 to ^0.8.5
|
|
33
|
+
* peerDependencies
|
|
34
|
+
* @privateaim/core-kit bumped from ^0.8.4 to ^0.8.5
|
|
35
|
+
|
|
3
36
|
## [0.7.5](https://github.com/PrivateAIM/hub/compare/v0.7.4...v0.7.5) (2024-10-24)
|
|
4
37
|
|
|
5
38
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var adapterZod = require('@validup/adapter-zod');
|
|
5
|
+
var validup = require('validup');
|
|
6
|
+
|
|
3
7
|
/*
|
|
4
8
|
* Copyright (c) 2024.
|
|
5
9
|
* Author Peter Placzek (tada5hi)
|
|
@@ -36,6 +40,74 @@ var CTSMessagingEventName = /*#__PURE__*/ function(CTSMessagingEventName) {
|
|
|
36
40
|
return CTSMessagingEventName;
|
|
37
41
|
}({});
|
|
38
42
|
|
|
43
|
+
class CTSMessagingPartyValidator extends validup.Container {
|
|
44
|
+
initialize() {
|
|
45
|
+
super.initialize();
|
|
46
|
+
this.mount('id', adapterZod.createValidator(zod.z.string().uuid()));
|
|
47
|
+
this.mount('type', adapterZod.createValidator(zod.z.enum([
|
|
48
|
+
'user',
|
|
49
|
+
'robot',
|
|
50
|
+
'client'
|
|
51
|
+
])));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* Copyright (c) 2025.
|
|
57
|
+
* Author Peter Placzek (tada5hi)
|
|
58
|
+
* For the full copyright and license information,
|
|
59
|
+
* view the LICENSE file that was distributed with this source code.
|
|
60
|
+
*/ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
61
|
+
try {
|
|
62
|
+
var info = gen[key](arg);
|
|
63
|
+
var value = info.value;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
reject(error);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (info.done) {
|
|
69
|
+
resolve(value);
|
|
70
|
+
} else {
|
|
71
|
+
Promise.resolve(value).then(_next, _throw);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function _async_to_generator(fn) {
|
|
75
|
+
return function() {
|
|
76
|
+
var self = this, args = arguments;
|
|
77
|
+
return new Promise(function(resolve, reject) {
|
|
78
|
+
var gen = fn.apply(self, args);
|
|
79
|
+
function _next(value) {
|
|
80
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
81
|
+
}
|
|
82
|
+
function _throw(err) {
|
|
83
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
84
|
+
}
|
|
85
|
+
_next(undefined);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
class CTSMessagingMessageValidator extends validup.Container {
|
|
90
|
+
initialize() {
|
|
91
|
+
super.initialize();
|
|
92
|
+
this.mount('data', adapterZod.createValidator(zod.z.object({}).passthrough().or(zod.z.string()).or(zod.z.null()).or(zod.z.undefined()).optional()));
|
|
93
|
+
this.mount('metadata', adapterZod.createValidator(zod.z.object({}).passthrough().or(zod.z.null()).or(zod.z.undefined()).optional()));
|
|
94
|
+
const partyValidator = new CTSMessagingPartyValidator();
|
|
95
|
+
this.mount('to', /*#__PURE__*/ function() {
|
|
96
|
+
var _ref = _async_to_generator(function*(ctx) {
|
|
97
|
+
const validator = adapterZod.createValidator(zod.z.array(zod.z.object({}).passthrough()));
|
|
98
|
+
const output = yield validator(ctx);
|
|
99
|
+
return Promise.all(output.map((el)=>partyValidator.run(el, {
|
|
100
|
+
path: ctx.pathAbsolute,
|
|
101
|
+
group: ctx.group
|
|
102
|
+
})));
|
|
103
|
+
});
|
|
104
|
+
return function(ctx) {
|
|
105
|
+
return _ref.apply(this, arguments);
|
|
106
|
+
};
|
|
107
|
+
}());
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
39
111
|
/*
|
|
40
112
|
* Copyright (c) 2021-2024.
|
|
41
113
|
* Author Peter Placzek (tada5hi)
|
|
@@ -53,6 +125,8 @@ function isEventTarget(input) {
|
|
|
53
125
|
|
|
54
126
|
exports.CTSConnectionEventName = CTSConnectionEventName;
|
|
55
127
|
exports.CTSMessagingEventName = CTSMessagingEventName;
|
|
128
|
+
exports.CTSMessagingMessageValidator = CTSMessagingMessageValidator;
|
|
129
|
+
exports.CTSMessagingPartyValidator = CTSMessagingPartyValidator;
|
|
56
130
|
exports.STCConnectionEventName = STCConnectionEventName;
|
|
57
131
|
exports.STCMessagingEventName = STCMessagingEventName;
|
|
58
132
|
exports.isEventCallback = isEventCallback;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/connection/constants.ts","../src/messaging/constants.ts","../src/utils.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCConnectionEventName {\n USER_CONNECTED = 'userConnected',\n USER_DISCONNECTED = 'userDisconnected',\n\n ROBOT_CONNECTED = 'robotConnected',\n ROBOT_DISCONNECTED = 'robotDisconnected',\n}\n\nexport enum CTSConnectionEventName {\n USER_CONNECTIONS = 'userConnections',\n USER_CONNECTION_SUBSCRIBE = 'userConnectionSubscribe',\n USER_CONNECTION_UNSUBSCRIBE = 'userConnectionUnsubscribe',\n\n ROBOT_CONNECTIONS = 'robotConnections',\n ROBOT_CONNECTION_SUBSCRIBE = 'robotConnectionSubscribe',\n ROBOT_CONNECTION_UNSUBSCRIBE = 'robotConnectionUnsubscribe',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCMessagingEventName {\n SEND = 'send',\n}\n\nexport enum CTSMessagingEventName {\n SEND = 'send',\n}\n","/*\n * Copyright (c) 2021-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventCallback } from './types';\n\nexport function isEventCallback(\n input: unknown,\n fnArgs?: number,\n) : input is EventCallback {\n if (typeof fnArgs === 'undefined') {\n return typeof input === 'function';\n }\n\n return typeof input === 'function' &&\n input.length >= fnArgs;\n}\n\nexport function isEventTarget(\n input: unknown,\n) : input is EventTarget {\n return typeof input === 'number' ||\n typeof input === 'string' ||\n typeof input === 'undefined';\n}\n"],"names":["STCConnectionEventName","CTSConnectionEventName","STCMessagingEventName","CTSMessagingEventName","isEventCallback","input","fnArgs","length","isEventTarget"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/connection/constants.ts","../src/messaging/constants.ts","../src/messaging/validators/to.ts","../src/messaging/validators/message.ts","../src/utils.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCConnectionEventName {\n USER_CONNECTED = 'userConnected',\n USER_DISCONNECTED = 'userDisconnected',\n\n ROBOT_CONNECTED = 'robotConnected',\n ROBOT_DISCONNECTED = 'robotDisconnected',\n}\n\nexport enum CTSConnectionEventName {\n USER_CONNECTIONS = 'userConnections',\n USER_CONNECTION_SUBSCRIBE = 'userConnectionSubscribe',\n USER_CONNECTION_UNSUBSCRIBE = 'userConnectionUnsubscribe',\n\n ROBOT_CONNECTIONS = 'robotConnections',\n ROBOT_CONNECTION_SUBSCRIBE = 'robotConnectionSubscribe',\n ROBOT_CONNECTION_UNSUBSCRIBE = 'robotConnectionUnsubscribe',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCMessagingEventName {\n SEND = 'send',\n}\n\nexport enum CTSMessagingEventName {\n SEND = 'send',\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { z } from 'zod';\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport type { CTSMessagingParty } from '../types';\n\nexport class CTSMessagingPartyValidator extends Container<CTSMessagingParty> {\n protected initialize() {\n super.initialize();\n\n this.mount(\n 'id',\n createValidator(\n z.string().uuid(),\n ),\n );\n\n this.mount(\n 'type',\n createValidator(\n z.enum(['user', 'robot', 'client']),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { z } from 'zod';\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport type { CTSMessagingMessage } from '../types';\nimport { CTSMessagingPartyValidator } from './to';\n\nexport class CTSMessagingMessageValidator extends Container<CTSMessagingMessage> {\n protected initialize() {\n super.initialize();\n\n this.mount(\n 'data',\n createValidator(\n z.object({})\n .passthrough()\n .or(z.string())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'metadata',\n createValidator(\n z.object({}).passthrough()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n const partyValidator = new CTSMessagingPartyValidator();\n\n this.mount('to', async (ctx) => {\n const validator = createValidator(\n z.array(z.object({}).passthrough()),\n );\n\n const output = (await validator(ctx)) as unknown[];\n return Promise.all(output.map((el) => partyValidator.run(el, {\n path: ctx.pathAbsolute,\n group: ctx.group,\n })));\n });\n }\n}\n","/*\n * Copyright (c) 2021-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventCallback } from './types';\n\nexport function isEventCallback(\n input: unknown,\n fnArgs?: number,\n) : input is EventCallback {\n if (typeof fnArgs === 'undefined') {\n return typeof input === 'function';\n }\n\n return typeof input === 'function' &&\n input.length >= fnArgs;\n}\n\nexport function isEventTarget(\n input: unknown,\n) : input is EventTarget {\n return typeof input === 'number' ||\n typeof input === 'string' ||\n typeof input === 'undefined';\n}\n"],"names":["STCConnectionEventName","CTSConnectionEventName","STCMessagingEventName","CTSMessagingEventName","CTSMessagingPartyValidator","Container","initialize","mount","createValidator","z","string","uuid","enum","CTSMessagingMessageValidator","object","passthrough","or","null","undefined","optional","partyValidator","ctx","validator","array","output","Promise","all","map","el","run","path","pathAbsolute","group","isEventCallback","input","fnArgs","length","isEventTarget"],"mappings":";;;;;;AAAA;;;;;IAOO,IAAKA,sBAAAA,iBAAAA,SAAAA,sBAAAA,EAAAA;;;;;AAAAA,IAAAA,OAAAA,sBAAAA;AAMX,CAAA,CAAA,EAAA;AAEM,IAAA,sBAAKC,iBAAAA,SAAAA,sBAAAA,EAAAA;;;;;;;AAAAA,IAAAA,OAAAA,sBAAAA;AAQX,CAAA,CAAA,EAAA;;ACvBD;;;;;IAOO,IAAKC,qBAAAA,iBAAAA,SAAAA,qBAAAA,EAAAA;;AAAAA,IAAAA,OAAAA,qBAAAA;AAEX,CAAA,CAAA,EAAA;AAEM,IAAA,qBAAKC,iBAAAA,SAAAA,qBAAAA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CAAA,CAAA;AAIrB,QAAA,MAAMC,iBAAiB,IAAIhB,0BAAAA,EAAAA;QAE3B,IAAI,CAACG,KAAK,CAAC,IAAA,gBAAA,WAAA;AAAM,YAAA,IAAA,IAAA,GAAA,mBAAA,CAAA,UAAOc,GAAAA,EAAAA;gBACpB,MAAMC,SAAAA,GAAYd,0BACdC,CAAAA,KAAAA,CAAEc,KAAK,CAACd,MAAEK,MAAM,CAAC,EAAC,CAAA,CAAGC,WAAW,EAAA,CAAA,CAAA;gBAGpC,MAAMS,MAAAA,GAAU,MAAMF,SAAUD,CAAAA,GAAAA,CAAAA;gBAChC,OAAOI,OAAAA,CAAQC,GAAG,CAACF,MAAOG,CAAAA,GAAG,CAAC,CAACC,EAAOR,GAAAA,cAAAA,CAAeS,GAAG,CAACD,EAAI,EAAA;AACzDE,wBAAAA,IAAAA,EAAMT,IAAIU,YAAY;AACtBC,wBAAAA,KAAAA,EAAOX,IAAIW;AACf,qBAAA,CAAA,CAAA,CAAA;AACJ,aAAA,CAAA;AAVwBX,YAAAA,OAAAA,SAAAA,GAAAA,EAAAA;;;;AAW5B;AACJ;;ACrDA;;;;;AAKC,IAIM,SAASY,eACZC,CAAAA,KAAc,EACdC,MAAe,EAAA;IAEf,IAAI,OAAOA,WAAW,WAAa,EAAA;AAC/B,QAAA,OAAO,OAAOD,KAAU,KAAA,UAAA;AAC5B;AAEA,IAAA,OAAO,OAAOA,KAAAA,KAAU,UACpBA,IAAAA,KAAAA,CAAME,MAAM,IAAID,MAAAA;AACxB;AAEO,SAASE,cACZH,KAAc,EAAA;AAEd,IAAA,OAAO,OAAOA,KAAU,KAAA,QAAA,IACpB,OAAOA,KAAU,KAAA,QAAA,IACjB,OAAOA,KAAU,KAAA,WAAA;AACzB;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { createValidator } from '@validup/adapter-zod';
|
|
3
|
+
import { Container } from 'validup';
|
|
4
|
+
|
|
1
5
|
/*
|
|
2
6
|
* Copyright (c) 2024.
|
|
3
7
|
* Author Peter Placzek (tada5hi)
|
|
@@ -34,6 +38,74 @@ var CTSMessagingEventName = /*#__PURE__*/ function(CTSMessagingEventName) {
|
|
|
34
38
|
return CTSMessagingEventName;
|
|
35
39
|
}({});
|
|
36
40
|
|
|
41
|
+
class CTSMessagingPartyValidator extends Container {
|
|
42
|
+
initialize() {
|
|
43
|
+
super.initialize();
|
|
44
|
+
this.mount('id', createValidator(z.string().uuid()));
|
|
45
|
+
this.mount('type', createValidator(z.enum([
|
|
46
|
+
'user',
|
|
47
|
+
'robot',
|
|
48
|
+
'client'
|
|
49
|
+
])));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Copyright (c) 2025.
|
|
55
|
+
* Author Peter Placzek (tada5hi)
|
|
56
|
+
* For the full copyright and license information,
|
|
57
|
+
* view the LICENSE file that was distributed with this source code.
|
|
58
|
+
*/ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
59
|
+
try {
|
|
60
|
+
var info = gen[key](arg);
|
|
61
|
+
var value = info.value;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (info.done) {
|
|
67
|
+
resolve(value);
|
|
68
|
+
} else {
|
|
69
|
+
Promise.resolve(value).then(_next, _throw);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function _async_to_generator(fn) {
|
|
73
|
+
return function() {
|
|
74
|
+
var self = this, args = arguments;
|
|
75
|
+
return new Promise(function(resolve, reject) {
|
|
76
|
+
var gen = fn.apply(self, args);
|
|
77
|
+
function _next(value) {
|
|
78
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
79
|
+
}
|
|
80
|
+
function _throw(err) {
|
|
81
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
82
|
+
}
|
|
83
|
+
_next(undefined);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
class CTSMessagingMessageValidator extends Container {
|
|
88
|
+
initialize() {
|
|
89
|
+
super.initialize();
|
|
90
|
+
this.mount('data', createValidator(z.object({}).passthrough().or(z.string()).or(z.null()).or(z.undefined()).optional()));
|
|
91
|
+
this.mount('metadata', createValidator(z.object({}).passthrough().or(z.null()).or(z.undefined()).optional()));
|
|
92
|
+
const partyValidator = new CTSMessagingPartyValidator();
|
|
93
|
+
this.mount('to', /*#__PURE__*/ function() {
|
|
94
|
+
var _ref = _async_to_generator(function*(ctx) {
|
|
95
|
+
const validator = createValidator(z.array(z.object({}).passthrough()));
|
|
96
|
+
const output = yield validator(ctx);
|
|
97
|
+
return Promise.all(output.map((el)=>partyValidator.run(el, {
|
|
98
|
+
path: ctx.pathAbsolute,
|
|
99
|
+
group: ctx.group
|
|
100
|
+
})));
|
|
101
|
+
});
|
|
102
|
+
return function(ctx) {
|
|
103
|
+
return _ref.apply(this, arguments);
|
|
104
|
+
};
|
|
105
|
+
}());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
37
109
|
/*
|
|
38
110
|
* Copyright (c) 2021-2024.
|
|
39
111
|
* Author Peter Placzek (tada5hi)
|
|
@@ -49,5 +121,5 @@ function isEventTarget(input) {
|
|
|
49
121
|
return typeof input === 'number' || typeof input === 'string' || typeof input === 'undefined';
|
|
50
122
|
}
|
|
51
123
|
|
|
52
|
-
export { CTSConnectionEventName, CTSMessagingEventName, STCConnectionEventName, STCMessagingEventName, isEventCallback, isEventTarget };
|
|
124
|
+
export { CTSConnectionEventName, CTSMessagingEventName, CTSMessagingMessageValidator, CTSMessagingPartyValidator, STCConnectionEventName, STCMessagingEventName, isEventCallback, isEventTarget };
|
|
53
125
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/connection/constants.ts","../src/messaging/constants.ts","../src/utils.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCConnectionEventName {\n USER_CONNECTED = 'userConnected',\n USER_DISCONNECTED = 'userDisconnected',\n\n ROBOT_CONNECTED = 'robotConnected',\n ROBOT_DISCONNECTED = 'robotDisconnected',\n}\n\nexport enum CTSConnectionEventName {\n USER_CONNECTIONS = 'userConnections',\n USER_CONNECTION_SUBSCRIBE = 'userConnectionSubscribe',\n USER_CONNECTION_UNSUBSCRIBE = 'userConnectionUnsubscribe',\n\n ROBOT_CONNECTIONS = 'robotConnections',\n ROBOT_CONNECTION_SUBSCRIBE = 'robotConnectionSubscribe',\n ROBOT_CONNECTION_UNSUBSCRIBE = 'robotConnectionUnsubscribe',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCMessagingEventName {\n SEND = 'send',\n}\n\nexport enum CTSMessagingEventName {\n SEND = 'send',\n}\n","/*\n * Copyright (c) 2021-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventCallback } from './types';\n\nexport function isEventCallback(\n input: unknown,\n fnArgs?: number,\n) : input is EventCallback {\n if (typeof fnArgs === 'undefined') {\n return typeof input === 'function';\n }\n\n return typeof input === 'function' &&\n input.length >= fnArgs;\n}\n\nexport function isEventTarget(\n input: unknown,\n) : input is EventTarget {\n return typeof input === 'number' ||\n typeof input === 'string' ||\n typeof input === 'undefined';\n}\n"],"names":["STCConnectionEventName","CTSConnectionEventName","STCMessagingEventName","CTSMessagingEventName","isEventCallback","input","fnArgs","length","isEventTarget"],"mappings":"AAAA;;;;;IAOO,IAAKA,sBAAAA,iBAAAA,SAAAA,sBAAAA,EAAAA;;;;;AAAAA,IAAAA,OAAAA,sBAAAA
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/connection/constants.ts","../src/messaging/constants.ts","../src/messaging/validators/to.ts","../src/messaging/validators/message.ts","../src/utils.ts"],"sourcesContent":["/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCConnectionEventName {\n USER_CONNECTED = 'userConnected',\n USER_DISCONNECTED = 'userDisconnected',\n\n ROBOT_CONNECTED = 'robotConnected',\n ROBOT_DISCONNECTED = 'robotDisconnected',\n}\n\nexport enum CTSConnectionEventName {\n USER_CONNECTIONS = 'userConnections',\n USER_CONNECTION_SUBSCRIBE = 'userConnectionSubscribe',\n USER_CONNECTION_UNSUBSCRIBE = 'userConnectionUnsubscribe',\n\n ROBOT_CONNECTIONS = 'robotConnections',\n ROBOT_CONNECTION_SUBSCRIBE = 'robotConnectionSubscribe',\n ROBOT_CONNECTION_UNSUBSCRIBE = 'robotConnectionUnsubscribe',\n}\n","/*\n * Copyright (c) 2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport enum STCMessagingEventName {\n SEND = 'send',\n}\n\nexport enum CTSMessagingEventName {\n SEND = 'send',\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { z } from 'zod';\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport type { CTSMessagingParty } from '../types';\n\nexport class CTSMessagingPartyValidator extends Container<CTSMessagingParty> {\n protected initialize() {\n super.initialize();\n\n this.mount(\n 'id',\n createValidator(\n z.string().uuid(),\n ),\n );\n\n this.mount(\n 'type',\n createValidator(\n z.enum(['user', 'robot', 'client']),\n ),\n );\n }\n}\n","/*\n * Copyright (c) 2025.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { z } from 'zod';\nimport { createValidator } from '@validup/adapter-zod';\nimport { Container } from 'validup';\nimport type { CTSMessagingMessage } from '../types';\nimport { CTSMessagingPartyValidator } from './to';\n\nexport class CTSMessagingMessageValidator extends Container<CTSMessagingMessage> {\n protected initialize() {\n super.initialize();\n\n this.mount(\n 'data',\n createValidator(\n z.object({})\n .passthrough()\n .or(z.string())\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n this.mount(\n 'metadata',\n createValidator(\n z.object({}).passthrough()\n .or(z.null())\n .or(z.undefined())\n .optional(),\n ),\n );\n\n const partyValidator = new CTSMessagingPartyValidator();\n\n this.mount('to', async (ctx) => {\n const validator = createValidator(\n z.array(z.object({}).passthrough()),\n );\n\n const output = (await validator(ctx)) as unknown[];\n return Promise.all(output.map((el) => partyValidator.run(el, {\n path: ctx.pathAbsolute,\n group: ctx.group,\n })));\n });\n }\n}\n","/*\n * Copyright (c) 2021-2024.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport type { EventCallback } from './types';\n\nexport function isEventCallback(\n input: unknown,\n fnArgs?: number,\n) : input is EventCallback {\n if (typeof fnArgs === 'undefined') {\n return typeof input === 'function';\n }\n\n return typeof input === 'function' &&\n input.length >= fnArgs;\n}\n\nexport function isEventTarget(\n input: unknown,\n) : input is EventTarget {\n return typeof input === 'number' ||\n typeof input === 'string' ||\n typeof input === 'undefined';\n}\n"],"names":["STCConnectionEventName","CTSConnectionEventName","STCMessagingEventName","CTSMessagingEventName","CTSMessagingPartyValidator","Container","initialize","mount","createValidator","z","string","uuid","enum","CTSMessagingMessageValidator","object","passthrough","or","null","undefined","optional","partyValidator","ctx","validator","array","output","Promise","all","map","el","run","path","pathAbsolute","group","isEventCallback","input","fnArgs","length","isEventTarget"],"mappings":";;;;AAAA;;;;;IAOO,IAAKA,sBAAAA,iBAAAA,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AAAA,KAAU,UACpBA,IAAAA,KAAAA,CAAME,MAAM,IAAID,MAAAA;AACxB;AAEO,SAASE,cACZH,KAAc,EAAA;AAEd,IAAA,OAAO,OAAOA,KAAU,KAAA,QAAA,IACpB,OAAOA,KAAU,KAAA,QAAA,IACjB,OAAOA,KAAU,KAAA,WAAA;AACzB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messaging/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { EventCallback } from '../types';
|
|
2
2
|
import type { CTSMessagingEventName, STCMessagingEventName } from './constants';
|
|
3
|
-
export type
|
|
3
|
+
export type CTSMessagingParty = {
|
|
4
4
|
type: 'user' | 'robot';
|
|
5
5
|
id: string;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
8
|
-
to:
|
|
9
|
-
data
|
|
10
|
-
metadata
|
|
7
|
+
export type CTSMessagingMessage = {
|
|
8
|
+
to: CTSMessagingParty[];
|
|
9
|
+
data?: Record<string, any> | string | null;
|
|
10
|
+
metadata?: Record<string, any> | null;
|
|
11
11
|
};
|
|
12
12
|
export type STCMessagingMessage = {
|
|
13
|
-
from:
|
|
14
|
-
data
|
|
15
|
-
metadata
|
|
13
|
+
from: CTSMessagingParty;
|
|
14
|
+
data?: Record<string, any> | string | null;
|
|
15
|
+
metadata?: Record<string, any> | null;
|
|
16
16
|
};
|
|
17
17
|
export type STCMessagingEvents = {
|
|
18
18
|
[STCMessagingEventName.SEND]: (data: STCMessagingMessage) => void;
|
|
19
19
|
};
|
|
20
20
|
export type CTSMessagingEvents = {
|
|
21
|
-
[CTSMessagingEventName.SEND]: (data:
|
|
21
|
+
[CTSMessagingEventName.SEND]: (data: CTSMessagingMessage, cb?: EventCallback) => void;
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/messaging/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEhF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/messaging/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEhF,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,EAAE,EAAE,MAAM,CAAA;CACb,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,EAAE,EAAE,iBAAiB,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;CACxC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,EAAE,iBAAiB,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAA;CACxC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACpE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC7B,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,mBAAmB,EAAE,EAAE,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CACzF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/messaging/validators/index.ts"],"names":[],"mappings":"AAOA,cAAc,WAAW,CAAC;AAC1B,cAAc,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../../src/messaging/validators/message.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAGpD,qBAAa,4BAA6B,SAAQ,SAAS,CAAC,mBAAmB,CAAC;IAC5E,SAAS,CAAC,UAAU;CAuCvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/messaging/validators/to.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,qBAAa,0BAA2B,SAAQ,SAAS,CAAC,iBAAiB,CAAC;IACxE,SAAS,CAAC,UAAU;CAiBvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@privateaim/messenger-kit",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"exports": {
|
|
@@ -23,13 +23,20 @@
|
|
|
23
23
|
"build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
|
|
24
24
|
"build:js": "rollup -c",
|
|
25
25
|
"build": "rimraf ./dist && cross-env NODE_ENV=production npm run build:js && npm run build:types",
|
|
26
|
-
"build-watch": "rimraf ./dist && tsc -p tsconfig.build.json --watch"
|
|
26
|
+
"build-watch": "rimraf ./dist && tsc -p tsconfig.build.json --watch",
|
|
27
|
+
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
|
|
28
|
+
"test:coverage": "npm run test -- --coverage"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@validup/adapter-zod": "^0.1.8",
|
|
32
|
+
"validup": "^0.1.8",
|
|
33
|
+
"zod": "^3.24.1"
|
|
27
34
|
},
|
|
28
35
|
"devDependencies": {
|
|
29
|
-
"@privateaim/core-kit": "^0.8.
|
|
36
|
+
"@privateaim/core-kit": "^0.8.6"
|
|
30
37
|
},
|
|
31
38
|
"peerDependencies": {
|
|
32
|
-
"@privateaim/core-kit": "^0.8.
|
|
39
|
+
"@privateaim/core-kit": "^0.8.6"
|
|
33
40
|
},
|
|
34
41
|
"publishConfig": {
|
|
35
42
|
"access": "public"
|
package/src/messaging/index.ts
CHANGED
package/src/messaging/types.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { EventCallback } from '../types';
|
|
2
2
|
import type { CTSMessagingEventName, STCMessagingEventName } from './constants';
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type CTSMessagingParty = {
|
|
5
5
|
type: 'user' | 'robot',
|
|
6
6
|
id: string
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
export type
|
|
10
|
-
to:
|
|
11
|
-
data
|
|
12
|
-
metadata
|
|
9
|
+
export type CTSMessagingMessage = {
|
|
10
|
+
to: CTSMessagingParty[],
|
|
11
|
+
data?: Record<string, any> | string | null,
|
|
12
|
+
metadata?: Record<string, any> | null
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export type STCMessagingMessage = {
|
|
16
|
-
from:
|
|
17
|
-
data
|
|
18
|
-
metadata
|
|
16
|
+
from: CTSMessagingParty,
|
|
17
|
+
data?: Record<string, any> | string | null,
|
|
18
|
+
metadata?: Record<string, any> | null
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export type STCMessagingEvents = {
|
|
@@ -23,5 +23,5 @@ export type STCMessagingEvents = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
export type CTSMessagingEvents = {
|
|
26
|
-
[CTSMessagingEventName.SEND]: (data:
|
|
26
|
+
[CTSMessagingEventName.SEND]: (data: CTSMessagingMessage, cb?: EventCallback) => void;
|
|
27
27
|
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { createValidator } from '@validup/adapter-zod';
|
|
10
|
+
import { Container } from 'validup';
|
|
11
|
+
import type { CTSMessagingMessage } from '../types';
|
|
12
|
+
import { CTSMessagingPartyValidator } from './to';
|
|
13
|
+
|
|
14
|
+
export class CTSMessagingMessageValidator extends Container<CTSMessagingMessage> {
|
|
15
|
+
protected initialize() {
|
|
16
|
+
super.initialize();
|
|
17
|
+
|
|
18
|
+
this.mount(
|
|
19
|
+
'data',
|
|
20
|
+
createValidator(
|
|
21
|
+
z.object({})
|
|
22
|
+
.passthrough()
|
|
23
|
+
.or(z.string())
|
|
24
|
+
.or(z.null())
|
|
25
|
+
.or(z.undefined())
|
|
26
|
+
.optional(),
|
|
27
|
+
),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
this.mount(
|
|
31
|
+
'metadata',
|
|
32
|
+
createValidator(
|
|
33
|
+
z.object({}).passthrough()
|
|
34
|
+
.or(z.null())
|
|
35
|
+
.or(z.undefined())
|
|
36
|
+
.optional(),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const partyValidator = new CTSMessagingPartyValidator();
|
|
41
|
+
|
|
42
|
+
this.mount('to', async (ctx) => {
|
|
43
|
+
const validator = createValidator(
|
|
44
|
+
z.array(z.object({}).passthrough()),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const output = (await validator(ctx)) as unknown[];
|
|
48
|
+
return Promise.all(output.map((el) => partyValidator.run(el, {
|
|
49
|
+
path: ctx.pathAbsolute,
|
|
50
|
+
group: ctx.group,
|
|
51
|
+
})));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { createValidator } from '@validup/adapter-zod';
|
|
10
|
+
import { Container } from 'validup';
|
|
11
|
+
import type { CTSMessagingParty } from '../types';
|
|
12
|
+
|
|
13
|
+
export class CTSMessagingPartyValidator extends Container<CTSMessagingParty> {
|
|
14
|
+
protected initialize() {
|
|
15
|
+
super.initialize();
|
|
16
|
+
|
|
17
|
+
this.mount(
|
|
18
|
+
'id',
|
|
19
|
+
createValidator(
|
|
20
|
+
z.string().uuid(),
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
this.mount(
|
|
25
|
+
'type',
|
|
26
|
+
createValidator(
|
|
27
|
+
z.enum(['user', 'robot', 'client']),
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021-2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
testEnvironment: 'node',
|
|
10
|
+
transform: {
|
|
11
|
+
'^.+\\.tsx?$': 'ts-jest',
|
|
12
|
+
},
|
|
13
|
+
moduleFileExtensions: [
|
|
14
|
+
'ts',
|
|
15
|
+
'tsx',
|
|
16
|
+
'js',
|
|
17
|
+
'jsx',
|
|
18
|
+
'json',
|
|
19
|
+
'node',
|
|
20
|
+
],
|
|
21
|
+
testRegex: '(/unit/.*|(\\.|/)(test|spec))\\.(ts|js)x?$',
|
|
22
|
+
testPathIgnorePatterns: [
|
|
23
|
+
'writable',
|
|
24
|
+
'dist',
|
|
25
|
+
'/unit/mock-util.ts',
|
|
26
|
+
],
|
|
27
|
+
coverageDirectory: 'writable/coverage',
|
|
28
|
+
collectCoverageFrom: [
|
|
29
|
+
'src/**/*.{ts,tsx,js,jsx}',
|
|
30
|
+
],
|
|
31
|
+
rootDir: '../',
|
|
32
|
+
verbose: true,
|
|
33
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024.
|
|
3
|
+
* Author Peter Placzek (tada5hi)
|
|
4
|
+
* For the full copyright and license information,
|
|
5
|
+
* view the LICENSE file that was distributed with this source code.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { buildErrorMessageForAttribute } from 'validup';
|
|
9
|
+
import type { CTSMessagingMessage } from '../../src';
|
|
10
|
+
import { CTSMessagingMessageValidator } from '../../src';
|
|
11
|
+
|
|
12
|
+
describe('messaging > validator', () => {
|
|
13
|
+
it('should validate message', async () => {
|
|
14
|
+
const validator = new CTSMessagingMessageValidator();
|
|
15
|
+
|
|
16
|
+
const message : CTSMessagingMessage = {
|
|
17
|
+
data: {},
|
|
18
|
+
to: [
|
|
19
|
+
{ type: 'user', id: '92b27b20-4c24-4897-ac68-daba7f306a08' },
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const output = await validator.run(message);
|
|
24
|
+
expect(output).toBeDefined();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should validate message with string data', async () => {
|
|
28
|
+
const validator = new CTSMessagingMessageValidator();
|
|
29
|
+
|
|
30
|
+
const message : CTSMessagingMessage = {
|
|
31
|
+
data: 'xxx',
|
|
32
|
+
to: [
|
|
33
|
+
{ type: 'user', id: '92b27b20-4c24-4897-ac68-daba7f306a08' },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const output = await validator.run(message);
|
|
38
|
+
expect(output).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should not validate message due invalid recipient format (type)', async () => {
|
|
42
|
+
const validator = new CTSMessagingMessageValidator();
|
|
43
|
+
|
|
44
|
+
const message : CTSMessagingMessage = {
|
|
45
|
+
data: 'xxx',
|
|
46
|
+
to: [
|
|
47
|
+
{ type: 'boxer' as 'user', id: '92b27b20-4c24-4897-ac68-daba7f306a08' },
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
await expect(validator.run(message)).rejects.toThrow(buildErrorMessageForAttribute('to'));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should not validate message due invalid recipient format (id)', async () => {
|
|
55
|
+
const validator = new CTSMessagingMessageValidator();
|
|
56
|
+
|
|
57
|
+
const message : CTSMessagingMessage = {
|
|
58
|
+
data: 'xxx',
|
|
59
|
+
to: [
|
|
60
|
+
{ type: 'user', id: '1' },
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
await expect(validator.run(message)).rejects.toThrow(buildErrorMessageForAttribute('to'));
|
|
65
|
+
});
|
|
66
|
+
});
|