@ledgerhq/device-management-kit 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +45 -40
- package/lib/cjs/src/api/device-action/os/Errors.js +1 -1
- package/lib/cjs/src/api/device-action/os/Errors.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +1 -1
- package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
- package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +2 -2
- package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
- package/lib/cjs/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/InstallApp/types.js.map +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/UninstallApp/types.js.map +1 -1
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
- package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/types.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/utils.js +1 -1
- package/lib/cjs/src/api/secure-channel/utils.js.map +3 -3
- package/lib/cjs/src/api/secure-channel/utils.test.js +1 -1
- package/lib/cjs/src/api/secure-channel/utils.test.js.map +3 -3
- package/lib/cjs/src/internal/crypto/CryptoService.js +2 -0
- package/lib/cjs/src/internal/crypto/CryptoService.js.map +7 -0
- package/lib/cjs/src/internal/crypto/NobleCryptoService.js +2 -0
- package/lib/cjs/src/internal/crypto/NobleCryptoService.js.map +7 -0
- package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js +2 -0
- package/lib/cjs/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/esm/package.json +45 -40
- package/lib/esm/src/api/device-action/os/Errors.js +1 -1
- package/lib/esm/src/api/device-action/os/Errors.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +2 -2
- package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js +1 -1
- package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.js.map +3 -3
- package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js +1 -1
- package/lib/esm/src/api/device-action/task/BuildAppsInstallPlanTask.test.js.map +3 -3
- package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js +1 -1
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.test.js.map +3 -3
- package/lib/esm/src/api/secure-channel/task/types.js +1 -1
- package/lib/esm/src/api/secure-channel/task/types.js.map +2 -2
- package/lib/esm/src/api/secure-channel/utils.js +1 -1
- package/lib/esm/src/api/secure-channel/utils.js.map +3 -3
- package/lib/esm/src/api/secure-channel/utils.test.js +1 -1
- package/lib/esm/src/api/secure-channel/utils.test.js.map +3 -3
- package/lib/esm/src/internal/crypto/CryptoService.js +1 -0
- package/lib/esm/src/internal/crypto/CryptoService.js.map +7 -0
- package/lib/esm/src/internal/crypto/NobleCryptoService.js +2 -0
- package/lib/esm/src/internal/crypto/NobleCryptoService.js.map +7 -0
- package/lib/esm/src/internal/crypto/NobleCryptoService.test.js +2 -0
- package/lib/esm/src/internal/crypto/NobleCryptoService.test.js.map +7 -0
- package/lib/types/src/api/device-action/os/Errors.d.ts +5 -0
- package/lib/types/src/api/device-action/os/Errors.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +1 -0
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +3 -2
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +1 -0
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts +2 -2
- package/lib/types/src/api/device-action/task/BuildAppsInstallPlanTask.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +1 -0
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts +1 -0
- package/lib/types/src/api/secure-channel/device-action/InstallApp/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +1 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/UninstallApp/UninstallAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts +1 -0
- package/lib/types/src/api/secure-channel/device-action/UninstallApp/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts +4 -0
- package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/task/types.d.ts +7 -0
- package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/utils.d.ts +18 -1
- package/lib/types/src/api/secure-channel/utils.d.ts.map +1 -1
- package/lib/types/src/internal/crypto/CryptoService.d.ts +12 -0
- package/lib/types/src/internal/crypto/CryptoService.d.ts.map +1 -0
- package/lib/types/src/internal/crypto/NobleCryptoService.d.ts +8 -0
- package/lib/types/src/internal/crypto/NobleCryptoService.d.ts.map +1 -0
- package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts +2 -0
- package/lib/types/src/internal/crypto/NobleCryptoService.test.d.ts.map +1 -0
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +34 -29
package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { OutOfMemoryDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport {\n BuildAppsInstallPlanTask,\n type BuildAppsInstallPlanTaskResult,\n} from \"@api/device-action/task/BuildAppsInstallPlanTask\";\nimport {\n PredictOutOfMemoryTask,\n type PredictOutOfMemoryTaskResult,\n} from \"@api/device-action/task/PredictOutOfMemoryTask\";\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 { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { type GetOsVersionResponse } from \"@api/index\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type ApplicationDependency,\n type InstallOrUpdateAppsDAError,\n type InstallOrUpdateAppsDAInput,\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"./types\";\n\ntype InstallOrUpdateAppsMachineInternalState = {\n readonly error: InstallOrUpdateAppsDAError | null;\n readonly osVersion: GetOsVersionResponse | null;\n readonly currentIndex: number;\n};\n\nexport type MachineDependencies = {\n readonly buildInstallPlan: (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) => Promise<BuildAppsInstallPlanTaskResult>;\n readonly predictOutOfMemory: (arg0: {\n input: {\n installPlan: Application[];\n };\n }) => Promise<PredictOutOfMemoryTaskResult>;\n readonly installApp: (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class InstallOrUpdateAppsDeviceAction extends XStateDeviceAction<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n > {\n type types = StateMachineTypes<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n >;\n\n const { buildInstallPlan, predictOutOfMemory, installApp } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n updateMetadata: updateMetadataMachine,\n buildInstallPlan: fromPromise(buildInstallPlan),\n predictOutOfMemory: fromPromise(predictOutOfMemory),\n goToDashboard: goToDashboardMachine,\n installApp: fromObservable(installApp),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasInstallPlan: (_) => _.context.intermediateValue.installPlan !== null,\n hasMoreApps: (_) =>\n _.context._internalState.currentIndex <\n _.context.intermediateValue.installPlan!.installPlan.length,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n nextAppIndex: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentIndex: _.context._internalState.currentIndex + 1,\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful installation, cleanup the device session state\n // to force fetching the new device state when required\n const state = internalApi.getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n internalApi.setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n id: \"InstallOrUpdateAppsDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n applications: _.input.applications,\n allowMissingApplication: _.input.allowMissingApplication,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n osVersion: null,\n currentIndex: 0,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n UpdateDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"updateMetadata\",\n src: \"updateMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"UpdateDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n osVersion: data.firmwareVersion.metadata!,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n UpdateDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasInstallPlan\",\n },\n {\n target: \"BuildInstallPlan\",\n },\n ],\n },\n BuildInstallPlan: {\n invoke: {\n src: \"buildInstallPlan\",\n input: (_) => ({\n applications: _.context.input.applications,\n allowMissingApplication: _.context.input.allowMissingApplication,\n }),\n onDone: {\n target: \"BuildInstallPlanCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else {\n return _.context._internalState;\n }\n },\n intermediateValue: (_) => {\n if (\"error\" in _.event.output) {\n return _.context.intermediateValue;\n } else {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n installPlan: _.event.output.installPlan,\n alreadyInstalled: _.event.output.alreadyInstalled,\n missingApplications: _.event.output.missingApplications,\n currentIndex: 0,\n currentProgress: 0,\n },\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n BuildInstallPlanCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"PredictOutOfMemory\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n PredictOutOfMemory: {\n invoke: {\n src: \"predictOutOfMemory\",\n input: (_) => ({\n installPlan: _.context.intermediateValue.installPlan!.installPlan,\n }),\n onDone: {\n target: \"PredictOutOfMemoryCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else if (_.event.output.outOfMemory) {\n return {\n ..._.context._internalState,\n error: new OutOfMemoryDAError(\n \"Not enough memory for those applications\",\n ),\n };\n } else {\n return _.context._internalState;\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n PredictOutOfMemoryCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\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: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n actions: \"cleanupDeviceState\",\n },\n ],\n },\n InstallApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"installApp\",\n src: \"installApp\",\n input: (_) => ({\n osVersion: _.context._internalState.osVersion!,\n application:\n _.context.intermediateValue.installPlan!.installPlan[\n _.context._internalState.currentIndex\n ]!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.PermissionRequested: {\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n isSecureConnectionAllowed: true,\n });\n }\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n case SecureChannelEventType.Progress: {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n ..._.context.intermediateValue.installPlan!,\n currentIndex: _.context._internalState.currentIndex,\n currentProgress:\n _.event.snapshot.context.payload.progress,\n },\n };\n }\n default:\n return _.context.intermediateValue;\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error:\n _.event.snapshot.context.error.mapInstallDAErrors(),\n };\n }\n return _.context._internalState;\n },\n }),\n },\n onDone: {\n target: \"InstallAppCheck\",\n actions: \"nextAppIndex\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error } = context._internalState;\n const { installPlan } = context.intermediateValue;\n if (error) {\n return Left(error);\n }\n return Right({\n successfullyInstalled: installPlan!.installPlan,\n alreadyInstalled: installPlan!.alreadyInstalled,\n missingApplications: installPlan!.missingApplications,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const buildInstallPlan = async (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) =>\n new BuildAppsInstallPlanTask(internalApi, {\n applications: arg0.input.applications,\n allowMissingApplication: arg0.input.allowMissingApplication,\n }).run();\n\n const predictOutOfMemory = async (arg0: {\n input: {\n installPlan: Application[];\n };\n }) =>\n new PredictOutOfMemoryTask(internalApi, {\n installPlan: arg0.input.installPlan,\n }).run();\n\n const installApp = (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => {\n const { osVersion, application } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .installApp(osVersion, application);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n buildInstallPlan,\n predictOutOfMemory,\n installApp,\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC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CAC3B,eAAiBwB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,MAAOA,EAAE,MAAM,KACjB,EACF,CAAC,EACD,aAAcxB,EAAO,CACnB,eAAiBwB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,aAAcA,EAAE,QAAQ,eAAe,aAAe,CACxD,EACF,CAAC,EACD,mBAAoB,IAAM,CAGxB,MAAMC,EAAQT,EAAY,sBAAsB,EAC5CS,EAAM,mBAAqBb,EAAuB,WACpDI,EAAY,sBAAsB,CAChC,GAAGS,EACH,cAAe,CAAC,EAChB,YAAa,MACf,CAAC,CAEL,CACF,CACF,CAAC,EAAE,cAAc,CACf,GAAI,kCACJ,QAAS,cACT,QAAUD,IACD,CACL,MAAO,CACL,aAAcA,EAAE,MAAM,aACtB,wBAAyBA,EAAE,MAAM,wBACjC,cAAeA,EAAE,MAAM,aACzB,EACA,kBAAmB,CACjB,wBAAyBpB,EAAwB,KACjD,YAAa,IACf,EACA,eAAgB,CACd,MAAO,KACP,UAAW,KACX,aAAc,CAChB,CACF,GAEF,OAAQ,CACN,YAAa,CACX,OAAQ,CACN,CACE,OAAQ,sBACV,CACF,CACF,EACA,qBAAsB,CACpB,KAAMJ,EAAO,CACX,kBAAoBwB,IAAO,CACzB,GAAGA,EAAE,QAAQ,kBACb,wBAAyBpB,EAAwB,IACnD,EACF,CAAC,EACD,OAAQ,CACN,GAAI,iBACJ,IAAK,iBACL,MAAQoB,IAAO,CACb,cAAeA,EAAE,QAAQ,MAAM,cAC/B,iBAAkB,GAClB,YAAa,EACf,GACA,WAAY,CACV,QAASxB,EAAO,CACd,kBAAoBwB,IAAO,CACzB,GAAGA,EAAE,QAAQ,kBACb,wBACEA,EAAE,MAAM,SAAS,QAAQ,kBACtB,
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { OutOfMemoryDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport {\n BuildAppsInstallPlanTask,\n type BuildAppsInstallPlanTaskResult,\n} from \"@api/device-action/task/BuildAppsInstallPlanTask\";\nimport {\n PredictOutOfMemoryTask,\n type PredictOutOfMemoryTaskResult,\n} from \"@api/device-action/task/PredictOutOfMemoryTask\";\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 { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { type GetOsVersionResponse } from \"@api/index\";\nimport { ConnectToSecureChannelTask } from \"@api/secure-channel/task/ConnectToSecureChannelTask\";\nimport { SecureChannelEventType } from \"@api/secure-channel/task/types\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n type ApplicationDependency,\n type InstallOrUpdateAppsDAError,\n type InstallOrUpdateAppsDAInput,\n type InstallOrUpdateAppsDAIntermediateValue,\n type InstallOrUpdateAppsDAOutput,\n} from \"./types\";\n\ntype InstallOrUpdateAppsMachineInternalState = {\n readonly error: InstallOrUpdateAppsDAError | null;\n readonly osVersion: GetOsVersionResponse | null;\n readonly currentIndex: number;\n};\n\nexport type MachineDependencies = {\n readonly buildInstallPlan: (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) => Promise<BuildAppsInstallPlanTaskResult>;\n readonly predictOutOfMemory: (arg0: {\n input: {\n installPlan: Application[];\n };\n }) => Promise<PredictOutOfMemoryTaskResult>;\n readonly installApp: (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class InstallOrUpdateAppsDeviceAction extends XStateDeviceAction<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n > {\n type types = StateMachineTypes<\n InstallOrUpdateAppsDAOutput,\n InstallOrUpdateAppsDAInput,\n InstallOrUpdateAppsDAError,\n InstallOrUpdateAppsDAIntermediateValue,\n InstallOrUpdateAppsMachineInternalState\n >;\n\n const { buildInstallPlan, predictOutOfMemory, installApp } =\n this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const updateMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n updateMetadata: updateMetadataMachine,\n buildInstallPlan: fromPromise(buildInstallPlan),\n predictOutOfMemory: fromPromise(predictOutOfMemory),\n goToDashboard: goToDashboardMachine,\n installApp: fromObservable(installApp),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasInstallPlan: (_) => _.context.intermediateValue.installPlan !== null,\n hasMoreApps: (_) =>\n _.context._internalState.currentIndex <\n _.context.intermediateValue.installPlan!.installPlan.length,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n nextAppIndex: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n currentIndex: _.context._internalState.currentIndex + 1,\n }),\n }),\n cleanupDeviceState: () => {\n // After app successful installation, cleanup the device session state\n // to force fetching the new device state when required\n const state = internalApi.getDeviceSessionState();\n if (state.sessionStateType !== DeviceSessionStateType.Connected) {\n internalApi.setDeviceSessionState({\n ...state,\n installedApps: [],\n appsUpdates: undefined,\n });\n }\n },\n },\n }).createMachine({\n id: \"InstallOrUpdateAppsDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n applications: _.input.applications,\n allowMissingApplication: _.input.allowMissingApplication,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n osVersion: null,\n currentIndex: 0,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n UpdateDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"updateMetadata\",\n src: \"updateMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n deviceId:\n _.event.snapshot.context.intermediateValue.deviceId ??\n _.context.intermediateValue.deviceId,\n }),\n }),\n },\n onDone: {\n target: \"UpdateDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n osVersion: data.firmwareVersion.metadata!,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n UpdateDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"Success\",\n guard: \"hasInstallPlan\",\n },\n {\n target: \"BuildInstallPlan\",\n },\n ],\n },\n BuildInstallPlan: {\n invoke: {\n src: \"buildInstallPlan\",\n input: (_) => ({\n applications: _.context.input.applications,\n allowMissingApplication: _.context.input.allowMissingApplication,\n }),\n onDone: {\n target: \"BuildInstallPlanCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else {\n return _.context._internalState;\n }\n },\n intermediateValue: (_) => {\n if (\"error\" in _.event.output) {\n return _.context.intermediateValue;\n } else {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n installPlan: _.event.output.installPlan,\n alreadyInstalled: _.event.output.alreadyInstalled,\n missingApplications: _.event.output.missingApplications,\n currentIndex: 0,\n currentProgress: 0,\n },\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n BuildInstallPlanCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"PredictOutOfMemory\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n PredictOutOfMemory: {\n invoke: {\n src: \"predictOutOfMemory\",\n input: (_) => ({\n installPlan: _.context.intermediateValue.installPlan!.installPlan,\n }),\n onDone: {\n target: \"PredictOutOfMemoryCheck\",\n actions: assign({\n _internalState: (_) => {\n if (\"error\" in _.event.output) {\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n } else if (_.event.output.outOfMemory) {\n return {\n ..._.context._internalState,\n error: new OutOfMemoryDAError(\n \"Not enough memory for those applications\",\n ),\n };\n } else {\n return _.context._internalState;\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n PredictOutOfMemoryCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n invoke: {\n id: \"goToDashboard\",\n src: \"goToDashboard\",\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: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<InstallOrUpdateAppsMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GoToDashboardCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n actions: \"cleanupDeviceState\",\n },\n ],\n },\n InstallApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"installApp\",\n src: \"installApp\",\n input: (_) => ({\n osVersion: _.context._internalState.osVersion!,\n application:\n _.context.intermediateValue.installPlan!.installPlan[\n _.context._internalState.currentIndex\n ]!,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => {\n switch (_.event.snapshot.context?.type) {\n case SecureChannelEventType.DeviceId: {\n return {\n ..._.context.intermediateValue,\n deviceId: _.event.snapshot.context.payload.deviceId,\n };\n }\n case SecureChannelEventType.PermissionRequested: {\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction:\n UserInteractionRequired.AllowSecureConnection,\n };\n }\n case SecureChannelEventType.PermissionGranted: {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n isSecureConnectionAllowed: true,\n });\n }\n return {\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n };\n }\n case SecureChannelEventType.Progress: {\n return {\n ..._.context.intermediateValue,\n installPlan: {\n ..._.context.intermediateValue.installPlan!,\n currentIndex: _.context._internalState.currentIndex,\n currentProgress:\n _.event.snapshot.context.payload.progress,\n },\n };\n }\n default:\n return _.context.intermediateValue;\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error:\n _.event.snapshot.context.error.mapInstallDAErrors(),\n };\n }\n return _.context._internalState;\n },\n }),\n },\n onDone: {\n target: \"InstallAppCheck\",\n actions: \"nextAppIndex\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallAppCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallApp\",\n guard: \"hasMoreApps\",\n },\n {\n target: \"UpdateDeviceMetadata\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error } = context._internalState;\n const { installPlan } = context.intermediateValue;\n if (error) {\n return Left(error);\n }\n return Right({\n successfullyInstalled: installPlan!.installPlan,\n alreadyInstalled: installPlan!.alreadyInstalled,\n missingApplications: installPlan!.missingApplications,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const buildInstallPlan = (arg0: {\n input: {\n applications: ApplicationDependency[];\n allowMissingApplication: boolean;\n };\n }) =>\n Promise.resolve(\n new BuildAppsInstallPlanTask(internalApi, {\n applications: arg0.input.applications,\n allowMissingApplication: arg0.input.allowMissingApplication,\n }).run(),\n );\n\n const predictOutOfMemory = (arg0: {\n input: {\n installPlan: Application[];\n };\n }) =>\n Promise.resolve(\n new PredictOutOfMemoryTask(internalApi, {\n installPlan: arg0.input.installPlan,\n }).run(),\n );\n\n const installApp = (arg0: {\n input: {\n osVersion: GetOsVersionResponse;\n application: Application;\n };\n }) => {\n const { osVersion, application } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .installApp(osVersion, application);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n buildInstallPlan,\n predictOutOfMemory,\n installApp,\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAG3D,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,sBAAAC,MAA0B,+BACnC,OAAS,iCAAAC,MAAqC,wEAC9C,OAAS,6BAAAC,MAAiC,gEAC1C,OACE,4BAAAC,MAEK,mDACP,OACE,0BAAAC,MAEK,iDAEP,OAEE,sBAAAC,MACK,qDACP,OAAS,0BAAAC,MAA8B,yCAEvC,OAAS,8BAAAC,MAAkC,sDAC3C,OAAS,0BAAAC,MAA8B,iCA0ChC,MAAMC,UAAwCJ,CAMnD,CACA,iBACEK,EAOA,CASA,KAAM,CAAE,iBAAAC,EAAkB,mBAAAC,EAAoB,WAAAC,CAAW,EACvD,KAAK,oBAAoBH,CAAW,EAEhCI,EAAgB,KAAK,MAAM,eAAiBf,EAE5CgB,EAAwB,IAAId,EAA8B,CAC9D,MAAO,CACL,cAAAa,EACA,iBAAkB,GAClB,YAAa,EACf,CACF,CAAC,EAAE,iBAAiBJ,CAAW,E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,UAAAC,EAAW,YAAAC,CAAY,EAAIF,EAAK,MAClCG,EAAalB,EAChB,wBAAwB,EACxB,WAAWgB,EAAWC,CAAW,EACpC,OAAO,IAAIpB,EAA2BG,EAAa,CACjD,WAAAkB,CACF,CAAC,EAAE,IAAI,CACT,CAMA,CACF,CACF",
|
|
6
6
|
"names": ["Left", "Right", "assign", "fromObservable", "fromPromise", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "OutOfMemoryDAError", "GetDeviceMetadataDeviceAction", "GoToDashboardDeviceAction", "BuildAppsInstallPlanTask", "PredictOutOfMemoryTask", "XStateDeviceAction", "DeviceSessionStateType", "ConnectToSecureChannelTask", "SecureChannelEventType", "InstallOrUpdateAppsDeviceAction", "internalApi", "buildInstallPlan", "predictOutOfMemory", "installApp", "unlockTimeout", "updateMetadataMachine", "goToDashboardMachine", "context", "_", "state", "data", "error", "deviceState", "args", "installPlan", "arg0", "osVersion", "application", "connection"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as d,Right as m}from"purify-ts";import{assign as n,setup as
|
|
1
|
+
import{Left as d,Right as m}from"purify-ts";import{assign as n,setup as h}from"xstate";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as A}from"../../../device-action/os/Const";import{UnsupportedFirmwareDAError as D}from"../../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as v}from"../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{InstallOrUpdateAppsDeviceAction as O}from"../../../device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction";import{OpenAppDeviceAction as I}from"../../../device-action/os/OpenAppDeviceAction/OpenAppDeviceAction";import{XStateDeviceAction as M}from"../../../device-action/xstate-utils/XStateDeviceAction";class w extends M{makeStateMachine(r){const a=this.input.unlockTimeout??A,o=new v({input:{unlockTimeout:a,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(r),c=new O({input:{unlockTimeout:a,applications:[...this.input.dependencies,this.input.application],allowMissingApplication:!1}}).makeStateMachine(r),s=new I({input:{unlockTimeout:a,appName:this.input.application.name}}).makeStateMachine(r);return h({types:{input:{unlockTimeout:a},context:{},output:{}},actors:{getMetadata:o,installApps:c,openApp:s},guards:{hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorFromEvent:n({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"OpenAppWithDependenciesDeviceAction",initial:"DeviceReady",context:e=>({input:{application:e.input.application,dependencies:e.input.dependencies,requireLatestFirmware:e.input.requireLatestFirmware,unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:i.None,installPlan:null},_internalState:{error:null,deviceMetadata:null,installResult:null}}),states:{DeviceReady:{always:[{target:"GetDeviceMetadata"}]},GetDeviceMetadata:{exit:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"getMetadata",src:"getMetadata",input:e=>({unlockTimeout:e.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,deviceId:e.event.snapshot.context.intermediateValue.deviceId??e.context.intermediateValue.deviceId})})},onDone:{target:"GetDeviceMetadataCheck",actions:n({_internalState:e=>e.event.output.caseOf({Right:t=>e.context.input.requireLatestFirmware&&t.firmwareUpdateContext.availableUpdate!==void 0?{...e.context._internalState,error:new D("Firmware is not the latest version")}:{...e.context._internalState,deviceMetadata:t},Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallDependencies"}]},InstallDependencies:{exit:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{src:"installApps",input:e=>({unlockTimeout:e.context.input.unlockTimeout,applications:[...e.context.input.dependencies,e.context.input.application],allowMissingApplication:!1}),onSnapshot:{actions:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:e.event.snapshot.context.intermediateValue.installPlan,deviceId:e.event.snapshot.context.intermediateValue.deviceId??e.context.intermediateValue.deviceId})})},onDone:{target:"InstallDependenciesCheck",actions:n({_internalState:e=>e.event.output.caseOf({Right:t=>({...e.context._internalState,installResult:t}),Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallDependenciesCheck:{always:[{guard:"hasError",target:"Error"},{target:"OpenApp"}]},OpenApp:{exit:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{src:"openApp",input:e=>({unlockTimeout:e.context.input.unlockTimeout,appName:e.context.input.application.name}),onSnapshot:{actions:n({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction,installPlan:null})})},onDone:{target:"OpenAppCheck",actions:n({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},OpenAppCheck:{always:[{guard:"hasError",target:"Error"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:t}=e,{error:p,deviceMetadata:l,installResult:u}=t._internalState;return p?d(p):m({deviceMetadata:l,installResult:u})}})}}export{w as OpenAppWithDependenciesDeviceAction};
|
|
2
2
|
//# sourceMappingURL=OpenAppWithDependenciesDeviceAction.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnsupportedFirmwareDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport type { GetDeviceMetadataDAOutput } from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport type { InstallOrUpdateAppsDAOutput } from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\n\nimport {\n type OpenAppWithDependenciesDAError,\n type OpenAppWithDependenciesDAInput,\n type OpenAppWithDependenciesDAIntermediateValue,\n type OpenAppWithDependenciesDAOutput,\n} from \"./types\";\n\ntype OpenAppWithDependenciesMachineInternalState = {\n readonly error: OpenAppWithDependenciesDAError | null;\n readonly deviceMetadata: GetDeviceMetadataDAOutput | null;\n readonly installResult: InstallOrUpdateAppsDAOutput | null;\n};\n\nexport class OpenAppWithDependenciesDeviceAction extends XStateDeviceAction<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n >;\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const installAppsMachine = new InstallOrUpdateAppsDeviceAction({\n input: {\n unlockTimeout,\n applications: [...this.input.dependencies, this.input.application],\n allowMissingApplication: false,\n },\n }).makeStateMachine(internalApi);\n\n const openAppMachine = new OpenAppDeviceAction({\n input: {\n unlockTimeout,\n appName: this.input.application.name,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getMetadata: getMetadataMachine,\n installApps: installAppsMachine,\n openApp: openAppMachine,\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n },\n }).createMachine({\n id: \"OpenAppWithDependenciesDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n application: _.input.application,\n dependencies: _.input.dependencies,\n requireLatestFirmware: _.input.requireLatestFirmware,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n deviceMetadata: null,\n installResult: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GetDeviceMetadata\",\n },\n ],\n },\n GetDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"getMetadata\",\n src: \"getMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n }),\n }),\n },\n onDone: {\n target: \"GetDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => {\n if (\n _.context.input.requireLatestFirmware &&\n data.firmwareUpdateContext.availableUpdate !==\n undefined\n ) {\n return {\n ..._.context._internalState,\n error: new UnsupportedFirmwareDAError(\n \"Firmware is not the latest version\",\n ),\n };\n } else {\n return {\n ..._.context._internalState,\n deviceMetadata: data,\n };\n }\n },\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallDependencies\",\n },\n ],\n },\n InstallDependencies: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"installApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n applications: [\n ..._.context.input.dependencies,\n _.context.input.application,\n ],\n allowMissingApplication: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan:\n _.event.snapshot.context.intermediateValue.installPlan,\n }),\n }),\n },\n onDone: {\n target: \"InstallDependenciesCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n installResult: data,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallDependenciesCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OpenApp\",\n },\n ],\n },\n OpenApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"openApp\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n appName: _.context.input.application.name,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan: null,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OpenAppCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error, deviceMetadata, installResult } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n deviceMetadata: deviceMetadata!,\n installResult: installResult!,\n });\n },\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,SAAAC,MAAa,SAG9B,OAAS,2BAAAC,MAA+B,m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ACjB,wBAAyBd,EAAwB,KACjD,YAAa,IACf,EACA,eAAgB,CACd,MAAO,KACP,eAAgB,KAChB,cAAe,IACjB,CACF,GAEF,OAAQ,CACN,YAAa,CACX,OAAQ,CACN,CACE,OAAQ,mBACV,CACF,CACF,EACA,kBAAmB,CACjB,KAAMF,EAAO,CACX,kBAAoBgB,IAAO,CACzB,GAAGA,EAAE,QAAQ,kBACb,wBAAyBd,EAAwB,IACnD,EACF,CAAC,EACD,OAAQ,CACN,GAAI,cACJ,IAAK,cACL,MAAQc,IAAO,CACb,cAAeA,EAAE,QAAQ,MAAM,cAC/B,iBAAkB,GAClB,YAAa,EACf,GACA,WAAY,CACV,QAAShB,EAAO,CACd,kBAAoBgB,IAAO,CACzB,GAAGA,EAAE,QAAQ,kBACb,wBACEA,EAAE,MAAM,SAAS,QAAQ,kBACtB,
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { assign, setup } from \"xstate\";\n\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport { UnsupportedFirmwareDAError } from \"@api/device-action/os/Errors\";\nimport { GetDeviceMetadataDeviceAction } from \"@api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction\";\nimport type { GetDeviceMetadataDAOutput } from \"@api/device-action/os/GetDeviceMetadata/types\";\nimport { InstallOrUpdateAppsDeviceAction } from \"@api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction\";\nimport type { InstallOrUpdateAppsDAOutput } from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { OpenAppDeviceAction } from \"@api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\n\nimport {\n type OpenAppWithDependenciesDAError,\n type OpenAppWithDependenciesDAInput,\n type OpenAppWithDependenciesDAIntermediateValue,\n type OpenAppWithDependenciesDAOutput,\n} from \"./types\";\n\ntype OpenAppWithDependenciesMachineInternalState = {\n readonly error: OpenAppWithDependenciesDAError | null;\n readonly deviceMetadata: GetDeviceMetadataDAOutput | null;\n readonly installResult: InstallOrUpdateAppsDAOutput | null;\n};\n\nexport class OpenAppWithDependenciesDeviceAction extends XStateDeviceAction<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n > {\n type types = StateMachineTypes<\n OpenAppWithDependenciesDAOutput,\n OpenAppWithDependenciesDAInput,\n OpenAppWithDependenciesDAError,\n OpenAppWithDependenciesDAIntermediateValue,\n OpenAppWithDependenciesMachineInternalState\n >;\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const getMetadataMachine = new GetDeviceMetadataDeviceAction({\n input: {\n unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n },\n }).makeStateMachine(internalApi);\n\n const installAppsMachine = new InstallOrUpdateAppsDeviceAction({\n input: {\n unlockTimeout,\n applications: [...this.input.dependencies, this.input.application],\n allowMissingApplication: false,\n },\n }).makeStateMachine(internalApi);\n\n const openAppMachine = new OpenAppDeviceAction({\n input: {\n unlockTimeout,\n appName: this.input.application.name,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getMetadata: getMetadataMachine,\n installApps: installAppsMachine,\n openApp: openAppMachine,\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n },\n }).createMachine({\n id: \"OpenAppWithDependenciesDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n application: _.input.application,\n dependencies: _.input.dependencies,\n requireLatestFirmware: _.input.requireLatestFirmware,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n installPlan: null,\n },\n _internalState: {\n error: null,\n deviceMetadata: null,\n installResult: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GetDeviceMetadata\",\n },\n ],\n },\n GetDeviceMetadata: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n id: \"getMetadata\",\n src: \"getMetadata\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n useSecureChannel: true,\n forceUpdate: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n deviceId:\n _.event.snapshot.context.intermediateValue.deviceId ??\n _.context.intermediateValue.deviceId,\n }),\n }),\n },\n onDone: {\n target: \"GetDeviceMetadataCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => {\n if (\n _.context.input.requireLatestFirmware &&\n data.firmwareUpdateContext.availableUpdate !==\n undefined\n ) {\n return {\n ..._.context._internalState,\n error: new UnsupportedFirmwareDAError(\n \"Firmware is not the latest version\",\n ),\n };\n } else {\n return {\n ..._.context._internalState,\n deviceMetadata: data,\n };\n }\n },\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"InstallDependencies\",\n },\n ],\n },\n InstallDependencies: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"installApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n applications: [\n ..._.context.input.dependencies,\n _.context.input.application,\n ],\n allowMissingApplication: false,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan:\n _.event.snapshot.context.intermediateValue.installPlan,\n deviceId:\n _.event.snapshot.context.intermediateValue.deviceId ??\n _.context.intermediateValue.deviceId,\n }),\n }),\n },\n onDone: {\n target: \"InstallDependenciesCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: (data) => ({\n ..._.context._internalState,\n installResult: data,\n }),\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n InstallDependenciesCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"OpenApp\",\n },\n ],\n },\n OpenApp: {\n exit: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }),\n }),\n invoke: {\n src: \"openApp\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n appName: _.context.input.application.name,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) => ({\n ..._.context.intermediateValue,\n requiredUserInteraction:\n _.event.snapshot.context.intermediateValue\n .requiredUserInteraction,\n installPlan: null,\n }),\n }),\n },\n onDone: {\n target: \"OpenAppCheck\",\n actions: assign({\n _internalState: (_) =>\n _.event.output.caseOf<OpenAppWithDependenciesMachineInternalState>(\n {\n Right: () => _.context._internalState,\n Left: (error) => ({\n ..._.context._internalState,\n error,\n }),\n },\n ),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n OpenAppCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n const { context } = args;\n const { error, deviceMetadata, installResult } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n deviceMetadata: deviceMetadata!,\n installResult: installResult!,\n });\n },\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,UAAAC,EAAQ,SAAAC,MAAa,SAG9B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,8BAAAC,MAAkC,+BAC3C,OAAS,iCAAAC,MAAqC,wEAE9C,OAAS,mCAAAC,MAAuC,4EAEhD,OAAS,uBAAAC,MAA2B,gEAEpC,OAEE,sBAAAC,MACK,qDAeA,MAAMC,UAA4CD,CAMvD,CACA,iBACEE,EAOA,CASA,MAAMC,EAAgB,KAAK,MAAM,eAAiBR,EAE5CS,EAAqB,IAAIP,EAA8B,CAC3D,MAAO,CACL,cAAAM,EACA,iBAAkB,GAClB,YAAa,EACf,CACF,CAAC,EAAE,iBAAiBD,CAAW,EAEzBG,EAAqB,IAAIP,EAAgC,CAC7D,MAAO,CACL,cAAAK,EACA,aAAc,CAAC,GAAG,KAAK,MAAM,aAAc,KAAK,MAAM,WAAW,EACjE,wBAAyB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,eACzD,OAAIG,EACKpB,EAAKoB,CAAK,EAEZnB,EAAM,CACX,eAAgBqB,EAChB,cAAeC,CACjB,CAAC,CACH,CACF,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["Left", "Right", "assign", "setup", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "UnsupportedFirmwareDAError", "GetDeviceMetadataDeviceAction", "InstallOrUpdateAppsDeviceAction", "OpenAppDeviceAction", "XStateDeviceAction", "OpenAppWithDependenciesDeviceAction", "internalApi", "unlockTimeout", "getMetadataMachine", "installAppsMachine", "openAppMachine", "context", "_", "data", "error", "args", "deviceMetadata", "installResult"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{gte as
|
|
1
|
+
import{gte as p}from"semver";import{UnknownDAError as d,UnsupportedApplicationDAError as u,UnsupportedFirmwareDAError as c}from"../../device-action/os/Errors";import{DeviceSessionStateType as m}from"../../device-session/DeviceSessionState";class w{constructor(n,i){this.api=n;this.args=i;const r=n.getDeviceModel();this.deviceModelId=r.id}deviceModelId;run(){const n=this.api.getDeviceSessionState();if(n.sessionStateType===m.Connected)return{error:new d("Invalid device state")};if(n.catalog===void 0)return{error:new d("Device apps metadata not fetched")};let i=[],r=[],t=[];for(const e of this.args.applications){const a=n.catalog.applications.find(l=>l.versionName===e.name),o=n.installedApps.find(l=>l.versionName===e.name);if(o!==void 0&&this.validateConstraint(o,a,e.constraints)){r=[...r,e.name];continue}if(a!==void 0&&this.validateConstraint(a,void 0,e.constraints))i=[...i,a];else if(this.args.allowMissingApplication)t=[...t,e.name];else return n.firmwareUpdateContext?.availableUpdate!==void 0&&a!==void 0?{error:new c(`Application ${e.name} needs latest firmware`)}:n.firmwareUpdateContext?.availableUpdate!==void 0?{error:new c(`Application ${e.name} needs latest firmware`)}:{error:new u(`Application ${e.name} not supported for this device`)}}return i=[...i.reduce((e,a)=>{const o=a.parentName;if(o){const l=n.catalog.applications.find(s=>s.versionName===o),f=n.installedApps.find(s=>s.versionName===o);if(l&&!f)return[...e,l]}return e},[]),...i],{installPlan:i.filter((e,a)=>i.findIndex(o=>o.versionName===e.versionName)===a),missingApplications:t,alreadyInstalled:r}}validateConstraint(n,i,r){if(r===void 0)return!0;for(const t of r)if(!(t.exemptModels!==void 0&&t.exemptModels.includes(this.deviceModelId))&&!(t.applicableModels!==void 0&&!t.applicableModels.includes(this.deviceModelId)))return t.minVersion==="latest"?!i||p(n.version,i.version):p(n.version,t.minVersion);return!0}}export{w as BuildAppsInstallPlanTask};
|
|
2
2
|
//# sourceMappingURL=BuildAppsInstallPlanTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/BuildAppsInstallPlanTask.ts"],
|
|
4
|
-
"sourcesContent": ["import { gte } from \"semver\";\n\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n ApplicationConstraint,\n ApplicationDependency,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type BuildAppsInstallPlanTaskArgs = {\n /**\n * List of applications to install or update\n */\n readonly applications: ApplicationDependency[];\n\n /**\n * Indicates if the device action should fail if an application is missing from the app store.\n */\n readonly allowMissingApplication: boolean;\n};\n\nexport type BuildAppsInstallPlanTaskResult =\n | {\n installPlan: Application[];\n alreadyInstalled: string[];\n missingApplications: string[];\n }\n | {\n error
|
|
5
|
-
"mappings": "AAAA,OAAS,OAAAA,MAAW,SAIpB,OACE,kBAAAC,EACA,8BAAAC,MACK,+BAKP,OAAS,0BAAAC,MAA8B,
|
|
6
|
-
"names": ["gte", "UnknownDAError", "UnsupportedFirmwareDAError", "DeviceSessionStateType", "BuildAppsInstallPlanTask", "api", "args", "deviceModel", "deviceState", "installPlan", "alreadyInstalled", "missingApplications", "app", "catalogApp", "a", "installedApp", "apps", "dependency", "index", "constraints", "constraint"]
|
|
4
|
+
"sourcesContent": ["import { gte } from \"semver\";\n\nimport type { DeviceModelId } from \"@api/device/DeviceModel\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport {\n UnknownDAError,\n UnsupportedApplicationDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type {\n ApplicationConstraint,\n ApplicationDependency,\n} from \"@api/device-action/os/InstallOrUpdateApps/types\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nexport type BuildAppsInstallPlanTaskArgs = {\n /**\n * List of applications to install or update\n */\n readonly applications: ApplicationDependency[];\n\n /**\n * Indicates if the device action should fail if an application is missing from the app store.\n */\n readonly allowMissingApplication: boolean;\n};\n\nexport type BuildAppsInstallPlanTaskResult =\n | {\n installPlan: Application[];\n alreadyInstalled: string[];\n missingApplications: string[];\n }\n | {\n error:\n | UnknownDAError\n | UnsupportedApplicationDAError\n | UnsupportedFirmwareDAError;\n };\n\nexport class BuildAppsInstallPlanTask {\n private readonly deviceModelId: DeviceModelId;\n\n constructor(\n private readonly api: InternalApi,\n private readonly args: BuildAppsInstallPlanTaskArgs,\n ) {\n const deviceModel = api.getDeviceModel();\n this.deviceModelId = deviceModel.id;\n }\n\n run(): BuildAppsInstallPlanTaskResult {\n // Get device session state.\n const deviceState = this.api.getDeviceSessionState();\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return { error: new UnknownDAError(\"Invalid device state\") };\n }\n\n // Ensure the device metadata were correctly fetched.\n if (deviceState.catalog === undefined) {\n return { error: new UnknownDAError(\"Device apps metadata not fetched\") };\n }\n\n // Build the install plan\n let installPlan: Application[] = [];\n let alreadyInstalled: string[] = [];\n let missingApplications: string[] = [];\n for (const app of this.args.applications) {\n // Get app entry from catalog and from installed apps\n const catalogApp = deviceState.catalog.applications.find(\n (a) => a.versionName === app.name,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === app.name,\n );\n\n // If app is already installed, with validated constraints, continue the iteration\n if (\n installedApp !== undefined &&\n this.validateConstraint(installedApp, catalogApp, app.constraints)\n ) {\n alreadyInstalled = [...alreadyInstalled, app.name];\n continue;\n }\n\n // Handle the catalog application\n if (\n catalogApp !== undefined &&\n this.validateConstraint(catalogApp, undefined, app.constraints)\n ) {\n // Add the catalog application to the install plan\n installPlan = [...installPlan, catalogApp];\n } else if (this.args.allowMissingApplication) {\n missingApplications = [...missingApplications, app.name];\n } else {\n /**\n * Fail immediately if missing application is not allowed.\n *\n * TODO: If the application is not in catalog, we should also check if the application will be available in the\n * latest firmware catalog before throwing `UnsupportedApplicationDAError`. The actual implementation will always\n * throw `UnsupportedFirmwareDAError` to force the user to update firmware first, even though the application may\n * be still not available after the firmware update. For now, we keep `catalogApp !== undefined` check to prevent\n * from forgetting this case.\n *\n * Decision matrix for application availability according to OS and catalog:\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 Not valid constraint \u2502 Found in catalog \u2502 Not found in catalog \u2502\n * \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n * \u2502 OS up-to-date \u2502 UnsupportedApplicationDAError \u2502 UnsupportedApplicationDAError \u2502\n * \u2502 OS out-of-date \u2502 UnsupportedFirmwareDAError \u2502 UnsupportedFirmwareDAError => TODO \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n */\n if (\n deviceState.firmwareUpdateContext?.availableUpdate !== undefined &&\n catalogApp !== undefined\n ) {\n return {\n error: new UnsupportedFirmwareDAError(\n `Application ${app.name} needs latest firmware`,\n ),\n };\n } else if (\n deviceState.firmwareUpdateContext?.availableUpdate !== undefined\n ) {\n // TODO: Application not found in out-of-date firmware catalog, needs to check if the application will be available\n // after firmware update\n return {\n error: new UnsupportedFirmwareDAError(\n `Application ${app.name} needs latest firmware`,\n ),\n };\n } else {\n return {\n error: new UnsupportedApplicationDAError(\n `Application ${app.name} not supported for this device`,\n ),\n };\n }\n }\n }\n\n // Find installPlan dependencies\n const dependencies = installPlan.reduce((apps, app) => {\n const dependency = app.parentName;\n if (dependency) {\n const catalogApp = deviceState.catalog!.applications.find(\n (a) => a.versionName === dependency,\n );\n const installedApp = deviceState.installedApps.find(\n (a) => a.versionName === dependency,\n );\n if (catalogApp && !installedApp) {\n return [...apps, catalogApp];\n }\n }\n return apps;\n }, [] as Application[]);\n\n // Reorder and deduplicate the install plan with its dependencies first\n installPlan = [...dependencies, ...installPlan];\n const reorderedInstallPlan = installPlan.filter(\n (app, index) =>\n installPlan.findIndex((a) => a.versionName === app.versionName) ===\n index,\n );\n\n return {\n installPlan: reorderedInstallPlan,\n missingApplications,\n alreadyInstalled,\n };\n }\n\n private validateConstraint(\n app: Application,\n catalogApp?: Application,\n constraints?: ApplicationConstraint[],\n ): boolean {\n if (constraints === undefined) {\n // No constraint\n return true;\n }\n\n // Validate the constraint\n for (const constraint of constraints) {\n // Is current device exempt from the constraint?\n if (\n constraint.exemptModels !== undefined &&\n constraint.exemptModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Is current device not applicable for the constraint?\n if (\n constraint.applicableModels !== undefined &&\n !constraint.applicableModels.includes(this.deviceModelId)\n ) {\n continue;\n }\n\n // Validate the min version\n if (constraint.minVersion === \"latest\") {\n return !catalogApp || gte(app.version, catalogApp.version);\n } else {\n return gte(app.version, constraint.minVersion);\n }\n }\n\n // No constraint for the device\n return true;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,OAAAA,MAAW,SAIpB,OACE,kBAAAC,EACA,iCAAAC,EACA,8BAAAC,MACK,+BAKP,OAAS,0BAAAC,MAA8B,yCA4BhC,MAAMC,CAAyB,CAGpC,YACmBC,EACAC,EACjB,CAFiB,SAAAD,EACA,UAAAC,EAEjB,MA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,CACd,MAAMJ,EAAaL,EAAY,QAAS,aAAa,KAClDM,GAAMA,EAAE,cAAgBG,CAC3B,EACMF,EAAeP,EAAY,cAAc,KAC5CM,GAAMA,EAAE,cAAgBG,CAC3B,EACA,GAAIJ,GAAc,CAACE,EACjB,MAAO,CAAC,GAAGC,EAAMH,CAAU,CAE/B,CACA,OAAOG,CACT,EAAG,CAAC,CAAkB,EAGU,GAAGP,CAAW,EAOvC,CACL,YAP2BA,EAAY,OACvC,CAACG,EAAKM,IACJT,EAAY,UAAWK,GAAMA,EAAE,cAAgBF,EAAI,WAAW,IAC9DM,CACJ,EAIE,oBAAAP,EACA,iBAAAD,CACF,CACF,CAEQ,mBACNE,EACAC,EACAM,EACS,CACT,GAAIA,IAAgB,OAElB,MAAO,GAIT,UAAWC,KAAcD,EAEvB,GACE,EAAAC,EAAW,eAAiB,QAC5BA,EAAW,aAAa,SAAS,KAAK,aAAa,IAOnD,EAAAA,EAAW,mBAAqB,QAChC,CAACA,EAAW,iBAAiB,SAAS,KAAK,aAAa,GAM1D,OAAIA,EAAW,aAAe,SACrB,CAACP,GAAcd,EAAIa,EAAI,QAASC,EAAW,OAAO,EAElDd,EAAIa,EAAI,QAASQ,EAAW,UAAU,EAKjD,MAAO,EACT,CACF",
|
|
6
|
+
"names": ["gte", "UnknownDAError", "UnsupportedApplicationDAError", "UnsupportedFirmwareDAError", "DeviceSessionStateType", "BuildAppsInstallPlanTask", "api", "args", "deviceModel", "deviceState", "installPlan", "alreadyInstalled", "missingApplications", "app", "catalogApp", "a", "installedApp", "apps", "dependency", "index", "constraints", "constraint"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DeviceModelId as
|
|
1
|
+
import{DeviceModelId as s}from"../../device/DeviceModel";import{DeviceStatus as a}from"../../device/DeviceStatus";import{makeDeviceActionInternalApiMock as c}from"../../device-action/__test-utils__/makeInternalApi";import{UnknownDAError as o,UnsupportedApplicationDAError as r,UnsupportedFirmwareDAError as l}from"../../device-action/os/Errors";import{DeviceSessionStateType as i}from"../../device-session/DeviceSessionState";import{BuildAppsInstallPlanTask as t}from"./BuildAppsInstallPlanTask";describe("BuildAppsInstallPlanTask",()=>{const e=c();beforeEach(()=>{vi.clearAllMocks(),e.getDeviceModel.mockReturnValue({id:s.NANO_X})}),it("Success with no changes needed",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum"},{name:"Bitcoin"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin"],missingApplications:[]})}),it("Success with no constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.1.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.1.0"}],alreadyInstalled:["Ethereum"],missingApplications:[]})}),it("Success with applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",applicableModels:[s.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",exemptModels:[s.NANO_S]}]},{name:"Solana",constraints:[{minVersion:"1.2.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:[],missingApplications:[]})}),it("Success with non-applicable constraints",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.2.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"Cardano",version:"1.1.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"MyShitCoin",version:"0.0.1"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0",exemptModels:[s.NANO_X]}]},{name:"Bitcoin",constraints:[{minVersion:"1.2.1",applicableModels:[s.NANO_S]}]},{name:"Cardano",constraints:[{minVersion:"1.1.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[],alreadyInstalled:["Ethereum","Bitcoin","Cardano"],missingApplications:[]})}),it("Success with applicable constraints latest version",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.1.0"},{versionName:"MyShitCoin",version:"0.0.1"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"},{versionName:"Cardano",version:"1.2.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"latest"}]},{name:"Bitcoin",constraints:[{minVersion:"latest"}]},{name:"MyShitCoin",constraints:[{minVersion:"latest"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0"}],alreadyInstalled:["Bitcoin","MyShitCoin"],missingApplications:[]})}),it("Success with dependencies",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"AlreadyInstalledDep",version:"1.2.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"Cardano",version:"1.2.0",parentName:void 0},{versionName:"AlreadyInstalledDep",version:"1.2.0",parentName:"Cardano"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"MyEthShitCoin"},{name:"MySolShitCoin"},{name:"Solana"},{name:"MyPumpFunShitCoin"},{name:"AlreadyInstalledDep"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Ethereum",version:"1.6.0",parentName:void 0},{versionName:"Solana",version:"1.2.0",parentName:void 0},{versionName:"MyEthShitCoin",version:"0.0.1",parentName:"Ethereum"},{versionName:"MySolShitCoin",version:"0.0.1",parentName:"Solana"},{versionName:"MyPumpFunShitCoin",version:"0.0.1",parentName:"Solana"}],alreadyInstalled:["AlreadyInstalledDep"],missingApplications:[]})}),it("Success with allowed missing applications",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[{versionName:"Ethereum",version:"1.5.0"},{versionName:"Bitcoin",version:"1.3.0"}],catalog:{applications:[{versionName:"Ethereum",version:"1.6.0"},{versionName:"Bitcoin",version:"1.3.0"},{versionName:"Solana",version:"1.2.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum"},{name:"Solana"},{name:"Cardano"}],allowMissingApplication:!0}).run();expect(n).toStrictEqual({installPlan:[{versionName:"Solana",version:"1.2.0"}],alreadyInstalled:["Ethereum"],missingApplications:["Cardano"]})}),it("Error when device is in incorrect state",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.Connected,deviceStatus:a.CONNECTED});const n=new t(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o("Invalid device state")})}),it("Error when device session was not populated",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[]});const n=new t(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new o("Device apps metadata not fetched")})}),describe("Error cases for unsupported applications and firmwares",()=>{describe("when firmware is up to date",()=>{it("should throw `UnsupportedApplicationDAError` when application not found in catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,firmwareUpdateContext:{currentFirmware:{}},installedApps:[],catalog:{applications:[],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new r("Application Ethereum not supported for this device")})}),it("should throw `UnsupportedApplicationDAError` when application version is not supported",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,firmwareUpdateContext:{currentFirmware:{}},installedApps:[],catalog:{applications:[{versionName:"Ethereum",version:"1.5.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new r("Application Ethereum not supported for this device")})})}),describe("when firmware is out of date",()=>{it("should throw `UnsupportedFirmwareDAError` when application not found in catalog",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,firmwareUpdateContext:{currentFirmware:{},availableUpdate:{}},installedApps:[],catalog:{applications:[],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum"}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new l("Application Ethereum needs latest firmware")})}),it("should throw `UnsupportedFirmwareDAError` when application version is not supported",()=>{e.getDeviceSessionState.mockReturnValueOnce({sessionStateType:i.ReadyWithoutSecureChannel,deviceStatus:a.CONNECTED,installedApps:[],firmwareUpdateContext:{currentFirmware:{},availableUpdate:{}},catalog:{applications:[{versionName:"Ethereum",version:"1.5.0"}],languagePackages:[]}});const n=new t(e,{applications:[{name:"Ethereum",constraints:[{minVersion:"1.6.0"}]}],allowMissingApplication:!1}).run();expect(n).toStrictEqual({error:new l("Application Ethereum needs latest firmware")})})})})});
|
|
2
2
|
//# sourceMappingURL=BuildAppsInstallPlanTask.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/BuildAppsInstallPlanTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport {\n UnknownDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type { DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\n\nimport { BuildAppsInstallPlanTask } from \"./BuildAppsInstallPlanTask\";\n\ndescribe(\"BuildAppsInstallPlanTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n id: DeviceModelId.NANO_X,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success with no changes needed\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }, { name: \"Bitcoin\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with no constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", applicableModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", exemptModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Solana\", constraints: [{ minVersion: \"1.2.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ],\n alreadyInstalled: [],\n missingApplications: [],\n });\n });\n\n it(\"Success with non-applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", exemptModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", applicableModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Cardano\", constraints: [{ minVersion: \"1.1.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\", \"Cardano\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints latest version\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"Bitcoin\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"MyShitCoin\", constraints: [{ minVersion: \"latest\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Ethereum\", version: \"1.6.0\" }],\n alreadyInstalled: [\"Bitcoin\", \"MyShitCoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with dependencies\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"AlreadyInstalledDep\", version: \"1.2.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n { versionName: \"Cardano\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"AlreadyInstalledDep\",\n version: \"1.2.0\",\n parentName: \"Cardano\",\n },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"MyEthShitCoin\" },\n { name: \"MySolShitCoin\" },\n { name: \"Solana\" },\n { name: \"MyPumpFunShitCoin\" },\n { name: \"AlreadyInstalledDep\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n ],\n alreadyInstalled: [\"AlreadyInstalledDep\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with allowed missing applications\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: true,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Solana\", version: \"1.2.0\" }],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [\"Cardano\"],\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device apps metadata not fetched\"),\n });\n });\n\n it(\"Error when an app is not found in the catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Bitcoin\" },\n { name: \"Solana\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\n \"Application Ethereum not found in the catalog\",\n ),\n });\n });\n\n it(\"Error when an app version is not found in the catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum not found in the catalog\",\n ),\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OACE,kBAAAC,EACA,8BAAAC,MACK,+
|
|
6
|
-
"names": ["DeviceModelId", "DeviceStatus", "makeDeviceActionInternalApiMock", "UnknownDAError", "UnsupportedFirmwareDAError", "DeviceSessionStateType", "BuildAppsInstallPlanTask", "apiMock", "result"]
|
|
4
|
+
"sourcesContent": ["import { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport {\n UnknownDAError,\n UnsupportedApplicationDAError,\n UnsupportedFirmwareDAError,\n} from \"@api/device-action/os/Errors\";\nimport type { TransportDeviceModel } from \"@api/device-model/model/DeviceModel\";\nimport type {\n DeviceSessionState,\n FirmwareUpdate,\n} from \"@api/device-session/DeviceSessionState\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport type { Application } from \"@internal/manager-api/model/Application\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { BuildAppsInstallPlanTask } from \"./BuildAppsInstallPlanTask\";\n\ndescribe(\"BuildAppsInstallPlanTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n\n beforeEach(() => {\n vi.clearAllMocks();\n apiMock.getDeviceModel.mockReturnValue({\n id: DeviceModelId.NANO_X,\n } as unknown as TransportDeviceModel);\n });\n\n it(\"Success with no changes needed\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }, { name: \"Bitcoin\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with no constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", applicableModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", exemptModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Solana\", constraints: [{ minVersion: \"1.2.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ],\n alreadyInstalled: [],\n missingApplications: [],\n });\n });\n\n it(\"Success with non-applicable constraints\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.2.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"Cardano\", version: \"1.1.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [\n { minVersion: \"1.6.0\", exemptModels: [DeviceModelId.NANO_X] },\n ],\n },\n {\n name: \"Bitcoin\",\n constraints: [\n { minVersion: \"1.2.1\", applicableModels: [DeviceModelId.NANO_S] },\n ],\n },\n { name: \"Cardano\", constraints: [{ minVersion: \"1.1.0\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [],\n alreadyInstalled: [\"Ethereum\", \"Bitcoin\", \"Cardano\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with applicable constraints latest version\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.1.0\" },\n { versionName: \"MyShitCoin\", version: \"0.0.1\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n { versionName: \"Cardano\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"Bitcoin\", constraints: [{ minVersion: \"latest\" }] },\n { name: \"MyShitCoin\", constraints: [{ minVersion: \"latest\" }] },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Ethereum\", version: \"1.6.0\" }],\n alreadyInstalled: [\"Bitcoin\", \"MyShitCoin\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with dependencies\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"AlreadyInstalledDep\", version: \"1.2.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n { versionName: \"Cardano\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"AlreadyInstalledDep\",\n version: \"1.2.0\",\n parentName: \"Cardano\",\n },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"MyEthShitCoin\" },\n { name: \"MySolShitCoin\" },\n { name: \"Solana\" },\n { name: \"MyPumpFunShitCoin\" },\n { name: \"AlreadyInstalledDep\" },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [\n { versionName: \"Ethereum\", version: \"1.6.0\", parentName: undefined },\n { versionName: \"Solana\", version: \"1.2.0\", parentName: undefined },\n {\n versionName: \"MyEthShitCoin\",\n version: \"0.0.1\",\n parentName: \"Ethereum\",\n },\n {\n versionName: \"MySolShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n {\n versionName: \"MyPumpFunShitCoin\",\n version: \"0.0.1\",\n parentName: \"Solana\",\n },\n ],\n alreadyInstalled: [\"AlreadyInstalledDep\"],\n missingApplications: [],\n });\n });\n\n it(\"Success with allowed missing applications\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n ] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.6.0\" },\n { versionName: \"Bitcoin\", version: \"1.3.0\" },\n { versionName: \"Solana\", version: \"1.2.0\" },\n ] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n { name: \"Ethereum\" },\n { name: \"Solana\" },\n { name: \"Cardano\" },\n ],\n allowMissingApplication: true,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n installPlan: [{ versionName: \"Solana\", version: \"1.2.0\" }],\n alreadyInstalled: [\"Ethereum\"],\n missingApplications: [\"Cardano\"],\n });\n });\n\n it(\"Error when device is in incorrect state\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n } as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Invalid device state\"),\n });\n });\n\n it(\"Error when device session was not populated\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnknownDAError(\"Device apps metadata not fetched\"),\n });\n });\n\n describe(\"Error cases for unsupported applications and firmwares\", () => {\n describe(\"when firmware is up to date\", () => {\n it(\"should throw `UnsupportedApplicationDAError` when application not found in catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedApplicationDAError(\n \"Application Ethereum not supported for this device\",\n ),\n });\n });\n it(\"should throw `UnsupportedApplicationDAError` when application version is not supported\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedApplicationDAError(\n \"Application Ethereum not supported for this device\",\n ),\n });\n });\n });\n describe(\"when firmware is out of date\", () => {\n it(\"should throw `UnsupportedFirmwareDAError` when application not found in catalog\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n availableUpdate: {} as FirmwareUpdate,\n },\n installedApps: [] as unknown as Application[],\n catalog: {\n applications: [] as unknown as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [{ name: \"Ethereum\" }],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum needs latest firmware\",\n ),\n });\n });\n it(\"should throw `UnsupportedFirmwareDAError` when application version is not supported\", () => {\n // GIVEN\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [] as unknown as Application[],\n firmwareUpdateContext: {\n currentFirmware: {} as FinalFirmware,\n availableUpdate: {} as FirmwareUpdate,\n },\n catalog: {\n applications: [\n { versionName: \"Ethereum\", version: \"1.5.0\" },\n ] as Application[],\n languagePackages: [],\n },\n } as unknown as DeviceSessionState);\n\n // WHEN\n const result = new BuildAppsInstallPlanTask(apiMock, {\n applications: [\n {\n name: \"Ethereum\",\n constraints: [{ minVersion: \"1.6.0\" }],\n },\n ],\n allowMissingApplication: false,\n }).run();\n\n // THEN\n expect(result).toStrictEqual({\n error: new UnsupportedFirmwareDAError(\n \"Application Ethereum needs latest firmware\",\n ),\n });\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,0BAC9B,OAAS,gBAAAC,MAAoB,2BAC7B,OAAS,mCAAAC,MAAuC,oDAChD,OACE,kBAAAC,EACA,iCAAAC,EACA,8BAAAC,MACK,+BAMP,OAAS,0BAAAC,MAA8B,yCAIvC,OAAS,4BAAAC,MAAgC,6BAEzC,SAAS,2BAA4B,IAAM,CACzC,MAAMC,EAAUN,EAAgC,EAEhD,WAAW,IAAM,CACf,GAAG,cAAc,EACjBM,EAAQ,eAAe,gBAAgB,CACrC,GAAIR,EAAc,MACpB,CAAoC,CACtC,CAAC,EAED,GAAG,iCAAkC,IAAM,CAEzCQ,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcL,EAAa,UAC3B,cAAe,CACb,CAAE,YAAa,WAAY,QAAS,OAAQ,EAC5C,CAAE,YAAa,UAAW,QAAS,OAAQ,CAC7C,EACA,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMQ,EAAS,IAAIF,EAAyBC,EAAS,CACnD,aAAc,CAAC,CAAE,KAAM,UAAW,EAAG,CAAE,KAAM,SAAU,CAAC,EACxD,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,YAAa,CAAC,EACd,iBAAkB,CAAC,WAAY,SAAS,EACxC,oBAAqB,CAAC,CACxB,CAAC,CACH,CAAC,EAED,GAAG,8BAA+B,IAAM,CAEtCD,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcL,EAAa,UAC3B,cAAe,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,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcL,EAAa,UAC3B,sBAAuB,CACrB,gBAAiB,CAAC,EAClB,gBAAiB,CAAC,CACpB,EACA,cAAe,CAAC,EAChB,QAAS,CACP,aAAc,CAAC,EACf,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMQ,EAAS,IAAIF,EAAyBC,EAAS,CACnD,aAAc,CAAC,CAAE,KAAM,UAAW,CAAC,EACnC,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAIJ,EACT,4CACF,CACF,CAAC,CACH,CAAC,EACD,GAAG,sFAAuF,IAAM,CAE9FG,EAAQ,sBAAsB,oBAAoB,CAChD,iBAAkBF,EAAuB,0BACzC,aAAcL,EAAa,UAC3B,cAAe,CAAC,EAChB,sBAAuB,CACrB,gBAAiB,CAAC,EAClB,gBAAiB,CAAC,CACpB,EACA,QAAS,CACP,aAAc,CACZ,CAAE,YAAa,WAAY,QAAS,OAAQ,CAC9C,EACA,iBAAkB,CAAC,CACrB,CACF,CAAkC,EAGlC,MAAMQ,EAAS,IAAIF,EAAyBC,EAAS,CACnD,aAAc,CACZ,CACE,KAAM,WACN,YAAa,CAAC,CAAE,WAAY,OAAQ,CAAC,CACvC,CACF,EACA,wBAAyB,EAC3B,CAAC,EAAE,IAAI,EAGP,OAAOC,CAAM,EAAE,cAAc,CAC3B,MAAO,IAAIJ,EACT,4CACF,CACF,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["DeviceModelId", "DeviceStatus", "makeDeviceActionInternalApiMock", "UnknownDAError", "UnsupportedApplicationDAError", "UnsupportedFirmwareDAError", "DeviceSessionStateType", "BuildAppsInstallPlanTask", "apiMock", "result"]
|
|
7
7
|
}
|
package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as
|
|
1
|
+
import{Left as g,Right as v}from"purify-ts";import{assign as o,fromObservable as D,fromPromise as u,setup as V}from"xstate";import{isSuccessCommandResult as k}from"../../../command/model/CommandResult";import{GetOsVersionCommand as C}from"../../../command/os/GetOsVersionCommand";import{UserInteractionRequired as p}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as G}from"../../../device-action/os/Const";import{GoToDashboardDeviceAction as f}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{XStateDeviceAction as x}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as I}from"../../../device-session/DeviceSessionState";import{ConnectToSecureChannelTask as y}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as s}from"../../../secure-channel/task/types";import{isDeviceGenuine as E}from"../../../secure-channel/utils";class P extends x{makeStateMachine(n){const{getOsVersion:h,getDeviceVersion:l,getFirmwareVersion:m,genuineCheck:S,getDeviceSessionState:r,setDeviceSessionState:i}=this.extractDependencies(n),a=this.input.unlockTimeout??G,c=new f({input:{unlockTimeout:a}}).makeStateMachine(n);return V({types:{input:{},context:{},output:{}},actors:{goToDashboard:c,getOsVersion:u(h),getDeviceVersion:u(l),getFirmwareVersion:u(m),genuineCheck:D(S)},guards:{hasError:e=>e.context._internalState.error!==null},actions:{assignErrorFromEvent:o({_internalState:e=>({...e.context._internalState,error:e.event.error})})}}).createMachine({id:"GenuineCheckDeviceAction",initial:"DeviceReady",context:e=>({input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:p.None},_internalState:{error:null,result:{isGenuine:!1},getOsVersionResponse:null,deviceVersion:null,firmwareVersion:null}}),states:{DeviceReady:{always:{target:"GoToDashboard"}},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:o({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:o({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetOsVersion"}]},GetOsVersion:{invoke:{id:"getOsVersion",src:"getOsVersion",input:e=>{},onDone:{target:"GetOsVersionCheck",actions:o({_internalState:e=>{if(k(e.event.output)){const t=r(),d=e.event.output.data.secureElementFlags.isSecureConnectionAllowed;return t.sessionStateType!==I.Connected&&i({...t,isSecureConnectionAllowed:d}),{...e.context._internalState,getOsVersionResponse:e.event.output.data}}return{...e.context._internalState,error:e.event.output.error}}})}}},GetOsVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetDeviceVersion"}]},GetDeviceVersion:{invoke:{id:"getDeviceVersion",src:"getDeviceVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse}),onDone:{target:"GetDeviceVersionCheck",actions:o({_internalState:e=>e.event.output.caseOf({Right:t=>({...e.context._internalState,deviceVersion:t}),Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetDeviceVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GetFirmwareVersion"}]},GetFirmwareVersion:{invoke:{id:"getFirmwareVersion",src:"getFirmwareVersion",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,deviceVersion:e.context._internalState.deviceVersion}),onDone:{target:"GetFirmwareVersionCheck",actions:o({_internalState:e=>e.event.output.caseOf({Right:t=>({...e.context._internalState,firmwareVersion:t}),Left:t=>({...e.context._internalState,error:t})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GetFirmwareVersionCheck:{always:[{target:"Error",guard:"hasError"},{target:"GenuineCheck"}]},GenuineCheck:{invoke:{id:"genuineCheck",src:"genuineCheck",input:e=>({deviceInfo:e.context._internalState.getOsVersionResponse,finalFirmware:e.context._internalState.firmwareVersion}),onSnapshot:{actions:o({intermediateValue:e=>{switch(e.event.snapshot.context?.type){case s.DeviceId:return{...e.context.intermediateValue,deviceId:e.event.snapshot.context.payload.deviceId};case s.PermissionRequested:return{...e.context.intermediateValue,requiredUserInteraction:p.AllowSecureConnection};case s.PermissionGranted:return{...e.context.intermediateValue,requiredUserInteraction:p.None};default:return{...e.context.intermediateValue}}},_internalState:e=>e.event.snapshot.context?.type===s.Error?{...e.context._internalState,error:e.event.snapshot.context.error.mapDAErrors()}:e.event.snapshot.context?.type===s.Result?{...e.context._internalState,result:{isGenuine:E(e.event.snapshot.context.payload)}}:e.context._internalState})},onDone:{target:"GenuineCheckCheck"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GenuineCheckCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>e.context._internalState.error?g(e.context._internalState.error):v(e.context._internalState.result)})}extractDependencies(n){return{getOsVersion:()=>n.sendCommand(new C),getDeviceVersion:({input:r})=>{const{deviceInfo:i}=r;return n.getManagerApiService().getDeviceVersion(i)},getFirmwareVersion:({input:r})=>{const{deviceInfo:i,deviceVersion:a}=r;return n.getManagerApiService().getFirmwareVersion(i,a)},genuineCheck:({input:r})=>{const{deviceInfo:i,finalFirmware:a}=r,c=n.getSecureChannelService().genuineCheck(i,a);return new y(n,{connection:c}).run()},getDeviceSessionState:()=>n.getDeviceSessionState(),setDeviceSessionState:r=>n.setDeviceSessionState(r)}}}export{P as GenuineCheckDeviceAction};
|
|
2
2
|
//# sourceMappingURL=GenuineCheckDeviceAction.js.map
|