@ledgerhq/device-management-kit 0.11.1 → 0.12.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 (127) hide show
  1. package/lib/cjs/package.json +45 -40
  2. package/lib/cjs/src/api/device-action/os/Errors.js +1 -1
  3. package/lib/cjs/src/api/device-action/os/Errors.js.map +3 -3
  4. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  5. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  6. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
  7. package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
  8. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  9. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  10. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
  11. package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
  12. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  13. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  14. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
  15. package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
  16. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  17. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +2 -2
  18. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  19. package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +2 -2
  20. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  21. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  22. package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
  23. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  24. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  25. package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
  26. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  27. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  28. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
  29. package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  30. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  31. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  32. package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
  33. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  34. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  35. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  36. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  37. package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
  38. package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
  39. package/lib/cjs/src/api/secure-channel/utils.js +1 -1
  40. package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
  41. package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
  42. package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
  43. package/lib/cjs/src/internal/crypto/CryptoService.js +2 -0
  44. package/lib/cjs/src/internal/crypto/CryptoService.js.map +7 -0
  45. package/lib/cjs/src/internal/crypto/NobleCryptoService.js +2 -0
  46. package/lib/cjs/src/internal/crypto/NobleCryptoService.js.map +7 -0
  47. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js +2 -0
  48. package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  49. package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
  50. package/lib/esm/package.json +45 -40
  51. package/lib/esm/src/api/device-action/os/Errors.js +1 -1
  52. package/lib/esm/src/api/device-action/os/Errors.js.map +3 -3
  53. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
  54. package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
  55. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
  56. package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
  57. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
  58. package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
  59. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
  60. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +3 -3
  61. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
  62. package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +3 -3
  63. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
  64. package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
  65. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
  66. package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
  67. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
  68. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
  69. package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
  70. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
  71. package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
  72. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  73. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  74. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
  75. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
  76. package/lib/esm/src/api/secure-channel/task/types.js +1 -1
  77. package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
  78. package/lib/esm/src/api/secure-channel/utils.js +1 -1
  79. package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
  80. package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
  81. package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
  82. package/lib/esm/src/internal/crypto/CryptoService.js +1 -0
  83. package/lib/esm/src/internal/crypto/CryptoService.js.map +7 -0
  84. package/lib/esm/src/internal/crypto/NobleCryptoService.js +2 -0
  85. package/lib/esm/src/internal/crypto/NobleCryptoService.js.map +7 -0
  86. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js +2 -0
  87. package/lib/esm/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
  88. package/lib/types/src/api/device-action/os/Errors.d.ts +5 -0
  89. package/lib/types/src/api/device-action/os/Errors.d.ts.map +1 -1
  90. package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
  91. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +1 -0
  92. package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
  93. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
  94. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +3 -2
  95. package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
  96. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
  97. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -0
  98. package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
  99. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts +2 -2
  100. package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts.map +1 -1
  101. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
  102. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +1 -0
  103. package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
  104. package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
  105. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +1 -0
  106. package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
  107. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
  108. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +1 -0
  109. package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
  110. package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
  111. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +1 -0
  112. package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
  113. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +4 -0
  114. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  115. package/lib/types/src/api/secure-channel/task/types.d.ts +7 -0
  116. package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
  117. package/lib/types/src/api/secure-channel/utils.d.ts +18 -1
  118. package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
  119. package/lib/types/src/internal/crypto/CryptoService.d.ts +12 -0
  120. package/lib/types/src/internal/crypto/CryptoService.d.ts.map +1 -0
  121. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts +8 -0
  122. package/lib/types/src/internal/crypto/NobleCryptoService.d.ts.map +1 -0
  123. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts +2 -0
  124. package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts.map +1 -0
  125. package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +1 -1
  126. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  127. package/package.json +34 -29
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/InstallOrUpdateApps/types.ts"],
4
- "sourcesContent": ["import type { CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport type {\n OutOfMemoryDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n GetDeviceMetadataDAError,\n GetDeviceMetadataDARequiredInteraction,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport type { GoToDashboardDARequiredInteraction } from \"@api/device-action/os/GoToDashboard/types\";\nimport type { GoToDashboardDAInput } from \"@api/device-action/os/GoToDashboard/types\";\nimport type { InstallAppDAError } from \"@api/secure-channel/device-action/InstallApp/types\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { SecureChannelInstallDAErrors } from \"@internal/secure-channel/model/Errors\";\n\n/**\n * An application version used as application constraint should either be a valid semantic versioning formatted\n * string, or \"latest\" to ensure the app is always up-to-date.\n */\nexport type ApplicationVersionConstraint =\n | `${number}.${number}.${number}`\n | `${number}.${number}.${number}-${string}`\n | `${number}.${number}.${number}+${string}`\n | `${number}.${number}.${number}-${string}+${string}`\n | \"latest\";\n\nexport type ApplicationConstraint = {\n /**\n * Required minimal version of the application, if already installed on the device.\n */\n readonly minVersion: ApplicationVersionConstraint;\n\n /**\n * List of device models that require the minVersion.\n */\n readonly applicableModels?: DeviceModelId[];\n\n /**\n * List of device models that do not require the minVersion.\n */\n readonly exemptModels?: DeviceModelId[];\n};\n\nexport type ApplicationDependency = {\n /**\n * Name of the application to install.\n */\n readonly name: string;\n\n /**\n * List of constraints for the application.\n * If no constraints are provided, no version checks are performed.\n * If the current device model is not concerned by any listed contraints, no version checks are performed.\n */\n readonly constraints?: ApplicationConstraint[];\n};\n\nexport type InstallPlan = {\n readonly installPlan: Application[];\n readonly alreadyInstalled: string[];\n readonly missingApplications: string[];\n readonly currentIndex: number;\n readonly currentProgress: number;\n};\n\nexport type InstallOrUpdateAppsDAOutput = {\n readonly successfullyInstalled: Application[];\n readonly alreadyInstalled: string[];\n readonly missingApplications: string[];\n};\n\nexport type InstallOrUpdateAppsDAInput = GoToDashboardDAInput & {\n readonly applications: ApplicationDependency[];\n readonly allowMissingApplication: boolean;\n};\n\nexport type InstallOrUpdateAppsDAError =\n | GetDeviceMetadataDAError\n | InstallAppDAError\n | OutOfMemoryDAError\n | UnsupportedFirmwareDAError\n | SecureChannelInstallDAErrors\n | CommandErrorResult[\"error\"];\n\nexport type InstallOrUpdateAppsDARequiredInteraction =\n | GoToDashboardDARequiredInteraction\n | GetDeviceMetadataDARequiredInteraction;\n\nexport type InstallOrUpdateAppsDAIntermediateValue = {\n requiredUserInteraction: InstallOrUpdateAppsDARequiredInteraction;\n installPlan: InstallPlan | null;\n};\n\nexport type InstallOrUpdateAppsDAState = DeviceActionState<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue\n>;\n"],
4
+ "sourcesContent": ["import type { CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport type {\n OutOfMemoryDAError,\n UnsupportedApplicationDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n GetDeviceMetadataDAError,\n GetDeviceMetadataDARequiredInteraction,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport type { GoToDashboardDARequiredInteraction } from \"@api/device-action/os/GoToDashboard/types\";\nimport type { GoToDashboardDAInput } from \"@api/device-action/os/GoToDashboard/types\";\nimport type { InstallAppDAError } from \"@api/secure-channel/device-action/InstallApp/types\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport type { SecureChannelInstallDAErrors } from \"@internal/secure-channel/model/Errors\";\n\n/**\n * An application version used as application constraint should either be a valid semantic versioning formatted\n * string, or \"latest\" to ensure the app is always up-to-date.\n */\nexport type ApplicationVersionConstraint =\n | `${number}.${number}.${number}`\n | `${number}.${number}.${number}-${string}`\n | `${number}.${number}.${number}+${string}`\n | `${number}.${number}.${number}-${string}+${string}`\n | \"latest\";\n\nexport type ApplicationConstraint = {\n /**\n * Required minimal version of the application, if already installed on the device.\n */\n readonly minVersion: ApplicationVersionConstraint;\n\n /**\n * List of device models that require the minVersion.\n */\n readonly applicableModels?: DeviceModelId[];\n\n /**\n * List of device models that do not require the minVersion.\n */\n readonly exemptModels?: DeviceModelId[];\n};\n\nexport type ApplicationDependency = {\n /**\n * Name of the application to install.\n */\n readonly name: string;\n\n /**\n * List of constraints for the application.\n * If no constraints are provided, no version checks are performed.\n * If the current device model is not concerned by any listed contraints, no version checks are performed.\n */\n readonly constraints?: ApplicationConstraint[];\n};\n\nexport type InstallPlan = {\n readonly installPlan: Application[];\n readonly alreadyInstalled: string[];\n readonly missingApplications: string[];\n readonly currentIndex: number;\n readonly currentProgress: number;\n};\n\nexport type InstallOrUpdateAppsDAOutput = {\n readonly successfullyInstalled: Application[];\n readonly alreadyInstalled: string[];\n readonly missingApplications: string[];\n};\n\nexport type InstallOrUpdateAppsDAInput = GoToDashboardDAInput & {\n readonly applications: ApplicationDependency[];\n readonly allowMissingApplication: boolean;\n};\n\nexport type InstallOrUpdateAppsDAError =\n | GetDeviceMetadataDAError\n | InstallAppDAError\n | OutOfMemoryDAError\n | UnsupportedApplicationDAError\n | UnsupportedFirmwareDAError\n | SecureChannelInstallDAErrors\n | CommandErrorResult[\"error\"];\n\nexport type InstallOrUpdateAppsDARequiredInteraction =\n | GoToDashboardDARequiredInteraction\n | GetDeviceMetadataDARequiredInteraction;\n\nexport type InstallOrUpdateAppsDAIntermediateValue = {\n requiredUserInteraction: InstallOrUpdateAppsDARequiredInteraction;\n installPlan: InstallPlan | null;\n deviceId?: Uint8Array;\n};\n\nexport type InstallOrUpdateAppsDAState = DeviceActionState<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue\n>;\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["types_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=(r,t)=>{for(var i in t)l(r,i,{get:t[i],enumerable:!0})},y=(r,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of x(t))!f.call(r,p)&&p!==i&&l(r,p,{get:()=>t[p],enumerable:!(c=I(t,p))||c.enumerable});return r};var E=r=>y(l({},"__esModule",{value:!0}),r);var k={};g(k,{OpenAppWithDependenciesDeviceAction:()=>W});module.exports=E(k);var s=require("purify-ts"),n=require("xstate"),o=require("../../../device-action/model/UserInteractionRequired"),d=require("../../../device-action/os/Const"),m=require("../../../device-action/os/Errors"),A=require("../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction"),D=require("../../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction"),h=require("../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction"),O=require("../../../device-action/xstate-utils/XStateDeviceAction");class W extends O.XStateDeviceAction{makeStateMachine(t){const i=this.input.unlockTimeout??d.DEFAULT_UNLOCK_TIMEOUT_MS,c=new A.GetDeviceMetadataDeviceAction({input:{unlockTimeout:i,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(t),p=new D.InstallOrUpdateAppsDeviceAction({input:{unlockTimeout:i,applications:[...this.input.dependencies,this.input.application],allowMissingApplication:!1}}).makeStateMachine(t),v=new h.OpenAppDeviceAction({input:{unlockTimeout:i,appName:this.input.application.name}}).makeStateMachine(t);return(0,n.setup)({types:{input:{unlockTimeout:i},context:{},output:{}},actors:{getMetadata:c,installApps:p,openApp:v},guards:{hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorFromEvent:(0,n.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"OpenAppWithDependenciesDeviceAction",initial:"DeviceReady",context:e=>({input:{application:e.input.application,dependencies:e.input.dependencies,requireLatestFirmware:e.input.requireLatestFirmware,unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:o.UserInteractionRequired.None,installPlan:null},_internalState:{error:null,deviceMetadata:null,installResult:null}}),states:{DeviceReady:{always:[{target:"GetDeviceMetadata"}]},GetDeviceMetadata:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{id:"getMetadata",src:"getMetadata",input:e=>({unlockTimeout:e.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GetDeviceMetadataCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:a=>e.context.input.requireLatestFirmware&&a.firmwareUpdateContext.availableUpdate!==void 0?{...e.context._internalState,error:new m.UnsupportedFirmwareDAError("Firmware is not the latest version")}:{...e.context._internalState,deviceMetadata:a},Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallDependencies"}]},InstallDependencies:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{src:"installApps",input:e=>({unlockTimeout:e.context.input.unlockTimeout,applications:[...e.context.input.dependencies,e.context.input.application],allowMissingApplication:!1}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:e.event.snapshot.context.intermediateValue.installPlan})})},onDone:{target:"InstallDependenciesCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:a=>({...e.context._internalState,installResult:a}),Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallDependenciesCheck:{always:[{guard:"hasError",target:"Error"},{target:"OpenApp"}]},OpenApp:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{src:"openApp",input:e=>({unlockTimeout:e.context.input.unlockTimeout,appName:e.context.input.application.name}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:null})})},onDone:{target:"OpenAppCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OpenAppCheck:{always:[{guard:"hasError",target:"Error"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:a}=e,{error:u,deviceMetadata:M,installResult:S}=a._internalState;return u?(0,s.Left)(u):(0,s.Right)({deviceMetadata:M,installResult:S})}})}}0&&(module.exports={OpenAppWithDependenciesDeviceAction});
1
+ "use strict";var l=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var g=(r,t)=>{for(var i in t)l(r,i,{get:t[i],enumerable:!0})},y=(r,t,i,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of S(t))!f.call(r,p)&&p!==i&&l(r,p,{get:()=>t[p],enumerable:!(c=x(t,p))||c.enumerable});return r};var E=r=>y(l({},"__esModule",{value:!0}),r);var V={};g(V,{OpenAppWithDependenciesDeviceAction:()=>W});module.exports=E(V);var s=require("purify-ts"),n=require("xstate"),o=require("../../../device-action/model/UserInteractionRequired"),d=require("../../../device-action/os/Const"),m=require("../../../device-action/os/Errors"),h=require("../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction"),A=require("../../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction"),D=require("../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction"),v=require("../../../device-action/xstate-utils/XStateDeviceAction");class W extends v.XStateDeviceAction{makeStateMachine(t){const i=this.input.unlockTimeout??d.DEFAULT_UNLOCK_TIMEOUT_MS,c=new h.GetDeviceMetadataDeviceAction({input:{unlockTimeout:i,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(t),p=new A.InstallOrUpdateAppsDeviceAction({input:{unlockTimeout:i,applications:[...this.input.dependencies,this.input.application],allowMissingApplication:!1}}).makeStateMachine(t),O=new D.OpenAppDeviceAction({input:{unlockTimeout:i,appName:this.input.application.name}}).makeStateMachine(t);return(0,n.setup)({types:{input:{unlockTimeout:i},context:{},output:{}},actors:{getMetadata:c,installApps:p,openApp:O},guards:{hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorFromEvent:(0,n.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"OpenAppWithDependenciesDeviceAction",initial:"DeviceReady",context:e=>({input:{application:e.input.application,dependencies:e.input.dependencies,requireLatestFirmware:e.input.requireLatestFirmware,unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:o.UserInteractionRequired.None,installPlan:null},_internalState:{error:null,deviceMetadata:null,installResult:null}}),states:{DeviceReady:{always:[{target:"GetDeviceMetadata"}]},GetDeviceMetadata:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{id:"getMetadata",src:"getMetadata",input:e=>({unlockTimeout:e.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,deviceId:e.event.snapshot.context.intermediateValue.deviceId??e.context.intermediateValue.deviceId})})},onDone:{target:"GetDeviceMetadataCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:a=>e.context.input.requireLatestFirmware&&a.firmwareUpdateContext.availableUpdate!==void 0?{...e.context._internalState,error:new m.UnsupportedFirmwareDAError("Firmware is not the latest version")}:{...e.context._internalState,deviceMetadata:a},Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallDependencies"}]},InstallDependencies:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{src:"installApps",input:e=>({unlockTimeout:e.context.input.unlockTimeout,applications:[...e.context.input.dependencies,e.context.input.application],allowMissingApplication:!1}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:e.event.snapshot.context.intermediateValue.installPlan,deviceId:e.event.snapshot.context.intermediateValue.deviceId??e.context.intermediateValue.deviceId})})},onDone:{target:"InstallDependenciesCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:a=>({...e.context._internalState,installResult:a}),Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallDependenciesCheck:{always:[{guard:"hasError",target:"Error"},{target:"OpenApp"}]},OpenApp:{exit:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:o.UserInteractionRequired.None})}),invoke:{src:"openApp",input:e=>({unlockTimeout:e.context.input.unlockTimeout,appName:e.context.input.application.name}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:null})})},onDone:{target:"OpenAppCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:a=>({...e.context._internalState,error:a})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OpenAppCheck:{always:[{guard:"hasError",target:"Error"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:a}=e,{error:u,deviceMetadata:I,installResult:M}=a._internalState;return u?(0,s.Left)(u):(0,s.Right)({deviceMetadata:I,installResult:M})}})}}0&&(module.exports={OpenAppWithDependenciesDeviceAction});
2
2
  //# sourceMappingURL=OpenAppWithDependenciesDeviceAction.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.ts"],
4
- "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnsupportedFirmwareDAError } 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 { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport type { InstallOrUpdateAppsDAOutput } from \"@api/device-action/os/InstallOrUpdateApps/types\";\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 OpenAppWithDependenciesDAError,\n type OpenAppWithDependenciesDAInput,\n type OpenAppWithDependenciesDAIntermediateValue,\n type OpenAppWithDependenciesDAOutput,\n} from \"./types\";\n\ntype OpenAppWithDependenciesMachineInternalState = {\n readonly error: OpenAppWithDependenciesDAError | null;\n readonly deviceMetadata: GetDeviceMetadataDAOutput | null;\n readonly installResult: InstallOrUpdateAppsDAOutput | null;\n};\n\nexport class OpenAppWithDependenciesDeviceAction extends XStateDeviceAction<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n >;\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const installAppsMachine = new InstallOrUpdateAppsDeviceAction({\n input: {\n unlockTimeout,\n applications: [...this.input.dependencies, this.input.application],\n allowMissingApplication: false,\n },\n }).makeStateMachine(internalApi);\n\n const openAppMachine = new OpenAppDeviceAction({\n input: {\n unlockTimeout,\n appName: this.input.application.name,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getMetadata: getMetadataMachine,\n installApps: installAppsMachine,\n openApp: openAppMachine,\n },\n guards: {\n hasError: ({ 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: \"OpenAppWithDependenciesDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n application: _.input.application,\n dependencies: _.input.dependencies,\n requireLatestFirmware: _.input.requireLatestFirmware,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n deviceMetadata: null,\n installResult: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GetDeviceMetadata\",\n },\n ],\n },\n GetDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"getMetadata\",\n src: \"getMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"GetDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => {\n if (\n _.context.input.requireLatestFirmware &&\n data.firmwareUpdateContext.availableUpdate !==\n undefined\n ) {\n return {\n ..._.context._internalState,\n error: new UnsupportedFirmwareDAError(\n \"Firmware is not the latest version\",\n ),\n };\n } else {\n return {\n ..._.context._internalState,\n deviceMetadata: data,\n };\n }\n },\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallDependencies\",\n },\n ],\n },\n InstallDependencies: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"installApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n applications: [\n ..._.context.input.dependencies,\n _.context.input.application,\n ],\n allowMissingApplication: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan:\n _.event.snapshot.context.intermediateValue.installPlan,\n }),\n }),\n },\n onDone: {\n target: \"InstallDependenciesCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n installResult: data,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallDependenciesCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OpenApp\",\n },\n ],\n },\n OpenApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"openApp\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n appName: _.context.input.application.name,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan: null,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OpenAppCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error, deviceMetadata, installResult } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n deviceMetadata: deviceMetadata!,\n installResult: installResult!,\n });\n },\n });\n }\n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,IAAW,CAChB,GAAGF,EAAE,QAAQ,eACb,MAAAE,CACF,EACF,CACF,CACJ,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,aAAc,CACZ,OAAQ,CACN,CACE,MAAO,WACP,OAAQ,OACV,EACA,CACE,OAAQ,SACV,CACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASC,GAAS,CAChB,KAAM,CAAE,QAAAJ,CAAQ,EAAII,EACd,CAAE,MAAAD,EAAO,eAAAE,EAAgB,cAAAC,CAAc,EAAIN,EAAQ,eACzD,OAAIG,KACK,QAAKA,CAAK,KAEZ,SAAM,CACX,eAAgBE,EAChB,cAAeC,CACjB,CAAC,CACH,CACF,CAAC,CACH,CACF",
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnsupportedFirmwareDAError } 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 { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport type { InstallOrUpdateAppsDAOutput } from \"@api/device-action/os/InstallOrUpdateApps/types\";\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 OpenAppWithDependenciesDAError,\n type OpenAppWithDependenciesDAInput,\n type OpenAppWithDependenciesDAIntermediateValue,\n type OpenAppWithDependenciesDAOutput,\n} from \"./types\";\n\ntype OpenAppWithDependenciesMachineInternalState = {\n readonly error: OpenAppWithDependenciesDAError | null;\n readonly deviceMetadata: GetDeviceMetadataDAOutput | null;\n readonly installResult: InstallOrUpdateAppsDAOutput | null;\n};\n\nexport class OpenAppWithDependenciesDeviceAction extends XStateDeviceAction<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n >;\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const installAppsMachine = new InstallOrUpdateAppsDeviceAction({\n input: {\n unlockTimeout,\n applications: [...this.input.dependencies, this.input.application],\n allowMissingApplication: false,\n },\n }).makeStateMachine(internalApi);\n\n const openAppMachine = new OpenAppDeviceAction({\n input: {\n unlockTimeout,\n appName: this.input.application.name,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getMetadata: getMetadataMachine,\n installApps: installAppsMachine,\n openApp: openAppMachine,\n },\n guards: {\n hasError: ({ 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: \"OpenAppWithDependenciesDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n application: _.input.application,\n dependencies: _.input.dependencies,\n requireLatestFirmware: _.input.requireLatestFirmware,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n deviceMetadata: null,\n installResult: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GetDeviceMetadata\",\n },\n ],\n },\n GetDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"getMetadata\",\n src: \"getMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n deviceId:\n _.event.snapshot.context.intermediateValue.deviceId ??\n _.context.intermediateValue.deviceId,\n }),\n }),\n },\n onDone: {\n target: \"GetDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => {\n if (\n _.context.input.requireLatestFirmware &&\n data.firmwareUpdateContext.availableUpdate !==\n undefined\n ) {\n return {\n ..._.context._internalState,\n error: new UnsupportedFirmwareDAError(\n \"Firmware is not the latest version\",\n ),\n };\n } else {\n return {\n ..._.context._internalState,\n deviceMetadata: data,\n };\n }\n },\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallDependencies\",\n },\n ],\n },\n InstallDependencies: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"installApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n applications: [\n ..._.context.input.dependencies,\n _.context.input.application,\n ],\n allowMissingApplication: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan:\n _.event.snapshot.context.intermediateValue.installPlan,\n deviceId:\n _.event.snapshot.context.intermediateValue.deviceId ??\n _.context.intermediateValue.deviceId,\n }),\n }),\n },\n onDone: {\n target: \"InstallDependenciesCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n installResult: data,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallDependenciesCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OpenApp\",\n },\n ],\n },\n OpenApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"openApp\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n appName: _.context.input.application.name,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan: null,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OpenAppCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error, deviceMetadata, installResult } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n deviceMetadata: deviceMetadata!,\n installResult: installResult!,\n });\n },\n });\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA4B,qBAC5BC,EAA8B,kBAG9BC,EAAwC,4DACxCC,EAA0C,uCAC1CC,EAA2C,wCAC3CC,EAA8C,iFAE9CC,EAAgD,qFAEhDC,EAAoC,yEAEpCC,EAGO,8DAeA,MAAMV,UAA4C,oBAMvD,CACA,iBACEW,EAOA,CASA,MAAMC,EAAgB,KAAK,MAAM,eAAiB,4BAE5CC,EAAqB,IAAI,gCAA8B,CAC3D,MAAO,CACL,cAAAD,EACA,iBAAkB,GAClB,YAAa,EACf,CACF,CAAC,EAAE,iBAAiBD,CAAW,EAEzBG,EAAqB,IAAI,kCAAgC,CAC7D,MAAO,CACL,cAAAF,EACA,aAAc,CAAC,GAAG,KAAK,MAAM,aAAc,KAAK,MAAM,WAAW,EACjE,wBAAyB,EAC3B,CACF,CAAC,EAAE,iBAAiBD,CAAW,EAEzBI,EAAiB,IAAI,sBAAoB,CAC7C,MAAO,CACL,cAAAH,EAC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ppWithDependenciesDeviceAction_exports", "__export", "OpenAppWithDependenciesDeviceAction", "__toCommonJS", "import_purify_ts", "import_xstate", "import_UserInteractionRequired", "import_Const", "import_Errors", "import_GetDeviceMetadataDeviceAction", "import_InstallOrUpdateAppsDeviceAction", "import_OpenAppDeviceAction", "import_XStateDeviceAction", "internalApi", "unlockTimeout", "getMetadataMachine", "installAppsMachine", "openAppMachine", "context", "_", "data", "error", "args", "deviceMetadata", "installResult"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var r=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var c=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of o(e))!A.call(t,p)&&p!==i&&r(t,p,{get:()=>e[p],enumerable:!(n=a(e,p))||n.enumerable});return t};var d=t=>c(r({},"__esModule",{value:!0}),t);var D={};module.exports=d(D);
1
+ "use strict";var r=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var d=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of o(e))!A.call(t,p)&&p!==i&&r(t,p,{get:()=>e[p],enumerable:!(n=a(e,p))||n.enumerable});return t};var c=t=>d(r({},"__esModule",{value:!0}),t);var D={};module.exports=c(D);
2
2
  //# sourceMappingURL=types.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../../src/api/device-action/os/OpenAppWithDependencies/types.ts"],
