@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,2002 @@
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/requestHandlers.ts
21
+ var requestHandlers_exports = {};
22
+ __export(requestHandlers_exports, {
23
+ default: () => requestHandlers_default
24
+ });
25
+ module.exports = __toCommonJS(requestHandlers_exports);
26
+ var import_msw7 = require("msw");
27
+
28
+ // src/requestHandlers/deploymentHandlers.ts
29
+ var import_constants2 = require("@northern.tech/utils/constants");
30
+ var import_msw = require("msw");
31
+
32
+ // src/mockData.ts
33
+ var import_constants = require("@northern.tech/utils/constants");
34
+ var TEST_SESSION_DATETIME = "2019-01-13T13:00:00.000Z";
35
+ var testDate = new Date(TEST_SESSION_DATETIME);
36
+ var mockDate = new Date(testDate.setMilliseconds(testDate.getMilliseconds() + import_constants.maxSessionAge));
37
+ var defaultPassword = "mysecretpassword!123";
38
+ var defaultCreationDate = "2019-01-13T06:25:00.000Z";
39
+ var defaultMacAddress = "dc:a6:32:12:ad:bf";
40
+ var testSsoId = "sso_id";
41
+ var permissionSetObjectTypes = {
42
+ any: "Any",
43
+ artifacts: "Artifacts",
44
+ empty: "",
45
+ groups: "Device groups",
46
+ releases: "Releases",
47
+ tenantManagement: "Tenant management",
48
+ userManagement: "User management"
49
+ };
50
+ var commonEndpoints = {
51
+ artifacts: "^/api/management/v1/deployments/artifacts",
52
+ artifactDetails: "^/api/management/v1/deployments/artifacts/[^/]+",
53
+ deviceManagement: "^/api/management/(v[1-9])/(devauth|inventory)/"
54
+ };
55
+ var token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJjZTNkMGY4Yy1hZWRlLTQwMzAtYjM5MS03ZDUwMjBlYjg3M2UiLCJzdWIiOiJhMzBhNzgwYi1iODQzLTUzNDQtODBlMy0wZmQ5NWE0ZjZmYzMiLCJleHAiOjE2MDY4MTUzNjksImlhdCI6MTYwNjIxMDU2OSwibWVuZGVyLnRlbmFudCI6IjVmODVjMTdiY2U2MmI3ZmE3ZjVmNzA0MCIsIm1lbmRlci51c2VyIjp0cnVlLCJpc3MiOiJNZW5kZXIgVXNlcnMiLCJzY3AiOiJtZW5kZXIuKiIsIm1lbmRlci5wbGFuIjoicHJvZmVzc2lvbmFsIiwibmJmIjoxNjA2MjEwNTY5fQ.qVgYdCzLTf8OdK9uUctqqaY_HWkIiwpekuGvuGQAXCEgOv4bRNDlZRN_ZRSbxQoARG3pquhScbQrjBV9tcF4irTUPlTn3yrsXNO17DpcbTVeKRkb88RDtIKiRw3orVZ_GlIb-ckTQ5dS-Nqlyyf3Fmrhca-gwt6m_xv2UrmJK6eYYTMfggdRRWb-4u7mEkBI_pHPMTQrT8kJ2BeX-vHgazH9AoH0k85LHtFZQXD7pXHlDZRnLxJXukncwMGDmF17374gavYAIyDIzcC8sEBMDnVXgpikeA1sauzirqix6mAVs6XmxdQO7aF0wfXO1_PTYUA3Nk1oQfMYNlEI3U9uLRJRZIq2L8fmrrBryhstKd4y0KlBbGAQrx8NtRkgajjd1ljMfPBUEZrb7uSerVjneiO-aIBO76CuH0zdklphIjpGJeogkBhe8pAYNggp1XsZHgpZfl7IE5faKaDkMGnutaea--Czor6bhqUNCuY4tR0cpQJbNwy6LS9o1CFy4Log";
56
+ var accessTokens = [
57
+ { id: "some-id-1", expiration_date: "2022-06-02T11:11:21.725Z", name: "some-name-1" },
58
+ { id: "some-id-2", expiration_date: "2022-06-02T11:11:21.725Z", last_used: "2022-06-02T11:05:21.725Z", name: "some-name-2" }
59
+ ];
60
+ var webhookEvents = [
61
+ {
62
+ id: "1",
63
+ type: "device-status-changed",
64
+ data: { id: "1", status: "accepted" },
65
+ time: "2020-09-01T12:00:00.000Z",
66
+ delivery_statuses: [{ integration_id: "1", success: true, status_code: 200 }]
67
+ },
68
+ {
69
+ id: "2",
70
+ type: "device-status-changed",
71
+ data: { id: "3", status: "accepted" },
72
+ time: "2020-09-01T12:00:05.000Z",
73
+ delivery_statuses: [{ integration_id: "1", success: true, status_code: 200 }]
74
+ }
75
+ ];
76
+ var tenants = [
77
+ {
78
+ id: "671a0f1dd58c813118fe8622",
79
+ parent_tenant_id: "6718de64b42e08dea2a2065d",
80
+ name: "child2",
81
+ tenant_token: "mQDYRCr-tGbDuJhPp7fArbfTA5htVTWE9G204AzhDUM",
82
+ status: "active",
83
+ additional_info: {
84
+ marketing: false,
85
+ campaign: ""
86
+ },
87
+ plan: "enterprise",
88
+ trial: false,
89
+ trial_expiration: null,
90
+ service_provider: false,
91
+ created_at: "2024-10-24T09:10:53.281Z",
92
+ cancelled_at: null,
93
+ children_tenants: null,
94
+ max_child_tenants: 0,
95
+ device_count: 0,
96
+ device_limit: 100,
97
+ device_limits: {
98
+ max_devices: {
99
+ current_value: 0,
100
+ name: "max_devices",
101
+ tenant_id: "699f07a3e783def54cf6201f",
102
+ value: 200
103
+ },
104
+ max_micro_devices: {
105
+ current_value: 0,
106
+ name: "max_micro_devices",
107
+ tenant_id: "699f07a3e783def54cf6201f",
108
+ value: 280
109
+ },
110
+ max_system_devices: {
111
+ current_value: 0,
112
+ name: "max_system_devices",
113
+ tenant_id: "699f07a3e783def54cf6201f",
114
+ value: 20
115
+ }
116
+ },
117
+ binary_delta: true
118
+ }
119
+ ];
120
+ var userId = "a30a780b-b843-5344-80e3-0fd95a4f6fc3";
121
+ var defaultUser = {
122
+ created_ts: "2019-01-01T10:30:00.000Z",
123
+ email: "a@b.com",
124
+ id: "a1",
125
+ roles: ["RBAC_ROLE_PERMIT_ALL"],
126
+ tfa_status: "enabled",
127
+ verified: true
128
+ };
129
+ var deviceTypes = { qemu: "qemux86-64" };
130
+ var checkInTimeRounded = "2019-01-01T00:00:00.000Z";
131
+ var checkInTimeExact = "2019-01-01T10:25:00.000Z";
132
+ var mockApiResponses = {
133
+ deployments: {
134
+ byId: {
135
+ d1: {
136
+ id: "d1",
137
+ name: "test deployment",
138
+ created: "2019-01-01T12:30:00.000Z",
139
+ devices: {
140
+ a1: {
141
+ id: "a1",
142
+ status: "installing",
143
+ attributes: {},
144
+ image: { size: 123 }
145
+ }
146
+ },
147
+ statistics: {
148
+ status: {
149
+ "already-installed": 0,
150
+ decommissioned: 0,
151
+ downloading: 0,
152
+ failure: 0,
153
+ installing: 1,
154
+ noartifact: 0,
155
+ pending: 0,
156
+ rebooting: 0,
157
+ success: 0
158
+ },
159
+ total_size: 1234
160
+ }
161
+ },
162
+ d2: {
163
+ id: "d2",
164
+ name: "test deployment 2",
165
+ artifact_name: "r1",
166
+ artifacts: ["123"],
167
+ created: "2019-01-01T12:25:00.000Z",
168
+ device_count: 1,
169
+ devices: {
170
+ b1: {
171
+ attributes: {},
172
+ id: "b1",
173
+ status: "pending"
174
+ }
175
+ },
176
+ filter: void 0,
177
+ group: void 0,
178
+ statistics: {
179
+ status: {
180
+ downloading: 0,
181
+ decommissioned: 0,
182
+ failure: 0,
183
+ installing: 0,
184
+ noartifact: 0,
185
+ pending: 1,
186
+ rebooting: 0,
187
+ success: 0,
188
+ "already-installed": 0
189
+ }
190
+ }
191
+ },
192
+ d3: {
193
+ id: "d3",
194
+ name: "Test",
195
+ phases: [
196
+ { id: "0", batch_size: 2, device_count: 2 },
197
+ { id: "1", start_ts: "2019-02-04T11:45:10.002Z", batch_size: 3, device_count: 3 },
198
+ { id: "2", start_ts: "2019-02-05T11:45:10.002Z", batch_size: 5, device_count: 5 },
199
+ { id: "3", start_ts: "2019-02-06T11:45:10.002Z", batch_size: 5, device_count: 5 },
200
+ { id: "4", start_ts: "2019-02-21T11:45:10.002Z", batch_size: 5, device_count: 0 }
201
+ ],
202
+ max_devices: 0,
203
+ created: "2019-01-31T12:59:30.020Z",
204
+ devices: {},
205
+ filter: void 0,
206
+ group: void 0,
207
+ stats: {
208
+ pending: 3,
209
+ decommissioned: 0,
210
+ failure: 23,
211
+ pause_before_committing: 0,
212
+ pause_before_rebooting: 0,
213
+ installing: 0,
214
+ rebooting: 0,
215
+ "already-installed": 0,
216
+ pause_before_installing: 0,
217
+ downloading: 0,
218
+ success: 6,
219
+ aborted: 0,
220
+ noartifact: 0
221
+ },
222
+ statistics: { total_size: "1234" },
223
+ status: "inprogress",
224
+ active: true,
225
+ device_count: 100,
226
+ retries: "0",
227
+ type: "software"
228
+ }
229
+ },
230
+ byStatus: {
231
+ pending: { deploymentIds: ["d2"] },
232
+ inprogress: { deploymentIds: ["d3"] }
233
+ }
234
+ },
235
+ devices: {
236
+ byId: {
237
+ a1: {
238
+ id: "a1",
239
+ auth_sets: [
240
+ {
241
+ id: "auth1",
242
+ identity_data: { mac: defaultMacAddress },
243
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
244
+ status: "accepted",
245
+ ts: defaultCreationDate
246
+ }
247
+ ],
248
+ updated_ts: "2019-01-01T09:25:00.000Z"
249
+ },
250
+ b1: {
251
+ id: "b1",
252
+ attributes: {
253
+ ipv4_wlan0: "192.168.10.141/24",
254
+ device_type: [deviceTypes.qemu]
255
+ },
256
+ system: {
257
+ check_in_time: checkInTimeRounded
258
+ },
259
+ check_in_time: checkInTimeExact,
260
+ check_in_time_exact: checkInTimeExact,
261
+ check_in_time_rounded: checkInTimeRounded,
262
+ identity_data: { mac: defaultMacAddress },
263
+ status: "accepted",
264
+ decommissioning: false,
265
+ created_ts: defaultCreationDate,
266
+ updated_ts: "2019-01-01T09:25:00.000Z",
267
+ auth_sets: [
268
+ {
269
+ id: "auth1",
270
+ identity_data: { mac: defaultMacAddress },
271
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
272
+ ts: defaultCreationDate,
273
+ status: "accepted"
274
+ }
275
+ ]
276
+ }
277
+ },
278
+ groups: {
279
+ byId: {
280
+ testGroup: {
281
+ deviceIds: ["a1", "b1"],
282
+ filters: [],
283
+ total: 2
284
+ },
285
+ testGroupDynamic: {
286
+ id: "filter1",
287
+ name: "filter1",
288
+ filters: [{ scope: "system", key: "group", operator: "$eq", value: "things" }]
289
+ }
290
+ }
291
+ },
292
+ limits: { standard: 500, micro: 0, system: 0 },
293
+ byStatus: {
294
+ accepted: { deviceIds: ["a1", "b1"], total: 2 },
295
+ active: { deviceIds: [], total: 0 },
296
+ inactive: { deviceIds: [], total: 0 },
297
+ pending: { deviceIds: ["c1"], total: 1 },
298
+ preauthorized: { deviceIds: [], total: 0 },
299
+ rejected: { deviceIds: [], total: 0 }
300
+ }
301
+ },
302
+ organization: {
303
+ organization: {
304
+ id: "1",
305
+ addons: [],
306
+ name: "test",
307
+ plan: "os",
308
+ trial: false
309
+ },
310
+ products: [
311
+ {
312
+ name: "mender_standard",
313
+ billing_unit: "devices",
314
+ prices: [
315
+ {
316
+ plan: "os",
317
+ constraints: {
318
+ min: 50,
319
+ max: 1e3,
320
+ div: 50
321
+ }
322
+ },
323
+ {
324
+ plan: "professional",
325
+ constraints: {
326
+ min: 250,
327
+ max: 1e4,
328
+ div: 50
329
+ }
330
+ }
331
+ ],
332
+ addons: [
333
+ {
334
+ name: "troubleshoot",
335
+ prices: [{ plan: "os" }, { plan: "professional" }]
336
+ },
337
+ {
338
+ name: "configure",
339
+ prices: [{ plan: "os" }, { plan: "professional" }]
340
+ },
341
+ {
342
+ name: "monitor",
343
+ prices: [{ plan: "professional" }]
344
+ }
345
+ ]
346
+ },
347
+ {
348
+ name: "mender_micro",
349
+ billing_unit: "devices",
350
+ prices: [
351
+ {
352
+ plan: "os",
353
+ constraints: {
354
+ min: 50,
355
+ max: 5e3,
356
+ div: 50
357
+ }
358
+ },
359
+ {
360
+ plan: "professional",
361
+ constraints: {
362
+ min: 500,
363
+ max: 1e5,
364
+ div: 50
365
+ }
366
+ }
367
+ ]
368
+ }
369
+ ],
370
+ intentId: "testIntent",
371
+ auditlog: {
372
+ events: [
373
+ {
374
+ actor: {
375
+ id: "string",
376
+ type: "user",
377
+ email: "string@example.com"
378
+ },
379
+ time: "2019-01-01T12:10:22.667Z",
380
+ action: "create",
381
+ object: {
382
+ id: "string",
383
+ type: "user",
384
+ user: {
385
+ email: "user@acme.com"
386
+ }
387
+ },
388
+ change: "change1"
389
+ },
390
+ {
391
+ actor: {
392
+ id: "string",
393
+ type: "user",
394
+ email: "string",
395
+ identity_data: "string"
396
+ },
397
+ time: "2019-01-01T12:16:22.667Z",
398
+ action: "create",
399
+ object: {
400
+ id: "string",
401
+ type: "deployment",
402
+ deployment: {
403
+ name: "production",
404
+ artifact_name: "Application 0.0.1"
405
+ }
406
+ },
407
+ change: "change2"
408
+ },
409
+ {
410
+ actor: {
411
+ id: "string",
412
+ type: "user",
413
+ email: "string@example.com"
414
+ },
415
+ time: "2019-01-01T12:10:22.669Z",
416
+ action: "open_terminal",
417
+ meta: {
418
+ session_id: ["abd313a8-ee88-48ab-9c99-fbcd80048e6e"]
419
+ },
420
+ object: {
421
+ id: "a1",
422
+ type: "device"
423
+ },
424
+ change: "change3"
425
+ }
426
+ ]
427
+ }
428
+ },
429
+ releases: {
430
+ byId: {
431
+ r1: {
432
+ name: "r1",
433
+ artifacts: [
434
+ {
435
+ id: "art1",
436
+ description: "test description",
437
+ device_types_compatible: [deviceTypes.qemu],
438
+ modified: "2020-09-10T12:16:22.667Z",
439
+ updates: [{ type_info: { type: "testtype" } }],
440
+ artifact_depends: {
441
+ device_type: [deviceTypes.qemu]
442
+ },
443
+ artifact_provides: {
444
+ artifact_name: "myapp",
445
+ "data-partition.myapp.version": "v2020.10",
446
+ list_of_fancy: [deviceTypes.qemu, "x172"]
447
+ },
448
+ clears_artifact_provides: ["data-partition.myapp.*"]
449
+ }
450
+ ],
451
+ device_types_compatible: [deviceTypes.qemu],
452
+ modified: "2020-09-10T12:16:22.667Z",
453
+ metaData: {}
454
+ }
455
+ }
456
+ },
457
+ users: {
458
+ byId: {
459
+ a1: defaultUser,
460
+ [userId]: { ...defaultUser, id: userId, email: "a2@b.com", created_ts: "2019-01-01T12:30:00.000Z" }
461
+ },
462
+ rolesById: {
463
+ admin: {
464
+ name: "admin",
465
+ description: "Administrator role",
466
+ permissions: []
467
+ },
468
+ test: { name: "test", description: "test description", permissions: [] }
469
+ },
470
+ globalSettings: {
471
+ "2fa": "enabled",
472
+ id_attribute: void 0,
473
+ previousFilters: []
474
+ },
475
+ userSettings: {
476
+ "2fa": "disabled",
477
+ columnSelection: [],
478
+ onboarding: { something: "here" },
479
+ tooltips: {},
480
+ previousFilters: []
481
+ }
482
+ }
483
+ };
484
+ var releasesList = Array.from({ length: 5e3 }, (x, i) => ({
485
+ artifacts: [
486
+ {
487
+ id: "art1",
488
+ description: "test description",
489
+ device_types_compatible: [deviceTypes.qemu],
490
+ modified: "2020-09-10T12:16:22.667Z",
491
+ updates: [{ type_info: { type: "testtype" } }],
492
+ artifact_depends: {
493
+ device_type: [deviceTypes.qemu]
494
+ },
495
+ artifact_provides: {
496
+ artifact_name: "myapp",
497
+ "data-partition.myapp.version": "v2020.10",
498
+ list_of_fancy: [deviceTypes.qemu, "x172"]
499
+ },
500
+ clears_artifact_provides: ["data-partition.myapp.*"]
501
+ }
502
+ ],
503
+ device_types_compatible: [deviceTypes.qemu],
504
+ metaData: {},
505
+ name: `release-${i + 1}`,
506
+ modified: i
507
+ }));
508
+ var permissionSets = [
509
+ {
510
+ ...import_constants.defaultPermissionSets.Basic,
511
+ object: permissionSetObjectTypes.empty,
512
+ description: "Set containing basic permissions.",
513
+ permissions: [
514
+ { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/settings$" } },
515
+ { action: "http", object: { type: "any", value: "^/api/management/v1/useradm/users/me$" } },
516
+ { action: "http", object: { type: "any", value: "^/api/management/1.0/auth/verify$" } },
517
+ { action: "http", object: { type: "PUT", value: "^/api/management/v1/useradm/2faverify$" } },
518
+ { action: "http", object: { type: "POST", value: "^/api/management/v1/useradm/users/me/2fa/(enable|disable)$" } },
519
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/roles" } },
520
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/user/tenant" } }
521
+ ]
522
+ },
523
+ {
524
+ ...import_constants.defaultPermissionSets.ManageReleases,
525
+ action: import_constants.uiPermissionsById.manage.title,
526
+ object: permissionSetObjectTypes.releases,
527
+ description: "Set of permissions which allows user to manage releases",
528
+ permissions: [
529
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
530
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
531
+ { action: "http", object: { type: "PUT", value: commonEndpoints.artifactDetails } },
532
+ { action: "http", object: { type: "DELETE", value: commonEndpoints.artifactDetails } },
533
+ { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
534
+ ]
535
+ },
536
+ {
537
+ ...import_constants.defaultPermissionSets.ReadUsers,
538
+ action: import_constants.uiPermissionsById.read.title,
539
+ object: permissionSetObjectTypes.userManagement,
540
+ description: "Set of permissions which allows user to view other users",
541
+ permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/useradm/" } }]
542
+ },
543
+ {
544
+ ...import_constants.defaultPermissionSets.ManageUsers,
545
+ action: import_constants.uiPermissionsById.manage.title,
546
+ object: permissionSetObjectTypes.userManagement,
547
+ description: "Set of permissions which allows user manage other user accounts",
548
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/" } }]
549
+ },
550
+ {
551
+ ...import_constants.defaultPermissionSets.ReadTenants,
552
+ action: import_constants.uiPermissionsById.read.title,
553
+ object: permissionSetObjectTypes.tenantManagement,
554
+ description: "Set of permissions which allows user to list other tenants and their config",
555
+ permissions: [
556
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
557
+ { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } }
558
+ ]
559
+ },
560
+ {
561
+ ...import_constants.defaultPermissionSets.ManageTenants,
562
+ action: import_constants.uiPermissionsById.manage.title,
563
+ object: permissionSetObjectTypes.tenantManagement,
564
+ description: "Set of permissions which allows user to manage other tenants and their config",
565
+ permissions: [
566
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/tenantadm/" } },
567
+ { action: "http", object: { type: "POST", value: "^/api/management/(v[1-9])/tenantadm/" } },
568
+ { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9])/tenantadm/" } }
569
+ ]
570
+ },
571
+ {
572
+ ...import_constants.defaultPermissionSets.ReadAuditLogs,
573
+ action: import_constants.uiPermissionsById.read.title,
574
+ object: "System Audit Log",
575
+ description: "Set of permissions which allows user to view system audit log",
576
+ permissions: [{ action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/auditlogs/logs" } }]
577
+ },
578
+ {
579
+ ...import_constants.defaultPermissionSets.DeployToDevices,
580
+ action: "Deploy",
581
+ object: permissionSetObjectTypes.groups,
582
+ description: "Set of permissions which allows user to deploy to devices",
583
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/(deployments|deviceconfig)/" } }],
584
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
585
+ },
586
+ {
587
+ ...import_constants.defaultPermissionSets.ConfigureDevices,
588
+ action: "Configure",
589
+ object: permissionSetObjectTypes.groups,
590
+ description: "Set of permissions which allows user to manage configuration of the devices",
591
+ permissions: [{ action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/" } }],
592
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
593
+ },
594
+ {
595
+ ...import_constants.defaultPermissionSets.ConnectToDevices,
596
+ action: "Connect",
597
+ object: permissionSetObjectTypes.groups,
598
+ description: "Set of permissions which allows user to use remote terminal and file transfer",
599
+ permissions: [
600
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/connect$" } },
601
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/download\\?path=[^&]+$" } },
602
+ { action: "http", object: { type: "PUT", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+/upload$" } }
603
+ ],
604
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
605
+ },
606
+ {
607
+ ...import_constants.defaultPermissionSets.SuperUser,
608
+ action: "Any",
609
+ object: permissionSetObjectTypes.any,
610
+ description: "Set of permissions which allows user to do anything",
611
+ permissions: [{ action: "any", object: { type: "any", value: "any" } }]
612
+ },
613
+ {
614
+ ...import_constants.defaultPermissionSets.UploadArtifacts,
615
+ action: "Upload",
616
+ object: permissionSetObjectTypes.artifacts,
617
+ description: "Set of permissions which allows user to upload artifacts",
618
+ permissions: [
619
+ { action: "http", object: { type: "POST", value: commonEndpoints.artifacts } },
620
+ { action: "http", object: { type: "POST", value: "^/api/management/v1/deployments/artifacts/generate" } }
621
+ ]
622
+ },
623
+ {
624
+ ...import_constants.defaultPermissionSets.ReadDevices,
625
+ action: import_constants.uiPermissionsById.read.title,
626
+ object: permissionSetObjectTypes.groups,
627
+ description: "Set of permissions which allows user to view devices",
628
+ permissions: [
629
+ { action: "http", object: { type: "POST", value: "^/api/management/v2/inventory/filters/search" } },
630
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9])/(deployments|devauth|inventory|deviceconfig|devicemonitor)/" } },
631
+ { action: "http", object: { type: "GET", value: "^/api/management/(v[1-9]|0.1.0)/deviceconnect/devices/[^/]+$" } }
632
+ ],
633
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
634
+ },
635
+ {
636
+ ...import_constants.defaultPermissionSets.ManageDevices,
637
+ action: import_constants.uiPermissionsById.manage.title,
638
+ object: permissionSetObjectTypes.groups,
639
+ description: "Set of permissions which allows user to manage devices",
640
+ permissions: [
641
+ { action: "http", object: { type: "POST", value: commonEndpoints.deviceManagement } },
642
+ { action: "http", object: { type: "PUT", value: commonEndpoints.deviceManagement } },
643
+ { action: "http", object: { type: "DELETE", value: commonEndpoints.deviceManagement } }
644
+ ],
645
+ supported_scope_types: [import_constants.scopedPermissionAreas.groups.scopeType]
646
+ },
647
+ {
648
+ ...import_constants.defaultPermissionSets.ReadReleases,
649
+ action: import_constants.uiPermissionsById.read.title,
650
+ object: permissionSetObjectTypes.releases,
651
+ description: "Set of permissions which allows user to view releases",
652
+ permissions: [
653
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifacts } },
654
+ { action: "http", object: { type: "GET", value: commonEndpoints.artifactDetails } },
655
+ { action: "http", object: { type: "GET", value: "^/api/management/v1/deployments/artifacts/[^/]+/download" } }
656
+ ]
657
+ },
658
+ {
659
+ name: "almostAdmin",
660
+ object: permissionSetObjectTypes.empty,
661
+ description: "Set containing all the permissions.",
662
+ permissions: [
663
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/auditlogs/.*" } },
664
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/.*" } },
665
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/config/.*" } },
666
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/.*" } },
667
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deployments/deployments/releases/.*" } },
668
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/devauth/.*" } },
669
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconfig/.*" } },
670
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/.*" } },
671
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/deviceconnect/devices" } },
672
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/inventory/.*" } },
673
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/iot-manager/.*" } },
674
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/monitor/.*" } },
675
+ { action: "http", object: { type: "any", value: "^/api/management/(v[1-9])/useradm/.*" } }
676
+ ]
677
+ }
678
+ ];
679
+ var rbacRoles = [
680
+ {
681
+ name: "dyn",
682
+ description: "",
683
+ permissions: [
684
+ { action: "CREATE_DEPLOYMENT", object: { type: "DEVICE_GROUP", value: "dyn" } },
685
+ { action: "VIEW_DEVICE", object: { type: "DEVICE_GROUP", value: "dyn" } }
686
+ ]
687
+ },
688
+ { name: "asdasd", description: "123", permissions: [{ action: "http", object: { type: "any", value: "/api/management/v1/useradm/.*" } }] },
689
+ {
690
+ name: "141sasd",
691
+ description: "1313adg",
692
+ permission_sets_with_scope: [
693
+ { ...import_constants.defaultPermissionSets.ReadDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
694
+ { ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } },
695
+ { ...import_constants.defaultPermissionSets.ManageUsers }
696
+ ]
697
+ },
698
+ {
699
+ name: "kljlkk",
700
+ description: "lkl",
701
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["bestgroup"] } }]
702
+ },
703
+ {
704
+ name: "yyyyy",
705
+ description: "asd",
706
+ permission_sets_with_scope: [
707
+ { ...import_constants.defaultPermissionSets.ManageDevices, scope: { type: import_constants.scopedPermissionAreas.groups.scopeType, value: ["dockerclient"] } },
708
+ { ...import_constants.defaultPermissionSets.ManageReleases }
709
+ ]
710
+ },
711
+ {
712
+ name: "RBAC_ROLE_DEPLOYMENTS_MANAGER",
713
+ description: "Intended for users responsible for managing deployments, this role can create and abort deployments",
714
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.DeployToDevices }]
715
+ },
716
+ {
717
+ name: "RBAC_ROLE_REMOTE_TERMINAL",
718
+ description: `Intended for tech support accounts, this role can access the devices' Remote Terminal.`,
719
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ConnectToDevices }]
720
+ },
721
+ { name: "RBAC_ROLE_PERMIT_ALL", description: "", permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.SuperUser }] },
722
+ {
723
+ name: "RBAC_ROLE_OBSERVER",
724
+ 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.",
725
+ permission_sets_with_scope: [{ ...import_constants.defaultPermissionSets.ReadReleases }, { ...import_constants.defaultPermissionSets.ReadDevices }]
726
+ },
727
+ {
728
+ name: "RBAC_ROLE_CI",
729
+ 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.",
730
+ permission_sets_with_scope: [
731
+ { ...import_constants.defaultPermissionSets.ReadReleases },
732
+ { ...import_constants.defaultPermissionSets.ManageReleases },
733
+ { ...import_constants.defaultPermissionSets.UploadArtifacts }
734
+ ]
735
+ },
736
+ {
737
+ name: "almostAdmin",
738
+ description: "almost admin rights",
739
+ permissions: permissionSets.find((item) => item.name === "almostAdmin")?.permissions
740
+ },
741
+ {
742
+ name: "almostAdminNew",
743
+ description: "almost admin rights",
744
+ permission_sets_with_scope: Object.values(import_constants.defaultPermissionSets)
745
+ }
746
+ ];
747
+ var expectedParsedRoles = {
748
+ "141sasd": {
749
+ editable: true,
750
+ isCustom: void 0,
751
+ uiPermissions: {
752
+ ...import_constants.emptyUiPermissions,
753
+ groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] },
754
+ userManagement: [import_constants.uiPermissionsById.manage.value]
755
+ }
756
+ },
757
+ asdasd: {
758
+ editable: false,
759
+ isCustom: true,
760
+ uiPermissions: { ...import_constants.emptyUiPermissions, userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] }
761
+ },
762
+ dyn: {
763
+ editable: false,
764
+ isCustom: true,
765
+ uiPermissions: {
766
+ ...import_constants.emptyUiPermissions,
767
+ deployments: [import_constants.uiPermissionsById.deploy.value],
768
+ groups: { dyn: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value] }
769
+ }
770
+ },
771
+ kljlkk: {
772
+ editable: true,
773
+ isCustom: false,
774
+ uiPermissions: { ...import_constants.emptyUiPermissions, groups: { bestgroup: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.connect.value] } }
775
+ },
776
+ yyyyy: {
777
+ editable: true,
778
+ isCustom: void 0,
779
+ uiPermissions: {
780
+ ...import_constants.emptyUiPermissions,
781
+ groups: { dockerclient: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value] },
782
+ releases: { [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value] }
783
+ }
784
+ },
785
+ almostAdmin: {
786
+ editable: false,
787
+ isCustom: true,
788
+ uiPermissions: {
789
+ ...import_constants.emptyUiPermissions,
790
+ auditlog: [import_constants.uiPermissionsById.read.value],
791
+ deployments: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.read.value],
792
+ groups: {
793
+ [import_constants.ALL_DEVICES]: [
794
+ import_constants.uiPermissionsById.read.value,
795
+ // we can't assign deployment permissions to devices here, since the old path based rbac controls don't allow the scoped permissions
796
+ // uiPermissionsById.deploy.value,
797
+ import_constants.uiPermissionsById.manage.value,
798
+ import_constants.uiPermissionsById.connect.value,
799
+ import_constants.uiPermissionsById.configure.value
800
+ ]
801
+ },
802
+ releases: {
803
+ [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.manage.value]
804
+ },
805
+ userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
806
+ }
807
+ },
808
+ almostAdminNew: {
809
+ editable: true,
810
+ isCustom: void 0,
811
+ uiPermissions: {
812
+ ...import_constants.emptyUiPermissions,
813
+ auditlog: [import_constants.uiPermissionsById.read.value],
814
+ deployments: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.deploy.value, import_constants.uiPermissionsById.manage.value],
815
+ groups: {
816
+ [import_constants.ALL_DEVICES]: [
817
+ import_constants.uiPermissionsById.read.value,
818
+ import_constants.uiPermissionsById.manage.value,
819
+ import_constants.uiPermissionsById.deploy.value,
820
+ import_constants.uiPermissionsById.connect.value,
821
+ import_constants.uiPermissionsById.configure.value
822
+ ]
823
+ },
824
+ releases: {
825
+ [import_constants.ALL_RELEASES]: [import_constants.uiPermissionsById.manage.value, import_constants.uiPermissionsById.upload.value, import_constants.uiPermissionsById.read.value]
826
+ },
827
+ tenantManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value],
828
+ userManagement: [import_constants.uiPermissionsById.read.value, import_constants.uiPermissionsById.manage.value]
829
+ }
830
+ }
831
+ };
832
+ var defaultRolesById = {
833
+ ...import_constants.rolesById,
834
+ test: {
835
+ ...import_constants.emptyRole,
836
+ name: "test",
837
+ description: "test description",
838
+ editable: true,
839
+ uiPermissions: {
840
+ ...import_constants.emptyUiPermissions,
841
+ groups: { testGroup: [import_constants.uiPermissionsById.read.value] },
842
+ releases: { bar: [import_constants.uiPermissionsById.read.value] }
843
+ }
844
+ }
845
+ };
846
+ var receivedRoles = rbacRoles.reduce(
847
+ (accu, role) => {
848
+ const { name, description, ...roleRemainder } = role;
849
+ if (name.startsWith("RBAC")) {
850
+ accu[name] = {
851
+ ...defaultRolesById[name],
852
+ ...roleRemainder,
853
+ editable: false,
854
+ isCustom: false,
855
+ description: defaultRolesById[name].description ? defaultRolesById[name].description : description
856
+ };
857
+ } else {
858
+ const result = expectedParsedRoles[name] ?? {};
859
+ accu[name] = {
860
+ ...import_constants.emptyRole,
861
+ ...role,
862
+ ...result,
863
+ name
864
+ };
865
+ }
866
+ return accu;
867
+ },
868
+ { ...defaultRolesById }
869
+ );
870
+ var receivedPermissionSets = permissionSets.reduce((accu, set) => {
871
+ const result = import_constants.defaultPermissionSets[set.name]?.result ?? {};
872
+ accu[set.name] = {
873
+ ...set,
874
+ result: {
875
+ ...import_constants.emptyUiPermissions,
876
+ ...result
877
+ }
878
+ };
879
+ return accu;
880
+ }, {});
881
+
882
+ // src/requestHandlers/deploymentHandlers.ts
883
+ var createdDeployment = {
884
+ id: "created-123",
885
+ name: "test deployment",
886
+ artifact_name: "r1",
887
+ artifacts: ["123"],
888
+ created: "2019-01-01T12:30:00.000Z",
889
+ device_count: 1,
890
+ devices: {
891
+ a1: {
892
+ attributes: {},
893
+ id: "a1",
894
+ image: { size: 123 },
895
+ status: "installing"
896
+ }
897
+ },
898
+ filter: void 0,
899
+ group: void 0,
900
+ statistics: {
901
+ status: {
902
+ downloading: 0,
903
+ decommissioned: 0,
904
+ failure: 0,
905
+ installing: 1,
906
+ noartifact: 0,
907
+ pending: 0,
908
+ rebooting: 0,
909
+ success: 0,
910
+ "already-installed": 0
911
+ },
912
+ total_size: 1234
913
+ }
914
+ };
915
+ var defaultDeploymentConfig = {
916
+ delta: {
917
+ enabled: true,
918
+ binary_delta: {
919
+ xdelta_args: {
920
+ disable_checksum: false,
921
+ disable_external_decompression: false,
922
+ compression_level: 6,
923
+ source_window_size: 0,
924
+ input_window_size: 0,
925
+ compression_duplicates_window: 0,
926
+ instruction_buffer_size: 0
927
+ },
928
+ timeout: 0
929
+ },
930
+ binary_delta_limits: {
931
+ xdelta_args_limits: {
932
+ source_window_size: import_constants2.limitDefault,
933
+ input_window_size: import_constants2.limitDefault,
934
+ compression_duplicates_window: import_constants2.limitDefault,
935
+ instruction_buffer_size: import_constants2.limitDefault
936
+ },
937
+ timeout: { min: 60, max: 3600, default: 60 },
938
+ jobs_in_parallel: import_constants2.limitDefault,
939
+ queue_length: import_constants2.limitDefault
940
+ }
941
+ }
942
+ };
943
+ var deploymentHandlers = [
944
+ import_msw.http.get(
945
+ `${import_constants2.deploymentsApiUrlV2}/deployments`,
946
+ () => new import_msw.HttpResponse(JSON.stringify(Object.values(mockApiResponses.deployments.byId).reverse()), {
947
+ headers: { [import_constants2.headerNames.total]: Object.keys(mockApiResponses.deployments.byId).length }
948
+ })
949
+ ),
950
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/releases`, ({ request }) => {
951
+ const { searchParams } = new URL(request.url);
952
+ const releaseName = searchParams.get("name");
953
+ const release = mockApiResponses.releases.byId[releaseName] || {};
954
+ if (releaseName) {
955
+ const { device_types_compatible, ...remainder } = release;
956
+ return Object.keys(remainder).length || releaseName === "createdRelease" ? import_msw.HttpResponse.json([remainder]) : new import_msw.HttpResponse(null, { status: 520 });
957
+ }
958
+ const releases = Object.values(mockApiResponses.releases.byId).map((stateRelease) => {
959
+ const { device_types_compatible, ...remainder } = stateRelease;
960
+ return remainder;
961
+ });
962
+ return import_msw.HttpResponse.json(releases);
963
+ }),
964
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId`, ({ params: { deploymentId } }) => {
965
+ if (deploymentId === createdDeployment.id) {
966
+ return import_msw.HttpResponse.json(createdDeployment);
967
+ } else if (deploymentId === "config1") {
968
+ return import_msw.HttpResponse.json({
969
+ ...createdDeployment,
970
+ id: "config1",
971
+ created: "2019-01-01T09:25:01.000Z",
972
+ finished: "2019-01-01T09:25:03.000Z",
973
+ status: "finished"
974
+ });
975
+ }
976
+ return import_msw.HttpResponse.json(mockApiResponses.deployments.byId[deploymentId]);
977
+ }),
978
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId/devices`, ({ params: { deploymentId } }) => {
979
+ if (deploymentId === createdDeployment.id) {
980
+ return import_msw.HttpResponse.json(Object.values(createdDeployment.devices));
981
+ } else if (mockApiResponses.deployments.byId[deploymentId]) {
982
+ return import_msw.HttpResponse.json(Object.values(mockApiResponses.deployments.byId[deploymentId].devices));
983
+ }
984
+ return new import_msw.HttpResponse(null, { status: 521 });
985
+ }),
986
+ import_msw.http.post(`${import_constants2.deploymentsApiUrl}/deployments/statistics/list`, async ({ request }) => {
987
+ const { deployment_ids = [] } = await request.json();
988
+ if (deployment_ids.includes(createdDeployment.id)) {
989
+ return import_msw.HttpResponse.json([]);
990
+ } else if (deployment_ids.every((id) => mockApiResponses.deployments.byId[id])) {
991
+ const stats = deployment_ids.map((id) => ({ id, stats: mockApiResponses.deployments.byId[id].statistics.status }));
992
+ return import_msw.HttpResponse.json(stats);
993
+ }
994
+ return new import_msw.HttpResponse(null, { status: 522 });
995
+ }),
996
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId/devices/:deviceId/log`, ({ params: { deploymentId, deviceId } }) => {
997
+ if (mockApiResponses.deployments.byId[deploymentId] && mockApiResponses.deployments.byId[deploymentId].devices[deviceId]) {
998
+ return import_msw.HttpResponse.text("test");
999
+ }
1000
+ return new import_msw.HttpResponse(null, { status: 523 });
1001
+ }),
1002
+ import_msw.http.post(`${import_constants2.deploymentsApiUrl}/deployments`, async ({ request }) => {
1003
+ const body = await request.json();
1004
+ if (!Object.keys(body).length) {
1005
+ return new import_msw.HttpResponse(JSON.stringify({}), { status: 524 });
1006
+ }
1007
+ return new import_msw.HttpResponse(JSON.stringify({}), { headers: { location: `find/me/here/${createdDeployment.id}` } });
1008
+ }),
1009
+ import_msw.http.post(`${import_constants2.deploymentsApiUrlV2}/deployments`, async ({ request }) => {
1010
+ const { filter_id, devices = [] } = await request.json();
1011
+ if (!filter_id || !!devices.length) {
1012
+ return new import_msw.HttpResponse(JSON.stringify({}), { status: 525 });
1013
+ }
1014
+ return new import_msw.HttpResponse(JSON.stringify({}), { headers: { location: `find/me/here/${createdDeployment.id}` } });
1015
+ }),
1016
+ import_msw.http.post(`${import_constants2.deploymentsApiUrl}/deployments/group/:deploymentGroup`, async ({ params: { deploymentGroup }, request }) => {
1017
+ const { filter_id, devices = [] } = await request.json();
1018
+ if (filter_id || !!devices.length || deploymentGroup !== Object.keys(mockApiResponses.devices.groups.byId)[0]) {
1019
+ return new import_msw.HttpResponse(JSON.stringify({}), { status: 526 });
1020
+ }
1021
+ return new import_msw.HttpResponse(JSON.stringify({}), { headers: { location: `find/me/here/${createdDeployment.id}` } });
1022
+ }),
1023
+ import_msw.http.patch(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId`, async ({ params: { deploymentId }, request }) => {
1024
+ const { update_control_map } = await request.json();
1025
+ if (deploymentId === createdDeployment.id && Object.keys(update_control_map).length) {
1026
+ return new import_msw.HttpResponse(null, { status: 204 });
1027
+ }
1028
+ return new import_msw.HttpResponse(null, { status: 581 });
1029
+ }),
1030
+ import_msw.http.put(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId/status`, async ({ params: { deploymentId }, request }) => {
1031
+ const { status } = await request.json();
1032
+ return new import_msw.HttpResponse(JSON.stringify({}), {
1033
+ status: status === "aborted" && [...mockApiResponses.deployments.byStatus.pending.deploymentIds, ...mockApiResponses.deployments.byStatus.inprogress.deploymentIds].includes(
1034
+ deploymentId
1035
+ ) ? 200 : 528
1036
+ });
1037
+ }),
1038
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/:deploymentId/devices/list`, ({ params: { deploymentId } }) => {
1039
+ if (deploymentId === createdDeployment.id) {
1040
+ return new import_msw.HttpResponse(JSON.stringify(Object.values(createdDeployment.devices)), {
1041
+ headers: { [import_constants2.headerNames.total]: Object.keys(createdDeployment.devices).length }
1042
+ });
1043
+ } else if (mockApiResponses.deployments.byId[deploymentId]) {
1044
+ return new import_msw.HttpResponse(JSON.stringify(Object.values(mockApiResponses.deployments.byId[deploymentId].devices)), {
1045
+ headers: { [import_constants2.headerNames.total]: Object.keys(mockApiResponses.deployments.byId[deploymentId].devices).length }
1046
+ });
1047
+ }
1048
+ return new import_msw.HttpResponse(null, { status: 529 });
1049
+ }),
1050
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/config`, () => import_msw.HttpResponse.json(defaultDeploymentConfig)),
1051
+ import_msw.http.put(`${import_constants2.deploymentsApiUrl}/config/binary_delta`, async ({ request }) => {
1052
+ const { xdelta_args = {} } = await request.json();
1053
+ if (xdelta_args.source_window_size === 55) {
1054
+ return new import_msw.HttpResponse(null, { status: 530 });
1055
+ }
1056
+ return new import_msw.HttpResponse(null, { status: 200 });
1057
+ }),
1058
+ import_msw.http.get(`${import_constants2.deploymentsApiUrl}/deployments/devices/:deviceId`, ({ params: { deviceId } }) => {
1059
+ if (deviceId === mockApiResponses.devices.byId.a1.id) {
1060
+ return new import_msw.HttpResponse(
1061
+ JSON.stringify([
1062
+ {
1063
+ id: createdDeployment.id + "something",
1064
+ deployment: { ...createdDeployment, id: mockApiResponses.deployments.byId.d1.id, status: "inprogress" },
1065
+ device: {
1066
+ created: "2019-01-01T12:35:00.000Z",
1067
+ finished: "2019-01-01T12:40:00.000Z",
1068
+ status: "noartifact",
1069
+ id: "something",
1070
+ image: { ...mockApiResponses.releases.byId.r1 }
1071
+ },
1072
+ log: true,
1073
+ attempts: 1,
1074
+ delta_job_id: ""
1075
+ }
1076
+ ]),
1077
+ {
1078
+ headers: { [import_constants2.headerNames.total]: 34 }
1079
+ }
1080
+ );
1081
+ }
1082
+ return new import_msw.HttpResponse(null, { status: 529 });
1083
+ }),
1084
+ import_msw.http.delete(`${import_constants2.deploymentsApiUrl}/deployments/devices/:deviceId/history`, () => new import_msw.HttpResponse(null, { status: 204 })),
1085
+ import_msw.http.get(`/api/management/v1alpha1/deployments/deployments/:deploymentId/devices/:deviceId/log/explain`, ({ params: { deploymentId, deviceId } }) => {
1086
+ if (deploymentId === mockApiResponses.deployments.byId.d1.id && deviceId === mockApiResponses.devices.byId.a1.id) {
1087
+ const mockAnalysis = `## Summary
1088
+ The deployment failed during the artifact download phase. The device was unable to establish a secure connection to the artifact repository.
1089
+
1090
+ ## Key Issues
1091
+ 1. **Network connectivity issues** - Connection timeout occurred
1092
+ 2. **SSL/TLS certificate verification failed** - Invalid certificate chain
1093
+ 3. **Artifact verification failed** - Checksum mismatch detected
1094
+
1095
+ ## Recommendations
1096
+ - Check network connectivity between device and artifact repository
1097
+ - Verify SSL certificates are properly configured
1098
+ - Ensure artifact integrity before deployment`;
1099
+ return import_msw.HttpResponse.text(mockAnalysis);
1100
+ }
1101
+ if (deploymentId === "rate-limited-deployment") {
1102
+ return new import_msw.HttpResponse(JSON.stringify({ error: "Rate limit exceeded" }), { status: 429 });
1103
+ }
1104
+ if (deploymentId === "error-deployment") {
1105
+ return new import_msw.HttpResponse(JSON.stringify({ error: "Analysis failed" }), { status: 500 });
1106
+ }
1107
+ return new import_msw.HttpResponse(null, { status: 404 });
1108
+ })
1109
+ ];
1110
+
1111
+ // src/requestHandlers/deviceHandlers.ts
1112
+ var import_constants3 = require("@northern.tech/utils/constants");
1113
+ var import_msw2 = require("msw");
1114
+ var defaultDeviceId = "a1";
1115
+ var deviceAuthDevice = {
1116
+ id: defaultDeviceId,
1117
+ identity_data: { mac: defaultMacAddress },
1118
+ status: "accepted",
1119
+ decommissioning: false,
1120
+ created_ts: defaultCreationDate,
1121
+ updated_ts: "2019-01-01T09:25:00.000Z",
1122
+ auth_sets: [
1123
+ {
1124
+ id: "auth1",
1125
+ identity_data: { mac: defaultMacAddress },
1126
+ pubkey: "-----BEGIN PUBLIC KEY-----\nMIIBojWELzgJ62hcXIhAfqfoNiaB1326XZByZwcnHr5BuSPAgMBAAE=\n-----END PUBLIC KEY-----\n",
1127
+ ts: defaultCreationDate,
1128
+ status: "accepted"
1129
+ }
1130
+ ]
1131
+ };
1132
+ var checkInTimeExact2 = "2019-01-01T10:25:00.000Z";
1133
+ var updatedTime = "2019-01-01T09:25:00.000Z";
1134
+ var inventoryDevice = {
1135
+ id: defaultDeviceId,
1136
+ attributes: [
1137
+ { name: "network_interfaces", value: ["eth0", "wlan0"], scope: "inventory" },
1138
+ { name: "kernel", value: "Linux version 4.19.75-v7l+", scope: "inventory" },
1139
+ { name: "artifact_name", value: "raspotifyInstaller", scope: "inventory" },
1140
+ { name: "ipv6_wlan0", value: "fe80::68d9:8453:3e9c:7c80/64", scope: "inventory" },
1141
+ { name: "mac_eth0", value: defaultMacAddress, scope: "inventory" },
1142
+ { name: "rootfs_type", value: "ext4", scope: "inventory" },
1143
+ { name: "mender_bootloader_integration", value: "unknown", scope: "inventory" },
1144
+ { name: "cpu_model", value: "ARMv7 Processor rev 3 (v7l)", scope: "inventory" },
1145
+ { name: "hostname", value: "raspberrypi", scope: "inventory" },
1146
+ { name: "mender_client_version", value: "2.1.0", scope: "inventory" },
1147
+ { name: "ipv4_wlan0", value: "192.168.10.141/24", scope: "inventory" },
1148
+ { name: "device_type", value: "raspberrypi4", scope: "inventory" },
1149
+ { name: "mem_total_kB", value: "1986024", scope: "inventory" },
1150
+ { name: "mac_wlan0", value: "dc:a6:32:12:ad:c0", scope: "inventory" },
1151
+ { name: "os", value: "Raspbian GNU/Linux 10 (buster)", scope: "inventory" },
1152
+ { name: "created_ts", value: defaultCreationDate, scope: "system" },
1153
+ { name: "updated_ts", value: updatedTime, scope: "system" },
1154
+ { name: "status", value: "accepted", scope: "identity" },
1155
+ { name: "mac", value: defaultMacAddress, scope: "identity" },
1156
+ { name: "group", value: "test", scope: "system" }
1157
+ ],
1158
+ check_in_time: checkInTimeExact2,
1159
+ updated_ts: updatedTime
1160
+ };
1161
+ var deviceAttributes = [
1162
+ { name: "status", scope: "identity", count: 5 },
1163
+ { name: "created_ts", scope: "system", count: 5 },
1164
+ { name: "updated_ts", scope: "system", count: 5 },
1165
+ { name: "mac", scope: "identity", count: 1 },
1166
+ { name: "artifact_name", scope: "inventory", count: 1 },
1167
+ { name: "cpu_model", scope: "inventory", count: 1 },
1168
+ { name: "device_type", scope: "inventory", count: 1 },
1169
+ { name: "hostname", scope: "inventory", count: 1 },
1170
+ { name: "ipv4_wlan0", scope: "inventory", count: 1 },
1171
+ { name: "ipv6_wlan0", scope: "inventory", count: 1 },
1172
+ { name: "kernel", scope: "inventory", count: 1 },
1173
+ { name: "mac_eth0", scope: "inventory", count: 1 },
1174
+ { name: "mac_wlan0", scope: "inventory", count: 1 },
1175
+ { name: "mem_total_kB", scope: "inventory", count: 1 },
1176
+ { name: "mender_bootloader_integration", scope: "inventory", count: 1 },
1177
+ { name: "mender_client_version", scope: "inventory", count: 1 },
1178
+ { name: "network_interfaces", scope: "inventory", count: 1 },
1179
+ { name: "os", scope: "inventory", count: 1 },
1180
+ { name: "rootfs_type", scope: "inventory", count: 1 },
1181
+ { name: "group", scope: "system", count: 1 }
1182
+ ];
1183
+ var searchHandler = async ({ request }) => {
1184
+ const { page, per_page, filters } = await request.json();
1185
+ if ([page, per_page, filters].some((item) => !item)) {
1186
+ return new import_msw2.HttpResponse(null, { status: 509 });
1187
+ }
1188
+ const filter = filters.find((filter2) => filter2.scope === "identity" && filter2.attribute === "status" && Object.values(import_constants3.DEVICE_STATES).includes(filter2.value));
1189
+ const status = filter?.value || "";
1190
+ if (!status || filters.length > 1) {
1191
+ if (filters.find((filter2) => filter2.attribute === "group" && filter2.value.includes(Object.keys(mockApiResponses.devices.groups.byId)[0]))) {
1192
+ return new import_msw2.HttpResponse(JSON.stringify([inventoryDevice, { ...inventoryDevice, id: "b1" }]), {
1193
+ headers: { [import_constants3.headerNames.total]: 2 }
1194
+ });
1195
+ }
1196
+ if (filters.find((filter2) => filter2.scope === "monitor" && ["failed_last_update", "alerts", "auth_request"].includes(filter2.attribute))) {
1197
+ return new import_msw2.HttpResponse(JSON.stringify([inventoryDevice]), { headers: { [import_constants3.headerNames.total]: 4 } });
1198
+ }
1199
+ return new import_msw2.HttpResponse(JSON.stringify([]), { headers: { [import_constants3.headerNames.total]: 0 } });
1200
+ }
1201
+ let deviceList = Array.from({ length: mockApiResponses.devices.byStatus[status].total }, (_, index) => ({
1202
+ ...inventoryDevice,
1203
+ attributes: [...inventoryDevice.attributes, { name: "test-count", value: index, scope: "system" }],
1204
+ id: `${String.fromCharCode("a".charCodeAt(0) + index)}1`
1205
+ }));
1206
+ deviceList = deviceList.slice((page - 1) * per_page, page * per_page);
1207
+ return new import_msw2.HttpResponse(JSON.stringify(deviceList), { headers: { [import_constants3.headerNames.total]: mockApiResponses.devices.byStatus[status].total } });
1208
+ };
1209
+ var deviceHandlers = [
1210
+ import_msw2.http.delete(`${import_constants3.deviceAuthV2}/devices/:deviceId/auth/:authId`, ({ params: { authId, deviceId } }) => {
1211
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId)) {
1212
+ return new import_msw2.HttpResponse(null, { status: 200 });
1213
+ }
1214
+ return new import_msw2.HttpResponse(null, { status: 501 });
1215
+ }),
1216
+ import_msw2.http.delete(`${import_constants3.deviceAuthV2}/devices/:deviceId`, ({ params: { deviceId } }) => {
1217
+ if (mockApiResponses.devices.byId[deviceId]) {
1218
+ return new import_msw2.HttpResponse(null, { status: 200 });
1219
+ }
1220
+ return new import_msw2.HttpResponse(null, { status: 502 });
1221
+ }),
1222
+ import_msw2.http.delete(`${import_constants3.inventoryApiUrl}/groups/:group`, ({ params: { group } }) => {
1223
+ if (mockApiResponses.devices.groups.byId[group]) {
1224
+ return new import_msw2.HttpResponse(null, { status: 200 });
1225
+ }
1226
+ return new import_msw2.HttpResponse(null, { status: 515 });
1227
+ }),
1228
+ import_msw2.http.delete(`${import_constants3.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
1229
+ const deviceIds = await request.json();
1230
+ if (mockApiResponses.devices.groups.byId[group] && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
1231
+ return new import_msw2.HttpResponse(null, { status: 200 });
1232
+ }
1233
+ return new import_msw2.HttpResponse(null, { status: 503 });
1234
+ }),
1235
+ import_msw2.http.delete(`${import_constants3.inventoryApiUrlV2}/filters/:filterId`, ({ params: { filterId } }) => {
1236
+ if (Object.values(mockApiResponses.devices.groups.byId).find((group) => group.id === filterId)) {
1237
+ return new import_msw2.HttpResponse(null, { status: 200 });
1238
+ }
1239
+ return new import_msw2.HttpResponse(null, { status: 504 });
1240
+ }),
1241
+ import_msw2.http.get(`${import_constants3.deviceAuthV2}/devices`, ({ request }) => {
1242
+ const { searchParams } = new URL(request.url);
1243
+ const deviceIds = searchParams.getAll("id");
1244
+ if (deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
1245
+ return import_msw2.HttpResponse.json(deviceIds.map((id) => ({ ...deviceAuthDevice, id })));
1246
+ }
1247
+ return new import_msw2.HttpResponse(null, { status: 505 });
1248
+ }),
1249
+ import_msw2.http.get(`${import_constants3.deviceAuthV2}/limits/devices`, () => import_msw2.HttpResponse.json(mockApiResponses.devices.limits)),
1250
+ import_msw2.http.get(`${import_constants3.inventoryApiUrl}/devices/:deviceId`, ({ params: { deviceId } }) => {
1251
+ if (mockApiResponses.devices.byId[deviceId]) {
1252
+ return import_msw2.HttpResponse.json(inventoryDevice);
1253
+ }
1254
+ return new import_msw2.HttpResponse(null, { status: 506 });
1255
+ }),
1256
+ import_msw2.http.put(`${import_constants3.inventoryApiUrl}/devices/:deviceId/tags`, async ({ params: { deviceId }, request }) => {
1257
+ const tags = await request.json();
1258
+ if (!mockApiResponses.devices.byId[deviceId] && !Array.isArray(tags) && !tags.every((item) => item.name && item.value)) {
1259
+ return new import_msw2.HttpResponse(null, { status: 506 });
1260
+ }
1261
+ return import_msw2.HttpResponse.json(tags);
1262
+ }),
1263
+ import_msw2.http.get(`${import_constants3.inventoryApiUrl}/groups`, () => {
1264
+ const groups = Object.entries(mockApiResponses.devices.groups.byId).reduce((accu, [groupName, group]) => {
1265
+ if (!group.id) {
1266
+ accu.push(groupName);
1267
+ }
1268
+ return accu;
1269
+ }, []);
1270
+ return import_msw2.HttpResponse.json(groups);
1271
+ }),
1272
+ import_msw2.http.get(`${import_constants3.inventoryApiUrlV2}/filters/attributes`, () => import_msw2.HttpResponse.json(deviceAttributes)),
1273
+ import_msw2.http.get(
1274
+ `${import_constants3.inventoryApiUrlV2}/filters`,
1275
+ () => import_msw2.HttpResponse.json([
1276
+ {
1277
+ id: "filter1",
1278
+ name: "testGroupDynamic",
1279
+ terms: [
1280
+ { scope: "identity", attribute: "id", type: "$in", value: [defaultDeviceId] },
1281
+ { scope: "identity", attribute: "mac", type: "$exists", value: false },
1282
+ { scope: "identity", attribute: "kernel", type: "$exists", value: true }
1283
+ ]
1284
+ }
1285
+ ])
1286
+ ),
1287
+ import_msw2.http.patch(`${import_constants3.inventoryApiUrl}/groups/:group/devices`, async ({ params: { group }, request }) => {
1288
+ const deviceIds = await request.json();
1289
+ if (!!group && deviceIds.every((id) => !!mockApiResponses.devices.byId[id])) {
1290
+ return new import_msw2.HttpResponse(null, { status: 200 });
1291
+ }
1292
+ return new import_msw2.HttpResponse(null, { status: 508 });
1293
+ }),
1294
+ import_msw2.http.post(`${import_constants3.deviceAuthV2}/devices`, async ({ request }) => {
1295
+ const authset = await request.json();
1296
+ if (Object.values(mockApiResponses.devices.byId).some(
1297
+ (device) => device.auth_sets.some((deviceAuthSet) => deviceAuthSet.pubkey == authset.pubkey || deviceAuthSet.identity_data == authset.identity_data)
1298
+ )) {
1299
+ return new import_msw2.HttpResponse(null, { status: 409 });
1300
+ }
1301
+ return new import_msw2.HttpResponse(null, { status: 200 });
1302
+ }),
1303
+ import_msw2.http.post(`${import_constants3.inventoryApiUrlV2}/filters/search`, searchHandler),
1304
+ import_msw2.http.post(`${import_constants3.inventoryApiUrlV2}/filters`, async ({ request }) => {
1305
+ const { name, terms } = await request.json();
1306
+ if ([name, terms].some((item) => !item) || mockApiResponses.devices.groups[name] || !terms.every((term) => import_constants3.DEVICE_FILTERING_OPTIONS[term.type] && ["identity", "inventory", "system"].includes(term.scope) && !!term.value && !!term.attribute)) {
1307
+ return new import_msw2.HttpResponse(null, { status: 510 });
1308
+ }
1309
+ return new import_msw2.HttpResponse(JSON.stringify({}), { headers: { location: "find/me/here/createdFilterId" } });
1310
+ }),
1311
+ import_msw2.http.get(
1312
+ `${import_constants3.inventoryApiUrlV2}/statistics`,
1313
+ async () => import_msw2.HttpResponse.json({
1314
+ devices_by_status: {
1315
+ accepted: { standard: mockApiResponses.devices.byStatus.accepted.total, micro: 0, system: 0 },
1316
+ pending: { standard: mockApiResponses.devices.byStatus.pending.total, micro: 0, system: 0 }
1317
+ }
1318
+ })
1319
+ ),
1320
+ import_msw2.http.put(`${import_constants3.deviceAuthV2}/devices/:deviceId/auth/:authId/status`, async ({ params: { authId, deviceId }, request }) => {
1321
+ const { status } = await request.json();
1322
+ if (mockApiResponses.devices.byId[deviceId].auth_sets.find((authSet) => authSet.id === authId) && import_constants3.DEVICE_STATES[status]) {
1323
+ return new import_msw2.HttpResponse(null, { status: 200 });
1324
+ }
1325
+ return new import_msw2.HttpResponse(null, { status: 511 });
1326
+ }),
1327
+ import_msw2.http.get(`${import_constants3.deviceConfig}/:deviceId`, ({ params: { deviceId } }) => {
1328
+ if (deviceId === "testId") {
1329
+ return new import_msw2.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
1330
+ }
1331
+ if (mockApiResponses.devices.byId[deviceId]) {
1332
+ return import_msw2.HttpResponse.json({
1333
+ configured: { test: true, something: "else", aNumber: 42 },
1334
+ deployment_id: "config1",
1335
+ reported: { test: true, something: "else", aNumber: 42 },
1336
+ updated_ts: updatedTime,
1337
+ reported_ts: "2019-01-01T09:25:01.000Z"
1338
+ });
1339
+ }
1340
+ return new import_msw2.HttpResponse(null, { status: 512 });
1341
+ }),
1342
+ import_msw2.http.put(`${import_constants3.deviceConfig}/:deviceId`, async ({ params: { deviceId }, request }) => {
1343
+ const body = await request.text();
1344
+ if (body.includes("evilValue")) {
1345
+ return new import_msw2.HttpResponse(null, { status: 418 });
1346
+ }
1347
+ return new import_msw2.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 201 : 513 });
1348
+ }),
1349
+ import_msw2.http.post(`${import_constants3.deviceConfig}/:deviceId/deploy`, ({ params: { deviceId } }) => {
1350
+ if (mockApiResponses.devices.byId[deviceId]) {
1351
+ return import_msw2.HttpResponse.json({ deployment_id: "config1" });
1352
+ }
1353
+ return new import_msw2.HttpResponse(null, { status: 514 });
1354
+ }),
1355
+ import_msw2.http.get(`${import_constants3.deviceConnect}/devices/:deviceId`, ({ params: { deviceId } }) => {
1356
+ if (deviceId === "testId") {
1357
+ return new import_msw2.HttpResponse(JSON.stringify({ error: { status_code: 404 } }), { status: 404 });
1358
+ }
1359
+ if (mockApiResponses.devices.byId[deviceId]) {
1360
+ return import_msw2.HttpResponse.json({ status: "connected", updated_ts: mockApiResponses.devices.byId[deviceId].updated_ts });
1361
+ }
1362
+ return new import_msw2.HttpResponse(null, { status: 512 });
1363
+ }),
1364
+ import_msw2.http.post(`${import_constants3.deviceConnect}/devices/:deviceId/:action`, ({ params: { deviceId, action } }) => {
1365
+ if (["check-update", "send-inventory"].includes(action) && mockApiResponses.devices.byId[deviceId]) {
1366
+ return new import_msw2.HttpResponse(null, { status: 202 });
1367
+ }
1368
+ return new import_msw2.HttpResponse(null, { status: 518 });
1369
+ }),
1370
+ import_msw2.http.get(`${import_constants3.iotManagerBaseURL}/devices/:deviceId/state`, ({ params: { deviceId } }) => {
1371
+ if (mockApiResponses.devices.byId[deviceId]) {
1372
+ return import_msw2.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1373
+ }
1374
+ return new import_msw2.HttpResponse(null, { status: 515 });
1375
+ }),
1376
+ import_msw2.http.put(`${import_constants3.iotManagerBaseURL}/devices/:deviceId/state/:integrationId`, async ({ params: { deviceId }, request }) => {
1377
+ const body = await request.json();
1378
+ if (mockApiResponses.devices.byId[deviceId] && body) {
1379
+ return import_msw2.HttpResponse.json({ deployment_id: mockApiResponses.deployments.byId.d1.id });
1380
+ }
1381
+ return new import_msw2.HttpResponse(null, { status: 516 });
1382
+ }),
1383
+ import_msw2.http.put(
1384
+ `${import_constants3.deviceConnect}/devices/:deviceId/upload`,
1385
+ ({ params: { deviceId } }) => new import_msw2.HttpResponse(null, { status: mockApiResponses.devices.byId[deviceId] ? 200 : 517 })
1386
+ ),
1387
+ import_msw2.http.get(`${import_constants3.deviceAuthV2}/license`, () => import_msw2.HttpResponse.text("test,report"))
1388
+ ];
1389
+
1390
+ // src/requestHandlers/monitorHandlers.ts
1391
+ var import_constants4 = require("@northern.tech/utils/constants");
1392
+ var import_msw3 = require("msw");
1393
+ var monitorHandlers = [
1394
+ import_msw3.http.get(`${import_constants4.monitorApiUrlv1}/devices/:id/alerts`, () => new import_msw3.HttpResponse(JSON.stringify([]), { headers: { [import_constants4.headerNames.total]: 1 } })),
1395
+ import_msw3.http.get(`${import_constants4.monitorApiUrlv1}/devices/:id/alerts/latest`, () => import_msw3.HttpResponse.json([])),
1396
+ import_msw3.http.get(`${import_constants4.monitorApiUrlv1}/devices/:id/config`, ({ params: { id } }) => {
1397
+ if (id === mockApiResponses.devices.byId.a1.id) {
1398
+ return import_msw3.HttpResponse.json([{ something: "here" }]);
1399
+ }
1400
+ return import_msw3.HttpResponse.json([]);
1401
+ }),
1402
+ import_msw3.http.put(`${import_constants4.monitorApiUrlv1}/settings/global/channel/alerts/:channel/status`, async ({ params: { channel }, request }) => {
1403
+ const { enabled } = await request.json();
1404
+ if (Object.keys(import_constants4.alertChannels).includes(channel) && enabled !== void 0) {
1405
+ return new import_msw3.HttpResponse(null, { status: 200 });
1406
+ }
1407
+ return new import_msw3.HttpResponse(null, { status: 590 });
1408
+ })
1409
+ ];
1410
+
1411
+ // src/requestHandlers/organizationHandlers.ts
1412
+ var import_constants5 = require("@northern.tech/utils/constants");
1413
+ var import_msw4 = require("msw");
1414
+ var PLANS = {
1415
+ os: { id: "os", name: "Basic" },
1416
+ professional: { id: "professional", name: "Professional" },
1417
+ enterprise: { id: "enterprise", name: "Enterprise" }
1418
+ };
1419
+ var releasesSample = {
1420
+ lts: ["3.3"],
1421
+ releases: {
1422
+ "3.2": {
1423
+ "3.2.1": {
1424
+ release_date: "2022-02-02",
1425
+ release: "3.2.1",
1426
+ repos: [
1427
+ { name: "integration", version: "1.2.3" },
1428
+ { name: "mender", version: "3.2.1" },
1429
+ { name: "mender-artifact", version: "1.3.7" },
1430
+ { name: "service", version: "3.0.0" },
1431
+ { name: "other-service", version: "1.1.0" }
1432
+ ]
1433
+ },
1434
+ "3.2.0": {
1435
+ release_date: "2022-01-24",
1436
+ release: "3.2.0",
1437
+ repos: [
1438
+ { name: "service", version: "3.0.0" },
1439
+ { name: "another-service", version: "4.1.0" }
1440
+ ]
1441
+ }
1442
+ },
1443
+ "2.7": {
1444
+ "2.7.2": {
1445
+ release_date: "2021-11-04",
1446
+ release: "2.7.2",
1447
+ repos: [
1448
+ { name: "service", version: "1.1.0" },
1449
+ { name: "more-service", version: "1.0.2" }
1450
+ ]
1451
+ }
1452
+ },
1453
+ "1.0": {
1454
+ supported_until: "2018-02",
1455
+ "1.0.1": {
1456
+ release_date: "2017-04-03",
1457
+ release: "1.0.1",
1458
+ repos: [{ name: "service", version: "1.0.1" }]
1459
+ },
1460
+ "1.0.0": {
1461
+ release_date: "2017-02-16",
1462
+ release: "1.0.0",
1463
+ repos: [{ name: "mono-service", version: "1.0.0" }]
1464
+ }
1465
+ }
1466
+ },
1467
+ saas: [
1468
+ { tag: "saas-v2022.03.10", date: "2022-03-09" },
1469
+ { tag: "saas-v2020.09.25", date: "2020-09-24" },
1470
+ { tag: "saas-v2020.07.09", date: "2020-07-09" }
1471
+ ]
1472
+ };
1473
+ var tagsSample = [{ name: "saas-v2023.05.02", more: "here" }];
1474
+ var signupHandler = async ({ request }) => {
1475
+ const signup = await request.json();
1476
+ if (["email", "organization", "plan", "tos"].every((item) => !!signup[item])) {
1477
+ return import_msw4.HttpResponse.text("test");
1478
+ }
1479
+ return new import_msw4.HttpResponse(null, { status: 400 });
1480
+ };
1481
+ var invoicePreviewBasic = {
1482
+ id: "upcoming_in_1RlAkbFlFfXikjZVOHK5VQx0",
1483
+ period_start: "2025-07-15T15:25:22Z",
1484
+ period_end: "2025-08-15T15:25:22Z",
1485
+ total: 3200,
1486
+ currency: "usd",
1487
+ lines: [
1488
+ {
1489
+ description: "50 device \xD7 Mender Basic (Tier 1 at $0.00 / month)",
1490
+ amount: 0,
1491
+ currency: "usd",
1492
+ product: "mender_standard",
1493
+ quantity: 50,
1494
+ price_id: "price_1PYktlFlFfXikjZVh2aNHp7i"
1495
+ },
1496
+ {
1497
+ description: "Mender Basic (Tier 1 at $32.00 / month)",
1498
+ amount: 3200,
1499
+ currency: "usd",
1500
+ product: "mender_standard",
1501
+ quantity: 0,
1502
+ price_id: "price_1PYktlFlFfXikjZVh2aNHp7i"
1503
+ }
1504
+ ]
1505
+ };
1506
+ var subscriptionBasic = {
1507
+ id: "sub_1RlAjOFlFfXikjZVj5BvpJE4",
1508
+ status: "active",
1509
+ plan: "os",
1510
+ products: [
1511
+ {
1512
+ name: "mender_standard",
1513
+ quantity: 50
1514
+ }
1515
+ ]
1516
+ };
1517
+ var organizationHandlers = [
1518
+ import_msw4.http.get("/tags.json", () => import_msw4.HttpResponse.json(tagsSample)),
1519
+ import_msw4.http.get("/versions.json", () => import_msw4.HttpResponse.json(releasesSample)),
1520
+ import_msw4.http.get(`${import_constants5.tenantadmApiUrlv1}/user/tenant`, () => import_msw4.HttpResponse.json(mockApiResponses.organization.organization)),
1521
+ import_msw4.http.put(`${import_constants5.tenantadmApiUrlv2}/tenants/:tenantId/child`, () => new import_msw4.HttpResponse(null, { status: 200 })),
1522
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/tenants/:tenantId/cancel`, () => new import_msw4.HttpResponse(null, { status: 200 })),
1523
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/tenants/trial`, signupHandler),
1524
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/tenants`, async ({ request }) => {
1525
+ const { users } = await request.json();
1526
+ const { email } = users[0];
1527
+ if (email.includes("bad")) {
1528
+ return new import_msw4.HttpResponse(null, { status: 553 });
1529
+ }
1530
+ return new import_msw4.HttpResponse(null, { status: 200 });
1531
+ }),
1532
+ import_msw4.http.post(`https://hosted.mender.io${import_constants5.tenantadmApiUrlv2}/tenants/trial`, signupHandler),
1533
+ import_msw4.http.get(`${import_constants5.tenantadmApiUrlv2}/tenants`, () => import_msw4.HttpResponse.json(tenants)),
1534
+ import_msw4.http.get(`${import_constants5.tenantadmApiUrlv2}/billing`, () => import_msw4.HttpResponse.json({ card: { last4: "7890", exp_month: 1, exp_year: 2024, brand: "testCorp" } })),
1535
+ import_msw4.http.get(
1536
+ `${import_constants5.tenantadmApiUrlv2}/billing/profile`,
1537
+ () => import_msw4.HttpResponse.json({
1538
+ name: "company",
1539
+ email: "test@test.com",
1540
+ address: { state: "OSLO", line1: "Blindern", country: "NO", city: "OSLO", postal_code: "0123" },
1541
+ shipping: { address: { state: "OSLO", line1: "Blindern", country: "NO", city: "OSLO", postal_code: "0123" } }
1542
+ })
1543
+ ),
1544
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/billing/card`, () => import_msw4.HttpResponse.json({ intent_id: mockApiResponses.organization.intentId, secret: "testSecret" })),
1545
+ import_msw4.http.post(
1546
+ `${import_constants5.tenantadmApiUrlv2}/billing/card/:intentId/confirm`,
1547
+ ({ params: { intentId } }) => new import_msw4.HttpResponse(null, { status: intentId == mockApiResponses.organization.intentId ? 200 : 540 })
1548
+ ),
1549
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/tenants/:tenantId/upgrade/:status`, async ({ params: { status, tenantId }, request }) => {
1550
+ if (tenantId != mockApiResponses.organization.organization.id || !["cancel", "complete", "start"].includes(status)) {
1551
+ return new import_msw4.HttpResponse(null, { status: 541 });
1552
+ }
1553
+ if (status === "start") {
1554
+ return import_msw4.HttpResponse.json({ secret: "testSecret" });
1555
+ }
1556
+ let plan;
1557
+ try {
1558
+ const body = await request.json();
1559
+ plan = body.plan;
1560
+ } catch {
1561
+ }
1562
+ if (plan && !Object.keys(PLANS).includes(plan)) {
1563
+ return new import_msw4.HttpResponse(null, { status: 542 });
1564
+ }
1565
+ return new import_msw4.HttpResponse(null, { status: 200 });
1566
+ }),
1567
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/tenants/:tenantId/plan`, async ({ params: { tenantId }, request }) => {
1568
+ const body = await request.json();
1569
+ const expectedKeys = ["current_plan", "requested_plan", "current_addons", "requested_addons", "user_message"];
1570
+ if (tenantId != mockApiResponses.organization.organization.id || !Object.keys(body).every((key) => expectedKeys.includes(key))) {
1571
+ return new import_msw4.HttpResponse(null, { status: 544 });
1572
+ }
1573
+ if (body.requested_plan && !Object.values(PLANS).some((item) => item.name === body.requested_plan)) {
1574
+ return new import_msw4.HttpResponse(null, { status: 545 });
1575
+ }
1576
+ return new import_msw4.HttpResponse(null, { status: 200 });
1577
+ }),
1578
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/contact/support`, async ({ request }) => {
1579
+ const { subject, body } = await request.json();
1580
+ if (!(subject && body)) {
1581
+ return new import_msw4.HttpResponse(null, { status: 543 });
1582
+ }
1583
+ return new import_msw4.HttpResponse(null, { status: 200 });
1584
+ }),
1585
+ import_msw4.http.patch(`${import_constants5.tenantadmApiUrlv2}/billing/profile`, () => new import_msw4.HttpResponse(null, { status: 200 })),
1586
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/billing/profile`, () => new import_msw4.HttpResponse(null, { status: 200 })),
1587
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/billing/subscription`, () => new import_msw4.HttpResponse(null, { status: 202 })),
1588
+ import_msw4.http.post(`${import_constants5.tenantadmApiUrlv2}/billing/subscription/invoices/preview`, () => import_msw4.HttpResponse.json(invoicePreviewBasic)),
1589
+ import_msw4.http.get(`${import_constants5.tenantadmApiUrlv2}/billing/subscription`, () => import_msw4.HttpResponse.json(subscriptionBasic)),
1590
+ import_msw4.http.get(`${import_constants5.tenantadmApiUrlv2}/billing/products`, () => import_msw4.HttpResponse.json(mockApiResponses.organization.products)),
1591
+ import_msw4.http.get(`${import_constants5.auditLogsApiUrl}/logs`, ({ request }) => {
1592
+ const { searchParams } = new URL(request.url);
1593
+ const perPage = Number(searchParams.get("per_page"));
1594
+ if (perPage === 500) {
1595
+ return import_msw4.HttpResponse.json([
1596
+ { meta: mockApiResponses.organization.auditlog.events[2].meta, time: mockApiResponses.organization.auditlog.events[1].time, action: "close_terminal" }
1597
+ ]);
1598
+ }
1599
+ return new import_msw4.HttpResponse(JSON.stringify(mockApiResponses.organization.auditlog.events), {
1600
+ headers: { [import_constants5.headerNames.total]: mockApiResponses.organization.auditlog.events.length }
1601
+ });
1602
+ }),
1603
+ import_msw4.http.get(
1604
+ `${import_constants5.auditLogsApiUrl}/logs/export`,
1605
+ () => import_msw4.HttpResponse.text(`action,actor.id,actor.type,actor.email,actor.identity_data,object.id,object.type,object.user.email,object.deployment.name,object.deployment.artifact_name,change
1606
+ update,5c56c2ed-2a9a-5de9-bb86-cf38b3d4a5e1,user,test@example.coim,,067f23a9-76a5-5585-b119-32402a120978,user,test@example.com,,,"Update user 067f23a9-76a5-5585-b119-32402a120978 (test@example.com).
1607
+ Diff:
1608
+ --- Original
1609
+ +++ Current
1610
+ @@ -9 +9,2 @@
1611
+ - ""RBAC_ROLE_OBSERVER""
1612
+ + ""RBAC_ROLE_OBSERVER"",
1613
+ + ""RBAC_ROLE_PERMIT_ALL""
1614
+ "
1615
+ `)
1616
+ ),
1617
+ import_msw4.http.get(
1618
+ `${import_constants5.iotManagerBaseURL}/integrations`,
1619
+ () => import_msw4.HttpResponse.json([
1620
+ { connection_string: "something_else", id: 1, provider: "iot-hub" },
1621
+ { id: 2, provider: "iot-core", something: "new" }
1622
+ ])
1623
+ ),
1624
+ import_msw4.http.post(`${import_constants5.iotManagerBaseURL}/integrations`, () => import_msw4.HttpResponse.json([{ connection_string: "something_else", provider: "iot-hub" }])),
1625
+ import_msw4.http.put(`${import_constants5.iotManagerBaseURL}/integrations/:integrationId`, ({ params: { integrationId } }) => {
1626
+ if (!integrationId) {
1627
+ return new import_msw4.HttpResponse(null, { status: 547 });
1628
+ }
1629
+ return new import_msw4.HttpResponse(null, { status: 200 });
1630
+ }),
1631
+ import_msw4.http.put(`${import_constants5.iotManagerBaseURL}/integrations/:integrationId/credentials`, ({ params: { integrationId } }) => {
1632
+ if (!integrationId) {
1633
+ return new import_msw4.HttpResponse(null, { status: 548 });
1634
+ }
1635
+ return new import_msw4.HttpResponse(null, { status: 200 });
1636
+ }),
1637
+ import_msw4.http.delete(`${import_constants5.iotManagerBaseURL}/integrations/:integrationId`, ({ params: { integrationId } }) => {
1638
+ if (!integrationId) {
1639
+ return new import_msw4.HttpResponse(null, { status: 549 });
1640
+ }
1641
+ return new import_msw4.HttpResponse(null, { status: 200 });
1642
+ }),
1643
+ import_msw4.http.get(`${import_constants5.iotManagerBaseURL}/events`, ({ request }) => {
1644
+ const { searchParams } = new URL(request.url);
1645
+ const page = Number(searchParams.get("page"));
1646
+ const perPage = Number(searchParams.get("per_page"));
1647
+ return import_msw4.HttpResponse.json(webhookEvents.slice(page - 1, page * perPage));
1648
+ }),
1649
+ import_msw4.http.get(
1650
+ import_constants5.ssoIdpApiUrlv1,
1651
+ () => import_msw4.HttpResponse.json([
1652
+ { id: "1", issuer: "https://samltest.id/saml/idp", valid_until: "2038-08-24T21:14:09Z" },
1653
+ { id: "2", issuer: "https://samltest2.id/saml/idp", valid_until: "2030-10-24T21:14:09Z" }
1654
+ ])
1655
+ ),
1656
+ import_msw4.http.post(import_constants5.ssoIdpApiUrlv1, () => new import_msw4.HttpResponse(null, { status: 200 })),
1657
+ import_msw4.http.get(`${import_constants5.ssoIdpApiUrlv1}/:configId`, ({ params: { configId } }) => {
1658
+ if (!configId) {
1659
+ return new import_msw4.HttpResponse(null, { status: 550 });
1660
+ }
1661
+ return import_msw4.HttpResponse.json({ email: "user@acme.com", password: "mypass1234", login: { google: "bob@gmail.com" }, config: "<div>not quite right</div>" });
1662
+ }),
1663
+ import_msw4.http.put(`${import_constants5.ssoIdpApiUrlv1}/:configId`, ({ params: { configId } }) => new import_msw4.HttpResponse(null, { status: configId ? 200 : 551 })),
1664
+ import_msw4.http.delete(`${import_constants5.ssoIdpApiUrlv1}/:configId`, ({ params: { configId } }) => new import_msw4.HttpResponse(null, { status: configId ? 200 : 552 }))
1665
+ ];
1666
+
1667
+ // src/requestHandlers/releaseHandlers.ts
1668
+ var import_constants6 = require("@northern.tech/utils/constants");
1669
+ var import_helpers = require("@northern.tech/utils/helpers");
1670
+ var import_msw5 = require("msw");
1671
+ var deltaJobs = {
1672
+ "delta-job-1": {
1673
+ id: "delta-job-1",
1674
+ to_release: "mender-demo-artifact-3.3.1",
1675
+ from_release: "mender-demo-artifact-3.2.1",
1676
+ to_version: "mender-demo-artifact-3.3.1",
1677
+ from_version: "mender-demo-artifact-3.2.1",
1678
+ device_types_compatible: ["qemux86-64"],
1679
+ started: "2022-07-11T20:49:00.000Z",
1680
+ status: "success"
1681
+ },
1682
+ "delta-job-2": {
1683
+ id: "delta-job-2",
1684
+ to_release: "mender-demo-artifact-3.3.1",
1685
+ from_release: "mender-demo-artifact-3.3.0",
1686
+ to_version: "mender-demo-artifact-3.3.1",
1687
+ from_version: "mender-demo-artifact-3.3.0",
1688
+ device_types_compatible: ["raspberrypi0w", "raspberrypi0-wifi", "raspberrypi3", "raspberrypi4"],
1689
+ started: "2022-07-11T20:49:00.000Z",
1690
+ status: "failed"
1691
+ },
1692
+ "delta-job-3": {
1693
+ id: "delta-job-3",
1694
+ to_release: "mender-demo-artifact-3.3.1",
1695
+ from_release: "mender-demo-artifact-3.3.0",
1696
+ to_version: "mender-demo-artifact-3.3.1",
1697
+ from_version: "mender-demo-artifact-3.3.0",
1698
+ device_types_compatible: ["beaglebone", "beaglebone-yocto", "beaglebone-yocto"],
1699
+ started: "2022-07-11T20:49:00.000Z",
1700
+ status: "pending"
1701
+ },
1702
+ "delta-job-4": {
1703
+ id: "delta-job-4",
1704
+ to_release: "mender-demo-artifact-3.2.0",
1705
+ from_release: "mender-demo-artifact-3.1.0",
1706
+ to_version: "mender-demo-artifact-3.2.0",
1707
+ from_version: "mender-demo-artifact-3.1.0",
1708
+ device_types_compatible: ["qemux86-64"],
1709
+ started: "2022-07-10T15:30:00.000Z",
1710
+ status: "artifact_uploaded"
1711
+ }
1712
+ };
1713
+ var mockDeltaJobDetails = {
1714
+ "delta-job-1": {
1715
+ ...deltaJobs["delta-job-1"],
1716
+ delta_artifact_size: 1024e3,
1717
+ deployment_id: "d1",
1718
+ devices_types_compatible: ["qemux86-64"],
1719
+ exit_code: 0,
1720
+ log: "Delta generation started at 2022-07-11T20:49:00.000Z\nProcessing artifacts...\nDelta generation completed successfully at 2022-07-11T20:52:15.000Z",
1721
+ to_artifact_size: 2048e3
1722
+ },
1723
+ "delta-job-2": {
1724
+ ...deltaJobs["delta-job-2"],
1725
+ delta_artifact_size: null,
1726
+ deployment_id: "d2",
1727
+ devices_types_compatible: ["raspberrypi0w", "raspberrypi0-wifi", "raspberrypi3", "raspberrypi4"],
1728
+ exit_code: 1,
1729
+ log: "Delta generation started at 2022-07-11T20:49:00.000Z\nError: incompatible artifact types\nDelta generation failed at 2022-07-11T20:51:30.000Z",
1730
+ to_artifact_size: 3072e3
1731
+ },
1732
+ "delta-job-3": {
1733
+ ...deltaJobs["delta-job-3"],
1734
+ delta_artifact_size: null,
1735
+ deployment_id: "d3",
1736
+ devices_types_compatible: ["beaglebone", "beaglebone-yocto"],
1737
+ exit_code: null,
1738
+ log: "Delta generation started at 2022-07-11T20:49:00.000Z\nQueued for processing...",
1739
+ to_artifact_size: 256e4
1740
+ },
1741
+ "delta-job-4": {
1742
+ ...deltaJobs["delta-job-4"],
1743
+ delta_artifact_size: 512e3,
1744
+ deployment_id: "d1",
1745
+ devices_types_compatible: ["qemux86-64"],
1746
+ exit_code: 0,
1747
+ log: "Delta generation started at 2022-07-10T15:30:00.000Z\nProcessing artifacts...\nArtifact uploaded successfully at 2022-07-10T15:45:20.000Z",
1748
+ to_artifact_size: 1536e3
1749
+ }
1750
+ };
1751
+ var releaseHandlers = [
1752
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrl}/artifacts/:id`, () => new import_msw5.HttpResponse(null, { status: 200 })),
1753
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrl}/artifacts/:id/download`, () => import_msw5.HttpResponse.json({ uri: "https://testlocation.com/artifact.mender" })),
1754
+ import_msw5.http.delete(
1755
+ `${import_constants6.deploymentsApiUrl}/artifacts/:id`,
1756
+ ({ params: { id } }) => new import_msw5.HttpResponse(null, { status: id === mockApiResponses.releases.byId.r1.artifacts[0].id ? 200 : 591 })
1757
+ ),
1758
+ import_msw5.http.put(`${import_constants6.deploymentsApiUrl}/artifacts/:id`, async ({ params: { id }, request }) => {
1759
+ const { description } = await request.json();
1760
+ return new import_msw5.HttpResponse(null, { status: id === mockApiResponses.releases.byId.r1.artifacts[0].id && description ? 200 : 592 });
1761
+ }),
1762
+ import_msw5.http.post(
1763
+ `${import_constants6.deploymentsApiUrl}/artifacts/generate`,
1764
+ () => new import_msw5.HttpResponse(null, {
1765
+ headers: { [import_constants6.headerNames.location]: `${import_constants6.deploymentsApiUrl}/artifacts/generate/${mockApiResponses.releases.byId.r1.artifacts[0].id}`, status: 201 }
1766
+ })
1767
+ ),
1768
+ import_msw5.http.post(`${import_constants6.deploymentsApiUrl}/artifacts`, () => new import_msw5.HttpResponse(null, { status: 200 })),
1769
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/deployments/releases`, async ({ request }) => {
1770
+ const { searchParams } = new URL(request.url);
1771
+ const page = Number(searchParams.get("page"));
1772
+ const perPage = Number(searchParams.get("per_page"));
1773
+ if (!page || ![1, 10, 20, 50, 100, 250, 500].includes(perPage)) {
1774
+ return new import_msw5.HttpResponse(null, { status: 593 });
1775
+ }
1776
+ if (searchParams.get("device_type")) {
1777
+ return import_msw5.HttpResponse.json([]);
1778
+ }
1779
+ if (page == 42) {
1780
+ return new import_msw5.HttpResponse(JSON.stringify([mockApiResponses.releases.byId.r1]), { headers: { [import_constants6.headerNames.total]: 1 } });
1781
+ }
1782
+ const sort = searchParams.get("sort");
1783
+ const releaseListSection = releasesList.sort((0, import_helpers.customSort)(sort.includes(import_constants6.SORTING_OPTIONS.desc), "name")).slice((page - 1) * perPage, page * perPage);
1784
+ if (page === 1 && perPage === 1 && searchParams.get("name")) {
1785
+ return import_msw5.HttpResponse.json([mockApiResponses.releases.byId.r1]);
1786
+ }
1787
+ if (searchParams.get("name")) {
1788
+ return new import_msw5.HttpResponse(JSON.stringify(releaseListSection), { headers: { [import_constants6.headerNames.total]: 1234 } });
1789
+ }
1790
+ return new import_msw5.HttpResponse(JSON.stringify(releaseListSection), { headers: { [import_constants6.headerNames.total]: releasesList.length } });
1791
+ }),
1792
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/deployments/releases/:name`, () => import_msw5.HttpResponse.json(mockApiResponses.releases.byId.r1)),
1793
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/releases/all/tags`, () => import_msw5.HttpResponse.json(["foo", "bar"])),
1794
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/releases/all/types`, () => import_msw5.HttpResponse.json(["single-file", "not-this"])),
1795
+ import_msw5.http.put(`${import_constants6.deploymentsApiUrlV2}/deployments/releases/:name/tags`, async ({ params: { name }, request }) => {
1796
+ const tags = await request.json();
1797
+ if (name && tags.every((i) => i && i.toString() === i)) {
1798
+ return new import_msw5.HttpResponse(null, { status: 200 });
1799
+ }
1800
+ return new import_msw5.HttpResponse(null, { status: 593 });
1801
+ }),
1802
+ import_msw5.http.patch(`${import_constants6.deploymentsApiUrlV2}/deployments/releases/:name`, async ({ params: { name }, request }) => {
1803
+ const { notes } = await request.json();
1804
+ return new import_msw5.HttpResponse(null, { status: name && notes.length ? 200 : 594 });
1805
+ }),
1806
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/deployments/releases/delta/jobs`, () => {
1807
+ const jobs = Object.values(deltaJobs);
1808
+ return new import_msw5.HttpResponse(JSON.stringify(jobs), { headers: { [import_constants6.headerNames.total]: jobs.length } });
1809
+ }),
1810
+ import_msw5.http.get(`${import_constants6.deploymentsApiUrlV2}/deployments/releases/delta/jobs/:jobId`, ({ params: { jobId } }) => {
1811
+ const jobDetails = mockDeltaJobDetails[jobId];
1812
+ if (jobDetails) {
1813
+ return import_msw5.HttpResponse.json(jobDetails);
1814
+ }
1815
+ return new import_msw5.HttpResponse(null, { status: 404 });
1816
+ })
1817
+ ];
1818
+
1819
+ // src/requestHandlers/userHandlers.ts
1820
+ var import_constants7 = require("@northern.tech/utils/constants");
1821
+ var import_msw6 = require("msw");
1822
+ var userHandlers = [
1823
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/auth/login`, ({ request }) => {
1824
+ const authHeader = request.headers.get("authorization");
1825
+ const authInfo = atob(authHeader?.split(" ")[1]);
1826
+ const [user, password] = authInfo.split(":");
1827
+ if (!password) {
1828
+ return import_msw6.HttpResponse.json({ id: testSsoId, kind: "sso/saml" });
1829
+ } else if (password !== defaultPassword) {
1830
+ return new import_msw6.HttpResponse(null, { status: 401 });
1831
+ } else if (user.includes("limited")) {
1832
+ return new import_msw6.HttpResponse("limitedToken", { headers: { "Content-Type": import_constants7.APPLICATION_JWT_CONTENT_TYPE } });
1833
+ } else if (user.includes("2fa")) {
1834
+ return new import_msw6.HttpResponse(JSON.stringify({ error: "2fa needed" }), { status: 401 });
1835
+ }
1836
+ return new import_msw6.HttpResponse(token, { headers: { "Content-Type": import_constants7.APPLICATION_JWT_CONTENT_TYPE } });
1837
+ }),
1838
+ import_msw6.http.get(`https://hosted.mender.io${import_constants7.useradmApiUrl}/auth/magic/:id`, ({ params: { id } }) => {
1839
+ if (id) {
1840
+ return new import_msw6.HttpResponse("test", { headers: { "Set-Cookie": "JWT=test" } });
1841
+ }
1842
+ return new import_msw6.HttpResponse(null, { status: 400 });
1843
+ }),
1844
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/auth/logout`, () => new import_msw6.HttpResponse(null, { status: 200 })),
1845
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/auth/password-reset/:status`, async ({ params: { status }, request }) => {
1846
+ const { email, secret_hash, password } = await request.json();
1847
+ if (!["start", "complete"].includes(status) && ![email, secret_hash, password].some((item) => item)) {
1848
+ return new import_msw6.HttpResponse(null, { status: 560 });
1849
+ }
1850
+ if (status === "start" && email) {
1851
+ return new import_msw6.HttpResponse(null, { status: 200 });
1852
+ }
1853
+ if (status === "complete" && secret_hash && password) {
1854
+ return new import_msw6.HttpResponse(null, { status: 200 });
1855
+ }
1856
+ return new import_msw6.HttpResponse(null, { status: 561 });
1857
+ }),
1858
+ import_msw6.http.put(`${import_constants7.useradmApiUrl}/2faverify`, async ({ request }) => {
1859
+ const { token2fa } = await request.json();
1860
+ if (!token2fa) {
1861
+ return new import_msw6.HttpResponse(null, { status: 562 });
1862
+ }
1863
+ return new import_msw6.HttpResponse(null, { status: 200 });
1864
+ }),
1865
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/users`, () => import_msw6.HttpResponse.json(Object.values(mockApiResponses.users.byId))),
1866
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/users/me`, ({ request }) => {
1867
+ const authHeader = request.headers.get("authorization");
1868
+ if (authHeader?.includes("limited")) {
1869
+ return new import_msw6.HttpResponse(JSON.stringify({ error: "forbidden by role-based access control" }), { status: 403 });
1870
+ }
1871
+ return import_msw6.HttpResponse.json(mockApiResponses.users.byId[userId]);
1872
+ }),
1873
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/users/exists`, ({ request }) => {
1874
+ const url = new URL(request.url);
1875
+ const email = url.searchParams.get("email");
1876
+ if (!decodeURIComponent(email).includes("child+123")) {
1877
+ return new import_msw6.HttpResponse(null, { status: 578 });
1878
+ }
1879
+ return import_msw6.HttpResponse.json({ exists: true });
1880
+ }),
1881
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/users/:userId`, ({ params: { userId: userId2 } }) => {
1882
+ if (userId2 === "me" || mockApiResponses.users.byId[userId2]) {
1883
+ const user = userId2 === "me" ? userId : userId2;
1884
+ return import_msw6.HttpResponse.json(mockApiResponses.users.byId[user]);
1885
+ }
1886
+ return new import_msw6.HttpResponse(null, { status: 563 });
1887
+ }),
1888
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/users`, async ({ request }) => {
1889
+ const { email, password } = await request.json();
1890
+ if (email === "test@test.com" || [email, password].every((value) => value)) {
1891
+ return import_msw6.HttpResponse.json(mockApiResponses.users.byId.a1);
1892
+ }
1893
+ return new import_msw6.HttpResponse(null, { status: 564 });
1894
+ }),
1895
+ import_msw6.http.put(`${import_constants7.useradmApiUrl}/users/:userId`, async ({ params: { userId: userId2 }, request }) => {
1896
+ const { email, password, current_password } = await request.json();
1897
+ if (current_password === "bad_password") {
1898
+ return new import_msw6.HttpResponse(null, { status: 401 });
1899
+ }
1900
+ if (mockApiResponses.users.byId[userId2] && [email, password].some((value) => Object.values(mockApiResponses.users.byId[userId2]).includes(value)) || email === "test@test.com") {
1901
+ return new import_msw6.HttpResponse(null, { status: 200 });
1902
+ }
1903
+ return new import_msw6.HttpResponse(null, { status: 565 });
1904
+ }),
1905
+ import_msw6.http.delete(
1906
+ `${import_constants7.useradmApiUrl}/users/:userId`,
1907
+ ({ params: { userId: userId2 } }) => new import_msw6.HttpResponse(null, { status: mockApiResponses.users.byId[userId2] ? 200 : 566 })
1908
+ ),
1909
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/roles`, () => import_msw6.HttpResponse.json(rbacRoles)),
1910
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/roles`, async ({ request }) => {
1911
+ const { name, permissions } = await request.json();
1912
+ if ([name, permissions].every((value) => value) && permissions.every((permission) => permission.action && permission.object && permission.object.type && permission.object.value)) {
1913
+ return new import_msw6.HttpResponse(null, { status: 200 });
1914
+ }
1915
+ return new import_msw6.HttpResponse(null, { status: 567 });
1916
+ }),
1917
+ import_msw6.http.put(`${import_constants7.useradmApiUrl}/roles/:roleId`, async ({ params: { roleId }, request }) => {
1918
+ const { description, name, permissions } = await request.json();
1919
+ if (mockApiResponses.users.rolesById[roleId] && [description, name, permissions].some((value) => value)) {
1920
+ return new import_msw6.HttpResponse(null, { status: 200 });
1921
+ }
1922
+ return new import_msw6.HttpResponse(null, { status: 568 });
1923
+ }),
1924
+ import_msw6.http.post(`${import_constants7.useradmApiUrlv2}/support/feedback/product`, async () => new import_msw6.HttpResponse(null, { status: 200 })),
1925
+ import_msw6.http.delete(
1926
+ `${import_constants7.useradmApiUrl}/roles/:roleId`,
1927
+ ({ params: { roleId } }) => new import_msw6.HttpResponse(null, { status: mockApiResponses.users.rolesById[roleId] ? 200 : 569 })
1928
+ ),
1929
+ import_msw6.http.get(`${import_constants7.useradmApiUrlv2}/roles`, () => import_msw6.HttpResponse.json(rbacRoles)),
1930
+ import_msw6.http.get(`${import_constants7.useradmApiUrlv2}/roles/:roleId`, async ({ params: { roleId } }) => {
1931
+ if (mockApiResponses.users.rolesById[roleId]) {
1932
+ return import_msw6.HttpResponse.json(mockApiResponses.users.rolesById[roleId]);
1933
+ }
1934
+ return new import_msw6.HttpResponse(null, { status: 571 });
1935
+ }),
1936
+ import_msw6.http.post(`${import_constants7.useradmApiUrlv2}/roles`, async ({ request }) => {
1937
+ const { name, permission_sets_with_scope } = await request.json();
1938
+ if (!!name && permission_sets_with_scope.every((permission) => permission.name && permissionSets.find((permissionSet) => permissionSet.name === permission.name))) {
1939
+ return new import_msw6.HttpResponse(null, { status: 200 });
1940
+ }
1941
+ return new import_msw6.HttpResponse(null, { status: 572 });
1942
+ }),
1943
+ import_msw6.http.put(`${import_constants7.useradmApiUrlv2}/roles/:roleId`, async ({ params: { roleId }, request }) => {
1944
+ const { description, name, permission_sets_with_scope } = await request.json();
1945
+ if (mockApiResponses.users.rolesById[roleId] && [description, name, permission_sets_with_scope].some((value) => value)) {
1946
+ return new import_msw6.HttpResponse(null, { status: 200 });
1947
+ }
1948
+ return new import_msw6.HttpResponse(null, { status: 573 });
1949
+ }),
1950
+ import_msw6.http.delete(`${import_constants7.useradmApiUrlv2}/roles/:roleId`, ({ params: { roleId } }) => {
1951
+ if (mockApiResponses.users.rolesById[roleId]) {
1952
+ return new import_msw6.HttpResponse(null, { status: 200 });
1953
+ }
1954
+ return new import_msw6.HttpResponse(null, { status: 574 });
1955
+ }),
1956
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/settings`, () => import_msw6.HttpResponse.json(mockApiResponses.users.globalSettings)),
1957
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/settings`, () => new import_msw6.HttpResponse(null, { status: 200 })),
1958
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/settings/me`, () => import_msw6.HttpResponse.json(mockApiResponses.users.userSettings)),
1959
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/settings/me`, () => new import_msw6.HttpResponse(null, { status: 200 })),
1960
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/settings/tokens`, () => import_msw6.HttpResponse.json(accessTokens)),
1961
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/settings/tokens`, () => import_msw6.HttpResponse.json("aNewToken")),
1962
+ import_msw6.http.delete(
1963
+ `${import_constants7.useradmApiUrl}/settings/tokens/:tokenId`,
1964
+ ({ params: { tokenId } }) => new import_msw6.HttpResponse(null, { status: tokenId === "some-id-1" ? 200 : 577 })
1965
+ ),
1966
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/2faqr`, () => import_msw6.HttpResponse.json({ qr: btoa("test") })),
1967
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/users/:userId/2fa/enable`, ({ params: { userId: userId2 } }) => {
1968
+ if (mockApiResponses.users.byId[userId2] || userId2 === "me") {
1969
+ return new import_msw6.HttpResponse(null, { status: 200 });
1970
+ }
1971
+ return new import_msw6.HttpResponse(null, { status: 570 });
1972
+ }),
1973
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/users/:userId/2fa/disable`, ({ params: { userId: userId2 } }) => {
1974
+ if (mockApiResponses.users.byId[userId2] || userId2 === "me") {
1975
+ return new import_msw6.HttpResponse(null, { status: 200 });
1976
+ }
1977
+ return new import_msw6.HttpResponse(null, { status: 571 });
1978
+ }),
1979
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/auth/verify-email/start`, () => new import_msw6.HttpResponse(null, { status: 200 })),
1980
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/auth/verify-email/complete`, async ({ request }) => {
1981
+ const { secret_hash } = await request.json();
1982
+ return new import_msw6.HttpResponse(null, { status: secret_hash === "superSecret" ? 200 : 576 });
1983
+ }),
1984
+ import_msw6.http.get(`${import_constants7.useradmApiUrlv2}/permission_sets`, () => import_msw6.HttpResponse.json(permissionSets)),
1985
+ import_msw6.http.post(`${import_constants7.useradmApiUrl}/users/:userId/assign`, async ({ request }) => {
1986
+ const { tenant_ids } = await request.json();
1987
+ return new import_msw6.HttpResponse(null, { status: tenant_ids.length ? 200 : 577 });
1988
+ }),
1989
+ import_msw6.http.get(`${import_constants7.useradmApiUrl}/users/tenants/:tenantId/token`, () => import_msw6.HttpResponse.text("differentToken"))
1990
+ ];
1991
+
1992
+ // src/requestHandlers/requestHandlers.ts
1993
+ var testLocation = "/test";
1994
+ var baseHandlers = [
1995
+ import_msw7.http.get(testLocation, () => new import_msw7.HttpResponse(null, { status: 200 })),
1996
+ import_msw7.http.post(testLocation, () => import_msw7.HttpResponse.json({})),
1997
+ import_msw7.http.put(testLocation, () => import_msw7.HttpResponse.json({})),
1998
+ import_msw7.http.delete(testLocation, () => import_msw7.HttpResponse.json({}))
1999
+ ];
2000
+ var handlers = [...baseHandlers, ...deploymentHandlers, ...deviceHandlers, ...monitorHandlers, ...organizationHandlers, ...releaseHandlers, ...userHandlers];
2001
+ var requestHandlers_default = handlers;
2002
+ //# sourceMappingURL=requestHandlers.cjs.map