@ledgerhq/device-management-kit 1.0.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -28
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.js.map +2 -2
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/cjs/src/api/command/os/GetBackgroundImageSizeCommand.js +2 -0
- package/lib/cjs/src/api/command/os/GetBackgroundImageSizeCommand.js.map +7 -0
- package/lib/cjs/src/api/command/os/GetBackgroundImageSizeCommand.test.js +2 -0
- package/lib/cjs/src/api/command/os/GetBackgroundImageSizeCommand.test.js.map +7 -0
- package/lib/cjs/src/api/device-action/DeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/DeviceAction.js.map +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/cjs/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js +1 -1
- package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -1
- package/lib/cjs/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceMetadata/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GetDeviceStatus/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/GoToDashboard/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +2 -2
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/InstallOrUpdateApps/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListApps/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListApps/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppDeviceAction/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -1
- package/lib/cjs/src/api/device-action/os/OpenAppWithDependencies/types.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -1
- package/lib/cjs/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +3 -3
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/index.js +1 -1
- package/lib/cjs/src/api/index.js.map +3 -3
- package/lib/cjs/src/api/logger-publisher/utils/noopLoggerFactory.js +2 -0
- package/lib/cjs/src/api/logger-publisher/utils/noopLoggerFactory.js.map +7 -0
- package/lib/cjs/src/api/logger-publisher/utils/noopLoggerFactory.test.js +2 -0
- package/lib/cjs/src/api/logger-publisher/utils/noopLoggerFactory.test.js.map +7 -0
- package/lib/cjs/src/api/logger-subscriber/service/WebLogsExporterLogger.test.js +1 -1
- package/lib/cjs/src/api/logger-subscriber/service/WebLogsExporterLogger.test.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js +1 -1
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +3 -3
- package/lib/cjs/src/api/transport/model/Errors.js +1 -1
- package/lib/cjs/src/api/transport/model/Errors.js.map +3 -3
- package/lib/cjs/src/api/types.js +1 -1
- package/lib/cjs/src/api/types.js.map +1 -1
- package/lib/cjs/src/api/utils/ApplicationChecker.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.js.map +7 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/cjs/src/api/utils/ApplicationResolver.js +2 -0
- package/lib/cjs/src/api/utils/ApplicationResolver.js.map +7 -0
- package/lib/cjs/src/api/utils/Base64String.js +1 -1
- package/lib/cjs/src/api/utils/Base64String.js.map +3 -3
- package/lib/cjs/src/api/utils/Base64String.test.js +1 -1
- package/lib/cjs/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js +1 -1
- package/lib/cjs/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
- package/lib/cjs/src/internal/device-session/di/deviceSessionTypes.js +1 -1
- package/lib/cjs/src/internal/device-session/di/deviceSessionTypes.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DevicePinger.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DevicePinger.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DevicePinger.test.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DevicePinger.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +3 -3
- package/lib/cjs/src/internal/device-session/model/DeviceSession.test.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSession.test.js.map +3 -3
- package/lib/cjs/src/internal/device-session/model/DeviceSessionEventDispatcher.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionEventDispatcher.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.js.map +3 -3
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/model/DeviceSessionStateHandler.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionStateHandler.js.map +3 -3
- package/lib/cjs/src/internal/device-session/model/DeviceSessionStateHandler.test.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionStateHandler.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/service/IntentQueueService.js +2 -0
- package/lib/cjs/src/internal/device-session/service/IntentQueueService.js.map +7 -0
- package/lib/cjs/src/internal/device-session/service/IntentQueueService.test.js +2 -0
- package/lib/cjs/src/internal/device-session/service/IntentQueueService.test.js.map +7 -0
- package/lib/cjs/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.js +2 -0
- package/lib/cjs/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.js.map +7 -0
- package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ConnectUseCase.test.js.map +3 -3
- package/lib/cjs/src/internal/send/use-case/SendApduUseCase.test.js +1 -1
- package/lib/cjs/src/internal/send/use-case/SendApduUseCase.test.js.map +3 -3
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/DeviceManagementKit.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.js.map +2 -2
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/esm/src/api/command/os/GetBackgroundImageSizeCommand.js +2 -0
- package/lib/esm/src/api/command/os/GetBackgroundImageSizeCommand.js.map +7 -0
- package/lib/esm/src/api/command/os/GetBackgroundImageSizeCommand.test.js +2 -0
- package/lib/esm/src/api/command/os/GetBackgroundImageSizeCommand.test.js.map +7 -0
- package/lib/esm/src/api/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/src/api/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js +1 -1
- package/lib/esm/src/api/device-action/__test-utils__/setupTestMachine.js.map +3 -3
- package/lib/esm/src/api/device-action/model/UserInteractionRequired.js +1 -1
- package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +2 -2
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js +1 -0
- package/lib/esm/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GetDeviceMetadata/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GetDeviceStatus/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/GoToDashboard/types.js +1 -0
- package/lib/esm/src/api/device-action/os/GoToDashboard/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js +1 -0
- package/lib/esm/src/api/device-action/os/InstallOrUpdateApps/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/ListApps/ListAppsDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListApps/types.js +1 -0
- package/lib/esm/src/api/device-action/os/ListApps/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js +1 -0
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js +1 -0
- package/lib/esm/src/api/device-action/os/OpenAppDeviceAction/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js +1 -0
- package/lib/esm/src/api/device-action/os/OpenAppWithDependencies/types.js.map +4 -4
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.js.map +3 -3
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js +1 -1
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.test.js.map +3 -3
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js +1 -0
- package/lib/esm/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.js.map +4 -4
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +3 -3
- package/lib/esm/src/api/index.js +1 -1
- package/lib/esm/src/api/index.js.map +3 -3
- package/lib/esm/src/api/logger-publisher/utils/noopLoggerFactory.js +2 -0
- package/lib/esm/src/api/logger-publisher/utils/noopLoggerFactory.js.map +7 -0
- package/lib/esm/src/api/logger-publisher/utils/noopLoggerFactory.test.js +2 -0
- package/lib/esm/src/api/logger-publisher/utils/noopLoggerFactory.test.js.map +7 -0
- package/lib/esm/src/api/logger-subscriber/service/WebLogsExporterLogger.test.js +1 -1
- package/lib/esm/src/api/logger-subscriber/service/WebLogsExporterLogger.test.js.map +3 -3
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js.map +3 -3
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js +1 -1
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.test.js.map +3 -3
- package/lib/esm/src/api/transport/model/Errors.js +1 -1
- package/lib/esm/src/api/transport/model/Errors.js.map +3 -3
- package/lib/esm/src/api/utils/ApplicationChecker.js +2 -0
- package/lib/esm/src/api/utils/ApplicationChecker.js.map +7 -0
- package/lib/esm/src/api/utils/ApplicationChecker.test.js +2 -0
- package/lib/esm/src/api/utils/ApplicationChecker.test.js.map +7 -0
- package/lib/esm/src/api/utils/ApplicationResolver.js +1 -0
- package/lib/esm/src/api/utils/ApplicationResolver.js.map +7 -0
- package/lib/esm/src/api/utils/Base64String.js +1 -1
- package/lib/esm/src/api/utils/Base64String.js.map +3 -3
- package/lib/esm/src/api/utils/Base64String.test.js +1 -1
- package/lib/esm/src/api/utils/Base64String.test.js.map +3 -3
- package/lib/esm/src/internal/device-session/di/deviceSessionModule.js +1 -1
- package/lib/esm/src/internal/device-session/di/deviceSessionModule.js.map +3 -3
- package/lib/esm/src/internal/device-session/di/deviceSessionTypes.js +1 -1
- package/lib/esm/src/internal/device-session/di/deviceSessionTypes.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DevicePinger.js +1 -1
- package/lib/esm/src/internal/device-session/model/DevicePinger.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DevicePinger.test.js +1 -1
- package/lib/esm/src/internal/device-session/model/DevicePinger.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSession.test.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSession.test.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSessionEventDispatcher.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionEventDispatcher.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionRefresher.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.test.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/service/IntentQueueService.js +2 -0
- package/lib/esm/src/internal/device-session/service/IntentQueueService.js.map +7 -0
- package/lib/esm/src/internal/device-session/service/IntentQueueService.test.js +2 -0
- package/lib/esm/src/internal/device-session/service/IntentQueueService.test.js.map +7 -0
- package/lib/esm/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.js +2 -0
- package/lib/esm/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.js.map +7 -0
- package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ConnectUseCase.test.js.map +3 -3
- package/lib/esm/src/internal/send/use-case/SendApduUseCase.test.js +1 -1
- package/lib/esm/src/internal/send/use-case/SendApduUseCase.test.js.map +3 -3
- package/lib/types/src/api/DeviceManagementKit.d.ts +10 -0
- package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts +7 -0
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
- package/lib/types/src/api/command/os/GetBackgroundImageSizeCommand.d.ts +17 -0
- package/lib/types/src/api/command/os/GetBackgroundImageSizeCommand.d.ts.map +1 -0
- package/lib/types/src/api/command/os/GetBackgroundImageSizeCommand.test.d.ts +2 -0
- package/lib/types/src/api/command/os/GetBackgroundImageSizeCommand.test.d.ts.map +1 -0
- package/lib/types/src/api/device-action/DeviceAction.d.ts +2 -1
- package/lib/types/src/api/device-action/DeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
- package/lib/types/src/api/device-action/__test-utils__/setupTestMachine.d.ts.map +1 -1
- package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +4 -1
- package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts +9 -1
- package/lib/types/src/api/device-action/os/CallTaskInAppDeviceAction/CallTaskInAppDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/GetDeviceMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts +13 -2
- package/lib/types/src/api/device-action/os/GetDeviceMetadata/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts +6 -0
- package/lib/types/src/api/device-action/os/GetDeviceStatus/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/GoToDashboardDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts +9 -1
- package/lib/types/src/api/device-action/os/GoToDashboard/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/InstallOrUpdateAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts +9 -1
- package/lib/types/src/api/device-action/os/InstallOrUpdateApps/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListApps/ListAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListApps/types.d.ts +6 -0
- package/lib/types/src/api/device-action/os/ListApps/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts +8 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/OpenAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts +12 -2
- package/lib/types/src/api/device-action/os/OpenAppDeviceAction/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/OpenAppWithDependenciesDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts +8 -0
- package/lib/types/src/api/device-action/os/OpenAppWithDependencies/types.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts +9 -1
- package/lib/types/src/api/device-action/os/SendCommandInAppDeviceAction/SendCommandInAppDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts +10 -1
- package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/index.d.ts +11 -4
- package/lib/types/src/api/index.d.ts.map +1 -1
- package/lib/types/src/api/logger-publisher/utils/noopLoggerFactory.d.ts +12 -0
- package/lib/types/src/api/logger-publisher/utils/noopLoggerFactory.d.ts.map +1 -0
- package/lib/types/src/api/logger-publisher/utils/noopLoggerFactory.test.d.ts +2 -0
- package/lib/types/src/api/logger-publisher/utils/noopLoggerFactory.test.d.ts.map +1 -0
- package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts +1 -0
- package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/Errors.d.ts +5 -0
- package/lib/types/src/api/transport/model/Errors.d.ts.map +1 -1
- package/lib/types/src/api/types.d.ts +1 -0
- package/lib/types/src/api/types.d.ts.map +1 -1
- package/lib/types/src/api/utils/ApplicationChecker.d.ts +14 -0
- package/lib/types/src/api/utils/ApplicationChecker.d.ts.map +1 -0
- package/lib/types/src/api/utils/ApplicationChecker.test.d.ts +2 -0
- package/lib/types/src/api/utils/ApplicationChecker.test.d.ts.map +1 -0
- package/lib/types/src/api/utils/ApplicationResolver.d.ts +12 -0
- package/lib/types/src/api/utils/ApplicationResolver.d.ts.map +1 -0
- package/lib/types/src/api/utils/Base64String.d.ts +1 -0
- package/lib/types/src/api/utils/Base64String.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/di/deviceSessionModule.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/di/deviceSessionTypes.d.ts +1 -0
- package/lib/types/src/internal/device-session/di/deviceSessionTypes.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts +13 -2
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionEventDispatcher.d.ts +3 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionEventDispatcher.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionRefresher.d.ts +0 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionRefresher.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSessionStateHandler.d.ts +1 -0
- package/lib/types/src/internal/device-session/model/DeviceSessionStateHandler.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/service/IntentQueueService.d.ts +101 -0
- package/lib/types/src/internal/device-session/service/IntentQueueService.d.ts.map +1 -0
- package/lib/types/src/internal/device-session/service/IntentQueueService.test.d.ts +2 -0
- package/lib/types/src/internal/device-session/service/IntentQueueService.test.d.ts.map +1 -0
- package/lib/types/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.d.ts +19 -0
- package/lib/types/src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.js +0 -2
- package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.js.map +0 -7
- package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.test.js +0 -2
- package/lib/cjs/src/api/command/os/GetCustomImageSizeCommand.test.js.map +0 -7
- package/lib/cjs/src/internal/device-session/service/MutexService.js +0 -2
- package/lib/cjs/src/internal/device-session/service/MutexService.js.map +0 -7
- package/lib/cjs/src/internal/device-session/service/MutexService.test.js +0 -2
- package/lib/cjs/src/internal/device-session/service/MutexService.test.js.map +0 -7
- package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.js +0 -2
- package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.js.map +0 -7
- package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.test.js +0 -2
- package/lib/esm/src/api/command/os/GetCustomImageSizeCommand.test.js.map +0 -7
- package/lib/esm/src/internal/device-session/service/MutexService.js +0 -2
- package/lib/esm/src/internal/device-session/service/MutexService.js.map +0 -7
- package/lib/esm/src/internal/device-session/service/MutexService.test.js +0 -2
- package/lib/esm/src/internal/device-session/service/MutexService.test.js.map +0 -7
- package/lib/types/src/api/command/os/GetCustomImageSizeCommand.d.ts +0 -17
- package/lib/types/src/api/command/os/GetCustomImageSizeCommand.d.ts.map +0 -1
- package/lib/types/src/api/command/os/GetCustomImageSizeCommand.test.d.ts +0 -2
- package/lib/types/src/api/command/os/GetCustomImageSizeCommand.test.d.ts.map +0 -1
- package/lib/types/src/internal/device-session/service/MutexService.d.ts +0 -6
- package/lib/types/src/internal/device-session/service/MutexService.d.ts.map +0 -1
- package/lib/types/src/internal/device-session/service/MutexService.test.d.ts +0 -2
- package/lib/types/src/internal/device-session/service/MutexService.test.d.ts.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=require("purify-ts"),r=require("rxjs"),m=require("rxjs/operators"),D=require("../../../api/command/model/CommandResult"),S=require("../../../api/device/DeviceStatus"),y=require("../../../api/device-session/DeviceSessionState"),C=require("../../../api/transport/model/TransportConnectedDevice.stub"),g=require("../../logger-publisher/service/DefaultLoggerPublisherService"),v=require("./DeviceSession");describe("DeviceSession",()=>{let e,k,u,d,l,o,p,b;const a=(0,C.connectedDeviceStubBuilder)();beforeEach(()=>{k=new g.DefaultLoggerPublisherService([],"device-session-test"),u=vi.fn(()=>k),d={getAppList:vi.fn(),getAppsByHash:vi.fn(),getCurrentFirmware:vi.fn(),getLatestFirmware:vi.fn()},l={genuineCheck:vi.fn(),listInstalledApps:vi.fn(),updateMcu:vi.fn(),updateFirmware:vi.fn(),installApp:vi.fn(),uninstallApp:vi.fn()},o={enqueue:vi.fn().mockReturnValue({observable:(0,r.of)(null).pipe((0,m.delay)(1)),cancel:vi.fn()})},p=()=>o,b={isRefresherDisabled:!0}}),afterEach(()=>{e?.close(),vi.restoreAllMocks()}),describe("constructor",()=>{it("should create a device session with default id",()=>{e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p),expect(e).toBeDefined(),expect(e.id).toBeDefined(),expect(e.connectedDevice).toBe(a)}),it("should create a device session with custom id",()=>{const t="custom-session-id";e=new v.DeviceSession({connectedDevice:a,id:t},u,d,l,b,p),expect(e.id).toBe(t)})}),describe("initialiseSession",()=>{it("should successfully initialize session",()=>{e=new v.DeviceSession({connectedDevice:a},u,d,l,{isRefresherDisabled:!1,pollingInterval:1e3},p);const t=vi.spyOn(e._deviceSessionRefresher,"startRefresher");e.initialiseSession(),expect(t).toHaveBeenCalled()})}),describe("getters",()=>{beforeEach(()=>{e=new v.DeviceSession({connectedDevice:a,id:"test-id"},u,d,l,b,p)}),it("should return session id",()=>{expect(e.id).toBe("test-id")}),it("should return connected device",()=>{expect(e.connectedDevice).toBe(a)}),it("should return state as observable",async()=>{const t=e.state;await new Promise(c=>{t.pipe((0,m.take)(1)).subscribe(n=>{expect(n.sessionStateType).toBe(y.DeviceSessionStateType.Connected),expect(n.deviceStatus).toBe(S.DeviceStatus.CONNECTED),c()})})})}),describe("getDeviceSessionState and setDeviceSessionState",()=>{beforeEach(()=>{e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p)}),it("should get current device session state",()=>{const t=e.getDeviceSessionState();expect(t.sessionStateType).toBe(y.DeviceSessionStateType.Connected),expect(t.deviceStatus).toBe(S.DeviceStatus.CONNECTED)}),it("should set device session state",async()=>{const t={sessionStateType:y.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:S.DeviceStatus.LOCKED,deviceModelId:a.deviceModel.id,currentApp:{name:"Test",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:!1};await new Promise(c=>{let n=!1;const s=e.state.subscribe(i=>{i.sessionStateType===y.DeviceSessionStateType.ReadyWithoutSecureChannel?(expect(i).toMatchObject({sessionStateType:y.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:S.DeviceStatus.LOCKED,deviceModelId:a.deviceModel.id}),s.unsubscribe(),c()):n||(n=!0)});e.setDeviceSessionState(t)})})}),describe("sendApdu",()=>{let t,c;beforeEach(()=>{t=new Uint8Array([224,1,0,0]),c={data:new Uint8Array([1,2]),statusCode:new Uint8Array([144,0])},e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p)}),it("should successfully send APDU",async()=>{const n=(0,r.of)((0,h.Right)(c)).pipe((0,m.delay)(1));o.enqueue.mockReturnValue({observable:n,cancel:vi.fn()});const s=await e.sendApdu(t);expect(o.enqueue).toHaveBeenCalledWith({type:"send-apdu",execute:expect.any(Function)}),expect(s.isRight()).toBe(!0),s.ifRight(i=>{expect(i).toEqual(c)})}),it("should handle APDU send error",async()=>{const n={_tag:"SendApduError"},s=(0,r.of)((0,h.Left)(n)).pipe((0,m.delay)(1));o.enqueue.mockReturnValue({observable:s,cancel:vi.fn()});const i=await e.sendApdu(t);expect(i.isLeft()).toBe(!0),i.ifLeft(f=>{expect(f).toEqual(n)})}),it("should handle APDU timeout",async()=>{const n=vi.fn(),s=new r.Subject;o.enqueue.mockReturnValue({observable:s.asObservable(),cancel:n}),vi.useFakeTimers();const i=e.sendApdu(t,{abortTimeout:1e3});vi.advanceTimersByTime(1100);let f;try{await i}catch(x){f=x}vi.useRealTimers(),expect(f).toBeDefined(),expect(o.enqueue).toHaveBeenCalled()})}),describe("sendCommand",()=>{let t,c;beforeEach(()=>{c={status:D.CommandResultStatus.Success,data:{test:"data"}},t={getApdu:vi.fn().mockReturnValue({getRawApdu:()=>new Uint8Array([224,1,0,0])}),parseResponse:vi.fn().mockReturnValue(c),triggersDisconnection:!1},e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p)}),it("should successfully send command",async()=>{const n=(0,r.of)(c).pipe((0,m.delay)(1));o.enqueue.mockReturnValue({observable:n,cancel:vi.fn()});const s=await e.sendCommand(t);expect(o.enqueue).toHaveBeenCalledWith({type:"send-command",execute:expect.any(Function)}),expect(s).toEqual(c)}),it("should handle command timeout",async()=>{const n=vi.fn(),s=new r.Subject;o.enqueue.mockReturnValue({observable:s.asObservable(),cancel:n}),vi.useFakeTimers();const i=e.sendCommand(t,1e3);vi.advanceTimersByTime(1100);try{await i}catch{}vi.useRealTimers(),expect(o.enqueue).toHaveBeenCalled()}),it("should handle command error",async()=>{const n=new Error("Command failed"),s=(0,r.throwError)(()=>n);o.enqueue.mockReturnValue({observable:s,cancel:vi.fn()}),await expect(e.sendCommand(t)).rejects.toThrow("Command failed")})}),describe("executeDeviceAction",()=>{let t;beforeEach(()=>{const c=(0,r.of)({intermediateValue:"test",requiredUserInteraction:"SignTransaction"}).pipe((0,m.delay)(1));t={_execute:vi.fn().mockReturnValue({observable:c})},e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p)}),it("should execute device action",async()=>{const c=(0,r.of)({intermediateValue:"test",requiredUserInteraction:"SignTransaction"}).pipe((0,m.delay)(1)),n=vi.fn();o.enqueue.mockReturnValue({observable:c,cancel:n});const{observable:s,cancel:i}=e.executeDeviceAction(t);expect(o.enqueue).toHaveBeenCalledWith({type:"device-action",execute:expect.any(Function)}),expect(s).toBeDefined(),expect(i).toBeTypeOf("function");const f=[];await new Promise(x=>{s.subscribe({next:A=>f.push(A),complete:()=>x()})}),expect(f).toEqual([{intermediateValue:"test",requiredUserInteraction:"SignTransaction"}]),i(),expect(n).toHaveBeenCalled()}),it("should provide correct internal API to device action",()=>{const c=(0,r.of)({intermediateValue:"test",requiredUserInteraction:"SignTransaction"}).pipe((0,m.delay)(1));o.enqueue.mockImplementation(n=>(n.execute(),{observable:c,cancel:vi.fn()})),e.executeDeviceAction(t),expect(t._execute).toHaveBeenCalledWith({sendApdu:expect.any(Function),sendCommand:expect.any(Function),getDeviceModel:expect.any(Function),getDeviceSessionState:expect.any(Function),getDeviceSessionStateObservable:expect.any(Function),setDeviceSessionState:expect.any(Function),getManagerApiService:expect.any(Function),getSecureChannelService:expect.any(Function),loggerFactory:expect.any(Function)})}),it("should allow cancelling device action",()=>{const c=vi.fn(),n=new r.Subject;o.enqueue.mockReturnValue({observable:n.asObservable(),cancel:c});const{cancel:s}=e.executeDeviceAction(t);s(),expect(c).toHaveBeenCalled()})}),describe("close",()=>{it("should close the session and update device status",()=>{e=new v.DeviceSession({connectedDevice:a},u,d,l,b,p);let t=!1;e.state.subscribe({complete:()=>{t=!0}}),e.close();const c=e.getDeviceSessionState();expect(c.deviceStatus).toBe(S.DeviceStatus.NOT_CONNECTED),expect(t).toBe(!0)})})});
|
|
2
2
|
//# sourceMappingURL=DeviceSession.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSession.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type DmkConfig } from \"@api/DmkConfig\";\nimport { connectedDeviceStubBuilder } from \"@api/index\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { AxiosManagerApiDataSource } from \"@internal/manager-api/data/AxiosManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\n\nimport { DeviceSession } from \"./DeviceSession\";\n\ndescribe(\"DeviceSession\", () => {\n it(\"should unsubscribe pinger from event subscriber when session is closed\", () => {\n // ARRANGE\n const logger = new DefaultLoggerPublisherService([], \"DeviceSession\");\n const managerApiDataSource = new AxiosManagerApiDataSource({} as DmkConfig);\n const managerApi = new DefaultManagerApiService(managerApiDataSource);\n const secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n const secureChannel = new DefaultSecureChannelService(\n secureChannelDataSource,\n );\n const deviceSessionRefresherOptions =\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS;\n const deviceSession = new DeviceSession(\n { connectedDevice: connectedDeviceStubBuilder() },\n () => logger,\n managerApi,\n secureChannel,\n deviceSessionRefresherOptions,\n );\n const unsubscribe = vi\n .spyOn(deviceSession[\"_pinger\"], \"unsubscribe\")\n .mockImplementation(() => {});\n\n // ACT\n deviceSession.close();\n\n // ASSERT\n expect(unsubscribe).toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
-
"mappings": "aACA,IAAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport { Left, Right } from \"purify-ts\";\nimport { of, Subject, throwError } from \"rxjs\";\nimport { delay, take } from \"rxjs/operators\";\nimport { type Mocked } from \"vitest\";\n\nimport { type Command } from \"@api/command/Command\";\nimport {\n type CommandResult,\n CommandResultStatus,\n} from \"@api/command/model/CommandResult\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type DeviceAction } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport { DeviceSessionStateType } from \"@api/device-session/DeviceSessionState\";\nimport { type DmkError } from \"@api/Error\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport { type IntentQueueService } from \"@internal/device-session/service/IntentQueueService\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport {\n DeviceSession,\n type DeviceSessionRefresherOptions,\n} from \"./DeviceSession\";\n\ndescribe(\"DeviceSession\", () => {\n let deviceSession: DeviceSession;\n let mockLogger: LoggerPublisherService;\n let mockLoggerFactory: ReturnType<typeof vi.fn>;\n let mockManagerApi: Mocked<ManagerApiService>;\n let mockSecureChannel: Mocked<SecureChannelService>;\n let mockIntentQueueService: Mocked<IntentQueueService>;\n let mockIntentQueueServiceFactory: () => IntentQueueService;\n let refresherOptions: DeviceSessionRefresherOptions;\n const mockConnectedDevice = connectedDeviceStubBuilder();\n\n beforeEach(() => {\n // Setup logger\n mockLogger = new DefaultLoggerPublisherService([], \"device-session-test\");\n mockLoggerFactory = vi.fn(() => mockLogger);\n\n // Setup mocks\n mockManagerApi = {\n getAppList: vi.fn(),\n getAppsByHash: vi.fn(),\n getCurrentFirmware: vi.fn(),\n getLatestFirmware: vi.fn(),\n } as unknown as Mocked<ManagerApiService>;\n\n mockSecureChannel = {\n genuineCheck: vi.fn(),\n listInstalledApps: vi.fn(),\n updateMcu: vi.fn(),\n updateFirmware: vi.fn(),\n installApp: vi.fn(),\n uninstallApp: vi.fn(),\n } as unknown as Mocked<SecureChannelService>;\n\n // Setup intent queue service with default mock\n mockIntentQueueService = {\n enqueue: vi.fn().mockReturnValue({\n observable: of(null).pipe(delay(1)),\n cancel: vi.fn(),\n }),\n } as unknown as Mocked<IntentQueueService>;\n\n mockIntentQueueServiceFactory = () => mockIntentQueueService;\n\n refresherOptions = {\n isRefresherDisabled: true,\n };\n });\n\n afterEach(() => {\n deviceSession?.close();\n vi.restoreAllMocks();\n });\n\n describe(\"constructor\", () => {\n it(\"should create a device session with default id\", () => {\n // when\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n\n // then\n expect(deviceSession).toBeDefined();\n expect(deviceSession.id).toBeDefined();\n expect(deviceSession.connectedDevice).toBe(mockConnectedDevice);\n });\n\n it(\"should create a device session with custom id\", () => {\n // given\n const customId = \"custom-session-id\";\n\n // when\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice, id: customId },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n\n // then\n expect(deviceSession.id).toBe(customId);\n });\n });\n\n describe(\"initialiseSession\", () => {\n it(\"should successfully initialize session\", () => {\n // given\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n { isRefresherDisabled: false, pollingInterval: 1000 },\n mockIntentQueueServiceFactory,\n );\n\n const mockRefresherStartSpy = vi.spyOn(\n deviceSession[\"_deviceSessionRefresher\"],\n \"startRefresher\",\n );\n\n // when\n deviceSession.initialiseSession();\n\n // then\n expect(mockRefresherStartSpy).toHaveBeenCalled();\n });\n });\n\n describe(\"getters\", () => {\n beforeEach(() => {\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice, id: \"test-id\" },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n });\n\n it(\"should return session id\", () => {\n expect(deviceSession.id).toBe(\"test-id\");\n });\n\n it(\"should return connected device\", () => {\n expect(deviceSession.connectedDevice).toBe(mockConnectedDevice);\n });\n\n it(\"should return state as observable\", async () => {\n const stateObservable = deviceSession.state;\n\n await new Promise<void>((resolve) => {\n stateObservable.pipe(take(1)).subscribe((state) => {\n expect(state.sessionStateType).toBe(DeviceSessionStateType.Connected);\n expect(state.deviceStatus).toBe(DeviceStatus.CONNECTED);\n resolve();\n });\n });\n });\n });\n\n describe(\"getDeviceSessionState and setDeviceSessionState\", () => {\n beforeEach(() => {\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n });\n\n it(\"should get current device session state\", () => {\n // when\n const state = deviceSession.getDeviceSessionState();\n\n // then\n expect(state.sessionStateType).toBe(DeviceSessionStateType.Connected);\n expect(state.deviceStatus).toBe(DeviceStatus.CONNECTED);\n });\n\n it(\"should set device session state\", async () => {\n // given\n const newState = {\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n deviceModelId: mockConnectedDevice.deviceModel.id,\n currentApp: { name: \"Test\", version: \"1.0.0\" },\n installedApps: [],\n isSecureConnectionAllowed: false,\n };\n\n // when\n await new Promise<void>((resolve) => {\n let subscriptionStarted = false;\n const subscription = deviceSession.state.subscribe((state) => {\n if (\n state.sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ) {\n expect(state).toMatchObject({\n sessionStateType:\n DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.LOCKED,\n deviceModelId: mockConnectedDevice.deviceModel.id,\n });\n subscription.unsubscribe();\n resolve();\n } else if (!subscriptionStarted) {\n subscriptionStarted = true;\n }\n });\n\n deviceSession.setDeviceSessionState(newState);\n });\n });\n });\n\n describe(\"sendApdu\", () => {\n let mockApdu: Uint8Array;\n let mockResponse: ApduResponse;\n\n beforeEach(() => {\n mockApdu = new Uint8Array([0xe0, 0x01, 0x00, 0x00]);\n mockResponse = {\n data: new Uint8Array([0x01, 0x02]),\n statusCode: new Uint8Array([0x90, 0x00]),\n };\n\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n });\n\n it(\"should successfully send APDU\", async () => {\n // given\n const mockObservable = of(Right(mockResponse)).pipe(delay(1));\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: mockObservable,\n cancel: vi.fn(),\n });\n\n // when\n const result = await deviceSession.sendApdu(mockApdu);\n\n // then\n expect(mockIntentQueueService.enqueue).toHaveBeenCalledWith({\n type: \"send-apdu\",\n execute: expect.any(Function),\n });\n expect(result.isRight()).toBe(true);\n result.ifRight((response) => {\n expect(response).toEqual(mockResponse);\n });\n });\n\n it(\"should handle APDU send error\", async () => {\n // given\n const error = { _tag: \"SendApduError\" } as DmkError;\n const mockObservable = of(Left(error)).pipe(delay(1));\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: mockObservable,\n cancel: vi.fn(),\n });\n\n // when\n const result = await deviceSession.sendApdu(mockApdu);\n\n // then\n expect(result.isLeft()).toBe(true);\n result.ifLeft((err) => {\n expect(err).toEqual(error);\n });\n });\n\n it(\"should handle APDU timeout\", async () => {\n // given\n const mockCancel = vi.fn();\n const subject = new Subject();\n\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: subject.asObservable(),\n cancel: mockCancel,\n });\n\n vi.useFakeTimers();\n\n // when\n const sendPromise = deviceSession.sendApdu(mockApdu, {\n abortTimeout: 1000,\n });\n\n // Advance timers to trigger timeout\n vi.advanceTimersByTime(1100);\n\n let caughtError: Error | undefined;\n try {\n await sendPromise;\n } catch (error) {\n caughtError = error as Error;\n }\n\n vi.useRealTimers();\n\n // then\n expect(caughtError).toBeDefined();\n expect(mockIntentQueueService.enqueue).toHaveBeenCalled();\n });\n });\n\n describe(\"sendCommand\", () => {\n type TestData = { test: string };\n type TestArgs = Record<string, never>;\n type TestErrorCodes = number;\n\n let mockCommand: Mocked<Command<TestData, TestArgs, TestErrorCodes>>;\n let mockCommandResult: CommandResult<TestData, TestErrorCodes>;\n\n beforeEach(() => {\n mockCommandResult = {\n status: CommandResultStatus.Success,\n data: { test: \"data\" },\n };\n\n mockCommand = {\n getApdu: vi.fn().mockReturnValue({\n getRawApdu: () => new Uint8Array([0xe0, 0x01, 0x00, 0x00]),\n }),\n parseResponse: vi.fn().mockReturnValue(mockCommandResult),\n triggersDisconnection: false,\n } as unknown as Mocked<Command<TestData, TestArgs, TestErrorCodes>>;\n\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n });\n\n it(\"should successfully send command\", async () => {\n // given\n const mockObservable = of(mockCommandResult).pipe(delay(1));\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: mockObservable,\n cancel: vi.fn(),\n });\n\n // when\n const result = await deviceSession.sendCommand(mockCommand);\n\n // then\n expect(mockIntentQueueService.enqueue).toHaveBeenCalledWith({\n type: \"send-command\",\n execute: expect.any(Function),\n });\n expect(result).toEqual(mockCommandResult);\n });\n\n it(\"should handle command timeout\", async () => {\n // given\n const mockCancel = vi.fn();\n const subject = new Subject();\n\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: subject.asObservable(),\n cancel: mockCancel,\n });\n\n vi.useFakeTimers();\n\n // when\n const commandPromise = deviceSession.sendCommand(mockCommand, 1000);\n\n // Advance timers to trigger timeout\n vi.advanceTimersByTime(1100);\n\n try {\n await commandPromise;\n } catch {\n // Expected to timeout\n }\n\n vi.useRealTimers();\n\n // then\n expect(mockIntentQueueService.enqueue).toHaveBeenCalled();\n });\n\n it(\"should handle command error\", async () => {\n // given\n const error = new Error(\"Command failed\");\n const mockObservable = throwError(() => error);\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: mockObservable,\n cancel: vi.fn(),\n });\n\n // when/then\n await expect(deviceSession.sendCommand(mockCommand)).rejects.toThrow(\n \"Command failed\",\n );\n });\n });\n\n describe(\"executeDeviceAction\", () => {\n type TestOutput = { result: string };\n type TestInput = { input: string };\n type TestError = DmkError;\n type TestIntermediateValue = {\n intermediateValue: string;\n requiredUserInteraction:\n | \"UnlockDevice\"\n | \"ConfirmOpenApp\"\n | \"ConfirmCloseApp\"\n | \"AllowListAccess\"\n | \"AllowSecureChannelConnection\"\n | \"AllowedDataRecording\"\n | \"SignTransaction\";\n };\n\n let mockDeviceAction: Mocked<\n DeviceAction<TestOutput, TestInput, TestError, TestIntermediateValue>\n >;\n\n beforeEach(() => {\n const mockActionObservable = of({\n intermediateValue: \"test\",\n requiredUserInteraction: \"SignTransaction\" as const,\n }).pipe(delay(1));\n\n mockDeviceAction = {\n _execute: vi.fn().mockReturnValue({\n observable: mockActionObservable,\n }),\n } as unknown as Mocked<\n DeviceAction<TestOutput, TestInput, TestError, TestIntermediateValue>\n >;\n\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n });\n\n it(\"should execute device action\", async () => {\n // given\n const mockActionObservable = of({\n intermediateValue: \"test\",\n requiredUserInteraction: \"SignTransaction\" as const,\n }).pipe(delay(1));\n const mockCancel = vi.fn();\n\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: mockActionObservable,\n cancel: mockCancel,\n });\n\n // when\n const { observable, cancel } =\n deviceSession.executeDeviceAction(mockDeviceAction);\n\n // then\n expect(mockIntentQueueService.enqueue).toHaveBeenCalledWith({\n type: \"device-action\",\n execute: expect.any(Function),\n });\n expect(observable).toBeDefined();\n expect(cancel).toBeTypeOf(\"function\");\n\n // Verify observable emits values\n const values: unknown[] = [];\n await new Promise<void>((resolve) => {\n observable.subscribe({\n next: (value) => values.push(value),\n complete: () => resolve(),\n });\n });\n\n expect(values).toEqual([\n {\n intermediateValue: \"test\",\n requiredUserInteraction: \"SignTransaction\",\n },\n ]);\n\n // Verify cancel is called\n cancel();\n expect(mockCancel).toHaveBeenCalled();\n });\n\n it(\"should provide correct internal API to device action\", () => {\n // given\n const mockActionObservable = of({\n intermediateValue: \"test\",\n requiredUserInteraction: \"SignTransaction\" as const,\n }).pipe(delay(1));\n\n mockIntentQueueService.enqueue.mockImplementation((intent) => {\n // Execute the device action to verify the internal API\n void intent.execute();\n\n return {\n observable: mockActionObservable,\n cancel: vi.fn(),\n };\n });\n\n // when\n deviceSession.executeDeviceAction(mockDeviceAction);\n\n // then\n expect(mockDeviceAction._execute).toHaveBeenCalledWith({\n sendApdu: expect.any(Function),\n sendCommand: expect.any(Function),\n getDeviceModel: expect.any(Function),\n getDeviceSessionState: expect.any(Function),\n getDeviceSessionStateObservable: expect.any(Function),\n setDeviceSessionState: expect.any(Function),\n getManagerApiService: expect.any(Function),\n getSecureChannelService: expect.any(Function),\n loggerFactory: expect.any(Function),\n });\n });\n\n it(\"should allow cancelling device action\", () => {\n // given\n const mockCancel = vi.fn();\n const subject = new Subject();\n\n mockIntentQueueService.enqueue.mockReturnValue({\n observable: subject.asObservable(),\n cancel: mockCancel,\n });\n\n // when\n const { cancel } = deviceSession.executeDeviceAction(mockDeviceAction);\n cancel();\n\n // then\n expect(mockCancel).toHaveBeenCalled();\n });\n });\n\n describe(\"close\", () => {\n it(\"should close the session and update device status\", () => {\n // given\n deviceSession = new DeviceSession(\n { connectedDevice: mockConnectedDevice },\n mockLoggerFactory,\n mockManagerApi,\n mockSecureChannel,\n refresherOptions,\n mockIntentQueueServiceFactory,\n );\n\n let isComplete = false;\n deviceSession.state.subscribe({\n complete: () => {\n isComplete = true;\n },\n });\n\n // when\n deviceSession.close();\n\n // then\n const state = deviceSession.getDeviceSessionState();\n expect(state.deviceStatus).toBe(DeviceStatus.NOT_CONNECTED);\n expect(isComplete).toBe(true);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aACA,IAAAA,EAA4B,qBAC5BC,EAAwC,gBACxCC,EAA4B,0BAI5BC,EAGO,4CACPC,EAA6B,oCAG7BC,EAAuC,kDAGvCC,EAA2C,8DAE3CC,EAA8C,4EAI9CC,EAGO,2BAEP,SAAS,gBAAiB,IAAM,CAC9B,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACJ,MAAMC,KAAsB,8BAA2B,EAEvD,WAAW,IAAM,CAEfP,EAAa,IAAI,gCAA8B,CAAC,EAAG,qBAAqB,EACxEC,EAAoB,GAAG,GAAG,IAAMD,CAAU,EAG1CE,EAAiB,CACf,WAAY,GAAG,GAAG,EAClB,cAAe,GAAG,GAAG,EACrB,mBAAoB,GAAG,GAAG,EAC1B,kBAAmB,GAAG,GAA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YAAa,OAAO,IAAI,QAAQ,EAChC,eAAgB,OAAO,IAAI,QAAQ,EACnC,sBAAuB,OAAO,IAAI,QAAQ,EAC1C,gCAAiC,OAAO,IAAI,QAAQ,EACpD,sBAAuB,OAAO,IAAI,QAAQ,EAC1C,qBAAsB,OAAO,IAAI,QAAQ,EACzC,wBAAyB,OAAO,IAAI,QAAQ,EAC5C,cAAe,OAAO,IAAI,QAAQ,CACpC,CAAC,CACH,CAAC,EAED,GAAG,wCAAyC,IAAM,CAEhD,MAAMP,EAAa,GAAG,GAAG,EACnBC,EAAU,IAAI,UAEpBpB,EAAuB,QAAQ,gBAAgB,CAC7C,WAAYoB,EAAQ,aAAa,EACjC,OAAQD,CACV,CAAC,EAGD,KAAM,CAAE,OAAAU,CAAO,EAAIlC,EAAc,oBAAoB+B,CAAgB,EACrEG,EAAO,EAGP,OAAOV,CAAU,EAAE,iBAAiB,CACtC,CAAC,CACH,CAAC,EAED,SAAS,QAAS,IAAM,CACtB,GAAG,oDAAqD,IAAM,CAE5DxB,EAAgB,IAAI,gBAClB,CAAE,gBAAiBQ,CAAoB,EACvCN,EACAC,EACAC,EACAG,EACAD,CACF,EAEA,IAAIgC,EAAa,GACjBtC,EAAc,MAAM,UAAU,CAC5B,SAAU,IAAM,CACdsC,EAAa,EACf,CACF,CAAC,EAGDtC,EAAc,MAAM,EAGpB,MAAMa,EAAQb,EAAc,sBAAsB,EAClD,OAAOa,EAAM,YAAY,EAAE,KAAK,eAAa,aAAa,EAC1D,OAAOyB,CAAU,EAAE,KAAK,EAAI,CAC9B,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_purify_ts", "import_rxjs", "import_operators", "import_CommandResult", "import_DeviceStatus", "import_DeviceSessionState", "import_TransportConnectedDevice", "import_DefaultLoggerPublisherService", "import_DeviceSession", "deviceSession", "mockLogger", "mockLoggerFactory", "mockManagerApi", "mockSecureChannel", "mockIntentQueueService", "mockIntentQueueServiceFactory", "refresherOptions", "mockConnectedDevice", "customId", "mockRefresherStartSpy", "stateObservable", "resolve", "state", "newState", "subscriptionStarted", "subscription", "mockApdu", "mockResponse", "mockObservable", "result", "response", "error", "err", "mockCancel", "subject", "sendPromise", "caughtError", "mockCommand", "mockCommandResult", "commandPromise", "mockDeviceAction", "mockActionObservable", "observable", "cancel", "values", "value", "intent", "isComplete"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var _=Object.defineProperty;var
|
|
1
|
+
"use strict";var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var N=(e,E)=>{for(var D in E)_(e,D,{get:E[D],enumerable:!0})},d=(e,E,D,T)=>{if(E&&typeof E=="object"||typeof E=="function")for(let t of C(E))!S.call(e,t)&&t!==D&&_(e,t,{get:()=>E[t],enumerable:!(T=A(E,t))||T.enumerable});return e};var o=e=>d(_({},"__esModule",{value:!0}),e);var v={};N(v,{DeviceSessionEventDispatcher:()=>a,SessionEvents:()=>i});module.exports=o(v);var s=require("rxjs"),i=(n=>(n.NEW_STATE="NEW_STATE",n.REFRESH_NEEDED="REFRESH_NEEDED",n.COMMAND_SUCCEEDED="COMMAND_SUCCEEDED",n.DEVICE_STATE_UPDATE_BUSY="DEVICE_STATE_UPDATE_BUSY",n.DEVICE_STATE_UPDATE_LOCKED="DEVICE_STATE_UPDATE_LOCKED",n.DEVICE_STATE_UPDATE_CONNECTED="DEVICE_STATE_UPDATE_CONNECTED",n.DEVICE_STATE_UPDATE_UNKNOWN="DEVICE_STATE_UPDATE_UNKNOWN",n))(i||{});class a{_eventEmitter=new s.Subject;listen(){return this._eventEmitter.asObservable()}dispatch(E){this._eventEmitter.next(E)}}0&&(module.exports={DeviceSessionEventDispatcher,SessionEvents});
|
|
2
2
|
//# sourceMappingURL=DeviceSessionEventDispatcher.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionEventDispatcher.ts"],
|
|
4
|
-
"sourcesContent": ["import { type Observable, Subject } from \"rxjs\";\n\nimport { type GetAppAndVersionResponse } from \"@api/index\";\nimport { type CommandResult } from \"@api/types\";\n\nexport enum SessionEvents {\n NEW_STATE = \"NEW_STATE\",\n REFRESH_NEEDED = \"REFRESH_NEEDED\",\n COMMAND_SUCCEEDED = \"COMMAND_SUCCEEDED\",\n DEVICE_STATE_UPDATE_BUSY = \"DEVICE_STATE_UPDATE_BUSY\",\n DEVICE_STATE_UPDATE_LOCKED = \"DEVICE_STATE_UPDATE_LOCKED\",\n DEVICE_STATE_UPDATE_CONNECTED = \"DEVICE_STATE_UPDATE_CONNECTED\",\n}\n\ninterface SessionEventPayloads {\n [SessionEvents.NEW_STATE]: undefined;\n [SessionEvents.REFRESH_NEEDED]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_BUSY]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_LOCKED]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_CONNECTED]: undefined;\n [SessionEvents.COMMAND_SUCCEEDED]: CommandResult<GetAppAndVersionResponse>;\n}\n\nexport type NewEvent = {\n [K in SessionEvents]: SessionEventPayloads[K] extends undefined\n ? { eventName: K; eventData?: undefined }\n : { eventName: K; eventData: SessionEventPayloads[K] };\n}[SessionEvents];\n\nexport class DeviceSessionEventDispatcher {\n private _eventEmitter: Subject<NewEvent> = new Subject();\n\n public listen(): Observable<NewEvent> {\n return this._eventEmitter.asObservable();\n }\n\n public dispatch(event: NewEvent): void {\n this._eventEmitter.next(event);\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,kBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAyC,gBAK7BF,OACVA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,kBAAoB,oBACpBA,EAAA,yBAA2B,2BAC3BA,EAAA,2BAA6B,6BAC7BA,EAAA,8BAAgC,
|
|
4
|
+
"sourcesContent": ["import { type Observable, Subject } from \"rxjs\";\n\nimport { type GetAppAndVersionResponse } from \"@api/index\";\nimport { type CommandResult } from \"@api/types\";\n\nexport enum SessionEvents {\n NEW_STATE = \"NEW_STATE\",\n REFRESH_NEEDED = \"REFRESH_NEEDED\",\n COMMAND_SUCCEEDED = \"COMMAND_SUCCEEDED\",\n DEVICE_STATE_UPDATE_BUSY = \"DEVICE_STATE_UPDATE_BUSY\",\n DEVICE_STATE_UPDATE_LOCKED = \"DEVICE_STATE_UPDATE_LOCKED\",\n DEVICE_STATE_UPDATE_CONNECTED = \"DEVICE_STATE_UPDATE_CONNECTED\",\n DEVICE_STATE_UPDATE_UNKNOWN = \"DEVICE_STATE_UPDATE_UNKNOWN\",\n}\n\ninterface SessionEventPayloads {\n [SessionEvents.NEW_STATE]: undefined;\n [SessionEvents.REFRESH_NEEDED]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_BUSY]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_LOCKED]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_CONNECTED]: undefined;\n [SessionEvents.DEVICE_STATE_UPDATE_UNKNOWN]: undefined;\n [SessionEvents.COMMAND_SUCCEEDED]: CommandResult<GetAppAndVersionResponse>;\n}\n\nexport type NewEvent = {\n [K in SessionEvents]: SessionEventPayloads[K] extends undefined\n ? { eventName: K; eventData?: undefined }\n : { eventName: K; eventData: SessionEventPayloads[K] };\n}[SessionEvents];\n\nexport class DeviceSessionEventDispatcher {\n private _eventEmitter: Subject<NewEvent> = new Subject();\n\n public listen(): Observable<NewEvent> {\n return this._eventEmitter.asObservable();\n }\n\n public dispatch(event: NewEvent): void {\n this._eventEmitter.next(event);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,kBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAyC,gBAK7BF,OACVA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,kBAAoB,oBACpBA,EAAA,yBAA2B,2BAC3BA,EAAA,2BAA6B,6BAC7BA,EAAA,8BAAgC,gCAChCA,EAAA,4BAA8B,8BAPpBA,OAAA,IA0BL,MAAMD,CAA6B,CAChC,cAAmC,IAAI,UAExC,QAA+B,CACpC,OAAO,KAAK,cAAc,aAAa,CACzC,CAEO,SAASI,EAAuB,CACrC,KAAK,cAAc,KAAKA,CAAK,CAC/B,CACF",
|
|
6
6
|
"names": ["DeviceSessionEventDispatcher_exports", "__export", "DeviceSessionEventDispatcher", "SessionEvents", "__toCommonJS", "import_rxjs", "event"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var v=(n,s)=>{for(var t in s)p(n,t,{get:s[t],enumerable:!0})},_=(n,s,t,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of a(s))!f.call(n,i)&&i!==t&&p(n,i,{get:()=>s[i],enumerable:!(e=l(s,i))||e.enumerable});return n};var d=n=>_(p({},"__esModule",{value:!0}),n);var g={};v(g,{DeviceSessionRefresher:()=>u});module.exports=d(g);var r=require("rxjs"),c=require("../../../api/device/DeviceModel"),o=require("../../device-session/data/DeviceSessionRefresherConst"),h=require("../../device-session/model/DeviceSessionEventDispatcher");class u{constructor(s,t,e,i){this._sessionEventDispatcher=e;this._refresherOptions=t,this._logger=s("device-session-refresher"),this._connectedDeviceID=i.deviceModel.id}_refresherSubscription;_refresherOptions;_logger;_connectedDeviceID;startRefresher(){if(this._refresherOptions.isRefresherDisabled||this._refresherSubscription)return;const s=this.getValidPollingInterval(this._refresherOptions,this._logger)*2,t=this._sessionEventDispatcher.listen().pipe((0,r.filter)(e=>e.eventName===h.SessionEvents.DEVICE_STATE_UPDATE_BUSY||e.eventName===h.SessionEvents.NEW_STATE),(0,r.map)(e=>e.eventName===h.SessionEvents.DEVICE_STATE_UPDATE_BUSY),(0,r.startWith)(!1),(0,r.distinctUntilChanged)());this._refresherSubscription=(0,r.timer)(0,s).pipe((0,r.withLatestFrom)(t),(0,r.tap)(([e,i])=>{i&&this._logger.debug("Refresh skipped: device is busy")}),(0,r.filter)(([e,i])=>!i),(0,r.tap)(()=>this._sessionEventDispatcher.dispatch({eventName:h.SessionEvents.REFRESH_NEEDED}))).subscribe(),this._logger.info("Refresher started.")}stopRefresher(){this._refresherSubscription&&(this._refresherSubscription.unsubscribe(),this._refresherSubscription=void 0,this._logger.info("Refresher stopped."))}restartRefresher(){this.stopRefresher(),this.startRefresher(),this._logger.info("Refresher restarted.")}getValidPollingInterval=(s,t)=>{const{pollingInterval:e}=s;switch(this._connectedDeviceID){case c.DeviceModelId.NANO_S:{const i=o.DEVICE_SESSION_REFRESHER_POLLING_INTERVAL*2;return e!==void 0&&e<i?(t.warn(`Polling interval of ${e} is too low, setting to minimum as ${i}`),i):e??i}default:return e!==void 0&&e<o.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL?(t.warn(`Polling interval of ${e} is too low, setting to minimum as ${o.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL}`),o.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL):e??o.DEVICE_SESSION_REFRESHER_POLLING_INTERVAL}}}0&&(module.exports={DeviceSessionRefresher});
|
|
2
2
|
//# sourceMappingURL=DeviceSessionRefresher.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionRefresher.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,
|
|
6
|
-
"names": ["DeviceSessionRefresher_exports", "__export", "DeviceSessionRefresher", "__toCommonJS", "import_rxjs", "import_DeviceModel", "import_DeviceSessionRefresherConst", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "refresherOptions", "_sessionEventDispatcher", "connectedDevice", "pollingInterval", "logger", "defaultNanoPollingInterval"]
|
|
4
|
+
"sourcesContent": ["import {\n distinctUntilChanged,\n filter,\n map,\n startWith,\n type Subscription,\n tap,\n timer,\n withLatestFrom,\n} from \"rxjs\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { type LoggerPublisherService } from \"@api/types\";\nimport {\n DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL,\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL,\n} from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport {\n type DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nexport interface DeviceSessionRefresherOptions {\n isRefresherDisabled: boolean;\n pollingInterval?: number;\n}\n\nexport class DeviceSessionRefresher {\n private _refresherSubscription!: Subscription | undefined;\n private _refresherOptions: DeviceSessionRefresherOptions;\n private readonly _logger: LoggerPublisherService;\n private _connectedDeviceID: DeviceModelId;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n refresherOptions: DeviceSessionRefresherOptions,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n connectedDevice: TransportConnectedDevice,\n ) {\n this._refresherOptions = refresherOptions;\n this._logger = loggerModuleFactory(\"device-session-refresher\");\n this._connectedDeviceID = connectedDevice.deviceModel.id;\n }\n\n public startRefresher(): void {\n if (this._refresherOptions.isRefresherDisabled) return;\n if (this._refresherSubscription) return;\n\n const pollingInterval =\n this.getValidPollingInterval(this._refresherOptions, this._logger) * 2;\n\n const isBusy$ = this._sessionEventDispatcher.listen().pipe(\n filter(\n (event) =>\n event.eventName === SessionEvents.DEVICE_STATE_UPDATE_BUSY ||\n event.eventName === SessionEvents.NEW_STATE,\n ),\n map(\n (event) => event.eventName === SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n ),\n startWith(false),\n distinctUntilChanged(),\n );\n\n this._refresherSubscription = timer(0, pollingInterval)\n .pipe(\n withLatestFrom(isBusy$),\n tap(([_, isBusy]) => {\n if (isBusy) {\n this._logger.debug(\"Refresh skipped: device is busy\");\n }\n }),\n filter(([_, isBusy]) => !isBusy),\n tap(() =>\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.REFRESH_NEEDED,\n }),\n ),\n )\n .subscribe();\n\n this._logger.info(\"Refresher started.\");\n }\n\n public stopRefresher(): void {\n if (this._refresherSubscription) {\n this._refresherSubscription.unsubscribe();\n this._refresherSubscription = undefined;\n this._logger.info(\"Refresher stopped.\");\n }\n }\n\n public restartRefresher(): void {\n this.stopRefresher();\n this.startRefresher();\n this._logger.info(\"Refresher restarted.\");\n }\n\n private getValidPollingInterval = (\n refresherOptions: DeviceSessionRefresherOptions,\n logger: LoggerPublisherService,\n ): number => {\n const { pollingInterval } = refresherOptions;\n switch (this._connectedDeviceID) {\n case DeviceModelId.NANO_S: {\n const defaultNanoPollingInterval =\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL * 2;\n if (\n pollingInterval !== undefined &&\n pollingInterval < defaultNanoPollingInterval\n ) {\n logger.warn(\n `Polling interval of ${pollingInterval} is too low, setting to minimum as ${defaultNanoPollingInterval}`,\n );\n return defaultNanoPollingInterval;\n }\n return pollingInterval ?? defaultNanoPollingInterval;\n }\n default:\n if (\n pollingInterval !== undefined &&\n pollingInterval < DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL\n ) {\n logger.warn(\n `Polling interval of ${pollingInterval} is too low, setting to minimum as ${DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL}`,\n );\n return DEV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AoB,EAE1C,CAEO,kBAAyB,CAC9B,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,QAAQ,KAAK,sBAAsB,CAC1C,CAEQ,wBAA0B,CAChCP,EACAQ,IACW,CACX,KAAM,CAAE,gBAAAL,CAAgB,EAAIH,EAC5B,OAAQ,KAAK,mBAAoB,CAC/B,KAAK,gBAAc,OAAQ,CACzB,MAAMS,EACJ,4CAA4C,EAC9C,OACEN,IAAoB,QACpBA,EAAkBM,GAElBD,EAAO,KACL,uBAAuBL,CAAe,sCAAsCM,CAA0B,EACxG,EACOA,GAEFN,GAAmBM,CAC5B,CACA,QACE,OACEN,IAAoB,QACpBA,EAAkB,qDAElBK,EAAO,KACL,uBAAuBL,CAAe,sCAAsC,mDAAiD,EAC/H,EACO,qDAGFA,GAAmB,2CAC9B,CACF,CACF",
|
|
6
|
+
"names": ["DeviceSessionRefresher_exports", "__export", "DeviceSessionRefresher", "__toCommonJS", "import_rxjs", "import_DeviceModel", "import_DeviceSessionRefresherConst", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "refresherOptions", "_sessionEventDispatcher", "connectedDevice", "pollingInterval", "isBusy$", "event", "_", "isBusy", "logger", "defaultNanoPollingInterval"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var h=require("rxjs"),e=require("vitest"),d=require("../../../api/device/DeviceModel"),l=require("../../device-session/data/DeviceSessionRefresherConst"),p=require("../../device-session/model/DeviceSessionEventDispatcher"),i=require("./DeviceSessionRefresher");(0,e.describe)("DeviceSessionRefresher",()=>{let f,t,n;const c={deviceModel:{id:d.DeviceModelId.FLEX}},m={deviceModel:{id:d.DeviceModelId.NANO_S}},a=e.vi.fn(()=>n);let s;(0,e.beforeEach)(()=>{e.vi.useFakeTimers(),f=new h.Subject,t={listen:()=>f.asObservable(),dispatch:e.vi.fn()},n={info:e.vi.fn(),warn:e.vi.fn(),error:e.vi.fn(),debug:e.vi.fn(),subscribers:[]}}),(0,e.afterEach)(()=>{s?.stopRefresher(),e.vi.useRealTimers(),e.vi.restoreAllMocks()}),(0,e.it)("should not start refresher if disabled",()=>{const r={isRefresherDisabled:!0,pollingInterval:1e3};s=new i.DeviceSessionRefresher(a,r,t,c),s.startRefresher(),e.vi.advanceTimersByTime(2e3),(0,e.expect)(t.dispatch).not.toHaveBeenCalled()}),(0,e.it)("should warn and use minimum polling interval for default device when provided interval is too low",()=>{const r=l.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL-100,o={isRefresherDisabled:!1,pollingInterval:r};s=new i.DeviceSessionRefresher(a,o,t,c),s.startRefresher();const v=`Polling interval of ${r} is too low, setting to minimum as ${l.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL}`;(0,e.expect)(n.warn).toHaveBeenCalledWith(v)}),(0,e.it)("should warn and use minimum polling interval for NANO_S device when provided interval is too low",()=>{const r=l.DEVICE_SESSION_REFRESHER_POLLING_INTERVAL*2,o=r-100,v={isRefresherDisabled:!1,pollingInterval:o};s=new i.DeviceSessionRefresher(a,v,t,m),s.startRefresher();const R=`Polling interval of ${o} is too low, setting to minimum as ${r}`;(0,e.expect)(n.warn).toHaveBeenCalledWith(R)}),(0,e.it)("should not warn when provided polling interval is valid for default device",()=>{const o={isRefresherDisabled:!1,pollingInterval:l.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL+100};s=new i.DeviceSessionRefresher(a,o,t,c),s.startRefresher(),(0,e.expect)(n.warn).not.toHaveBeenCalled()}),(0,e.it)("should dispatch refresh event on timer ticks",()=>{const r=l.DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL+100,o={isRefresherDisabled:!1,pollingInterval:r};s=new i.DeviceSessionRefresher(a,o,t,c),s.startRefresher(),f.next({eventName:p.SessionEvents.NEW_STATE});const v=r*2;e.vi.advanceTimersByTime(v*3),(0,e.expect)(t.dispatch.mock.calls.length).toBe(4),(0,e.expect)(t.dispatch.mock.calls[0][0]).toEqual({eventName:p.SessionEvents.REFRESH_NEEDED})}),(0,e.it)("should stop refresher",()=>{const r={isRefresherDisabled:!1,pollingInterval:1e3};s=new i.DeviceSessionRefresher(a,r,t,c),s.startRefresher(),t.dispatch.mockClear(),s.stopRefresher(),e.vi.advanceTimersByTime(2e3),(0,e.expect)(t.dispatch).not.toHaveBeenCalled(),(0,e.expect)(n.info).toHaveBeenCalledWith("Refresher stopped.")}),(0,e.it)("should restart refresher",()=>{const r={isRefresherDisabled:!1,pollingInterval:1e3};s=new i.DeviceSessionRefresher(a,r,t,c),s.startRefresher(),t.dispatch.mockClear(),e.vi.clearAllTimers(),s.restartRefresher(),(0,e.expect)(n.info).toHaveBeenCalledWith("Refresher stopped."),(0,e.expect)(n.info).toHaveBeenCalledWith("Refresher restarted."),f.next({eventName:p.SessionEvents.NEW_STATE}),e.vi.advanceTimersByTime(2e3),(0,e.expect)(t.dispatch.mock.calls.length).toBeGreaterThan(0)})});
|
|
2
2
|
//# sourceMappingURL=DeviceSessionRefresher.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionRefresher.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Subject } from \"rxjs\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport type { LoggerPublisherService } from \"@api/types\";\nimport {\n DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL,\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL,\n} from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport type {\n DeviceSessionEventDispatcher,\n NewEvent,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { SessionEvents } from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nimport {\n DeviceSessionRefresher,\n type DeviceSessionRefresherOptions,\n} from \"./DeviceSessionRefresher\";\n\ndescribe(\"DeviceSessionRefresher\", () => {\n let subject: Subject<NewEvent>;\n let mockSessionEventDispatcher: DeviceSessionEventDispatcher;\n let mockLogger: LoggerPublisherService & {\n info: ReturnType<typeof vi.fn>;\n warn: ReturnType<typeof vi.fn>;\n error: ReturnType<typeof vi.fn>;\n debug: ReturnType<typeof vi.fn>;\n subscribers?: unknown[];\n };\n\n const stubDefaultDevice = {\n deviceModel: {\n id: DeviceModelId.FLEX,\n },\n } as TransportConnectedDevice;\n\n const stubNanoSDevice = {\n deviceModel: {\n id: DeviceModelId.NANO_S,\n },\n } as TransportConnectedDevice;\n\n const mockedLoggerModuleFactory = vi.fn(() => mockLogger);\n let refresher: DeviceSessionRefresher;\n\n beforeEach(() => {\n vi.useFakeTimers();\n subject = new Subject<NewEvent>();\n mockSessionEventDispatcher = {\n listen: () => subject.asObservable(),\n dispatch: vi.fn(),\n } as unknown as DeviceSessionEventDispatcher;\n mockLogger = {\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n debug: vi.fn(),\n subscribers: [],\n };\n });\n\n afterEach(() => {\n refresher?.
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAAwB,gBACxBC,EAAgE,kBAEhEC,EAA8B,mCAG9BC,EAGO,qEAKPC,EAA8B,uEAE9BC,EAGO,uCAEP,YAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EACAC,EAQJ,MAAMC,EAAoB,CACxB,YAAa,CACX,GAAI,gBAAc,IACpB,CACF,EAEMC,EAAkB,CACtB,YAAa,CACX,GAAI,gBAAc,MACpB,CACF,EAEMC,EAA4B,KAAG,GAAG,IAAMH,CAAU,EACxD,IAAII,KAEJ,cAAW,IAAM,CACf,KAAG,cAAc,EACjBN,EAAU,IAAI,UACdC,EAA6B,CAC3B,OAAQ,IAAMD,EAAQ,aAAa,EACnC,SAAU,KAAG,GAAG,CAClB,EACAE,EAAa,CACX,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,CACF,CAAC,KAED,aAAU,IAAM,CACdI,GAAW,
|
|
4
|
+
"sourcesContent": ["import { Subject } from \"rxjs\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport type { LoggerPublisherService } from \"@api/types\";\nimport {\n DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL,\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL,\n} from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport type {\n DeviceSessionEventDispatcher,\n NewEvent,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { SessionEvents } from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nimport {\n DeviceSessionRefresher,\n type DeviceSessionRefresherOptions,\n} from \"./DeviceSessionRefresher\";\n\ndescribe(\"DeviceSessionRefresher\", () => {\n let subject: Subject<NewEvent>;\n let mockSessionEventDispatcher: DeviceSessionEventDispatcher;\n let mockLogger: LoggerPublisherService & {\n info: ReturnType<typeof vi.fn>;\n warn: ReturnType<typeof vi.fn>;\n error: ReturnType<typeof vi.fn>;\n debug: ReturnType<typeof vi.fn>;\n subscribers?: unknown[];\n };\n\n const stubDefaultDevice = {\n deviceModel: {\n id: DeviceModelId.FLEX,\n },\n } as TransportConnectedDevice;\n\n const stubNanoSDevice = {\n deviceModel: {\n id: DeviceModelId.NANO_S,\n },\n } as TransportConnectedDevice;\n\n const mockedLoggerModuleFactory = vi.fn(() => mockLogger);\n let refresher: DeviceSessionRefresher;\n\n beforeEach(() => {\n vi.useFakeTimers();\n subject = new Subject<NewEvent>();\n mockSessionEventDispatcher = {\n listen: () => subject.asObservable(),\n dispatch: vi.fn(),\n } as unknown as DeviceSessionEventDispatcher;\n mockLogger = {\n info: vi.fn(),\n warn: vi.fn(),\n error: vi.fn(),\n debug: vi.fn(),\n subscribers: [],\n };\n });\n\n afterEach(() => {\n refresher?.stopRefresher();\n vi.useRealTimers();\n vi.restoreAllMocks();\n });\n\n it(\"should not start refresher if disabled\", () => {\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: true,\n pollingInterval: 1000,\n };\n\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n vi.advanceTimersByTime(2000);\n\n expect(mockSessionEventDispatcher.dispatch).not.toHaveBeenCalled();\n });\n\n it(\"should warn and use minimum polling interval for default device when provided interval is too low\", () => {\n const lowInterval = DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL - 100;\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: lowInterval,\n };\n\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n\n const expectedMessage = `Polling interval of ${lowInterval} is too low, setting to minimum as ${DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL}`;\n expect(mockLogger.warn).toHaveBeenCalledWith(expectedMessage);\n });\n\n it(\"should warn and use minimum polling interval for NANO_S device when provided interval is too low\", () => {\n const defaultNanoPollingInterval =\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL * 2;\n const lowInterval = defaultNanoPollingInterval - 100;\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: lowInterval,\n };\n\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubNanoSDevice,\n );\n refresher.startRefresher();\n\n const expectedMessage = `Polling interval of ${lowInterval} is too low, setting to minimum as ${defaultNanoPollingInterval}`;\n expect(mockLogger.warn).toHaveBeenCalledWith(expectedMessage);\n });\n\n it(\"should not warn when provided polling interval is valid for default device\", () => {\n const validInterval =\n DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL + 100;\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: validInterval,\n };\n\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n\n expect(mockLogger.warn).not.toHaveBeenCalled();\n });\n\n it(\"should dispatch refresh event on timer ticks\", () => {\n const validInterval =\n DEVICE_SESSION_REFRESHER_MINIMUM_POLLING_INTERVAL + 100;\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: validInterval,\n };\n\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n\n // Trigger NEW_STATE event to start the refresher timer\n subject.next({ eventName: SessionEvents.NEW_STATE });\n\n const timerInterval = validInterval * 2;\n\n vi.advanceTimersByTime(timerInterval * 3);\n\n expect(\n (mockSessionEventDispatcher.dispatch as ReturnType<typeof vi.fn>).mock\n .calls.length,\n ).toBe(4);\n expect(\n (mockSessionEventDispatcher.dispatch as ReturnType<typeof vi.fn>).mock\n .calls[0]![0],\n ).toEqual({\n eventName: SessionEvents.REFRESH_NEEDED,\n });\n });\n\n it(\"should stop refresher\", () => {\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: 1000,\n };\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n (\n mockSessionEventDispatcher.dispatch as ReturnType<typeof vi.fn>\n ).mockClear();\n\n refresher.stopRefresher();\n vi.advanceTimersByTime(2000);\n\n expect(mockSessionEventDispatcher.dispatch).not.toHaveBeenCalled();\n expect(mockLogger.info).toHaveBeenCalledWith(\"Refresher stopped.\");\n });\n\n it(\"should restart refresher\", () => {\n const options: DeviceSessionRefresherOptions = {\n isRefresherDisabled: false,\n pollingInterval: 1000,\n };\n refresher = new DeviceSessionRefresher(\n mockedLoggerModuleFactory,\n options,\n mockSessionEventDispatcher,\n stubDefaultDevice,\n );\n refresher.startRefresher();\n (\n mockSessionEventDispatcher.dispatch as ReturnType<typeof vi.fn>\n ).mockClear();\n vi.clearAllTimers();\n\n refresher.restartRefresher();\n expect(mockLogger.info).toHaveBeenCalledWith(\"Refresher stopped.\");\n expect(mockLogger.info).toHaveBeenCalledWith(\"Refresher restarted.\");\n\n // Trigger NEW_STATE event to start the refresher timer\n subject.next({ eventName: SessionEvents.NEW_STATE });\n\n vi.advanceTimersByTime(2000);\n expect(\n (mockSessionEventDispatcher.dispatch as ReturnType<typeof vi.fn>).mock\n .calls.length,\n ).toBeGreaterThan(0);\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAwB,gBACxBC,EAAgE,kBAEhEC,EAA8B,mCAG9BC,EAGO,qEAKPC,EAA8B,uEAE9BC,EAGO,uCAEP,YAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EACAC,EAQJ,MAAMC,EAAoB,CACxB,YAAa,CACX,GAAI,gBAAc,IACpB,CACF,EAEMC,EAAkB,CACtB,YAAa,CACX,GAAI,gBAAc,MACpB,CACF,EAEMC,EAA4B,KAAG,GAAG,IAAMH,CAAU,EACxD,IAAII,KAEJ,cAAW,IAAM,CACf,KAAG,cAAc,EACjBN,EAAU,IAAI,UACdC,EAA6B,CAC3B,OAAQ,IAAMD,EAAQ,aAAa,EACnC,SAAU,KAAG,GAAG,CAClB,EACAE,EAAa,CACX,KAAM,KAAG,GAAG,EACZ,KAAM,KAAG,GAAG,EACZ,MAAO,KAAG,GAAG,EACb,MAAO,KAAG,GAAG,EACb,YAAa,CAAC,CAChB,CACF,CAAC,KAED,aAAU,IAAM,CACdI,GAAW,cAAc,EAC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DeviceSessionEventDispatcher", "import_DeviceSessionRefresher", "subject", "mockSessionEventDispatcher", "mockLogger", "stubDefaultDevice", "stubNanoSDevice", "mockedLoggerModuleFactory", "refresher", "options", "lowInterval", "expectedMessage", "defaultNanoPollingInterval", "validInterval", "timerInterval"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var v=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var D=(c,e)=>{for(var i in e)v(c,i,{get:e[i],enumerable:!0})},d=(c,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!u.call(c,n)&&n!==i&&v(c,n,{get:()=>e[n],enumerable:!(s=S(e,n))||s.enumerable});return c};var E=c=>d(v({},"__esModule",{value:!0}),c);var h={};D(h,{DeviceSessionStateHandler:()=>_});module.exports=E(h);var t=require("../../../api/index"),a=require("../../device-session/model/DeviceSessionEventDispatcher");class _{constructor(e,i,s,n,o){this._sessionEventDispatcher=i;this._connectedDevice=s;this._deviceState=n;this.setDeviceSessionState=o;this._subscription=this._sessionEventDispatcher.listen().subscribe(r=>this.mapEventAction(r)),this._logger=e("device-session-state-handler")}_subscription;_logger;_pendingDeviceStatus=t.DeviceStatus.BUSY;_updateDeviceState(e){const i=this._parseDeviceStatus(e);if(i){const{sessionStateType:s,deviceStatus:n,currentApp:o}=i,r=this._deviceState.getValue();r.sessionStateType===t.DeviceSessionStateType.Connected?this.setDeviceSessionState({sessionStateType:s,deviceStatus:n,deviceModelId:this._connectedDevice.deviceModel.id,currentApp:o,installedApps:[],isSecureConnectionAllowed:!1}):this.setDeviceSessionState({...r,sessionStateType:s,deviceStatus:n,deviceModelId:this._connectedDevice.deviceModel.id,currentApp:o})}}mapEventAction=e=>{const{eventName:i}=e;switch(i){case a.SessionEvents.COMMAND_SUCCEEDED:return this._updateDeviceState(e.eventData);case a.SessionEvents.DEVICE_STATE_UPDATE_BUSY:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.DeviceStatus.BUSY});case a.SessionEvents.DEVICE_STATE_UPDATE_LOCKED:this._pendingDeviceStatus=t.DeviceStatus.LOCKED;return;case a.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED:this._pendingDeviceStatus=t.DeviceStatus.CONNECTED;return;case a.SessionEvents.NEW_STATE:{const s=this._pendingDeviceStatus;return this._pendingDeviceStatus=t.DeviceStatus.BUSY,this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:s})}case a.SessionEvents.DEVICE_STATE_UPDATE_UNKNOWN:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.DeviceStatus.BUSY});case a.SessionEvents.REFRESH_NEEDED:return;default:{const s=i;throw new Error(`Unhandled context type ${s}`)}}};_parseDeviceStatus(e){return(0,t.isSuccessCommandResult)(e)?{sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,currentApp:{name:e.data.name,version:e.data.version}}:(this._logger.debug("Error while parsing APDU response",{data:{parsedResponse:e}}),null)}unsubscribe(){this._subscription.unsubscribe()}}0&&(module.exports={DeviceSessionStateHandler});
|
|
2
2
|
//# sourceMappingURL=DeviceSessionStateHandler.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionStateHandler.ts"],
|
|
4
|
-
"sourcesContent": ["import { type BehaviorSubject, type Subscription } from \"rxjs\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n DeviceSessionStateType,\n DeviceStatus,\n type GetAppAndVersionResponse,\n isSuccessCommandResult,\n type TransportConnectedDevice,\n} from \"@api/index\";\nimport { type CommandResult, type LoggerPublisherService } from \"@api/types\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nexport type SetDeviceSessionStateFn = (state: DeviceSessionState) => void;\n\ntype NewDeviceStatus = {\n sessionStateType: DeviceSessionStateType;\n deviceStatus: DeviceStatus;\n currentApp: {\n name: string;\n version: string;\n };\n};\n\nexport class DeviceSessionStateHandler {\n private _subscription: Subscription;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n private _connectedDevice: TransportConnectedDevice,\n private _deviceState: BehaviorSubject<DeviceSessionState>,\n private setDeviceSessionState: SetDeviceSessionStateFn,\n ) {\n this._subscription = this._sessionEventDispatcher\n .listen()\n .subscribe((event) => this.mapEventAction(event));\n this._logger = loggerModuleFactory(\"device-session-state-handler\");\n }\n\n private _updateDeviceState(\n parsedResponse: CommandResult<GetAppAndVersionResponse>,\n ): void {\n const newDeviceStatus = this._parseDeviceStatus(parsedResponse);\n\n if (newDeviceStatus) {\n const { sessionStateType, deviceStatus, currentApp } = newDeviceStatus;\n const state = this._deviceState.getValue();\n if (state.sessionStateType === DeviceSessionStateType.Connected) {\n // When device is connected, initialize fields to default values\n this.setDeviceSessionState({\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n } else {\n // When device is ready, keep un-modified state fields\n this.setDeviceSessionState({\n ...state,\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n });\n }\n }\n }\n\n private mapEventAction = (event: NewEvent) => {\n switch (
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAGA,IAAAI,EAMO,sBAEPC,EAIO,uEAaA,MAAMH,CAA0B,
|
|
6
|
-
"names": ["DeviceSessionStateHandler_exports", "__export", "DeviceSessionStateHandler", "__toCommonJS", "import_api", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "_sessionEventDispatcher", "_connectedDevice", "_deviceState", "setDeviceSessionState", "event", "parsedResponse", "newDeviceStatus", "sessionStateType", "deviceStatus", "currentApp", "state"]
|
|
4
|
+
"sourcesContent": ["import { type BehaviorSubject, type Subscription } from \"rxjs\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n DeviceSessionStateType,\n DeviceStatus,\n type GetAppAndVersionResponse,\n isSuccessCommandResult,\n type TransportConnectedDevice,\n} from \"@api/index\";\nimport { type CommandResult, type LoggerPublisherService } from \"@api/types\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nexport type SetDeviceSessionStateFn = (state: DeviceSessionState) => void;\n\ntype NewDeviceStatus = {\n sessionStateType: DeviceSessionStateType;\n deviceStatus: DeviceStatus;\n currentApp: {\n name: string;\n version: string;\n };\n};\n\nexport class DeviceSessionStateHandler {\n private _subscription: Subscription;\n private readonly _logger: LoggerPublisherService;\n // BUSY is used as the default status when an intent fails, since it is not yet clear\n // whether the device is disconnected or simply unresponsive. The actual disconnection\n // status will be determined and notified asynchronously by the transport layer.\n private _pendingDeviceStatus: DeviceStatus = DeviceStatus.BUSY;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n private _connectedDevice: TransportConnectedDevice,\n private _deviceState: BehaviorSubject<DeviceSessionState>,\n private setDeviceSessionState: SetDeviceSessionStateFn,\n ) {\n this._subscription = this._sessionEventDispatcher\n .listen()\n .subscribe((event) => this.mapEventAction(event));\n this._logger = loggerModuleFactory(\"device-session-state-handler\");\n }\n\n private _updateDeviceState(\n parsedResponse: CommandResult<GetAppAndVersionResponse>,\n ): void {\n const newDeviceStatus = this._parseDeviceStatus(parsedResponse);\n\n if (newDeviceStatus) {\n const { sessionStateType, deviceStatus, currentApp } = newDeviceStatus;\n const state = this._deviceState.getValue();\n if (state.sessionStateType === DeviceSessionStateType.Connected) {\n // When device is connected, initialize fields to default values\n this.setDeviceSessionState({\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n } else {\n // When device is ready, keep un-modified state fields\n this.setDeviceSessionState({\n ...state,\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n });\n }\n }\n }\n\n private mapEventAction = (event: NewEvent) => {\n const { eventName } = event;\n switch (eventName) {\n case SessionEvents.COMMAND_SUCCEEDED:\n return this._updateDeviceState(event.eventData);\n case SessionEvents.DEVICE_STATE_UPDATE_BUSY:\n return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.BUSY,\n });\n case SessionEvents.DEVICE_STATE_UPDATE_LOCKED:\n this._pendingDeviceStatus = DeviceStatus.LOCKED;\n return;\n case SessionEvents.DEVICE_STATE_UPDATE_CONNECTED:\n this._pendingDeviceStatus = DeviceStatus.CONNECTED;\n return;\n case SessionEvents.NEW_STATE: {\n // On new state, if an intent is successful,\n // we should have a DEVICE_STATE_UPDATE_LOCKED or DEVICE_STATE_UPDATE_CONNECTED as pending status event\n // If not, we should still have a BUSY status as fallback waiting for the transport to disconnect\n const newDeviceStatus = this._pendingDeviceStatus;\n this._pendingDeviceStatus = DeviceStatus.BUSY;\n return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: newDeviceStatus,\n });\n }\n case SessionEvents.DEVICE_STATE_UPDATE_UNKNOWN:\n return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.BUSY,\n });\n case SessionEvents.REFRESH_NEEDED:\n // This case is handled by the DeviceSessionRefresher\n return;\n default: {\n const uncoveredType: never = eventName;\n throw new Error(`Unhandled context type ${uncoveredType}`);\n }\n }\n };\n\n private _parseDeviceStatus(\n parsedResponse: CommandResult<GetAppAndVersionResponse>,\n ): NewDeviceStatus | null {\n if (isSuccessCommandResult(parsedResponse)) {\n return {\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n currentApp: {\n name: parsedResponse.data.name,\n version: parsedResponse.data.version,\n },\n };\n } else {\n this._logger.debug(\"Error while parsing APDU response\", {\n data: { parsedResponse },\n });\n return null;\n }\n }\n\n public unsubscribe(): void {\n this._subscription.unsubscribe();\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAGA,IAAAI,EAMO,sBAEPC,EAIO,uEAaA,MAAMH,CAA0B,CAQrC,YACEI,EACQC,EACAC,EACAC,EACAC,EACR,CAJQ,6BAAAH,EACA,sBAAAC,EACA,kBAAAC,EACA,2BAAAC,EAER,KAAK,cAAgB,KAAK,wBACvB,OAAO,EACP,UAAWC,GAAU,KAAK,eAAeA,CAAK,CAAC,EAClD,KAAK,QAAUL,EAAoB,8BAA8B,CACnE,CAlBQ,cACS,QAIT,qBAAqC,eAAa,KAelD,mBACNM,EACM,CACN,MAAMC,EAAkB,KAAK,mBAAmBD,CAAc,EAE9D,GAAIC,EAAiB,CACnB,KAAM,CAAE,iBAAAC,EAAkB,aAAAC,EAAc,WAAAC,CAAW,EAAIH,EACjDI,EAAQ,KAAK,aAAa,SAAS,EACrCA,EAAM,mBAAqB,yBAAuB,UAEpD,KAAK,sBAAsB,CACzB,iBAAAH,EACA,aAAAC,EACA,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAAC,EACA,cAAe,CAAC,EAChB,0BAA2B,EAC7B,CAAC,EAGD,KAAK,sBAAsB,CACzB,GAAGC,EACH,iBAAAH,EACA,aAAAC,EACA,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAAC,CACF,CAAC,CAEL,CACF,CAEQ,eAAkBL,GAAoB,CAC5C,KAAM,CAAE,UAAAO,CAAU,EAAIP,EACtB,OAAQO,EAAW,CACjB,KAAK,gBAAc,kBACjB,OAAO,KAAK,mBAAmBP,EAAM,SAAS,EAChD,KAAK,gBAAc,yBACjB,OAAO,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAc,eAAa,IAC7B,CAAC,EACH,KAAK,gBAAc,2BACjB,KAAK,qBAAuB,eAAa,OACzC,OACF,KAAK,gBAAc,8BACjB,KAAK,qBAAuB,eAAa,UACzC,OACF,KAAK,gBAAc,UAAW,CAI5B,MAAME,EAAkB,KAAK,qBAC7B,YAAK,qBAAuB,eAAa,KAClC,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAcA,CAChB,CAAC,CACH,CACA,KAAK,gBAAc,4BACjB,OAAO,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAc,eAAa,IAC7B,CAAC,EACH,KAAK,gBAAc,eAEjB,OACF,QAAS,CACP,MAAMM,EAAuBD,EAC7B,MAAM,IAAI,MAAM,0BAA0BC,CAAa,EAAE,CAC3D,CACF,CACF,EAEQ,mBACNP,EACwB,CACxB,SAAI,0BAAuBA,CAAc,EAChC,CACL,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,WAAY,CACV,KAAMA,EAAe,KAAK,KAC1B,QAASA,EAAe,KAAK,OAC/B,CACF,GAEA,KAAK,QAAQ,MAAM,oCAAqC,CACtD,KAAM,CAAE,eAAAA,CAAe,CACzB,CAAC,EACM,KAEX,CAEO,aAAoB,CACzB,KAAK,cAAc,YAAY,CACjC,CACF",
|
|
6
|
+
"names": ["DeviceSessionStateHandler_exports", "__export", "DeviceSessionStateHandler", "__toCommonJS", "import_api", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "_sessionEventDispatcher", "_connectedDevice", "_deviceState", "setDeviceSessionState", "event", "parsedResponse", "newDeviceStatus", "sessionStateType", "deviceStatus", "currentApp", "state", "eventName", "uncoveredType"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=require("rxjs"),t=require("vitest"),e=require("../../../api/index"),i=require("../../device-session/model/DeviceSessionEventDispatcher"),
|
|
1
|
+
"use strict";var r=require("rxjs"),t=require("vitest"),e=require("../../../api/index"),i=require("../../device-session/model/DeviceSessionEventDispatcher"),S=require("./DeviceSessionStateHandler");describe("DeviceSessionStateHandler",()=>{let n,v,c;const u=vi.fn(()=>c);let l,d,s,o;beforeEach(()=>{n=new r.Subject,v={listen:()=>n,dispatch:vi.fn()},c={error:vi.fn(),debug:vi.fn()},l={deviceModel:{id:"device-model-1"}},d=new r.BehaviorSubject({sessionStateType:e.DeviceSessionStateType.Connected,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:e.DeviceModelId.NANO_X}),s=vi.fn(),o=new S.DeviceSessionStateHandler(u,v,l,d,s)}),afterEach(()=>{o&&typeof o.unsubscribe=="function"&&o.unsubscribe()}),it("updates device state on COMMAND_SUCCEEDED event with a successful response",()=>{const a={data:{name:"TestApp",version:"1.0.0"},status:e.CommandResultStatus.Success};n.next({eventName:i.SessionEvents.COMMAND_SUCCEEDED,eventData:a}),(0,t.expect)(s).toHaveBeenCalledWith({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:"device-model-1",currentApp:{name:"TestApp",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:!1})}),it("updates device state on COMMAND_SUCCEEDED event when device is ready",()=>{d.next({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:e.DeviceModelId.NANO_X,currentApp:{name:"",version:""},installedApps:["Bitcoin","Ethereum"],isSecureConnectionAllowed:!0});const a={data:{name:"TestApp",version:"1.0.0"},status:e.CommandResultStatus.Success};n.next({eventName:i.SessionEvents.COMMAND_SUCCEEDED,eventData:a}),(0,t.expect)(s).toHaveBeenCalledWith({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:"device-model-1",currentApp:{name:"TestApp",version:"1.0.0"},installedApps:["Bitcoin","Ethereum"],isSecureConnectionAllowed:!0})}),it("updates device state on DEVICE_STATE_UPDATE_BUSY event",()=>{n.next({eventName:i.SessionEvents.DEVICE_STATE_UPDATE_BUSY}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.BUSY}))}),it("updates device state on DEVICE_STATE_UPDATE_CONNECTED event",()=>{n.next({eventName:i.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED}),n.next({eventName:i.SessionEvents.NEW_STATE}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.CONNECTED}))}),it("logs error and does not update state if command result is unsuccessful",()=>{const a={data:null,error:{_tag:"SomeOtherError"}};n.next({eventName:i.SessionEvents.COMMAND_SUCCEEDED,eventData:a}),(0,t.expect)(c.debug).toHaveBeenCalledWith("Error while parsing APDU response",{data:{parsedResponse:a}}),(0,t.expect)(s).not.toHaveBeenCalled()}),it("does not update state if command result is not a success",()=>{const a={data:null,error:{_tag:"SomeOtherError"}};n.next({eventName:i.SessionEvents.COMMAND_SUCCEEDED,eventData:a}),(0,t.expect)(s).not.toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=DeviceSessionStateHandler.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionStateHandler.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { BehaviorSubject, Subject } from \"rxjs\";\nimport { expect, type Mock } from \"vitest\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n CommandResultStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@api/index\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n DeviceSessionStateHandler,\n type SetDeviceSessionStateFn,\n} from \"./DeviceSessionStateHandler\";\n\ndescribe(\"DeviceSessionStateHandler\", () => {\n let fakeEventSubject: Subject<NewEvent>;\n let fakeSessionEventDispatcher: DeviceSessionEventDispatcher;\n let mockLogger: {\n error: (message: string, meta?: Record<string, unknown>) => void;\n debug: (message: string, meta?: Record<string, unknown>) => void;\n };\n const mockLoggerModuleFactory = vi.fn(() => mockLogger);\n let fakeConnectedDevice: { deviceModel: { id: string } };\n let deviceState: BehaviorSubject<DeviceSessionState>;\n let setDeviceSessionState: Mock<SetDeviceSessionStateFn>;\n let handler: DeviceSessionStateHandler;\n\n beforeEach(() => {\n fakeEventSubject = new Subject<NewEvent>();\n //@ts-expect-error mock\n fakeSessionEventDispatcher = {\n listen: () => fakeEventSubject,\n dispatch: vi.fn(),\n };\n\n mockLogger = {\n error: vi.fn(),\n debug: vi.fn(),\n };\n\n fakeConnectedDevice = {\n deviceModel: {\n id: \"device-model-1\",\n },\n };\n\n deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n setDeviceSessionState = vi.fn();\n\n handler = new DeviceSessionStateHandler(\n //@ts-expect-error mock\n mockLoggerModuleFactory,\n fakeSessionEventDispatcher,\n fakeConnectedDevice,\n deviceState,\n setDeviceSessionState,\n );\n });\n\n afterEach(() => {\n if (handler && typeof handler.unsubscribe === \"function\") {\n handler.unsubscribe();\n }\n });\n\n it(\"updates device state on COMMAND_SUCCEEDED event with a successful response\", () => {\n // Given\n const fakeCommandResult = {\n data: {\n name: \"TestApp\",\n version: \"1.0.0\",\n },\n status: CommandResultStatus.Success,\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: \"device-model-1\",\n currentApp: { name: \"TestApp\", version: \"1.0.0\" },\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n });\n\n it(\"updates device state on COMMAND_SUCCEEDED event when device is ready\", () => {\n // Given\n deviceState.next({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n currentApp: { name: \"\", version: \"\" },\n installedApps: [\"Bitcoin\", \"Ethereum\"] as unknown as Application[],\n isSecureConnectionAllowed: true,\n });\n const fakeCommandResult = {\n data: {\n name: \"TestApp\",\n version: \"1.0.0\",\n },\n status: CommandResultStatus.Success,\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: \"device-model-1\",\n currentApp: { name: \"TestApp\", version: \"1.0.0\" },\n installedApps: [\"Bitcoin\", \"Ethereum\"] as unknown as Application[],\n isSecureConnectionAllowed: true,\n });\n });\n\n it(\"updates device state on DEVICE_STATE_UPDATE_BUSY event\", () => {\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith(\n expect.objectContaining({ deviceStatus: DeviceStatus.BUSY }),\n );\n });\n\n it(\"updates device state on DEVICE_STATE_UPDATE_CONNECTED event\", () => {\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith(\n expect.objectContaining({ deviceStatus: DeviceStatus.CONNECTED }),\n );\n });\n\n it(\"logs error and does not update state if command result is unsuccessful\", () => {\n // Given\n const fakeErrorCommandResult = {\n data: null,\n error: { _tag: \"SomeOtherError\" },\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeErrorCommandResult,\n });\n\n // Then\n expect(mockLogger.debug).toHaveBeenCalledWith(\n \"Error while parsing APDU response\",\n { data: { parsedResponse: fakeErrorCommandResult } },\n );\n expect(setDeviceSessionState).not.toHaveBeenCalled();\n });\n\n it(\"does not update state if command result is not a success\", () => {\n // Given\n const fakeErrorCommandResult = {\n data: null,\n error: { _tag: \"SomeOtherError\" },\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeErrorCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAAyC,gBACzCC,EAAkC,kBAGlCC,EAKO,sBACPC,EAIO,uEAGPC,EAGO,uCAEP,SAAS,4BAA6B,IAAM,CAC1C,IAAIC,EACAC,EACAC,EAIJ,MAAMC,EAA0B,GAAG,GAAG,IAAMD,CAAU,EACtD,IAAIE,EACAC,EACAC,EACAC,EAEJ,WAAW,IAAM,CACfP,EAAmB,IAAI,UAEvBC,EAA6B,CAC3B,OAAQ,IAAMD,EACd,SAAU,GAAG,GAAG,CAClB,EAEAE,EAAa,CACX,MAAO,GAAG,GAAG,EACb,MAAO,GAAG,GAAG,CACf,EAEAE,EAAsB,CACpB,YAAa,CACX,GAAI,gBACN,CACF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AA0D,IAAM,CAEjEN,EAAiB,KAAK,CACpB,UAAW,gBAAc,wBAC3B,CAAC,KAGD,UAAOM,CAAqB,EAAE,qBAC5B,SAAO,iBAAiB,CAAE,aAAc,eAAa,IAAK,CAAC,CAC7D,CACF,CAAC,EAED,GAAG,8DAA+D,IAAM,CAEtEN,EAAiB,KAAK,CACpB,UAAW,gBAAc,6BAC3B,CAAC,KAGD,UAAOM,CAAqB,EAAE,qBAC5B,SAAO,iBAAiB,CAAE,aAAc,eAAa,SAAU,CAAC,CAClE,CACF,CAAC,EAED,GAAG,yEAA0E,IAAM,CAEjF,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOP,EAAW,KAAK,EAAE,qBACvB,oCACA,CAAE,KAAM,CAAE,eAAgBO,CAAuB,CAAE,CACrD,KACA,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,EAED,GAAG,2DAA4D,IAAM,CAEnE,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,CACH,CAAC",
|
|
4
|
+
"sourcesContent": ["import { BehaviorSubject, Subject } from \"rxjs\";\nimport { expect, type Mock } from \"vitest\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n CommandResultStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@api/index\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\n\nimport {\n DeviceSessionStateHandler,\n type SetDeviceSessionStateFn,\n} from \"./DeviceSessionStateHandler\";\n\ndescribe(\"DeviceSessionStateHandler\", () => {\n let fakeEventSubject: Subject<NewEvent>;\n let fakeSessionEventDispatcher: DeviceSessionEventDispatcher;\n let mockLogger: {\n error: (message: string, meta?: Record<string, unknown>) => void;\n debug: (message: string, meta?: Record<string, unknown>) => void;\n };\n const mockLoggerModuleFactory = vi.fn(() => mockLogger);\n let fakeConnectedDevice: { deviceModel: { id: string } };\n let deviceState: BehaviorSubject<DeviceSessionState>;\n let setDeviceSessionState: Mock<SetDeviceSessionStateFn>;\n let handler: DeviceSessionStateHandler;\n\n beforeEach(() => {\n fakeEventSubject = new Subject<NewEvent>();\n //@ts-expect-error mock\n fakeSessionEventDispatcher = {\n listen: () => fakeEventSubject,\n dispatch: vi.fn(),\n };\n\n mockLogger = {\n error: vi.fn(),\n debug: vi.fn(),\n };\n\n fakeConnectedDevice = {\n deviceModel: {\n id: \"device-model-1\",\n },\n };\n\n deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n });\n\n setDeviceSessionState = vi.fn();\n\n handler = new DeviceSessionStateHandler(\n //@ts-expect-error mock\n mockLoggerModuleFactory,\n fakeSessionEventDispatcher,\n fakeConnectedDevice,\n deviceState,\n setDeviceSessionState,\n );\n });\n\n afterEach(() => {\n if (handler && typeof handler.unsubscribe === \"function\") {\n handler.unsubscribe();\n }\n });\n\n it(\"updates device state on COMMAND_SUCCEEDED event with a successful response\", () => {\n // Given\n const fakeCommandResult = {\n data: {\n name: \"TestApp\",\n version: \"1.0.0\",\n },\n status: CommandResultStatus.Success,\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: \"device-model-1\",\n currentApp: { name: \"TestApp\", version: \"1.0.0\" },\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n });\n\n it(\"updates device state on COMMAND_SUCCEEDED event when device is ready\", () => {\n // Given\n deviceState.next({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n currentApp: { name: \"\", version: \"\" },\n installedApps: [\"Bitcoin\", \"Ethereum\"] as unknown as Application[],\n isSecureConnectionAllowed: true,\n });\n const fakeCommandResult = {\n data: {\n name: \"TestApp\",\n version: \"1.0.0\",\n },\n status: CommandResultStatus.Success,\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: \"device-model-1\",\n currentApp: { name: \"TestApp\", version: \"1.0.0\" },\n installedApps: [\"Bitcoin\", \"Ethereum\"] as unknown as Application[],\n isSecureConnectionAllowed: true,\n });\n });\n\n it(\"updates device state on DEVICE_STATE_UPDATE_BUSY event\", () => {\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith(\n expect.objectContaining({ deviceStatus: DeviceStatus.BUSY }),\n );\n });\n\n it(\"updates device state on DEVICE_STATE_UPDATE_CONNECTED event\", () => {\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n\n // Trigger NEW_STATE to apply the pending status\n fakeEventSubject.next({\n eventName: SessionEvents.NEW_STATE,\n });\n\n // Then\n expect(setDeviceSessionState).toHaveBeenCalledWith(\n expect.objectContaining({ deviceStatus: DeviceStatus.CONNECTED }),\n );\n });\n\n it(\"logs error and does not update state if command result is unsuccessful\", () => {\n // Given\n const fakeErrorCommandResult = {\n data: null,\n error: { _tag: \"SomeOtherError\" },\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeErrorCommandResult,\n });\n\n // Then\n expect(mockLogger.debug).toHaveBeenCalledWith(\n \"Error while parsing APDU response\",\n { data: { parsedResponse: fakeErrorCommandResult } },\n );\n expect(setDeviceSessionState).not.toHaveBeenCalled();\n });\n\n it(\"does not update state if command result is not a success\", () => {\n // Given\n const fakeErrorCommandResult = {\n data: null,\n error: { _tag: \"SomeOtherError\" },\n };\n\n // When\n fakeEventSubject.next({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n //@ts-expect-error mock\n eventData: fakeErrorCommandResult,\n });\n\n // Then\n expect(setDeviceSessionState).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAyC,gBACzCC,EAAkC,kBAGlCC,EAKO,sBACPC,EAIO,uEAGPC,EAGO,uCAEP,SAAS,4BAA6B,IAAM,CAC1C,IAAIC,EACAC,EACAC,EAIJ,MAAMC,EAA0B,GAAG,GAAG,IAAMD,CAAU,EACtD,IAAIE,EACAC,EACAC,EACAC,EAEJ,WAAW,IAAM,CACfP,EAAmB,IAAI,UAEvBC,EAA6B,CAC3B,OAAQ,IAAMD,EACd,SAAU,GAAG,GAAG,CAClB,EAEAE,EAAa,CACX,MAAO,GAAG,GAAG,EACb,MAAO,GAAG,GAAG,CACf,EAEAE,EAAsB,CACpB,YAAa,CACX,GAAI,gBACN,CACF,EAEAC,EAAc,IAAI,kBAAoC,CACpD,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,UAC3B,cAAe,gBAAc,MAC/B,CAAC,EAEDC,EAAwB,GAAG,GAAG,EAE9BC,EAAU,IAAI,4BAEZJ,EACA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,EAED,GAAG,8DAA+D,IAAM,CAEtEN,EAAiB,KAAK,CACpB,UAAW,gBAAc,6BAC3B,CAAC,EAGDA,EAAiB,KAAK,CACpB,UAAW,gBAAc,SAC3B,CAAC,KAGD,UAAOM,CAAqB,EAAE,qBAC5B,SAAO,iBAAiB,CAAE,aAAc,eAAa,SAAU,CAAC,CAClE,CACF,CAAC,EAED,GAAG,yEAA0E,IAAM,CAEjF,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOP,EAAW,KAAK,EAAE,qBACvB,oCACA,CAAE,KAAM,CAAE,eAAgBO,CAAuB,CAAE,CACrD,KACA,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,EAED,GAAG,2DAA4D,IAAM,CAEnE,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_rxjs", "import_vitest", "import_api", "import_DeviceSessionEventDispatcher", "import_DeviceSessionStateHandler", "fakeEventSubject", "fakeSessionEventDispatcher", "mockLogger", "mockLoggerModuleFactory", "fakeConnectedDevice", "deviceState", "setDeviceSessionState", "handler", "fakeCommandResult", "fakeErrorCommandResult"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var a=(s,e)=>{for(var t in e)u(s,t,{get:e[t],enumerable:!0})},h=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of l(e))!p.call(s,n)&&n!==t&&u(s,n,{get:()=>e[n],enumerable:!(i=c(e,n))||i.enumerable});return s};var g=s=>h(u({},"__esModule",{value:!0}),s);var _={};a(_,{IntentQueueService:()=>b});module.exports=g(_);var r=require("rxjs"),o=require("../../device-session/model/DeviceSessionEventDispatcher");class b{constructor(e,t){this.loggerModuleFactory=e;this.sessionEventDispatcher=t;this._logger=this.loggerModuleFactory("IntentQueueService")}_logger;_queue=[];_isProcessing=!1;_currentSubscription=null;enqueue(e){this._logger.debug("Enqueueing intent",{data:{type:e.type}});const t=new r.Subject,i={intent:e,subject:t,isCancelled:!1};this._queue.push(i);const n=()=>{this._logger.debug("Cancelling intent",{data:{type:e.type}}),i.isCancelled=!0,this._queue[0]===i&&this._currentSubscription?(this._currentSubscription.unsubscribe(),this._currentSubscription=null,t.complete(),this._queue.shift(),this._isProcessing=!1,this._processQueue()):(!this._isProcessing||this._queue[0]!==i)&&t.complete()};return this._isProcessing||this._processQueue(),{observable:t.asObservable().pipe((0,r.finalize)(()=>{this._logger.debug("Intent observable finalized",{data:{type:e.type}})})),cancel:n}}_processQueue(){if(this._isProcessing)return;if(this._queue.length===0){this.sessionEventDispatcher.dispatch({eventName:o.SessionEvents.NEW_STATE});return}this.sessionEventDispatcher.dispatch({eventName:o.SessionEvents.DEVICE_STATE_UPDATE_BUSY}),this._isProcessing=!0;const e=this._queue[0];if(e.isCancelled){this._logger.debug("Skipping cancelled intent",{data:{type:e.intent.type}}),e.subject.complete(),this._queue.shift(),this._isProcessing=!1,this._processQueue();return}this._logger.debug("Processing intent",{data:{type:e.intent.type}}),this._currentSubscription=e.intent.execute().subscribe({next:t=>{e.isCancelled||e.subject.next(t)},error:t=>{e.isCancelled||e.subject.error(t),this._onIntentComplete()},complete:()=>{e.isCancelled||e.subject.complete(),this._onIntentComplete()}})}_onIntentComplete(){this._logger.debug("Intent completed"),this._currentSubscription=null,this._queue.shift(),this._isProcessing=!1,this._processQueue()}}0&&(module.exports={IntentQueueService});
|
|
2
|
+
//# sourceMappingURL=IntentQueueService.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/internal/device-session/service/IntentQueueService.ts"],
|
|
4
|
+
"sourcesContent": ["import { finalize, type Observable, Subject, type Subscription } from \"rxjs\";\n\nimport {\n type DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { type LoggerPublisherService } from \"@root/src\";\n\nexport type IntentType = \"device-action\" | \"send-apdu\" | \"send-command\";\n\nexport type Intent<T> = {\n type: IntentType;\n execute: () => Observable<T>;\n};\n\ntype QueueItem<T> = {\n intent: Intent<T>;\n subject: Subject<T>;\n isCancelled: boolean;\n};\n\n/**\n * Intent Queue Service\n *\n * Manages a sequential queue of intents (device actions, APDUs, commands) that must be\n * executed one at a time. Each intent returns an Observable and a cancel function.\n *\n * @remarks\n * **Queue Processing:**\n * - Intents are processed in FIFO (First-In-First-Out) order\n * - Only one intent executes at a time (sequential processing)\n * - Subsequent intents wait for the current one to complete\n *\n * **Graphical Representation:**\n *\n * Normal Sequential Processing:\n * ```\n * Time \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\n *\n * Intent 1: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * Intent 2: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * Intent 3: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n *\n * Queue: [1,2,3] \u2192 [2,3] \u2192 [3] \u2192 []\n * ```\n *\n * Cancelling Currently Executing Intent:\n * ```\n * Time \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\n *\n * Intent 1: [\u2588\u2588\u2588\u2588XX]\n * Intent 2: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * Intent 3: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * \u2191 Intent 2 starts immediately\n * Queue: [1,2,3] \u2192 [2,3] \u2192 [3] \u2192 []\n * Cancel 1 \u2191\n * ```\n *\n * Cancelling Queued Intent:\n * ```\n * Time \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\n *\n * Intent 1: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * Intent 2: [CANCELLED]\n * Intent 3: [\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588]\n * \u2191 Intent 3 starts immediately\n * Queue: [1,2,3] \u2192 [1,3] \u2192 [3] \u2192 []\n * Cancel 2 \u2191\n * ```\n *\n * @example\n * ```typescript\n * const { observable, cancel } = intentQueue.enqueue({\n * type: \"device-action\",\n * execute: () => of(result)\n * });\n *\n * observable.subscribe({\n * next: (value) => console.log(value),\n * complete: () => console.log('Done')\n * });\n *\n * // Cancel if needed\n * cancel();\n * ```\n */\nexport class IntentQueueService {\n private readonly _logger: LoggerPublisherService;\n private readonly _queue: QueueItem<unknown>[] = [];\n private _isProcessing = false;\n private _currentSubscription: Subscription | null = null;\n\n constructor(\n private readonly loggerModuleFactory: (\n tag: string,\n ) => LoggerPublisherService,\n private readonly sessionEventDispatcher: DeviceSessionEventDispatcher,\n ) {\n this._logger = this.loggerModuleFactory(\"IntentQueueService\");\n }\n\n /**\n * Enqueues an intent and returns an observable that will emit the result\n * of the intent execution, along with a cancel function.\n */\n public enqueue<T>(intent: Intent<T>): {\n observable: Observable<T>;\n cancel: () => void;\n } {\n this._logger.debug(\"Enqueueing intent\", { data: { type: intent.type } });\n\n const subject = new Subject<T>();\n const queueItem: QueueItem<T> = {\n intent,\n subject,\n isCancelled: false,\n };\n\n this._queue.push(queueItem as QueueItem<unknown>);\n\n const cancel = () => {\n this._logger.debug(\"Cancelling intent\", { data: { type: intent.type } });\n queueItem.isCancelled = true;\n\n // If this is the currently executing intent, cancel the subscription\n if (this._queue[0] === queueItem && this._currentSubscription) {\n this._currentSubscription.unsubscribe();\n this._currentSubscription = null;\n subject.complete();\n this._queue.shift();\n this._isProcessing = false;\n this._processQueue();\n } else if (!this._isProcessing || this._queue[0] !== queueItem) {\n // If not currently executing, just complete the subject\n subject.complete();\n }\n };\n\n // Start processing if not already processing\n if (!this._isProcessing) {\n this._processQueue();\n }\n\n return {\n observable: subject.asObservable().pipe(\n finalize(() => {\n this._logger.debug(\"Intent observable finalized\", {\n data: { type: intent.type },\n });\n }),\n ),\n cancel,\n };\n }\n\n /**\n * Processes the queue sequentially.\n * Skips cancelled items and continues to the next one.\n */\n private _processQueue(): void {\n // If already processing or queue is empty, do nothing\n if (this._isProcessing) {\n return;\n }\n\n if (this._queue.length === 0) {\n this.sessionEventDispatcher.dispatch({\n eventName: SessionEvents.NEW_STATE,\n });\n return;\n }\n\n this.sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n\n this._isProcessing = true;\n\n // Get the next item from the queue\n const queueItem = this._queue[0] as QueueItem<unknown>;\n\n // Skip cancelled items\n if (queueItem.isCancelled) {\n this._logger.debug(\"Skipping cancelled intent\", {\n data: { type: queueItem.intent.type },\n });\n queueItem.subject.complete();\n this._queue.shift();\n this._isProcessing = false;\n this._processQueue();\n return;\n }\n\n this._logger.debug(\"Processing intent\", {\n data: { type: queueItem.intent.type },\n });\n\n // Execute the intent\n this._currentSubscription = queueItem.intent.execute().subscribe({\n next: (value) => {\n if (!queueItem.isCancelled) {\n queueItem.subject.next(value);\n }\n },\n error: (error) => {\n if (!queueItem.isCancelled) {\n queueItem.subject.error(error);\n }\n this._onIntentComplete();\n },\n complete: () => {\n if (!queueItem.isCancelled) {\n queueItem.subject.complete();\n }\n this._onIntentComplete();\n },\n });\n }\n\n /**\n * Called when an intent completes (either successfully or with error).\n * Removes the completed item from the queue and processes the next one.\n */\n private _onIntentComplete(): void {\n this._logger.debug(\"Intent completed\");\n this._currentSubscription = null;\n this._queue.shift();\n this._isProcessing = false;\n this._processQueue();\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsE,gBAEtEC,EAGO,uEAiFA,MAAMH,CAAmB,CAM9B,YACmBI,EAGAC,EACjB,CAJiB,yBAAAD,EAGA,4BAAAC,EAEjB,KAAK,QAAU,KAAK,oBAAoB,oBAAoB,CAC9D,CAZiB,QACA,OAA+B,CAAC,EACzC,cAAgB,GAChB,qBAA4C,KAe7C,QAAWC,EAGhB,CACA,KAAK,QAAQ,MAAM,oBAAqB,CAAE,KAAM,CAAE,KAAMA,EAAO,IAAK,CAAE,CAAC,EAEvE,MAAMC,EAAU,IAAI,UACdC,EAA0B,CAC9B,OAAAF,EACA,QAAAC,EACA,YAAa,EACf,EAEA,KAAK,OAAO,KAAKC,CAA+B,EAEhD,MAAMC,EAAS,IAAM,CACnB,KAAK,QAAQ,MAAM,oBAAqB,CAAE,KAAM,CAAE,KAAMH,EAAO,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,QAAQ,MAAMG,CAAK,EAE/B,KAAK,kBAAkB,CACzB,EACA,SAAU,IAAM,CACTH,EAAU,aACbA,EAAU,QAAQ,SAAS,EAE7B,KAAK,kBAAkB,CACzB,CACF,CAAC,CACH,CAMQ,mBAA0B,CAChC,KAAK,QAAQ,MAAM,kBAAkB,EACrC,KAAK,qBAAuB,KAC5B,KAAK,OAAO,MAAM,EAClB,KAAK,cAAgB,GACrB,KAAK,cAAc,CACrB,CACF",
|
|
6
|
+
"names": ["IntentQueueService_exports", "__export", "IntentQueueService", "__toCommonJS", "import_rxjs", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "sessionEventDispatcher", "intent", "subject", "queueItem", "cancel", "value", "error"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=require("rxjs"),b=require("rxjs/operators"),w=require("../../logger-publisher/service/DefaultLoggerPublisherService"),q=require("./IntentQueueService");let i,x,h;describe("IntentQueueService",()=>{beforeEach(()=>{x=new w.DefaultLoggerPublisherService([],"intent-queue-service");const e=()=>x;h={listen:()=>(0,o.of)(void 0).pipe((0,b.delay)(1)),dispatch:vi.fn()},i=new q.IntentQueueService(e,h)}),it("should enqueue an observable and emit each value",async()=>{const e={type:"device-action",execute:()=>(0,o.of)(1,2,3).pipe((0,b.delay)(1))},{observable:c}=i.enqueue(e),r=[];await new Promise(n=>{c.subscribe({next:s=>r.push(s),complete:()=>n()})}),expect(r).toEqual([1,2,3])}),it("should enqueue two observables and emit each value sequentially",async()=>{const e={type:"device-action",execute:()=>(0,o.of)("a","b").pipe((0,b.delay)(10))},c={type:"send-apdu",execute:()=>(0,o.of)("c","d")},{observable:r}=i.enqueue(e),{observable:a}=i.enqueue(c),n=[];await Promise.all([new Promise(s=>{r.subscribe({next:t=>n.push(t),complete:()=>s()})}),new Promise(s=>{a.subscribe({next:t=>n.push(t),complete:()=>s()})})]),expect(n).toEqual(["a","b","c","d"])}),it("should enqueue an observable and cancel it",async()=>{const e=new o.Subject,c={type:"device-action",execute:()=>e.asObservable()},{observable:r,cancel:a}=i.enqueue(c),n=[];let s=!1;r.subscribe({next:t=>n.push(t),complete:()=>{s=!0}}),e.next(1),e.next(2),a(),await new Promise(t=>setTimeout(t,10)),expect(n).toEqual([1,2]),expect(s).toBe(!0)}),it("should enqueue two observables and cancel the first one",async()=>{const e=new o.Subject,c={type:"device-action",execute:()=>e.asObservable()},r={type:"send-apdu",execute:()=>(0,o.of)("x","y").pipe((0,b.delay)(1))},{observable:a,cancel:n}=i.enqueue(c),{observable:s}=i.enqueue(r),t=[];let p=!1;a.subscribe({next:u=>t.push(u),complete:()=>{p=!0}});const l=new Promise(u=>{s.subscribe({next:m=>t.push(m),complete:()=>u()})});e.next("a"),e.next("b"),expect(t).toEqual(["a","b"]),n(),await new Promise(u=>setTimeout(u,10)),expect(p).toBe(!0),await l,expect(t).toEqual(["a","b","x","y"])}),it("should enqueue two observables and cancel the second one",async()=>{const e=[],c={type:"device-action",execute:()=>(0,o.of)("a","b").pipe((0,b.delay)(10))},r={type:"send-apdu",execute:()=>(0,o.of)("x","y").pipe((0,b.delay)(10))},{observable:a}=i.enqueue(c),{observable:n,cancel:s}=i.enqueue(r),t=new Promise(l=>{a.subscribe({next:u=>e.push(u),complete:()=>l()})});let p=!1;n.subscribe({next:l=>e.push(l),complete:()=>{p=!0}}),s(),await t,await new Promise(l=>setTimeout(l,20)),expect(e).toEqual(["a","b"]),expect(p).toBe(!0)}),it("should enqueue three observables and cancel the second one",async()=>{const e=[],c={type:"device-action",execute:()=>(0,o.of)("a","b").pipe((0,b.delay)(10))},r={type:"send-apdu",execute:()=>(0,o.of)("x","y").pipe((0,b.delay)(10))},a={type:"send-command",execute:()=>(0,o.of)("1","2").pipe((0,b.delay)(10))},{observable:n}=i.enqueue(c),{observable:s,cancel:t}=i.enqueue(r),{observable:p}=i.enqueue(a),l=new Promise(d=>{n.subscribe({next:v=>e.push(v),complete:()=>d()})});let u=!1;s.subscribe({next:d=>e.push(d),complete:()=>{u=!0}});const m=new Promise(d=>{p.subscribe({next:v=>e.push(v),complete:()=>d()})});t(),await l,expect(e).toEqual(["a","b"]),await m,expect(u).toBe(!0),expect(e).toEqual(["a","b","1","2"])}),it("should handle errors in intent execution",async()=>{const e=new Error("Test error"),c={type:"device-action",execute:()=>(0,o.throwError)(()=>e)},{observable:r}=i.enqueue(c);await expect(new Promise((a,n)=>{r.subscribe({error:s=>n(s)})})).rejects.toThrow("Test error")}),it("should continue processing queue after error",async()=>{const e=[],c=new Error("Test error"),r={type:"device-action",execute:()=>(0,o.throwError)(()=>c).pipe((0,b.delay)(10))},a={type:"send-apdu",execute:()=>(0,o.of)("success").pipe((0,b.delay)(10))},{observable:n}=i.enqueue(r),{observable:s}=i.enqueue(a);let t=!1;const p=new Promise(u=>{n.subscribe({next:m=>e.push(String(m)),error:m=>{expect(m).toEqual(c),t=!0,u()}})}),l=new Promise(u=>{s.subscribe({next:m=>e.push(m),complete:()=>u()})});await p,await l,expect(t).toBe(!0),expect(e).toEqual(["success"])})});
|
|
2
|
+
//# sourceMappingURL=IntentQueueService.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/internal/device-session/service/IntentQueueService.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { of, Subject, throwError } from \"rxjs\";\nimport { delay } from \"rxjs/operators\";\n\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type DeviceSessionEventDispatcher } from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\n\nimport { type Intent, IntentQueueService } from \"./IntentQueueService\";\n\nlet service: IntentQueueService;\nlet logger: LoggerPublisherService;\nlet mockSessionEventDispatcher: DeviceSessionEventDispatcher;\n\ndescribe(\"IntentQueueService\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService([], \"intent-queue-service\");\n const loggerFactory = () => logger;\n mockSessionEventDispatcher = {\n listen: () => of(undefined).pipe(delay(1)),\n dispatch: vi.fn(),\n } as unknown as DeviceSessionEventDispatcher;\n service = new IntentQueueService(loggerFactory, mockSessionEventDispatcher);\n });\n\n it(\"should enqueue an observable and emit each value\", async () => {\n // Arrange\n const intent: Intent<number> = {\n type: \"device-action\",\n execute: () => of(1, 2, 3).pipe(delay(1)), // Make it async\n };\n\n // Act\n const { observable } = service.enqueue(intent);\n const results: number[] = [];\n const promise = new Promise<void>((resolve) => {\n observable.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n // Wait for completion\n await promise;\n\n // Assert\n expect(results).toEqual([1, 2, 3]);\n });\n\n it(\"should enqueue two observables and emit each value sequentially\", async () => {\n // Arrange\n const intent1: Intent<string> = {\n type: \"device-action\",\n execute: () => of(\"a\", \"b\").pipe(delay(10)),\n };\n\n const intent2: Intent<string> = {\n type: \"send-apdu\",\n execute: () => of(\"c\", \"d\"),\n };\n\n // Act\n const { observable: obs1 } = service.enqueue(intent1);\n const { observable: obs2 } = service.enqueue(intent2);\n\n const results: string[] = [];\n\n await Promise.all([\n new Promise<void>((resolve) => {\n obs1.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n }),\n new Promise<void>((resolve) => {\n obs2.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n }),\n ]);\n\n // Assert\n expect(results).toEqual([\"a\", \"b\", \"c\", \"d\"]);\n });\n\n it(\"should enqueue an observable and cancel it\", async () => {\n // Arrange\n const subject = new Subject<number>();\n const intent: Intent<number> = {\n type: \"device-action\",\n execute: () => subject.asObservable(),\n };\n\n // Act\n const { observable, cancel } = service.enqueue(intent);\n const results: number[] = [];\n let completed = false;\n\n observable.subscribe({\n next: (value) => results.push(value),\n complete: () => {\n completed = true;\n },\n });\n\n // Emit some values\n subject.next(1);\n subject.next(2);\n\n // Cancel the intent\n cancel();\n\n // Wait a bit to ensure cancellation is processed\n await new Promise((resolve) => setTimeout(resolve, 10));\n\n // Assert\n expect(results).toEqual([1, 2]);\n expect(completed).toBe(true);\n });\n\n it(\"should enqueue two observables and cancel the first one\", async () => {\n // Arrange\n const subject1 = new Subject<string>();\n const intent1: Intent<string> = {\n type: \"device-action\",\n execute: () => subject1.asObservable(),\n };\n\n const intent2: Intent<string> = {\n type: \"send-apdu\",\n execute: () => of(\"x\", \"y\").pipe(delay(1)), // Make it async\n };\n\n // Act\n const { observable: obs1, cancel: cancel1 } = service.enqueue(intent1);\n const { observable: obs2 } = service.enqueue(intent2);\n\n const results: string[] = [];\n let completed1 = false;\n\n obs1.subscribe({\n next: (value) => results.push(value),\n complete: () => {\n completed1 = true;\n },\n });\n\n const Promise2 = new Promise<void>((resolve) => {\n obs2.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n // Emit some values from first intent\n subject1.next(\"a\");\n subject1.next(\"b\");\n\n expect(results).toEqual([\"a\", \"b\"]);\n\n // Cancel the first intent\n cancel1();\n\n // Wait a bit for cancellation to process and queue to continue\n await new Promise((resolve) => setTimeout(resolve, 10));\n expect(completed1).toBe(true);\n\n // Wait for second to complete\n await Promise2;\n expect(results).toEqual([\"a\", \"b\", \"x\", \"y\"]);\n });\n\n it(\"should enqueue two observables and cancel the second one\", async () => {\n // Arrange\n const results: string[] = [];\n const intent1: Intent<string> = {\n type: \"device-action\",\n execute: () => of(\"a\", \"b\").pipe(delay(10)),\n };\n\n const intent2: Intent<string> = {\n type: \"send-apdu\",\n execute: () => of(\"x\", \"y\").pipe(delay(10)),\n };\n\n // Act\n const { observable: obs1 } = service.enqueue(intent1);\n const { observable: obs2, cancel: cancel2 } = service.enqueue(intent2);\n\n const results1Promise = new Promise<void>((resolve) => {\n obs1.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n let completed2 = false;\n\n obs2.subscribe({\n next: (value) => results.push(value),\n complete: () => {\n completed2 = true;\n },\n });\n\n // Cancel the second intent before first completes\n cancel2();\n\n // Wait for first to complete\n await results1Promise;\n\n // Wait a bit for cancellation to be processed\n await new Promise((resolve) => setTimeout(resolve, 20));\n\n // Assert\n expect(results).toEqual([\"a\", \"b\"]);\n expect(completed2).toBe(true);\n });\n\n it(\"should enqueue three observables and cancel the second one\", async () => {\n // Arrange\n const results: string[] = [];\n const intent1: Intent<string> = {\n type: \"device-action\",\n execute: () => of(\"a\", \"b\").pipe(delay(10)),\n };\n\n const intent2: Intent<string> = {\n type: \"send-apdu\",\n execute: () => of(\"x\", \"y\").pipe(delay(10)),\n };\n\n const intent3: Intent<string> = {\n type: \"send-command\",\n execute: () => of(\"1\", \"2\").pipe(delay(10)),\n };\n\n // Act\n const { observable: obs1 } = service.enqueue(intent1);\n const { observable: obs2, cancel: cancel2 } = service.enqueue(intent2);\n const { observable: obs3 } = service.enqueue(intent3);\n\n const results1Promise = new Promise<void>((resolve) => {\n obs1.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n let completed2 = false;\n\n obs2.subscribe({\n next: (value) => results.push(value),\n complete: () => {\n completed2 = true;\n },\n });\n\n const results3Promise = new Promise<void>((resolve) => {\n obs3.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n // Cancel the second intent before first completes\n cancel2();\n\n // Wait for first and third to complete\n await results1Promise;\n expect(results).toEqual([\"a\", \"b\"]);\n await results3Promise;\n expect(completed2).toBe(true);\n expect(results).toEqual([\"a\", \"b\", \"1\", \"2\"]);\n });\n\n it(\"should handle errors in intent execution\", async () => {\n // Arrange\n const error = new Error(\"Test error\");\n const intent: Intent<number> = {\n type: \"device-action\",\n execute: () => throwError(() => error),\n };\n\n // Act\n const { observable } = service.enqueue(intent);\n\n // Assert\n await expect(\n new Promise((_, reject) => {\n observable.subscribe({\n error: (err) => reject(err),\n });\n }),\n ).rejects.toThrow(\"Test error\");\n });\n\n it(\"should continue processing queue after error\", async () => {\n // Arrange\n const results: string[] = [];\n const error = new Error(\"Test error\");\n const intent1: Intent<number> = {\n type: \"device-action\",\n execute: () => throwError(() => error).pipe(delay(10)),\n };\n\n const intent2: Intent<string> = {\n type: \"send-apdu\",\n execute: () => of(\"success\").pipe(delay(10)),\n };\n\n // Act\n const { observable: obs1 } = service.enqueue(intent1);\n const { observable: obs2 } = service.enqueue(intent2);\n\n let error1Caught = false;\n\n // Subscribe to both immediately\n const promise1 = new Promise<void>((resolve) => {\n obs1.subscribe({\n next: (value) => results.push(String(value)),\n error: (err) => {\n expect(err).toEqual(error);\n error1Caught = true;\n resolve();\n },\n });\n });\n\n const promise2 = new Promise<void>((resolve) => {\n obs2.subscribe({\n next: (value) => results.push(value),\n complete: () => resolve(),\n });\n });\n\n // Wait for both to complete\n await promise1;\n await promise2;\n\n // Assert\n expect(error1Caught).toBe(true);\n expect(results).toEqual([\"success\"]);\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAwC,gBACxCC,EAAsB,0BAItBC,EAA8C,4EAE9CC,EAAgD,gCAEhD,IAAIC,EACAC,EACAC,EAEJ,SAAS,qBAAsB,IAAM,CACnC,WAAW,IAAM,CACfD,EAAS,IAAI,gCAA8B,CAAC,EAAG,sBAAsB,EACrE,MAAME,EAAgB,IAAMF,EAC5BC,EAA6B,CAC3B,OAAQ,OAAM,MAAG,MAAS,EAAE,QAAK,SAAM,CAAC,CAAC,EACzC,SAAU,GAAG,GAAG,CAClB,EACAF,EAAU,IAAI,qBAAmBG,EAAeD,CAA0B,CAC5E,CAAC,EAED,GAAG,mDAAoD,SAAY,CAEjE,MAAME,EAAyB,CAC7B,KAAM,gBACN,QAAS,OAAM,MAAG,EAAG,EAAG,CAAC,EAAE,QAAK,SAAM,CAAC,CAAC,CAC1C,EAGM,CAAE,WAAAC,CAAW,EAAIL,EAAQ,QAAQI,CAAM,EACvCE,EAAoB,CAAC,EAS3B,MARgB,IAAI,QAAeC,GAAY,CAC7CF,EAAW,UAAU,CACnB,KAAOG,GAAUF,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K,SAAM,EAAE,CAAC,CACvD,EAEMhB,EAA0B,CAC9B,KAAM,YACN,QAAS,OAAM,MAAG,SAAS,EAAE,QAAK,SAAM,EAAE,CAAC,CAC7C,EAGM,CAAE,WAAYC,CAAK,EAAIX,EAAQ,QAAQS,CAAO,EAC9C,CAAE,WAAYG,CAAK,EAAIZ,EAAQ,QAAQU,CAAO,EAEpD,IAAIoB,EAAe,GAGnB,MAAMC,EAAW,IAAI,QAAexB,GAAY,CAC9CI,EAAK,UAAU,CACb,KAAOH,GAAUF,EAAQ,KAAK,OAAOE,CAAK,CAAC,EAC3C,MAAQqB,GAAQ,CACd,OAAOA,CAAG,EAAE,QAAQH,CAAK,EACzBI,EAAe,GACfvB,EAAQ,CACV,CACF,CAAC,CACH,CAAC,EAEKyB,EAAW,IAAI,QAAezB,GAAY,CAC9CK,EAAK,UAAU,CACb,KAAOJ,GAAUF,EAAQ,KAAKE,CAAK,EACnC,SAAU,IAAMD,EAAQ,CAC1B,CAAC,CACH,CAAC,EAGD,MAAMwB,EACN,MAAMC,EAGN,OAAOF,CAAY,EAAE,KAAK,EAAI,EAC9B,OAAOxB,CAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CACrC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_rxjs", "import_operators", "import_DefaultLoggerPublisherService", "import_IntentQueueService", "service", "logger", "mockSessionEventDispatcher", "loggerFactory", "intent", "observable", "results", "resolve", "value", "intent1", "intent2", "obs1", "obs2", "subject", "cancel", "completed", "subject1", "cancel1", "completed1", "Promise2", "cancel2", "results1Promise", "completed2", "intent3", "obs3", "results3Promise", "error", "_", "reject", "err", "error1Caught", "promise1", "promise2"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var u=(s,e)=>{for(var r in e)c(s,r,{get:e[r],enumerable:!0})},f=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of y(e))!h.call(s,i)&&i!==r&&c(s,i,{get:()=>e[i],enumerable:!(o=a(e,i))||o.enumerable});return s};var D=s=>f(c({},"__esModule",{value:!0}),s),p=(s,e,r,o)=>{for(var i=o>1?void 0:o?a(e,r):e,g=s.length-1,v;g>=0;g--)(v=s[g])&&(i=(o?v(e,r,i):v(i))||i);return o&&i&&c(e,r,i),i},S=(s,e)=>(r,o)=>e(r,o,s);var b={};u(b,{UnsafeBypassIntentQueueUseCase:()=>t});module.exports=D(b);var n=require("inversify"),l=require("../../device-session/di/deviceSessionTypes"),m=require("../../logger-publisher/di/loggerTypes");let t=class{_sessionService;_logger;constructor(e,r){this._sessionService=e,this._logger=r("UnsafeBypassIntentQueueUseCase")}execute({sessionId:e,bypass:r}){this._sessionService.getDeviceSessionById(e).caseOf({Left:i=>{throw this._logger.error("Error getting session",{data:{error:i}}),i},Right:i=>{this._logger.warn(`UNSAFE: ${r?"Enabling":"Disabling"} intent queue bypass for session ${e}`),i._unsafeBypassIntentQueue(r)}})}};t=p([(0,n.injectable)(),S(0,(0,n.inject)(l.deviceSessionTypes.DeviceSessionService)),S(1,(0,n.inject)(m.loggerTypes.LoggerPublisherServiceFactory))],t);0&&(module.exports={UnsafeBypassIntentQueueUseCase});
|
|
2
|
+
//# sourceMappingURL=UnsafeBypassIntentQueueUseCase.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../src/internal/device-session/use-case/UnsafeBypassIntentQueueUseCase.ts"],
|
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\nexport type UnsafeBypassIntentQueueUseCaseArgs = {\n sessionId: DeviceSessionId;\n bypass: boolean;\n};\n\n/**\n * UNSAFE: Bypasses the intent queue for a device session.\n * This allows intents to execute directly without being queued.\n * Use with caution as this can lead to race conditions.\n */\n@injectable()\nexport class UnsafeBypassIntentQueueUseCase {\n private readonly _sessionService: DeviceSessionService;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._sessionService = sessionService;\n this._logger = loggerFactory(\"UnsafeBypassIntentQueueUseCase\");\n }\n\n execute({ sessionId, bypass }: UnsafeBypassIntentQueueUseCaseArgs): void {\n const errorOrDeviceSession =\n this._sessionService.getDeviceSessionById(sessionId);\n\n errorOrDeviceSession.caseOf({\n Left: (error) => {\n this._logger.error(\"Error getting session\", { data: { error } });\n throw error;\n },\n Right: (deviceSession) => {\n this._logger.warn(\n `UNSAFE: ${bypass ? \"Enabling\" : \"Disabling\"} intent queue bypass for session ${sessionId}`,\n );\n deviceSession._unsafeBypassIntentQueue(bypass);\n },\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAInCC,EAAmC,0DAEnCC,EAA4B,qDAarB,IAAMC,EAAN,KAAqC,CACzB,gBACA,QAEjB,YAEEC,EAEAC,EACA,CACA,KAAK,gBAAkBD,EACvB,KAAK,QAAUC,EAAc,gCAAgC,CAC/D,CAEA,QAAQ,CAAE,UAAAC,EAAW,OAAAC,CAAO,EAA6C,CAErE,KAAK,gBAAgB,qBAAqBD,CAAS,EAEhC,OAAO,CAC1B,KAAOE,GAAU,CACf,WAAK,QAAQ,MAAM,wBAAyB,CAAE,KAAM,CAAE,MAAAA,CAAM,CAAE,CAAC,EACzDA,CACR,EACA,MAAQC,GAAkB,CACxB,KAAK,QAAQ,KACX,WAAWF,EAAS,WAAa,WAAW,oCAAoCD,CAAS,EAC3F,EACAG,EAAc,yBAAyBF,CAAM,CAC/C,CACF,CAAC,CACH,CACF,EA/BaJ,EAANO,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,qBAAmB,oBAAoB,GAE9CA,EAAA,eAAO,cAAY,6BAA6B,IAPxCR",
|
|
6
|
+
"names": ["UnsafeBypassIntentQueueUseCase_exports", "__export", "UnsafeBypassIntentQueueUseCase", "__toCommonJS", "import_inversify", "import_deviceSessionTypes", "import_loggerTypes", "UnsafeBypassIntentQueueUseCase", "sessionService", "loggerFactory", "sessionId", "bypass", "error", "deviceSession", "__decorateClass", "__decorateParam"]
|
|
7
|
+
}
|