@ledgerhq/device-management-kit 0.11.2 → 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 -41
- 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/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/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/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/esm/package.json +45 -41
- 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/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/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/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +2 -2
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/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/internal/manager-api/data/ManagerApiDataSource.d.ts +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +33 -29
package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\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 { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport {\n GetApplicationsMetadataTask,\n type GetApplicationsMetadataTaskResult,\n type InstalledApp,\n} from \"@api/device-action/task/GetApplicationsMetadataTask\";\nimport {\n GetFirmwareMetadataTask,\n type GetFirmwareMetadataTaskResult,\n} from \"@api/device-action/task/GetFirmwareMetadataTask\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type Catalog,\n type CustomImage,\n DeviceSessionStateType,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n type InstalledLanguagePackage,\n} from \"@api/device-session/DeviceSessionState\";\nimport { installedAppResultGuard } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\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\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport {\n type GetDeviceMetadataDAError,\n type GetDeviceMetadataDAInput,\n type GetDeviceMetadataDAIntermediateValue,\n type GetDeviceMetadataDAOutput,\n} from \"./types\";\n\ntype GetDeviceMetadataMachineInternalState = {\n readonly error: GetDeviceMetadataDAError | null;\n readonly deviceVersion: DeviceVersion | null;\n readonly firmware: FinalFirmware | null;\n readonly firmwareVersion: FirmwareVersion | null;\n readonly firmwareUpdateContext: FirmwareUpdateContext | null;\n readonly customImage: CustomImage | null;\n readonly installedApps: InstalledApp[] | null;\n readonly applications: Application[] | null;\n readonly applicationsUpdates: Application[] | null;\n readonly installedLanguages: InstalledLanguagePackage[] | null;\n readonly catalog: Catalog | null;\n};\n\nexport type GetDeviceMetadataFromContextTaskResult = {\n readonly firmwareVersion: FirmwareVersion;\n readonly firmwareUpdateContext: FirmwareUpdateContext;\n readonly customImage: CustomImage;\n readonly applications: Application[];\n readonly applicationsUpdates: Application[];\n readonly installedLanguages: InstalledLanguagePackage[];\n readonly catalog: Catalog;\n} | null;\n\nexport type MachineDependencies = {\n readonly getDeviceMetadata: () => Promise<GetDeviceMetadataFromContextTaskResult>;\n readonly getFirmwareMetadata: () => Promise<GetFirmwareMetadataTaskResult>;\n readonly getApplicationsMetadata: (arg0: {\n input: {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n installedApps: InstalledApp[];\n };\n }) => Promise<GetApplicationsMetadataTaskResult>;\n readonly listAppsSecureChannel: (arg0: {\n input: {\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceMetadataDeviceAction extends XStateDeviceAction<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n >;\n\n const {\n getDeviceMetadata,\n getFirmwareMetadata,\n getApplicationsMetadata,\n listAppsSecureChannel,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n const listAppsMachine = new ListAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n goToDashboard: goToDashboardMachine,\n getDeviceMetadata: fromPromise(getDeviceMetadata),\n getFirmwareMetadata: fromPromise(getFirmwareMetadata),\n getApplicationsMetadata: fromPromise(getApplicationsMetadata),\n listApps: listAppsMachine,\n listAppsSecureChannel: fromObservable(listAppsSecureChannel),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasMetadata: ({ context }) =>\n context._internalState.firmwareVersion !== null &&\n context._internalState.firmwareUpdateContext !== null &&\n context._internalState.customImage !== null &&\n context._internalState.applications !== null &&\n context._internalState.applicationsUpdates !== null &&\n context._internalState.installedLanguages !== null &&\n context._internalState.catalog !== null,\n forceUpdate: ({ context }) => Boolean(context.input.forceUpdate),\n useSecureChannel: ({ context }) =>\n Boolean(context.input.useSecureChannel),\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: \"GetDeviceMetadataDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n useSecureChannel: _.input.useSecureChannel,\n forceUpdate: _.input.forceUpdate,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n deviceVersion: null,\n firmware: null,\n firmwareVersion: null,\n firmwareUpdateContext: null,\n customImage: null,\n installedApps: null,\n applications: null,\n applicationsUpdates: null,\n installedLanguages: null,\n catalog: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GoToDashboard\",\n guard: \"forceUpdate\",\n },\n {\n target: \"GetDeviceMetadataFromContext\",\n },\n ],\n },\n GetDeviceMetadataFromContext: {\n invoke: {\n src: \"getDeviceMetadata\",\n onDone: {\n target: \"GetDeviceMetadataFromContextResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (_.event.output === null) {\n return _.context._internalState;\n } else {\n return {\n ..._.context._internalState,\n firmwareVersion: _.event.output.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.firmwareUpdateContext,\n customImage: _.event.output.customImage,\n applications: _.event.output.applications,\n applicationsUpdates: _.event.output.applicationsUpdates,\n installedLanguages: _.event.output.installedLanguages,\n catalog: _.event.output.catalog,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataFromContextResultCheck: {\n always: [\n {\n target: \"Success\",\n guard: \"hasMetadata\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"dashboard\",\n src: \"goToDashboard\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf({\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: \"GetFirmwareMetadata\",\n },\n ],\n },\n GetFirmwareMetadata: {\n invoke: {\n src: \"getFirmwareMetadata\",\n onDone: {\n target: \"GetFirmwareMetadataResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n firmwareVersion: _.event.output.data.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.data.firmwareUpdateContext,\n customImage: _.event.output.data.customImage,\n });\n }\n return {\n ..._.context._internalState,\n deviceVersion: _.event.output.data.deviceVersion,\n firmware: _.event.output.data.firmware,\n firmwareVersion: _.event.output.data.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.data.firmwareUpdateContext,\n customImage: _.event.output.data.customImage,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetFirmwareMetadataResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"useSecureChannel\",\n target: \"ListAppsSecureChannel\",\n },\n {\n target: \"ListApps\",\n },\n ],\n },\n ListAppsSecureChannel: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"listAppsSecureChannel\",\n src: \"listAppsSecureChannel\",\n input: (_) => ({\n firmware: _.context._internalState.firmware!,\n firmwareVersion: _.context._internalState.firmwareVersion!,\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 default:\n return {\n ..._.context.intermediateValue,\n };\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error: _.event.snapshot.context.error.mapDAErrors(),\n };\n } else if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Result\n ) {\n if (\n installedAppResultGuard(_.event.snapshot.context.payload)\n ) {\n return {\n ..._.context._internalState,\n installedApps: _.event.snapshot.context.payload.map(\n (app) => ({\n name: app.name,\n hash: app.hash,\n hashCode: app.hash_code_data,\n }),\n ),\n };\n }\n throw new Error(\n `Invalid result ${JSON.stringify(_.event.snapshot.context.payload)}`,\n );\n }\n return { ..._.context._internalState };\n },\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListApps: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"listApps\",\n src: \"listApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n actions: assign({\n _internalState: (_) => {\n if (_.event.output.isLeft()) {\n return {\n ..._.context._internalState,\n error: _.event.output.extract(),\n };\n } else {\n return {\n ..._.context._internalState,\n installedApps: _.event.output\n .unsafeCoerce()\n .map((app) => ({\n name: app.appName,\n hash: app.appFullHash,\n hashCode: app.appCodeHash,\n })),\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetApplicationsMetadata\",\n },\n ],\n },\n GetApplicationsMetadata: {\n invoke: {\n src: \"getApplicationsMetadata\",\n input: (_) => ({\n deviceVersion: _.context._internalState.deviceVersion!,\n firmware: _.context._internalState.firmware!,\n firmwareVersion: _.context._internalState.firmwareVersion!,\n installedApps: _.context._internalState.installedApps!,\n }),\n onDone: {\n target: \"GetApplicationsMetadataResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n installedApps: _.event.output.data.applications,\n appsUpdates: _.event.output.data.applicationsUpdates,\n installedLanguages:\n _.event.output.data.installedLanguages,\n catalog: _.event.output.data.catalog,\n });\n }\n return {\n ..._.context._internalState,\n applications: _.event.output.data.applications,\n applicationsUpdates:\n _.event.output.data.applicationsUpdates,\n installedLanguages:\n _.event.output.data.installedLanguages,\n catalog: _.event.output.data.catalog,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetApplicationsMetadataResultCheck: {\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 {\n error,\n firmwareVersion,\n firmwareUpdateContext,\n customImage,\n applications,\n applicationsUpdates,\n installedLanguages,\n catalog,\n } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n firmwareVersion: firmwareVersion!,\n firmwareUpdateContext: firmwareUpdateContext!,\n customImage: customImage!,\n applications: applications!,\n applicationsUpdates: applicationsUpdates!,\n installedLanguages: installedLanguages!,\n catalog: catalog!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getDeviceMetadata = async () => {\n const deviceState = internalApi.getDeviceSessionState();\n if (deviceState.sessionStateType === DeviceSessionStateType.Connected) {\n return null;\n }\n if (\n deviceState.firmwareVersion?.metadata === undefined ||\n deviceState.firmwareUpdateContext === undefined ||\n deviceState.customImage === undefined ||\n deviceState.installedApps.length === 0 ||\n deviceState.appsUpdates === undefined ||\n deviceState.installedLanguages === undefined ||\n deviceState.catalog === undefined\n ) {\n return null;\n }\n return {\n firmwareVersion: deviceState.firmwareVersion,\n firmwareUpdateContext: deviceState.firmwareUpdateContext,\n customImage: deviceState.customImage,\n applications: deviceState.installedApps,\n applicationsUpdates: deviceState.appsUpdates,\n installedLanguages: deviceState.installedLanguages,\n catalog: deviceState.catalog,\n };\n };\n\n const getFirmwareMetadata = async () =>\n new GetFirmwareMetadataTask(internalApi).run();\n\n const getApplicationsMetadata = async (arg0: {\n input: {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n installedApps: InstalledApp[];\n };\n }) =>\n new GetApplicationsMetadataTask(internalApi, {\n deviceVersion: arg0.input.deviceVersion,\n firmware: arg0.input.firmware,\n firmwareVersion: arg0.input.firmwareVersion,\n installedApps: arg0.input.installedApps,\n }).run();\n\n const listAppsSecureChannel = (arg0: {\n input: {\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n };\n }) => {\n const { firmware, firmwareVersion } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .listInstalledApps(firmwareVersion.metadata!, firmware);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n getDeviceMetadata,\n getFirmwareMetadata,\n getApplicationsMetadata,\n listAppsSecureChannel,\n };\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCAEvC,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AQ,EAAIK,EACd,CACJ,MAAAH,EACA,gBAAAI,EACA,sBAAAC,EACA,YAAAC,EACA,aAAAC,EACA,oBAAAC,EACA,mBAAAC,EACA,QAAAC,CACF,EAAIZ,EAAQ,eACZ,OAAIE,EACK7B,EAAK6B,CAAK,EAEZ5B,EAAM,CACX,gBAAiBgC,EACjB,sBAAuBC,EACvB,YAAaC,EACb,aAAcC,EACd,oBAAqBC,EACrB,mBAAoBC,EACpB,QAASC,CACX,CAAC,CACH,CACF,CAAC,CACH,CAEA,oBAAoBpB,EAA+C,
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\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 { GoToDashboardDeviceAction } from \"@api/device-action/os/GoToDashboard/GoToDashboardDeviceAction\";\nimport { ListAppsDeviceAction } from \"@api/device-action/os/ListApps/ListAppsDeviceAction\";\nimport {\n GetApplicationsMetadataTask,\n type GetApplicationsMetadataTaskResult,\n type InstalledApp,\n} from \"@api/device-action/task/GetApplicationsMetadataTask\";\nimport {\n GetFirmwareMetadataTask,\n type GetFirmwareMetadataTaskResult,\n} from \"@api/device-action/task/GetFirmwareMetadataTask\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type Catalog,\n type CustomImage,\n DeviceSessionStateType,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n type InstalledLanguagePackage,\n} from \"@api/device-session/DeviceSessionState\";\nimport { installedAppResultGuard } from \"@api/secure-channel/device-action/ListInstalledApps/types\";\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\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport {\n type GetDeviceMetadataDAError,\n type GetDeviceMetadataDAInput,\n type GetDeviceMetadataDAIntermediateValue,\n type GetDeviceMetadataDAOutput,\n} from \"./types\";\n\ntype GetDeviceMetadataMachineInternalState = {\n readonly error: GetDeviceMetadataDAError | null;\n readonly deviceVersion: DeviceVersion | null;\n readonly firmware: FinalFirmware | null;\n readonly firmwareVersion: FirmwareVersion | null;\n readonly firmwareUpdateContext: FirmwareUpdateContext | null;\n readonly customImage: CustomImage | null;\n readonly installedApps: InstalledApp[] | null;\n readonly applications: Application[] | null;\n readonly applicationsUpdates: Application[] | null;\n readonly installedLanguages: InstalledLanguagePackage[] | null;\n readonly catalog: Catalog | null;\n};\n\nexport type GetDeviceMetadataFromContextTaskResult = {\n readonly firmwareVersion: FirmwareVersion;\n readonly firmwareUpdateContext: FirmwareUpdateContext;\n readonly customImage: CustomImage;\n readonly applications: Application[];\n readonly applicationsUpdates: Application[];\n readonly installedLanguages: InstalledLanguagePackage[];\n readonly catalog: Catalog;\n} | null;\n\nexport type MachineDependencies = {\n readonly getDeviceMetadata: () => Promise<GetDeviceMetadataFromContextTaskResult>;\n readonly getFirmwareMetadata: () => Promise<GetFirmwareMetadataTaskResult>;\n readonly getApplicationsMetadata: (arg0: {\n input: {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n installedApps: InstalledApp[];\n };\n }) => Promise<GetApplicationsMetadataTaskResult>;\n readonly listAppsSecureChannel: (arg0: {\n input: {\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n };\n }) => Observable<SecureChannelEvent>;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceMetadataDeviceAction extends XStateDeviceAction<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceMetadataDAOutput,\n GetDeviceMetadataDAInput,\n GetDeviceMetadataDAError,\n GetDeviceMetadataDAIntermediateValue,\n GetDeviceMetadataMachineInternalState\n >;\n\n const {\n getDeviceMetadata,\n getFirmwareMetadata,\n getApplicationsMetadata,\n listAppsSecureChannel,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n const goToDashboardMachine = new GoToDashboardDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n const listAppsMachine = new ListAppsDeviceAction({\n input: {\n unlockTimeout,\n },\n }).makeStateMachine(internalApi);\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n goToDashboard: goToDashboardMachine,\n getDeviceMetadata: fromPromise(getDeviceMetadata),\n getFirmwareMetadata: fromPromise(getFirmwareMetadata),\n getApplicationsMetadata: fromPromise(getApplicationsMetadata),\n listApps: listAppsMachine,\n listAppsSecureChannel: fromObservable(listAppsSecureChannel),\n },\n guards: {\n hasError: ({ context }) => context._internalState.error !== null,\n hasMetadata: ({ context }) =>\n context._internalState.firmwareVersion !== null &&\n context._internalState.firmwareUpdateContext !== null &&\n context._internalState.customImage !== null &&\n context._internalState.applications !== null &&\n context._internalState.applicationsUpdates !== null &&\n context._internalState.installedLanguages !== null &&\n context._internalState.catalog !== null,\n forceUpdate: ({ context }) => Boolean(context.input.forceUpdate),\n useSecureChannel: ({ context }) =>\n Boolean(context.input.useSecureChannel),\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: \"GetDeviceMetadataDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n return {\n input: {\n useSecureChannel: _.input.useSecureChannel,\n forceUpdate: _.input.forceUpdate,\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n error: null,\n deviceVersion: null,\n firmware: null,\n firmwareVersion: null,\n firmwareUpdateContext: null,\n customImage: null,\n installedApps: null,\n applications: null,\n applicationsUpdates: null,\n installedLanguages: null,\n catalog: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: [\n {\n target: \"GoToDashboard\",\n guard: \"forceUpdate\",\n },\n {\n target: \"GetDeviceMetadataFromContext\",\n },\n ],\n },\n GetDeviceMetadataFromContext: {\n invoke: {\n src: \"getDeviceMetadata\",\n onDone: {\n target: \"GetDeviceMetadataFromContextResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (_.event.output === null) {\n return _.context._internalState;\n } else {\n return {\n ..._.context._internalState,\n firmwareVersion: _.event.output.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.firmwareUpdateContext,\n customImage: _.event.output.customImage,\n applications: _.event.output.applications,\n applicationsUpdates: _.event.output.applicationsUpdates,\n installedLanguages: _.event.output.installedLanguages,\n catalog: _.event.output.catalog,\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetDeviceMetadataFromContextResultCheck: {\n always: [\n {\n target: \"Success\",\n guard: \"hasMetadata\",\n },\n {\n target: \"GoToDashboard\",\n },\n ],\n },\n GoToDashboard: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"dashboard\",\n src: \"goToDashboard\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"GoToDashboardCheck\",\n actions: assign({\n _internalState: (_) => {\n return _.event.output.caseOf({\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: \"GetFirmwareMetadata\",\n },\n ],\n },\n GetFirmwareMetadata: {\n invoke: {\n src: \"getFirmwareMetadata\",\n onDone: {\n target: \"GetFirmwareMetadataResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n firmwareVersion: _.event.output.data.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.data.firmwareUpdateContext,\n customImage: _.event.output.data.customImage,\n });\n }\n return {\n ..._.context._internalState,\n deviceVersion: _.event.output.data.deviceVersion,\n firmware: _.event.output.data.firmware,\n firmwareVersion: _.event.output.data.firmwareVersion,\n firmwareUpdateContext:\n _.event.output.data.firmwareUpdateContext,\n customImage: _.event.output.data.customImage,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetFirmwareMetadataResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n guard: \"useSecureChannel\",\n target: \"ListAppsSecureChannel\",\n },\n {\n target: \"ListApps\",\n },\n ],\n },\n ListAppsSecureChannel: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"listAppsSecureChannel\",\n src: \"listAppsSecureChannel\",\n input: (_) => ({\n firmware: _.context._internalState.firmware!,\n firmwareVersion: _.context._internalState.firmwareVersion!,\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 default:\n return {\n ..._.context.intermediateValue,\n };\n }\n },\n _internalState: (_) => {\n if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Error\n ) {\n return {\n ..._.context._internalState,\n error: _.event.snapshot.context.error.mapDAErrors(),\n };\n } else if (\n _.event.snapshot.context?.type ===\n SecureChannelEventType.Result\n ) {\n if (\n installedAppResultGuard(_.event.snapshot.context.payload)\n ) {\n return {\n ..._.context._internalState,\n installedApps: _.event.snapshot.context.payload.map(\n (app) => ({\n name: app.name,\n hash: app.hash,\n hashCode: app.hash_code_data,\n }),\n ),\n };\n }\n throw new Error(\n `Invalid result ${JSON.stringify(_.event.snapshot.context.payload)}`,\n );\n }\n return { ..._.context._internalState };\n },\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListApps: {\n exit: assign({\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n }),\n invoke: {\n id: \"listApps\",\n src: \"listApps\",\n input: (_) => ({\n unlockTimeout: _.context.input.unlockTimeout,\n }),\n onSnapshot: {\n actions: assign({\n intermediateValue: (_) =>\n _.event.snapshot.context.intermediateValue,\n }),\n },\n onDone: {\n target: \"ListAppsCheck\",\n actions: assign({\n _internalState: (_) => {\n if (_.event.output.isLeft()) {\n return {\n ..._.context._internalState,\n error: _.event.output.extract(),\n };\n } else {\n return {\n ..._.context._internalState,\n installedApps: _.event.output\n .unsafeCoerce()\n .map((app) => ({\n name: app.appName,\n hash: app.appFullHash,\n hashCode: app.appCodeHash,\n })),\n };\n }\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ListAppsCheck: {\n always: [\n {\n target: \"Error\",\n guard: \"hasError\",\n },\n {\n target: \"GetApplicationsMetadata\",\n },\n ],\n },\n GetApplicationsMetadata: {\n invoke: {\n src: \"getApplicationsMetadata\",\n input: (_) => ({\n deviceVersion: _.context._internalState.deviceVersion!,\n firmware: _.context._internalState.firmware!,\n firmwareVersion: _.context._internalState.firmwareVersion!,\n installedApps: _.context._internalState.installedApps!,\n }),\n onDone: {\n target: \"GetApplicationsMetadataResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n internalApi.setDeviceSessionState({\n ...deviceState,\n installedApps: _.event.output.data.applications,\n appsUpdates: _.event.output.data.applicationsUpdates,\n installedLanguages:\n _.event.output.data.installedLanguages,\n catalog: _.event.output.data.catalog,\n });\n }\n return {\n ..._.context._internalState,\n applications: _.event.output.data.applications,\n applicationsUpdates:\n _.event.output.data.applicationsUpdates,\n installedLanguages:\n _.event.output.data.installedLanguages,\n catalog: _.event.output.data.catalog,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n GetApplicationsMetadataResultCheck: {\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 {\n error,\n firmwareVersion,\n firmwareUpdateContext,\n customImage,\n applications,\n applicationsUpdates,\n installedLanguages,\n catalog,\n } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right({\n firmwareVersion: firmwareVersion!,\n firmwareUpdateContext: firmwareUpdateContext!,\n customImage: customImage!,\n applications: applications!,\n applicationsUpdates: applicationsUpdates!,\n installedLanguages: installedLanguages!,\n catalog: catalog!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getDeviceMetadata = () => {\n const deviceState = internalApi.getDeviceSessionState();\n if (\n deviceState.sessionStateType === DeviceSessionStateType.Connected ||\n deviceState.firmwareVersion?.metadata === undefined ||\n deviceState.firmwareUpdateContext === undefined ||\n deviceState.customImage === undefined ||\n deviceState.installedApps.length === 0 ||\n deviceState.appsUpdates === undefined ||\n deviceState.installedLanguages === undefined ||\n deviceState.catalog === undefined\n ) {\n return Promise.resolve(null);\n }\n return Promise.resolve({\n firmwareVersion: deviceState.firmwareVersion,\n firmwareUpdateContext: deviceState.firmwareUpdateContext,\n customImage: deviceState.customImage,\n applications: deviceState.installedApps,\n applicationsUpdates: deviceState.appsUpdates,\n installedLanguages: deviceState.installedLanguages,\n catalog: deviceState.catalog,\n });\n };\n\n const getFirmwareMetadata = async () =>\n new GetFirmwareMetadataTask(internalApi).run();\n\n const getApplicationsMetadata = async (arg0: {\n input: {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n installedApps: InstalledApp[];\n };\n }) =>\n new GetApplicationsMetadataTask(internalApi, {\n deviceVersion: arg0.input.deviceVersion,\n firmware: arg0.input.firmware,\n firmwareVersion: arg0.input.firmwareVersion,\n installedApps: arg0.input.installedApps,\n }).run();\n\n const listAppsSecureChannel = (arg0: {\n input: {\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n };\n }) => {\n const { firmware, firmwareVersion } = arg0.input;\n const connection = internalApi\n .getSecureChannelService()\n .listInstalledApps(firmwareVersion.metadata!, firmware);\n return new ConnectToSecureChannelTask(internalApi, {\n connection,\n }).run();\n };\n\n return {\n getDeviceMetadata,\n getFirmwareMetadata,\n getApplicationsMetadata,\n listAppsSecureChannel,\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCAEvC,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OAAS,6BAAAC,MAAiC,gEAC1C,OAAS,wBAAAC,MAA4B,sDACrC,OACE,+BAAAC,MAGK,sDACP,OACE,2BAAAC,MAEK,kDAEP,OAEE,sBAAAC,MACK,qDACP,OAGE,0BAAAC,MAIK,yCACP,OAAS,2BAAAC,MAA+B,4DACxC,OAAS,8BAAAC,MAAkC,sDAC3C,OAAS,0BAAAC,MAA8B,iCA4DhC,MAAMC,UAAsCL,CAMjD,CACA,iBACEM,EAOA,CASA,KAAM,CACJ,kBAAAC,EACA,oBAAAC,EACA,wBAAAC,EACA,sBAAAC,CACF,EAAI,KAAK,oBAAoBJ,CAAW,EAElCK,EAAgB,KAAK,MAAM,eAAiBhB,EAE5CiB,EAAuB,IAAIhB,EAA0B,CACzD,MAAO,CACL,cAAAe,CACF,CACF,CAAC,EAAE,iBAAiBL,CAAW,EACzBO,E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uB,QACnCA,EAAY,UAAY,OAEjB,QAAQ,QAAQ,IAAI,EAEtB,QAAQ,QAAQ,CACrB,gBAAiBA,EAAY,gBAC7B,sBAAuBA,EAAY,sBACnC,YAAaA,EAAY,YACzB,aAAcA,EAAY,cAC1B,oBAAqBA,EAAY,YACjC,mBAAoBA,EAAY,mBAChC,QAASA,EAAY,OACvB,CAAC,CACH,EAqCE,oBAnC0B,SAC1B,IAAIlB,EAAwBO,CAAW,EAAE,IAAI,EAmC7C,wBAjC8B,MAAOqB,GAQrC,IAAI7B,EAA4BQ,EAAa,CAC3C,cAAeqB,EAAK,MAAM,cAC1B,SAAUA,EAAK,MAAM,SACrB,gBAAiBA,EAAK,MAAM,gBAC5B,cAAeA,EAAK,MAAM,aAC5B,CAAC,EAAE,IAAI,EAqBP,sBAnB6BA,GAKzB,CACJ,KAAM,CAAE,SAAAC,EAAU,gBAAAR,CAAgB,EAAIO,EAAK,MACrCE,EAAavB,EAChB,wBAAwB,EACxB,kBAAkBc,EAAgB,SAAWQ,CAAQ,EACxD,OAAO,IAAIzB,EAA2BG,EAAa,CACjD,WAAAuB,CACF,CAAC,EAAE,IAAI,CACT,CAOA,CACF,CACF",
|
|
6
6
|
"names": ["Left", "Right", "assign", "fromObservable", "fromPromise", "setup", "isSuccessCommandResult", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "GoToDashboardDeviceAction", "ListAppsDeviceAction", "GetApplicationsMetadataTask", "GetFirmwareMetadataTask", "XStateDeviceAction", "DeviceSessionStateType", "installedAppResultGuard", "ConnectToSecureChannelTask", "SecureChannelEventType", "GetDeviceMetadataDeviceAction", "internalApi", "getDeviceMetadata", "getFirmwareMetadata", "getApplicationsMetadata", "listAppsSecureChannel", "unlockTimeout", "goToDashboardMachine", "listAppsMachine", "context", "_", "error", "deviceState", "app", "args", "firmwareVersion", "firmwareUpdateContext", "customImage", "applications", "applicationsUpdates", "installedLanguages", "catalog", "arg0", "firmware", "connection"]
|
|
7
7
|
}
|
package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Left as h,Right as
|
|
1
|
+
import{Left as h,Right as S}from"purify-ts";import{assign as a,fromObservable as x,fromPromise as I,setup as y}from"xstate";import{UserInteractionRequired as i}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as g}from"../../../device-action/os/Const";import{OutOfMemoryDAError as v}from"../../../device-action/os/Errors";import{GetDeviceMetadataDeviceAction as O}from"../../../device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction";import{GoToDashboardDeviceAction as D}from"../../../device-action/os/GoToDashboard/GoToDashboardDeviceAction";import{BuildAppsInstallPlanTask as f}from"../../../device-action/task/BuildAppsInstallPlanTask";import{PredictOutOfMemoryTask as M}from"../../../device-action/task/PredictOutOfMemoryTask";import{XStateDeviceAction as P}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as A}from"../../../device-session/DeviceSessionState";import{ConnectToSecureChannelTask as E}from"../../../secure-channel/task/ConnectToSecureChannelTask";import{SecureChannelEventType as o}from"../../../secure-channel/task/types";class K extends P{makeStateMachine(t){const{buildInstallPlan:c,predictOutOfMemory:u,installApp:d}=this.extractDependencies(t),r=this.input.unlockTimeout??g,l=new O({input:{unlockTimeout:r,useSecureChannel:!0,forceUpdate:!1}}).makeStateMachine(t),s=new D({input:{unlockTimeout:r}}).makeStateMachine(t);return y({types:{input:{unlockTimeout:r},context:{},output:{}},actors:{updateMetadata:l,buildInstallPlan:I(c),predictOutOfMemory:I(u),goToDashboard:s,installApp:x(d)},guards:{hasError:({context:e})=>e._internalState.error!==null,hasInstallPlan:e=>e.context.intermediateValue.installPlan!==null,hasMoreApps:e=>e.context._internalState.currentIndex<e.context.intermediateValue.installPlan.installPlan.length},actions:{assignErrorFromEvent:a({_internalState:e=>({...e.context._internalState,error:e.event.error})}),nextAppIndex:a({_internalState:e=>({...e.context._internalState,currentIndex:e.context._internalState.currentIndex+1})}),cleanupDeviceState:()=>{const e=t.getDeviceSessionState();e.sessionStateType!==A.Connected&&t.setDeviceSessionState({...e,installedApps:[],appsUpdates:void 0})}}}).createMachine({id:"InstallOrUpdateAppsDeviceAction",initial:"DeviceReady",context:e=>({input:{applications:e.input.applications,allowMissingApplication:e.input.allowMissingApplication,unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:i.None,installPlan:null},_internalState:{error:null,osVersion:null,currentIndex:0}}),states:{DeviceReady:{always:[{target:"UpdateDeviceMetadata"}]},UpdateDeviceMetadata:{exit:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"updateMetadata",src:"updateMetadata",input:e=>({unlockTimeout:e.context.input.unlockTimeout,useSecureChannel:!0,forceUpdate:!1}),onSnapshot:{actions:a({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:"UpdateDeviceMetadataCheck",actions:a({_internalState:e=>e.event.output.caseOf({Right:n=>({...e.context._internalState,osVersion:n.firmwareVersion.metadata}),Left:n=>({...e.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},UpdateDeviceMetadataCheck:{always:[{target:"Error",guard:"hasError"},{target:"Success",guard:"hasInstallPlan"},{target:"BuildInstallPlan"}]},BuildInstallPlan:{invoke:{src:"buildInstallPlan",input:e=>({applications:e.context.input.applications,allowMissingApplication:e.context.input.allowMissingApplication}),onDone:{target:"BuildInstallPlanCheck",actions:a({_internalState:e=>"error"in e.event.output?{...e.context._internalState,error:e.event.output.error}:e.context._internalState,intermediateValue:e=>"error"in e.event.output?e.context.intermediateValue:{...e.context.intermediateValue,installPlan:{installPlan:e.event.output.installPlan,alreadyInstalled:e.event.output.alreadyInstalled,missingApplications:e.event.output.missingApplications,currentIndex:0,currentProgress:0}}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},BuildInstallPlanCheck:{always:[{guard:"hasError",target:"Error"},{target:"PredictOutOfMemory",guard:"hasMoreApps"},{target:"Success"}]},PredictOutOfMemory:{invoke:{src:"predictOutOfMemory",input:e=>({installPlan:e.context.intermediateValue.installPlan.installPlan}),onDone:{target:"PredictOutOfMemoryCheck",actions:a({_internalState:e=>"error"in e.event.output?{...e.context._internalState,error:e.event.output.error}:e.event.output.outOfMemory?{...e.context._internalState,error:new v("Not enough memory for those applications")}:e.context._internalState})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},PredictOutOfMemoryCheck:{always:[{guard:"hasError",target:"Error"},{target:"GoToDashboard"}]},GoToDashboard:{invoke:{id:"goToDashboard",src:"goToDashboard",input:e=>({unlockTimeout:e.context.input.unlockTimeout}),onSnapshot:{actions:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:e.event.snapshot.context.intermediateValue.requiredUserInteraction})})},onDone:{target:"GoToDashboardCheck",actions:a({_internalState:e=>e.event.output.caseOf({Right:()=>e.context._internalState,Left:n=>({...e.context._internalState,error:n})})})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},GoToDashboardCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",actions:"cleanupDeviceState"}]},InstallApp:{exit:a({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:i.None})}),invoke:{id:"installApp",src:"installApp",input:e=>({osVersion:e.context._internalState.osVersion,application:e.context.intermediateValue.installPlan.installPlan[e.context._internalState.currentIndex]}),onSnapshot:{actions:a({intermediateValue:e=>{switch(e.event.snapshot.context?.type){case o.DeviceId:return{...e.context.intermediateValue,deviceId:e.event.snapshot.context.payload.deviceId};case o.PermissionRequested:return{...e.context.intermediateValue,requiredUserInteraction:i.AllowSecureConnection};case o.PermissionGranted:{const n=t.getDeviceSessionState();return n.sessionStateType!==A.Connected&&t.setDeviceSessionState({...n,isSecureConnectionAllowed:!0}),{...e.context.intermediateValue,requiredUserInteraction:i.None}}case o.Progress:return{...e.context.intermediateValue,installPlan:{...e.context.intermediateValue.installPlan,currentIndex:e.context._internalState.currentIndex,currentProgress:e.event.snapshot.context.payload.progress}};default:return e.context.intermediateValue}},_internalState:e=>e.event.snapshot.context?.type===o.Error?{...e.context._internalState,error:e.event.snapshot.context.error.mapInstallDAErrors()}:e.context._internalState})},onDone:{target:"InstallAppCheck",actions:"nextAppIndex"},onError:{target:"Error",actions:"assignErrorFromEvent"}}},InstallAppCheck:{always:[{target:"Error",guard:"hasError"},{target:"InstallApp",guard:"hasMoreApps"},{target:"UpdateDeviceMetadata"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:n}=e,{error:m}=n._internalState,{installPlan:p}=n.intermediateValue;return m?h(m):S({successfullyInstalled:p.installPlan,alreadyInstalled:p.alreadyInstalled,missingApplications:p.missingApplications})}})}extractDependencies(t){return{buildInstallPlan:r=>Promise.resolve(new f(t,{applications:r.input.applications,allowMissingApplication:r.input.allowMissingApplication}).run()),predictOutOfMemory:r=>Promise.resolve(new M(t,{installPlan:r.input.installPlan}).run()),installApp:r=>{const{osVersion:l,application:s}=r.input,e=t.getSecureChannelService().installApp(l,s);return new E(t,{connection:e}).run()}}}}export{K as InstallOrUpdateAppsDeviceAction};
|
|
2
2
|
//# sourceMappingURL=InstallOrUpdateAppsDeviceAction.js.map
|
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 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 = 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,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,EAEzBM,EAAuB,IAAId,EAA0B,CACzD,MAAO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EAAE,QAAQ,eAAe,aACvC,gBACEA,EAAE,MAAM,SAAS,QAAQ,QAAQ,QACrC,CACF,EAEF,QACE,OAAOA,EAAE,QAAQ,iBACrB,CACF,EACA,eAAiBA,GAEbA,EAAE,MAAM,SAAS,SAAS,OAC1BV,EAAuB,MAEhB,CACL,GAAGU,EAAE,QAAQ,eACb,MACEA,EAAE,MAAM,SAAS,QAAQ,MAAM,mBAAmB,CACtD,EAEKA,EAAE,QAAQ,cAErB,CAAC,CACH,EACA,OAAQ,CACN,OAAQ,kBACR,QAAS,cACX,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,gBAAiB,CACf,OAAQ,CACN,CACE,OAAQ,QACR,MAAO,UACT,EACA,CACE,OAAQ,aACR,MAAO,aACT,EACA,CACE,OAAQ,sBACV,CACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASK,GAAS,CAChB,KAAM,CAAE,QAAAN,CAAQ,EAAIM,EACd,CAAE,MAAAF,CAAM,EAAIJ,EAAQ,eACpB,CAAE,YAAAO,CAAY,EAAIP,EAAQ,kBAChC,OAAII,EACK7B,EAAK6B,CAAK,EAEZ5B,EAAM,CACX,sBAAuB+B,EAAa,YACpC,iBAAkBA,EAAa,iBAC/B,oBAAqBA,EAAa,mBACpC,CAAC,CACH,CACF,CAAC,CACH,CAEA,oBAAoBd,EAA+C,
|
|
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,EAEzBM,EAAuB,IAAId,EAA0B,CACzD,MAAO,CACL,cAAAY,CACF,CACF,CAAC,EAAE,iBAAiBJ,CAAW,EAE/B,OAAOb,EAAM,CACX,MAAO,CACL,MAAO,CACL,cAAAiB,CACF,EACA,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ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
|
"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{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,MAAM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ACd,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
|