@northern.tech/store 0.1.1 → 0.1.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 (622) hide show
  1. package/dist/actions.d.mts +95 -0
  2. package/dist/actions.d.ts +95 -0
  3. package/dist/actions.js +1746 -0
  4. package/dist/actions.js.map +1 -0
  5. package/dist/actions.mjs +21 -0
  6. package/dist/actions.mjs.map +1 -0
  7. package/dist/api/general-api.d.mts +21 -0
  8. package/dist/api/general-api.d.ts +21 -0
  9. package/dist/api/general-api.js +1002 -0
  10. package/dist/api/general-api.js.map +1 -0
  11. package/dist/api/general-api.mjs +18 -0
  12. package/dist/api/general-api.mjs.map +1 -0
  13. package/dist/api/types/Address.ts +6 -0
  14. package/dist/api/types/AddressUpdate.ts +12 -0
  15. package/dist/api/types/AuthSet.ts +37 -0
  16. package/{api/types/AuthSet.ts → dist/api/types/AuthSetIot_manager.ts} +2 -2
  17. package/dist/api/types/BillingProfile.ts +37 -0
  18. package/dist/api/types/BillingProfileUpdate.ts +37 -0
  19. package/{api → dist/api}/types/BinaryDeltaLimits.ts +6 -0
  20. package/{api → dist/api}/types/BoundingBox.ts +1 -3
  21. package/dist/api/types/Deployment.ts +45 -0
  22. package/{api → dist/api}/types/DeploymentAggregation.ts +1 -3
  23. package/{api → dist/api}/types/DeploymentAggregationItem.ts +1 -3
  24. package/{api → dist/api}/types/DeploymentAggregationTerm.ts +1 -2
  25. package/{api → dist/api}/types/DeploymentAggregationTerms.ts +1 -3
  26. package/{api → dist/api}/types/DeploymentAttributeProjection.ts +1 -2
  27. package/{api → dist/api}/types/DeploymentDeployments.ts +4 -5
  28. package/{api → dist/api}/types/DeploymentFilterTerm.ts +1 -3
  29. package/dist/api/types/DeploymentPhaseDeployments.ts +23 -0
  30. package/{api → dist/api}/types/DeploymentSearchTerms.ts +1 -3
  31. package/{api → dist/api}/types/DeploymentSortTerm.ts +1 -3
  32. package/dist/api/types/DeploymentStatisticsDeployments.ts +15 -0
  33. package/dist/api/types/DeploymentStatusStatisticsDeployments.ts +54 -0
  34. package/dist/api/types/Device.ts +20 -0
  35. package/{api → dist/api}/types/DeviceAggregation.ts +1 -3
  36. package/{api → dist/api}/types/DeviceAggregationItem.ts +1 -3
  37. package/{api → dist/api}/types/DeviceAggregationTerm.ts +1 -2
  38. package/{api → dist/api}/types/DeviceAggregationTerms.ts +1 -3
  39. package/{api → dist/api}/types/DeviceAttribute.ts +1 -2
  40. package/{api → dist/api}/types/DeviceAttributeProjection.ts +1 -2
  41. package/{api/types/Device.ts → dist/api/types/DeviceDeployments.ts} +1 -1
  42. package/{api → dist/api}/types/DeviceFilterAttribute.ts +1 -2
  43. package/{api → dist/api}/types/DeviceFilterTerm.ts +1 -3
  44. package/{api → dist/api}/types/DeviceSearchTerms.ts +1 -3
  45. package/{api → dist/api}/types/DeviceSortTerm.ts +1 -3
  46. package/{api → dist/api}/types/Error.ts +1 -1
  47. package/{api/types/FilterInventory.ts → dist/api/types/Filter.ts} +3 -4
  48. package/{api/types/Filter.ts → dist/api/types/FilterInventory.ts} +1 -1
  49. package/dist/api/types/FilterPredicate.ts +48 -0
  50. package/{api/types/FilterPredicate.ts → dist/api/types/FilterPredicateInventory.ts} +3 -3
  51. package/{api → dist/api}/types/GeoBoundingBox.ts +1 -3
  52. package/{api → dist/api}/types/GeoBoundingBoxFilter.ts +1 -2
  53. package/{api → dist/api}/types/GeoDistance.ts +1 -3
  54. package/{api → dist/api}/types/GeoDistanceFilter.ts +1 -3
  55. package/{api → dist/api}/types/GeoPoint.ts +1 -2
  56. package/{api → dist/api}/types/Integration.ts +6 -0
  57. package/{api → dist/api}/types/MenderTypes.ts +41 -11
  58. package/{api → dist/api}/types/NewDeploymentV2.ts +3 -0
  59. package/{api → dist/api}/types/NewTenant.ts +16 -8
  60. package/{api → dist/api}/types/Object.ts +3 -0
  61. package/{api → dist/api}/types/PreAuthSet.ts +1 -1
  62. package/{api → dist/api}/types/Settings.ts +3 -3
  63. package/{api → dist/api}/types/Status.ts +5 -4
  64. package/{api → dist/api}/types/StatusTenantadm.ts +1 -3
  65. package/dist/api/types/Tenant.ts +21 -0
  66. package/{api → dist/api}/types/TenantTenantadm.ts +16 -0
  67. package/dist/api/types/UpdateChildTenant.ts +17 -0
  68. package/{api → dist/api}/types/UpdateDeployments.ts +1 -1
  69. package/{api → dist/api}/types/UpgradeCompleteRequest.ts +2 -0
  70. package/{api → dist/api}/types/UserWithTenantInfo.ts +7 -3
  71. package/dist/api/users-api.d.mts +16 -0
  72. package/dist/api/users-api.d.ts +16 -0
  73. package/dist/api/users-api.js +1026 -0
  74. package/dist/api/users-api.js.map +1 -0
  75. package/dist/api/users-api.mjs +15 -0
  76. package/dist/api/users-api.mjs.map +1 -0
  77. package/dist/appSlice/constants.d.mts +210 -0
  78. package/dist/appSlice/constants.d.ts +210 -0
  79. package/dist/appSlice/constants.js +221 -0
  80. package/dist/appSlice/constants.js.map +1 -0
  81. package/dist/appSlice/constants.mjs +42 -0
  82. package/dist/appSlice/constants.mjs.map +1 -0
  83. package/dist/appSlice/index.d.mts +1557 -0
  84. package/dist/appSlice/index.d.ts +1557 -0
  85. package/dist/appSlice/index.js +1067 -0
  86. package/dist/appSlice/index.js.map +1 -0
  87. package/dist/appSlice/index.mjs +21 -0
  88. package/dist/appSlice/index.mjs.map +1 -0
  89. package/dist/appSlice/selectors.d.mts +91 -0
  90. package/dist/appSlice/selectors.d.ts +91 -0
  91. package/dist/appSlice/selectors.js +90 -0
  92. package/dist/appSlice/selectors.js.map +1 -0
  93. package/dist/appSlice/selectors.mjs +20 -0
  94. package/dist/appSlice/selectors.mjs.map +1 -0
  95. package/dist/appSlice/thunks.d.mts +46 -0
  96. package/dist/appSlice/thunks.d.ts +46 -0
  97. package/dist/appSlice/thunks.js +5655 -0
  98. package/dist/appSlice/thunks.js.map +1 -0
  99. package/dist/appSlice/thunks.mjs +45 -0
  100. package/dist/appSlice/thunks.mjs.map +1 -0
  101. package/dist/auth.d.mts +17 -0
  102. package/dist/auth.d.ts +17 -0
  103. package/dist/auth.js +985 -0
  104. package/dist/auth.js.map +1 -0
  105. package/dist/auth.mjs +23 -0
  106. package/dist/auth.mjs.map +1 -0
  107. package/dist/chunk-6667TCAJ.mjs +135 -0
  108. package/dist/chunk-6667TCAJ.mjs.map +1 -0
  109. package/{releasesSlice/index.ts → dist/chunk-7E7KJHY3.mjs} +33 -32
  110. package/dist/chunk-7E7KJHY3.mjs.map +1 -0
  111. package/{usersSlice/index.ts → dist/chunk-BJSH2G7W.mjs} +39 -58
  112. package/dist/chunk-BJSH2G7W.mjs.map +1 -0
  113. package/dist/chunk-BOSBROA3.mjs +168 -0
  114. package/dist/chunk-BOSBROA3.mjs.map +1 -0
  115. package/dist/chunk-BRHSKNFC.mjs +70 -0
  116. package/dist/chunk-BRHSKNFC.mjs.map +1 -0
  117. package/dist/chunk-C2YZYTJ6.mjs +37 -0
  118. package/dist/chunk-C2YZYTJ6.mjs.map +1 -0
  119. package/dist/chunk-DZBVTSIX.mjs +55 -0
  120. package/dist/chunk-DZBVTSIX.mjs.map +1 -0
  121. package/{appSlice/index.ts → dist/chunk-F37LUTBX.mjs} +58 -68
  122. package/dist/chunk-F37LUTBX.mjs.map +1 -0
  123. package/dist/chunk-G32LAKW4.mjs +239 -0
  124. package/dist/chunk-G32LAKW4.mjs.map +1 -0
  125. package/dist/chunk-G3I53JGW.mjs +243 -0
  126. package/dist/chunk-G3I53JGW.mjs.map +1 -0
  127. package/dist/chunk-G4FGNSV3.mjs +13 -0
  128. package/dist/chunk-G4FGNSV3.mjs.map +1 -0
  129. package/dist/chunk-G7LATUT6.mjs +110 -0
  130. package/dist/chunk-G7LATUT6.mjs.map +1 -0
  131. package/dist/chunk-H2PQQMRY.mjs +7 -0
  132. package/dist/chunk-H2PQQMRY.mjs.map +1 -0
  133. package/{devicesSlice/index.ts → dist/chunk-HRWZJQMH.mjs} +57 -77
  134. package/dist/chunk-HRWZJQMH.mjs.map +1 -0
  135. package/dist/chunk-HVHZG2H4.mjs +56 -0
  136. package/dist/chunk-HVHZG2H4.mjs.map +1 -0
  137. package/dist/chunk-HXPYJ6QN.mjs +75 -0
  138. package/dist/chunk-HXPYJ6QN.mjs.map +1 -0
  139. package/dist/chunk-IPPIKGIB.mjs +35 -0
  140. package/dist/chunk-IPPIKGIB.mjs.map +1 -0
  141. package/dist/chunk-IU4OXOPA.mjs +46 -0
  142. package/dist/chunk-IU4OXOPA.mjs.map +1 -0
  143. package/dist/chunk-IVSYYXTC.mjs +36 -0
  144. package/dist/chunk-IVSYYXTC.mjs.map +1 -0
  145. package/{onboardingSlice/index.ts → dist/chunk-M4U5R7A4.mjs} +19 -22
  146. package/dist/chunk-M4U5R7A4.mjs.map +1 -0
  147. package/dist/chunk-N7G6QK2E.mjs +414 -0
  148. package/dist/chunk-N7G6QK2E.mjs.map +1 -0
  149. package/dist/chunk-O6O3D52B.mjs +39 -0
  150. package/dist/chunk-O6O3D52B.mjs.map +1 -0
  151. package/dist/chunk-QBKCUIWO.mjs +7 -0
  152. package/dist/chunk-QBKCUIWO.mjs.map +1 -0
  153. package/dist/chunk-R2GBNXLV.mjs +57 -0
  154. package/dist/chunk-R2GBNXLV.mjs.map +1 -0
  155. package/dist/chunk-RH6ONMG7.mjs +65 -0
  156. package/dist/chunk-RH6ONMG7.mjs.map +1 -0
  157. package/dist/chunk-RQOE5OOT.mjs +284 -0
  158. package/dist/chunk-RQOE5OOT.mjs.map +1 -0
  159. package/dist/chunk-TD45YTYK.mjs +108 -0
  160. package/dist/chunk-TD45YTYK.mjs.map +1 -0
  161. package/dist/chunk-V32GTKOS.mjs +1 -0
  162. package/dist/chunk-V32GTKOS.mjs.map +1 -0
  163. package/dist/chunk-XWBD7VOK.mjs +93 -0
  164. package/dist/chunk-XWBD7VOK.mjs.map +1 -0
  165. package/dist/chunk-XYVPYFSM.mjs +106 -0
  166. package/dist/chunk-XYVPYFSM.mjs.map +1 -0
  167. package/dist/chunk-YNVSU3AA.mjs +2977 -0
  168. package/dist/chunk-YNVSU3AA.mjs.map +1 -0
  169. package/dist/chunk-ZIYGEXSJ.mjs +145 -0
  170. package/dist/chunk-ZIYGEXSJ.mjs.map +1 -0
  171. package/dist/chunk-ZNST5R6O.mjs +658 -0
  172. package/dist/chunk-ZNST5R6O.mjs.map +1 -0
  173. package/dist/commonConstants.d.mts +248 -0
  174. package/dist/commonConstants.d.ts +248 -0
  175. package/dist/commonConstants.js +303 -0
  176. package/dist/commonConstants.js.map +1 -0
  177. package/dist/commonConstants.mjs +40 -0
  178. package/dist/commonConstants.mjs.map +1 -0
  179. package/dist/commonSelectors.d.mts +896 -0
  180. package/dist/commonSelectors.d.ts +896 -0
  181. package/dist/commonSelectors.js +1482 -0
  182. package/dist/commonSelectors.js.map +1 -0
  183. package/dist/commonSelectors.mjs +54 -0
  184. package/dist/commonSelectors.mjs.map +1 -0
  185. package/dist/constants.d.mts +12 -0
  186. package/dist/constants.d.ts +12 -0
  187. package/dist/constants.js +1246 -0
  188. package/dist/constants.js.map +1 -0
  189. package/dist/constants.mjs +219 -0
  190. package/dist/constants.mjs.map +1 -0
  191. package/dist/deploymentsSlice/constants.d.mts +142 -0
  192. package/dist/deploymentsSlice/constants.d.ts +142 -0
  193. package/dist/deploymentsSlice/constants.js +969 -0
  194. package/dist/deploymentsSlice/constants.js.map +1 -0
  195. package/dist/deploymentsSlice/constants.mjs +42 -0
  196. package/dist/deploymentsSlice/constants.mjs.map +1 -0
  197. package/dist/deploymentsSlice/index.d.mts +2373 -0
  198. package/dist/deploymentsSlice/index.d.ts +2373 -0
  199. package/dist/deploymentsSlice/index.js +1053 -0
  200. package/dist/deploymentsSlice/index.js.map +1 -0
  201. package/dist/deploymentsSlice/index.mjs +21 -0
  202. package/dist/deploymentsSlice/index.mjs.map +1 -0
  203. package/dist/deploymentsSlice/selectors.d.mts +59 -0
  204. package/dist/deploymentsSlice/selectors.d.ts +59 -0
  205. package/dist/deploymentsSlice/selectors.js +969 -0
  206. package/dist/deploymentsSlice/selectors.js.map +1 -0
  207. package/dist/deploymentsSlice/selectors.mjs +25 -0
  208. package/dist/deploymentsSlice/selectors.mjs.map +1 -0
  209. package/dist/deploymentsSlice/thunks.d.mts +202 -0
  210. package/dist/deploymentsSlice/thunks.d.ts +202 -0
  211. package/dist/deploymentsSlice/thunks.js +5671 -0
  212. package/dist/deploymentsSlice/thunks.js.map +1 -0
  213. package/dist/deploymentsSlice/thunks.mjs +63 -0
  214. package/dist/deploymentsSlice/thunks.mjs.map +1 -0
  215. package/dist/devicesSlice/constants.d.mts +44 -0
  216. package/dist/devicesSlice/constants.d.ts +44 -0
  217. package/dist/devicesSlice/constants.js +969 -0
  218. package/dist/devicesSlice/constants.js.map +1 -0
  219. package/dist/devicesSlice/constants.mjs +40 -0
  220. package/dist/devicesSlice/constants.mjs.map +1 -0
  221. package/dist/devicesSlice/index.d.mts +2223 -0
  222. package/dist/devicesSlice/index.d.ts +2223 -0
  223. package/dist/devicesSlice/index.js +1109 -0
  224. package/dist/devicesSlice/index.js.map +1 -0
  225. package/dist/devicesSlice/index.mjs +21 -0
  226. package/dist/devicesSlice/index.mjs.map +1 -0
  227. package/dist/devicesSlice/selectors.d.mts +261 -0
  228. package/dist/devicesSlice/selectors.d.ts +261 -0
  229. package/dist/devicesSlice/selectors.js +1084 -0
  230. package/dist/devicesSlice/selectors.js.map +1 -0
  231. package/dist/devicesSlice/selectors.mjs +53 -0
  232. package/dist/devicesSlice/selectors.mjs.map +1 -0
  233. package/dist/devicesSlice/thunks.d.mts +742 -0
  234. package/dist/devicesSlice/thunks.d.ts +742 -0
  235. package/dist/devicesSlice/thunks.js +5743 -0
  236. package/dist/devicesSlice/thunks.js.map +1 -0
  237. package/dist/devicesSlice/thunks.mjs +135 -0
  238. package/dist/devicesSlice/thunks.mjs.map +1 -0
  239. package/dist/monitorSlice/constants.d.mts +6 -0
  240. package/dist/monitorSlice/constants.d.ts +6 -0
  241. package/dist/monitorSlice/constants.js +919 -0
  242. package/dist/monitorSlice/constants.js.map +1 -0
  243. package/dist/monitorSlice/constants.mjs +14 -0
  244. package/dist/monitorSlice/constants.mjs.map +1 -0
  245. package/dist/monitorSlice/index.d.mts +291 -0
  246. package/dist/monitorSlice/index.d.ts +291 -0
  247. package/dist/monitorSlice/index.js +971 -0
  248. package/dist/monitorSlice/index.js.map +1 -0
  249. package/dist/monitorSlice/index.mjs +21 -0
  250. package/dist/monitorSlice/index.mjs.map +1 -0
  251. package/dist/monitorSlice/selectors.d.mts +3 -0
  252. package/dist/monitorSlice/selectors.d.ts +3 -0
  253. package/dist/monitorSlice/selectors.js +31 -0
  254. package/dist/monitorSlice/selectors.js.map +1 -0
  255. package/dist/monitorSlice/selectors.mjs +8 -0
  256. package/dist/monitorSlice/selectors.mjs.map +1 -0
  257. package/dist/monitorSlice/thunks.d.mts +71 -0
  258. package/dist/monitorSlice/thunks.d.ts +71 -0
  259. package/dist/monitorSlice/thunks.js +2531 -0
  260. package/dist/monitorSlice/thunks.js.map +1 -0
  261. package/dist/monitorSlice/thunks.mjs +44 -0
  262. package/dist/monitorSlice/thunks.mjs.map +1 -0
  263. package/dist/onboardingSlice/constants.d.mts +23 -0
  264. package/dist/onboardingSlice/constants.d.ts +23 -0
  265. package/dist/onboardingSlice/constants.js +71 -0
  266. package/dist/onboardingSlice/constants.js.map +1 -0
  267. package/dist/onboardingSlice/constants.mjs +10 -0
  268. package/dist/onboardingSlice/constants.mjs.map +1 -0
  269. package/dist/onboardingSlice/index.d.mts +237 -0
  270. package/dist/onboardingSlice/index.d.ts +237 -0
  271. package/dist/onboardingSlice/index.js +94 -0
  272. package/dist/onboardingSlice/index.js.map +1 -0
  273. package/dist/onboardingSlice/index.mjs +16 -0
  274. package/dist/onboardingSlice/index.mjs.map +1 -0
  275. package/dist/onboardingSlice/selectors.d.mts +3 -0
  276. package/dist/onboardingSlice/selectors.d.ts +3 -0
  277. package/dist/onboardingSlice/selectors.js +31 -0
  278. package/dist/onboardingSlice/selectors.js.map +1 -0
  279. package/dist/onboardingSlice/selectors.mjs +8 -0
  280. package/dist/onboardingSlice/selectors.mjs.map +1 -0
  281. package/dist/onboardingSlice/thunks.d.mts +172 -0
  282. package/dist/onboardingSlice/thunks.d.ts +172 -0
  283. package/dist/onboardingSlice/thunks.js +5661 -0
  284. package/dist/onboardingSlice/thunks.js.map +1 -0
  285. package/dist/onboardingSlice/thunks.mjs +51 -0
  286. package/dist/onboardingSlice/thunks.mjs.map +1 -0
  287. package/dist/organizationSlice/constants.d.mts +134 -0
  288. package/dist/organizationSlice/constants.d.ts +134 -0
  289. package/dist/organizationSlice/constants.js +978 -0
  290. package/dist/organizationSlice/constants.js.map +1 -0
  291. package/dist/organizationSlice/constants.mjs +34 -0
  292. package/dist/organizationSlice/constants.mjs.map +1 -0
  293. package/dist/organizationSlice/index.d.mts +1097 -0
  294. package/dist/organizationSlice/index.d.ts +1097 -0
  295. package/dist/organizationSlice/index.js +1015 -0
  296. package/dist/organizationSlice/index.js.map +1 -0
  297. package/dist/organizationSlice/index.mjs +21 -0
  298. package/dist/organizationSlice/index.mjs.map +1 -0
  299. package/dist/organizationSlice/selectors.d.mts +134 -0
  300. package/dist/organizationSlice/selectors.d.ts +134 -0
  301. package/dist/organizationSlice/selectors.js +977 -0
  302. package/dist/organizationSlice/selectors.js.map +1 -0
  303. package/dist/organizationSlice/selectors.mjs +39 -0
  304. package/dist/organizationSlice/selectors.mjs.map +1 -0
  305. package/dist/organizationSlice/thunks.d.mts +502 -0
  306. package/dist/organizationSlice/thunks.d.ts +502 -0
  307. package/dist/organizationSlice/thunks.js +5709 -0
  308. package/dist/organizationSlice/thunks.js.map +1 -0
  309. package/dist/organizationSlice/thunks.mjs +101 -0
  310. package/dist/organizationSlice/thunks.mjs.map +1 -0
  311. package/dist/releasesSlice/constants.d.mts +14 -0
  312. package/dist/releasesSlice/constants.d.ts +14 -0
  313. package/dist/releasesSlice/constants.js +40 -0
  314. package/dist/releasesSlice/constants.js.map +1 -0
  315. package/dist/releasesSlice/constants.mjs +14 -0
  316. package/dist/releasesSlice/constants.mjs.map +1 -0
  317. package/dist/releasesSlice/index.d.mts +483 -0
  318. package/dist/releasesSlice/index.d.ts +483 -0
  319. package/dist/releasesSlice/index.js +1034 -0
  320. package/dist/releasesSlice/index.js.map +1 -0
  321. package/dist/releasesSlice/index.mjs +21 -0
  322. package/dist/releasesSlice/index.mjs.map +1 -0
  323. package/dist/releasesSlice/selectors.d.mts +92 -0
  324. package/dist/releasesSlice/selectors.d.ts +92 -0
  325. package/dist/releasesSlice/selectors.js +967 -0
  326. package/dist/releasesSlice/selectors.js.map +1 -0
  327. package/dist/releasesSlice/selectors.mjs +28 -0
  328. package/dist/releasesSlice/selectors.mjs.map +1 -0
  329. package/dist/releasesSlice/thunks.d.mts +276 -0
  330. package/dist/releasesSlice/thunks.d.ts +276 -0
  331. package/dist/releasesSlice/thunks.js +2843 -0
  332. package/dist/releasesSlice/thunks.js.map +1 -0
  333. package/dist/releasesSlice/thunks.mjs +66 -0
  334. package/dist/releasesSlice/thunks.mjs.map +1 -0
  335. package/dist/selectors.d.mts +10 -0
  336. package/dist/selectors.d.ts +10 -0
  337. package/dist/selectors.js +1636 -0
  338. package/dist/selectors.js.map +1 -0
  339. package/dist/selectors.mjs +207 -0
  340. package/dist/selectors.mjs.map +1 -0
  341. package/dist/store.d.mts +2306 -0
  342. package/dist/store.d.ts +2306 -0
  343. package/dist/store.js +1877 -0
  344. package/dist/store.js.map +1 -0
  345. package/dist/store.mjs +32 -0
  346. package/dist/store.mjs.map +1 -0
  347. package/dist/storehooks.d.mts +4 -0
  348. package/dist/storehooks.d.ts +4 -0
  349. package/dist/storehooks.js +5844 -0
  350. package/dist/storehooks.js.map +1 -0
  351. package/dist/storehooks.mjs +265 -0
  352. package/dist/storehooks.mjs.map +1 -0
  353. package/dist/thunks.d.mts +12 -0
  354. package/dist/thunks.d.ts +12 -0
  355. package/dist/thunks.js +5973 -0
  356. package/dist/thunks.js.map +1 -0
  357. package/dist/thunks.mjs +363 -0
  358. package/dist/thunks.mjs.map +1 -0
  359. package/dist/usersSlice/constants.d.mts +635 -0
  360. package/dist/usersSlice/constants.d.ts +635 -0
  361. package/dist/usersSlice/constants.js +967 -0
  362. package/dist/usersSlice/constants.js.map +1 -0
  363. package/dist/usersSlice/constants.mjs +43 -0
  364. package/dist/usersSlice/constants.mjs.map +1 -0
  365. package/dist/usersSlice/index.d.mts +6993 -0
  366. package/dist/usersSlice/index.d.ts +6993 -0
  367. package/dist/usersSlice/index.js +1054 -0
  368. package/dist/usersSlice/index.js.map +1 -0
  369. package/dist/usersSlice/index.mjs +21 -0
  370. package/dist/usersSlice/index.mjs.map +1 -0
  371. package/dist/usersSlice/selectors.d.mts +209 -0
  372. package/dist/usersSlice/selectors.d.ts +209 -0
  373. package/dist/usersSlice/selectors.js +997 -0
  374. package/dist/usersSlice/selectors.js.map +1 -0
  375. package/dist/usersSlice/selectors.mjs +38 -0
  376. package/dist/usersSlice/selectors.mjs.map +1 -0
  377. package/dist/usersSlice/thunks.d.mts +881 -0
  378. package/dist/usersSlice/thunks.d.ts +881 -0
  379. package/dist/usersSlice/thunks.js +5717 -0
  380. package/dist/usersSlice/thunks.js.map +1 -0
  381. package/dist/usersSlice/thunks.mjs +109 -0
  382. package/dist/usersSlice/thunks.mjs.map +1 -0
  383. package/dist/utils.d.mts +60 -0
  384. package/dist/utils.d.ts +60 -0
  385. package/dist/utils.js +1160 -0
  386. package/dist/utils.js.map +1 -0
  387. package/dist/utils.mjs +49 -0
  388. package/dist/utils.mjs.map +1 -0
  389. package/package.json +22 -5
  390. package/.eslintrc.cjs +0 -9
  391. package/.prettierignore +0 -1
  392. package/CHANGELOG.md +0 -19
  393. package/actions.ts +0 -32
  394. package/api/general-api.test.ts +0 -51
  395. package/api/general-api.ts +0 -60
  396. package/api/types/Deployment.ts +0 -95
  397. package/api/types/DeviceDeployments.ts +0 -31
  398. package/api/types/FilterPredicateInventory.ts +0 -76
  399. package/api/types/Tenant.ts +0 -38
  400. package/api/users-api.ts +0 -34
  401. package/appSlice/constants.ts +0 -166
  402. package/appSlice/reducer.test.ts +0 -97
  403. package/appSlice/selectors.ts +0 -33
  404. package/appSlice/thunks.test.ts +0 -118
  405. package/appSlice/thunks.ts +0 -148
  406. package/auth.test.ts +0 -36
  407. package/auth.ts +0 -82
  408. package/commonConstants.tsx +0 -252
  409. package/commonSelectors.ts +0 -255
  410. package/constants.ts +0 -22
  411. package/deploymentsSlice/constants.ts +0 -175
  412. package/deploymentsSlice/index.ts +0 -145
  413. package/deploymentsSlice/reducer.test.ts +0 -108
  414. package/deploymentsSlice/selectors.ts +0 -58
  415. package/deploymentsSlice/thunks.test.ts +0 -425
  416. package/deploymentsSlice/thunks.ts +0 -382
  417. package/devicesSlice/constants.ts +0 -56
  418. package/devicesSlice/reducer.test.ts +0 -194
  419. package/devicesSlice/selectors.ts +0 -127
  420. package/devicesSlice/thunks.test.tsx +0 -1245
  421. package/devicesSlice/thunks.tsx +0 -1098
  422. package/monitorSlice/constants.ts +0 -17
  423. package/monitorSlice/index.ts +0 -65
  424. package/monitorSlice/reducer.test.ts +0 -79
  425. package/monitorSlice/selectors.ts +0 -15
  426. package/monitorSlice/thunks.test.ts +0 -112
  427. package/monitorSlice/thunks.ts +0 -101
  428. package/onboardingSlice/constants.ts +0 -53
  429. package/onboardingSlice/reducer.test.ts +0 -45
  430. package/onboardingSlice/selectors.ts +0 -15
  431. package/onboardingSlice/thunks.test.ts +0 -235
  432. package/onboardingSlice/thunks.ts +0 -142
  433. package/organizationSlice/constants.ts +0 -82
  434. package/organizationSlice/index.ts +0 -111
  435. package/organizationSlice/reducer.test.ts +0 -78
  436. package/organizationSlice/selectors.ts +0 -45
  437. package/organizationSlice/thunks.test.ts +0 -619
  438. package/organizationSlice/thunks.ts +0 -383
  439. package/releasesSlice/constants.ts +0 -18
  440. package/releasesSlice/reducer.test.ts +0 -78
  441. package/releasesSlice/selectors.ts +0 -33
  442. package/releasesSlice/thunks.test.ts +0 -389
  443. package/releasesSlice/thunks.ts +0 -379
  444. package/selectors.ts +0 -22
  445. package/store.ts +0 -89
  446. package/storehooks.test.tsx +0 -386
  447. package/storehooks.ts +0 -250
  448. package/thunks.ts +0 -21
  449. package/tsconfig.json +0 -11
  450. package/tsup.config.ts +0 -11
  451. package/usersSlice/constants.ts +0 -374
  452. package/usersSlice/reducer.test.ts +0 -141
  453. package/usersSlice/selectors.ts +0 -60
  454. package/usersSlice/thunks.test.ts +0 -660
  455. package/usersSlice/thunks.ts +0 -773
  456. package/utils.test.ts +0 -187
  457. package/utils.ts +0 -249
  458. /package/{api → dist/api}/types/AWSCredentials.ts +0 -0
  459. /package/{api → dist/api}/types/Actor.ts +0 -0
  460. /package/{api → dist/api}/types/Addon.ts +0 -0
  461. /package/{api → dist/api}/types/AddonTenantadm.ts +0 -0
  462. /package/{api → dist/api}/types/Alert.ts +0 -0
  463. /package/{api → dist/api}/types/AlertDetails.ts +0 -0
  464. /package/{api → dist/api}/types/AlertSubject.ts +0 -0
  465. /package/{api → dist/api}/types/ApiBurst.ts +0 -0
  466. /package/{api → dist/api}/types/ApiBurstTenantadm.ts +0 -0
  467. /package/{api → dist/api}/types/ApiLimits.ts +0 -0
  468. /package/{api → dist/api}/types/ApiLimitsTenantadm.ts +0 -0
  469. /package/{api → dist/api}/types/ApiQuota.ts +0 -0
  470. /package/{api → dist/api}/types/ApiQuotaTenantadm.ts +0 -0
  471. /package/{api → dist/api}/types/Artifact.ts +0 -0
  472. /package/{api → dist/api}/types/ArtifactDeployments.ts +0 -0
  473. /package/{api → dist/api}/types/ArtifactInfo.ts +0 -0
  474. /package/{api → dist/api}/types/ArtifactInfoDeployments.ts +0 -0
  475. /package/{api → dist/api}/types/ArtifactLink.ts +0 -0
  476. /package/{api → dist/api}/types/ArtifactTypeInfo.ts +0 -0
  477. /package/{api → dist/api}/types/ArtifactTypeInfoDeployments.ts +0 -0
  478. /package/{api → dist/api}/types/ArtifactUpdate.ts +0 -0
  479. /package/{api → dist/api}/types/ArtifactUploadLink.ts +0 -0
  480. /package/{api → dist/api}/types/Attribute.ts +0 -0
  481. /package/{api → dist/api}/types/AttributeInventory.ts +0 -0
  482. /package/{api → dist/api}/types/AuditLog.ts +0 -0
  483. /package/{api → dist/api}/types/AuthSetDeviceauth.ts +0 -0
  484. /package/{api → dist/api}/types/AutoAuthRequest.ts +0 -0
  485. /package/{api → dist/api}/types/AzureSharedAccessSecret.ts +0 -0
  486. /package/{api → dist/api}/types/BillingInfo.ts +0 -0
  487. /package/{api → dist/api}/types/BinaryDeltaConfiguration.ts +0 -0
  488. /package/{api → dist/api}/types/BinaryDeltaConfigurationDeployments.ts +0 -0
  489. /package/{api → dist/api}/types/BinaryDeltaLimitsDeployments.ts +0 -0
  490. /package/{api → dist/api}/types/CancelRequest.ts +0 -0
  491. /package/{api → dist/api}/types/CardData.ts +0 -0
  492. /package/{api → dist/api}/types/CardSetupData.ts +0 -0
  493. /package/{api → dist/api}/types/CheckoutData.ts +0 -0
  494. /package/{api → dist/api}/types/Configuration.ts +0 -0
  495. /package/{api → dist/api}/types/Count.ts +0 -0
  496. /package/{api → dist/api}/types/Credentials.ts +0 -0
  497. /package/{api → dist/api}/types/DBusSubsystem.ts +0 -0
  498. /package/{api → dist/api}/types/DeltaConfiguration.ts +0 -0
  499. /package/{api → dist/api}/types/DeltaConfigurationDeployments.ts +0 -0
  500. /package/{api → dist/api}/types/DeploymentAuditlogs.ts +0 -0
  501. /package/{api → dist/api}/types/DeploymentIdentifier.ts +0 -0
  502. /package/{api → dist/api}/types/DeploymentPhase.ts +0 -0
  503. /package/{api → dist/api}/types/DeploymentReporting.ts +0 -0
  504. /package/{api → dist/api}/types/DeploymentStatistics.ts +0 -0
  505. /package/{api → dist/api}/types/DeploymentStatusStatistics.ts +0 -0
  506. /package/{api → dist/api}/types/DeviceAuditlogs.ts +0 -0
  507. /package/{api → dist/api}/types/DeviceAuthEvent.ts +0 -0
  508. /package/{api → dist/api}/types/DeviceConfiguration.ts +0 -0
  509. /package/{api → dist/api}/types/DeviceDeployment.ts +0 -0
  510. /package/{api → dist/api}/types/DeviceDeviceauth.ts +0 -0
  511. /package/{api → dist/api}/types/DeviceInventory.ts +0 -0
  512. /package/{api → dist/api}/types/DeviceInventoryInventory.ts +0 -0
  513. /package/{api → dist/api}/types/DeviceReporting.ts +0 -0
  514. /package/{api → dist/api}/types/DeviceState.ts +0 -0
  515. /package/{api → dist/api}/types/DeviceStateDeviceconnect.ts +0 -0
  516. /package/{api → dist/api}/types/DeviceStateIot_manager.ts +0 -0
  517. /package/{api → dist/api}/types/DeviceStatus.ts +0 -0
  518. /package/{api → dist/api}/types/DeviceWithImage.ts +0 -0
  519. /package/{api → dist/api}/types/DirectUploadMetadata.ts +0 -0
  520. /package/{api → dist/api}/types/EmailVerificationCompletion.ts +0 -0
  521. /package/{api → dist/api}/types/EmailVerificationRequest.ts +0 -0
  522. /package/{api → dist/api}/types/ErrorAuditlogs.ts +0 -0
  523. /package/{api → dist/api}/types/ErrorDeployments.ts +0 -0
  524. /package/{api → dist/api}/types/ErrorDeviceauth.ts +0 -0
  525. /package/{api → dist/api}/types/ErrorDeviceconfig.ts +0 -0
  526. /package/{api → dist/api}/types/ErrorDeviceconnect.ts +0 -0
  527. /package/{api → dist/api}/types/ErrorDevicemonitor.ts +0 -0
  528. /package/{api → dist/api}/types/ErrorExt.ts +0 -0
  529. /package/{api → dist/api}/types/ErrorInventory.ts +0 -0
  530. /package/{api → dist/api}/types/ErrorIot_manager.ts +0 -0
  531. /package/{api → dist/api}/types/ErrorNotFound.ts +0 -0
  532. /package/{api → dist/api}/types/ErrorReporting.ts +0 -0
  533. /package/{api → dist/api}/types/ErrorTenantadm.ts +0 -0
  534. /package/{api → dist/api}/types/ErrorUseradm.ts +0 -0
  535. /package/{api → dist/api}/types/Event.ts +0 -0
  536. /package/{api → dist/api}/types/ExternalIdentity.ts +0 -0
  537. /package/{api → dist/api}/types/Features.ts +0 -0
  538. /package/{api → dist/api}/types/FileUpload.ts +0 -0
  539. /package/{api → dist/api}/types/FilterAttribute.ts +0 -0
  540. /package/{api → dist/api}/types/FilterDefinition.ts +0 -0
  541. /package/{api → dist/api}/types/FilterDeployments.ts +0 -0
  542. /package/{api → dist/api}/types/FilterPredicateDeployments.ts +0 -0
  543. /package/{api → dist/api}/types/Group.ts +0 -0
  544. /package/{api → dist/api}/types/HTTP.ts +0 -0
  545. /package/{api → dist/api}/types/IdentityData.ts +0 -0
  546. /package/{api → dist/api}/types/InputParameter.ts +0 -0
  547. /package/{api → dist/api}/types/JobStatus.ts +0 -0
  548. /package/{api → dist/api}/types/Limit.ts +0 -0
  549. /package/{api → dist/api}/types/LimitDeployments.ts +0 -0
  550. /package/{api → dist/api}/types/LimitDeviceauth.ts +0 -0
  551. /package/{api → dist/api}/types/LimitUseradm.ts +0 -0
  552. /package/{api → dist/api}/types/Limits.ts +0 -0
  553. /package/{api → dist/api}/types/LineDescriptor.ts +0 -0
  554. /package/{api → dist/api}/types/LogSubsystem.ts +0 -0
  555. /package/{api → dist/api}/types/LoginOptions.ts +0 -0
  556. /package/{api → dist/api}/types/ManagementAPIConfiguration.ts +0 -0
  557. /package/{api → dist/api}/types/MonitorConfiguration.ts +0 -0
  558. /package/{api → dist/api}/types/NewConfigurationDeployment.ts +0 -0
  559. /package/{api → dist/api}/types/NewConfigurationDeploymentResponse.ts +0 -0
  560. /package/{api → dist/api}/types/NewDeployment.ts +0 -0
  561. /package/{api → dist/api}/types/NewDeploymentForGroup.ts +0 -0
  562. /package/{api → dist/api}/types/NewDeploymentPhase.ts +0 -0
  563. /package/{api → dist/api}/types/NewDeploymentPhaseDeployments.ts +0 -0
  564. /package/{api → dist/api}/types/OwnUserUpdate.ts +0 -0
  565. /package/{api → dist/api}/types/PasswordResetCompletion.ts +0 -0
  566. /package/{api → dist/api}/types/PasswordResetRequest.ts +0 -0
  567. /package/{api → dist/api}/types/Permission.ts +0 -0
  568. /package/{api → dist/api}/types/PermissionObject.ts +0 -0
  569. /package/{api → dist/api}/types/PermissionSet.ts +0 -0
  570. /package/{api → dist/api}/types/PermissionSetWithScope.ts +0 -0
  571. /package/{api → dist/api}/types/PersonalAccessToken.ts +0 -0
  572. /package/{api → dist/api}/types/PersonalAccessTokenRequest.ts +0 -0
  573. /package/{api → dist/api}/types/Plan.ts +0 -0
  574. /package/{api → dist/api}/types/PlanBindingDetails.ts +0 -0
  575. /package/{api → dist/api}/types/PlanChangeRequest.ts +0 -0
  576. /package/{api → dist/api}/types/PlanLimits.ts +0 -0
  577. /package/{api → dist/api}/types/Release.ts +0 -0
  578. /package/{api → dist/api}/types/ReleaseDeployments.ts +0 -0
  579. /package/{api → dist/api}/types/ReleaseUpdate.ts +0 -0
  580. /package/{api → dist/api}/types/Releases.ts +0 -0
  581. /package/{api → dist/api}/types/ReleasesDeleteError.ts +0 -0
  582. /package/{api → dist/api}/types/ReleasesDeployments.ts +0 -0
  583. /package/{api → dist/api}/types/Role.ts +0 -0
  584. /package/{api → dist/api}/types/RolePermission.ts +0 -0
  585. /package/{api → dist/api}/types/RolePermissionObject.ts +0 -0
  586. /package/{api → dist/api}/types/RoleUseradm.ts +0 -0
  587. /package/{api → dist/api}/types/SAMLMetadata.ts +0 -0
  588. /package/{api → dist/api}/types/Scope.ts +0 -0
  589. /package/{api → dist/api}/types/SelectAttribute.ts +0 -0
  590. /package/{api → dist/api}/types/ServiceSubsystem.ts +0 -0
  591. /package/{api → dist/api}/types/SortCriteria.ts +0 -0
  592. /package/{api → dist/api}/types/SsoObject.ts +0 -0
  593. /package/{api → dist/api}/types/StatusDeviceauth.ts +0 -0
  594. /package/{api → dist/api}/types/StorageLimit.ts +0 -0
  595. /package/{api → dist/api}/types/SubscriptionData.ts +0 -0
  596. /package/{api → dist/api}/types/SupportRequest.ts +0 -0
  597. /package/{api → dist/api}/types/Tag.ts +0 -0
  598. /package/{api → dist/api}/types/Tags.ts +0 -0
  599. /package/{api → dist/api}/types/TaskResult.ts +0 -0
  600. /package/{api → dist/api}/types/TaskResultCLI.ts +0 -0
  601. /package/{api → dist/api}/types/TaskResultHTTPRequest.ts +0 -0
  602. /package/{api → dist/api}/types/TaskResultHTTPResponse.ts +0 -0
  603. /package/{api → dist/api}/types/TenantApiLimits.ts +0 -0
  604. /package/{api → dist/api}/types/TenantApiLimitsTenantadm.ts +0 -0
  605. /package/{api → dist/api}/types/TenantIdName.ts +0 -0
  606. /package/{api → dist/api}/types/TenantIdsData.ts +0 -0
  607. /package/{api → dist/api}/types/TenantInfo.ts +0 -0
  608. /package/{api → dist/api}/types/TenantShortInfo.ts +0 -0
  609. /package/{api → dist/api}/types/TenantsIdName.ts +0 -0
  610. /package/{api → dist/api}/types/Update.ts +0 -0
  611. /package/{api → dist/api}/types/UpdateFile.ts +0 -0
  612. /package/{api → dist/api}/types/UpdateFileDeployments.ts +0 -0
  613. /package/{api → dist/api}/types/UpdateTypes.ts +0 -0
  614. /package/{api → dist/api}/types/User.ts +0 -0
  615. /package/{api → dist/api}/types/UserAuditlogs.ts +0 -0
  616. /package/{api → dist/api}/types/UserNew.ts +0 -0
  617. /package/{api → dist/api}/types/UserUpdate.ts +0 -0
  618. /package/{api → dist/api}/types/UserUseradm.ts +0 -0
  619. /package/{api → dist/api}/types/XDeltaArgs.ts +0 -0
  620. /package/{api → dist/api}/types/XDeltaArgsDeployments.ts +0 -0
  621. /package/{api → dist/api}/types/XDeltaArgsLimits.ts +0 -0
  622. /package/{api → dist/api}/types/XDeltaArgsLimitsDeployments.ts +0 -0
