@ledgerhq/device-management-kit 0.7.0 → 0.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 (388) hide show
  1. package/lib/cjs/package.json +1 -2
  2. package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
  3. package/lib/cjs/src/api/DeviceManagementKit.test.js.map +2 -2
  4. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  5. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  6. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  7. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  8. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js +1 -1
  9. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  10. package/lib/cjs/src/api/command/di/commandModule.js +1 -1
  11. package/lib/cjs/src/api/command/di/commandModule.js.map +3 -3
  12. package/lib/cjs/src/api/command/di/commandModule.test.js +1 -1
  13. package/lib/cjs/src/api/command/di/commandModule.test.js.map +2 -2
  14. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  15. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  16. package/lib/cjs/src/api/command/utils/CommandUtils.js +1 -1
  17. package/lib/cjs/src/api/command/utils/CommandUtils.js.map +2 -2
  18. package/lib/cjs/src/api/command/utils/CommandUtils.test.js +1 -1
  19. package/lib/cjs/src/api/command/utils/CommandUtils.test.js.map +2 -2
  20. package/lib/cjs/src/api/command/utils/GlobalCommandError.js +1 -1
  21. package/lib/cjs/src/api/command/utils/GlobalCommandError.js.map +2 -2
  22. package/lib/cjs/src/api/device/DeviceModel.js +1 -1
  23. package/lib/cjs/src/api/device/DeviceModel.js.map +2 -2
  24. package/lib/cjs/src/api/device-action/di/deviceActionModule.js +1 -1
  25. package/lib/cjs/src/api/device-action/di/deviceActionModule.js.map +3 -3
  26. package/lib/cjs/src/api/device-action/di/deviceActionModule.test.js +1 -1
  27. package/lib/cjs/src/api/device-action/di/deviceActionModule.test.js.map +2 -2
  28. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js +1 -1
  29. package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  30. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  31. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +2 -2
  32. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +1 -1
  33. package/lib/cjs/src/api/device-action/os/Errors.js +1 -1
  34. package/lib/cjs/src/api/device-action/os/Errors.js.map +3 -3
  35. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  36. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  37. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
  38. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  39. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +2 -2
  40. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  41. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  42. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  43. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  44. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  45. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  46. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
  47. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
  48. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  49. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
  50. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  51. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +2 -2
  52. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
  53. package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +1 -1
  54. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  55. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  56. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  57. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  58. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +2 -2
  59. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -1
  60. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +1 -1
  61. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  62. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +2 -2
  63. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  64. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +2 -2
  65. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  66. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  67. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  68. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  69. package/lib/cjs/src/api/device-model/model/DeviceModel.js +1 -1
  70. package/lib/cjs/src/api/device-model/model/DeviceModel.js.map +2 -2
  71. package/lib/cjs/src/api/index.js +1 -1
  72. package/lib/cjs/src/api/index.js.map +2 -2
  73. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  74. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  75. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  76. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  77. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  78. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js +1 -1
  79. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
  80. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  81. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  82. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  83. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  84. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  85. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  86. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js +1 -1
  87. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
  88. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  89. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  90. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  91. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  92. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  93. package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
  94. package/lib/cjs/src/api/secure-channel/utils.js +1 -1
  95. package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
  96. package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
  97. package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
  98. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
  99. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
  100. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js +2 -0
  101. package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +7 -0
  102. package/lib/cjs/src/api/transport/model/Errors.js +1 -1
  103. package/lib/cjs/src/api/transport/model/Errors.js.map +3 -3
  104. package/lib/cjs/src/api/utils/AppName.js +2 -0
  105. package/lib/cjs/src/api/utils/AppName.js.map +7 -0
  106. package/lib/cjs/src/api/utils/AppName.test.js +2 -0
  107. package/lib/cjs/src/api/utils/AppName.test.js.map +7 -0
  108. package/lib/cjs/src/di.js +1 -1
  109. package/lib/cjs/src/di.js.map +2 -2
  110. package/lib/cjs/src/internal/config/di/configModule.js +1 -1
  111. package/lib/cjs/src/internal/config/di/configModule.js.map +3 -3
  112. package/lib/cjs/src/internal/config/di/configModule.test.js +1 -1
  113. package/lib/cjs/src/internal/config/di/configModule.test.js.map +2 -2
  114. package/lib/cjs/src/internal/device-model/di/deviceModelModule.js +1 -1
  115. package/lib/cjs/src/internal/device-model/di/deviceModelModule.js.map +3 -3
  116. package/lib/cjs/src/internal/device-model/di/deviceModelModule.test.js +1 -1
  117. package/lib/cjs/src/internal/device-model/di/deviceModelModule.test.js.map +2 -2
  118. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js +1 -1
  119. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
  120. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.test.js +1 -1
  121. package/lib/cjs/src/internal/device-session/di/deviceSessionModule.test.js.map +2 -2
  122. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  123. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  124. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  125. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  126. package/lib/cjs/src/internal/discovery/di/discoveryModule.js +1 -1
  127. package/lib/cjs/src/internal/discovery/di/discoveryModule.js.map +3 -3
  128. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js +1 -1
  129. package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
  130. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.js +1 -1
  131. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.js.map +3 -3
  132. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.test.js +1 -1
  133. package/lib/cjs/src/internal/logger-publisher/di/loggerModule.test.js.map +2 -2
  134. package/lib/cjs/src/internal/manager-api/di/managerApiModule.js +1 -1
  135. package/lib/cjs/src/internal/manager-api/di/managerApiModule.js.map +3 -3
  136. package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js +1 -1
  137. package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
  138. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.js +1 -1
  139. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.js.map +3 -3
  140. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.test.js +1 -1
  141. package/lib/cjs/src/internal/secure-channel/di/secureChannelModule.test.js.map +2 -2
  142. package/lib/cjs/src/internal/secure-channel/model/Errors.js +1 -1
  143. package/lib/cjs/src/internal/secure-channel/model/Errors.js.map +3 -3
  144. package/lib/cjs/src/internal/send/di/sendModule.js +1 -1
  145. package/lib/cjs/src/internal/send/di/sendModule.js.map +3 -3
  146. package/lib/cjs/src/internal/send/di/sendModule.test.js +1 -1
  147. package/lib/cjs/src/internal/send/di/sendModule.test.js.map +2 -2
  148. package/lib/cjs/src/internal/send/use-case/SendApduUseCase.js +1 -1
  149. package/lib/cjs/src/internal/send/use-case/SendApduUseCase.js.map +3 -3
  150. package/lib/cjs/src/internal/transport/di/transportModule.js +1 -1
  151. package/lib/cjs/src/internal/transport/di/transportModule.js.map +3 -3
  152. package/lib/cjs/src/internal/transport/di/transportModule.test.js +1 -1
  153. package/lib/cjs/src/internal/transport/di/transportModule.test.js.map +2 -2
  154. package/lib/esm/package.json +1 -2
  155. package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
  156. package/lib/esm/src/api/DeviceManagementKit.test.js.map +2 -2
  157. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  158. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  159. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  160. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  161. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js +1 -1
  162. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  163. package/lib/esm/src/api/command/di/commandModule.js +1 -1
  164. package/lib/esm/src/api/command/di/commandModule.js.map +3 -3
  165. package/lib/esm/src/api/command/di/commandModule.test.js +1 -1
  166. package/lib/esm/src/api/command/di/commandModule.test.js.map +2 -2
  167. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  168. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  169. package/lib/esm/src/api/command/utils/CommandUtils.js +1 -1
  170. package/lib/esm/src/api/command/utils/CommandUtils.js.map +3 -3
  171. package/lib/esm/src/api/command/utils/CommandUtils.test.js +1 -1
  172. package/lib/esm/src/api/command/utils/CommandUtils.test.js.map +2 -2
  173. package/lib/esm/src/api/command/utils/GlobalCommandError.js +1 -1
  174. package/lib/esm/src/api/command/utils/GlobalCommandError.js.map +2 -2
  175. package/lib/esm/src/api/device/DeviceModel.js +1 -1
  176. package/lib/esm/src/api/device/DeviceModel.js.map +2 -2
  177. package/lib/esm/src/api/device-action/di/deviceActionModule.js +1 -1
  178. package/lib/esm/src/api/device-action/di/deviceActionModule.js.map +3 -3
  179. package/lib/esm/src/api/device-action/di/deviceActionModule.test.js +1 -1
  180. package/lib/esm/src/api/device-action/di/deviceActionModule.test.js.map +2 -2
  181. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js +1 -1
  182. package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
  183. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  184. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +2 -2
  185. package/lib/esm/src/api/device-action/os/Errors.js +1 -1
  186. package/lib/esm/src/api/device-action/os/Errors.js.map +3 -3
  187. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  188. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  189. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  190. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +2 -2
  191. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  192. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  193. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  194. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  195. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  196. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  197. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  198. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
  199. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  200. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
  201. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  202. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  203. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  204. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +2 -2
  205. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  206. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +3 -3
  207. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  208. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +3 -3
  209. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  210. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  211. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  212. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  213. package/lib/esm/src/api/device-model/model/DeviceModel.js +1 -1
  214. package/lib/esm/src/api/device-model/model/DeviceModel.js.map +2 -2
  215. package/lib/esm/src/api/index.js +1 -1
  216. package/lib/esm/src/api/index.js.map +3 -3
  217. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  218. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  219. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  220. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  221. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  222. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  223. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  224. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  225. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  226. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  227. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  228. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  229. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  230. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  231. package/lib/esm/src/api/secure-channel/task/types.js +1 -1
  232. package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
  233. package/lib/esm/src/api/secure-channel/utils.js +1 -1
  234. package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
  235. package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
  236. package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
  237. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
  238. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
  239. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js +2 -0
  240. package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +7 -0
  241. package/lib/esm/src/api/transport/model/Errors.js +1 -1
  242. package/lib/esm/src/api/transport/model/Errors.js.map +3 -3
  243. package/lib/esm/src/api/utils/AppName.js +2 -0
  244. package/lib/esm/src/api/utils/AppName.js.map +7 -0
  245. package/lib/esm/src/api/utils/AppName.test.js +2 -0
  246. package/lib/esm/src/api/utils/AppName.test.js.map +7 -0
  247. package/lib/esm/src/di.js +1 -1
  248. package/lib/esm/src/di.js.map +2 -2
  249. package/lib/esm/src/internal/config/di/configModule.js +1 -1
  250. package/lib/esm/src/internal/config/di/configModule.js.map +3 -3
  251. package/lib/esm/src/internal/config/di/configModule.test.js +1 -1
  252. package/lib/esm/src/internal/config/di/configModule.test.js.map +2 -2
  253. package/lib/esm/src/internal/device-model/di/deviceModelModule.js +1 -1
  254. package/lib/esm/src/internal/device-model/di/deviceModelModule.js.map +3 -3
  255. package/lib/esm/src/internal/device-model/di/deviceModelModule.test.js +1 -1
  256. package/lib/esm/src/internal/device-model/di/deviceModelModule.test.js.map +2 -2
  257. package/lib/esm/src/internal/device-session/di/deviceSessionModule.js +1 -1
  258. package/lib/esm/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
  259. package/lib/esm/src/internal/device-session/di/deviceSessionModule.test.js +1 -1
  260. package/lib/esm/src/internal/device-session/di/deviceSessionModule.test.js.map +2 -2
  261. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  262. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  263. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  264. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  265. package/lib/esm/src/internal/discovery/di/discoveryModule.js +1 -1
  266. package/lib/esm/src/internal/discovery/di/discoveryModule.js.map +3 -3
  267. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js +1 -1
  268. package/lib/esm/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
  269. package/lib/esm/src/internal/logger-publisher/di/loggerModule.js +1 -1
  270. package/lib/esm/src/internal/logger-publisher/di/loggerModule.js.map +3 -3
  271. package/lib/esm/src/internal/logger-publisher/di/loggerModule.test.js +1 -1
  272. package/lib/esm/src/internal/logger-publisher/di/loggerModule.test.js.map +2 -2
  273. package/lib/esm/src/internal/manager-api/di/managerApiModule.js +1 -1
  274. package/lib/esm/src/internal/manager-api/di/managerApiModule.js.map +3 -3
  275. package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js +1 -1
  276. package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
  277. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.js +1 -1
  278. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.js.map +3 -3
  279. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.test.js +1 -1
  280. package/lib/esm/src/internal/secure-channel/di/secureChannelModule.test.js.map +2 -2
  281. package/lib/esm/src/internal/secure-channel/model/Errors.js +1 -1
  282. package/lib/esm/src/internal/secure-channel/model/Errors.js.map +3 -3
  283. package/lib/esm/src/internal/send/di/sendModule.js +1 -1
  284. package/lib/esm/src/internal/send/di/sendModule.js.map +3 -3
  285. package/lib/esm/src/internal/send/di/sendModule.test.js +1 -1
  286. package/lib/esm/src/internal/send/di/sendModule.test.js.map +2 -2
  287. package/lib/esm/src/internal/send/use-case/SendApduUseCase.js +1 -1
  288. package/lib/esm/src/internal/send/use-case/SendApduUseCase.js.map +3 -3
  289. package/lib/esm/src/internal/transport/di/transportModule.js +1 -1
  290. package/lib/esm/src/internal/transport/di/transportModule.js.map +3 -3
  291. package/lib/esm/src/internal/transport/di/transportModule.test.js +1 -1
  292. package/lib/esm/src/internal/transport/di/transportModule.test.js.map +2 -2
  293. package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
  294. package/lib/types/src/api/apdu/utils/ApduParser.d.ts.map +1 -1
  295. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts +28 -0
  296. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts.map +1 -1
  297. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts +1 -0
  298. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts.map +1 -1
  299. package/lib/types/src/api/command/di/commandModule.d.ts.map +1 -1
  300. package/lib/types/src/api/command/os/__mocks__/GetOsVersionCommand.d.ts.map +1 -1
  301. package/lib/types/src/api/command/utils/CommandErrors.d.ts.map +1 -1
  302. package/lib/types/src/api/command/utils/CommandUtils.d.ts +3 -0
  303. package/lib/types/src/api/command/utils/CommandUtils.d.ts.map +1 -1
  304. package/lib/types/src/api/command/utils/GlobalCommandError.d.ts +1 -1
  305. package/lib/types/src/api/command/utils/GlobalCommandError.d.ts.map +1 -1
  306. package/lib/types/src/api/device/DeviceModel.d.ts +2 -1
  307. package/lib/types/src/api/device/DeviceModel.d.ts.map +1 -1
  308. package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
  309. package/lib/types/src/api/device-action/di/deviceActionModule.d.ts.map +1 -1
  310. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +1 -0
  311. package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts.map +1 -1
  312. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.d.ts.map +1 -1
  313. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts +0 -1
  314. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts.map +1 -1
  315. package/lib/types/src/api/device-action/os/Errors.d.ts +10 -0
  316. package/lib/types/src/api/device-action/os/Errors.d.ts.map +1 -1
  317. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  318. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +2 -1
  319. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  320. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
  321. package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts.map +1 -1
  322. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  323. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +3 -2
  324. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  325. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
  326. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +0 -1
  327. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
  328. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  329. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +0 -1
  330. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  331. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.d.ts.map +1 -1
  332. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts +0 -1
  333. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
  334. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts +2 -2
  335. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts.map +1 -1
  336. package/lib/types/src/api/device-model/data/StaticDeviceModelDataSource.d.ts.map +1 -1
  337. package/lib/types/src/api/device-model/model/DeviceModel.d.ts.map +1 -1
  338. package/lib/types/src/api/device-session/service/DefaultApduReceiverService.stub.d.ts.map +1 -1
  339. package/lib/types/src/api/device-session/service/DefaultApduSenderService.stub.d.ts.map +1 -1
  340. package/lib/types/src/api/index.d.ts +1 -1
  341. package/lib/types/src/api/index.d.ts.map +1 -1
  342. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  343. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +2 -1
  344. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  345. package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
  346. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +2 -1
  347. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
  348. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
  349. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +2 -1
  350. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
  351. package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
  352. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +2 -1
  353. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
  354. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +5 -2
  355. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  356. package/lib/types/src/api/secure-channel/task/types.d.ts +6 -1
  357. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  358. package/lib/types/src/api/secure-channel/utils.d.ts +0 -11
  359. package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
  360. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts +8 -7
  361. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts.map +1 -1
  362. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.test.d.ts +2 -0
  363. package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.test.d.ts.map +1 -0
  364. package/lib/types/src/api/transport/model/Errors.d.ts +5 -0
  365. package/lib/types/src/api/transport/model/Errors.d.ts.map +1 -1
  366. package/lib/types/src/api/utils/AppName.d.ts +2 -0
  367. package/lib/types/src/api/utils/AppName.d.ts.map +1 -0
  368. package/lib/types/src/api/utils/AppName.test.d.ts +2 -0
  369. package/lib/types/src/api/utils/AppName.test.d.ts.map +1 -0
  370. package/lib/types/src/api/utils/HexaString.d.ts.map +1 -1
  371. package/lib/types/src/di.d.ts.map +1 -1
  372. package/lib/types/src/internal/config/di/configModule.d.ts.map +1 -1
  373. package/lib/types/src/internal/device-model/di/deviceModelModule.d.ts.map +1 -1
  374. package/lib/types/src/internal/device-session/di/deviceSessionModule.d.ts.map +1 -1
  375. package/lib/types/src/internal/device-session/model/DeviceSession.stub.d.ts.map +1 -1
  376. package/lib/types/src/internal/device-session/utils/deviceSessionUtils.d.ts.map +1 -1
  377. package/lib/types/src/internal/discovery/di/discoveryModule.d.ts.map +1 -1
  378. package/lib/types/src/internal/logger-publisher/di/loggerModule.d.ts.map +1 -1
  379. package/lib/types/src/internal/manager-api/di/managerApiModule.d.ts.map +1 -1
  380. package/lib/types/src/internal/secure-channel/di/secureChannelModule.d.ts.map +1 -1
  381. package/lib/types/src/internal/secure-channel/model/Errors.d.ts +22 -2
  382. package/lib/types/src/internal/secure-channel/model/Errors.d.ts.map +1 -1
  383. package/lib/types/src/internal/send/di/sendModule.d.ts.map +1 -1
  384. package/lib/types/src/internal/send/use-case/SendApduUseCase.d.ts +5 -1
  385. package/lib/types/src/internal/send/use-case/SendApduUseCase.d.ts.map +1 -1
  386. package/lib/types/src/internal/transport/di/transportModule.d.ts.map +1 -1
  387. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  388. package/package.json +2 -3
