@ledgerhq/device-management-kit 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +3 -3
- package/lib/cjs/src/api/index.js +1 -1
- package/lib/cjs/src/api/index.js.map +3 -3
- package/lib/cjs/src/api/types.js +1 -1
- package/lib/cjs/src/api/types.js.map +1 -1
- package/lib/cjs/src/api/utils/ApplicationChecker.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.js.map +7 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/cjs/src/api/utils/ApplicationResolver.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationResolver.js.map +7 -0
- package/lib/cjs/src/api/utils/Base64String.js +1 -1
- package/lib/cjs/src/api/utils/Base64String.js.map +3 -3
- package/lib/cjs/src/api/utils/Base64String.test.js +1 -1
- package/lib/cjs/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -0
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GoToDashboard/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GoToDashboard/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -0
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListApps/types.js +1 -0
- package/lib/esm/src/api/device-action/os/ListApps/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -0
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -0
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -0
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -0
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +4 -4
- package/lib/esm/src/api/index.js +1 -1
- package/lib/esm/src/api/index.js.map +3 -3
- package/lib/esm/src/api/utils/ApplicationChecker.js +2 -0
- package/lib/esm/src/api/utils/ApplicationChecker.js.map +7 -0
- package/lib/esm/src/api/utils/ApplicationChecker.test.js +2 -0
- package/lib/esm/src/api/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/esm/src/api/utils/ApplicationResolver.js +1 -0
- package/lib/esm/src/api/utils/ApplicationResolver.js.map +7 -0
- package/lib/esm/src/api/utils/Base64String.js +1 -1
- package/lib/esm/src/api/utils/Base64String.js.map +3 -3
- package/lib/esm/src/api/utils/Base64String.test.js +1 -1
- package/lib/esm/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts +7 -0
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
- package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts +9 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +13 -2
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +6 -0
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts +9 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +9 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListApps/ListAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListApps/types.d.ts +6 -0
- package/lib/types/src/api/device-action/os/ListApps/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts +8 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +12 -2
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +8 -0
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts +9 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/src/api/index.d.ts +4 -2
- package/lib/types/src/api/index.d.ts.map +1 -1
- package/lib/types/src/api/types.d.ts +1 -0
- package/lib/types/src/api/types.d.ts.map +1 -1
- package/lib/types/src/api/utils/ApplicationChecker.d.ts +14 -0
- package/lib/types/src/api/utils/ApplicationChecker.d.ts.map +1 -0
- package/lib/types/src/api/utils/ApplicationChecker.test.d.ts +2 -0
- package/lib/types/src/api/utils/ApplicationChecker.test.d.ts.map +1 -0
- package/lib/types/src/api/utils/ApplicationResolver.d.ts +12 -0
- package/lib/types/src/api/utils/ApplicationResolver.d.ts.map +1 -0
- package/lib/types/src/api/utils/Base64String.d.ts +1 -0
- package/lib/types/src/api/utils/Base64String.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as d,Right as
|
|
1
|
+
import{Left as d,Right as M}from"purify-ts";import{assign as n,fromCallback as D,fromPromise as y,setup as m}from"xstate";import{UserInteractionRequired as u}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as L}from"../../../device-action/os/Const";import{ListAppsDeviceAction as v}from"../../../device-action/os/ListApps/ListAppsDeviceAction";import{XStateDeviceAction as g}from"../../../device-action/xstate-utils/XStateDeviceAction";import{listAppsWithMetadataDAStateStep as A}from"./types";class F extends g{makeStateMachine(a){const{getAppsByHash:c,setDeviceSessionState:i,getDeviceSessionState:r}=this.extractDependencies(a),s=this.input.unlockTimeout??L,p=new v({input:{unlockTimeout:s}}).makeStateMachine(a);return m({types:{input:{unlockTimeout:s},context:{},output:{}},actors:{listApps:p,getAppsByHash:y(c),updateDeviceSessionState:D(({input:t,sendBack:e})=>{const{appsWithMetadata:h}=t,S=h.filter(o=>o!==null),l={...r(),installedApps:S};try{i(l),e({type:"done"})}catch(o){e({type:"error",error:o})}})},guards:{hasError:({context:t})=>t._internalState.error!==null,hasNoAppsInstalled:({context:t})=>t._internalState.apps.length===0},actions:{assignErrorFromEvent:n({_internalState:t=>({...t.context._internalState,error:t.event.error})})}}).createMachine({id:"ListAppsWithMetadataDeviceAction",initial:"DeviceReady",context:t=>({input:t.input,_internalState:{error:null,apps:[],appsWithMetadata:[]},intermediateValue:{requiredUserInteraction:u.None,step:A.LIST_APPS}}),states:{DeviceReady:{always:{target:"ListApps"}},ListApps:{invoke:{id:"listApps",src:"listApps",input:t=>({unlockTimeout:t.context.input.unlockTimeout}),onSnapshot:{actions:n({intermediateValue:t=>t.event.snapshot.context.intermediateValue})},onDone:{target:"ListAppsCheck",actions:n({intermediateValue:t=>({requiredUserInteraction:u.None,step:A.LIST_APPS}),_internalState:t=>t.event.output.caseOf({Right:e=>({...t.context._internalState,apps:e}),Left:e=>({...t.context._internalState,error:e})})})}}},ListAppsCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"hasNoAppsInstalled",actions:n({_internalState:t=>({...t.context._internalState,appsWithMetadata:[]})})},{target:"FetchMetadata"}]},FetchMetadata:{invoke:{id:"getAppsByHash",src:"getAppsByHash",input:t=>t.context._internalState.apps,onDone:{target:"FetchMetadataCheck",actions:n({_internalState:t=>t.event.output.caseOf({Right:e=>({...t.context._internalState,appsWithMetadata:e}),Left:e=>({...t.context._internalState,error:e})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},FetchMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"SaveSession"}]},SaveSession:{invoke:{src:"updateDeviceSessionState",input:t=>({appsWithMetadata:t.context._internalState.appsWithMetadata})},on:{done:{target:"Success"},error:{target:"Error",actions:"assignErrorFromEvent"}}},Success:{type:"final"},Error:{type:"final"}},output:t=>t.context._internalState.error?d(t.context._internalState.error):M(t.context._internalState.appsWithMetadata)})}extractDependencies(a){return{getAppsByHash:({input:i})=>{const r=i.reduce((s,p)=>p.appFullHash?s.concat(p.appFullHash):s,[]);return a.getManagerApiService().getAppsByHash(r)},getDeviceSessionState:()=>a.getDeviceSessionState(),setDeviceSessionState:i=>a.setDeviceSessionState(i)}}}export{F as ListAppsWithMetadataDeviceAction};
|
|
2
2
|
//# sourceMappingURL=ListAppsWithMetadataDeviceAction.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { type EitherAsync, Left, Right } from \"purify-ts\";\nimport {\n type AnyEventObject,\n assign,\n fromCallback,\n fromPromise,\n setup,\n} from \"xstate\";\n\nimport { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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 { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { type ListAppsDAOutput } from \"@api/device-action/os/ListApps/types\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport {\n type ListAppsWithMetadataDAError,\n type ListAppsWithMetadataDAInput,\n type ListAppsWithMetadataDAIntermediateValue,\n type ListAppsWithMetadataDAOutput,\n} from \"./types\";\n\ntype ListAppsWithMetadataMachineInternalState = {\n error: ListAppsWithMetadataDAError | null;\n apps: ListAppsResponse;\n appsWithMetadata: ListAppsWithMetadataDAOutput;\n};\n\nexport type MachineDependencies = {\n getAppsByHash: ({\n input,\n }: {\n input: ListAppsDAOutput;\n }) => EitherAsync<HttpFetchApiError, Array<Application | null>>;\n getDeviceSessionState: () => DeviceSessionState;\n setDeviceSessionState: (state: DeviceSessionState) => DeviceSessionState;\n};\n\nexport class ListAppsWithMetadataDeviceAction extends XStateDeviceAction<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n> {\n makeStateMachine(\n internalAPI: InternalApi,\n ): DeviceActionStateMachine<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n > {\n type types = StateMachineTypes<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n >;\n\n const { getAppsByHash, setDeviceSessionState, getDeviceSessionState } =\n this.extractDependencies(internalAPI);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const listAppsMachine = new ListAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalAPI);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n listApps: listAppsMachine,\n getAppsByHash: fromPromise(getAppsByHash),\n updateDeviceSessionState: fromCallback(\n ({\n input,\n sendBack,\n }: {\n sendBack: (event: AnyEventObject) => void;\n input: {\n appsWithMetadata: Array<Application | null>;\n };\n }) => {\n const { appsWithMetadata } = input;\n\n const filterted = appsWithMetadata.filter((app) => app !== null);\n\n const sessionState = getDeviceSessionState();\n const updatedState = {\n ...sessionState,\n installedApps: filterted,\n };\n try {\n setDeviceSessionState(updatedState);\n sendBack({ type: \"done\" });\n } catch (error) {\n sendBack({ type: \"error\", error });\n }\n },\n ),\n },\n guards: {\n hasError: ({ context }: { context: types[\"context\"] }) => {\n return context._internalState.error !== null;\n },\n hasNoAppsInstalled: ({ context }: { context: types[\"context\"] }) =>\n context._internalState.apps.length === 0,\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 /** @xstate-layout N4IgpgJg5mDOIC5QBkCWsAuBBADj2A6qhgBYCyYGAhhFdQCJgBuqAxmFqxqgPYB2AOkYt2AJTA0AngGIA2gAYAuolA4esYrz4qQAD0QBGAJzyBADgBsAdgNWAzPIAs8+TceOANCEmILAJjMBKwsHOyMjAzN7SIBfGK80TFx8IlIKaloGZjYOLi0BROw8WGkIfjABVD4mHgBrCoAbdCL8BWUkEDUNbn4dfQQAVgCBIz9IgacQ6z8-Lx8Ef1N5OwsBlbs7dyNHCziE5uTCYnJKGjoqYRzOHsFCw+kwACdHnkeBHAa6ADNXgFsBJpJYptHRdTS9Dr9IaBUbjSYrKwzOaIMwGAQTFx2MxmOx+AYDKxGAZ7EB3YqpE4Zc6XdjXfJk-AAYRIYFYtTkSlB6nB2khKKGAj89jCRjCFmWdmRCD8LiCGIMMysqIsCpJDKOaVOmQu2VpeX4BQOxWZrPZsgM7VU3JufX5fkFwvCYolUqVjkFyxlA3FeO9VjVRpSx3SZyyIlyN0NQKZLLZcj8ls61q0toQZgFQo2TqM4o2UosjjsQRC8iFa1GfiJAejGspoZ14bpBoAYpRWHXtaVypVqnUKjAWrAAEKSAASVFgJBBHTBNr5CAM7gsAkcY3TZmW-iMiPzm0Flkc2PX8gMTmrg4pIe1NIj+VbGHbV-OD2er3enwwP0e-wHhxH48nacrW6FN50XHYVzXAYNxWSsd28RA7GMQUMUcaCLFFTZdniUlA1rJ8wyufVBHvR8tXOE04yApMQIhUB+kiVYBFLTYbBmPwCwsKUdjRRxghVMwAlWSIjHPQ5L3Iwi9UjUiOwo2MzQtLlaN5ejDEsAZmL8ViFRmTj8wLSDt3kbFtzGZYxPJYNJIbIjIwAZSoJgwHsuANH4Ls+DAajZ1AtTpQ4wJnH8UyHB9fNgiMjCzCdcUzEcSyg01KkpNvA1HOc1zYHcvgXxeR4fOTOi9EQPSgvkEKYrC0spQJIwRn4pw8QLAwQjiHC+B4CA4B0dUJJS2zpL8mieVTABaLiEIQMbNPCOb5vmyxEvwmybybQQb3EKRlNG+dV3zIVizCxwc3sPxlv6+s1uIqNBx2ud-ICWa1lPexsWMb18ycQUS3FfEFTsb0LusgbrsjdVKNqe7hv6CwogECwCxPQGhSsNCjHzVdmIMMKBgMBV8eMYHkqu3U0pIts5OoaHioY093QCEwMNFJV5Gg-NInRHGKoqnNSzR4mqcG8mBFkgiqEhmnVJKhdVndQTlncKxXCsfF829H6HFsEJvSFbD9hrS7rzJ9aBAyly3OG3zadK-nzAGUUzKsQlxQxqaQnq2xt1XNnnBMuxBfFsH8nsgBXVh2GyqXUzxCqBEB7YxlXGLIisV0cy5sLlcR53RUD1aTZugBRV9Hmj+dY+XBPV0XRnU9qyxzGiiqNwmOxgnamIgA */\n id: \"ListAppsWithMetadataDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: _.input,\n _internalState: {\n error: null,\n apps: [],\n appsWithMetadata: [],\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"ListApps\",\n },\n },\n ListApps: {\n invoke: {\n id: \"listApps\",\n src: \"listApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n actions: assign({\n intermediateValue: (_) => ({\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n _internalState: (_) => {\n return _.event.output.caseOf({\n Right: (apps) => ({\n ..._.context._internalState,\n apps,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n });\n },\n }),\n },\n },\n },\n ListAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasNoAppsInstalled\",\n actions: assign({\n _internalState: (_) => {\n return {\n ..._.context._internalState,\n appsWithMetadata: [],\n };\n },\n }),\n },\n {\n target: \"FetchMetadata\",\n },\n ],\n },\n FetchMetadata: {\n invoke: {\n id: \"getAppsByHash\",\n src: \"getAppsByHash\",\n input: (_) => _.context._internalState.apps,\n onDone: {\n target: \"FetchMetadataCheck\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf({\n Right: (appsWithMetadata) => ({\n ..._.context._internalState,\n appsWithMetadata,\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 FetchMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"SaveSession\",\n },\n ],\n },\n SaveSession: {\n invoke: {\n src: \"updateDeviceSessionState\",\n input: (_) => ({\n appsWithMetadata: _.context._internalState.appsWithMetadata,\n }),\n },\n on: {\n done: {\n target: \"Success\",\n },\n error: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (_) => {\n if (_.context._internalState.error) {\n return Left(_.context._internalState.error);\n }\n\n return Right(_.context._internalState.appsWithMetadata);\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppsByHash = ({ input }: { input: ListAppsDAOutput }) => {\n const appHashes = input.reduce<string[]>((acc, app) => {\n if (app.appFullHash) {\n return acc.concat(app.appFullHash);\n }\n return acc;\n }, []);\n return internalApi.getManagerApiService().getAppsByHash(appHashes);\n };\n return {\n getAppsByHash,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAA2B,QAAAA,EAAM,SAAAC,MAAa,YAC9C,OAEE,UAAAC,EACA,gBAAAC,EACA,eAAAC,EACA,SAAAC,MACK,SAIP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,wBAAAC,MAA4B,sDAGrC,OAEE,sBAAAC,MACK,
|
|
6
|
-
"names": ["Left", "Right", "assign", "fromCallback", "fromPromise", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "ListAppsDeviceAction", "XStateDeviceAction", "ListAppsWithMetadataDeviceAction", "internalAPI", "getAppsByHash", "setDeviceSessionState", "getDeviceSessionState", "unlockTimeout", "listAppsMachine", "input", "sendBack", "appsWithMetadata", "filterted", "app", "updatedState", "error", "context", "_", "apps", "internalApi", "appHashes", "acc", "state"]
|
|
4
|
+
"sourcesContent": ["import { type EitherAsync, Left, Right } from \"purify-ts\";\nimport {\n type AnyEventObject,\n assign,\n fromCallback,\n fromPromise,\n setup,\n} from \"xstate\";\n\nimport { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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 { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport { type ListAppsDAOutput } from \"@api/device-action/os/ListApps/types\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport {\n type ListAppsWithMetadataDAError,\n type ListAppsWithMetadataDAInput,\n type ListAppsWithMetadataDAIntermediateValue,\n type ListAppsWithMetadataDAOutput,\n listAppsWithMetadataDAStateStep,\n} from \"./types\";\n\ntype ListAppsWithMetadataMachineInternalState = {\n error: ListAppsWithMetadataDAError | null;\n apps: ListAppsResponse;\n appsWithMetadata: ListAppsWithMetadataDAOutput;\n};\n\nexport type MachineDependencies = {\n getAppsByHash: ({\n input,\n }: {\n input: ListAppsDAOutput;\n }) => EitherAsync<HttpFetchApiError, Array<Application | null>>;\n getDeviceSessionState: () => DeviceSessionState;\n setDeviceSessionState: (state: DeviceSessionState) => DeviceSessionState;\n};\n\nexport class ListAppsWithMetadataDeviceAction extends XStateDeviceAction<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n> {\n makeStateMachine(\n internalAPI: InternalApi,\n ): DeviceActionStateMachine<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n > {\n type types = StateMachineTypes<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAInput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue,\n ListAppsWithMetadataMachineInternalState\n >;\n\n const { getAppsByHash, setDeviceSessionState, getDeviceSessionState } =\n this.extractDependencies(internalAPI);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const listAppsMachine = new ListAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalAPI);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n listApps: listAppsMachine,\n getAppsByHash: fromPromise(getAppsByHash),\n updateDeviceSessionState: fromCallback(\n ({\n input,\n sendBack,\n }: {\n sendBack: (event: AnyEventObject) => void;\n input: {\n appsWithMetadata: Array<Application | null>;\n };\n }) => {\n const { appsWithMetadata } = input;\n\n const filterted = appsWithMetadata.filter((app) => app !== null);\n\n const sessionState = getDeviceSessionState();\n const updatedState = {\n ...sessionState,\n installedApps: filterted,\n };\n try {\n setDeviceSessionState(updatedState);\n sendBack({ type: \"done\" });\n } catch (error) {\n sendBack({ type: \"error\", error });\n }\n },\n ),\n },\n guards: {\n hasError: ({ context }: { context: types[\"context\"] }) => {\n return context._internalState.error !== null;\n },\n hasNoAppsInstalled: ({ context }: { context: types[\"context\"] }) =>\n context._internalState.apps.length === 0,\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 /** @xstate-layout N4IgpgJg5mDOIC5QBkCWsAuBBADj2A6qhgBYCyYGAhhFdQCJgBuqAxmFqxqgPYB2AOkYt2AJTA0AngGIA2gAYAuolA4esYrz4qQAD0QBGAJzyBADgBsAdgNWAzPIAs8+TceOANCEmILAJjMBKwsHOyMjAzN7SIBfGK80TFx8IlIKaloGZjYOLi0BROw8WGkIfjABVD4mHgBrCoAbdCL8BWUkEDUNbn4dfQQAVgCBIz9IgacQ6z8-Lx8Ef1N5OwsBlbs7dyNHCziE5uTCYnJKGjoqYRzOHsFCw+kwACdHnkeBHAa6ADNXgFsBJpJYptHRdTS9Dr9IaBUbjSYrKwzOaIMwGAQTFx2MxmOx+AYDKxGAZ7EB3YqpE4Zc6XdjXfJk-AAYRIYFYtTkSlB6nB2khKKGAj89jCRjCFmWdmRCD8LiCGIMMysqIsCpJDKOaVOmQu2VpeX4BQOxWZrPZsgM7VU3JufX5fkFwvCYolUqVjkFyxlA3FeO9VjVRpSx3SZyyIlyN0NQKZLLZcj8ls61q0toQZgFQo2TqM4o2UosjjsQRC8iFa1GfiJAejGspoZ14bpBoAYpRWHXtaVypVqnUKjAWrAAEKSAASVFgJBBHTBNr5CAM7gsAkcY3TZmW-iMiPzm0Flkc2PX8gMTmrg4pIe1NIj+VbGHbV-OD2er3enwwP0e-wHhxH48nacrW6FN50XHYVzXAYNxWSsd28RA7GMQUMUcaCLFFTZdniUlA1rJ8wyufVBHvR8tXOE04yApMQIhUB+kiVYBFLTYbBmPwCwsKUdjRRxghVMwAlWSIjHPQ5L3Iwi9UjUiOwo2MzQtLlaN5ejDEsAZmL8ViFRmTj8wLSDt3kbFtzGZYxPJYNJIbIjIwAZSoJgwHsuANH4Ls+DAajZ1AtTpQ4wJnH8UyHB9fNgiMjCzCdcUzEcSyg01KkpNvA1HOc1zYHcvgXxeR4fOTOi9EQPSgvkEKYrC0spQJIwRn4pw8QLAwQjiHC+B4CA4B0dUJJS2zpL8mieVTABaLiEIQMbNPCOb5vmyxEvwmybybQQb3EKRlNG+dV3zIVizCxwc3sPxlv6+s1uIqNBx2ud-ICWa1lPexsWMb18ycQUS3FfEFTsb0LusgbrsjdVKNqe7hv6CwogECwCxPQGhSsNCjHzVdmIMMKBgMBV8eMYHkqu3U0pIts5OoaHioY093QCEwMNFJV5Gg-NInRHGKoqnNSzR4mqcG8mBFkgiqEhmnVJKhdVndQTlncKxXCsfF829H6HFsEJvSFbD9hrS7rzJ9aBAyly3OG3zadK-nzAGUUzKsQlxQxqaQnq2xt1XNnnBMuxBfFsH8nsgBXVh2GyqXUzxCqBEB7YxlXGLIisV0cy5sLlcR53RUD1aTZugBRV9Hmj+dY+XBPV0XRnU9qyxzGiiqNwmOxgnamIgA */\n id: \"ListAppsWithMetadataDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: _.input,\n _internalState: {\n error: null,\n apps: [],\n appsWithMetadata: [],\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"ListApps\",\n },\n },\n ListApps: {\n invoke: {\n id: \"listApps\",\n src: \"listApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n actions: assign({\n intermediateValue: (_) => ({\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n }),\n _internalState: (_) => {\n return _.event.output.caseOf({\n Right: (apps) => ({\n ..._.context._internalState,\n apps,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n });\n },\n }),\n },\n },\n },\n ListAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasNoAppsInstalled\",\n actions: assign({\n _internalState: (_) => {\n return {\n ..._.context._internalState,\n appsWithMetadata: [],\n };\n },\n }),\n },\n {\n target: \"FetchMetadata\",\n },\n ],\n },\n FetchMetadata: {\n invoke: {\n id: \"getAppsByHash\",\n src: \"getAppsByHash\",\n input: (_) => _.context._internalState.apps,\n onDone: {\n target: \"FetchMetadataCheck\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf({\n Right: (appsWithMetadata) => ({\n ..._.context._internalState,\n appsWithMetadata,\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 FetchMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"SaveSession\",\n },\n ],\n },\n SaveSession: {\n invoke: {\n src: \"updateDeviceSessionState\",\n input: (_) => ({\n appsWithMetadata: _.context._internalState.appsWithMetadata,\n }),\n },\n on: {\n done: {\n target: \"Success\",\n },\n error: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (_) => {\n if (_.context._internalState.error) {\n return Left(_.context._internalState.error);\n }\n\n return Right(_.context._internalState.appsWithMetadata);\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppsByHash = ({ input }: { input: ListAppsDAOutput }) => {\n const appHashes = input.reduce<string[]>((acc, app) => {\n if (app.appFullHash) {\n return acc.concat(app.appFullHash);\n }\n return acc;\n }, []);\n return internalApi.getManagerApiService().getAppsByHash(appHashes);\n };\n return {\n getAppsByHash,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAA2B,QAAAA,EAAM,SAAAC,MAAa,YAC9C,OAEE,UAAAC,EACA,gBAAAC,EACA,eAAAC,EACA,SAAAC,MACK,SAIP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,wBAAAC,MAA4B,sDAGrC,OAEE,sBAAAC,MACK,qDAKP,OAKE,mCAAAC,MACK,UAkBA,MAAMC,UAAyCF,CAMpD,CACA,iBACEG,EAOA,CASA,KAAM,CAAE,cAAAC,EAAe,sBAAAC,EAAuB,sBAAAC,CAAsB,EAClE,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,MAAM,eAAiBT,EAE5CU,EAAkB,IAAIT,EAAqB,CAC/C,MAAO,CACL,cAAAQ,CACF,CACF,CAAC,EAAE,iBAAiBJ,CAAW,EAE/B,OAAOP,EAAM,CACX,MAAO,CACL,MAAO,CACL,cAAAW,CACF,EACA,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAAUC,EACV,cAAeb,EAAYS,CAAa,EACxC,yBAA0BV,EACxB,CAAC,CACC,MAAAe,EACA,SAAAC,CACF,IAKM,CACJ,KAAM,CAAE,iBAAAC,CAAiB,EAAIF,EAEvBG,EAAYD,EAAiB,OAAQE,GAAQA,IAAQ,IAAI,EAGzDC,EAAe,CACnB,GAFmBR,EAAsB,EAGzC,cAAeM,CACjB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ACCQ,EAAI,OAAOR,EAAI,WAAW,EAE5BQ,EACN,CAAC,CAAC,EACL,OAAOF,EAAY,qBAAqB,EAAE,cAAcC,CAAS,CACnE,EAGE,sBAAuB,IAAMD,EAAY,sBAAsB,EAC/D,sBAAwBG,GACtBH,EAAY,sBAAsBG,CAAK,CAC3C,CACF,CACF",
|
|
6
|
+
"names": ["Left", "Right", "assign", "fromCallback", "fromPromise", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "ListAppsDeviceAction", "XStateDeviceAction", "listAppsWithMetadataDAStateStep", "ListAppsWithMetadataDeviceAction", "internalAPI", "getAppsByHash", "setDeviceSessionState", "getDeviceSessionState", "unlockTimeout", "listAppsMachine", "input", "sendBack", "appsWithMetadata", "filterted", "app", "updatedState", "error", "context", "_", "apps", "internalApi", "appHashes", "acc", "state"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as M,Right as
|
|
1
|
+
import{Left as M,Right as P}from"purify-ts";import{DeviceStatus as T}from"../../../device/DeviceStatus";import{BTC_APP as S,BTC_APP_METADATA as A,CUSTOM_LOCK_SCREEN_APP as V,CUSTOM_LOCK_SCREEN_APP_METADATA as L,ETH_APP as _,ETH_APP_METADATA as g}from"../../../device-action/__test-utils__/data";import{makeDeviceActionInternalApiMock as o}from"../../../device-action/__test-utils__/makeInternalApi";import{setupListAppsMock as p}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as c}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as e}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as t}from"../../../device-action/model/UserInteractionRequired";import{UnknownDAError as m}from"../../../device-action/os/Errors";import{listAppsDAStateStep as d}from"../../../device-action/os/ListApps/types";import{DeviceSessionStateType as f}from"../../../device-session/DeviceSessionState";import{HttpFetchApiError as k}from"../../../../internal/manager-api/model/Errors";import{ListAppsWithMetadataDeviceAction as u}from"./ListAppsWithMetadataDeviceAction";import{listAppsWithMetadataDAStateStep as i}from"./types";vi.mock("@api/device-action/os/ListApps/ListAppsDeviceAction");describe("ListAppsWithMetadataDeviceAction",()=>{const{getManagerApiService:l}=o(),v=vi.fn(),h=vi.fn(),I=vi.fn();function w(){return{getAppsByHash:I,getDeviceSessionState:h,setDeviceSessionState:v}}beforeEach(()=>{vi.resetAllMocks()}),describe("success case",()=>{it("should run the device actions with no apps installed",()=>new Promise((r,a)=>{p([]);const s=new u({input:{}});l.mockReturnValue({getAppsByHash:vi.fn().mockResolvedValue(P([]))});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{status:e.Completed,output:[]}];c(s,n,o(),{onDone:r,onError:a})})),it("should run the device actions with 1 app installed",()=>new Promise((r,a)=>{p([S]);const s=new u({input:{}});l.mockReturnValue({getAppsByHash:vi.fn().mockResolvedValue(P([A]))});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Completed,output:[A]}];c(s,n,o(),{onDone:r,onError:a})})),it("should run the device actions with 2 apps installed",()=>new Promise((r,a)=>{p([S,_]);const s=new u({input:{}});l.mockReturnValue({getAppsByHash:vi.fn().mockResolvedValue(P([A,g]))});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Completed,output:[A,g]}];c(s,n,o(),{onDone:r,onError:a})})),it("should run the device actions with 1 app installed and a custom lock screen",()=>new Promise((r,a)=>{p([S,V]);const s=new u({input:{}});l.mockReturnValue({getAppsByHash:vi.fn().mockResolvedValue(P([A,L]))});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Completed,output:[A,L]}];c(s,n,o(),{onDone:r,onError:a})}))}),describe("error case",()=>{it("should error when ListApps fails",()=>new Promise((r,a)=>{p([],!0);const s=new u({input:{}}),n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{status:e.Error,error:new m("ListApps failed")}];c(s,n,o(),{onDone:r,onError:a})})),it("should error when getAppsByHash rejects",()=>new Promise((r,a)=>{p([S]);const s=new u({input:{}});l.mockReturnValue({getAppsByHash:vi.fn().mockRejectedValue(new m("getAppsByHash failed"))});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Error,error:new m("getAppsByHash failed")}];c(s,n,o(),{onDone:r,onError:a})})),it("should error when getAppsByHash fails but error is known",()=>new Promise((r,a)=>{p([S]);const s=new u({input:{}}),n=new k(new Error("Failed to fetch data"));l.mockReturnValue({getAppsByHash:vi.fn().mockResolvedValue(M(n))});const D=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Error,error:n}];c(s,D,o(),{onDone:r,onError:a})})),it("should error when SaveSession fails",()=>new Promise((r,a)=>{p([S]);const s=new u({input:{}});I.mockImplementation(async()=>Promise.resolve(P([A]))),vi.spyOn(s,"extractDependencies").mockReturnValue(w()),h.mockReturnValue({sessionStateType:f.ReadyWithoutSecureChannel,deviceStatus:T.CONNECTED,currentApp:"BOLOS",installedApps:[]}),v.mockImplementation(()=>{throw new m("SaveSession failed")});const n=[{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps,step:d.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None,step:i.LIST_APPS},status:e.Pending},{status:e.Error,error:new m("SaveSession failed")}];c(s,n,o(),{onDone:r,onError:a})}))})});
|
|
2
2
|
//# sourceMappingURL=ListAppsWithMetadataDeviceAction.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n ETH_APP,\n ETH_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { setupListAppsMock } from \"@api/device-action/__test-utils__/setupTestMachine\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport { DeviceActionStatus } from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { ListAppsWithMetadataDeviceAction } from \"./ListAppsWithMetadataDeviceAction\";\nimport { type ListAppsWithMetadataDAState } from \"./types\";\n\nvi.mock(\"@api/device-action/os/ListApps/ListAppsDeviceAction\");\n\ndescribe(\"ListAppsWithMetadataDeviceAction\", () => {\n const { getManagerApiService: getManagerApiServiceMock } =\n makeDeviceActionInternalApiMock();\n\n const setDeviceSessionStateMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const getAppsByHashMock = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getAppsByHash: getAppsByHashMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"success case\", () => {\n it(\"should run the device actions with no apps installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Right([])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n status: DeviceActionStatus.Completed,\n output: [],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 1 app installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Right([BTC_APP_METADATA])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 2 apps installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP, ETH_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockResolvedValue(Right([BTC_APP_METADATA, ETH_APP_METADATA])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA, ETH_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 1 app installed and a custom lock screen\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP, CUSTOM_LOCK_SCREEN_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockResolvedValue(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n ),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"error case\", () => {\n it(\"should error when ListApps fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([], true);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"ListApps failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when getAppsByHash rejects\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockRejectedValue(new UnknownDAError(\"getAppsByHash failed\")),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"getAppsByHash failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when getAppsByHash fails but error is known\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n const error = new HttpFetchApiError(new Error(\"Failed to fetch data\"));\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Left(error)),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n status: DeviceActionStatus.Error,\n error,\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when SaveSession fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getAppsByHashMock.mockImplementation(async () =>\n Promise.resolve(Right([BTC_APP_METADATA])),\n );\n\n vi.spyOn(\n listAppsWithMetadataDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: \"BOLOS\",\n installedApps: [],\n });\n\n setDeviceSessionStateMock.mockImplementation(() => {\n throw new UnknownDAError(\"SaveSession failed\");\n });\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"SaveSession failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,gBAAAC,MAAoB,2BAC7B,OACE,WAAAC,EACA,oBAAAC,EACA,0BAAAC,EACA,mCAAAC,EACA,WAAAC,EACA,oBAAAC,MACK,yCACP,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,qBAAAC,MAAyB,qDAClC,OAAS,0BAAAC,MAA8B,2DACvC,OAAS,sBAAAC,MAA0B,6CACnC,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,qBAAAC,MAAyB,qCAGlC,OAAS,oCAAAC,MAAwC,
|
|
6
|
-
"names": ["Left", "Right", "DeviceStatus", "BTC_APP", "BTC_APP_METADATA", "CUSTOM_LOCK_SCREEN_APP", "CUSTOM_LOCK_SCREEN_APP_METADATA", "ETH_APP", "ETH_APP_METADATA", "makeDeviceActionInternalApiMock", "setupListAppsMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "DeviceSessionStateType", "HttpFetchApiError", "ListAppsWithMetadataDeviceAction", "getManagerApiServiceMock", "setDeviceSessionStateMock", "getDeviceSessionStateMock", "getAppsByHashMock", "extractDependenciesMock", "resolve", "reject", "listAppsWithMetadataDeviceAction", "expectedStates", "error"]
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n ETH_APP,\n ETH_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { setupListAppsMock } from \"@api/device-action/__test-utils__/setupTestMachine\";\nimport { testDeviceActionStates } from \"@api/device-action/__test-utils__/testDeviceActionStates\";\nimport { DeviceActionStatus } from \"@api/device-action/model/DeviceActionState\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { UnknownDAError } from \"@api/device-action/os/Errors\";\nimport { listAppsDAStateStep } from \"@api/device-action/os/ListApps/types\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { ListAppsWithMetadataDeviceAction } from \"./ListAppsWithMetadataDeviceAction\";\nimport {\n type ListAppsWithMetadataDAState,\n listAppsWithMetadataDAStateStep,\n} from \"./types\";\n\nvi.mock(\"@api/device-action/os/ListApps/ListAppsDeviceAction\");\n\ndescribe(\"ListAppsWithMetadataDeviceAction\", () => {\n const { getManagerApiService: getManagerApiServiceMock } =\n makeDeviceActionInternalApiMock();\n\n const setDeviceSessionStateMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const getAppsByHashMock = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getAppsByHash: getAppsByHashMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n };\n }\n\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n describe(\"success case\", () => {\n it(\"should run the device actions with no apps installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Right([])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n status: DeviceActionStatus.Completed,\n output: [],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 1 app installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Right([BTC_APP_METADATA])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 2 apps installed\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP, ETH_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockResolvedValue(Right([BTC_APP_METADATA, ETH_APP_METADATA])),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA, ETH_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device actions with 1 app installed and a custom lock screen\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP, CUSTOM_LOCK_SCREEN_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockResolvedValue(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n ),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Completed,\n output: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"error case\", () => {\n it(\"should error when ListApps fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([], true);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"ListApps failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when getAppsByHash rejects\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi\n .fn()\n .mockRejectedValue(new UnknownDAError(\"getAppsByHash failed\")),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"getAppsByHash failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when getAppsByHash fails but error is known\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n const error = new HttpFetchApiError(new Error(\"Failed to fetch data\"));\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: vi.fn().mockResolvedValue(Left(error)),\n } as unknown as ManagerApiService);\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n status: DeviceActionStatus.Error,\n error,\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should error when SaveSession fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getAppsByHashMock.mockImplementation(async () =>\n Promise.resolve(Right([BTC_APP_METADATA])),\n );\n\n vi.spyOn(\n listAppsWithMetadataDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: \"BOLOS\",\n installedApps: [],\n });\n\n setDeviceSessionStateMock.mockImplementation(() => {\n throw new UnknownDAError(\"SaveSession failed\");\n });\n\n const expectedStates: Array<ListAppsWithMetadataDAState> = [\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // Ready\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.AllowListApps,\n step: listAppsDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // ListAppsDeviceAction\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // FetchMetadata\n },\n {\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: listAppsWithMetadataDAStateStep.LIST_APPS,\n },\n status: DeviceActionStatus.Pending, // SaveSession\n },\n {\n status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"SaveSession failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,gBAAAC,MAAoB,2BAC7B,OACE,WAAAC,EACA,oBAAAC,EACA,0BAAAC,EACA,mCAAAC,EACA,WAAAC,EACA,oBAAAC,MACK,yCACP,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,qBAAAC,MAAyB,qDAClC,OAAS,0BAAAC,MAA8B,2DACvC,OAAS,sBAAAC,MAA0B,6CACnC,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,kBAAAC,MAAsB,+BAC/B,OAAS,uBAAAC,MAA2B,uCACpC,OAAS,0B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EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,cACjD,KAAME,EAAoB,SAC5B,EACA,OAAQH,EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,KACjD,KAAMM,EAAgC,SACxC,EACA,OAAQP,EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,KACjD,KAAMM,EAAgC,SACxC,EACA,OAAQP,EAAmB,OAC7B,EACA,CACE,OAAQA,EAAmB,MAC3B,MAAO,IAAIE,EAAe,oBAAoB,CAChD,CACF,EAEAH,EACEgB,EACAC,EACAnB,EAAgC,EAChC,CACE,OAAQgB,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["Left", "Right", "DeviceStatus", "BTC_APP", "BTC_APP_METADATA", "CUSTOM_LOCK_SCREEN_APP", "CUSTOM_LOCK_SCREEN_APP_METADATA", "ETH_APP", "ETH_APP_METADATA", "makeDeviceActionInternalApiMock", "setupListAppsMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "UnknownDAError", "listAppsDAStateStep", "DeviceSessionStateType", "HttpFetchApiError", "ListAppsWithMetadataDeviceAction", "listAppsWithMetadataDAStateStep", "getManagerApiServiceMock", "setDeviceSessionStateMock", "getDeviceSessionStateMock", "getAppsByHashMock", "extractDependenciesMock", "resolve", "reject", "listAppsWithMetadataDeviceAction", "expectedStates", "error"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [],
|
|
4
|
-
"sourcesContent": [],
|
|
5
|
-
"mappings": "",
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../../../../../../src/api/device-action/os/ListAppsWithMetadata/types.ts"],
|
|
4
|
+
"sourcesContent": ["import { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport { type ListAppsErrorCodes } from \"@api/command/os/ListAppsCommand\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { type UnknownDAError } from \"@api/device-action/os/Errors\";\nimport {\n type ListAppsDAError,\n type ListAppsDAInput,\n type ListAppsDAIntermediateValue,\n} from \"@api/device-action/os/ListApps/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nexport const listAppsWithMetadataDAStateStep = Object.freeze({\n LIST_APPS: \"os.listAppsWithMetadata.steps.listApps\",\n FETCH_METADATA: \"os.listAppsWithMetadata.steps.fetchMetadata\",\n SAVE_SESSION: \"os.listAppsWithMetadata.steps.saveSession\",\n} as const);\n\nexport type ListAppsWithMetadataDAStateStep =\n (typeof listAppsWithMetadataDAStateStep)[keyof typeof listAppsWithMetadataDAStateStep];\n\nexport type ListAppsWithMetadataDAOutput = Array<Application | null>;\nexport type ListAppsWithMetadataDAInput = ListAppsDAInput;\n\nexport type ListAppsWithMetadataDAError =\n | ListAppsDAError\n | UnknownDAError\n | HttpFetchApiError\n | CommandErrorResult<ListAppsErrorCodes>[\"error\"];\n\nexport type ListAppsWithMetadataDARequiredInteraction =\n UserInteractionRequired.None;\n\nexport type ListAppsWithMetadataDAIntermediateValue =\n | ListAppsDAIntermediateValue\n | {\n readonly requiredUserInteraction: ListAppsWithMetadataDARequiredInteraction;\n readonly step: ListAppsWithMetadataDAStateStep;\n };\n\nexport type ListAppsWithMetadataDAState = DeviceActionState<\n ListAppsWithMetadataDAOutput,\n ListAppsWithMetadataDAError,\n ListAppsWithMetadataDAIntermediateValue\n>;\n"],
|
|
5
|
+
"mappings": "AAaO,MAAMA,EAAkC,OAAO,OAAO,CAC3D,UAAW,yCACX,eAAgB,8CAChB,aAAc,2CAChB,CAAU",
|
|
6
|
+
"names": ["listAppsWithMetadataDAStateStep"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as D,Right as g}from"purify-ts";import{assign as t,fromPromise as c,setup as y}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as f}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as
|
|
1
|
+
import{Left as D,Right as g}from"purify-ts";import{assign as t,fromPromise as c,setup as y}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as f}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as C}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as R}from"../../../transport/model/Errors";import{isDashboardName as x}from"../../../utils/AppName";import{openAppDAStateStep as N}from"./types";class B extends C{makeStateMachine(r){const{closeApp:o,openApp:s,getDeviceSessionState:a,isDeviceOnboarded:A,setDeviceSessionState:d}=this.extractDependencies(r),S=this.input.unlockTimeout??h,m=new f({input:{unlockTimeout:S}}).makeStateMachine(r);return y({types:{input:{},context:{},output:{}},actors:{closeApp:c(o),openApp:c(s),getDeviceStatus:m},guards:{isDeviceOnboarded:()=>A(),isRequestedAppOpen:({context:e})=>e._internalState.currentlyRunningApp===null?!1:e._internalState.currentlyRunningApp===e.input.appName,isDashboardOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return x(e._internalState.currentlyRunningApp)},hasDisconnectedWhileSending:({context:e})=>e._internalState.error!==null&&e._internalState.error instanceof R,hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:t({_internalState:e=>({...e.context._internalState,error:new E})}),assignUserActionNeededOpenApp:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.ConfirmOpenApp})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoError:t({_internalState:e=>({...e.context._internalState,error:null})})}}).createMachine({id:"OpenAppDeviceAction",initial:"DeviceReady",context:({input:e})=>{const n=a(),{sessionStateType:p}=n;return{input:e,intermediateValue:{requiredUserInteraction:i.None,step:N.GET_DEVICE_STATUS},_internalState:{error:null,currentlyRunningApp:p===l.ReadyWithoutSecureChannel?n.currentApp.name:null}}},states:{DeviceReady:{always:{target:"OnboardingCheck"}},OnboardingCheck:{always:[{target:"GetDeviceStatus",guard:{type:"isDeviceOnboarded"}},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:t({_internalState:e=>e.event.output.caseOf({Right:n=>{const p=a();return p.sessionStateType!==l.Connected&&d({...p,currentApp:{name:n.currentApp,version:n.currentAppVersion}}),{...e.context._internalState,currentlyRunningApp:n.currentApp}},Left:n=>({...e.context._internalState,currentlyRunningApp:null,error:n})})})},onError:{target:"Error",actions:[t({_internalState:e=>({...e.context._internalState,currentlyRunningApp:null})}),"assignErrorFromEvent"]}}},CheckDeviceStatus:{always:[{target:"ApplicationReady",guard:"isRequestedAppOpen",actions:"assignNoError"},{target:"Error",guard:"hasError"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"OpenApplication",guard:"isDashboardOpen"},"CloseApplication"]},OpenApplication:{entry:"assignUserActionNeededOpenApp",exit:"assignNoUserActionNeeded",invoke:{src:"openApp",input:({context:e})=>({appName:e.input.appName}),onDone:{target:"OpenApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:e.context.input.appName}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"OpenApplicationResultCheck",actions:"assignErrorFromEvent"}}},OpenApplicationResultCheck:{always:[{target:"GetDeviceStatus",guard:"hasDisconnectedWhileSending"},{target:"Error",guard:"hasError"},{target:"GetDeviceStatus"}]},CloseApplication:{invoke:{src:"closeApp",onDone:{target:"CloseApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:"BOLOS"}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"OpenApplication"}]},ApplicationReady:{always:"Success"},Success:{type:"final",actions:"assignNoError"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?D(e._internalState.error):g(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new O),openApp:async a=>r.sendCommand(new v({appName:a.input.appName})),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a),isDeviceOnboarded:()=>!0}}}export{B as OpenAppDeviceAction};
|
|
2
2
|
//# sourceMappingURL=OpenAppDeviceAction.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceDisconnectedWhileSendingError } from \"@api/transport/model/Errors\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null) return false;\n return (\n context._internalState.currentlyRunningApp === context.input.appName\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return isDashboardName(context._internalState.currentlyRunningApp);\n },\n hasDisconnectedWhileSending: ({ context }) =>\n context._internalState.error !== null &&\n context._internalState.error instanceof\n DeviceDisconnectedWhileSendingError,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WB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dGKTSvXgLrFKSENcbsC4Hwa6i9eQHgQgmCkIlBjKmcEFUY24ejaSTMeCkHxPgYFoBAOAcgA5u1um3XkABaHeEoKEEkKvQwQJ4XjKl6ErIBDUmCenATwA2RM7rknUm4FUhV-oiTJFTCUth05j0xJVFUTxt7sIOssRIKRQRyV4bdWOTNkTqDekqAwbxNDIUzFIhwzhZHVHkf0akZ9rKFx1CyPI6j2SaJjsoUsBIBimB8MMeUZJqFdH6PYDwKYBjwQaEYpRtlOYzlfC2NxS8bB6HsM4RUIwiSH0VNxAy6lkL1EEjTYUtisLn1ISAhuDZZxvhvpsRJmVX51FJFlZ4-Qk5wUYcxR2BTTIGUKtEvCoDpwaMUobbqugUzIg8PmEwIiTJ9yqAMaUW90IngCaIgZcUEpJVUa1Vxoy+GVGMbvZiuVf5IM8CoTZOpNZDL4eQjcIlDLIRRH5FhoxDyIGFMiASe8IoFlGNchaS0waxNqfkepG4tACiMGeQw6IiQeBGncMaMycxEl8eoIFu0fiVPbg87qSE3q6MVBpehPQ4K6G+uoZUJIVB7laNiq+2s4DkRGYTLRygs6GSQtmO4iIaWljgvUBgip-K5RErofOdiYocLBZwHhBzOWSkKqKz6Lw3i6U+QgPchlTB7xTPBeCWVHDYoAMqflIOQWA8AlXuO6KMQylImipgMi4BZzhDIKkpM0FEypRimplXNWyABRMuSRIXjNaKvHQ3h0Q0reCYT+3khGNEKgqIRxgAgBCAA */\n id: \"OpenAppDeviceAction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n // check device capabilities & status known\n always: {\n target: \"OnboardingCheck\",\n },\n },\n\n OnboardingCheck: {\n // check onboarding status provided by device session\n always: [\n {\n target: \"GetDeviceStatus\",\n guard: {\n type: \"isDeviceOnboarded\",\n },\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n error,\n }),\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: [\n assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n }),\n }),\n \"assignErrorFromEvent\",\n ],\n },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n // If target app is currently opened, we can ignore errors\n actions: \"assignNoError\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"OpenApplicationResultCheck\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n // When an APDU triggers a disconnection, some transports may possibly\n // be closed on device side before the APDU response could be received,\n // especially on BLE transports.\n // Therefore when a disconnection occurs while sending, we should verify\n // the device status because it may have been successfully executed.\n target: \"GetDeviceStatus\",\n guard: \"hasDisconnectedWhileSending\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,uCAAAC,MAA2C,8BACpD,OAAS,mBAAAC,MAAuB,
|
|
6
|
-
"names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "DeviceDisconnectedWhileSendingError", "isDashboardName", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "isDeviceOnboarded", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceDisconnectedWhileSendingError } from \"@api/transport/model/Errors\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n openAppDAStateStep,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null) return false;\n return (\n context._internalState.currentlyRunningApp === context.input.appName\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return isDashboardName(context._internalState.currentlyRunningApp);\n },\n hasDisconnectedWhileSending: ({ context }) =>\n context._internalState.error !== null &&\n context._internalState.error instanceof\n DeviceDisconnectedWhileSendingError,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WBeBB6GAGGlCLQ8g7abNNf8mfrDcbTebLdaEE7gUbokJhBGuaUjvCbCSCdZNI5UQqhg1cQhNOprAxND4XP0xZTHI01SEPX9GTqf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J4XjKl6ErIBDUmCenATwA2RM7rknUm4FUhV-oiTJFTCUth05j0xJVFUTxt7sIOssRIKRQRyV4bdWOTNkTqDekqAwbxNDIUzFIhwzhZHVHkf0akZ9rKFx1CyPI6j2SaJjsoUsBIBimB8MMeUZJqFdH6PYDwKYBjwQaEYpRtlOYzlfC2NxS8bB6HsM4RUIwiSH0VNxAy6lkL1EEjTYUtisLn1ISAhuDZZxvhvpsRJmVX51FJFlZ4-Qk5wUYcxR2BTTIGUKtEvCoDpwaMUobbqugUzIg8PmEwIiTJ9yqAMaUW90IngCaIgZcUEpJVUa1Vxoy+GVGMbvZiuVf5IM8CoTZOpNZDL4eQjcIlDLIRRH5FhoxDyIGFMiASe8IoFlGNchaS0waxNqfkepG4tACiMGeQw6IiQeBGncMaMycxEl8eoIFu0fiVPbg87qSE3q6MVBpehPQ4K6G+uoZUJIVB7laNiq+2s4DkRGYTLRygs6GSQtmO4iIaWljgvUBgip-K5RErofOdiYocLBZwHhBzOWSkKqKz6Lw3i6U+QgPchlTB7xTPBeCWVHDYoAMqflIOQWA8AlXuO6KMQylImipgMi4BZzhDIKkpM0FEypRimplXNWyABRMuSRIXjNaKvHQ3h0Q0reCYT+3khGNEKgqIRxgAgBCAA */\n id: \"OpenAppDeviceAction\",\n initial: \"DeviceReady\",\n context: ({ input }) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input,\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: openAppDAStateStep.GET_DEVICE_STATUS,\n },\n _internalState: {\n error: null,\n currentlyRunningApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n },\n };\n },\n states: {\n DeviceReady: {\n // check device capabilities & status known\n always: {\n target: \"OnboardingCheck\",\n },\n },\n\n OnboardingCheck: {\n // check onboarding status provided by device session\n always: [\n {\n target: \"GetDeviceStatus\",\n guard: {\n type: \"isDeviceOnboarded\",\n },\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n\n GetDeviceStatus: {\n // We run the GetDeviceStatus flow to get information about the device state\n invoke: {\n id: \"deviceStatus\",\n src: \"getDeviceStatus\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"CheckDeviceStatus\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf<OpenAppStateMachineInternalState>(\n {\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: {\n name: output.currentApp,\n version: output.currentAppVersion,\n },\n });\n }\n return {\n ..._.context._internalState,\n currentlyRunningApp: output.currentApp,\n };\n },\n Left: (error) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n error,\n }),\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: [\n assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentlyRunningApp: null,\n }),\n }),\n \"assignErrorFromEvent\",\n ],\n },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n // If target app is currently opened, we can ignore errors\n actions: \"assignNoError\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"OpenApplicationResultCheck\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n // When an APDU triggers a disconnection, some transports may possibly\n // be closed on device side before the APDU response could be received,\n // especially on BLE transports.\n // Therefore when a disconnection occurs while sending, we should verify\n // the device status because it may have been successfully executed.\n target: \"GetDeviceStatus\",\n guard: \"hasDisconnectedWhileSending\",\n },\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCACP,OAAS,uCAAAC,MAA2C,8BACpD,OAAS,mBAAAC,MAAuB,qBAEhC,OAKE,sBAAAC,MACK,UAuCA,MAAMC,UAA4BL,CAMvC,CACA,iBACEM,EAOA,CASA,KAAM,CACJ,SAAAC,EACA,QAAAC,EACA,sBAAAC,EACA,kBAAAC,EACA,sBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBf,EAE5CgB,EAAyB,IAAId,EAA4B,CAC7D,MAAO,CACL,cAAAa,CACF,CACF,CAAC,EAAE,iBAAiBN,CAAW,EAE/B,OAAOd,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAAUD,EAAYgB,CAAQ,EAC9B,QAAShB,EAAYiB,CAAO,EAC5B,gBAAiBK,CACnB,EACA,OAAQ,CACN,kBAAmB,IAAMH,EAAkB,EAC3C,mBAAoB,CAAC,CAAE,QAAAI,CAAQ,IACzBA,EAAQ,eAAe,sBAAwB,KAAa,GA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,SAAYA,EAAY,YAAY,IAAIZ,CAAiB,EAQxE,QAPc,MAAO4B,GACrBhB,EAAY,YACV,IAAIX,EAAe,CAAE,QAAS2B,EAAK,MAAM,OAAQ,CAAC,CACpD,EAKA,sBAAuB,IAAMhB,EAAY,sBAAsB,EAC/D,sBAAwBc,GACtBd,EAAY,sBAAsBc,CAAK,EACzC,kBAAmB,IAAM,EAC3B,CACF,CACF",
|
|
6
|
+
"names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "DeviceDisconnectedWhileSendingError", "isDashboardName", "openAppDAStateStep", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "isDeviceOnboarded", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{lastValueFrom as C}from"rxjs";import{InvalidStatusWordError as S}from"../../../command/Errors";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{DeviceModelId as R}from"../../../device/DeviceModel";import{DeviceStatus as a}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as p}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as l}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as u}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as e}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as t}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as E,DeviceNotOnboardedError as P,UnknownDAError as D}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as y}from"../../../transport/model/Errors";import{OpenAppDeviceAction as d}from"./OpenAppDeviceAction";vi.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const O=vi.fn(),v=vi.fn(),V=vi.fn(),c=vi.fn(),h=vi.fn(),k=vi.fn();function m(){return{getDeviceSessionState:c,setDeviceSessionState:h,getAppAndVersion:O,openApp:v,closeApp:V,isDeviceOnboarded:k}}const{getDeviceSessionState:w}=p();beforeEach(()=>{vi.resetAllMocks(),k.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",()=>new Promise((r,o)=>{w.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[],deviceModelId:R.NANO_X,isSecureConnectionAllowed:!1}),l([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})}))}),describe("success cases",()=>{it("should end in a success if the app is already opened",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),l([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const n=new d({input:{appName:"Bitcoin",unlockTimeout:void 0}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if the dashboard is open and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),l([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),v.mockResolvedValue(A({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});C(N).then(()=>{expect(h).toHaveBeenCalledWith({deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})})),it("should end in a success if disconnection occurs while open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]),v.mockRejectedValue(new y);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if another app is open, close app succeeds and open app succeeds",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),V.mockResolvedValue(A({data:void 0})),v.mockResolvedValue(A({data:void 0}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Completed,output:void 0}],{observable:N}=u(n,i,p(),{onDone:r,onError:o});C(N).then(()=>{expect(h).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:a.CONNECTED,sessionStateType:s.ReadyWithoutSecureChannel})})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),k.mockReturnValue(!1);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{error:new P,status:e.Error}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the device is locked",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new E]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new E}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new S("mocked error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if the dashboard is open and open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in a success if disconnection occurs while open app failed",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),O.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockRejectedValue(new y);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new y}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, and close app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if another app is open, close app succeeds but open app returns an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),V.mockResolvedValue(A({data:void 0})),v.mockResolvedValue(A({error:new S("mocked error")}));const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new S("mocked error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),l([new D("Unknown error")]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if openApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),l([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),v.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should end in an error if closeApp actor throws an error",()=>new Promise((r,o)=>{c.mockReturnValue(A({data:{sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),l([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),V.mockImplementation(()=>{throw new D("Unknown error")});const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Error,error:new D("Unknown error")}];u(n,i,p(),{onDone:r,onError:o})})),it("should emit a stopped state if the action is cancelled",()=>new Promise((r,o)=>{c.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),l([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const n=new d({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None}},{status:e.Stopped}],{cancel:N}=u(n,i,p(),{onDone:r,onError:o});N()}))})});
|
|
1
|
+
import{lastValueFrom as T}from"rxjs";import{InvalidStatusWordError as C}from"../../../command/Errors";import{CommandResultFactory as l}from"../../../command/model/CommandResult";import{DeviceModelId as U}from"../../../device/DeviceModel";import{DeviceStatus as a}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as c}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as D}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as d}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as e}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as t}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as y,DeviceNotOnboardedError as w,UnknownDAError as E}from"../../../device-action/os/Errors";import{getDeviceStatusDAStateStep as s}from"../../../device-action/os/GetDeviceStatus/types";import{DeviceSessionStateType as p}from"../../../device-session/DeviceSessionState";import{DeviceDisconnectedWhileSendingError as k}from"../../../transport/model/Errors";import{OpenAppDeviceAction as A}from"./OpenAppDeviceAction";import{openAppDAStateStep as S}from"./types";vi.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const N=vi.fn(),O=vi.fn(),v=vi.fn(),u=vi.fn(),R=vi.fn(),h=vi.fn();function m(){return{getDeviceSessionState:u,setDeviceSessionState:R,getAppAndVersion:N,openApp:O,closeApp:v,isDeviceOnboarded:h}}const{getDeviceSessionState:B}=c();beforeEach(()=>{vi.resetAllMocks(),h.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",()=>new Promise((r,o)=>{B.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[],deviceModelId:U.NANO_X,isSecureConnectionAllowed:!1}),D([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const n=new A({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Completed,output:void 0}];d(n,i,c(),{onDone:r,onError:o})}))}),describe("success cases",()=>{it("should end in a success if the app is already opened",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),D([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const n=new A({input:{appName:"Bitcoin",unlockTimeout:void 0}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Completed,output:void 0}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in a success if the dashboard is open and open app succeeds",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),D([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),O.mockResolvedValue(l({data:void 0}));const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Completed,output:void 0}],{observable:V}=d(n,i,c(),{onDone:r,onError:o});T(V).then(()=>{expect(R).toHaveBeenCalledWith({deviceStatus:a.CONNECTED,sessionStateType:p.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})})),it("should end in a success if disconnection occurs while open app succeeds",()=>new Promise((r,o)=>{u.mockReturnValue(l({data:{sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),N.mockResolvedValue(l({data:{name:"BOLOS",version:"0.0.0"}})),D([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]),O.mockRejectedValue(new k);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Completed,output:void 0}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in a success if another app is open, close app succeeds and open app succeeds",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),D([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),v.mockResolvedValue(l({data:void 0})),O.mockResolvedValue(l({data:void 0}));const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Completed,output:void 0}],{observable:V}=d(n,i,c(),{onDone:r,onError:o});T(V).then(()=>{expect(R).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:a.CONNECTED,sessionStateType:p.ReadyWithoutSecureChannel})})}))}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),h.mockReturnValue(!1);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{error:new w,status:e.Error}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if the device is locked",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),D([new y]);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new y}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion returns an error",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),D([new C("mocked error")]);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new C("mocked error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if the dashboard is open and open app returns an error",()=>new Promise((r,o)=>{u.mockReturnValue(l({data:{sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),N.mockResolvedValue(l({data:{name:"BOLOS",version:"0.0.0"}})),D([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),O.mockResolvedValue(l({error:new C("mocked error")}));const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Error,error:new C("mocked error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in a success if disconnection occurs while open app failed",()=>new Promise((r,o)=>{u.mockReturnValue(l({data:{sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),N.mockResolvedValue(l({data:{name:"BOLOS",version:"0.0.0"}})),D([{currentApp:"BOLOS",currentAppVersion:"0.0.0"},{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),O.mockRejectedValue(new k);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new k}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if another app is open, and close app returns an error",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),D([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(l({error:new C("mocked error")}));const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new C("mocked error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if another app is open, close app succeeds but open app returns an error",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),D([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(l({data:void 0})),O.mockResolvedValue(l({error:new C("mocked error")}));const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Error,error:new C("mocked error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),D([new E("Unknown error")]);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new E("Unknown error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if openApp actor throws an error",()=>new Promise((r,o)=>{u.mockReturnValue(l({data:{sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),D([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),O.mockImplementation(()=>{throw new E("Unknown error")});const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.ConfirmOpenApp,step:s.ONBOARD_CHECK}},{status:e.Error,error:new E("Unknown error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should end in an error if closeApp actor throws an error",()=>new Promise((r,o)=>{u.mockReturnValue(l({data:{sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),D([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),v.mockImplementation(()=>{throw new E("Unknown error")});const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Error,error:new E("Unknown error")}];d(n,i,c(),{onDone:r,onError:o})})),it("should emit a stopped state if the action is cancelled",()=>new Promise((r,o)=>{u.mockReturnValue({sessionStateType:p.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),D([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const n=new A({input:{appName:"Bitcoin"}});vi.spyOn(n,"extractDependencies").mockReturnValue(m());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:S.GET_DEVICE_STATUS}},{status:e.Pending,intermediateValue:{requiredUserInteraction:t.None,step:s.ONBOARD_CHECK}},{status:e.Stopped}],{cancel:V}=d(n,i,c(),{onDone:r,onError:o});V()}))})});
|
|
2
2
|
//# sourceMappingURL=OpenAppDeviceAction.test.js.map
|