@ledgerhq/device-management-kit 1.1.0 → 1.2.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 (204) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/api/apdu/utils/ApduBuilder.js +1 -1
  3. package/lib/cjs/src/api/apdu/utils/ApduBuilder.js.map +3 -3
  4. package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
  5. package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
  6. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  7. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
  8. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
  9. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
  10. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -1
  11. package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +3 -3
  12. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  13. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  14. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
  15. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
  16. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
  17. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +3 -3
  18. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  19. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  20. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  21. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
  22. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
  23. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +3 -3
  24. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  25. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  26. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
  27. package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
  28. package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js +1 -1
  29. package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js.map +3 -3
  30. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  31. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  32. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
  33. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +2 -2
  34. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
  35. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +3 -3
  36. package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
  37. package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
  38. package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
  39. package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
  40. package/lib/cjs/src/api/device-action/os/ListApps/types.js +1 -1
  41. package/lib/cjs/src/api/device-action/os/ListApps/types.js.map +3 -3
  42. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
  43. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
  44. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
  45. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
  46. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -1
  47. package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js.map +3 -3
  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 +3 -3
  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 +3 -3
  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 +3 -3
  56. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
  57. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
  58. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
  59. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +3 -3
  60. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  61. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
  62. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
  63. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
  64. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -1
  65. package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +3 -3
  66. package/lib/cjs/src/api/index.js +1 -1
  67. package/lib/cjs/src/api/index.js.map +3 -3
  68. package/lib/cjs/src/api/types.js +1 -1
  69. package/lib/cjs/src/api/types.js.map +1 -1
  70. package/lib/cjs/src/api/utils/ApplicationChecker.js +2 -0
  71. package/lib/cjs/src/api/utils/ApplicationChecker.js.map +7 -0
  72. package/lib/cjs/src/api/utils/ApplicationChecker.test.js +2 -0
  73. package/lib/cjs/src/api/utils/ApplicationChecker.test.js.map +7 -0
  74. package/lib/cjs/src/api/utils/ApplicationResolver.js +2 -0
  75. package/lib/cjs/src/api/utils/ApplicationResolver.js.map +7 -0
  76. package/lib/cjs/src/api/utils/Base64String.js +1 -1
  77. package/lib/cjs/src/api/utils/Base64String.js.map +3 -3
  78. package/lib/cjs/src/api/utils/Base64String.test.js +1 -1
  79. package/lib/cjs/src/api/utils/Base64String.test.js.map +3 -3
  80. package/lib/esm/package.json +1 -1
  81. package/lib/esm/src/api/apdu/utils/ApduBuilder.js +1 -1
  82. package/lib/esm/src/api/apdu/utils/ApduBuilder.js.map +3 -3
  83. package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
  84. package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
  85. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
  86. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
  87. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
  88. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
  89. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -0
  90. package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +4 -4
  91. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  92. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +3 -3
  93. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
  94. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
  95. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js +1 -0
  96. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js.map +4 -4
  97. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  98. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  99. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  100. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
  101. package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js +1 -0
  102. package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +4 -4
  103. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
  104. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
  105. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
  106. package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
  107. package/lib/esm/src/api/device-action/os/GoToDashboard/types.js +1 -0
  108. package/lib/esm/src/api/device-action/os/GoToDashboard/types.js.map +4 -4
  109. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  110. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +3 -3
  111. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
  112. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +3 -3
  113. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -0
  114. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js.map +4 -4
  115. package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
  116. package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
  117. package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
  118. package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
  119. package/lib/esm/src/api/device-action/os/ListApps/types.js +1 -0
  120. package/lib/esm/src/api/device-action/os/ListApps/types.js.map +4 -4
  121. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
  122. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
  123. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
  124. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
  125. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -0
  126. package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js.map +4 -4
  127. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
  128. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
  129. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
  130. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
  131. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -0
  132. package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js.map +4 -4
  133. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  134. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +3 -3
  135. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
  136. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
  137. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -0
  138. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js.map +4 -4
  139. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
  140. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
  141. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
  142. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
  143. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -0
  144. package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +4 -4
  145. package/lib/esm/src/api/index.js +1 -1
  146. package/lib/esm/src/api/index.js.map +3 -3
  147. package/lib/esm/src/api/utils/ApplicationChecker.js +2 -0
  148. package/lib/esm/src/api/utils/ApplicationChecker.js.map +7 -0
  149. package/lib/esm/src/api/utils/ApplicationChecker.test.js +2 -0
  150. package/lib/esm/src/api/utils/ApplicationChecker.test.js.map +7 -0
  151. package/lib/esm/src/api/utils/ApplicationResolver.js +1 -0
  152. package/lib/esm/src/api/utils/ApplicationResolver.js.map +7 -0
  153. package/lib/esm/src/api/utils/Base64String.js +1 -1
  154. package/lib/esm/src/api/utils/Base64String.js.map +3 -3
  155. package/lib/esm/src/api/utils/Base64String.test.js +1 -1
  156. package/lib/esm/src/api/utils/Base64String.test.js.map +3 -3
  157. package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts +7 -0
  158. package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
  159. package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
  160. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.d.ts.map +1 -1
  161. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts +9 -1
  162. package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts.map +1 -1
  163. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  164. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +13 -2
  165. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  166. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
  167. package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +6 -0
  168. package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
  169. package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts +1 -1
  170. package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts.map +1 -1
  171. package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts +9 -1
  172. package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts.map +1 -1
  173. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  174. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +9 -1
  175. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  176. package/lib/types/src/api/device-action/os/ListApps/ListAppsDeviceAction.d.ts.map +1 -1
  177. package/lib/types/src/api/device-action/os/ListApps/types.d.ts +6 -0
  178. package/lib/types/src/api/device-action/os/ListApps/types.d.ts.map +1 -1
  179. package/lib/types/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.d.ts.map +1 -1
  180. package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts +8 -1
  181. package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts.map +1 -1
  182. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
  183. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +12 -2
  184. package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
  185. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  186. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +8 -0
  187. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  188. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.d.ts.map +1 -1
  189. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts +9 -1
  190. package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
  191. package/lib/types/src/api/index.d.ts +4 -2
  192. package/lib/types/src/api/index.d.ts.map +1 -1
  193. package/lib/types/src/api/types.d.ts +1 -0
  194. package/lib/types/src/api/types.d.ts.map +1 -1
  195. package/lib/types/src/api/utils/ApplicationChecker.d.ts +14 -0
  196. package/lib/types/src/api/utils/ApplicationChecker.d.ts.map +1 -0
  197. package/lib/types/src/api/utils/ApplicationChecker.test.d.ts +2 -0
  198. package/lib/types/src/api/utils/ApplicationChecker.test.d.ts.map +1 -0
  199. package/lib/types/src/api/utils/ApplicationResolver.d.ts +12 -0
  200. package/lib/types/src/api/utils/ApplicationResolver.d.ts.map +1 -0
  201. package/lib/types/src/api/utils/Base64String.d.ts +1 -0
  202. package/lib/types/src/api/utils/Base64String.d.ts.map +1 -1
  203. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  204. package/package.json +5 -5
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/api/utils/ApplicationChecker.ts"],
4
+ "sourcesContent": ["import { gt, gte } from \"semver\";\n\nimport { type DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type AppConfig,\n type ApplicationResolver,\n} from \"./ApplicationResolver\";\n\nexport class ApplicationChecker {\n private isCompatible: boolean;\n private version: string;\n private modelId: DeviceModelId;\n\n constructor(\n deviceState: DeviceSessionState,\n appConfig: AppConfig,\n resolver: ApplicationResolver,\n ) {\n this.modelId = deviceState.deviceModelId;\n const resolved = resolver.resolve(deviceState, appConfig);\n this.isCompatible = resolved.isCompatible;\n this.version = resolved.version;\n }\n\n withMinVersionInclusive(version: string): ApplicationChecker {\n if (!gte(this.version, version)) this.isCompatible = false;\n return this;\n }\n\n withMinVersionExclusive(version: string): ApplicationChecker {\n if (!gt(this.version, version)) this.isCompatible = false;\n return this;\n }\n\n excludeDeviceModel(modelId: DeviceModelId): ApplicationChecker {\n if (this.modelId === modelId) this.isCompatible = false;\n return this;\n }\n\n check(): boolean {\n return this.isCompatible;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAwB,kBAUjB,MAAMF,CAAmB,CACtB,aACA,QACA,QAER,YACEG,EACAC,EACAC,EACA,CACA,KAAK,QAAUF,EAAY,cAC3B,MAAMG,EAAWD,EAAS,QAAQF,EAAaC,CAAS,EACxD,KAAK,aAAeE,EAAS,aAC7B,KAAK,QAAUA,EAAS,OAC1B,CAEA,wBAAwBC,EAAqC,CAC3D,SAAK,OAAI,KAAK,QAASA,CAAO,IAAG,KAAK,aAAe,IAC9C,IACT,CAEA,wBAAwBA,EAAqC,CAC3D,SAAK,MAAG,KAAK,QAASA,CAAO,IAAG,KAAK,aAAe,IAC7C,IACT,CAEA,mBAAmBC,EAA4C,CAC7D,OAAI,KAAK,UAAYA,IAAS,KAAK,aAAe,IAC3C,IACT,CAEA,OAAiB,CACf,OAAO,KAAK,YACd,CACF",
6
+ "names": ["ApplicationChecker_exports", "__export", "ApplicationChecker", "__toCommonJS", "import_semver", "deviceState", "appConfig", "resolver", "resolved", "version", "modelId"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var r=require("../device/DeviceModel"),n=require("../device/DeviceStatus"),l=require("../device-session/DeviceSessionState"),i=require("./ApplicationChecker");describe("ApplicationChecker",()=>{function s(e=r.DeviceModelId.FLEX){return{sessionStateType:l.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:n.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"TestApp",version:"1.0.0"},deviceModelId:e,isSecureConnectionAllowed:!1}}function o(e){return{resolve:()=>e}}const c={version:"1.0.0"};it("should pass check when resolved as compatible",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(),c,e).check();expect(t).toStrictEqual(!0)}),it("should reject check when resolved as incompatible",()=>{const e=o({isCompatible:!1,version:"0.0.1"}),t=new i.ApplicationChecker(s(),c,e).check();expect(t).toStrictEqual(!1)}),it("should pass with min version inclusive when version matches",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionInclusive("1.12.0").check();expect(t).toStrictEqual(!0)}),it("should reject with min version inclusive when version is too low",()=>{const e=o({isCompatible:!0,version:"1.11.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionInclusive("1.12.0").check();expect(t).toStrictEqual(!1)}),it("should pass with min version exclusive when version is greater",()=>{const e=o({isCompatible:!0,version:"1.13.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionExclusive("1.12.0").check();expect(t).toStrictEqual(!0)}),it("should reject with min version exclusive when version is equal",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionExclusive("1.12.0").check();expect(t).toStrictEqual(!1)}),it("should pass when device model is not excluded",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(r.DeviceModelId.FLEX),c,e).excludeDeviceModel(r.DeviceModelId.NANO_S).check();expect(t).toStrictEqual(!0)}),it("should reject when device model is excluded",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(r.DeviceModelId.FLEX),c,e).excludeDeviceModel(r.DeviceModelId.FLEX).check();expect(t).toStrictEqual(!1)}),it("should pass with chained conditions when all are met",()=>{const e=o({isCompatible:!0,version:"1.12.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionInclusive("1.11.0").excludeDeviceModel(r.DeviceModelId.NANO_S).check();expect(t).toStrictEqual(!0)}),it("should reject with chained conditions when one fails",()=>{const e=o({isCompatible:!0,version:"1.10.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionInclusive("1.11.0").excludeDeviceModel(r.DeviceModelId.NANO_S).check();expect(t).toStrictEqual(!1)}),it("should not override incompatible resolution even if constraints pass",()=>{const e=o({isCompatible:!1,version:"1.15.0"}),t=new i.ApplicationChecker(s(),c,e).withMinVersionInclusive("1.12.0").check();expect(t).toStrictEqual(!1)})});
2
+ //# sourceMappingURL=ApplicationChecker.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/api/utils/ApplicationChecker.test.ts"],
4
+ "sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\n\nimport { ApplicationChecker } from \"./ApplicationChecker\";\nimport {\n type ApplicationResolver,\n type ResolvedApp,\n} from \"./ApplicationResolver\";\n\ndescribe(\"ApplicationChecker\", () => {\n function createReadyState(modelId: DeviceModelId = DeviceModelId.FLEX) {\n return {\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"TestApp\", version: \"1.0.0\" },\n deviceModelId: modelId,\n isSecureConnectionAllowed: false,\n };\n }\n\n function createMockResolver(resolved: ResolvedApp): ApplicationResolver {\n return {\n resolve: () => resolved,\n };\n }\n\n const appConfig = { version: \"1.0.0\" };\n\n it(\"should pass check when resolved as compatible\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n ).check();\n expect(result).toStrictEqual(true);\n });\n\n it(\"should reject check when resolved as incompatible\", () => {\n const resolver = createMockResolver({\n isCompatible: false,\n version: \"0.0.1\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n ).check();\n expect(result).toStrictEqual(false);\n });\n\n it(\"should pass with min version inclusive when version matches\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionInclusive(\"1.12.0\")\n .check();\n expect(result).toStrictEqual(true);\n });\n\n it(\"should reject with min version inclusive when version is too low\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.11.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionInclusive(\"1.12.0\")\n .check();\n expect(result).toStrictEqual(false);\n });\n\n it(\"should pass with min version exclusive when version is greater\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.13.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionExclusive(\"1.12.0\")\n .check();\n expect(result).toStrictEqual(true);\n });\n\n it(\"should reject with min version exclusive when version is equal\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionExclusive(\"1.12.0\")\n .check();\n expect(result).toStrictEqual(false);\n });\n\n it(\"should pass when device model is not excluded\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(DeviceModelId.FLEX),\n appConfig,\n resolver,\n )\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n expect(result).toStrictEqual(true);\n });\n\n it(\"should reject when device model is excluded\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(DeviceModelId.FLEX),\n appConfig,\n resolver,\n )\n .excludeDeviceModel(DeviceModelId.FLEX)\n .check();\n expect(result).toStrictEqual(false);\n });\n\n it(\"should pass with chained conditions when all are met\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.12.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionInclusive(\"1.11.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n expect(result).toStrictEqual(true);\n });\n\n it(\"should reject with chained conditions when one fails\", () => {\n const resolver = createMockResolver({\n isCompatible: true,\n version: \"1.10.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionInclusive(\"1.11.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n expect(result).toStrictEqual(false);\n });\n\n it(\"should not override incompatible resolution even if constraints pass\", () => {\n const resolver = createMockResolver({\n isCompatible: false,\n version: \"1.15.0\",\n });\n const result = new ApplicationChecker(\n createReadyState(),\n appConfig,\n resolver,\n )\n .withMinVersionInclusive(\"1.12.0\")\n .check();\n expect(result).toStrictEqual(false);\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,mCAC9BC,EAA6B,oCAC7BC,EAAuC,kDAEvCC,EAAmC,gCAMnC,SAAS,qBAAsB,IAAM,CACnC,SAASC,EAAiBC,EAAyB,gBAAc,KAAM,CACrE,MAAO,CACL,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,WAAY,CAAE,KAAM,UAAW,QAAS,OAAQ,EAChD,cAAeA,EACf,0BAA2B,EAC7B,CACF,CAEA,SAASC,EAAmBC,EAA4C,CACtE,MAAO,CACL,QAAS,IAAMA,CACjB,CACF,CAEA,MAAMC,EAAY,CAAE,QAAS,OAAQ,EAErC,GAAG,gDAAiD,IAAM,CACxD,MAAMC,EAAWH,EAAmB,CAClC,aAAc,GACd,QAAS,QACX,CAAC,EACKI,EAAS,IAAI,qBACjBN,EAAiB,EACjBI,EACAC,CACF,EAAE,MA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,qBACjBN,EAAiB,gBAAc,IAAI,EACnCI,EACAC,CACF,EACG,mBAAmB,gBAAc,MAAM,EACvC,MAAM,EACT,OAAOC,CAAM,EAAE,cAAc,EAAI,CACnC,CAAC,EAED,GAAG,8CAA+C,IAAM,CACtD,MAAMD,EAAWH,EAAmB,CAClC,aAAc,GACd,QAAS,QACX,CAAC,EACKI,EAAS,IAAI,qBACjBN,EAAiB,gBAAc,IAAI,EACnCI,EACAC,CACF,EACG,mBAAmB,gBAAc,IAAI,EACrC,MAAM,EACT,OAAOC,CAAM,EAAE,cAAc,EAAK,CACpC,CAAC,EAED,GAAG,uDAAwD,IAAM,CAC/D,MAAMD,EAAWH,EAAmB,CAClC,aAAc,GACd,QAAS,QACX,CAAC,EACKI,EAAS,IAAI,qBACjBN,EAAiB,EACjBI,EACAC,CACF,EACG,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,EACT,OAAOC,CAAM,EAAE,cAAc,EAAI,CACnC,CAAC,EAED,GAAG,uDAAwD,IAAM,CAC/D,MAAMD,EAAWH,EAAmB,CAClC,aAAc,GACd,QAAS,QACX,CAAC,EACKI,EAAS,IAAI,qBACjBN,EAAiB,EACjBI,EACAC,CACF,EACG,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,EACT,OAAOC,CAAM,EAAE,cAAc,EAAK,CACpC,CAAC,EAED,GAAG,uEAAwE,IAAM,CAC/E,MAAMD,EAAWH,EAAmB,CAClC,aAAc,GACd,QAAS,QACX,CAAC,EACKI,EAAS,IAAI,qBACjBN,EAAiB,EACjBI,EACAC,CACF,EACG,wBAAwB,QAAQ,EAChC,MAAM,EACT,OAAOC,CAAM,EAAE,cAAc,EAAK,CACpC,CAAC,CACH,CAAC",
6
+ "names": ["import_DeviceModel", "import_DeviceStatus", "import_DeviceSessionState", "import_ApplicationChecker", "createReadyState", "modelId", "createMockResolver", "resolved", "appConfig", "resolver", "result"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var l=(o,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of s(e))!a.call(o,p)&&p!==t&&n(o,p,{get:()=>e[p],enumerable:!(i=r(e,p))||i.enumerable});return o};var v=o=>l(n({},"__esModule",{value:!0}),o);var d={};module.exports=v(d);
2
+ //# sourceMappingURL=ApplicationResolver.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/api/utils/ApplicationResolver.ts"],
4
+ "sourcesContent": ["import { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\n\nexport type AppConfig = Record<string, unknown> & {\n readonly version: string;\n};\n\nexport type ResolvedApp = {\n readonly isCompatible: boolean;\n readonly version: string;\n};\n\nexport interface ApplicationResolver {\n resolve(deviceState: DeviceSessionState, appConfig: AppConfig): ResolvedApp;\n}\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["ApplicationResolver_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(r,n)=>{for(var t in n)i(r,t,{get:n[t],enumerable:!0})},A=(r,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of s(n))!u.call(r,o)&&o!==t&&i(r,o,{get:()=>n[o],enumerable:!(e=a(n,o))||e.enumerable});return r};var g=r=>A(i({},"__esModule",{value:!0}),r);var l={};c(l,{base64StringToBuffer:()=>b,isBase64String:()=>f});module.exports=g(l);function f(r){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(r)}function b(r){if(r.length===0)return new Uint8Array;if(!f(r))return null;try{const n=atob(r),t=new Uint8Array(n.length);for(let e=0;e<n.length;e++)t[e]=n.charCodeAt(e);return t}catch{return Uint8Array.from(Buffer.from(r,"base64"))}}0&&(module.exports={base64StringToBuffer,isBase64String});
1
+ "use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var b=(r,n)=>{for(var t in n)i(r,t,{get:n[t],enumerable:!0})},c=(r,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of s(n))!g.call(r,o)&&o!==t&&i(r,o,{get:()=>n[o],enumerable:!(e=u(n,o))||e.enumerable});return r};var l=r=>c(i({},"__esModule",{value:!0}),r);var y={};b(y,{base64StringToBuffer:()=>d,bufferToBase64String:()=>h,isBase64String:()=>a});module.exports=l(y);function a(r){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(r)}function d(r){if(r.length===0)return new Uint8Array;if(!a(r))return null;try{const n=atob(r),t=new Uint8Array(n.length);for(let e=0;e<n.length;e++)t[e]=n.charCodeAt(e);return t}catch{return Uint8Array.from(Buffer.from(r,"base64"))}}function h(r){const n=globalThis;if(typeof n.btoa=="function"){let e="";for(let o=0;o<r.length;o++){const f=r[o];if(f===void 0)throw new Error("Unexpected undefined byte in array.");e+=String.fromCharCode(f)}return n.btoa(e)}const t=n.Buffer;if(typeof t<"u")return t.from(r).toString("base64");throw new Error("No Base64 encoder available in this environment.")}0&&(module.exports={base64StringToBuffer,bufferToBase64String,isBase64String});
2
2
  //# sourceMappingURL=Base64String.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/api/utils/Base64String.ts"],