@@ -1,2 +1,2 @@
1
- import{Left as D,Right as l}from"purify-ts";import{assign as n,fromPromise as p,setup as S}from"xstate";import{isSuccessCommandResult as c}from"../../../command/model/CommandResult";import{CloseAppCommand as A}from"../../../command/os/CloseAppCommand";import{GetAppAndVersionCommand as m}from"../../../command/os/GetAppAndVersionCommand";import{UserInteractionRequired as h}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as v}from"../../../device-action/os/Const";import{UnknownDAError as y}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as g}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as T}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as G}from"../../../device-session/DeviceSessionState";class w extends T{makeStateMachine(r){const{getDeviceSessionState:o,setDeviceSessionState:s,closeApp:a,getAppAndVersion:u}=this.extractDependencies(r),i=this.input.unlockTimeout??v,d=new g({input:{unlockTimeout:i}}).makeStateMachine(r);return S({types:{input:{unlockTimeout:i},context:{},output:{}},actors:{getAppAndVersion:p(u),closeApp:p(a),getDeviceStatus:d},guards:{hasError:({context:e})=>e._internalState.error!==null,isDashboardOpen:({context:e})=>e._internalState.currentApp==="BOLOS"},actions:{assignErrorFromEvent:n({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GoToDashboardDeviceAction",initial:"DeviceReady",context:e=>{const t=o();return{input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:h.None},_internalState:{currentApp:"currentApp"in t?t.currentApp.name:null,error:null}}},states:{DeviceReady:{always:{target:"GetDeviceStatus"}},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:n({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:n({_internalState:e=>e.event.output.caseOf({Right:t=>({...e.context._internalState,currentApp:t.currentApp}),Left:t=>({...e.context._internalState,error:t})})})}}},CheckDeviceStatus:{always:[{target:"Error",guard:"hasError"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"Success",guard:"isDashboardOpen"},{target:"Error",guard:"hasError"},{target:"Error",guard:e=>e.context._internalState.currentApp===null,actions:n({_internalState:e=>({...e.context._internalState,error:new y("currentApp === null")})})},{target:"CloseApp"}]},CloseApp:{invoke:{src:"closeApp",onDone:{target:"CloseAppCheck",actions:n({_internalState:e=>c(e.event.output)?e.context._internalState:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseAppCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetAppAndVersion",reenter:!0}]},GetAppAndVersion:{invoke:{src:"getAppAndVersion",onDone:{target:"DashboardCheck",actions:n({_internalState:e=>{if(c(e.event.output)){const t=o();return t.sessionStateType!==G.Connected&&s({...t,currentApp:e.event.output.data}),{...e.context._internalState,currentApp:e.event.output.data.name}}return{...e.context._internalState,error:e.event.output.error}}})}}},Success:{type:"final"},Error:{type:"final"}},output:e=>e.context._internalState.error?D(e.context._internalState.error):l(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new A),getAppAndVersion:async()=>r.sendCommand(new m),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a)}}}export{w as GoToDashboardDeviceAction};
1
+ import{Left as D,Right as l}from"purify-ts";import{assign as n,fromPromise as p,setup as S}from"xstate";import{isSuccessCommandResult as c}from"../../../command/model/CommandResult";import{CloseAppCommand as A}from"../../../command/os/CloseAppCommand";import{GetAppAndVersionCommand as m}from"../../../command/os/GetAppAndVersionCommand";import{UserInteractionRequired as h}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as v}from"../../../device-action/os/Const";import{UnknownDAError as y}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as g}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as T}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as G}from"../../../device-session/DeviceSessionState";import{isDashboardName as b}from"../../../utils/AppName";class L extends T{makeStateMachine(r){const{getDeviceSessionState:o,setDeviceSessionState:s,closeApp:a,getAppAndVersion:u}=this.extractDependencies(r),i=this.input.unlockTimeout??v,d=new g({input:{unlockTimeout:i}}).makeStateMachine(r);return S({types:{input:{unlockTimeout:i},context:{},output:{}},actors:{getAppAndVersion:p(u),closeApp:p(a),getDeviceStatus:d},guards:{hasError:({context:e})=>e._internalState.error!==null,isDashboardOpen:({context:e})=>e._internalState.currentApp!==null&&b(e._internalState.currentApp)},actions:{assignErrorFromEvent:n({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GoToDashboardDeviceAction",initial:"DeviceReady",context:e=>{const t=o();return{input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:h.None},_internalState:{currentApp:"currentApp"in t?t.currentApp.name:null,error:null}}},states:{DeviceReady:{always:{target:"GetDeviceStatus"}},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:n({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:n({_internalState:e=>e.event.output.caseOf({Right:t=>({...e.context._internalState,currentApp:t.currentApp}),Left:t=>({...e.context._internalState,error:t})})})}}},CheckDeviceStatus:{always:[{target:"Error",guard:"hasError"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"Success",guard:"isDashboardOpen"},{target:"Error",guard:"hasError"},{target:"Error",guard:e=>e.context._internalState.currentApp===null,actions:n({_internalState:e=>({...e.context._internalState,error:new y("currentApp === null")})})},{target:"CloseApp"}]},CloseApp:{invoke:{src:"closeApp",onDone:{target:"CloseAppCheck",actions:n({_internalState:e=>c(e.event.output)?e.context._internalState:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseAppCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetAppAndVersion",reenter:!0}]},GetAppAndVersion:{invoke:{src:"getAppAndVersion",onDone:{target:"DashboardCheck",actions:n({_internalState:e=>{if(c(e.event.output)){const t=o();return t.sessionStateType!==G.Connected&&s({...t,currentApp:e.event.output.data}),{...e.context._internalState,currentApp:e.event.output.data.name}}return{...e.context._internalState,error:e.event.output.error}}})}}},Success:{type:"final"},Error:{type:"final"}},output:e=>e.context._internalState.error?D(e.context._internalState.error):l(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new A),getAppAndVersion:async()=>r.sendCommand(new m),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a)}}}export{L as GoToDashboardDeviceAction};
2
2
  //# sourceMappingURL=GoToDashboardDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\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 { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\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} from \"@api/device-session/DeviceSessionState\";\n\nimport type {\n GoToDashboardDAError,\n GoToDashboardDAInput,\n GoToDashboardDAIntermediateValue,\n GoToDashboardDAOutput,\n} from \"./types\";\n\ntype GoToDashboardMachineInternalState = {\n readonly currentApp: string | null;\n readonly error: GoToDashboardDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GoToDashboardDeviceAction extends XStateDeviceAction<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n > {\n type types = StateMachineTypes<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n >;\n\n const {\n getDeviceSessionState,\n setDeviceSessionState,\n closeApp,\n getAppAndVersion,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\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 closeApp: fromPromise(closeApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n hasError: ({ context }: { context: types[\"context\"] }) => {\n return context._internalState.error !== null;\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) =>\n context._internalState.currentApp === \"BOLOS\",\n },\n actions: {\n // assignGetDeviceStatusUnknownError: assign({\n // _internalState: (_) => ({\n // ..._.context._internalState,\n // error: new UnknownDAError(\"GetDeviceUnknownStatusError\"),\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 N4IgpgJg5mDOIC5QHED2AVVARAhrAFgEao4BOEWYAbgJYDGYAgnQC42oB2AdJbQwEpgcEAJ4BiANoAGALqJQAB1SwabTvJAAPRAHYAjFwDMATikA2MwA5DOnQBYArGeOGANCBGI9VrlcvmpRyknQwcAXzD3NExcAmIyCmp6JlZ2bmQwFl5kgGUWHBYAV1gxCE4wLhoOKlQAawqIJIY8guLpOSQQJRU1Dg1tBAAmOy49QYcpHQdBvR0pMcszO3dPBEM7My4HYz1pqWNLPRsdJYiojGw8IhJybIZmXq4AYXwwOlq7sBaikvaNbtUaX6iDsgy2g3Wdksjn8JlBDhWiAchk2OkMgysB2RzlBZxA0UucRuiT4KUeLzeHyaX3yP0keg6imUgPUnQGgxmo3hdkcemMwwcG0RCGxXDRGMsWJRxlxkXxF1i1wSnweaR4V3i5Ap70ksn+zN6wIQfMsYsG0LMg2MZlm60mwucDi4HMli0GgX0zjxBMVmpJyVVnHVRIS2tq9MZX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id: \"GoToDashboardDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n currentApp:\n \"currentApp\" in sessionState\n ? sessionState.currentApp.name\n : null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"GetDeviceStatus\",\n },\n },\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<GoToDashboardMachineInternalState>(\n {\n Right: (output) => ({\n ..._.context._internalState,\n currentApp: output.currentApp,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n );\n },\n }),\n },\n // NOTE: The way we handle our DeviceActions means that we should never as we return an Either\n // onError: {\n // target: \"Error\",\n // actions: \"assignGetDeviceStatusUnknownError\",\n // },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n DashboardCheck: {\n // We check if the dashboard is open\n always: [\n {\n target: \"Success\",\n guard: \"isDashboardOpen\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Error\",\n guard: (_) => {\n return _.context._internalState.currentApp === null;\n },\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\"currentApp === null\"),\n }),\n }),\n },\n {\n target: \"CloseApp\",\n },\n ],\n },\n CloseApp: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseAppCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return _.context._internalState;\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 CloseAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetAppAndVersion\",\n reenter: true,\n },\n ],\n },\n GetAppAndVersion: {\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"DashboardCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n // Narrow the type to ReadyWithoutSecureChannelState or ReadyWithSecureChannelState\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n }\n return {\n ..._.context._internalState,\n currentApp: _.event.output.data.name,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (_) => {\n if (_.context._internalState.error) {\n return Left(_.context._internalState.error);\n }\n\n return Right(undefined);\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const getAppAndVersion = async () =>\n internalApi.sendCommand(new GetAppAndVersionCommand());\n\n return {\n closeApp,\n getAppAndVersion,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,2BA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AQ,mBACR,QAAS,EACX,CACF,CACF,EACA,iBAAkB,CAChB,OAAQ,CACN,IAAK,mBACL,OAAQ,CACN,OAAQ,iBACR,QAASrB,EAAO,CACd,eAAiBqB,GAAM,CACrB,GAAIlB,EAAuBkB,EAAE,MAAM,MAAM,EAAG,CAC1C,MAAMI,EAA4BX,EAAsB,EAExD,OACEW,EAAM,mBACNd,EAAuB,WAEvBI,EAAsB,CACpB,GAAGU,EACH,WAAYJ,EAAE,MAAM,OAAO,IAC7B,CAAC,EAEI,CACL,GAAGA,EAAE,QAAQ,eACb,WAAYA,EAAE,MAAM,OAAO,KAAK,IAClC,CACF,CACA,MAAO,CACL,GAAGA,EAAE,QAAQ,eACb,MAAOA,EAAE,MAAM,OAAO,KACxB,CACF,CACF,CAAC,CACH,CACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASA,GACHA,EAAE,QAAQ,eAAe,MACpBvB,EAAKuB,EAAE,QAAQ,eAAe,KAAK,EAGrCtB,EAAM,MAAS,CAE1B,CAAC,CACH,CAEA,oBAAoBc,EAA+C,CAKjE,MAAO,CACL,SALe,SAAYA,EAAY,YAAY,IAAIT,CAAiB,EAMxE,iBALuB,SACvBS,EAAY,YAAY,IAAIR,CAAyB,EAKrD,sBAAuB,IAAMQ,EAAY,sBAAsB,EAC/D,sBAAwBY,GACtBZ,EAAY,sBAAsBY,CAAK,CAC3C,CACF,CACF",
