@northern.tech/testing 0.1.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 (84) hide show
  1. package/dist/baseTestConfig.json +24 -0
  2. package/dist/chunk-3KEPLFEG.js +64 -0
  3. package/dist/chunk-3KEPLFEG.js.map +1 -0
  4. package/dist/chunk-4ZCNCVNV.js +309 -0
  5. package/dist/chunk-4ZCNCVNV.js.map +1 -0
  6. package/dist/chunk-5MREOBVU.js +833 -0
  7. package/dist/chunk-5MREOBVU.js.map +1 -0
  8. package/dist/chunk-A7LWVKMZ.js +209 -0
  9. package/dist/chunk-A7LWVKMZ.js.map +1 -0
  10. package/dist/chunk-ERCKCRE4.js +179 -0
  11. package/dist/chunk-ERCKCRE4.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-MH5OGHNU.js +29 -0
  15. package/dist/chunk-MH5OGHNU.js.map +1 -0
  16. package/dist/chunk-QSR5PAZ3.js +207 -0
  17. package/dist/chunk-QSR5PAZ3.js.map +1 -0
  18. package/dist/mockData.cjs +866 -0
  19. package/dist/mockData.cjs.map +1 -0
  20. package/dist/mockData.d.cts +558 -0
  21. package/dist/mockData.d.ts +558 -0
  22. package/dist/mockData.js +45 -0
  23. package/dist/mockData.js.map +1 -0
  24. package/dist/requestHandlers/deploymentHandlers.cjs +955 -0
  25. package/dist/requestHandlers/deploymentHandlers.cjs.map +1 -0
  26. package/dist/requestHandlers/deploymentHandlers.d.cts +5 -0
  27. package/dist/requestHandlers/deploymentHandlers.d.ts +5 -0
  28. package/dist/requestHandlers/deploymentHandlers.js +8 -0
  29. package/dist/requestHandlers/deploymentHandlers.js.map +1 -0
  30. package/dist/requestHandlers/deviceHandlers.cjs +1044 -0
  31. package/dist/requestHandlers/deviceHandlers.cjs.map +1 -0
  32. package/dist/requestHandlers/deviceHandlers.d.cts +20 -0
  33. package/dist/requestHandlers/deviceHandlers.d.ts +20 -0
  34. package/dist/requestHandlers/deviceHandlers.js +12 -0
  35. package/dist/requestHandlers/deviceHandlers.js.map +1 -0
  36. package/dist/requestHandlers/monitorHandlers.cjs +775 -0
  37. package/dist/requestHandlers/monitorHandlers.cjs.map +1 -0
  38. package/dist/requestHandlers/monitorHandlers.d.cts +5 -0
  39. package/dist/requestHandlers/monitorHandlers.d.ts +5 -0
  40. package/dist/requestHandlers/monitorHandlers.js +8 -0
  41. package/dist/requestHandlers/monitorHandlers.js.map +1 -0
  42. package/dist/requestHandlers/organizationHandlers.cjs +968 -0
  43. package/dist/requestHandlers/organizationHandlers.cjs.map +1 -0
  44. package/dist/requestHandlers/organizationHandlers.d.cts +5 -0
  45. package/dist/requestHandlers/organizationHandlers.d.ts +5 -0
  46. package/dist/requestHandlers/organizationHandlers.js +8 -0
  47. package/dist/requestHandlers/organizationHandlers.js.map +1 -0
  48. package/dist/requestHandlers/releaseHandlers.cjs +809 -0
  49. package/dist/requestHandlers/releaseHandlers.cjs.map +1 -0
  50. package/dist/requestHandlers/releaseHandlers.d.cts +5 -0
  51. package/dist/requestHandlers/releaseHandlers.d.ts +5 -0
  52. package/dist/requestHandlers/releaseHandlers.js +8 -0
  53. package/dist/requestHandlers/releaseHandlers.js.map +1 -0
  54. package/dist/requestHandlers/requestHandlers.cjs +1712 -0
  55. package/dist/requestHandlers/requestHandlers.cjs.map +1 -0
  56. package/dist/requestHandlers/requestHandlers.d.cts +5 -0
  57. package/dist/requestHandlers/requestHandlers.d.ts +5 -0
  58. package/dist/requestHandlers/requestHandlers.js +35 -0
  59. package/dist/requestHandlers/requestHandlers.js.map +1 -0
  60. package/dist/requestHandlers/userHandlers.cjs +925 -0
  61. package/dist/requestHandlers/userHandlers.cjs.map +1 -0
  62. package/dist/requestHandlers/userHandlers.d.cts +5 -0
  63. package/dist/requestHandlers/userHandlers.d.ts +5 -0
  64. package/dist/requestHandlers/userHandlers.js +8 -0
  65. package/dist/requestHandlers/userHandlers.js.map +1 -0
  66. package/dist/setupTests.cjs +905 -0
  67. package/dist/setupTests.cjs.map +1 -0
  68. package/dist/setupTests.d.cts +75 -0
  69. package/dist/setupTests.d.ts +75 -0
  70. package/dist/setupTests.js +119 -0
  71. package/dist/setupTests.js.map +1 -0
  72. package/dist/theme/light.cjs +41 -0
  73. package/dist/theme/light.cjs.map +1 -0
  74. package/dist/theme/light.d.cts +12 -0
  75. package/dist/theme/light.d.ts +12 -0
  76. package/dist/theme/light.js +7 -0
  77. package/dist/theme/light.js.map +1 -0
  78. package/dist/utils.cjs +41 -0
  79. package/dist/utils.cjs.map +1 -0
  80. package/dist/utils.d.cts +3 -0
  81. package/dist/utils.d.ts +3 -0
  82. package/dist/utils.js +16 -0
  83. package/dist/utils.js.map +1 -0
  84. package/package.json +55 -0
