@ledgerhq/device-management-kit 0.0.0-rnble-transport-20250404160243 → 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 +6 -3
- 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/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/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/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/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/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/types/src/api/DeviceManagementKit.d.ts +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/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/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/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/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA8B,mCAC9BC,EAKO,sBAMPC,EAA0D,qEAC1DC,EAIO,
|
6
|
-
"names": ["DevicePinger_exports", "__export", "DevicePinger", "__toCommonJS", "import_DeviceModel", "import_api", "import_DeviceSessionRefresherConst", "import_DeviceSessionEventDispatcher", "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();\n }\n}\n"],
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA8B,mCAC9BC,EAKO,sBAMPC,EAA+B,2DAC/BC,EAA0D,qEAC1DC,EAIO,uEAOA,MAAMN,CAAa,CAKxB,YACEO,EACQC,EACAC,EACRC,EACA,CAHQ,qBAAAF,EACA,6BAAAC,EAGR,KAAK,qBAAuBC,EAC5B,KAAK,QAAUH,EAAoB,eAAe,EAClD,KAAK,cAAgB,KAAK,wBACvB,OAAO,EACP,UAAU,MAAOI,GAAU,MAAM,KAAK,eAAeA,CAAK,CAAC,CAChE,CAfiB,qBACT,cACA,QAeR,MAAa,MAAgE,CAC3E,GAAI,CAIF,OAHe,MAAM,KAAK,oBACxB,KAAK,gBAAgB,YAAY,EACnC,CAEF,OAASC,EAAO,CACd,WAAK,QAAQ,MAAM,6BAA8B,CAC/C,KAAM,CACJ,MAAAA,CACF,CACF,CAAC,EACKA,CACR,CACF,CAEQ,eAAiB,MAAOD,GAAoB,CAClD,OAAQA,EAAM,UAAW,CACvB,KAAK,gBAAc,eACjB,OAAO,MAAM,KAAK,KAAK,EACzB,QACE,OAAO,IACX,CACF,EAEA,MAAc,oBAAoBE,EAA8B,CAC9D,OAAQA,EAAe,CACrB,KAAK,gBAAc,OAAQ,CACzB,MAAMC,EAEF,SAAY,CACd,MAAMC,EAAmB,MAAM,KAAK,qBAClC,IAAI,0BACJ,gBACF,EAEA,YAAK,qBAAqB,IAAI,sBAAuB,gBAAc,EAC5DA,CACT,EAEMC,EAAgC,IAAI,QAASC,GAAY,CAC7D,WACE,IAAMA,EAAQ,IAAI,EAClB,4CAA4C,EAAI,GAClD,CACF,CAAC,EAEKC,EACJ,MAAM,QAAQ,KAAK,CAACJ,EAAa,EAAGE,CAAc,CAAC,EAErD,OAAKE,EAKH,KAAK,wBAAwB,SAAS,CACpC,UAAW,gBAAc,kBACzB,UAAWA,CACb,CAAC,EAPD,KAAK,wBAAwB,SAAS,CACpC,UAAW,gBAAc,0BAC3B,CAAC,EAOIA,CACT,CACA,QAAS,CACP,MAAMC,EAAS,MAAM,KAAK,qBACxB,IAAI,0BACJ,gBACF,EACA,YAAK,wBAAwB,SAAS,CACpC,UAAW,gBAAc,kBACzB,UAAWA,CACb,CAAC,EACMA,CACT,CACF,CACF,CAEO,aAAoB,CACzB,KAAK,cAAc,YAAY,CACjC,CACF",
|
6
|
+
"names": ["DevicePinger_exports", "__export", "DevicePinger", "__toCommonJS", "import_DeviceModel", "import_api", "import_ApduResponseConst", "import_DeviceSessionRefresherConst", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "connectedDevice", "_sessionEventDispatcher", "sendCommandFunction", "event", "error", "deviceModelId", "chainPromise", "appVersionResult", "timeoutPromise", "resolve", "resultOrTimeout", "result"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var a=Object.defineProperty;var
|
1
|
+
"use strict";var a=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var b=(n,e)=>{for(var t in e)a(n,t,{get:e[t],enumerable:!0})},y=(n,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of C(e))!R.call(n,i)&&i!==t&&a(n,i,{get:()=>e[i],enumerable:!(s=A(e,i))||s.enumerable});return n};var T=n=>y(a({},"__esModule",{value:!0}),n);var I={};b(I,{DeviceSession:()=>O});module.exports=T(I);var v=require("rxjs"),d=require("uuid"),h=require("../../../api/command/utils/CommandUtils"),p=require("../../../api/device/DeviceStatus"),S=require("../../../api/device-session/DeviceSessionState"),u=require("../../device-session/data/DeviceSessionRefresherConst"),m=require("../../device-session/service/MutexService"),D=require("../../device-session/service/RefresherService"),l=require("./DevicePinger"),o=require("./DeviceSessionEventDispatcher"),_=require("./DeviceSessionRefresher"),f=require("./DeviceSessionStateHandler");class O{_id;_connectedDevice;_deviceState;_managerApiService;_secureChannelService;_logger;_refresherOptions;_pinger;_deviceSessionRefresher;_refresherService;_commandMutex=new m.MutexService;_sessionEventDispatcher=new o.DeviceSessionEventDispatcher;constructor({connectedDevice:e,id:t=(0,d.v4)()},s,i,r,E){this._id=t,this._connectedDevice=e,this._logger=s("device-session"),this._managerApiService=i,this._secureChannelService=r,this._refresherOptions={...u.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,...E},this._deviceState=new v.BehaviorSubject({sessionStateType:S.DeviceSessionStateType.Connected,deviceStatus:p.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._pinger=new l.DevicePinger(s,e,this._sessionEventDispatcher,(c,g)=>this.sendCommand(c,g)),this._deviceSessionRefresher=new _.DeviceSessionRefresher(s,this._refresherOptions,this._sessionEventDispatcher,this._connectedDevice),new f.DeviceSessionStateHandler(s,this._sessionEventDispatcher,this._connectedDevice,this._deviceState,c=>this.setDeviceSessionState(c)),this._refresherService=new D.RefresherService(s,{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,t={isPolling:!1,triggersDisconnection:!1,abortTimeout:void 0}){const s=await this._commandMutex.lock();try{this._sessionEventDispatcher.dispatch({eventName:o.SessionEvents.DEVICE_STATE_UPDATE_BUSY});const i=await this._connectedDevice.sendApdu(e,t.triggersDisconnection,t.abortTimeout);return i.ifRight(r=>{h.CommandUtils.isLockedDeviceResponse(r)?this._sessionEventDispatcher.dispatch({eventName:o.SessionEvents.DEVICE_STATE_UPDATE_LOCKED}):this._sessionEventDispatcher.dispatch({eventName:o.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED})}).ifLeft(()=>{this._sessionEventDispatcher.dispatch({eventName:o.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED})}),i}finally{s()}}async sendCommand(e,t){const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1,abortTimeout:t})).caseOf({Left:r=>{throw r},Right:r=>e.parseResponse(r,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:t,cancel:s}=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:t,cancel:s}}close(){this._updateDeviceStatus(p.DeviceStatus.NOT_CONNECTED),this._deviceState.complete(),this._deviceSessionRefresher.stopRefresher()}disableRefresher(e){return this._refresherService.disableRefresher(e)}_updateDeviceStatus(e){const t=this._deviceState.getValue();this._deviceState.next({...t,deviceStatus:e})}}0&&(module.exports={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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAAiD,gBACjDC,EAA6B,gBAI7BC,EAA6B,2CAC7BC,EAA6B,oCAO7BC,EAGO,kDAKPC,EAAyD,qEACzDC,EAA6B,yDAC7BC,EAAiC,6DAIjCC,EAA6B,0BAC7BC,EAGO,0CACPC,EAAuC,oCACvCC,EAA0C,uCAqBnC,MAAMb,CAAc,CACR,IACA,iBACA,aACA,mBACA,sBACA,QACA,kBACT,QACA,wBACS,kBACT,cAAgB,IAAI,eACpB,wBAA0B,IAAI,+BAEtC,YACE,CAAE,gBAAAc,EAAiB,GAAAC,KAAK,EAAAC,IAAO,CAAE,EACjCC,EACAC,EACAC,EACAC,EACA,CACA,KAAK,IAAML,EACX,KAAK,iBAAmBD,EACxB,KAAK,QAAUG,EAAoB,gBAAgB,EACnD,KAAK,mBAAqBC,EAC1B,KAAK,sBAAwBC,EAC7B,KAAK,kBAAoB,CACvB,GAAG,2CACH,GAAGC,CACL,EACA,KAAK,aAAe,IAAI,kBAAoC,CAC1D,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,EACnD,CAAC,EAED,KAAK,QAAU,IAAI,eACjBH,EACAH,EACA,KAAK,
|
6
|
-
"names": ["DeviceSession_exports", "__export", "DeviceSession", "__toCommonJS", "import_rxjs", "import_uuid", "import_CommandUtils", "import_DeviceStatus", "import_DeviceSessionState", "import_DeviceSessionRefresherConst", "import_MutexService", "import_RefresherService", "import_DevicePinger", "import_DeviceSessionEventDispatcher", "import_DeviceSessionRefresher", "import_DeviceSessionStateHandler", "connectedDevice", "id", "uuidv4", "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": "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",
|
6
|
+
"names": ["DeviceSession_exports", "__export", "DeviceSession", "__toCommonJS", "import_rxjs", "import_uuid", "import_CommandUtils", "import_DeviceStatus", "import_DeviceSessionState", "import_DeviceSessionRefresherConst", "import_MutexService", "import_RefresherService", "import_DevicePinger", "import_DeviceSessionEventDispatcher", "import_DeviceSessionRefresher", "import_DeviceSessionStateHandler", "connectedDevice", "id", "uuidv4", "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
|
-
"use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var D=(i,e)=>{for(var s in e)c(i,s,{get:e[s],enumerable:!0})},d=(i,e,s,
|
1
|
+
"use strict";var c=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var D=(i,e)=>{for(var s in e)c(i,s,{get:e[s],enumerable:!0})},d=(i,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!u.call(i,n)&&n!==s&&c(i,n,{get:()=>e[n],enumerable:!(a=S(e,n))||a.enumerable});return i};var l=i=>d(c({},"__esModule",{value:!0}),i);var h={};D(h,{DeviceSessionStateHandler:()=>E});module.exports=l(h);var t=require("../../../api/index"),r=require("../../device-session/model/DeviceSessionEventDispatcher");class E{constructor(e,s,a,n,o){this._sessionEventDispatcher=s;this._connectedDevice=a;this._deviceState=n;this.setDeviceSessionState=o;this._subscription=this._sessionEventDispatcher.listen().subscribe(v=>this.mapEventAction(v)),this._logger=e("device-session-state-handler")}_subscription;_logger;_updateDeviceState(e){const s=this._parseDeviceStatus(e);if(s){const{sessionStateType:a,deviceStatus:n,currentApp:o}=s;this.setDeviceSessionState({sessionStateType:a,deviceStatus:n,deviceModelId:this._connectedDevice.deviceModel.id,currentApp:o,installedApps:[],isSecureConnectionAllowed:!1})}}mapEventAction=e=>{switch(e.eventName){case r.SessionEvents.COMMAND_SUCCEEDED:return this._updateDeviceState(e.eventData);case r.SessionEvents.DEVICE_STATE_UPDATE_BUSY:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.DeviceStatus.BUSY});case r.SessionEvents.DEVICE_STATE_UPDATE_LOCKED:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.DeviceStatus.LOCKED});case r.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED:return this.setDeviceSessionState({...this._deviceState.getValue(),deviceStatus:t.DeviceStatus.CONNECTED});default:return null}};_parseDeviceStatus(e){return(0,t.isSuccessCommandResult)(e)?{sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,currentApp:{name:e.data.name,version:e.data.version}}:(this._logger.debug("Error while parsing APDU response",{data:{parsedResponse:e}}),null)}unsubscribe(){this._subscription.unsubscribe()}}0&&(module.exports={DeviceSessionStateHandler});
|
2
2
|
//# sourceMappingURL=DeviceSessionStateHandler.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionStateHandler.ts"],
|
4
|
-
"sourcesContent": ["import { type BehaviorSubject, type Subscription } from \"rxjs\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n DeviceSessionStateType,\n DeviceStatus,\n type GetAppAndVersionResponse,\n isSuccessCommandResult,\n type TransportConnectedDevice,\n} from \"@api/index\";\nimport { type CommandResult, type LoggerPublisherService } from \"@api/types\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\n\nexport type SetDeviceSessionStateFn = (state: DeviceSessionState) => void;\n\ntype NewDeviceStatus = {\n sessionStateType: DeviceSessionStateType;\n deviceStatus: DeviceStatus;\n currentApp: {\n name: string;\n version: string;\n };\n};\n\nexport class DeviceSessionStateHandler {\n private _subscription: Subscription;\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n private _sessionEventDispatcher: DeviceSessionEventDispatcher,\n private _connectedDevice: TransportConnectedDevice,\n private _deviceState: BehaviorSubject<DeviceSessionState>,\n private setDeviceSessionState: SetDeviceSessionStateFn,\n ) {\n this._subscription = this._sessionEventDispatcher\n .listen()\n .subscribe((event) => this.mapEventAction(event));\n this._logger = loggerModuleFactory(\"device-session-state-handler\");\n }\n\n private _updateDeviceState(\n parsedResponse: CommandResult<GetAppAndVersionResponse>,\n ): void {\n const newDeviceStatus = this._parseDeviceStatus(parsedResponse);\n\n if (newDeviceStatus) {\n const { sessionStateType, deviceStatus, currentApp } = newDeviceStatus;\n\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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAGA,IAAAI,EAMO,sBAEPC,EAIO,uEAaA,MAAMH,CAA0B,CAIrC,YACEI,EACQC,EACAC,EACAC,EACAC,EACR,CAJQ,6BAAAH,EACA,sBAAAC,EACA,kBAAAC,EACA,2BAAAC,EAER,KAAK,cAAgB,KAAK,wBACvB,OAAO,EACP,UAAWC,GAAU,KAAK,eAAeA,CAAK,CAAC,EAClD,KAAK,QAAUL,EAAoB,8BAA8B,CACnE,CAdQ,cACS,QAeT,mBACNM,EACM,CACN,MAAMC,EAAkB,KAAK,mBAAmBD,CAAc,EAE9D,GAAIC,EAAiB,CACnB,KAAM,CAAE,iBAAAC,EAAkB,aAAAC,EAAc,WAAAC,CAAW,EAAIH,EAEvD,KAAK,sBAAsB,CACzB,iBAAAC,EACA,aAAAC,EACA,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAAC,EACA,cAAe,CAAC,EAChB,0BAA2B,EAC7B,CAAC,CACH,CACF,CAEQ,eAAkBL,GAAoB,CAC5C,OAAQA,EAAM,UAAW,CACvB,KAAK,gBAAc,kBACjB,OAAO,KAAK,mBAAmBA,EAAM,SAAS,EAChD,KAAK,gBAAc,yBACjB,OAAO,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAc,eAAa,IAC7B,CAAC,EACH,KAAK,gBAAc,2BACjB,OAAO,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAc,eAAa,MAC7B,CAAC,EACH,KAAK,gBAAc,8BACjB,OAAO,KAAK,sBAAsB,CAChC,GAAG,KAAK,aAAa,SAAS,EAC9B,aAAc,eAAa,SAC7B,CAAC,EACH,QACE,OAAO,IACX,CACF,EAEQ,mBACNC,EACwB,CACxB,SAAI,0BAAuBA,CAAc,EAChC,CACL,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,WAAY,CACV,KAAMA,EAAe,KAAK,KAC1B,QAASA,EAAe,KAAK,OAC/B,CACF,GAEA,KAAK,QAAQ,MAAM,oCAAqC,CACtD,KAAM,CAAE,eAAAA,CAAe,CACzB,CAAC,EACM,KAEX,CAEO,aAAoB,CACzB,KAAK,cAAc,YAAY,CACjC,CACF",
|
6
6
|
"names": ["DeviceSessionStateHandler_exports", "__export", "DeviceSessionStateHandler", "__toCommonJS", "import_api", "import_DeviceSessionEventDispatcher", "loggerModuleFactory", "_sessionEventDispatcher", "_connectedDevice", "_deviceState", "setDeviceSessionState", "event", "parsedResponse", "newDeviceStatus", "sessionStateType", "deviceStatus", "currentApp"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var r=require("rxjs"),t=require("vitest"),e=require("../../../api/index"),a=require("../../device-session/model/DeviceSessionEventDispatcher"),S=require("./DeviceSessionStateHandler");describe("DeviceSessionStateHandler",()=>{let n,d,c;const E=vi.fn(()=>c);let v,l,s,i;beforeEach(()=>{n=new r.Subject,d={listen:()=>n,dispatch:vi.fn()},c={error:vi.fn()},v={deviceModel:{id:"device-model-1"}},l=new r.BehaviorSubject({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:e.DeviceModelId.NANO_X,currentApp:{name:"",version:""},installedApps:[],isSecureConnectionAllowed:!1}),s=vi.fn(),i=new S.DeviceSessionStateHandler(E,d,v,l,s)}),afterEach(()=>{i&&typeof i.unsubscribe=="function"&&i.unsubscribe()}),it("updates device state on COMMAND_SUCCEEDED event with a successful response",()=>{const o={data:{name:"TestApp",version:"1.0.0"},status:e.CommandResultStatus.Success};n.next({eventName:a.SessionEvents.COMMAND_SUCCEEDED,eventData:o}),(0,t.expect)(s).toHaveBeenCalledWith({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:"device-model-1",currentApp:{name:"TestApp",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:!1})}),it("updates device state on DEVICE_STATE_UPDATE_BUSY event",()=>{n.next({eventName:a.SessionEvents.DEVICE_STATE_UPDATE_BUSY}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.BUSY}))}),it("updates device state on DEVICE_STATE_UPDATE_CONNECTED event",()=>{n.next({eventName:a.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.CONNECTED}))}),it("logs error and does not update state if command result is unsuccessful",()=>{const o={data:null,error:{_tag:"SomeOtherError"}};n.next({eventName:a.SessionEvents.COMMAND_SUCCEEDED,eventData:o}),(0,t.expect)(c.
|
1
|
+
"use strict";var r=require("rxjs"),t=require("vitest"),e=require("../../../api/index"),a=require("../../device-session/model/DeviceSessionEventDispatcher"),S=require("./DeviceSessionStateHandler");describe("DeviceSessionStateHandler",()=>{let n,d,c;const E=vi.fn(()=>c);let v,l,s,i;beforeEach(()=>{n=new r.Subject,d={listen:()=>n,dispatch:vi.fn()},c={error:vi.fn(),debug:vi.fn()},v={deviceModel:{id:"device-model-1"}},l=new r.BehaviorSubject({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:e.DeviceModelId.NANO_X,currentApp:{name:"",version:""},installedApps:[],isSecureConnectionAllowed:!1}),s=vi.fn(),i=new S.DeviceSessionStateHandler(E,d,v,l,s)}),afterEach(()=>{i&&typeof i.unsubscribe=="function"&&i.unsubscribe()}),it("updates device state on COMMAND_SUCCEEDED event with a successful response",()=>{const o={data:{name:"TestApp",version:"1.0.0"},status:e.CommandResultStatus.Success};n.next({eventName:a.SessionEvents.COMMAND_SUCCEEDED,eventData:o}),(0,t.expect)(s).toHaveBeenCalledWith({sessionStateType:e.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:e.DeviceStatus.CONNECTED,deviceModelId:"device-model-1",currentApp:{name:"TestApp",version:"1.0.0"},installedApps:[],isSecureConnectionAllowed:!1})}),it("updates device state on DEVICE_STATE_UPDATE_BUSY event",()=>{n.next({eventName:a.SessionEvents.DEVICE_STATE_UPDATE_BUSY}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.BUSY}))}),it("updates device state on DEVICE_STATE_UPDATE_CONNECTED event",()=>{n.next({eventName:a.SessionEvents.DEVICE_STATE_UPDATE_CONNECTED}),(0,t.expect)(s).toHaveBeenCalledWith(t.expect.objectContaining({deviceStatus:e.DeviceStatus.CONNECTED}))}),it("logs error and does not update state if command result is unsuccessful",()=>{const o={data:null,error:{_tag:"SomeOtherError"}};n.next({eventName:a.SessionEvents.COMMAND_SUCCEEDED,eventData:o}),(0,t.expect)(c.debug).toHaveBeenCalledWith("Error while parsing APDU response",{data:{parsedResponse:o}}),(0,t.expect)(s).not.toHaveBeenCalled()}),it("does not update state if command result is not a success",()=>{const o={data:null,error:{_tag:"SomeOtherError"}};n.next({eventName:a.SessionEvents.COMMAND_SUCCEEDED,eventData:o}),(0,t.expect)(s).not.toHaveBeenCalled()})});
|
2
2
|
//# sourceMappingURL=DeviceSessionStateHandler.test.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/device-session/model/DeviceSessionStateHandler.test.ts"],
|
4
|
-
"sourcesContent": ["import { BehaviorSubject, Subject } from \"rxjs\";\nimport { expect, type Mock } from \"vitest\";\n\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport {\n CommandResultStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n} from \"@api/index\";\nimport {\n type DeviceSessionEventDispatcher,\n type NewEvent,\n SessionEvents,\n} from \"@internal/device-session/model/DeviceSessionEventDispatcher\";\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,IAAAA,EAAyC,gBACzCC,EAAkC,kBAGlCC,EAKO,sBACPC,EAIO,uEAEPC,EAGO,uCAEP,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,IAAAA,EAAyC,gBACzCC,EAAkC,kBAGlCC,EAKO,sBACPC,EAIO,uEAEPC,EAGO,uCAEP,SAAS,4BAA6B,IAAM,CAC1C,IAAIC,EACAC,EACAC,EAIJ,MAAMC,EAA0B,GAAG,GAAG,IAAMD,CAAU,EACtD,IAAIE,EACAC,EACAC,EACAC,EAEJ,WAAW,IAAM,CACfP,EAAmB,IAAI,UAEvBC,EAA6B,CAC3B,OAAQ,IAAMD,EACd,SAAU,GAAG,GAAG,CAClB,EAEAE,EAAa,CACX,MAAO,GAAG,GAAG,EACb,MAAO,GAAG,GAAG,CACf,EAEAE,EAAsB,CACpB,YAAa,CACX,GAAI,gBACN,CACF,EAEAC,EAAc,IAAI,kBAAoC,CACpD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,gBAAc,OAC7B,WAAY,CAAE,KAAM,GAAI,QAAS,EAAG,EACpC,cAAe,CAAC,EAChB,0BAA2B,EAC7B,CAAC,EAEDC,EAAwB,GAAG,GAAG,EAE9BC,EAAU,IAAI,4BAEZJ,EACAF,EACAG,EACAC,EACAC,CACF,CACF,CAAC,EAED,UAAU,IAAM,CACVC,GAAW,OAAOA,EAAQ,aAAgB,YAC5CA,EAAQ,YAAY,CAExB,CAAC,EAED,GAAG,6EAA8E,IAAM,CAErF,MAAMC,EAAoB,CACxB,KAAM,CACJ,KAAM,UACN,QAAS,OACX,EACA,OAAQ,sBAAoB,OAC9B,EAGAR,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWQ,CACb,CAAC,KAGD,UAAOF,CAAqB,EAAE,qBAAqB,CACjD,iBAAkB,yBAAuB,0BACzC,aAAc,eAAa,UAC3B,cAAe,iBACf,WAAY,CAAE,KAAM,UAAW,QAAS,OAAQ,EAChD,cAAe,CAAC,EAChB,0BAA2B,EAC7B,CAAC,CACH,CAAC,EAED,GAAG,yDAA0D,IAAM,CAEjEN,EAAiB,KAAK,CACpB,UAAW,gBAAc,wBAC3B,CAAC,KAGD,UAAOM,CAAqB,EAAE,qBAC5B,SAAO,iBAAiB,CAAE,aAAc,eAAa,IAAK,CAAC,CAC7D,CACF,CAAC,EAED,GAAG,8DAA+D,IAAM,CAEtEN,EAAiB,KAAK,CACpB,UAAW,gBAAc,6BAC3B,CAAC,KAGD,UAAOM,CAAqB,EAAE,qBAC5B,SAAO,iBAAiB,CAAE,aAAc,eAAa,SAAU,CAAC,CAClE,CACF,CAAC,EAED,GAAG,yEAA0E,IAAM,CAEjF,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOP,EAAW,KAAK,EAAE,qBACvB,oCACA,CAAE,KAAM,CAAE,eAAgBO,CAAuB,CAAE,CACrD,KACA,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,EAED,GAAG,2DAA4D,IAAM,CAEnE,MAAMG,EAAyB,CAC7B,KAAM,KACN,MAAO,CAAE,KAAM,gBAAiB,CAClC,EAGAT,EAAiB,KAAK,CACpB,UAAW,gBAAc,kBAEzB,UAAWS,CACb,CAAC,KAGD,UAAOH,CAAqB,EAAE,IAAI,iBAAiB,CACrD,CAAC,CACH,CAAC",
|
6
6
|
"names": ["import_rxjs", "import_vitest", "import_api", "import_DeviceSessionEventDispatcher", "import_DeviceSessionStateHandler", "fakeEventSubject", "fakeSessionEventDispatcher", "mockLogger", "mockLoggerModuleFactory", "fakeConnectedDevice", "deviceState", "setDeviceSessionState", "handler", "fakeCommandResult", "fakeErrorCommandResult"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var v=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var b=(o,r)=>{for(var t in r)v(o,t,{get:r[t],enumerable:!0})},u=(o,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of f(r))!h.call(o,e)&&e!==t&&v(o,e,{get:()=>r[e],enumerable:!(i=m(r,e))||i.enumerable});return o};var _=o=>u(v({},"__esModule",{value:!0}),o),g=(o,r,t,i)=>{for(var e=i>1?void 0:i?m(r,t):r,n=o.length-1,a;n>=0;n--)(a=o[n])&&(e=(i?a(r,t,e):a(e))||e);return i&&e&&v(r,t,e),e},l=(o,r)=>(t,i)=>r(t,i,o);var y={};b(y,{ListenToAvailableDevicesUseCase:()=>p});module.exports=_(y);var c=require("inversify"),s=require("rxjs"),D=require("../../../api/device/DeviceModel"),d=require("../../logger-publisher/di/loggerTypes"),T=require("../../transport/di/transportDiTypes");let p=class{_transports;_transportService;_logger;constructor(r,t){this._transports=r.getAllTransports(),this._transportService=r,this._logger=t("ListenToAvailableDevicesUseCase")}mapTransportDiscoveredDeviceToDiscoveredDevice(r){const t=new D.DeviceModel({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"),(0,s.from)([[]]);if(!r){this._logger.info("Discovering all available transports");const i=this._transports.map((e,n)=>e.listenToAvailableDevices().pipe((0,s.map)(a=>({index:n,arr:a}))));return(0,s.merge)(...i).pipe((0,s.scan)((e,{index:n,arr:a})=>(e[n]=a,e),{}),(0,s.map)(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`),(0,s.of)([])),Just:i=>i.listenToAvailableDevices().pipe((0,s.map)(e=>e.map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))})}};p=g([(0,c.injectable)(),l(0,(0,c.inject)(T.transportDiTypes.TransportService)),l(1,(0,c.inject)(d.loggerTypes.LoggerPublisherServiceFactory))],p);0&&(module.exports={ListenToAvailableDevicesUseCase});
|
1
|
+
"use strict";var v=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var b=(o,r)=>{for(var t in r)v(o,t,{get:r[t],enumerable:!0})},u=(o,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of f(r))!h.call(o,e)&&e!==t&&v(o,e,{get:()=>r[e],enumerable:!(i=m(r,e))||i.enumerable});return o};var _=o=>u(v({},"__esModule",{value:!0}),o),g=(o,r,t,i)=>{for(var e=i>1?void 0:i?m(r,t):r,n=o.length-1,a;n>=0;n--)(a=o[n])&&(e=(i?a(r,t,e):a(e))||e);return i&&e&&v(r,t,e),e},l=(o,r)=>(t,i)=>r(t,i,o);var y={};b(y,{ListenToAvailableDevicesUseCase:()=>p});module.exports=_(y);var c=require("inversify"),s=require("rxjs"),D=require("../../../api/device/DeviceModel"),d=require("../../logger-publisher/di/loggerTypes"),T=require("../../transport/di/transportDiTypes");let p=class{_transports;_transportService;_logger;constructor(r,t){this._transports=r.getAllTransports(),this._transportService=r,this._logger=t("ListenToAvailableDevicesUseCase")}mapTransportDiscoveredDeviceToDiscoveredDevice(r){const t=new D.DeviceModel({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"),(0,s.from)([[]]);if(!r){this._logger.info("Discovering all available transports");const i=this._transports.map((e,n)=>e.listenToAvailableDevices().pipe((0,s.map)(a=>({index:n,arr:a}))));return(0,s.merge)(...i).pipe((0,s.scan)((e,{index:n,arr:a})=>(e[n]=a,e),{}),(0,s.map)(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`),(0,s.of)([])),Just:i=>i.listenToAvailableDevices().pipe((0,s.map)(e=>e.map(this.mapTransportDiscoveredDeviceToDiscoveredDevice)))})}};p=g([(0,c.injectable)(),l(0,(0,c.inject)(T.transportDiTypes.TransportService)),l(1,(0,c.inject)(d.loggerTypes.LoggerPublisherServiceFactory))],p);0&&(module.exports={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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAAuD,gBAEvDC,EAA4B,mCAM5BC,EAA4B,qDAC5BC,EAAiC,mDAe1B,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,IAAI,cAAY,CAClC,GAAID,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.mapTransportDiscoveredDeviceToDiscoveredDevice),\n ),\n );\n },\n });\n }\n}\n"],
|
5
|
+
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAAuD,gBAEvDC,EAA4B,mCAM5BC,EAA4B,qDAC5BC,EAAiC,mDAe1B,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,IAAI,cAAY,CAClC,GAAID,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,CAAE,UAAAE,CAAU,EAAyC,CAAC,EAE5D,CAGA,GAFA,KAAK,QAAQ,KAAK,gCAAgC,EAE9C,KAAK,YAAY,SAAW,EAC9B,YAAK,QAAQ,KAAK,yBAAyB,KACpC,QAAK,CAAC,CAAC,CAAC,CAAC,EAGlB,GAAI,CAACA,EAAW,CACd,KAAK,QAAQ,KAAK,sCAAsC,EASxD,MAAMC,EAAuB,KAAK,YAAY,IAAI,CAACC,EAAGC,IACpDD,EAAE,yBAAyB,EAAE,QAC3B,OAAKE,IAAS,CACZ,MAAAD,EACA,IAAAC,CACF,EAAE,CACJ,CACF,EAEA,SAAO,SAAM,GAAGH,CAAoB,EAAE,QACpC,QAGE,CAACI,EAAK,CAAE,MAAAF,EAAO,IAAAC,CAAI,KACnBC,EAAIF,CAAK,EAAIC,EACNC,GACN,CAAC,CAAC,KACL,OAAKA,GACH,OAAO,OAAOA,CAAG,EACd,KAAK,EACL,IAAI,KAAK,8CAA8C,CAC5D,CACF,CACF,CAEA,YAAK,QAAQ,KAAK,oCAAoCL,CAAS,EAAE,EAEhD,KAAK,kBAAkB,aAAaA,CAAS,EAE9C,OAAO,CACrB,QAAS,KACP,KAAK,QAAQ,MAAM,aAAaA,CAAS,YAAY,KAC9C,MAAG,CAAC,CAAC,GAEd,KAAOE,GACEA,EACJ,yBAAyB,EACzB,QACC,OAAKI,GACHA,EAAQ,IAAI,KAAK,8CAA8C,CACjE,CACF,CAEN,CAAC,CACH,CACF,EAjGaX,EAANY,EAAA,IADN,cAAW,EAMPC,EAAA,eAAO,mBAAiB,gBAAgB,GAExCA,EAAA,eAAO,cAAY,6BAA6B,IAPxCb",
|
6
6
|
"names": ["ListenToAvailableDevicesUseCase_exports", "__export", "ListenToAvailableDevicesUseCase", "__toCommonJS", "import_inversify", "import_rxjs", "import_DeviceModel", "import_loggerTypes", "import_transportDiTypes", "ListenToAvailableDevicesUseCase", "transportService", "loggerFactory", "discoveredDevice", "deviceModel", "transport", "observablesWithIndex", "t", "index", "arr", "acc", "devices", "__decorateClass", "__decorateParam"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var h=(o,r)=>{for(var t in r)a(o,t,{get:r[t],enumerable:!0})},S=(o,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of u(r))!g.call(o,e)&&e!==t&&a(o,e,{get:()=>r[e],enumerable:!(i=v(r,e))||i.enumerable});return o};var b=o=>S(a({},"__esModule",{value:!0}),o),d=(o,r,t,i)=>{for(var e=i>1?void 0:i?v(r,t):r,p=o.length-1,m;p>=0;p--)(m=o[p])&&(e=(i?m(r,t,e):m(e))||e);return i&&e&&a(r,t,e),e},D=(o,r)=>(t,i)=>r(t,i,o);var w={};h(w,{StartDiscoveringUseCase:()=>n});module.exports=b(w);var c=require("inversify"),s=require("rxjs"),f=require("../../../api/device/DeviceModel"),l=require("../../../api/transport/model/Errors"),T=require("../../transport/di/transportDiTypes");let n=class{constructor(r){this._transportService=r}mapDiscoveredDevice(r){const t=new f.DeviceModel({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(!r){const i=this._transportService.getAllTransports();return(0,s.of)(...i).pipe((0,s.mergeMap)(e=>e.startDiscovering().pipe((0,s.map)(p=>this.mapDiscoveredDevice(p)))))}return this._transportService.getTransport(r).caseOf({Just:i=>i.startDiscovering().pipe((0,s.map)(e=>this.mapDiscoveredDevice(e))),Nothing:()=>{throw new l.TransportNotSupportedError(new Error("Unknown transport"))}})}};n=d([(0,c.injectable)(),D(0,(0,c.inject)(T.transportDiTypes.TransportService))],n);0&&(module.exports={StartDiscoveringUseCase});
|
1
|
+
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var h=(o,r)=>{for(var t in r)a(o,t,{get:r[t],enumerable:!0})},S=(o,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of u(r))!g.call(o,e)&&e!==t&&a(o,e,{get:()=>r[e],enumerable:!(i=v(r,e))||i.enumerable});return o};var b=o=>S(a({},"__esModule",{value:!0}),o),d=(o,r,t,i)=>{for(var e=i>1?void 0:i?v(r,t):r,p=o.length-1,m;p>=0;p--)(m=o[p])&&(e=(i?m(r,t,e):m(e))||e);return i&&e&&a(r,t,e),e},D=(o,r)=>(t,i)=>r(t,i,o);var w={};h(w,{StartDiscoveringUseCase:()=>n});module.exports=b(w);var c=require("inversify"),s=require("rxjs"),f=require("../../../api/device/DeviceModel"),l=require("../../../api/transport/model/Errors"),T=require("../../transport/di/transportDiTypes");let n=class{constructor(r){this._transportService=r}mapDiscoveredDevice(r){const t=new f.DeviceModel({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(!r){const i=this._transportService.getAllTransports();return(0,s.of)(...i).pipe((0,s.mergeMap)(e=>e.startDiscovering().pipe((0,s.map)(p=>this.mapDiscoveredDevice(p)))))}return this._transportService.getTransport(r).caseOf({Just:i=>i.startDiscovering().pipe((0,s.map)(e=>this.mapDiscoveredDevice(e))),Nothing:()=>{throw new l.TransportNotSupportedError(new Error("Unknown transport"))}})}};n=d([(0,c.injectable)(),D(0,(0,c.inject)(T.transportDiTypes.TransportService))],n);0&&(module.exports={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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA8C,gBAE9CC,EAA4B,mCAE5BC,EAA2C,uCAG3CC,EAAiC,mDAiB1B,IAAMC,EAAN,KAA8B,CACnC,YAEmBC,EACjB,CADiB,uBAAAA,CAChB,CAEK,oBACNC,EACkB,CAClB,MAAMC,EAAc,IAAI,cAAY,CAClC,GAAID,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,UAAAE,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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA8C,gBAE9CC,EAA4B,mCAE5BC,EAA2C,uCAG3CC,EAAiC,mDAiB1B,IAAMC,EAAN,KAA8B,CACnC,YAEmBC,EACjB,CADiB,uBAAAA,CAChB,CAEK,oBACNC,EACkB,CAClB,MAAMC,EAAc,IAAI,cAAY,CAClC,GAAID,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,UAAAE,CACF,EAAiC,CAAC,EAAiC,CACjE,GAAI,CAACA,EAAW,CACd,MAAMC,EAAa,KAAK,kBAAkB,iBAAiB,EAC3D,SAAO,MAAG,GAAGA,CAAU,EAAE,QACvB,YAAUC,GACRA,EACG,iBAAiB,EACjB,QAAK,OAAKJ,GAAW,KAAK,oBAAoBA,CAAM,CAAC,CAAC,CAC3D,CACF,CACF,CAIA,OAFiB,KAAK,kBAAkB,aAAaE,CAAS,EAE9C,OAAO,CACrB,KAAOG,GACEA,EACJ,iBAAiB,EACjB,QAAK,OAAKL,GAAW,KAAK,oBAAoBA,CAAM,CAAC,CAAC,EAE3D,QAAS,IAAM,CACb,MAAM,IAAI,6BAA2B,IAAI,MAAM,mBAAmB,CAAC,CACrE,CACF,CAAC,CACH,CACF,EAlDaF,EAANQ,EAAA,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,gBAAgB,IAFhCT",
|
6
6
|
"names": ["StartDiscoveringUseCase_exports", "__export", "StartDiscoveringUseCase", "__toCommonJS", "import_inversify", "import_rxjs", "import_DeviceModel", "import_Errors", "import_transportDiTypes", "StartDiscoveringUseCase", "_transportService", "device", "deviceModel", "transport", "transports", "instance", "t", "__decorateClass", "__decorateParam"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var
|
1
|
+
"use strict";var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var j=(t,r)=>{for(var e in r)a(t,e,{get:r[e],enumerable:!0})},u=(t,r,e,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of l(r))!y.call(t,o)&&o!==e&&a(t,o,{get:()=>r[o],enumerable:!(p=m(r,o))||p.enumerable});return t};var x=t=>u(a({},"__esModule",{value:!0}),t),f=(t,r,e,p)=>{for(var o=p>1?void 0:p?m(r,e):r,n=t.length-1,s;n>=0;n--)(s=t[n])&&(o=(p?s(r,e,o):s(o))||o);return p&&o&&a(r,e,o),o},v=(t,r)=>(e,p)=>r(e,p,t);var S={};j(S,{StopDiscoveringUseCase:()=>i});module.exports=x(S);var c=require("inversify"),T=require("../../transport/di/transportDiTypes");let i=class{constructor(r){this.transportService=r}async execute(){for(const r of this.transportService.getAllTransports())await r.stopDiscovering()}};i=f([(0,c.injectable)(),v(0,(0,c.inject)(T.transportDiTypes.TransportService))],i);0&&(module.exports={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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAEnCC,EAAiC,mDAO1B,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": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBAEnCC,EAAiC,mDAO1B,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,IADN,cAAW,EAGPC,EAAA,eAAO,mBAAiB,gBAAgB,IAFhCJ",
|
6
6
|
"names": ["StopDiscoveringUseCase_exports", "__export", "StopDiscoveringUseCase", "__toCommonJS", "import_inversify", "import_transportDiTypes", "StopDiscoveringUseCase", "transportService", "transport", "__decorateClass", "__decorateParam"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";var s=require("../../../api/transport/model/__mocks__/TransportMock"),n=require("../../transport/service/DefaultTransportService"),a=require("./StopDiscoveringUseCase");vi.mock("@internal/transport/service/DefaultTransportService");let e,r,t;describe("StopDiscoveringUseCase",()=>{beforeEach(()=>{e=new s.TransportMock,r=[e],
|
1
|
+
"use strict";var s=require("../../../api/transport/model/__mocks__/TransportMock"),n=require("../../transport/service/DefaultTransportService"),a=require("./StopDiscoveringUseCase");vi.mock("@internal/transport/service/DefaultTransportService");let e,r,t,o;describe("StopDiscoveringUseCase",()=>{beforeEach(()=>{e=new s.TransportMock,r=new s.TransportMock,t=[e,r],o=new n.DefaultTransportService(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.StopDiscoveringUseCase(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,IAAAA,EAA8B,wDAE9BC,EAAwC,+DAGxCC,EAAuC,oCAEvC,GAAG,KAAK,qDAAqD,EAG7D,IAAIC,EACAC,EACAC,EAEJ,SAAS,yBAA0B,IAAM,CACvC,WAAW,IAAM,
|
6
|
-
"names": ["import_TransportMock", "import_DefaultTransportService", "import_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,IAAAA,EAA8B,wDAE9BC,EAAwC,+DAGxCC,EAAuC,oCAEvC,GAAG,KAAK,qDAAqD,EAG7D,IAAIC,EACAC,EACAC,EACAC,EAEJ,SAAS,yBAA0B,IAAM,CACvC,WAAW,IAAM,CACfH,EAAY,IAAI,gBAChBC,EAAa,IAAI,gBACjBC,EAAa,CAACF,EAAWC,CAAU,EAEnCE,EAAmB,IAAI,0BAAwBD,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,IAAI,yBAAuBC,CAAgB,EAE7C,QAAQ,EAEtB,OAAOH,EAAU,eAAe,EAAE,iBAAiB,EACnD,OAAOC,EAAW,eAAe,EAAE,iBAAiB,CACtD,CAAC,CACH,CAAC",
|
6
|
+
"names": ["import_TransportMock", "import_DefaultTransportService", "import_StopDiscoveringUseCase", "transport", "transport2", "transports", "transportService"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var S=Object.defineProperty;var
|
1
|
+
var S=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=(t,e,r,s)=>{for(var o=s>1?void 0:s?d(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=(s?c(e,r,o):c(o))||o);return s&&o&&S(e,r,o),o},a=(t,e)=>(r,s)=>e(r,s,t);import{inject as m,injectable as v}from"inversify";import{deviceSessionTypes as p}from"../../../internal/device-session/di/deviceSessionTypes";import{loggerTypes as l}from"../../../internal/logger-publisher/di/loggerTypes";let n=class{_sessionService;_logger;constructor(e,r){this._sessionService=e,this._logger=r("SendCommandUseCase")}async execute({sessionId:e,command:r,abortTimeout:s}){return this._sessionService.getDeviceSessionById(e).caseOf({Right:async i=>await i.sendCommand(r,s),Left:i=>{throw this._logger.error("Error getting session",{data:{error:i}}),i}})}};n=g([v(),a(0,m(p.DeviceSessionService)),a(1,m(l.LoggerPublisherServiceFactory))],n);export{n as SendCommandUseCase};
|
2
2
|
//# sourceMappingURL=SendCommandUseCase.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/api/command/use-case/SendCommandUseCase.ts"],
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { Command } from \"@api/command/Command\";\nimport { CommandResult } from \"@api/command/model/CommandResult\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\nexport type SendCommandUseCaseArgs<Response, ErrorStatusCodes, Args = void> = {\n /**\n * The device session id.\n */\n readonly sessionId: string;\n /**\n * The command to send.\n */\n readonly command: Command<Response, ErrorStatusCodes, Args>;\n};\n\n/**\n * Sends a command to a device through a device session.\n */\n@injectable()\nexport class SendCommandUseCase {\n private readonly _sessionService: DeviceSessionService;\n private readonly _logger: LoggerPublisherService;\n constructor(\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._sessionService = sessionService;\n this._logger = loggerFactory(\"SendCommandUseCase\");\n }\n\n /**\n * Sends a command to a device through a device session.\n *\n * @param sessionId - The device session id.\n * @param command - The command to send.\n * @returns The response from the command.\n */\n async execute<Response, Args, ErrorStatusCodes>({\n sessionId,\n command,\n }: SendCommandUseCaseArgs<Response, Args, ErrorStatusCodes>): Promise<\n CommandResult<Response, ErrorStatusCodes>\n > {\n const deviceSessionOrError =\n this._sessionService.getDeviceSessionById(sessionId);\n\n return deviceSessionOrError.caseOf({\n // Case device session found\n Right: async (deviceSession) =>\n await deviceSession.sendCommand<Response, Args, ErrorStatusCodes>(\n command,\n ),\n // Case device session not found\n Left: (error) => {\n this._logger.error(\"Error getting session\", {\n data: { error },\n });\n throw error;\n },\n });\n }\n}\n"],
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAKnC,OAAS,sBAAAC,MAA0B,iDAEnC,OAAS,eAAAC,MAAmB,
|
6
|
-
"names": ["inject", "injectable", "deviceSessionTypes", "loggerTypes", "SendCommandUseCase", "sessionService", "loggerFactory", "sessionId", "command", "deviceSession", "error", "__decorateClass", "injectable", "__decorateParam", "inject", "deviceSessionTypes", "loggerTypes"]
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { Command } from \"@api/command/Command\";\nimport { CommandResult } from \"@api/command/model/CommandResult\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport type { DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\nexport type SendCommandUseCaseArgs<Response, ErrorStatusCodes, Args = void> = {\n /**\n * The device session id.\n */\n readonly sessionId: string;\n /**\n * The command to send.\n */\n readonly command: Command<Response, ErrorStatusCodes, Args>;\n /**\n * The timeout to abort the command.\n */\n readonly abortTimeout?: number;\n};\n\n/**\n * Sends a command to a device through a device session.\n */\n@injectable()\nexport class SendCommandUseCase {\n private readonly _sessionService: DeviceSessionService;\n private readonly _logger: LoggerPublisherService;\n constructor(\n @inject(deviceSessionTypes.DeviceSessionService)\n sessionService: DeviceSessionService,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._sessionService = sessionService;\n this._logger = loggerFactory(\"SendCommandUseCase\");\n }\n\n /**\n * Sends a command to a device through a device session.\n *\n * @param sessionId - The device session id.\n * @param command - The command to send.\n * @returns The response from the command.\n */\n async execute<Response, Args, ErrorStatusCodes>({\n sessionId,\n command,\n abortTimeout,\n }: SendCommandUseCaseArgs<Response, Args, ErrorStatusCodes>): Promise<\n CommandResult<Response, ErrorStatusCodes>\n > {\n const deviceSessionOrError =\n this._sessionService.getDeviceSessionById(sessionId);\n\n return deviceSessionOrError.caseOf({\n // Case device session found\n Right: async (deviceSession) =>\n await deviceSession.sendCommand<Response, Args, ErrorStatusCodes>(\n command,\n abortTimeout,\n ),\n // Case device session not found\n Left: (error) => {\n this._logger.error(\"Error getting session\", {\n data: { error },\n });\n throw error;\n },\n });\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAKnC,OAAS,sBAAAC,MAA0B,iDAEnC,OAAS,eAAAC,MAAmB,4CAqBrB,IAAMC,EAAN,KAAyB,CACb,gBACA,QACjB,YAEEC,EAEAC,EACA,CACA,KAAK,gBAAkBD,EACvB,KAAK,QAAUC,EAAc,oBAAoB,CACnD,CASA,MAAM,QAA0C,CAC9C,UAAAC,EACA,QAAAC,EACA,aAAAC,CACF,EAEE,CAIA,OAFE,KAAK,gBAAgB,qBAAqBF,CAAS,EAEzB,OAAO,CAEjC,MAAO,MAAOG,GACZ,MAAMA,EAAc,YAClBF,EACAC,CACF,EAEF,KAAOE,GAAU,CACf,WAAK,QAAQ,MAAM,wBAAyB,CAC1C,KAAM,CAAE,MAAAA,CAAM,CAChB,CAAC,EACKA,CACR,CACF,CAAC,CACH,CACF,EA9CaP,EAANQ,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAmB,oBAAoB,GAE9CF,EAAA,EAAAC,EAAOE,EAAY,6BAA6B,IANxCb",
|
6
|
+
"names": ["inject", "injectable", "deviceSessionTypes", "loggerTypes", "SendCommandUseCase", "sessionService", "loggerFactory", "sessionId", "command", "abortTimeout", "deviceSession", "error", "__decorateClass", "injectable", "__decorateParam", "inject", "deviceSessionTypes", "loggerTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{Left as
|
1
|
+
import{Left as S,Right as A}from"purify-ts";import{Observable as m}from"rxjs";import{tap as y,timeout as g}from"rxjs/operators";import{assign as t,fromObservable as k,fromPromise as b,setup as f}from"xstate";import{isSuccessCommandResult as E}from"../../../command/model/CommandResult";import{GetAppAndVersionCommand as V}from"../../../command/os/GetAppAndVersionCommand";import{DeviceStatus as h}from"../../../device/DeviceStatus";import{UserInteractionRequired as c}from"../../../device-action/model/UserInteractionRequired";import{DEFAULT_UNLOCK_TIMEOUT_MS as U}from"../../../device-action/os/Const";import{DeviceLockedError as G,DeviceNotOnboardedError as x}from"../../../device-action/os/Errors";import{XStateDeviceAction as I}from"../../../device-action/xstate-utils/XStateDeviceAction";import{DeviceSessionStateType as d}from"../../../device-session/DeviceSessionState";class W extends I{makeStateMachine(r){const{getAppAndVersion:l,getDeviceSessionState:u,setDeviceSessionState:i,waitForDeviceUnlock:p,isDeviceOnboarded:o}=this.extractDependencies(r),a=this.input.unlockTimeout??U;return f({types:{input:{unlockTimeout:a},context:{},output:{}},actors:{getAppAndVersion:b(l),waitForDeviceUnlock:k(p)},guards:{isDeviceOnboarded:()=>o(),isDeviceLocked:({context:e})=>e._internalState.locked,hasError:({context:e})=>e._internalState.error!==null},actions:{assignErrorDeviceNotOnboarded:t({_internalState:e=>({...e.context._internalState,error:new x})}),assignErrorDeviceLocked:t({_internalState:e=>({...e.context._internalState,error:new G}),intermediateValue:{requiredUserInteraction:c.UnlockDevice}}),assignErrorFromEvent:t({_internalState:e=>({...e.context._internalState,error:e.event.error})}),assignNoUserActionNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:c.None})}),assignUserActionUnlockNeeded:t({intermediateValue:e=>({...e.context.intermediateValue,requiredUserInteraction:c.UnlockDevice})})}}).createMachine({id:"GetDeviceStatusDeviceAction",initial:"DeviceReady",context:e=>{const n=u(),{sessionStateType:s}=n;return{input:{unlockTimeout:e.input.unlockTimeout},intermediateValue:{requiredUserInteraction:c.None},_internalState:{onboarded:!1,locked:!1,currentApp:s===d.ReadyWithoutSecureChannel?n.currentApp.name:null,currentAppVersion:null,error:null}}},states:{DeviceReady:{always:{target:"OnboardingCheck"}},OnboardingCheck:{always:[{guard:{type:"isDeviceOnboarded"},target:"AppAndVersionCheck",actions:t({_internalState:e=>({...e.context._internalState,onboarded:!0})})},{target:"Error",actions:"assignErrorDeviceNotOnboarded"}]},UserActionUnlockDevice:{entry:"assignUserActionUnlockNeeded",exit:"assignNoUserActionNeeded",invoke:{id:"UserActionUnlockDevice",src:"waitForDeviceUnlock",input:e=>({unlockTimeout:a}),onDone:{target:"AppAndVersionCheck",actions:t({_internalState:e=>({...e.context._internalState,locked:!1})})},onError:{target:"Error",actions:"assignErrorDeviceLocked"}}},AppAndVersionCheck:{invoke:{src:"getAppAndVersion",onDone:{target:"ApplicationAvailableResultCheck",actions:t({_internalState:e=>{if(E(e.event.output)){const n=u();return n.sessionStateType!==d.Connected&&i({...n,currentApp:e.event.output.data}),{...e.context._internalState,locked:!1,currentApp:e.event.output.data.name,currentAppVersion:e.event.output.data.version}}return"errorCode"in e.event.output.error&&e.event.output.error.errorCode==="5515"?{...e.context._internalState,locked:!0}:{...e.context._internalState,error:e.event.output.error}}})},onError:{target:"Error",actions:"assignErrorFromEvent"}}},ApplicationAvailableResultCheck:{always:[{guard:"hasError",target:"Error"},{target:"UserActionUnlockDevice",guard:"isDeviceLocked"},{target:"Success"}]},Success:{type:"final"},Error:{type:"final"}},output:e=>{const{context:n}=e,{error:s,currentApp:D,currentAppVersion:v}=n._internalState;return s?S(s):A({currentApp:D,currentAppVersion:v})}})}extractDependencies(r){return{getAppAndVersion:()=>r.sendCommand(new V),waitForDeviceUnlock:({input:i})=>new m(p=>{const o=r.getDeviceSessionStateObservable().pipe(y(a=>{a.deviceStatus===h.CONNECTED&&(p.complete(),o.unsubscribe())})).subscribe();return()=>{o.unsubscribe()}}).pipe(g(i.unlockTimeout)),getDeviceSessionState:()=>r.getDeviceSessionState(),setDeviceSessionState:i=>r.setDeviceSessionState(i),isDeviceOnboarded:()=>!0}}}export{W as GetDeviceStatusDeviceAction};
|
2
2
|
//# sourceMappingURL=GetDeviceStatusDeviceAction.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../../src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.ts"],
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\nimport { tap, timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n isDeviceOnboarded,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isDeviceUnlocked: () =>\n getDeviceSessionState().deviceStatus !== DeviceStatus.LOCKED,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzadjiHx2KyORbzcRBczmH4IbTOdjaabaKmdGy6XSRaIw1bbdZJLa0MBI9LsVHo45Ys4XBr45r3dps-n0ubaGxgx6PZlWULkkLBGmDCzGYzQ2Ei+HJEVStjsACqsDA+SdrBdrAANmjqmthBA2GB2MVsMxqmG3R6vT7-TU1hJcdcVXciYgglZycYQiYqRTQoZtMynDmbM4aW8rHYzD4BSs4hL7eLuF7Xe7PWk2AmA0GPflmPl2LJfeQAGbDgC2nbjPe9fv7IpTyqaGdAbXmxnZPkMNNM820VuZ+8M7Dsb3MznpwW31sFtpbGwdEo7dFksjorAgADUPYobAnNiIasGGEZRmGT4JC+bY7NKH5fj+-75IBrDAdUCAQfg5DpCmq5XDcqqZmMjgGDY-yGJeejjFRzJ2P47DZoEJb+Hyx42sKz5ioiC7sIh35-gB6QYcIg7DqO45oFO+SztBhCtrxuwCchwlAQqWGsJGOHNPh9SEemhKbogdLsIMTjmPuNF1nYZaOBW+5OPu9l1oCjZCs2ME8Y6fGIb6BC4WwdDYKQuDjtkvq8HAFC+mgokEXi65GeoiBguYZJOPSJa6Hm1hGsyuglkxxiUjYVjXlq7nyaKCI+cpn7+Tp6TBaF4WRXwsAxXFCpiEqBlJS0JFAo4vg+BCe55e8-QFUVVglVShjlWRtZ2FEgqsMwEBwKo1WKXVG5pgNaokmRZmQg4fyLHR7ieCNpjGPyx7aNo6UNo4nGeQpsFKdKax8AIoyJQSg3Ge0L07q9F3+Istk3Qg1IjUaZ7GNS-LlU4H1wt9+3OvseSFBiGFrsDx01mZ15mHooReFaVj0fZ5Jci5zissYIKY3a2NvnxsrVITCrE8RoMdDucxWgx1jpZCELDHDgKTC9jg6mNXKLDSHPcbV3O7LG3bNH2SYioLB3EmCI1-HuVL6Cj4hU6eNjsIVD3UrWfKXVCj5cV5Wvtr5n6CShaFE-1JMkWzPgXpCjh+Faw3Mjq5jdOlJhGvo-RzRr3uvr79VjgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n onboarded: false, // we don't know how to check yet\n locked: sessionState.deviceStatus === DeviceStatus.LOCKED,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"OnboardingCheck\",\n },\n },\n OnboardingCheck: {\n // TODO: we don't have this info for now\n always: [\n {\n guard: {\n type: \"isDeviceOnboarded\",\n },\n target: \"LockingCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n LockingCheck: {\n // We check if the device is locked in the session state\n always: [\n {\n target: \"AppAndVersionCheck\",\n guard: {\n type: \"isDeviceUnlocked\",\n },\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n {\n target: \"UserActionUnlockDevice\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion command\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n // Narrow the type to ReadyWithoutSecureChannelState or ReadyWithSecureChannelState\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n }\n return {\n ..._.context._internalState,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n new Observable<void>((subscriber) => {\n const inner = internalApi\n .getDeviceSessionStateObservable()\n .pipe(\n tap((state) => {\n if (state.deviceStatus === DeviceStatus.CONNECTED) {\n subscriber.complete();\n inner.unsubscribe();\n }\n }),\n )\n .subscribe();\n\n return () => {\n inner.unsubscribe();\n };\n }).pipe(timeout(input.unlockTimeout));\n\n return {\n getAppAndVersion,\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now\n };\n }\n}\n"],
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,MAAkB,OAC3B,OAAS,OAAAC,EAAK,WAAAC,MAAe,iBAC7B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCACvC,OACE,2BAAAC,MAEK,0CACP,OAAS,gBAAAC,MAAoB,2BAE7B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OACE,qBAAAC,EACA,2BAAAC,MACK,+BAEP,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCAiCA,MAAMC,UAAoCF,CAM/C,CACA,iBACEG,EAOA,CASA,KAAM,CACJ,iBAAAC,EACA,sBAAAC,EACA,sBAAAC,EACA,oBAAAC,EACA,kBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBZ,EAElD,OAAOL,EAAM,CACX,MAAO,CACL,MAAO,CACL,cAAAiB,CACF,EACA,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,iBAAkBlB,EAAYa,CAAgB,EAC9C,oBAAqBd,EAAeiB,CAAmB,CACzD,EACA,OAAQ,CACN,kBAAmB,IAAMC,EAAkB,EAC3C,
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\nimport { tap, timeout } from \"rxjs/operators\";\nimport { assign, fromObservable, fromPromise, setup } from \"xstate\";\n\nimport { isSuccessCommandResult } from \"@api/command/model/CommandResult\";\nimport {\n GetAppAndVersionCommand,\n type GetAppAndVersionCommandResult,\n} from \"@api/command/os/GetAppAndVersionCommand\";\nimport { DeviceStatus } from \"@api/device/DeviceStatus\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { DEFAULT_UNLOCK_TIMEOUT_MS } from \"@api/device-action/os/Const\";\nimport {\n DeviceLockedError,\n DeviceNotOnboardedError,\n} from \"@api/device-action/os/Errors\";\nimport { type StateMachineTypes } from \"@api/device-action/xstate-utils/StateMachineTypes\";\nimport {\n type DeviceActionStateMachine,\n XStateDeviceAction,\n} from \"@api/device-action/xstate-utils/XStateDeviceAction\";\nimport {\n type DeviceSessionState,\n DeviceSessionStateType,\n} from \"@api/device-session/DeviceSessionState\";\n\nimport {\n type GetDeviceStatusDAError,\n type GetDeviceStatusDAInput,\n type GetDeviceStatusDAIntermediateValue,\n type GetDeviceStatusDAOutput,\n} from \"./types\";\n\ntype GetDeviceStatusMachineInternalState = {\n readonly onboarded: boolean;\n readonly locked: boolean;\n readonly currentApp: string | null;\n readonly currentAppVersion: string | null;\n readonly error: GetDeviceStatusDAError | null;\n};\n\nexport type MachineDependencies = {\n readonly getAppAndVersion: () => Promise<GetAppAndVersionCommandResult>;\n readonly getDeviceSessionState: () => DeviceSessionState;\n readonly waitForDeviceUnlock: (args: {\n input: { unlockTimeout: number };\n }) => Observable<void>;\n readonly setDeviceSessionState: (\n state: DeviceSessionState,\n ) => DeviceSessionState;\n readonly isDeviceOnboarded: () => boolean;\n};\n\nexport type ExtractMachineDependencies = (\n internalApi: InternalApi,\n) => MachineDependencies;\n\nexport class GetDeviceStatusDeviceAction extends XStateDeviceAction<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n> {\n makeStateMachine(\n internalApi: InternalApi,\n ): DeviceActionStateMachine<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n > {\n type types = StateMachineTypes<\n GetDeviceStatusDAOutput,\n GetDeviceStatusDAInput,\n GetDeviceStatusDAError,\n GetDeviceStatusDAIntermediateValue,\n GetDeviceStatusMachineInternalState\n >;\n\n const {\n getAppAndVersion,\n getDeviceSessionState,\n setDeviceSessionState,\n waitForDeviceUnlock,\n isDeviceOnboarded,\n } = this.extractDependencies(internalApi);\n\n const unlockTimeout = this.input.unlockTimeout ?? DEFAULT_UNLOCK_TIMEOUT_MS;\n\n return setup({\n types: {\n input: {\n unlockTimeout,\n } as types[\"input\"],\n context: {} as types[\"context\"],\n output: {} as types[\"output\"],\n },\n actors: {\n getAppAndVersion: fromPromise(getAppAndVersion),\n waitForDeviceUnlock: fromObservable(waitForDeviceUnlock),\n },\n guards: {\n isDeviceOnboarded: () => isDeviceOnboarded(), // TODO: we don't have this info for now, this can be derived from the \"flags\" obtained in the getVersion command\n isDeviceLocked: ({ context }) => context._internalState.locked,\n hasError: ({ context }) => context._internalState.error !== null,\n },\n actions: {\n assignErrorDeviceNotOnboarded: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceNotOnboardedError(),\n }),\n }),\n assignErrorDeviceLocked: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: new DeviceLockedError(),\n }),\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n },\n }),\n assignErrorFromEvent: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n error: _.event[\"error\"], // NOTE: it should never happen, the error is not typed anymore here\n }),\n }),\n assignNoUserActionNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.None,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n assignUserActionUnlockNeeded: assign({\n intermediateValue: (_) =>\n ({\n ..._.context.intermediateValue,\n requiredUserInteraction: UserInteractionRequired.UnlockDevice,\n }) satisfies types[\"context\"][\"intermediateValue\"],\n }),\n },\n }).createMachine({\n /** @xstate-layout N4IgpgJg5mDOIC5QHEwBcAiYBuBLAxmAMpoCGaArrFnoQIL5q4D2AdgHQ0FgBKYpEAJ4BiANoAGALqJQAB2axcTNjJAAPRAFoArAHZx7AIwAmQ7oCcugMyHzANmMAWYwBoQgxI8vsAHOJM+VuLmVj5e2gC+EW6omDjcJORUXPSMLBwA8qwARsykAE4QuKxQAMIAFmD4ANZiUqryisqsqhoImo4O7OGhPj4h5n6Obh4IunZ2RoZ+ena6nYaGUTHoKcRklNTxqc3sWbkFRSUVVbWihtJIII1K6a1aVtoGTxOOjtbv84YjiObik7ofPM7GFDP9jNofMsQLE1olNmsGLsADLMGrFMqVGp1S5yBS3FRXNqaOzadjiHx2KyORbzcRBczmH4IbTOdjaabaKmdGy6XSRaIw1bbdZJLa0MBI9LsVHo45Ys4XBr45r3dps-n0ubaGxgx6PZlWULkkLBGmDCzGYzQ2Ei+HJEVStjsACqsDA+SdrBdrAANmjqmthBA2GB2MVsMxqmG3R6vT7-TU1hJcdcVXciYgglZycYQiYqRTQoZtMynDmbM4aW8rHYzD4BSs4hL7eLuF7Xe7PWk2AmA0GPflmPl2LJfeQAGbDgC2nbjPe9fv7IpTyqaGdAbXmxnZPkMNNM820VuZ+8M7Dsb3MznpwW31sFtpbGwdEo7dFksjorAgADUPYobAnNiIasGGEZRmGT4JC+bY7NKH5fj+-75IBrDAdUCAQfg5DpCmq5XDcqqZmMjgGDY-yGJeejjFRzJ2P47DZoEJb+Hyx42sKz5ioiC7sIh35-gB6QYcIg7DqO45oFO+SztBhCtrxuwCchwlAQqWGsJGOHNPh9SEemhKbogdLsIMTjmPuNF1nYZaOBW+5OPu9l1oCjZCs2ME8Y6fGIb6BC4WwdDYKQuDjtkvq8HAFC+mgokEXi65GeoiBguYZJOPSJa6Hm1hGsyuglkxxiUjYVjXlq7nyaKCI+cpn7+Tp6TBaF4WRXwsAxXFCpiEqBlJS0JFAo4vg+BCe55e8-QFUVVglVShjlWRtZ2FEgqsMwEBwKo1WKXVG5pgNaokmRZmQg4fyLHR7ieCNpjGPyx7aNo6UNo4nGeQpsFKdKax8AIoyJQSg3Ge0L07q9F3+Istk3Qg1IjUaZ7GNS-LlU4H1wt9+3OvseSFBiGFrsDx01mZ15mHooReFaVj0fZ5Jci5zissYIKY3a2NvnxsrVITCrE8RoMdDucxWgx1jpZCELDHDgKTC9jg6mNXKLDSHPcbV3O7LG3bNH2SYioLB3EmCI1-HuVL6Cj4hU6eNjsIVD3UrWfKXVCj5cV5Wvtr5n6CShaFE-1JMkWzPgXpCjh+Faw3Mjq5jdOlJhGvo-RzRr3uvr79VjgFzQtWFpARVFnWxcHQNCylCBm+eKPjJL4jWMEdNww4O46vSFVsfyD5Nlj3na9KRAUPghCwPAIdV20QIR7e-RzOYbNK98cN7ndgR-BSzgo+YmdfYPOfSgAovkQ75MbyVtItehmSrJgcijz2uHD+pmXyQSQnyVLs2tQA */\n id: \"GetDeviceStatusDeviceAction\",\n initial: \"DeviceReady\",\n context: (_) => {\n const sessionState = getDeviceSessionState();\n const { sessionStateType } = sessionState;\n return {\n input: {\n unlockTimeout: _.input.unlockTimeout,\n },\n intermediateValue: {\n requiredUserInteraction: UserInteractionRequired.None,\n },\n _internalState: {\n onboarded: false, // we don't know how to check yet\n locked: false,\n currentApp:\n sessionStateType ===\n DeviceSessionStateType.ReadyWithoutSecureChannel\n ? sessionState.currentApp.name\n : null,\n currentAppVersion: null,\n error: null,\n },\n };\n },\n states: {\n DeviceReady: {\n always: {\n target: \"OnboardingCheck\",\n },\n },\n OnboardingCheck: {\n // TODO: we don't have this info for now\n always: [\n {\n guard: {\n type: \"isDeviceOnboarded\",\n },\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n onboarded: true,\n }),\n }),\n },\n {\n target: \"Error\",\n actions: \"assignErrorDeviceNotOnboarded\",\n },\n ],\n },\n UserActionUnlockDevice: {\n // we wait for the device to be unlocked (default timeout is 15s)\n entry: \"assignUserActionUnlockNeeded\",\n exit: \"assignNoUserActionNeeded\",\n invoke: {\n id: \"UserActionUnlockDevice\",\n src: \"waitForDeviceUnlock\",\n input: (_) => ({\n unlockTimeout,\n }),\n onDone: {\n target: \"AppAndVersionCheck\",\n actions: assign({\n _internalState: (_) => ({\n ..._.context._internalState,\n locked: false,\n }),\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorDeviceLocked\",\n },\n },\n },\n AppAndVersionCheck: {\n // We check the current app and version using the getAppAndVersion command\n invoke: {\n src: \"getAppAndVersion\",\n onDone: {\n target: \"ApplicationAvailableResultCheck\",\n actions: assign({\n _internalState: (_) => {\n if (isSuccessCommandResult(_.event.output)) {\n const state: DeviceSessionState = getDeviceSessionState();\n // Narrow the type to ReadyWithoutSecureChannelState or ReadyWithSecureChannelState\n if (\n state.sessionStateType !==\n DeviceSessionStateType.Connected\n ) {\n setDeviceSessionState({\n ...state,\n currentApp: _.event.output.data,\n });\n }\n return {\n ..._.context._internalState,\n locked: false,\n currentApp: _.event.output.data.name,\n currentAppVersion: _.event.output.data.version,\n };\n }\n if (\n \"errorCode\" in _.event.output.error &&\n _.event.output.error.errorCode === \"5515\"\n ) {\n return {\n ..._.context._internalState,\n locked: true,\n };\n }\n return {\n ..._.context._internalState,\n error: _.event.output.error,\n };\n },\n }),\n },\n onError: {\n target: \"Error\",\n actions: \"assignErrorFromEvent\",\n },\n },\n },\n ApplicationAvailableResultCheck: {\n always: [\n {\n guard: \"hasError\",\n target: \"Error\",\n },\n {\n target: \"UserActionUnlockDevice\",\n guard: \"isDeviceLocked\",\n },\n {\n target: \"Success\",\n },\n ],\n },\n Success: {\n type: \"final\",\n },\n Error: {\n type: \"final\",\n },\n },\n output: (args) => {\n // TODO: instead we should rely on the current state (\"Success\" or \"Error\")\n const { context } = args;\n const { error, currentApp, currentAppVersion } = context._internalState;\n if (error) {\n return Left(error);\n }\n return Right<GetDeviceStatusDAOutput>({\n currentApp: currentApp!,\n currentAppVersion: currentAppVersion!,\n });\n },\n });\n }\n\n extractDependencies(internalApi: InternalApi): MachineDependencies {\n const getAppAndVersion = () => {\n return internalApi.sendCommand(new GetAppAndVersionCommand());\n };\n\n const waitForDeviceUnlock = ({\n input,\n }: {\n input: { unlockTimeout: number };\n }) =>\n new Observable<void>((subscriber) => {\n const inner = internalApi\n .getDeviceSessionStateObservable()\n .pipe(\n tap((state) => {\n if (state.deviceStatus === DeviceStatus.CONNECTED) {\n subscriber.complete();\n inner.unsubscribe();\n }\n }),\n )\n .subscribe();\n\n return () => {\n inner.unsubscribe();\n };\n }).pipe(timeout(input.unlockTimeout));\n\n return {\n getAppAndVersion,\n waitForDeviceUnlock,\n getDeviceSessionState: () => internalApi.getDeviceSessionState(),\n setDeviceSessionState: (state: DeviceSessionState) =>\n internalApi.setDeviceSessionState(state),\n isDeviceOnboarded: () => true, // TODO: we don't have this info for now\n };\n }\n}\n"],
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAC5B,OAAS,cAAAC,MAAkB,OAC3B,OAAS,OAAAC,EAAK,WAAAC,MAAe,iBAC7B,OAAS,UAAAC,EAAQ,kBAAAC,EAAgB,eAAAC,EAAa,SAAAC,MAAa,SAE3D,OAAS,0BAAAC,MAA8B,mCACvC,OACE,2BAAAC,MAEK,0CACP,OAAS,gBAAAC,MAAoB,2BAE7B,OAAS,2BAAAC,MAA+B,mDACxC,OAAS,6BAAAC,MAAiC,8BAC1C,OACE,qBAAAC,EACA,2BAAAC,MACK,+BAEP,OAEE,sBAAAC,MACK,qDACP,OAEE,0BAAAC,MACK,yCAiCA,MAAMC,UAAoCF,CAM/C,CACA,iBACEG,EAOA,CASA,KAAM,CACJ,iBAAAC,EACA,sBAAAC,EACA,sBAAAC,EACA,oBAAAC,EACA,kBAAAC,CACF,EAAI,KAAK,oBAAoBL,CAAW,EAElCM,EAAgB,KAAK,MAAM,eAAiBZ,EAElD,OAAOL,EAAM,CACX,MAAO,CACL,MAAO,CACL,cAAAiB,CACF,EACA,QAAS,CAAC,EACV,OAAQ,CAAC,CACX,EACA,OAAQ,CACN,iBAAkBlB,EAAYa,CAAgB,EAC9C,oBAAqBd,EAAeiB,CAAmB,CACzD,EACA,OAAQ,CACN,kBAAmB,IAAMC,EAAkB,EAC3C,eAAgB,CAAC,CAAE,QAAAE,CAAQ,IAAMA,EAAQ,eAAe,OACxD,SAAU,CAAC,CAAE,QAAAA,CAAQ,IAAMA,EAAQ,eAAe,QAAU,IAC9D,EACA,QAAS,CACP,8BAA+BrB,EAAO,CACpC,eAAiBsB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,MAAO,IAAIZ,CACb,EACF,CAAC,EACD,wBAAyBV,EAAO,CAC9B,eAAiBsB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,MAAO,IAAIb,CACb,GACA,kBAAmB,CACjB,wBAAyBF,EAAwB,YACnD,CACF,CAAC,EACD,qBAAsBP,EAAO,CAC3B,eAAiBsB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,MAAOA,EAAE,MAAM,KACjB,EACF,CAAC,EACD,yBAA0BtB,EAAO,CAC/B,kBAAoBsB,IACjB,CACC,GAAGA,EAAE,QAAQ,kBACb,wBAAyBf,EAAwB,IACnD,EACJ,CAAC,EACD,6BAA8BP,EAAO,CACnC,kBAAoBsB,IACjB,CACC,GAAGA,EAAE,QAAQ,kBACb,wBAAyBf,EAAwB,YACnD,EACJ,CAAC,CACH,CACF,CAAC,EAAE,cAAc,CAEf,GAAI,8BACJ,QAAS,cACT,QAAUe,GAAM,CACd,MAAMC,EAAeP,EAAsB,EACrC,CAAE,iBAAAQ,CAAiB,EAAID,EAC7B,MAAO,CACL,MAAO,CACL,cAAeD,EAAE,MAAM,aACzB,EACA,kBAAmB,CACjB,wBAAyBf,EAAwB,IACnD,EACA,eAAgB,CACd,UAAW,GACX,OAAQ,GACR,WACEiB,IACAZ,EAAuB,0BACnBW,EAAa,WAAW,KACxB,KACN,kBAAmB,KACnB,MAAO,IACT,CACF,CACF,EACA,OAAQ,CACN,YAAa,CACX,OAAQ,CACN,OAAQ,iBACV,CACF,EACA,gBAAiB,CAEf,OAAQ,CACN,CACE,MAAO,CACL,KAAM,mBACR,EACA,OAAQ,qBACR,QAASvB,EAAO,CACd,eAAiBsB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,UAAW,EACb,EACF,CAAC,CACH,EACA,CACE,OAAQ,QACR,QAAS,+BACX,CACF,CACF,EACA,uBAAwB,CAEtB,MAAO,+BACP,KAAM,2BACN,OAAQ,CACN,GAAI,yBACJ,IAAK,sBACL,MAAQA,IAAO,CACb,cAAAF,CACF,GACA,OAAQ,CACN,OAAQ,qBACR,QAASpB,EAAO,CACd,eAAiBsB,IAAO,CACtB,GAAGA,EAAE,QAAQ,eACb,OAAQ,EACV,EACF,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,yBACX,CACF,CACF,EACA,mBAAoB,CAElB,OAAQ,CACN,IAAK,mBACL,OAAQ,CACN,OAAQ,kCACR,QAAStB,EAAO,CACd,eAAiBsB,GAAM,CACrB,GAAIlB,EAAuBkB,EAAE,MAAM,MAAM,EAAG,CAC1C,MAAMG,EAA4BT,EAAsB,EAExD,OACES,EAAM,mBACNb,EAAuB,WAEvBK,EAAsB,CACpB,GAAGQ,EACH,WAAYH,EAAE,MAAM,OAAO,IAC7B,CAAC,EAEI,CACL,GAAGA,EAAE,QAAQ,eACb,OAAQ,GACR,WAAYA,EAAE,MAAM,OAAO,KAAK,KAChC,kBAAmBA,EAAE,MAAM,OAAO,KAAK,OACzC,CACF,CACA,MACE,cAAeA,EAAE,MAAM,OAAO,OAC9BA,EAAE,MAAM,OAAO,MAAM,YAAc,OAE5B,CACL,GAAGA,EAAE,QAAQ,eACb,OAAQ,EACV,EAEK,CACL,GAAGA,EAAE,QAAQ,eACb,MAAOA,EAAE,MAAM,OAAO,KACxB,CACF,CACF,CAAC,CACH,EACA,QAAS,CACP,OAAQ,QACR,QAAS,sBACX,CACF,CACF,EACA,gCAAiC,CAC/B,OAAQ,CACN,CACE,MAAO,WACP,OAAQ,OACV,EACA,CACE,OAAQ,yBACR,MAAO,gBACT,EACA,CACE,OAAQ,SACV,CACF,CACF,EACA,QAAS,CACP,KAAM,OACR,EACA,MAAO,CACL,KAAM,OACR,CACF,EACA,OAASI,GAAS,CAEhB,KAAM,CAAE,QAAAL,CAAQ,EAAIK,EACd,CAAE,MAAAC,EAAO,WAAAC,EAAY,kBAAAC,CAAkB,EAAIR,EAAQ,eACzD,OAAIM,EACKhC,EAAKgC,CAAK,EAEZ/B,EAA+B,CACpC,WAAYgC,EACZ,kBAAmBC,CACrB,CAAC,CACH,CACF,CAAC,CACH,CAEA,oBAAoBf,EAA+C,CA4BjE,MAAO,CACL,iBA5BuB,IAChBA,EAAY,YAAY,IAAIT,CAAyB,EA4B5D,oBAzB0B,CAAC,CAC3B,MAAAyB,CACF,IAGE,IAAIjC,EAAkBkC,GAAe,CACnC,MAAMC,EAAQlB,EACX,gCAAgC,EAChC,KACChB,EAAK2B,GAAU,CACTA,EAAM,eAAiBnB,EAAa,YACtCyB,EAAW,SAAS,EACpBC,EAAM,YAAY,EAEtB,CAAC,CACH,EACC,UAAU,EAEb,MAAO,IAAM,CACXA,EAAM,YAAY,CACpB,CACF,CAAC,EAAE,KAAKjC,EAAQ+B,EAAM,aAAa,CAAC,EAKpC,sBAAuB,IAAMhB,EAAY,sBAAsB,EAC/D,sBAAwBW,GACtBX,EAAY,sBAAsBW,CAAK,EACzC,kBAAmB,IAAM,EAC3B,CACF,CACF",
|
6
6
|
"names": ["Left", "Right", "Observable", "tap", "timeout", "assign", "fromObservable", "fromPromise", "setup", "isSuccessCommandResult", "GetAppAndVersionCommand", "DeviceStatus", "UserInteractionRequired", "DEFAULT_UNLOCK_TIMEOUT_MS", "DeviceLockedError", "DeviceNotOnboardedError", "XStateDeviceAction", "DeviceSessionStateType", "GetDeviceStatusDeviceAction", "internalApi", "getAppAndVersion", "getDeviceSessionState", "setDeviceSessionState", "waitForDeviceUnlock", "isDeviceOnboarded", "unlockTimeout", "context", "_", "sessionState", "sessionStateType", "state", "args", "error", "currentApp", "currentAppVersion", "input", "subscriber", "inner"]
|
7
7
|
}
|