@ledgerhq/device-management-kit 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +0 -3
  2. package/lib/cjs/package.json +1 -1
  3. package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
  4. package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
  5. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js +1 -1
  6. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  7. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  8. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  9. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  10. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
  11. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
  12. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +2 -2
  13. package/lib/cjs/src/api/device-action/os/InstallLanguagePackage/types.js +1 -1
  14. package/lib/cjs/src/api/device-action/os/InstallLanguagePackage/types.js.map +3 -3
  15. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  16. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
  17. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  18. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
  19. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
  20. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
  21. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  22. package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
  23. package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
  24. package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
  25. package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
  26. package/lib/cjs/src/api/index.js +1 -1
  27. package/lib/cjs/src/api/index.js.map +3 -3
  28. package/lib/cjs/src/api/types.js +1 -1
  29. package/lib/cjs/src/api/types.js.map +3 -3
  30. package/lib/cjs/src/api/utils/apduLogs.js +1 -1
  31. package/lib/cjs/src/api/utils/apduLogs.js.map +3 -3
  32. package/lib/cjs/src/api/utils/apduLogs.test.js +1 -1
  33. package/lib/cjs/src/api/utils/apduLogs.test.js.map +3 -3
  34. package/lib/cjs/src/internal/device-session/model/DeviceSession.js +1 -1
  35. package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +3 -3
  36. package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.js +1 -1
  37. package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.js.map +2 -2
  38. package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
  39. package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
  40. package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
  41. package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +2 -2
  42. package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
  43. package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +2 -2
  44. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
  45. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
  46. package/lib/cjs/src/internal/manager-api/model/Const.js +1 -1
  47. package/lib/cjs/src/internal/manager-api/model/Const.js.map +1 -1
  48. package/lib/cjs/src/internal/manager-api/model/Firmware.js +1 -1
  49. package/lib/cjs/src/internal/manager-api/model/Firmware.js.map +1 -1
  50. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
  51. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js.map +2 -2
  52. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
  53. package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
  54. package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js +1 -1
  55. package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
  56. package/lib/cjs/src/internal/secure-channel/model/Errors.js +1 -1
  57. package/lib/cjs/src/internal/secure-channel/model/Errors.js.map +2 -2
  58. package/lib/cjs/src/internal/secure-channel/service/DefaultSecureChannelService.js +1 -1
  59. package/lib/cjs/src/internal/secure-channel/service/DefaultSecureChannelService.js.map +3 -3
  60. package/lib/cjs/src/internal/secure-channel/service/SecureChannelService.js +1 -1
  61. package/lib/cjs/src/internal/secure-channel/service/SecureChannelService.js.map +1 -1
  62. package/lib/esm/package.json +1 -1
  63. package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
  64. package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
  65. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js +1 -1
  66. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  67. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  68. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  69. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  70. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
  71. package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
  72. package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +2 -2
  73. package/lib/esm/src/api/device-action/os/InstallLanguagePackage/types.js +1 -1
  74. package/lib/esm/src/api/device-action/os/InstallLanguagePackage/types.js.map +3 -3
  75. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  76. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
  77. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  78. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
  79. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
  80. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  81. package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
  82. package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
  83. package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
  84. package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
  85. package/lib/esm/src/api/index.js +1 -1
  86. package/lib/esm/src/api/index.js.map +3 -3
  87. package/lib/esm/src/api/types.js +1 -0
  88. package/lib/esm/src/api/types.js.map +4 -4
  89. package/lib/esm/src/api/utils/apduLogs.js +1 -1
  90. package/lib/esm/src/api/utils/apduLogs.js.map +3 -3
  91. package/lib/esm/src/api/utils/apduLogs.test.js +1 -1
  92. package/lib/esm/src/api/utils/apduLogs.test.js.map +3 -3
  93. package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
  94. package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +3 -3
  95. package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.js +1 -1
  96. package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.js.map +2 -2
  97. package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
  98. package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
  99. package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
  100. package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +3 -3
  101. package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
  102. package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +3 -3
  103. package/lib/esm/src/internal/manager-api/model/Const.js +1 -1
  104. package/lib/esm/src/internal/manager-api/model/Const.js.map +1 -1
  105. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
  106. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js.map +2 -2
  107. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
  108. package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
  109. package/lib/esm/src/internal/secure-channel/model/Errors.js +1 -1
  110. package/lib/esm/src/internal/secure-channel/model/Errors.js.map +3 -3
  111. package/lib/esm/src/internal/secure-channel/service/DefaultSecureChannelService.js +1 -1
  112. package/lib/esm/src/internal/secure-channel/service/DefaultSecureChannelService.js.map +3 -3
  113. package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts +3 -0
  114. package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
  115. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +3 -1
  116. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts.map +1 -1
  117. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts +0 -9
  118. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
  119. package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +5 -4
  120. package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
  121. package/lib/types/src/api/device-action/os/InstallLanguagePackage/types.d.ts +1 -0
  122. package/lib/types/src/api/device-action/os/InstallLanguagePackage/types.d.ts.map +1 -1
  123. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
  124. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +1 -1
  125. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
  126. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -1
  127. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  128. package/lib/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts +2 -0
  129. package/lib/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts.map +1 -1
  130. package/lib/types/src/api/index.d.ts +3 -4
  131. package/lib/types/src/api/index.d.ts.map +1 -1
  132. package/lib/types/src/api/types.d.ts +1 -1
  133. package/lib/types/src/api/types.d.ts.map +1 -1
  134. package/lib/types/src/api/utils/apduLogs.d.ts +15 -0
  135. package/lib/types/src/api/utils/apduLogs.d.ts.map +1 -1
  136. package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
  137. package/lib/types/src/internal/device-session/model/DeviceSessionRefresher.d.ts.map +1 -1
  138. package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts +2 -2
  139. package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts.map +1 -1
  140. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +4 -4
  141. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
  142. package/lib/types/src/internal/manager-api/model/Const.d.ts +1 -1
  143. package/lib/types/src/internal/manager-api/model/Firmware.d.ts +3 -0
  144. package/lib/types/src/internal/manager-api/model/Firmware.d.ts.map +1 -1
  145. package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +2 -1
  146. package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts.map +1 -1
  147. package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +9 -3
  148. package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
  149. package/lib/types/src/internal/secure-channel/model/Errors.d.ts +8 -1
  150. package/lib/types/src/internal/secure-channel/model/Errors.d.ts.map +1 -1
  151. package/lib/types/src/internal/secure-channel/service/DefaultSecureChannelService.d.ts +1 -1
  152. package/lib/types/src/internal/secure-channel/service/DefaultSecureChannelService.d.ts.map +1 -1
  153. package/lib/types/src/internal/secure-channel/service/SecureChannelService.d.ts +2 -2
  154. package/lib/types/src/internal/secure-channel/service/SecureChannelService.d.ts.map +1 -1
  155. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  156. package/package.json +4 -4
  157. package/lib/cjs/src/api/command/os/BackupStorageCommand.js +0 -2
  158. package/lib/cjs/src/api/command/os/BackupStorageCommand.js.map +0 -7
  159. package/lib/cjs/src/api/command/os/BackupStorageCommand.test.js +0 -2
  160. package/lib/cjs/src/api/command/os/BackupStorageCommand.test.js.map +0 -7
  161. package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.js +0 -2
  162. package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.js.map +0 -7
  163. package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.test.js +0 -2
  164. package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.test.js.map +0 -7
  165. package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.js +0 -2
  166. package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.js.map +0 -7
  167. package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.test.js +0 -2
  168. package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.test.js.map +0 -7
  169. package/lib/cjs/src/api/storage/KeyValueStorage.js +0 -2
  170. package/lib/cjs/src/api/storage/KeyValueStorage.js.map +0 -7
  171. package/lib/esm/src/api/command/os/BackupStorageCommand.js +0 -2
  172. package/lib/esm/src/api/command/os/BackupStorageCommand.js.map +0 -7
  173. package/lib/esm/src/api/command/os/BackupStorageCommand.test.js +0 -2
  174. package/lib/esm/src/api/command/os/BackupStorageCommand.test.js.map +0 -7
  175. package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.js +0 -2
  176. package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.js.map +0 -7
  177. package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.test.js +0 -2
  178. package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.test.js.map +0 -7
  179. package/lib/esm/src/api/device-action/task/BackupAppStorageTask.js +0 -2
  180. package/lib/esm/src/api/device-action/task/BackupAppStorageTask.js.map +0 -7
  181. package/lib/esm/src/api/device-action/task/BackupAppStorageTask.test.js +0 -2
  182. package/lib/esm/src/api/device-action/task/BackupAppStorageTask.test.js.map +0 -7
  183. package/lib/esm/src/api/storage/KeyValueStorage.js +0 -2
  184. package/lib/esm/src/api/storage/KeyValueStorage.js.map +0 -7
  185. package/lib/types/src/api/command/os/BackupStorageCommand.d.ts +0 -23
  186. package/lib/types/src/api/command/os/BackupStorageCommand.d.ts.map +0 -1
  187. package/lib/types/src/api/command/os/BackupStorageCommand.test.d.ts +0 -2
  188. package/lib/types/src/api/command/os/BackupStorageCommand.test.d.ts.map +0 -1
  189. package/lib/types/src/api/command/os/GetAppStorageInfoCommand.d.ts +0 -31
  190. package/lib/types/src/api/command/os/GetAppStorageInfoCommand.d.ts.map +0 -1
  191. package/lib/types/src/api/command/os/GetAppStorageInfoCommand.test.d.ts +0 -2
  192. package/lib/types/src/api/command/os/GetAppStorageInfoCommand.test.d.ts.map +0 -1
  193. package/lib/types/src/api/device-action/task/BackupAppStorageTask.d.ts +0 -23
  194. package/lib/types/src/api/device-action/task/BackupAppStorageTask.d.ts.map +0 -1
  195. package/lib/types/src/api/device-action/task/BackupAppStorageTask.test.d.ts +0 -2
  196. package/lib/types/src/api/device-action/task/BackupAppStorageTask.test.d.ts.map +0 -1
  197. package/lib/types/src/api/storage/KeyValueStorage.d.ts +0 -7
  198. package/lib/types/src/api/storage/KeyValueStorage.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Device Management Kit Library Documentation
