@alwaysai/device-agent-schemas 2.0.4 → 2.1.1
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/lib/app-action-schema.d.ts +14 -14
- package/lib/app-action-schema.d.ts.map +1 -1
- package/lib/app-logs-schema.d.ts +2 -2
- package/lib/app-logs-schema.d.ts.map +1 -1
- package/lib/app-state-schema.d.ts +2 -2
- package/lib/app-state-schema.d.ts.map +1 -1
- package/lib/constants.d.ts +20 -14
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +12 -8
- package/lib/constants.js.map +1 -1
- package/lib/constants.test.js +10 -7
- package/lib/constants.test.js.map +1 -1
- package/lib/device-agent-action-schema.d.ts +2 -2
- package/lib/device-agent-action-schema.d.ts.map +1 -1
- package/lib/device-stats-schema.d.ts +2 -2
- package/lib/device-stats-schema.d.ts.map +1 -1
- package/lib/device-stats-schema.js +1 -1
- package/lib/device-stats-schema.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/lib/schemas/{app-install-cloud-response-schema.json → app-install-response-schema.json} +4 -4
- package/lib/schemas/{models-install-cloud-response-schema.json → models-install-response-schema.json} +4 -4
- package/lib/schemas/{client-message-schema.json → to-client-message-schema.json} +5 -24
- package/lib/schemas/to-cloud-message-schema.json +56 -0
- package/lib/schemas/{device-agent-message-schema.json → to-device-agent-message-schema.json} +10 -10
- package/lib/signed-urls-request-schema.d.ts +2 -2
- package/lib/signed-urls-request-schema.d.ts.map +1 -1
- package/lib/status-response-schema.d.ts +2 -2
- package/lib/status-response-schema.d.ts.map +1 -1
- package/lib/types.d.ts +21 -12
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +18 -16
- package/lib/types.js.map +1 -1
- package/lib/types.test.js +128 -43
- package/lib/types.test.js.map +1 -1
- package/package.json +1 -1
- package/src/app-action-schema.ts +15 -15
- package/src/app-logs-schema.ts +2 -2
- package/src/app-state-schema.ts +2 -2
- package/src/constants.test.ts +11 -7
- package/src/constants.ts +23 -15
- package/src/device-agent-action-schema.ts +2 -2
- package/src/device-stats-schema.ts +3 -3
- package/src/index.ts +41 -31
- package/src/schemas/{app-install-cloud-response-schema.json → app-install-response-schema.json} +4 -4
- package/src/schemas/{models-install-cloud-response-schema.json → models-install-response-schema.json} +4 -4
- package/src/schemas/{client-message-schema.json → to-client-message-schema.json} +5 -24
- package/src/schemas/to-cloud-message-schema.json +56 -0
- package/src/schemas/{device-agent-message-schema.json → to-device-agent-message-schema.json} +10 -10
- package/src/signed-urls-request-schema.ts +2 -2
- package/src/status-response-schema.ts +2 -2
- package/src/types.test.ts +149 -49
- package/src/types.ts +50 -35
package/src/schemas/{device-agent-message-schema.json → to-device-agent-message-schema.json}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"$id": "https://alwaysai.co/device-agent-message-schema.json",
|
|
2
|
+
"$id": "https://alwaysai.co/to-device-agent-message-schema.json",
|
|
3
3
|
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
-
"title": "
|
|
4
|
+
"title": "to_device_agent_message",
|
|
5
5
|
"description":
|
|
6
6
|
"A schema that describes the message payload structure for messages sent from clients to device agent",
|
|
7
7
|
"type": "object",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"enum": [
|
|
16
16
|
"app_state_control",
|
|
17
17
|
"app_version_control",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"app_install_response",
|
|
19
|
+
"models_install_response",
|
|
20
20
|
"live_state_updates"
|
|
21
21
|
]
|
|
22
22
|
},
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"oneOf": [
|
|
28
28
|
{ "$ref": "https://alwaysai.co/app-state-control-schema.json" },
|
|
29
29
|
{ "$ref": "https://alwaysai.co/app-version-control-schema.json" },
|
|
30
|
-
{ "$ref": "https://alwaysai.co/app-install-
|
|
31
|
-
{ "$ref": "https://alwaysai.co/models-install-
|
|
30
|
+
{ "$ref": "https://alwaysai.co/app-install-response-schema.json" },
|
|
31
|
+
{ "$ref": "https://alwaysai.co/models-install-response-schema.json" },
|
|
32
32
|
{ "$ref": "https://alwaysai.co/live-updates-toggle-schema.json" }
|
|
33
33
|
]
|
|
34
34
|
}
|
|
@@ -61,24 +61,24 @@
|
|
|
61
61
|
{
|
|
62
62
|
"if": {
|
|
63
63
|
"properties": {
|
|
64
|
-
"messageType": { "const": "
|
|
64
|
+
"messageType": { "const": "app_install_response" }
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
67
|
"then": {
|
|
68
68
|
"properties": {
|
|
69
|
-
"payload": {"$ref": "https://alwaysai.co/app-install-
|
|
69
|
+
"payload": {"$ref": "https://alwaysai.co/app-install-response-schema.json"}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
74
|
"if": {
|
|
75
75
|
"properties": {
|
|
76
|
-
"messageType": { "const": "
|
|
76
|
+
"messageType": { "const": "models_install_response" }
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"then": {
|
|
80
80
|
"properties": {
|
|
81
|
-
"payload": {"$ref": "https://alwaysai.co/models-install-
|
|
81
|
+
"payload": {"$ref": "https://alwaysai.co/models-install-response-schema.json"}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SignedUrlsRequestMessageType } from './constants';
|
|
2
|
-
import {
|
|
2
|
+
import { BaseToClientMessage } from './types';
|
|
3
3
|
|
|
4
4
|
type ModelsObject = {
|
|
5
5
|
[modelId: string]: number;
|
|
@@ -16,7 +16,7 @@ export interface SignedUrlsRequestPayload {
|
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export interface SignedUrlsRequestMessage extends
|
|
19
|
+
export interface SignedUrlsRequestMessage extends BaseToClientMessage {
|
|
20
20
|
messageType: SignedUrlsRequestMessageType;
|
|
21
21
|
payload: SignedUrlsRequestPayload;
|
|
22
22
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { StatusResponseMessageType, StatusResponseValue } from './constants';
|
|
2
|
-
import {
|
|
2
|
+
import { BaseToClientMessage } from './types';
|
|
3
3
|
|
|
4
4
|
export interface StatusResponsePayload {
|
|
5
5
|
status: StatusResponseValue;
|
|
6
6
|
message?: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export interface StatusResponseMessage extends
|
|
9
|
+
export interface StatusResponseMessage extends BaseToClientMessage {
|
|
10
10
|
messageType: StatusResponseMessageType;
|
|
11
11
|
payload: StatusResponsePayload;
|
|
12
12
|
}
|
package/src/types.test.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { clientMessageTypeValues, deviceAgentMessageTypeValues } from './constants';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
toClientMessageTypeValues,
|
|
3
|
+
toCloudMessageTypeValues,
|
|
4
|
+
toDeviceAgentMessageTypeValues,
|
|
5
|
+
} from './constants';
|
|
6
|
+
import {
|
|
7
|
+
validateToClientMessage,
|
|
8
|
+
validateToDeviceAgentMessage,
|
|
9
|
+
getToCloudTopic,
|
|
10
|
+
getToClientTopic,
|
|
11
|
+
getToDeviceTopic,
|
|
12
|
+
validateToCloudMessage,
|
|
8
13
|
} from './types';
|
|
9
14
|
import { generateTxId } from './utils';
|
|
10
15
|
|
|
11
16
|
const validTxId = generateTxId();
|
|
12
|
-
|
|
17
|
+
|
|
18
|
+
const validToCloudMessages = [
|
|
13
19
|
{
|
|
14
20
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
15
21
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
16
|
-
topic:
|
|
22
|
+
topic: getToCloudTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
17
23
|
txId: validTxId,
|
|
18
24
|
messageType: 'signed_urls_request',
|
|
19
25
|
payload: {
|
|
@@ -24,10 +30,72 @@ const validClientMessages = [
|
|
|
24
30
|
},
|
|
25
31
|
},
|
|
26
32
|
},
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
const invalidToCloudMessages = [
|
|
36
|
+
{
|
|
37
|
+
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
38
|
+
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
39
|
+
topic: getToCloudTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
40
|
+
// missing txId
|
|
41
|
+
messageType: 'signed_urls_request',
|
|
42
|
+
payload: {
|
|
43
|
+
signedUrlsRequest: {
|
|
44
|
+
projectId: 'b8f8e280-0c59-46e7-911e-7b897263ebc3',
|
|
45
|
+
appReleaseHash:
|
|
46
|
+
'c36d58b6a5b5c09e5d46da8a5315f01c20f8c7ff0087b1e31e6e334a702ee8ba',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
52
|
+
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
53
|
+
topic: getToCloudTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
54
|
+
txId: validTxId,
|
|
55
|
+
messageType: 'app_logs', // incorrect messageType
|
|
56
|
+
payload: {
|
|
57
|
+
signedUrlsRequest: {
|
|
58
|
+
projectId: 'b8f8e280-0c59-46e7-911e-7b897263ebc3',
|
|
59
|
+
appReleaseHash:
|
|
60
|
+
'c36d58b6a5b5c09e5d46da8a5315f01c20f8c7ff0087b1e31e6e334a702ee8ba',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
66
|
+
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
67
|
+
topic: getToCloudTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
68
|
+
txId: validTxId,
|
|
69
|
+
messageType: 'signed_urls_request',
|
|
70
|
+
payload: {
|
|
71
|
+
signedUrlsRequest: {
|
|
72
|
+
// missing releaseHash
|
|
73
|
+
projectId: 'b8f8e280-0c59-46e7-911e-7b897263ebc3',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
// wrong type -- ToClientMessage
|
|
27
78
|
{
|
|
28
79
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
29
80
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
30
|
-
topic:
|
|
81
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
82
|
+
txId: validTxId,
|
|
83
|
+
messageType: 'device_stats',
|
|
84
|
+
payload: {
|
|
85
|
+
deviceStats: {
|
|
86
|
+
cpuUsage: 50,
|
|
87
|
+
diskUtil: 40,
|
|
88
|
+
usedMemoryPercentage: 70,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const validToClientMessages = [
|
|
95
|
+
{
|
|
96
|
+
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
97
|
+
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
98
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
31
99
|
txId: validTxId,
|
|
32
100
|
messageType: 'device_stats',
|
|
33
101
|
payload: {
|
|
@@ -39,7 +107,7 @@ const validClientMessages = [
|
|
|
39
107
|
{
|
|
40
108
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
41
109
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
42
|
-
topic:
|
|
110
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
43
111
|
txId: validTxId,
|
|
44
112
|
messageType: 'app_logs',
|
|
45
113
|
payload: {
|
|
@@ -50,7 +118,7 @@ const validClientMessages = [
|
|
|
50
118
|
{
|
|
51
119
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
52
120
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
53
|
-
topic:
|
|
121
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
54
122
|
txId: validTxId,
|
|
55
123
|
messageType: 'app_state',
|
|
56
124
|
payload: {
|
|
@@ -73,7 +141,7 @@ const validClientMessages = [
|
|
|
73
141
|
{
|
|
74
142
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
75
143
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
76
|
-
topic:
|
|
144
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
77
145
|
txId: validTxId,
|
|
78
146
|
messageType: 'status_response',
|
|
79
147
|
payload: {
|
|
@@ -83,7 +151,7 @@ const validClientMessages = [
|
|
|
83
151
|
{
|
|
84
152
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
85
153
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
86
|
-
topic:
|
|
154
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
87
155
|
txId: validTxId,
|
|
88
156
|
messageType: 'status_response',
|
|
89
157
|
payload: {
|
|
@@ -115,12 +183,12 @@ const validClientMessages = [
|
|
|
115
183
|
},
|
|
116
184
|
];
|
|
117
185
|
|
|
118
|
-
const
|
|
186
|
+
const invalidToClientMessages = [
|
|
119
187
|
// invalid txId -> too short
|
|
120
188
|
{
|
|
121
189
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
122
190
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
123
|
-
topic:
|
|
191
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
124
192
|
txId: '124gabaA',
|
|
125
193
|
messageType: 'device_stats',
|
|
126
194
|
payload: {
|
|
@@ -136,7 +204,7 @@ const invalidClientMessages = [
|
|
|
136
204
|
{
|
|
137
205
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
138
206
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
139
|
-
topic:
|
|
207
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
140
208
|
txId: validTxId,
|
|
141
209
|
messageType: 'device_stats',
|
|
142
210
|
payload: {
|
|
@@ -152,7 +220,7 @@ const invalidClientMessages = [
|
|
|
152
220
|
{
|
|
153
221
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
154
222
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
155
|
-
topic:
|
|
223
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
156
224
|
txId: validTxId,
|
|
157
225
|
messageType: 'device_stats',
|
|
158
226
|
payload: {
|
|
@@ -167,7 +235,7 @@ const invalidClientMessages = [
|
|
|
167
235
|
{
|
|
168
236
|
timestamp: 'Mon, 06 Jun 2022 20:21:46 GMT',
|
|
169
237
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
170
|
-
topic:
|
|
238
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
171
239
|
txId: validTxId,
|
|
172
240
|
messageType: 'app_state',
|
|
173
241
|
payload: {
|
|
@@ -181,7 +249,7 @@ const invalidClientMessages = [
|
|
|
181
249
|
{
|
|
182
250
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
183
251
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
184
|
-
topic:
|
|
252
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
185
253
|
txId: validTxId,
|
|
186
254
|
messageType: 'app_logs',
|
|
187
255
|
payload: {
|
|
@@ -194,7 +262,7 @@ const invalidClientMessages = [
|
|
|
194
262
|
{
|
|
195
263
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
196
264
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
197
|
-
topic:
|
|
265
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
198
266
|
txId: validTxId,
|
|
199
267
|
messageType: 'status_response',
|
|
200
268
|
payload: {
|
|
@@ -206,7 +274,7 @@ const invalidClientMessages = [
|
|
|
206
274
|
{
|
|
207
275
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
208
276
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
209
|
-
topic:
|
|
277
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
210
278
|
messageType: 'status_response',
|
|
211
279
|
payload: {
|
|
212
280
|
txId: validTxId,
|
|
@@ -217,7 +285,7 @@ const invalidClientMessages = [
|
|
|
217
285
|
{
|
|
218
286
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
219
287
|
deviceId: '68195e4f-045c-4a9e-ae50-b87ed4d611f7',
|
|
220
|
-
topic:
|
|
288
|
+
topic: getToClientTopic('68195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
221
289
|
txId: 'dagagfadb',
|
|
222
290
|
messageType: 'status_response',
|
|
223
291
|
payload: {
|
|
@@ -226,10 +294,10 @@ const invalidClientMessages = [
|
|
|
226
294
|
},
|
|
227
295
|
];
|
|
228
296
|
|
|
229
|
-
const
|
|
297
|
+
const validToDeviceAgentMessages = [
|
|
230
298
|
{
|
|
231
299
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
232
|
-
topic:
|
|
300
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
233
301
|
txId: validTxId,
|
|
234
302
|
messageType: 'live_state_updates',
|
|
235
303
|
payload: {
|
|
@@ -239,7 +307,7 @@ const validDeviceAgentMessages = [
|
|
|
239
307
|
},
|
|
240
308
|
{
|
|
241
309
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
242
|
-
topic:
|
|
310
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
243
311
|
txId: validTxId,
|
|
244
312
|
messageType: 'app_state_control',
|
|
245
313
|
payload: {
|
|
@@ -249,7 +317,7 @@ const validDeviceAgentMessages = [
|
|
|
249
317
|
},
|
|
250
318
|
{
|
|
251
319
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
252
|
-
topic:
|
|
320
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
253
321
|
txId: validTxId,
|
|
254
322
|
messageType: 'app_version_control',
|
|
255
323
|
payload: {
|
|
@@ -260,7 +328,7 @@ const validDeviceAgentMessages = [
|
|
|
260
328
|
},
|
|
261
329
|
{
|
|
262
330
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
263
|
-
topic:
|
|
331
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
264
332
|
txId: validTxId,
|
|
265
333
|
messageType: 'app_version_control',
|
|
266
334
|
payload: {
|
|
@@ -280,10 +348,10 @@ const validDeviceAgentMessages = [
|
|
|
280
348
|
},
|
|
281
349
|
];
|
|
282
350
|
|
|
283
|
-
const
|
|
351
|
+
const invalidToDeviceAgentMessages = [
|
|
284
352
|
{
|
|
285
353
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
286
|
-
topic:
|
|
354
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
287
355
|
txId: validTxId,
|
|
288
356
|
messageType: 'live_updates',
|
|
289
357
|
payload: {
|
|
@@ -304,7 +372,7 @@ const invalidDeviceAgentMessages = [
|
|
|
304
372
|
},
|
|
305
373
|
{
|
|
306
374
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
307
|
-
topic:
|
|
375
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
308
376
|
txId: validTxId,
|
|
309
377
|
messageType: 'app_state_control',
|
|
310
378
|
payload: {
|
|
@@ -315,7 +383,7 @@ const invalidDeviceAgentMessages = [
|
|
|
315
383
|
// Missing appReleaseHash
|
|
316
384
|
{
|
|
317
385
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
318
|
-
topic:
|
|
386
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
319
387
|
txId: validTxId,
|
|
320
388
|
messageType: 'app_version_control',
|
|
321
389
|
payload: {
|
|
@@ -328,7 +396,7 @@ const invalidDeviceAgentMessages = [
|
|
|
328
396
|
// Missing projectId
|
|
329
397
|
{
|
|
330
398
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
331
|
-
topic:
|
|
399
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
332
400
|
txId: validTxId,
|
|
333
401
|
messageType: 'app_version_control',
|
|
334
402
|
payload: {
|
|
@@ -340,7 +408,7 @@ const invalidDeviceAgentMessages = [
|
|
|
340
408
|
// missing txId
|
|
341
409
|
{
|
|
342
410
|
timestamp: 'Fri, 27 May 2022 03:47:15 GMT',
|
|
343
|
-
topic:
|
|
411
|
+
topic: getToDeviceTopic('8195e4f-045c-4a9e-ae50-b87ed4d611f7'),
|
|
344
412
|
messageType: 'app_version_control',
|
|
345
413
|
payload: {
|
|
346
414
|
appVersionControl: {
|
|
@@ -350,42 +418,74 @@ const invalidDeviceAgentMessages = [
|
|
|
350
418
|
},
|
|
351
419
|
];
|
|
352
420
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
421
|
+
/* ============================================================================
|
|
422
|
+
Test To Device Agent Message
|
|
423
|
+
============================================================================ */
|
|
424
|
+
|
|
425
|
+
test('test valid to device agent message', () => {
|
|
426
|
+
validToDeviceAgentMessages.forEach((item) => {
|
|
427
|
+
const valid = validateToDeviceAgentMessage(item);
|
|
428
|
+
if (!valid) {
|
|
429
|
+
// eslint-disable-next-line no-console
|
|
430
|
+
console.log(item);
|
|
431
|
+
// eslint-disable-next-line no-console
|
|
432
|
+
console.log(validateToDeviceAgentMessage.errors);
|
|
433
|
+
}
|
|
434
|
+
expect(valid).toBe(true);
|
|
435
|
+
expect(item.messageType in toDeviceAgentMessageTypeValues);
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
test('test invalid to device agent message', () => {
|
|
440
|
+
invalidToDeviceAgentMessages.forEach((item) => {
|
|
441
|
+
expect(validateToDeviceAgentMessage(item)).toBe(false);
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
/* ============================================================================
|
|
446
|
+
Test To Cloud Message
|
|
447
|
+
============================================================================ */
|
|
448
|
+
|
|
449
|
+
test('test valid to cloud message', () => {
|
|
450
|
+
validToCloudMessages.forEach((item) => {
|
|
451
|
+
const valid = validateToCloudMessage(item);
|
|
356
452
|
if (!valid) {
|
|
357
453
|
// eslint-disable-next-line no-console
|
|
358
454
|
console.log(item);
|
|
359
455
|
// eslint-disable-next-line no-console
|
|
360
|
-
console.log(
|
|
456
|
+
console.log(validateToCloudMessage.errors);
|
|
361
457
|
}
|
|
362
458
|
expect(valid).toBe(true);
|
|
363
|
-
expect(item.messageType in
|
|
459
|
+
expect(item.messageType in toCloudMessageTypeValues);
|
|
364
460
|
});
|
|
365
461
|
});
|
|
366
462
|
|
|
367
|
-
test('test invalid
|
|
368
|
-
|
|
369
|
-
expect(
|
|
463
|
+
test('test invalid to cloud message', () => {
|
|
464
|
+
invalidToCloudMessages.forEach((item) => {
|
|
465
|
+
expect(validateToCloudMessage(item)).toBe(false);
|
|
370
466
|
});
|
|
371
467
|
});
|
|
372
468
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
469
|
+
/* ============================================================================
|
|
470
|
+
Test To Client Message
|
|
471
|
+
============================================================================ */
|
|
472
|
+
|
|
473
|
+
test('test valid to client message', () => {
|
|
474
|
+
validToClientMessages.forEach((item) => {
|
|
475
|
+
const valid = validateToClientMessage(item);
|
|
376
476
|
if (!valid) {
|
|
377
477
|
// eslint-disable-next-line no-console
|
|
378
478
|
console.log(item);
|
|
379
479
|
// eslint-disable-next-line no-console
|
|
380
|
-
console.log(
|
|
480
|
+
console.log(validateToClientMessage.errors);
|
|
381
481
|
}
|
|
382
482
|
expect(valid).toBe(true);
|
|
383
|
-
expect(item.messageType in
|
|
483
|
+
expect(item.messageType in toClientMessageTypeValues);
|
|
384
484
|
});
|
|
385
485
|
});
|
|
386
486
|
|
|
387
|
-
test('test invalid client message', () => {
|
|
388
|
-
|
|
389
|
-
expect(
|
|
487
|
+
test('test invalid to client message', () => {
|
|
488
|
+
invalidToClientMessages.forEach((item) => {
|
|
489
|
+
expect(validateToClientMessage(item)).toBe(false);
|
|
390
490
|
});
|
|
391
491
|
});
|
package/src/types.ts
CHANGED
|
@@ -11,27 +11,28 @@ import * as appStateSchema from './schemas/app-state-schema.json';
|
|
|
11
11
|
import * as appLogsSchema from './schemas/app-logs-schema.json';
|
|
12
12
|
import * as statusResponseSchema from './schemas/status-response-schema.json';
|
|
13
13
|
import * as signedUrlsRequestSchema from './schemas/signed-urls-request-schema.json';
|
|
14
|
-
import * as
|
|
14
|
+
import * as toDeviceAgentMessageSchema from './schemas/to-device-agent-message-schema.json';
|
|
15
15
|
import * as modelsInstallPayloadSchema from './schemas/models-install-payload-schema.json';
|
|
16
16
|
import * as appInstallSchema from './schemas/app-install-schema.json';
|
|
17
17
|
import * as appUninstallSchema from './schemas/app-uninstall-schema.json';
|
|
18
|
-
import * as
|
|
18
|
+
import * as toClientMessageSchema from './schemas/to-client-message-schema.json';
|
|
19
|
+
import * as toCloudMessageSchema from './schemas/to-cloud-message-schema.json';
|
|
19
20
|
import * as appStateControlSchema from './schemas/app-state-control-schema.json';
|
|
20
21
|
import * as appVersionControlSchema from './schemas/app-version-control-schema.json';
|
|
21
|
-
import * as
|
|
22
|
-
import * as
|
|
22
|
+
import * as appInstallResponseSchema from './schemas/app-install-response-schema.json';
|
|
23
|
+
import * as modelsInstallResponseSchema from './schemas/models-install-response-schema.json';
|
|
23
24
|
import * as liveUpdatesTogglesSchema from './schemas/live-updates-toggle-schema.json';
|
|
24
25
|
import { AppLogsMessage, AppLogsPayload } from './app-logs-schema';
|
|
25
26
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
AppInstallResponseMessage,
|
|
28
|
+
AppInstallResponsePayload,
|
|
28
29
|
AppStateControlMessage,
|
|
29
30
|
AppStateControlPayload,
|
|
30
31
|
AppVersionControlInstallPayload,
|
|
31
32
|
AppVersionControlMessage,
|
|
32
33
|
AppVersionControlUninstallPayload,
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
ModelsInstallResponseMessage,
|
|
35
|
+
ModelsInstallResponsePayload,
|
|
35
36
|
} from './app-action-schema';
|
|
36
37
|
import {
|
|
37
38
|
LiveStateUpdatesToggleMessage,
|
|
@@ -52,87 +53,101 @@ const ajv = new Ajv2019({
|
|
|
52
53
|
schemas: [commonSchema],
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
export const
|
|
56
|
+
export const getToClientTopic = (deviceUuid: string, deviceType: string = DEVICE_TYPE) =>
|
|
56
57
|
`${CLIENT_TOPIC_PREFIX}/${deviceType}/${deviceUuid}`;
|
|
57
58
|
|
|
58
|
-
export const
|
|
59
|
+
export const getToCloudTopic = (deviceUuid: string, deviceType: string = DEVICE_TYPE) =>
|
|
59
60
|
`${CLOUD_TOPIC_PREFIX}/${deviceType}/${deviceUuid}`;
|
|
60
61
|
|
|
61
|
-
export const
|
|
62
|
+
export const getToDeviceTopic = (deviceUuid: string, deviceType: string = DEVICE_TYPE) =>
|
|
62
63
|
`${DEVICE_TOPIC_PREFIX}/${deviceType}/${deviceUuid}`;
|
|
63
64
|
|
|
64
65
|
/* ============================================================================
|
|
65
|
-
|
|
66
|
+
ToClient Message
|
|
66
67
|
============================================================================ */
|
|
67
68
|
|
|
68
|
-
export interface
|
|
69
|
+
export interface BaseToClientMessage {
|
|
69
70
|
deviceId: string;
|
|
70
71
|
timestamp: string;
|
|
71
72
|
topic?: string;
|
|
72
73
|
txId: string;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
export type
|
|
76
|
+
export type ToClientMessage =
|
|
76
77
|
| AppLogsMessage
|
|
77
78
|
| StatusResponseMessage
|
|
78
79
|
| AppStateMessage
|
|
79
|
-
| SignedUrlsRequestMessage
|
|
80
80
|
| DeviceStatsMessage;
|
|
81
81
|
|
|
82
|
-
export type
|
|
82
|
+
export type ToClientMessagePayload =
|
|
83
83
|
| AppLogsPayload
|
|
84
84
|
| AppStatePayload
|
|
85
85
|
| DeviceStatsPayload
|
|
86
|
-
| StatusResponsePayload
|
|
87
|
-
| SignedUrlsRequestPayload;
|
|
86
|
+
| StatusResponsePayload;
|
|
88
87
|
|
|
89
88
|
ajv.addSchema(deviceStatsSchema, 'device-stats-schema.json');
|
|
90
89
|
ajv.addSchema(appStateSchema, 'app-state-schema.json');
|
|
91
90
|
ajv.addSchema(appLogsSchema, 'app-logs-schema.json');
|
|
92
91
|
ajv.addSchema(statusResponseSchema, 'status-response-schema.json');
|
|
92
|
+
ajv.addSchema(toClientMessageSchema, 'to-client-message-schema.json');
|
|
93
|
+
export const validateToClientMessage =
|
|
94
|
+
ajv.compile<BaseToClientMessage>(toClientMessageSchema);
|
|
95
|
+
|
|
96
|
+
/* ============================================================================
|
|
97
|
+
ToCloud Message
|
|
98
|
+
============================================================================ */
|
|
99
|
+
|
|
100
|
+
export interface BaseToCloudMessage {
|
|
101
|
+
deviceId: string;
|
|
102
|
+
timestamp: string;
|
|
103
|
+
topic?: string;
|
|
104
|
+
txId: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type ToCloudMessage = SignedUrlsRequestMessage;
|
|
108
|
+
|
|
109
|
+
export type ToCloudMessagePayload = SignedUrlsRequestPayload;
|
|
110
|
+
|
|
93
111
|
ajv.addSchema(signedUrlsRequestSchema, 'signed-urls-request-schema.json');
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
export const validateToCloudMessage =
|
|
113
|
+
ajv.compile<BaseToCloudMessage>(toCloudMessageSchema);
|
|
96
114
|
|
|
97
115
|
/* ============================================================================
|
|
98
|
-
Device Agent Message
|
|
116
|
+
To Device Agent Message
|
|
99
117
|
============================================================================ */
|
|
100
118
|
|
|
101
|
-
export interface
|
|
119
|
+
export interface BaseToDeviceAgentMessage {
|
|
102
120
|
timestamp: string;
|
|
103
121
|
topic?: string;
|
|
104
122
|
txId: string;
|
|
105
123
|
}
|
|
106
124
|
|
|
107
|
-
export type
|
|
125
|
+
export type ToDeviceAgentMessage =
|
|
108
126
|
| AppStateControlMessage
|
|
109
127
|
| AppVersionControlMessage
|
|
110
128
|
| LiveStateUpdatesToggleMessage
|
|
111
129
|
| StatusResponseMessage
|
|
112
|
-
|
|
|
113
|
-
|
|
|
130
|
+
| AppInstallResponseMessage
|
|
131
|
+
| ModelsInstallResponseMessage;
|
|
114
132
|
|
|
115
|
-
export type
|
|
133
|
+
export type ToDeviceAgentMessagePayload =
|
|
116
134
|
| AppStateControlPayload
|
|
117
135
|
| AppVersionControlInstallPayload
|
|
118
136
|
| AppVersionControlUninstallPayload
|
|
119
137
|
| LiveStateUpdatesTogglePayload
|
|
120
138
|
| StatusResponsePayload
|
|
121
|
-
|
|
|
122
|
-
|
|
|
139
|
+
| AppInstallResponsePayload
|
|
140
|
+
| ModelsInstallResponsePayload;
|
|
123
141
|
|
|
124
142
|
ajv.addSchema(modelsInstallPayloadSchema, 'models-install-payload-schema.json');
|
|
125
143
|
ajv.addSchema(appInstallSchema, 'app-install-schema.json');
|
|
126
144
|
ajv.addSchema(appUninstallSchema, 'app-uninstall-schema.json');
|
|
127
145
|
ajv.addSchema(appStateControlSchema, 'app-state-control-schema.json');
|
|
128
146
|
ajv.addSchema(appVersionControlSchema, 'app-version-control-schema.json');
|
|
129
|
-
ajv.addSchema(
|
|
130
|
-
ajv.addSchema(
|
|
131
|
-
modelsInstallCloudResponseSchema,
|
|
132
|
-
'model-install-cloud-response-schema.json',
|
|
133
|
-
);
|
|
147
|
+
ajv.addSchema(appInstallResponseSchema, 'app-install-response-schema.json');
|
|
148
|
+
ajv.addSchema(modelsInstallResponseSchema, 'models-install-response-schema.json');
|
|
134
149
|
ajv.addSchema(liveUpdatesTogglesSchema, 'live-updates-toggle-schema.json');
|
|
135
150
|
|
|
136
|
-
export const
|
|
137
|
-
|
|
151
|
+
export const validateToDeviceAgentMessage = ajv.compile<ToDeviceAgentMessage>(
|
|
152
|
+
toDeviceAgentMessageSchema,
|
|
138
153
|
);
|