6
- "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "GetAppAndVersionCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "UnknownDAError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "GoToDashboardDeviceAction", "internalApi", "getDeviceSessionState", "setDeviceSessionState", "closeApp", "getAppAndVersion", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "sessionState", "output", "error", "state"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\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 { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\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} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport type {\n GoToDashboardDAError,\n GoToDashboardDAInput,\n GoToDashboardDAIntermediateValue,\n GoToDashboardDAOutput,\n} from \"./types\";\n\ntype GoToDashboardMachineInternalState = {\n readonly currentApp: string | null;\n readonly error: GoToDashboardDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GoToDashboardDeviceAction extends XStateDeviceAction<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n > {\n type types = StateMachineTypes<\n GoToDashboardDAOutput,\n GoToDashboardDAInput,\n GoToDashboardDAError,\n GoToDashboardDAIntermediateValue,\n GoToDashboardMachineInternalState\n >;\n\n const {\n getDeviceSessionState,\n setDeviceSessionState,\n closeApp,\n getAppAndVersion,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\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 closeApp: fromPromise(closeApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n hasError: ({ context }: { context: types[\"context\"] }) => {\n return context._internalState.error !== null;\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) =>\n context._internalState.currentApp !== null &&\n isDashboardName(context._internalState.currentApp),\n },\n actions: {\n // assignGetDeviceStatusUnknownError: assign({\n // _internalState: (_) => ({\n // ..._.context._internalState,\n // error: new UnknownDAError(\"GetDeviceUnknownStatusError\"),\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 N4IgpgJg5mDOIC5QHED2AVVARAhrAFgEao4BOEWYAbgJYDGYAgnQC42oB2AdJbQwEpgcEAJ4BiANoAGALqJQAB1SwabTvJAAPRAHYAjFwDMATikA2MwA5DOnQBYArGeOGANCBGI9VrlcvmpRyknQwcA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CYjgex1mD5oLrPTL2M-FC5UqSrOPejDbrbMraniZ+4nGV6J6OmqwbJsl3jPY2wQ2YaKy6W8sVpZYbs+rmUzDl4y84T7rBDyZgOvsWvqd4EI67bU7AeJtlJc7zkbnyYrBORxGaVCDh6PhhtGAcJjjPye3EWHolxUGCV2YrMcfWhFi5TyjgUYb9h+2TFG+GMIUhRyUy7IXjV0RNH5tZ13VvUpRpjOYYpBWZCxzOnZNHQZGweSR7qhDLcMTqN9vcDkhR0AwsCq1Gq1GhyIxWvsSYWMZ-I9mTJGEbXsx7Av4Qb7ecsR48ACirHsRXmMBjIi2JaRwEIDzeWtsDMmgUdCthwjadSaJFiWBumEIAA */\n id: \"GoToDashboardDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n currentApp:\n \"currentApp\" in sessionState\n ? sessionState.currentApp.name\n : null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"GetDeviceStatus\",\n },\n },\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<GoToDashboardMachineInternalState>(\n {\n Right: (output) => ({\n ..._.context._internalState,\n currentApp: output.currentApp,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n );\n },\n }),\n },\n // NOTE: The way we handle our DeviceActions means that we should never as we return an Either\n // onError: {\n // target: \"Error\",\n // actions: \"assignGetDeviceStatusUnknownError\",\n // },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n DashboardCheck: {\n // We check if the dashboard is open\n always: [\n {\n target: \"Success\",\n guard: \"isDashboardOpen\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Error\",\n guard: (_) => {\n return _.context._internalState.currentApp === null;\n },\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new UnknownDAError(\"currentApp === null\"),\n }),\n }),\n },\n {\n target: \"CloseApp\",\n },\n ],\n },\n CloseApp: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseAppCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return _.context._internalState;\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 CloseAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetAppAndVersion\",\n reenter: true,\n },\n ],\n },\n GetAppAndVersion: {\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"DashboardCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n // Narrow the type to ReadyWithoutSecureChannelState or ReadyWithSecureChannelState\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n }\n return {\n ..._.context._internalState,\n currentApp: _.event.output.data.name,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (_) => {\n if (_.context._internalState.error) {\n return Left(_.context._internalState.error);\n }\n\n return Right(undefined);\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const getAppAndVersion = async () =>\n internalApi.sendCommand(new GetAppAndVersionCommand());\n\n return {\n closeApp,\n getAppAndVersion,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,2BAAAC,MAEK,0CAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,mBAAAC,MAAuB,qBA2BzB,MAAMC,UAAkCH,CAM7C,CACA,iBACEI,EAOA,CASA,KAAM,CACJ,sBAAAC,EACA,sBAAAC,EACA,SAAAC,EACA,iBAAAC,CACF,EAAI,KAAK,oBAAoBJ,CAAW,EAElCK,EAAgB,KAAK,MAAM,eAAiBZ,EAE5Ca,EAAyB,IAAIX,EAA4B,CAC7D,MAAO,CACL,cAAAU,CACF,CACF,CAAC,EAAE,iBAAiBL,CAAW,EAC/B,OAAOZ,EAAM,CACX,MAAO,CACL,MAAO,CACL,cAAAiB,CACF,EACA,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,iBAAkBlB,EAAYiB,CAAgB,EAC9C,SAAUjB,EAAYgB,CAAQ,EAC9B,gBAAiBG,CACnB,EACA,OAAQ,CACN,SAAU,CAAC,CAAE,QAAAC,CAAQ,IACZA,EAAQ,eAAe,QAAU,KAE1C,gBAAiB,CAAC,CAAE,QAAAA,CAAQ,IAC1B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IV,CAAiB,EAMxE,iBALuB,SACvBU,EAAY,YAAY,IAAIT,CAAyB,EAKrD,sBAAuB,IAAMS,EAAY,sBAAsB,EAC/D,sBAAwBY,GACtBZ,EAAY,sBAAsBY,CAAK,CAC3C,CACF,CACF",
6
+ "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "GetAppAndVersionCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "UnknownDAError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "isDashboardName", "GoToDashboardDeviceAction", "internalApi", "getDeviceSessionState", "setDeviceSessionState", "closeApp", "getAppAndVersion", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "sessionState", "output", "error", "state"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as h,Right as y}from"purify-ts";import{assign as a,fromObservable as S,fromPromise as A,setup as g}from"xstate";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as O}from"../../../device-action/os/Const";import{OutOfMemoryDAError as x}from"../../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as D}from"../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{GoToDashboardDeviceAction as f}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{BuildAppsInstallPlanTask as M}from"../../../device-action/task/BuildAppsInstallPlanTask";import{PredictOutOfMemoryTask as v}from"../../../device-action/task/PredictOutOfMemoryTask";import{XStateDeviceAction as P}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as I}from"../../../device-session/DeviceSessionState";import{ConnectToSecureChannelTask as E}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as p}from"../../../secure-channel/task/types";class K extends P{makeStateMachine(t){const{buildInstallPlan:c,predictOutOfMemory:u,installApp:d}=this.extractDependencies(t),r=this.input.unlockTimeout??O,o=new D({input:{unlockTimeout:r,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(t),l=new f({input:{unlockTimeout:r}}).makeStateMachine(t);return g({types:{input:{unlockTimeout:r},context:{},output:{}},actors:{updateMetadata:o,buildInstallPlan:A(c),predictOutOfMemory:A(u),goToDashboard:l,installApp:S(d)},guards:{hasError:({context:e})=>e._internalState.error!==null,hasInstallPlan:e=>e.context.intermediateValue.installPlan!==null,hasMoreApps:e=>e.context._internalState.currentIndex<e.context.intermediateValue.installPlan.installPlan.length},actions:{assignErrorFromEvent:a({_internalState:e=>({...e.context._internalState,error:e.event.error})}),nextAppIndex:a({_internalState:e=>({...e.context._internalState,currentIndex:e.context._internalState.currentIndex+1})}),cleanupDeviceState:()=>{const e=t.getDeviceSessionState();e.sessionStateType!==I.Connected&&t.setDeviceSessionState({...e,installedApps:[],appsUpdates:void 0})}}}).createMachine({id:"InstallOrUpdateAppsDeviceAction",initial:"DeviceReady",context:e=>({input:{applications:e.input.applications,allowMissingApplication:e.input.allowMissingApplication,unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:i.None,installPlan:null},_internalState:{error:null,osVersion:null,currentIndex:0}}),states:{DeviceReady:{always:[{target:"UpdateDeviceMetadata"}]},UpdateDeviceMetadata:{exit:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"updateMetadata",src:"updateMetadata",input:e=>({unlockTimeout:e.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"UpdateDeviceMetadataCheck",actions:a({_internalState:e=>e.event.output.caseOf({Right:n=>({...e.context._internalState,osVersion:n.firmwareVersion.metadata}),Left:n=>({...e.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},UpdateDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"hasInstallPlan"},{target:"BuildInstallPlan"}]},BuildInstallPlan:{invoke:{src:"buildInstallPlan",input:e=>({applications:e.context.input.applications,allowMissingApplication:e.context.input.allowMissingApplication}),onDone:{target:"BuildInstallPlanCheck",actions:a({_internalState:e=>"error"in e.event.output?{...e.context._internalState,error:e.event.output.error}:e.context._internalState,intermediateValue:e=>"error"in e.event.output?e.context.intermediateValue:{...e.context.intermediateValue,installPlan:{installPlan:e.event.output.installPlan,alreadyInstalled:e.event.output.alreadyInstalled,missingApplications:e.event.output.missingApplications,currentIndex:0,currentProgress:0}}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},BuildInstallPlanCheck:{always:[{guard:"hasError",target:"Error"},{target:"PredictOutOfMemory",guard:"hasMoreApps"},{target:"Success"}]},PredictOutOfMemory:{invoke:{src:"predictOutOfMemory",input:e=>({installPlan:e.context.intermediateValue.installPlan.installPlan}),onDone:{target:"PredictOutOfMemoryCheck",actions:a({_internalState:e=>"error"in e.event.output?{...e.context._internalState,error:e.event.output.error}:e.event.output.outOfMemory?{...e.context._internalState,error:new x("Not enough memory for those applications")}:e.context._internalState})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},PredictOutOfMemoryCheck:{always:[{guard:"hasError",target:"Error"},{target:"GoToDashboard"}]},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:a({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:n=>({...e.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",actions:"cleanupDeviceState"}]},InstallApp:{exit:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"installApp",src:"installApp",input:e=>({osVersion:e.context._internalState.osVersion,application:e.context.intermediateValue.installPlan.installPlan[e.context._internalState.currentIndex]}),onSnapshot:{actions:a({intermediateValue:e=>{switch(e.event.snapshot.context?.type){case p.PermissionRequested:return{...e.context.intermediateValue,requiredUserInteraction:i.AllowSecureConnection};case p.PermissionGranted:{const n=t.getDeviceSessionState();return n.sessionStateType!==I.Connected&&t.setDeviceSessionState({...n,isSecureConnectionAllowed:!0}),{...e.context.intermediateValue,requiredUserInteraction:i.None}}case p.Progress:return{...e.context.intermediateValue,installPlan:{...e.context.intermediateValue.installPlan,currentIndex:e.context._internalState.currentIndex,currentProgress:e.event.snapshot.context.payload.progress}};default:return e.context.intermediateValue}}})},onDone:{target:"InstallAppCheck",actions:"nextAppIndex"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallAppCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",guard:"hasMoreApps"},{target:"UpdateDeviceMetadata"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:n}=e,{error:m}=n._internalState,{installPlan:s}=n.intermediateValue;return m?h(m):y({successfullyInstalled:s.installPlan,alreadyInstalled:s.alreadyInstalled,missingApplications:s.missingApplications})}})}extractDependencies(t){return{buildInstallPlan:async r=>new M(t,{applications:r.input.applications,allowMissingApplication:r.input.allowMissingApplication}).run(),predictOutOfMemory:async r=>new v(t,{installPlan:r.input.installPlan}).run(),installApp:r=>{const{osVersion:o,application:l}=r.input,e=t.getSecureChannelService().installApp(o,l);return new E(t,{connection:e}).run()}}}}export{K as InstallOrUpdateAppsDeviceAction};
1
+ import{Left as h,Right as y}from"purify-ts";import{assign as a,fromObservable as S,fromPromise as A,setup as g}from"xstate";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as x}from"../../../device-action/os/Const";import{OutOfMemoryDAError as O}from"../../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as D}from"../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{GoToDashboardDeviceAction as f}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{BuildAppsInstallPlanTask as v}from"../../../device-action/task/BuildAppsInstallPlanTask";import{PredictOutOfMemoryTask as M}from"../../../device-action/task/PredictOutOfMemoryTask";import{XStateDeviceAction as P}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as I}from"../../../device-session/DeviceSessionState";import{ConnectToSecureChannelTask as E}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as o}from"../../../secure-channel/task/types";class K extends P{makeStateMachine(e){const{buildInstallPlan:c,predictOutOfMemory:u,installApp:d}=this.extractDependencies(e),r=this.input.unlockTimeout??x,l=new D({input:{unlockTimeout:r,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(e),s=new f({input:{unlockTimeout:r}}).makeStateMachine(e);return g({types:{input:{unlockTimeout:r},context:{},output:{}},actors:{updateMetadata:l,buildInstallPlan:A(c),predictOutOfMemory:A(u),goToDashboard:s,installApp:S(d)},guards:{hasError:({context:t})=>t._internalState.error!==null,hasInstallPlan:t=>t.context.intermediateValue.installPlan!==null,hasMoreApps:t=>t.context._internalState.currentIndex<t.context.intermediateValue.installPlan.installPlan.length},actions:{assignErrorFromEvent:a({_internalState:t=>({...t.context._internalState,error:t.event.error})}),nextAppIndex:a({_internalState:t=>({...t.context._internalState,currentIndex:t.context._internalState.currentIndex+1})}),cleanupDeviceState:()=>{const t=e.getDeviceSessionState();t.sessionStateType!==I.Connected&&e.setDeviceSessionState({...t,installedApps:[],appsUpdates:void 0})}}}).createMachine({id:"InstallOrUpdateAppsDeviceAction",initial:"DeviceReady",context:t=>({input:{applications:t.input.applications,allowMissingApplication:t.input.allowMissingApplication,unlockTimeout:t.input.unlockTimeout},intermediateValue:{requiredUserInteraction:i.None,installPlan:null},_internalState:{error:null,osVersion:null,currentIndex:0}}),states:{DeviceReady:{always:[{target:"UpdateDeviceMetadata"}]},UpdateDeviceMetadata:{exit:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"updateMetadata",src:"updateMetadata",input:t=>({unlockTimeout:t.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"UpdateDeviceMetadataCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:n=>({...t.context._internalState,osVersion:n.firmwareVersion.metadata}),Left:n=>({...t.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},UpdateDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"hasInstallPlan"},{target:"BuildInstallPlan"}]},BuildInstallPlan:{invoke:{src:"buildInstallPlan",input:t=>({applications:t.context.input.applications,allowMissingApplication:t.context.input.allowMissingApplication}),onDone:{target:"BuildInstallPlanCheck",actions:a({_internalState:t=>"error"in t.event.output?{...t.context._internalState,error:t.event.output.error}:t.context._internalState,intermediateValue:t=>"error"in t.event.output?t.context.intermediateValue:{...t.context.intermediateValue,installPlan:{installPlan:t.event.output.installPlan,alreadyInstalled:t.event.output.alreadyInstalled,missingApplications:t.event.output.missingApplications,currentIndex:0,currentProgress:0}}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},BuildInstallPlanCheck:{always:[{guard:"hasError",target:"Error"},{target:"PredictOutOfMemory",guard:"hasMoreApps"},{target:"Success"}]},PredictOutOfMemory:{invoke:{src:"predictOutOfMemory",input:t=>({installPlan:t.context.intermediateValue.installPlan.installPlan}),onDone:{target:"PredictOutOfMemoryCheck",actions:a({_internalState:t=>"error"in t.event.output?{...t.context._internalState,error:t.event.output.error}:t.event.output.outOfMemory?{...t.context._internalState,error:new O("Not enough memory for those applications")}:t.context._internalState})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},PredictOutOfMemoryCheck:{always:[{guard:"hasError",target:"Error"},{target:"GoToDashboard"}]},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:t.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:a({_internalState:t=>t.event.output.caseOf({Right:()=>t.context._internalState,Left:n=>({...t.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",actions:"cleanupDeviceState"}]},InstallApp:{exit:a({intermediateValue:t=>({...t.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"installApp",src:"installApp",input:t=>({osVersion:t.context._internalState.osVersion,application:t.context.intermediateValue.installPlan.installPlan[t.context._internalState.currentIndex]}),onSnapshot:{actions:a({intermediateValue:t=>{switch(t.event.snapshot.context?.type){case o.PermissionRequested:return{...t.context.intermediateValue,requiredUserInteraction:i.AllowSecureConnection};case o.PermissionGranted:{const n=e.getDeviceSessionState();return n.sessionStateType!==I.Connected&&e.setDeviceSessionState({...n,isSecureConnectionAllowed:!0}),{...t.context.intermediateValue,requiredUserInteraction:i.None}}case o.Progress:return{...t.context.intermediateValue,installPlan:{...t.context.intermediateValue.installPlan,currentIndex:t.context._internalState.currentIndex,currentProgress:t.event.snapshot.context.payload.progress}};default:return t.context.intermediateValue}},_internalState:t=>t.event.snapshot.context?.type===o.Error?{...t.context._internalState,error:t.event.snapshot.context.error.mapInstallDAErrors()}:t.context._internalState})},onDone:{target:"InstallAppCheck",actions:"nextAppIndex"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallAppCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",guard:"hasMoreApps"},{target:"UpdateDeviceMetadata"}]},Success:{type:"final"},Error:{type:"final"}},output:t=>{const{context:n}=t,{error:m}=n._internalState,{installPlan:p}=n.intermediateValue;return m?h(m):y({successfullyInstalled:p.installPlan,alreadyInstalled:p.alreadyInstalled,missingApplications:p.missingApplications})}})}extractDependencies(e){return{buildInstallPlan:async r=>new v(e,{applications:r.input.applications,allowMissingApplication:r.input.allowMissingApplication}).run(),predictOutOfMemory:async r=>new M(e,{installPlan:r.input.installPlan}).run(),installApp:r=>{const{osVersion:l,application:s}=r.input,t=e.getSecureChannelService().installApp(l,s);return new E(e,{connection:t}).run()}}}}export{K as InstallOrUpdateAppsDeviceAction};
2
2
  //# sourceMappingURL=InstallOrUpdateAppsDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\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 { OutOfMemoryDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport {\n BuildAppsInstallPlanTask,\n type BuildAppsInstallPlanTaskResult,\n} from \"@api/device-action/task/BuildAppsInstallPlanTask\";\nimport {\n PredictOutOfMemoryTask,\n type PredictOutOfMemoryTaskResult,\n} from \"@api/device-action/task/PredictOutOfMemoryTask\";\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 { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { type GetOsVersionResponse } from \"@api/index\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type ApplicationDependency,\n type InstallOrUpdateAppsDAError,\n type InstallOrUpdateAppsDAInput,\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"./types\";\n\ntype InstallOrUpdateAppsMachineInternalState = {\n readonly error: InstallOrUpdateAppsDAError | null;\n readonly osVersion: GetOsVersionResponse | null;\n readonly currentIndex: number;\n};\n\nexport type MachineDependencies = {\n readonly buildInstallPlan: (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) => Promise<BuildAppsInstallPlanTaskResult>;\n readonly predictOutOfMemory: (arg0: {\n input: {\n installPlan: Application[];\n };\n }) => Promise<PredictOutOfMemoryTaskResult>;\n readonly installApp: (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class InstallOrUpdateAppsDeviceAction extends XStateDeviceAction<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n > {\n type types = StateMachineTypes<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n >;\n\n const { buildInstallPlan, predictOutOfMemory, installApp } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\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 updateMetadata: updateMetadataMachine,\n buildInstallPlan: fromPromise(buildInstallPlan),\n predictOutOfMemory: fromPromise(predictOutOfMemory),\n goToDashboard: goToDashboardMachine,\n installApp: fromObservable(installApp),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasInstallPlan: (_) => _.context.intermediateValue.installPlan !== null,\n hasMoreApps: (_) =>\n _.context._internalState.currentIndex <\n _.context.intermediateValue.installPlan!.installPlan.length,\n },\n actions: {\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 nextAppIndex: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentIndex: _.context._internalState.currentIndex + 1,\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful installation, cleanup the device session state\n // to force fetching the new device state when required\n const state = internalApi.getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n internalApi.setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n id: \"InstallOrUpdateAppsDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n applications: _.input.applications,\n allowMissingApplication: _.input.allowMissingApplication,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n osVersion: null,\n currentIndex: 0,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n UpdateDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"updateMetadata\",\n src: \"updateMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\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: \"UpdateDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n osVersion: data.firmwareVersion.metadata!,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n UpdateDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasInstallPlan\",\n },\n {\n target: \"BuildInstallPlan\",\n },\n ],\n },\n BuildInstallPlan: {\n invoke: {\n src: \"buildInstallPlan\",\n input: (_) => ({\n applications: _.context.input.applications,\n allowMissingApplication: _.context.input.allowMissingApplication,\n }),\n onDone: {\n target: \"BuildInstallPlanCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else {\n return _.context._internalState;\n }\n },\n intermediateValue: (_) => {\n if (\"error\" in _.event.output) {\n return _.context.intermediateValue;\n } else {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n installPlan: _.event.output.installPlan,\n alreadyInstalled: _.event.output.alreadyInstalled,\n missingApplications: _.event.output.missingApplications,\n currentIndex: 0,\n currentProgress: 0,\n },\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n BuildInstallPlanCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"PredictOutOfMemory\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n PredictOutOfMemory: {\n invoke: {\n src: \"predictOutOfMemory\",\n input: (_) => ({\n installPlan: _.context.intermediateValue.installPlan!.installPlan,\n }),\n onDone: {\n target: \"PredictOutOfMemoryCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else if (_.event.output.outOfMemory) {\n return {\n ..._.context._internalState,\n error: new OutOfMemoryDAError(\n \"Not enough memory for those applications\",\n ),\n };\n } else {\n return _.context._internalState;\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n PredictOutOfMemoryCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\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: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n actions: \"cleanupDeviceState\",\n },\n ],\n },\n InstallApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"installApp\",\n src: \"installApp\",\n input: (_) => ({\n osVersion: _.context._internalState.osVersion!,\n application:\n _.context.intermediateValue.installPlan!.installPlan[\n _.context._internalState.currentIndex\n ]!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.PermissionRequested: {\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n isSecureConnectionAllowed: true,\n });\n }\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n case SecureChannelEventType.Progress: {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n ..._.context.intermediateValue.installPlan!,\n currentIndex: _.context._internalState.currentIndex,\n currentProgress:\n _.event.snapshot.context.payload.progress,\n },\n };\n }\n default:\n return _.context.intermediateValue;\n }\n },\n }),\n },\n onDone: {\n target: \"InstallAppCheck\",\n actions: \"nextAppIndex\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error } = context._internalState;\n const { installPlan } = context.intermediateValue;\n if (error) {\n return Left(error);\n }\n return Right({\n successfullyInstalled: installPlan!.installPlan,\n alreadyInstalled: installPlan!.alreadyInstalled,\n missingApplications: installPlan!.missingApplications,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const buildInstallPlan = async (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) =>\n new BuildAppsInstallPlanTask(internalApi, {\n applications: arg0.input.applications,\n allowMissingApplication: arg0.input.allowMissingApplication,\n }).run();\n\n const predictOutOfMemory = async (arg0: {\n input: {\n installPlan: Application[];\n };\n }) =>\n new PredictOutOfMemoryTask(internalApi, {\n installPlan: arg0.input.installPlan,\n }).run();\n\n const installApp = (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => {\n const { osVersion, application } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .installApp(osVersion, application);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n buildInstallPlan,\n predictOutOfMemory,\n installApp,\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAG3D,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,iCAAAC,MAAqC,wEAC9C,OAAS,6BAAAC,MAAiC,gEAC1C,OACE,4BAAAC,MAEK,mDACP,OACE,0BAAAC,MAEK,iDAEP,OAEE,sBAAAC,MACK,qDACP,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,8BAAAC,MAAkC,sDAC3C,OAAS,0BAAAC,MAA8B,iCA0ChC,MAAMC,UAAwC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O,IAAIpB,EAA2BG,EAAa,CACjD,WAAAkB,CACF,CAAC,EAAE,IAAI,CACT,CAMA,CACF,CACF",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\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 { OutOfMemoryDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport {\n BuildAppsInstallPlanTask,\n type BuildAppsInstallPlanTaskResult,\n} from \"@api/device-action/task/BuildAppsInstallPlanTask\";\nimport {\n PredictOutOfMemoryTask,\n type PredictOutOfMemoryTaskResult,\n} from \"@api/device-action/task/PredictOutOfMemoryTask\";\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 { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { type GetOsVersionResponse } from \"@api/index\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type ApplicationDependency,\n type InstallOrUpdateAppsDAError,\n type InstallOrUpdateAppsDAInput,\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"./types\";\n\ntype InstallOrUpdateAppsMachineInternalState = {\n readonly error: InstallOrUpdateAppsDAError | null;\n readonly osVersion: GetOsVersionResponse | null;\n readonly currentIndex: number;\n};\n\nexport type MachineDependencies = {\n readonly buildInstallPlan: (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) => Promise<BuildAppsInstallPlanTaskResult>;\n readonly predictOutOfMemory: (arg0: {\n input: {\n installPlan: Application[];\n };\n }) => Promise<PredictOutOfMemoryTaskResult>;\n readonly installApp: (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class InstallOrUpdateAppsDeviceAction extends XStateDeviceAction<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n > {\n type types = StateMachineTypes<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n >;\n\n const { buildInstallPlan, predictOutOfMemory, installApp } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\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 updateMetadata: updateMetadataMachine,\n buildInstallPlan: fromPromise(buildInstallPlan),\n predictOutOfMemory: fromPromise(predictOutOfMemory),\n goToDashboard: goToDashboardMachine,\n installApp: fromObservable(installApp),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasInstallPlan: (_) => _.context.intermediateValue.installPlan !== null,\n hasMoreApps: (_) =>\n _.context._internalState.currentIndex <\n _.context.intermediateValue.installPlan!.installPlan.length,\n },\n actions: {\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 nextAppIndex: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentIndex: _.context._internalState.currentIndex + 1,\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful installation, cleanup the device session state\n // to force fetching the new device state when required\n const state = internalApi.getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n internalApi.setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n id: \"InstallOrUpdateAppsDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n applications: _.input.applications,\n allowMissingApplication: _.input.allowMissingApplication,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n osVersion: null,\n currentIndex: 0,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n UpdateDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"updateMetadata\",\n src: \"updateMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\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: \"UpdateDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n osVersion: data.firmwareVersion.metadata!,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n UpdateDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasInstallPlan\",\n },\n {\n target: \"BuildInstallPlan\",\n },\n ],\n },\n BuildInstallPlan: {\n invoke: {\n src: \"buildInstallPlan\",\n input: (_) => ({\n applications: _.context.input.applications,\n allowMissingApplication: _.context.input.allowMissingApplication,\n }),\n onDone: {\n target: \"BuildInstallPlanCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else {\n return _.context._internalState;\n }\n },\n intermediateValue: (_) => {\n if (\"error\" in _.event.output) {\n return _.context.intermediateValue;\n } else {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n installPlan: _.event.output.installPlan,\n alreadyInstalled: _.event.output.alreadyInstalled,\n missingApplications: _.event.output.missingApplications,\n currentIndex: 0,\n currentProgress: 0,\n },\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n BuildInstallPlanCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"PredictOutOfMemory\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n PredictOutOfMemory: {\n invoke: {\n src: \"predictOutOfMemory\",\n input: (_) => ({\n installPlan: _.context.intermediateValue.installPlan!.installPlan,\n }),\n onDone: {\n target: \"PredictOutOfMemoryCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else if (_.event.output.outOfMemory) {\n return {\n ..._.context._internalState,\n error: new OutOfMemoryDAError(\n \"Not enough memory for those applications\",\n ),\n };\n } else {\n return _.context._internalState;\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n PredictOutOfMemoryCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\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: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n actions: \"cleanupDeviceState\",\n },\n ],\n },\n InstallApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"installApp\",\n src: \"installApp\",\n input: (_) => ({\n osVersion: _.context._internalState.osVersion!,\n application:\n _.context.intermediateValue.installPlan!.installPlan[\n _.context._internalState.currentIndex\n ]!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.PermissionRequested: {\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n isSecureConnectionAllowed: true,\n });\n }\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n case SecureChannelEventType.Progress: {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n ..._.context.intermediateValue.installPlan!,\n currentIndex: _.context._internalState.currentIndex,\n currentProgress:\n _.event.snapshot.context.payload.progress,\n },\n };\n }\n default:\n return _.context.intermediateValue;\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error:\n _.event.snapshot.context.error.mapInstallDAErrors(),\n };\n }\n return _.context._internalState;\n },\n }),\n },\n onDone: {\n target: \"InstallAppCheck\",\n actions: \"nextAppIndex\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error } = context._internalState;\n const { installPlan } = context.intermediateValue;\n if (error) {\n return Left(error);\n }\n return Right({\n successfullyInstalled: installPlan!.installPlan,\n alreadyInstalled: installPlan!.alreadyInstalled,\n missingApplications: installPlan!.missingApplications,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const buildInstallPlan = async (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) =>\n new BuildAppsInstallPlanTask(internalApi, {\n applications: arg0.input.applications,\n allowMissingApplication: arg0.input.allowMissingApplication,\n }).run();\n\n const predictOutOfMemory = async (arg0: {\n input: {\n installPlan: Application[];\n };\n }) =>\n new PredictOutOfMemoryTask(internalApi, {\n installPlan: arg0.input.installPlan,\n }).run();\n\n const installApp = (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => {\n const { osVersion, application } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .installApp(osVersion, application);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n buildInstallPlan,\n predictOutOfMemory,\n installApp,\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAG3D,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,iCAAAC,MAAqC,wEAC9C,OAAS,6BAAAC,MAAiC,gEAC1C,OACE,4BAAAC,MAEK,mDACP,OACE,0BAAAC,MAEK,iDAEP,OAEE,sBAAAC,MACK,qDACP,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,8BAAAC,MAAkC,sDAC3C,OAAS,0BAAAC,MAA8B,iCA0ChC,MAAMC,UAAwCJ,CAMnD,CACA,iBACEK,EAOA,CASA,KAAM,CAAE,iBAAAC,EAAkB,mBAAAC,EAAoB,WAAAC,CAAW,EACvD,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,MAAM,eAAiBf,EAE5CgB,EAAwB,IAAId,EAA8B,CAC9D,MAAO,CACL,cAAAa,EACA,iBAAkB,GAClB,YAAa,EACf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CAMA,CACF,CACF",
6
6
  "names": ["Left", "Right", "assign", "fromObservable", "fromPromise", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "OutOfMemoryDAError", "GetDeviceMetadataDeviceAction", "GoToDashboardDeviceAction", "BuildAppsInstallPlanTask", "PredictOutOfMemoryTask", "XStateDeviceAction", "DeviceSessionStateType", "ConnectToSecureChannelTask", "SecureChannelEventType", "InstallOrUpdateAppsDeviceAction", "internalApi", "buildInstallPlan", "predictOutOfMemory", "installApp", "unlockTimeout", "updateMetadataMachine", "goToDashboardMachine", "context", "_", "state", "data", "error", "deviceState", "args", "installPlan", "arg0", "osVersion", "application", "connection"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as D,Right as y}from"purify-ts";import{assign as t,fromPromise as c,setup as g}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as R}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as C}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";class q extends C{makeStateMachine(r){const{closeApp:o,openApp:s,getDeviceSessionState:a,isDeviceOnboarded:A,setDeviceSessionState:d}=this.extractDependencies(r),S=this.input.unlockTimeout??h,m=new R({input:{unlockTimeout:S}}).makeStateMachine(r);return g({types:{input:{},context:{},output:{}},actors:{closeApp:c(o),openApp:c(s),getDeviceStatus:m},guards:{isDeviceOnboarded:()=>A(),isRequestedAppOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return e._internalState.currentlyRunningApp===e.input.appName||e.input.compatibleAppNames!==void 0&&e.input.compatibleAppNames.includes(e._internalState.currentlyRunningApp)},isDashboardOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return e._internalState.currentlyRunningApp==="BOLOS"},hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:t({_internalState:e=>({...e.context._internalState,error:new E})}),assignUserActionNeededOpenApp:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.ConfirmOpenApp})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoError:t({_internalState:e=>({...e.context._internalState,error:null})})}}).createMachine({id:"OpenAppDeviceAction",initial:"DeviceReady",context:({input:e})=>{const n=a(),{sessionStateType:p}=n;return{input:e,intermediateValue:{requiredUserInteraction:i.None},_internalState:{error:null,currentlyRunningApp:p===l.ReadyWithoutSecureChannel?n.currentApp.name:null}}},states:{DeviceReady:{always:{target:"OnboardingCheck"}},OnboardingCheck:{always:[{target:"GetDeviceStatus",guard:{type:"isDeviceOnboarded"}},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:t({_internalState:e=>e.event.output.caseOf({Right:n=>{const p=a();return p.sessionStateType!==l.Connected&&d({...p,currentApp:{name:n.currentApp,version:n.currentAppVersion}}),{...e.context._internalState,currentlyRunningApp:n.currentApp}},Left:n=>({...e.context._internalState,error:n})})})}}},CheckDeviceStatus:{always:[{target:"Error",guard:"hasError"},{target:"ApplicationReady",guard:"isRequestedAppOpen"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"OpenApplication",guard:"isDashboardOpen"},"CloseApplication"]},OpenApplication:{entry:"assignUserActionNeededOpenApp",exit:"assignNoUserActionNeeded",invoke:{src:"openApp",input:({context:e})=>({appName:e.input.appName}),onDone:{target:"OpenApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:e.context.input.appName}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OpenApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetDeviceStatus"}]},CloseApplication:{invoke:{src:"closeApp",onDone:{target:"CloseApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:"BOLOS"}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"OpenApplication"}]},ApplicationCheck:{always:[{target:"ApplicationReady",guard:"isRequestedAppOpen"},"DashboardCheck"]},ApplicationReady:{always:"Success"},Success:{type:"final",actions:"assignNoError"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?D(e._internalState.error):y(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new O),openApp:async a=>r.sendCommand(new v({appName:a.input.appName})),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a),isDeviceOnboarded:()=>!0}}}export{q as OpenAppDeviceAction};
1
+ import{Left as D,Right as g}from"purify-ts";import{assign as t,fromPromise as c,setup as y}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as f}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as R}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as C}from"../../../transport/model/Errors";import{isDashboardName as x}from"../../../utils/AppName";class W extends R{makeStateMachine(r){const{closeApp:o,openApp:s,getDeviceSessionState:a,isDeviceOnboarded:A,setDeviceSessionState:d}=this.extractDependencies(r),S=this.input.unlockTimeout??h,m=new f({input:{unlockTimeout:S}}).makeStateMachine(r);return y({types:{input:{},context:{},output:{}},actors:{closeApp:c(o),openApp:c(s),getDeviceStatus:m},guards:{isDeviceOnboarded:()=>A(),isRequestedAppOpen:({context:e})=>e._internalState.currentlyRunningApp===null?!1:e._internalState.currentlyRunningApp===e.input.appName,isDashboardOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return x(e._internalState.currentlyRunningApp)},hasDisconnectedWhileSending:({context:e})=>e._internalState.error!==null&&e._internalState.error instanceof C,hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:t({_internalState:e=>({...e.context._internalState,error:new E})}),assignUserActionNeededOpenApp:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.ConfirmOpenApp})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoError:t({_internalState:e=>({...e.context._internalState,error:null})})}}).createMachine({id:"OpenAppDeviceAction",initial:"DeviceReady",context:({input:e})=>{const n=a(),{sessionStateType:p}=n;return{input:e,intermediateValue:{requiredUserInteraction:i.None},_internalState:{error:null,currentlyRunningApp:p===l.ReadyWithoutSecureChannel?n.currentApp.name:null}}},states:{DeviceReady:{always:{target:"OnboardingCheck"}},OnboardingCheck:{always:[{target:"GetDeviceStatus",guard:{type:"isDeviceOnboarded"}},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:t({_internalState:e=>e.event.output.caseOf({Right:n=>{const p=a();return p.sessionStateType!==l.Connected&&d({...p,currentApp:{name:n.currentApp,version:n.currentAppVersion}}),{...e.context._internalState,currentlyRunningApp:n.currentApp}},Left:n=>({...e.context._internalState,currentlyRunningApp:null,error:n})})})},onError:{target:"Error",actions:[t({_internalState:e=>({...e.context._internalState,currentlyRunningApp:null})}),"assignErrorFromEvent"]}}},CheckDeviceStatus:{always:[{target:"ApplicationReady",guard:"isRequestedAppOpen",actions:"assignNoError"},{target:"Error",guard:"hasError"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"OpenApplication",guard:"isDashboardOpen"},"CloseApplication"]},OpenApplication:{entry:"assignUserActionNeededOpenApp",exit:"assignNoUserActionNeeded",invoke:{src:"openApp",input:({context:e})=>({appName:e.input.appName}),onDone:{target:"OpenApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:e.context.input.appName}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"OpenApplicationResultCheck",actions:"assignErrorFromEvent"}}},OpenApplicationResultCheck:{always:[{target:"GetDeviceStatus",guard:"hasDisconnectedWhileSending"},{target:"Error",guard:"hasError"},{target:"GetDeviceStatus"}]},CloseApplication:{invoke:{src:"closeApp",onDone:{target:"CloseApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:"BOLOS"}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"OpenApplication"}]},ApplicationReady:{always:"Success"},Success:{type:"final",actions:"assignNoError"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?D(e._internalState.error):g(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new O),openApp:async a=>r.sendCommand(new v({appName:a.input.appName})),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a),isDeviceOnboarded:()=>!0}}}export{W as OpenAppDeviceAction};
2
2
  //# sourceMappingURL=OpenAppDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\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 { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\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} from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return (\n context._internalState.currentlyRunningApp ===\n context.input.appName ||\n (context.input.compatibleAppNames !== undefined &&\n context.input.compatibleAppNames.includes(\n context._internalState.currentlyRunningApp,\n ))\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return context._internalState.currentlyRunningApp === \"BOLOS\";\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 assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnC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: \"OpenAppDeviceAction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n // check device capabilities & status known\n always: {\n target: \"OnboardingCheck\",\n },\n },\n\n OnboardingCheck: {\n // check onboarding status provided by device session\n always: [\n {\n target: \"GetDeviceStatus\",\n guard: {\n type: \"isDeviceOnboarded\",\n },\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n );\n },\n }),\n },\n // NOTE: The way we handle our DeviceActions means that we should never as we return an Either\n // onError: {\n // target: \"Error\",\n // actions: \"assignGetDeviceStatusUnknownError\",\n // },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationCheck: {\n // Is the current application the requested one\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n \"DashboardCheck\",\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCA8CA,MAAMC,UAA4BF,CAMvC,CACA,iBACEG,EAOA,CASA,KAAM,CACJ,SAAAC,EACA,QAAAC,EACA,sBAAAC,EACA,kBAAAC,EACA,sBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBZ,EAE5Ca,EAAyB,IAAIX,EAA4B,CAC7D,MAAO,CACL,cAAAU,CACF,CACF,CAAC,EAAE,iBAAiBN,CAAW,EAE/B,OAAOX,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAA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AAM,MAAS,CACvB,CAAC,CACH,CAEA,oBAAoBc,EAA+C,CAOjE,MAAO,CACL,SAPe,SAAYA,EAAY,YAAY,IAAIT,CAAiB,EAQxE,QAPc,MAAOyB,GACrBhB,EAAY,YACV,IAAIR,EAAe,CAAE,QAASwB,EAAK,MAAM,OAAQ,CAAC,CACpD,EAKA,sBAAuB,IAAMhB,EAAY,sBAAsB,EAC/D,sBAAwBc,GACtBd,EAAY,sBAAsBc,CAAK,EACzC,kBAAmB,IAAM,EAC3B,CACF,CACF",