2
2
 
3
- > [!CAUTION]
4
- > This is still under development and we are free to make new interfaces which may lead to Device Management Kit breaking changes.
5
-
6
3
  - [Device Management Kit Library Documentation](#device-management-kit-library-documentation)
7
4
  - [Description](#description)
8
5
  - [Installation](#installation)
@@ -62,5 +62,5 @@
62
62
  "watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
63
63
  "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
64
64
  },
65
- "version": "1.7.0"
65
+ "version": "1.8.0"
66
66
  }
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var T=(e,t)=>{for(var o in t)m(e,o,{get:t[o],enumerable:!0})},G=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of O(t))!U.call(e,p)&&p!==o&&m(e,p,{get:()=>t[p],enumerable:!(s=S(t,p))||s.enumerable});return e};var E=e=>G(m({},"__esModule",{value:!0}),e);var q={};T(q,{setupGetDeviceMetadataMock:()=>V,setupGetDeviceStatusMock:()=>b,setupGoToDashboardMock:()=>C,setupInstallOrUpdateAppsMock:()=>L,setupListAppsMock:()=>h,setupListInstalledAppsMock:()=>g,setupOpenAppMock:()=>_});module.exports=E(q);var a=require("purify-ts"),n=require("xstate"),i=require("../../device-action/model/UserInteractionRequired"),r=require("../../device-action/os/Errors"),c=require("../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction"),d=require("../../device-action/os/GetDeviceMetadata/types"),l=require("../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction"),A=require("../../device-action/os/GetDeviceStatus/types"),u=require("../../device-action/os/GoToDashboard/GoToDashboardDeviceAction"),f=require("../../device-action/os/GoToDashboard/types"),k=require("../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction"),D=require("../../device-action/os/ListApps/ListAppsDeviceAction"),I=require("../../device-action/os/ListApps/types"),y=require("../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction"),M=require("../../device-action/os/OpenAppDeviceAction/types"),v=require("../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction");const h=(e,t=!1)=>{D.ListAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockListAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.AllowListApps,step:I.listAppsDAStateStep.LIST_APPS})})},done:{type:"final"}},output:()=>t?(0,a.Left)(new r.UnknownDAError("ListApps failed")):(0,a.Right)(e)}))}))},V=(e,t=!1)=>{c.GetDeviceMetadataDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockGetDeviceMetadataDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:d.getDeviceMetadataDAStateStep.GET_DEVICE_METADATA})})},done:{type:"final"}},output:()=>t?(0,a.Left)(new r.UnknownDAError("GetDeviceMetadata failed")):(0,a.Right)(e)}))}))},L=(e,t,o=!1)=>{k.InstallOrUpdateAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockInstallOrUpdateAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>t})},done:{type:"final"}},output:()=>o?(0,a.Left)(new r.UnknownDAError("InstallOrUpdateApps failed")):(0,a.Right)(e)}))}))},_=(e=!1)=>{y.OpenAppDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({initial:"ready",states:{ready:{entry:(0,n.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.ConfirmOpenApp,step:M.openAppDAStateStep.GET_DEVICE_STATUS}}),after:{0:"done"}},done:{type:"final"}},output:()=>e?(0,a.Left)(new r.UnknownDAError("OpenApp failed")):(0,a.Right)(void 0)}))}))},C=(e=!1)=>{u.GoToDashboardDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockGoToDashboardDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:f.goToDashboardDAStateStep.GET_DEVICE_STATUS})})},done:{type:"final"}},output:()=>e?(0,a.Left)(new r.UnknownDAError("GoToDashboard failed")):(0,a.Right)(void 0)}))}))},b=(e=[{currentApp:"BOLOS",currentAppVersion:"1.0.0"}])=>{const t=vi.fn();for(const o of e)t.mockImplementationOnce(()=>"currentApp"in o?(0,a.Right)(o):(0,a.Left)(o));l.GetDeviceStatusDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockGetDeviceStatusDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:A.getDeviceStatusDAStateStep.ONBOARD_CHECK})})},done:{type:"final"}},output:t}))}))},g=(e=[])=>{v.ListInstalledAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,n.createMachine)({id:"MockListInstalledAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,n.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None})})},done:{type:"final"}},output:e.reduce((t,o)=>t.mockImplementationOnce(()=>"installedApps"in o?(0,a.Right)(o):(0,a.Left)(o)),vi.fn()).mockImplementation(()=>(0,a.Right)([]))}))}))};0&&(module.exports={setupGetDeviceMetadataMock,setupGetDeviceStatusMock,setupGoToDashboardMock,setupInstallOrUpdateAppsMock,setupListAppsMock,setupListInstalledAppsMock,setupOpenAppMock});
1
+ "use strict";var s=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var U=(e,t)=>{for(var a in t)s(e,a,{get:t[a],enumerable:!0})},T=(e,t,a,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of E(t))!G.call(e,p)&&p!==a&&s(e,p,{get:()=>t[p],enumerable:!(c=V(t,p))||c.enumerable});return e};var _=e=>T(s({},"__esModule",{value:!0}),e);var g={};U(g,{setupGetDeviceMetadataMock:()=>L,setupGetDeviceStatusMock:()=>w,setupGoToDashboardMock:()=>q,setupInstallOrUpdateAppsMock:()=>N,setupListAppsMock:()=>h,setupListInstalledAppsMock:()=>x,setupOpenAppMock:()=>P,setupWaitForAppAndVersionMock:()=>R});module.exports=_(g);var n=require("purify-ts"),o=require("xstate"),i=require("../../device-action/model/UserInteractionRequired"),r=require("../../device-action/os/Errors"),d=require("../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction"),l=require("../../device-action/os/GetDeviceMetadata/types"),A=require("../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction"),f=require("../../device-action/os/GetDeviceStatus/types"),u=require("../../device-action/os/GoToDashboard/GoToDashboardDeviceAction"),k=require("../../device-action/os/GoToDashboard/types"),D=require("../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction"),I=require("../../device-action/os/ListApps/ListAppsDeviceAction"),y=require("../../device-action/os/ListApps/types"),M=require("../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction"),v=require("../../device-action/os/OpenAppDeviceAction/types"),m=require("../../device-action/os/WaitForAppAndVersion/types"),S=require("../../device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction"),O=require("../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction");const h=(e,t=!1)=>{I.ListAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockListAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.AllowListApps,step:y.listAppsDAStateStep.LIST_APPS})})},done:{type:"final"}},output:()=>t?(0,n.Left)(new r.UnknownDAError("ListApps failed")):(0,n.Right)(e)}))}))},L=(e,t=!1)=>{d.GetDeviceMetadataDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockGetDeviceMetadataDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:l.getDeviceMetadataDAStateStep.GET_DEVICE_METADATA})})},done:{type:"final"}},output:()=>t?(0,n.Left)(new r.UnknownDAError("GetDeviceMetadata failed")):(0,n.Right)(e)}))}))},N=(e,t,a=!1)=>{D.InstallOrUpdateAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockInstallOrUpdateAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>t})},done:{type:"final"}},output:()=>a?(0,n.Left)(new r.UnknownDAError("InstallOrUpdateApps failed")):(0,n.Right)(e)}))}))},P=(e=!1)=>{M.OpenAppDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({initial:"ready",states:{ready:{entry:(0,o.assign)({intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.ConfirmOpenApp,step:v.openAppDAStateStep.GET_DEVICE_STATUS}}),after:{0:"done"}},done:{type:"final"}},output:()=>e?(0,n.Left)(new r.UnknownDAError("OpenApp failed")):(0,n.Right)(void 0)}))}))},q=(e=!1)=>{u.GoToDashboardDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockGoToDashboardDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:k.goToDashboardDAStateStep.GET_DEVICE_STATUS})})},done:{type:"final"}},output:()=>e?(0,n.Left)(new r.UnknownDAError("GoToDashboard failed")):(0,n.Right)(void 0)}))}))},w=(e=[{currentApp:"BOLOS",currentAppVersion:"1.0.0"}])=>{const t=vi.fn();for(const a of e)t.mockImplementationOnce(()=>"currentApp"in a?(0,n.Right)(a):(0,n.Left)(a));A.GetDeviceStatusDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockGetDeviceStatusDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None,step:f.getDeviceStatusDAStateStep.ONBOARD_CHECK})})},done:{type:"final"}},output:t}))}))},x=(e=[])=>{O.ListInstalledAppsDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockListInstalledAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:i.UserInteractionRequired.None})})},done:{type:"final"}},output:e.reduce((t,a)=>t.mockImplementationOnce(()=>"installedApps"in a?(0,n.Right)(a):(0,n.Left)(a)),vi.fn()).mockImplementation(()=>(0,n.Right)([]))}))}))},R=(e,t=i.UserInteractionRequired.None)=>{S.WaitForAppAndVersionDeviceAction.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>(0,o.createMachine)({id:"MockWaitForAppAndVersionDeviceAction",initial:"ready",context:{intermediateValue:{requiredUserInteraction:i.UserInteractionRequired.None,step:m.waitForAppAndVersionDAStateStep.GET_APP_AND_VERSION}},states:{ready:{after:{0:"done"},entry:(0,o.assign)({intermediateValue:()=>({requiredUserInteraction:t,step:m.waitForAppAndVersionDAStateStep.GET_APP_AND_VERSION})})},done:{type:"final"}},output:()=>"_tag"in e?(0,n.Left)(e):(0,n.Right)(e)}))}))};0&&(module.exports={setupGetDeviceMetadataMock,setupGetDeviceStatusMock,setupGoToDashboardMock,setupInstallOrUpdateAppsMock,setupListAppsMock,setupListInstalledAppsMock,setupOpenAppMock,setupWaitForAppAndVersionMock});
2
2
  //# sourceMappingURL=setupTestMachine.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/device-action/__test-utils__/setupTestMachine.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport {\n type GetDeviceMetadataDAOutput,\n getDeviceMetadataDAStateStep,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { getDeviceStatusDAStateStep } from \"@api/device-action/os/GetDeviceStatus/types\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { goToDashboardDAStateStep } from \"@api/device-action/os/GoToDashboard/types\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport {\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { listAppsDAStateStep } from \"@api/device-action/os/ListApps/types\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { openAppDAStateStep } from \"@api/device-action/os/OpenAppDeviceAction/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\n\nimport { type BTC_APP } from \"./data\";\n\ntype App = typeof BTC_APP;\n\nexport const setupListAppsMock = (apps: App[], error = false) => {\n (ListAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"ListApps failed\"))\n : Right(apps);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceMetadataMock = (\n metadata: GetDeviceMetadataDAOutput,\n error = false,\n) => {\n (GetDeviceMetadataDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceMetadataDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceMetadataDAStateStep.GET_DEVICE_METADATA,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GetDeviceMetadata failed\"))\n : Right(metadata);\n },\n }),\n ),\n }));\n};\n\nexport const setupInstallOrUpdateAppsMock = (\n result: InstallOrUpdateAppsDAOutput,\n intermediateValue: InstallOrUpdateAppsDAIntermediateValue,\n error = false,\n) => {\n (InstallOrUpdateAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockInstallOrUpdateAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => intermediateValue,\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"InstallOrUpdateApps failed\"))\n : Right(result);\n },\n }),\n ),\n }));\n};\n\nexport const setupOpenAppMock = (error: boolean = false) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"ready\",\n states: {\n ready: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"OpenApp failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGoToDashboardMock = (error: boolean = false) => {\n (GoToDashboardDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGoToDashboardDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: goToDashboardDAStateStep.GET_DEVICE_STATUS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GoToDashboard failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceStatusMock = (\n outputs: ReadonlyArray<\n { currentApp: string; currentAppVersion: string } | DmkError\n > = [\n {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n ],\n) => {\n const outputFn = vi.fn();\n\n for (const output of outputs) {\n outputFn.mockImplementationOnce(() =>\n \"currentApp\" in output ? Right(output) : Left(output),\n );\n }\n (GetDeviceStatusDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceStatusDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputFn,\n }),\n ),\n }));\n};\n\nexport const setupListInstalledAppsMock = (\n outputs: Array<{ installedApps: InstalledApp[] } | DmkError> = [],\n) => {\n (ListInstalledAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListInstalledAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputs\n .reduce(\n (mockFn, output) =>\n mockFn.mockImplementationOnce(() =>\n \"installedApps\" in output ? Right(output) : Left(output),\n ),\n vi.fn(),\n )\n .mockImplementation(() => Right([])),\n }),\n ),\n }));\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,EAAA,6BAAAC,EAAA,2BAAAC,EAAA,iCAAAC,EAAA,sBAAAC,EAAA,+BAAAC,EAAA,qBAAAC,IAAA,eAAAC,EAAAT,GAAA,IAAAU,EAA4B,qBAE5BC,EAAsC,kBAEtCC,EAAwC,4DACxCC,EAA+B,wCAC/BC,EAA8C,i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C,KAAUF,EACnBC,EAAS,uBAAuB,IAC9B,eAAgBC,KAAS,SAAMA,CAAM,KAAI,QAAKA,CAAM,CACtD,EAED,8BAAqC,mBAAmB,KAAO,CAC9D,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,OAC3C,iBAAc,CACZ,GAAI,kCACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,SAAO,UAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyB,0BAAwB,KACjD,KAAM,6BAA2B,aACnC,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQD,CACV,CAAC,CACH,CACF,EAAE,CACJ,EAEarB,EAA6B,CACxCoB,EAA+D,CAAC,IAC7D,CACF,gCAAuC,mBAAmB,KAAO,CAChE,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,OAC3C,iBAAc,CACZ,GAAI,oCACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,SAAO,UAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyB,0BAAwB,IACnD,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQA,EACL,OACC,CAACG,EAAQD,IACPC,EAAO,uBAAuB,IAC5B,kBAAmBD,KAAS,SAAMA,CAAM,KAAI,QAAKA,CAAM,CACzD,EACF,GAAG,GAAG,CACR,EACC,mBAAmB,OAAM,SAAM,CAAC,CAAC,CAAC,CACvC,CAAC,CACH,CACF,EAAE,CACJ",
