@northern.tech/testing 0.8.3 → 0.9.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.
Files changed (101) hide show
  1. package/dist/chunk-CKQMccvm.cjs +28 -0
  2. package/dist/mockData.cjs +1288 -953
  3. package/dist/mockData.cjs.map +1 -1
  4. package/dist/mockData.d.cts +595 -569
  5. package/dist/mockData.d.ts +595 -569
  6. package/dist/mockData.js +1278 -45
  7. package/dist/mockData.js.map +1 -1
  8. package/dist/openapi.yaml.d.cjs +0 -0
  9. package/dist/openapi.yaml.d.cts +4 -0
  10. package/dist/openapi.yaml.d.ts +5 -0
  11. package/dist/requestHandlers/deploymentHandlers.cjs +181 -1031
  12. package/dist/requestHandlers/deploymentHandlers.cjs.map +1 -1
  13. package/dist/requestHandlers/deploymentHandlers.d.cts +5 -3
  14. package/dist/requestHandlers/deploymentHandlers.d.ts +5 -3
  15. package/dist/requestHandlers/deploymentHandlers.js +190 -6
  16. package/dist/requestHandlers/deploymentHandlers.js.map +1 -1
  17. package/dist/requestHandlers/deviceHandlers.cjs +427 -1090
  18. package/dist/requestHandlers/deviceHandlers.cjs.map +1 -1
  19. package/dist/requestHandlers/deviceHandlers.d.cts +17 -15
  20. package/dist/requestHandlers/deviceHandlers.d.ts +17 -15
  21. package/dist/requestHandlers/deviceHandlers.js +427 -10
  22. package/dist/requestHandlers/deviceHandlers.js.map +1 -1
  23. package/dist/requestHandlers/monitorHandlers.cjs +21 -831
  24. package/dist/requestHandlers/monitorHandlers.cjs.map +1 -1
  25. package/dist/requestHandlers/monitorHandlers.d.cts +5 -3
  26. package/dist/requestHandlers/monitorHandlers.d.ts +5 -3
  27. package/dist/requestHandlers/monitorHandlers.js +21 -7
  28. package/dist/requestHandlers/monitorHandlers.js.map +1 -1
  29. package/dist/requestHandlers/organizationHandlers.cjs +296 -1113
  30. package/dist/requestHandlers/organizationHandlers.cjs.map +1 -1
  31. package/dist/requestHandlers/organizationHandlers.d.cts +5 -3
  32. package/dist/requestHandlers/organizationHandlers.d.ts +5 -3
  33. package/dist/requestHandlers/organizationHandlers.js +308 -6
  34. package/dist/requestHandlers/organizationHandlers.js.map +1 -1
  35. package/dist/requestHandlers/releaseHandlers.cjs +157 -960
  36. package/dist/requestHandlers/releaseHandlers.cjs.map +1 -1
  37. package/dist/requestHandlers/releaseHandlers.d.cts +5 -3
  38. package/dist/requestHandlers/releaseHandlers.d.ts +5 -3
  39. package/dist/requestHandlers/releaseHandlers.js +158 -6
  40. package/dist/requestHandlers/releaseHandlers.js.map +1 -1
  41. package/dist/requestHandlers/requestHandlers.cjs +26 -2000
  42. package/dist/requestHandlers/requestHandlers.cjs.map +1 -1
  43. package/dist/requestHandlers/requestHandlers.d.cts +5 -4
  44. package/dist/requestHandlers/requestHandlers.d.ts +5 -3
  45. package/dist/requestHandlers/requestHandlers.js +24 -32
  46. package/dist/requestHandlers/requestHandlers.js.map +1 -1
  47. package/dist/requestHandlers/userHandlers.cjs +139 -990
  48. package/dist/requestHandlers/userHandlers.cjs.map +1 -1
  49. package/dist/requestHandlers/userHandlers.d.cts +5 -3
  50. package/dist/requestHandlers/userHandlers.d.ts +5 -3
  51. package/dist/requestHandlers/userHandlers.js +139 -7
  52. package/dist/requestHandlers/userHandlers.js.map +1 -1
  53. package/dist/requestHandlers/validation.cjs +4 -0
  54. package/dist/requestHandlers/validation.d.cts +6 -0
  55. package/dist/requestHandlers/validation.d.ts +6 -0
  56. package/dist/requestHandlers/validation.js +2 -0
  57. package/dist/setupTests.cjs +148 -992
  58. package/dist/setupTests.cjs.map +1 -1
  59. package/dist/setupTests.d.cts +68 -66
  60. package/dist/setupTests.d.ts +68 -66
  61. package/dist/setupTests.js +114 -117
  62. package/dist/setupTests.js.map +1 -1
  63. package/dist/theme/light.cjs +7 -39
  64. package/dist/theme/light.cjs.map +1 -1
  65. package/dist/theme/light.d.cts +5 -10
  66. package/dist/theme/light.d.ts +5 -10
  67. package/dist/theme/light.js +7 -6
  68. package/dist/theme/light.js.map +1 -1
  69. package/dist/theme/mui.d.cjs +0 -0
  70. package/dist/theme/mui.d.cts +11 -0
  71. package/dist/theme/mui.d.ts +11 -0
  72. package/dist/utils.cjs +18 -68
  73. package/dist/utils.cjs.map +1 -1
  74. package/dist/utils.d.cts +6 -67
  75. package/dist/utils.d.ts +6 -67
  76. package/dist/utils.js +16 -10
  77. package/dist/utils.js.map +1 -1
  78. package/dist/validation-CsEFO-Cv.cjs +77 -0
  79. package/dist/validation-CsEFO-Cv.cjs.map +1 -0
  80. package/dist/validation-JDM_vsFz.js +64 -0
  81. package/dist/validation-JDM_vsFz.js.map +1 -0
  82. package/package.json +8 -6
  83. package/dist/chunk-3CVNBMEF.js +0 -161
  84. package/dist/chunk-3CVNBMEF.js.map +0 -1
  85. package/dist/chunk-7GNK7IRV.js +0 -29
  86. package/dist/chunk-7GNK7IRV.js.map +0 -1
  87. package/dist/chunk-AP4MOFMD.js +0 -239
  88. package/dist/chunk-AP4MOFMD.js.map +0 -1
  89. package/dist/chunk-DOHA53UH.js +0 -301
  90. package/dist/chunk-DOHA53UH.js.map +0 -1
  91. package/dist/chunk-H4J7L3HX.js +0 -188
  92. package/dist/chunk-H4J7L3HX.js.map +0 -1
  93. package/dist/chunk-HRGVXWMH.js +0 -17
  94. package/dist/chunk-HRGVXWMH.js.map +0 -1
  95. package/dist/chunk-KCLTR6QS.js +0 -34
  96. package/dist/chunk-KCLTR6QS.js.map +0 -1
  97. package/dist/chunk-M2TKDOPD.js +0 -266
  98. package/dist/chunk-M2TKDOPD.js.map +0 -1
  99. package/dist/chunk-O42KIJXJ.js +0 -933
  100. package/dist/chunk-O42KIJXJ.js.map +0 -1
  101. /package/dist/{baseTestConfig.json → public/baseTestConfig.json} +0 -0
@@ -1,1096 +1,433 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../chunk-CKQMccvm.cjs");
3
+ const require_mockData = require("../mockData.cjs");
4
+ const require_validation = require("../validation-CsEFO-Cv.cjs");
5
+ let _northern_tech_utils_constants = require("@northern.tech/utils/constants");
6
+ let msw = require("msw");
7
+ //#region src/requestHandlers/deviceHandlers.ts
8
+ const defaultDeviceId = "a1";
9
+ const deviceAuthDevice = {
10
+ id: "a1",
11
+ identity_data: { mac: require_mockData.defaultMacAddress },
12
+ status: "accepted",
13
+ decommissioning: false,
14
+ created_ts: require_mockData.defaultCreationDate,
15
+ updated_ts: "2019-01-01T09:25:00.000Z",
16
+ auth_sets: [{
17
+ id: "auth1",
18
+ identity_data: { mac: require_mockData.defaultMacAddress },
19
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
20
+ ts: require_mockData.defaultCreationDate,
21
+ status: "accepted"
22
+ }]
9
23
  };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