4
- "sourcesContent": ["export function isBase64String(value: string): boolean {\n // Valid base64 characters are [A-Za-z0-9+/]\n // They are always grouped by 4 characters.\n // Optional padding at the end with one or two '='.\n // see section 4 of: https://www.rfc-editor.org/rfc/rfc4648.txt\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(\n value,\n );\n}\n\nexport function base64StringToBuffer(value: string): Uint8Array | null {\n if (value.length === 0) {\n return new Uint8Array();\n }\n if (!isBase64String(value)) {\n return null;\n }\n try {\n // Use the browser implementation of atob\n const base64Decoded = atob(value);\n const buffer = new Uint8Array(base64Decoded.length);\n for (let i = 0; i < base64Decoded.length; i++) {\n buffer[i] = base64Decoded.charCodeAt(i);\n }\n return buffer;\n } catch (_error: unknown) {\n // Use the implementation of Buffer for environments such as node\n return Uint8Array.from(Buffer.from(value, \"base64\"));\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,mBAAAC,IAAA,eAAAC,EAAAJ,GAAO,SAASG,EAAeE,EAAwB,CAKrD,MAAO,mEAAmE,KACxEA,CACF,CACF,CAEO,SAASH,EAAqBG,EAAkC,CACrE,GAAIA,EAAM,SAAW,EACnB,OAAO,IAAI,WAEb,GAAI,CAACF,EAAeE,CAAK,EACvB,OAAO,KAET,GAAI,CAEF,MAAMC,EAAgB,KAAKD,CAAK,EAC1BE,EAAS,IAAI,WAAWD,EAAc,MAAM,EAClD,QAASE,EAAI,EAAGA,EAAIF,EAAc,OAAQE,IACxCD,EAAOC,CAAC,EAAIF,EAAc,WAAWE,CAAC,EAExC,OAAOD,CACT,MAA0B,CAExB,OAAO,WAAW,KAAK,OAAO,KAAKF,EAAO,QAAQ,CAAC,CACrD,CACF",
6
- "names": ["Base64String_exports", "__export", "base64StringToBuffer", "isBase64String", "__toCommonJS", "value", "base64Decoded", "buffer", "i"]
4
+ "sourcesContent": ["export function isBase64String(value: string): boolean {\n // Valid base64 characters are [A-Za-z0-9+/]\n // They are always grouped by 4 characters.\n // Optional padding at the end with one or two '='.\n // see section 4 of: https://www.rfc-editor.org/rfc/rfc4648.txt\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(\n value,\n );\n}\n\nexport function base64StringToBuffer(value: string): Uint8Array | null {\n if (value.length === 0) {\n return new Uint8Array();\n }\n if (!isBase64String(value)) {\n return null;\n }\n try {\n // Use the browser implementation of atob\n const base64Decoded = atob(value);\n const buffer = new Uint8Array(base64Decoded.length);\n for (let i = 0; i < base64Decoded.length; i++) {\n buffer[i] = base64Decoded.charCodeAt(i);\n }\n return buffer;\n } catch (_error: unknown) {\n // Use the implementation of Buffer for environments such as node\n return Uint8Array.from(Buffer.from(value, \"base64\"));\n }\n}\n\nexport function bufferToBase64String(bytes: Uint8Array): string {\n const g = globalThis as typeof globalThis & {\n Buffer?: typeof Buffer;\n btoa?: (data: string) => string;\n };\n\n if (typeof g.btoa === \"function\") {\n // convert bytes to a binary string for btoa\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n const byte = bytes[i];\n if (byte === undefined) {\n throw new Error(\"Unexpected undefined byte in array.\");\n }\n binary += String.fromCharCode(byte);\n }\n return g.btoa(binary);\n }\n\n const Buf = g.Buffer;\n if (typeof Buf !== \"undefined\") {\n return Buf.from(bytes).toString(\"base64\");\n }\n\n throw new Error(\"No Base64 encoder available in this environment.\");\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,yBAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAL,GAAO,SAASI,EAAeE,EAAwB,CAKrD,MAAO,mEAAmE,KACxEA,CACF,CACF,CAEO,SAASJ,EAAqBI,EAAkC,CACrE,GAAIA,EAAM,SAAW,EACnB,OAAO,IAAI,WAEb,GAAI,CAACF,EAAeE,CAAK,EACvB,OAAO,KAET,GAAI,CAEF,MAAMC,EAAgB,KAAKD,CAAK,EAC1BE,EAAS,IAAI,WAAWD,EAAc,MAAM,EAClD,QAASE,EAAI,EAAGA,EAAIF,EAAc,OAAQE,IACxCD,EAAOC,CAAC,EAAIF,EAAc,WAAWE,CAAC,EAExC,OAAOD,CACT,MAA0B,CAExB,OAAO,WAAW,KAAK,OAAO,KAAKF,EAAO,QAAQ,CAAC,CACrD,CACF,CAEO,SAASH,EAAqBO,EAA2B,CAC9D,MAAMC,EAAI,WAKV,GAAI,OAAOA,EAAE,MAAS,WAAY,CAEhC,IAAIC,EAAS,GACb,QAASH,EAAI,EAAGA,EAAIC,EAAM,OAAQD,IAAK,CACrC,MAAMI,EAAOH,EAAMD,CAAC,EACpB,GAAII,IAAS,OACX,MAAM,IAAI,MAAM,qCAAqC,EAEvDD,GAAU,OAAO,aAAaC,CAAI,CACpC,CACA,OAAOF,EAAE,KAAKC,CAAM,CACtB,CAEA,MAAME,EAAMH,EAAE,OACd,GAAI,OAAOG,EAAQ,IACjB,OAAOA,EAAI,KAAKJ,CAAK,EAAE,SAAS,QAAQ,EAG1C,MAAM,IAAI,MAAM,kDAAkD,CACpE",
6
+ "names": ["Base64String_exports", "__export", "base64StringToBuffer", "bufferToBase64String", "isBase64String", "__toCommonJS", "value", "base64Decoded", "buffer", "i", "bytes", "g", "binary", "byte", "Buf"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./Base64String");describe("Base64String",()=>{describe("isBase64String function",()=>{it("should return true if the value is a valid base64 string",()=>{const t=(0,e.isBase64String)("Zmlyc3QgdG/zdGluZyBz+HI9");expect(t).toBeTruthy()}),it("should return true if the value is a valid base64 string, one padding",()=>{const t=(0,e.isBase64String)("Zmlyc3QgdGVzdGluZyBzdHI=");expect(t).toBeTruthy()}),it("should return true if the value is a valid base64 string, two paddings",()=>{const t=(0,e.isBase64String)("Zmlyc3QgdGVzdGluZyBzdH==");expect(t).toBeTruthy()}),it("should return true for an empty string",()=>{const t=(0,e.isBase64String)("");expect(t).toBeTruthy()}),it("should return false for an invalid base64 string",()=>{const t=(0,e.isBase64String)("invalid base64 string");expect(t).toBeFalsy()}),it("should return false with 3 paddings",()=>{const t=(0,e.isBase64String)("Zmlyc3QgdGVzdGluZyBzd===");expect(t).toBeFalsy()}),it("should return false on incomplete string (not multiple of 4)",()=>{const t=(0,e.isBase64String)("Zmlyc3QgdGVzdGluZyBzdHI");expect(t).toBeFalsy()})}),describe("base64StringToBuffer function",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should convert empty input to empty buffer",()=>{const t=(0,e.base64StringToBuffer)("");expect(t).toStrictEqual(new Uint8Array)}),it("invalid base64 string converted to null",()=>{const t=(0,e.base64StringToBuffer)("invalid string");expect(t).toStrictEqual(null)}),it("should convert a base64 string to a buffer using browser's atob",()=>{const t=(0,e.base64StringToBuffer)("Zmlyc3QgdGVzdCBzdHJpbmc=");expect(t).toStrictEqual(Uint8Array.from([102,105,114,115,116,32,116,101,115,116,32,115,116,114,105,110,103]))}),it("should convert a base64 string to a buffer using Buffer",()=>{vi.spyOn(global,"atob").mockImplementation(()=>{throw new Error("atob is not defined")});const t=(0,e.base64StringToBuffer)("Zmlyc3QgdGVzdCBzdHJpbmc=");expect(t).toStrictEqual(Uint8Array.from([102,105,114,115,116,32,116,101,115,116,32,115,116,114,105,110,103]))})})});
1
+ "use strict";var t=require("./Base64String");describe("Base64String",()=>{describe("isBase64String function",()=>{it("should return true if the value is a valid base64 string",()=>{const e=(0,t.isBase64String)("Zmlyc3QgdG/zdGluZyBz+HI9");expect(e).toBeTruthy()}),it("should return true if the value is a valid base64 string, one padding",()=>{const e=(0,t.isBase64String)("Zmlyc3QgdGVzdGluZyBzdHI=");expect(e).toBeTruthy()}),it("should return true if the value is a valid base64 string, two paddings",()=>{const e=(0,t.isBase64String)("Zmlyc3QgdGVzdGluZyBzdH==");expect(e).toBeTruthy()}),it("should return true for an empty string",()=>{const e=(0,t.isBase64String)("");expect(e).toBeTruthy()}),it("should return false for an invalid base64 string",()=>{const e=(0,t.isBase64String)("invalid base64 string");expect(e).toBeFalsy()}),it("should return false with 3 paddings",()=>{const e=(0,t.isBase64String)("Zmlyc3QgdGVzdGluZyBzd===");expect(e).toBeFalsy()}),it("should return false on incomplete string (not multiple of 4)",()=>{const e=(0,t.isBase64String)("Zmlyc3QgdGVzdGluZyBzdHI");expect(e).toBeFalsy()})}),describe("base64StringToBuffer function",()=>{beforeEach(()=>{vi.resetAllMocks()}),it("should convert empty input to empty buffer",()=>{const e=(0,t.base64StringToBuffer)("");expect(e).toStrictEqual(new Uint8Array)}),it("invalid base64 string converted to null",()=>{const e=(0,t.base64StringToBuffer)("invalid string");expect(e).toStrictEqual(null)}),it("should convert a base64 string to a buffer using browser's atob",()=>{const e=(0,t.base64StringToBuffer)("Zmlyc3QgdGVzdCBzdHJpbmc=");expect(e).toStrictEqual(Uint8Array.from([102,105,114,115,116,32,116,101,115,116,32,115,116,114,105,110,103]))}),it("should convert a base64 string to a buffer using Buffer",()=>{vi.spyOn(global,"atob").mockImplementation(()=>{throw new Error("atob is not defined")});const e=(0,t.base64StringToBuffer)("Zmlyc3QgdGVzdCBzdHJpbmc=");expect(e).toStrictEqual(Uint8Array.from([102,105,114,115,116,32,116,101,115,116,32,115,116,114,105,110,103]))})})});describe("bufferToBase64String",()=>{const a=globalThis.btoa,e=globalThis.Buffer;beforeEach(()=>{vi.restoreAllMocks(),globalThis.btoa=a,globalThis.Buffer=e}),afterAll(()=>{globalThis.btoa=a,globalThis.Buffer=e}),it("should encode an empty buffer to an empty base64 string when btoa is available",()=>{globalThis.btoa=vi.fn(o=>(expect(o).toBe(""),""));const s=new Uint8Array,n=(0,t.bufferToBase64String)(s);expect(n).toBe(""),expect(globalThis.btoa).toHaveBeenCalledTimes(1)}),it("should encode a buffer to base64 using btoa when available",()=>{const s="first testing str",n=Uint8Array.from(s.split("").map(r=>r.charCodeAt(0)));globalThis.btoa=vi.fn(r=>(expect(r).toBe(s),"Zmlyc3QgdGVzdGluZyBzdHI="));const o=(0,t.bufferToBase64String)(n);expect(o).toBe("Zmlyc3QgdGVzdGluZyBzdHI="),expect(globalThis.btoa).toHaveBeenCalledTimes(1)}),it("should encode a buffer to base64 using Buffer when btoa is not available",()=>{globalThis.btoa=void 0;const s="testing str",n=Buffer.from(s,"binary").toString("base64"),o=Uint8Array.from(s.split("").map(i=>i.charCodeAt(0))),r=vi.spyOn(Buffer,"from"),l=(0,t.bufferToBase64String)(o);expect(l).toBe(n),expect(r).toHaveBeenCalledTimes(1)}),it("should throw an error when no Base64 encoder is available",()=>{globalThis.btoa=void 0,globalThis.Buffer=void 0;const s=Uint8Array.from([1,2,3]);expect(()=>(0,t.bufferToBase64String)(s)).toThrowError("No Base64 encoder available in this environment.")}),it("should throw if an undefined byte is encountered (defensive check)",()=>{const s={length:3,0:102,1:void 0,2:111};globalThis.btoa=vi.fn(),expect(()=>(0,t.bufferToBase64String)(s)).toThrowError("Unexpected undefined byte in array.")})});
2
2
  //# sourceMappingURL=Base64String.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/api/utils/Base64String.test.ts"],
