@ledgerhq/device-management-kit 0.0.0-develop-20241223085243 → 0.0.0-develop-20241230143137

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.
@@ -40,13 +40,13 @@
40
40
  "@sentry/minimal": "^6.19.7",
41
41
  "@statelyai/inspect": "^0.4.0",
42
42
  "axios": "^1.7.9",
43
- "inversify": "^6.1.6",
43
+ "inversify": "^6.2.1",
44
44
  "inversify-logger-middleware": "^3.1.0",
45
45
  "purify-ts": "^2.1.0",
46
46
  "reflect-metadata": "^0.2.2",
47
47
  "semver": "^7.6.3",
48
48
  "uuid": "^11.0.3",
49
- "xstate": "^5.19.0"
49
+ "xstate": "^5.19.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "rxjs": "^7.8.1"
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var A=(i,e)=>{for(var s in e)c(i,s,{get:e[s],enumerable:!0})},_=(i,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of g(e))!f.call(i,t)&&t!==s&&c(i,t,{get:()=>e[t],enumerable:!(r=l(e,t))||r.enumerable});return i};var y=i=>_(c({},"__esModule",{value:!0}),i);var C={};A(C,{DeviceSession:()=>E});module.exports=y(C);var a=require("purify-ts"),p=require("rxjs"),d=require("uuid"),v=require("../../../api/command/utils/CommandUtils"),o=require("../../../api/device/DeviceStatus"),u=require("../../../api/device-session/DeviceSessionState"),S=require("../../device-session/data/DeviceSessionRefresherConst"),m=require("./DeviceSessionRefresher"),D=require("./Errors");class E{_id;_connectedDevice;_deviceState;_refresher;_managerApiService;constructor({connectedDevice:e,id:s=(0,d.v4)()},r,t){this._id=s,this._connectedDevice=e,this._deviceState=new p.BehaviorSubject({sessionStateType:u.DeviceSessionStateType.Connected,deviceStatus:o.DeviceStatus.CONNECTED}),this._refresher=new m.DeviceSessionRefresher({refreshInterval:S.DEVICE_SESSION_REFRESH_INTERVAL,deviceStatus:o.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:n=>this.sendApdu(n,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:n=>{const h=this._deviceState.getValue();this.setDeviceSessionState(n(h))}},r("device-session-refresher")),this._managerApiService=t}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}updateDeviceStatus(e){const s=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...s,deviceStatus:e})}async sendApdu(e,s={isPolling:!1,triggersDisconnection:!1}){return this._deviceState.getValue().deviceStatus===o.DeviceStatus.BUSY?(0,a.Left)(new D.DeviceBusyError):(s.isPolling||this.updateDeviceStatus(o.DeviceStatus.BUSY),(await this._connectedDevice.sendApdu(e,s.triggersDisconnection)).ifRight(n=>{v.CommandUtils.isLockedDeviceResponse(n)?this.updateDeviceStatus(o.DeviceStatus.LOCKED):this.updateDeviceStatus(o.DeviceStatus.CONNECTED)}))}async sendCommand(e){const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:s,cancel:r}=e._execute({sendCommand:async t=>this.sendCommand(t),getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:t=>(this.setDeviceSessionState(t),this._deviceState.getValue()),getMetadataForAppHashes:t=>this._managerApiService.getAppsByHash(t)});return{observable:s,cancel:r}}close(){this.updateDeviceStatus(o.DeviceStatus.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}toggleRefresher(e){e?this._refresher.start():this._refresher.stop()}}0&&(module.exports={DeviceSession});
1
+ "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var s in e)a(r,s,{get:e[s],enumerable:!0})},_=(r,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of g(e))!f.call(r,t)&&t!==s&&a(r,t,{get:()=>e[t],enumerable:!(o=l(e,t))||o.enumerable});return r};var E=r=>_(a({},"__esModule",{value:!0}),r);var y={};A(y,{DeviceSession:()=>C});module.exports=E(y);var c=require("purify-ts"),p=require("rxjs"),d=require("uuid"),v=require("../../../api/command/utils/CommandUtils"),i=require("../../../api/device/DeviceStatus"),u=require("../../../api/device-session/DeviceSessionState"),S=require("../../device-session/data/DeviceSessionRefresherConst"),m=require("./DeviceSessionRefresher"),D=require("./Errors");class C{_id;_connectedDevice;_deviceState;_refresher;_managerApiService;constructor({connectedDevice:e,id:s=(0,d.v4)()},o,t){this._id=s,this._connectedDevice=e,this._deviceState=new p.BehaviorSubject({sessionStateType:u.DeviceSessionStateType.Connected,deviceStatus:i.DeviceStatus.CONNECTED}),this._refresher=new m.DeviceSessionRefresher({refreshInterval:S.DEVICE_SESSION_REFRESH_INTERVAL,deviceStatus:i.DeviceStatus.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:n=>this.sendApdu(n,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:n=>{const h=this._deviceState.getValue();this.setDeviceSessionState(n(h))}},o("device-session-refresher")),this._managerApiService=t}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}updateDeviceStatus(e){const s=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...s,deviceStatus:e})}async sendApdu(e,s={isPolling:!1,triggersDisconnection:!1}){return this._deviceState.getValue().deviceStatus===i.DeviceStatus.BUSY?(0,c.Left)(new D.DeviceBusyError):(s.isPolling||this.updateDeviceStatus(i.DeviceStatus.BUSY),(await this._connectedDevice.sendApdu(e,s.triggersDisconnection)).ifRight(n=>{v.CommandUtils.isLockedDeviceResponse(n)?this.updateDeviceStatus(i.DeviceStatus.LOCKED):this.updateDeviceStatus(i.DeviceStatus.CONNECTED)}).ifLeft(n=>{this.updateDeviceStatus(i.DeviceStatus.CONNECTED)}))}async sendCommand(e){const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:s,cancel:o}=e._execute({sendCommand:async t=>this.sendCommand(t),getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:t=>(this.setDeviceSessionState(t),this._deviceState.getValue()),getMetadataForAppHashes:t=>this._managerApiService.getAppsByHash(t)});return{observable:s,cancel:o}}close(){this.updateDeviceStatus(i.DeviceStatus.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}toggleRefresher(e){e?this._refresher.start():this._refresher.stop()}}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, Left } from \"purify-ts\";\nimport { BehaviorSubject } 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 { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceBusyError } from \"./Errors\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\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 _refresher: DeviceSessionRefresher;\n private readonly _managerApiService: ManagerApiService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._managerApiService = managerApiService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n async sendApdu(\n rawApdu: Uint8Array,\n options: {\n isPolling: boolean;\n triggersDisconnection: boolean;\n } = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n if (!options.isPolling) this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse.ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n });\n }\n\n async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\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 executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\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 getMetadataForAppHashes: (apps: ListAppsResponse) =>\n this._managerApiService.getAppsByHash(apps),\n });\n\n return {\n observable,\n cancel,\n };\n }\n\n close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n toggleRefresher(enabled: boolean) {\n if (enabled) {\n this._refresher.start();\n } else {\n this._refresher.stop();\n }\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,qBAClCC,EAAgC,gBAChCC,EAA6B,gBAK7BC,EAA6B,2CAC7BC,EAA6B,oCAO7BC,EAGO,kDAKPC,EAAgD,qEAGhDC,EAAuC,oCACvCC,EAAgC,oBAUzB,MAAMV,CAAc,CACR,IACA,iBACA,aACA,WACA,mBAEjB,YACE,CAAE,gBAAAW,EAAiB,GAAAC,KAAK,EAAAC,IAAO,CAAE,EACjCC,EACAC,EACA,CACA,KAAK,IAAMH,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAI,kBAAoC,CAC1D,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,SAC7B,CAAC,EACD,KAAK,WAAa,IAAI,yBACpB,CACE,gBAAiB,kCACjB,aAAc,eAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaK,GACX,KAAK,SAASA,EAAS,CACrB,UAAW,GACX,sBAAuB,EACzB,CAAC,EACH,cAAgBC,GAAa,CAC3B,MAAMC,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,sBAAsBD,EAASC,CAAK,CAAC,CAC5C,CACF,EACAJ,EAAoB,0BAA0B,CAChD,EACA,KAAK,mBAAqBC,CAC5B,CA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C5C,sBAAwBL,IACtB,KAAK,sBAAsBA,CAAK,EACzB,KAAK,aAAa,SAAS,GAEpC,wBAA0BY,GACxB,KAAK,mBAAmB,cAAcA,CAAI,CAC9C,CAAC,EAED,MAAO,CACL,WAAAF,EACA,OAAAC,CACF,CACF,CAEA,OAAQ,CACN,KAAK,mBAAmB,eAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEA,gBAAgBE,EAAkB,CAC5BA,EACF,KAAK,WAAW,MAAM,EAEtB,KAAK,WAAW,KAAK,CAEzB,CACF",
6
- "names": ["DeviceSession_exports", "__export", "DeviceSession", "__toCommonJS", "import_purify_ts", "import_rxjs", "import_uuid", "import_CommandUtils", "import_DeviceStatus", "import_DeviceSessionState", "import_DeviceSessionRefresherConst", "import_DeviceSessionRefresher", "import_Errors", "connectedDevice", "id", "uuidv4", "loggerModuleFactory", "managerApiService", "rawApdu", "callback", "state", "deviceStatus", "sessionState", "options", "response", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "apps", "enabled"]
4
+ "sourcesContent": ["import { type Either, Left } from \"purify-ts\";\nimport { BehaviorSubject } 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 { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceBusyError } from \"./Errors\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\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 _refresher: DeviceSessionRefresher;\n private readonly _managerApiService: ManagerApiService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._managerApiService = managerApiService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n async sendApdu(\n rawApdu: Uint8Array,\n options: {\n isPolling: boolean;\n triggersDisconnection: boolean;\n } = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n if (!options.isPolling) this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n })\n .ifLeft((_error) => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n });\n }\n\n async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\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 executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\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 getMetadataForAppHashes: (apps: ListAppsResponse) =>\n this._managerApiService.getAppsByHash(apps),\n });\n\n return {\n observable,\n cancel,\n };\n }\n\n close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n toggleRefresher(enabled: boolean) {\n if (enabled) {\n this._refresher.start();\n } else {\n this._refresher.stop();\n }\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkC,qBAClCC,EAAgC,gBAChCC,EAA6B,gBAK7BC,EAA6B,2CAC7BC,EAA6B,oCAO7BC,EAGO,kDAKPC,EAAgD,qEAGhDC,EAAuC,oCACvCC,EAAgC,oBAUzB,MAAMV,CAAc,CACR,IACA,iBACA,aACA,WACA,mBAEjB,YACE,CAAE,gBAAAW,EAAiB,GAAAC,KAAK,EAAAC,IAAO,CAAE,EACjCC,EACAC,EACA,CACA,KAAK,IAAMH,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAI,kBAAoC,CAC1D,iBAAkB,yBAAuB,UACzC,aAAc,eAAa,SAC7B,CAAC,EACD,KAAK,WAAa,IAAI,yBACpB,CACE,gBAAiB,kCACjB,aAAc,eAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaK,GACX,KAAK,SAASA,EAAS,CACrB,UAAW,GACX,sBAAuB,EACzB,CAAC,EACH,cAAgBC,GAAa,CAC3B,MAAMC,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,sBAAsBD,EAASC,CAAK,CAAC,CAC5C,CACF,EACAJ,EAAoB,0BAA0B,CAChD,EACA,KAAK,mBAAqBC,CAC5B,CAEA,IAAW,IAAK,CACd,OAAO,KAAK,GACd,CAEA,IAAW,iBAAkB,CAC3B,OAA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BAAwBN,IACtB,KAAK,sBAAsBA,CAAK,EACzB,KAAK,aAAa,SAAS,GAEpC,wBAA0Ba,GACxB,KAAK,mBAAmB,cAAcA,CAAI,CAC9C,CAAC,EAED,MAAO,CACL,WAAAF,EACA,OAAAC,CACF,CACF,CAEA,OAAQ,CACN,KAAK,mBAAmB,eAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEA,gBAAgBE,EAAkB,CAC5BA,EACF,KAAK,WAAW,MAAM,EAEtB,KAAK,WAAW,KAAK,CAEzB,CACF",
6
+ "names": ["DeviceSession_exports", "__export", "DeviceSession", "__toCommonJS", "import_purify_ts", "import_rxjs", "import_uuid", "import_CommandUtils", "import_DeviceStatus", "import_DeviceSessionState", "import_DeviceSessionRefresherConst", "import_DeviceSessionRefresher", "import_Errors", "connectedDevice", "id", "uuidv4", "loggerModuleFactory", "managerApiService", "rawApdu", "callback", "state", "deviceStatus", "sessionState", "options", "response", "_error", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "apps", "enabled"]
7
7
  }
