@northern.tech/testing 0.8.1 → 0.8.3

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 (86) hide show
  1. package/dist/baseTestConfig.json +17 -0
  2. package/dist/chunk-3CVNBMEF.js +161 -0
  3. package/dist/chunk-3CVNBMEF.js.map +1 -0
  4. package/dist/chunk-7GNK7IRV.js +29 -0
  5. package/dist/chunk-7GNK7IRV.js.map +1 -0
  6. package/dist/chunk-AP4MOFMD.js +239 -0
  7. package/dist/chunk-AP4MOFMD.js.map +1 -0
  8. package/dist/chunk-DOHA53UH.js +301 -0
  9. package/dist/chunk-DOHA53UH.js.map +1 -0
  10. package/dist/chunk-H4J7L3HX.js +188 -0
  11. package/dist/chunk-H4J7L3HX.js.map +1 -0
  12. package/dist/chunk-HRGVXWMH.js +17 -0
  13. package/dist/chunk-HRGVXWMH.js.map +1 -0
  14. package/dist/chunk-KCLTR6QS.js +34 -0
  15. package/dist/chunk-KCLTR6QS.js.map +1 -0
  16. package/dist/chunk-M2TKDOPD.js +266 -0
  17. package/dist/chunk-M2TKDOPD.js.map +1 -0
  18. package/dist/chunk-O42KIJXJ.js +933 -0
  19. package/dist/chunk-O42KIJXJ.js.map +1 -0
  20. package/dist/mockData.cjs +967 -0
  21. package/dist/mockData.cjs.map +1 -0
  22. package/dist/mockData.d.cts +636 -0
  23. package/dist/mockData.d.ts +636 -0
  24. package/dist/mockData.js +47 -0
  25. package/dist/mockData.js.map +1 -0
  26. package/dist/requestHandlers/deploymentHandlers.cjs +1044 -0
  27. package/dist/requestHandlers/deploymentHandlers.cjs.map +1 -0
  28. package/dist/requestHandlers/deploymentHandlers.d.cts +5 -0
  29. package/dist/requestHandlers/deploymentHandlers.d.ts +5 -0
  30. package/dist/requestHandlers/deploymentHandlers.js +8 -0
  31. package/dist/requestHandlers/deploymentHandlers.js.map +1 -0
  32. package/dist/requestHandlers/deviceHandlers.cjs +1096 -0
  33. package/dist/requestHandlers/deviceHandlers.cjs.map +1 -0
  34. package/dist/requestHandlers/deviceHandlers.d.cts +20 -0
  35. package/dist/requestHandlers/deviceHandlers.d.ts +20 -0
  36. package/dist/requestHandlers/deviceHandlers.js +12 -0
  37. package/dist/requestHandlers/deviceHandlers.js.map +1 -0
  38. package/dist/requestHandlers/monitorHandlers.cjs +834 -0
  39. package/dist/requestHandlers/monitorHandlers.cjs.map +1 -0
  40. package/dist/requestHandlers/monitorHandlers.d.cts +5 -0
  41. package/dist/requestHandlers/monitorHandlers.d.ts +5 -0
  42. package/dist/requestHandlers/monitorHandlers.js +8 -0
  43. package/dist/requestHandlers/monitorHandlers.js.map +1 -0
  44. package/dist/requestHandlers/organizationHandlers.cjs +1129 -0
  45. package/dist/requestHandlers/organizationHandlers.cjs.map +1 -0
  46. package/dist/requestHandlers/organizationHandlers.d.cts +5 -0
  47. package/dist/requestHandlers/organizationHandlers.d.ts +5 -0
  48. package/dist/requestHandlers/organizationHandlers.js +8 -0
  49. package/dist/requestHandlers/organizationHandlers.js.map +1 -0
  50. package/dist/requestHandlers/releaseHandlers.cjs +965 -0
  51. package/dist/requestHandlers/releaseHandlers.cjs.map +1 -0
  52. package/dist/requestHandlers/releaseHandlers.d.cts +5 -0
  53. package/dist/requestHandlers/releaseHandlers.d.ts +5 -0
  54. package/dist/requestHandlers/releaseHandlers.js +8 -0
  55. package/dist/requestHandlers/releaseHandlers.js.map +1 -0
  56. package/dist/requestHandlers/requestHandlers.cjs +2002 -0
  57. package/dist/requestHandlers/requestHandlers.cjs.map +1 -0
  58. package/dist/requestHandlers/requestHandlers.d.cts +5 -0
  59. package/dist/requestHandlers/requestHandlers.d.ts +5 -0
  60. package/dist/requestHandlers/requestHandlers.js +35 -0
  61. package/dist/requestHandlers/requestHandlers.js.map +1 -0
  62. package/dist/requestHandlers/userHandlers.cjs +993 -0
  63. package/dist/requestHandlers/userHandlers.cjs.map +1 -0
  64. package/dist/requestHandlers/userHandlers.d.cts +5 -0
  65. package/dist/requestHandlers/userHandlers.d.ts +5 -0
  66. package/dist/requestHandlers/userHandlers.js +8 -0
  67. package/dist/requestHandlers/userHandlers.js.map +1 -0
  68. package/dist/setupTests.cjs +995 -0
  69. package/dist/setupTests.cjs.map +1 -0
  70. package/dist/setupTests.d.cts +77 -0
  71. package/dist/setupTests.d.ts +77 -0
  72. package/dist/setupTests.js +138 -0
  73. package/dist/setupTests.js.map +1 -0
  74. package/dist/theme/light.cjs +41 -0
  75. package/dist/theme/light.cjs.map +1 -0
  76. package/dist/theme/light.d.cts +12 -0
  77. package/dist/theme/light.d.ts +12 -0
  78. package/dist/theme/light.js +7 -0
  79. package/dist/theme/light.js.map +1 -0
  80. package/dist/utils.cjs +71 -0
  81. package/dist/utils.cjs.map +1 -0
  82. package/dist/utils.d.cts +69 -0
  83. package/dist/utils.d.ts +69 -0
  84. package/dist/utils.js +12 -0
  85. package/dist/utils.js.map +1 -0
  86. package/package.json +1 -1
@@ -0,0 +1,1096 @@
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 });
9
+ };
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;
17
+ };
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
+ }
610
+ ];
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
+ }
678
+ ];
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
+ }, {});
813
+
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
+ //# sourceMappingURL=deviceHandlers.cjs.map