4
- "sourcesContent": ["import { base64StringToBuffer, isBase64String } from \"./Base64String\";\n\ndescribe(\"Base64String\", () => {\n describe(\"isBase64String function\", () => {\n it(\"should return true if the value is a valid base64 string\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdG/zdGluZyBz+HI9\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true if the value is a valid base64 string, one padding\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdHI=\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true if the value is a valid base64 string, two paddings\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdH==\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true for an empty string\", () => {\n // GIVEN\n const value = \"\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return false for an invalid base64 string\", () => {\n // GIVEN\n const value = \"invalid base64 string\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n\n it(\"should return false with 3 paddings\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzd===\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n\n it(\"should return false on incomplete string (not multiple of 4)\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdHI\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n });\n\n describe(\"base64StringToBuffer function\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should convert empty input to empty buffer\", () => {\n // GIVEN\n const value = \"\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(new Uint8Array());\n });\n\n it(\"invalid base64 string converted to null\", () => {\n // GIVEN\n const value = \"invalid string\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(null);\n });\n\n it(\"should convert a base64 string to a buffer using browser's atob\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdCBzdHJpbmc=\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(\n Uint8Array.from([\n 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20,\n 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,\n ]),\n );\n });\n\n it(\"should convert a base64 string to a buffer using Buffer\", () => {\n // GIVEN\n vi.spyOn(global, \"atob\").mockImplementation(() => {\n throw new Error(\"atob is not defined\");\n });\n const value = \"Zmlyc3QgdGVzdCBzdHJpbmc=\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(\n Uint8Array.from([\n 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20,\n 0x73,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CAK1E,MAAMA,KAAS,wBAHD,0BAG2B,EAGzC,OAAOA,CAAM,EAAE,cACb,WAAW,KAAK,CACd,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IAAM,IAAM,IAAM,GAC5D,IAAM,IAAM,IAAM,IAAM,IAAM,GAChC,CAAC,CACH,CACF,CAAC,EAED,GAAG,0DAA2D,IAAM,CAElE,GAAG,MAAM,OAAQ,MAAM,EAAE,mBAAmB,IAAM,CAChD,MAAM,IAAI,MAAM,qBAAqB,CACvC,CAAC,EAID,MAAMA,KAAS,wBAHD,0BAG2B,EAGzC,OAAOA,CAAM,EAAE,cACb,WAAW,KAAK,CACd,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IAAM,IAAM,IAAM,GAC5D,IAAM,IAAM,IAAM,IAAM,IAAM,GAChC,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_Base64String", "result"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n base64StringToBuffer,\n bufferToBase64String,\n isBase64String,\n} from \"./Base64String\";\n\ndescribe(\"Base64String\", () => {\n describe(\"isBase64String function\", () => {\n it(\"should return true if the value is a valid base64 string\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdG/zdGluZyBz+HI9\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true if the value is a valid base64 string, one padding\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdHI=\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true if the value is a valid base64 string, two paddings\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdH==\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return true for an empty string\", () => {\n // GIVEN\n const value = \"\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeTruthy();\n });\n\n it(\"should return false for an invalid base64 string\", () => {\n // GIVEN\n const value = \"invalid base64 string\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n\n it(\"should return false with 3 paddings\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzd===\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n\n it(\"should return false on incomplete string (not multiple of 4)\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdGluZyBzdHI\";\n\n // WHEN\n const result = isBase64String(value);\n\n // THEN\n expect(result).toBeFalsy();\n });\n });\n\n describe(\"base64StringToBuffer function\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should convert empty input to empty buffer\", () => {\n // GIVEN\n const value = \"\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(new Uint8Array());\n });\n\n it(\"invalid base64 string converted to null\", () => {\n // GIVEN\n const value = \"invalid string\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(null);\n });\n\n it(\"should convert a base64 string to a buffer using browser's atob\", () => {\n // GIVEN\n const value = \"Zmlyc3QgdGVzdCBzdHJpbmc=\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(\n Uint8Array.from([\n 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20,\n 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,\n ]),\n );\n });\n\n it(\"should convert a base64 string to a buffer using Buffer\", () => {\n // GIVEN\n vi.spyOn(global, \"atob\").mockImplementation(() => {\n throw new Error(\"atob is not defined\");\n });\n const value = \"Zmlyc3QgdGVzdCBzdHJpbmc=\";\n\n // WHEN\n const result = base64StringToBuffer(value);\n\n // THEN\n expect(result).toStrictEqual(\n Uint8Array.from([\n 0x66, 0x69, 0x72, 0x73, 0x74, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20,\n 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67,\n ]),\n );\n });\n });\n});\n\ndescribe(\"bufferToBase64String\", () => {\n const originalBtoa = (globalThis as any).btoa;\n const originalBuffer = (globalThis as any).Buffer;\n\n beforeEach(() => {\n vi.restoreAllMocks();\n (globalThis as any).btoa = originalBtoa;\n (globalThis as any).Buffer = originalBuffer;\n });\n\n afterAll(() => {\n (globalThis as any).btoa = originalBtoa;\n (globalThis as any).Buffer = originalBuffer;\n });\n\n it(\"should encode an empty buffer to an empty base64 string when btoa is available\", () => {\n // GIVEN\n (globalThis as any).btoa = vi.fn((input: string) => {\n expect(input).toBe(\"\");\n return \"\";\n });\n\n const bytes = new Uint8Array();\n\n // WHEN\n const result = bufferToBase64String(bytes);\n\n // THEN\n expect(result).toBe(\"\");\n expect(globalThis.btoa).toHaveBeenCalledTimes(1);\n });\n\n it(\"should encode a buffer to base64 using btoa when available\", () => {\n // GIVEN\n const text = \"first testing str\";\n const bytes = Uint8Array.from(text.split(\"\").map((c) => c.charCodeAt(0)));\n\n (globalThis as any).btoa = vi.fn((input: string) => {\n expect(input).toBe(text);\n return \"Zmlyc3QgdGVzdGluZyBzdHI=\";\n });\n\n // WHEN\n const result = bufferToBase64String(bytes);\n\n // THEN\n expect(result).toBe(\"Zmlyc3QgdGVzdGluZyBzdHI=\");\n expect(globalThis.btoa).toHaveBeenCalledTimes(1);\n });\n\n it(\"should encode a buffer to base64 using Buffer when btoa is not available\", () => {\n // GIVEN\n (globalThis as any).btoa = undefined;\n\n const text = \"testing str\";\n const expectedBase64 = Buffer.from(text, \"binary\").toString(\"base64\");\n const bytes = Uint8Array.from(text.split(\"\").map((c) => c.charCodeAt(0)));\n\n const bufferFromSpy = vi.spyOn(Buffer, \"from\");\n\n // WHEN\n const result = bufferToBase64String(bytes);\n\n // THEN\n expect(result).toBe(expectedBase64);\n expect(bufferFromSpy).toHaveBeenCalledTimes(1);\n });\n\n it(\"should throw an error when no Base64 encoder is available\", () => {\n // GIVEN\n (globalThis as any).btoa = undefined;\n (globalThis as any).Buffer = undefined;\n\n const bytes = Uint8Array.from([0x01, 0x02, 0x03]);\n\n // WHEN / THEN\n expect(() => bufferToBase64String(bytes)).toThrowError(\n \"No Base64 encoder available in this environment.\",\n );\n });\n\n it(\"should throw if an undefined byte is encountered (defensive check)\", () => {\n // GIVEN\n const bytes = {\n length: 3,\n 0: 0x66,\n 1: undefined,\n 2: 0x6f,\n } as unknown as Uint8Array;\n\n (globalThis as any).btoa = vi.fn();\n\n // WHEN / THEN\n expect(() => bufferToBase64String(bytes)).toThrowError(\n \"Unexpected undefined byte in array.\",\n );\n });\n});\n"],
5
+ "mappings": "aAIA,IAAAA,EAIO,0BAEP,SAAS,eAAgB,IAAM,CAC7B,SAAS,0BAA2B,IAAM,CACxC,GAAG,2DAA4D,IAAM,CAKnE,MAAMC,KAAS,kBAHD,0BAGqB,EAGnC,OAAOA,CAAM,EAAE,WAAW,CAC5B,CAAC,EAED,GAAG,wEAAyE,IAAM,CAKhF,MAAMA,KAAS,kBAHD,0BAGqB,EAGnC,OAAOA,CAAM,EAAE,WAAW,CAC5B,CAAC,EAED,GAAG,yEAA0E,IAAM,CAKjF,MAAMA,KAAS,kBAHD,0BAGqB,EAGnC,OAAOA,CAAM,EAAE,WAAW,CAC5B,CAAC,EAED,GAAG,yCAA0C,IAAM,CAKjD,MAAMA,KAAS,kBAHD,EAGqB,EAGnC,OAAOA,CAAM,EAAE,WAAW,CAC5B,CAAC,EAED,GAAG,mDAAoD,IAAM,CAK3D,MAAMA,KAAS,kBAHD,uBAGqB,EAGnC,OAAOA,CAAM,EAAE,UAAU,CAC3B,CAAC,EAED,GAAG,sCAAuC,IAAM,CAK9C,MAAMA,KAAS,kBAHD,0BAGqB,EA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,aACxC,kDACF,CACF,CAAC,EAED,GAAG,qEAAsE,IAAM,CAE7E,MAAMA,EAAQ,CACZ,OAAQ,EACR,EAAG,IACH,EAAG,OACH,EAAG,GACL,EAEC,WAAmB,KAAO,GAAG,GAAG,EAGjC,OAAO,OAAM,wBAAqBA,CAAK,CAAC,EAAE,aACxC,qCACF,CACF,CAAC,CACH,CAAC",
6
+ "names": ["import_Base64String", "result", "originalBtoa", "originalBuffer", "input", "bytes", "text", "c", "expectedBase64", "bufferFromSpy"]
7
7
  }
