@alwaysai/device-agent-schemas 3.3.0 → 3.3.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.
Files changed (91) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +14 -0
  3. package/.gitattributes +2 -0
  4. package/.nvmrc +1 -0
  5. package/bitbucket-pipelines.yml +54 -0
  6. package/development.md +53 -0
  7. package/jest.config.js +3 -0
  8. package/lib/app-action-schema.d.ts +7 -1
  9. package/lib/app-action-schema.d.ts.map +1 -0
  10. package/lib/app-action-schema.js.map +1 -0
  11. package/lib/app-logs-schema.d.ts.map +1 -0
  12. package/lib/app-logs-schema.js.map +1 -0
  13. package/lib/app-state-schema.d.ts.map +1 -0
  14. package/lib/app-state-schema.js.map +1 -0
  15. package/lib/common.d.ts.map +1 -0
  16. package/lib/common.js.map +1 -0
  17. package/lib/constants.d.ts +2 -1
  18. package/lib/constants.d.ts.map +1 -0
  19. package/lib/constants.js +2 -1
  20. package/lib/constants.js.map +1 -0
  21. package/lib/device-action-schema.d.ts.map +1 -0
  22. package/lib/device-action-schema.js.map +1 -0
  23. package/lib/device-agent-action-schema.d.ts.map +1 -0
  24. package/lib/device-agent-action-schema.js.map +1 -0
  25. package/lib/device-stats-schema.d.ts.map +1 -0
  26. package/lib/device-stats-schema.js.map +1 -0
  27. package/lib/index.d.ts +2 -2
  28. package/lib/index.d.ts.map +1 -0
  29. package/lib/index.js.map +1 -0
  30. package/lib/message-builders.d.ts +2 -2
  31. package/lib/message-builders.d.ts.map +1 -0
  32. package/lib/message-builders.js.map +1 -0
  33. package/lib/schemas/app-update-config-schema.json +22 -0
  34. package/lib/schemas/app-version-control-schema.json +3 -0
  35. package/lib/shadow-schema.d.ts.map +1 -0
  36. package/lib/shadow-schema.js.map +1 -0
  37. package/lib/signed-urls-request-schema.d.ts.map +1 -0
  38. package/lib/signed-urls-request-schema.js.map +1 -0
  39. package/lib/status-response-schema.d.ts.map +1 -0
  40. package/lib/status-response-schema.js.map +1 -0
  41. package/lib/types.d.ts +2 -2
  42. package/lib/types.d.ts.map +1 -0
  43. package/lib/types.js +2 -0
  44. package/lib/types.js.map +1 -0
  45. package/lib/utils.d.ts.map +1 -0
  46. package/lib/utils.js.map +1 -0
  47. package/package.json +1 -6
  48. package/src/app-action-schema.ts +83 -0
  49. package/src/app-logs-schema.ts +13 -0
  50. package/src/app-state-schema.ts +27 -0
  51. package/src/common.ts +19 -0
  52. package/src/constants.ts +141 -0
  53. package/src/device-action-schema.ts +11 -0
  54. package/src/device-agent-action-schema.ts +17 -0
  55. package/src/device-stats-schema.ts +33 -0
  56. package/src/index.ts +192 -0
  57. package/src/message-builders.ts +269 -0
  58. package/src/schemas/app-install-response-schema.json +38 -0
  59. package/src/schemas/app-install-schema.json +25 -0
  60. package/src/schemas/app-logs-schema.json +15 -0
  61. package/src/schemas/app-state-control-schema.json +16 -0
  62. package/src/schemas/app-state-schema.json +45 -0
  63. package/src/schemas/app-uninstall-schema.json +16 -0
  64. package/src/schemas/app-update-config-schema.json +22 -0
  65. package/src/schemas/app-version-control-schema.json +17 -0
  66. package/src/schemas/common-schema.json +27 -0
  67. package/src/schemas/device-action-schema.json +13 -0
  68. package/src/schemas/device-agent-status-schema.json +33 -0
  69. package/src/schemas/device-stats-schema.json +57 -0
  70. package/src/schemas/env-var-schema.json +18 -0
  71. package/src/schemas/live-updates-toggle-schema.json +27 -0
  72. package/src/schemas/models-install-payload-schema.json +21 -0
  73. package/src/schemas/models-install-response-schema.json +21 -0
  74. package/src/schemas/secure-tunnel-schema.json +31 -0
  75. package/src/schemas/shadow-project-update-legacy-schema.json +30 -0
  76. package/src/schemas/shadow-project-update-schema.json +16 -0
  77. package/src/schemas/shadow-projects-update-all-schema.json +20 -0
  78. package/src/schemas/signed-urls-request-schema.json +39 -0
  79. package/src/schemas/status-response-schema.json +15 -0
  80. package/src/schemas/system-information-schema.json +149 -0
  81. package/src/schemas/to-client-message-schema.json +92 -0
  82. package/src/schemas/to-cloud-message-schema.json +53 -0
  83. package/src/schemas/to-device-agent-message-schema.json +127 -0
  84. package/src/shadow-schema.ts +258 -0
  85. package/src/signed-urls-request-schema.ts +22 -0
  86. package/src/status-response-schema.ts +19 -0
  87. package/src/types.ts +160 -0
  88. package/src/utils.ts +21 -0
  89. package/tsconfig.build.json +4 -0
  90. package/tsconfig.eslint.json +5 -0
  91. package/tsconfig.json +88 -0