@@ -40,13 +40,13 @@
40
40
  "@sentry/minimal": "^6.19.7",
41
41
  "@statelyai/inspect": "^0.4.0",
42
42
  "axios": "^1.7.9",
43
- "inversify": "^6.1.6",
43
+ "inversify": "^6.2.1",
44
44
  "inversify-logger-middleware": "^3.1.0",
45
45
  "purify-ts": "^2.1.0",
46
46
  "reflect-metadata": "^0.2.2",
47
47
  "semver": "^7.6.3",
48
48
  "uuid": "^11.0.3",
49
- "xstate": "^5.19.0"
49
+ "xstate": "^5.19.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "rxjs": "^7.8.1"
@@ -1,2 +1,2 @@
1
- import{Left as c}from"purify-ts";import{BehaviorSubject as a}from"rxjs";import{v4 as p}from"uuid";import{CommandUtils as d}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as i}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as v}from"../../../api/device-session/DeviceSessionState";import{DEVICE_SESSION_REFRESH_INTERVAL as u}from"../../device-session/data/DeviceSessionRefresherConst";import{DeviceSessionRefresher as S}from"./DeviceSessionRefresher";import{DeviceBusyError as m}from"./Errors";class R{_id;_connectedDevice;_deviceState;_refresher;_managerApiService;constructor({connectedDevice:e,id:s=p()},r,t){this._id=s,this._connectedDevice=e,this._deviceState=new a({sessionStateType:v.Connected,deviceStatus:i.CONNECTED}),this._refresher=new S({refreshInterval:u,deviceStatus:i.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:o=>this.sendApdu(o,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:o=>{const n=this._deviceState.getValue();this.setDeviceSessionState(o(n))}},r("device-session-refresher")),this._managerApiService=t}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}updateDeviceStatus(e){const s=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...s,deviceStatus:e})}async sendApdu(e,s={isPolling:!1,triggersDisconnection:!1}){return this._deviceState.getValue().deviceStatus===i.BUSY?c(new m):(s.isPolling||this.updateDeviceStatus(i.BUSY),(await this._connectedDevice.sendApdu(e,s.triggersDisconnection)).ifRight(o=>{d.isLockedDeviceResponse(o)?this.updateDeviceStatus(i.LOCKED):this.updateDeviceStatus(i.CONNECTED)}))}async sendCommand(e){const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:s,cancel:r}=e._execute({sendCommand:async t=>this.sendCommand(t),getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:t=>(this.setDeviceSessionState(t),this._deviceState.getValue()),getMetadataForAppHashes:t=>this._managerApiService.getAppsByHash(t)});return{observable:s,cancel:r}}close(){this.updateDeviceStatus(i.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}toggleRefresher(e){e?this._refresher.start():this._refresher.stop()}}export{R as DeviceSession};
1
+ import{Left as a}from"purify-ts";import{BehaviorSubject as c}from"rxjs";import{v4 as p}from"uuid";import{CommandUtils as d}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as i}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as v}from"../../../api/device-session/DeviceSessionState";import{DEVICE_SESSION_REFRESH_INTERVAL as u}from"../../device-session/data/DeviceSessionRefresherConst";import{DeviceSessionRefresher as S}from"./DeviceSessionRefresher";import{DeviceBusyError as m}from"./Errors";class R{_id;_connectedDevice;_deviceState;_refresher;_managerApiService;constructor({connectedDevice:e,id:s=p()},o,t){this._id=s,this._connectedDevice=e,this._deviceState=new c({sessionStateType:v.Connected,deviceStatus:i.CONNECTED}),this._refresher=new S({refreshInterval:u,deviceStatus:i.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:r=>this.sendApdu(r,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:r=>{const n=this._deviceState.getValue();this.setDeviceSessionState(r(n))}},o("device-session-refresher")),this._managerApiService=t}get id(){return this._id}get connectedDevice(){return this._connectedDevice}get state(){return this._deviceState.asObservable()}setDeviceSessionState(e){this._deviceState.next(e)}updateDeviceStatus(e){const s=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...s,deviceStatus:e})}async sendApdu(e,s={isPolling:!1,triggersDisconnection:!1}){return this._deviceState.getValue().deviceStatus===i.BUSY?a(new m):(s.isPolling||this.updateDeviceStatus(i.BUSY),(await this._connectedDevice.sendApdu(e,s.triggersDisconnection)).ifRight(r=>{d.isLockedDeviceResponse(r)?this.updateDeviceStatus(i.LOCKED):this.updateDeviceStatus(i.CONNECTED)}).ifLeft(r=>{this.updateDeviceStatus(i.CONNECTED)}))}async sendCommand(e){const s=e.getApdu();return(await this.sendApdu(s.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:t=>{throw t},Right:t=>e.parseResponse(t,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:s,cancel:o}=e._execute({sendCommand:async t=>this.sendCommand(t),getDeviceSessionState:()=>this._deviceState.getValue(),getDeviceSessionStateObservable:()=>this.state,setDeviceSessionState:t=>(this.setDeviceSessionState(t),this._deviceState.getValue()),getMetadataForAppHashes:t=>this._managerApiService.getAppsByHash(t)});return{observable:s,cancel:o}}close(){this.updateDeviceStatus(i.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}toggleRefresher(e){e?this._refresher.start():this._refresher.stop()}}export{R as DeviceSession};
2
2
  //# sourceMappingURL=DeviceSession.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/model/DeviceSession.ts"],
4
- "sourcesContent": ["import { type Either, Left } from \"purify-ts\";\nimport { BehaviorSubject } 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 { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceBusyError } from \"./Errors\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\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 _refresher: DeviceSessionRefresher;\n private readonly _managerApiService: ManagerApiService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._managerApiService = managerApiService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n async sendApdu(\n rawApdu: Uint8Array,\n options: {\n isPolling: boolean;\n triggersDisconnection: boolean;\n } = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n if (!options.isPolling) this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse.ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n });\n }\n\n async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\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 executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\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 getMetadataForAppHashes: (apps: ListAppsResponse) =>\n this._managerApiService.getAppsByHash(apps),\n });\n\n return {\n observable,\n cancel,\n };\n }\n\n close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n toggleRefresher(enabled: boolean) {\n if (enabled) {\n this._refresher.start();\n } else {\n this._refresher.stop();\n }\n }\n}\n"],
5
- "mappings": "AAAA,OAAsB,QAAAA,MAAY,YAClC,OAAS,mBAAAC,MAAuB,OAChC,OAAS,MAAMC,MAAc,OAK7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAKP,OAAS,mCAAAC,MAAuC,4DAGhD,OAAS,0BAAAC,MAA8B,2BACvC,OAAS,mBAAAC,MAAuB,WAUzB,MAAMC,CAAc,CACR,IACA,iBACA,aACA,WACA,mBAEjB,YACE,CAAE,gBAAAC,EAAiB,GAAAC,EAAKT,EAAO,CAAE,EACjCU,EACAC,EACA,CACA,KAAK,IAAMF,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAIT,EAAoC,CAC1D,iBAAkBI,EAAuB,UACzC,aAAcD,EAAa,SAC7B,CAAC,EACD,KAAK,WAAa,IAAIG,EACpB,CACE,gBAAiBD,EACjB,aAAcF,EAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaU,GACX,KAAK,SAASA,EAAS,CACrB,UAAW,GACX,sBAAuB,EACzB,CAAC,EACH,cAAgBC,GAAa,CAC3B,MAAMC,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,sBAAsBD,EAASC,CAAK,CAAC,CAC5C,CACF,EACAJ,EAAoB,0BAA0B,CAChD,EACA,KAAK,mBAAqBC,CAC5B,CAEA,IAAW,IAAK,CACd,OAAO,KAAK,GACd,CAEA,IAAW,iBAAkB,CAC3B,OAAO,KAAK,gBACd,CAEA,IAAW,OAAQ,CACjB,OAAO,KAAK,aAAa,aAAa,CACxC,CAEO,sBAAsBG,EAA2B,CACtD,KAAK,aAAa,KAAKA,CAAK,CAC9B,CAEQ,mBAAmBC,EAA4B,CAC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Aa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEA,gBAAgByB,EAAkB,CAC5BA,EACF,KAAK,WAAW,MAAM,EAEtB,KAAK,WAAW,KAAK,CAEzB,CACF",
6
- "names": ["Left", "BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "DEVICE_SESSION_REFRESH_INTERVAL", "DeviceSessionRefresher", "DeviceBusyError", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "rawApdu", "callback", "state", "deviceStatus", "sessionState", "options", "response", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "apps", "enabled"]
4
+ "sourcesContent": ["import { type Either, Left } from \"purify-ts\";\nimport { BehaviorSubject } 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 { type ListAppsResponse } from \"@api/command/os/ListAppsCommand\";\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_REFRESH_INTERVAL } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\nimport { DeviceBusyError } from \"./Errors\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\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 _refresher: DeviceSessionRefresher;\n private readonly _managerApiService: ManagerApiService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n });\n this._refresher = new DeviceSessionRefresher(\n {\n refreshInterval: DEVICE_SESSION_REFRESH_INTERVAL,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\n sendApduFn: (rawApdu: Uint8Array) =>\n this.sendApdu(rawApdu, {\n isPolling: true,\n triggersDisconnection: false,\n }),\n updateStateFn: (callback) => {\n const state = this._deviceState.getValue();\n this.setDeviceSessionState(callback(state));\n },\n },\n loggerModuleFactory(\"device-session-refresher\"),\n );\n this._managerApiService = managerApiService;\n }\n\n public get id() {\n return this._id;\n }\n\n public get connectedDevice() {\n return this._connectedDevice;\n }\n\n public get state() {\n return this._deviceState.asObservable();\n }\n\n public setDeviceSessionState(state: DeviceSessionState) {\n this._deviceState.next(state);\n }\n\n private updateDeviceStatus(deviceStatus: DeviceStatus) {\n const sessionState = this._deviceState.getValue();\n this._refresher.setDeviceStatus(deviceStatus);\n this._deviceState.next({\n ...sessionState,\n deviceStatus,\n });\n }\n\n async sendApdu(\n rawApdu: Uint8Array,\n options: {\n isPolling: boolean;\n triggersDisconnection: boolean;\n } = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n if (!options.isPolling) this.updateDeviceStatus(DeviceStatus.BUSY);\n\n const errorOrResponse = await this._connectedDevice.sendApdu(\n rawApdu,\n options.triggersDisconnection,\n );\n\n return errorOrResponse\n .ifRight((response: ApduResponse) => {\n if (CommandUtils.isLockedDeviceResponse(response)) {\n this.updateDeviceStatus(DeviceStatus.LOCKED);\n } else {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n }\n })\n .ifLeft((_error) => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n });\n }\n\n async sendCommand<Response, Args, ErrorStatusCodes>(\n command: Command<Response, Args, ErrorStatusCodes>,\n ): Promise<CommandResult<Response, ErrorStatusCodes>> {\n const apdu = command.getApdu();\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 executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n deviceAction: DeviceAction<Output, Input, Error, IntermediateValue>,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n const { observable, cancel } = deviceAction._execute({\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 getMetadataForAppHashes: (apps: ListAppsResponse) =>\n this._managerApiService.getAppsByHash(apps),\n });\n\n return {\n observable,\n cancel,\n };\n }\n\n close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n toggleRefresher(enabled: boolean) {\n if (enabled) {\n this._refresher.start();\n } else {\n this._refresher.stop();\n }\n }\n}\n"],
5
+ "mappings": "AAAA,OAAsB,QAAAA,MAAY,YAClC,OAAS,mBAAAC,MAAuB,OAChC,OAAS,MAAMC,MAAc,OAK7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAKP,OAAS,mCAAAC,MAAuC,4DAGhD,OAAS,0BAAAC,MAA8B,2BACvC,OAAS,mBAAAC,MAAuB,WAUzB,MAAMC,CAAc,CACR,IACA,iBACA,aACA,WACA,mBAEjB,YACE,CAAE,gBAAAC,EAAiB,GAAAC,EAAKT,EAAO,CAAE,EACjCU,EACAC,EACA,CACA,KAAK,IAAMF,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAIT,EAAoC,CAC1D,iBAAkBI,EAAuB,UACzC,aAAcD,EAAa,SAC7B,CAAC,EACD,KAAK,WAAa,IAAIG,EACpB,CACE,gBAAiBD,EACjB,aAAcF,EAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaU,GACX,KAAK,SAASA,EAAS,CACrB,UAAW,GACX,sBAAuB,EACzB,CAAC,EACH,cAAgBC,GAAa,CAC3B,MAAMC,EAAQ,KAAK,aAAa,SAAS,EACzC,KAAK,sBAAsBD,EAASC,CAAK,CAAC,CAC5C,CACF,EACAJ,EAAoB,0BAA0B,CAChD,EACA,KAAK,mBAAqBC,CAC5B,CAEA,IAAW,IAAK,CACd,OAAO,KAAK,GACd,CAEA,IAAW,iBAAkB,CAC3B,OAAO,KAAK,gBACd,CAEA,IAAW,OAAQ,CACjB,OAAO,KAAK,aAAa,aAAa,CACxC,CAEO,sBAAsBG,EAA2B,CACtD,KAAK,aAAa,KAAKA,CAAK,CAC9B,CAEQ,mBAAmBC,EAA4B,CACrD,MAAMC,EAAe,KAAK,aAAa,SAAS,EAChD,KAAK,WAAW,gBA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AAmBxB,EAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEA,gBAAgB0B,EAAkB,CAC5BA,EACF,KAAK,WAAW,MAAM,EAEtB,KAAK,WAAW,KAAK,CAEzB,CACF",
6
+ "names": ["Left", "BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "DEVICE_SESSION_REFRESH_INTERVAL", "DeviceSessionRefresher", "DeviceBusyError", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "rawApdu", "callback", "state", "deviceStatus", "sessionState", "options", "response", "_error", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "apps", "enabled"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceSession.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/device-session/model/DeviceSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,WAAW,CAAC;AAI9C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAItE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAE9F,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAKzF,M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,KAAK,EAAE,iBAAiB,CAAC;IAqBlE,KAAK;IAML,eAAe,CAAC,OAAO,EAAE,OAAO;CAOjC"}
1
+ {"version":3,"file":"DeviceSession.d.ts","sourceRoot":"","sources":["../../../../../../src/internal/device-session/model/DeviceSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,WAAW,CAAC;AAI9C,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAItE,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,6BAA6B,EAClC,KAAK,6BAA6B,EACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EACL,KAAK,kBAAkB,EAExB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AACnG,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAE9F,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAKzF,MAAM,MAAM,sBAAsB,GAAG;IACnC,eAAe,EAAE,wBAAwB,CAAC;IAC1C,EAAE,CAAC,EAAE,eAAe,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAC5D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsC;IACnE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;gBAG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