@@ -64,5 +64,5 @@
64
64
  "watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
65
65
  "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
66
66
  },
67
- "version": "1.1.0"
67
+ "version": "1.2.0"
68
68
  }
@@ -1,2 +1,2 @@
1
- import{Apdu as i}from"../../apdu/model/Apdu";import{ByteArrayBuilder as n}from"./ByteArrayBuilder";const p=5,r=255,l=r+5;class A{_ins;_cla;_p1;p2;data=new n(r);constructor({ins:t,cla:a,p1:e,p2:d}){this._cla=a&255,this._ins=t&255,this._p1=e&255,this.p2=d&255}build=()=>new i(this._cla,this._ins,this._p1,this.p2,this.data.build());add8BitUIntToData=t=>(this.data.add8BitUIntToData(t),this);add16BitUIntToData=t=>(this.data.add16BitUIntToData(t),this);add32BitUIntToData=t=>(this.data.add32BitUIntToData(t),this);addBufferToData=t=>(this.data.addBufferToData(t),this);addHexaStringToData=t=>(this.data.addHexaStringToData(t),this);addAsciiStringToData=t=>(this.data.addAsciiStringToData(t),this);encodeInLVFromHexa=t=>(this.data.encodeInLVFromHexa(t),this);encodeInLVFromBuffer=t=>(this.data.encodeInLVFromBuffer(t),this);encodeInLVFromAscii=t=>(this.data.encodeInLVFromAscii(t),this);getAvailablePayloadLength=()=>this.data.getAvailablePayloadLength();getErrors=()=>this.data.getErrors()}export{r as APDU_MAX_PAYLOAD,l as APDU_MAX_SIZE,A as ApduBuilder,p as HEADER_LENGTH};
1
+ import{Apdu as i}from"../../apdu/model/Apdu";import{ByteArrayBuilder as n}from"./ByteArrayBuilder";const p=5,a=255,l=a+5;class A{_ins;_cla;_p1;p2;data=new n(a);constructor({ins:t,cla:r,p1:e,p2:d}){this._cla=r&255,this._ins=t&255,this._p1=e&255,this.p2=d&255}build=()=>new i(this._cla,this._ins,this._p1,this.p2,this.data.build());add8BitUIntToData=t=>(this.data.add8BitUIntToData(t),this);add16BitUIntToData=t=>(this.data.add16BitUIntToData(t),this);add32BitUIntToData=t=>(this.data.add32BitUIntToData(t),this);add64BitUIntToData=(t,r=!0)=>(this.data.add64BitUIntToData(t,r),this);addBufferToData=t=>(this.data.addBufferToData(t),this);addHexaStringToData=t=>(this.data.addHexaStringToData(t),this);addAsciiStringToData=t=>(this.data.addAsciiStringToData(t),this);encodeInLVFromHexa=t=>(this.data.encodeInLVFromHexa(t),this);encodeInLVFromBuffer=t=>(this.data.encodeInLVFromBuffer(t),this);encodeInLVFromAscii=t=>(this.data.encodeInLVFromAscii(t),this);getAvailablePayloadLength=()=>this.data.getAvailablePayloadLength();getErrors=()=>this.data.getErrors()}export{a as APDU_MAX_PAYLOAD,l as APDU_MAX_SIZE,A as ApduBuilder,p as HEADER_LENGTH};
2
2
  //# sourceMappingURL=ApduBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/apdu/utils/ApduBuilder.ts"],
