@ledgerhq/device-management-kit 0.0.0-develop-20250106155719 → 0.0.0-webhid-20250124103640
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 +4 -1
- package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.test.js.map +2 -2
- package/lib/cjs/src/api/DeviceManagementKitBuilder.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKitBuilder.js.map +2 -2
- package/lib/cjs/src/api/DmkConfig.js +1 -1
- package/lib/cjs/src/api/DmkConfig.js.map +1 -1
- package/lib/cjs/src/api/command/model/CommandResult.js.map +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
- package/lib/cjs/src/api/command/utils/CommandUtils.js +1 -1
- package/lib/cjs/src/api/command/utils/CommandUtils.js.map +2 -2
- package/lib/cjs/src/api/device-action/DeviceAction.js.map +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/makeInternalApi.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/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/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +2 -2
- 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/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- package/lib/cjs/src/api/device-session/DeviceSessionState.js +1 -1
- package/lib/cjs/src/api/device-session/DeviceSessionState.js.map +2 -2
- package/lib/cjs/src/api/device-session/use-case/ToggleDeviceSessionRefresher.test.js +1 -1
- package/lib/cjs/src/api/device-session/use-case/ToggleDeviceSessionRefresher.test.js.map +2 -2
- package/lib/cjs/src/api/types.js.map +1 -1
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +3 -3
- package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
- package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/use-case/CloseSessionsUseCase.test.js +1 -1
- package/lib/cjs/src/internal/device-session/use-case/CloseSessionsUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js +1 -1
- package/lib/cjs/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js +1 -1
- package/lib/cjs/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/model/Const.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Const.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/model/Errors.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Errors.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/model/Params.js +2 -0
- package/lib/cjs/src/internal/manager-api/model/Params.js.map +7 -0
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
- package/lib/cjs/src/internal/send/use-case/SendApduUseCase.test.js +1 -1
- package/lib/cjs/src/internal/send/use-case/SendApduUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/transport/di/transportModule.test.js +1 -1
- package/lib/cjs/src/internal/transport/di/transportModule.test.js.map +2 -2
- package/lib/esm/package.json +4 -1
- package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.test.js.map +2 -2
- package/lib/esm/src/api/DeviceManagementKitBuilder.js +1 -1
- package/lib/esm/src/api/DeviceManagementKitBuilder.js.map +3 -3
- package/lib/esm/src/api/command/model/CommandResult.js.map +1 -1
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
- package/lib/esm/src/api/command/utils/CommandUtils.js +1 -1
- package/lib/esm/src/api/command/utils/CommandUtils.js.map +2 -2
- package/lib/esm/src/api/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/src/api/device-action/__test-utils__/makeInternalApi.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/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/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +2 -2
- 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/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +2 -2
- 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/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +2 -2
- package/lib/esm/src/api/device-session/DeviceSessionState.js.map +2 -2
- package/lib/esm/src/api/device-session/use-case/ToggleDeviceSessionRefresher.test.js +1 -1
- package/lib/esm/src/api/device-session/use-case/ToggleDeviceSessionRefresher.test.js.map +2 -2
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +3 -3
- package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
- package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/use-case/CloseSessionsUseCase.test.js +1 -1
- package/lib/esm/src/internal/device-session/use-case/CloseSessionsUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js +1 -1
- package/lib/esm/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/di/discoveryModule.test.js +1 -1
- package/lib/esm/src/internal/discovery/di/discoveryModule.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/model/Const.js +1 -1
- package/lib/esm/src/internal/manager-api/model/Const.js.map +3 -3
- package/lib/esm/src/internal/manager-api/model/Errors.js +1 -1
- package/lib/esm/src/internal/manager-api/model/Errors.js.map +3 -3
- package/lib/esm/src/internal/manager-api/model/Params.js +1 -0
- package/lib/esm/src/internal/manager-api/model/Params.js.map +7 -0
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
- package/lib/esm/src/internal/send/use-case/SendApduUseCase.test.js +1 -1
- package/lib/esm/src/internal/send/use-case/SendApduUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/transport/di/transportModule.test.js +1 -1
- package/lib/esm/src/internal/transport/di/transportModule.test.js.map +2 -2
- package/lib/types/src/api/DeviceManagementKitBuilder.d.ts.map +1 -1
- package/lib/types/src/api/DmkConfig.d.ts +1 -0
- package/lib/types/src/api/DmkConfig.d.ts.map +1 -1
- package/lib/types/src/api/command/model/CommandResult.d.ts +1 -2
- package/lib/types/src/api/command/model/CommandResult.d.ts.map +1 -1
- package/lib/types/src/api/device-action/DeviceAction.d.ts +1 -1
- package/lib/types/src/api/device-action/DeviceAction.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/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +1 -0
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/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 +1 -0
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/src/api/device-session/DeviceSessionState.d.ts +5 -0
- package/lib/types/src/api/device-session/DeviceSessionState.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/Errors.d.ts +26 -26
- package/lib/types/src/api/transport/model/Errors.d.ts.map +1 -1
- package/lib/types/src/api/types.d.ts +1 -1
- package/lib/types/src/api/types.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts +15 -5
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +70 -2
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts +6 -0
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Const.d.ts +1 -0
- package/lib/types/src/internal/manager-api/model/Const.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Errors.d.ts +6 -0
- package/lib/types/src/internal/manager-api/model/Errors.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Params.d.ts +86 -0
- package/lib/types/src/internal/manager-api/model/Params.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -2
@@ -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 saveSessionState: (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, saveSessionState, 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 saveSessionState: 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 saveSessionState(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+Tce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OoaHioY093QCEwMNFJV5Gg-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: \"saveSessionState\",\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 return {\n getAppsByHash: ({ input }) => internalApi.getMetadataForAppHashes(input),\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n saveSessionState: (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,qDA4BA,MAAMC,UAAyCD,CAMpD,CACA,iBACEE,EAOA,CASA,KAAM,CAAE,cAAAC,EAAe,iBAAAC,EAAkB,sBAAAC,CAAsB,EAC7D,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,MAAM,eAAiBR,EAE5CS,EAAkB,IAAIR,EAAqB,CAC/C,MAAO,CACL,cAAAO,CACF,CACF,CAAC,EAAE,iBA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,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASA,GACHA,EAAE,QAAQ,eAAe,MACpBzB,EAAKyB,EAAE,QAAQ,eAAe,KAAK,EAGrCxB,EAAMwB,EAAE,QAAQ,eAAe,gBAAgB,CAE1D,CAAC,CACH,CAEA,oBAAoBE,EAA+C,CACjE,MAAO,CACL,cAAe,CAAC,CAAE,MAAAV,CAAM,
|
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 saveSessionState: (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, saveSessionState, 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 saveSessionState: 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 saveSessionState(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: \"saveSessionState\",\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 return {\n getAppsByHash: ({ input }) =>\n internalApi.getManagerApiService().getAppsByHash(input),\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n saveSessionState: (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,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eACb,MAAAF,CACF,EACF,CAAC,CAEL,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,mBAAoB,CAClB,OAAQ,CACN,CACE,OAAQ,QACR,MAAO,UACT,EACA,CACE,OAAQ,aACV,CACF,CACF,EACA,YAAa,CACX,OAAQ,CACN,IAAK,mBACL,MAAQE,IAAO,CACb,iBAAkBA,EAAE,QAAQ,eAAe,gBAC7C,EACF,EACA,GAAI,CACF,KAAM,CACJ,OAAQ,SACV,EACA,MAAO,CACL,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASA,GACHA,EAAE,QAAQ,eAAe,MACpBzB,EAAKyB,EAAE,QAAQ,eAAe,KAAK,EAGrCxB,EAAMwB,EAAE,QAAQ,eAAe,gBAAgB,CAE1D,CAAC,CACH,CAEA,oBAAoBE,EAA+C,CACjE,MAAO,CACL,cAAe,CAAC,CAAE,MAAAV,CAAM,IACtBU,EAAY,qBAAqB,EAAE,cAAcV,CAAK,EACxD,sBAAuB,IAAMU,EAAY,sBAAsB,EAC/D,iBAAmBC,GACjBD,EAAY,sBAAsBC,CAAK,CAC3C,CACF,CACF",
|
6
6
|
"names": ["Left", "Right", "assign", "fromCallback", "fromPromise", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "ListAppsDeviceAction", "XStateDeviceAction", "ListAppsWithMetadataDeviceAction", "internalAPI", "getAppsByHash", "saveSessionState", "getDeviceSessionState", "unlockTimeout", "listAppsMachine", "input", "sendBack", "appsWithMetadata", "filterted", "app", "updatedState", "error", "context", "_", "apps", "internalApi", "state"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{Left as
|
1
|
+
import{Left as V,Right as A}from"purify-ts";import{DeviceStatus as P}from"../../../device/DeviceStatus";import{BTC_APP as d,BTC_APP_METADATA as c,CUSTOM_LOCK_SCREEN_APP as f,CUSTOM_LOCK_SCREEN_APP_METADATA as g,ETH_APP as k,ETH_APP_METADATA as v}from"../../../device-action/__test-utils__/data";import{makeDeviceActionInternalApiMock as n}from"../../../device-action/__test-utils__/makeInternalApi";import{setupListAppsMock as r}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as o}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 l}from"../../../device-action/os/Errors";import{DeviceSessionStateType as D}from"../../../device-session/DeviceSessionState";import{HttpFetchApiError as I}from"../../../../internal/manager-api/model/Errors";import{ListAppsWithMetadataDeviceAction as p}from"./ListAppsWithMetadataDeviceAction";jest.mock("@api/device-action/os/ListApps/ListAppsDeviceAction");describe("ListAppsWithMetadataDeviceAction",()=>{const{getManagerApiService:u}=n(),m=jest.fn(),h=jest.fn(),S=jest.fn();function M(){return{getAppsByHash:S,getDeviceSessionState:h,saveSessionState:m}}beforeEach(()=>{jest.resetAllMocks()}),describe("success case",()=>{it("should run the device actions with no apps installed",a=>{r([]);const i=new p({input:{}});u.mockReturnValue({getAppsByHash:jest.fn().mockResolvedValue(A([]))});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{status:e.Completed,output:[]}];o(i,s,n(),a)}),it("should run the device actions with 1 app installed",a=>{r([d]);const i=new p({input:{}});u.mockReturnValue({getAppsByHash:jest.fn().mockResolvedValue(A([c]))});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Completed,output:[c]}];o(i,s,n(),a)}),it("should run the device actions with 2 apps installed",a=>{r([d,k]);const i=new p({input:{}});u.mockReturnValue({getAppsByHash:jest.fn().mockResolvedValue(A([c,v]))});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Completed,output:[c,v]}];o(i,s,n(),a)}),it("should run the device actions with 1 app installed and a custom lock screen",a=>{r([d,f]);const i=new p({input:{}});u.mockReturnValue({getAppsByHash:jest.fn().mockResolvedValue(A([c,g]))});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Completed,output:[c,g]}];o(i,s,n(),a)})}),describe("error case",()=>{it("should error when ListApps fails",a=>{r([],!0);const i=new p({input:{}}),s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{status:e.Error,error:new l("ListApps failed")}];o(i,s,n(),a)}),it("should error when getAppsByHash rejects",a=>{r([d]);const i=new p({input:{}});u.mockReturnValue({getAppsByHash:jest.fn().mockRejectedValue(new l("getAppsByHash failed"))});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Error,error:new l("getAppsByHash failed")}];o(i,s,n(),a)}),it("should error when getAppsByHash fails but error is known",a=>{r([d]);const i=new p({input:{}}),s=new I(new Error("Failed to fetch data"));u.mockReturnValue({getAppsByHash:jest.fn().mockResolvedValue(V(s))});const w=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Error,error:s}];o(i,w,n(),a)}),it("should error when SaveSession fails",a=>{r([d]);const i=new p({input:{}});S.mockImplementation(async()=>Promise.resolve(A([c]))),jest.spyOn(i,"extractDependencies").mockReturnValue(M()),h.mockReturnValue({sessionStateType:D.ReadyWithoutSecureChannel,deviceStatus:P.CONNECTED,currentApp:"BOLOS",installedApps:[]}),m.mockImplementation(()=>{throw new l("SaveSession failed")});const s=[{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.AllowListApps},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{intermediateValue:{requiredUserInteraction:t.None},status:e.Pending},{status:e.Error,error:new l("SaveSession failed")}];o(i,s,n(),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\";\n\nimport { ListAppsWithMetadataDeviceAction } from \"./ListAppsWithMetadataDeviceAction\";\nimport { type ListAppsWithMetadataDAState } from \"./types\";\n\njest.mock(\"@api/device-action/os/ListApps/ListAppsDeviceAction\");\n\ndescribe(\"ListAppsWithMetadataDeviceAction\", () => {\n const {\n getMetadataForAppHashes: getMetadataForAppHashesMock,\n // getDeviceSessionState: apiGetDeviceSessionStateMock,\n // setDeviceSessionState: apiSetDeviceSessionStateMock,\n } = makeDeviceActionInternalApiMock();\n\n const saveSessionStateMock = jest.fn();\n const getDeviceSessionStateMock = jest.fn();\n const getAppsByHashMock = jest.fn();\n\n function extractDependenciesMock() {\n return {\n getAppsByHash: getAppsByHashMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n saveSessionState: saveSessionStateMock,\n };\n }\n\n beforeEach(() => {\n jest.resetAllMocks();\n });\n\n describe(\"success case\", () => {\n it(\"should run the device actions with no apps installed\", (done) => {\n setupListAppsMock([]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getMetadataForAppHashesMock.mockResolvedValue(Right([]));\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 done,\n );\n });\n\n it(\"should run the device actions with 1 app installed\", (done) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getMetadataForAppHashesMock.mockResolvedValue(Right([BTC_APP_METADATA]));\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 done,\n );\n });\n\n it(\"should run the device actions with 2 apps installed\", (done) => {\n setupListAppsMock([BTC_APP, ETH_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getMetadataForAppHashesMock.mockResolvedValue(\n Right([BTC_APP_METADATA, ETH_APP_METADATA]),\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.Completed,\n output: [BTC_APP_METADATA, ETH_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n done,\n );\n });\n\n it(\"should run the device actions with 1 app installed and a custom lock screen\", (done) => {\n setupListAppsMock([BTC_APP, CUSTOM_LOCK_SCREEN_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getMetadataForAppHashesMock.mockResolvedValue(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\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.Completed,\n output: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n done,\n );\n });\n });\n\n describe(\"error case\", () => {\n it(\"should error when ListApps fails\", (done) => {\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 done,\n );\n });\n\n it(\"should error when getAppsByHash rejects\", (done) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getMetadataForAppHashesMock.mockRejectedValue(\n new UnknownDAError(\"getAppsByHash 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 status: DeviceActionStatus.Error,\n error: new UnknownDAError(\"getAppsByHash failed\"),\n },\n ];\n\n testDeviceActionStates(\n listAppsWithMetadataDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n done,\n );\n });\n\n it(\"should error when getAppsByHash fails but error is known\", (done) => {\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 getMetadataForAppHashesMock.mockResolvedValue(Left(error));\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 done,\n );\n });\n\n it(\"should error when SaveSession fails\", (done) => {\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 jest\n .spyOn(listAppsWithMetadataDeviceAction, \"extractDependencies\")\n .mockReturnValue(extractDependenciesMock());\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: \"BOLOS\",\n installedApps: [],\n });\n\n saveSessionStateMock.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 done,\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,
|
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", "
|
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\njest.mock(\"@api/device-action/os/ListApps/ListAppsDeviceAction\");\n\ndescribe(\"ListAppsWithMetadataDeviceAction\", () => {\n const { getManagerApiService: getManagerApiServiceMock } =\n makeDeviceActionInternalApiMock();\n\n const saveSessionStateMock = jest.fn();\n const getDeviceSessionStateMock = jest.fn();\n const getAppsByHashMock = jest.fn();\n\n function extractDependenciesMock() {\n return {\n getAppsByHash: getAppsByHashMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n saveSessionState: saveSessionStateMock,\n };\n }\n\n beforeEach(() => {\n jest.resetAllMocks();\n });\n\n describe(\"success case\", () => {\n it(\"should run the device actions with no apps installed\", (done) => {\n setupListAppsMock([]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: jest.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 done,\n );\n });\n\n it(\"should run the device actions with 1 app installed\", (done) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: jest.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 done,\n );\n });\n\n it(\"should run the device actions with 2 apps installed\", (done) => {\n setupListAppsMock([BTC_APP, ETH_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: jest\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 done,\n );\n });\n\n it(\"should run the device actions with 1 app installed and a custom lock screen\", (done) => {\n setupListAppsMock([BTC_APP, CUSTOM_LOCK_SCREEN_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: jest\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 done,\n );\n });\n });\n\n describe(\"error case\", () => {\n it(\"should error when ListApps fails\", (done) => {\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 done,\n );\n });\n\n it(\"should error when getAppsByHash rejects\", (done) => {\n setupListAppsMock([BTC_APP]);\n const listAppsWithMetadataDeviceAction =\n new ListAppsWithMetadataDeviceAction({\n input: {},\n });\n\n getManagerApiServiceMock.mockReturnValue({\n getAppsByHash: jest\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 done,\n );\n });\n\n it(\"should error when getAppsByHash fails but error is known\", (done) => {\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: jest.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 done,\n );\n });\n\n it(\"should error when SaveSession fails\", (done) => {\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 jest\n .spyOn(listAppsWithMetadataDeviceAction, \"extractDependencies\")\n .mockReturnValue(extractDependenciesMock());\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: \"BOLOS\",\n installedApps: [],\n });\n\n saveSessionStateMock.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 done,\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,y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AiC,CACnC,MAAO,CAAC,CACV,CAAC,EAEHI,EAAkB,mBAAmB,SACnC,QAAQ,QAAQpB,EAAM,CAACG,CAAgB,CAAC,CAAC,CAC3C,EAEA,KACG,MAAMoB,EAAkC,qBAAqB,EAC7D,gBAAgBF,EAAwB,CAAC,EAE5CF,EAA0B,gBAAgB,CACxC,iBAAkBL,EAAuB,0BACzC,aAAcb,EAAa,UAC3B,WAAY,QACZ,cAAe,CAAC,CAClB,CAAC,EAEDiB,EAAqB,mBAAmB,IAAM,CAC5C,MAAM,IAAIL,EAAe,oBAAoB,CAC/C,CAAC,EAED,MAAMW,EAAqD,CACzD,CACE,kBAAmB,CACjB,wBAAyBZ,EAAwB,IACnD,EACA,OAAQD,EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,aACnD,EACA,OAAQD,EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,IACnD,EACA,OAAQD,EAAmB,OAC7B,EACA,CACE,kBAAmB,CACjB,wBAAyBC,EAAwB,IACnD,EACA,OAAQD,EAAmB,OAC7B,EACA,CACE,OAAQA,EAAmB,MAC3B,MAAO,IAAIE,EAAe,oBAAoB,CAChD,CACF,EAEAH,EACEa,EACAC,EACAhB,EAAgC,EAChCc,CACF,CACF,CAAC,CACH,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", "DeviceSessionStateType", "HttpFetchApiError", "ListAppsWithMetadataDeviceAction", "getManagerApiServiceMock", "saveSessionStateMock", "getDeviceSessionStateMock", "getAppsByHashMock", "extractDependenciesMock", "done", "listAppsWithMetadataDeviceAction", "expectedStates", "error"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{Left as D,Right as y}from"purify-ts";import{assign as t,fromPromise as c,setup as g}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as
|
1
|
+
import{Left as D,Right as y}from"purify-ts";import{assign as t,fromPromise as c,setup as g}from"xstate";import{isSuccessCommandResult as u}from"../../../command/model/CommandResult";import{CloseAppCommand as O}from"../../../command/os/CloseAppCommand";import{OpenAppCommand as v}from"../../../command/os/OpenAppCommand";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as h}from"../../../device-action/os/Const";import{DeviceNotOnboardedError as E}from"../../../device-action/os/Errors";import{GetDeviceStatusDeviceAction as R}from"../../../device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction";import{XStateDeviceAction as C}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";class q extends C{makeStateMachine(r){const{closeApp:o,openApp:s,getDeviceSessionState:a,isDeviceOnboarded:A,setDeviceSessionState:d}=this.extractDependencies(r),S=this.input.unlockTimeout??h,m=new R({input:{unlockTimeout:S}}).makeStateMachine(r);return g({types:{input:{},context:{},output:{}},actors:{closeApp:c(o),openApp:c(s),getDeviceStatus:m},guards:{isDeviceOnboarded:()=>A(),isRequestedAppOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return e._internalState.currentlyRunningApp===e.input.appName||e.input.compatibleAppNames!==void 0&&e.input.compatibleAppNames.includes(e._internalState.currentlyRunningApp)},isDashboardOpen:({context:e})=>{if(e._internalState.currentlyRunningApp===null)throw new Error("context.currentlyRunningApp === null");return e._internalState.currentlyRunningApp==="BOLOS"},hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:t({_internalState:e=>({...e.context._internalState,error:new E})}),assignUserActionNeededOpenApp:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.ConfirmOpenApp})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoError:t({_internalState:e=>({...e.context._internalState,error:null})})}}).createMachine({id:"OpenAppDeviceAction",initial:"DeviceReady",context:({input:e})=>{const n=a(),{sessionStateType:p}=n;return{input:e,intermediateValue:{requiredUserInteraction:i.None},_internalState:{error:null,currentlyRunningApp:p===l.ReadyWithoutSecureChannel?n.currentApp.name:null}}},states:{DeviceReady:{always:{target:"OnboardingCheck"}},OnboardingCheck:{always:[{target:"GetDeviceStatus",guard:{type:"isDeviceOnboarded"}},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},GetDeviceStatus:{invoke:{id:"deviceStatus",src:"getDeviceStatus",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:t({intermediateValue:e=>e.event.snapshot.context.intermediateValue})},onDone:{target:"CheckDeviceStatus",actions:t({_internalState:e=>e.event.output.caseOf({Right:n=>{const p=a();return p.sessionStateType!==l.Connected&&d({...p,currentApp:{name:n.currentApp,version:n.currentAppVersion}}),{...e.context._internalState,currentlyRunningApp:n.currentApp}},Left:n=>({...e.context._internalState,error:n})})})}}},CheckDeviceStatus:{always:[{target:"Error",guard:"hasError"},{target:"ApplicationReady",guard:"isRequestedAppOpen"},{target:"DashboardCheck"}]},DashboardCheck:{always:[{target:"OpenApplication",guard:"isDashboardOpen"},"CloseApplication"]},OpenApplication:{entry:"assignUserActionNeededOpenApp",exit:"assignNoUserActionNeeded",invoke:{src:"openApp",input:({context:e})=>({appName:e.input.appName}),onDone:{target:"OpenApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:e.context.input.appName}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OpenApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetDeviceStatus"}]},CloseApplication:{invoke:{src:"closeApp",onDone:{target:"CloseApplicationResultCheck",actions:t({_internalState:e=>u(e.event.output)?{...e.context._internalState,currentlyRunningApp:"BOLOS"}:{...e.context._internalState,error:e.event.output.error}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},CloseApplicationResultCheck:{always:[{target:"Error",guard:"hasError"},{target:"OpenApplication"}]},ApplicationCheck:{always:[{target:"ApplicationReady",guard:"isRequestedAppOpen"},"DashboardCheck"]},ApplicationReady:{always:"Success"},Success:{type:"final",actions:"assignNoError"},Error:{type:"final"}},output:({context:e})=>e._internalState.error?D(e._internalState.error):y(void 0)})}extractDependencies(r){return{closeApp:async()=>r.sendCommand(new O),openApp:async a=>r.sendCommand(new v({appName:a.input.appName})),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:a=>r.setDeviceSessionState(a),isDeviceOnboarded:()=>!0}}}export{q as OpenAppDeviceAction};
|
2
2
|
//# sourceMappingURL=OpenAppDeviceAction.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.ts"],
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return (\n context._internalState.currentlyRunningApp === 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 context._internalState.currentlyRunningApp === \"BOLOS\";\n },\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WBeBB6GAGGlCLQ8g7abNNf8mfrDcbTebLdaEE7gUbokJhBGuaUjvCbCSCdZNI5UQqhg1cQhNOprAxND4XP0xZTHI01SEPX9GTqfaQw-QTWaLVabWAkklaEkGKgLVQAGadgC2S3Vlfm2sYtfr2H9zaDIbrZQjUb2Bx5cb5CelydTxnT2nFXTcmjUBYTzlazkcE0CX1Hv3HiynfqbgbA7FgAFc9VQNhCV9CMZwqAlQuAWZwHiqbStI0mY+PmdRKNYxLZmKgjvDeUwVg+WpPrgBqLtEjYBi2H7fr+7ICJyq7crGIGIK0LwME8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Ln1ISAhuDZZxvhvpsRJmVX51FJFlZ4-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 error,\n }),\n },\n );\n },\n }),\n },\n // NOTE: The way we handle our DeviceActions means that we should never as we return an Either\n // onError: {\n // target: \"Error\",\n // actions: \"assignGetDeviceStatusUnknownError\",\n // },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationCheck: {\n // Is the current application the requested one\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n \"DashboardCheck\",\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCA8CA,MAAMC,UAA4BF,CAMvC,CACA,iBACEG,EAOA,CASA,KAAM,CACJ,SAAAC,EACA,QAAAC,EACA,sBAAAC,EACA,kBAAAC,EACA,sBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBZ,EAE5Ca,EAAyB,IAAIX,EAA4B,CAC7D,MAAO,CACL,cAAAU,CACF,CACF,CAAC,EAAE,iBAAiBN,CAAW,EAE/B,OAAOX,EAAM,CACX,MAAO,CACL,MAAO,CAAC,EACR,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,SAAUD,EAAYa,CAAQ,EAC9B,QAASb,EAAYc,CAAO,EAC5B,gBAAiBK,CACnB,EACA,OAAQ,CACN,kBAAmB,IAAMH,EAAkB,EAC3C,mBAAoB,CAAC,CAAE,QAAAI,CAAQ,IAAqC,CAClE,GAAIA,EAAQ,eAAe,sBAAwB,KACjD,MAAM,IAAI,MAAM,sCAAsC,EACxD,OACEA,EAAQ,eAAe,
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n CloseAppCommand,\n type CloseAppCommandResult,\n} from \"@api/command/os/CloseAppCommand\";\nimport {\n OpenAppCommand,\n type OpenAppCommandResult,\n} from \"@api/command/os/OpenAppCommand\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceStatusDeviceAction } from \"@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type OpenAppDAError,\n type OpenAppDAInput,\n type OpenAppDAIntermediateValue,\n type OpenAppDAOutput,\n} from \"./types\";\n\ntype OpenAppStateMachineInternalState = {\n readonly currentlyRunningApp: string | null;\n readonly error: OpenAppDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly closeApp: () => Promise<CloseAppCommandResult>;\n readonly openApp: (arg0: {\n input: { appName: string };\n }) => Promise<OpenAppCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (state: DeviceSessionState) => void;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\n/**\n * Opens a given app on the device.\n *\n * It checks if the device is onboarded, unlocked, and which app is currently open.\n * If the current app is the dashboard, it will directly open the requested app.\n * If another app is opened, it will close the current app and open the requested app.\n *\n * Example of usage:\n *\n * ```ts\n * const deviceAction = new OpenAppDeviceAction({\n * input: {\n * appName: \"MyApp\",\n * },\n * });\n * dmk.executeDeviceAction({ sessionId: \"mySessionId\", deviceAction });\n * ```\n */\nexport class OpenAppDeviceAction extends XStateDeviceAction<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppDAOutput,\n OpenAppDAInput,\n OpenAppDAError,\n OpenAppDAIntermediateValue,\n OpenAppStateMachineInternalState\n >;\n\n const {\n closeApp,\n openApp,\n getDeviceSessionState,\n isDeviceOnboarded,\n setDeviceSessionState,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getDeviceStatusMachine = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {} as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n closeApp: fromPromise(closeApp),\n openApp: fromPromise(openApp),\n getDeviceStatus: getDeviceStatusMachine,\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isRequestedAppOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return (\n context._internalState.currentlyRunningApp ===\n context.input.appName ||\n (context.input.compatibleAppNames !== undefined &&\n context.input.compatibleAppNames.includes(\n context._internalState.currentlyRunningApp,\n ))\n );\n },\n isDashboardOpen: ({ context }: { context: types[\"context\"] }) => {\n if (context._internalState.currentlyRunningApp === null)\n throw new Error(\"context.currentlyRunningApp === null\");\n return context._internalState.currentlyRunningApp === \"BOLOS\";\n },\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignUserActionNeededOpenApp: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.ConfirmOpenApp,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // FIXME: add a typeguard\n }),\n }),\n assignNoError: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: null,\n }),\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHkAOYB2BBVqAiYAbgJYDGYWpALsQPYYB0BJ5ASmAIYQCeAxANoAGALqJQqWrGI16YkAA9EARhWCGADgAsAZm1b1SwUoDspgDQhuiAEzX1DbQE5tJlQDYlm414CsAXz8LNEwcfCIyCmo6RmQMACNaDgAnCGIMKABhAAswUgBrARE5CSkZDDlFBCUPbQYfZx91H0FtTRNjCysEbWM1bTdHAzcfH2q9awCg9GxcZgjKMoZYhOTU9Ozcgv4lUSQQEuloiuUauoamlrbzSxtBNTu7pW1BEe1rJUmQYJmwlkjFgAytHyaUyOXyhV24kkh1ke0q7w8DDcxmqjkM1l6Kh8nUQzR8DEEjjcz3UxKUjiMbk+31Cc3IC2iDCBIPW4K2O2KMLKxwQiKUyNRAwxWKUOJu3TaDFsw28bkExmsgnU-Rp0zp4QZUXoDFCABsyBwylhCBxiHqOHE9WBeBB6GAGGlCLQ8g7abNNf8mfrDcbTebLdaEE7gUbokJhBGuaUjvCbCSCdZNI5UQqhg1cQhNOprAxND4XP0xZTHI01SEPX9GTqfaQw-QTWaLVabWAkklaEkGKgLVQAGadgC2S3Vlfm2sYtfr2H9zaDIbrZQjUb2Bx5cb5CelydTxnT2nFXTcmjUBYTzlazkcE0CX1Hv3HiynfqbgbA7FgAFc9VQNhCV9CMZwqAlQuAWZwHiqbStI0mY+PmdRKNYxLZmKgjvDeUwVg+WpPrgBqLtEjYBi2H7fr+7ICJyq7crGIGIK0LwME8dzJuizzNNYmZeLmAysZ4Ph2KYmiaOWPz0l6Nb4b60R-lsRQ0UB5Qbq0pgMM4FJ8dYx4KpomaOJo6k9G4yHvEhBmYmJGpVhOurSYR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a1Vxoy+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 error,\n }),\n },\n );\n },\n }),\n },\n // NOTE: The way we handle our DeviceActions means that we should never as we return an Either\n // onError: {\n // target: \"Error\",\n // actions: \"assignGetDeviceStatusUnknownError\",\n // },\n },\n },\n CheckDeviceStatus: {\n // We check the device status to see if we can have an error\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n {\n target: \"DashboardCheck\",\n },\n ],\n },\n\n DashboardCheck: {\n // Is the current application the dashboard\n always: [\n {\n target: \"OpenApplication\",\n guard: \"isDashboardOpen\",\n },\n \"CloseApplication\",\n ],\n },\n\n OpenApplication: {\n // execute openApp command,\n entry: \"assignUserActionNeededOpenApp\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n src: \"openApp\",\n input: ({ context }) => ({ appName: context.input.appName }),\n onDone: {\n target: \"OpenApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: _.context.input.appName,\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n\n OpenApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"GetDeviceStatus\" },\n ],\n },\n\n CloseApplication: {\n invoke: {\n src: \"closeApp\",\n onDone: {\n target: \"CloseApplicationResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n return {\n ..._.context._internalState,\n currentlyRunningApp: \"BOLOS\",\n };\n } else {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n CloseApplicationResultCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n { target: \"OpenApplication\" },\n ],\n },\n\n ApplicationCheck: {\n // Is the current application the requested one\n always: [\n {\n target: \"ApplicationReady\",\n guard: \"isRequestedAppOpen\",\n },\n \"DashboardCheck\",\n ],\n },\n\n ApplicationReady: {\n // application is ready to be used\n always: \"Success\",\n },\n\n // success state\n Success: {\n type: \"final\",\n actions: \"assignNoError\", // TODO, we should not need this\n },\n\n // error state\n Error: {\n type: \"final\",\n },\n },\n output: ({ context }) =>\n context._internalState.error // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n ? Left(context._internalState.error)\n : Right(undefined),\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const closeApp = async () => internalApi.sendCommand(new CloseAppCommand());\n const openApp = async (arg0: { input: { appName: string } }) =>\n internalApi.sendCommand(\n new OpenAppCommand({ appName: arg0.input.appName }),\n );\n\n return {\n closeApp,\n openApp,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n };\n }\n}\n"],
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,mBAAAC,MAEK,kCACP,OACE,kBAAAC,MAEK,iCAEP,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,+BAAAC,MAAmC,oEAE5C,OAEE,sBAAAC,MACK,qDACP,OAEE,0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AAS,sBACX,CACF,CACF,EACA,4BAA6B,CAC3B,OAAQ,CACN,CACE,OAAQ,QACR,MAAO,UACT,EACA,CAAE,OAAQ,iBAAkB,CAC9B,CACF,EAEA,iBAAkB,CAEhB,OAAQ,CACN,CACE,OAAQ,mBACR,MAAO,oBACT,EACA,gBACF,CACF,EAEA,iBAAkB,CAEhB,OAAQ,SACV,EAGA,QAAS,CACP,KAAM,QACN,QAAS,eACX,EAGA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAAQ,CAAC,CAAE,QAAAD,CAAQ,IACjBA,EAAQ,eAAe,MACnBvB,EAAKuB,EAAQ,eAAe,KAAK,EACjCtB,EAAM,MAAS,CACvB,CAAC,CACH,CAEA,oBAAoBc,EAA+C,CAOjE,MAAO,CACL,SAPe,SAAYA,EAAY,YAAY,IAAIT,CAAiB,EAQxE,QAPc,MAAOyB,GACrBhB,EAAY,YACV,IAAIR,EAAe,CAAE,QAASwB,EAAK,MAAM,OAAQ,CAAC,CACpD,EAKA,sBAAuB,IAAMhB,EAAY,sBAAsB,EAC/D,sBAAwBc,GACtBd,EAAY,sBAAsBc,CAAK,EACzC,kBAAmB,IAAM,EAC3B,CACF,CACF",
|
6
6
|
"names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "CloseAppCommand", "OpenAppCommand", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "GetDeviceStatusDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "OpenAppDeviceAction", "internalApi", "closeApp", "openApp", "getDeviceSessionState", "isDeviceOnboarded", "setDeviceSessionState", "unlockTimeout", "getDeviceStatusMachine", "context", "_", "input", "sessionState", "sessionStateType", "output", "state", "error", "arg0"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{lastValueFrom as O}from"rxjs";import{InvalidStatusWordError as l}from"../../../command/Errors";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{DeviceStatus as o}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as s}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as m}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 n}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as y,DeviceNotOnboardedError as R,UnknownDAError as V}from"../../../device-action/os/Errors";import{DeviceSessionStateType as a}from"../../../device-session/DeviceSessionState";import{OpenAppDeviceAction as u}from"./OpenAppDeviceAction";jest.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const k=jest.fn(),S=jest.fn(),v=jest.fn(),p=jest.fn(),h=jest.fn(),N=jest.fn();function d(){return{getDeviceSessionState:p,setDeviceSessionState:h,getAppAndVersion:k,openApp:S,closeApp:v,isDeviceOnboarded:N}}const{getDeviceSessionState:C}=s();beforeEach(()=>{jest.resetAllMocks(),N.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",r=>{C.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[]}),m([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const t=new u({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}];c(t,i,s(),r)})}),describe("success cases",()=>{it("should end in a success if the app is already opened",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),m([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const t=new u({input:{appName:"Bitcoin",unlockTimeout:void 0}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}];c(t,i,s(),r)}),it("should end in a success if the dashboard is open and open app succeeds",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),m([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),S.mockResolvedValue(A({data:void 0}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}],{observable:D}=c(t,i,s(),r);O(D).then(()=>{expect(h).toHaveBeenCalledWith({deviceStatus:o.CONNECTED,sessionStateType:a.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})}),it("should end in a success if another app is open, close app succeeds and open app succeeds",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),v.mockResolvedValue(A({data:void 0})),S.mockResolvedValue(A({data:void 0}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}],{observable:D}=c(t,i,s(),r);O(D).then(()=>{expect(h).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:o.CONNECTED,sessionStateType:a.ReadyWithoutSecureChannel})})})}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),N.mockReturnValue(!1);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{error:new R,status:e.Error}];c(t,i,s(),r)}),it("should end in an error if the device is locked",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new y]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new y}];c(t,i,s(),r)}),it("should end in an error if getAppAndVersion returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new l("mocked error")]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if the dashboard is open and open app returns an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),k.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),m([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if another app is open, and close app returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if another app is open, close app succeeds but open app returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({data:void 0})),S.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if getAppAndVersion actor throws an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new V("Unknown error")]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)}),it("should end in an error if openApp actor throws an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),m([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockImplementation(()=>{throw new V("Unknown error")});const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)}),it("should end in an error if closeApp actor throws an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),m([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),v.mockImplementation(()=>{throw new V("Unknown error")});const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)})}),it("should emit a stopped state if the action is cancelled",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Stopped}],{cancel:D}=c(t,i,s(),r);D()})});
|
1
|
+
import{lastValueFrom as O}from"rxjs";import{InvalidStatusWordError as l}from"../../../command/Errors";import{CommandResultFactory as A}from"../../../command/model/CommandResult";import{DeviceModelId as R}from"../../../device/DeviceModel";import{DeviceStatus as o}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as s}from"../../../device-action/__test-utils__/makeInternalApi";import{setupGetDeviceStatusMock as m}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 n}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as y,DeviceNotOnboardedError as f,UnknownDAError as V}from"../../../device-action/os/Errors";import{DeviceSessionStateType as a}from"../../../device-session/DeviceSessionState";import{OpenAppDeviceAction as u}from"./OpenAppDeviceAction";jest.mock("@api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction");describe("OpenAppDeviceAction",()=>{const k=jest.fn(),S=jest.fn(),v=jest.fn(),p=jest.fn(),N=jest.fn(),h=jest.fn();function d(){return{getDeviceSessionState:p,setDeviceSessionState:N,getAppAndVersion:k,openApp:S,closeApp:v,isDeviceOnboarded:h}}const{getDeviceSessionState:C}=s();beforeEach(()=>{jest.resetAllMocks(),h.mockReturnValue(!0)}),describe("without overriding `extractDependencies`",()=>{it("should end if the required application is opened",r=>{C.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"},installedApps:[],deviceModelId:R.NANO_X}),m([{currentApp:"Bitcoin",currentAppVersion:"0.0.0"}]);const t=new u({input:{appName:"Bitcoin"}}),i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}];c(t,i,s(),r)})}),describe("success cases",()=>{it("should end in a success if the app is already opened",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"Bitcoin",version:"1.0.0"}}),m([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]);const t=new u({input:{appName:"Bitcoin",unlockTimeout:void 0}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}];c(t,i,s(),r)}),it("should end in a success if a compatible app is already opened",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"Bitcoin Testnet",version:"1.0.0"}}),m([{currentApp:"Bitcoin Testnet",currentAppVersion:"1.0.0"}]);const t=new u({input:{appName:"Bitcoin",unlockTimeout:void 0,compatibleAppNames:["Bitcoin Testnet"]}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}];c(t,i,s(),r)}),it("should end in a success if the dashboard is open and open app succeeds",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}),m([{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),S.mockResolvedValue(A({data:void 0}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}],{observable:D}=c(t,i,s(),r);O(D).then(()=>{expect(N).toHaveBeenCalledWith({deviceStatus:o.CONNECTED,sessionStateType:a.ReadyWithoutSecureChannel,currentApp:{name:"Bitcoin",version:"1.0.0"}})})}),it("should end in a success if another app is open, close app succeeds and open app succeeds",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"},{currentApp:"Bitcoin",currentAppVersion:"1.0.0"}]),v.mockResolvedValue(A({data:void 0})),S.mockResolvedValue(A({data:void 0}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Completed,output:void 0}],{observable:D}=c(t,i,s(),r);O(D).then(()=>{expect(N).toHaveBeenCalledWith({currentApp:{name:"Bitcoin",version:"1.0.0"},deviceStatus:o.CONNECTED,sessionStateType:a.ReadyWithoutSecureChannel})})})}),describe("errors cases",()=>{it("should end in an error if the device is not onboarded",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),h.mockReturnValue(!1);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{error:new f,status:e.Error}];c(t,i,s(),r)}),it("should end in an error if the device is locked",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new y]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new y}];c(t,i,s(),r)}),it("should end in an error if getAppAndVersion returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new l("mocked error")]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if the dashboard is open and open app returns an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),k.mockResolvedValue(A({data:{name:"BOLOS",version:"0.0.0"}})),m([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if another app is open, and close app returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if another app is open, close app succeeds but open app returns an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]),v.mockResolvedValue(A({data:void 0})),S.mockResolvedValue(A({error:new l("mocked error")}));const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new l("mocked error")}];c(t,i,s(),r)}),it("should end in an error if getAppAndVersion actor throws an error",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),m([new V("Unknown error")]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)}),it("should end in an error if openApp actor throws an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),m([{currentApp:"BOLOS",currentAppVersion:"0.0.0"}]),S.mockImplementation(()=>{throw new V("Unknown error")});const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.ConfirmOpenApp}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)}),it("should end in an error if closeApp actor throws an error",r=>{p.mockReturnValue(A({data:{sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"BOLOS",version:"0.0.0"}}})),m([{currentApp:"anApp",currentAppVersion:"0.0.0"}]),v.mockImplementation(()=>{throw new V("Unknown error")});const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Error,error:new V("Unknown error")}];c(t,i,s(),r)})}),it("should emit a stopped state if the action is cancelled",r=>{p.mockReturnValue({sessionStateType:a.ReadyWithoutSecureChannel,deviceStatus:o.CONNECTED,currentApp:{name:"AnotherApp",version:"0.0.0"}}),m([{currentApp:"AnotherApp",currentAppVersion:"0.0.0"}]);const t=new u({input:{appName:"Bitcoin"}});jest.spyOn(t,"extractDependencies").mockReturnValue(d());const i=[{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Pending,intermediateValue:{requiredUserInteraction:n.None}},{status:e.Stopped}],{cancel:D}=c(t,i,s(),r);D()})});
|
2
2
|
//# sourceMappingURL=OpenAppDeviceAction.test.js.map
|