@@ -0,0 +1,149 @@
1
+ {
2
+ "$id": "https://alwaysai.co/system-information-schema.json",
3
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
4
+ "title": "system-information",
5
+ "type": "object",
6
+ "properties": {
7
+ "os": {
8
+ "type": "object",
9
+ "properties": {
10
+ "platform": {
11
+ "type": "string"
12
+ },
13
+ "distro": {
14
+ "type": "string"
15
+ },
16
+ "release": {
17
+ "type": "string"
18
+ },
19
+ "kernel": {
20
+ "type": "string"
21
+ },
22
+ "architecture": {
23
+ "type": "string"
24
+ },
25
+ "hostname": {
26
+ "type": "string"
27
+ }
28
+ }
29
+ },
30
+ "cpu": {
31
+ "type": "object",
32
+ "properties": {
33
+ "manufacturer": {
34
+ "type": "string"
35
+ },
36
+ "brand": {
37
+ "type": "string"
38
+ },
39
+ "vendor": {
40
+ "type": "string"
41
+ },
42
+ "model": {
43
+ "type": "string"
44
+ },
45
+ "cores": {
46
+ "type": "string"
47
+ },
48
+ "physicalCores": {
49
+ "type": "string"
50
+ },
51
+ "efficiencyCores": {
52
+ "type": "string"
53
+ },
54
+ "processors": {
55
+ "type": "string"
56
+ }
57
+ }
58
+ },
59
+ "disk": {
60
+ "type": "object",
61
+ "properties": {
62
+ "drives": {
63
+ "type": "array",
64
+ "items": {
65
+ "type": "object",
66
+ "properties": {
67
+ "device": {
68
+ "type": "string"
69
+ },
70
+ "type": {
71
+ "type": "string"
72
+ },
73
+ "name": {
74
+ "type": "string"
75
+ },
76
+ "vendor": {
77
+ "type": "string"
78
+ },
79
+ "size": {
80
+ "type": "string"
81
+ }
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "required": []
87
+ },
88
+ "device": {
89
+ "type": "object",
90
+ "properties": {
91
+ "manufacturer": {
92
+ "type": "string"
93
+ },
94
+ "model": {
95
+ "type": "string"
96
+ },
97
+ "version": {
98
+ "type": "string"
99
+ },
100
+ "serial": {
101
+ "type": "string"
102
+ },
103
+ "virtual": {
104
+ "type": "boolean"
105
+ }
106
+ }
107
+ },
108
+ "network": {
109
+ "type": "object",
110
+ "properties": {
111
+ "ipv4Address": {
112
+ "type": "string"
113
+ },
114
+ "ipv6Address": {
115
+ "type": "string"
116
+ },
117
+ "macAddress": {
118
+ "type": "string"
119
+ }
120
+ }
121
+ },
122
+ "versions": {
123
+ "type": "object",
124
+ "properties": {
125
+ "agent": {
126
+ "type": "string"
127
+ },
128
+ "deviceAgentSchemas": {
129
+ "type": "string"
130
+ },
131
+ "npm": {
132
+ "type": "string"
133
+ },
134
+ "node": {
135
+ "type": "string"
136
+ },
137
+ "docker": {
138
+ "type": "string"
139
+ },
140
+ "dockerCompose": {
141
+ "type": "string"
142
+ }
143
+ }
144
+ },
145
+ "lastBootTime": {
146
+ "type": "string"
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,92 @@
1
+ {
2
+ "$id": "https://alwaysai.co/to-client-message-schema.json",
3
+ "title": "to_client_message",
4
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
5
+ "description": "The messaging payload structure for messages sent from device agent to clients",
6
+ "type": "object",
7
+ "properties": {
8
+ "timestamp": {
9
+ "type": "string"
10
+ },
11
+ "deviceId": {
12
+ "description": "Device UUID of device sending the message",
13
+ "type": "string"
14
+ },
15
+ "topic": {
16
+ "oneOf": [{ "$ref": "#/$defs/toClient" }]
17
+ },
18
+ "messageType": {
19
+ "type": "string",
20
+ "enum": [
21
+ "device_stats",
22
+ "app_state",
23
+ "status_response",
24
+ "app_logs"
25
+ ]
26
+ },
27
+ "txId": {
28
+ "$ref": "https://alwaysai.co/common-schema.json#/$defs/txId"
29
+ },
30
+ "payload": {
31
+ "type": "object"
32
+ }
33
+ },
34
+ "required": ["timestamp", "deviceId", "messageType", "txId", "payload"],
35
+ "allOf":[
36
+ {
37
+ "if": {
38
+ "properties": {
39
+ "messageType": { "const": "device_stats" }
40
+ }
41
+ },
42
+ "then": {
43
+ "properties": {
44
+ "payload": {"$ref": "https://alwaysai.co/device-stats-schema.json"}
45
+ }
46
+ }
47
+ },
48
+ {
49
+ "if": {
50
+ "properties": {
51
+ "messageType": { "const": "app_state" }
52
+ }
53
+ },
54
+ "then": {
55
+ "properties": {
56
+ "payload": {"$ref": "https://alwaysai.co/app-state-schema.json"}
57
+ }
58
+ }
59
+ },
60
+ {
61
+ "if": {
62
+ "properties": {
63
+ "messageType": { "const": "status_response" }
64
+ }
65
+ },
66
+ "then": {
67
+ "properties": {
68
+ "payload": {"$ref": "https://alwaysai.co/status-response-schema.json"}
69
+ }
70
+ }
71
+ },
72
+ {
73
+ "if": {
74
+ "properties": {
75
+ "messageType": { "const": "app_logs" }
76
+ }
77
+ },
78
+ "then": {
79
+ "properties": {
80
+ "payload": {"$ref": "https://alwaysai.co/app-logs-schema.json"}
81
+ }
82
+ }
83
+ }
84
+ ],
85
+ "$defs": {
86
+ "toClient": {
87
+ "description": "Messages sent from the device agent to console client",
88
+ "type": "string",
89
+ "pattern": "to-client/aai-device/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "$id": "https://alwaysai.co/cloud-message-schema.json",
3
+ "title": "cloud_message",
4
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
5
+ "description": "The messaging payload structure for messages sent from device agent to the cloud",
6
+ "type": "object",
7
+ "properties": {
8
+ "timestamp": {
9
+ "type": "string"
10
+ },
11
+ "deviceId": {
12
+ "description": "Device UUID of device sending the message",
13
+ "type": "string"
14
+ },
15
+ "topic": {
16
+ "oneOf": [{ "$ref": "#/$defs/toCloud" }]
17
+ },
18
+ "messageType": {
19
+ "type": "string",
20
+ "enum": [
21
+ "signed_urls_request"
22
+ ]
23
+ },
24
+ "txId": {
25
+ "$ref": "https://alwaysai.co/common-schema.json#/$defs/txId"
26
+ },
27
+ "payload": {
28
+ "type": "object"
29
+ }
30
+ },
31
+ "allOf":[
32
+ {
33
+ "if": {
34
+ "properties": {
35
+ "messageType": { "const": "signed_urls_request" }
36
+ }
37
+ },
38
+ "then": {
39
+ "properties": {
40
+ "payload": {"$ref": "https://alwaysai.co/signed-urls-request-schema.json"}
41
+ }
42
+ }
43
+ }
44
+ ],
45
+ "required": ["timestamp", "deviceId", "txId", "payload", "messageType"],
46
+ "$defs": {
47
+ "toCloud": {
48
+ "description": "Messages sent from the device agent to cloud backend client",
49
+ "type": "string",
50
+ "pattern": "to-cloud/aai-device/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,127 @@
1
+ {
2
+ "$id": "https://alwaysai.co/to-device-agent-message-schema.json",
3
+ "$schema": "https://json-schema.org/draft/2019-09/schema",
4
+ "title": "to_device_agent_message",
5
+ "description":
6
+ "A schema that describes the message payload structure for messages sent from clients to device agent",
7
+ "type": "object",
8
+ "properties": {
9
+ "timestamp": {
10
+ "type": "string"
11
+ },
12
+ "topic": { "$ref": "#/$defs/toDevice" },
13
+ "messageType": {
14
+ "type": "string",
15
+ "enum": [
16
+ "app_state_control",
17
+ "app_version_control",
18
+ "fleet_app_version_control",
19
+ "app_install_response",
20
+ "models_install_response",
21
+ "live_state_updates",
22
+ "device_action",
23
+ "status_response"
24
+ ]
25
+ },
26
+ "txId": {
27
+ "$ref": "https://alwaysai.co/common-schema.json#/$defs/txId"
28
+ },
29
+ "payload": {
30
+ "type": "object"
31
+ }
32
+ },
33
+ "required": ["messageType", "timestamp", "txId", "payload"],
34
+ "allOf":[
35
+ {
36
+ "if": {
37
+ "properties": {
38
+ "messageType": { "const": "app_state_control" }
39
+ }
40
+ },
41
+ "then": {
42
+ "properties": {
43
+ "payload": {"$ref": "https://alwaysai.co/app-state-control-schema.json"}
44
+ }
45
+ }
46
+ },
47
+ {
48
+ "if": {
49
+ "properties": {
50
+ "messageType": { "const": "app_version_control" }
51
+ }
52
+ },
53
+ "then": {
54
+ "properties": {
55
+ "payload": {"$ref": "https://alwaysai.co/app-version-control-schema.json"}
56
+ }
57
+ }
58
+ },
59
+ {
60
+ "if": {
61
+ "properties": {
62
+ "messageType": { "const": "app_install_response" }
63
+ }
64
+ },
65
+ "then": {
66
+ "properties": {
67
+ "payload": {"$ref": "https://alwaysai.co/app-install-response-schema.json"}
68
+ }
69
+ }
70
+ },
71
+ {
72
+ "if": {
73
+ "properties": {
74
+ "messageType": { "const": "models_install_response" }
75
+ }
76
+ },
77
+ "then": {
78
+ "properties": {
79
+ "payload": {"$ref": "https://alwaysai.co/models-install-response-schema.json"}
80
+ }
81
+ }
82
+ },
83
+ {
84
+ "if": {
85
+ "properties": {
86
+ "messageType": { "const": "live_state_updates" }
87
+ }
88
+ },
89
+ "then": {
90
+ "properties": {
91
+ "payload": {"$ref": "https://alwaysai.co/live-updates-toggle-schema.json"}
92
+ }
93
+ }
94
+ },
95
+ {
96
+ "if": {
97
+ "properties": {
98
+ "messageType": { "const": "device_action" }
99
+ }
100
+ },
101
+ "then": {
102
+ "properties": {
103
+ "payload": {"$ref": "https://alwaysai.co/device-action-schema.json"}
104
+ }
105
+ }
106
+ },
107
+ {
108
+ "if": {
109
+ "properties": {
110
+ "messageType": { "const": "status_response" }
111
+ }
112
+ },
113
+ "then": {
114
+ "properties": {
115
+ "payload": {"$ref": "https://alwaysai.co/status-response-schema.json"}
116
+ }
117
+ }
118
+ }
119
+ ],
120
+ "$defs": {
121
+ "toDevice": {
122
+ "description": "Topic on which messages are sent to device agent.",
123
+ "type": "string",
124
+ "pattern": "^to-device/aai-device/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
125
+ }
126
+ }
127
+ }
@@ -0,0 +1,258 @@
1
+ import Ajv2019 from 'ajv/dist/2019';
2
+ import * as commonSchema from './schemas/common-schema.json';
3
+ import * as deviceAgentStatusSchema from './schemas/device-agent-status-schema.json';
4
+ import * as envVarSchema from './schemas/env-var-schema.json';
5
+ import * as secureTunnelSchema from './schemas/secure-tunnel-schema.json';
6
+ import * as shadowProjectUpdateLegacySchema from './schemas/shadow-project-update-legacy-schema.json';
7
+ import * as shadowProjectUpdateSchema from './schemas/shadow-project-update-schema.json';
8
+ import * as shadowProjectsUpdateAllSchema from './schemas/shadow-projects-update-all-schema.json';
9
+ import * as systemInformationSchema from './schemas/system-information-schema.json';
10
+
11
+ import { keyMirror } from './utils';
12
+
13
+ const ajv = new Ajv2019({
14
+ allErrors: true,
15
+ schemas: [commonSchema]
16
+ });
17
+
18
+ export function getDesiredFromMessage(message) {
19
+ if (message?.state?.desired) {
20
+ return message.state.desired;
21
+ } else return null;
22
+ }
23
+
24
+ export function getReportedFromMessage(message) {
25
+ if (message?.state?.reported) {
26
+ return message.state.reported;
27
+ } else return null;
28
+ }
29
+
30
+ export function getUpdateDeltaStateFromMessage(message) {
31
+ if (message?.state) {
32
+ return message.state;
33
+ } else return null;
34
+ }
35
+
36
+ /* ============================================================================
37
+ Shadow Topics
38
+ ============================================================================ */
39
+
40
+ const SHADOW_PREFIX = `$aws/things/`;
41
+
42
+ export const ShadowTopics = keyMirror({
43
+ get: null,
44
+ 'get/accepted': null,
45
+ 'get/rejected': null,
46
+ update: null,
47
+ 'update/delta': null,
48
+ 'update/accepted': null,
49
+ 'update/rejected': null,
50
+ delete: null,
51
+ 'delete/accepted': null,
52
+ 'delete/rejected': null
53
+ });
54
+ export type ShadowTopics = keyof typeof ShadowTopics;
55
+ export const SHADOW_TOPICS = Object.keys(ShadowTopics) as ShadowTopics[];
56
+
57
+ const ShadowNames = keyMirror({
58
+ projects: null,
59
+ 'system-info': null,
60
+ 'secure-tunnel': null,
61
+ 'device-agent-status': null
62
+ });
63
+ export type ShadowNames = keyof typeof ShadowNames;
64
+ export const SHADOW_NAMES = Object.keys(ShadowNames) as ShadowNames[];
65
+
66
+ export const getShadowTopic = (
67
+ clientId: string,
68
+ shadowName: ShadowNames,
69
+ shadowTopic: ShadowTopics
70
+ ) => `${SHADOW_PREFIX}${clientId}/shadow/name/${shadowName}/${shadowTopic}`;
71
+
72
+ /* ============================================================================
73
+ Project Shadow
74
+ ============================================================================ */
75
+
76
+ export type ShadowUpdateTypes =
77
+ | ShadowProjectsUpdateAll
78
+ | SystemInformationShadowUpdate
79
+ | SecureTunnelShadowUpdate
80
+ | DeviceAgentStatusShadowUpdate;
81
+
82
+ export interface ProjectShadowUpdate {
83
+ appConfig?: string;
84
+ envVars?: string;
85
+ }
86
+
87
+ export interface ProjectShadowUpdateLegacy {
88
+ appConfig?: string;
89
+ envVars?: {
90
+ [service: string]: {
91
+ [key: string]: string | null;
92
+ };
93
+ };
94
+ }
95
+
96
+ export interface ShadowProjectsUpdateAll {
97
+ [projectId: string]: ProjectShadowUpdate | null;
98
+ }
99
+
100
+ // Shadow Message validator functions
101
+ ajv.addSchema(shadowProjectUpdateSchema, 'shadow-project-update-schema.json');
102
+ export const validateProjectShadowUpdate = ajv.compile<ProjectShadowUpdate>(
103
+ shadowProjectUpdateSchema
104
+ );
105
+
106
+ ajv.addSchema(
107
+ shadowProjectUpdateLegacySchema,
108
+ 'shadow-project-update-legacy-schema.json'
109
+ );
110
+ export const validateLegacyProjectShadowUpdate =
111
+ ajv.compile<ProjectShadowUpdateLegacy>(shadowProjectUpdateSchema);
112
+
113
+ ajv.addSchema(
114
+ shadowProjectsUpdateAllSchema,
115
+ 'shadow-projects-update-all-schema.json'
116
+ );
117
+ export const validateShadowProjectsUpdateAll =
118
+ ajv.compile<ShadowProjectsUpdateAll>(shadowProjectsUpdateAllSchema);
119
+
120
+ /* ============================================================================
121
+ System Information Shadow
122
+ ============================================================================ */
123
+
124
+ export interface SystemInformationShadowUpdate {
125
+ os?: {
126
+ platform?: string;
127
+ distro?: string;
128
+ release?: string;
129
+ kernel?: string;
130
+ architecture?: string;
131
+ hostname?: string;
132
+ };
133
+ cpu?: {
134
+ manufacturer?: string;
135
+ brand?: string;
136
+ vendor?: string;
137
+ model?: string;
138
+ cores?: string;
139
+ physicalCores?: string;
140
+ efficiencyCores?: string;
141
+ processors?: string;
142
+ };
143
+ disk?: {
144
+ drives: {
145
+ device?: string;
146
+ type?: string;
147
+ name?: string;
148
+ vendor?: string;
149
+ size?: string;
150
+ }[];
151
+ };
152
+ device?: {
153
+ manufacturer?: string;
154
+ model?: string;
155
+ version?: string;
156
+ serial?: string;
157
+ virtual?: boolean; // boolean on purpose
158
+ };
159
+ network?: {
160
+ ipv4Address?: string;
161
+ ipv6Address?: string;
162
+ macAddress?: string;
163
+ };
164
+ versions?: {
165
+ agent?: string;
166
+ deviceAgentSchemas?: string;
167
+ npm?: string;
168
+ node?: string;
169
+ docker?: string;
170
+ dockerCompose?: string;
171
+ };
172
+ lastBootTime?: string;
173
+ }
174
+
175
+ ajv.addSchema(systemInformationSchema, 'system-information-schema.json');
176
+ export const validateSystemInformationShadowUpdate =
177
+ ajv.compile<SystemInformationShadowUpdate>(systemInformationSchema);
178
+
179
+ /* ============================================================================
180
+ Environment Variables Shadow
181
+ ============================================================================ */
182
+
183
+ export interface EnvVars {
184
+ [service: string]: {
185
+ [name: string]: string | null;
186
+ };
187
+ }
188
+
189
+ ajv.addSchema(envVarSchema, 'env-var-schema.json');
190
+ export const validateEnvVarSchemaShadowUpdate =
191
+ ajv.compile<EnvVars>(envVarSchema);
192
+
193
+ /* ============================================================================
194
+ Secure Tunnel Shadow
195
+ ============================================================================ */
196
+
197
+ export type SecureTunnelPortInfo = {
198
+ enabled: boolean;
199
+ type: string;
200
+ ip: string;
201
+ port: number;
202
+ };
203
+
204
+ export type SecureTunnelShadowUpdate = {
205
+ st_ports: SecureTunnelPortInfo[];
206
+ };
207
+
208
+ ajv.addSchema(secureTunnelSchema, 'secure-tunnel-schema.json');
209
+ export const validateSecureTunnelShadowUpdate =
210
+ ajv.compile<SecureTunnelShadowUpdate>(secureTunnelSchema);
211
+
212
+ /* ============================================================================
213
+ Device Agent Status
214
+ ============================================================================ */
215
+
216
+ export const passthroughStatusEnum = keyMirror({
217
+ starting: null,
218
+ running: null,
219
+ error: null,
220
+ disabled: null
221
+ });
222
+
223
+ export type PassthroughStatusValue = keyof typeof passthroughStatusEnum;
224
+ export interface DeviceAgentStatusShadowUpdate {
225
+ passthrough: {
226
+ status: PassthroughStatusValue;
227
+ message: string;
228
+ };
229
+ }
230
+
231
+ ajv.addSchema(deviceAgentStatusSchema, 'device-agent-status-schema.json');
232
+ export const validateDeviceAgentStatusShadowUpdate =
233
+ ajv.compile<DeviceAgentStatusShadowUpdate>(deviceAgentStatusSchema);
234
+
235
+ /* ============================================================================
236
+ Shadow Message Builders
237
+ ============================================================================ */
238
+
239
+ export function buildUpdateShadowMessage<T extends ShadowUpdateTypes>(opts: {
240
+ clientId: string;
241
+ reported?: T;
242
+ desired?: T;
243
+ }) {
244
+ const { clientId, reported, desired } = opts;
245
+ const state = { reported, desired };
246
+ const message = {
247
+ ...buildBaseShadowMessage(clientId),
248
+ state
249
+ };
250
+ return message;
251
+ }
252
+
253
+ export function buildBaseShadowMessage(clientId: string) {
254
+ const baseShadowMessage = {
255
+ clientToken: clientId
256
+ };
257
+ return baseShadowMessage;
258
+ }
@@ -0,0 +1,22 @@
1
+ import { SignedUrlsRequestMessageType } from './constants';
2
+ import { BaseToClientMessage } from './common';
3
+
4
+ type ModelsObject = {
5
+ [modelId: string]: number;
6
+ };
7
+
8
+ export interface SignedUrlsRequestPayload {
9
+ signedUrlsRequest?: {
10
+ projectId: string;
11
+ appReleaseHash: string;
12
+ };
13
+ modelsOnlyUrlsRequest?: {
14
+ projectId: string;
15
+ models: ModelsObject;
16
+ };
17
+ }
18
+
19
+ export interface SignedUrlsRequestMessage extends BaseToClientMessage {
20
+ messageType: SignedUrlsRequestMessageType;
21
+ payload: SignedUrlsRequestPayload;
22
+ }