4
- "sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field if it has enough remaining space\n * and it can be formatted as a hexadecimal string\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\n return this;\n };\n\n /**\n * Add an ascii string to the data field if it has enough remaining space\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded buffer to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded ascii string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,MAAY,uBAGrB,OAAS,oBAAAC,MAAwB,qBAE1B,MAAMC,EAAgB,EAChBC,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAIJ,EAAiBE,CAAgB,EAEtE,YAAY,CAAE,IAAAG,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAIT,EAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBU,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,gBAAmBA,IACjB,KAAK,KAAK,gBAAgBA,CAAK,EACxB,MAST,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAQT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAUT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAOT,0BAA4B,IAC1B,KAAK,KAAK,0BAA0B,EAMtC,UAAY,IAAyB,KAAK,KAAK,UAAU,CAC3D",
6
- "names": ["Apdu", "ByteArrayBuilder", "HEADER_LENGTH", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "ins", "cla", "p1", "p2", "value"]
4
+ "sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 64-bit unsigned integer to the data field in big-endian (max value 0xffffffffffffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True for big-endian (default), false for little-endian\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add64BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ApduBuilder => {\n this.data.add64BitUIntToData(value, bigEndian);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field if it has enough remaining space\n * and it can be formatted as a hexadecimal string\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\n return this;\n };\n\n /**\n * Add an ascii string to the data field if it has enough remaining space\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded buffer to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded ascii string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,MAAY,uBAGrB,OAAS,oBAAAC,MAAwB,qBAE1B,MAAMC,EAAgB,EAChBC,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAIJ,EAAiBE,CAAgB,EAEtE,YAAY,CAAE,IAAAG,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAIT,EAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBU,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAST,mBAAqB,CACnBA,EACAC,EAAqB,MAErB,KAAK,KAAK,mBAAmBD,EAAOC,CAAS,EACtC,MAQT,gBAAmBD,IACjB,KAAK,KAAK,gBAAgBA,CAAK,EACxB,MAST,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAQT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAUT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAOT,0BAA4B,IAC1B,KAAK,KAAK,0BAA0B,EAMtC,UAAY,IAAyB,KAAK,KAAK,UAAU,CAC3D",
6
+ "names": ["Apdu", "ByteArrayBuilder", "HEADER_LENGTH", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "ins", "cla", "p1", "p2", "value", "bigEndian"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as o,Right as a}from"purify-ts";import{assign as i,createMachine as r}from"xstate";import{UserInteractionRequired as p}from"../../device-action/model/UserInteractionRequired";import{UnknownDAError as c}from"../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as m}from"../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{GetDeviceStatusDeviceAction as s}from"../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{GoToDashboardDeviceAction as d}from"../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{InstallOrUpdateAppsDeviceAction as l}from"../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction";import{ListAppsDeviceAction as u}from"../../device-action/os/ListApps/ListAppsDeviceAction";import{OpenAppDeviceAction as f}from"../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{ListInstalledAppsDeviceAction as A}from"../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction";const V=(e,t=!1)=>{u.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockListAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.AllowListApps})})},done:{type:"final"}},output:()=>t?o(new c("ListApps failed")):a(e)}))}))},L=(e,t=!1)=>{m.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGetDeviceMetadataDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None})})},done:{type:"final"}},output:()=>t?o(new c("GetDeviceMetadata failed")):a(e)}))}))},q=(e,t,n=!1)=>{l.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockInstallOrUpdateAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>t})},done:{type:"final"}},output:()=>n?o(new c("InstallOrUpdateApps failed")):a(e)}))}))},w=(e=!1)=>{f.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({initial:"ready",states:{ready:{entry:i({intermediateValue:{requiredUserInteraction:p.ConfirmOpenApp}}),after:{0:"done"}},done:{type:"final"}},output:()=>e?o(new c("OpenApp failed")):a(void 0)}))}))},x=(e=!1)=>{d.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGoToDashboardDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None})})},done:{type:"final"}},output:()=>e?o(new c("GoToDashboard failed")):a(void 0)}))}))},b=(e=[{currentApp:"BOLOS",currentAppVersion:"1.0.0"}])=>{const t=vi.fn();for(const n of e)t.mockImplementationOnce(()=>"currentApp"in n?a(n):o(n));s.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGetDeviceStatusDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None})})},done:{type:"final"}},output:t}))}))},T=(e=[])=>{A.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockListInstalledAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None})})},done:{type:"final"}},output:e.reduce((t,n)=>t.mockImplementationOnce(()=>"installedApps"in n?a(n):o(n)),vi.fn()).mockImplementation(()=>a([]))}))}))};export{L as setupGetDeviceMetadataMock,b as setupGetDeviceStatusMock,x as setupGoToDashboardMock,q as setupInstallOrUpdateAppsMock,V as setupListAppsMock,T as setupListInstalledAppsMock,w as setupOpenAppMock};
1
+ import{Left as o,Right as n}from"purify-ts";import{assign as i,createMachine as r}from"xstate";import{UserInteractionRequired as p}from"../../device-action/model/UserInteractionRequired";import{UnknownDAError as m}from"../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as s}from"../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{getDeviceMetadataDAStateStep as c}from"../../device-action/os/GetDeviceMetadata/types";import{GetDeviceStatusDeviceAction as d}from"../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{getDeviceStatusDAStateStep as l}from"../../device-action/os/GetDeviceStatus/types";import{GoToDashboardDeviceAction as A}from"../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{goToDashboardDAStateStep as u}from"../../device-action/os/GoToDashboard/types";import{InstallOrUpdateAppsDeviceAction as f}from"../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction";import{ListAppsDeviceAction as k}from"../../device-action/os/ListApps/ListAppsDeviceAction";import{listAppsDAStateStep as D}from"../../device-action/os/ListApps/types";import{OpenAppDeviceAction as I}from"../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{openAppDAStateStep as y}from"../../device-action/os/OpenAppDeviceAction/types";import{ListInstalledAppsDeviceAction as M}from"../../secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction";const x=(e,t=!1)=>{k.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockListAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.AllowListApps,step:D.LIST_APPS})})},done:{type:"final"}},output:()=>t?o(new m("ListApps failed")):n(e)}))}))},P=(e,t=!1)=>{s.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGetDeviceMetadataDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None,step:c.GET_DEVICE_METADATA})})},done:{type:"final"}},output:()=>t?o(new m("GetDeviceMetadata failed")):n(e)}))}))},N=(e,t,a=!1)=>{f.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockInstallOrUpdateAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>t})},done:{type:"final"}},output:()=>a?o(new m("InstallOrUpdateApps failed")):n(e)}))}))},B=(e=!1)=>{I.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({initial:"ready",states:{ready:{entry:i({intermediateValue:{requiredUserInteraction:p.ConfirmOpenApp,step:y.GET_DEVICE_STATUS}}),after:{0:"done"}},done:{type:"final"}},output:()=>e?o(new m("OpenApp failed")):n(void 0)}))}))},R=(e=!1)=>{A.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGoToDashboardDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None,step:u.GET_DEVICE_STATUS})})},done:{type:"final"}},output:()=>e?o(new m("GoToDashboard failed")):n(void 0)}))}))},F=(e=[{currentApp:"BOLOS",currentAppVersion:"1.0.0"}])=>{const t=vi.fn();for(const a of e)t.mockImplementationOnce(()=>"currentApp"in a?n(a):o(a));d.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockGetDeviceStatusDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None,step:l.ONBOARD_CHECK})})},done:{type:"final"}},output:t}))}))},H=(e=[])=>{M.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>r({id:"MockListInstalledAppsDeviceAction",initial:"ready",states:{ready:{after:{0:"done"},entry:i({intermediateValue:()=>({requiredUserInteraction:p.None})})},done:{type:"final"}},output:e.reduce((t,a)=>t.mockImplementationOnce(()=>"installedApps"in a?n(a):o(a)),vi.fn()).mockImplementation(()=>n([]))}))}))};export{P as setupGetDeviceMetadataMock,F as setupGetDeviceStatusMock,R as setupGoToDashboardMock,N as setupInstallOrUpdateAppsMock,x as setupListAppsMock,H as setupListInstalledAppsMock,B as setupOpenAppMock};
2
2
  //# sourceMappingURL=setupTestMachine.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/device-action/__test-utils__/setupTestMachine.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport { type GetDeviceMetadataDAOutput } from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport {\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type DmkError } from \"@api/Error\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\n\nimport { type BTC_APP } from \"./data\";\n\ntype App = typeof BTC_APP;\n\nexport const setupListAppsMock = (apps: App[], error = false) => {\n (ListAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"ListApps failed\"))\n : Right(apps);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceMetadataMock = (\n metadata: GetDeviceMetadataDAOutput,\n error = false,\n) => {\n (GetDeviceMetadataDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceMetadataDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GetDeviceMetadata failed\"))\n : Right(metadata);\n },\n }),\n ),\n }));\n};\n\nexport const setupInstallOrUpdateAppsMock = (\n result: InstallOrUpdateAppsDAOutput,\n intermediateValue: InstallOrUpdateAppsDAIntermediateValue,\n error = false,\n) => {\n (InstallOrUpdateAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockInstallOrUpdateAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => intermediateValue,\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"InstallOrUpdateApps failed\"))\n : Right(result);\n },\n }),\n ),\n }));\n};\n\nexport const setupOpenAppMock = (error: boolean = false) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"ready\",\n states: {\n ready: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"OpenApp failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGoToDashboardMock = (error: boolean = false) => {\n (GoToDashboardDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGoToDashboardDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GoToDashboard failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceStatusMock = (\n outputs: ReadonlyArray<\n { currentApp: string; currentAppVersion: string } | DmkError\n > = [\n {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n ],\n) => {\n const outputFn = vi.fn();\n\n for (const output of outputs) {\n outputFn.mockImplementationOnce(() =>\n \"currentApp\" in output ? Right(output) : Left(output),\n );\n }\n (GetDeviceStatusDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceStatusDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputFn,\n }),\n ),\n }));\n};\n\nexport const setupListInstalledAppsMock = (\n outputs: Array<{ installedApps: InstalledApp[] } | DmkError> = [],\n) => {\n (ListInstalledAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListInstalledAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputs\n .reduce(\n (mockFn, output) =>\n mockFn.mockImplementationOnce(() =>\n \"installedApps\" in output ? Right(output) : Left(output),\n ),\n vi.fn(),\n )\n .mockImplementation(() => Right([])),\n }),\n ),\n }));\n};\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAEtC,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,iCAAAC,MAAqC,wEAE9C,OAAS,+BAAAC,MAAmC,oEAC5C,OAAS,6BAAAC,MAAiC,gEAC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O,CAC9D,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,IAC3CJ,EAAc,CACZ,GAAI,kCACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,MAAOD,EAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyBE,EAAwB,IACnD,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQqB,CACV,CAAC,CACH,CACF,EAAE,CACJ,EAEaE,EAA6B,CACxCH,EAA+D,CAAC,IAC7D,CACFZ,EAAuC,mBAAmB,KAAO,CAChE,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,IAC3CT,EAAc,CACZ,GAAI,oCACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,MAAOD,EAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyBE,EAAwB,IACnD,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQoB,EACL,OACC,CAACI,EAAQF,IACPE,EAAO,uBAAuB,IAC5B,kBAAmBF,EAASzB,EAAMyB,CAAM,EAAI1B,EAAK0B,CAAM,CACzD,EACF,GAAG,GAAG,CACR,EACC,mBAAmB,IAAMzB,EAAM,CAAC,CAAC,CAAC,CACvC,CAAC,CACH,CACF,EAAE,CACJ",