@@ -1,1098 +0,0 @@
1
- // Copyright 2024 Northern.tech AS
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- // @ts-nocheck
15
-
16
- /*eslint import/namespace: ['error', { allowComputed: true }]*/
17
- import React from 'react';
18
- import { Link } from 'react-router-dom';
19
-
20
- import storeActions from '@northern.tech/store/actions';
21
- import GeneralApi from '@northern.tech/store/api/general-api';
22
- import {
23
- ALL_DEVICES,
24
- DEVICE_FILTERING_OPTIONS,
25
- DEVICE_LIST_DEFAULTS,
26
- EXTERNAL_PROVIDER,
27
- MAX_PAGE_SIZE,
28
- SORTING_OPTIONS,
29
- TIMEOUTS,
30
- UNGROUPED_GROUP,
31
- auditLogsApiUrl,
32
- defaultReports,
33
- headerNames,
34
- rootfsImageVersion
35
- } from '@northern.tech/store/constants';
36
- import {
37
- getAttrsEndpoint,
38
- getCurrentUser,
39
- getDeviceTwinIntegrations,
40
- getGlobalSettings,
41
- getIdAttribute,
42
- getSearchEndpoint,
43
- getTenantCapabilities,
44
- getUserCapabilities,
45
- getUserSettings
46
- } from '@northern.tech/store/selectors';
47
- import { commonErrorFallback, commonErrorHandler } from '@northern.tech/store/store';
48
- import { getDeviceMonitorConfig, getLatestDeviceAlerts, getSingleDeployment, saveGlobalSettings } from '@northern.tech/store/thunks';
49
- import {
50
- convertDeviceListStateToFilters,
51
- extractErrorMessage,
52
- filtersFilter,
53
- mapDeviceAttributes,
54
- mapFiltersToTerms,
55
- mapTermsToFilters,
56
- progress
57
- } from '@northern.tech/store/utils';
58
- import { attributeDuplicateFilter, deepCompare, getSnackbarMessage } from '@northern.tech/utils/helpers';
59
- import { createAsyncThunk } from '@reduxjs/toolkit';
60
- import { isCancel } from 'axios';
61
- import pluralize from 'pluralize';
62
- import { v4 as uuid } from 'uuid';
63
-
64
- import { actions, sliceName } from '.';
65
- import {
66
- ALL_DEVICE_STATES,
67
- DEVICE_STATES,
68
- deviceAuthV2,
69
- deviceConfig,
70
- deviceConnect,
71
- emptyFilter,
72
- geoAttributes,
73
- inventoryApiUrl,
74
- inventoryApiUrlV2,
75
- iotManagerBaseURL,
76
- reportingApiUrl
77
- } from './constants';
78
- import {
79
- getDeviceById as getDeviceByIdSelector,
80
- getDeviceFilters,
81
- getDeviceListState,
82
- getDevicesById,
83
- getGroupsById,
84
- getGroups as getGroupsSelector,
85
- getSelectedGroup
86
- } from './selectors';
87
-
88
- const { cleanUpUpload, initUpload, setSnackbar, uploadProgress } = storeActions;
89
- const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
90
-
91
- const defaultAttributes = [
92
- { scope: 'identity', attribute: 'status' },
93
- { scope: 'inventory', attribute: 'artifact_name' },
94
- { scope: 'inventory', attribute: 'device_type' },
95
- { scope: 'inventory', attribute: 'mender_is_gateway' },
96
- { scope: 'inventory', attribute: 'mender_gateway_system_id' },
97
- { scope: 'inventory', attribute: rootfsImageVersion },
98
- { scope: 'monitor', attribute: 'alerts' },
99
- { scope: 'system', attribute: 'created_ts' },
100
- { scope: 'system', attribute: 'updated_ts' },
101
- { scope: 'system', attribute: 'check_in_time' },
102
- { scope: 'system', attribute: 'group' },
103
- { scope: 'tags', attribute: 'name' }
104
- ];
105
-
106
- export const getGroups = createAsyncThunk(`${sliceName}/getGroups`, (_, { dispatch, getState }) =>
107
- GeneralApi.get(`${inventoryApiUrl}/groups`).then(res => {
108
- const state = getGroupsById(getState());
109
- const dynamicGroups = Object.entries(state).reduce((accu, [id, group]) => {
110
- if (group.id || (group.filters?.length && id !== UNGROUPED_GROUP.id)) {
111
- accu[id] = group;
112
- }
113
- return accu;
114
- }, {});
115
- const groups = res.data.reduce((accu, group) => {
116
- accu[group] = { deviceIds: [], filters: [], total: 0, ...state[group] };
117
- return accu;
118
- }, dynamicGroups);
119
- const filters = [{ key: 'group', value: res.data, operator: DEVICE_FILTERING_OPTIONS.$nin.key, scope: 'system' }];
120
- return Promise.all([
121
- dispatch(actions.receivedGroups(groups)),
122
- dispatch(getDevicesByStatus({ filterSelection: filters, group: 0, page: 1, perPage: 1, status: undefined }))
123
- ]).then(promises => {
124
- const devicesRetrieval = promises[promises.length - 1] || [];
125
- const { payload } = devicesRetrieval || {};
126
- const result = payload[payload.length - 1] || {};
127
- if (!result.total) {
128
- return Promise.resolve();
129
- }
130
- return Promise.resolve(
131
- dispatch(
132
- actions.addGroup({
133
- groupName: UNGROUPED_GROUP.id,
134
- group: { filters: [{ key: 'group', value: res.data, operator: DEVICE_FILTERING_OPTIONS.$nin.key, scope: 'system' }] }
135
- })
136
- )
137
- );
138
- });
139
- })
140
- );
141
-
142
- export const addDevicesToGroup = createAsyncThunk(`${sliceName}/addDevicesToGroup`, ({ group, deviceIds, isCreation }, { dispatch }) =>
143
- GeneralApi.patch(`${inventoryApiUrl}/groups/${group}/devices`, deviceIds)
144
- .then(() => dispatch(actions.addToGroup({ group, deviceIds })))
145
- .finally(() => (isCreation ? Promise.resolve(dispatch(getGroups())) : {}))
146
- );
147
-
148
- export const removeDevicesFromGroup = createAsyncThunk(`${sliceName}/removeDevicesFromGroup`, ({ group, deviceIds }, { dispatch }) =>
149
- GeneralApi.delete(`${inventoryApiUrl}/groups/${group}/devices`, deviceIds).then(() =>
150
- Promise.all([
151
- dispatch(actions.removeFromGroup({ group, deviceIds })),
152
- dispatch(setSnackbar(`The ${pluralize('devices', deviceIds.length)} ${pluralize('were', deviceIds.length)} removed from the group`, TIMEOUTS.fiveSeconds))
153
- ])
154
- )
155
- );
156
-
157
- const getGroupNotification = (newGroup, selectedGroup) => {
158
- const successMessage = 'The group was updated successfully';
159
- if (newGroup === selectedGroup) {
160
- return [successMessage, TIMEOUTS.fiveSeconds];
161
- }
162
- return [
163
- <>
164
- {successMessage} - <Link to={`/devices?inventory=group:eq:${newGroup}`}>click here</Link> to see it.
165
- </>,
166
- 5000,
167
- undefined,
168
- undefined,
169
- () => {}
170
- ];
171
- };
172
-
173
- export const addStaticGroup = createAsyncThunk(`${sliceName}/addStaticGroup`, ({ group, devices }, { dispatch, getState }) =>
174
- Promise.resolve(dispatch(addDevicesToGroup({ group, deviceIds: devices.map(({ id }) => id), isCreation: true })))
175
- .then(() =>
176
- Promise.resolve(
177
- dispatch(
178
- actions.addGroup({
179
- group: { deviceIds: [], total: 0, filters: [], ...getState().devices.groups.byId[group] },
180
- groupName: group
181
- })
182
- )
183
- ).then(() =>
184
- Promise.all([
185
- dispatch(setDeviceListState({ setOnly: true })),
186
- dispatch(getGroups()),
187
- dispatch(setSnackbar(...getGroupNotification(group, getState().devices.groups.selectedGroup)))
188
- ])
189
- )
190
- )
191
- .catch(err => commonErrorHandler(err, `Group could not be updated:`, dispatch))
192
- );
193
-
194
- export const removeStaticGroup = createAsyncThunk(`${sliceName}/removeStaticGroup`, (groupName, { dispatch }) =>
195
- GeneralApi.delete(`${inventoryApiUrl}/groups/${groupName}`).then(() =>
196
- Promise.all([
197
- dispatch(actions.removeGroup(groupName)),
198
- dispatch(getGroups()),
199
- dispatch(setSnackbar('Group was removed successfully', TIMEOUTS.fiveSeconds))
200
- ])
201
- )
202
- );
203
-
204
- export const getDynamicGroups = createAsyncThunk(`${sliceName}/getDynamicGroups`, (_, { dispatch, getState }) =>
205
- GeneralApi.get(`${inventoryApiUrlV2}/filters?per_page=${MAX_PAGE_SIZE}`)
206
- .then(({ data: filters }) => {
207
- const state = getGroupsById(getState());
208
- const staticGroups = Object.entries(state).reduce((accu, [id, group]) => {
209
- if (!(group.id || group.filters?.length)) {
210
- accu[id] = group;
211
- }
212
- return accu;
213
- }, {});
214
- const groups = (filters || []).reduce((accu, filter) => {
215
- accu[filter.name] = {
216
- deviceIds: [],
217
- total: 0,
218
- ...state[filter.name],
219
- id: filter.id,
220
- filters: mapTermsToFilters(filter.terms)
221
- };
222
- return accu;
223
- }, staticGroups);
224
- return Promise.resolve(dispatch(actions.receivedGroups(groups)));
225
- })
226
- .catch(() => console.log('Dynamic group retrieval failed - likely accessing a non-enterprise backend'))
227
- );
228
-
229
- export const addDynamicGroup = createAsyncThunk(`${sliceName}/addDynamicGroup`, ({ groupName, filterPredicates }, { dispatch, getState }) =>
230
- GeneralApi.post(`${inventoryApiUrlV2}/filters`, { name: groupName, terms: mapFiltersToTerms(filterPredicates) })
231
- .then(res =>
232
- Promise.resolve(
233
- dispatch(
234
- actions.addGroup({
235
- groupName,
236
- group: {
237
- id: res.headers[headerNames.location].substring(res.headers[headerNames.location].lastIndexOf('/') + 1),
238
- filters: filterPredicates
239
- }
240
- })
241
- )
242
- ).then(() => {
243
- const { cleanedFilters } = getGroupFilters(groupName, getState().devices.groups);
244
- return Promise.all([
245
- dispatch(actions.setDeviceFilters(cleanedFilters)),
246
- dispatch(setSnackbar(...getGroupNotification(groupName, getState().devices.groups.selectedGroup))),
247
- dispatch(getDynamicGroups())
248
- ]);
249
- })
250
- )
251
- .catch(err => commonErrorHandler(err, `Group could not be updated:`, dispatch))
252
- );
253
-
254
- export const updateDynamicGroup = createAsyncThunk(`${sliceName}/updateDynamicGroup`, ({ groupName, filterPredicates }, { dispatch, getState }) => {
255
- const filterId = getState().devices.groups.byId[groupName].id;
256
- return GeneralApi.delete(`${inventoryApiUrlV2}/filters/${filterId}`).then(() => Promise.resolve(dispatch(addDynamicGroup({ groupName, filterPredicates }))));
257
- });
258
-
259
- export const removeDynamicGroup = createAsyncThunk(`${sliceName}/removeDynamicGroup`, (groupName, { dispatch, getState }) => {
260
- const filterId = getState().devices.groups.byId[groupName].id;
261
- return GeneralApi.delete(`${inventoryApiUrlV2}/filters/${filterId}`).then(() =>
262
- Promise.all([dispatch(actions.removeGroup(groupName)), dispatch(setSnackbar('Group was removed successfully', TIMEOUTS.fiveSeconds))])
263
- );
264
- });
265
-
266
- /*
267
- * Device inventory functions
268
- */
269
- const getGroupFilters = (group, groupsState, filters = []) => {
270
- const groupName = group === UNGROUPED_GROUP.id || group === UNGROUPED_GROUP.name ? UNGROUPED_GROUP.id : group;
271
- const selectedGroup = groupsState.byId[groupName];
272
- const groupFilterLength = selectedGroup?.filters?.length || 0;
273
- const cleanedFilters = groupFilterLength ? [...filters, ...selectedGroup.filters].filter(filtersFilter) : filters;
274
- return { cleanedFilters, groupName, selectedGroup, groupFilterLength };
275
- };
276
-
277
- export const selectGroup = createAsyncThunk(`${sliceName}/selectGroup`, ({ group, filters = [] }, { dispatch, getState }) => {
278
- const { cleanedFilters, groupName, selectedGroup, groupFilterLength } = getGroupFilters(group, getState().devices.groups, filters);
279
- if (getSelectedGroup(getState()) === groupName && ((filters.length === 0 && !groupFilterLength) || filters.length === cleanedFilters.length)) {
280
- return Promise.resolve();
281
- }
282
- let tasks = [];
283
- if (groupFilterLength) {
284
- tasks.push(dispatch(actions.setDeviceFilters(cleanedFilters)));
285
- } else {
286
- tasks.push(dispatch(actions.setDeviceFilters(filters)));
287
- tasks.push(dispatch(getGroupDevices({ group: groupName, perPage: 1, shouldIncludeAllStates: true })));
288
- }
289
- const selectedGroupName = selectedGroup || !Object.keys(getGroupsById(getState())).length ? groupName : undefined;
290
- tasks.push(dispatch(actions.selectGroup(selectedGroupName)));
291
- return Promise.all(tasks);
292
- });
293
-
294
- const getEarliestTs = (dateA = '', dateB = '') => (!dateA || !dateB ? dateA || dateB : dateA < dateB ? dateA : dateB);
295
-
296
- const reduceReceivedDevices = (devices, ids, state, status) =>
297
- devices.reduce(
298
- (accu, device) => {
299
- const stateDevice = getDeviceByIdSelector(state, device.id);
300
- const {
301
- attributes: storedAttributes = {},
302
- identity_data: storedIdentity = {},
303
- monitor: storedMonitor = {},
304
- tags: storedTags = {},
305
- group: storedGroup
306
- } = stateDevice;
307
- const { identity, inventory, monitor, system = {}, tags } = mapDeviceAttributes(device.attributes);
308
- device.tags = { ...storedTags, ...tags };
309
- device.group = system.group ?? storedGroup;
310
- device.monitor = { ...storedMonitor, ...monitor };
311
- device.identity_data = { ...storedIdentity, ...identity, ...(device.identity_data ? device.identity_data : {}) };
312
- device.status = status ? status : device.status || identity.status;
313
- device.check_in_time_rounded = system.check_in_time ?? stateDevice.check_in_time_rounded;
314
- device.check_in_time_exact = device.check_in_time ?? stateDevice.check_in_time_exact;
315
- device.created_ts = getEarliestTs(getEarliestTs(system.created_ts, device.created_ts), stateDevice.created_ts);
316
- device.updated_ts = device.attributes ? device.updated_ts : stateDevice.updated_ts;
317
- device.isNew = new Date(device.created_ts) > new Date(state.app.newThreshold);
318
- device.isOffline = new Date(device.check_in_time_rounded) < new Date(state.app.offlineThreshold) || device.check_in_time_rounded === undefined;
319
- // all the other mapped attributes return as empty objects if there are no attributes to map, but identity will be initialized with an empty state
320
- // for device_type and artifact_name, potentially overwriting existing info, so rely on stored information instead if there are no attributes
321
- device.attributes = device.attributes ? { ...storedAttributes, ...inventory } : storedAttributes;
322
- accu.devicesById[device.id] = { ...stateDevice, ...device };
323
- accu.ids.push(device.id);
324
- return accu;
325
- },
326
- { ids, devicesById: {} }
327
- );
328
-
329
- export const getGroupDevices = createAsyncThunk(`${sliceName}/getGroupDevices`, (options, { dispatch, getState }) => {
330
- const { group, shouldIncludeAllStates, ...remainder } = options;
331
- const { cleanedFilters: filterSelection } = getGroupFilters(group, getState().devices.groups);
332
- return Promise.resolve(
333
- dispatch(getDevicesByStatus({ ...remainder, filterSelection, group, status: shouldIncludeAllStates ? undefined : DEVICE_STATES.accepted }))
334
- )
335
- .unwrap()
336
- .then(results => {
337
- if (!group) {
338
- return Promise.resolve();
339
- }
340
- const { deviceAccu, total } = results[results.length - 1];
341
- const stateGroup = getState().devices.groups.byId[group];
342
- if (!stateGroup && !total && !deviceAccu.ids.length) {
343
- return Promise.resolve();
344
- }
345
- return Promise.resolve(
346
- dispatch(
347
- actions.addGroup({
348
- group: {
349
- deviceIds: deviceAccu.ids.length === total || deviceAccu.ids.length > stateGroup?.deviceIds ? deviceAccu.ids : stateGroup.deviceIds,
350
- total
351
- },
352
- groupName: group
353
- })
354
- )
355
- );
356
- });
357
- });
358
-
359
- export const getAllGroupDevices = createAsyncThunk(`${sliceName}/getAllGroupDevices`, (group, { dispatch, getState }) => {
360
- if (!group || (!!group && (!getGroupsById(getState())[group] || getGroupsById(getState())[group].filters.length))) {
361
- return Promise.resolve();
362
- }
363
- const { attributes, filterTerms } = prepareSearchArguments({
364
- filters: [],
365
- group,
366
- state: getState(),
367
- status: DEVICE_STATES.accepted
368
- });
369
- const getAllDevices = (perPage = MAX_PAGE_SIZE, page = defaultPage, devices = []) =>
370
- GeneralApi.post(getSearchEndpoint(getState()), {
371
- page,
372
- per_page: perPage,
373
- filters: filterTerms,
374
- attributes
375
- }).then(res => {
376
- const state = getState();
377
- const deviceAccu = reduceReceivedDevices(res.data, devices, state);
378
- dispatch(actions.receivedDevices(deviceAccu.devicesById));
379
- const total = Number(res.headers[headerNames.total]);
380
- if (total > perPage * page) {
381
- return getAllDevices(perPage, page + 1, deviceAccu.ids);
382
- }
383
- return Promise.resolve(dispatch(actions.addGroup({ group: { deviceIds: deviceAccu.ids, total: deviceAccu.ids.length }, groupName: group })));
384
- });
385
- return getAllDevices();
386
- });
387
-
388
- export const getAllDynamicGroupDevices = createAsyncThunk(`${sliceName}/getAllDynamicGroupDevices`, (group, { dispatch, getState }) => {
389
- if (!!group && (!getGroupsById(getState())[group] || !getGroupsById(getState())[group].filters.length)) {
390
- return Promise.resolve();
391
- }
392
- const { attributes, filterTerms: filters } = prepareSearchArguments({
393
- filters: getState().devices.groups.byId[group].filters,
394
- state: getState(),
395
- status: DEVICE_STATES.accepted
396
- });
397
- const getAllDevices = (perPage = MAX_PAGE_SIZE, page = defaultPage, devices = []) =>
398
- GeneralApi.post(getSearchEndpoint(getState()), { page, per_page: perPage, filters, attributes }).then(res => {
399
- const state = getState();
400
- const deviceAccu = reduceReceivedDevices(res.data, devices, state);
401
- dispatch(actions.receivedDevices(deviceAccu.devicesById));
402
- const total = Number(res.headers[headerNames.total]);
403
- if (total > deviceAccu.ids.length) {
404
- return getAllDevices(perPage, page + 1, deviceAccu.ids);
405
- }
406
- return Promise.resolve(dispatch(actions.addGroup({ group: { deviceIds: deviceAccu.ids, total }, groupName: group })));
407
- });
408
- return getAllDevices();
409
- });
410
-
411
- export const getDeviceById = createAsyncThunk(`${sliceName}/getDeviceById`, (id, { dispatch, getState }) =>
412
- GeneralApi.get(`${inventoryApiUrl}/devices/${id}`)
413
- .then(res => {
414
- const device = reduceReceivedDevices([res.data], [], getState()).devicesById[id];
415
- device.etag = res.headers.etag;
416
- dispatch(actions.receivedDevice(device));
417
- return Promise.resolve(device);
418
- })
419
- .catch(err => {
420
- const errMsg = extractErrorMessage(err);
421
- if (errMsg.includes('Not Found')) {
422
- console.log(`${id} does not have any inventory information`);
423
- const device = reduceReceivedDevices(
424
- [
425
- {
426
- id,
427
- attributes: [
428
- { name: 'status', value: 'decomissioned', scope: 'identity' },
429
- { name: 'decomissioned', value: 'true', scope: 'inventory' }
430
- ]
431
- }
432
- ],
433
- [],
434
- getState()
435
- ).devicesById[id];
436
- dispatch(actions.receivedDevice(device));
437
- }
438
- })
439
- );
440
-
441
- export const getDeviceInfo = createAsyncThunk(`${sliceName}/getDeviceInfo`, (deviceId, { dispatch, getState }) => {
442
- const device = getDeviceByIdSelector(getState(), deviceId);
443
- const { hasDeviceConfig, hasDeviceConnect, hasMonitor } = getTenantCapabilities(getState());
444
- const { canConfigure } = getUserCapabilities(getState());
445
- const integrations = getDeviceTwinIntegrations(getState());
446
- let tasks = [dispatch(getDeviceAuth(deviceId)), ...integrations.map(integration => dispatch(getDeviceTwin({ deviceId, integration })))];
447
- if (hasDeviceConfig && canConfigure && [DEVICE_STATES.accepted, DEVICE_STATES.preauth].includes(device.status)) {
448
- tasks.push(dispatch(getDeviceConfig(deviceId)));
449
- }
450
- if (device.status === DEVICE_STATES.accepted) {
451
- // Get full device identity details for single selected device
452
- tasks.push(dispatch(getDeviceById(deviceId)));
453
- if (hasDeviceConnect) {
454
- tasks.push(dispatch(getDeviceConnect(deviceId)));
455
- }
456
- if (hasMonitor) {
457
- tasks.push(dispatch(getLatestDeviceAlerts({ id: deviceId })));
458
- tasks.push(dispatch(getDeviceMonitorConfig(deviceId)));
459
- }
460
- }
461
- return Promise.all(tasks);
462
- });
463
-
464
- export const deriveInactiveDevices = createAsyncThunk(`${sliceName}/deriveInactiveDevices`, (deviceIds, { dispatch, getState }) => {
465
- const yesterday = new Date();
466
- yesterday.setDate(yesterday.getDate() - 1);
467
- const yesterdaysIsoString = yesterday.toISOString();
468
- // now boil the list down to the ones that were not updated since yesterday
469
- const devices = deviceIds.reduce(
470
- (accu, id) => {
471
- const device = getDeviceByIdSelector(getState(), id);
472
- if (device && device.updated_ts > yesterdaysIsoString) {
473
- accu.active.push(id);
474
- } else {
475
- accu.inactive.push(id);
476
- }
477
- return accu;
478
- },
479
- { active: [], inactive: [] }
480
- );
481
- return dispatch(actions.setInactiveDevices({ activeDeviceTotal: devices.active.length, inactiveDeviceTotal: devices.inactive.length }));
482
- });
483
-
484
- /*
485
- Device Auth + admission
486
- */
487
- export const getDeviceCount = createAsyncThunk(`${sliceName}/getDeviceCount`, (status, { dispatch, getState }) =>
488
- GeneralApi.post(getSearchEndpoint(getState()), {
489
- page: 1,
490
- per_page: 1,
491
- filters: mapFiltersToTerms([{ key: 'status', value: status, operator: DEVICE_FILTERING_OPTIONS.$eq.key, scope: 'identity' }]),
492
- attributes: defaultAttributes
493
- }).then(response => {
494
- const count = Number(response.headers[headerNames.total]);
495
- if (status) {
496
- return dispatch(actions.setDevicesCountByStatus({ count, status }));
497
- }
498
- return dispatch(actions.setTotalDevices(count));
499
- })
500
- );
501
-
502
- export const getAllDeviceCounts = createAsyncThunk(`${sliceName}/getAllDeviceCounts`, (_, { dispatch }) =>
503
- Promise.all([DEVICE_STATES.accepted, DEVICE_STATES.pending].map(status => dispatch(getDeviceCount(status))))
504
- );
505
-
506
- export const getDeviceLimit = createAsyncThunk(`${sliceName}/getDeviceLimit`, (_, { dispatch }) =>
507
- GeneralApi.get(`${deviceAuthV2}/limits/max_devices`).then(res => dispatch(actions.setDeviceLimit(res.data.limit)))
508
- );
509
-
510
- export const setDeviceListState = createAsyncThunk(
511
- `${sliceName}/setDeviceListState`,
512
- ({ shouldSelectDevices = true, forceRefresh, fetchAuth = true, ...selectionState }, { dispatch, getState }) => {
513
- const currentState = getDeviceListState(getState());
514
- const refreshTrigger = forceRefresh ? !currentState.refreshTrigger : selectionState.refreshTrigger;
515
- let nextState = {
516
- ...currentState,
517
- setOnly: false,
518
- refreshTrigger,
519
- ...selectionState,
520
- sort: { ...currentState.sort, ...selectionState.sort }
521
- };
522
- let tasks = [];
523
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
524
- const { isLoading: currentLoading, deviceIds: currentDevices, selection: currentSelection, ...currentRequestState } = currentState;
525
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
526
- const { isLoading: nextLoading, deviceIds: nextDevices, selection: nextSelection, ...nextRequestState } = nextState;
527
- if (!nextState.setOnly && !deepCompare(currentRequestState, nextRequestState)) {
528
- const { direction: sortDown = SORTING_OPTIONS.desc, key: sortCol, scope: sortScope } = nextState.sort ?? {};
529
- const sortBy = sortCol ? [{ attribute: sortCol, order: sortDown, scope: sortScope }] : undefined;
530
- const applicableSelectedState = nextState.state === ALL_DEVICE_STATES ? undefined : nextState.state;
531
- nextState.isLoading = true;
532
- tasks.push(
533
- dispatch(getDevicesByStatus({ ...nextState, status: applicableSelectedState, sortOptions: sortBy, fetchAuth }))
534
- .unwrap()
535
- .then(results => {
536
- const { deviceAccu, total } = results[results.length - 1];
537
- const devicesState = shouldSelectDevices ? { deviceIds: deviceAccu.ids, total, isLoading: false } : { isLoading: false };
538
- return Promise.resolve(dispatch(actions.setDeviceListState(devicesState)));
539
- })
540
- // whatever happens, change "loading" back to null
541
- .catch(() => Promise.resolve({ isLoading: false }))
542
- );
543
- }
544
- tasks.push(dispatch(actions.setDeviceListState(nextState)));
545
- return Promise.all(tasks);
546
- }
547
- );
548
-
549
- // get devices from inventory
550
- export const getDevicesByStatus = createAsyncThunk(`${sliceName}/getDevicesByStatus`, (options, { dispatch, getState }) => {
551
- const {
552
- status,
553
- fetchAuth = true,
554
- filterSelection,
555
- group,
556
- selectedIssues = [],
557
- page = defaultPage,
558
- perPage = defaultPerPage,
559
- sortOptions = [],
560
- selectedAttributes = []
561
- } = options;
562
- const state = getState();
563
- const { applicableFilters, filterTerms } = convertDeviceListStateToFilters({
564
- filters: filterSelection ?? getDeviceFilters(state),
565
- group: group ?? getSelectedGroup(state),
566
- groups: state.devices.groups,
567
- offlineThreshold: state.app.offlineThreshold,
568
- selectedIssues,
569
- status
570
- });
571
- const attributes = [...defaultAttributes, getIdAttribute(getState()), ...selectedAttributes];
572
- return GeneralApi.post(getSearchEndpoint(getState()), {
573
- page,
574
- per_page: perPage,
575
- filters: filterTerms,
576
- sort: sortOptions,
577
- attributes
578
- })
579
- .then(response => {
580
- const state = getState();
581
- const deviceAccu = reduceReceivedDevices(response.data, [], state, status);
582
- let total = !applicableFilters.length ? Number(response.headers[headerNames.total]) : null;
583
- if (status && state.devices.byStatus[status].total === deviceAccu.ids.length) {
584
- total = deviceAccu.ids.length;
585
- }
586
- let tasks = [dispatch(actions.receivedDevices(deviceAccu.devicesById))];
587
- if (status) {
588
- tasks.push(dispatch(actions.setDevicesByStatus({ deviceIds: deviceAccu.ids, status, total })));
589
- }
590
- // for each device, get device identity info
591
- const receivedDevices = Object.values(deviceAccu.devicesById);
592
- if (receivedDevices.length && fetchAuth) {
593
- tasks.push(dispatch(getDevicesWithAuth(receivedDevices)));
594
- }
595
- tasks.push(Promise.resolve({ deviceAccu, total: Number(response.headers[headerNames.total]) }));
596
- return Promise.all(tasks);
597
- })
598
- .catch(err => commonErrorHandler(err, `${status} devices couldn't be loaded.`, dispatch, commonErrorFallback));
599
- });
600
-
601
- export const getAllDevicesByStatus = createAsyncThunk(`${sliceName}/getAllDevicesByStatus`, (status, { dispatch, getState }) => {
602
- const attributes = [...defaultAttributes, getIdAttribute(getState())];
603
- const getAllDevices = (perPage = MAX_PAGE_SIZE, page = 1, devices = []) =>
604
- GeneralApi.post(getSearchEndpoint(getState()), {
605
- page,
606
- per_page: perPage,
607
- filters: mapFiltersToTerms([{ key: 'status', value: status, operator: DEVICE_FILTERING_OPTIONS.$eq.key, scope: 'identity' }]),
608
- attributes
609
- }).then(res => {
610
- const state = getState();
611
- const deviceAccu = reduceReceivedDevices(res.data, devices, state, status);
612
- dispatch(actions.receivedDevices(deviceAccu.devicesById));
613
- const total = Number(res.headers[headerNames.total]);
614
- if (total > state.deployments.deploymentDeviceLimit) {
615
- return Promise.resolve();
616
- }
617
- if (total > perPage * page) {
618
- return getAllDevices(perPage, page + 1, deviceAccu.ids);
619
- }
620
- let tasks = [dispatch(actions.setDevicesByStatus({ deviceIds: deviceAccu.ids, forceUpdate: true, status, total: deviceAccu.ids.length }))];
621
- if (status === DEVICE_STATES.accepted && deviceAccu.ids.length === total) {
622
- tasks.push(dispatch(deriveInactiveDevices(deviceAccu.ids)));
623
- tasks.push(dispatch(deriveReportsData()));
624
- }
625
- return Promise.all(tasks);
626
- });
627
- return getAllDevices();
628
- });
629
-
630
- export const searchDevices = createAsyncThunk(`${sliceName}/searchDevices`, (passedOptions = {}, { dispatch, getState }) => {
631
- const state = getState();
632
- let options = { ...state.app.searchState, ...passedOptions };
633
- const { page = defaultPage, searchTerm, sortOptions = [] } = options;
634
- const { columnSelection = [] } = getUserSettings(state);
635
- const selectedAttributes = columnSelection.map(column => ({ attribute: column.key, scope: column.scope }));
636
- const attributes = attributeDuplicateFilter([...defaultAttributes, getIdAttribute(state), ...selectedAttributes], 'attribute');
637
- return GeneralApi.post(getSearchEndpoint(getState()), {
638
- page,
639
- per_page: 10,
640
- filters: [],
641
- sort: sortOptions,
642
- text: searchTerm,
643
- attributes
644
- })
645
- .then(response => {
646
- const deviceAccu = reduceReceivedDevices(response.data, [], getState());
647
- return Promise.all([
648
- dispatch(actions.receivedDevices(deviceAccu.devicesById)),
649
- Promise.resolve({ deviceIds: deviceAccu.ids, searchTotal: Number(response.headers[headerNames.total]) })
650
- ]);
651
- })
652
- .catch(err => commonErrorHandler(err, `devices couldn't be searched.`, dispatch, commonErrorFallback));
653
- });
654
-
655
- const ATTRIBUTE_LIST_CUTOFF = 100;
656
- const attributeReducer = (attributes = []) =>
657
- attributes.slice(0, ATTRIBUTE_LIST_CUTOFF).reduce(
658
- (accu, { name, scope }) => {
659
- if (!accu[scope]) {
660
- accu[scope] = [];
661
- }
662
- accu[scope].push(name);
663
- return accu;
664
- },
665
- { identity: [], inventory: [], system: [], tags: [] }
666
- );
667
-
668
- export const getDeviceAttributes = createAsyncThunk(`${sliceName}/getDeviceAttributes`, (_, { dispatch, getState }) =>
669
- GeneralApi.get(getAttrsEndpoint(getState())).then(({ data }) => {
670
- // TODO: remove the array fallback once the inventory attributes endpoint is fixed
671
- const { identity: identityAttributes, inventory: inventoryAttributes, system: systemAttributes, tags: tagAttributes } = attributeReducer(data || []);
672
- return dispatch(actions.setFilterAttributes({ identityAttributes, inventoryAttributes, systemAttributes, tagAttributes }));
673
- })
674
- );
675
-
676
- export const getReportingLimits = createAsyncThunk(`${sliceName}/getReportingLimits`, (_, { dispatch }) =>
677
- GeneralApi.get(`${reportingApiUrl}/devices/attributes`)
678
- .catch(err => commonErrorHandler(err, `filterable attributes limit & usage could not be retrieved.`, dispatch, commonErrorFallback))
679
- .then(({ data }) => {
680
- const { attributes, count, limit } = data;
681
- const groupedAttributes = attributeReducer(attributes);
682
- return Promise.resolve(dispatch(actions.setFilterablesConfig({ count, limit, attributes: groupedAttributes })));
683
- })
684
- );
685
-
686
- export const ensureVersionString = (software, fallback) =>
687
- software.length && software !== 'artifact_name' ? (software.endsWith('.version') ? software : `${software}.version`) : fallback;
688
-
689
- const REPORT_CHART_SIZE_LIMIT = 6;
690
- const getSingleReportData = (reportConfig, groups) => {
691
- const { attribute, group, software = '' } = reportConfig;
692
- const filters = [{ key: 'status', scope: 'identity', operator: DEVICE_FILTERING_OPTIONS.$eq.key, value: 'accepted' }];
693
- if (group) {
694
- const staticGroupFilter = { key: 'group', scope: 'system', operator: DEVICE_FILTERING_OPTIONS.$eq.key, value: group };
695
- const { cleanedFilters: groupFilters } = getGroupFilters(group, groups);
696
- filters.push(...(groupFilters.length ? groupFilters : [staticGroupFilter]));
697
- }
698
- const aggregationAttribute = ensureVersionString(software, attribute);
699
- return GeneralApi.post(`${reportingApiUrl}/devices/aggregate`, {
700
- aggregations: [{ attribute: aggregationAttribute, name: '*', scope: 'inventory', size: REPORT_CHART_SIZE_LIMIT }],
701
- filters: mapFiltersToTerms(filters)
702
- }).then(({ data }) => ({ data, reportConfig }));
703
- };
704
-
705
- export const getReportsData = createAsyncThunk(`${sliceName}/getReportsData`, (_, { dispatch, getState }) => {
706
- const state = getState();
707
- const currentUserId = getCurrentUser(state).id;
708
- const reports =
709
- getUserSettings(state).reports || getGlobalSettings(state)[`${currentUserId}-reports`] || (Object.keys(getDevicesById(state)).length ? defaultReports : []);
710
- return Promise.all(reports.map(report => getSingleReportData(report, getState().devices.groups))).then(results => {
711
- const devicesState = getState().devices;
712
- const totalDeviceCount = devicesState.byStatus.accepted.total;
713
- const newReports = results.map(({ data, reportConfig }) => {
714
- let { items, other_count } = data[0];
715
- const { attribute, group, software = '' } = reportConfig;
716
- const dataCount = items.reduce((accu, item) => accu + item.count, 0);
717
- // the following is needed to show reports including both old (artifact_name) & current style (rootfs-image.version) device software
718
- const otherCount = !group && (software === rootfsImageVersion || attribute === 'artifact_name') ? totalDeviceCount - dataCount : other_count;
719
- return { items, otherCount, total: otherCount + dataCount };
720
- });
721
- return Promise.resolve(dispatch(actions.setDeviceReports(newReports)));
722
- });
723
- });
724
-
725
- const initializeDistributionData = (report, groups, devices, totalDeviceCount) => {
726
- const { attribute, group = '', software = '' } = report;
727
- const effectiveAttribute = software ? software : attribute;
728
- const { deviceIds, total = 0 } = groups[group] || {};
729
- const relevantDevices = groups[group] ? deviceIds.map(id => devices[id]) : Object.values(devices);
730
- const distributionByAttribute = relevantDevices.reduce((accu, item) => {
731
- if (!item.attributes || item.status !== DEVICE_STATES.accepted) return accu;
732
- if (!accu[item.attributes[effectiveAttribute]]) {
733
- accu[item.attributes[effectiveAttribute]] = 0;
734
- }
735
- accu[item.attributes[effectiveAttribute]] = accu[item.attributes[effectiveAttribute]] + 1;
736
- return accu;
737
- }, {});
738
- const distributionByAttributeSorted = Object.entries(distributionByAttribute).sort((pairA, pairB) => pairB[1] - pairA[1]);
739
- const items = distributionByAttributeSorted.map(([key, count]) => ({ key, count }));
740
- const dataCount = items.reduce((accu, item) => accu + item.count, 0);
741
- // the following is needed to show reports including both old (artifact_name) & current style (rootfs-image.version) device software
742
- const otherCount = (groups[group] ? total : totalDeviceCount) - dataCount;
743
- return { items, otherCount, total: otherCount + dataCount };
744
- };
745
-
746
- export const deriveReportsData = createAsyncThunk(`${sliceName}/deriveReportsData`, (_, { dispatch, getState }) => {
747
- const state = getState();
748
- const {
749
- groups: { byId: groupsById },
750
- byId,
751
- byStatus: {
752
- accepted: { total }
753
- }
754
- } = state.devices;
755
- const reports =
756
- getUserSettings(state).reports || state.users.globalSettings[`${state.users.currentUser}-reports`] || (Object.keys(byId).length ? defaultReports : []);
757
- const newReports = reports.map(report => initializeDistributionData(report, groupsById, byId, total));
758
- return Promise.resolve(dispatch(actions.setDeviceReports(newReports)));
759
- });
760
-
761
- export const getReportsDataWithoutBackendSupport = createAsyncThunk(`${sliceName}/getReportsDataWithoutBackendSupport`, (_, { dispatch, getState }) =>
762
- Promise.all([dispatch(getAllDevicesByStatus(DEVICE_STATES.accepted)), dispatch(getGroups()), dispatch(getDynamicGroups())]).then(() => {
763
- const { dynamic: dynamicGroups, static: staticGroups } = getGroupsSelector(getState());
764
- return Promise.all([
765
- ...staticGroups.map(({ groupId }) => dispatch(getAllGroupDevices(groupId))),
766
- ...dynamicGroups.map(({ groupId }) => dispatch(getAllDynamicGroupDevices(groupId)))
767
- ]).then(() => dispatch(deriveReportsData()));
768
- })
769
- );
770
-
771
- export const getDeviceConnect = createAsyncThunk(`${sliceName}/getDeviceConnect`, (id, { dispatch }) =>
772
- GeneralApi.get(`${deviceConnect}/devices/${id}`).then(({ data }) =>
773
- Promise.all([dispatch(actions.receivedDevice({ connect_status: data.status, connect_updated_ts: data.updated_ts, id })), Promise.resolve(data)])
774
- )
775
- );
776
-
777
- export const getSessionDetails = createAsyncThunk(`${sliceName}/getSessionDetails`, ({ sessionId, deviceId, userId, startDate, endDate }) => {
778
- const createdAfter = startDate ? `&created_after=${Math.round(Date.parse(startDate) / 1000)}` : '';
779
- const createdBefore = endDate ? `&created_before=${Math.round(Date.parse(endDate) / 1000)}` : '';
780
- const objectSearch = `&object_id=${deviceId}`;
781
- return GeneralApi.get(`${auditLogsApiUrl}/logs?per_page=500${createdAfter}${createdBefore}&actor_id=${userId}${objectSearch}`).then(
782
- ({ data: auditLogEntries }) => {
783
- const { start, end } = auditLogEntries.reduce(
784
- (accu, item) => {
785
- if (item.meta?.session_id?.includes(sessionId)) {
786
- accu.start = new Date(item.action.startsWith('open') ? item.time : accu.start);
787
- accu.end = new Date(item.action.startsWith('close') ? item.time : accu.end);
788
- }
789
- return accu;
790
- },
791
- { start: startDate || endDate, end: endDate || startDate }
792
- );
793
- return Promise.resolve({ start, end });
794
- }
795
- );
796
- });
797
-
798
- export const getDeviceFileDownloadLink = createAsyncThunk(`${sliceName}/getDeviceFileDownloadLink`, ({ deviceId, path }) =>
799
- Promise.resolve(`${window.location.origin}${deviceConnect}/devices/${deviceId}/download?path=${encodeURIComponent(path)}`)
800
- );
801
-
802
- export const deviceFileUpload = createAsyncThunk(`${sliceName}/deviceFileUpload`, ({ deviceId, path, file }, { dispatch }) => {
803
- let formData = new FormData();
804
- formData.append('path', path);
805
- formData.append('file', file);
806
- const uploadId = uuid();
807
- const cancelSource = new AbortController();
808
- return Promise.all([
809
- dispatch(setSnackbar('Uploading file')),
810
- dispatch(initUpload({ id: uploadId, upload: { inprogress: true, uploadProgress: 0, cancelSource } })),
811
- GeneralApi.uploadPut(
812
- `${deviceConnect}/devices/${deviceId}/upload`,
813
- formData,
814
- e => dispatch(uploadProgress({ id: uploadId, progress: progress(e) })),
815
- cancelSource.signal
816
- )
817
- ])
818
- .then(() => Promise.resolve(dispatch(setSnackbar('Upload successful', TIMEOUTS.fiveSeconds))))
819
- .catch(err => {
820
- if (isCancel(err)) {
821
- return dispatch(setSnackbar('The upload has been cancelled', TIMEOUTS.fiveSeconds));
822
- }
823
- return commonErrorHandler(err, `Error uploading file to device.`, dispatch);
824
- })
825
- .finally(() => dispatch(cleanUpUpload(uploadId)));
826
- });
827
-
828
- export const getDeviceAuth = createAsyncThunk(`${sliceName}/getDeviceAuth`, (id, { dispatch }) =>
829
- dispatch(getDevicesWithAuth([{ id }]))
830
- .unwrap()
831
- .then(results => {
832
- if (results[results.length - 1]) {
833
- return Promise.resolve(results[results.length - 1][0]);
834
- }
835
- return Promise.resolve();
836
- })
837
- );
838
-
839
- export const getDevicesWithAuth = createAsyncThunk(`${sliceName}/getDevicesWithAuth`, (devices, { dispatch, getState }) =>
840
- devices.length
841
- ? GeneralApi.get(`${deviceAuthV2}/devices?id=${devices.map(device => device.id).join('&id=')}`)
842
- .then(({ data: receivedDevices }) => {
843
- const { devicesById } = reduceReceivedDevices(receivedDevices, [], getState());
844
- return Promise.all([dispatch(actions.receivedDevices(devicesById)), Promise.resolve(receivedDevices)]);
845
- })
846
- .catch(err => commonErrorHandler(err, `Error: ${err}`, dispatch))
847
- : Promise.resolve([[], []])
848
- );
849
-
850
- export const updateDeviceAuth = createAsyncThunk(`${sliceName}/updateDeviceAuth`, ({ deviceId, authId, status }, { dispatch, getState }) =>
851
- GeneralApi.put(`${deviceAuthV2}/devices/${deviceId}/auth/${authId}/status`, { status })
852
- .then(() => Promise.all([dispatch(getDeviceAuth(deviceId)), dispatch(setSnackbar('Device authorization status was updated successfully'))]))
853
- .catch(err => commonErrorHandler(err, 'There was a problem updating the device authorization status:', dispatch))
854
- .then(() => Promise.resolve(dispatch(actions.maybeUpdateDevicesByStatus({ deviceId, authId }))))
855
- .finally(() => dispatch(setDeviceListState({ refreshTrigger: !getDeviceListState(getState()).refreshTrigger })))
856
- );
857
-
858
- export const updateDevicesAuth = createAsyncThunk(`${sliceName}/updateDevicesAuth`, ({ deviceIds, status }, { dispatch, getState }) => {
859
- let devices = getDevicesById(getState());
860
- const deviceIdsWithoutAuth = deviceIds.reduce((accu, id) => (devices[id].auth_sets ? accu : [...accu, { id }]), []);
861
- return dispatch(getDevicesWithAuth(deviceIdsWithoutAuth)).then(() => {
862
- devices = getDevicesById(getState());
863
- // for each device, get id and id of authset & make api call to accept
864
- // if >1 authset, skip instead
865
- const deviceAuthUpdates = deviceIds.map(id => {
866
- const device = devices[id];
867
- if (device.auth_sets.length !== 1) {
868
- return Promise.reject();
869
- }
870
- // api call device.id and device.authsets[0].id
871
- return dispatch(updateDeviceAuth({ authId: device.auth_sets[0].id, deviceId: device.id, status }))
872
- .unwrap()
873
- .catch(err => commonErrorHandler(err, 'The action was stopped as there was a problem updating a device authorization status: ', dispatch, '', false));
874
- });
875
- return Promise.allSettled(deviceAuthUpdates).then(results => {
876
- const { skipped, count } = results.reduce(
877
- (accu, item) => {
878
- if (item.status === 'rejected') {
879
- accu.skipped = accu.skipped + 1;
880
- } else {
881
- accu.count = accu.count + 1;
882
- }
883
- return accu;
884
- },
885
- { skipped: 0, count: 0 }
886
- );
887
- const message = getSnackbarMessage(skipped, count);
888
- // break if an error occurs, display status up til this point before error message
889
- return dispatch(setSnackbar(message));
890
- });
891
- });
892
- });
893
-
894
- export const deleteAuthset = createAsyncThunk(`${sliceName}/deleteAuthset`, ({ deviceId, authId }, { dispatch, getState }) =>
895
- GeneralApi.delete(`${deviceAuthV2}/devices/${deviceId}/auth/${authId}`)
896
- .then(() => Promise.all([dispatch(setSnackbar('Device authorization status was updated successfully'))]))
897
- .catch(err => commonErrorHandler(err, 'There was a problem updating the device authorization status:', dispatch))
898
- .then(() => Promise.resolve(dispatch(actions.maybeUpdateDevicesByStatus({ deviceId, authId }))))
899
- .finally(() => dispatch(setDeviceListState({ refreshTrigger: !getState().devices.deviceList.refreshTrigger })))
900
- );
901
-
902
- export const preauthDevice = createAsyncThunk(`${sliceName}/preauthDevice`, (authset, { dispatch }) =>
903
- GeneralApi.post(`${deviceAuthV2}/devices`, authset)
904
- .catch(err => {
905
- if (err.response.status === 409) {
906
- return Promise.reject('A device with a matching identity data set already exists');
907
- }
908
- return commonErrorHandler(err, 'The device could not be added:', dispatch);
909
- })
910
- .then(() => Promise.resolve(dispatch(setSnackbar('Device was successfully added to the preauthorization list', TIMEOUTS.fiveSeconds))))
911
- );
912
-
913
- export const decommissionDevice = createAsyncThunk(`${sliceName}/decommissionDevice`, ({ deviceId, authId }, { dispatch, getState }) =>
914
- GeneralApi.delete(`${deviceAuthV2}/devices/${deviceId}`)
915
- .then(() => Promise.resolve(dispatch(setSnackbar('Device was decommissioned successfully'))))
916
- .catch(err => commonErrorHandler(err, 'There was a problem decommissioning the device:', dispatch))
917
- .then(() => Promise.resolve(dispatch(actions.maybeUpdateDevicesByStatus({ deviceId, authId }))))
918
- // trigger reset of device list list!
919
- .finally(() => dispatch(setDeviceListState({ refreshTrigger: !getState().devices.deviceList.refreshTrigger })))
920
- );
921
-
922
- export const getDeviceConfig = createAsyncThunk(`${sliceName}/getDeviceConfig`, (deviceId, { dispatch }) =>
923
- GeneralApi.get(`${deviceConfig}/${deviceId}`)
924
- .then(({ data }) => Promise.all([dispatch(actions.receivedDevice({ id: deviceId, config: data })), Promise.resolve(data)]))
925
- .catch(err => {
926
- // if we get a proper error response we most likely queried a device without an existing config check-in and we can just ignore the call
927
- if (err.response?.data?.error.status_code !== 404) {
928
- return commonErrorHandler(err, `There was an error retrieving the configuration for device ${deviceId}.`, dispatch, commonErrorFallback);
929
- }
930
- })
931
- );
932
-
933
- export const setDeviceConfig = createAsyncThunk(`${sliceName}/setDeviceConfig`, ({ deviceId, config }, { dispatch }) =>
934
- GeneralApi.put(`${deviceConfig}/${deviceId}`, config)
935
- .catch(err => commonErrorHandler(err, `There was an error setting the configuration for device ${deviceId}.`, dispatch, commonErrorFallback))
936
- .then(() => Promise.resolve(dispatch(getDeviceConfig(deviceId))))
937
- );
938
-
939
- export const applyDeviceConfig = createAsyncThunk(
940
- `${sliceName}/applyDeviceConfig`,
941
- ({ deviceId, configDeploymentConfiguration, isDefault, config }, { dispatch, getState }) =>
942
- GeneralApi.post(`${deviceConfig}/${deviceId}/deploy`, configDeploymentConfiguration)
943
- .catch(err => commonErrorHandler(err, `There was an error deploying the configuration to device ${deviceId}.`, dispatch, commonErrorFallback))
944
- .then(({ data }) => {
945
- const device = getDeviceByIdSelector(getState(), deviceId);
946
- const { canManageUsers } = getUserCapabilities(getState());
947
- let tasks = [
948
- dispatch(actions.receivedDevice({ ...device, config: { ...device.config, deployment_id: data.deployment_id } })),
949
- new Promise(resolve => setTimeout(() => resolve(dispatch(getSingleDeployment(data.deployment_id))), TIMEOUTS.oneSecond))
950
- ];
951
- if (isDefault && canManageUsers) {
952
- const { previous } = getGlobalSettings(getState()).defaultDeviceConfig ?? {};
953
- tasks.push(dispatch(saveGlobalSettings({ defaultDeviceConfig: { current: config, previous } })));
954
- }
955
- return Promise.all(tasks);
956
- })
957
- );
958
-
959
- export const setDeviceTags = createAsyncThunk(`${sliceName}/setDeviceTags`, ({ deviceId, tags }, { dispatch }) =>
960
- // to prevent tag set failures, retrieve the device & use the freshest etag we can get
961
- Promise.resolve(dispatch(getDeviceById(deviceId))).then(device => {
962
- const headers = device.etag ? { 'If-Match': device.etag } : {};
963
- return GeneralApi.put(
964
- `${inventoryApiUrl}/devices/${deviceId}/tags`,
965
- Object.entries(tags).map(([name, value]) => ({ name, value })),
966
- { headers }
967
- )
968
- .catch(err => commonErrorHandler(err, `There was an error setting tags for device ${deviceId}.`, dispatch, 'Please check your connection.'))
969
- .then(() => Promise.all([dispatch(actions.receivedDevice({ ...device, id: deviceId, tags })), dispatch(setSnackbar('Device name changed'))]));
970
- })
971
- );
972
-
973
- export const getDeviceTwin = createAsyncThunk(`${sliceName}/getDeviceTwin`, ({ deviceId, integration }, { dispatch, getState }) => {
974
- let providerResult = {};
975
- return GeneralApi.get(`${iotManagerBaseURL}/devices/${deviceId}/state`)
976
- .then(({ data }) => {
977
- providerResult = { ...data, twinError: '' };
978
- })
979
- .catch(err => {
980
- providerResult = {
981
- twinError: `There was an error getting the ${EXTERNAL_PROVIDER[integration.provider].twinTitle.toLowerCase()} for device ${deviceId}. ${err}`
982
- };
983
- })
984
- .finally(() => {
985
- const device = getDeviceByIdSelector(getState(), deviceId);
986
- Promise.resolve(dispatch(actions.receivedDevice({ ...device, twinsByIntegration: { ...device.twinsByIntegration, ...providerResult } })));
987
- });
988
- });
989
-
990
- export const setDeviceTwin = createAsyncThunk(`${sliceName}/setDeviceTwin`, ({ deviceId, integration, settings }, { dispatch, getState }) =>
991
- GeneralApi.put(`${iotManagerBaseURL}/devices/${deviceId}/state/${integration.id}`, { desired: settings })
992
- .catch(err =>
993
- commonErrorHandler(
994
- err,
995
- `There was an error updating the ${EXTERNAL_PROVIDER[integration.provider].twinTitle.toLowerCase()} for device ${deviceId}.`,
996
- dispatch
997
- )
998
- )
999
- .then(() => {
1000
- const device = getDeviceByIdSelector(getState(), deviceId);
1001
- const { twinsByIntegration = {} } = device;
1002
- const { [integration.id]: currentState = {} } = twinsByIntegration;
1003
- return Promise.resolve(
1004
- dispatch(actions.receivedDevice({ ...device, twinsByIntegration: { ...twinsByIntegration, [integration.id]: { ...currentState, desired: settings } } }))
1005
- );
1006
- })
1007
- );
1008
-
1009
- const prepareSearchArguments = ({ filters, group, state, status }) => {
1010
- const { filterTerms } = convertDeviceListStateToFilters({ filters, group, offlineThreshold: state.app.offlineThreshold, selectedIssues: [], status });
1011
- const { columnSelection = [] } = getUserSettings(state);
1012
- const selectedAttributes = columnSelection.map(column => ({ attribute: column.key, scope: column.scope }));
1013
- const attributes = [...defaultAttributes, getIdAttribute(state), ...selectedAttributes];
1014
- return { attributes, filterTerms };
1015
- };
1016
-
1017
- export const getSystemDevices = createAsyncThunk(`${sliceName}/getSystemDevices`, (options, { dispatch, getState }) => {
1018
- const { id, page = defaultPage, perPage = defaultPerPage, sortOptions = [] } = options;
1019
- const state = getState();
1020
- const { hasFullFiltering } = getTenantCapabilities(state);
1021
- if (!hasFullFiltering) {
1022
- return Promise.resolve();
1023
- }
1024
- const { attributes: deviceAttributes = {} } = getDeviceByIdSelector(state, id);
1025
- const { mender_gateway_system_id = '' } = deviceAttributes;
1026
- const filters = [
1027
- { ...emptyFilter, key: 'mender_is_gateway', operator: DEVICE_FILTERING_OPTIONS.$ne.key, value: 'true', scope: 'inventory' },
1028
- { ...emptyFilter, key: 'mender_gateway_system_id', value: mender_gateway_system_id, scope: 'inventory' }
1029
- ];
1030
- const { attributes, filterTerms } = prepareSearchArguments({ filters, state });
1031
- return GeneralApi.post(getSearchEndpoint(getState()), {
1032
- page,
1033
- per_page: perPage,
1034
- filters: filterTerms,
1035
- sort: sortOptions,
1036
- attributes
1037
- })
1038
- .catch(err => commonErrorHandler(err, `There was an error getting system devices device ${id}.`, dispatch, 'Please check your connection.'))
1039
- .then(({ data, headers }) => {
1040
- const state = getState();
1041
- const { devicesById, ids } = reduceReceivedDevices(data, [], state);
1042
- const device = {
1043
- ...getDeviceByIdSelector(state, id),
1044
- systemDeviceIds: ids,
1045
- systemDeviceTotal: Number(headers[headerNames.total])
1046
- };
1047
- return Promise.resolve(dispatch(actions.receivedDevices({ ...devicesById, [id]: device })));
1048
- });
1049
- });
1050
-
1051
- export const getGatewayDevices = createAsyncThunk(`${sliceName}/getGatewayDevices`, (deviceId, { dispatch, getState }) => {
1052
- const state = getState();
1053
- const { attributes = {} } = getDeviceByIdSelector(state, deviceId);
1054
- const { mender_gateway_system_id = '' } = attributes;
1055
- const filters = [
1056
- { ...emptyFilter, key: 'id', operator: DEVICE_FILTERING_OPTIONS.$ne.key, value: deviceId, scope: 'identity' },
1057
- { ...emptyFilter, key: 'mender_is_gateway', value: 'true', scope: 'inventory' },
1058
- { ...emptyFilter, key: 'mender_gateway_system_id', value: mender_gateway_system_id, scope: 'inventory' }
1059
- ];
1060
- const { attributes: attributeSelection, filterTerms } = prepareSearchArguments({ filters, state });
1061
- return GeneralApi.post(getSearchEndpoint(getState()), {
1062
- page: 1,
1063
- per_page: MAX_PAGE_SIZE,
1064
- filters: filterTerms,
1065
- attributes: attributeSelection
1066
- }).then(({ data }) => {
1067
- const { ids } = reduceReceivedDevices(data, [], getState());
1068
- let tasks = ids.map(deviceId => dispatch(getDeviceInfo(deviceId)));
1069
- tasks.push(dispatch(actions.receivedDevice({ id: deviceId, gatewayIds: ids })));
1070
- return Promise.all(tasks);
1071
- });
1072
- });
1073
-
1074
- export const getDevicesInBounds = createAsyncThunk(`${sliceName}/getDevicesInBounds`, ({ bounds, group }, { dispatch, getState }) => {
1075
- const state = getState();
1076
- const { filterTerms } = convertDeviceListStateToFilters({
1077
- group: group === ALL_DEVICES ? undefined : group,
1078
- groups: state.devices.groups,
1079
- status: DEVICE_STATES.accepted
1080
- });
1081
- return GeneralApi.post(getSearchEndpoint(getState()), {
1082
- page: 1,
1083
- per_page: MAX_PAGE_SIZE,
1084
- filters: filterTerms,
1085
- attributes: geoAttributes,
1086
- geo_bounding_box_filter: {
1087
- geo_bounding_box: {
1088
- location: {
1089
- top_left: { lat: bounds._northEast.lat, lon: bounds._southWest.lng },
1090
- bottom_right: { lat: bounds._southWest.lat, lon: bounds._northEast.lng }
1091
- }
1092
- }
1093
- }
1094
- }).then(({ data }) => {
1095
- const { devicesById } = reduceReceivedDevices(data, [], getState());
1096
- return Promise.resolve(dispatch(actions.receivedDevices(devicesById)));
1097
- });
1098
- });