4
- "sourcesContent": ["import type { CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport type { DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport type {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDARequiredInteraction,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport type { GetDeviceStatusDAInput } from \"@api/device-action/os/GetDeviceStatus/types\";\nimport type {\n ApplicationDependency,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDARequiredInteraction,\n InstallPlan,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport type {\n OpenAppDAError,\n OpenAppDARequiredInteraction,\n} from \"@api/device-action/os/OpenAppDeviceAction/types\";\n\nexport type OpenAppWithDependenciesDAOutput = {\n deviceMetadata: GetDeviceMetadataDAOutput;\n installResult: InstallOrUpdateAppsDAOutput;\n};\n\nexport type OpenAppWithDependenciesDAInput = GetDeviceStatusDAInput & {\n readonly application: ApplicationDependency;\n readonly dependencies: ApplicationDependency[];\n readonly requireLatestFirmware?: boolean;\n};\n\nexport type OpenAppWithDependenciesDAError =\n | InstallOrUpdateAppsDAError\n | OpenAppDAError\n | UnknownDAError\n | UnsupportedFirmwareDAError\n | CommandErrorResult[\"error\"];\n\nexport type OpenAppWithDependenciesDARequiredInteraction =\n | GetDeviceMetadataDARequiredInteraction\n | InstallOrUpdateAppsDARequiredInteraction\n | OpenAppDARequiredInteraction;\n\nexport type OpenAppWithDependenciesDAIntermediateValue = {\n requiredUserInteraction: OpenAppWithDependenciesDARequiredInteraction;\n installPlan: InstallPlan | null;\n};\n\nexport type OpenAppWithDependenciesDAState = DeviceActionState<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue\n>;\n"],
4
+ "sourcesContent": ["import type { CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport type { DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport type {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDARequiredInteraction,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport type { GetDeviceStatusDAInput } from \"@api/device-action/os/GetDeviceStatus/types\";\nimport type {\n ApplicationDependency,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDARequiredInteraction,\n InstallPlan,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport type {\n OpenAppDAError,\n OpenAppDARequiredInteraction,\n} from \"@api/device-action/os/OpenAppDeviceAction/types\";\n\nexport type OpenAppWithDependenciesDAOutput = {\n deviceMetadata: GetDeviceMetadataDAOutput;\n installResult: InstallOrUpdateAppsDAOutput;\n};\n\nexport type OpenAppWithDependenciesDAInput = GetDeviceStatusDAInput & {\n readonly application: ApplicationDependency;\n readonly dependencies: ApplicationDependency[];\n readonly requireLatestFirmware?: boolean;\n};\n\nexport type OpenAppWithDependenciesDAError =\n | InstallOrUpdateAppsDAError\n | OpenAppDAError\n | UnknownDAError\n | UnsupportedFirmwareDAError\n | CommandErrorResult[\"error\"];\n\nexport type OpenAppWithDependenciesDARequiredInteraction =\n | GetDeviceMetadataDARequiredInteraction\n | InstallOrUpdateAppsDARequiredInteraction\n | OpenAppDARequiredInteraction;\n\nexport type OpenAppWithDependenciesDAIntermediateValue = {\n requiredUserInteraction: OpenAppWithDependenciesDARequiredInteraction;\n installPlan: InstallPlan | null;\n deviceId?: Uint8Array;\n};\n\nexport type OpenAppWithDependenciesDAState = DeviceActionState<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue\n>;\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["types_exports", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var I=(r,e)=>{for(var n in e)c(r,n,{get:e[n],enumerable:!0})},y=(r,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of v(e))!g.call(r,i)&&i!==n&&c(r,i,{get:()=>e[i],enumerable:!(a=A(e,i))||a.enumerable});return r};var M=r=>y(c({},"__esModule",{value:!0}),r);var h={};I(h,{BuildAppsInstallPlanTask:()=>D});module.exports=M(h);var f=require("semver"),p=require("../../device-action/os/Errors"),u=require("../../device-session/DeviceSessionState");class D{constructor(e,n){this.api=e;this.args=n;const a=e.getDeviceModel();this.deviceModelId=a.id}deviceModelId;run(){const e=this.api.getDeviceSessionState();if(e.sessionStateType===u.DeviceSessionStateType.Connected)return{error:new p.UnknownDAError("Invalid device state")};if(e.catalog===void 0)return{error:new p.UnknownDAError("Device apps metadata not fetched")};let n=[],a=[],i=[];for(const t of this.args.applications){const o=e.catalog.applications.find(s=>s.versionName===t.name),l=e.installedApps.find(s=>s.versionName===t.name);if(l!==void 0&&this.validateConstraint(l,o,t.constraints)){a=[...a,t.name];continue}if(o!==void 0&&this.validateConstraint(o,void 0,t.constraints))n=[...n,o];else if(this.args.allowMissingApplication)i=[...i,t.name];else return o!==void 0?{error:new p.UnsupportedFirmwareDAError(`Application ${t.name} not found in the catalog`)}:{error:new p.UnknownDAError(`Application ${t.name} not found in the catalog`)}}return n=[...n.reduce((t,o)=>{const l=o.parentName;if(l){const s=e.catalog.applications.find(d=>d.versionName===l),m=e.installedApps.find(d=>d.versionName===l);if(s&&!m)return[...t,s]}return t},[]),...n],{installPlan:n.filter((t,o)=>n.findIndex(l=>l.versionName===t.versionName)===o),missingApplications:i,alreadyInstalled:a}}validateConstraint(e,n,a){if(a===void 0)return!0;for(const i of a)if(!(i.exemptModels!==void 0&&i.exemptModels.includes(this.deviceModelId))&&!(i.applicableModels!==void 0&&!i.applicableModels.includes(this.deviceModelId)))return i.minVersion==="latest"?!n||(0,f.gte)(e.version,n.version):(0,f.gte)(e.version,i.minVersion);return!0}}0&&(module.exports={BuildAppsInstallPlanTask});
1
+ "use strict";var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var n in e)c(o,n,{get:e[n],enumerable:!0})},y=(o,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of v(e))!g.call(o,i)&&i!==n&&c(o,i,{get:()=>e[i],enumerable:!(a=A(e,i))||a.enumerable});return o};var D=o=>y(c({},"__esModule",{value:!0}),o);var M={};I(M,{BuildAppsInstallPlanTask:()=>w});module.exports=D(M);var f=require("semver"),s=require("../../device-action/os/Errors"),u=require("../../device-session/DeviceSessionState");class w{constructor(e,n){this.api=e;this.args=n;const a=e.getDeviceModel();this.deviceModelId=a.id}deviceModelId;run(){const e=this.api.getDeviceSessionState();if(e.sessionStateType===u.DeviceSessionStateType.Connected)return{error:new s.UnknownDAError("Invalid device state")};if(e.catalog===void 0)return{error:new s.UnknownDAError("Device apps metadata not fetched")};let n=[],a=[],i=[];for(const t of this.args.applications){const r=e.catalog.applications.find(p=>p.versionName===t.name),l=e.installedApps.find(p=>p.versionName===t.name);if(l!==void 0&&this.validateConstraint(l,r,t.constraints)){a=[...a,t.name];continue}if(r!==void 0&&this.validateConstraint(r,void 0,t.constraints))n=[...n,r];else if(this.args.allowMissingApplication)i=[...i,t.name];else return e.firmwareUpdateContext?.availableUpdate!==void 0&&r!==void 0?{error:new s.UnsupportedFirmwareDAError(`Application ${t.name} needs latest firmware`)}:e.firmwareUpdateContext?.availableUpdate!==void 0?{error:new s.UnsupportedFirmwareDAError(`Application ${t.name} needs latest firmware`)}:{error:new s.UnsupportedApplicationDAError(`Application ${t.name} not supported for this device`)}}return n=[...n.reduce((t,r)=>{const l=r.parentName;if(l){const p=e.catalog.applications.find(d=>d.versionName===l),m=e.installedApps.find(d=>d.versionName===l);if(p&&!m)return[...t,p]}return t},[]),...n],{installPlan:n.filter((t,r)=>n.findIndex(l=>l.versionName===t.versionName)===r),missingApplications:i,alreadyInstalled:a}}validateConstraint(e,n,a){if(a===void 0)return!0;for(const i of a)if(!(i.exemptModels!==void 0&&i.exemptModels.includes(this.deviceModelId))&&!(i.applicableModels!==void 0&&!i.applicableModels.includes(this.deviceModelId)))return i.minVersion==="latest"?!n||(0,f.gte)(e.version,n.version):(0,f.gte)(e.version,i.minVersion);return!0}}0&&(module.exports={BuildAppsInstallPlanTask});
2
2
  //# sourceMappingURL=BuildAppsInstallPlanTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/device-action/task/BuildAppsInstallPlanTask.ts"],
