@ledgerhq/device-management-kit 1.7.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -3
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/DeviceManagementKitBuilder.test.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKitBuilder.test.js.map +2 -2
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js +1 -1
- package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallLanguagePackage/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallLanguagePackage/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
- package/lib/cjs/src/api/index.js +1 -1
- package/lib/cjs/src/api/index.js.map +3 -3
- package/lib/cjs/src/api/types.js +1 -1
- package/lib/cjs/src/api/types.js.map +3 -3
- package/lib/cjs/src/api/utils/ApplicationChecker.js +1 -1
- package/lib/cjs/src/api/utils/ApplicationChecker.js.map +3 -3
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js +1 -1
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js.map +2 -2
- package/lib/cjs/src/api/utils/apduLogs.js +1 -1
- package/lib/cjs/src/api/utils/apduLogs.js.map +3 -3
- package/lib/cjs/src/api/utils/apduLogs.test.js +1 -1
- package/lib/cjs/src/api/utils/apduLogs.test.js.map +3 -3
- package/lib/cjs/src/di.test.js +2 -0
- package/lib/cjs/src/di.test.js.map +7 -0
- 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/model/DeviceSessionRefresher.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +2 -2
- 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/model/Const.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Const.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/model/Firmware.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Firmware.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js.map +2 -2
- 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/manager-api/service/ManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
- package/lib/cjs/src/internal/secure-channel/model/Errors.js +1 -1
- package/lib/cjs/src/internal/secure-channel/model/Errors.js.map +2 -2
- package/lib/cjs/src/internal/secure-channel/service/DefaultSecureChannelService.js +1 -1
- package/lib/cjs/src/internal/secure-channel/service/DefaultSecureChannelService.js.map +3 -3
- package/lib/cjs/src/internal/secure-channel/service/SecureChannelService.js +1 -1
- package/lib/cjs/src/internal/secure-channel/service/SecureChannelService.js.map +1 -1
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/DeviceManagementKitBuilder.test.js +1 -1
- package/lib/esm/src/api/DeviceManagementKitBuilder.test.js.map +2 -2
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/esm/src/api/device-action/model/UserInteractionRequired.js +1 -1
- package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +2 -2
- package/lib/esm/src/api/device-action/os/InstallLanguagePackage/types.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallLanguagePackage/types.js.map +3 -3
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
- package/lib/esm/src/api/index.js +1 -1
- package/lib/esm/src/api/index.js.map +3 -3
- package/lib/esm/src/api/types.js +1 -0
- package/lib/esm/src/api/types.js.map +4 -4
- package/lib/esm/src/api/utils/ApplicationChecker.js +1 -1
- package/lib/esm/src/api/utils/ApplicationChecker.js.map +3 -3
- package/lib/esm/src/api/utils/ApplicationChecker.test.js +1 -1
- package/lib/esm/src/api/utils/ApplicationChecker.test.js.map +2 -2
- package/lib/esm/src/api/utils/apduLogs.js +1 -1
- package/lib/esm/src/api/utils/apduLogs.js.map +3 -3
- package/lib/esm/src/api/utils/apduLogs.test.js +1 -1
- package/lib/esm/src/api/utils/apduLogs.test.js.map +3 -3
- package/lib/esm/src/di.test.js +2 -0
- package/lib/esm/src/di.test.js.map +7 -0
- 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/model/DeviceSessionRefresher.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/model/Const.js +1 -1
- package/lib/esm/src/internal/manager-api/model/Const.js.map +2 -2
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js.map +2 -2
- 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/secure-channel/model/Errors.js +1 -1
- package/lib/esm/src/internal/secure-channel/model/Errors.js.map +3 -3
- package/lib/esm/src/internal/secure-channel/service/DefaultSecureChannelService.js +1 -1
- package/lib/esm/src/internal/secure-channel/service/DefaultSecureChannelService.js.map +3 -3
- package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts +3 -0
- package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
- package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +3 -1
- package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts +0 -9
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +4 -4
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallLanguagePackage/types.d.ts +1 -0
- package/lib/types/src/api/device-action/os/InstallLanguagePackage/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts +2 -0
- package/lib/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts.map +1 -1
- package/lib/types/src/api/index.d.ts +3 -4
- package/lib/types/src/api/index.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/api/utils/ApplicationChecker.d.ts +17 -0
- package/lib/types/src/api/utils/ApplicationChecker.d.ts.map +1 -1
- package/lib/types/src/api/utils/apduLogs.d.ts +15 -0
- package/lib/types/src/api/utils/apduLogs.d.ts.map +1 -1
- package/lib/types/src/di.test.d.ts +2 -0
- package/lib/types/src/di.test.d.ts.map +1 -0
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionRefresher.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts +2 -2
- package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +4 -4
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Const.d.ts +1 -1
- package/lib/types/src/internal/manager-api/model/Const.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Firmware.d.ts +3 -0
- package/lib/types/src/internal/manager-api/model/Firmware.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +2 -1
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +9 -3
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
- package/lib/types/src/internal/secure-channel/model/Errors.d.ts +8 -1
- package/lib/types/src/internal/secure-channel/model/Errors.d.ts.map +1 -1
- package/lib/types/src/internal/secure-channel/service/DefaultSecureChannelService.d.ts +1 -1
- package/lib/types/src/internal/secure-channel/service/DefaultSecureChannelService.d.ts.map +1 -1
- package/lib/types/src/internal/secure-channel/service/SecureChannelService.d.ts +2 -2
- package/lib/types/src/internal/secure-channel/service/SecureChannelService.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib/cjs/src/api/command/os/BackupStorageCommand.js +0 -2
- package/lib/cjs/src/api/command/os/BackupStorageCommand.js.map +0 -7
- package/lib/cjs/src/api/command/os/BackupStorageCommand.test.js +0 -2
- package/lib/cjs/src/api/command/os/BackupStorageCommand.test.js.map +0 -7
- package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.js +0 -2
- package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.js.map +0 -7
- package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.test.js +0 -2
- package/lib/cjs/src/api/command/os/GetAppStorageInfoCommand.test.js.map +0 -7
- package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.js +0 -2
- package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.js.map +0 -7
- package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.test.js +0 -2
- package/lib/cjs/src/api/device-action/task/BackupAppStorageTask.test.js.map +0 -7
- package/lib/cjs/src/api/storage/KeyValueStorage.js +0 -2
- package/lib/cjs/src/api/storage/KeyValueStorage.js.map +0 -7
- package/lib/esm/src/api/command/os/BackupStorageCommand.js +0 -2
- package/lib/esm/src/api/command/os/BackupStorageCommand.js.map +0 -7
- package/lib/esm/src/api/command/os/BackupStorageCommand.test.js +0 -2
- package/lib/esm/src/api/command/os/BackupStorageCommand.test.js.map +0 -7
- package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.js +0 -2
- package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.js.map +0 -7
- package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.test.js +0 -2
- package/lib/esm/src/api/command/os/GetAppStorageInfoCommand.test.js.map +0 -7
- package/lib/esm/src/api/device-action/task/BackupAppStorageTask.js +0 -2
- package/lib/esm/src/api/device-action/task/BackupAppStorageTask.js.map +0 -7
- package/lib/esm/src/api/device-action/task/BackupAppStorageTask.test.js +0 -2
- package/lib/esm/src/api/device-action/task/BackupAppStorageTask.test.js.map +0 -7
- package/lib/esm/src/api/storage/KeyValueStorage.js +0 -2
- package/lib/esm/src/api/storage/KeyValueStorage.js.map +0 -7
- package/lib/types/src/api/command/os/BackupStorageCommand.d.ts +0 -23
- package/lib/types/src/api/command/os/BackupStorageCommand.d.ts.map +0 -1
- package/lib/types/src/api/command/os/BackupStorageCommand.test.d.ts +0 -2
- package/lib/types/src/api/command/os/BackupStorageCommand.test.d.ts.map +0 -1
- package/lib/types/src/api/command/os/GetAppStorageInfoCommand.d.ts +0 -31
- package/lib/types/src/api/command/os/GetAppStorageInfoCommand.d.ts.map +0 -1
- package/lib/types/src/api/command/os/GetAppStorageInfoCommand.test.d.ts +0 -2
- package/lib/types/src/api/command/os/GetAppStorageInfoCommand.test.d.ts.map +0 -1
- package/lib/types/src/api/device-action/task/BackupAppStorageTask.d.ts +0 -23
- package/lib/types/src/api/device-action/task/BackupAppStorageTask.d.ts.map +0 -1
- package/lib/types/src/api/device-action/task/BackupAppStorageTask.test.d.ts +0 -2
- package/lib/types/src/api/device-action/task/BackupAppStorageTask.test.d.ts.map +0 -1
- package/lib/types/src/api/storage/KeyValueStorage.d.ts +0 -7
- package/lib/types/src/api/storage/KeyValueStorage.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport {\n EMPTY,\n from,\n interval,\n mergeMap,\n type Observable,\n of,\n switchMap,\n take,\n} from \"rxjs\";\nimport { timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\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 {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\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 type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName, LEDGER_OS_NAME } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getOsVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n const allowNonOnboardedDevice = this.input.allowNonOnboardedDevice ?? true;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n allowNonOnboardedDevice,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n getOsVersion: fromPromise(getOsVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isAllowedNonOnboardedDevice: ({ context }) => {\n const secureElementFlags =\n context._internalState.osVersionMetadata?.secureElementFlags;\n return (\n context.input.allowNonOnboardedDevice === true &&\n secureElementFlags?.isOnboarded === false\n );\n },\n isDeviceLocked: ({ context }) => context._internalState.locked,\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 assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzadjiHx2KyORbzcRBczmH4IbTOdjaabaKmdGy6XSRaIw1bbdZJL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BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n allowNonOnboardedDevice: _.input.allowNonOnboardedDevice ?? true,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n _internalState: {\n onboarded: false,\n locked: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"AppAndVersionCheck\",\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n } else {\n // The device can be set to Ready if GetAppAndVersionCommand was successful.\n // The firmware version and secure connection flag are enriched later from\n // the OS version, which can only be read on the dashboard.\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: _.event.output.data,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n if (\"errorCode\" in _.event.output.error) {\n if (_.event.output.error.errorCode === \"5515\") {\n // Locked device error\n return {\n ..._.context._internalState,\n locked: true,\n };\n } else if (_.event.output.error.errorCode === \"6e00\") {\n // CLA not supported\n // GetAppAndVersion should always be supported by the firmware or any app.\n // But on old firmware versions, that APDU was not supported in the dashboard.\n // On those firmwares, it fails with CLA_NOT_SUPPORTED in BOLOS, and INS_NOT_SUPPORTED\n // in applications. Therefore if CLA is not supported, we can consider we're on the\n // dashboard on an old firmware. We should therefore return that information to\n // ensure the user can still update his firmware and is not blocked at this step.\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: LEDGER_OS_NAME,\n currentAppVersion: \"0.0.0\",\n };\n }\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"UserActionUnlockDevice\",\n guard: \"isDeviceLocked\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n guard: \"isAllowedNonOnboardedDevice\",\n target: \"Success\",\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n interval(1000).pipe(\n switchMap(() =>\n from(internalApi.sendCommand(new GetAppAndVersionCommand())),\n ),\n mergeMap((output) => {\n const isLocked =\n !isSuccessCommandResult(output) &&\n \"errorCode\" in output.error &&\n output.error.errorCode === \"5515\";\n if (isLocked) {\n return EMPTY; // Continue the polling\n }\n return of(undefined); // Complete the observable\n }),\n take(1),\n timeout(input.unlockTimeout),\n );\n\n return {\n getAppAndVersion,\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,
|
|
6
|
-
"names": ["Left", "Right", "
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetOsVersionCommand,\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\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 { WaitForAppAndVersionDeviceAction } from \"@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction\";\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 type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { isDashboardName } from \"@api/utils/AppName\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly osVersionMetadata: GetOsVersionResponse | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getOsVersion: () => Promise<GetOsVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n};\n\nconst firmwareVersionFromOsVersion = (\n data: GetOsVersionResponse,\n): FirmwareVersion => ({\n mcu: data.mcuSephVersion,\n bootloader: data.mcuBootloaderVersion,\n os: data.seVersion,\n metadata: data,\n});\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const { getOsVersion, getDeviceSessionState, setDeviceSessionState } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n const allowNonOnboardedDevice = this.input.allowNonOnboardedDevice ?? true;\n\n const updateSessionFromOsVersion = (data: GetOsVersionResponse) => {\n const currentState = getDeviceSessionState();\n if (currentState.sessionStateType === DeviceSessionStateType.Connected) {\n return;\n }\n setDeviceSessionState({\n ...currentState,\n firmwareVersion: firmwareVersionFromOsVersion(data),\n isSecureConnectionAllowed:\n data.secureElementFlags.isSecureConnectionAllowed,\n });\n };\n\n const waitForAppAndVersion = new WaitForAppAndVersionDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n allowNonOnboardedDevice,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n waitForAppAndVersion,\n getOsVersion: fromPromise(getOsVersion),\n },\n guards: {\n isCurrentAppBolos: ({ context }) =>\n isDashboardName(context._internalState.currentApp),\n isOnboardedFromOsVersion: ({ context }) =>\n context._internalState.osVersionMetadata?.secureElementFlags\n .isOnboarded === true,\n isAllowedNonOnboardedDevice: ({ context }) => {\n const secureElementFlags =\n context._internalState.osVersionMetadata?.secureElementFlags;\n return (\n context.input.allowNonOnboardedDevice === true &&\n secureElementFlags?.isOnboarded === false\n );\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 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 N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzad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D5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n allowNonOnboardedDevice: _.input.allowNonOnboardedDevice ?? true,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.WAIT_FOR_APP_AND_VERSION,\n },\n _internalState: {\n onboarded: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n osVersionMetadata: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"WaitForAppAndVersion\",\n },\n },\n WaitForAppAndVersion: {\n // We check the current app and version using the getAppAndVersion\n // command. This command is supported both on the dashboard (BOLOS)\n // and inside applications, so it is used to determine the currently\n // running app before deciding whether to read the OS version.\n invoke: {\n src: \"waitForAppAndVersion\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"WaitForAppAndVersionResultCheck\",\n actions: assign({\n _internalState: (_): GetDeviceStatusMachineInternalState => {\n return _.event.output.caseOf<GetDeviceStatusMachineInternalState>(\n {\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n Right: (output) => {\n const state: DeviceSessionState =\n getDeviceSessionState();\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n // Update the current app\n setDeviceSessionState({\n ...state,\n currentApp: output,\n });\n } else {\n setDeviceSessionState({\n deviceModelId: state.deviceModelId,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: output,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n return {\n ..._.context._internalState,\n currentApp: output.name,\n currentAppVersion: output.version,\n };\n },\n },\n );\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n WaitForAppAndVersionResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OnboardingCheck\",\n },\n ],\n },\n OnboardingCheck: {\n entry: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n }),\n }),\n always: [\n {\n // The OS version (and thus the onboarding flag) can only be read\n // on the dashboard. If we are inside an application, fetching it\n // would fail, so we only fetch it when the current app is BOLOS.\n guard: \"isCurrentAppBolos\",\n target: \"GetOsVersion\",\n },\n {\n // A non-BOLOS application can only run on an onboarded device, so\n // if an app is open we can safely consider the device onboarded\n // without reading the OS version.\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n ],\n },\n GetOsVersion: {\n invoke: {\n src: \"getOsVersion\",\n onDone: {\n target: \"OnboardingResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n updateSessionFromOsVersion(_.event.output.data);\n return {\n ..._.context._internalState,\n osVersionMetadata: _.event.output.data,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OnboardingResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"isOnboardedFromOsVersion\",\n target: \"Success\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n guard: \"isAllowedNonOnboardedDevice\",\n target: \"Success\",\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n return {\n getOsVersion: () => internalApi.sendCommand(new GetOsVersionCommand()),\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,eAAAC,EAAa,SAAAC,MAAa,SAE3C,OAAS,0BAAAC,MAA8B,mCACvC,OACE,uBAAAC,MAGK,sCACP,OAAS,gBAAAC,MAAoB,2BAE7B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,2BAAAC,MAA+B,+BACxC,OAAS,oCAAAC,MAAwC,8EAEjD,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MAEK,yCACP,OAAS,mBAAAC,MAAuB,qBAEhC,OAKE,8BAAAC,MACK,UAkBP,MAAMC,EACJC,IACqB,CACrB,IAAKA,EAAK,eACV,WAAYA,EAAK,qBACjB,GAAIA,EAAK,UACT,SAAUA,CACZ,GAMO,MAAMC,UAAoCN,CAM/C,CACA,iBACEO,EAOA,CASA,KAAM,CAAE,aAAAC,EAAc,sBAAAC,EAAuB,sBAAAC,CAAsB,EACjE,KAAK,oBAAoBH,CAAW,EAEhCI,EA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EZhC,EAA+B,CACpC,WAAYoC,EACZ,kBAAmBC,CACrB,CAAC,CACH,CACF,CAAC,CACH,CAEA,oBAAoBnB,EAA+C,CACjE,MAAO,CACL,aAAc,IAAMA,EAAY,YAAY,IAAIb,CAAqB,EACrE,sBAAuB,IAAMa,EAAY,sBAAsB,EAC/D,sBAAwBgB,GACtBhB,EAAY,sBAAsBgB,CAAK,CAC3C,CACF,CACF",
|
|
6
|
+
"names": ["Left", "Right", "assign", "fromPromise", "setup", "isSuccessCommandResult", "GetOsVersionCommand", "DeviceStatus", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceNotOnboardedError", "WaitForAppAndVersionDeviceAction", "XStateDeviceAction", "DeviceSessionStateType", "isDashboardName", "getDeviceStatusDAStateStep", "firmwareVersionFromOsVersion", "data", "GetDeviceStatusDeviceAction", "internalApi", "getOsVersion", "getDeviceSessionState", "setDeviceSessionState", "unlockTimeout", "allowNonOnboardedDevice", "updateSessionFromOsVersion", "currentState", "waitForAppAndVersion", "context", "secureElementFlags", "_", "sessionState", "sessionStateType", "error", "output", "state", "args", "currentApp", "currentAppVersion"]
|
|
7
7
|
}
|
package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{interval as B,Observable as w}from"rxjs";import{CommandResultFactory as y}from"../../../command/model/CommandResult";import{getOsVersionCommandResponseMockBuilder as I}from"../../../command/os/__mocks__/GetOsVersionCommand";import{GLOBAL_ERRORS as x,GlobalCommandError as L}from"../../../command/utils/GlobalCommandError";import{DeviceModelId as l}from"../../../device/DeviceModel";import{DeviceStatus as i}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as a}from"../../../device-action/__test-utils__/makeInternalApi";import{testDeviceActionStates as d}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as c}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as P}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as b,DeviceNotOnboardedError as _,UnknownDAError as M}from"../../../device-action/os/Errors";import{DeviceSessionStateType as s}from"../../../device-session/DeviceSessionState";import{GetDeviceStatusDeviceAction as p}from"./GetDeviceStatusDeviceAction";import{getDeviceStatusDAStateStep as G}from"./types";const k=(u={},D=l.NANO_X)=>y({data:I(D,u)}),O=(u,D)=>y({data:{name:u,version:D}}),f=()=>y({error:new L({...x[5515],errorCode:"5515"})}),S=()=>({intermediateValue:{requiredUserInteraction:P.None,step:G.ONBOARD_CHECK},status:c.Pending}),C=()=>[S(),S()],g=()=>({intermediateValue:{requiredUserInteraction:P.UnlockDevice,step:G.UNLOCK_DEVICE},status:c.Pending}),T=()=>({intermediateValue:{requiredUserInteraction:P.None,step:G.UNLOCK_DEVICE},status:c.Pending});describe("GetDeviceStatusDeviceAction",()=>{const u=vi.fn(),D=vi.fn(),v=vi.fn(),h=vi.fn(),R=vi.fn();function A(){return{getAppAndVersion:u,getOsVersion:D,getDeviceSessionState:v,waitForDeviceUnlock:h,setDeviceSessionState:R}}const{sendCommand:E,getDeviceSessionState:V,getDeviceSessionStateObservable:W}=a();beforeEach(()=>{vi.resetAllMocks(),D.mockResolvedValue(k())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with an unlocked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(O("BOLOS","1.0.0")));const t=[...C(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,t,a(),{onDone:n,onError:o})})),it("should run the device action with a locked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:1500}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1});let t=0;E.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(k()):(t+=1,t===1?Promise.resolve(f()):Promise.resolve(O("BOLOS","1.0.0"))));const r=[S(),g(),T(),T(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];d(e,r,a(),{onDone:n,onError:o})})),it("should timeout with a locked device",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:200}});V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(f()));const t=[S(),g(),{error:new b("Device locked."),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should run the device action with an old firmware not supporting GetAppAndVersion",()=>new Promise((n,o)=>{const e=new p({input:{unlockTimeout:500}});V.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),E.mockImplementation(r=>r.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(y({error:new L({...x["6e00"],errorCode:"6e00"})})));const t=[...C(),{output:{currentApp:"BOLOS",currentAppVersion:"0.0.0"},status:c.Completed}];d(e,t,a(),{onDone:n,onError:o})}))}),describe("success cases",()=>{it("should return the device status if the device is unlocked",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(O("BOLOS","1.0.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),n()},onError:o})})),it("should return the device status and update session if the device is not ready",()=>new Promise((n,o)=>{let e={sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X};v.mockImplementation(()=>e),R.mockImplementation(N=>(e=N,N)),u.mockResolvedValue(O("BOLOS","1.0.0"));const t=new p({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const r=I(l.NANO_X),m=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(t,m,a(),{onDone:()=>{expect(R).toHaveBeenCalledWith({deviceModelId:l.NANO_X,sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:r.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:r.mcuSephVersion,bootloader:r.mcuBootloaderVersion,os:r.seVersion,metadata:r}}),n()},onError:o})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.Connected,deviceStatus:i.CONNECTED,deviceModelId:l.NANO_X}),u.mockResolvedValue(O("Bitcoin","2.1.0"));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),{status:c.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];d(e,t,a(),{onDone:()=>{expect(D).not.toHaveBeenCalled(),n()},onError:o})})),it("GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),u.mockResolvedValue(O("BOLOS","1.0.0")),D.mockResolvedValue(k({secureElementFlags:{...I().secureElementFlags,isOnboarded:!1}}));const e=new p({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:n,onError:o})})),it("should return the device status if the device is locked and the user unlocks the device",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValueOnce(f()).mockResolvedValueOnce(O("BOLOS","1.0.0")),h.mockImplementation(()=>new w(r=>{const m=B(50).subscribe({next:N=>{N>2?(r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),r.complete()):r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),g(),T(),T(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];d(e,t,a(),{onDone:n,onError:o})}))}),describe("errors cases",()=>{it("GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),u.mockResolvedValue(O("BOLOS","1.0.0")),D.mockResolvedValue(k({secureElementFlags:{...I().secureElementFlags,isOnboarded:!1}}));const e=new p({input:{unlockTimeout:500,allowNonOnboardedDevice:!1}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[...C(),{error:new _,status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockResolvedValue(f()),h.mockImplementation(()=>new w(r=>{r.error(new b("Device locked."))})),W.mockImplementation(()=>new w(r=>{const m=B(200).subscribe({next:()=>{r.next({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1})}});return()=>{m.unsubscribe()}}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),g(),{error:new b("Device locked."),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})})),it("should end in an error if the GetAppAndVersion command fails",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new L({...x[5501],errorCode:"5501"});u.mockResolvedValue(y({error:e})),h.mockImplementation(()=>new w(m=>{m.complete()}));const t=new p({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(A());const r=[S(),{error:e,status:c.Error}];d(t,r,a(),{onDone:n,onError:o})})),it("should end in an error if getAppAndVersion actor throws an error",()=>new Promise((n,o)=>{v.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}}),u.mockImplementation(()=>{throw new M("error")}),h.mockImplementation(()=>new w(r=>{r.complete()}));const e=new p({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(A());const t=[S(),{error:new M("error"),status:c.Error}];d(e,t,a(),{onDone:n,onError:o})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((n,o)=>{V.mockReturnValue({sessionStateType:s.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:l.NANO_X,isSecureConnectionAllowed:!1}),E.mockImplementation(m=>m.name==="getOsVersion"?Promise.resolve(k()):Promise.resolve(O("BOLOS","1.0.0")));const e=new p({input:{unlockTimeout:500}}),t=[S(),{status:c.Stopped}],{cancel:r}=d(e,t,a(),{onDone:n,onError:o});r()}))});
|
|
1
|
+
import{CommandResultFactory as g}from"../../../command/model/CommandResult";import{getOsVersionCommandResponseMockBuilder as C}from"../../../command/os/__mocks__/GetOsVersionCommand";import{GLOBAL_ERRORS as w,GlobalCommandError as N}from"../../../command/utils/GlobalCommandError";import{DeviceModelId as O}from"../../../device/DeviceModel";import{DeviceStatus as u}from"../../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as a}from"../../../device-action/__test-utils__/makeInternalApi";import{setupWaitForAppAndVersionMock as d}from"../../../device-action/__test-utils__/setupTestMachine";import{testDeviceActionStates as p}from"../../../device-action/__test-utils__/testDeviceActionStates";import{DeviceActionStatus as c}from"../../../device-action/model/DeviceActionState";import{UserInteractionRequired as k}from"../../../device-action/model/UserInteractionRequired";import{DeviceLockedError as f,DeviceNotOnboardedError as L,UnknownDAError as T}from"../../../device-action/os/Errors";import{DeviceSessionStateType as l}from"../../../device-session/DeviceSessionState";import{GetDeviceStatusDeviceAction as v}from"./GetDeviceStatusDeviceAction";import{getDeviceStatusDAStateStep as G}from"./types";vi.mock("@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction");const h=(r={},s=O.NANO_X)=>g({data:C(s,r)}),m=(r,s)=>({name:r,version:s}),A=(r=k.None)=>({intermediateValue:{requiredUserInteraction:r,step:G.ONBOARD_CHECK},status:c.Pending}),n=(r=k.None)=>({intermediateValue:{requiredUserInteraction:r,step:G.WAIT_FOR_APP_AND_VERSION},status:c.Pending});describe("GetDeviceStatusDeviceAction",()=>{const r=vi.fn(),s=vi.fn(),V=vi.fn();function D(){return{getOsVersion:r,getDeviceSessionState:s,setDeviceSessionState:V}}const{sendCommand:E,getDeviceSessionState:R}=a();beforeEach(()=>{vi.resetAllMocks(),r.mockResolvedValue(h())}),describe("without overriding `extractDependencies`",()=>{it("should run the device action with the device on the dashboard",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),R.mockReturnValue({sessionStateType:l.Connected,deviceStatus:u.CONNECTED,deviceModelId:O.NANO_X}),E.mockResolvedValue(h());const e=new v({input:{unlockTimeout:500}}),t=[n(),n(),A(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];p(e,t,a(),{onDone:o,onError:i})})),it("should run the device action when the device needs to be unlocked",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0"),k.UnlockDevice),R.mockReturnValue({sessionStateType:l.Connected,deviceStatus:u.LOCKED,deviceModelId:O.NANO_X}),E.mockResolvedValue(h());const e=new v({input:{unlockTimeout:500}}),t=[n(),n(k.UnlockDevice),A(),{output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"},status:c.Completed}];p(e,t,a(),{onDone:o,onError:i})}))}),describe("success cases",()=>{it("should return the device status if the device is on the dashboard",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),A(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];p(e,t,a(),{onDone:o,onError:i})})),it("should return the device status and update the session firmware version",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0"));let e={sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:O.NANO_X,isSecureConnectionAllowed:!1};s.mockImplementation(()=>e),V.mockImplementation(y=>(e=y,y));const t=new v({input:{unlockTimeout:void 0}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=C(O.NANO_X),B=[n(),n(),A(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];p(t,B,a(),{onDone:()=>{expect(V).toHaveBeenCalledWith(expect.objectContaining({isSecureConnectionAllowed:S.secureElementFlags.isSecureConnectionAllowed,firmwareVersion:{mcu:S.mcuSephVersion,bootloader:S.mcuBootloaderVersion,os:S.seVersion,metadata:S}})),o()},onError:i})})),it("should not fetch the OS version when an app other than BOLOS is open",()=>new Promise((o,i)=>{d(m("Bitcoin","2.1.0")),s.mockReturnValue({sessionStateType:l.Connected,deviceStatus:u.CONNECTED,deviceModelId:O.NANO_X});const e=new v({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),{status:c.Completed,output:{currentApp:"Bitcoin",currentAppVersion:"2.1.0"}}];p(e,t,a(),{onDone:()=>{expect(r).not.toHaveBeenCalled(),o()},onError:i})})),it("GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:O.NANO_X,isSecureConnectionAllowed:!1}),r.mockResolvedValue(h({secureElementFlags:{...C().secureElementFlags,isOnboarded:!1}}));const e=new v({input:{unlockTimeout:void 0}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),A(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];p(e,t,a(),{onDone:o,onError:i})})),it("should surface the unlock interaction then return the device status",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0"),k.UnlockDevice),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(k.UnlockDevice),A(),{status:c.Completed,output:{currentApp:"BOLOS",currentAppVersion:"1.0.0"}}];p(e,t,a(),{onDone:o,onError:i})}))}),describe("errors cases",()=>{it("GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"},installedApps:[],deviceModelId:O.NANO_X,isSecureConnectionAllowed:!1}),r.mockResolvedValue(h({secureElementFlags:{...C().secureElementFlags,isOnboarded:!1}}));const e=new v({input:{unlockTimeout:500,allowNonOnboardedDevice:!1}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),A(),{error:new L,status:c.Error}];p(e,t,a(),{onDone:o,onError:i})})),it("should end in an error if the device is locked and the user does not unlock",()=>new Promise((o,i)=>{d(new f("Device locked."),k.UnlockDevice),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const e=new v({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(k.UnlockDevice),{error:new f("Device locked."),status:c.Error}];p(e,t,a(),{onDone:o,onError:i})})),it("should end in an error if the WaitForAppAndVersion sub-action fails",()=>new Promise((o,i)=>{const e=new N({...w[5501],errorCode:"5501"});d(e),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.LOCKED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"}});const t=new v({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=[n(),n(),{error:e,status:c.Error}];p(t,S,a(),{onDone:o,onError:i})})),it("should end in an error if the GetOsVersion command fails",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}});const e=new N({...w[5501],errorCode:"5501"});r.mockResolvedValue(g({error:e}));const t=new v({input:{unlockTimeout:500}});vi.spyOn(t,"extractDependencies").mockReturnValue(D());const S=[n(),n(),A(),{error:e,status:c.Error}];p(t,S,a(),{onDone:o,onError:i})})),it("should end in an error if the getOsVersion actor throws an error",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),s.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"BOLOS",version:"1.0.0"}}),r.mockImplementation(()=>{throw new T("error")});const e=new v({input:{unlockTimeout:500}});vi.spyOn(e,"extractDependencies").mockReturnValue(D());const t=[n(),n(),A(),{error:new T("error"),status:c.Error}];p(e,t,a(),{onDone:o,onError:i})}))}),it("should emit a stopped state if the action is cancelled",()=>new Promise((o,i)=>{d(m("BOLOS","1.0.0")),R.mockReturnValue({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:u.CONNECTED,currentApp:{name:"mockedCurrentApp",version:"1.0.0"},installedApps:[],deviceModelId:O.NANO_X,isSecureConnectionAllowed:!1}),E.mockResolvedValue(h());const e=new v({input:{unlockTimeout:500}}),t=[n(),n(),{status:c.Stopped}],{cancel:S}=p(e,t,a(),{onDone:o,onError:i});S()}))});
|
|
2
2
|
//# sourceMappingURL=GetDeviceStatusDeviceAction.test.js.map
|
package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { interval, Observable } from \"rxjs\";\n\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport {\n GLOBAL_ERRORS,\n GlobalCommandError,\n} from \"@api/command/utils/GlobalCommandError\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\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 {\n DeviceLockedError,\n DeviceNotOnboardedError,\n UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\n\nimport { GetDeviceStatusDeviceAction } from \"./GetDeviceStatusDeviceAction\";\nimport {\n type GetDeviceStatusDAState,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\nconst osVersionCommandResult = (\n props: Partial<GetOsVersionResponse> = {},\n deviceModelId: DeviceModelId = DeviceModelId.NANO_X,\n) =>\n CommandResultFactory({\n data: getOsVersionCommandResponseMockBuilder(deviceModelId, props),\n });\n\nconst appAndVersionResult = (name: string, version: string) =>\n CommandResultFactory({\n data: {\n name,\n version,\n },\n });\n\nconst lockedErrorResult = () =>\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5515\"],\n errorCode: \"5515\",\n }),\n });\n\nconst onboardCheckPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst onboardCheckPendingStatesWithOsVersionFetch =\n (): Array<GetDeviceStatusDAState> => [\n onboardCheckPendingState(),\n onboardCheckPendingState(),\n ];\n\nconst unlockRequestedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst unlockResolvedPendingState = (): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n step: getDeviceStatusDAStateStep.UNLOCK_DEVICE,\n },\n status: DeviceActionStatus.Pending,\n});\n\ndescribe(\"GetDeviceStatusDeviceAction\", () => {\n const getAppAndVersionMock = vi.fn();\n const getOsVersionMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const waitForDeviceUnlockMock = vi.fn();\n const setDeviceSessionState = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getAppAndVersion: getAppAndVersionMock,\n getOsVersion: getOsVersionMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n waitForDeviceUnlock: waitForDeviceUnlockMock,\n setDeviceSessionState: setDeviceSessionState,\n };\n }\n\n const {\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n } = makeDeviceActionInternalApiMock();\n beforeEach(() => {\n vi.resetAllMocks();\n getOsVersionMock.mockResolvedValue(osVersionCommandResult());\n });\n\n describe(\"without overriding `extractDependencies`\", () => {\n it(\"should run the device action with an unlocked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is called first to determine the current app, then\n // GetOsVersion is called because the app is BOLOS (dashboard).\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 1500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // First GetAppAndVersion fails because the device is locked, then it\n // succeeds (BOLOS) once unlocked, then GetOsVersion is fetched.\n let appCall = 0;\n sendCommandMock.mockImplementation((command) => {\n if (command.name === \"getOsVersion\") {\n return Promise.resolve(osVersionCommandResult());\n }\n appCall += 1;\n if (appCall === 1) {\n return Promise.resolve(lockedErrorResult());\n }\n return Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should timeout with a locked device\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 200 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // GetAppAndVersion always reports a locked device, so the unlock\n // polling times out.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(lockedErrorResult()),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action with an old firmware not supporting GetAppAndVersion\", () =>\n new Promise<void>((resolve, reject) => {\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // GetAppAndVersion is not supported (CLA_NOT_SUPPORTED), which means we\n // are on the dashboard of an old firmware: the current app is BOLOS so\n // the OS version can still be fetched.\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(\n CommandResultFactory({\n error: new GlobalCommandError({\n ...GLOBAL_ERRORS[\"6e00\"],\n errorCode: \"6e00\",\n }),\n }),\n ),\n );\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"0.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should return the device status if the device is unlocked\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be updated with current app\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status and update session if the device is not ready\", () =>\n new Promise<void>((resolve, reject) => {\n // The session state is stateful so the firmware version enrichment from\n // the OS version (which reads back the ready state) can be observed.\n let sessionState: object = {\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n };\n getDeviceSessionStateMock.mockImplementation(() => sessionState);\n setDeviceSessionState.mockImplementation((state) => {\n sessionState = state;\n return state;\n });\n\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const osVersionData = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.NANO_X,\n );\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be set as ready if GetAppAndVersionCommand was successful\n // and then enriched with the firmware version from the OS version.\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n deviceModelId: DeviceModelId.NANO_X,\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"BOLOS\",\n version: \"1.0.0\",\n },\n installedApps: [],\n isSecureConnectionAllowed:\n osVersionData.secureElementFlags.isSecureConnectionAllowed,\n firmwareVersion: {\n mcu: osVersionData.mcuSephVersion,\n bootloader: osVersionData.mcuBootloaderVersion,\n os: osVersionData.seVersion,\n metadata: osVersionData,\n },\n });\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should not fetch the OS version when an app other than BOLOS is open\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // An application is open: the device is necessarily onboarded and the\n // OS version cannot be read outside of the dashboard.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"Bitcoin\", \"2.1.0\"),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"Bitcoin\",\n currentAppVersion: \"2.1.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n expect(getOsVersionMock).not.toHaveBeenCalled();\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status if the device is locked and the user unlocks the device\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock\n .mockResolvedValueOnce(lockedErrorResult())\n .mockResolvedValueOnce(appAndVersionResult(\"BOLOS\", \"1.0.0\"));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(50).subscribe({\n next: (i) => {\n if (i > 2) {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n o.complete();\n } else {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: {\n name: \"mockedCurrentApp\",\n version: \"1.0.0\",\n },\n });\n }\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n unlockResolvedPendingState(),\n unlockResolvedPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"errors cases\", () => {\n it(\"GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n // A non-onboarded device sits on the dashboard (BOLOS), so the app check\n // succeeds and the OS version reveals the onboarding status.\n getAppAndVersionMock.mockResolvedValue(\n appAndVersionResult(\"BOLOS\", \"1.0.0\"),\n );\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout: 500,\n allowNonOnboardedDevice: false,\n },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n ...onboardCheckPendingStatesWithOsVersionFetch(),\n {\n error: new DeviceNotOnboardedError(),\n status: DeviceActionStatus.Error,\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the device is locked and the user does not unlock\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockResolvedValue(lockedErrorResult());\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.error(new DeviceLockedError(\"Device locked.\"));\n }),\n );\n\n apiGetDeviceSessionStateObservableMock.mockImplementation(\n () =>\n new Observable((o) => {\n const inner = interval(200).subscribe({\n next: () => {\n o.next({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n },\n });\n\n return () => {\n inner.unsubscribe();\n };\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n unlockRequestedPendingState(),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the GetAppAndVersion command fails\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const error = new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5501\"],\n errorCode: \"5501\",\n });\n\n getAppAndVersionMock.mockResolvedValue(CommandResultFactory({ error }));\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error,\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if getAppAndVersion actor throws an error\", () =>\n new Promise<void>((resolve, reject) => {\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n getAppAndVersionMock.mockImplementation(() => {\n throw new UnknownDAError(\"error\");\n });\n\n waitForDeviceUnlockMock.mockImplementation(\n () =>\n new Observable((o) => {\n o.complete();\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n error: new UnknownDAError(\"error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n it(\"should emit a stopped state if the action is cancelled\", () =>\n new Promise<void>((resolve, reject) => {\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n sendCommandMock.mockImplementation((command) =>\n command.name === \"getOsVersion\"\n ? Promise.resolve(osVersionCommandResult())\n : Promise.resolve(appAndVersionResult(\"BOLOS\", \"1.0.0\")),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Stopped,\n },\n ];\n\n const { cancel } = testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n cancel();\n }));\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,YAAAA,EAAU,cAAAC,MAAkB,OAErC,OAAS,wBAAAC,MAA4B,mCACrC,OAAS,0CAAAC,MAA8C,gDAEvD,OACE,iBAAAC,EACA,sBAAAC,MACK,wCACP,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,0BAAAC,MAA8B,2DACvC,OAAS,sBAAAC,MAA0B,6CACnC,OAAS,2BAAAC,MAA+B,mDACxC,OACE,qBAAAC,EACA,2BAAAC,EACA,kBAAAC,MACK,+BACP,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,+BAAAC,MAAmC,gCAC5C,OAEE,8BAAAC,MACK,UAEP,MAAMC,EAAyB,CAC7BC,EAAuC,CAAC,EACxCC,EAA+Bd,EAAc,SAE7CJ,EAAqB,CACnB,KAAMC,EAAuCiB,EAAeD,CAAK,CACnE,CAAC,EAEGE,EAAsB,CAACC,EAAcC,IACz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B,EAAyB,EACzB,CACE,MAAO,IAAIX,EAAe,OAAO,EACjC,OAAQJ,EAAmB,KAC7B,CACF,EAEAD,EACE+B,EACAE,EACAlC,EAAgC,EAChC,CACE,OAAQ8B,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,EAED,GAAG,yDAA0D,IAC3D,IAAI,QAAc,CAACD,EAASC,IAAW,CACrCH,EAA6B,gBAAgB,CAC3C,iBAAkBrB,EAAuB,0BACzC,aAAcR,EAAa,UAC3B,WAAY,CAAE,KAAM,mBAAoB,QAAS,OAAQ,EACzD,cAAe,CAAC,EAChB,cAAeD,EAAc,OAC7B,0BAA2B,EAC7B,CAAC,EAED6B,EAAgB,mBAAoBM,GAClCA,EAAQ,OAAS,eACb,QAAQ,QAAQvB,EAAuB,CAAC,EACxC,QAAQ,QAAQG,EAAoB,QAAS,OAAO,CAAC,CAC3D,EAEA,MAAMmB,EAA6B,IAAIxB,EAA4B,CACjE,MAAO,CAAE,cAAe,GAAI,CAC9B,CAAC,EAEK0B,EAAgD,CACpDjB,EAAyB,EACzB,CACE,OAAQf,EAAmB,OAC7B,CACF,EAEM,CAAE,OAAAyC,CAAO,EAAI1C,EACjB+B,EACAE,EACAlC,EAAgC,EAChC,CACE,OAAQ8B,EACR,QAASC,CACX,CACF,EACAY,EAAO,CACT,CAAC,CAAC,CACN,CAAC",
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { type GetAppAndVersionResponse } from \"@api/command/os/GetAppAndVersionCommand\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport {\n GLOBAL_ERRORS,\n GlobalCommandError,\n} from \"@api/command/utils/GlobalCommandError\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { setupWaitForAppAndVersionMock } 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 {\n DeviceLockedError,\n DeviceNotOnboardedError,\n UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\n\nimport { GetDeviceStatusDeviceAction } from \"./GetDeviceStatusDeviceAction\";\nimport {\n type GetDeviceStatusDARequiredInteraction,\n type GetDeviceStatusDAState,\n getDeviceStatusDAStateStep,\n} from \"./types\";\n\nvi.mock(\n \"@api/device-action/os/WaitForAppAndVersion/WaitForAppAndVersionDeviceAction\",\n);\n\nconst osVersionCommandResult = (\n props: Partial<GetOsVersionResponse> = {},\n deviceModelId: DeviceModelId = DeviceModelId.NANO_X,\n) =>\n CommandResultFactory({\n data: getOsVersionCommandResponseMockBuilder(deviceModelId, props),\n });\n\nconst appAndVersion = (\n name: string,\n version: string,\n): GetAppAndVersionResponse => ({\n name,\n version,\n});\n\nconst onboardCheckPendingState = (\n requiredUserInteraction: GetDeviceStatusDARequiredInteraction = UserInteractionRequired.None,\n): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction,\n step: getDeviceStatusDAStateStep.ONBOARD_CHECK,\n },\n status: DeviceActionStatus.Pending,\n});\n\nconst waitForAppAndVersionPendingState = (\n requiredUserInteraction: GetDeviceStatusDARequiredInteraction = UserInteractionRequired.None,\n): GetDeviceStatusDAState => ({\n intermediateValue: {\n requiredUserInteraction,\n step: getDeviceStatusDAStateStep.WAIT_FOR_APP_AND_VERSION,\n },\n status: DeviceActionStatus.Pending,\n});\n\ndescribe(\"GetDeviceStatusDeviceAction\", () => {\n const getOsVersionMock = vi.fn();\n const getDeviceSessionStateMock = vi.fn();\n const setDeviceSessionState = vi.fn();\n\n function extractDependenciesMock() {\n return {\n getOsVersion: getOsVersionMock,\n getDeviceSessionState: getDeviceSessionStateMock,\n setDeviceSessionState: setDeviceSessionState,\n };\n }\n\n const {\n sendCommand: sendCommandMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n } = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.resetAllMocks();\n getOsVersionMock.mockResolvedValue(osVersionCommandResult());\n });\n\n describe(\"without overriding `extractDependencies`\", () => {\n it(\"should run the device action with the device on the dashboard\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n // The current app is BOLOS (dashboard), so the OS version is fetched.\n sendCommandMock.mockResolvedValue(osVersionCommandResult());\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should run the device action when the device needs to be unlocked\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(\n appAndVersion(\"BOLOS\", \"1.0.0\"),\n UserInteractionRequired.UnlockDevice,\n );\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.LOCKED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n sendCommandMock.mockResolvedValue(osVersionCommandResult());\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(\n UserInteractionRequired.UnlockDevice,\n ),\n onboardCheckPendingState(),\n {\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n status: DeviceActionStatus.Completed,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"success cases\", () => {\n it(\"should return the device status if the device is on the dashboard\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should return the device status and update the session firmware version\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n // The session must already be ready (not Connected) for the firmware\n // version enrichment from the OS version to be applied. The session\n // state is stateful so the enrichment can be observed.\n let sessionState: object = {\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n };\n getDeviceSessionStateMock.mockImplementation(() => sessionState);\n setDeviceSessionState.mockImplementation((state) => {\n sessionState = state;\n return state;\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const osVersionData = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.NANO_X,\n );\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n // Session should be enriched with the firmware version from the OS version.\n expect(setDeviceSessionState).toHaveBeenCalledWith(\n expect.objectContaining({\n isSecureConnectionAllowed:\n osVersionData.secureElementFlags.isSecureConnectionAllowed,\n firmwareVersion: {\n mcu: osVersionData.mcuSephVersion,\n bootloader: osVersionData.mcuBootloaderVersion,\n os: osVersionData.seVersion,\n metadata: osVersionData,\n },\n }),\n );\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"should not fetch the OS version when an app other than BOLOS is open\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"Bitcoin\", \"2.1.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"Bitcoin\",\n currentAppVersion: \"2.1.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: () => {\n expect(getOsVersionMock).not.toHaveBeenCalled();\n resolve();\n },\n onError: reject,\n },\n );\n }));\n\n it(\"GIVEN a non-onboarded device WHEN checking the device status THEN it returns the device status by default\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: undefined },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should surface the unlock interaction then return the device status\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(\n appAndVersion(\"BOLOS\", \"1.0.0\"),\n UserInteractionRequired.UnlockDevice,\n );\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(\n UserInteractionRequired.UnlockDevice,\n ),\n onboardCheckPendingState(),\n {\n status: DeviceActionStatus.Completed,\n output: {\n currentApp: \"BOLOS\",\n currentAppVersion: \"1.0.0\",\n },\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n describe(\"errors cases\", () => {\n it(\"GIVEN a non-onboarded device and the non-onboarded allowance is disabled WHEN checking the device status THEN it returns a not-onboarded error\", () =>\n new Promise<void>((resolve, reject) => {\n // GIVEN\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n // The device sits on the dashboard (BOLOS), so the OS version reveals\n // the onboarding status.\n getOsVersionMock.mockResolvedValue(\n osVersionCommandResult({\n secureElementFlags: {\n ...getOsVersionCommandResponseMockBuilder().secureElementFlags,\n isOnboarded: false,\n },\n }),\n );\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: {\n unlockTimeout: 500,\n allowNonOnboardedDevice: false,\n },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n error: new DeviceNotOnboardedError(),\n status: DeviceActionStatus.Error,\n },\n ];\n\n // WHEN\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n // THEN\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the device is locked and the user does not unlock\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(\n new DeviceLockedError(\"Device locked.\"),\n UserInteractionRequired.UnlockDevice,\n );\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(\n UserInteractionRequired.UnlockDevice,\n ),\n {\n error: new DeviceLockedError(\"Device locked.\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the WaitForAppAndVersion sub-action fails\", () =>\n new Promise<void>((resolve, reject) => {\n const error = new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5501\"],\n errorCode: \"5501\",\n });\n\n setupWaitForAppAndVersionMock(error);\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n {\n error,\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the GetOsVersion command fails\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n });\n\n const error = new GlobalCommandError({\n ...GLOBAL_ERRORS[\"5501\"],\n errorCode: \"5501\",\n });\n\n getOsVersionMock.mockResolvedValue(CommandResultFactory({ error }));\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n error,\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n\n it(\"should end in an error if the getOsVersion actor throws an error\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n getDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"BOLOS\", version: \"1.0.0\" },\n });\n\n getOsVersionMock.mockImplementation(() => {\n throw new UnknownDAError(\"error\");\n });\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n vi.spyOn(\n getDeviceStateDeviceAction,\n \"extractDependencies\",\n ).mockReturnValue(extractDependenciesMock());\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n onboardCheckPendingState(),\n {\n error: new UnknownDAError(\"error\"),\n status: DeviceActionStatus.Error,\n },\n ];\n\n testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n }));\n });\n\n it(\"should emit a stopped state if the action is cancelled\", () =>\n new Promise<void>((resolve, reject) => {\n setupWaitForAppAndVersionMock(appAndVersion(\"BOLOS\", \"1.0.0\"));\n\n apiGetDeviceSessionStateMock.mockReturnValue({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: { name: \"mockedCurrentApp\", version: \"1.0.0\" },\n installedApps: [],\n deviceModelId: DeviceModelId.NANO_X,\n isSecureConnectionAllowed: false,\n });\n\n sendCommandMock.mockResolvedValue(osVersionCommandResult());\n\n const getDeviceStateDeviceAction = new GetDeviceStatusDeviceAction({\n input: { unlockTimeout: 500 },\n });\n\n const expectedStates: Array<GetDeviceStatusDAState> = [\n waitForAppAndVersionPendingState(),\n waitForAppAndVersionPendingState(),\n {\n status: DeviceActionStatus.Stopped,\n },\n ];\n\n const { cancel } = testDeviceActionStates(\n getDeviceStateDeviceAction,\n expectedStates,\n makeDeviceActionInternalApiMock(),\n {\n onDone: resolve,\n onError: reject,\n },\n );\n cancel();\n }));\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,wBAAAA,MAA4B,mCACrC,OAAS,0CAAAC,MAA8C,gDAGvD,OACE,iBAAAC,EACA,sBAAAC,MACK,wCACP,OAAS,iBAAAC,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OAAS,iCAAAC,MAAqC,qDAC9C,OAAS,0BAAAC,MAA8B,2DACvC,OAAS,sBAAAC,MAA0B,6CACnC,OAAS,2BAAAC,MAA+B,mDACxC,OACE,qBAAAC,EACA,2BAAAC,EACA,kBAAAC,MACK,+BACP,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,+BAAAC,MAAmC,gCAC5C,OAGE,8BAAAC,MACK,UAEP,GAAG,KACD,6EACF,EAEA,MAAMC,EAAyB,CAC7BC,EAAuC,CAAC,EACxCC,EAA+Bf,EAAc,SAE7CJ,EAAqB,CACnB,KAAMC,EAAuCkB,EAAeD,CAAK,CACnE,CAAC,EAEGE,EAAgB,CACpBC,EACAC,KAC8B,CAC9B,KAAAD,EACA,QAAAC,CACF,GAEMC,EAA2B,CAC/BC,EAAgEd,EA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AAO,EACjC,OAAQJ,EAAmB,KAC7B,CACF,EAEAD,EACE0B,EACAC,EACA7B,EAAgC,EAChC,CACE,OAAQ0B,EACR,QAASC,CACX,CACF,CACF,CAAC,CAAC,CACN,CAAC,EAED,GAAG,yDAA0D,IAC3D,IAAI,QAAc,CAACD,EAASC,IAAW,CACrC1B,EAA8Ba,EAAc,QAAS,OAAO,CAAC,EAE7DW,EAA6B,gBAAgB,CAC3C,iBAAkBjB,EAAuB,0BACzC,aAAcT,EAAa,UAC3B,WAAY,CAAE,KAAM,mBAAoB,QAAS,OAAQ,EACzD,cAAe,CAAC,EAChB,cAAeD,EAAc,OAC7B,0BAA2B,EAC7B,CAAC,EAED0B,EAAgB,kBAAkBb,EAAuB,CAAC,EAE1D,MAAMiB,EAA6B,IAAInB,EAA4B,CACjE,MAAO,CAAE,cAAe,GAAI,CAC9B,CAAC,EAEKoB,EAAgD,CACpDV,EAAiC,EACjCA,EAAiC,EACjC,CACE,OAAQhB,EAAmB,OAC7B,CACF,EAEM,CAAE,OAAA+B,CAAO,EAAIhC,EACjB0B,EACAC,EACA7B,EAAgC,EAChC,CACE,OAAQ0B,EACR,QAASC,CACX,CACF,EACAO,EAAO,CACT,CAAC,CAAC,CACN,CAAC",
|
|
6
|
+
"names": ["CommandResultFactory", "getOsVersionCommandResponseMockBuilder", "GLOBAL_ERRORS", "GlobalCommandError", "DeviceModelId", "DeviceStatus", "makeDeviceActionInternalApiMock", "setupWaitForAppAndVersionMock", "testDeviceActionStates", "DeviceActionStatus", "UserInteractionRequired", "DeviceLockedError", "DeviceNotOnboardedError", "UnknownDAError", "DeviceSessionStateType", "GetDeviceStatusDeviceAction", "getDeviceStatusDAStateStep", "osVersionCommandResult", "props", "deviceModelId", "appAndVersion", "name", "version", "onboardCheckPendingState", "requiredUserInteraction", "waitForAppAndVersionPendingState", "getOsVersionMock", "getDeviceSessionStateMock", "setDeviceSessionState", "extractDependenciesMock", "sendCommandMock", "apiGetDeviceSessionStateMock", "resolve", "reject", "getDeviceStateDeviceAction", "expectedStates", "sessionState", "state", "osVersionData", "error", "cancel"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=Object.freeze({
|
|
1
|
+
const e=Object.freeze({WAIT_FOR_APP_AND_VERSION:"os.getDeviceStatus.steps.waitForAppAndVersion",ONBOARD_CHECK:"os.getDeviceStatus.steps.onboardCheck"});export{e as getDeviceStatusDAStateStep};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { type
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { type DeviceNotOnboardedError } from \"@api/device-action/os/Errors\";\nimport { type WaitForAppAndVersionDAError } from \"@api/device-action/os/WaitForAppAndVersion/types\";\n\nexport const getDeviceStatusDAStateStep = Object.freeze({\n WAIT_FOR_APP_AND_VERSION: \"os.getDeviceStatus.steps.waitForAppAndVersion\",\n ONBOARD_CHECK: \"os.getDeviceStatus.steps.onboardCheck\",\n} as const);\n\nexport type GetDeviceStatusDAStateStep =\n (typeof getDeviceStatusDAStateStep)[keyof typeof getDeviceStatusDAStateStep];\n\nexport type GetDeviceStatusDAOutput = {\n readonly currentApp: string;\n readonly currentAppVersion: string;\n};\nexport type GetDeviceStatusDAInput = {\n readonly unlockTimeout?: number;\n readonly allowNonOnboardedDevice?: boolean;\n};\n\nexport type GetDeviceStatusDAError =\n | WaitForAppAndVersionDAError\n | DeviceNotOnboardedError;\n\nexport type GetDeviceStatusDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice;\n\nexport type GetDeviceStatusDAIntermediateValue = {\n requiredUserInteraction: GetDeviceStatusDARequiredInteraction;\n step: GetDeviceStatusDAStateStep;\n};\n\nexport type GetDeviceStatusDAState = DeviceActionState<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue\n>;\n"],
|
|
5
|
+
"mappings": "AAKO,MAAMA,EAA6B,OAAO,OAAO,CACtD,yBAA0B,gDAC1B,cAAe,uCACjB,CAAU",
|
|
6
6
|
"names": ["getDeviceStatusDAStateStep"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=Object.freeze({DEVICE_READY:"os.installLanguagePackage.steps.deviceReady",GET_DEVICE_METADATA:"os.installLanguagePackage.steps.getDeviceMetadata",DELETE_CURRENT_LANGUAGE_PACK:"os.installLanguagePackage.steps.deleteCurrentLanguagePack",INSTALL_LANGUAGE_PACK:"os.installLanguagePackage.steps.installLanguagePack"});export{e as installLanguagePackageDAStateStep};
|
|
1
|
+
const e={0:"english",1:"french",2:"spanish",3:"brazilian",4:"german",5:"russian",6:"turkish",7:"thai"},a=Object.freeze({DEVICE_READY:"os.installLanguagePackage.steps.deviceReady",GET_DEVICE_METADATA:"os.installLanguagePackage.steps.getDeviceMetadata",DELETE_CURRENT_LANGUAGE_PACK:"os.installLanguagePackage.steps.deleteCurrentLanguagePack",INSTALL_LANGUAGE_PACK:"os.installLanguagePackage.steps.installLanguagePack"});export{e as LANGUAGE_ID_TO_LANGUAGE,a as installLanguagePackageDAStateStep};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/InstallLanguagePackage/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n type DeleteLanguagePackDAError,\n type MissingLanguagePackageDAError,\n type MissingLanguagePackagesForOSDAError,\n type OutOfMemoryDAError,\n type RefusedByUserDAError,\n type UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport {\n type GetDeviceMetadataDAError,\n type GetDeviceMetadataDAIntermediateValue,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { type GoToDashboardDAInput } from \"@api/device-action/os/GoToDashboard/types\";\n\nexport type Language =\n | \"french\"\n | \"english\"\n | \"spanish\"\n | \"brazilian\"\n | \"german\"\n | \"russian\"\n | \"turkish\"\n | \"thai\";\n\nexport const installLanguagePackageDAStateStep = Object.freeze({\n DEVICE_READY: \"os.installLanguagePackage.steps.deviceReady\",\n GET_DEVICE_METADATA: \"os.installLanguagePackage.steps.getDeviceMetadata\",\n DELETE_CURRENT_LANGUAGE_PACK:\n \"os.installLanguagePackage.steps.deleteCurrentLanguagePack\",\n INSTALL_LANGUAGE_PACK: \"os.installLanguagePackage.steps.installLanguagePack\",\n} as const);\n\nexport type InstallLanguagePackageDAInput = GoToDashboardDAInput & {\n readonly language: Language;\n};\n\nexport type InstallLanguagePackageDAOutput = undefined;\n\nexport type InstallLanguagePackageDAGetDeviceMetadataIntermediateValue = Omit<\n GetDeviceMetadataDAIntermediateValue,\n \"step\"\n> & {\n readonly step: typeof installLanguagePackageDAStateStep.GET_DEVICE_METADATA;\n};\n\nexport type InstallLanguagePackageDAIntermediateValue =\n | GetDeviceMetadataDAIntermediateValue\n | InstallLanguagePackageDAGetDeviceMetadataIntermediateValue\n | {\n readonly requiredUserInteraction: UserInteractionRequired.None;\n readonly step: Exclude<\n (typeof installLanguagePackageDAStateStep)[keyof typeof installLanguagePackageDAStateStep],\n typeof installLanguagePackageDAStateStep.GET_DEVICE_METADATA\n >;\n readonly progress?: number;\n };\n\nexport type InstallLanguagePackageDAError =\n | GetDeviceMetadataDAError\n | MissingLanguagePackagesForOSDAError\n | MissingLanguagePackageDAError\n | DeleteLanguagePackDAError\n | RefusedByUserDAError // from InstallLanguagePackageTask\n | OutOfMemoryDAError // from InstallLanguagePackageTask\n | UnknownDAError; // from InstallLanguagePackageTask (network error, invalid APDU, etc.)\n\nexport type InstallLanguagePackageDAState = DeviceActionState<\n InstallLanguagePackageDAOutput,\n InstallLanguagePackageDAError,\n InstallLanguagePackageDAIntermediateValue\n>;\n"],
|
|
5
|
-
"mappings": "AA0BO,MAAMA,EAAoC,OAAO,OAAO,CAC7D,aAAc,8CACd,oBAAqB,oDACrB,6BACE,4DACF,sBAAuB,qDACzB,CAAU",
|
|
6
|
-
"names": ["installLanguagePackageDAStateStep"]
|
|
4
|
+
"sourcesContent": ["import { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport {\n type DeleteLanguagePackDAError,\n type MissingLanguagePackageDAError,\n type MissingLanguagePackagesForOSDAError,\n type OutOfMemoryDAError,\n type RefusedByUserDAError,\n type UnknownDAError,\n} from \"@api/device-action/os/Errors\";\nimport {\n type GetDeviceMetadataDAError,\n type GetDeviceMetadataDAIntermediateValue,\n} from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { type GoToDashboardDAInput } from \"@api/device-action/os/GoToDashboard/types\";\n\nexport type Language =\n | \"french\"\n | \"english\"\n | \"spanish\"\n | \"brazilian\"\n | \"german\"\n | \"russian\"\n | \"turkish\"\n | \"thai\";\n\nexport const LANGUAGE_ID_TO_LANGUAGE: Record<number, Language> = {\n 0: \"english\",\n 1: \"french\",\n 2: \"spanish\",\n 3: \"brazilian\",\n 4: \"german\",\n 5: \"russian\",\n 6: \"turkish\",\n 7: \"thai\",\n};\n\nexport const installLanguagePackageDAStateStep = Object.freeze({\n DEVICE_READY: \"os.installLanguagePackage.steps.deviceReady\",\n GET_DEVICE_METADATA: \"os.installLanguagePackage.steps.getDeviceMetadata\",\n DELETE_CURRENT_LANGUAGE_PACK:\n \"os.installLanguagePackage.steps.deleteCurrentLanguagePack\",\n INSTALL_LANGUAGE_PACK: \"os.installLanguagePackage.steps.installLanguagePack\",\n} as const);\n\nexport type InstallLanguagePackageDAInput = GoToDashboardDAInput & {\n readonly language: Language;\n};\n\nexport type InstallLanguagePackageDAOutput = undefined;\n\nexport type InstallLanguagePackageDAGetDeviceMetadataIntermediateValue = Omit<\n GetDeviceMetadataDAIntermediateValue,\n \"step\"\n> & {\n readonly step: typeof installLanguagePackageDAStateStep.GET_DEVICE_METADATA;\n};\n\nexport type InstallLanguagePackageDAIntermediateValue =\n | GetDeviceMetadataDAIntermediateValue\n | InstallLanguagePackageDAGetDeviceMetadataIntermediateValue\n | {\n readonly requiredUserInteraction: UserInteractionRequired.None;\n readonly step: Exclude<\n (typeof installLanguagePackageDAStateStep)[keyof typeof installLanguagePackageDAStateStep],\n typeof installLanguagePackageDAStateStep.GET_DEVICE_METADATA\n >;\n readonly progress?: number;\n };\n\nexport type InstallLanguagePackageDAError =\n | GetDeviceMetadataDAError\n | MissingLanguagePackagesForOSDAError\n | MissingLanguagePackageDAError\n | DeleteLanguagePackDAError\n | RefusedByUserDAError // from InstallLanguagePackageTask\n | OutOfMemoryDAError // from InstallLanguagePackageTask\n | UnknownDAError; // from InstallLanguagePackageTask (network error, invalid APDU, etc.)\n\nexport type InstallLanguagePackageDAState = DeviceActionState<\n InstallLanguagePackageDAOutput,\n InstallLanguagePackageDAError,\n InstallLanguagePackageDAIntermediateValue\n>;\n"],
|
|
5
|
+
"mappings": "AA0BO,MAAMA,EAAoD,CAC/D,EAAG,UACH,EAAG,SACH,EAAG,UACH,EAAG,YACH,EAAG,SACH,EAAG,UACH,EAAG,UACH,EAAG,MACL,EAEaC,EAAoC,OAAO,OAAO,CAC7D,aAAc,8CACd,oBAAqB,oDACrB,6BACE,4DACF,sBAAuB,qDACzB,CAAU",
|
|
6
|
+
"names": ["LANGUAGE_ID_TO_LANGUAGE", "installLanguagePackageDAStateStep"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{isSuccessCommandResult as
|
|
1
|
+
import{isSuccessCommandResult as c}from"../../command/model/CommandResult";import{GetBackgroundImageSizeCommand as f}from"../../command/os/GetBackgroundImageSizeCommand";import{GetOsVersionCommand as F}from"../../command/os/GetOsVersionCommand";import{InvalidGetFirmwareMetadataResponseError as l}from"../../device-action/task/Errors";import{DmkResultFactory as m}from"../../model/DmkResult";class M{constructor(e){this.api=e}async run(){const e=await this.api.sendCommand(new F);if(!c(e))return m({error:e.error});const t={mcu:e.data.mcuSephVersion,bootloader:e.data.mcuBootloaderVersion,os:e.data.seVersion,metadata:e.data},i=this.api.getManagerApiService(),n=await i.getDeviceVersion(e.data).chain(u=>i.getFirmwareVersion(e.data,u).map(w=>({deviceVersion:u,currentFirmware:w})));if(n.isLeft())return m({error:new l});const{deviceVersion:a,currentFirmware:r}=n.unsafeCoerce(),o=await this.getAvailableUpdate(i,r,a,t),s={currentFirmware:r,availableUpdate:o};let d={};const p=await this.api.sendCommand(new f);return c(p)&&(d={size:p.data}),m({data:{deviceVersion:a,firmware:r,firmwareVersion:t,firmwareUpdateContext:s,customImage:d}})}async getAvailableUpdate(e,t,i,n){const a=await e.getLatestFirmwareVersion(t,i);if(a.isLeft())return;const r=a.unsafeCoerce();if(!r.isNothing())return this.getFirmwareUpdate(e,r.unsafeCoerce(),n)}async getFirmwareUpdate(e,t,i){const n=await e.getNextFirmwareVersion(t);if(n.isLeft())return;const a=await e.getMcuList();if(a.isLeft())return;const r=n.unsafeCoerce(),o=a.unsafeCoerce().find(s=>s.name===i.mcu);return{osuFirmware:t,finalFirmware:r,mcuUpdateRequired:o===void 0||!r.mcuVersions.includes(o.id)}}}export{M as GetFirmwareMetadataTask};
|
|
2
2
|
//# sourceMappingURL=GetFirmwareMetadataTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/GetFirmwareMetadataTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type CommandErrorResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { GetBackgroundImageSizeCommand } from \"@api/command/os/GetBackgroundImageSizeCommand\";\nimport { GetOsVersionCommand } from \"@api/command/os/GetOsVersionCommand\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport {\n type CustomImage,\n type FirmwareUpdate,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DmkResult, DmkResultFactory } from \"@api/model/DmkResult\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport {
|
|
5
|
-
"mappings": "AAAA,OAEE,0BAAAA,MACK,mCACP,OAAS,iCAAAC,MAAqC,gDAC9C,OAAS,uBAAAC,MAA2B,sCAEpC,OAAS,2CAAAC,MAA+C,iCAOxD,OAAyB,oBAAAC,MAAwB,
|
|
6
|
-
"names": ["isSuccessCommandResult", "GetBackgroundImageSizeCommand", "GetOsVersionCommand", "InvalidGetFirmwareMetadataResponseError", "DmkResultFactory", "GetFirmwareMetadataTask", "api", "osVersion", "firmwareVersion", "manager", "result", "deviceVersion", "currentFirmware", "availableUpdate", "
|
|
4
|
+
"sourcesContent": ["import {\n type CommandErrorResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { GetBackgroundImageSizeCommand } from \"@api/command/os/GetBackgroundImageSizeCommand\";\nimport { GetOsVersionCommand } from \"@api/command/os/GetOsVersionCommand\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport {\n type CustomImage,\n type FirmwareUpdate,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DmkResult, DmkResultFactory } from \"@api/model/DmkResult\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport {\n type FinalFirmware,\n type OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nexport type GetFirmwareMetadataTaskResponse = {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n firmwareUpdateContext: FirmwareUpdateContext;\n customImage: CustomImage;\n};\n\nexport type GetFirmwareMetadataTaskError =\n | CommandErrorResult[\"error\"]\n | InvalidGetFirmwareMetadataResponseError;\n\nexport type GetFirmwareMetadataTaskResult = DmkResult<\n GetFirmwareMetadataTaskResponse,\n GetFirmwareMetadataTaskError\n>;\n\nexport class GetFirmwareMetadataTask {\n constructor(private readonly api: InternalApi) {}\n\n async run(): Promise<GetFirmwareMetadataTaskResult> {\n // Get installed firmware metadata\n const osVersion = await this.api.sendCommand(new GetOsVersionCommand());\n if (!isSuccessCommandResult(osVersion)) {\n return DmkResultFactory({\n error: osVersion.error,\n });\n }\n const firmwareVersion: FirmwareVersion = {\n mcu: osVersion.data.mcuSephVersion,\n bootloader: osVersion.data.mcuBootloaderVersion,\n os: osVersion.data.seVersion,\n metadata: osVersion.data,\n };\n\n // Fetch current firmware metadata from app store\n const manager = this.api.getManagerApiService();\n const result = await manager\n .getDeviceVersion(osVersion.data)\n .chain((deviceVersion) =>\n manager\n .getFirmwareVersion(osVersion.data, deviceVersion)\n .map((currentFirmware) => ({ deviceVersion, currentFirmware })),\n );\n if (result.isLeft()) {\n return DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n });\n }\n const { deviceVersion, currentFirmware } = result.unsafeCoerce();\n\n const availableUpdate = await this.getAvailableUpdate(\n manager,\n currentFirmware,\n deviceVersion,\n firmwareVersion,\n );\n\n const firmwareUpdateContext = {\n currentFirmware,\n availableUpdate,\n };\n\n // Get custom image metadata\n let customImage: CustomImage = {};\n const imageSize = await this.api.sendCommand(\n new GetBackgroundImageSizeCommand(),\n );\n if (isSuccessCommandResult(imageSize)) {\n customImage = { size: imageSize.data };\n }\n\n // Return firmware metadata\n return DmkResultFactory({\n data: {\n deviceVersion,\n firmware: currentFirmware,\n firmwareVersion,\n firmwareUpdateContext,\n customImage,\n },\n });\n }\n\n private async getAvailableUpdate(\n manager: ManagerApiService,\n currentFirmware: FinalFirmware,\n deviceVersion: DeviceVersion,\n firmwareVersion: FirmwareVersion,\n ): Promise<FirmwareUpdate | undefined> {\n // Fetch latest firmware available, if any\n const maybeOsuFirmwareResult = await manager.getLatestFirmwareVersion(\n currentFirmware,\n deviceVersion,\n );\n if (maybeOsuFirmwareResult.isLeft()) {\n return undefined;\n }\n\n const maybeOsuFirmware = maybeOsuFirmwareResult.unsafeCoerce();\n if (maybeOsuFirmware.isNothing()) {\n return undefined;\n }\n\n return this.getFirmwareUpdate(\n manager,\n maybeOsuFirmware.unsafeCoerce(),\n firmwareVersion,\n );\n }\n\n private async getFirmwareUpdate(\n manager: ManagerApiService,\n osuFirmware: OsuFirmware,\n firmwareVersion: FirmwareVersion,\n ): Promise<FirmwareUpdate | undefined> {\n const finalFirmwareResult =\n await manager.getNextFirmwareVersion(osuFirmware);\n if (finalFirmwareResult.isLeft()) {\n return undefined;\n }\n\n const mcusResult = await manager.getMcuList();\n if (mcusResult.isLeft()) {\n return undefined;\n }\n\n const finalFirmware = finalFirmwareResult.unsafeCoerce();\n const mcu = mcusResult\n .unsafeCoerce()\n .find((candidate) => candidate.name === firmwareVersion.mcu);\n\n return {\n osuFirmware,\n finalFirmware,\n mcuUpdateRequired:\n mcu === undefined || !finalFirmware.mcuVersions.includes(mcu.id),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,0BAAAA,MACK,mCACP,OAAS,iCAAAC,MAAqC,gDAC9C,OAAS,uBAAAC,MAA2B,sCAEpC,OAAS,2CAAAC,MAA+C,iCAOxD,OAAyB,oBAAAC,MAAwB,uBAyB1C,MAAMC,CAAwB,CACnC,YAA6BC,EAAkB,CAAlB,SAAAA,CAAmB,CAEhD,MAAM,KAA8C,CAElD,MAAMC,EAA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Ac,kBACZC,EACAU,EACAX,EACqC,CACrC,MAAMY,EACJ,MAAMX,EAAQ,uBAAuBU,CAAW,EAClD,GAAIC,EAAoB,OAAO,EAC7B,OAGF,MAAMC,EAAa,MAAMZ,EAAQ,WAAW,EAC5C,GAAIY,EAAW,OAAO,EACpB,OAGF,MAAMC,EAAgBF,EAAoB,aAAa,EACjDG,EAAMF,EACT,aAAa,EACb,KAAMG,GAAcA,EAAU,OAAShB,EAAgB,GAAG,EAE7D,MAAO,CACL,YAAAW,EACA,cAAAG,EACA,kBACEC,IAAQ,QAAa,CAACD,EAAc,YAAY,SAASC,EAAI,EAAE,CACnE,CACF,CACF",
|
|
6
|
+
"names": ["isSuccessCommandResult", "GetBackgroundImageSizeCommand", "GetOsVersionCommand", "InvalidGetFirmwareMetadataResponseError", "DmkResultFactory", "GetFirmwareMetadataTask", "api", "osVersion", "firmwareVersion", "manager", "result", "deviceVersion", "currentFirmware", "availableUpdate", "firmwareUpdateContext", "customImage", "imageSize", "maybeOsuFirmwareResult", "maybeOsuFirmware", "osuFirmware", "finalFirmwareResult", "mcusResult", "finalFirmware", "mcu", "candidate"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EitherAsync as
|
|
1
|
+
import{EitherAsync as i,Just as f,Nothing as R}from"purify-ts";import{InvalidStatusWordError as d}from"../../command/Errors";import{CommandResultFactory as o}from"../../command/model/CommandResult";import{makeDeviceActionInternalApiMock as F}from"../../device-action/__test-utils__/makeInternalApi";import{InvalidGetFirmwareMetadataResponseError as V}from"../../device-action/task/Errors";import{DmkResultFactory as m}from"../../model/DmkResult";import{GetFirmwareMetadataTask as u}from"./GetFirmwareMetadataTask";describe("GetFirmwareMetadataTask",()=>{const e=F(),a={mcuSephVersion:"mcu_version",mcuBootloaderVersion:"bl_version",seVersion:"se_version"},w=97,c={id:7},n={id:361,version:"1.6.0",perso:"perso_11"},l={id:362,perso:"perso_11",notes:"notes"},v={id:363,version:"1.7.0",perso:"perso_11",mcuVersions:[1]},p=[{id:3,name:"other_version",fromBootloaderVersion:"1.0"},{id:1,name:"mcu_version",fromBootloaderVersion:"1.0"}],t={getDeviceVersion:vi.fn(),getFirmwareVersion:vi.fn(),getLatestFirmwareVersion:vi.fn(),getNextFirmwareVersion:vi.fn(),getMcuList:vi.fn()};beforeEach(()=>{vi.resetAllMocks(),e.getManagerApiService.mockReturnValue(t),t.getDeviceVersion.mockReturnValue(i(async()=>c)),t.getFirmwareVersion.mockReturnValue(i(async()=>n)),t.getLatestFirmwareVersion.mockReturnValue(i(async()=>f(l))),t.getNextFirmwareVersion.mockReturnValue(i(async()=>v)),t.getMcuList.mockReturnValue(i(async()=>p))}),it("success with no firmware update available",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({data:w})),t.getLatestFirmwareVersion.mockReturnValueOnce(i(async()=>R));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:void 0},customImage:{size:w}}}))}),it("success with no firmware update when latest firmware cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({data:w})),t.getLatestFirmwareVersion.mockReturnValueOnce(i(async({throwE:s})=>{s(new Error("error"))}));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:void 0},customImage:{size:w}}}))}),it("success with a firmware update available",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({error:new d("error")}));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:{osuFirmware:l,finalFirmware:v,mcuUpdateRequired:!1}},customImage:{}}})),expect(t.getDeviceVersion).toHaveBeenCalledWith(a),expect(t.getFirmwareVersion).toHaveBeenCalledWith(a,c),expect(t.getLatestFirmwareVersion).toHaveBeenCalledWith(n,c),expect(t.getNextFirmwareVersion).toHaveBeenCalledWith(l)}),it("success with a firmware update available and MCU update",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({error:new d("error")}));const r={...v,mcuVersions:[3]};t.getNextFirmwareVersion.mockReturnValue(i(async()=>r));const s=await new u(e).run();expect(s).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:{osuFirmware:l,finalFirmware:r,mcuUpdateRequired:!0}},customImage:{}}}))}),it("success with a firmware update available when current MCU is unknown",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({error:new d("error")})),t.getMcuList.mockReturnValueOnce(i(async()=>[{id:3,name:"other_version",fromBootloaderVersion:"1.0"}]));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:{osuFirmware:l,finalFirmware:v,mcuUpdateRequired:!0}},customImage:{}}}))}),it("success with no firmware update when next firmware cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({error:new d("error")})),t.getNextFirmwareVersion.mockReturnValueOnce(i(async({throwE:s})=>{s(new Error("error"))}));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:void 0},customImage:{}}}))}),it("success with no firmware update when MCU list cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})).mockResolvedValueOnce(o({error:new d("error")})),t.getMcuList.mockReturnValueOnce(i(async({throwE:s})=>{s(new Error("error"))}));const r=await new u(e).run();expect(r).toStrictEqual(m({data:{deviceVersion:c,firmware:n,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:n,availableUpdate:void 0},customImage:{}}}))}),it("should fail when OS version cannot be retrieved",async()=>{e.sendCommand.mockResolvedValueOnce(o({error:new d("error")}));const r=await new u(e).run();expect(r).toStrictEqual(m({error:new d("error")}))}),it("should fail if device version cannot be fetched with InvalidGetFirmwareMetadataResponseError",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})),t.getDeviceVersion.mockReturnValueOnce(i(async({throwE:s})=>{s(new Error("error"))}));const r=await new u(e).run();expect(r).toStrictEqual(m({error:new V}))}),it("should fail if firmware version cannot be fetched with InvalidGetFirmwareMetadataResponseError",async()=>{e.sendCommand.mockResolvedValueOnce(o({data:a})),t.getFirmwareVersion.mockReturnValueOnce(i(async({throwE:s})=>{s(new Error("error"))}));const r=await new u(e).run();expect(r).toStrictEqual(m({error:new V}))})});
|
|
2
2
|
//# sourceMappingURL=GetFirmwareMetadataTask.test.js.map
|