6
- "names": ["Left", "Right", "assign", "createMachine", "UserInteractionRequired", "UnknownDAError", "GetDeviceMetadataDeviceAction", "GetDeviceStatusDeviceAction", "GoToDashboardDeviceAction", "InstallOrUpdateAppsDeviceAction", "ListAppsDeviceAction", "OpenAppDeviceAction", "ListInstalledAppsDeviceAction", "setupListAppsMock", "apps", "error", "setupGetDeviceMetadataMock", "metadata", "setupInstallOrUpdateAppsMock", "result", "intermediateValue", "setupOpenAppMock", "setupGoToDashboardMock", "setupGetDeviceStatusMock", "outputs", "outputFn", "output", "setupListInstalledAppsMock", "mockFn"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport {\n type GetDeviceMetadataDAOutput,\n getDeviceMetadataDAStateStep,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { getDeviceStatusDAStateStep } from \"@api/device-action/os/GetDeviceStatus/types\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { goToDashboardDAStateStep } from \"@api/device-action/os/GoToDashboard/types\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport {\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { listAppsDAStateStep } from \"@api/device-action/os/ListApps/types\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { openAppDAStateStep } from \"@api/device-action/os/OpenAppDeviceAction/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { ListInstalledAppsDeviceAction } from \"@api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction\";\nimport { type InstalledApp } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\n\nimport { type BTC_APP } from \"./data\";\n\ntype App = typeof BTC_APP;\n\nexport const setupListAppsMock = (apps: App[], error = false) => {\n (ListAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"ListApps failed\"))\n : Right(apps);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceMetadataMock = (\n metadata: GetDeviceMetadataDAOutput,\n error = false,\n) => {\n (GetDeviceMetadataDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceMetadataDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceMetadataDAStateStep.GET_DEVICE_METADATA,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GetDeviceMetadata failed\"))\n : Right(metadata);\n },\n }),\n ),\n }));\n};\n\nexport const setupInstallOrUpdateAppsMock = (\n result: InstallOrUpdateAppsDAOutput,\n intermediateValue: InstallOrUpdateAppsDAIntermediateValue,\n error = false,\n) => {\n (InstallOrUpdateAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockInstallOrUpdateAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => intermediateValue,\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"InstallOrUpdateApps failed\"))\n : Right(result);\n },\n }),\n ),\n }));\n};\n\nexport const setupOpenAppMock = (error: boolean = false) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"ready\",\n states: {\n ready: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"OpenApp failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGoToDashboardMock = (error: boolean = false) => {\n (GoToDashboardDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGoToDashboardDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: goToDashboardDAStateStep.GET_DEVICE_STATUS,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: () => {\n return error\n ? Left(new UnknownDAError(\"GoToDashboard failed\"))\n : Right(undefined);\n },\n }),\n ),\n }));\n};\n\nexport const setupGetDeviceStatusMock = (\n outputs: ReadonlyArray<\n { currentApp: string; currentAppVersion: string } | DmkError\n > = [\n {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n ],\n) => {\n const outputFn = vi.fn();\n\n for (const output of outputs) {\n outputFn.mockImplementationOnce(() =>\n \"currentApp\" in output ? Right(output) : Left(output),\n );\n }\n (GetDeviceStatusDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockGetDeviceStatusDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputFn,\n }),\n ),\n }));\n};\n\nexport const setupListInstalledAppsMock = (\n outputs: Array<{ installedApps: InstalledApp[] } | DmkError> = [],\n) => {\n (ListInstalledAppsDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n id: \"MockListInstalledAppsDeviceAction\",\n initial: \"ready\",\n states: {\n ready: {\n after: {\n 0: \"done\",\n },\n entry: assign({\n intermediateValue: () => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n },\n done: {\n type: \"final\",\n },\n },\n output: outputs\n .reduce(\n (mockFn, output) =>\n mockFn.mockImplementationOnce(() =>\n \"installedApps\" in output ? Right(output) : Left(output),\n ),\n vi.fn(),\n )\n .mockImplementation(() => Right([])),\n }),\n ),\n }));\n};\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,iBAAAC,MAAqB,SAEtC,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,iCAAAC,MAAqC,wEAC9C,OAEE,gCAAAC,MACK,gDACP,OAAS,+BAAAC,MAAmC,oEAC5C,OAAS,8BAAAC,MAAkC,8CAC3C,OAAS,6BAAAC,MAAiC,gEAC1C,OAAS,4BAAAC,MAAgC,4CACzC,OAAS,mCAAAC,MAAuC,4EAKhD,OAAS,wBAAAC,MAA4B,sDACrC,OAAS,uBAAAC,MAA2B,uCACpC,OAAS,uBAAAC,MAA2B,gEACpC,OAAS,sBAAAC,MAA0B,kDAEnC,OAAS,iCAAAC,MAAqC,oFAOvC,MAAMC,EAAoB,CAACC,EAAaC,EAAQ,KAAU,CAC9DP,EAA8B,mBAAmB,KAAO,CACvD,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,IAC3CV,EAAc,CACZ,GAAI,2BACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,MAAOD,EAAO,CACZ,kBAAmB,K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OACR,CACF,EACA,OAAQqB,CACV,CAAC,CACH,CACF,EAAE,CACJ,EAEaE,EAA6B,CACxCH,EAA+D,CAAC,IAC7D,CACFZ,EAAuC,mBAAmB,KAAO,CAChE,iBAAkB,GAAG,GAAG,EAAE,mBAAmB,IAC3Cd,EAAc,CACZ,GAAI,oCACJ,QAAS,QACT,OAAQ,CACN,MAAO,CACL,MAAO,CACL,EAAG,MACL,EACA,MAAOD,EAAO,CACZ,kBAAmB,KAAO,CACxB,wBAAyBE,EAAwB,IACnD,EACF,CAAC,CACH,EACA,KAAM,CACJ,KAAM,OACR,CACF,EACA,OAAQyB,EACL,OACC,CAACI,EAAQF,IACPE,EAAO,uBAAuB,IAC5B,kBAAmBF,EAAS9B,EAAM8B,CAAM,EAAI/B,EAAK+B,CAAM,CACzD,EACF,GAAG,GAAG,CACR,EACC,mBAAmB,IAAM9B,EAAM,CAAC,CAAC,CAAC,CACvC,CAAC,CACH,CACF,EAAE,CACJ",
6
+ "names": ["Left", "Right", "assign", "createMachine", "UserInteractionRequired", "UnknownDAError", "GetDeviceMetadataDeviceAction", "getDeviceMetadataDAStateStep", "GetDeviceStatusDeviceAction", "getDeviceStatusDAStateStep", "GoToDashboardDeviceAction", "goToDashboardDAStateStep", "InstallOrUpdateAppsDeviceAction", "ListAppsDeviceAction", "listAppsDAStateStep", "OpenAppDeviceAction", "openAppDAStateStep", "ListInstalledAppsDeviceAction", "setupListAppsMock", "apps", "error", "setupGetDeviceMetadataMock", "metadata", "setupInstallOrUpdateAppsMock", "result", "intermediateValue", "setupOpenAppMock", "setupGoToDashboardMock", "setupGetDeviceStatusMock", "outputs", "outputFn", "output", "setupListInstalledAppsMock", "mockFn"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as p,Right as o}from"purify-ts";import{assign as t,fromPromise as i,setup as l}from"xstate";import{isSuccessCommandResult as c}from"../../../command/model/CommandResult";import{UserInteractionRequired as s}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as u}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as k}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{XStateDeviceAction as A}from"../../../device-action/xstate-utils/XStateDeviceAction";class R extends A{makeStateMachine(a){const{callTask:r}=this.extractDependencies(a);return l({types:{input:{},context:{},output:{}},actors:{callTask:i(r),openAppStateMachine:new k({input:{appName:this.input.appName}}).makeStateMachine(a)},guards:{skipOpenApp:()=>this.input.skipOpenApp,noInternalError:({context:e})=>e._internalState.error===null},actions:{assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"CallTaskInAppDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:s.None},_internalState:{taskResponse:null,error:null}}),states:{InitialState:{always:[{target:"CallTask",guard:"skipOpenApp"},"OpenAppDeviceAction"]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",input:{appName:this.input.appName},src:"openAppStateMachine",onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{actions:t({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:n=>({...e.context._internalState,error:n})})}),target:"CheckOpenAppDeviceActionResult"}}},CheckOpenAppDeviceActionResult:{always:[{target:"CallTask",guard:"noInternalError"},"Error"]},CallTask:{entry:t({intermediateValue:{requiredUserInteraction:this.input.requiredUserInteraction}}),exit:t({intermediateValue:{requiredUserInteraction:s.None}}),invoke:{id:"callTask",src:"callTask",input:e=>e.context.input.task,onDone:{target:"CallTaskResultCheck",actions:[t({_internalState:({event:e,context:n})=>c(e.output)?{...n._internalState,taskResponse:e.output.data}:{...n._internalState,error:e.output.error}})]},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CallTaskResultCheck:{always:[{target:"Success",guard:"noInternalError"},"Error"]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>e._internalState.taskResponse?o(e._internalState.taskResponse):p(e._internalState.error||new u("No error in final state"))})}extractDependencies(a){return{callTask:r=>r.input(a)}}}export{R as CallTaskInAppDeviceAction};
1
+ import{Left as o,Right as i}from"purify-ts";import{assign as t,fromPromise as l,setup as c}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{UserInteractionRequired as p}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as k}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as A}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{XStateDeviceAction as T}from"../../../device-action/xstate-utils/XStateDeviceAction";import{callTaskInAppDAStateStep as s}from"./CallTaskInAppDeviceActionTypes";class h extends T{makeStateMachine(a){const{callTask:r}=this.extractDependencies(a);return c({types:{input:{},context:{},output:{}},actors:{callTask:l(r),openAppStateMachine:new A({input:{appName:this.input.appName}}).makeStateMachine(a)},guards:{skipOpenApp:()=>this.input.skipOpenApp,noInternalError:({context:e})=>e._internalState.error===null},actions:{assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"CallTaskInAppDeviceAction",initial:"InitialState",context:({input:e})=>({input:e,intermediateValue:{requiredUserInteraction:p.None,step:s.OPEN_APP},_internalState:{taskResponse:null,error:null}}),states:{InitialState:{always:[{target:"CallTask",guard:"skipOpenApp"},"OpenAppDeviceAction"]},OpenAppDeviceAction:{invoke:{id:"openAppStateMachine",input:{appName:this.input.appName},src:"openAppStateMachine",onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{actions:t({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:n=>({...e.context._internalState,error:n})})}),target:"CheckOpenAppDeviceActionResult"}}},CheckOpenAppDeviceActionResult:{always:[{target:"CallTask",guard:"noInternalError"},"Error"]},CallTask:{entry:t({intermediateValue:{requiredUserInteraction:this.input.requiredUserInteraction,step:s.CALL_TASK}}),exit:t({intermediateValue:{requiredUserInteraction:p.None,step:s.CALL_TASK}}),invoke:{id:"callTask",src:"callTask",input:e=>e.context.input.task,onDone:{target:"CallTaskResultCheck",actions:[t({_internalState:({event:e,context:n})=>u(e.output)?{...n._internalState,taskResponse:e.output.data}:{...n._internalState,error:e.output.error}})]},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CallTaskResultCheck:{always:[{target:"Success",guard:"noInternalError"},"Error"]},Success:{type:"final"},Error:{type:"final"}},output:({context:e})=>e._internalState.taskResponse?i(e._internalState.taskResponse):o(e._internalState.error||new k("No error in final state"))})}extractDependencies(a){return{callTask:r=>r.input(a)}}}export{h as CallTaskInAppDeviceAction};
2
2
  //# sourceMappingURL=CallTaskInAppDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type CommandResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\n\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAInput,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAInternalState,\n type CallTaskInAppDAOutput,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\n/**\n * Tries to open an app on the device, and if it is successful, calls a task\n * in the app.\n * The output will be the result of the task.\n *\n * ```ts\n * input: {\n * appName: string;\n * task: (internalApi: InternalApi) => Promise<CommandResult<TaskResponse, TaskErrorCodes>>;\n * requiredUserInteraction: UserInteraction;\n * }\n * ```\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new CallTaskInAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * task: async (internalApi: InternalApi) => internalApi.sendCommand(new MyAppSpecificCommand()),\n * requiredUserInteraction: UserInteractionRequired.None,\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class CallTaskInAppDeviceAction<\n TaskResponse,\n TaskErrorCodes,\n UserInteraction extends UserInteractionRequired,\n> extends XStateDeviceAction<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n> {\n makeStateMachine(\n internalAPI: InternalApi,\n ): DeviceActionStateMachine<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n > {\n type types = StateMachineTypes<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n >;\n\n const { callTask } = this.extractDependencies(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 callTask: fromPromise(callTask),\n openAppStateMachine: new OpenAppDeviceAction({\n input: {\n appName: this.input.appName,\n },\n }).makeStateMachine(internalAPI),\n },\n guards: {\n skipOpenApp: () => this.input.skipOpenApp,\n noInternalError: ({ context }) => context._internalState.error === null,\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 },\n }).createMachine({\n id: \"CallTaskInAppDeviceAction\",\n initial: \"InitialState\",\n context: ({ input }) => {\n return {\n input: input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n taskResponse: null,\n error: null,\n },\n };\n },\n states: {\n InitialState: {\n always: [\n {\n target: \"CallTask\",\n guard: \"skipOpenApp\",\n },\n \"OpenAppDeviceAction\",\n ],\n },\n OpenAppDeviceAction: {\n invoke: {\n id: \"openAppStateMachine\",\n input: {\n appName: this.input.appName,\n },\n src: \"openAppStateMachine\",\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n >({\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n });\n },\n }),\n target: \"CheckOpenAppDeviceActionResult\",\n },\n },\n },\n CheckOpenAppDeviceActionResult: {\n always: [\n {\n target: \"CallTask\",\n guard: \"noInternalError\",\n },\n \"Error\",\n ],\n },\n CallTask: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: this.input.requiredUserInteraction,\n },\n }),\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"callTask\",\n src: \"callTask\",\n input: (_: { context: types[\"context\"] }) => _.context.input.task,\n onDone: {\n target: \"CallTaskResultCheck\",\n actions: [\n assign({\n _internalState: ({ event, context }) => {\n if (isSuccessCommandResult(event.output)) {\n return {\n ...context._internalState,\n taskResponse: event.output.data,\n };\n }\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 CallTaskResultCheck: {\n always: [\n {\n target: \"Success\",\n guard: \"noInternalError\",\n },\n \"Error\",\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.taskResponse\n ? Right(context._internalState.taskResponse)\n : Left(\n context._internalState.error ||\n new UnknownDAError(\"No error in final state\"),\n ),\n });\n }\n\n extractDependencies(internalApi: InternalApi) {\n return {\n callTask: (_: {\n input: (\n internalApi: InternalApi,\n ) => Promise<CommandResult<TaskResponse, TaskErrorCodes>>;\n }): Promise<CommandResult<TaskResponse, TaskErrorCodes>> =>\n _.input(internalApi),\n };\n }\n}\n"],
5
- "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAEE,0BAAAC,MACK,mCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,uBAAAC,MAA2B,gEAEpC,OAEE,sBAAAC,MACK,qDAoCA,MAAMC,UAIHD,CAMR,CACA,iBACEE,EAOA,CASA,KAAM,CAAE,SAAAC,CAAS,EAAI,KAAK,oBAAoBD,CAAW,EAEzD,OAAOP,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAAUD,EAAYS,CAAQ,EAC9B,oBAAqB,IAAIJ,EAAoB,CAC3C,MAAO,CACL,QAAS,KAAK,MAAM,OACtB,CACF,CAAC,EAAE,iBAAiBG,CAAW,CACjC,EACA,OAAQ,CACN,YAAa,IAAM,KAAK,MAAM,YAC9B,gBAAiB,CAAC,CAAE,QAAAE,CAAQ,IAAMA,EAAQ,eAAe,QAAU,IACrE,EACA,QAAS,CACP,qBAAsBX,EAAO,CAC3B,eAAiBY,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,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AAGJ,EAAQ,eACX,MAAOI,EAAM,OAAO,KACtB,CAEJ,CAAC,CACH,CACF,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,oBAAqB,CACnB,OAAQ,CACN,CACE,OAAQ,UACR,MAAO,iBACT,EACA,OACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAAQ,CAAC,CAAE,QAAAJ,CAAQ,IACjBA,EAAQ,eAAe,aACnBZ,EAAMY,EAAQ,eAAe,YAAY,EACzCb,EACEa,EAAQ,eAAe,OACrB,IAAIN,EAAe,yBAAyB,CAChD,CACR,CAAC,CACH,CAEA,oBAAoBW,EAA0B,CAC5C,MAAO,CACL,SAAWJ,GAKTA,EAAE,MAAMI,CAAW,CACvB,CACF,CACF",
6
- "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "XStateDeviceAction", "CallTaskInAppDeviceAction", "internalAPI", "callTask", "context", "_", "input", "error", "event", "internalApi"]
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport {\n type CommandResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\n\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAInput,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAInternalState,\n type CallTaskInAppDAOutput,\n callTaskInAppDAStateStep,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\n/**\n * Tries to open an app on the device, and if it is successful, calls a task\n * in the app.\n * The output will be the result of the task.\n *\n * ```ts\n * input: {\n * appName: string;\n * task: (internalApi: InternalApi) => Promise<CommandResult<TaskResponse, TaskErrorCodes>>;\n * requiredUserInteraction: UserInteraction;\n * }\n * ```\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new CallTaskInAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * task: async (internalApi: InternalApi) => internalApi.sendCommand(new MyAppSpecificCommand()),\n * requiredUserInteraction: UserInteractionRequired.None,\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class CallTaskInAppDeviceAction<\n TaskResponse,\n TaskErrorCodes,\n UserInteraction extends UserInteractionRequired,\n> extends XStateDeviceAction<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n> {\n makeStateMachine(\n internalAPI: InternalApi,\n ): DeviceActionStateMachine<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n > {\n type types = StateMachineTypes<\n CallTaskInAppDAOutput<TaskResponse>,\n CallTaskInAppDAInput<TaskResponse, TaskErrorCodes, UserInteraction>,\n CallTaskInAppDAError<TaskErrorCodes>,\n CallTaskInAppDAIntermediateValue<UserInteraction>,\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n >;\n\n const { callTask } = this.extractDependencies(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 callTask: fromPromise(callTask),\n openAppStateMachine: new OpenAppDeviceAction({\n input: {\n appName: this.input.appName,\n },\n }).makeStateMachine(internalAPI),\n },\n guards: {\n skipOpenApp: () => this.input.skipOpenApp,\n noInternalError: ({ context }) => context._internalState.error === null,\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 },\n }).createMachine({\n id: \"CallTaskInAppDeviceAction\",\n initial: \"InitialState\",\n context: ({ input }) => {\n return {\n input: input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: callTaskInAppDAStateStep.OPEN_APP,\n },\n _internalState: {\n taskResponse: null,\n error: null,\n },\n };\n },\n states: {\n InitialState: {\n always: [\n {\n target: \"CallTask\",\n guard: \"skipOpenApp\",\n },\n \"OpenAppDeviceAction\",\n ],\n },\n OpenAppDeviceAction: {\n invoke: {\n id: \"openAppStateMachine\",\n input: {\n appName: this.input.appName,\n },\n src: \"openAppStateMachine\",\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<\n CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes>\n >({\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n });\n },\n }),\n target: \"CheckOpenAppDeviceActionResult\",\n },\n },\n },\n CheckOpenAppDeviceActionResult: {\n always: [\n {\n target: \"CallTask\",\n guard: \"noInternalError\",\n },\n \"Error\",\n ],\n },\n CallTask: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: this.input.requiredUserInteraction,\n step: callTaskInAppDAStateStep.CALL_TASK,\n },\n }),\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: callTaskInAppDAStateStep.CALL_TASK,\n },\n }),\n invoke: {\n id: \"callTask\",\n src: \"callTask\",\n input: (_: { context: types[\"context\"] }) => _.context.input.task,\n onDone: {\n target: \"CallTaskResultCheck\",\n actions: [\n assign({\n _internalState: ({ event, context }) => {\n if (isSuccessCommandResult(event.output)) {\n return {\n ...context._internalState,\n taskResponse: event.output.data,\n };\n }\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 CallTaskResultCheck: {\n always: [\n {\n target: \"Success\",\n guard: \"noInternalError\",\n },\n \"Error\",\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.taskResponse\n ? Right(context._internalState.taskResponse)\n : Left(\n context._internalState.error ||\n new UnknownDAError(\"No error in final state\"),\n ),\n });\n }\n\n extractDependencies(internalApi: InternalApi) {\n return {\n callTask: (_: {\n input: (\n internalApi: InternalApi,\n ) => Promise<CommandResult<TaskResponse, TaskErrorCodes>>;\n }): Promise<CommandResult<TaskResponse, TaskErrorCodes>> =>\n _.input(internalApi),\n };\n }\n}\n"],
5
+ "mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAEE,0BAAAC,MACK,mCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,uBAAAC,MAA2B,gEAEpC,OAEE,sBAAAC,MACK,qDAEP,OAME,4BAAAC,MACK,mCA4BA,MAAMC,UAIHF,CAMR,CACA,iBACEG,EAOA,CASA,KAAM,CAAE,SAAAC,CAAS,EAAI,KAAK,oBAAoBD,CAAW,EAEzD,OAAOR,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAAUD,E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C,CACF,CAAC,EACD,KAAMR,EAAO,CACX,kBAAmB,CACjB,wBAAyBI,EAAwB,KACjD,KAAMI,EAAyB,SACjC,CACF,CAAC,EACD,OAAQ,CACN,GAAI,WACJ,IAAK,WACL,MAAQK,GAAqCA,EAAE,QAAQ,MAAM,KAC7D,OAAQ,CACN,OAAQ,sBACR,QAAS,CACPb,EAAO,CACL,eAAgB,CAAC,CAAE,MAAAgB,EAAO,QAAAJ,CAAQ,IAC5BT,EAAuBa,EAAM,MAAM,EAC9B,CACL,GAAGJ,EAAQ,eACX,aAAcI,EAAM,OAAO,IAC7B,EAEK,CACL,GAAGJ,EAAQ,eACX,MAAOI,EAAM,OAAO,KACtB,CAEJ,CAAC,CACH,CACF,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,oBAAqB,CACnB,OAAQ,CACN,CACE,OAAQ,UACR,MAAO,iBACT,EACA,OACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAAQ,CAAC,CAAE,QAAAJ,CAAQ,IACjBA,EAAQ,eAAe,aACnBb,EAAMa,EAAQ,eAAe,YAAY,EACzCd,EACEc,EAAQ,eAAe,OACrB,IAAIP,EAAe,yBAAyB,CAChD,CACR,CAAC,CACH,CAEA,oBAAoBY,EAA0B,CAC5C,MAAO,CACL,SAAWJ,GAKTA,EAAE,MAAMI,CAAW,CACvB,CACF,CACF",
6
+ "names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "XStateDeviceAction", "callTaskInAppDAStateStep", "CallTaskInAppDeviceAction", "internalAPI", "callTask", "context", "_", "input", "error", "event", "internalApi"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{Left as D,Right as w}from"purify-ts";import{assign as I,createMachine as M}from"xstate";import{ApduBuilder as g}from"../../../apdu/utils/ApduBuilder";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{makeDeviceActionInternalApiMock as m}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as y}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as n}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as e}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as C}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as S}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{UnknownDeviceExchangeError as v}from"../../../../../src";import{CallTaskInAppDeviceAction as u}from"./CallTaskInAppDeviceAction";vi.mock("@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction",async r=>{const o=await r();return{...o,OpenAppDeviceAction:vi.fn(()=>({...o.OpenAppDeviceAction,makeStateMachine:vi.fn()}))}});const l=r=>{S.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>M({initial:"pending",states:{pending:{entry:I({intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}}),after:{0:"done"}},done:{type:"final"}},output:()=>r?D(r):w(void 0)}))}))};describe("CallTaskInAppDeviceAction",()=>{const r=vi.fn(),o=()=>({callTask:r}),{sendCommand:f}=m(),p={paramString:"aParameter",paramNumber:1234},k={aNumber:5678,aString:"mockedResponseString"};beforeEach(()=>{vi.resetAllMocks()}),describe("without mocking extractDependencies",()=>{it("should call sendCommand on internalApi with the correct parameters",async()=>{l(),f.mockResolvedValue(A({data:void 0}));const i=new u({input:{task:async a=>await a.sendCommand(new d(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});await new Promise((a,t)=>{i._execute(m()).observable.subscribe({error:()=>t(),complete:()=>a(),next:()=>{}})}),expect(f).toHaveBeenCalledWith(new d(p))})}),describe("error cases",()=>{it("should error and output the error if the open app fails",()=>new Promise((i,a)=>{l(new C("Mocked error"));const t=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Error,error:new C("Mocked error")}];y(new u({input:{task:async s=>await s.sendCommand(new d(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}}),t,m(),{onDone:i,onError:a})})),it("should error and output an error if the call task fails",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(A({error:new v("Mocked error")}));const t=new u({input:{task:async c=>await c.sendCommand(new d(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(o);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Error,error:new v("Mocked error")}];y(t,s,m(),{onDone:i,onError:a})}))}),describe("success cases",()=>{it("should succeed and output the command result if the send command succeeds",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(A({data:k}));const t=new u({input:{task:async c=>await c.sendCommand(new d(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(t,"extractDependencies").mockImplementation(o);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.None}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp}},{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:k}];y(t,s,m(),{onDone:i,onError:a})})),it("should succeed while skipping OpenApp",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(A({data:k}));const t=new u({input:{task:async c=>await c.sendCommand(new d(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!0}});vi.spyOn(t,"extractDependencies").mockImplementation(o);const s=[{status:n.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress}},{status:n.Completed,output:k}];y(t,s,m(),{onDone:i,onError:a})}))})});class d{name="testCommand";params;constructor(o){this.params=o}getApdu(){return new g({cla:0,ins:1,p1:2,p2:3}).add32BitUIntToData(this.params.paramNumber).addAsciiStringToData(this.params.paramString).build()}parseResponse(){return A({data:{aNumber:1,aString:"aString"}})}}
1
+ import{Left as S,Right as w}from"purify-ts";import{assign as T,createMachine as M}from"xstate";import{ApduBuilder as g}from"../../../apdu/utils/ApduBuilder";import{CommandResultFactory as k}from"../../../command/model/CommandResult";import{makeDeviceActionInternalApiMock as m}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as y}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as t}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as e}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as v}from"../../../device-action/os/Errors";import{OpenAppDeviceAction as P}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{openAppDAStateStep as f}from"../../../device-action/os/OpenAppDeviceAction/types";import{UnknownDeviceExchangeError as I}from"../../../../../src";import{CallTaskInAppDeviceAction as A}from"./CallTaskInAppDeviceAction";import{callTaskInAppDAStateStep as d}from"./CallTaskInAppDeviceActionTypes";vi.mock("@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction",async r=>{const o=await r();return{...o,OpenAppDeviceAction:vi.fn(()=>({...o.OpenAppDeviceAction,makeStateMachine:vi.fn()}))}});const l=r=>{P.mockImplementation(()=>({makeStateMachine:vi.fn().mockImplementation(()=>M({initial:"pending",states:{pending:{entry:T({intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp,step:f.GET_DEVICE_STATUS}}),after:{0:"done"}},done:{type:"final"}},output:()=>r?S(r):w(void 0)}))}))};describe("CallTaskInAppDeviceAction",()=>{const r=vi.fn(),o=()=>({callTask:r}),{sendCommand:D}=m(),p={paramString:"aParameter",paramNumber:1234},C={aNumber:5678,aString:"mockedResponseString"};beforeEach(()=>{vi.resetAllMocks()}),describe("without mocking extractDependencies",()=>{it("should call sendCommand on internalApi with the correct parameters",async()=>{l(),D.mockResolvedValue(k({data:void 0}));const i=new A({input:{task:async a=>await a.sendCommand(new c(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});await new Promise((a,n)=>{i._execute(m()).observable.subscribe({error:()=>n(),complete:()=>a(),next:()=>{}})}),expect(D).toHaveBeenCalledWith(new c(p))})}),describe("error cases",()=>{it("should error and output the error if the open app fails",()=>new Promise((i,a)=>{l(new v("Mocked error"));const n=[{status:t.Pending,intermediateValue:{requiredUserInteraction:e.None,step:d.OPEN_APP}},{status:t.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp,step:f.GET_DEVICE_STATUS}},{status:t.Error,error:new v("Mocked error")}];y(new A({input:{task:async s=>await s.sendCommand(new c(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}}),n,m(),{onDone:i,onError:a})})),it("should error and output an error if the call task fails",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(k({error:new I("Mocked error")}));const n=new A({input:{task:async u=>await u.sendCommand(new c(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(n,"extractDependencies").mockImplementation(o);const s=[{status:t.Pending,intermediateValue:{requiredUserInteraction:e.None,step:d.OPEN_APP}},{status:t.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp,step:f.GET_DEVICE_STATUS}},{status:t.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress,step:d.CALL_TASK}},{status:t.Error,error:new I("Mocked error")}];y(n,s,m(),{onDone:i,onError:a})}))}),describe("success cases",()=>{it("should succeed and output the command result if the send command succeeds",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(k({data:C}));const n=new A({input:{task:async u=>await u.sendCommand(new c(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!1}});vi.spyOn(n,"extractDependencies").mockImplementation(o);const s=[{status:t.Pending,intermediateValue:{requiredUserInteraction:e.None,step:d.OPEN_APP}},{status:t.Pending,intermediateValue:{requiredUserInteraction:e.ConfirmOpenApp,step:f.GET_DEVICE_STATUS}},{status:t.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress,step:d.CALL_TASK}},{status:t.Completed,output:C}];y(n,s,m(),{onDone:i,onError:a})})),it("should succeed while skipping OpenApp",()=>new Promise((i,a)=>{l(),r.mockResolvedValue(k({data:C}));const n=new A({input:{task:async u=>await u.sendCommand(new c(p)),appName:"MyApp",requiredUserInteraction:e.VerifyAddress,skipOpenApp:!0}});vi.spyOn(n,"extractDependencies").mockImplementation(o);const s=[{status:t.Pending,intermediateValue:{requiredUserInteraction:e.VerifyAddress,step:d.CALL_TASK}},{status:t.Completed,output:C}];y(n,s,m(),{onDone:i,onError:a})}))})});class c{name="testCommand";params;constructor(o){this.params=o}getApdu(){return new g({cla:0,ins:1,p1:2,p2:3}).add32BitUIntToData(this.params.paramNumber).addAsciiStringToData(this.params.paramString).build()}parseResponse(){return k({data:{aNumber:1,aString:"aString"}})}}
2
2
  //# sourceMappingURL=CallTaskInAppDeviceAction.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.ts"],
4
- "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { CallTaskInAppDeviceAction } from \"./CallTaskInAppDeviceAction\";\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAOutput,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n ...original.OpenAppDeviceAction,\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"CallTaskInAppDeviceAction\", () => {\n const callMyTask = vi.fn();\n\n const extractDependenciesMock = () => ({\n callTask: callMyTask,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the call task fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n readonly name = \"testCommand\";\n\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandCallTaskDAState = DeviceActionState<\n CallTaskInAppDAOutput<MyCommandResponse>,\n CallTaskInAppDAError<UnknownDAError>,\n CallTaskInAppDAIntermediateValue<\n UserInteractionRequired.None | UserInteractionRequired.VerifyAddress\n >\n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,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
6
- "names": ["Left", "Right", "assign", "createMachine", "ApduBuilder", "CommandResultFactory", "makeDeviceActionInternalApiMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "UnknownDeviceExchangeError", "CallTaskInAppDeviceAction", "importOriginal", "original", "setupOpenAppDAMock", "error", "callMyTask", "extractDependenciesMock", "apiSendCommandMock", "commandParams", "mockedCommandResponse", "deviceAction", "internalApi", "TestCommand", "resolve", "reject", "expectedStates", "params"]
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports:0 */\nimport { Left, Right } from \"purify-ts\";\nimport { type Mock } from \"vitest\";\nimport { assign, createMachine } from \"xstate\";\n\nimport { type Apdu } from \"@api/apdu/model/Apdu\";\nimport { ApduBuilder } from \"@api/apdu/utils/ApduBuilder\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport {\n type DeviceActionState,\n DeviceActionStatus,\n} from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { openAppDAStateStep } from \"@api/device-action/os/OpenAppDeviceAction/types\";\nimport { type Command } from \"@api/types\";\nimport { UnknownDeviceExchangeError } from \"@root/src\";\n\nimport { CallTaskInAppDeviceAction } from \"./CallTaskInAppDeviceAction\";\nimport {\n type CallTaskInAppDAError,\n type CallTaskInAppDAIntermediateValue,\n type CallTaskInAppDAOutput,\n callTaskInAppDAStateStep,\n} from \"./CallTaskInAppDeviceActionTypes\";\n\nvi.mock(\n \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\",\n async (importOriginal) => {\n const original =\n await importOriginal<\n typeof import(\"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\")\n >();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n ...original.OpenAppDeviceAction,\n makeStateMachine: vi.fn(),\n })),\n };\n },\n);\n\nconst setupOpenAppDAMock = (error?: unknown) => {\n (OpenAppDeviceAction as Mock).mockImplementation(() => ({\n makeStateMachine: vi.fn().mockImplementation(() =>\n createMachine({\n initial: \"pending\",\n states: {\n pending: {\n entry: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n }),\n after: {\n 0: \"done\",\n },\n },\n done: {\n type: \"final\",\n },\n },\n output: () => (error ? Left(error) : Right(undefined)),\n }),\n ),\n }));\n};\n\ndescribe(\"CallTaskInAppDeviceAction\", () => {\n const callMyTask = vi.fn();\n\n const extractDependenciesMock = () => ({\n callTask: callMyTask,\n });\n\n const { sendCommand: apiSendCommandMock } = makeDeviceActionInternalApiMock();\n\n const commandParams = {\n paramString: \"aParameter\",\n paramNumber: 1234,\n };\n const mockedCommandResponse = {\n aNumber: 5678,\n aString: \"mockedResponseString\",\n };\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"without mocking extractDependencies\", () => {\n it(\"should call sendCommand on internalApi with the correct parameters\", async () => {\n setupOpenAppDAMock();\n apiSendCommandMock.mockResolvedValue(\n CommandResultFactory({ data: undefined }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n await new Promise<void>((resolve, reject) => {\n deviceAction\n ._execute(makeDeviceActionInternalApiMock())\n .observable.subscribe({\n error: () => reject(),\n complete: () => resolve(),\n next: () => {},\n });\n });\n\n expect(apiSendCommandMock).toHaveBeenCalledWith(\n new TestCommand(commandParams),\n );\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should error and output the error if the open app fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock(new UnknownDAError(\"Mocked error\"));\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: callTaskInAppDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n }),\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error and output an error if the call task fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: callTaskInAppDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n step: callTaskInAppDAStateStep.CALL_TASK,\n },\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDeviceExchangeError(\"Mocked error\"),\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should succeed and output the command result if the send command succeeds\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: false,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: callTaskInAppDAStateStep.OPEN_APP,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n },\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n step: callTaskInAppDAStateStep.CALL_TASK,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should succeed while skipping OpenApp\", () =>\n new Promise<void>((resolve, reject) => {\n setupOpenAppDAMock();\n\n callMyTask.mockResolvedValue(\n CommandResultFactory({ data: mockedCommandResponse }),\n );\n\n const deviceAction = new CallTaskInAppDeviceAction({\n input: {\n task: async (internalApi) =>\n await internalApi.sendCommand(new TestCommand(commandParams)),\n appName: \"MyApp\",\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n skipOpenApp: true,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockImplementation(\n extractDependenciesMock,\n );\n\n const expectedStates: MyCommandCallTaskDAState[] = [\n {\n status: DeviceActionStatus.Pending,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.VerifyAddress,\n step: callTaskInAppDAStateStep.CALL_TASK,\n },\n },\n {\n status: DeviceActionStatus.Completed,\n output: mockedCommandResponse,\n },\n ];\n\n testDeviceActionStates(\n deviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n\ntype MyCommandResponse = {\n aNumber: number;\n aString: string;\n};\n\ntype MyCommandParams = {\n paramString: string;\n paramNumber: number;\n};\n\nclass TestCommand implements Command<MyCommandResponse, MyCommandParams> {\n readonly name = \"testCommand\";\n\n params: MyCommandParams;\n constructor(params: MyCommandParams) {\n this.params = params;\n }\n getApdu(): Apdu {\n return new ApduBuilder({ cla: 0x00, ins: 0x01, p1: 0x02, p2: 0x03 })\n .add32BitUIntToData(this.params.paramNumber)\n .addAsciiStringToData(this.params.paramString)\n .build();\n }\n parseResponse() {\n return CommandResultFactory({ data: { aNumber: 1, aString: \"aString\" } });\n }\n}\n\ntype MyCommandCallTaskDAState = DeviceActionState<\n CallTaskInAppDAOutput<MyCommandResponse>,\n CallTaskInAppDAError<UnknownDAError>,\n CallTaskInAppDAIntermedi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,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC,EAYD,MAAMF,CAAmE,CAC9D,KAAO,cAEhB,OACA,YAAYI,EAAyB,CACnC,KAAK,OAASA,CAChB,CACA,SAAgB,CACd,OAAO,IAAI3B,EAAY,CAAE,IAAK,EAAM,IAAK,EAAM,GAAI,EAAM,GAAI,CAAK,CAAC,EAChE,mBAAmB,KAAK,OAAO,WAAW,EAC1C,qBAAqB,KAAK,OAAO,WAAW,EAC5C,MAAM,CACX,CACA,eAAgB,CACd,OAAOC,EAAqB,CAAE,KAAM,CAAE,QAAS,EAAG,QAAS,SAAU,CAAE,CAAC,CAC1E,CACF",
6
+ "names": ["Left", "Right", "assign", "createMachine", "ApduBuilder", "CommandResultFactory", "makeDeviceActionInternalApiMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "OpenAppDeviceAction", "openAppDAStateStep", "UnknownDeviceExchangeError", "CallTaskInAppDeviceAction", "callTaskInAppDAStateStep", "importOriginal", "original", "setupOpenAppDAMock", "error", "callMyTask", "extractDependenciesMock", "apiSendCommandMock", "commandParams", "mockedCommandResponse", "deviceAction", "internalApi", "TestCommand", "resolve", "reject", "expectedStates", "params"]
7
7
  }
@@ -1 +1,2 @@
1
+ const e=Object.freeze({OPEN_APP:"os.callTaskInApp.steps.openApp",CALL_TASK:"os.callTaskInApp.steps.callTask"});export{e as callTaskInAppDAStateStep};
1
2
  //# sourceMappingURL=CallTaskInAppDeviceActionTypes.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": [],
4
- "sourcesContent": [],
5
- "mappings": "",
6
- "names": []
3
+ "sources": ["../../../../../../../src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.ts"],
4
+ "sourcesContent": ["import {\n type CommandErrorResult,\n type CommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n type OpenAppDAError,\n type OpenAppDAIntermediateValue,\n} from \"@api/device-action/os/OpenAppDeviceAction/types\";\n\nexport const callTaskInAppDAStateStep = Object.freeze({\n OPEN_APP: \"os.callTaskInApp.steps.openApp\",\n CALL_TASK: \"os.callTaskInApp.steps.callTask\",\n} as const);\n\nexport type CallTaskInAppDAStateStep =\n (typeof callTaskInAppDAStateStep)[keyof typeof callTaskInAppDAStateStep];\n\nexport type CallTaskInAppDAOutput<TaskResponse> = TaskResponse;\n\nexport type CallTaskInAppDAInput<\n TaskResponse,\n TaskErrorCodes,\n UserInteraction,\n> = {\n readonly task: (\n internalApi: InternalApi,\n ) => Promise<CommandResult<TaskResponse, TaskErrorCodes>>;\n readonly appName: string;\n readonly skipOpenApp: boolean;\n readonly requiredUserInteraction: UserInteraction;\n};\n\nexport type CallTaskInAppDAError<TaskErrorCodes = void> =\n | OpenAppDAError\n | CommandErrorResult<TaskErrorCodes>[\"error\"];\n\nexport type CallTaskInAppDARequiredInteraction = UserInteractionRequired.None;\n\nexport type CallTaskInAppDAIntermediateValue<UserInteraction> =\n | {\n readonly requiredUserInteraction:\n | UserInteraction\n | CallTaskInAppDARequiredInteraction;\n readonly step: CallTaskInAppDAStateStep;\n }\n | OpenAppDAIntermediateValue;\n\nexport type CallTaskInAppDAInternalState<TaskResponse, TaskErrorCodes> = {\n readonly taskResponse: TaskResponse | null;\n readonly error: CallTaskInAppDAError<TaskErrorCodes> | null;\n};\n"],
5
+ "mappings": "AAWO,MAAMA,EAA2B,OAAO,OAAO,CACpD,SAAU,iCACV,UAAW,iCACb,CAAU",
6
+ "names": ["callTaskInAppDAStateStep"]
7
7
  }