4
- "sourcesContent": ["import { gte } from \"semver\";\n\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n ApplicationConstraint,\n ApplicationDependency,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type BuildAppsInstallPlanTaskArgs = {\n /**\n * List of applications to install or update\n */\n readonly applications: ApplicationDependency[];\n\n /**\n * Indicates if the device action should fail if an application is missing from the app store.\n */\n readonly allowMissingApplication: boolean;\n};\n\nexport type BuildAppsInstallPlanTaskResult =\n | {\n installPlan: Application[];\n alreadyInstalled: string[];\n missingApplications: string[];\n }\n | {\n error: UnknownDAError | UnsupportedFirmwareDAError;\n };\n\nexport class BuildAppsInstallPlanTask {\n private readonly deviceModelId: DeviceModelId;\n\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildAppsInstallPlanTaskArgs,\n ) {\n const deviceModel = api.getDeviceModel();\n this.deviceModelId = deviceModel.id;\n }\n\n run(): BuildAppsInstallPlanTaskResult {\n // Get device session state.\n const deviceState = this.api.getDeviceSessionState();\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return { error: new UnknownDAError(\"Invalid device state\") };\n }\n\n // Ensure the device metadata were correctly fetched.\n if (deviceState.catalog === undefined) {\n return { error: new UnknownDAError(\"Device apps metadata not fetched\") };\n }\n\n // Build the install plan\n let installPlan: Application[] = [];\n let alreadyInstalled: string[] = [];\n let missingApplications: string[] = [];\n for (const app of this.args.applications) {\n // Get app entry from catalog and from installed apps\n const catalogApp = deviceState.catalog.applications.find(\n (a) => a.versionName === app.name,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === app.name,\n );\n\n // If app is already installed, with validated constraints, continue the iteration\n if (\n installedApp !== undefined &&\n this.validateConstraint(installedApp, catalogApp, app.constraints)\n ) {\n alreadyInstalled = [...alreadyInstalled, app.name];\n continue;\n }\n\n // Handle the catalog application\n if (\n catalogApp !== undefined &&\n this.validateConstraint(catalogApp, undefined, app.constraints)\n ) {\n // Add the catalog application to the install plan\n installPlan = [...installPlan, catalogApp];\n } else if (this.args.allowMissingApplication) {\n missingApplications = [...missingApplications, app.name];\n } else {\n // Fail immediately if missing application is not allowed\n if (catalogApp !== undefined) {\n // Is application is found in the catalog in an old version,\n // it usually means the firmware is also outdated.\n return {\n error: new UnsupportedFirmwareDAError(\n `Application ${app.name} not found in the catalog`,\n ),\n };\n } else {\n return {\n error: new UnknownDAError(\n `Application ${app.name} not found in the catalog`,\n ),\n };\n }\n }\n }\n\n // Find installPlan dependencies\n const dependencies = installPlan.reduce((apps, app) => {\n const dependency = app.parentName;\n if (dependency) {\n const catalogApp = deviceState.catalog!.applications.find(\n (a) => a.versionName === dependency,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === dependency,\n );\n if (catalogApp && !installedApp) {\n return [...apps, catalogApp];\n }\n }\n return apps;\n }, [] as Application[]);\n\n // Reorder and deduplicate the install plan with its dependencies first\n installPlan = [...dependencies, ...installPlan];\n const reorderedInstallPlan = installPlan.filter(\n (app, index) =>\n installPlan.findIndex((a) => a.versionName === app.versionName) ===\n index,\n );\n\n return {\n installPlan: reorderedInstallPlan,\n missingApplications,\n alreadyInstalled,\n };\n }\n\n private validateConstraint(\n app: Application,\n catalogApp?: Application,\n constraints?: ApplicationConstraint[],\n ): boolean {\n if (constraints === undefined) {\n // No constraint\n return true;\n }\n\n // Validate the constraint\n for (const constraint of constraints) {\n // Is current device exempt from the constraint?\n if (\n constraint.exemptModels !== undefined &&\n constraint.exemptModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Is current device not applicable for the constraint?\n if (\n constraint.applicableModels !== undefined &&\n !constraint.applicableModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Validate the min version\n if (constraint.minVersion === \"latest\") {\n return !catalogApp || gte(app.version, catalogApp.version);\n } else {\n return gte(app.version, constraint.minVersion);\n }\n }\n\n // No constraint for the device\n return true;\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoB,kBAIpBC,EAGO,wCAKPC,EAAuC,kDAyBhC,MAAMJ,CAAyB,CAGpC,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,EAEjB,MAAMC,EAAcF,EAAI,eAAe,EACvC,KAAK,cAAgBE,EAAY,EACnC,CARiB,cAUjB,KAAsC,CAEpC,MAAMC,EAAc,KAAK,IAAI,sBAAsB,EACnD,GAAIA,EAAY,mBAAqB,yBAAuB,UAC1D,MAAO,CAAE,MAAO,IAAI,iBAAe,sBAAsB,CAAE,EAI7D,GAAIA,EAAY,UAAY,OAC1B,MAAO,CAAE,MAAO,IAAI,iBAAe,kCAAkC,CAAE,EAIzE,IAAIC,EAA6B,CAAC,EAC9BC,EAA6B,CAAC,EAC9BC,EAAgC,CAAC,EACrC,UAAWC,KAAO,KAAK,KAAK,aAAc,CAExC,MAAMC,EAAaL,EAAY,QAAQ,aAAa,KACjDM,GAAMA,EAAE,cAAgBF,EAAI,IAC/B,EACMG,EAAeP,EAAY,cAAc,KAC5CM,GAAMA,EAAE,cAAgBF,EAAI,IAC/B,EAGA,GACEG,IAAiB,QACjB,KAAK,mBAAmBA,EAAcF,EAAYD,EAAI,WAAW,EACjE,CAC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AW,UAAU,EAKjD,MAAO,EACT,CACF",
4
+ "sourcesContent": ["import { gte } from \"semver\";\n\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport {\n UnknownDAError,\n UnsupportedApplicationDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n ApplicationConstraint,\n ApplicationDependency,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type BuildAppsInstallPlanTaskArgs = {\n /**\n * List of applications to install or update\n */\n readonly applications: ApplicationDependency[];\n\n /**\n * Indicates if the device action should fail if an application is missing from the app store.\n */\n readonly allowMissingApplication: boolean;\n};\n\nexport type BuildAppsInstallPlanTaskResult =\n | {\n installPlan: Application[];\n alreadyInstalled: string[];\n missingApplications: string[];\n }\n | {\n error:\n | UnknownDAError\n | UnsupportedApplicationDAError\n | UnsupportedFirmwareDAError;\n };\n\nexport class BuildAppsInstallPlanTask {\n private readonly deviceModelId: DeviceModelId;\n\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildAppsInstallPlanTaskArgs,\n ) {\n const deviceModel = api.getDeviceModel();\n this.deviceModelId = deviceModel.id;\n }\n\n run(): BuildAppsInstallPlanTaskResult {\n // Get device session state.\n const deviceState = this.api.getDeviceSessionState();\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return { error: new UnknownDAError(\"Invalid device state\") };\n }\n\n // Ensure the device metadata were correctly fetched.\n if (deviceState.catalog === undefined) {\n return { error: new UnknownDAError(\"Device apps metadata not fetched\") };\n }\n\n // Build the install plan\n let installPlan: Application[] = [];\n let alreadyInstalled: string[] = [];\n let missingApplications: string[] = [];\n for (const app of this.args.applications) {\n // Get app entry from catalog and from installed apps\n const catalogApp = deviceState.catalog.applications.find(\n (a) => a.versionName === app.name,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === app.name,\n );\n\n // If app is already installed, with validated constraints, continue the iteration\n if (\n installedApp !== undefined &&\n this.validateConstraint(installedApp, catalogApp, app.constraints)\n ) {\n alreadyInstalled = [...alreadyInstalled, app.name];\n continue;\n }\n\n // Handle the catalog application\n if (\n catalogApp !== undefined &&\n this.validateConstraint(catalogApp, undefined, app.constraints)\n ) {\n // Add the catalog application to the install plan\n installPlan = [...installPlan, catalogApp];\n } else if (this.args.allowMissingApplication) {\n missingApplications = [...missingApplications, app.name];\n } else {\n /**\n * Fail immediately if missing application is not allowed.\n *\n * TODO: If the application is not in catalog, we should also check if the application will be available in the\n * latest firmware catalog before throwing `UnsupportedApplicationDAError`. The actual implementation will always\n * throw `UnsupportedFirmwareDAError` to force the user to update firmware first, even though the application may\n * be still not available after the firmware update. For now, we keep `catalogApp !== undefined` check to prevent\n * from forgetting this case.\n *\n * Decision matrix for application availability according to OS and catalog:\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 Not valid constraint \u2502 Found in catalog \u2502 Not found in catalog \u2502\n * \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n * \u2502 OS up-to-date \u2502 UnsupportedApplicationDAError \u2502 UnsupportedApplicationDAError \u2502\n * \u2502 OS out-of-date \u2502 UnsupportedFirmwareDAError \u2502 UnsupportedFirmwareDAError => TODO \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n */\n if (\n deviceState.firmwareUpdateContext?.availableUpdate !== undefined &&\n catalogApp !== undefined\n ) {\n return {\n error: new UnsupportedFirmwareDAError(\n `Application ${app.name} needs latest firmware`,\n ),\n };\n } else if (\n deviceState.firmwareUpdateContext?.availableUpdate !== undefined\n ) {\n // TODO: Application not found in out-of-date firmware catalog, needs to check if the application will be available\n // after firmware update\n return {\n error: new UnsupportedFirmwareDAError(\n `Application ${app.name} needs latest firmware`,\n ),\n };\n } else {\n return {\n error: new UnsupportedApplicationDAError(\n `Application ${app.name} not supported for this device`,\n ),\n };\n }\n }\n }\n\n // Find installPlan dependencies\n const dependencies = installPlan.reduce((apps, app) => {\n const dependency = app.parentName;\n if (dependency) {\n const catalogApp = deviceState.catalog!.applications.find(\n (a) => a.versionName === dependency,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === dependency,\n );\n if (catalogApp && !installedApp) {\n return [...apps, catalogApp];\n }\n }\n return apps;\n }, [] as Application[]);\n\n // Reorder and deduplicate the install plan with its dependencies first\n installPlan = [...dependencies, ...installPlan];\n const reorderedInstallPlan = installPlan.filter(\n (app, index) =>\n installPlan.findIndex((a) => a.versionName === app.versionName) ===\n index,\n );\n\n return {\n installPlan: reorderedInstallPlan,\n missingApplications,\n alreadyInstalled,\n };\n }\n\n private validateConstraint(\n app: Application,\n catalogApp?: Application,\n constraints?: ApplicationConstraint[],\n ): boolean {\n if (constraints === undefined) {\n // No constraint\n return true;\n }\n\n // Validate the constraint\n for (const constraint of constraints) {\n // Is current device exempt from the constraint?\n if (\n constraint.exemptModels !== undefined &&\n constraint.exemptModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Is current device not applicable for the constraint?\n if (\n constraint.applicableModels !== undefined &&\n !constraint.applicableModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Validate the min version\n if (constraint.minVersion === \"latest\") {\n return !catalogApp || gte(app.version, catalogApp.version);\n } else {\n return gte(app.version, constraint.minVersion);\n }\n }\n\n // No constraint for the device\n return true;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAoB,kBAIpBC,EAIO,wCAKPC,EAAuC,kDA4BhC,MAAMJ,CAAyB,CAGpC,YACmBK,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,EAEjB,MAAMC,EAAcF,EAAI,eAAe,EACvC,KAAK,cAAgBE,EAAY,EACnC,CARiB,cAUjB,KAAsC,CAEpC,MAAMC,E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,cAAc,KAC5CM,GAAMA,EAAE,cAAgBG,CAC3B,EACA,GAAIJ,GAAc,CAACE,EACjB,MAAO,CAAC,GAAGC,EAAMH,CAAU,CAE/B,CACA,OAAOG,CACT,EAAG,CAAC,CAAkB,EAGU,GAAGP,CAAW,EAOvC,CACL,YAP2BA,EAAY,OACvC,CAACG,EAAKM,IACJT,EAAY,UAAWK,GAAMA,EAAE,cAAgBF,EAAI,WAAW,IAC9DM,CACJ,EAIE,oBAAAP,EACA,iBAAAD,CACF,CACF,CAEQ,mBACNE,EACAC,EACAM,EACS,CACT,GAAIA,IAAgB,OAElB,MAAO,GAIT,UAAWC,KAAcD,EAEvB,GACE,EAAAC,EAAW,eAAiB,QAC5BA,EAAW,aAAa,SAAS,KAAK,aAAa,IAOnD,EAAAA,EAAW,mBAAqB,QAChC,CAACA,EAAW,iBAAiB,SAAS,KAAK,aAAa,GAM1D,OAAIA,EAAW,aAAe,SACrB,CAACP,MAAc,OAAID,EAAI,QAASC,EAAW,OAAO,KAElD,OAAID,EAAI,QAASQ,EAAW,UAAU,EAKjD,MAAO,EACT,CACF",
6
6
  "names": ["BuildAppsInstallPlanTask_exports", "__export", "BuildAppsInstallPlanTask", "__toCommonJS", "import_semver", "import_Errors", "import_DeviceSessionState", "api", "args", "deviceModel", "deviceState", "installPlan", "alreadyInstalled", "missingApplications", "app", "catalogApp", "a", "installedApp", "apps", "dependency", "index", "constraints", "constraint"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("../../device/DeviceModel"),a=require("../../device/DeviceStatus"),r=require("../../device-action/__test-utils__/makeInternalApi"),o=require("../../device-action/os/Errors"),i=require("../../device-session/DeviceSessionState"),s=require("./BuildAppsInstallPlanTask");describe("BuildAppsInstallPlanTask",()=>{const e=(0,r.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.clearAllMocks(),e.getDeviceModel.mockReturnValue({id:t.DeviceModelId.NANO_X})}),it("Success with no changes needed",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Bitcoin"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin"],missingApplications:[]})}),it("Success with no constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.1.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.1.0"}],alreadyInstalled:["Ethereum"],missingApplications:[]})}),it("Success with applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",applicableModels:[t.DeviceModelId.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",exemptModels:[t.DeviceModelId.NANO_S]}]},{name:"Solana",constraints:[{minVersion:"1.2.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:[],missingApplications:[]})}),it("Success with non-applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",exemptModels:[t.DeviceModelId.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",applicableModels:[t.DeviceModelId.NANO_S]}]},{name:"Cardano",constraints:[{minVersion:"1.1.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin","Cardano"],missingApplications:[]})}),it("Success with applicable constraints latest version",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"MyShitCoin",version:"0.0.1"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"latest"}]},{name:"Bitcoin",constraints:[{minVersion:"latest"}]},{name:"MyShitCoin",constraints:[{minVersion:"latest"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"}],alreadyInstalled:["Bitcoin","MyShitCoin"],missingApplications:[]})}),it("Success with dependencies",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"AlreadyInstalledDep",version:"1.2.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"Cardano",version:"1.2.0",parentName:void 0},{versionName:"AlreadyInstalledDep",version:"1.2.0",parentName:"Cardano"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"MyEthShitCoin"},{name:"MySolShitCoin"},{name:"Solana"},{name:"MyPumpFunShitCoin"},{name:"AlreadyInstalledDep"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"}],alreadyInstalled:["AlreadyInstalledDep"],missingApplications:[]})}),it("Success with allowed missing applications",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!0}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:["Ethereum"],missingApplications:["Cardano"]})}),it("Error when device is in incorrect state",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.Connected,deviceStatus:a.DeviceStatus.CONNECTED});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o.UnknownDAError("Invalid device state")})}),it("Error when device session was not populated",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[]});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o.UnknownDAError("Device apps metadata not fetched")})}),it("Error when an app is not found in the catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],catalog:{applications:[],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Bitcoin"},{name:"Solana"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o.UnknownDAError("Application Ethereum not found in the catalog")})}),it("Error when an app version is not found in the catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],catalog:{applications:[{versionName:"Ethereum",version:"1.5.0"}],languagePackages:[]}});const n=new s.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o.UnsupportedFirmwareDAError("Application Ethereum not found in the catalog")})})});
1
+ "use strict";var o=require("../../device/DeviceModel"),a=require("../../device/DeviceStatus"),r=require("../../device-action/__test-utils__/makeInternalApi"),s=require("../../device-action/os/Errors"),i=require("../../device-session/DeviceSessionState"),t=require("./BuildAppsInstallPlanTask");describe("BuildAppsInstallPlanTask",()=>{const e=(0,r.makeDeviceActionInternalApiMock)();beforeEach(()=>{vi.clearAllMocks(),e.getDeviceModel.mockReturnValue({id:o.DeviceModelId.NANO_X})}),it("Success with no changes needed",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Bitcoin"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin"],missingApplications:[]})}),it("Success with no constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.1.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.1.0"}],alreadyInstalled:["Ethereum"],missingApplications:[]})}),it("Success with applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",applicableModels:[o.DeviceModelId.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",exemptModels:[o.DeviceModelId.NANO_S]}]},{name:"Solana",constraints:[{minVersion:"1.2.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:[],missingApplications:[]})}),it("Success with non-applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",exemptModels:[o.DeviceModelId.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",applicableModels:[o.DeviceModelId.NANO_S]}]},{name:"Cardano",constraints:[{minVersion:"1.1.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin","Cardano"],missingApplications:[]})}),it("Success with applicable constraints latest version",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"MyShitCoin",version:"0.0.1"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"latest"}]},{name:"Bitcoin",constraints:[{minVersion:"latest"}]},{name:"MyShitCoin",constraints:[{minVersion:"latest"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"}],alreadyInstalled:["Bitcoin","MyShitCoin"],missingApplications:[]})}),it("Success with dependencies",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"AlreadyInstalledDep",version:"1.2.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"Cardano",version:"1.2.0",parentName:void 0},{versionName:"AlreadyInstalledDep",version:"1.2.0",parentName:"Cardano"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"MyEthShitCoin"},{name:"MySolShitCoin"},{name:"Solana"},{name:"MyPumpFunShitCoin"},{name:"AlreadyInstalledDep"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"}],alreadyInstalled:["AlreadyInstalledDep"],missingApplications:[]})}),it("Success with allowed missing applications",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!0}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:["Ethereum"],missingApplications:["Cardano"]})}),it("Error when device is in incorrect state",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.Connected,deviceStatus:a.DeviceStatus.CONNECTED});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnknownDAError("Invalid device state")})}),it("Error when device session was not populated",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[]});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnknownDAError("Device apps metadata not fetched")})}),describe("Error cases for unsupported applications and firmwares",()=>{describe("when firmware is up to date",()=>{it("should throw `UnsupportedApplicationDAError` when application not found in catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{}},installedApps:[],catalog:{applications:[],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnsupportedApplicationDAError("Application Ethereum not supported for this device")})}),it("should throw `UnsupportedApplicationDAError` when application version is not supported",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{}},installedApps:[],catalog:{applications:[{versionName:"Ethereum",version:"1.5.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnsupportedApplicationDAError("Application Ethereum not supported for this device")})})}),describe("when firmware is out of date",()=>{it("should throw `UnsupportedFirmwareDAError` when application not found in catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,firmwareUpdateContext:{currentFirmware:{},availableUpdate:{}},installedApps:[],catalog:{applications:[],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnsupportedFirmwareDAError("Application Ethereum needs latest firmware")})}),it("should throw `UnsupportedFirmwareDAError` when application version is not supported",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:a.DeviceStatus.CONNECTED,installedApps:[],firmwareUpdateContext:{currentFirmware:{},availableUpdate:{}},catalog:{applications:[{versionName:"Ethereum",version:"1.5.0"}],languagePackages:[]}});const n=new t.BuildAppsInstallPlanTask(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new s.UnsupportedFirmwareDAError("Application Ethereum needs latest firmware")})})})})});
2
2
  //# sourceMappingURL=BuildAppsInstallPlanTask.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/device-action/task/BuildAppsInstallPlanTask.test.ts"],
4
- "sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nimport { BuildAppsInstallPlanTask } from \"./BuildAppsInstallPlanTask\";\n\ndescribe(\"BuildAppsInstallPlanTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n id: DeviceModelId.NANO_X,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success with no changes needed\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }, { name: \"Bitcoin\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with no constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", applicableModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", exemptModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Solana\", constraints: [{ minVersion: \"1.2.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ],\n alreadyInstalled: [],\n missingApplications: [],\n });\n });\n\n it(\"Success with non-applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", exemptModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", applicableModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Cardano\", constraints: [{ minVersion: \"1.1.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\", \"Cardano\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints latest version\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"Bitcoin\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"MyShitCoin\", constraints: [{ minVersion: \"latest\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Ethereum\", version: \"1.6.0\" }],\n alreadyInstalled: [\"Bitcoin\", \"MyShitCoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with dependencies\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"AlreadyInstalledDep\", version: \"1.2.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n { versionName: \"Cardano\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"AlreadyInstalledDep\",\n version: \"1.2.0\",\n parentName: \"Cardano\",\n },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"MyEthShitCoin\" },\n { name: \"MySolShitCoin\" },\n { name: \"Solana\" },\n { name: \"MyPumpFunShitCoin\" },\n { name: \"AlreadyInstalledDep\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n ],\n alreadyInstalled: [\"AlreadyInstalledDep\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with allowed missing applications\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: true,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Solana\", version: \"1.2.0\" }],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [\"Cardano\"],\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device apps metadata not fetched\"),\n });\n });\n\n it(\"Error when an app is not found in the catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Bitcoin\" },\n { name: \"Solana\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\n \"Application Ethereum not found in the catalog\",\n ),\n });\n });\n\n it(\"Error when an app version is not found in the catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum not found in the catalog\",\n ),\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAA8B,mCAC9BC,EAA6B,oCAC7BC,EAAgD,6DAChDC,EAGO,wCAGPC,EAAuC,kDAGvCC,EAAyC,sCAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,KAAU,mCAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAQ,eAAe,gBAAgB,CACrC,GAAI,gBAAc,MACpB,CAAoC,CACtC,CAAC,EAED,GAAG,iCAAkC,IAAM,CAEzCA,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CACb,CAAE,YAAa,WAAY,QAAS,OAAQ,EAC5C,CAAE,YAAa,UAAW,QAAS,OAAQ,CAC7C,EACA,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CAAC,CAAE,KAAM,UAAW,EAAG,CAAE,KAAM,SAAU,CAAC,EACxD,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,YAAa,CAAC,EACd,iBAAkB,CAAC,WAAY,SAAS,EACxC,oBAAqB,CAAC,CACxB,CAAC,CACH,CAAC,EAED,GAAG,8BAA+B,IAAM,CAEtCD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CACb,CAAE,YAAa,WAAY,QAAS,OAAQ,EAC5C,CAAE,YAAa,UAAW,QAAS,O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,MAAO,IAAI,iBAAe,kCAAkC,CAC9D,CAAC,CACH,CAAC,EAED,GAAG,gDAAiD,IAAM,CAExDD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CACZ,CAAE,KAAM,UAAW,EACnB,CAAE,KAAM,SAAU,EAClB,CAAE,KAAM,QAAS,CACnB,EACA,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,iBACT,+CACF,CACF,CAAC,CACH,CAAC,EAED,GAAG,wDAAyD,IAAM,CAEhED,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,QAAS,CACP,aAAc,CACZ,CAAE,YAAa,WAAY,QAAS,OAAQ,CAC9C,EACA,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CACZ,CACE,KAAM,WACN,YAAa,CAAC,CAAE,WAAY,OAAQ,CAAC,CACvC,CACF,EACA,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,6BACT,+CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport {\n UnknownDAError,\n UnsupportedApplicationDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type {\n DeviceSessionState,\n FirmwareUpdate,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { BuildAppsInstallPlanTask } from \"./BuildAppsInstallPlanTask\";\n\ndescribe(\"BuildAppsInstallPlanTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n id: DeviceModelId.NANO_X,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success with no changes needed\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }, { name: \"Bitcoin\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with no constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", applicableModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", exemptModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Solana\", constraints: [{ minVersion: \"1.2.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ],\n alreadyInstalled: [],\n missingApplications: [],\n });\n });\n\n it(\"Success with non-applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", exemptModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", applicableModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Cardano\", constraints: [{ minVersion: \"1.1.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\", \"Cardano\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints latest version\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"Bitcoin\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"MyShitCoin\", constraints: [{ minVersion: \"latest\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Ethereum\", version: \"1.6.0\" }],\n alreadyInstalled: [\"Bitcoin\", \"MyShitCoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with dependencies\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"AlreadyInstalledDep\", version: \"1.2.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n { versionName: \"Cardano\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"AlreadyInstalledDep\",\n version: \"1.2.0\",\n parentName: \"Cardano\",\n },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"MyEthShitCoin\" },\n { name: \"MySolShitCoin\" },\n { name: \"Solana\" },\n { name: \"MyPumpFunShitCoin\" },\n { name: \"AlreadyInstalledDep\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n ],\n alreadyInstalled: [\"AlreadyInstalledDep\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with allowed missing applications\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: true,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Solana\", version: \"1.2.0\" }],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [\"Cardano\"],\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device apps metadata not fetched\"),\n });\n });\n\n describe(\"Error cases for unsupported applications and firmwares\", () => {\n describe(\"when firmware is up to date\", () => {\n it(\"should throw `UnsupportedApplicationDAError` when application not found in catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedApplicationDAError(\n \"Application Ethereum not supported for this device\",\n ),\n });\n });\n it(\"should throw `UnsupportedApplicationDAError` when application version is not supported\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedApplicationDAError(\n \"Application Ethereum not supported for this device\",\n ),\n });\n });\n });\n describe(\"when firmware is out of date\", () => {\n it(\"should throw `UnsupportedFirmwareDAError` when application not found in catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n availableUpdate: {} as FirmwareUpdate,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum needs latest firmware\",\n ),\n });\n });\n it(\"should throw `UnsupportedFirmwareDAError` when application version is not supported\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n availableUpdate: {} as FirmwareUpdate,\n },\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum needs latest firmware\",\n ),\n });\n });\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA8B,mCAC9BC,EAA6B,oCAC7BC,EAAgD,6DAChDC,EAIO,wCAMPC,EAAuC,kDAIvCC,EAAyC,sCAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,KAAU,mCAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBA,EAAQ,eAAe,gBAAgB,CACrC,GAAI,gBAAc,MACpB,CAAoC,CACtC,CAAC,EAED,GAAG,iCAAkC,IAAM,CAEzCA,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CACb,CAAE,YAAa,WAAY,QAAS,OAAQ,EAC5C,CAAE,YAAa,UAAW,QAAS,OAAQ,CAC7C,EACA,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CAAC,CAAE,KAAM,UAAW,EAAG,CAAE,KAAM,SAAU,CAAC,EACxD,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,YAAa,CAAC,EACd,iBAAkB,CAAC,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c,CAC3B,MAAO,IAAI,gCACT,oDACF,CACF,CAAC,CACH,CAAC,CACH,CAAC,EACD,SAAS,+BAAgC,IAAM,CAC7C,GAAG,kFAAmF,IAAM,CAE1FD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,sBAAuB,CACrB,gBAAiB,CAAC,EAClB,gBAAiB,CAAC,CACpB,EACA,cAAe,CAAC,EAChB,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CAAC,CAAE,KAAM,UAAW,CAAC,EACnC,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,6BACT,4CACF,CACF,CAAC,CACH,CAAC,EACD,GAAG,sFAAuF,IAAM,CAE9FD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,CAAC,EAChB,sBAAuB,CACrB,gBAAiB,CAAC,EAClB,gBAAiB,CAAC,CACpB,EACA,QAAS,CACP,aAAc,CACZ,CAAE,YAAa,WAAY,QAAS,OAAQ,CAC9C,EACA,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMC,EAAS,IAAI,2BAAyBD,EAAS,CACnD,aAAc,CACZ,CACE,KAAM,WACN,YAAa,CAAC,CAAE,WAAY,OAAQ,CAAC,CACvC,CACF,EACA,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAI,6BACT,4CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_DeviceModel", "import_DeviceStatus", "import_makeInternalApi", "import_Errors", "import_DeviceSessionState", "import_BuildAppsInstallPlanTask", "apiMock", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(o,t)=>{for(var s in t)g(o,s,{get:t[s],enumerable:!0})},A=(o,t,s,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of x(t))!w.call(o,a)&&a!==s&&g(o,a,{get:()=>t[a],enumerable:!(u=I(t,a))||u.enumerable});return o};var F=o=>A(g({},"__esModule",{value:!0}),o);var M={};O(M,{GenuineCheckDeviceAction:()=>T});module.exports=F(M);var m=require("purify-ts"),n=require("xstate"),d=require("../../../command/model/CommandResult"),D=require("../../../command/os/GetOsVersionCommand"),l=require("../../../device-action/model/UserInteractionRequired"),V=require("../../../device-action/os/Const"),k=require("../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction"),C=require("../../../device-action/xstate-utils/XStateDeviceAction"),G=require("../../../device-session/DeviceSessionState"),f=require("../../../secure-channel/task/ConnectToSecureChannelTask"),h=require("../../../secure-channel/task/types"),E=require("../../../secure-channel/utils");class T extends C.XStateDeviceAction{makeStateMachine(t){const{getOsVersion:s,getDeviceVersion:u,getFirmwareVersion:a,genuineCheck:v,getDeviceSessionState:i,setDeviceSessionState:c}=this.extractDependencies(t),p=this.input.unlockTimeout??V.DEFAULT_UNLOCK_TIMEOUT_MS,S=new k.GoToDashboardDeviceAction({input:{unlockTimeout:p}}).makeStateMachine(t);return(0,n.setup)({types:{input:{},context:{},output:{}},actors:{goToDashboard:S,getOsVersion:(0,n.fromPromise)(s),getDeviceVersion:(0,n.fromPromise)(u),getFirmwareVersion:(0,n.fromPromise)(a),genuineCheck:(0,n.fromObservable)(v)},guards:{hasError:e=>e.context._internalState.error!==null},actions:{assignErrorFromEvent:(0,n.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GenuineCheckDeviceAction",initial:"DeviceReady",context:e=>({input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:l.UserInteractionRequired.None},_internalState:{error:null,result:{isGenuine:!1},getOsVersionResponse:null,deviceVersion:null,firmwareVersion:null}}),states:{DeviceReady:{always:{target:"GoToDashboard"}},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetOsVersion"}]},GetOsVersion:{invoke:{id:"getOsVersion",src:"getOsVersion",input:e=>{},onDone:{target:"GetOsVersionCheck",actions:(0,n.assign)({_internalState:e=>{if((0,d.isSuccessCommandResult)(e.event.output)){const r=i(),y=e.event.output.data.secureElementFlags.isSecureConnectionAllowed;return r.sessionStateType!==G.DeviceSessionStateType.Connected&&c({...r,isSecureConnectionAllowed:y}),{...e.context._internalState,getOsVersionResponse:e.event.output.data}}return{...e.context._internalState,error:e.event.output.error}}})}}},GetOsVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetDeviceVersion"}]},GetDeviceVersion:{invoke:{id:"getDeviceVersion",src:"getDeviceVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse}),onDone:{target:"GetDeviceVersionCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:r=>({...e.context._internalState,deviceVersion:r}),Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetFirmwareVersion"}]},GetFirmwareVersion:{invoke:{id:"getFirmwareVersion",src:"getFirmwareVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,deviceVersion:e.context._internalState.deviceVersion}),onDone:{target:"GetFirmwareVersionCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:r=>({...e.context._internalState,firmwareVersion:r}),Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetFirmwareVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GenuineCheck"}]},GenuineCheck:{invoke:{id:"genuineCheck",src:"genuineCheck",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,finalFirmware:e.context._internalState.firmwareVersion}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>{switch(e.event.snapshot.context?.type){case h.SecureChannelEventType.PermissionRequested:return{requiredUserInteraction:l.UserInteractionRequired.AllowSecureConnection};case h.SecureChannelEventType.PermissionGranted:return{requiredUserInteraction:l.UserInteractionRequired.None};default:return{...e.context.intermediateValue}}},_internalState:e=>e.event.snapshot.context?.type===h.SecureChannelEventType.Error?{...e.context._internalState,error:e.event.snapshot.context.error.mapDAErrors()}:e.event.snapshot.context?.type===h.SecureChannelEventType.Result?{...e.context._internalState,result:{isGenuine:(0,E.isDeviceGenuine)(e.event.snapshot.context.payload)}}:e.context._internalState})},onDone:{target:"GenuineCheckCheck"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GenuineCheckCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>e.context._internalState.error?(0,m.Left)(e.context._internalState.error):(0,m.Right)(e.context._internalState.result)})}extractDependencies(t){return{getOsVersion:()=>t.sendCommand(new D.GetOsVersionCommand),getDeviceVersion:({input:i})=>{const{deviceInfo:c}=i;return t.getManagerApiService().getDeviceVersion(c)},getFirmwareVersion:({input:i})=>{const{deviceInfo:c,deviceVersion:p}=i;return t.getManagerApiService().getFirmwareVersion(c,p)},genuineCheck:({input:i})=>{const{deviceInfo:c,finalFirmware:p}=i,S=t.getSecureChannelService().genuineCheck(c,p);return new f.ConnectToSecureChannelTask(t,{connection:S}).run()},getDeviceSessionState:()=>t.getDeviceSessionState(),setDeviceSessionState:i=>t.setDeviceSessionState(i)}}}0&&(module.exports={GenuineCheckDeviceAction});
1
+ "use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var O=(o,t)=>{for(var s in t)d(o,s,{get:t[s],enumerable:!0})},A=(o,t,s,p)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of E(t))!w.call(o,a)&&a!==s&&d(o,a,{get:()=>t[a],enumerable:!(p=y(t,a))||p.enumerable});return o};var F=o=>A(d({},"__esModule",{value:!0}),o);var M={};O(M,{GenuineCheckDeviceAction:()=>T});module.exports=F(M);var m=require("purify-ts"),n=require("xstate"),v=require("../../../command/model/CommandResult"),D=require("../../../command/os/GetOsVersionCommand"),l=require("../../../device-action/model/UserInteractionRequired"),V=require("../../../device-action/os/Const"),k=require("../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction"),C=require("../../../device-action/xstate-utils/XStateDeviceAction"),G=require("../../../device-session/DeviceSessionState"),f=require("../../../secure-channel/task/ConnectToSecureChannelTask"),u=require("../../../secure-channel/task/types"),x=require("../../../secure-channel/utils");class T extends C.XStateDeviceAction{makeStateMachine(t){const{getOsVersion:s,getDeviceVersion:p,getFirmwareVersion:a,genuineCheck:g,getDeviceSessionState:i,setDeviceSessionState:c}=this.extractDependencies(t),h=this.input.unlockTimeout??V.DEFAULT_UNLOCK_TIMEOUT_MS,S=new k.GoToDashboardDeviceAction({input:{unlockTimeout:h}}).makeStateMachine(t);return(0,n.setup)({types:{input:{},context:{},output:{}},actors:{goToDashboard:S,getOsVersion:(0,n.fromPromise)(s),getDeviceVersion:(0,n.fromPromise)(p),getFirmwareVersion:(0,n.fromPromise)(a),genuineCheck:(0,n.fromObservable)(g)},guards:{hasError:e=>e.context._internalState.error!==null},actions:{assignErrorFromEvent:(0,n.assign)({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GenuineCheckDeviceAction",initial:"DeviceReady",context:e=>({input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:l.UserInteractionRequired.None},_internalState:{error:null,result:{isGenuine:!1},getOsVersionResponse:null,deviceVersion:null,firmwareVersion:null}}),states:{DeviceReady:{always:{target:"GoToDashboard"}},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetOsVersion"}]},GetOsVersion:{invoke:{id:"getOsVersion",src:"getOsVersion",input:e=>{},onDone:{target:"GetOsVersionCheck",actions:(0,n.assign)({_internalState:e=>{if((0,v.isSuccessCommandResult)(e.event.output)){const r=i(),I=e.event.output.data.secureElementFlags.isSecureConnectionAllowed;return r.sessionStateType!==G.DeviceSessionStateType.Connected&&c({...r,isSecureConnectionAllowed:I}),{...e.context._internalState,getOsVersionResponse:e.event.output.data}}return{...e.context._internalState,error:e.event.output.error}}})}}},GetOsVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetDeviceVersion"}]},GetDeviceVersion:{invoke:{id:"getDeviceVersion",src:"getDeviceVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse}),onDone:{target:"GetDeviceVersionCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:r=>({...e.context._internalState,deviceVersion:r}),Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetFirmwareVersion"}]},GetFirmwareVersion:{invoke:{id:"getFirmwareVersion",src:"getFirmwareVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,deviceVersion:e.context._internalState.deviceVersion}),onDone:{target:"GetFirmwareVersionCheck",actions:(0,n.assign)({_internalState:e=>e.event.output.caseOf({Right:r=>({...e.context._internalState,firmwareVersion:r}),Left:r=>({...e.context._internalState,error:r})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetFirmwareVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GenuineCheck"}]},GenuineCheck:{invoke:{id:"genuineCheck",src:"genuineCheck",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,finalFirmware:e.context._internalState.firmwareVersion}),onSnapshot:{actions:(0,n.assign)({intermediateValue:e=>{switch(e.event.snapshot.context?.type){case u.SecureChannelEventType.DeviceId:return{...e.context.intermediateValue,deviceId:e.event.snapshot.context.payload.deviceId};case u.SecureChannelEventType.PermissionRequested:return{...e.context.intermediateValue,requiredUserInteraction:l.UserInteractionRequired.AllowSecureConnection};case u.SecureChannelEventType.PermissionGranted:return{...e.context.intermediateValue,requiredUserInteraction:l.UserInteractionRequired.None};default:return{...e.context.intermediateValue}}},_internalState:e=>e.event.snapshot.context?.type===u.SecureChannelEventType.Error?{...e.context._internalState,error:e.event.snapshot.context.error.mapDAErrors()}:e.event.snapshot.context?.type===u.SecureChannelEventType.Result?{...e.context._internalState,result:{isGenuine:(0,x.isDeviceGenuine)(e.event.snapshot.context.payload)}}:e.context._internalState})},onDone:{target:"GenuineCheckCheck"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GenuineCheckCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>e.context._internalState.error?(0,m.Left)(e.context._internalState.error):(0,m.Right)(e.context._internalState.result)})}extractDependencies(t){return{getOsVersion:()=>t.sendCommand(new D.GetOsVersionCommand),getDeviceVersion:({input:i})=>{const{deviceInfo:c}=i;return t.getManagerApiService().getDeviceVersion(c)},getFirmwareVersion:({input:i})=>{const{deviceInfo:c,deviceVersion:h}=i;return t.getManagerApiService().getFirmwareVersion(c,h)},genuineCheck:({input:i})=>{const{deviceInfo:c,finalFirmware:h}=i,S=t.getSecureChannelService().genuineCheck(c,h);return new f.ConnectToSecureChannelTask(t,{connection:S}).run()},getDeviceSessionState:()=>t.getDeviceSessionState(),setDeviceSessionState:i=>t.setDeviceSessionState(i)}}}0&&(module.exports={GenuineCheckDeviceAction});
2
2
  //# sourceMappingURL=GenuineCheckDeviceAction.js.map