6
- "names": ["setupTestMachine_exports", "__export", "setupGetDeviceMetadataMock", "setupGetDeviceStatusMock", "setupGoToDashboardMock", "setupInstallOrUpdateAppsMock", "setupListAppsMock", "setupListInstalledAppsMock", "setupOpenAppMock", "__toCommonJS", "import_purify_ts", "import_xstate", "import_UserInteractionRequired", "import_Errors", "import_GetDeviceMetadataDeviceAction", "import_types", "import_GetDeviceStatusDeviceAction", "import_GoToDashboardDeviceAction", "import_InstallOrUpdateAppsDeviceAction", "import_ListAppsDeviceAction", "import_OpenAppDeviceAction", "import_ListInstalledAppsDeviceAction", "apps", "error", "metadata", "result", "intermediateValue", "outputs", "outputFn", "output", "mockFn"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type GetAppAndVersionResponse } from \"@api/command/os/GetAppAndVersionCommand\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport {\n type GetDeviceMetadataDAOutput,\n getDeviceMetadataDAStateStep,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { getDeviceStatusDAStateStep } from \"@api/device-action/os/GetDeviceStatus/types\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { goToDashboardDAStateStep } from \"@api/device-action/os/GoToDashboard/types\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport {\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { listAppsDAStateStep } from \"@api/device-action/os/ListApps/types\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { openAppDAStateStep } from \"@api/device-action/os/OpenAppDeviceAction/types\";\nimport { waitForAppAndVersionDAStateStep } from \"@api/device-action/os/WaitForAppAndVersion/types\";\nimport { WaitForAppAndVersionDeviceAction } from \"@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction\";\nimport { type DmkError } from \"@api/Error\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\n\nimport { type BTC_APP } from \"./data\";\n\ntype App = typeof BTC_APP;\n\nexport const setupListAppsMock = (apps: App[], error = false) => {\n (ListAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"ListApps failed\"))\n : Right(apps);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceMetadataMock = (\n metadata: GetDeviceMetadataDAOutput,\n error = false,\n) => {\n (GetDeviceMetadataDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceMetadataDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceMetadataDAStateStep.GET_DEVICE_METADATA,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GetDeviceMetadata failed\"))\n : Right(metadata);\n },\n }),\n ),\n }));\n};\n\nexport const setupInstallOrUpdateAppsMock = (\n result: InstallOrUpdateAppsDAOutput,\n intermediateValue: InstallOrUpdateAppsDAIntermediateValue,\n error = false,\n) => {\n (InstallOrUpdateAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockInstallOrUpdateAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => intermediateValue,\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"InstallOrUpdateApps failed\"))\n : Right(result);\n },\n }),\n ),\n }));\n};\n\nexport const setupOpenAppMock = (error: boolean = false) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"ready\",\n states: {\n ready: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"OpenApp failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGoToDashboardMock = (error: boolean = false) => {\n (GoToDashboardDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGoToDashboardDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: goToDashboardDAStateStep.GET_DEVICE_STATUS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GoToDashboard failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceStatusMock = (\n outputs: ReadonlyArray<\n { currentApp: string; currentAppVersion: string } | DmkError\n > = [\n {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n ],\n) => {\n const outputFn = vi.fn();\n\n for (const output of outputs) {\n outputFn.mockImplementationOnce(() =>\n \"currentApp\" in output ? Right(output) : Left(output),\n );\n }\n (GetDeviceStatusDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceStatusDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputFn,\n }),\n ),\n }));\n};\n\nexport const setupListInstalledAppsMock = (\n outputs: Array<{ installedApps: InstalledApp[] } | DmkError> = [],\n) => {\n (ListInstalledAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListInstalledAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputs\n .reduce(\n (mockFn, output) =>\n mockFn.mockImplementationOnce(() =>\n \"installedApps\" in output ? Right(output) : Left(output),\n ),\n vi.fn(),\n )\n .mockImplementation(() => Right([])),\n }),\n ),\n }));\n};\n\nexport const setupWaitForAppAndVersionMock = (\n output: GetAppAndVersionResponse | DmkError,\n requiredUserInteraction: UserInteractionRequired = UserInteractionRequired.None,\n) => {\n (WaitForAppAndVersionDeviceAction as unknown as Mock).mockImplementation(\n () => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockWaitForAppAndVersionDeviceAction\",\n initial: \"ready\",\n context: {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: waitForAppAndVersionDAStateStep.GET_APP_AND_VERSION,\n },\n },\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction,\n step: waitForAppAndVersionDAStateStep.GET_APP_AND_VERSION,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (\"_tag\" in output ? Left(output) : Right(output)),\n }),\n ),\n }),\n );\n};\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,EAAA,6BAAAC,EAAA,2BAAAC,EAAA,iCAAAC,EAAA,sBAAAC,EAAA,+BAAAC,EAAA,qBAAAC,EAAA,kCAAAC,IAAA,eAAAC,EAAAV,GAAA,IAAAW,EAA4B,qBAE5BC,EAAsC,kBAGtCC,EAAwC,4DACxCC,EAA+B,wCAC/BC,EAA8C,iFAC9CC,EAGO,yDACPC,EAA4C,6EAC5CD,EAA2C,uDAC3CE,EAA0C,yEAC1CF,EAAyC,qDACzCG,EAAgD,qFAKhDC,EAAqC,+DACrCJ,EAAoC,gDACpCK,EAAoC,yEACpCL,EAAmC,2DACnCA,EAAgD,4DAChDM,EAAiD,uFAEjDC,EAA8C,6FAOvC,MAAMjB,EAAoB,CAACkB,EAAaC,EAAQ,KAAU,CAC9D,uBAA8B,mBAAmB,KAAO,CACvD,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,OAC3C,iBAAc,CACZ,GAAI,2BACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,SAAO,UAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyB,0BAAwB,cACjD,KAAM,sBAAoB,SAC5B,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQ,IACCA,KACH,QAAK,IAAI,iBAAe,iBAAiB,CAAC,KAC1C,SAAMD,CAAI,CAElB,CAAC,CACH,CACF,EAAE,CACJ,EAEatB,EAA6B,CACxCwB,EACAD,EAAQ,KACL,CACF,gCAAuC,mBAAmB,KAAO,CAChE,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,OAC3C,iBAAc,CACZ,G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C,CAACG,EAAQD,IACPC,EAAO,uBAAuB,IAC5B,kBAAmBD,KAAS,SAAMA,CAAM,KAAI,QAAKA,CAAM,CACzD,EACF,GAAG,GAAG,CACR,EACC,mBAAmB,OAAM,SAAM,CAAC,CAAC,CAAC,CACvC,CAAC,CACH,CACF,EAAE,CACJ,EAEatB,EAAgC,CAC3CsB,EACAE,EAAmD,0BAAwB,OACxE,CACF,mCAAqD,mBACpD,KAAO,CACL,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,OAC3C,iBAAc,CACZ,GAAI,uCACJ,QAAS,QACT,QAAS,CACP,kBAAmB,CACjB,wBAAyB,0BAAwB,KACjD,KAAM,kCAAgC,mBACxC,CACF,EACA,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,SAAO,UAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAAA,EACA,KAAM,kCAAgC,mBACxC,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQ,IAAO,SAAUF,KAAS,QAAKA,CAAM,KAAI,SAAMA,CAAM,CAC/D,CAAC,CACH,CACF,EACF,CACF",
6
+ "names": ["setupTestMachine_exports", "__export", "setupGetDeviceMetadataMock", "setupGetDeviceStatusMock", "setupGoToDashboardMock", "setupInstallOrUpdateAppsMock", "setupListAppsMock", "setupListInstalledAppsMock", "setupOpenAppMock", "setupWaitForAppAndVersionMock", "__toCommonJS", "import_purify_ts", "import_xstate", "import_UserInteractionRequired", "import_Errors", "import_GetDeviceMetadataDeviceAction", "import_types", "import_GetDeviceStatusDeviceAction", "import_GoToDashboardDeviceAction", "import_InstallOrUpdateAppsDeviceAction", "import_ListAppsDeviceAction", "import_OpenAppDeviceAction", "import_WaitForAppAndVersionDeviceAction", "import_ListInstalledAppsDeviceAction", "apps", "error", "metadata", "result", "intermediateValue", "outputs", "outputFn", "output", "mockFn", "requiredUserInteraction"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(g,m)=>{for(var a in m)p(g,a,{get:m[a],enumerable:!0})},v=(g,m,a,f)=>{if(m&&typeof m=="object"||typeof m=="function")for(let l of n(m))!A.call(g,l)&&l!==a&&p(g,l,{get:()=>m[l],enumerable:!(f=i(m,l))||f.enumerable});return g};var w=g=>v(p({},"__esModule",{value:!0}),g);var y={};C(y,{UserInteractionRequired:()=>s});module.exports=w(y);var s=(o=>(o.None="none",o.UnlockDevice="unlock-device",o.AllowSecureConnection="allow-secure-connection",o.ConfirmOpenApp="confirm-open-app",o.SignTransaction="sign-transaction",o.SignTypedData="sign-typed-data",o.AllowListApps="allow-list-apps",o.VerifyAddress="verify-address",o.SignPersonalMessage="sign-personal-message",o.SignDelegationAuthorization="sign-delegation-authorization",o.Web3ChecksOptIn="web3-checks-opt-in",o.VerifySafeAddress="verify-safe-address",o.RegisterWallet="register-wallet",o.ConfirmLoadImage="confirm-load-image",o.ConfirmCommitImage="confirm-commit-image",o.ConfirmRemoveImage="confirm-remove-image",o))(s||{});0&&(module.exports={UserInteractionRequired});
1
+ "use strict";var p=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var A=(a,o)=>{for(var g in o)p(a,g,{get:o[g],enumerable:!0})},C=(a,o,g,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of w(o))!i.call(a,m)&&m!==g&&p(a,m,{get:()=>o[m],enumerable:!(s=n(o,m))||s.enumerable});return a};var v=a=>C(p({},"__esModule",{value:!0}),a);var y={};A(y,{UserInteractionRequired:()=>f});module.exports=v(y);var f=(l=>(l.None="none",l.UnlockDevice="unlock-device",l.AllowSecureConnection="allow-secure-connection",l.ConfirmOpenApp="confirm-open-app",l.SignTransaction="sign-transaction",l.SignTypedData="sign-typed-data",l.AllowListApps="allow-list-apps",l.VerifyAddress="verify-address",l.SignPersonalMessage="sign-personal-message",l.SignDelegationAuthorization="sign-delegation-authorization",l.Web3ChecksOptIn="web3-checks-opt-in",l.VerifySafeAddress="verify-safe-address",l.RegisterWallet="register-wallet",l.ConfirmLoadImage="confirm-load-image",l.ConfirmCommitImage="confirm-commit-image",l.ConfirmRemoveImage="confirm-remove-image",l.GrantConsent="grant-consent",l.AllowInstallFirmware="allow-install-firmware",l))(f||{});0&&(module.exports={UserInteractionRequired});
2
2
  //# sourceMappingURL=UserInteractionRequired.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/device-action/model/UserInteractionRequired.ts"],
4
- "sourcesContent": ["/**\n * The user interaction required on the device to move further in a device action.\n * This is used to inform the users about the action they need to take on the device.\n */\nexport enum UserInteractionRequired {\n None = \"none\",\n UnlockDevice = \"unlock-device\",\n AllowSecureConnection = \"allow-secure-connection\",\n ConfirmOpenApp = \"confirm-open-app\",\n SignTransaction = \"sign-transaction\",\n SignTypedData = \"sign-typed-data\",\n AllowListApps = \"allow-list-apps\",\n VerifyAddress = \"verify-address\",\n SignPersonalMessage = \"sign-personal-message\",\n SignDelegationAuthorization = \"sign-delegation-authorization\",\n Web3ChecksOptIn = \"web3-checks-opt-in\",\n VerifySafeAddress = \"verify-safe-address\",\n RegisterWallet = \"register-wallet\",\n ConfirmLoadImage = \"confirm-load-image\",\n ConfirmCommitImage = \"confirm-commit-image\",\n ConfirmRemoveImage = \"confirm-remove-image\",\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAIO,IAAKE,OACVA,EAAA,KAAO,OACPA,EAAA,aAAe,gBACfA,EAAA,sBAAwB,0BACxBA,EAAA,eAAiB,mBACjBA,EAAA,gBAAkB,mBAClBA,EAAA,cAAgB,kBAChBA,EAAA,cAAgB,kBAChBA,EAAA,cAAgB,iBAChBA,EAAA,oBAAsB,wBACtBA,EAAA,4BAA8B,gCAC9BA,EAAA,gBAAkB,qBAClBA,EAAA,kBAAoB,sBACpBA,EAAA,eAAiB,kBACjBA,EAAA,iBAAmB,qBACnBA,EAAA,mBAAqB,uBACrBA,EAAA,mBAAqB,uBAhBXA,OAAA",
4
+ "sourcesContent": ["/**\n * The user interaction required on the device to move further in a device action.\n * This is used to inform the users about the action they need to take on the device.\n */\nexport enum UserInteractionRequired {\n None = \"none\",\n UnlockDevice = \"unlock-device\",\n AllowSecureConnection = \"allow-secure-connection\",\n ConfirmOpenApp = \"confirm-open-app\",\n SignTransaction = \"sign-transaction\",\n SignTypedData = \"sign-typed-data\",\n AllowListApps = \"allow-list-apps\",\n VerifyAddress = \"verify-address\",\n SignPersonalMessage = \"sign-personal-message\",\n SignDelegationAuthorization = \"sign-delegation-authorization\",\n Web3ChecksOptIn = \"web3-checks-opt-in\",\n VerifySafeAddress = \"verify-safe-address\",\n RegisterWallet = \"register-wallet\",\n ConfirmLoadImage = \"confirm-load-image\",\n ConfirmCommitImage = \"confirm-commit-image\",\n ConfirmRemoveImage = \"confirm-remove-image\",\n GrantConsent = \"grant-consent\",\n AllowInstallFirmware = \"allow-install-firmware\",\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAIO,IAAKE,OACVA,EAAA,KAAO,OACPA,EAAA,aAAe,gBACfA,EAAA,sBAAwB,0BACxBA,EAAA,eAAiB,mBACjBA,EAAA,gBAAkB,mBAClBA,EAAA,cAAgB,kBAChBA,EAAA,cAAgB,kBAChBA,EAAA,cAAgB,iBAChBA,EAAA,oBAAsB,wBACtBA,EAAA,4BAA8B,gCAC9BA,EAAA,gBAAkB,qBAClBA,EAAA,kBAAoB,sBACpBA,EAAA,eAAiB,kBACjBA,EAAA,iBAAmB,qBACnBA,EAAA,mBAAqB,uBACrBA,EAAA,mBAAqB,uBACrBA,EAAA,aAAe,gBACfA,EAAA,qBAAuB,yBAlBbA,OAAA",
6
6
  "names": ["UserInteractionRequired_exports", "__export", "UserInteractionRequired", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var V=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var w=(o,r)=>{for(var s in r)V(o,s,{get:r[s],enumerable:!0})},R=(o,r,s,u)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of I(r))!M.call(o,i)&&i!==s&&V(o,i,{get:()=>r[i],enumerable:!(u=x(r,i))||u.enumerable});return o};var N=o=>R(V({},"__esModule",{value:!0}),o);var _={};w(_,{GetDeviceStatusDeviceAction:()=>F});module.exports=N(_);var D=require("purify-ts"),n=require("rxjs"),E=require("rxjs/operators"),t=require("xstate"),S=require("../../../command/model/CommandResult"),g=require("../../../command/os/GetAppAndVersionCommand"),f=require("../../../command/os/GetOsVersionCommand"),O=require("../../../device/DeviceStatus"),p=require("../../../device-action/model/UserInteractionRequired"),C=require("../../../device-action/os/Const"),v=require("../../../device-action/os/Errors"),G=require("../../../device-action/xstate-utils/XStateDeviceAction"),l=require("../../../device-session/DeviceSessionState"),A=require("../../../utils/AppName"),m=require("./types");const T=o=>({mcu:o.mcuSephVersion,bootloader:o.mcuBootloaderVersion,os:o.seVersion,metadata:o});class F extends G.XStateDeviceAction{makeStateMachine(r){const{getAppAndVersion:s,getOsVersion:u,getDeviceSessionState:i,setDeviceSessionState:c,waitForDeviceUnlock:y}=this.extractDependencies(r),k=this.input.unlockTimeout??C.DEFAULT_UNLOCK_TIMEOUT_MS,h=e=>{const a=i();a.sessionStateType!==l.DeviceSessionStateType.Connected&&c({...a,firmwareVersion:T(e),isSecureConnectionAllowed:e.secureElementFlags.isSecureConnectionAllowed})};return(0,t.setup)({types:{input:{unlockTimeout:k},context:{},output:{}},actors:{getAppAndVersion:(0,t.fromPromise)(s),getOsVersion:(0,t.fromPromise)(u),waitForDeviceUnlock:(0,t.fromObservable)(y)},guards:{isCurrentAppBolos:({context:e})=>(0,A.isDashboardName)(e._internalState.currentApp),isOnboardedFromOsVersion:({context:e})=>e._internalState.osVersionMetadata?.secureElementFlags.isOnboarded===!0,isDeviceLocked:({context:e})=>e._internalState.locked,hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:(0,t.assign)({_internalState:e=>({...e.context._internalState,error:new v.DeviceNotOnboardedError})}),assignErrorDeviceLocked:(0,t.assign)({_internalState:e=>({...e.context._internalState,error:new v.DeviceLockedError}),intermediateValue:{requiredUserInteraction:p.UserInteractionRequired.UnlockDevice,step:m.getDeviceStatusDAStateStep.UNLOCK_DEVICE}}),assignErrorFromEvent:(0,t.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoUserActionNeeded:(0,t.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:p.UserInteractionRequired.None})}),assignUserActionUnlockNeeded:(0,t.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:p.UserInteractionRequired.UnlockDevice,step:m.getDeviceStatusDAStateStep.UNLOCK_DEVICE})})}}).createMachine({id:"GetDeviceStatusDeviceAction",initial:"DeviceReady",context:e=>{const a=i(),{sessionStateType:d}=a;return{input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:p.UserInteractionRequired.None,step:m.getDeviceStatusDAStateStep.ONBOARD_CHECK},_internalState:{onboarded:!1,locked:!1,currentApp:d===l.DeviceSessionStateType.ReadyWithoutSecureChannel?a.currentApp.name:null,currentAppVersion:null,osVersionMetadata:null,error:null}}},states:{DeviceReady:{always:{target:"AppAndVersionCheck"}},AppAndVersionCheck:{invoke:{src:"getAppAndVersion",onDone:{target:"ApplicationAvailableResultCheck",actions:(0,t.assign)({_internalState:e=>{if((0,S.isSuccessCommandResult)(e.event.output)){const a=i();return a.sessionStateType!==l.DeviceSessionStateType.Connected?c({...a,currentApp:e.event.output.data}):c({deviceModelId:a.deviceModelId,sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:O.DeviceStatus.CONNECTED,currentApp:e.event.output.data,installedApps:[],isSecureConnectionAllowed:!1}),{...e.context._internalState,locked:!1,currentApp:e.event.output.data.name,currentAppVersion:e.event.output.data.version}}if("errorCode"in e.event.output.error){if(e.event.output.error.errorCode==="5515")return{...e.context._internalState,locked:!0};if(e.event.output.error.errorCode==="6e00")return{...e.context._internalState,locked:!1,currentApp:A.LEDGER_OS_NAME,currentAppVersion:"0.0.0"}}return{...e.context._internalState,error:e.event.output.error}}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ApplicationAvailableResultCheck:{always:[{guard:"hasError",target:"Error"},{target:"UserActionUnlockDevice",guard:"isDeviceLocked"},{target:"OnboardingCheck"}]},OnboardingCheck:{always:[{guard:"isCurrentAppBolos",target:"GetOsVersion"},{target:"Success",actions:(0,t.assign)({_internalState:e=>({...e.context._internalState,onboarded:!0})})}]},GetOsVersion:{invoke:{src:"getOsVersion",onDone:{target:"OnboardingResultCheck",actions:(0,t.assign)({_internalState:e=>(0,S.isSuccessCommandResult)(e.event.output)?(h(e.event.output.data),{...e.context._internalState,osVersionMetadata:e.event.output.data}):{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OnboardingResultCheck:{always:[{guard:"hasError",target:"Error"},{guard:"isOnboardedFromOsVersion",target:"Success",actions:(0,t.assign)({_internalState:e=>({...e.context._internalState,onboarded:!0})})},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},UserActionUnlockDevice:{entry:"assignUserActionUnlockNeeded",exit:"assignNoUserActionNeeded",invoke:{id:"UserActionUnlockDevice",src:"waitForDeviceUnlock",input:e=>({unlockTimeout:k}),onDone:{target:"AppAndVersionCheck",actions:(0,t.assign)({_internalState:e=>({...e.context._internalState,locked:!1})})},onError:{target:"Error",actions:"assignErrorDeviceLocked"}}},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:a}=e,{error:d,currentApp:U,currentAppVersion:b}=a._internalState;return d?(0,D.Left)(d):(0,D.Right)({currentApp:U,currentAppVersion:b})}})}extractDependencies(r){return{getAppAndVersion:()=>r.sendCommand(new g.GetAppAndVersionCommand),getOsVersion:()=>r.sendCommand(new f.GetOsVersionCommand),waitForDeviceUnlock:({input:i})=>(0,n.interval)(1e3).pipe((0,n.switchMap)(()=>(0,n.from)(r.sendCommand(new g.GetAppAndVersionCommand))),(0,n.mergeMap)(c=>!(0,S.isSuccessCommandResult)(c)&&"errorCode"in c.error&&c.error.errorCode==="5515"?n.EMPTY:(0,n.of)(void 0)),(0,n.take)(1),(0,E.timeout)(i.unlockTimeout)),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:i=>r.setDeviceSessionState(i)}}}0&&(module.exports={GetDeviceStatusDeviceAction});
1
+ "use strict";var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var x=(r,t)=>{for(var i in t)l(r,i,{get:t[i],enumerable:!0})},F=(r,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of C(t))!w.call(r,a)&&a!==i&&l(r,a,{get:()=>t[a],enumerable:!(c=b(t,a))||c.enumerable});return r};var R=r=>F(l({},"__esModule",{value:!0}),r);var _={};x(_,{GetDeviceStatusDeviceAction:()=>T});module.exports=R(_);var p=require("purify-ts"),o=require("xstate"),m=require("../../../command/model/CommandResult"),v=require("../../../command/os/GetOsVersionCommand"),A=require("../../../device/DeviceStatus"),d=require("../../../device-action/model/UserInteractionRequired"),V=require("../../../device-action/os/Const"),O=require("../../../device-action/os/Errors"),g=require("../../../device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction"),y=require("../../../device-action/xstate-utils/XStateDeviceAction"),u=require("../../../device-session/DeviceSessionState"),h=require("../../../utils/AppName"),S=require("./types");const N=r=>({mcu:r.mcuSephVersion,bootloader:r.mcuBootloaderVersion,os:r.seVersion,metadata:r});class T extends y.XStateDeviceAction{makeStateMachine(t){const{getOsVersion:i,getDeviceSessionState:c,setDeviceSessionState:a}=this.extractDependencies(t),D=this.input.unlockTimeout??V.DEFAULT_UNLOCK_TIMEOUT_MS,E=this.input.allowNonOnboardedDevice??!0,G=e=>{const n=c();n.sessionStateType!==u.DeviceSessionStateType.Connected&&a({...n,firmwareVersion:N(e),isSecureConnectionAllowed:e.secureElementFlags.isSecureConnectionAllowed})},f=new g.WaitForAppAndVersionDeviceAction({input:{unlockTimeout:D}}).makeStateMachine(t);return(0,o.setup)({types:{input:{unlockTimeout:D,allowNonOnboardedDevice:E},context:{},output:{}},actors:{waitForAppAndVersion:f,getOsVersion:(0,o.fromPromise)(i)},guards:{isCurrentAppBolos:({context:e})=>(0,h.isDashboardName)(e._internalState.currentApp),isOnboardedFromOsVersion:({context:e})=>e._internalState.osVersionMetadata?.secureElementFlags.isOnboarded===!0,isAllowedNonOnboardedDevice:({context:e})=>{const n=e._internalState.osVersionMetadata?.secureElementFlags;return e.input.allowNonOnboardedDevice===!0&&n?.isOnboarded===!1},hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:(0,o.assign)({_internalState:e=>({...e.context._internalState,error:new O.DeviceNotOnboardedError})}),assignErrorFromEvent:(0,o.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GetDeviceStatusDeviceAction",initial:"DeviceReady",context:e=>{const n=c(),{sessionStateType:s}=n;return{input:{unlockTimeout:e.input.unlockTimeout,allowNonOnboardedDevice:e.input.allowNonOnboardedDevice??!0},intermediateValue:{requiredUserInteraction:d.UserInteractionRequired.None,step:S.getDeviceStatusDAStateStep.WAIT_FOR_APP_AND_VERSION},_internalState:{onboarded:!1,currentApp:s===u.DeviceSessionStateType.ReadyWithoutSecureChannel?n.currentApp.name:null,currentAppVersion:null,osVersionMetadata:null,error:null}}},states:{DeviceReady:{always:{target:"WaitForAppAndVersion"}},WaitForAppAndVersion:{invoke:{src:"waitForAppAndVersion",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:(0,o.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"WaitForAppAndVersionResultCheck",actions:(0,o.assign)({_internalState:e=>e.event.output.caseOf({Left:n=>({...e.context._internalState,error:n}),Right:n=>{const s=c();return s.sessionStateType!==u.DeviceSessionStateType.Connected?a({...s,currentApp:n}):a({deviceModelId:s.deviceModelId,sessionStateType:u.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:A.DeviceStatus.CONNECTED,currentApp:n,installedApps:[],isSecureConnectionAllowed:!1}),{...e.context._internalState,currentApp:n.name,currentAppVersion:n.version}}})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},WaitForAppAndVersionResultCheck:{always:[{guard:"hasError",target:"Error"},{target:"OnboardingCheck"}]},OnboardingCheck:{entry:(0,o.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:d.UserInteractionRequired.None,step:S.getDeviceStatusDAStateStep.ONBOARD_CHECK})}),always:[{guard:"isCurrentAppBolos",target:"GetOsVersion"},{target:"Success",actions:(0,o.assign)({_internalState:e=>({...e.context._internalState,onboarded:!0})})}]},GetOsVersion:{invoke:{src:"getOsVersion",onDone:{target:"OnboardingResultCheck",actions:(0,o.assign)({_internalState:e=>(0,m.isSuccessCommandResult)(e.event.output)?(G(e.event.output.data),{...e.context._internalState,osVersionMetadata:e.event.output.data}):{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OnboardingResultCheck:{always:[{guard:"hasError",target:"Error"},{guard:"isOnboardedFromOsVersion",target:"Success",actions:(0,o.assign)({_internalState:e=>({...e.context._internalState,onboarded:!0})})},{guard:"isAllowedNonOnboardedDevice",target:"Success"},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:n}=e,{error:s,currentApp:I,currentAppVersion:M}=n._internalState;return s?(0,p.Left)(s):(0,p.Right)({currentApp:I,currentAppVersion:M})}})}extractDependencies(t){return{getOsVersion:()=>t.sendCommand(new v.GetOsVersionCommand),getDeviceSessionState:()=>t.getDeviceSessionState(),setDeviceSessionState:i=>t.setDeviceSessionState(i)}}}0&&(module.exports={GetDeviceStatusDeviceAction});
2
2
  //# sourceMappingURL=GetDeviceStatusDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport {\n EMPTY,\n from,\n interval,\n mergeMap,\n type Observable,\n of,\n switchMap,\n take,\n} from \"rxjs\";\nimport { timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getOsVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n getOsVersion: fromPromise(getOsVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isDeviceLocked: ({ context }) => context._internalState.locked,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzadjiHx2KyORbzcRBczmH4IbTOdjaabaKmdGy6XSRaIw1bbdZJLa0MBI9LsVHo45Ys4XBr45r3dps-n0ubaGxgx6PZlWULkkLBGmDCzGYzQ2Ei+HJEVStjsACqsDA+SdrBdrAANmjqmthBA2GB2MVsMxqmG3R6vT7-TU1hJcdcVXciYgglZycYQiYqRTQoZtMynDmbM4aW8rHYzD4BSs4hL7eLuF7Xe7PWk2AmA0GPflmPl2LJfeQAGbDgC2nbjPe9fv7IpTyqaGdAbXmxnZPkMNNM820VuZ+8M7Dsb3MznpwW31sFtpbGwdEo7dFksjorAgADUPYobAnNiIasGGEZRmGT4JC+bY7NKH5fj+-75IBrDAdUCAQfg5DpCmq5XDcqqZmMjgGDY-yGJeejjFRzJ2P47DZoEJb+Hyx42sKz5ioiC7sIh35-gB6QYcIg7DqO45oFO+SztBhCtrxuwCchwlAQqWGsJGOHNPh9SEemhKbogdLsIMTjmPuNF1nYZaOBW+5OPu9l1oCjZCs2ME8Y6fGIb6BC4WwdDYKQuDjtkvq8HAFC+mgokEXi65GeoiBguYZJOPSJa6Hm1hGsyuglkxxiUjYVjXlq7nyaKCI+cpn7+Tp6TBaF4WRXwsAxXFCpiEqBlJS0JFAo4vg+BCe55e8-QFUVVglVShjlWRtZ2FEgqsMwEBwKo1WKXVG5pgNaokmRZmQg4fyLHR7ieCNpjGPyx7aNo6UNo4nGeQpsFKdKax8AIoyJQSg3Ge0L07q9F3+Istk3Qg1IjUaZ7GNS-LlU4H1wt9+3OvseSFBiGFrsDx01mZ15mHooReFaVj0fZ5Jci5zissYIKY3a2NvnxsrVITCrE8RoMdDucxWgx1jpZCELDHDgKTC9jg6mNXKLDSHPcbV3O7LG3bNH2SYioLB3EmCI1-HuVL6Cj4hU6eNjsIVD3UrWfKXVCj5cV5Wvtr5n6CShaFE-1JMkWzPgXpCjh+Faw3Mjq5jdOlJhGvo-RzRr3uvr79VjgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n _internalState: {\n onboarded: false,\n locked: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"AppAndVersionCheck\",\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n } else {\n // The device can be set to Ready if GetAppAndVersionCommand was successful.\n // The firmware version and secure connection flag are enriched later from\n // the OS version, which can only be read on the dashboard.\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: _.event.output.data,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n if (\"errorCode\" in _.event.output.error) {\n if (_.event.output.error.errorCode === \"5515\") {\n // Locked device error\n return {\n ..._.context._internalState,\n locked: true,\n };\n } else if (_.event.output.error.errorCode === \"6e00\") {\n // CLA not supported\n // GetAppAndVersion should always be supported by the firmware or any app.\n // But on old firmware versions, that APDU was not supported in the dashboard.\n // On those firmwares, it fails with CLA_NOT_SUPPORTED in BOLOS, and INS_NOT_SUPPORTED\n // in applications. Therefore if CLA is not supported, we can consider we're on the\n // dashboard on an old firmware. We should therefore return that information to\n // ensure the user can still update his firmware and is not blocked at this step.\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: LEDGER_OS_NAME,\n currentAppVersion: \"0.0.0\",\n };\n }\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"UserActionUnlockDevice\",\n guard: \"isDeviceLocked\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n interval(1000).pipe(\n switchMap(() =>\n from(internalApi.sendCommand(new GetAppAndVersionCommand())),\n ),\n mergeMap((output) => {\n const isLocked =\n !isSuccessCommandResult(output) &&\n \"errorCode\" in output.error &&\n output.error.errorCode === \"5515\";\n if (isLocked) {\n return EMPTY; // Continue the polling\n }\n return of(undefined); // Complete the observable\n }),\n take(1),\n timeout(input.unlockTimeout),\n );\n\n return {\n getAppAndVersion,\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA4B,qBAC5BC,EASO,gBACPC,EAAwB,0BACxBC,EAA2D,kBAE3DC,EAAuC,4CACvCC,EAGO,mDACPC,EAIO,+CACPC,EAA6B,oCAE7BC,EAAwC,4DACxCC,EAA0C,uCAC1CC,EAGO,wCAEPC,EAGO,8DACPC,EAIO,kDACPC,EAAgD,8BAEhDC,EAMO,mBAuBP,MAAMC,EACJC,IACqB,CACrB,IAAKA,EAAK,eACV,WAAYA,EAAK,qBACjB,GAAIA,EAAK,UACT,SAAUA,CACZ,GAMO,MAAMlB,UAAoC,oBA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usDeviceAction_exports", "__export", "GetDeviceStatusDeviceAction", "__toCommonJS", "import_purify_ts", "import_rxjs", "import_operators", "import_xstate", "import_CommandResult", "import_GetAppAndVersionCommand", "import_GetOsVersionCommand", "import_DeviceStatus", "import_UserInteractionRequired", "import_Const", "import_Errors", "import_XStateDeviceAction", "import_DeviceSessionState", "import_AppName", "import_types", "firmwareVersionFromOsVersion", "data", "internalApi", "getAppAndVersion", "getOsVersion", "getDeviceSessionState", "setDeviceSessionState", "waitForDeviceUnlock", "unlockTimeout", "updateSessionFromOsVersion", "currentState", "context", "_", "sessionState", "sessionStateType", "state", "args", "error", "currentApp", "currentAppVersion", "input", "output"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { WaitForAppAndVersionDeviceAction } from \"@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const { getOsVersion, getDeviceSessionState, setDeviceSessionState } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n const allowNonOnboardedDevice = this.input.allowNonOnboardedDevice ?? true;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n const waitForAppAndVersion = new WaitForAppAndVersionDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n allowNonOnboardedDevice,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n waitForAppAndVersion,\n getOsVersion: fromPromise(getOsVersion),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isAllowedNonOnboardedDevice: ({ context }) => {\n const secureElementFlags =\n context._internalState.osVersionMetadata?.secureElementFlags;\n return (\n context.input.allowNonOnboardedDevice === true &&\n secureElementFlags?.isOnboarded === false\n );\n },\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM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jgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n allowNonOnboardedDevice: _.input.allowNonOnboardedDevice ?? true,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.WAIT_FOR_APP_AND_VERSION,\n },\n _internalState: {\n onboarded: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"WaitForAppAndVersion\",\n },\n },\n WaitForAppAndVersion: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"waitForAppAndVersion\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"WaitForAppAndVersionResultCheck\",\n actions: assign({\n _internalState: (_): GetDeviceStatusMachineInternalState => {\n return _.event.output.caseOf<GetDeviceStatusMachineInternalState>(\n {\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: output,\n });\n } else {\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: output,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n currentApp: output.name,\n currentAppVersion: output.version,\n };\n },\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n WaitForAppAndVersionResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n entry: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n }),\n }),\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n guard: \"isAllowedNonOnboardedDevice\",\n target: \"Success\",\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n return {\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA4B,qBAC5BC,EAA2C,kBAE3CC,EAAuC,4CACvCC,EAIO,+CACPC,EAA6B,oCAE7BC,EAAwC,4DACxCC,EAA0C,uCAC1CC,EAAwC,wCACxCC,EAAiD,uFAEjDC,EAGO,8DACPC,EAIO,kDACPC,EAAgC,8BAEhCC,EAMO,mBAkBP,MAAMC,EACJC,IACqB,CACrB,IAAKA,EAAK,eACV,WAAYA,EAAK,qBACjB,GAAIA,EAAK,UACT,SAAUA,CACZ,GAMO,MAAMhB,UAAoC,oBAM/C,CACA,iBACEiB,EAOA,CASA,KAAM,CAAE,aAAAC,EAAc,sBAAAC,EAAuB,sBAAAC,CAAsB,EACjE,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,MAAM,eAAiB,4BAC5CC,EAA0B,KAAK,MAAM,yBAA2B,GAEhEC,E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Ac,IAAMA,EAAY,YAAY,IAAI,qBAAqB,EACrE,sBAAuB,IAAMA,EAAY,sBAAsB,EAC/D,sBAAwBgB,GACtBhB,EAAY,sBAAsBgB,CAAK,CAC3C,CACF,CACF",
6
+ "names": ["GetDeviceStatusDeviceAction_exports", "__export", "GetDeviceStatusDeviceAction", "__toCommonJS", "import_purify_ts", "import_xstate", "import_CommandResult", "import_GetOsVersionCommand", "import_DeviceStatus", "import_UserInteractionRequired", "import_Const", "import_Errors", "import_WaitForAppAndVersionDeviceAction", "import_XStateDeviceAction", "import_DeviceSessionState", "import_AppName", "import_types", "firmwareVersionFromOsVersion", "data", "internalApi", "getOsVersion", "getDeviceSessionState", "setDeviceSessionState", "unlockTimeout", "allowNonOnboardedDevice", "updateSessionFromOsVersion", "currentState", "waitForAppAndVersion", "context", "secureElementFlags", "_", "sessionState", "sessionStateType", "error", "output", "state", "args", "currentApp", "currentAppVersion"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var D=require("rxjs"),E=require("../../../command/model/CommandResult"),x=require("../../../command/os/__mocks__/GetOsVersionCommand"),h=require("../../../command/utils/GlobalCommandError"),l=require("../../../device/DeviceModel"),i=require("../../../device/DeviceStatus"),a=require("../../../device-action/__test-utils__/makeInternalApi"),u=require("../../../device-action/__test-utils__/testDeviceActionStates"),c=require("../../../device-action/model/DeviceActionState"),L=require("../../../device-action/model/UserInteractionRequired"),A=require("../../../device-action/os/Errors"),s=require("../../../device-session/DeviceSessionState"),d=require("./GetDeviceStatusDeviceAction"),G=require("./types");const V=(p={},k=l.DeviceModelId.NANO_X)=>(0,E.CommandResultFactory)({data:(0,x.getOsVersionCommandResponseMockBuilder)(k,p)}),C=(p,k)=>(0,E.CommandResultFactory)({data:{name:p,version:k}}),T=()=>(0,E.CommandResultFactory)({error:new h.GlobalCommandError({...h.GLOBAL_ERRORS[5515],errorCode:"5515"})}),v=()=>({intermediateValue:{requiredUserInteraction:L.UserInteractionRequired.None,step:G.getDeviceStatusDAStateStep.ONBOARD_CHECK},status:c.DeviceActionStatus.Pending}),N=()=>[v(),v()],I=()=>({intermediateValue:{requiredUserInteraction:L.UserInteractionRequired.UnlockDevice,step:G.getDeviceStatusDAStateStep.UNLOCK_DEVICE},status:c.DeviceActionStatus.Pending}),P=()=>({intermediateValue:{requiredUserInteraction:L.UserInteractionRequired.None,step:G.getDeviceStatusDAStateStep.UNLOCK_DEVICE},status:c.DeviceActionStatus.Pending});describe("GetDeviceStatusDeviceAction",()=>{const p=vi.fn(),k=vi.fn(),S=vi.fn(),w=vi.fn(),f=vi.fn();function O(){return{getAppAndVersion:p,getOsVersion:k,getDeviceSessionState:S,waitForDeviceUnlock:w,setDeviceSessionState:f}}const{sendCommand:y,getDeviceSessionState:R,getDeviceSessionStateObservable:b}=(0,a.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),k.mockResolvedValue(V())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with an unlocked device",()=>new Promise((o,r)=>{const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});R.mockReturnValue({sessionStateType:s.DeviceSessionStateType.Connected,deviceStatus:i.DeviceStatus.CONNECTED,deviceModelId:l.DeviceModelId.NANO_X}),y.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(V()):Promise.resolve(C("BOLOS","1.0.0")));const t=[...N(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.DeviceActionStatus.Completed}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should run the device action with a locked device",()=>new Promise((o,r)=>{const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:1500}});R.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1});let t=0;y.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(V()):(t+=1,t===1?Promise.resolve(T()):Promise.resolve(C("BOLOS","1.0.0"))));const n=[v(),I(),P(),P(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.DeviceActionStatus.Completed}];(0,u.testDeviceActionStates)(e,n,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should timeout with a locked device",()=>new Promise((o,r)=>{const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:200}});R.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),y.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(V()):Promise.resolve(T()));const t=[v(),I(),{error:new A.DeviceLockedError("Device locked."),status:c.DeviceActionStatus.Error}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should run the device action with an old firmware not supporting GetAppAndVersion",()=>new Promise((o,r)=>{const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});R.mockReturnValue({sessionStateType:s.DeviceSessionStateType.Connected,deviceStatus:i.DeviceStatus.CONNECTED,deviceModelId:l.DeviceModelId.NANO_X}),y.mockImplementation(n=>n.name==="getOsVersion"?Promise.resolve(V()):Promise.resolve((0,E.CommandResultFactory)({error:new h.GlobalCommandError({...h.GLOBAL_ERRORS["6e00"],errorCode:"6e00"})})));const t=[...N(),{output:{currentApp:"BOLOS",currentAppVersion:"0.0.0"},status:c.DeviceActionStatus.Completed}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})}))}),describe("success cases",()=>{it("should return the device status if the device is unlocked",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),p.mockResolvedValue(C("BOLOS","1.0.0"));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[...N(),{status:c.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:()=>{expect(f).toHaveBeenCalledWith({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),o()},onError:r})})),it("should return the device status and update session if the device is not ready",()=>new Promise((o,r)=>{let e={sessionStateType:s.DeviceSessionStateType.Connected,deviceStatus:i.DeviceStatus.CONNECTED,deviceModelId:l.DeviceModelId.NANO_X};S.mockImplementation(()=>e),f.mockImplementation(g=>(e=g,g)),p.mockResolvedValue(C("BOLOS","1.0.0"));const t=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(O());const n=(0,x.getOsVersionCommandResponseMockBuilder)(l.DeviceModelId.NANO_X),m=[...N(),{status:c.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,u.testDeviceActionStates)(t,m,(0,a.makeDeviceActionInternalApiMock)(),{onDone:()=>{expect(f).toHaveBeenCalledWith({deviceModelId:l.DeviceModelId.NANO_X,sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:n.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:n.mcuSephVersion,bootloader:n.mcuBootloaderVersion,os:n.seVersion,metadata:n}}),o()},onError:r})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.Connected,deviceStatus:i.DeviceStatus.CONNECTED,deviceModelId:l.DeviceModelId.NANO_X}),p.mockResolvedValue(C("Bitcoin","2.1.0"));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[v(),{status:c.DeviceActionStatus.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:()=>{expect(k).not.toHaveBeenCalled(),o()},onError:r})})),it("should return the device status if the device is locked and the user unlocks the device",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),p.mockResolvedValueOnce(T()).mockResolvedValueOnce(C("BOLOS","1.0.0")),w.mockImplementation(()=>new D.Observable(n=>{const m=(0,D.interval)(50).subscribe({next:g=>{g>2?(n.next({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),n.complete()):n.next({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}})}});return()=>{m.unsubscribe()}}));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[v(),I(),P(),P(),{status:c.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),p.mockResolvedValue(C("BOLOS","1.0.0")),k.mockResolvedValue(V({secureElementFlags:{...(0,x.getOsVersionCommandResponseMockBuilder)().secureElementFlags,isOnboarded:!1}}));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[...N(),{error:new A.DeviceNotOnboardedError,status:c.DeviceActionStatus.Error}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),p.mockResolvedValue(T()),w.mockImplementation(()=>new D.Observable(n=>{n.error(new A.DeviceLockedError("Device locked."))})),b.mockImplementation(()=>new D.Observable(n=>{const m=(0,D.interval)(200).subscribe({next:()=>{n.next({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1})}});return()=>{m.unsubscribe()}}));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[v(),I(),{error:new A.DeviceLockedError("Device locked."),status:c.DeviceActionStatus.Error}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should end in an error if the GetAppAndVersion command fails",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new h.GlobalCommandError({...h.GLOBAL_ERRORS[5501],errorCode:"5501"});p.mockResolvedValue((0,E.CommandResultFactory)({error:e})),w.mockImplementation(()=>new D.Observable(m=>{m.complete()}));const t=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(O());const n=[v(),{error:e,status:c.DeviceActionStatus.Error}];(0,u.testDeviceActionStates)(t,n,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((o,r)=>{S.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),p.mockImplementation(()=>{throw new A.UnknownDAError("error")}),w.mockImplementation(()=>new D.Observable(n=>{n.complete()}));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(O());const t=[v(),{error:new A.UnknownDAError("error"),status:c.DeviceActionStatus.Error}];(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((o,r)=>{R.mockReturnValue({sessionStateType:s.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:i.DeviceStatus.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),y.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(V()):Promise.resolve(C("BOLOS","1.0.0")));const e=new d.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}}),t=[v(),{status:c.DeviceActionStatus.Stopped}],{cancel:n}=(0,u.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:r});n()}))});
1
+ "use strict";var N=require("../../../command/model/CommandResult"),E=require("../../../command/os/__mocks__/GetOsVersionCommand"),V=require("../../../command/utils/GlobalCommandError"),A=require("../../../device/DeviceModel"),u=require("../../../device/DeviceStatus"),a=require("../../../device-action/__test-utils__/makeInternalApi"),d=require("../../../device-action/__test-utils__/setupTestMachine"),p=require("../../../device-action/__test-utils__/testDeviceActionStates"),r=require("../../../device-action/model/DeviceActionState"),k=require("../../../device-action/model/UserInteractionRequired"),h=require("../../../device-action/os/Errors"),l=require("../../../device-session/DeviceSessionState"),v=require("./GetDeviceStatusDeviceAction"),f=require("./types");vi.mock("@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction");const C=(s={},c=A.DeviceModelId.NANO_X)=>(0,N.CommandResultFactory)({data:(0,E.getOsVersionCommandResponseMockBuilder)(c,s)}),m=(s,c)=>({name:s,version:c}),O=(s=k.UserInteractionRequired.None)=>({intermediateValue:{requiredUserInteraction:s,step:f.getDeviceStatusDAStateStep.ONBOARD_CHECK},status:r.DeviceActionStatus.Pending}),n=(s=k.UserInteractionRequired.None)=>({intermediateValue:{requiredUserInteraction:s,step:f.getDeviceStatusDAStateStep.WAIT_FOR_APP_AND_VERSION},status:r.DeviceActionStatus.Pending});describe("GetDeviceStatusDeviceAction",()=>{const s=vi.fn(),c=vi.fn(),R=vi.fn();function D(){return{getOsVersion:s,getDeviceSessionState:c,setDeviceSessionState:R}}const{sendCommand:y,getDeviceSessionState:w}=(0,a.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.resetAllMocks(),s.mockResolvedValue(C())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with the device on the dashboard",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),w.mockReturnValue({sessionStateType:l.DeviceSessionStateType.Connected,deviceStatus:u.DeviceStatus.CONNECTED,deviceModelId:A.DeviceModelId.NANO_X}),y.mockResolvedValue(C());const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}}),t=[n(),n(),O(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:r.DeviceActionStatus.Completed}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should run the device action when the device needs to be unlocked",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0"),k.UserInteractionRequired.UnlockDevice),w.mockReturnValue({sessionStateType:l.DeviceSessionStateType.Connected,deviceStatus:u.DeviceStatus.LOCKED,deviceModelId:A.DeviceModelId.NANO_X}),y.mockResolvedValue(C());const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}}),t=[n(),n(k.UserInteractionRequired.UnlockDevice),O(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:r.DeviceActionStatus.Completed}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})}))}),describe("success cases",()=>{it("should return the device status if the device is on the dashboard",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),O(),{status:r.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should return the device status and update the session firmware version",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0"));let e={sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:A.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1};c.mockImplementation(()=>e),R.mockImplementation(T=>(e=T,T));const t=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=(0,E.getOsVersionCommandResponseMockBuilder)(A.DeviceModelId.NANO_X),g=[n(),n(),O(),{status:r.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,p.testDeviceActionStates)(t,g,(0,a.makeDeviceActionInternalApiMock)(),{onDone:()=>{expect(R).toHaveBeenCalledWith(expect.objectContaining({isSecureConnectionAllowed:S.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:S.mcuSephVersion,bootloader:S.mcuBootloaderVersion,os:S.seVersion,metadata:S}})),o()},onError:i})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("Bitcoin","2.1.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.Connected,deviceStatus:u.DeviceStatus.CONNECTED,deviceModelId:A.DeviceModelId.NANO_X});const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),{status:r.DeviceActionStatus.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:()=>{expect(s).not.toHaveBeenCalled(),o()},onError:i})})),it("GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:A.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),s.mockResolvedValue(C({secureElementFlags:{...(0,E.getOsVersionCommandResponseMockBuilder)().secureElementFlags,isOnboarded:!1}}));const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),O(),{status:r.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should surface the unlock interaction then return the device status",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0"),k.UserInteractionRequired.UnlockDevice),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(k.UserInteractionRequired.UnlockDevice),O(),{status:r.DeviceActionStatus.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})}))}),describe("errors cases",()=>{it("GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:A.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),s.mockResolvedValue(C({secureElementFlags:{...(0,E.getOsVersionCommandResponseMockBuilder)().secureElementFlags,isOnboarded:!1}}));const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500,allowNonOnboardedDevice:!1}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),O(),{error:new h.DeviceNotOnboardedError,status:r.DeviceActionStatus.Error}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(new h.DeviceLockedError("Device locked."),k.UserInteractionRequired.UnlockDevice),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(k.UserInteractionRequired.UnlockDevice),{error:new h.DeviceLockedError("Device locked."),status:r.DeviceActionStatus.Error}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should end in an error if the WaitForAppAndVersion sub-action fails",()=>new Promise((o,i)=>{const e=new V.GlobalCommandError({...V.GLOBAL_ERRORS[5501],errorCode:"5501"});(0,d.setupWaitForAppAndVersionMock)(e),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const t=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=[n(),n(),{error:e,status:r.DeviceActionStatus.Error}];(0,p.testDeviceActionStates)(t,S,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should end in an error if the GetOsVersion command fails",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}});const e=new V.GlobalCommandError({...V.GLOBAL_ERRORS[5501],errorCode:"5501"});s.mockResolvedValue((0,N.CommandResultFactory)({error:e}));const t=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=[n(),n(),O(),{error:e,status:r.DeviceActionStatus.Error}];(0,p.testDeviceActionStates)(t,S,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})})),it("should end in an error if the getOsVersion actor throws an error",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),c.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),s.mockImplementation(()=>{throw new h.UnknownDAError("error")});const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),O(),{error:new h.UnknownDAError("error"),status:r.DeviceActionStatus.Error}];(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((o,i)=>{(0,d.setupWaitForAppAndVersionMock)(m("BOLOS","1.0.0")),w.mockReturnValue({sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:u.DeviceStatus.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:A.DeviceModelId.NANO_X,isSecureConnectionAllowed:!1}),y.mockResolvedValue(C());const e=new v.GetDeviceStatusDeviceAction({input:{unlockTimeout:500}}),t=[n(),n(),{status:r.DeviceActionStatus.Stopped}],{cancel:S}=(0,p.testDeviceActionStates)(e,t,(0,a.makeDeviceActionInternalApiMock)(),{onDone:o,onError:i});S()}))});
2
2
  //# sourceMappingURL=GetDeviceStatusDeviceAction.test.js.map