@@ -0,0 +1,1044 @@
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
+ limit: 500,
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
+ intentId: "testIntent",
243
+ auditlog: {
244
+ events: [
245
+ {
246
+ actor: {
247
+ id: "string",
248
+ type: "user",
249
+ email: "string@example.com"
250
+ },
251
+ time: "2019-01-01T12:10:22.667Z",
252
+ action: "create",
253
+ object: {
254
+ id: "string",
255
+ type: "user",
256
+ user: {
257
+ email: "user@acme.com"
258
+ }
259
+ },
260
+ change: "change1"
261
+ },
262
+ {
263
+ actor: {
264
+ id: "string",
265
+ type: "user",
266
+ email: "string",
267
+ identity_data: "string"
268
+ },
269
+ time: "2019-01-01T12:16:22.667Z",
270
+ action: "create",
271
+ object: {
272
+ id: "string",
273
+ type: "deployment",
274
+ deployment: {
275
+ name: "production",
276
+ artifact_name: "Application 0.0.1"
277
+ }
278
+ },
279
+ change: "change2"
280
+ },
281
+ {
282
+ actor: {
283
+ id: "string",
284
+ type: "user",
285
+ email: "string@example.com"
286
+ },
287
+ time: "2019-01-01T12:10:22.669Z",
288
+ action: "open_terminal",
289
+ meta: {
290
+ session_id: ["abd313a8-ee88-48ab-9c99-fbcd80048e6e"]
291
+ },
292
+ object: {
293
+ id: "a1",
294
+ type: "device"
295
+ },
296
+ change: "change3"
297
+ }
298
+ ]
299
+ }
300
+ },
301
+ releases: {
302
+ byId: {
303
+ r1: {
304
+ name: "r1",
305
+ artifacts: [
306
+ {
307
+ id: "art1",
308
+ description: "test description",
309
+ device_types_compatible: [deviceTypes.qemu],
310
+ modified: "2020-09-10T12:16:22.667Z",
311
+ updates: [{ type_info: "testtype" }],
312
+ artifact_depends: {
313
+ device_type: [deviceTypes.qemu]
314
+ },
315
+ artifact_provides: {
316
+ artifact_name: "myapp",
317
+ "data-partition.myapp.version": "v2020.10",
318
+ list_of_fancy: [deviceTypes.qemu, "x172"]
319
+ },
320
+ clears_artifact_provides: ["data-partition.myapp.*"]
321
+ }
322
+ ],
323
+ device_types_compatible: [deviceTypes.qemu],
324
+ modified: "2020-09-10T12:16:22.667Z",
325
+ metaData: {}
326
+ }
327
+ }
328
+ },
329
+ users: {
330
+ byId: {
331
+ a1: defaultUser,
332
+ [userId]: { ...defaultUser, id: userId, email: "a2@b.com", created_ts: "2019-01-01T12:30:00.000Z" }
333
+ },
334
+ rolesById: {
335
+ admin: {
336
+ name: "admin",
337
+ description: "Administrator role",
338
+ permissions: []
339
+ },
340
+ test: { name: "test", description: "test description", permissions: [] }
341
+ },
342
+ globalSettings: {
343
+ "2fa": "enabled",
344
+ id_attribute: void 0,
345
+ previousFilters: []
346
+ },
347
+ userSettings: {
348
+ "2fa": "disabled",
349
+ columnSelection: [],
350
+ onboarding: { something: "here" },
351
+ tooltips: {},
352
+ previousFilters: []
353
+ }
354
+ }
355
+ };
356
+ var releasesList = Array.from({ length: 5e3 }, (x, i) => ({
357
+ artifacts: [
358
+ {
359
+ id: "art1",
360
+ description: "test description",
361
+ device_types_compatible: [deviceTypes.qemu],
362
+ modified: "2020-09-10T12:16:22.667Z",
363
+ updates: [{ type_info: "testtype" }],
364
+ artifact_depends: {
365
+ device_type: [deviceTypes.qemu]
366
+ },
367
+ artifact_provides: {
368
+ artifact_name: "myapp",
369
+ "data-partition.myapp.version": "v2020.10",
370
+ list_of_fancy: [deviceTypes.qemu, "x172"]
371
+ },
372
+ clears_artifact_provides: ["data-partition.myapp.*"]
373
+ }
374
+ ],
375
+ device_types_compatible: [deviceTypes.qemu],
376
+ metaData: {},
377
+ name: `release-${i + 1}`,
378
+ modified: i
379
+ }));
380
+ var permissionSets = [
381
+ {
382
+ ...import_constants.defaultPermissionSets.Basic,
383
+ object: permissionSetObjectTypes.empty,
384
+ description: "Set containing basic permissions.",
385
+ permissions: [
386
+ { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/settings$" } },
387
+ { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/users/me$" } },
388
+ { action: "http", object: { type: "any", value: "^/api/management/1.0/auth/verify$" } },
389
+ { action: "http", object: { type: "PUT", value: "^/api/management/v1/useradm/2faverify$" } },
390
+ { action: "http", object: { type: "POST", value: "^/api/management/v1/useradm/users/me/2fa/(enable|disable)$" } },
391
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/roles" } },
392
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/user/tenant" } }
393
+ ]
394
+ },
395
+ {
396
+ ...import_constants.defaultPermissionSets.ManageReleases,
397
+ action: import_constants.uiPermissionsById.manage.title,
398
+ object: permissionSetObjectTypes.releases,
399
+ description: "Set of permissions which allows user to manage releases",
400
+ permissions: [
401
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
402
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
403
+ { action: "http", object: { type: "PUT", value: commonEndpoints.artifactDetails } },
404
+ { action: "http", object: { type: "DELETE", value: commonEndpoints.artifactDetails } },
405
+ { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
406
+ ]
407
+ },
408
+ {
409
+ ...import_constants.defaultPermissionSets.ReadUsers,
410
+ action: import_constants.uiPermissionsById.read.title,
411
+ object: permissionSetObjectTypes.userManagement,
412
+ description: "Set of permissions which allows user to view other users",
413
+ permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/" } }]
414
+ },
415
+ {
416
+ ...import_constants.defaultPermissionSets.ManageUsers,
417
+ action: import_constants.uiPermissionsById.manage.title,
418
+ object: permissionSetObjectTypes.userManagement,
419
+ description: "Set of permissions which allows user manage other user accounts",
420
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/" } }]
421
+ },
422
+ {
423
+ ...import_constants.defaultPermissionSets.ReadTenants,
424
+ action: import_constants.uiPermissionsById.read.title,
425
+ object: permissionSetObjectTypes.tenantManagement,
426
+ description: "Set of permissions which allows user to list other tenants and their config",
427
+ permissions: [
428
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
429
+ { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } }
430
+ ]
431
+ },
432
+ {
433
+ ...import_constants.defaultPermissionSets.ManageTenants,
434
+ action: import_constants.uiPermissionsById.manage.title,
435
+ object: permissionSetObjectTypes.tenantManagement,
436
+ description: "Set of permissions which allows user to manage other tenants and their config",
437
+ permissions: [
438
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
439
+ { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } },
440
+ { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9])/tenantadm/" } }
441
+ ]
442
+ },
443
+ {
444
+ ...import_constants.defaultPermissionSets.ReadAuditLogs,
445
+ action: import_constants.uiPermissionsById.read.title,
446
+ object: "System Audit Log",
447
+ description: "Set of permissions which allows user to view system audit log",
448
+ permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/auditlogs/logs" } }]
449
+ },
450
+ {
451
+ ...import_constants.defaultPermissionSets.DeployToDevices,
452
+ action: "Deploy",
453
+ object: permissionSetObjectTypes.groups,
454
+ description: "Set of permissions which allows user to deploy to devices",
455
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/(deployments|deviceconfig)/" } }],
456
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
457
+ },
458
+ {
459
+ ...import_constants.defaultPermissionSets.ConfigureDevices,
460
+ action: "Configure",
461
+ object: permissionSetObjectTypes.groups,
462
+ description: "Set of permissions which allows user to manage configuration of the devices",
463
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/" } }],
464
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
465
+ },
466
+ {
467
+ ...import_constants.defaultPermissionSets.ConnectToDevices,
468
+ action: "Connect",
469
+ object: permissionSetObjectTypes.groups,
470
+ description: "Set of permissions which allows user to use remote terminal and file transfer",
471
+ permissions: [
472
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/connect$" } },
473
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/download\\?path=[^&]+$" } },
474
+ { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/upload$" } }
475
+ ],
476
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
477
+ },
478
+ {
479
+ ...import_constants.defaultPermissionSets.SuperUser,
480
+ action: "Any",
481
+ object: permissionSetObjectTypes.any,
482
+ description: "Set of permissions which allows user to do anything",
483
+ permissions: [{ action: "any", object: { type: "any", value: "any" } }]
484
+ },
485
+ {
486
+ ...import_constants.defaultPermissionSets.UploadArtifacts,
487
+ action: "Upload",
488
+ object: permissionSetObjectTypes.artifacts,
489
+ description: "Set of permissions which allows user to upload artifacts",
490
+ permissions: [
491
+ { action: "http", object: { type: "POST", value: commonEndpoints.artifacts } },
492
+ { action: "http", object: { type: "POST", value: "^/api/management/v1/deployments/artifacts/generate" } }
493
+ ]
494
+ },
495
+ {
496
+ ...import_constants.defaultPermissionSets.ReadDevices,
497
+ action: import_constants.uiPermissionsById.read.title,
498
+ object: permissionSetObjectTypes.groups,
499
+ description: "Set of permissions which allows user to view devices",
500
+ permissions: [
501
+ { action: "http", object: { type: "POST", value: "^/api/management/v2/inventory/filters/search" } },
502
+ { action: "http", object: { type: "POST", value: "^/api/management/v1/reporting/devices/search" } },
503
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/(deployments|devauth|inventory|deviceconfig|devicemonitor)/" } },
504
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+$" } }
505
+ ],
506
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
507
+ },
508
+ {
509
+ ...import_constants.defaultPermissionSets.ManageDevices,
510
+ action: import_constants.uiPermissionsById.manage.title,
511
+ object: permissionSetObjectTypes.groups,
512
+ description: "Set of permissions which allows user to manage devices",
513
+ permissions: [
514
+ { action: "http", object: { type: "POST", value: commonEndpoints.deviceManagement } },
515
+ { action: "http", object: { type: "PUT", value: commonEndpoints.deviceManagement } },
516
+ { action: "http", object: { type: "DELETE", value: commonEndpoints.deviceManagement } }
517
+ ],
518
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
519
+ },
520
+ {
521
+ ...import_constants.defaultPermissionSets.ReadReleases,
522
+ action: import_constants.uiPermissionsById.read.title,
523
+ object: permissionSetObjectTypes.releases,
524
+ description: "Set of permissions which allows user to view releases",
525
+ permissions: [
526
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
527
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
528
+ { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
529
+ ]
530
+ },
531
+ {
532
+ name: "almostAdmin",
533
+ object: permissionSetObjectTypes.empty,
534
+ description: "Set containing all the permissions.",
535
+ permissions: [
536
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/auditlogs/.*" } },
537
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/.*" } },
538
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/config/.*" } },
539
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/.*" } },
540
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/releases/.*" } },
541
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/devauth/.*" } },
542
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/.*" } },
543
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/.*" } },
544
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/devices" } },
545
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/inventory/.*" } },
546
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/iot-manager/.*" } },
547
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/monitor/.*" } },
548
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/.*" } }
549
+ ]
550
+ }
551
+ ];
552
+ var rbacRoles = [
553
+ {
554
+ name: "dyn",
555
+ description: "",
556
+ permissions: [
557
+ { action: "CREATE_DEPLOYMENT", object: { type: "DEVICE_GROUP", value: "dyn" } },
558
+ { action: "VIEW_DEVICE", object: { type: "DEVICE_GROUP", value: "dyn" } }
559
+ ]
560
+ },
561
+ { name: "asdasd", description: "123", permissions: [{ action: "http", object: { type: "any", value: "/api/management/v1/useradm/.*" } }] },
562
+ {
563
+ name: "141sasd",
564
+ description: "1313adg",
565
+ permission_sets_with_scope: [
566
+ { ...import_constants.defaultPermissionSets.ReadDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
567
+ { ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
568
+ { ...import_constants.defaultPermissionSets.ManageUsers }
569
+ ]
570
+ },
571
+ {
572
+ name: "kljlkk",
573
+ description: "lkl",
574
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } }]
575
+ },
576
+ {
577
+ name: "yyyyy",
578
+ description: "asd",
579
+ permission_sets_with_scope: [
580
+ { ...import_constants.defaultPermissionSets.ManageDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["dockerclient"] } },
581
+ { ...import_constants.defaultPermissionSets.ManageReleases }
582
+ ]
583
+ },
584
+ {
585
+ name: "RBAC_ROLE_DEPLOYMENTS_MANAGER",
586
+ description: "Intended for users responsible for managing deployments, this role can create and abort deployments",
587
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.DeployToDevices }]
588
+ },
589
+ {
590
+ name: "RBAC_ROLE_REMOTE_TERMINAL",
591
+ description: `Intended for tech support accounts, this role can access the devices' Remote Terminal.`,
592
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices }]
593
+ },
594
+ { name: "RBAC_ROLE_PERMIT_ALL", description: "", permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.SuperUser }] },
595
+ {
596
+ name: "RBAC_ROLE_OBSERVER",
597
+ 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.",
598
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ReadReleases }, { ...import_constants.defaultPermissionSets.ReadDevices }]
599
+ },
600
+ {
601
+ name: "RBAC_ROLE_CI",
602
+ 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.",
603
+ permission_sets_with_scope: [
604
+ { ...import_constants.defaultPermissionSets.ReadReleases },
605
+ { ...import_constants.defaultPermissionSets.ManageReleases },
606
+ { ...import_constants.defaultPermissionSets.UploadArtifacts }
607
+ ]
608
+ },
609
+ {
610
+ name: "almostAdmin",
611
+ description: "almost admin rights",
612
+ permissions: permissionSets.find((item) => item.name === "almostAdmin")?.permissions
613
+ },
614
+ {
615
+ name: "almostAdminNew",
616
+ description: "almost admin rights",
617
+ permission_sets_with_scope: Object.values(import_constants.defaultPermissionSets)
618
+ }
619
+ ];
620
+ var expectedParsedRoles = {
621
+ "141sasd": {
622
+ editable: true,
623
+ isCustom: void 0,
624
+ uiPermissions: {
625
+ ...import_constants.emptyUiPermissions,
626
+ groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] },
627
+ userManagement: [import_constants.uiPermissionsById.manage.value]
628
+ }
629
+ },
630
+ asdasd: {
631
+ editable: false,
632
+ isCustom: true,
633
+ uiPermissions: { ...import_constants.emptyUiPermissions, userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] }
634
+ },
635
+ dyn: {
636
+ editable: false,
637
+ isCustom: true,
638
+ uiPermissions: {
639
+ ...import_constants.emptyUiPermissions,
640
+ deployments: [import_constants.uiPermissionsById.deploy.value],
641
+ groups: { dyn: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value] }
642
+ }
643
+ },
644
+ kljlkk: {
645
+ editable: true,
646
+ isCustom: false,
647
+ uiPermissions: { ...import_constants.emptyUiPermissions, groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] } }
648
+ },
649
+ yyyyy: {
650
+ editable: true,
651
+ isCustom: void 0,
652
+ uiPermissions: {
653
+ ...import_constants.emptyUiPermissions,
654
+ groups: { dockerclient: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] },
655
+ releases: { [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value] }
656
+ }
657
+ },
658
+ almostAdmin: {
659
+ editable: false,
660
+ isCustom: true,
661
+ uiPermissions: {
662
+ ...import_constants.emptyUiPermissions,
663
+ auditlog: [import_constants.uiPermissionsById.read.value],
664
+ deployments: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.read.value],
665
+ groups: {
666
+ [import_constants.ALL_DEVICES]: [
667
+ import_constants.uiPermissionsById.read.value,
668
+ // we can't assign deployment permissions to devices here, since the old path based rbac controls don't allow the scoped permissions
669
+ // uiPermissionsById.deploy.value,
670
+ import_constants.uiPermissionsById.manage.value,
671
+ import_constants.uiPermissionsById.connect.value,
672
+ import_constants.uiPermissionsById.configure.value
673
+ ]
674
+ },
675
+ releases: {
676
+ [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.manage.value]
677
+ },
678
+ userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
679
+ }
680
+ },
681
+ almostAdminNew: {
682
+ editable: true,
683
+ isCustom: void 0,
684
+ uiPermissions: {
685
+ ...import_constants.emptyUiPermissions,
686
+ auditlog: [import_constants.uiPermissionsById.read.value],
687
+ deployments: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.manage.value],
688
+ groups: {
689
+ [import_constants.ALL_DEVICES]: [
690
+ import_constants.uiPermissionsById.read.value,
691
+ import_constants.uiPermissionsById.manage.value,
692
+ import_constants.uiPermissionsById.deploy.value,
693
+ import_constants.uiPermissionsById.connect.value,
694
+ import_constants.uiPermissionsById.configure.value
695
+ ]
696
+ },
697
+ releases: {
698
+ [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.read.value]
699
+ },
700
+ tenantManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value],
701
+ userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
702
+ }
703
+ }
704
+ };
705
+ var defaultRolesById = {
706
+ ...import_constants.rolesById,
707
+ test: {
708
+ ...import_constants.emptyRole,
709
+ name: "test",
710
+ description: "test description",
711
+ editable: true,
712
+ uiPermissions: {
713
+ ...import_constants.emptyUiPermissions,
714
+ groups: { testGroup: [import_constants.uiPermissionsById.read.value] },
715
+ releases: { bar: [import_constants.uiPermissionsById.read.value] }
716
+ }
717
+ }
718
+ };
719
+ var receivedRoles = rbacRoles.reduce(
720
+ (accu, role) => {
721
+ const { name, description, ...roleRemainder } = role;
722
+ if (name.startsWith("RBAC")) {
723
+ accu[name] = {
724
+ ...defaultRolesById[name],
725
+ ...roleRemainder,
726
+ editable: false,
727
+ isCustom: false,
728
+ description: defaultRolesById[name].description ? defaultRolesById[name].description : description
729
+ };
730
+ } else {
731
+ const result = expectedParsedRoles[name] ?? {};
732
+ accu[name] = {
733
+ ...import_constants.emptyRole,
734
+ ...role,
735
+ ...result,
736
+ name
737
+ };
738
+ }
739
+ return accu;
740
+ },
741
+ { ...defaultRolesById }
742
+ );
743
+ var receivedPermissionSets = permissionSets.reduce((accu, set) => {
744
+ const result = import_constants.defaultPermissionSets[set.name]?.result ?? {};
745
+ accu[set.name] = {
746
+ ...set,
747
+ result: {
748
+ ...import_constants.emptyUiPermissions,
749
+ ...result
750
+ }
751
+ };
752
+ return accu;
753
+ }, {});
754
+
755
+ // src/requestHandlers/deviceHandlers.ts
756
+ var defaultDeviceId = "a1";
757
+ var deviceAuthDevice = {
758
+ id: defaultDeviceId,
759
+ identity_data: { mac: defaultMacAddress },
760
+ status: "accepted",
761
+ decommissioning: false,
762
+ created_ts: defaultCreationDate,
763
+ updated_ts: "2019-01-01T09:25:00.000Z",
764
+ auth_sets: [
765
+ {
766
+ id: "auth1",
767
+ identity_data: { mac: defaultMacAddress },
768
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
769
+ ts: defaultCreationDate,
770
+ status: "accepted"
771
+ }
772
+ ]
773
+ };
774
+ var checkInTimeExact2 = "2019-01-01T10:25:00.000Z";
775
+ var updatedTime = "2019-01-01T09:25:00.000Z";
776
+ var inventoryDevice = {
777
+ id: defaultDeviceId,
778
+ attributes: [
779
+ { name: "network_interfaces", value: ["eth0", "wlan0"], scope: "inventory" },
780
+ { name: "kernel", value: "Linux version 4.19.75-v7l+", scope: "inventory" },
781
+ { name: "artifact_name", value: "raspotifyInstaller", scope: "inventory" },
782
+ { name: "ipv6_wlan0", value: "fe80::68d9:8453:3e9c:7c80/64", scope: "inventory" },
783
+ { name: "mac_eth0", value: defaultMacAddress, scope: "inventory" },
784
+ { name: "rootfs_type", value: "ext4", scope: "inventory" },
785
+ { name: "mender_bootloader_integration", value: "unknown", scope: "inventory" },
786
+ { name: "cpu_model", value: "ARMv7 Processor rev 3 (v7l)", scope: "inventory" },
787
+ { name: "hostname", value: "raspberrypi", scope: "inventory" },
788
+ { name: "mender_client_version", value: "2.1.0", scope: "inventory" },
789
+ { name: "ipv4_wlan0", value: "192.168.10.141/24", scope: "inventory" },
790
+ { name: "device_type", value: "raspberrypi4", scope: "inventory" },
791
+ { name: "mem_total_kB", value: "1986024", scope: "inventory" },
792
+ { name: "mac_wlan0", value: "dc:a6:32:12:ad:c0", scope: "inventory" },
793
+ { name: "os", value: "Raspbian GNU/Linux 10 (buster)", scope: "inventory" },
794
+ { name: "created_ts", value: defaultCreationDate, scope: "system" },
795
+ { name: "updated_ts", value: updatedTime, scope: "system" },
796
+ { name: "status", value: "accepted", scope: "identity" },
797
+ { name: "mac", value: defaultMacAddress, scope: "identity" },
798
+ { name: "group", value: "test", scope: "system" }
799
+ ],
800
+ check_in_time: checkInTimeExact2,
801
+ updated_ts: updatedTime
802
+ };
803
+ var deviceAttributes = [
804
+ { name: "status", scope: "identity", count: 5 },
805
+ { name: "created_ts", scope: "system", count: 5 },
806
+ { name: "updated_ts", scope: "system", count: 5 },
807
+ { name: "mac", scope: "identity", count: 1 },
808
+ { name: "artifact_name", scope: "inventory", count: 1 },
809
+ { name: "cpu_model", scope: "inventory", count: 1 },
810
+ { name: "device_type", scope: "inventory", count: 1 },
811
+ { name: "hostname", scope: "inventory", count: 1 },
812
+ { name: "ipv4_wlan0", scope: "inventory", count: 1 },
813
+ { name: "ipv6_wlan0", scope: "inventory", count: 1 },
814
+ { name: "kernel", scope: "inventory", count: 1 },
815
+ { name: "mac_eth0", scope: "inventory", count: 1 },
816
+ { name: "mac_wlan0", scope: "inventory", count: 1 },
817
+ { name: "mem_total_kB", scope: "inventory", count: 1 },
818
+ { name: "mender_bootloader_integration", scope: "inventory", count: 1 },
819
+ { name: "mender_client_version", scope: "inventory", count: 1 },
820
+ { name: "network_interfaces", scope: "inventory", count: 1 },
821
+ { name: "os", scope: "inventory", count: 1 },
822
+ { name: "rootfs_type", scope: "inventory", count: 1 },
823
+ { name: "group", scope: "system", count: 1 }
824
+ ];
825
+ var searchHandler = async ({ request }) => {
826
+ const { page, per_page, filters } = await request.json();
827
+ if ([page, per_page, filters].some((item) => !item)) {
828
+ return new import_msw.HttpResponse(null, { status: 509 });
829
+ }
830
+ const filter = filters.find((filter2) => filter2.scope === "identity" && filter2.attribute === "status" && Object.values(import_constants2.DEVICE_STATES).includes(filter2.value));
831
+ const status = filter?.value || "";
832
+ if (!status || filters.length > 1) {
833
+ if (filters.find((filter2) => filter2.attribute === "group" && filter2.value.includes(Object.keys(mockApiResponses.devices.groups.byId)[0]))) {
834
+ return new import_msw.HttpResponse(JSON.stringify([inventoryDevice, { ...inventoryDevice, id: "b1" }]), {
835
+ headers: { [import_constants2.headerNames.total]: 2 }
836
+ });
837
+ }
838
+ if (filters.find((filter2) => filter2.scope === "monitor" && ["failed_last_update", "alerts", "auth_request"].includes(filter2.attribute))) {
839
+ return new import_msw.HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [import_constants2.headerNames.total]: 4 } });
840
+ }
841
+ return new import_msw.HttpResponse(JSON.stringify([]), { headers: { [import_constants2.headerNames.total]: 0 } });
842
+ }
843
+ let deviceList = Array.from({ length: mockApiResponses.devices.byStatus[status].total }, (_, index) => ({
844
+ ...inventoryDevice,
845
+ attributes: [...inventoryDevice.attributes, { name: "test-count", value: index, scope: "system" }],
846
+ id: `${String.fromCharCode("a".charCodeAt(0) + index)}1`
847
+ }));
848
+ deviceList = deviceList.slice((page - 1) * per_page, page * per_page);
849
+ return new import_msw.HttpResponse(JSON.stringify(deviceList), { headers: { [import_constants2.headerNames.total]: mockApiResponses.devices.byStatus[status].total } });
850
+ };
851
+ var deviceHandlers = [
852
+ import_msw.http.delete(`${import_constants2.deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {
853
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId)) {
854
+ return new import_msw.HttpResponse(null, { status: 200 });
855
+ }
856
+ return new import_msw.HttpResponse(null, { status: 501 });
857
+ }),
858
+ import_msw.http.delete(`${import_constants2.deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {
859
+ if (mockApiResponses.devices.byId[deviceId]) {
860
+ return new import_msw.HttpResponse(null, { status: 200 });
861
+ }
862
+ return new import_msw.HttpResponse(null, { status: 502 });
863
+ }),
864
+ import_msw.http.delete(`${import_constants2.inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {
865
+ if (mockApiResponses.devices.groups.byId[group]) {
866
+ return new import_msw.HttpResponse(null, { status: 200 });
867
+ }
868
+ return new import_msw.HttpResponse(null, { status: 515 });
869
+ }),
870
+ import_msw.http.delete(`${import_constants2.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
871
+ const deviceIds = await request.json();
872
+ if (mockApiResponses.devices.groups.byId[group] && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
873
+ return new import_msw.HttpResponse(null, { status: 200 });
874
+ }
875
+ return new import_msw.HttpResponse(null, { status: 503 });
876
+ }),
877
+ import_msw.http.delete(`${import_constants2.inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {
878
+ if (Object.values(mockApiResponses.devices.groups.byId).find((group) => group.id === filterId)) {
879
+ return new import_msw.HttpResponse(null, { status: 200 });
880
+ }
881
+ return new import_msw.HttpResponse(null, { status: 504 });
882
+ }),
883
+ import_msw.http.get(`${import_constants2.deviceAuthV2}/devices`, ({ request }) => {
884
+ const { searchParams } = new URL(request.url);
885
+ const deviceIds = searchParams.getAll("id");
886
+ if (deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
887
+ return import_msw.HttpResponse.json(deviceIds.map((id) => ({ ...deviceAuthDevice, id })));
888
+ }
889
+ return new import_msw.HttpResponse(null, { status: 505 });
890
+ }),
891
+ import_msw.http.get(`${import_constants2.deviceAuthV2}/limits/max_devices`, () => import_msw.HttpResponse.json({ limit: mockApiResponses.devices.limit })),
892
+ import_msw.http.get(`${import_constants2.inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {
893
+ if (mockApiResponses.devices.byId[deviceId]) {
894
+ return import_msw.HttpResponse.json(inventoryDevice);
895
+ }
896
+ return new import_msw.HttpResponse(null, { status: 506 });
897
+ }),
898
+ import_msw.http.put(`${import_constants2.inventoryApiUrl}/devices/:deviceId/tags`, async ({ params: { deviceId }, request }) => {
899
+ const tags = await request.json();
900
+ if (!mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every((item) => item.name && item.value)) {
901
+ return new import_msw.HttpResponse(null, { status: 506 });
902
+ }
903
+ return import_msw.HttpResponse.json(tags);
904
+ }),
905
+ import_msw.http.get(`${import_constants2.inventoryApiUrl}/groups`, () => {
906
+ const groups = Object.entries(mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {
907
+ if (!group.id) {
908
+ accu.push(groupName);
909
+ }
910
+ return accu;
911
+ }, []);
912
+ return import_msw.HttpResponse.json(groups);
913
+ }),
914
+ import_msw.http.get(`${import_constants2.inventoryApiUrlV2}/filters/attributes`, () => import_msw.HttpResponse.json(deviceAttributes)),
915
+ import_msw.http.get(`${import_constants2.reportingApiUrl}/devices/attributes`, () => import_msw.HttpResponse.json({ attributes: deviceAttributes, count: deviceAttributes.length, limit: 100 })),
916
+ import_msw.http.get(`${import_constants2.reportingApiUrl}/devices/search/attributes`, () => import_msw.HttpResponse.json(deviceAttributes)),
917
+ import_msw.http.post(
918
+ `${import_constants2.reportingApiUrl}/devices/aggregate`,
919
+ () => import_msw.HttpResponse.json([
920
+ {
921
+ name: "*",
922
+ items: [
923
+ { key: "test", count: 6 },
924
+ { key: "original", count: 1 }
925
+ ],
926
+ other_count: 42
927
+ }
928
+ ])
929
+ ),
930
+ import_msw.http.get(
931
+ `${import_constants2.inventoryApiUrlV2}/filters`,
932
+ () => import_msw.HttpResponse.json([
933
+ {
934
+ id: "filter1",
935
+ name: "testGroupDynamic",
936
+ terms: [
937
+ { scope: "identity", attribute: "id", type: "$in", value: [defaultDeviceId] },
938
+ { scope: "identity", attribute: "mac", type: "$exists", value: false },
939
+ { scope: "identity", attribute: "kernel", type: "$exists", value: true }
940
+ ]
941
+ }
942
+ ])
943
+ ),
944
+ import_msw.http.patch(`${import_constants2.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
945
+ const deviceIds = await request.json();
946
+ if (!!group && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
947
+ return new import_msw.HttpResponse(null, { status: 200 });
948
+ }
949
+ return new import_msw.HttpResponse(null, { status: 508 });
950
+ }),
951
+ import_msw.http.post(`${import_constants2.deviceAuthV2}/devices`, async ({ request }) => {
952
+ const authset = await request.json();
953
+ if (Object.values(mockApiResponses.devices.byId).some(
954
+ (device) => device.auth_sets.some((deviceAuthSet) => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data)
955
+ )) {
956
+ return new import_msw.HttpResponse(null, { status: 409 });
957
+ }
958
+ return new import_msw.HttpResponse(null, { status: 200 });
959
+ }),
960
+ import_msw.http.post(`${import_constants2.inventoryApiUrlV2}/filters/search`, searchHandler),
961
+ import_msw.http.post(`${import_constants2.reportingApiUrl}/filters/search`, searchHandler),
962
+ import_msw.http.post(`${import_constants2.inventoryApiUrlV2}/filters`, async ({ request }) => {
963
+ const { name, terms } = await request.json();
964
+ 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)) {
965
+ return new import_msw.HttpResponse(null, { status: 510 });
966
+ }
967
+ return new import_msw.HttpResponse(JSON.stringify({}), { headers: { location: "find/me/here/createdFilterId" } });
968
+ }),
969
+ import_msw.http.put(`${import_constants2.deviceAuthV2}/devices/:deviceId/auth/:authId/status`, async ({ params: { authId, deviceId }, request }) => {
970
+ const { status } = await request.json();
971
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId) && import_constants2.DEVICE_STATES[status]) {
972
+ return new import_msw.HttpResponse(null, { status: 200 });
973
+ }
974
+ return new import_msw.HttpResponse(null, { status: 511 });
975
+ }),
976
+ import_msw.http.get(`${import_constants2.deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {
977
+ if (deviceId === "testId") {
978
+ return new import_msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
979
+ }
980
+ if (mockApiResponses.devices.byId[deviceId]) {
981
+ return import_msw.HttpResponse.json({
982
+ configured: { test: true, something: "else", aNumber: 42 },
983
+ deployment_id: "config1",
984
+ reported: { test: true, something: "else", aNumber: 42 },
985
+ updated_ts: updatedTime,
986
+ reported_ts: "2019-01-01T09:25:01.000Z"
987
+ });
988
+ }
989
+ return new import_msw.HttpResponse(null, { status: 512 });
990
+ }),
991
+ import_msw.http.put(`${import_constants2.deviceConfig}/:deviceId`, async ({ params: { deviceId }, request }) => {
992
+ const body = await request.text();
993
+ if (body.includes("evilValue")) {
994
+ return new import_msw.HttpResponse(null, { status: 418 });
995
+ }
996
+ return new import_msw.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 201 : 513 });
997
+ }),
998
+ import_msw.http.post(`${import_constants2.deviceConfig}/:deviceId/deploy`, ({ params: { deviceId } }) => {
999
+ if (mockApiResponses.devices.byId[deviceId]) {
1000
+ return import_msw.HttpResponse.json({ deployment_id: "config1" });
1001
+ }
1002
+ return new import_msw.HttpResponse(null, { status: 514 });
1003
+ }),
1004
+ import_msw.http.get(`${import_constants2.deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {
1005
+ if (deviceId === "testId") {
1006
+ return new import_msw.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
1007
+ }
1008
+ if (mockApiResponses.devices.byId[deviceId]) {
1009
+ return import_msw.HttpResponse.json({ status: "connected", updated_ts: mockApiResponses.devices.byId[deviceId].updated_ts });
1010
+ }
1011
+ return new import_msw.HttpResponse(null, { status: 512 });
1012
+ }),
1013
+ import_msw.http.post(`${import_constants2.deviceConnect}/devices/:deviceId/:action`, ({ params: { deviceId, action } }) => {
1014
+ if (["check-update", "send-inventory"].includes(action) && mockApiResponses.devices.byId[deviceId]) {
1015
+ return new import_msw.HttpResponse(null, { status: 202 });
1016
+ }
1017
+ return new import_msw.HttpResponse(null, { status: 518 });
1018
+ }),
1019
+ import_msw.http.get(`${import_constants2.iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {
1020
+ if (mockApiResponses.devices.byId[deviceId]) {
1021
+ return import_msw.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1022
+ }
1023
+ return new import_msw.HttpResponse(null, { status: 515 });
1024
+ }),
1025
+ import_msw.http.put(`${import_constants2.iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, async ({ params: { deviceId }, request }) => {
1026
+ const body = await request.json();
1027
+ if (mockApiResponses.devices.byId[deviceId] && body) {
1028
+ return import_msw.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1029
+ }
1030
+ return new import_msw.HttpResponse(null, { status: 516 });
1031
+ }),
1032
+ import_msw.http.put(
1033
+ `${import_constants2.deviceConnect}/devices/:deviceId/upload`,
1034
+ ({ params: { deviceId } }) => new import_msw.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 200 : 517 })
1035
+ ),
1036
+ import_msw.http.get(`${import_constants2.deviceAuthV2}/reports/devices`, () => import_msw.HttpResponse.text("test,report"))
1037
+ ];
1038
+ // Annotate the CommonJS export names for ESM import in node:
1039
+ 0 && (module.exports = {
1040
+ defaultDeviceId,
1041
+ deviceHandlers,
1042
+ inventoryDevice
1043
+ });
1044
+ //# sourceMappingURL=deviceHandlers.cjs.map