@ledgerhq/device-management-kit 0.0.0-rnble-transport-20250401145214 → 0.0.0-rnble-transport-20250422084848
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 +40 -3
- package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.js.map +3 -3
- package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.test.js.map +3 -3
- package/lib/cjs/src/api/DeviceManagementKitBuilder.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKitBuilder.js.map +2 -2
- package/lib/cjs/src/api/DmkConfig.js +1 -1
- package/lib/cjs/src/api/DmkConfig.js.map +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.js +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.js.map +3 -3
- package/lib/cjs/src/api/device-action/DeviceAction.js.map +1 -1
- 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 +2 -2
- 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 +2 -2
- package/lib/cjs/src/api/index.js +1 -1
- package/lib/cjs/src/api/index.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/transport/model/DeviceConnection.js +1 -1
- package/lib/cjs/src/api/transport/model/DeviceConnection.js.map +1 -1
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
- package/lib/cjs/src/api/transport/model/DeviceConnectionStateMachine.js.map +2 -2
- package/lib/cjs/src/api/transport/model/Transport.js.map +1 -1
- package/lib/cjs/src/api/types.js +1 -1
- package/lib/cjs/src/api/types.js.map +1 -1
- package/lib/cjs/src/di.js +1 -1
- package/lib/cjs/src/di.js.map +2 -2
- package/lib/cjs/src/internal/device-session/data/ApduResponseConst.js +1 -1
- package/lib/cjs/src/internal/device-session/data/ApduResponseConst.js.map +3 -3
- package/lib/cjs/src/internal/device-session/model/DevicePinger.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DevicePinger.js.map +3 -3
- 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/DeviceSessionStateHandler.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSessionStateHandler.js.map +1 -1
- 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/discovery/use-case/ListenToAvailableDevicesUseCase.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ListenToAvailableDevicesUseCase.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/StartDiscoveringUseCase.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/StartDiscoveringUseCase.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/StopDiscoveringUseCase.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/StopDiscoveringUseCase.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/StopDiscoveringUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/StopDiscoveringUseCase.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/di/managerApiTypes.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiTypes.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/model/Const.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Const.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/model/Params.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Params.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/use-case/SetProviderUseCase.js +2 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetProviderUseCase.js.map +7 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetProviderUseCase.test.js +2 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetProviderUseCase.test.js.map +7 -0
- package/lib/cjs/src/internal/transport/di/transportModule.test.js +1 -1
- package/lib/cjs/src/internal/transport/di/transportModule.test.js.map +2 -2
- package/lib/esm/src/api/DeviceManagementKit.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.js.map +3 -3
- package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.test.js.map +3 -3
- package/lib/esm/src/api/DeviceManagementKitBuilder.js +1 -1
- package/lib/esm/src/api/DeviceManagementKitBuilder.js.map +3 -3
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.js +1 -1
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.js.map +3 -3
- 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 +2 -2
- 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 +2 -2
- package/lib/esm/src/api/index.js +1 -1
- package/lib/esm/src/api/index.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +1 -1
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +2 -2
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js +1 -1
- package/lib/esm/src/api/transport/model/DeviceConnectionStateMachine.js.map +2 -2
- package/lib/esm/src/di.js +1 -1
- package/lib/esm/src/di.js.map +3 -3
- package/lib/esm/src/internal/device-session/data/ApduResponseConst.js +1 -1
- package/lib/esm/src/internal/device-session/data/ApduResponseConst.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DevicePinger.js +1 -1
- package/lib/esm/src/internal/device-session/model/DevicePinger.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +3 -3
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSessionStateHandler.js.map +1 -1
- 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/discovery/use-case/ListenToAvailableDevicesUseCase.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ListenToAvailableDevicesUseCase.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/StartDiscoveringUseCase.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/StartDiscoveringUseCase.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/StopDiscoveringUseCase.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/StopDiscoveringUseCase.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/StopDiscoveringUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/StopDiscoveringUseCase.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/esm/src/internal/manager-api/di/managerApiModule.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiModule.js.map +3 -3
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/di/managerApiTypes.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiTypes.js.map +2 -2
- package/lib/esm/src/internal/manager-api/model/Const.js +1 -1
- package/lib/esm/src/internal/manager-api/model/Const.js.map +3 -3
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/use-case/SetProviderUseCase.js +2 -0
- package/lib/esm/src/internal/manager-api/use-case/SetProviderUseCase.js.map +7 -0
- package/lib/esm/src/internal/manager-api/use-case/SetProviderUseCase.test.js +2 -0
- package/lib/esm/src/internal/manager-api/use-case/SetProviderUseCase.test.js.map +7 -0
- package/lib/esm/src/internal/transport/di/transportModule.test.js +1 -1
- package/lib/esm/src/internal/transport/di/transportModule.test.js.map +2 -2
- package/lib/types/src/api/DeviceManagementKit.d.ts +11 -1
- package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
- package/lib/types/src/api/DeviceManagementKitBuilder.d.ts.map +1 -1
- package/lib/types/src/api/DmkConfig.d.ts +1 -0
- package/lib/types/src/api/DmkConfig.d.ts.map +1 -1
- package/lib/types/src/api/command/use-case/SendCommandUseCase.d.ts +5 -1
- package/lib/types/src/api/command/use-case/SendCommandUseCase.d.ts.map +1 -1
- package/lib/types/src/api/device-action/DeviceAction.d.ts +1 -1
- package/lib/types/src/api/device-action/DeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/index.d.ts +1 -1
- package/lib/types/src/api/index.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/InstallApp/InstallAppDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/DeviceConnection.d.ts +2 -1
- package/lib/types/src/api/transport/model/DeviceConnection.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts +7 -6
- package/lib/types/src/api/transport/model/DeviceConnectionStateMachine.d.ts.map +1 -1
- package/lib/types/src/api/transport/model/Transport.d.ts +1 -1
- package/lib/types/src/api/transport/model/Transport.d.ts.map +1 -1
- package/lib/types/src/api/types.d.ts +1 -1
- package/lib/types/src/api/types.d.ts.map +1 -1
- package/lib/types/src/di.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/data/ApduResponseConst.d.ts +1 -0
- package/lib/types/src/internal/device-session/data/ApduResponseConst.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DevicePinger.d.ts +1 -1
- package/lib/types/src/internal/device-session/model/DevicePinger.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
- package/lib/types/src/internal/discovery/use-case/ListenToAvailableDevicesUseCase.d.ts +1 -1
- package/lib/types/src/internal/discovery/use-case/ListenToAvailableDevicesUseCase.d.ts.map +1 -1
- package/lib/types/src/internal/discovery/use-case/StartDiscoveringUseCase.d.ts +1 -1
- package/lib/types/src/internal/discovery/use-case/StartDiscoveringUseCase.d.ts.map +1 -1
- package/lib/types/src/internal/discovery/use-case/StopDiscoveringUseCase.d.ts +1 -1
- package/lib/types/src/internal/discovery/use-case/StopDiscoveringUseCase.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts +5 -2
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +10 -0
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts +2 -0
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/di/managerApiModule.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/di/managerApiTypes.d.ts +1 -0
- package/lib/types/src/internal/manager-api/di/managerApiTypes.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Const.d.ts +1 -0
- package/lib/types/src/internal/manager-api/model/Const.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Params.d.ts +0 -6
- package/lib/types/src/internal/manager-api/model/Params.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +3 -3
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +3 -6
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/use-case/SetProviderUseCase.d.ts +11 -0
- package/lib/types/src/internal/manager-api/use-case/SetProviderUseCase.d.ts.map +1 -0
- package/lib/types/src/internal/manager-api/use-case/SetProviderUseCase.test.d.ts +2 -0
- package/lib/types/src/internal/manager-api/use-case/SetProviderUseCase.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/esm/src/di.js.map
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../src/di.ts"],
|
4
|
-
"sourcesContent": ["import { Container } from \"inversify\";\n\n// Uncomment this line to enable the logger middleware\n// import { makeLoggerMiddleware } from \"inversify-logger-middleware\";\nimport { commandModuleFactory } from \"@api/command/di/commandModule\";\nimport { deviceActionModuleFactory } from \"@api/device-action/di/deviceActionModule\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerSubscriberService } from \"@api/logger-subscriber/service/LoggerSubscriberService\";\nimport { type TransportFactory } from \"@api/transport/model/Transport\";\nimport { configModuleFactory } from \"@internal/config/di/configModule\";\nimport { deviceModelModuleFactory } from \"@internal/device-model/di/deviceModelModule\";\nimport { deviceSessionModuleFactory } from \"@internal/device-session/di/deviceSessionModule\";\nimport { discoveryModuleFactory } from \"@internal/discovery/di/discoveryModule\";\nimport { loggerModuleFactory } from \"@internal/logger-publisher/di/loggerModule\";\nimport { managerApiModuleFactory } from \"@internal/manager-api/di/managerApiModule\";\nimport {\n DEFAULT_MANAGER_API_BASE_URL,\n DEFAULT_MOCK_SERVER_BASE_URL,\n} from \"@internal/manager-api/model/Const\";\nimport { secureChannelModuleFactory } from \"@internal/secure-channel/di/secureChannelModule\";\nimport { DEFAULT_WEB_SOCKET_BASE_URL } from \"@internal/secure-channel/model/Const\";\nimport { sendModuleFactory } from \"@internal/send/di/sendModule\";\nimport { transportModuleFactory } from \"@internal/transport//di/transportModule\";\n\n// Uncomment this line to enable the logger middleware\n// const logger = makeLoggerMiddleware();\n\nexport type MakeContainerProps = {\n stub: boolean;\n transports: TransportFactory[];\n loggers: LoggerSubscriberService[];\n config: DmkConfig;\n};\n\nexport const makeContainer = ({\n stub = false,\n transports = [],\n loggers = [],\n config = {\n mockUrl: DEFAULT_MOCK_SERVER_BASE_URL,\n managerApiUrl: DEFAULT_MANAGER_API_BASE_URL,\n webSocketUrl: DEFAULT_WEB_SOCKET_BASE_URL,\n },\n}: Partial<MakeContainerProps>) => {\n const container = new Container();\n\n // Uncomment this line to enable the logger middleware\n // container.applyMiddleware(logger);\n\n container.load(\n configModuleFactory({ stub }),\n deviceModelModuleFactory({ stub }),\n transportModuleFactory({ stub, transports, config }),\n managerApiModuleFactory({ stub, config }),\n secureChannelModuleFactory({ stub, config }),\n discoveryModuleFactory({ stub }),\n loggerModuleFactory({ subscribers: loggers }),\n deviceSessionModuleFactory({ stub }),\n sendModuleFactory({ stub }),\n commandModuleFactory({ stub }),\n deviceActionModuleFactory({ stub }),\n // modules go here\n );\n\n return container;\n};\n"],
|
5
|
-
"mappings": "AAAA,OAAS,aAAAA,MAAiB,YAI1B,OAAS,wBAAAC,MAA4B,gCACrC,OAAS,6BAAAC,MAAiC,2CAI1C,OAAS,uBAAAC,MAA2B,mCACpC,OAAS,4BAAAC,MAAgC,8CACzC,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,uBAAAC,MAA2B,6CACpC,OAAS,2BAAAC,MAA+B,4CACxC,OACE,gCAAAC,EACA,gCAAAC,MACK,oCACP,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,+BAAAC,MAAmC,uCAC5C,OAAS,qBAAAC,MAAyB,+BAClC,OAAS,0BAAAC,MAA8B,0CAYhC,MAAMC,EAAgB,CAAC,CAC5B,KAAAC,EAAO,GACP,WAAAC,EAAa,CAAC,EACd,QAAAC,EAAU,CAAC,EACX,OAAAC,EAAS,CACP,
|
6
|
-
"names": ["Container", "commandModuleFactory", "deviceActionModuleFactory", "configModuleFactory", "deviceModelModuleFactory", "deviceSessionModuleFactory", "discoveryModuleFactory", "loggerModuleFactory", "managerApiModuleFactory", "DEFAULT_MANAGER_API_BASE_URL", "DEFAULT_MOCK_SERVER_BASE_URL", "secureChannelModuleFactory", "DEFAULT_WEB_SOCKET_BASE_URL", "sendModuleFactory", "transportModuleFactory", "makeContainer", "stub", "transports", "loggers", "config", "container"]
|
4
|
+
"sourcesContent": ["import { Container } from \"inversify\";\n\n// Uncomment this line to enable the logger middleware\n// import { makeLoggerMiddleware } from \"inversify-logger-middleware\";\nimport { commandModuleFactory } from \"@api/command/di/commandModule\";\nimport { deviceActionModuleFactory } from \"@api/device-action/di/deviceActionModule\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerSubscriberService } from \"@api/logger-subscriber/service/LoggerSubscriberService\";\nimport { type TransportFactory } from \"@api/transport/model/Transport\";\nimport { configModuleFactory } from \"@internal/config/di/configModule\";\nimport { deviceModelModuleFactory } from \"@internal/device-model/di/deviceModelModule\";\nimport { deviceSessionModuleFactory } from \"@internal/device-session/di/deviceSessionModule\";\nimport { discoveryModuleFactory } from \"@internal/discovery/di/discoveryModule\";\nimport { loggerModuleFactory } from \"@internal/logger-publisher/di/loggerModule\";\nimport { managerApiModuleFactory } from \"@internal/manager-api/di/managerApiModule\";\nimport {\n DEFAULT_MANAGER_API_BASE_URL,\n DEFAULT_MOCK_SERVER_BASE_URL,\n DEFAULT_PROVIDER,\n} from \"@internal/manager-api/model/Const\";\nimport { secureChannelModuleFactory } from \"@internal/secure-channel/di/secureChannelModule\";\nimport { DEFAULT_WEB_SOCKET_BASE_URL } from \"@internal/secure-channel/model/Const\";\nimport { sendModuleFactory } from \"@internal/send/di/sendModule\";\nimport { transportModuleFactory } from \"@internal/transport//di/transportModule\";\n\n// Uncomment this line to enable the logger middleware\n// const logger = makeLoggerMiddleware();\n\nexport type MakeContainerProps = {\n stub: boolean;\n transports: TransportFactory[];\n loggers: LoggerSubscriberService[];\n config: DmkConfig;\n};\n\nexport const makeContainer = ({\n stub = false,\n transports = [],\n loggers = [],\n config = {\n mockUrl: DEFAULT_MOCK_SERVER_BASE_URL,\n managerApiUrl: DEFAULT_MANAGER_API_BASE_URL,\n webSocketUrl: DEFAULT_WEB_SOCKET_BASE_URL,\n provider: DEFAULT_PROVIDER,\n },\n}: Partial<MakeContainerProps>) => {\n const container = new Container();\n\n // Uncomment this line to enable the logger middleware\n // container.applyMiddleware(logger);\n\n container.load(\n configModuleFactory({ stub }),\n deviceModelModuleFactory({ stub }),\n transportModuleFactory({ stub, transports, config }),\n managerApiModuleFactory({ stub, config }),\n secureChannelModuleFactory({ stub, config }),\n discoveryModuleFactory({ stub }),\n loggerModuleFactory({ subscribers: loggers }),\n deviceSessionModuleFactory({ stub }),\n sendModuleFactory({ stub }),\n commandModuleFactory({ stub }),\n deviceActionModuleFactory({ stub }),\n // modules go here\n );\n\n return container;\n};\n"],
|
5
|
+
"mappings": "AAAA,OAAS,aAAAA,MAAiB,YAI1B,OAAS,wBAAAC,MAA4B,gCACrC,OAAS,6BAAAC,MAAiC,2CAI1C,OAAS,uBAAAC,MAA2B,mCACpC,OAAS,4BAAAC,MAAgC,8CACzC,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,0BAAAC,MAA8B,yCACvC,OAAS,uBAAAC,MAA2B,6CACpC,OAAS,2BAAAC,MAA+B,4CACxC,OACE,gCAAAC,EACA,gCAAAC,EACA,oBAAAC,MACK,oCACP,OAAS,8BAAAC,MAAkC,kDAC3C,OAAS,+BAAAC,MAAmC,uCAC5C,OAAS,qBAAAC,MAAyB,+BAClC,OAAS,0BAAAC,MAA8B,0CAYhC,MAAMC,EAAgB,CAAC,CAC5B,KAAAC,EAAO,GACP,WAAAC,EAAa,CAAC,EACd,QAAAC,EAAU,CAAC,EACX,OAAAC,EAAS,CACP,QAASV,EACT,cAAeD,EACf,aAAcI,EACd,SAAUF,CACZ,CACF,IAAmC,CACjC,MAAMU,EAAY,IAAIrB,EAKtB,OAAAqB,EAAU,KACRlB,EAAoB,CAAE,KAAAc,CAAK,CAAC,EAC5Bb,EAAyB,CAAE,KAAAa,CAAK,CAAC,EACjCF,EAAuB,CAAE,KAAAE,EAAM,WAAAC,EAAY,OAAAE,CAAO,CAAC,EACnDZ,EAAwB,CAAE,KAAAS,EAAM,OAAAG,CAAO,CAAC,EACxCR,EAA2B,CAAE,KAAAK,EAAM,OAAAG,CAAO,CAAC,EAC3Cd,EAAuB,CAAE,KAAAW,CAAK,CAAC,EAC/BV,EAAoB,CAAE,YAAaY,CAAQ,CAAC,EAC5Cd,EAA2B,CAAE,KAAAY,CAAK,CAAC,EACnCH,EAAkB,CAAE,KAAAG,CAAK,CAAC,EAC1BhB,EAAqB,CAAE,KAAAgB,CAAK,CAAC,EAC7Bf,EAA0B,CAAE,KAAAe,CAAK,CAAC,CAEpC,EAEOI,CACT",
|
6
|
+
"names": ["Container", "commandModuleFactory", "deviceActionModuleFactory", "configModuleFactory", "deviceModelModuleFactory", "deviceSessionModuleFactory", "discoveryModuleFactory", "loggerModuleFactory", "managerApiModuleFactory", "DEFAULT_MANAGER_API_BASE_URL", "DEFAULT_MOCK_SERVER_BASE_URL", "DEFAULT_PROVIDER", "secureChannelModuleFactory", "DEFAULT_WEB_SOCKET_BASE_URL", "sendModuleFactory", "transportModuleFactory", "makeContainer", "stub", "transports", "loggers", "config", "container"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
const E=2;export{E as APDU_RESPONSE_STATUS_CODE_LENGTH};
|
1
|
+
const E=2,T=800;export{E as APDU_RESPONSE_STATUS_CODE_LENGTH,T as PINGER_TIMEOUT};
|
2
2
|
//# sourceMappingURL=ApduResponseConst.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/data/ApduResponseConst.ts"],
|
4
|
-
"sourcesContent": ["export const APDU_RESPONSE_STATUS_CODE_LENGTH = 2;\n"],
|
5
|
-
"mappings": "AAAO,MAAMA,EAAmC",
|
6
|
-
"names": ["APDU_RESPONSE_STATUS_CODE_LENGTH"]
|
4
|
+
"sourcesContent": ["export const APDU_RESPONSE_STATUS_CODE_LENGTH = 2;\nexport const PINGER_TIMEOUT = 800;\n"],
|
5
|
+
"mappings": "AAAO,MAAMA,EAAmC,EACnCC,EAAiB",
|
6
|
+
"names": ["APDU_RESPONSE_STATUS_CODE_LENGTH", "PINGER_TIMEOUT"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{DeviceModelId as
|
1
|
+
import{DeviceModelId as c}from"../../../api/device/DeviceModel";import{GetAppAndVersionCommand as a,GetOsVersionCommand as m}from"../../../api/index";import{PINGER_TIMEOUT as o}from"../../device-session/data/ApduResponseConst";import{DEVICE_SESSION_REFRESHER_POLLING_INTERVAL as p}from"../../device-session/data/DeviceSessionRefresherConst";import{SessionEvents as i}from"../../device-session/model/DeviceSessionEventDispatcher";class D{constructor(e,t,r,n){this.connectedDevice=t;this._sessionEventDispatcher=r;this._sendCommandFunction=n,this._logger=e("device-pinger"),this._subscription=this._sessionEventDispatcher.listen().subscribe(async s=>await this.mapEventAction(s))}_sendCommandFunction;_subscription;_logger;async ping(){try{return await this.mapDevicePingAction(this.connectedDevice.deviceModel.id)}catch(e){throw this._logger.error("Error while pinging device",{data:{error:e}}),e}}mapEventAction=async e=>{switch(e.eventName){case i.REFRESH_NEEDED:return await this.ping();default:return null}};async mapDevicePingAction(e){switch(e){case c.NANO_S:{const t=async()=>{const s=await this._sendCommandFunction(new a,o);return this._sendCommandFunction(new m,o),s},r=new Promise(s=>{setTimeout(()=>s(null),p*2+100)}),n=await Promise.race([t(),r]);return n?this._sessionEventDispatcher.dispatch({eventName:i.COMMAND_SUCCEEDED,eventData:n}):this._sessionEventDispatcher.dispatch({eventName:i.DEVICE_STATE_UPDATE_LOCKED}),n}default:{const t=await this._sendCommandFunction(new a,o);return this._sessionEventDispatcher.dispatch({eventName:i.COMMAND_SUCCEEDED,eventData:t}),t}}}unsubscribe(){this._subscription.unsubscribe()}}export{D as DevicePinger};
|
2
2
|
//# sourceMappingURL=DevicePinger.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DevicePinger.ts"],
|
4
|
-
"sourcesContent": ["import { type Subscription } from \"rxjs\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionResponse,\n GetOsVersionCommand,\n type TransportConnectedDevice,\n} from \"@api/index\";\nimport {\n type Command,\n type CommandResult,\n type LoggerPublisherService,\n} from \"@api/types\";\nimport { DEVICE_SESSION_REFRESHER_POLLING_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\ntype SendCommandFunction = <Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n) => Promise<CommandResult<Response, ErrorStatusCodes>>;\n\nexport class DevicePinger {\n private readonly _sendCommandFunction: SendCommandFunction;\n private _subscription: Subscription;\n private _logger: LoggerPublisherService;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n private connectedDevice: TransportConnectedDevice,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n sendCommandFunction: SendCommandFunction,\n ) {\n this._sendCommandFunction = sendCommandFunction;\n this._logger = loggerModuleFactory(\"device-pinger\");\n this._subscription = this._sessionEventDispatcher\n .listen()\n .subscribe(async (event) => await this.mapEventAction(event));\n }\n\n public async ping(): Promise<CommandResult<GetAppAndVersionResponse> | null> {\n try {\n const result = await this.mapDevicePingAction(\n this.connectedDevice.deviceModel.id,\n );\n return result;\n } catch (error) {\n this._logger.error(\"Error while pinging device\", {\n data: {\n error,\n },\n });\n throw error;\n }\n }\n\n private mapEventAction = async (event: NewEvent) => {\n switch (event.eventName) {\n case SessionEvents.REFRESH_NEEDED:\n return await this.ping();\n default:\n return null;\n }\n };\n\n private async mapDevicePingAction(deviceModelId: DeviceModelId) {\n switch (deviceModelId) {\n case DeviceModelId.NANO_S: {\n const chainPromise: Promise
|
5
|
-
"mappings": "AAEA,OAAS,iBAAAA,MAAqB,0BAC9B,OACE,2BAAAC,EAEA,uBAAAC,MAEK,aAMP,OAAS,6CAAAC,MAAiD,4DAC1D,OAGE,iBAAAC,MACK,
|
6
|
-
"names": ["DeviceModelId", "GetAppAndVersionCommand", "GetOsVersionCommand", "DEVICE_SESSION_REFRESHER_POLLING_INTERVAL", "SessionEvents", "DevicePinger", "loggerModuleFactory", "connectedDevice", "_sessionEventDispatcher", "sendCommandFunction", "event", "error", "deviceModelId", "chainPromise", "appVersionResult", "timeoutPromise", "resolve", "resultOrTimeout", "result"]
|
4
|
+
"sourcesContent": ["import { type Subscription } from \"rxjs\";\n\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionResponse,\n GetOsVersionCommand,\n type TransportConnectedDevice,\n} from \"@api/index\";\nimport {\n type Command,\n type CommandResult,\n type LoggerPublisherService,\n} from \"@api/types\";\nimport { PINGER_TIMEOUT } from \"@internal/device-session/data/ApduResponseConst\";\nimport { DEVICE_SESSION_REFRESHER_POLLING_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\ntype SendCommandFunction = <Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n abortTimeout?: number,\n) => Promise<CommandResult<Response, ErrorStatusCodes>>;\n\nexport class DevicePinger {\n private readonly _sendCommandFunction: SendCommandFunction;\n private _subscription: Subscription;\n private _logger: LoggerPublisherService;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n private connectedDevice: TransportConnectedDevice,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n sendCommandFunction: SendCommandFunction,\n ) {\n this._sendCommandFunction = sendCommandFunction;\n this._logger = loggerModuleFactory(\"device-pinger\");\n this._subscription = this._sessionEventDispatcher\n .listen()\n .subscribe(async (event) => await this.mapEventAction(event));\n }\n\n public async ping(): Promise<CommandResult<GetAppAndVersionResponse> | null> {\n try {\n const result = await this.mapDevicePingAction(\n this.connectedDevice.deviceModel.id,\n );\n return result;\n } catch (error) {\n this._logger.error(\"Error while pinging device\", {\n data: {\n error,\n },\n });\n throw error;\n }\n }\n\n private mapEventAction = async (event: NewEvent) => {\n switch (event.eventName) {\n case SessionEvents.REFRESH_NEEDED:\n return await this.ping();\n default:\n return null;\n }\n };\n\n private async mapDevicePingAction(deviceModelId: DeviceModelId) {\n switch (deviceModelId) {\n case DeviceModelId.NANO_S: {\n const chainPromise: () => Promise<\n CommandResult<GetAppAndVersionResponse>\n > = async () => {\n const appVersionResult = await this._sendCommandFunction(\n new GetAppAndVersionCommand(),\n PINGER_TIMEOUT,\n );\n\n this._sendCommandFunction(new GetOsVersionCommand(), PINGER_TIMEOUT);\n return appVersionResult;\n };\n\n const timeoutPromise: Promise<null> = new Promise((resolve) => {\n setTimeout(\n () => resolve(null),\n DEVICE_SESSION_REFRESHER_POLLING_INTERVAL * 2 + 100,\n );\n });\n\n const resultOrTimeout: CommandResult<GetAppAndVersionResponse> | null =\n await Promise.race([chainPromise(), timeoutPromise]);\n\n if (!resultOrTimeout) {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_LOCKED,\n });\n } else {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n eventData: resultOrTimeout,\n });\n }\n return resultOrTimeout;\n }\n default: {\n const result = await this._sendCommandFunction(\n new GetAppAndVersionCommand(),\n PINGER_TIMEOUT,\n );\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.COMMAND_SUCCEEDED,\n eventData: result,\n });\n return result;\n }\n }\n }\n\n public unsubscribe(): void {\n this._subscription.unsubscribe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AAC,EAPD,KAAK,wBAAwB,SAAS,CACpC,UAAWb,EAAc,0BAC3B,CAAC,EAOIa,CACT,CACA,QAAS,CACP,MAAMC,EAAS,MAAM,KAAK,qBACxB,IAAIlB,EACJE,CACF,EACA,YAAK,wBAAwB,SAAS,CACpC,UAAWE,EAAc,kBACzB,UAAWc,CACb,CAAC,EACMA,CACT,CACF,CACF,CAEO,aAAoB,CACzB,KAAK,cAAc,YAAY,CACjC,CACF",
|
6
|
+
"names": ["DeviceModelId", "GetAppAndVersionCommand", "GetOsVersionCommand", "PINGER_TIMEOUT", "DEVICE_SESSION_REFRESHER_POLLING_INTERVAL", "SessionEvents", "DevicePinger", "loggerModuleFactory", "connectedDevice", "_sessionEventDispatcher", "sendCommandFunction", "event", "error", "deviceModelId", "chainPromise", "appVersionResult", "timeoutPromise", "resolve", "resultOrTimeout", "result"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{BehaviorSubject as
|
1
|
+
import{BehaviorSubject as v}from"rxjs";import{v4 as d}from"uuid";import{CommandUtils as h}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as c}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as S}from"../../../api/device-session/DeviceSessionState";import{DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS as u}from"../../device-session/data/DeviceSessionRefresherConst";import{MutexService as m}from"../../device-session/service/MutexService";import{RefresherService as D}from"../../device-session/service/RefresherService";import{DevicePinger as l}from"./DevicePinger";import{DeviceSessionEventDispatcher as _,SessionEvents as n}from"./DeviceSessionEventDispatcher";import{DeviceSessionRefresher as f}from"./DeviceSessionRefresher";import{DeviceSessionStateHandler as E}from"./DeviceSessionStateHandler";class V{_id;_connectedDevice;_deviceState;_managerApiService;_secureChannelService;_logger;_refresherOptions;_pinger;_deviceSessionRefresher;_refresherService;_commandMutex=new m;_sessionEventDispatcher=new _;constructor({connectedDevice:e,id:s=d()},t,i,r,a){this._id=s,this._connectedDevice=e,this._logger=t("device-session"),this._managerApiService=i,this._secureChannelService=r,this._refresherOptions={...u,...a},this._deviceState=new v({sessionStateType:S.Connected,deviceStatus:c.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._pinger=new l(t,e,this._sessionEventDispatcher,(o,p)=>this.sendCommand(o,p)),this._deviceSessionRefresher=new f(t,this._refresherOptions,this._sessionEventDispatcher,this._connectedDevice),new E(t,this._sessionEventDispatcher,this._connectedDevice,this._deviceState,o=>this.setDeviceSessionState(o)),this._refresherService=new D(t,{start:()=>this._deviceSessionRefresher.restartRefresher(),stop:()=>this._deviceSessionRefresher.stopRefresher()})}async initialiseSession(){try{await this._pinger.ping()}catch(e){throw this._logger.error("Error while initialising session",{data:{error:e}}),e}finally{this._refresherOptions.isRefresherDisabled||this._deviceSessionRefresher.startRefresher()}}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}async sendApdu(e,s={isPolling:!1,triggersDisconnection:!1,abortTimeout:void 0}){const t=await this._commandMutex.lock();try{this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_BUSY});const i=await this._connectedDevice.sendApdu(e,s.triggersDisconnection,s.abortTimeout);return i.ifRight(r=>{h.isLockedDeviceResponse(r)?this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_LOCKED}):this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_CONNECTED})}).ifLeft(()=>{this._sessionEventDispatcher.dispatch({eventName:n.DEVICE_STATE_UPDATE_CONNECTED})}),i}finally{t()}}async sendCommand(e,s){const t=e.getApdu();return(await this.sendApdu(t.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1,abortTimeout:s})).caseOf({Left:r=>{throw r},Right:r=>e.parseResponse(r,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:s,cancel:t}=e._execute({sendApdu:async i=>this.sendApdu(i),sendCommand:async(i,r)=>this.sendCommand(i,r),getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:i=>(this.setDeviceSessionState(i),this._deviceState.getValue()),disableRefresher:i=>this._refresherService.disableRefresher(i),getManagerApiService:()=>this._managerApiService,getSecureChannelService:()=>this._secureChannelService});return{observable:s,cancel:t}}close(){this._updateDeviceStatus(c.NOT_CONNECTED),this._deviceState.complete(),this._deviceSessionRefresher.stopRefresher()}disableRefresher(e){return this._refresherService.disableRefresher(e)}_updateDeviceStatus(e){const s=this._deviceState.getValue();this._deviceState.next({...s,deviceStatus:e})}}export{V as DeviceSession};
|
2
2
|
//# sourceMappingURL=DeviceSession.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSession.ts"],
|
4
|
-
"sourcesContent": ["import { type Either } from \"purify-ts\";\nimport { BehaviorSubject, type Observable } from \"rxjs\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport { type Command } from \"@api/command/Command\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { MutexService } from \"@internal/device-session/service/MutexService\";\nimport { RefresherService } from \"@internal/device-session/service/RefresherService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DevicePinger } from \"./DevicePinger\";\nimport {\n DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"./DeviceSessionEventDispatcher\";\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceSessionStateHandler } from \"./DeviceSessionStateHandler\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\nexport type DeviceSessionRefresherOptions = {\n isRefresherDisabled: boolean;\n pollingInterval?: number;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\n abortTimeout?: number;\n};\n\n/**\n * Represents a session with a device.\n */\nexport class DeviceSession {\n private readonly _id: DeviceSessionId;\n private readonly _connectedDevice: TransportConnectedDevice;\n private readonly _deviceState: BehaviorSubject<DeviceSessionState>;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n private readonly _refresherOptions: DeviceSessionRefresherOptions;\n private _pinger: DevicePinger;\n private _deviceSessionRefresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private _commandMutex = new MutexService();\n private _sessionEventDispatcher = new DeviceSessionEventDispatcher();\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n deviceSessionRefresherOptions: DeviceSessionRefresherOptions | undefined,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._logger = loggerModuleFactory(\"device-session\");\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n this._refresherOptions = {\n ...DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ...deviceSessionRefresherOptions,\n };\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n\n this._pinger = new DevicePinger(\n loggerModuleFactory,\n connectedDevice,\n this._sessionEventDispatcher,\n (command) => this.sendCommand(command),\n );\n this._deviceSessionRefresher = new DeviceSessionRefresher(\n loggerModuleFactory,\n this._refresherOptions,\n this._sessionEventDispatcher,\n this._connectedDevice,\n );\n new DeviceSessionStateHandler(\n loggerModuleFactory,\n this._sessionEventDispatcher,\n this._connectedDevice,\n this._deviceState,\n (state) => this.setDeviceSessionState(state),\n );\n\n this._refresherService = new RefresherService(loggerModuleFactory, {\n start: () => this._deviceSessionRefresher.restartRefresher(),\n stop: () => this._deviceSessionRefresher.stopRefresher(),\n });\n }\n\n public async initialiseSession(): Promise<void> {\n try {\n await this._pinger.ping();\n } catch (error) {\n this._logger.error(\"Error while initialising session\", {\n data: { error },\n });\n throw error;\n } finally {\n if (!this._refresherOptions.isRefresherDisabled) {\n this._deviceSessionRefresher.startRefresher();\n }\n }\n }\n\n public get id(): DeviceSessionId {\n return this._id;\n }\n\n public get connectedDevice(): TransportConnectedDevice {\n return this._connectedDevice;\n }\n\n public get state(): Observable<DeviceSessionState> {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState): void {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n abortTimeout: undefined,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const release = await this._commandMutex.lock();\n\n try {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n const result = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n options.abortTimeout,\n );\n\n result\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_LOCKED,\n });\n } else {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n }\n })\n .ifLeft(() => {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n });\n return result;\n } finally {\n release();\n }\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\n\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\n });\n\n return response.caseOf({\n Left: (err) => {\n throw err;\n },\n Right: (r) =>\n command.parseResponse(r, this._connectedDevice.deviceModel.id),\n });\n }\n\n public executeDeviceAction<\n Output,\n Input,\n E extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, E, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, E, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\n sendApdu: async (apdu: Uint8Array) => this.sendApdu(apdu),\n sendCommand: async <Response, ErrorStatusCodes, Args>(\n command: Command<Response, ErrorStatusCodes, Args>,\n ) => this.sendCommand(command),\n getDeviceSessionState: () => this._deviceState.getValue(),\n getDeviceSessionStateObservable: () => this.state,\n setDeviceSessionState: (state: DeviceSessionState) => {\n this.setDeviceSessionState(state);\n return this._deviceState.getValue();\n },\n disableRefresher: (blockerId: string) =>\n this._refresherService.disableRefresher(blockerId),\n getManagerApiService: () => this._managerApiService,\n getSecureChannelService: () => this._secureChannelService,\n });\n return { observable, cancel };\n }\n\n public close(): void {\n this._updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._deviceSessionRefresher.stopRefresher();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private _updateDeviceStatus(deviceStatus: DeviceStatus): void {\n const state = this._deviceState.getValue();\n this._deviceState.next({ ...state, deviceStatus });\n }\n}\n"],
|
5
|
-
"mappings": "AACA,OAAS,mBAAAA,MAAwC,OACjD,OAAS,MAAMC,MAAc,OAI7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAKP,OAAS,4CAAAC,MAAgD,4DACzD,OAAS,gBAAAC,MAAoB,gDAC7B,OAAS,oBAAAC,MAAwB,oDAIjC,OAAS,gBAAAC,MAAoB,iBAC7B,OACE,gCAAAC,EACA,iBAAAC,MACK,iCACP,OAAS,0BAAAC,MAA8B,2BACvC,OAAS,6BAAAC,MAAiC,8BAqBnC,MAAMC,CAAc,CACR,IACA,iBACA,aACA,mBACA,sBACA,QACA,kBACT,QACA,wBACS,kBACT,cAAgB,IAAIP,EACpB,wBAA0B,IAAIG,EAEtC,YACE,CAAE,gBAAAK,EAAiB,GAAAC,EAAKd,EAAO,CAAE,EACjCe,EACAC,EACAC,EACAC,EACA,CACA,KAAK,IAAMJ,EACX,KAAK,iBAAmBD,EACxB,KAAK,QAAUE,EAAoB,gBAAgB,EACnD,KAAK,mBAAqBC,EAC1B,KAAK,sBAAwBC,EAC7B,KAAK,kBAAoB,CACvB,GAAGb,EACH,GAAGc,CACL,EACA,KAAK,aAAe,IAAInB,EAAoC,CAC1D,iBAAkBI,EAAuB,UACzC,aAAcD,EAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,EACnD,CAAC,EAED,KAAK,QAAU,IAAIK,EACjBQ,EACAF,EACA,KAAK,
|
6
|
-
"names": ["BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS", "MutexService", "RefresherService", "DevicePinger", "DeviceSessionEventDispatcher", "SessionEvents", "DeviceSessionRefresher", "DeviceSessionStateHandler", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "secureChannelService", "deviceSessionRefresherOptions", "command", "state", "error", "rawApdu", "options", "release", "result", "response", "apdu", "err", "
|
4
|
+
"sourcesContent": ["import { type Either } from \"purify-ts\";\nimport { BehaviorSubject, type Observable } from \"rxjs\";\nimport { v4 as uuidv4 } from \"uuid\";\n\nimport { type Command } from \"@api/command/Command\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport {\n type DeviceAction,\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type DmkError } from \"@api/Error\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { type TransportConnectedDevice } from \"@api/transport/model/TransportConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { MutexService } from \"@internal/device-session/service/MutexService\";\nimport { RefresherService } from \"@internal/device-session/service/RefresherService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { DevicePinger } from \"./DevicePinger\";\nimport {\n DeviceSessionEventDispatcher,\n SessionEvents,\n} from \"./DeviceSessionEventDispatcher\";\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceSessionStateHandler } from \"./DeviceSessionStateHandler\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\nexport type DeviceSessionRefresherOptions = {\n isRefresherDisabled: boolean;\n pollingInterval?: number;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\n abortTimeout?: number;\n};\n\n/**\n * Represents a session with a device.\n */\nexport class DeviceSession {\n private readonly _id: DeviceSessionId;\n private readonly _connectedDevice: TransportConnectedDevice;\n private readonly _deviceState: BehaviorSubject<DeviceSessionState>;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n private readonly _logger: LoggerPublisherService;\n private readonly _refresherOptions: DeviceSessionRefresherOptions;\n private _pinger: DevicePinger;\n private _deviceSessionRefresher: DeviceSessionRefresher;\n private readonly _refresherService: RefresherService;\n private _commandMutex = new MutexService();\n private _sessionEventDispatcher = new DeviceSessionEventDispatcher();\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n deviceSessionRefresherOptions: DeviceSessionRefresherOptions | undefined,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._logger = loggerModuleFactory(\"device-session\");\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\n this._refresherOptions = {\n ...DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ...deviceSessionRefresherOptions,\n };\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n });\n\n this._pinger = new DevicePinger(\n loggerModuleFactory,\n connectedDevice,\n this._sessionEventDispatcher,\n (command, abortTimeout) => this.sendCommand(command, abortTimeout),\n );\n this._deviceSessionRefresher = new DeviceSessionRefresher(\n loggerModuleFactory,\n this._refresherOptions,\n this._sessionEventDispatcher,\n this._connectedDevice,\n );\n new DeviceSessionStateHandler(\n loggerModuleFactory,\n this._sessionEventDispatcher,\n this._connectedDevice,\n this._deviceState,\n (state) => this.setDeviceSessionState(state),\n );\n\n this._refresherService = new RefresherService(loggerModuleFactory, {\n start: () => this._deviceSessionRefresher.restartRefresher(),\n stop: () => this._deviceSessionRefresher.stopRefresher(),\n });\n }\n\n public async initialiseSession(): Promise<void> {\n try {\n await this._pinger.ping();\n } catch (error) {\n this._logger.error(\"Error while initialising session\", {\n data: { error },\n });\n throw error;\n } finally {\n if (!this._refresherOptions.isRefresherDisabled) {\n this._deviceSessionRefresher.startRefresher();\n }\n }\n }\n\n public get id(): DeviceSessionId {\n return this._id;\n }\n\n public get connectedDevice(): TransportConnectedDevice {\n return this._connectedDevice;\n }\n\n public get state(): Observable<DeviceSessionState> {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState): void {\n this._deviceState.next(state);\n }\n\n public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n abortTimeout: undefined,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const release = await this._commandMutex.lock();\n\n try {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_BUSY,\n });\n const result = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n options.abortTimeout,\n );\n\n result\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_LOCKED,\n });\n } else {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n }\n })\n .ifLeft(() => {\n this._sessionEventDispatcher.dispatch({\n eventName: SessionEvents.DEVICE_STATE_UPDATE_CONNECTED,\n });\n });\n return result;\n } finally {\n release();\n }\n }\n\n public async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n abortTimeout?: number,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\n\n const response = await this.sendApdu(apdu.getRawApdu(), {\n isPolling: false,\n triggersDisconnection: command.triggersDisconnection ?? false,\n abortTimeout,\n });\n\n return response.caseOf({\n Left: (err) => {\n throw err;\n },\n Right: (r) =>\n command.parseResponse(r, this._connectedDevice.deviceModel.id),\n });\n }\n\n public executeDeviceAction<\n Output,\n Input,\n E extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, E, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, E, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\n sendApdu: async (apdu: Uint8Array) => this.sendApdu(apdu),\n sendCommand: async <Response, ErrorStatusCodes, Args>(\n command: Command<Response, ErrorStatusCodes, Args>,\n abortTimeout?: number,\n ) => this.sendCommand(command, abortTimeout),\n getDeviceSessionState: () => this._deviceState.getValue(),\n getDeviceSessionStateObservable: () => this.state,\n setDeviceSessionState: (state: DeviceSessionState) => {\n this.setDeviceSessionState(state);\n return this._deviceState.getValue();\n },\n disableRefresher: (blockerId: string) =>\n this._refresherService.disableRefresher(blockerId),\n getManagerApiService: () => this._managerApiService,\n getSecureChannelService: () => this._secureChannelService,\n });\n return { observable, cancel };\n }\n\n public close(): void {\n this._updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._deviceSessionRefresher.stopRefresher();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\n }\n\n private _updateDeviceStatus(deviceStatus: DeviceStatus): void {\n const state = this._deviceState.getValue();\n this._deviceState.next({ ...state, deviceStatus });\n }\n}\n"],
|
5
|
+
"mappings": "AACA,OAAS,mBAAAA,MAAwC,OACjD,OAAS,MAAMC,MAAc,OAI7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAKP,OAAS,4CAAAC,MAAgD,4DACzD,OAAS,gBAAAC,MAAoB,gDAC7B,OAA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AC,EAAY,OAAAC,CAAO,EAAIF,EAAa,SAAS,CACnD,SAAU,MAAOF,GAAqB,KAAK,SAASA,CAAI,EACxD,YAAa,MACXT,EACAC,IACG,KAAK,YAAYD,EAASC,CAAY,EAC3C,sBAAuB,IAAM,KAAK,aAAa,SAAS,EACxD,gCAAiC,IAAM,KAAK,MAC5C,sBAAwBC,IACtB,KAAK,sBAAsBA,CAAK,EACzB,KAAK,aAAa,SAAS,GAEpC,iBAAmBY,GACjB,KAAK,kBAAkB,iBAAiBA,CAAS,EACnD,qBAAsB,IAAM,KAAK,mBACjC,wBAAyB,IAAM,KAAK,qBACtC,CAAC,EACD,MAAO,CAAE,WAAAF,EAAY,OAAAC,CAAO,CAC9B,CAEO,OAAc,CACnB,KAAK,oBAAoB9B,EAAa,aAAa,EACnD,KAAK,aAAa,SAAS,EAC3B,KAAK,wBAAwB,cAAc,CAC7C,CAEO,iBAAiBY,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,oBAAoBoB,EAAkC,CAC5D,MAAMb,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,aAAa,KAAK,CAAE,GAAGA,EAAO,aAAAa,CAAa,CAAC,CACnD,CACF",
|
6
|
+
"names": ["BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS", "MutexService", "RefresherService", "DevicePinger", "DeviceSessionEventDispatcher", "SessionEvents", "DeviceSessionRefresher", "DeviceSessionStateHandler", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "secureChannelService", "deviceSessionRefresherOptions", "command", "abortTimeout", "state", "error", "rawApdu", "options", "release", "result", "response", "apdu", "err", "deviceAction", "observable", "cancel", "blockerId", "deviceStatus"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{DeviceSessionStateType as o,DeviceStatus as t,isSuccessCommandResult as v}from"../../../api/index";import{SessionEvents as i}from"../../device-session/model/DeviceSessionEventDispatcher";class D{constructor(e,s,n,r
|
1
|
+
import{DeviceSessionStateType as o,DeviceStatus as t,isSuccessCommandResult as v}from"../../../api/index";import{SessionEvents as i}from"../../device-session/model/DeviceSessionEventDispatcher";class D{constructor(e,s,n,a,r){this._sessionEventDispatcher=s;this._connectedDevice=n;this._deviceState=a;this.setDeviceSessionState=r;this._subscription=this._sessionEventDispatcher.listen().subscribe(c=>this.mapEventAction(c)),this._logger=e("device-session-state-handler")}_subscription;_logger;_updateDeviceState(e){const s=this._parseDeviceStatus(e);if(s){const{sessionStateType:n,deviceStatus:a,currentApp:r}=s;this.setDeviceSessionState({sessionStateType:n,deviceStatus:a,deviceModelId:this._connectedDevice.deviceModel.id,currentApp:r,installedApps:[],isSecureConnectionAllowed:!1})}}mapEventAction=e=>{switch(e.eventName){case i.COMMAND_SUCCEEDED:return this._updateDeviceState(e.eventData);case i.DEVICE_STATE_UPDATE_BUSY:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.BUSY});case i.DEVICE_STATE_UPDATE_LOCKED:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.LOCKED});case i.DEVICE_STATE_UPDATE_CONNECTED:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.CONNECTED});default:return null}};_parseDeviceStatus(e){return v(e)?{sessionStateType:o.ReadyWithoutSecureChannel,deviceStatus:t.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()}}export{D as 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\n this.setDeviceSessionState({\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n }\n\n private mapEventAction = (event: NewEvent) => {\n switch (event.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 return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.LOCKED,\n });\n case SessionEvents.DEVICE_STATE_UPDATE_CONNECTED:\n return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.CONNECTED,\n });\n default:\n return null;\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.
|
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\n this.setDeviceSessionState({\n sessionStateType,\n deviceStatus,\n deviceModelId: this._connectedDevice.deviceModel.id,\n currentApp,\n installedApps: [],\n isSecureConnectionAllowed: false,\n });\n }\n }\n\n private mapEventAction = (event: NewEvent) => {\n switch (event.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 return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.LOCKED,\n });\n case SessionEvents.DEVICE_STATE_UPDATE_CONNECTED:\n return this.setDeviceSessionState({\n ...this._deviceState.getValue(),\n deviceStatus: DeviceStatus.CONNECTED,\n });\n default:\n return null;\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
5
|
"mappings": "AAGA,OACE,0BAAAA,EACA,gBAAAC,EAEA,0BAAAC,MAEK,aAEP,OAGE,iBAAAC,MACK,8DAaA,MAAMC,CAA0B,CAIrC,YACEC,EACQ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CAEO,aAAoB,CACzB,KAAK,cAAc,YAAY,CACjC,CACF",
|
6
6
|
"names": ["DeviceSessionStateType", "DeviceStatus", "isSuccessCommandResult", "SessionEvents", "DeviceSessionStateHandler", "loggerModuleFactory", "_sessionEventDispatcher", "_connectedDevice", "_deviceState", "setDeviceSessionState", "event", "parsedResponse", "newDeviceStatus", "sessionStateType", "deviceStatus", "currentApp"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{BehaviorSubject as E,Subject as u}from"rxjs";import{expect as e}from"vitest";import{CommandResultStatus as D,DeviceModelId as C,DeviceSessionStateType as l,DeviceStatus as i}from"../../../api/index";import{SessionEvents as o}from"../../device-session/model/DeviceSessionEventDispatcher";import{DeviceSessionStateHandler as
|
1
|
+
import{BehaviorSubject as E,Subject as u}from"rxjs";import{expect as e}from"vitest";import{CommandResultStatus as D,DeviceModelId as C,DeviceSessionStateType as l,DeviceStatus as i}from"../../../api/index";import{SessionEvents as o}from"../../device-session/model/DeviceSessionEventDispatcher";import{DeviceSessionStateHandler as m}from"./DeviceSessionStateHandler";describe("DeviceSessionStateHandler",()=>{let t,c,r;const S=vi.fn(()=>r);let d,v,n,a;beforeEach(()=>{t=new u,c={listen:()=>t,dispatch:vi.fn()},r={error:vi.fn(),debug:vi.fn()},d={deviceModel:{id:"device-model-1"}},v=new E({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,deviceModelId:C.NANO_X,currentApp:{name:"",version:""},installedApps:[],isSecureConnectionAllowed:!1}),n=vi.fn(),a=new m(S,c,d,v,n)}),afterEach(()=>{a&&typeof a.unsubscribe=="function"&&a.unsubscribe()}),it("updates device state on COMMAND_SUCCEEDED event with a successful response",()=>{const s={data:{name:"TestApp",version:"1.0.0"},status:D.Success};t.next({eventName:o.COMMAND_SUCCEEDED,eventData:s}),e(n).toHaveBeenCalledWith({sessionStateType:l.ReadyWithoutSecureChannel,deviceStatus:i.CONNECTED,deviceModelId:"device-model-1",currentApp:{name:"TestApp",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:!1})}),it("updates device state on DEVICE_STATE_UPDATE_BUSY event",()=>{t.next({eventName:o.DEVICE_STATE_UPDATE_BUSY}),e(n).toHaveBeenCalledWith(e.objectContaining({deviceStatus:i.BUSY}))}),it("updates device state on DEVICE_STATE_UPDATE_CONNECTED event",()=>{t.next({eventName:o.DEVICE_STATE_UPDATE_CONNECTED}),e(n).toHaveBeenCalledWith(e.objectContaining({deviceStatus:i.CONNECTED}))}),it("logs error and does not update state if command result is unsuccessful",()=>{const s={data:null,error:{_tag:"SomeOtherError"}};t.next({eventName:o.COMMAND_SUCCEEDED,eventData:s}),e(r.debug).toHaveBeenCalledWith("Error while parsing APDU response",{data:{parsedResponse:s}}),e(n).not.toHaveBeenCalled()}),it("does not update state if command result is not a success",()=>{const s={data:null,error:{_tag:"SomeOtherError"}};t.next({eventName:o.COMMAND_SUCCEEDED,eventData:s}),e(n).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\";\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 };\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 };\n\n fakeConnectedDevice = {\n deviceModel: {\n id: \"device-model-1\",\n },\n };\n\n deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n currentApp: { name: \"\", version: \"\" },\n installedApps: [],\n isSecureConnectionAllowed: false,\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 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.
|
5
|
-
"mappings": "AAAA,OAAS,mBAAAA,EAAiB,WAAAC,MAAe,OACzC,OAAS,UAAAC,MAAyB,SAGlC,OACE,uBAAAC,EACA,iBAAAC,EACA,0BAAAC,EACA,gBAAAC,MACK,aACP,OAGE,iBAAAC,MACK,8DAEP,OACE,6BAAAC,MAEK,8BAEP,SAAS,4BAA6B,IAAM,CAC1C,IAAIC,EACAC,EACAC,
|
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\";\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.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: DeviceModelId.NANO_X,\n currentApp: { name: \"\", version: \"\" },\n installedApps: [],\n isSecureConnectionAllowed: false,\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 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,OAAS,mBAAAA,EAAiB,WAAAC,MAAe,OACzC,OAA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AAM,CAEjEG,EAAiB,KAAK,CACpB,UAAWF,EAAc,wBAC3B,CAAC,EAGDL,EAAOa,CAAqB,EAAE,qBAC5Bb,EAAO,iBAAiB,CAAE,aAAcI,EAAa,IAAK,CAAC,CAC7D,CACF,CAAC,EAED,GAAG,8DAA+D,IAAM,CAEtEG,EAAiB,KAAK,CACpB,UAAWF,EAAc,6BAC3B,CAAC,EAGDL,EAAOa,CAAqB,EAAE,qBAC5Bb,EAAO,iBAAiB,CAAE,aAAcI,EAAa,SAAU,CAAC,CAClE,CACF,CAAC,EAED,GAAG,yEAA0E,IAAM,CAEjF,MAAMY,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAWF,EAAc,kBAEzB,UAAWW,CACb,CAAC,EAGDhB,EAAOS,EAAW,KAAK,EAAE,qBACvB,oCACA,CAAE,KAAM,CAAE,eAAgBO,CAAuB,CAAE,CACrD,EACAhB,EAAOa,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,UAAWF,EAAc,kBAEzB,UAAWW,CACb,CAAC,EAGDhB,EAAOa,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,CACH,CAAC",
|
6
6
|
"names": ["BehaviorSubject", "Subject", "expect", "CommandResultStatus", "DeviceModelId", "DeviceSessionStateType", "DeviceStatus", "SessionEvents", "DeviceSessionStateHandler", "fakeEventSubject", "fakeSessionEventDispatcher", "mockLogger", "mockLoggerModuleFactory", "fakeConnectedDevice", "deviceState", "setDeviceSessionState", "handler", "fakeCommandResult", "fakeErrorCommandResult"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var m=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var v=(n,r,t,o)=>{for(var e=o>1?void 0:o?g(r,t):r,i=n.length-1,s;i>=0;i--)(s=n[i])&&(e=(o?s(r,t,e):s(e))||e);return o&&e&&m(r,t,e),e},p=(n,r)=>(t,o)=>r(t,o,n);import{inject as l,injectable as D}from"inversify";import{from as d,map as c,merge as T,of as f,scan as h}from"rxjs";import{DeviceModel as b}from"../../../api/device/DeviceModel";import{loggerTypes as u}from"../../logger-publisher/di/loggerTypes";import{transportDiTypes as _}from"../../transport/di/transportDiTypes";let a=class{_transports;_transportService;_logger;constructor(r,t){this._transports=r.getAllTransports(),this._transportService=r,this._logger=t("ListenToAvailableDevicesUseCase")}mapTransportDiscoveredDeviceToDiscoveredDevice(r){const t=new b({id:r.id,model:r.deviceModel.id,name:r.deviceModel.productName});return{id:r.id,deviceModel:t,transport:r.transport,name:r.name||t.name,rssi:r.rssi}}execute({transport:r}){if(this._logger.info("Listening to available devices"),this._transports.length===0)return this._logger.warn("No transports available"),d([[]]);if(!r){this._logger.info("Discovering all available transports");const o=this._transports.map((e,i)=>e.listenToAvailableDevices().pipe(c(s=>({index:i,arr:s}))));return T(...o).pipe(h((e,{index:i,arr:s})=>(e[i]=s,e),{}),c(e=>Object.values(e).flat().map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))}return this._logger.info(`Discovering devices on transport ${r}`),this._transportService.getTransport(r).caseOf({Nothing:()=>(this._logger.error(`Transport ${r} not found`),f([])),Just:o=>o.listenToAvailableDevices().pipe(c(e=>e.map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))})}};a=v([D(),p(0,l(_.TransportService)),p(1,l(u.LoggerPublisherServiceFactory))],a);export{a as ListenToAvailableDevicesUseCase};
|
1
|
+
var m=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var v=(n,r,t,o)=>{for(var e=o>1?void 0:o?g(r,t):r,i=n.length-1,s;i>=0;i--)(s=n[i])&&(e=(o?s(r,t,e):s(e))||e);return o&&e&&m(r,t,e),e},p=(n,r)=>(t,o)=>r(t,o,n);import{inject as l,injectable as D}from"inversify";import{from as d,map as c,merge as T,of as f,scan as h}from"rxjs";import{DeviceModel as b}from"../../../api/device/DeviceModel";import{loggerTypes as u}from"../../logger-publisher/di/loggerTypes";import{transportDiTypes as _}from"../../transport/di/transportDiTypes";let a=class{_transports;_transportService;_logger;constructor(r,t){this._transports=r.getAllTransports(),this._transportService=r,this._logger=t("ListenToAvailableDevicesUseCase")}mapTransportDiscoveredDeviceToDiscoveredDevice(r){const t=new b({id:r.id,model:r.deviceModel.id,name:r.deviceModel.productName});return{id:r.id,deviceModel:t,transport:r.transport,name:r.name||t.name,rssi:r.rssi}}execute({transport:r}={}){if(this._logger.info("Listening to available devices"),this._transports.length===0)return this._logger.warn("No transports available"),d([[]]);if(!r){this._logger.info("Discovering all available transports");const o=this._transports.map((e,i)=>e.listenToAvailableDevices().pipe(c(s=>({index:i,arr:s}))));return T(...o).pipe(h((e,{index:i,arr:s})=>(e[i]=s,e),{}),c(e=>Object.values(e).flat().map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))}return this._logger.info(`Discovering devices on transport ${r}`),this._transportService.getTransport(r).caseOf({Nothing:()=>(this._logger.error(`Transport ${r} not found`),f([])),Just:o=>o.listenToAvailableDevices().pipe(c(e=>e.map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))})}};a=v([D(),p(0,l(_.TransportService)),p(1,l(u.LoggerPublisherServiceFactory))],a);export{a as ListenToAvailableDevicesUseCase};
|
2
2
|
//# sourceMappingURL=ListenToAvailableDevicesUseCase.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/ListenToAvailableDevicesUseCase.ts"],
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { from, map, merge, Observable, of, scan } from \"rxjs\";\n\nimport { DeviceModel } from \"@api/device/DeviceModel\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { type Transport } from \"@api/transport/model/Transport\";\nimport { type TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nimport { type TransportIdentifier } from \"@api/transport/model/TransportIdentifier\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nexport type ListenToAvailableDevicesUseCaseArgs = {\n /**\n * Identifier of the transport to start discovering devices.\n * Can be undefined to discover all available transports in parallel.\n */\n transport?: TransportIdentifier;\n};\n\n/**\n * Listen to list of known discovered devices (and later BLE).\n */\n@injectable()\nexport class ListenToAvailableDevicesUseCase {\n private readonly _transports: Transport[];\n private readonly _transportService: TransportService;\n private readonly _logger: LoggerPublisherService;\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._transports = transportService.getAllTransports();\n this._transportService = transportService;\n this._logger = loggerFactory(\"ListenToAvailableDevicesUseCase\");\n }\n\n private mapTransportDiscoveredDeviceToDiscoveredDevice(\n discoveredDevice: TransportDiscoveredDevice,\n ): DiscoveredDevice {\n const deviceModel = new DeviceModel({\n id: discoveredDevice.id,\n model: discoveredDevice.deviceModel.id,\n name: discoveredDevice.deviceModel.productName,\n });\n return {\n id: discoveredDevice.id,\n deviceModel,\n transport: discoveredDevice.transport,\n name: discoveredDevice.name || deviceModel.name,\n rssi: discoveredDevice.rssi,\n };\n }\n\n execute({
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,QAAAC,EAAM,OAAAC,EAAK,SAAAC,EAAmB,MAAAC,EAAI,QAAAC,MAAY,OAEvD,OAAS,eAAAC,MAAmB,0BAM5B,OAAS,eAAAC,MAAmB,4CAC5B,OAAS,oBAAAC,MAAwB,0CAe1B,IAAMC,EAAN,KAAsC,CAC1B,YACA,kBACA,QACjB,YAEEC,EAEAC,EACA,CACA,KAAK,YAAcD,EAAiB,iBAAiB,EACrD,KAAK,kBAAoBA,EACzB,KAAK,QAAUC,EAAc,iCAAiC,CAChE,CAEQ,+CACNC,EACkB,CAClB,MAAMC,EAAc,IAAIC,EAAY,CAClC,GAAIF,EAAiB,GACrB,MAAOA,EAAiB,YAAY,GACpC,KAAMA,EAAiB,YAAY,WACrC,CAAC,EACD,MAAO,CACL,GAAIA,EAAiB,GACrB,YAAAC,EACA,UAAWD,EAAiB,UAC5B,KAAMA,EAAiB,MAAQC,EAAY,KAC3C,KAAMD,EAAiB,IACzB,CACF,CAEA,QAAQ,
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { from, map, merge, Observable, of, scan } from \"rxjs\";\n\nimport { DeviceModel } from \"@api/device/DeviceModel\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { type Transport } from \"@api/transport/model/Transport\";\nimport { type TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nimport { type TransportIdentifier } from \"@api/transport/model/TransportIdentifier\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nexport type ListenToAvailableDevicesUseCaseArgs = {\n /**\n * Identifier of the transport to start discovering devices.\n * Can be undefined to discover all available transports in parallel.\n */\n transport?: TransportIdentifier;\n};\n\n/**\n * Listen to list of known discovered devices (and later BLE).\n */\n@injectable()\nexport class ListenToAvailableDevicesUseCase {\n private readonly _transports: Transport[];\n private readonly _transportService: TransportService;\n private readonly _logger: LoggerPublisherService;\n constructor(\n @inject(transportDiTypes.TransportService)\n transportService: TransportService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._transports = transportService.getAllTransports();\n this._transportService = transportService;\n this._logger = loggerFactory(\"ListenToAvailableDevicesUseCase\");\n }\n\n private mapTransportDiscoveredDeviceToDiscoveredDevice(\n discoveredDevice: TransportDiscoveredDevice,\n ): DiscoveredDevice {\n const deviceModel = new DeviceModel({\n id: discoveredDevice.id,\n model: discoveredDevice.deviceModel.id,\n name: discoveredDevice.deviceModel.productName,\n });\n return {\n id: discoveredDevice.id,\n deviceModel,\n transport: discoveredDevice.transport,\n name: discoveredDevice.name || deviceModel.name,\n rssi: discoveredDevice.rssi,\n };\n }\n\n execute({ transport }: ListenToAvailableDevicesUseCaseArgs = {}): Observable<\n DiscoveredDevice[]\n > {\n this._logger.info(\"Listening to available devices\");\n\n if (this._transports.length === 0) {\n this._logger.warn(\"No transports available\");\n return from([[]]);\n }\n\n if (!transport) {\n this._logger.info(\"Discovering all available transports\");\n /**\n * Note: we're not using combineLatest because combineLatest will\n * - wait for all observables to emit at least once before emitting.\n * - complete as soon as one of the observables completes.\n * Some transports will just return an empty array and complete.\n * We want to keep listening to all transports until all have completed.\n */\n\n const observablesWithIndex = this._transports.map((t, index) =>\n t.listenToAvailableDevices().pipe(\n map((arr) => ({\n index,\n arr,\n })),\n ),\n );\n\n return merge(...observablesWithIndex).pipe(\n scan<\n { index: number; arr: TransportDiscoveredDevice[] },\n { [key: number]: TransportDiscoveredDevice[] }\n >((acc, { index, arr }) => {\n acc[index] = arr;\n return acc;\n }, {}),\n map((acc) =>\n Object.values(acc)\n .flat()\n .map(this.mapTransportDiscoveredDeviceToDiscoveredDevice),\n ),\n );\n }\n\n this._logger.info(`Discovering devices on transport ${transport}`);\n\n const instance = this._transportService.getTransport(transport);\n\n return instance.caseOf({\n Nothing: () => {\n this._logger.error(`Transport ${transport} not found`);\n return of([]);\n },\n Just: (t) => {\n return t\n .listenToAvailableDevices()\n .pipe(\n map((devices) =>\n devices.map(this.mapTransportDiscoveredDeviceToDisco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,CAAC,EACLJ,EAAKI,GACH,OAAO,OAAOA,CAAG,EACd,KAAK,EACL,IAAI,KAAK,8CAA8C,CAC5D,CACF,CACF,CAEA,YAAK,QAAQ,KAAK,oCAAoCT,CAAS,EAAE,EAEhD,KAAK,kBAAkB,aAAaA,CAAS,EAE9C,OAAO,CACrB,QAAS,KACP,KAAK,QAAQ,MAAM,aAAaA,CAAS,YAAY,EAC9CU,EAAG,CAAC,CAAC,GAEd,KAAOP,GACEA,EACJ,yBAAyB,EACzB,KACCE,EAAKM,GACHA,EAAQ,IAAI,KAAK,8CAA8C,CACjE,CACF,CAEN,CAAC,CACH,CACF,EAjGajB,EAANkB,EAAA,CADNC,EAAW,EAMPC,EAAA,EAAAC,EAAOC,EAAiB,gBAAgB,GAExCF,EAAA,EAAAC,EAAOE,EAAY,6BAA6B,IAPxCvB",
|
6
6
|
"names": ["inject", "injectable", "from", "map", "merge", "of", "scan", "DeviceModel", "loggerTypes", "transportDiTypes", "ListenToAvailableDevicesUseCase", "transportService", "loggerFactory", "discoveredDevice", "deviceModel", "DeviceModel", "transport", "from", "observablesWithIndex", "t", "index", "map", "arr", "merge", "scan", "acc", "of", "devices", "__decorateClass", "injectable", "__decorateParam", "inject", "transportDiTypes", "loggerTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var v=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var a=(i,r,o,t)=>{for(var e=t>1?void 0:t?d(r,o):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(e=(t?n(r,o,e):n(e))||e);return t&&e&&v(r,o,e),e},c=(i,r)=>(o,t)=>r(o,t,i);import{inject as D,injectable as f}from"inversify";import{map as m,mergeMap as l,of as T}from"rxjs";import{DeviceModel as u}from"../../../api/device/DeviceModel";import{TransportNotSupportedError as g}from"../../../api/transport/model/Errors";import{transportDiTypes as h}from"../../transport/di/transportDiTypes";let p=class{constructor(r){this._transportService=r}mapDiscoveredDevice(r){const o=new u({id:r.id,model:r.deviceModel.id,name:r.deviceModel.productName});return{id:r.id,deviceModel:o,transport:r.transport,name:r.name||o.name,rssi:r.rssi}}execute({transport:r}){if(!r){const t=this._transportService.getAllTransports();return T(...t).pipe(l(e=>e.startDiscovering().pipe(m(s=>this.mapDiscoveredDevice(s)))))}return this._transportService.getTransport(r).caseOf({Just:t=>t.startDiscovering().pipe(m(e=>this.mapDiscoveredDevice(e))),Nothing:()=>{throw new g(new Error("Unknown transport"))}})}};p=a([f(),c(0,D(h.TransportService))],p);export{p as StartDiscoveringUseCase};
|
1
|
+
var v=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var a=(i,r,o,t)=>{for(var e=t>1?void 0:t?d(r,o):r,s=i.length-1,n;s>=0;s--)(n=i[s])&&(e=(t?n(r,o,e):n(e))||e);return t&&e&&v(r,o,e),e},c=(i,r)=>(o,t)=>r(o,t,i);import{inject as D,injectable as f}from"inversify";import{map as m,mergeMap as l,of as T}from"rxjs";import{DeviceModel as u}from"../../../api/device/DeviceModel";import{TransportNotSupportedError as g}from"../../../api/transport/model/Errors";import{transportDiTypes as h}from"../../transport/di/transportDiTypes";let p=class{constructor(r){this._transportService=r}mapDiscoveredDevice(r){const o=new u({id:r.id,model:r.deviceModel.id,name:r.deviceModel.productName});return{id:r.id,deviceModel:o,transport:r.transport,name:r.name||o.name,rssi:r.rssi}}execute({transport:r}={}){if(!r){const t=this._transportService.getAllTransports();return T(...t).pipe(l(e=>e.startDiscovering().pipe(m(s=>this.mapDiscoveredDevice(s)))))}return this._transportService.getTransport(r).caseOf({Just:t=>t.startDiscovering().pipe(m(e=>this.mapDiscoveredDevice(e))),Nothing:()=>{throw new g(new Error("Unknown transport"))}})}};p=a([f(),c(0,D(h.TransportService))],p);export{p as StartDiscoveringUseCase};
|
2
2
|
//# sourceMappingURL=StartDiscoveringUseCase.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/StartDiscoveringUseCase.ts"],
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { map, mergeMap, Observable, of } from \"rxjs\";\n\nimport { DeviceModel } from \"@api/device/DeviceModel\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nimport { TransportIdentifier } from \"@api/transport/model/TransportIdentifier\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nexport type StartDiscoveringUseCaseArgs = {\n /**\n * Identifier of the transport to start discovering devices.\n * Can be undefined to discover all available transports in parralel.\n */\n transport?: TransportIdentifier;\n};\n\n/**\n * Starts discovering devices connected.\n *\n * For the WebHID implementation, this use-case needs to be called as a result of an user interaction (button \"click\" event for ex).\n */\n@injectable()\nexport class StartDiscoveringUseCase {\n constructor(\n @inject(transportDiTypes.TransportService)\n private readonly _transportService: TransportService,\n ) {}\n\n private mapDiscoveredDevice(\n device: TransportDiscoveredDevice,\n ): DiscoveredDevice {\n const deviceModel = new DeviceModel({\n id: device.id,\n model: device.deviceModel.id,\n name: device.deviceModel.productName,\n });\n return {\n id: device.id,\n deviceModel,\n transport: device.transport,\n name: device.name || deviceModel.name,\n rssi: device.rssi,\n };\n }\n\n execute({\n transport,\n }: StartDiscoveringUseCaseArgs): Observable<DiscoveredDevice> {\n if (!transport) {\n const transports = this._transportService.getAllTransports();\n return of(...transports).pipe(\n mergeMap((instance) =>\n instance\n .startDiscovering()\n .pipe(map((device) => this.mapDiscoveredDevice(device))),\n ),\n );\n }\n\n const instance = this._transportService.getTransport(transport);\n\n return instance.caseOf({\n Just: (t) => {\n return t\n .startDiscovering()\n .pipe(map((device) => this.mapDiscoveredDevice(device)));\n },\n Nothing: () => {\n throw new TransportNotSupportedError(new Error(\"Unknown transport\"));\n },\n });\n }\n}\n"],
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,OAAAC,EAAK,YAAAC,EAAsB,MAAAC,MAAU,OAE9C,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,8BAAAC,MAAkC,8BAG3C,OAAS,oBAAAC,MAAwB,0CAiB1B,IAAMC,EAAN,KAA8B,CACnC,YAEmBC,EACjB,CADiB,uBAAAA,CAChB,CAEK,oBACNC,EACkB,CAClB,MAAMC,EAAc,IAAIC,EAAY,CAClC,GAAIF,EAAO,GACX,MAAOA,EAAO,YAAY,GAC1B,KAAMA,EAAO,YAAY,WAC3B,CAAC,EACD,MAAO,CACL,GAAIA,EAAO,GACX,YAAAC,EACA,UAAWD,EAAO,UAClB,KAAMA,EAAO,MAAQC,EAAY,KACjC,KAAMD,EAAO,IACf,CACF,CAEA,QAAQ,CACN,UAAAG,CACF,
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { map, mergeMap, Observable, of } from \"rxjs\";\n\nimport { DeviceModel } from \"@api/device/DeviceModel\";\nimport { DiscoveredDevice } from \"@api/transport/model/DiscoveredDevice\";\nimport { TransportNotSupportedError } from \"@api/transport/model/Errors\";\nimport { TransportDiscoveredDevice } from \"@api/transport/model/TransportDiscoveredDevice\";\nimport { TransportIdentifier } from \"@api/transport/model/TransportIdentifier\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nexport type StartDiscoveringUseCaseArgs = {\n /**\n * Identifier of the transport to start discovering devices.\n * Can be undefined to discover all available transports in parralel.\n */\n transport?: TransportIdentifier;\n};\n\n/**\n * Starts discovering devices connected.\n *\n * For the WebHID implementation, this use-case needs to be called as a result of an user interaction (button \"click\" event for ex).\n */\n@injectable()\nexport class StartDiscoveringUseCase {\n constructor(\n @inject(transportDiTypes.TransportService)\n private readonly _transportService: TransportService,\n ) {}\n\n private mapDiscoveredDevice(\n device: TransportDiscoveredDevice,\n ): DiscoveredDevice {\n const deviceModel = new DeviceModel({\n id: device.id,\n model: device.deviceModel.id,\n name: device.deviceModel.productName,\n });\n return {\n id: device.id,\n deviceModel,\n transport: device.transport,\n name: device.name || deviceModel.name,\n rssi: device.rssi,\n };\n }\n\n execute({\n transport,\n }: StartDiscoveringUseCaseArgs = {}): Observable<DiscoveredDevice> {\n if (!transport) {\n const transports = this._transportService.getAllTransports();\n return of(...transports).pipe(\n mergeMap((instance) =>\n instance\n .startDiscovering()\n .pipe(map((device) => this.mapDiscoveredDevice(device))),\n ),\n );\n }\n\n const instance = this._transportService.getTransport(transport);\n\n return instance.caseOf({\n Just: (t) => {\n return t\n .startDiscovering()\n .pipe(map((device) => this.mapDiscoveredDevice(device)));\n },\n Nothing: () => {\n throw new TransportNotSupportedError(new Error(\"Unknown transport\"));\n },\n });\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,OAAAC,EAAK,YAAAC,EAAsB,MAAAC,MAAU,OAE9C,OAAS,eAAAC,MAAmB,0BAE5B,OAAS,8BAAAC,MAAkC,8BAG3C,OAAS,oBAAAC,MAAwB,0CAiB1B,IAAMC,EAAN,KAA8B,CACnC,YAEmBC,EACjB,CADiB,uBAAAA,CAChB,CAEK,oBACNC,EACkB,CAClB,MAAMC,EAAc,IAAIC,EAAY,CAClC,GAAIF,EAAO,GACX,MAAOA,EAAO,YAAY,GAC1B,KAAMA,EAAO,YAAY,WAC3B,CAAC,EACD,MAAO,CACL,GAAIA,EAAO,GACX,YAAAC,EACA,UAAWD,EAAO,UAClB,KAAMA,EAAO,MAAQC,EAAY,KACjC,KAAMD,EAAO,IACf,CACF,CAEA,QAAQ,CACN,UAAAG,CACF,EAAiC,CAAC,EAAiC,CACjE,GAAI,CAACA,EAAW,CACd,MAAMC,EAAa,KAAK,kBAAkB,iBAAiB,EAC3D,OAAOC,EAAG,GAAGD,CAAU,EAAE,KACvBE,EAAUC,GACRA,EACG,iBAAiB,EACjB,KAAKC,EAAKR,GAAW,KAAK,oBAAoBA,CAAM,CAAC,CAAC,CAC3D,CACF,CACF,CAIA,OAFiB,KAAK,kBAAkB,aAAaG,CAAS,EAE9C,OAAO,CACrB,KAAO,GACE,EACJ,iBAAiB,EACjB,KAAKK,EAAKR,GAAW,KAAK,oBAAoBA,CAAM,CAAC,CAAC,EAE3D,QAAS,IAAM,CACb,MAAM,IAAIS,EAA2B,IAAI,MAAM,mBAAmB,CAAC,CACrE,CACF,CAAC,CACH,CACF,EAlDaX,EAANY,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,gBAAgB,IAFhChB",
|
6
6
|
"names": ["inject", "injectable", "map", "mergeMap", "of", "DeviceModel", "TransportNotSupportedError", "transportDiTypes", "StartDiscoveringUseCase", "_transportService", "device", "deviceModel", "DeviceModel", "transport", "transports", "of", "mergeMap", "instance", "map", "TransportNotSupportedError", "__decorateClass", "injectable", "__decorateParam", "inject", "transportDiTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var
|
1
|
+
var m=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var n=(e,r,p,o)=>{for(var t=o>1?void 0:o?f(r,p):r,a=e.length-1,c;a>=0;a--)(c=e[a])&&(t=(o?c(r,p,t):c(t))||t);return o&&t&&m(r,p,t),t},s=(e,r)=>(p,o)=>r(p,o,e);import{inject as v,injectable as T}from"inversify";import{transportDiTypes as l}from"../../transport/di/transportDiTypes";let i=class{constructor(r){this.transportService=r}async execute(){for(const r of this.transportService.getAllTransports())await r.stopDiscovering()}};i=n([T(),s(0,v(l.TransportService))],i);export{i as StopDiscoveringUseCase};
|
2
2
|
//# sourceMappingURL=StopDiscoveringUseCase.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/StopDiscoveringUseCase.ts"],
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * Stops discovering devices connected.\n */\n@injectable()\nexport class StopDiscoveringUseCase {\n constructor(\n @inject(transportDiTypes.TransportService)\n private transportService: TransportService,\n ) {}\n\n execute(): void {\n for (const transport of this.transportService.getAllTransports()) {\n transport.stopDiscovering();\n }\n }\n}\n"],
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,oBAAAC,MAAwB,0CAO1B,IAAMC,EAAN,KAA6B,CAClC,YAEUC,EACR,CADQ,sBAAAA,CACP,CAEH,
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\n/**\n * Stops discovering devices connected.\n */\n@injectable()\nexport class StopDiscoveringUseCase {\n constructor(\n @inject(transportDiTypes.TransportService)\n private transportService: TransportService,\n ) {}\n\n async execute(): Promise<void> {\n for (const transport of this.transportService.getAllTransports()) {\n await transport.stopDiscovering();\n }\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAEnC,OAAS,oBAAAC,MAAwB,0CAO1B,IAAMC,EAAN,KAA6B,CAClC,YAEUC,EACR,CADQ,sBAAAA,CACP,CAEH,MAAM,SAAyB,CAC7B,UAAWC,KAAa,KAAK,iBAAiB,iBAAiB,EAC7D,MAAMA,EAAU,gBAAgB,CAEpC,CACF,EAXaF,EAANG,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAiB,gBAAgB,IAFhCP",
|
6
6
|
"names": ["inject", "injectable", "transportDiTypes", "StopDiscoveringUseCase", "transportService", "transport", "__decorateClass", "injectable", "__decorateParam", "inject", "transportDiTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{TransportMock as s}from"../../../api/transport/model/__mocks__/TransportMock";import{DefaultTransportService as n}from"../../transport/service/DefaultTransportService";import{StopDiscoveringUseCase as a}from"./StopDiscoveringUseCase";vi.mock("@internal/transport/service/DefaultTransportService");let e,r,t;describe("StopDiscoveringUseCase",()=>{beforeEach(()=>{e=new s,r=[e],
|
1
|
+
import{TransportMock as s}from"../../../api/transport/model/__mocks__/TransportMock";import{DefaultTransportService as n}from"../../transport/service/DefaultTransportService";import{StopDiscoveringUseCase as a}from"./StopDiscoveringUseCase";vi.mock("@internal/transport/service/DefaultTransportService");let e,r,t,o;describe("StopDiscoveringUseCase",()=>{beforeEach(()=>{e=new s,r=new s,t=[e,r],o=new n(t)}),afterEach(()=>{vi.clearAllMocks()}),test("should call stop discovering",async()=>{vi.spyOn(e,"stopDiscovering").mockImplementation(vi.fn()),vi.spyOn(r,"stopDiscovering").mockImplementation(async()=>Promise.resolve(void 0)),vi.spyOn(o,"getAllTransports").mockReturnValue(t),await new a(o).execute(),expect(e.stopDiscovering).toHaveBeenCalled(),expect(r.stopDiscovering).toHaveBeenCalled()})});
|
2
2
|
//# sourceMappingURL=StopDiscoveringUseCase.test.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/StopDiscoveringUseCase.test.ts"],
|
4
|
-
"sourcesContent": ["import { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { type Transport } from \"@api/types\";\nimport { DefaultTransportService } from \"@internal/transport/service/DefaultTransportService\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nimport { StopDiscoveringUseCase } from \"./StopDiscoveringUseCase\";\n\nvi.mock(\"@internal/transport/service/DefaultTransportService\");\n\n// TODO test several transports\nlet transport: Transport;\nlet transports: Transport[];\nlet transportService: TransportService;\n\ndescribe(\"StopDiscoveringUseCase\", () => {\n beforeEach(() => {\n transport = new TransportMock();\n transports = [transport];\n // @ts-expect-error mock\n transportService = new DefaultTransportService(transports);\n });\n\n afterEach(() => {\n vi.clearAllMocks();\n });\n\n test(\"should call stop discovering\", () => {\n
|
5
|
-
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,+CAE9B,OAAS,2BAAAC,MAA+B,sDAGxC,OAAS,0BAAAC,MAA8B,2BAEvC,GAAG,KAAK,qDAAqD,EAG7D,IAAIC,EACAC,EACAC,EAEJ,SAAS,yBAA0B,IAAM,CACvC,WAAW,IAAM,
|
6
|
-
"names": ["TransportMock", "DefaultTransportService", "StopDiscoveringUseCase", "transport", "
|
4
|
+
"sourcesContent": ["import { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { type Transport } from \"@api/types\";\nimport { DefaultTransportService } from \"@internal/transport/service/DefaultTransportService\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nimport { StopDiscoveringUseCase } from \"./StopDiscoveringUseCase\";\n\nvi.mock(\"@internal/transport/service/DefaultTransportService\");\n\n// TODO test several transports\nlet transport: Transport;\nlet transport2: Transport;\nlet transports: Transport[];\nlet transportService: TransportService;\n\ndescribe(\"StopDiscoveringUseCase\", () => {\n beforeEach(() => {\n transport = new TransportMock();\n transport2 = new TransportMock();\n transports = [transport, transport2];\n // @ts-expect-error mock\n transportService = new DefaultTransportService(transports);\n });\n\n afterEach(() => {\n vi.clearAllMocks();\n });\n\n test(\"should call stop discovering\", async () => {\n vi.spyOn(transport, \"stopDiscovering\").mockImplementation(vi.fn());\n vi.spyOn(transport2, \"stopDiscovering\").mockImplementation(async () =>\n Promise.resolve(undefined),\n );\n\n vi.spyOn(transportService, \"getAllTransports\").mockReturnValue(transports);\n\n const usecase = new StopDiscoveringUseCase(transportService);\n\n await usecase.execute();\n\n expect(transport.stopDiscovering).toHaveBeenCalled();\n expect(transport2.stopDiscovering).toHaveBeenCalled();\n });\n});\n"],
|
5
|
+
"mappings": "AAAA,OAAS,iBAAAA,MAAqB,+CAE9B,OAAS,2BAAAC,MAA+B,sDAGxC,OAAS,0BAAAC,MAA8B,2BAEvC,GAAG,KAAK,qDAAqD,EAG7D,IAAIC,EACAC,EACAC,EACAC,EAEJ,SAAS,yBAA0B,IAAM,CACvC,WAAW,IAAM,CACfH,EAAY,IAAIH,EAChBI,EAAa,IAAIJ,EACjBK,EAAa,CAACF,EAAWC,CAAU,EAEnCE,EAAmB,IAAIL,EAAwBI,CAAU,CAC3D,CAAC,EAED,UAAU,IAAM,CACd,GAAG,cAAc,CACnB,CAAC,EAED,KAAK,+BAAgC,SAAY,CAC/C,GAAG,MAAMF,EAAW,iBAAiB,EAAE,mBAAmB,GAAG,GAAG,CAAC,EACjE,GAAG,MAAMC,EAAY,iBAAiB,EAAE,mBAAmB,SACzD,QAAQ,QAAQ,MAAS,CAC3B,EAEA,GAAG,MAAME,EAAkB,kBAAkB,EAAE,gBAAgBD,CAAU,EAIzE,MAFgB,IAAIH,EAAuBI,CAAgB,EAE7C,QAAQ,EAEtB,OAAOH,EAAU,eAAe,EAAE,iBAAiB,EACnD,OAAOC,EAAW,eAAe,EAAE,iBAAiB,CACtD,CAAC,CACH,CAAC",
|
6
|
+
"names": ["TransportMock", "DefaultTransportService", "StopDiscoveringUseCase", "transport", "transport2", "transports", "transportService"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var h=Object.defineProperty;var
|
1
|
+
var h=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var y=(i,r,t,e)=>{for(var p=e>1?void 0:e?g(r,t):r,A=i.length-1,l;A>=0;A--)(l=i[A])&&(p=(e?l(r,t,p):l(p))||p);return e&&p&&h(r,t,p),p},v=(i,r)=>(t,e)=>r(t,e,i);import a from"axios";import{inject as u,injectable as d}from"inversify";import{EitherAsync as o}from"purify-ts";import{managerApiTypes as f}from"../../manager-api/di/managerApiTypes";import{AppType as n}from"../../manager-api/model/Application";import{DEFAULT_PROVIDER as _}from"../../manager-api/model/Const";import{HttpFetchApiError as s}from"../../manager-api/model/Errors";import{AppTypeDto as m}from"./ManagerApiDto";let c=class{_managerApiBaseUrl;_provider=_;constructor({managerApiUrl:r,provider:t}){this._managerApiBaseUrl=r,this._provider=t}setProvider(r){this._provider===r||r<1||(this._provider=r)}getProvider(){return this._provider}getAppList(r){const{targetId:t,firmwareVersionName:e}=r;return o(()=>a.get(`${this._managerApiBaseUrl}/v2/apps/by-target`,{params:{target_id:t,provider:this._provider,firmware_version_name:e}})).map(p=>p.data).mapLeft(p=>new s(p))}getDeviceVersion(r){const{targetId:t}=r;return o(()=>a.get(`${this._managerApiBaseUrl}/get_device_version`,{params:{target_id:t,provider:this._provider}})).map(e=>e.data).mapLeft(e=>new s(e))}getFirmwareVersion(r){const{deviceId:t,version:e}=r;return o(()=>a.get(`${this._managerApiBaseUrl}/get_firmware_version`,{params:{device_version:t,version_name:e,provider:this._provider}})).map(p=>p.data).mapLeft(p=>new s(p))}getAppsByHash(r){const{hashes:t}=r;return o(()=>a.post(`${this._managerApiBaseUrl}/v2/apps/hash`,t)).map(e=>e.data).map(e=>this.mapApplicationDtoToApplication(e)).mapLeft(e=>new s(e))}mapAppTypeDtoToAppType(r){switch(r){case m.currency:return n.currency;case m.plugin:return n.plugin;case m.tool:return n.tool;case m.swap:return n.swap}}mapApplicationDtoToApplication(r){return r.map(t=>{if(t===null)return null;const{applicationType:e,...p}=t;return{...p,applicationType:this.mapAppTypeDtoToAppType(e)}})}};c=y([d(),v(0,u(f.DmkConfig))],c);export{c as AxiosManagerApiDataSource};
|
2
2
|
//# sourceMappingURL=AxiosManagerApiDataSource.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/data/AxiosManagerApiDataSource.ts"],
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly
|
5
|
-
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAG5B,OAAS,mBAAAC,MAAuB,2CAChC,OAEE,WAAAC,MACK,
|
6
|
-
"names": ["axios", "inject", "injectable", "EitherAsync", "managerApiTypes", "AppType", "HttpFetchApiError", "AppTypeDto", "AxiosManagerApiDataSource", "managerApiUrl", "
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { DEFAULT_PROVIDER } from \"@internal/manager-api/model/Const\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly _managerApiBaseUrl: string;\n private _provider: number = DEFAULT_PROVIDER;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl, provider }: DmkConfig,\n ) {\n this._managerApiBaseUrl = managerApiUrl;\n this._provider = provider;\n }\n\n setProvider(provider: number): void {\n if (this._provider === provider || provider < 1) {\n return;\n }\n this._provider = provider;\n }\n\n getProvider(): number {\n return this._provider;\n }\n\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Application[]> {\n const { targetId, firmwareVersionName } = params;\n return EitherAsync(() =>\n axios.get<Application[]>(`${this._managerApiBaseUrl}/v2/apps/by-target`, {\n params: {\n target_id: targetId,\n provider: this._provider,\n firmware_version_name: firmwareVersionName,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n const { targetId } = params;\n return EitherAsync(() =>\n axios.get<DeviceVersion>(\n `${this._managerApiBaseUrl}/get_device_version`,\n {\n params: {\n target_id: targetId,\n provider: this._provider,\n },\n },\n ),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n const { deviceId, version } = params;\n return EitherAsync(() =>\n axios.get<FinalFirmware>(\n `${this._managerApiBaseUrl}/get_firmware_version`,\n {\n params: {\n device_version: deviceId,\n version_name: version,\n provider: this._provider,\n },\n },\n ),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n const { hashes } = params;\n return EitherAsync(() =>\n axios.post<Array<ApplicationDto | null>>(\n `${this._managerApiBaseUrl}/v2/apps/hash`,\n hashes,\n ),\n )\n .map((res) => res.data)\n .map((apps) => this.mapApplicationDtoToApplication(apps))\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto): AppType {\n switch (appType) {\n case AppTypeDto.currency:\n return AppType.currency;\n case AppTypeDto.plugin:\n return AppType.plugin;\n case AppTypeDto.tool:\n return AppType.tool;\n case AppTypeDto.swap:\n return AppType.swap;\n }\n }\n\n private mapApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): Array<Application | null> {\n return apps.map((app) => {\n if (app === null) {\n return null;\n }\n const { applicationType, ...rest } = app;\n return {\n ...rest,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n });\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAG5B,OAAS,mBAAAC,MAAuB,2CAChC,OAEE,WAAAC,MACK,0CACP,OAAS,oBAAAC,MAAwB,oCAEjC,OAAS,qBAAAC,MAAyB,qCAUlC,OAAyB,cAAAC,MAAkB,kBAGpC,IAAMC,EAAN,KAAgE,CACpD,mBACT,UAAoBC,EAE5B,YAEE,CAAE,cAAAC,EAAe,SAAAC,CAAS,EAC1B,CACA,KAAK,mBAAqBD,EAC1B,KAAK,UAAYC,CACnB,CAEA,YAAYA,EAAwB,CAC9B,KAAK,YAAcA,GAAYA,EAAW,IAG9C,KAAK,UAAYA,EACnB,CAEA,aAAsB,CACpB,OAAO,KAAK,SACd,CAEA,WACEC,EAC+C,CAC/C,KAAM,CAAE,SAAAC,EAAU,oBAAAC,CAAoB,EAAIF,EAC1C,OAAOG,EAAY,IACjBC,EAAM,IAAmB,GAAG,KAAK,kBAAkB,qBAAsB,CACvE,OAAQ,CACN,UAAWH,EACX,SAAU,KAAK,UACf,sBAAuBC,C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ACV,OAAO,KAET,KAAM,CAAE,gBAAAC,EAAiB,GAAGC,CAAK,EAAIF,EACrC,MAAO,CACL,GAAGE,EACH,gBAAiB,KAAK,uBAAuBD,CAAe,CAC9D,CACF,CAAC,CACH,CACF,EAzHapB,EAANsB,EAAA,CADNC,EAAW,EAMPC,EAAA,EAAAC,EAAOC,EAAgB,SAAS,IALxB1B",
|
6
|
+
"names": ["axios", "inject", "injectable", "EitherAsync", "managerApiTypes", "AppType", "DEFAULT_PROVIDER", "HttpFetchApiError", "AppTypeDto", "AxiosManagerApiDataSource", "DEFAULT_PROVIDER", "managerApiUrl", "provider", "params", "targetId", "firmwareVersionName", "EitherAsync", "axios", "res", "error", "HttpFetchApiError", "deviceId", "version", "hashes", "apps", "appType", "AppTypeDto", "AppType", "app", "applicationType", "rest", "__decorateClass", "injectable", "__decorateParam", "inject", "managerApiTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import
|
1
|
+
import a from"axios";import{Left as n,Right as s}from"purify-ts";import{BTC_APP as p,BTC_APP_METADATA as i,CUSTOM_LOCK_SCREEN_APP as v,CUSTOM_LOCK_SCREEN_APP_METADATA as d}from"../../../api/device-action/__test-utils__/data";import{HttpFetchApiError as c}from"../../manager-api/model/Errors";import{AxiosManagerApiDataSource as o}from"./AxiosManagerApiDataSource";vi.mock("axios");const l={id:17,target_id:"857735172"},u={id:361,perso:"perso_11"};describe("AxiosManagerApiDataSource",()=>{describe("getAppList",()=>{let e;beforeEach(()=>{e=new o({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a list of applications",async()=>{const r=[i,d];vi.spyOn(a,"get").mockResolvedValue({data:r});const t=await e.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(t).toEqual(s(r))}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(a,"get").mockRejectedValue(r);const t=await e.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(t).toEqual(n(new c(r)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let e;beforeEach(()=>{e=new o({})}),afterEach(()=>{vi.clearAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(a,"post").mockResolvedValue({data:[i]});const r=[p.appFullHash],t=await e.getAppsByHash({hashes:r});expect(t).toEqual(s([i]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(a,"post").mockResolvedValue({data:[]});const r=[],t=await e.getAppsByHash({hashes:r});expect(t).toEqual(s([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(a,"post").mockResolvedValue({data:[i,d]});const r=[p.appFullHash,v.appFullHash],t=await e.getAppsByHash({hashes:r});expect(t).toEqual(s([i,d]))})}),describe("error cases",()=>{afterEach(()=>{vi.clearAllMocks()}),it("should throw an error if the request fails",async()=>{const e=new o({}),r=new Error("fetch error");vi.spyOn(a,"post").mockRejectedValue(r);const t=[p.appFullHash],h=await e.getAppsByHash({hashes:t});expect(h).toEqual(n(new c(r)))})})}),describe("getDeviceVersion",()=>{let e;beforeEach(()=>{e=new o({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete device version",async()=>{vi.spyOn(a,"get").mockResolvedValue({data:l});const r=await e.getDeviceVersion({targetId:"targetId"});expect(r).toEqual(s(l))}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(a,"get").mockRejectedValue(r);const t=await e.getDeviceVersion({targetId:"targetId"});expect(t).toEqual(n(new c(r)))})}),describe("getFirmwareVersion",()=>{let e;beforeEach(()=>{e=new o({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete firmware version",async()=>{vi.spyOn(a,"get").mockResolvedValue({data:u});const r=await e.getFirmwareVersion({version:"versionName",deviceId:42});expect(r).toEqual(s(u))}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(a,"get").mockRejectedValue(r);const t=await e.getFirmwareVersion({version:"versionName",deviceId:42});expect(t).toEqual(n(new c(r)))})}),describe("setProvider",()=>{let e;beforeEach(()=>{e=new o({managerApiUrl:"http://fake-url.com",provider:1})}),it("should not change the provider if the new value is the same",()=>{const r=e._provider;e.setProvider(r),expect(e._provider).toBe(r)}),it("should not change the provider if the new value is less than 1",()=>{const r=e._provider;e.setProvider(0),e.setProvider(-5),expect(e._provider).toBe(r)}),it("should update the provider if a valid and different value is provided",()=>{e.setProvider(2),expect(e._provider).toBe(2)})}),describe("getProvider",()=>{let e;beforeEach(()=>{e=new o({managerApiUrl:"http://fake-url.com",provider:123})}),afterEach(()=>{vi.clearAllMocks()}),it("should return the initial provider",()=>{expect(e.getProvider()).toBe(123)}),it("should return the updated provider after setProvider is called",()=>{e.setProvider(321),expect(e.getProvider()).toBe(321)})})});
|
2
2
|
//# sourceMappingURL=AxiosManagerApiDataSource.test.js.map
|