24
+ const checkInTimeExact = "2019-01-01T10:25:00.000Z";
25
+ const updatedTime = "2019-01-01T09:25:00.000Z";
26
+ const inventoryDevice = {
27
+ id: "a1",
28
+ attributes: [
29
+ {
30
+ name: "network_interfaces",
31
+ value: ["eth0", "wlan0"],
32
+ scope: "inventory"
33
+ },
34
+ {
35
+ name: "kernel",
36
+ value: "Linux version 4.19.75-v7l+",
37
+ scope: "inventory"
38
+ },
39
+ {
40
+ name: "artifact_name",
41
+ value: "raspotifyInstaller",
42
+ scope: "inventory"
43
+ },
44
+ {
45
+ name: "ipv6_wlan0",
46
+ value: "fe80::68d9:8453:3e9c:7c80/64",
47
+ scope: "inventory"
48
+ },
49
+ {
50
+ name: "mac_eth0",
51
+ value: require_mockData.defaultMacAddress,
52
+ scope: "inventory"
53
+ },
54
+ {
55
+ name: "rootfs_type",
56
+ value: "ext4",
57
+ scope: "inventory"
58
+ },
59
+ {
60
+ name: "mender_bootloader_integration",
61
+ value: "unknown",
62
+ scope: "inventory"
63
+ },
64
+ {
65
+ name: "cpu_model",
66
+ value: "ARMv7 Processor rev 3 (v7l)",
67
+ scope: "inventory"
68
+ },
69
+ {
70
+ name: "hostname",
71
+ value: "raspberrypi",
72
+ scope: "inventory"
73
+ },
74
+ {
75
+ name: "mender_client_version",
76
+ value: "2.1.0",
77
+ scope: "inventory"
78
+ },
79
+ {
80
+ name: "ipv4_wlan0",
81
+ value: "192.168.10.141/24",
82
+ scope: "inventory"
83
+ },
84
+ {
85
+ name: "device_type",
86
+ value: "raspberrypi4",
87
+ scope: "inventory"
88
+ },
89
+ {
90
+ name: "mem_total_kB",
91
+ value: "1986024",
92
+ scope: "inventory"
93
+ },
94
+ {
95
+ name: "mac_wlan0",
96
+ value: "dc:a6:32:12:ad:c0",
97
+ scope: "inventory"
98
+ },
99
+ {
100
+ name: "os",
101
+ value: "Raspbian GNU/Linux 10 (buster)",
102
+ scope: "inventory"
103
+ },
104
+ {
105
+ name: "created_ts",
106
+ value: require_mockData.defaultCreationDate,
107
+ scope: "system"
108
+ },
109
+ {
110
+ name: "updated_ts",
111
+ value: updatedTime,
112
+ scope: "system"
113
+ },
114
+ {
115
+ name: "status",
116
+ value: "accepted",
117
+ scope: "identity"
118
+ },
119
+ {
120
+ name: "mac",
121
+ value: require_mockData.defaultMacAddress,
122
+ scope: "identity"
123
+ },
124
+ {
125
+ name: "group",
126
+ value: "test",
127
+ scope: "system"
128
+ }
129
+ ],
130
+ check_in_time: checkInTimeExact,
131
+ updated_ts: updatedTime
17
132
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/requestHandlers/deviceHandlers.ts
21
- var deviceHandlers_exports = {};
22
- __export(deviceHandlers_exports, {
23
- defaultDeviceId: () => defaultDeviceId,
24
- deviceHandlers: () => deviceHandlers,
25
- inventoryDevice: () => inventoryDevice
26
- });
27
- module.exports = __toCommonJS(deviceHandlers_exports);
28
- var import_constants2 = require("@northern.tech/utils/constants");
29
- var import_msw = require("msw");
30
-
31
- // src/mockData.ts
32
- var import_constants = require("@northern.tech/utils/constants");
33
- var TEST_SESSION_DATETIME = "2019-01-13T13:00:00.000Z";
34
- var testDate = new Date(TEST_SESSION_DATETIME);
35
- var mockDate = new Date(testDate.setMilliseconds(testDate.getMilliseconds() + import_constants.maxSessionAge));
36
- var defaultCreationDate = "2019-01-13T06:25:00.000Z";
37
- var defaultMacAddress = "dc:a6:32:12:ad:bf";
38
- var permissionSetObjectTypes = {
39
- any: "Any",
40
- artifacts: "Artifacts",
41
- empty: "",
42
- groups: "Device groups",
43
- releases: "Releases",
44
- tenantManagement: "Tenant management",
45
- userManagement: "User management"
46
- };
47
- var commonEndpoints = {
48
- artifacts: "^/api/management/v1/deployments/artifacts",
49
- artifactDetails: "^/api/management/v1/deployments/artifacts/[^/]+",
50
- deviceManagement: "^/api/management/(v[1-9])/(devauth|inventory)/"
51
- };
52
- var userId = "a30a780b-b843-5344-80e3-0fd95a4f6fc3";
53
- var defaultUser = {
54
- created_ts: "2019-01-01T10:30:00.000Z",
55
- email: "a@b.com",
56
- id: "a1",
57
- roles: ["RBAC_ROLE_PERMIT_ALL"],
58
- tfa_status: "enabled",
59
- verified: true
60
- };
61
- var deviceTypes = { qemu: "qemux86-64" };
62
- var checkInTimeRounded = "2019-01-01T00:00:00.000Z";
63
- var checkInTimeExact = "2019-01-01T10:25:00.000Z";
64
- var mockApiResponses = {
65
- deployments: {
66
- byId: {
67
- d1: {
68
- id: "d1",
69
- name: "test deployment",
70
- created: "2019-01-01T12:30:00.000Z",
71
- devices: {
72
- a1: {
73
- id: "a1",
74
- status: "installing",
75
- attributes: {},
76
- image: { size: 123 }
77
- }
78
- },
79
- statistics: {
80
- status: {
81
- "already-installed": 0,
82
- decommissioned: 0,
83
- downloading: 0,
84
- failure: 0,
85
- installing: 1,
86
- noartifact: 0,
87
- pending: 0,
88
- rebooting: 0,
89
- success: 0
90
- },
91
- total_size: 1234
92
- }
93
- },
94
- d2: {
95
- id: "d2",
96
- name: "test deployment 2",
97
- artifact_name: "r1",
98
- artifacts: ["123"],
99
- created: "2019-01-01T12:25:00.000Z",
100
- device_count: 1,
101
- devices: {
102
- b1: {
103
- attributes: {},
104
- id: "b1",
105
- status: "pending"
106
- }
107
- },
108
- filter: void 0,
109
- group: void 0,
110
- statistics: {
111
- status: {
112
- downloading: 0,
113
- decommissioned: 0,
114
- failure: 0,
115
- installing: 0,
116
- noartifact: 0,
117
- pending: 1,
118
- rebooting: 0,
119
- success: 0,
120
- "already-installed": 0
121
- }
122
- }
123
- },
124
- d3: {
125
- id: "d3",
126
- name: "Test",
127
- phases: [
128
- { id: "0", batch_size: 2, device_count: 2 },
129
- { id: "1", start_ts: "2019-02-04T11:45:10.002Z", batch_size: 3, device_count: 3 },
130
- { id: "2", start_ts: "2019-02-05T11:45:10.002Z", batch_size: 5, device_count: 5 },
131
- { id: "3", start_ts: "2019-02-06T11:45:10.002Z", batch_size: 5, device_count: 5 },
132
- { id: "4", start_ts: "2019-02-21T11:45:10.002Z", batch_size: 5, device_count: 0 }
133
- ],
134
- max_devices: 0,
135
- created: "2019-01-31T12:59:30.020Z",
136
- devices: {},
137
- filter: void 0,
138
- group: void 0,
139
- stats: {
140
- pending: 3,
141
- decommissioned: 0,
142
- failure: 23,
143
- pause_before_committing: 0,
144
- pause_before_rebooting: 0,
145
- installing: 0,
146
- rebooting: 0,
147
- "already-installed": 0,
148
- pause_before_installing: 0,
149
- downloading: 0,
150
- success: 6,
151
- aborted: 0,
152
- noartifact: 0
153
- },
154
- statistics: { total_size: "1234" },
155
- status: "inprogress",
156
- active: true,
157
- device_count: 100,
158
- retries: "0",
159
- type: "software"
160
- }
161
- },
162
- byStatus: {
163
- pending: { deploymentIds: ["d2"] },
164
- inprogress: { deploymentIds: ["d3"] }
165
- }
166
- },
167
- devices: {
168
- byId: {
169
- a1: {
170
- id: "a1",
171
- auth_sets: [
172
- {
173
- id: "auth1",
174
- identity_data: { mac: defaultMacAddress },
175
- pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
176
- status: "accepted",
177
- ts: defaultCreationDate
178
- }
179
- ],
180
- updated_ts: "2019-01-01T09:25:00.000Z"
181
- },
182
- b1: {
183
- id: "b1",
184
- attributes: {
185
- ipv4_wlan0: "192.168.10.141/24",
186
- device_type: [deviceTypes.qemu]
187
- },
188
- system: {
189
- check_in_time: checkInTimeRounded
190
- },
191
- check_in_time: checkInTimeExact,
192
- check_in_time_exact: checkInTimeExact,
193
- check_in_time_rounded: checkInTimeRounded,
194
- identity_data: { mac: defaultMacAddress },
195
- status: "accepted",
196
- decommissioning: false,
197
- created_ts: defaultCreationDate,
198
- updated_ts: "2019-01-01T09:25:00.000Z",
199
- auth_sets: [
200
- {
201
- id: "auth1",
202
- identity_data: { mac: defaultMacAddress },
203
- pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
204
- ts: defaultCreationDate,
205
- status: "accepted"
206
- }
207
- ]
208
- }
209
- },
210
- groups: {
211
- byId: {
212
- testGroup: {
213
- deviceIds: ["a1", "b1"],
214
- filters: [],
215
- total: 2
216
- },
217
- testGroupDynamic: {
218
- id: "filter1",
219
- name: "filter1",
220
- filters: [{ scope: "system", key: "group", operator: "$eq", value: "things" }]
221
- }
222
- }
223
- },
224
- limits: { standard: 500, micro: 0, system: 0 },
225
- byStatus: {
226
- accepted: { deviceIds: ["a1", "b1"], total: 2 },
227
- active: { deviceIds: [], total: 0 },
228
- inactive: { deviceIds: [], total: 0 },
229
- pending: { deviceIds: ["c1"], total: 1 },
230
- preauthorized: { deviceIds: [], total: 0 },
231
- rejected: { deviceIds: [], total: 0 }
232
- }
233
- },
234
- organization: {
235
- organization: {
236
- id: "1",
237
- addons: [],
238
- name: "test",
239
- plan: "os",
240
- trial: false
241
- },
242
- products: [
243
- {
244
- name: "mender_standard",
245
- billing_unit: "devices",
246
- prices: [
247
- {
248
- plan: "os",
249
- constraints: {
250
- min: 50,
251
- max: 1e3,
252
- div: 50
253
- }
254
- },
255
- {
256
- plan: "professional",
257
- constraints: {
258
- min: 250,
259
- max: 1e4,
260
- div: 50
261
- }
262
- }
263
- ],
264
- addons: [
265
- {
266
- name: "troubleshoot",
267
- prices: [{ plan: "os" }, { plan: "professional" }]
268
- },
269
- {
270
- name: "configure",
271
- prices: [{ plan: "os" }, { plan: "professional" }]
272
- },
273
- {
274
- name: "monitor",
275
- prices: [{ plan: "professional" }]
276
- }
277
- ]
278
- },
279
- {
280
- name: "mender_micro",
281
- billing_unit: "devices",
282
- prices: [
283
- {
284
- plan: "os",
285
- constraints: {
286
- min: 50,
287
- max: 5e3,
288
- div: 50
289
- }
290
- },
291
- {
292
- plan: "professional",
293
- constraints: {
294
- min: 500,
295
- max: 1e5,
296
- div: 50
297
- }
298
- }
299
- ]
300
- }
301
- ],
302
- intentId: "testIntent",
303
- auditlog: {
304
- events: [
305
- {
306
- actor: {
307
- id: "string",
308
- type: "user",
309
- email: "string@example.com"
310
- },
311
- time: "2019-01-01T12:10:22.667Z",
312
- action: "create",
313
- object: {
314
- id: "string",
315
- type: "user",
316
- user: {
317
- email: "user@acme.com"
318
- }
319
- },
320
- change: "change1"
321
- },
322
- {
323
- actor: {
324
- id: "string",
325
- type: "user",
326
- email: "string",
327
- identity_data: "string"
328
- },
329
- time: "2019-01-01T12:16:22.667Z",
330
- action: "create",
331
- object: {
332
- id: "string",
333
- type: "deployment",
334
- deployment: {
335
- name: "production",
336
- artifact_name: "Application 0.0.1"
337
- }
338
- },
339
- change: "change2"
340
- },
341
- {
342
- actor: {
343
- id: "string",
344
- type: "user",
345
- email: "string@example.com"
346
- },
347
- time: "2019-01-01T12:10:22.669Z",
348
- action: "open_terminal",
349
- meta: {
350
- session_id: ["abd313a8-ee88-48ab-9c99-fbcd80048e6e"]
351
- },
352
- object: {
353
- id: "a1",
354
- type: "device"
355
- },
356
- change: "change3"
357
- }
358
- ]
359
- }
360
- },
361
- releases: {
362
- byId: {
363
- r1: {
364
- name: "r1",
365
- artifacts: [
366
- {
367
- id: "art1",
368
- description: "test description",
369
- device_types_compatible: [deviceTypes.qemu],
370
- modified: "2020-09-10T12:16:22.667Z",
371
- updates: [{ type_info: { type: "testtype" } }],
372
- artifact_depends: {
373
- device_type: [deviceTypes.qemu]
374
- },
375
- artifact_provides: {
376
- artifact_name: "myapp",
377
- "data-partition.myapp.version": "v2020.10",
378
- list_of_fancy: [deviceTypes.qemu, "x172"]
379
- },
380
- clears_artifact_provides: ["data-partition.myapp.*"]
381
- }
382
- ],
383
- device_types_compatible: [deviceTypes.qemu],
384
- modified: "2020-09-10T12:16:22.667Z",
385
- metaData: {}
386
- }
387
- }
388
- },
389
- users: {
390
- byId: {
391
- a1: defaultUser,
392
- [userId]: { ...defaultUser, id: userId, email: "a2@b.com", created_ts: "2019-01-01T12:30:00.000Z" }
393
- },
394
- rolesById: {
395
- admin: {
396
- name: "admin",
397
- description: "Administrator role",
398
- permissions: []
399
- },
400
- test: { name: "test", description: "test description", permissions: [] }
401
- },
402
- globalSettings: {
403
- "2fa": "enabled",
404
- id_attribute: void 0,
405
- previousFilters: []
406
- },
407
- userSettings: {
408
- "2fa": "disabled",
409
- columnSelection: [],
410
- onboarding: { something: "here" },
411
- tooltips: {},
412
- previousFilters: []
413
- }
414
- }
415
- };
416
- var releasesList = Array.from({ length: 5e3 }, (x, i) => ({
417
- artifacts: [
418
- {
419
- id: "art1",
420
- description: "test description",
421
- device_types_compatible: [deviceTypes.qemu],
422
- modified: "2020-09-10T12:16:22.667Z",
423
- updates: [{ type_info: { type: "testtype" } }],
424
- artifact_depends: {
425
- device_type: [deviceTypes.qemu]
426
- },
427
- artifact_provides: {
428
- artifact_name: "myapp",
429
- "data-partition.myapp.version": "v2020.10",
430
- list_of_fancy: [deviceTypes.qemu, "x172"]
431
- },
432
- clears_artifact_provides: ["data-partition.myapp.*"]
433
- }
434
- ],
435
- device_types_compatible: [deviceTypes.qemu],
436
- metaData: {},
437
- name: `release-${i + 1}`,
438
- modified: i
439
- }));
440
- var permissionSets = [
441
- {
442
- ...import_constants.defaultPermissionSets.Basic,
443
- object: permissionSetObjectTypes.empty,
444
- description: "Set containing basic permissions.",
445
- permissions: [
446
- { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/settings$" } },
447
- { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/users/me$" } },
448
- { action: "http", object: { type: "any", value: "^/api/management/1.0/auth/verify$" } },
449
- { action: "http", object: { type: "PUT", value: "^/api/management/v1/useradm/2faverify$" } },
450
- { action: "http", object: { type: "POST", value: "^/api/management/v1/useradm/users/me/2fa/(enable|disable)$" } },
451
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/roles" } },
452
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/user/tenant" } }
453
- ]
454
- },
455
- {
456
- ...import_constants.defaultPermissionSets.ManageReleases,
457
- action: import_constants.uiPermissionsById.manage.title,
458
- object: permissionSetObjectTypes.releases,
459
- description: "Set of permissions which allows user to manage releases",
460
- permissions: [
461
- { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
462
- { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
463
- { action: "http", object: { type: "PUT", value: commonEndpoints.artifactDetails } },
464
- { action: "http", object: { type: "DELETE", value: commonEndpoints.artifactDetails } },
465
- { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
466
- ]
467
- },
468
- {
469
- ...import_constants.defaultPermissionSets.ReadUsers,
470
- action: import_constants.uiPermissionsById.read.title,
471
- object: permissionSetObjectTypes.userManagement,
472
- description: "Set of permissions which allows user to view other users",
473
- permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/" } }]
474
- },
475
- {
476
- ...import_constants.defaultPermissionSets.ManageUsers,
477
- action: import_constants.uiPermissionsById.manage.title,
478
- object: permissionSetObjectTypes.userManagement,
479
- description: "Set of permissions which allows user manage other user accounts",
480
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/" } }]
481
- },
482
- {
483
- ...import_constants.defaultPermissionSets.ReadTenants,
484
- action: import_constants.uiPermissionsById.read.title,
485
- object: permissionSetObjectTypes.tenantManagement,
486
- description: "Set of permissions which allows user to list other tenants and their config",
487
- permissions: [
488
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
489
- { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } }
490
- ]
491
- },
492
- {
493
- ...import_constants.defaultPermissionSets.ManageTenants,
494
- action: import_constants.uiPermissionsById.manage.title,
495
- object: permissionSetObjectTypes.tenantManagement,
496
- description: "Set of permissions which allows user to manage other tenants and their config",
497
- permissions: [
498
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
499
- { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } },
500
- { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9])/tenantadm/" } }
501
- ]
502
- },
503
- {
504
- ...import_constants.defaultPermissionSets.ReadAuditLogs,
505
- action: import_constants.uiPermissionsById.read.title,
506
- object: "System Audit Log",
507
- description: "Set of permissions which allows user to view system audit log",
508
- permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/auditlogs/logs" } }]
509
- },
510
- {
511
- ...import_constants.defaultPermissionSets.DeployToDevices,
512
- action: "Deploy",
513
- object: permissionSetObjectTypes.groups,
514
- description: "Set of permissions which allows user to deploy to devices",
515
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/(deployments|deviceconfig)/" } }],
516
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
517
- },
518
- {
519
- ...import_constants.defaultPermissionSets.ConfigureDevices,
520
- action: "Configure",
521
- object: permissionSetObjectTypes.groups,
522
- description: "Set of permissions which allows user to manage configuration of the devices",
523
- permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/" } }],
524
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
525
- },
526
- {
527
- ...import_constants.defaultPermissionSets.ConnectToDevices,
528
- action: "Connect",
529
- object: permissionSetObjectTypes.groups,
530
- description: "Set of permissions which allows user to use remote terminal and file transfer",
531
- permissions: [
532
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/connect$" } },
533
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/download\\?path=[^&]+$" } },
534
- { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/upload$" } }
535
- ],
536
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
537
- },
538
- {
539
- ...import_constants.defaultPermissionSets.SuperUser,
540
- action: "Any",
541
- object: permissionSetObjectTypes.any,
542
- description: "Set of permissions which allows user to do anything",
543
- permissions: [{ action: "any", object: { type: "any", value: "any" } }]
544
- },
545
- {
546
- ...import_constants.defaultPermissionSets.UploadArtifacts,
547
- action: "Upload",
548
- object: permissionSetObjectTypes.artifacts,
549
- description: "Set of permissions which allows user to upload artifacts",
550
- permissions: [
551
- { action: "http", object: { type: "POST", value: commonEndpoints.artifacts } },
552
- { action: "http", object: { type: "POST", value: "^/api/management/v1/deployments/artifacts/generate" } }
553
- ]
554
- },
555
- {
556
- ...import_constants.defaultPermissionSets.ReadDevices,
557
- action: import_constants.uiPermissionsById.read.title,
558
- object: permissionSetObjectTypes.groups,
559
- description: "Set of permissions which allows user to view devices",
560
- permissions: [
561
- { action: "http", object: { type: "POST", value: "^/api/management/v2/inventory/filters/search" } },
562
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/(deployments|devauth|inventory|deviceconfig|devicemonitor)/" } },
563
- { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+$" } }
564
- ],
565
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
566
- },
567
- {
568
- ...import_constants.defaultPermissionSets.ManageDevices,
569
- action: import_constants.uiPermissionsById.manage.title,
570
- object: permissionSetObjectTypes.groups,
571
- description: "Set of permissions which allows user to manage devices",
572
- permissions: [
573
- { action: "http", object: { type: "POST", value: commonEndpoints.deviceManagement } },
574
- { action: "http", object: { type: "PUT", value: commonEndpoints.deviceManagement } },
575
- { action: "http", object: { type: "DELETE", value: commonEndpoints.deviceManagement } }
576
- ],
577
- supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
578
- },
579
- {
580
- ...import_constants.defaultPermissionSets.ReadReleases,
581
- action: import_constants.uiPermissionsById.read.title,
582
- object: permissionSetObjectTypes.releases,
583
- description: "Set of permissions which allows user to view releases",
584
- permissions: [
585
- { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
586
- { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
587
- { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
588
- ]
589
- },
590
- {
591
- name: "almostAdmin",
592
- object: permissionSetObjectTypes.empty,
593
- description: "Set containing all the permissions.",
594
- permissions: [
595
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/auditlogs/.*" } },
596
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/.*" } },
597
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/config/.*" } },
598
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/.*" } },
599
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/releases/.*" } },
600
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/devauth/.*" } },
601
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/.*" } },
602
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/.*" } },
603
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/devices" } },
604
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/inventory/.*" } },
605
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/iot-manager/.*" } },
606
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/monitor/.*" } },
607
- { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/.*" } }
608
- ]
609
- }
133
+ const deviceAttributes = [
134
+ {
135
+ name: "status",
136
+ scope: "identity",
137
+ count: 5
138
+ },
139
+ {
140
+ name: "created_ts",
141
+ scope: "system",
142
+ count: 5
143
+ },
144
+ {
145
+ name: "updated_ts",
146
+ scope: "system",
147
+ count: 5
148
+ },
149
+ {
150
+ name: "mac",
151
+ scope: "identity",
152
+ count: 1
153
+ },
154
+ {
155
+ name: "artifact_name",
156
+ scope: "inventory",
157
+ count: 1
158
+ },
159
+ {
160
+ name: "cpu_model",
161
+ scope: "inventory",
162
+ count: 1
163
+ },
164
+ {
165
+ name: "device_type",
166
+ scope: "inventory",
167
+ count: 1
168
+ },
169
+ {
170
+ name: "hostname",
171
+ scope: "inventory",
172
+ count: 1
173
+ },
174
+ {
175
+ name: "ipv4_wlan0",
176
+ scope: "inventory",
177
+ count: 1
178
+ },
179
+ {
180
+ name: "ipv6_wlan0",
181
+ scope: "inventory",
182
+ count: 1
183
+ },
184
+ {
185
+ name: "kernel",
186
+ scope: "inventory",
187
+ count: 1
188
+ },
189
+ {
190
+ name: "mac_eth0",
191
+ scope: "inventory",
192
+ count: 1
193
+ },
194
+ {
195
+ name: "mac_wlan0",
196
+ scope: "inventory",
197
+ count: 1
198
+ },
199
+ {
200
+ name: "mem_total_kB",
201
+ scope: "inventory",
202
+ count: 1
203
+ },
204
+ {
205
+ name: "mender_bootloader_integration",
206
+ scope: "inventory",
207
+ count: 1
208
+ },
209
+ {
210
+ name: "mender_client_version",
211
+ scope: "inventory",
212
+ count: 1
213
+ },
214
+ {
215
+ name: "network_interfaces",
216
+ scope: "inventory",
217
+ count: 1
218
+ },
219
+ {
220
+ name: "os",
221
+ scope: "inventory",
222
+ count: 1
223
+ },
224
+ {
225
+ name: "rootfs_type",
226
+ scope: "inventory",
227
+ count: 1
228
+ },
229
+ {
230
+ name: "group",
231
+ scope: "system",
232
+ count: 1
233
+ }
610
234
  ];
611
- var rbacRoles = [
612
- {
613
- name: "dyn",
614
- description: "",
615
- permissions: [
616
- { action: "CREATE_DEPLOYMENT", object: { type: "DEVICE_GROUP", value: "dyn" } },
617
- { action: "VIEW_DEVICE", object: { type: "DEVICE_GROUP", value: "dyn" } }
618
- ]
619
- },
620
- { name: "asdasd", description: "123", permissions: [{ action: "http", object: { type: "any", value: "/api/management/v1/useradm/.*" } }] },
621
- {
622
- name: "141sasd",
623
- description: "1313adg",
624
- permission_sets_with_scope: [
625
- { ...import_constants.defaultPermissionSets.ReadDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
626
- { ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
627
- { ...import_constants.defaultPermissionSets.ManageUsers }
628
- ]
629
- },
630
- {
631
- name: "kljlkk",
632
- description: "lkl",
633
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } }]
634
- },
635
- {
636
- name: "yyyyy",
637
- description: "asd",
638
- permission_sets_with_scope: [
639
- { ...import_constants.defaultPermissionSets.ManageDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["dockerclient"] } },
640
- { ...import_constants.defaultPermissionSets.ManageReleases }
641
- ]
642
- },
643
- {
644
- name: "RBAC_ROLE_DEPLOYMENTS_MANAGER",
645
- description: "Intended for users responsible for managing deployments, this role can create and abort deployments",
646
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.DeployToDevices }]
647
- },
648
- {
649
- name: "RBAC_ROLE_REMOTE_TERMINAL",
650
- description: `Intended for tech support accounts, this role can access the devices' Remote Terminal.`,
651
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices }]
652
- },
653
- { name: "RBAC_ROLE_PERMIT_ALL", description: "", permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.SuperUser }] },
654
- {
655
- name: "RBAC_ROLE_OBSERVER",
656
- description: "Intended for team leaders or limited tech support accounts, this role can see all Devices, Artifacts and Deployment reports but not make any changes.",
657
- permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ReadReleases }, { ...import_constants.defaultPermissionSets.ReadDevices }]
658
- },
659
- {
660
- name: "RBAC_ROLE_CI",
661
- description: "Intended for automation accounts building software (e.g. CI/CD systems), this role can only manage Artifacts, including upload new Artifacts and delete Artifacts. It does not have access to Devices or Deployments.",
662
- permission_sets_with_scope: [
663
- { ...import_constants.defaultPermissionSets.ReadReleases },
664
- { ...import_constants.defaultPermissionSets.ManageReleases },
665
- { ...import_constants.defaultPermissionSets.UploadArtifacts }
666
- ]
667
- },
668
- {
669
- name: "almostAdmin",
670
- description: "almost admin rights",
671
- permissions: permissionSets.find((item) => item.name === "almostAdmin")?.permissions
672
- },
673
- {
674
- name: "almostAdminNew",
675
- description: "almost admin rights",
676
- permission_sets_with_scope: Object.values(import_constants.defaultPermissionSets)
677
- }
235
+ const searchHandler = require_validation.validated(async ({ request }) => {
236
+ const { page, per_page, filters } = await request.json();
237
+ if ([
238
+ page,
239
+ per_page,
240
+ filters
241
+ ].some((item) => !item)) return new msw.HttpResponse(null, { status: 509 });
242
+ const status = filters.find((filter) => filter.scope === "identity" && filter.attribute === "status" && Object.values(_northern_tech_utils_constants.DEVICE_STATES).includes(filter.value))?.value || "";
243
+ if (!status || filters.length > 1) {
244
+ if (filters.find((filter) => filter.attribute === "group" && filter.value.includes(Object.keys(require_mockData.mockApiResponses.devices.groups.byId)[0]))) return new msw.HttpResponse(JSON.stringify([inventoryDevice, {
245
+ ...inventoryDevice,
246
+ id: "b1"
247
+ }]), { headers: { [_northern_tech_utils_constants.headerNames.total]: 2 } });
248
+ if (filters.find((filter) => filter.scope === "monitor" && [
249
+ "failed_last_update",
250
+ "alerts",
251
+ "auth_request"
252
+ ].includes(filter.attribute))) return new msw.HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [_northern_tech_utils_constants.headerNames.total]: 4 } });
253
+ return new msw.HttpResponse(JSON.stringify([]), { headers: { [_northern_tech_utils_constants.headerNames.total]: 0 } });
254
+ }
255
+ let deviceList = Array.from({ length: require_mockData.mockApiResponses.devices.byStatus[status].total }, (_, index) => ({
256
+ ...inventoryDevice,
257
+ attributes: [...inventoryDevice.attributes, {
258
+ name: "test-count",
259
+ value: index,
260
+ scope: "system"
261
+ }],
262
+ id: `${String.fromCharCode("a".charCodeAt(0) + index)}1`
263
+ }));
264
+ deviceList = deviceList.slice((page - 1) * per_page, page * per_page);
265
+ return new msw.HttpResponse(JSON.stringify(deviceList), { headers: { [_northern_tech_utils_constants.headerNames.total]: require_mockData.mockApiResponses.devices.byStatus[status].total } });
266
+ });
267
+ const deviceHandlers = [
268
+ msw.http.delete(`${_northern_tech_utils_constants.deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {
269
+ if (require_mockData.mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId)) return new msw.HttpResponse(null, { status: 200 });
270
+ return new msw.HttpResponse(null, { status: 501 });
271
+ }),
272
+ msw.http.delete(`${_northern_tech_utils_constants.deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {
273
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return new msw.HttpResponse(null, { status: 200 });
274
+ return new msw.HttpResponse(null, { status: 502 });
275
+ }),
276
+ msw.http.delete(`${_northern_tech_utils_constants.inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {
277
+ if (require_mockData.mockApiResponses.devices.groups.byId[group]) return new msw.HttpResponse(null, { status: 200 });
278
+ return new msw.HttpResponse(null, { status: 515 });
279
+ }),
280
+ msw.http.delete(`${_northern_tech_utils_constants.inventoryApiUrl}/groups/:group/devices`, require_validation.validated(async ({ params: { group }, request }) => {
281
+ const deviceIds = await request.json();
282
+ if (require_mockData.mockApiResponses.devices.groups.byId[group] && deviceIds.every((id) => !!require_mockData.mockApiResponses.devices.byId[id])) return new msw.HttpResponse(null, { status: 200 });
283
+ return new msw.HttpResponse(null, { status: 503 });
284
+ })),
285
+ msw.http.delete(`${_northern_tech_utils_constants.inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {
286
+ if (Object.values(require_mockData.mockApiResponses.devices.groups.byId).find((group) => group.id === filterId)) return new msw.HttpResponse(null, { status: 200 });
287
+ return new msw.HttpResponse(null, { status: 504 });
288
+ }),
289
+ msw.http.get(`${_northern_tech_utils_constants.deviceAuthV2}/devices`, ({ request }) => {
290
+ const { searchParams } = new URL(request.url);
291
+ const deviceIds = searchParams.getAll("id");
292
+ if (deviceIds.every((id) => !!require_mockData.mockApiResponses.devices.byId[id])) return msw.HttpResponse.json(deviceIds.map((id) => ({
293
+ ...deviceAuthDevice,
294
+ id
295
+ })));
296
+ return new msw.HttpResponse(null, { status: 505 });
297
+ }),
298
+ msw.http.get(`${_northern_tech_utils_constants.deviceAuthV2}/limits/devices`, () => msw.HttpResponse.json(require_mockData.mockApiResponses.devices.limits)),
299
+ msw.http.get(`${_northern_tech_utils_constants.inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {
300
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return msw.HttpResponse.json(inventoryDevice);
301
+ return new msw.HttpResponse(null, { status: 506 });
302
+ }),
303
+ msw.http.put(`${_northern_tech_utils_constants.inventoryApiUrl}/devices/:deviceId/tags`, require_validation.validated(async ({ params: { deviceId }, request }) => {
304
+ const tags = await request.json();
305
+ if (!require_mockData.mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every((item) => item.name && item.value)) return new msw.HttpResponse(null, { status: 506 });
306
+ return msw.HttpResponse.json(tags);
307
+ })),
308
+ msw.http.get(`${_northern_tech_utils_constants.inventoryApiUrl}/groups`, () => {
309
+ const groups = Object.entries(require_mockData.mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {
310
+ if (!group.id) accu.push(groupName);
311
+ return accu;
312
+ }, []);
313
+ return msw.HttpResponse.json(groups);
314
+ }),
315
+ msw.http.get(`${_northern_tech_utils_constants.inventoryApiUrlV2}/filters/attributes`, () => msw.HttpResponse.json(deviceAttributes)),
316
+ msw.http.get(`${_northern_tech_utils_constants.inventoryApiUrlV2}/filters`, () => msw.HttpResponse.json([{
317
+ id: "filter1",
318
+ name: "testGroupDynamic",
319
+ terms: [
320
+ {
321
+ scope: "identity",
322
+ attribute: "id",
323
+ type: "$in",
324
+ value: ["a1"]
325
+ },
326
+ {
327
+ scope: "identity",
328
+ attribute: "mac",
329
+ type: "$exists",
330
+ value: false
331
+ },
332
+ {
333
+ scope: "identity",
334
+ attribute: "kernel",
335
+ type: "$exists",
336
+ value: true
337
+ }
338
+ ]
339
+ }])),
340
+ msw.http.patch(`${_northern_tech_utils_constants.inventoryApiUrl}/groups/:group/devices`, require_validation.validated(async ({ params: { group }, request }) => {
341
+ const deviceIds = await request.json();
342
+ if (!!group && deviceIds.every((id) => !!require_mockData.mockApiResponses.devices.byId[id])) return new msw.HttpResponse(null, { status: 200 });
343
+ return new msw.HttpResponse(null, { status: 508 });
344
+ })),
345
+ msw.http.post(`${_northern_tech_utils_constants.deviceAuthV2}/devices`, require_validation.validated(async ({ request }) => {
346
+ const authset = await request.json();
347
+ if (Object.values(require_mockData.mockApiResponses.devices.byId).some((device) => device.auth_sets.some((deviceAuthSet) => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data))) return new msw.HttpResponse(null, { status: 409 });
348
+ return new msw.HttpResponse(null, { status: 200 });
349
+ })),
350
+ msw.http.post(`${_northern_tech_utils_constants.inventoryApiUrlV2}/filters/search`, searchHandler),
351
+ msw.http.post(`${_northern_tech_utils_constants.inventoryApiUrlV2}/filters`, require_validation.validated(async ({ request }) => {
352
+ const { name, terms } = await request.json();
353
+ if ([name, terms].some((item) => !item) || require_mockData.mockApiResponses.devices.groups[name] || !terms.every((term) => _northern_tech_utils_constants.DEVICE_FILTERING_OPTIONS[term.type] && [
354
+ "identity",
355
+ "inventory",
356
+ "system"
357
+ ].includes(term.scope) && !!term.value && !!term.attribute)) return new msw.HttpResponse(null, { status: 510 });
358
+ return new msw.HttpResponse(JSON.stringify({}), { headers: { location: "find/me/here/createdFilterId" } });
359
+ })),
360
+ msw.http.get(`${_northern_tech_utils_constants.inventoryApiUrlV2}/statistics`, async () => msw.HttpResponse.json({ devices_by_status: {
361
+ accepted: {
362
+ standard: require_mockData.mockApiResponses.devices.byStatus.accepted.total,
363
+ micro: 0,
364
+ system: 0
365
+ },
366
+ pending: {
367
+ standard: require_mockData.mockApiResponses.devices.byStatus.pending.total,
368
+ micro: 0,
369
+ system: 0
370
+ }
371
+ } })),
372
+ msw.http.put(`${_northern_tech_utils_constants.deviceAuthV2}/devices/:deviceId/auth/:authId/status`, require_validation.validated(async ({ params: { authId, deviceId }, request }) => {
373
+ const { status } = await request.json();
374
+ if (require_mockData.mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId) && _northern_tech_utils_constants.DEVICE_STATES[status]) return new msw.HttpResponse(null, { status: 200 });
375
+ return new msw.HttpResponse(null, { status: 511 });
376
+ })),
377
+ msw.http.get(`${_northern_tech_utils_constants.deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {
378
+ if (deviceId === "testId") return new msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
379
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return msw.HttpResponse.json({
380
+ configured: {
381
+ test: true,
382
+ something: "else",
383
+ aNumber: 42
384
+ },
385
+ deployment_id: "config1",
386
+ reported: {
387
+ test: true,
388
+ something: "else",
389
+ aNumber: 42
390
+ },
391
+ updated_ts: updatedTime,
392
+ reported_ts: "2019-01-01T09:25:01.000Z"
393
+ });
394
+ return new msw.HttpResponse(null, { status: 512 });
395
+ }),
396
+ msw.http.put(`${_northern_tech_utils_constants.deviceConfig}/:deviceId`, require_validation.validated(async ({ params: { deviceId }, request }) => {
397
+ if ((await request.text()).includes("evilValue")) return new msw.HttpResponse(null, { status: 418 });
398
+ return new msw.HttpResponse(null, { status: require_mockData.mockApiResponses.devices.byId[deviceId] ? 201 : 513 });
399
+ })),
400
+ msw.http.post(`${_northern_tech_utils_constants.deviceConfig}/:deviceId/deploy`, require_validation.validated(({ params: { deviceId } }) => {
401
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return msw.HttpResponse.json({ deployment_id: "config1" });
402
+ return new msw.HttpResponse(null, { status: 514 });
403
+ })),
404
+ msw.http.get(`${_northern_tech_utils_constants.deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {
405
+ if (deviceId === "testId") return new msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
406
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return msw.HttpResponse.json({
407
+ status: "connected",
408
+ updated_ts: require_mockData.mockApiResponses.devices.byId[deviceId].updated_ts
409
+ });
410
+ return new msw.HttpResponse(null, { status: 512 });
411
+ }),
412
+ msw.http.post(`${_northern_tech_utils_constants.deviceConnect}/devices/:deviceId/:action`, require_validation.validated(({ params: { deviceId, action } }) => {
413
+ if (["check-update", "send-inventory"].includes(action) && require_mockData.mockApiResponses.devices.byId[deviceId]) return new msw.HttpResponse(null, { status: 202 });
414
+ return new msw.HttpResponse(null, { status: 518 });
415
+ })),
416
+ msw.http.get(`${_northern_tech_utils_constants.iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {
417
+ if (require_mockData.mockApiResponses.devices.byId[deviceId]) return msw.HttpResponse.json({ deployment_id: require_mockData.mockApiResponses.deployments.byId.d1.id });
418
+ return new msw.HttpResponse(null, { status: 515 });
419
+ }),
420
+ msw.http.put(`${_northern_tech_utils_constants.iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, require_validation.validated(async ({ params: { deviceId }, request }) => {
421
+ const body = await request.json();
422
+ if (require_mockData.mockApiResponses.devices.byId[deviceId] && body) return msw.HttpResponse.json({ deployment_id: require_mockData.mockApiResponses.deployments.byId.d1.id });
423
+ return new msw.HttpResponse(null, { status: 516 });
424
+ })),
425
+ msw.http.put(`${_northern_tech_utils_constants.deviceConnect}/devices/:deviceId/upload`, require_validation.validated(({ params: { deviceId } }) => new msw.HttpResponse(null, { status: require_mockData.mockApiResponses.devices.byId[deviceId] ? 200 : 517 }))),
426
+ msw.http.get(`${_northern_tech_utils_constants.deviceAuthV2}/license`, () => msw.HttpResponse.text("test,report"))
678
427
  ];
679
- var expectedParsedRoles = {
680
- "141sasd": {
681
- editable: true,
682
- isCustom: void 0,
683
- uiPermissions: {
684
- ...import_constants.emptyUiPermissions,
685
- groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] },
686
- userManagement: [import_constants.uiPermissionsById.manage.value]
687
- }
688
- },
689
- asdasd: {
690
- editable: false,
691
- isCustom: true,
692
- uiPermissions: { ...import_constants.emptyUiPermissions, userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] }
693
- },
694
- dyn: {
695
- editable: false,
696
- isCustom: true,
697
- uiPermissions: {
698
- ...import_constants.emptyUiPermissions,
699
- deployments: [import_constants.uiPermissionsById.deploy.value],
700
- groups: { dyn: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value] }
701
- }
702
- },
703
- kljlkk: {
704
- editable: true,
705
- isCustom: false,
706
- uiPermissions: { ...import_constants.emptyUiPermissions, groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] } }
707
- },
708
- yyyyy: {
709
- editable: true,
710
- isCustom: void 0,
711
- uiPermissions: {
712
- ...import_constants.emptyUiPermissions,
713
- groups: { dockerclient: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] },
714
- releases: { [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value] }
715
- }
716
- },
717
- almostAdmin: {
718
- editable: false,
719
- isCustom: true,
720
- uiPermissions: {
721
- ...import_constants.emptyUiPermissions,
722
- auditlog: [import_constants.uiPermissionsById.read.value],
723
- deployments: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.read.value],
724
- groups: {
725
- [import_constants.ALL_DEVICES]: [
726
- import_constants.uiPermissionsById.read.value,
727
- // we can't assign deployment permissions to devices here, since the old path based rbac controls don't allow the scoped permissions
728
- // uiPermissionsById.deploy.value,
729
- import_constants.uiPermissionsById.manage.value,
730
- import_constants.uiPermissionsById.connect.value,
731
- import_constants.uiPermissionsById.configure.value
732
- ]
733
- },
734
- releases: {
735
- [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.manage.value]
736
- },
737
- userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
738
- }
739
- },
740
- almostAdminNew: {
741
- editable: true,
742
- isCustom: void 0,
743
- uiPermissions: {
744
- ...import_constants.emptyUiPermissions,
745
- auditlog: [import_constants.uiPermissionsById.read.value],
746
- deployments: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.manage.value],
747
- groups: {
748
- [import_constants.ALL_DEVICES]: [
749
- import_constants.uiPermissionsById.read.value,
750
- import_constants.uiPermissionsById.manage.value,
751
- import_constants.uiPermissionsById.deploy.value,
752
- import_constants.uiPermissionsById.connect.value,
753
- import_constants.uiPermissionsById.configure.value
754
- ]
755
- },
756
- releases: {
757
- [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.read.value]
758
- },
759
- tenantManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value],
760
- userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
761
- }
762
- }
763
- };
764
- var defaultRolesById = {
765
- ...import_constants.rolesById,
766
- test: {
767
- ...import_constants.emptyRole,
768
- name: "test",
769
- description: "test description",
770
- editable: true,
771
- uiPermissions: {
772
- ...import_constants.emptyUiPermissions,
773
- groups: { testGroup: [import_constants.uiPermissionsById.read.value] },
774
- releases: { bar: [import_constants.uiPermissionsById.read.value] }
775
- }
776
- }
777
- };
778
- var receivedRoles = rbacRoles.reduce(
779
- (accu, role) => {
780
- const { name, description, ...roleRemainder } = role;
781
- if (name.startsWith("RBAC")) {
782
- accu[name] = {
783
- ...defaultRolesById[name],
784
- ...roleRemainder,
785
- editable: false,
786
- isCustom: false,
787
- description: defaultRolesById[name].description ? defaultRolesById[name].description : description
788
- };
789
- } else {
790
- const result = expectedParsedRoles[name] ?? {};
791
- accu[name] = {
792
- ...import_constants.emptyRole,
793
- ...role,
794
- ...result,
795
- name
796
- };
797
- }
798
- return accu;
799
- },
800
- { ...defaultRolesById }
801
- );
802
- var receivedPermissionSets = permissionSets.reduce((accu, set) => {
803
- const result = import_constants.defaultPermissionSets[set.name]?.result ?? {};
804
- accu[set.name] = {
805
- ...set,
806
- result: {
807
- ...import_constants.emptyUiPermissions,
808
- ...result
809
- }
810
- };
811
- return accu;
812
- }, {});
428
+ //#endregion
429
+ exports.defaultDeviceId = defaultDeviceId;
430
+ exports.deviceHandlers = deviceHandlers;
431
+ exports.inventoryDevice = inventoryDevice;
813
432
 
814
- // src/requestHandlers/deviceHandlers.ts
815
- var defaultDeviceId = "a1";
816
- var deviceAuthDevice = {
817
- id: defaultDeviceId,
818
- identity_data: { mac: defaultMacAddress },
819
- status: "accepted",
820
- decommissioning: false,
821
- created_ts: defaultCreationDate,
822
- updated_ts: "2019-01-01T09:25:00.000Z",
823
- auth_sets: [
824
- {
825
- id: "auth1",
826
- identity_data: { mac: defaultMacAddress },
827
- pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
828
- ts: defaultCreationDate,
829
- status: "accepted"
830
- }
831
- ]
832
- };
833
- var checkInTimeExact2 = "2019-01-01T10:25:00.000Z";
834
- var updatedTime = "2019-01-01T09:25:00.000Z";
835
- var inventoryDevice = {
836
- id: defaultDeviceId,
837
- attributes: [
838
- { name: "network_interfaces", value: ["eth0", "wlan0"], scope: "inventory" },
839
- { name: "kernel", value: "Linux version 4.19.75-v7l+", scope: "inventory" },
840
- { name: "artifact_name", value: "raspotifyInstaller", scope: "inventory" },
841
- { name: "ipv6_wlan0", value: "fe80::68d9:8453:3e9c:7c80/64", scope: "inventory" },
842
- { name: "mac_eth0", value: defaultMacAddress, scope: "inventory" },
843
- { name: "rootfs_type", value: "ext4", scope: "inventory" },
844
- { name: "mender_bootloader_integration", value: "unknown", scope: "inventory" },
845
- { name: "cpu_model", value: "ARMv7 Processor rev 3 (v7l)", scope: "inventory" },
846
- { name: "hostname", value: "raspberrypi", scope: "inventory" },
847
- { name: "mender_client_version", value: "2.1.0", scope: "inventory" },
848
- { name: "ipv4_wlan0", value: "192.168.10.141/24", scope: "inventory" },
849
- { name: "device_type", value: "raspberrypi4", scope: "inventory" },
850
- { name: "mem_total_kB", value: "1986024", scope: "inventory" },
851
- { name: "mac_wlan0", value: "dc:a6:32:12:ad:c0", scope: "inventory" },
852
- { name: "os", value: "Raspbian GNU/Linux 10 (buster)", scope: "inventory" },
853
- { name: "created_ts", value: defaultCreationDate, scope: "system" },
854
- { name: "updated_ts", value: updatedTime, scope: "system" },
855
- { name: "status", value: "accepted", scope: "identity" },
856
- { name: "mac", value: defaultMacAddress, scope: "identity" },
857
- { name: "group", value: "test", scope: "system" }
858
- ],
859
- check_in_time: checkInTimeExact2,
860
- updated_ts: updatedTime
861
- };
862
- var deviceAttributes = [
863
- { name: "status", scope: "identity", count: 5 },
864
- { name: "created_ts", scope: "system", count: 5 },
865
- { name: "updated_ts", scope: "system", count: 5 },
866
- { name: "mac", scope: "identity", count: 1 },
867
- { name: "artifact_name", scope: "inventory", count: 1 },
868
- { name: "cpu_model", scope: "inventory", count: 1 },
869
- { name: "device_type", scope: "inventory", count: 1 },
870
- { name: "hostname", scope: "inventory", count: 1 },
871
- { name: "ipv4_wlan0", scope: "inventory", count: 1 },
872
- { name: "ipv6_wlan0", scope: "inventory", count: 1 },
873
- { name: "kernel", scope: "inventory", count: 1 },
874
- { name: "mac_eth0", scope: "inventory", count: 1 },
875
- { name: "mac_wlan0", scope: "inventory", count: 1 },
876
- { name: "mem_total_kB", scope: "inventory", count: 1 },
877
- { name: "mender_bootloader_integration", scope: "inventory", count: 1 },
878
- { name: "mender_client_version", scope: "inventory", count: 1 },
879
- { name: "network_interfaces", scope: "inventory", count: 1 },
880
- { name: "os", scope: "inventory", count: 1 },
881
- { name: "rootfs_type", scope: "inventory", count: 1 },
882
- { name: "group", scope: "system", count: 1 }
883
- ];
884
- var searchHandler = async ({ request }) => {
885
- const { page, per_page, filters } = await request.json();
886
- if ([page, per_page, filters].some((item) => !item)) {
887
- return new import_msw.HttpResponse(null, { status: 509 });
888
- }
889
- const filter = filters.find((filter2) => filter2.scope === "identity" && filter2.attribute === "status" && Object.values(import_constants2.DEVICE_STATES).includes(filter2.value));
890
- const status = filter?.value || "";
891
- if (!status || filters.length > 1) {
892
- if (filters.find((filter2) => filter2.attribute === "group" && filter2.value.includes(Object.keys(mockApiResponses.devices.groups.byId)[0]))) {
893
- return new import_msw.HttpResponse(JSON.stringify([inventoryDevice, { ...inventoryDevice, id: "b1" }]), {
894
- headers: { [import_constants2.headerNames.total]: 2 }
895
- });
896
- }
897
- if (filters.find((filter2) => filter2.scope === "monitor" && ["failed_last_update", "alerts", "auth_request"].includes(filter2.attribute))) {
898
- return new import_msw.HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [import_constants2.headerNames.total]: 4 } });
899
- }
900
- return new import_msw.HttpResponse(JSON.stringify([]), { headers: { [import_constants2.headerNames.total]: 0 } });
901
- }
902
- let deviceList = Array.from({ length: mockApiResponses.devices.byStatus[status].total }, (_, index) => ({
903
- ...inventoryDevice,
904
- attributes: [...inventoryDevice.attributes, { name: "test-count", value: index, scope: "system" }],
905
- id: `${String.fromCharCode("a".charCodeAt(0) + index)}1`
906
- }));
907
- deviceList = deviceList.slice((page - 1) * per_page, page * per_page);
908
- return new import_msw.HttpResponse(JSON.stringify(deviceList), { headers: { [import_constants2.headerNames.total]: mockApiResponses.devices.byStatus[status].total } });
909
- };
910
- var deviceHandlers = [
911
- import_msw.http.delete(`${import_constants2.deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {
912
- if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId)) {
913
- return new import_msw.HttpResponse(null, { status: 200 });
914
- }
915
- return new import_msw.HttpResponse(null, { status: 501 });
916
- }),
917
- import_msw.http.delete(`${import_constants2.deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {
918
- if (mockApiResponses.devices.byId[deviceId]) {
919
- return new import_msw.HttpResponse(null, { status: 200 });
920
- }
921
- return new import_msw.HttpResponse(null, { status: 502 });
922
- }),
923
- import_msw.http.delete(`${import_constants2.inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {
924
- if (mockApiResponses.devices.groups.byId[group]) {
925
- return new import_msw.HttpResponse(null, { status: 200 });
926
- }
927
- return new import_msw.HttpResponse(null, { status: 515 });
928
- }),
929
- import_msw.http.delete(`${import_constants2.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
930
- const deviceIds = await request.json();
931
- if (mockApiResponses.devices.groups.byId[group] && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
932
- return new import_msw.HttpResponse(null, { status: 200 });
933
- }
934
- return new import_msw.HttpResponse(null, { status: 503 });
935
- }),
936
- import_msw.http.delete(`${import_constants2.inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {
937
- if (Object.values(mockApiResponses.devices.groups.byId).find((group) => group.id === filterId)) {
938
- return new import_msw.HttpResponse(null, { status: 200 });
939
- }
940
- return new import_msw.HttpResponse(null, { status: 504 });
941
- }),
942
- import_msw.http.get(`${import_constants2.deviceAuthV2}/devices`, ({ request }) => {
943
- const { searchParams } = new URL(request.url);
944
- const deviceIds = searchParams.getAll("id");
945
- if (deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
946
- return import_msw.HttpResponse.json(deviceIds.map((id) => ({ ...deviceAuthDevice, id })));
947
- }
948
- return new import_msw.HttpResponse(null, { status: 505 });
949
- }),
950
- import_msw.http.get(`${import_constants2.deviceAuthV2}/limits/devices`, () => import_msw.HttpResponse.json(mockApiResponses.devices.limits)),
951
- import_msw.http.get(`${import_constants2.inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {
952
- if (mockApiResponses.devices.byId[deviceId]) {
953
- return import_msw.HttpResponse.json(inventoryDevice);
954
- }
955
- return new import_msw.HttpResponse(null, { status: 506 });
956
- }),
957
- import_msw.http.put(`${import_constants2.inventoryApiUrl}/devices/:deviceId/tags`, async ({ params: { deviceId }, request }) => {
958
- const tags = await request.json();
959
- if (!mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every((item) => item.name && item.value)) {
960
- return new import_msw.HttpResponse(null, { status: 506 });
961
- }
962
- return import_msw.HttpResponse.json(tags);
963
- }),
964
- import_msw.http.get(`${import_constants2.inventoryApiUrl}/groups`, () => {
965
- const groups = Object.entries(mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {
966
- if (!group.id) {
967
- accu.push(groupName);
968
- }
969
- return accu;
970
- }, []);
971
- return import_msw.HttpResponse.json(groups);
972
- }),
973
- import_msw.http.get(`${import_constants2.inventoryApiUrlV2}/filters/attributes`, () => import_msw.HttpResponse.json(deviceAttributes)),
974
- import_msw.http.get(
975
- `${import_constants2.inventoryApiUrlV2}/filters`,
976
- () => import_msw.HttpResponse.json([
977
- {
978
- id: "filter1",
979
- name: "testGroupDynamic",
980
- terms: [
981
- { scope: "identity", attribute: "id", type: "$in", value: [defaultDeviceId] },
982
- { scope: "identity", attribute: "mac", type: "$exists", value: false },
983
- { scope: "identity", attribute: "kernel", type: "$exists", value: true }
984
- ]
985
- }
986
- ])
987
- ),
988
- import_msw.http.patch(`${import_constants2.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
989
- const deviceIds = await request.json();
990
- if (!!group && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
991
- return new import_msw.HttpResponse(null, { status: 200 });
992
- }
993
- return new import_msw.HttpResponse(null, { status: 508 });
994
- }),
995
- import_msw.http.post(`${import_constants2.deviceAuthV2}/devices`, async ({ request }) => {
996
- const authset = await request.json();
997
- if (Object.values(mockApiResponses.devices.byId).some(
998
- (device) => device.auth_sets.some((deviceAuthSet) => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data)
999
- )) {
1000
- return new import_msw.HttpResponse(null, { status: 409 });
1001
- }
1002
- return new import_msw.HttpResponse(null, { status: 200 });
1003
- }),
1004
- import_msw.http.post(`${import_constants2.inventoryApiUrlV2}/filters/search`, searchHandler),
1005
- import_msw.http.post(`${import_constants2.inventoryApiUrlV2}/filters`, async ({ request }) => {
1006
- const { name, terms } = await request.json();
1007
- if ([name, terms].some((item) => !item) || mockApiResponses.devices.groups[name] || !terms.every((term) => import_constants2.DEVICE_FILTERING_OPTIONS[term.type] && ["identity", "inventory", "system"].includes(term.scope) && !!term.value && !!term.attribute)) {
1008
- return new import_msw.HttpResponse(null, { status: 510 });
1009
- }
1010
- return new import_msw.HttpResponse(JSON.stringify({}), { headers: { location: "find/me/here/createdFilterId" } });
1011
- }),
1012
- import_msw.http.get(
1013
- `${import_constants2.inventoryApiUrlV2}/statistics`,
1014
- async () => import_msw.HttpResponse.json({
1015
- devices_by_status: {
1016
- accepted: { standard: mockApiResponses.devices.byStatus.accepted.total, micro: 0, system: 0 },
1017
- pending: { standard: mockApiResponses.devices.byStatus.pending.total, micro: 0, system: 0 }
1018
- }
1019
- })
1020
- ),
1021
- import_msw.http.put(`${import_constants2.deviceAuthV2}/devices/:deviceId/auth/:authId/status`, async ({ params: { authId, deviceId }, request }) => {
1022
- const { status } = await request.json();
1023
- if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId) && import_constants2.DEVICE_STATES[status]) {
1024
- return new import_msw.HttpResponse(null, { status: 200 });
1025
- }
1026
- return new import_msw.HttpResponse(null, { status: 511 });
1027
- }),
1028
- import_msw.http.get(`${import_constants2.deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {
1029
- if (deviceId === "testId") {
1030
- return new import_msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
1031
- }
1032
- if (mockApiResponses.devices.byId[deviceId]) {
1033
- return import_msw.HttpResponse.json({
1034
- configured: { test: true, something: "else", aNumber: 42 },
1035
- deployment_id: "config1",
1036
- reported: { test: true, something: "else", aNumber: 42 },
1037
- updated_ts: updatedTime,
1038
- reported_ts: "2019-01-01T09:25:01.000Z"
1039
- });
1040
- }
1041
- return new import_msw.HttpResponse(null, { status: 512 });
1042
- }),
1043
- import_msw.http.put(`${import_constants2.deviceConfig}/:deviceId`, async ({ params: { deviceId }, request }) => {
1044
- const body = await request.text();
1045
- if (body.includes("evilValue")) {
1046
- return new import_msw.HttpResponse(null, { status: 418 });
1047
- }
1048
- return new import_msw.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 201 : 513 });
1049
- }),
1050
- import_msw.http.post(`${import_constants2.deviceConfig}/:deviceId/deploy`, ({ params: { deviceId } }) => {
1051
- if (mockApiResponses.devices.byId[deviceId]) {
1052
- return import_msw.HttpResponse.json({ deployment_id: "config1" });
1053
- }
1054
- return new import_msw.HttpResponse(null, { status: 514 });
1055
- }),
1056
- import_msw.http.get(`${import_constants2.deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {
1057
- if (deviceId === "testId") {
1058
- return new import_msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
1059
- }
1060
- if (mockApiResponses.devices.byId[deviceId]) {
1061
- return import_msw.HttpResponse.json({ status: "connected", updated_ts: mockApiResponses.devices.byId[deviceId].updated_ts });
1062
- }
1063
- return new import_msw.HttpResponse(null, { status: 512 });
1064
- }),
1065
- import_msw.http.post(`${import_constants2.deviceConnect}/devices/:deviceId/:action`, ({ params: { deviceId, action } }) => {
1066
- if (["check-update", "send-inventory"].includes(action) && mockApiResponses.devices.byId[deviceId]) {
1067
- return new import_msw.HttpResponse(null, { status: 202 });
1068
- }
1069
- return new import_msw.HttpResponse(null, { status: 518 });
1070
- }),
1071
- import_msw.http.get(`${import_constants2.iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {
1072
- if (mockApiResponses.devices.byId[deviceId]) {
1073
- return import_msw.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1074
- }
1075
- return new import_msw.HttpResponse(null, { status: 515 });
1076
- }),
1077
- import_msw.http.put(`${import_constants2.iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, async ({ params: { deviceId }, request }) => {
1078
- const body = await request.json();
1079
- if (mockApiResponses.devices.byId[deviceId] && body) {
1080
- return import_msw.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1081
- }
1082
- return new import_msw.HttpResponse(null, { status: 516 });
1083
- }),
1084
- import_msw.http.put(
1085
- `${import_constants2.deviceConnect}/devices/:deviceId/upload`,
1086
- ({ params: { deviceId } }) => new import_msw.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 200 : 517 })
1087
- ),
1088
- import_msw.http.get(`${import_constants2.deviceAuthV2}/license`, () => import_msw.HttpResponse.text("test,report"))
1089
- ];
1090
- // Annotate the CommonJS export names for ESM import in node:
1091
- 0 && (module.exports = {
1092
- defaultDeviceId,
1093
- deviceHandlers,
1094
- inventoryDevice
1095
- });
1096
433
  //# sourceMappingURL=deviceHandlers.cjs.map