6
- "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "isDeviceOnboarded", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\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 { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\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} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceDisconnectedWhileSendingError } from \"@api/transport/model/Errors\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null) return false;\n return (\n context._internalState.currentlyRunningApp === context.input.appName\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return isDashboardName(context._internalState.currentlyRunningApp);\n },\n hasDisconnectedWhileSending: ({ context }) =>\n context._internalState.error !== null &&\n context._internalState.error instanceof\n DeviceDisconnectedWhileSendingError,\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 assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WBeBB6GAGGlCLQ8g7abNNf8mfrDcbTebLdaEE7gUbokJhBGuaUjvCbCSCdZNI5UQqhg1cQhNOprAxND4XP0xZTHI01SEPX9GTqfaQw-QTWaLVabWAkklaEkGKgLVQAGadgC2S3Vlfm2sYtfr2H9zaDIbrZQjUb2Bx5cb5CelydTxnT2nFXTcmjUBYTzlazkcE0CX1Hv3HiynfqbgbA7FgAFc9VQNhCV9CMZwqAlQuAWZwHiqbStI0mY+PmdRKNYxLZmKgjvDeUwVg+WpPrgBqLtEjYBi2H7fr+7ICJyq7crGIGIK0LwME8dzJuizzNNYmZeLmAysZ4Ph2KYmiaOWPz0l6Nb4b60R-lsRQ0UB5Qbq0pgMM4FJ8dYx4KpomaOJo6k9G4yHvEhBmYmJGpVhOurSYR9ByVRUL7LRwEKAxYq1PUkGtE8+ZaJmBh1A8hieMh17vFZY64UyeAcLAWQr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MiASe8IoFlGNchaS0waxNqfkepG4tACiMGeQw6IiQeBGncMaMycxEl8eoIFu0fiVPbg87qSE3q6MVBpehPQ4K6G+uoZUJIVB7laNiq+2s4DkRGYTLRygs6GSQtmO4iIaWljgvUBgip-K5RErofOdiYocLBZwHhBzOWSkKqKz6Lw3i6U+QgPchlTB7xTPBeCWVHDYoAMqflIOQWA8AlXuO6KMQylImipgMi4BZzhDIKkpM0FEypRimplXNWyABRMuSRIXjNaKvHQ3h0Q0reCYT+3khGNEKgqIRxgAgBCAA */\n id: \"OpenAppDeviceAction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n // check device capabilities & status known\n always: {\n target: \"OnboardingCheck\",\n },\n },\n\n OnboardingCheck: {\n // check onboarding status provided by device session\n always: [\n {\n target: \"GetDeviceStatus\",\n guard: {\n type: \"isDeviceOnboarded\",\n },\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n error,\n }),\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: [\n assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n }),\n }),\n \"assignErrorFromEvent\",\n ],\n },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n // If target app is currently opened, we can ignore errors\n actions: \"assignNoError\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"OpenApplicationResultCheck\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n // When an APDU triggers a disconnection, some transports may possibly\n // be closed on device side before the APDU response could be received,\n // especially on BLE transports.\n // Therefore when a disconnection occurs while sending, we should verify\n // the device status because it may have been successfully executed.\n target: \"GetDeviceStatus\",\n guard: \"hasDisconnectedWhileSending\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC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iBAAkB,CAC9B,CACF,EAEA,iBAAkB,CAChB,OAAQ,CACN,IAAK,WACL,OAAQ,CACN,OAAQ,8BACR,QAASxB,EAAO,CACd,eAAiBwB,GACXrB,EAAuBqB,EAAE,MAAM,MAAM,EAChC,CACL,GAAGA,EAAE,QAAQ,eACb,oBAAqB,OACvB,EAEO,CACL,GAAGA,EAAE,QAAQ,eACb,MAAOA,EAAE,MAAM,OAAO,KACxB,CAGN,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,4BAA6B,CAC3B,OAAQ,CACN,CACE,OAAQ,QACR,MAAO,UACT,EACA,CAAE,OAAQ,iBAAkB,CAC9B,CACF,EAEA,iBAAkB,CAEhB,OAAQ,SACV,EAGA,QAAS,CACP,KAAM,QACN,QAAS,eACX,EAGA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAAQ,CAAC,CAAE,QAAAD,CAAQ,IACjBA,EAAQ,eAAe,MACnBzB,EAAKyB,EAAQ,eAAe,KAAK,EACjCxB,EAAM,MAAS,CACvB,CAAC,CACH,CAEA,oBAAoBgB,EAA+C,CAOjE,MAAO,CACL,SAPe,SAAYA,EAAY,YAAY,IAAIX,CAAiB,EAQxE,QAPc,MAAO2B,GACrBhB,EAAY,YACV,IAAIV,EAAe,CAAE,QAAS0B,EAAK,MAAM,OAAQ,CAAC,CACpD,EAKA,sBAAuB,IAAMhB,EAAY,sBAAsB,EAC/D,sBAAwBc,GACtBd,EAAY,sBAAsBc,CAAK,EACzC,kBAAmB,IAAM,EAC3B,CACF,CACF",
6
+ "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "DeviceDisconnectedWhileSendingError", "isDashboardName", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "isDeviceOnboarded", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{lastValueFrom as y}from"rxjs";import{InvalidStatusWordError as v}from"../../../command/Errors";import{CommandResultFactory as l}from"../../../command/model/CommandResult";import{DeviceModelId as w}from"../../../device/DeviceModel";import{DeviceStatus as a}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as p}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as A}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as u}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as e}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as t}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as C,DeviceNotOnboardedError as R,UnknownDAError as D}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{OpenAppDeviceAction as d}from"./OpenAppDeviceAction";vi.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const O=vi.fn(),S=vi.fn(),V=vi.fn(),c=vi.fn(),h=vi.fn(),k=vi.fn();function m(){return{getDeviceSessionState:c,setDeviceSessionState:h,getAppAndVersion:O,openApp:S,closeApp:V,isDeviceOnboarded:k}}const{getDeviceSessionState:E}=p();beforeEach(()=>{vi.resetAllMocks(),k.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",()=>new Promise((r,o)=>{E.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[],deviceModelId:w.NANO_X,isSecureConnectionAllowed:!1}),A([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})}))}),describe("success cases",()=>{it("should end in a success if the app is already opened",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),A([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const n=new d({input:{appName:"Bitcoin",unlockTimeout:void 0}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if a compatible app is already opened",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin Testnet",version:"1.0.0"}}),A([{currentApp:"Bitcoin Testnet",currentAppVersion:"1.0.0"}]);const n=new d({input:{appName:"Bitcoin",unlockTimeout:void 0,compatibleAppNames:["Bitcoin Testnet"]}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if the dashboard is open and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),A([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),S.mockResolvedValue(l({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});y(N).then(()=>{expect(h).toHaveBeenCalledWith({deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})})),it("should end in a success if another app is open, close app succeeds and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),A([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),V.mockResolvedValue(l({data:void 0})),S.mockResolvedValue(l({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});y(N).then(()=>{expect(h).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel})})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),k.mockReturnValue(!1);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{error:new R,status:e.Error}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the device is locked",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),A([new C]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new C}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),A([new v("mocked error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new v("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the dashboard is open and open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue(l({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(l({data:{name:"BOLOS",version:"0.0.0"}})),A([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockResolvedValue(l({error:new v("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new v("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, and close app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),A([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(l({error:new v("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new v("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, close app succeeds but open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),A([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(l({data:void 0})),S.mockResolvedValue(l({error:new v("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new v("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),A([new D("Unknown error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if openApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(l({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),A([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if closeApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(l({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),A([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),V.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should emit a stopped state if the action is cancelled",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),A([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Stopped}],{cancel:N}=u(n,i,p(),{onDone:r,onError:o});N()}))})});
1
+ import{lastValueFrom as C}from"rxjs";import{InvalidStatusWordError as S}from"../../../command/Errors";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{DeviceModelId as R}from"../../../device/DeviceModel";import{DeviceStatus as a}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as p}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as l}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as u}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as e}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as t}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as E,DeviceNotOnboardedError as P,UnknownDAError as D}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as y}from"../../../transport/model/Errors";import{OpenAppDeviceAction as d}from"./OpenAppDeviceAction";vi.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const O=vi.fn(),v=vi.fn(),V=vi.fn(),c=vi.fn(),h=vi.fn(),k=vi.fn();function m(){return{getDeviceSessionState:c,setDeviceSessionState:h,getAppAndVersion:O,openApp:v,closeApp:V,isDeviceOnboarded:k}}const{getDeviceSessionState:w}=p();beforeEach(()=>{vi.resetAllMocks(),k.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",()=>new Promise((r,o)=>{w.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[],deviceModelId:R.NANO_X,isSecureConnectionAllowed:!1}),l([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})}))}),describe("success cases",()=>{it("should end in a success if the app is already opened",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),l([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const n=new d({input:{appName:"Bitcoin",unlockTimeout:void 0}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if the dashboard is open and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),l([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),v.mockResolvedValue(A({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});C(N).then(()=>{expect(h).toHaveBeenCalledWith({deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})})),it("should end in a success if disconnection occurs while open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]),v.mockRejectedValue(new y);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if another app is open, close app succeeds and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),V.mockResolvedValue(A({data:void 0})),v.mockResolvedValue(A({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});C(N).then(()=>{expect(h).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel})})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),k.mockReturnValue(!1);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{error:new P,status:e.Error}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the device is locked",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new E]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new E}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new S("mocked error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the dashboard is open and open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if disconnection occurs while open app failed",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockRejectedValue(new y);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new y}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, and close app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, close app succeeds but open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(A({data:void 0})),v.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new D("Unknown error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if openApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if closeApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),l([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),V.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should emit a stopped state if the action is cancelled",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Stopped}],{cancel:N}=u(n,i,p(),{onDone:r,onError:o});N()}))})});
2
2
  //# sourceMappingURL=OpenAppDeviceAction.test.js.map