@ledgerhq/device-management-kit 0.0.0-rnble-transport-20250307123452 → 0.0.0-rnble-transport-20250317160347
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +2 -2
- package/lib/cjs/src/api/device-action/model/UserInteractionRequired.js.map +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/cjs/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/cjs/src/api/index.js +1 -1
- package/lib/cjs/src/api/index.js.map +3 -3
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/GenuineCheck/types.js.map +1 -1
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +2 -0
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +7 -0
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js +2 -0
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js.map +7 -0
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js +2 -0
- package/lib/cjs/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +7 -0
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
- package/lib/cjs/src/api/secure-channel/task/types.js +1 -1
- package/lib/cjs/src/api/secure-channel/task/types.js.map +1 -1
- package/lib/cjs/src/api/secure-channel/types.js +2 -0
- package/lib/cjs/src/api/secure-channel/types.js.map +7 -0
- 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/model/DeviceSession.js +1 -1
- package/lib/cjs/src/internal/device-session/model/DeviceSession.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDto.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDto.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/model/Application.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Application.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/model/Params.js +2 -0
- package/lib/cjs/src/internal/manager-api/model/Params.js.map +7 -0
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
- package/lib/esm/package.json +2 -2
- package/lib/esm/src/api/device-action/model/UserInteractionRequired.js.map +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js +1 -1
- package/lib/esm/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.js.map +3 -3
- package/lib/esm/src/api/index.js +1 -1
- package/lib/esm/src/api/index.js.map +3 -3
- package/lib/esm/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.js.map +2 -2
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js +2 -0
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.js.map +7 -0
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js +2 -0
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.js.map +7 -0
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js +2 -0
- package/lib/esm/src/api/secure-channel/device-action/ListInstalledApps/types.js.map +7 -0
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
- package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
- package/lib/esm/src/api/secure-channel/task/types.js.map +1 -1
- package/lib/esm/src/api/secure-channel/types.js +1 -0
- package/lib/esm/src/api/secure-channel/types.js.map +7 -0
- package/lib/esm/src/internal/device-session/model/DeviceSession.js +1 -1
- package/lib/esm/src/internal/device-session/model/DeviceSession.js.map +2 -2
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js +1 -1
- package/lib/esm/src/internal/manager-api/data/AxiosManagerApiDataSource.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/ManagerApiDto.js.map +1 -1
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.js.map +2 -2
- package/lib/esm/src/internal/manager-api/model/Application.js.map +1 -1
- package/lib/esm/src/internal/manager-api/model/Params.js +1 -0
- package/lib/esm/src/internal/manager-api/model/Params.js.map +7 -0
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.js.map +3 -3
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +3 -3
- package/lib/types/src/api/device-action/model/UserInteractionRequired.d.ts +1 -1
- package/lib/types/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/index.d.ts +1 -0
- package/lib/types/src/api/index.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/GenuineCheckDeviceAction.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts +5 -7
- package/lib/types/src/api/secure-channel/device-action/GenuineCheck/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts +8 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.d.ts.map +1 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.d.ts +1 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/ListInstalledAppsDeviceAction.test.d.ts.map +1 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts +59 -0
- package/lib/types/src/api/secure-channel/device-action/ListInstalledApps/types.d.ts.map +1 -0
- package/lib/types/src/api/secure-channel/task/types.d.ts +1 -1
- package/lib/types/src/api/secure-channel/task/types.d.ts.map +1 -1
- package/lib/types/src/api/secure-channel/types.d.ts +4 -0
- package/lib/types/src/api/secure-channel/types.d.ts.map +1 -0
- package/lib/types/src/api/types.d.ts +1 -0
- package/lib/types/src/api/types.d.ts.map +1 -1
- package/lib/types/src/internal/device-session/model/DeviceSession.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts +6 -5
- package/lib/types/src/internal/manager-api/data/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +14 -9
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDto.d.ts +4 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDto.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts +1 -0
- package/lib/types/src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Application.d.ts +4 -1
- package/lib/types/src/internal/manager-api/model/Application.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Params.d.ts +43 -0
- package/lib/types/src/internal/manager-api/model/Params.d.ts.map +1 -0
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +5 -5
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +33 -2
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -4
@@ -0,0 +1,7 @@
|
|
1
|
+
{
|
2
|
+
"version": 3,
|
3
|
+
"sources": ["../../../../../../../src/api/secure-channel/device-action/ListInstalledApps/types.ts"],
|
4
|
+
"sourcesContent": ["import { type EitherAsync } from \"purify-ts\";\nimport { type Observable } from \"rxjs\";\n\nimport { type CommandErrorResult } from \"@api/command/model/CommandResult\";\nimport {\n type GetOsVersionCommandResult,\n type GetOsVersionResponse,\n} from \"@api/command/os/GetOsVersionCommand\";\nimport { type DeviceActionState } from \"@api/device-action/model/DeviceActionState\";\nimport { type UserInteractionRequired } from \"@api/device-action/model/UserInteractionRequired\";\nimport { type UnknownDAError } from \"@api/device-action/os/Errors\";\nimport {\n type GoToDashboardDAError,\n type GoToDashboardDAInput,\n} from \"@api/device-action/os/GoToDashboard/types\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type SecureChannelEvent } from \"@api/secure-channel/task/types\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { type HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nexport type Input<T> = { input: T };\n\nexport type ListInstalledAppsDAOutput = {\n installedApps: Array<InstalledApp>;\n};\n\nexport type ListInstalledAppsDAInput = GoToDashboardDAInput;\n\nexport type ListInstalledAppsDAError =\n | CommandErrorResult[\"error\"]\n | GoToDashboardDAError\n | HttpFetchApiError\n | UnknownDAError;\n\nexport type ListInstalledAppsDARequiredInteraction =\n | UserInteractionRequired.None\n | UserInteractionRequired.UnlockDevice\n | UserInteractionRequired.AllowSecureConnection;\n\nexport type ListInstalledAppsDAIntermediateValue = {\n requiredUserInteraction: ListInstalledAppsDARequiredInteraction;\n};\n\nexport type ListInstalledAppsDAState = DeviceActionState<\n ListInstalledAppsDAOutput,\n ListInstalledAppsDAError,\n ListInstalledAppsDAIntermediateValue\n>;\n\nexport type ListInstalledAppsStateMachineInternalState = {\n error: ListInstalledAppsDAError | null;\n result: { installedApps: Array<InstalledApp> };\n getOsVersionResponse: GetOsVersionResponse | null;\n deviceVersion: DeviceVersion | null;\n firmwareVersion: FinalFirmware | null;\n};\n\nexport type MachineDependencies = {\n getOsVersion: () => Promise<GetOsVersionCommandResult>;\n getDeviceVersion: (\n args: Input<{ deviceInfo: GetOsVersionResponse }>,\n ) => EitherAsync<HttpFetchApiError, DeviceVersion>;\n getFirmwareVersion: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n deviceVersion: DeviceVersion;\n }>,\n ) => EitherAsync<HttpFetchApiError, FinalFirmware>;\n listInstalledApps: (\n args: Input<{\n deviceInfo: GetOsVersionResponse;\n finalFirmware: FinalFirmware;\n }>,\n ) => Observable<SecureChannelEvent>;\n getDeviceSessionState: () => DeviceSessionState;\n setDeviceSessionState: (state: DeviceSessionState) => DeviceSessionState;\n};\n\nexport type InstalledApp = {\n flags: number;\n hash: string;\n hash_code_data: string;\n name: string;\n};\n\nexport function installedAppResultGuard(\n value: unknown,\n): value is ListInstalledAppsDAOutput[\"installedApps\"] {\n return (\n Array.isArray(value) &&\n value.every(\n (item) =>\n typeof item === \"object\" &&\n item !== null &&\n \"flags\" in item &&\n \"hash\" in item &&\n \"hash_code_data\" in item &&\n \"name\" in item &&\n typeof item.flags === \"number\" &&\n typeof item.hash === \"string\" &&\n typeof item.hash_code_data === \"string\" &&\n typeof item.name === \"string\",\n )\n );\n}\n"],
|
5
|
+
"mappings": "AAsFO,SAASA,EACdC,EACqD,CACrD,OACE,MAAM,QAAQA,CAAK,GACnBA,EAAM,MACHC,GACC,OAAOA,GAAS,UAChBA,IAAS,MACT,UAAWA,GACX,SAAUA,GACV,mBAAoBA,GACpB,SAAUA,GACV,OAAOA,EAAK,OAAU,UACtB,OAAOA,EAAK,MAAS,UACrB,OAAOA,EAAK,gBAAmB,UAC/B,OAAOA,EAAK,MAAS,QACzB,CAEJ",
|
6
|
+
"names": ["installedAppResultGuard", "value", "item"]
|
7
|
+
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import w from"isomorphic-ws";import{Observable as A}from"rxjs";import{CommandUtils as S}from"../../command/utils/CommandUtils";import{InMessageQueryEnum as l,OutMessageResponseEnum as m,SecureChannelEventType as i}from"../../secure-channel/task/types";import{isRefusedByUser as v,willRequestPermission as x}from"../../secure-channel/utils";import{bufferToHexaString as C,hexaStringToBuffer as k}from"../../utils/HexaString";import{SecureChannelError as
|
1
|
+
import w from"isomorphic-ws";import{Observable as A}from"rxjs";import{CommandUtils as S}from"../../command/utils/CommandUtils";import{InMessageQueryEnum as l,OutMessageResponseEnum as m,SecureChannelEventType as i}from"../../secure-channel/task/types";import{isRefusedByUser as v,willRequestPermission as x}from"../../secure-channel/utils";import{bufferToHexaString as C,hexaStringToBuffer as k}from"../../utils/HexaString";import{SecureChannelError as o}from"../../../internal/secure-channel/model/Errors";class P{constructor(d,E){this._api=d;this._args=E;if(this._args.connection.isRight())this._connection=this._args.connection.extract();else throw new o(`Invalid WebSocket connection: ${String(this._args.connection.extract())}`)}_connection;run(){const d=this._api.disableRefresher("connectToSecureChannel");return new A(e=>{let u=!1,c=!1,y=!1,p=null,h=!1;return this._connection.onopen=()=>{e.next({type:i.Opened})},this._connection.onerror=f=>{c||e.error(new o({url:this._connection.url,errorMessage:f.message}))},this._connection.onclose=()=>{c||(y?(e.next({type:i.Closed}),e.complete()):e.error(new o(p??{url:this._connection.url,errorMessage:"Connection closed unexpectedly"})))},this._connection.onmessage=async f=>{if(!u){p=null;try{const t=JSON.parse(String(f.data));switch(t.query){case l.EXCHANGE:{const{nonce:a}=t;if(Array.isArray(t.data)){e.error(new o(`${l.EXCHANGE} data type should not be Array`));break}const n=k(t.data);if(n===null||n.length<5){e.error(new o(`Received invalid APDU data: ${t.data}`));break}e.next({type:i.PreExchange,payload:{nonce:a,apdu:n}}),x(n)&&!this.isSecureConnectionAllowed()&&(h=!0,e.next({type:i.PermissionRequested}));const s=await this._api.sendApdu(n);if(u)return;s.caseOf({Left:r=>{e.error(new o(r))},Right:r=>{let g;if(S.isSuccessResponse(r))g=m.SUCCESS,e.next({type:i.Exchange,payload:{nonce:a,apdu:n,data:r.data,status:r.statusCode}});else{if(g=m.ERROR,p=new o({url:this._connection.url,errorMessage:`Invalid status code: ${C(r.statusCode)}`}),S.isLockedDeviceResponse(r)){e.error(new o({url:this._connection.url,errorMessage:"Device is locked"}));return}if(v(r.statusCode)&&h){e.error(new o({url:this._connection.url,errorMessage:"User refused on the device"}));return}}h&&(e.next({type:i.PermissionGranted}),h=!1);const _={nonce:a,response:g,data:C(r.data).slice(2)};this._connection.send(JSON.stringify(_))}});break}case l.BULK:{if(c=!0,this._connection.close(),!Array.isArray(t.data)||t.data.length===0){e.error(new o("Invalid bulk data received"));break}const a=t.data.reduce((n,s)=>{const r=k(s);return r===null?n:[...n,r]},[]);for(let n=0,s=a.length;n<s;n++){if(await this._api.sendApdu(a[n]),u){e.error(new o("Bulk sending cancelled by unsubscribing"));break}e.next({type:i.Progress,payload:{progress:+Number((n+1)/s).toFixed(2),index:n,total:s}})}y=!0,e.complete();break}case l.SUCCESS:{if(c)break;const a=t.result??t.data;a&&e.next({type:i.Result,payload:a??""}),y=!0,e.complete();break}case l.WARNING:{if(c)break;e.next({type:i.Warning,payload:{message:String(t.data)}});break}case l.ERROR:{if(c)break;e.error(new o({url:this._connection.url,errorMessage:String(t.data)}))}}}catch(t){p=new o(t),e.error(p)}}},()=>{d(),u=!0,this._connection.readyState===w.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const d=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in d&&d.isSecureConnectionAllowed}}export{P as ConnectToSecureChannelTask};
|
2
2
|
//# sourceMappingURL=ConnectToSecureChannelTask.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/api/secure-channel/task/ConnectToSecureChannelTask.ts"],
|
4
|
-
"sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n isRefusedByUser,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let inBulkMode = false;\n let communicationFinished = false;\n let deviceError: SecureChannelError | null = null;\n let waitingForUserAction = false;\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n // When the bulk sending is in progress, network error is ignored\n if (inBulkMode) {\n return;\n }\n\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n );\n };\n\n this._connection.onclose = () => {\n // When the bulk sending is in progress, network event is ignored\n if (inBulkMode) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n subscriber.complete();\n } else {\n subscriber.error(\n new SecureChannelError(\n deviceError ?? {\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n },\n ),\n );\n }\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n deviceError = null;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const input: InMessageType = JSON.parse(String(event.data));\n\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce } = input;\n\n if (Array.isArray(input.data)) {\n subscriber.error(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should not be Array`,\n ),\n );\n break;\n }\n\n const apdu = hexaStringToBuffer(input.data);\n\n if (apdu === null || apdu.length < 5) {\n subscriber.error(\n new SecureChannelError(\n `Received invalid APDU data: ${input.data}`,\n ),\n );\n break;\n }\n\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n waitingForUserAction = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n const response = await this._api.sendApdu(apdu);\n\n if (unsubscribed) {\n return;\n }\n\n response.caseOf({\n Left: (error) => {\n subscriber.error(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n /**\n * | Status Code | Description | Event Emitted |\n * |-------------|------------------------------------|------------------------------------|\n * | 0x9000 | Success | SecureChannelEventEnum.Exchange |\n * | 0x5515 | Device is locked | Error |\n * | 0x5501 | User refused on the device | Error |\n * | 0x6985 | Condition of use not satisfied | Error |\n */\n // Success response\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n\n deviceError = new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Device is locked`,\n }),\n );\n return;\n }\n\n // User refused the permission\n if (\n isRefusedByUser(apduResponse.statusCode) &&\n waitingForUserAction\n ) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n }),\n );\n return;\n }\n }\n\n if (waitingForUserAction) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n waitingForUserAction = false;\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n inBulkMode = true;\n this._connection.close();\n\n if (!Array.isArray(input.data) || input.data.length === 0) {\n subscriber.error(\n new SecureChannelError(\"Invalid bulk data received\"),\n );\n break;\n }\n\n const apdus = input.data.reduce(\n (acc: Array<Uint8Array>, cur: string) => {\n const apdu = hexaStringToBuffer(cur);\n return apdu === null ? acc : [...acc, apdu];\n },\n [],\n );\n\n for (let i = 0, len = apdus.length; i < len; i++) {\n await this._api.sendApdu(apdus[i]!);\n if (unsubscribed) {\n subscriber.error(\n new SecureChannelError(\n \"Bulk sending cancelled by unsubscribing\",\n ),\n );\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n // Ignore success message when in bulk mode\n if (inBulkMode) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: String(payload ?? \"\"),\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n // Ignore warning message when in bulk mode\n if (inBulkMode) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (inBulkMode) {\n break;\n }\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n } catch (error) {\n deviceError = new SecureChannelError(error);\n subscriber.error(deviceError);\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n}\n"],
|
5
|
-
"mappings": "AAAA,OAAOA,MAAe,gBAEtB,OAAS,cAAAC,MAAkB,OAE3B,OAAS,gBAAAC,MAAoB,kCAG7B,OACE,sBAAAC,EAEA,0BAAAC,EAGA,0BAAAC,MACK,iCACP,OACE,mBAAAC,EACA,yBAAAC,MACK,4BACP,OAAS,sBAAAC,EAAoB,sBAAAC,MAA0B,wBACvD,OACE,sBAAAC,MAEK,wCAMA,MAAMC,CAA2B,CAEtC,YACmBC,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KAAK,YAAc,KAAK,MAAM,WAAW,QAAQ,MAEjD,OAAM,IAAIH,EACR,iCAAiC,OAAO,KAAK,MAAM,WAAW,QAAQ,CAAC,CAAC,EAC1E,CAEJ,CAZiB,YAcjB,KAAsC,CACpC,MAAMI,EAAoB,KAAK,KAAK,iBAClC,wBACF,EA+RA,OA7RY,IAAIb,EAAgCc,GAAe,CAC7D,IAAIC,EAAwB,GACxBC,EAAa,GACbC,EAAwB,GACxBC,EAAyC,KACzCC,EAAuB,GAE3B,YAAK,YAAY,OAAS,IAAM,CAC9BL,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC/B,CAAC,CACH,EAEA,K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S,KAAOM,EAAM,CAAC,GAAGA,EAAKN,CAAI,CAC5C,EACA,CAAC,CACH,EAEA,QAASQ,EAAI,EAAGC,EAAMJ,EAAM,OAAQG,EAAIC,EAAKD,IAAK,CAEhD,GADA,MAAM,KAAK,KAAK,SAASH,EAAMG,CAAC,CAAE,EAC9BjB,EAAc,CAChBD,EAAW,MACT,IAAIL,EACF,yCACF,CACF,EACA,KACF,CACAK,EAAW,KAAK,CACd,KAAMV,EAAuB,SAC7B,QAAS,CACP,SAAU,CAAC,QAAQ4B,EAAI,GAAKC,CAAG,EAAE,QAAQ,CAAC,EAC1C,MAAOD,EACP,MAAOC,CACT,CACF,CAAC,CACH,CACAhB,EAAwB,GACxBH,EAAW,SAAS,EACpB,KACF,CACA,KAAKZ,EAAmB,QAAS,CAE/B,GAAIc,EACF,MAGF,MAAMkB,EAAUZ,EAAM,QAAUA,EAAM,KAClCY,GACFpB,EAAW,KAAK,CACd,KAAMV,EAAuB,OAC7B,
|
4
|
+
"sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport {\n isRefusedByUser,\n willRequestPermission,\n} from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let inBulkMode = false;\n let communicationFinished = false;\n let deviceError: SecureChannelError | null = null;\n let waitingForUserAction = false;\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n // When the bulk sending is in progress, network error is ignored\n if (inBulkMode) {\n return;\n }\n\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n );\n };\n\n this._connection.onclose = () => {\n // When the bulk sending is in progress, network event is ignored\n if (inBulkMode) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n subscriber.complete();\n } else {\n subscriber.error(\n new SecureChannelError(\n deviceError ?? {\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n },\n ),\n );\n }\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n deviceError = null;\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const input: InMessageType = JSON.parse(String(event.data));\n\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce } = input;\n\n if (Array.isArray(input.data)) {\n subscriber.error(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should not be Array`,\n ),\n );\n break;\n }\n\n const apdu = hexaStringToBuffer(input.data);\n\n if (apdu === null || apdu.length < 5) {\n subscriber.error(\n new SecureChannelError(\n `Received invalid APDU data: ${input.data}`,\n ),\n );\n break;\n }\n\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n waitingForUserAction = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n const response = await this._api.sendApdu(apdu);\n\n if (unsubscribed) {\n return;\n }\n\n response.caseOf({\n Left: (error) => {\n subscriber.error(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n /**\n * | Status Code | Description | Event Emitted |\n * |-------------|------------------------------------|------------------------------------|\n * | 0x9000 | Success | SecureChannelEventEnum.Exchange |\n * | 0x5515 | Device is locked | Error |\n * | 0x5501 | User refused on the device | Error |\n * | 0x6985 | Condition of use not satisfied | Error |\n */\n // Success response\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n\n deviceError = new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Device is locked`,\n }),\n );\n return;\n }\n\n // User refused the permission\n if (\n isRefusedByUser(apduResponse.statusCode) &&\n waitingForUserAction\n ) {\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n }),\n );\n return;\n }\n }\n\n if (waitingForUserAction) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n waitingForUserAction = false;\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n inBulkMode = true;\n this._connection.close();\n\n if (!Array.isArray(input.data) || input.data.length === 0) {\n subscriber.error(\n new SecureChannelError(\"Invalid bulk data received\"),\n );\n break;\n }\n\n const apdus = input.data.reduce(\n (acc: Array<Uint8Array>, cur: string) => {\n const apdu = hexaStringToBuffer(cur);\n return apdu === null ? acc : [...acc, apdu];\n },\n [],\n );\n\n for (let i = 0, len = apdus.length; i < len; i++) {\n await this._api.sendApdu(apdus[i]!);\n if (unsubscribed) {\n subscriber.error(\n new SecureChannelError(\n \"Bulk sending cancelled by unsubscribing\",\n ),\n );\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n // Ignore success message when in bulk mode\n if (inBulkMode) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n // Ignore warning message when in bulk mode\n if (inBulkMode) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (inBulkMode) {\n break;\n }\n subscriber.error(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n } catch (error) {\n deviceError = new SecureChannelError(error);\n subscriber.error(deviceError);\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n}\n"],
|
5
|
+
"mappings": "AAAA,OAAOA,MAAe,gBAEtB,OAAS,cAAAC,MAAkB,OAE3B,OAAS,gBAAAC,MAAoB,kCAG7B,OACE,sBAAAC,EAEA,0BAAAC,EAGA,0BAAAC,MACK,iCACP,OACE,mBAAAC,EACA,yBAAAC,MACK,4BACP,OAAS,sBAAAC,EAAoB,sBAAAC,MAA0B,wBACvD,OACE,sBAAAC,MAEK,wCAMA,MAAMC,CAA2B,CAEtC,YACmBC,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KAAK,YAAc,KAAK,MAAM,WAAW,QAAQ,MAEjD,OAAM,IAAIH,EACR,iCAAiC,OAAO,KAAK,MAAM,WAAW,QAAQ,CAAC,CAAC,EAC1E,CAEJ,CAZiB,YAcjB,KAAsC,CACpC,MAAMI,EAAoB,KAAK,KAAK,iBAClC,wBACF,EA+RA,OA7RY,IAAIb,EAAgCc,GAAe,CAC7D,IAAIC,EAAwB,GACxBC,EAAa,GACbC,EAAwB,GACxBC,EAAyC,KACzCC,EAAuB,GAE3B,YAAK,YAAY,OAAS,IAAM,CAC9BL,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC/B,CAAC,CACH,EAEA,KAAK,YAAY,QAAWgB,GAAU,CAEhCJ,GAIJF,EAAW,MACT,IAAIL,EAAmB,CACrB,IAAK,KAAK,YAAY,IACtB,aAAcW,EAAM,OACtB,CAAC,CACH,CACF,EAEA,KAAK,YAAY,QAAU,IAAM,CAE3BJ,IAIAC,GACFH,EAAW,KAAK,CACd,KAAMV,EAAuB,MAC/B,CAAC,EACDU,EAAW,SAAS,GAEpBA,EAAW,MACT,IAAIL,EACFS,GAAe,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AAuB,SAC7B,QAAS,CACP,SAAU,CAAC,QAAQ4B,EAAI,GAAKC,CAAG,EAAE,QAAQ,CAAC,EAC1C,MAAOD,EACP,MAAOC,CACT,CACF,CAAC,CACH,CACAhB,EAAwB,GACxBH,EAAW,SAAS,EACpB,KACF,CACA,KAAKZ,EAAmB,QAAS,CAE/B,GAAIc,EACF,MAGF,MAAMkB,EAAUZ,EAAM,QAAUA,EAAM,KAClCY,GACFpB,EAAW,KAAK,CACd,KAAMV,EAAuB,OAC7B,QAAS8B,GAAW,EACtB,CAAC,EAEHjB,EAAwB,GACxBH,EAAW,SAAS,EACpB,KACF,CACA,KAAKZ,EAAmB,QAAS,CAE/B,GAAIc,EACF,MAEFF,EAAW,KAAK,CACd,KAAMV,EAAuB,QAC7B,QAAS,CAAE,QAAS,OAAOkB,EAAM,IAAI,CAAE,CACzC,CAAC,EACD,KACF,CACA,KAAKpB,EAAmB,MAAO,CAC7B,GAAIc,EACF,MAEFF,EAAW,MACT,IAAIL,EAAmB,CACrB,IAAK,KAAK,YAAY,IACtB,aAAc,OAAOa,EAAM,IAAI,CACjC,CAAC,CACH,CACF,CACF,CACF,OAASF,EAAO,CACdF,EAAc,IAAIT,EAAmBW,CAAK,EAC1CN,EAAW,MAAMI,CAAW,CAC9B,EACF,EAEO,IAAM,CACXL,EAAkB,EAClBE,EAAe,GAEX,KAAK,YAAY,aAAehB,EAAU,MAC5C,KAAK,YAAY,MAAM,CAE3B,CACF,CAAC,CAGH,CAOA,2BAAqC,CACnC,MAAMoC,EAAqB,KAAK,KAAK,sBAAsB,EAC3D,MACE,8BAA+BA,GAC/BA,EAAmB,yBAEvB,CACF",
|
6
6
|
"names": ["WebSocket", "Observable", "CommandUtils", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType", "isRefusedByUser", "willRequestPermission", "bufferToHexaString", "hexaStringToBuffer", "SecureChannelError", "ConnectToSecureChannelTask", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "inBulkMode", "communicationFinished", "deviceError", "waitingForUserAction", "error", "event", "input", "nonce", "apdu", "response", "apduResponse", "outMessageResponse", "message", "apdus", "acc", "cur", "i", "len", "payload", "deviceSessionState"]
|
7
7
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/api/secure-channel/task/types.ts"],
|
4
|
-
"sourcesContent": ["export enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: string | Array<string>;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result:
|
4
|
+
"sourcesContent": ["export enum SecureChannelOperationEnum {\n GenuineCheck = \"GenuineCheck\",\n ListInstalledApps = \"ListInstalledApps\",\n UpdateMcu = \"UpdateMcu\",\n UpdateFirmware = \"UpdateFirmware\",\n InstallApp = \"InstallApp\",\n UninstallApp = \"UninstallApp\",\n}\n\n/**\n * The message that will be received from the server by the secure channel.\n */\nexport type InMessageType = {\n uuid: string;\n session: string;\n query: InMessageQueryEnum;\n nonce: number;\n data: string | Array<string>;\n result?: unknown;\n};\n\nexport enum InMessageQueryEnum {\n EXCHANGE = \"exchange\",\n BULK = \"bulk\",\n ERROR = \"error\",\n WARNING = \"warning\",\n SUCCESS = \"success\",\n}\n\n/**\n * The message that will be sent to the server by the secure channel.\n */\nexport type OutMessageType = {\n nonce: number;\n response: OutMessageResponseEnum;\n data: string;\n};\n\nexport enum OutMessageResponseEnum {\n SUCCESS = \"success\",\n ERROR = \"error\",\n}\n\n/**\n * The all event types that can be emitted to the client by the secure channel.\n *\n */\nexport enum SecureChannelEventType {\n Opened = \"opened\",\n Closed = \"closed\",\n PermissionRequested = \"permission-requested\",\n PermissionGranted = \"permission-granted\",\n PreExchange = \"pre-exchange\",\n Exchange = \"exchange\",\n Progress = \"progress\",\n Warning = \"warning\",\n Result = \"result\",\n}\n\n/**\n * The possible payload that will be sent to the client when a secure channel event occurs.\n */\nexport type SecureChannelEventPayload = {\n PreExchange: { nonce: number; apdu: Uint8Array };\n Exchange: {\n nonce: number;\n apdu: Uint8Array;\n data: Uint8Array;\n status: Uint8Array;\n };\n Progress: { progress: number; index: number; total: number };\n Warning: { message: string };\n Result: unknown;\n};\n\n/**\n * The event type that will be emitted to the client when a secure channel event occurs.\n */\nexport type SecureChannelEvent =\n | {\n type: SecureChannelEventType.Opened;\n }\n | {\n type: SecureChannelEventType.Closed;\n }\n | {\n type: SecureChannelEventType.PermissionRequested;\n }\n | {\n type: SecureChannelEventType.PermissionGranted;\n }\n | {\n type: SecureChannelEventType.PreExchange;\n payload: SecureChannelEventPayload[\"PreExchange\"];\n }\n | {\n type: SecureChannelEventType.Exchange;\n payload: SecureChannelEventPayload[\"Exchange\"];\n }\n | {\n type: SecureChannelEventType.Progress;\n payload: SecureChannelEventPayload[\"Progress\"];\n }\n | {\n type: SecureChannelEventType.Warning;\n payload: SecureChannelEventPayload[\"Warning\"];\n }\n | {\n type: SecureChannelEventType.Result;\n payload: SecureChannelEventPayload[\"Result\"];\n };\n"],
|
5
5
|
"mappings": "AAAO,IAAKA,OACVA,EAAA,aAAe,eACfA,EAAA,kBAAoB,oBACpBA,EAAA,UAAY,YACZA,EAAA,eAAiB,iBACjBA,EAAA,WAAa,aACbA,EAAA,aAAe,eANLA,OAAA,IAqBAC,OACVA,EAAA,SAAW,WACXA,EAAA,KAAO,OACPA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,QAAU,UALAA,OAAA,IAiBAC,OACVA,EAAA,QAAU,UACVA,EAAA,MAAQ,QAFEA,OAAA,IASAC,OACVA,EAAA,OAAS,SACTA,EAAA,OAAS,SACTA,EAAA,oBAAsB,uBACtBA,EAAA,kBAAoB,qBACpBA,EAAA,YAAc,eACdA,EAAA,SAAW,WACXA,EAAA,SAAW,WACXA,EAAA,QAAU,UACVA,EAAA,OAAS,SATCA,OAAA",
|
6
6
|
"names": ["SecureChannelOperationEnum", "InMessageQueryEnum", "OutMessageResponseEnum", "SecureChannelEventType"]
|
7
7
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{Left as a}from"purify-ts";import{BehaviorSubject as d}from"rxjs";import{v4 as p}from"uuid";import{CommandUtils as v}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as s}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as u}from"../../../api/device-session/DeviceSessionState";import{DeviceBusyError as S}from"../../../api/Error";import{DEVICE_SESSION_REFRESH_INTERVAL as l}from"../../device-session/data/DeviceSessionRefresherConst";import{RefresherService as h}from"../../device-session/service/RefresherService";import{DeviceSessionRefresher as m}from"./DeviceSessionRefresher";class I{_id;_connectedDevice;_deviceState;_refresher;_refresherService;_managerApiService;_secureChannelService;constructor({connectedDevice:e,id:t=p()},r,i,o){this._id=t,this._connectedDevice=e,this._deviceState=new d({sessionStateType:u.Connected,deviceStatus:s.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._refresher=new m({refreshInterval:l,deviceStatus:s.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:n=>this.sendApdu(n,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:n=>{const c=this._deviceState.getValue();this.setDeviceSessionState(n(c))}},r("device-session-refresher")),this._refresherService=new h(this._refresher),this._managerApiService=i,this._secureChannelService=o}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}){let r;return t.isPolling||(r=this._refresherService.disableRefresher("sendApdu"),await this.waitUntilReady()),this._deviceState.getValue().deviceStatus===s.BUSY?a(new S):(this.updateDeviceStatus(s.BUSY),(await this._connectedDevice.sendApdu(e,t.triggersDisconnection)).ifRight(n=>{v.isLockedDeviceResponse(n)?this.updateDeviceStatus(s.LOCKED):this.updateDeviceStatus(s.CONNECTED),!t.isPolling&&r&&r()}).ifLeft(()=>{this.updateDeviceStatus(s.CONNECTED),!t.isPolling&&r&&r()}))}async sendCommand(e){const t=e.getApdu();return(await this.sendApdu(t.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:i=>{throw i},Right:i=>e.parseResponse(i,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:t,cancel:r}=e._execute({sendApdu:async i=>this.sendApdu(i),sendCommand:async i=>this.sendCommand(i),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:r}}close(){this.updateDeviceStatus(s.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}disableRefresher(e){return this._refresherService.disableRefresher(e)}updateDeviceStatus(e){const t=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...t,deviceStatus:e})}async waitUntilReady(){let e;await new Promise(t=>{e=this._deviceState.subscribe(r=>{
|
1
|
+
import{Left as a}from"purify-ts";import{BehaviorSubject as d}from"rxjs";import{v4 as p}from"uuid";import{CommandUtils as v}from"../../../api/command/utils/CommandUtils";import{DeviceStatus as s}from"../../../api/device/DeviceStatus";import{DeviceSessionStateType as u}from"../../../api/device-session/DeviceSessionState";import{DeviceBusyError as S}from"../../../api/Error";import{DEVICE_SESSION_REFRESH_INTERVAL as l}from"../../device-session/data/DeviceSessionRefresherConst";import{RefresherService as h}from"../../device-session/service/RefresherService";import{DeviceSessionRefresher as m}from"./DeviceSessionRefresher";class I{_id;_connectedDevice;_deviceState;_refresher;_refresherService;_managerApiService;_secureChannelService;constructor({connectedDevice:e,id:t=p()},r,i,o){this._id=t,this._connectedDevice=e,this._deviceState=new d({sessionStateType:u.Connected,deviceStatus:s.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id}),this._refresher=new m({refreshInterval:l,deviceStatus:s.CONNECTED,deviceModelId:this._connectedDevice.deviceModel.id,sendApduFn:n=>this.sendApdu(n,{isPolling:!0,triggersDisconnection:!1}),updateStateFn:n=>{const c=this._deviceState.getValue();this.setDeviceSessionState(n(c))}},r("device-session-refresher")),this._refresherService=new h(this._refresher),this._managerApiService=i,this._secureChannelService=o}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}){let r;return t.isPolling||(r=this._refresherService.disableRefresher("sendApdu"),await this.waitUntilReady()),this._deviceState.getValue().deviceStatus===s.BUSY?a(new S):(this.updateDeviceStatus(s.BUSY),(await this._connectedDevice.sendApdu(e,t.triggersDisconnection)).ifRight(n=>{v.isLockedDeviceResponse(n)?this.updateDeviceStatus(s.LOCKED):this.updateDeviceStatus(s.CONNECTED),!t.isPolling&&r&&r()}).ifLeft(()=>{this.updateDeviceStatus(s.CONNECTED),!t.isPolling&&r&&r()}))}async sendCommand(e){const t=e.getApdu();return(await this.sendApdu(t.getRawApdu(),{isPolling:!1,triggersDisconnection:e.triggersDisconnection??!1})).caseOf({Left:i=>{throw i},Right:i=>e.parseResponse(i,this._connectedDevice.deviceModel.id)})}executeDeviceAction(e){const{observable:t,cancel:r}=e._execute({sendApdu:async i=>this.sendApdu(i),sendCommand:async i=>this.sendCommand(i),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:r}}close(){this.updateDeviceStatus(s.NOT_CONNECTED),this._deviceState.complete(),this._refresher.stop()}disableRefresher(e){return this._refresherService.disableRefresher(e)}updateDeviceStatus(e){const t=this._deviceState.getValue();this._refresher.setDeviceStatus(e),this._deviceState.next({...t,deviceStatus:e})}async waitUntilReady(){let e;await new Promise(t=>{e=this._deviceState.subscribe(r=>{[s.LOCKED,s.CONNECTED].includes(r.deviceStatus)&&(e?.unsubscribe(),t())})})}}export{I 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, type Subscription } 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 { DeviceBusyError, 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 { 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 { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\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 _refresherService: RefresherService;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\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._refresherService = new RefresherService(this._refresher);\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\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 public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n let reenableRefresher: () => void;\n if (!options.isPolling) {\n reenableRefresher = this._refresherService.disableRefresher(\"sendApdu\");\n await this.waitUntilReady();\n }\n\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n 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 if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n })\n .ifLeft(() => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\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 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 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 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\n return {\n observable,\n cancel,\n };\n }\n\n public close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\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 private async waitUntilReady() {\n let deviceStateSub: Subscription;\n\n await new Promise<void>((resolve) => {\n deviceStateSub = this._deviceState.subscribe((state) => {\n if (
|
5
|
-
"mappings": "AAAA,OAAsB,QAAAA,MAAY,YAClC,OAAS,mBAAAC,MAA0C,OACnD,OAAS,MAAMC,MAAc,OAI7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAEP,OAAS,mBAAAC,MAAsC,aAG/C,OAAS,mCAAAC,MAAuC,4DAChD,OAAS,oBAAAC,MAAwB,oDAIjC,OAAS,0BAAAC,MAA8B,2BAehC,MAAMC,CAAc,CACR,IACA,iBACA,aACA,WACA,kBACA,mBACA,sBAEjB,YACE,CAAE,gBAAAC,EAAiB,GAAAC,EAAKV,EAAO,CAAE,EACjCW,EACAC,EACAC,EACA,CACA,KAAK,IAAMH,EACX,KAAK,iBAAmBD,EACxB,KAAK,aAAe,IAAIV,EAAoC,CAC1D,iBAAkBI,EAAuB,UACzC,aAAcD,EAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,EACnD,CAAC,EACD,KAAK,WAAa,IAAIK,EACpB,CACE,gBAAiBF,EACjB,aAAcH,EAAa,UAC3B,cAAe,KAAK,iBAAiB,YAAY,GACjD,WAAaY,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,EACAL,EAAoB,0BAA0B,CAChD,EACA,KAAK,kBAAoB,IAAIL,EAAiB,KAAK,UAAU,EAC7D,KAAK,mBAAqBM,EAC1B,KAAK,sBAAwBC,CAC/B,CAEA,IAAW,IAAK,CACd,OAAO,KAAK,GACd,CAEA,IAAW,iBAAkB,CAC3B,OAAO,KAAK,gBACd,CAEA,I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,SAAS,EACxD,gCAAiC,IAAM,KAAK,MAC5C,sBAAwBJ,IACtB,KAAK,sBAAsBA,CAAK,EACzB,KAAK,aAAa,SAAS,GAEpC,iBAAmBW,GACjB,KAAK,kBAAkB,iBAAiBA,CAAS,EACnD,qBAAsB,IAAM,KAAK,mBACjC,wBAAyB,IAAM,KAAK,qBACtC,CAAC,EAED,MAAO,CACL,WAAAF,EACA,OAAAC,CACF,CACF,CAEO,OAAQ,CACb,KAAK,mBAAmBxB,EAAa,aAAa,EAClD,KAAK,aAAa,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEO,iBAAiBQ,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,mBAAmBkB,EAA4B,CACrD,MAAMC,EAAe,KAAK,aAAa,SAAS,EAChD,KAAK,WAAW,gBAAgBD,CAAY,EAC5C,KAAK,aAAa,KAAK,CACrB,GAAGC,EACH,aAAAD,CACF,CAAC,CACH,CAEA,MAAc,gBAAiB,CAC7B,IAAIE,EAEJ,MAAM,IAAI,QAAeC,GAAY,CACnCD,EAAiB,KAAK,aAAa,UAAWd,GAAU,
|
4
|
+
"sourcesContent": ["import { type Either, Left } from \"purify-ts\";\nimport { BehaviorSubject, type Subscription } 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 { DeviceBusyError, 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 { 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 { DeviceSessionRefresher } from \"./DeviceSessionRefresher\";\n\nexport type SessionConstructorArgs = {\n connectedDevice: TransportConnectedDevice;\n id?: DeviceSessionId;\n};\n\ntype SendApduOptions = {\n isPolling?: boolean;\n triggersDisconnection?: boolean;\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 _refresherService: RefresherService;\n private readonly _managerApiService: ManagerApiService;\n private readonly _secureChannelService: SecureChannelService;\n\n constructor(\n { connectedDevice, id = uuidv4() }: SessionConstructorArgs,\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n managerApiService: ManagerApiService,\n secureChannelService: SecureChannelService,\n ) {\n this._id = id;\n this._connectedDevice = connectedDevice;\n this._deviceState = new BehaviorSubject<DeviceSessionState>({\n sessionStateType: DeviceSessionStateType.Connected,\n deviceStatus: DeviceStatus.CONNECTED,\n deviceModelId: this._connectedDevice.deviceModel.id,\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._refresherService = new RefresherService(this._refresher);\n this._managerApiService = managerApiService;\n this._secureChannelService = secureChannelService;\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 public async sendApdu(\n rawApdu: Uint8Array,\n options: SendApduOptions = {\n isPolling: false,\n triggersDisconnection: false,\n },\n ): Promise<Either<DmkError, ApduResponse>> {\n let reenableRefresher: () => void;\n if (!options.isPolling) {\n reenableRefresher = this._refresherService.disableRefresher(\"sendApdu\");\n await this.waitUntilReady();\n }\n\n const sessionState = this._deviceState.getValue();\n if (sessionState.deviceStatus === DeviceStatus.BUSY) {\n return Left(new DeviceBusyError());\n }\n\n 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 if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\n })\n .ifLeft(() => {\n this.updateDeviceStatus(DeviceStatus.CONNECTED);\n\n if (!options.isPolling && reenableRefresher) {\n reenableRefresher();\n }\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 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 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 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\n return {\n observable,\n cancel,\n };\n }\n\n public close() {\n this.updateDeviceStatus(DeviceStatus.NOT_CONNECTED);\n this._deviceState.complete();\n this._refresher.stop();\n }\n\n public disableRefresher(id: string): () => void {\n return this._refresherService.disableRefresher(id);\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 private async waitUntilReady() {\n let deviceStateSub: Subscription;\n\n await new Promise<void>((resolve) => {\n deviceStateSub = this._deviceState.subscribe((state) => {\n if (\n [DeviceStatus.LOCKED, DeviceStatus.CONNECTED].includes(\n state.deviceStatus,\n )\n ) {\n deviceStateSub?.unsubscribe();\n resolve();\n }\n });\n });\n }\n}\n"],
|
5
|
+
"mappings": "AAAA,OAAsB,QAAAA,MAAY,YAClC,OAAS,mBAAAC,MAA0C,OACnD,OAAS,MAAMC,MAAc,OAI7B,OAAS,gBAAAC,MAAoB,kCAC7B,OAAS,gBAAAC,MAAoB,2BAO7B,OAEE,0BAAAC,MACK,yCAEP,OAAS,mBAAA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a,SAAS,EAC3B,KAAK,WAAW,KAAK,CACvB,CAEO,iBAAiBQ,EAAwB,CAC9C,OAAO,KAAK,kBAAkB,iBAAiBA,CAAE,CACnD,CAEQ,mBAAmBkB,EAA4B,CACrD,MAAMC,EAAe,KAAK,aAAa,SAAS,EAChD,KAAK,WAAW,gBAAgBD,CAAY,EAC5C,KAAK,aAAa,KAAK,CACrB,GAAGC,EACH,aAAAD,CACF,CAAC,CACH,CAEA,MAAc,gBAAiB,CAC7B,IAAIE,EAEJ,MAAM,IAAI,QAAeC,GAAY,CACnCD,EAAiB,KAAK,aAAa,UAAWd,GAAU,CAEpD,CAACd,EAAa,OAAQA,EAAa,SAAS,EAAE,SAC5Cc,EAAM,YACR,IAEAc,GAAgB,YAAY,EAC5BC,EAAQ,EAEZ,CAAC,CACH,CAAC,CACH,CACF",
|
6
6
|
"names": ["Left", "BehaviorSubject", "uuidv4", "CommandUtils", "DeviceStatus", "DeviceSessionStateType", "DeviceBusyError", "DEVICE_SESSION_REFRESH_INTERVAL", "RefresherService", "DeviceSessionRefresher", "DeviceSession", "connectedDevice", "id", "loggerModuleFactory", "managerApiService", "secureChannelService", "rawApdu", "callback", "state", "options", "reenableRefresher", "response", "command", "apdu", "err", "r", "deviceAction", "observable", "cancel", "blockerId", "deviceStatus", "sessionState", "deviceStateSub", "resolve"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var
|
1
|
+
var h=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var y=(a,r,p,e)=>{for(var t=e>1?void 0:e?f(r,p):r,i=a.length-1,A;i>=0;i--)(A=a[i])&&(t=(e?A(r,p,t):A(t))||t);return e&&t&&h(r,p,t),t},g=(a,r)=>(p,e)=>r(p,e,a);import o from"axios";import{inject as v,injectable as u}from"inversify";import{EitherAsync as n}from"purify-ts";import{managerApiTypes as D}from"../../manager-api/di/managerApiTypes";import{AppType as s}from"../../manager-api/model/Application";import{HttpFetchApiError as m}from"../../manager-api/model/Errors";import{AppTypeDto as c}from"./ManagerApiDto";let l=class{managerApiBaseUrl;constructor({managerApiUrl:r}){this.managerApiBaseUrl=r}getAppList(r){const{targetId:p,provider:e,firmwareVersionName:t}=r;return n(()=>o.get(`${this.managerApiBaseUrl}/v2/apps/by-target`,{params:{target_id:p,provider:e,firmware_version_name:t}})).map(i=>i.data).mapLeft(i=>new m(i))}getDeviceVersion(r){const{targetId:p,provider:e}=r;return n(()=>o.get(`${this.managerApiBaseUrl}/get_device_version`,{params:{target_id:p,provider:e}})).map(t=>t.data).mapLeft(t=>new m(t))}getFirmwareVersion(r){const{deviceId:p,version:e,provider:t}=r;return n(()=>o.get(`${this.managerApiBaseUrl}/get_firmware_version`,{params:{device_version:p,version_name:e,provider:t}})).map(i=>i.data).mapLeft(i=>new m(i))}getAppsByHash(r){const{hashes:p}=r;return n(()=>o.post(`${this.managerApiBaseUrl}/v2/apps/hash`,p)).map(e=>e.data).map(e=>this.mapApplicationDtoToApplication(e)).mapLeft(e=>new m(e))}mapAppTypeDtoToAppType(r){switch(r){case c.currency:return s.currency;case c.plugin:return s.plugin;case c.tool:return s.tool;case c.swap:return s.swap}}mapApplicationDtoToApplication(r){return r.map(p=>{if(p===null)return null;const{applicationType:e,...t}=p;return{...t,applicationType:this.mapAppTypeDtoToAppType(e)}})}};l=y([u(),g(0,v(D.DmkConfig))],l);export{l as AxiosManagerApiDataSource};
|
2
2
|
//# sourceMappingURL=AxiosManagerApiDataSource.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/data/AxiosManagerApiDataSource.ts"],
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly managerApiBaseUrl: string;\n
|
5
|
-
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAG5B,OAAS,mBAAAC,MAAuB,2CAChC,OAEE,WAAAC,MACK,0CAEP,OAAS,qBAAAC,MAAyB,
|
6
|
-
"names": ["axios", "inject", "injectable", "EitherAsync", "managerApiTypes", "AppType", "HttpFetchApiError", "AppTypeDto", "AxiosManagerApiDataSource", "managerApiUrl", "
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport { type FinalFirmware } from \"@internal/manager-api/model/Firmware\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport { ApplicationDto, AppTypeDto } from \"./ManagerApiDto\";\n\n@injectable()\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n private readonly managerApiBaseUrl: string;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl }: DmkConfig,\n ) {\n this.managerApiBaseUrl = managerApiUrl;\n }\n\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Application[]> {\n const { targetId, provider, firmwareVersionName } = params;\n return EitherAsync(() =>\n axios.get<Application[]>(`${this.managerApiBaseUrl}/v2/apps/by-target`, {\n params: {\n target_id: targetId,\n provider,\n firmware_version_name: firmwareVersionName,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n const { targetId, provider } = params;\n return EitherAsync(() =>\n axios.get<DeviceVersion>(`${this.managerApiBaseUrl}/get_device_version`, {\n params: {\n target_id: targetId,\n provider,\n },\n }),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n const { deviceId, version, provider } = params;\n return EitherAsync(() =>\n axios.get<FinalFirmware>(\n `${this.managerApiBaseUrl}/get_firmware_version`,\n {\n params: {\n device_version: deviceId,\n version_name: version,\n provider,\n },\n },\n ),\n )\n .map((res) => res.data)\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n const { hashes } = params;\n return EitherAsync(() =>\n axios.post<Array<ApplicationDto | null>>(\n `${this.managerApiBaseUrl}/v2/apps/hash`,\n hashes,\n ),\n )\n .map((res) => res.data)\n .map((apps) => this.mapApplicationDtoToApplication(apps))\n .mapLeft((error) => new HttpFetchApiError(error));\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto): AppType {\n switch (appType) {\n case AppTypeDto.currency:\n return AppType.currency;\n case AppTypeDto.plugin:\n return AppType.plugin;\n case AppTypeDto.tool:\n return AppType.tool;\n case AppTypeDto.swap:\n return AppType.swap;\n }\n }\n\n private mapApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): Array<Application | null> {\n return apps.map((app) => {\n if (app === null) {\n return null;\n }\n const { applicationType, ...rest } = app;\n return {\n ...rest,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n });\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAG5B,OAAS,mBAAAC,MAAuB,2CAChC,OAEE,WAAAC,MACK,0CAEP,OAAS,qBAAAC,MAAyB,qCAUlC,OAAyB,cAAAC,MAAkB,kBAGpC,IAAMC,EAAN,KAAgE,CACpD,kBAEjB,YAEE,CAAE,cAAAC,CAAc,EAChB,CACA,KAAK,kBAAoBA,CAC3B,CAEA,WACEC,EAC+C,CAC/C,KAAM,CAAE,SAAAC,EAAU,SAAAC,EAAU,oBAAAC,CAAoB,EAAIH,EACpD,OAAOI,EAAY,IACjBC,EAAM,IAAmB,GAAG,KAAK,iBAAiB,qBAAsB,CACtE,OAAQ,CACN,UAAWJ,EACX,SAAAC,EACA,sBAAuBC,CACzB,CACF,CAAC,CACH,EACG,IAAKG,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAIC,EAAkBD,CAAK,CAAC,CACpD,CAEA,iBACEP,EAC+C,CAC/C,KAAM,CAAE,SAAAC,EAAU,SAAAC,CAAS,EAAIF,EAC/B,OAAOI,EAAY,IACjBC,EAAM,IAAmB,GAAG,KAAK,iBAAiB,sBAAuB,CACvE,OAAQ,CACN,UAAWJ,EACX,SAAAC,CACF,CACF,CAAC,CACH,EACG,IAAKI,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAIC,EAAkBD,CAAK,CAAC,CACpD,CAEA,mBACEP,EAC+C,CAC/C,KAAM,CAAE,SAAAS,EAAU,QAAAC,EAAS,SAAAR,CAAS,EAAIF,EACxC,OAAOI,EAAY,IACjBC,EAAM,IACJ,GAAG,KAAK,iBAAiB,wBACzB,CACE,OAAQ,CACN,eAAgBI,EAChB,aAAcC,EACd,SAAAR,CACF,CACF,CACF,CACF,EACG,IAAKI,GAAQA,EAAI,IAAI,EACrB,QAASC,GAAU,IAAIC,EAAkBD,CAAK,CAAC,CACpD,CAEA,cACEP,EAC2D,CAC3D,KAAM,CAAE,OAAAW,CAAO,EAAIX,EACnB,OAAOI,EAAY,IACjBC,EAAM,KACJ,GAAG,KAAK,iBAAiB,gBACzBM,CACF,CACF,EACG,IAAKL,GAAQA,EAAI,IAAI,EACrB,IAAKM,GAAS,KAAK,+BAA+BA,CAAI,CAAC,EACvD,QAASL,GAAU,IAAIC,EAAkBD,CAAK,CAAC,CACpD,CAEQ,uBAAuBM,EAA8B,CAC3D,OAAQA,EAAS,CACf,KAAKC,EAAW,SACd,OAAOC,EAAQ,SACjB,KAAKD,EAAW,OACd,OAAOC,EAAQ,OACjB,KAAKD,EAAW,KACd,OAAOC,EAAQ,KACjB,KAAKD,EAAW,KACd,OAAOC,EAAQ,IACnB,CACF,CAEQ,+BACNH,EAC2B,CAC3B,OAAOA,EAAK,IAAKI,GAAQ,CACvB,GAAIA,IAAQ,KACV,OAAO,KAET,KAAM,CAAE,gBAAAC,EAAiB,GAAGC,CAAK,EAAIF,EACrC,MAAO,CACL,GAAGE,EACH,gBAAiB,KAAK,uBAAuBD,CAAe,CAC9D,CACF,CAAC,CACH,CACF,EAzGanB,EAANqB,EAAA,CADNC,EAAW,EAKPC,EAAA,EAAAC,EAAOC,EAAgB,SAAS,IAJxBzB",
|
6
|
+
"names": ["axios", "inject", "injectable", "EitherAsync", "managerApiTypes", "AppType", "HttpFetchApiError", "AppTypeDto", "AxiosManagerApiDataSource", "managerApiUrl", "params", "targetId", "provider", "firmwareVersionName", "EitherAsync", "axios", "res", "error", "HttpFetchApiError", "deviceId", "version", "hashes", "apps", "appType", "AppTypeDto", "AppType", "app", "applicationType", "rest", "__decorateClass", "injectable", "__decorateParam", "inject", "managerApiTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import
|
1
|
+
import s from"axios";import{Left as c,Right as a}from"purify-ts";import{BTC_APP as p,BTC_APP_METADATA as o,CUSTOM_LOCK_SCREEN_APP as h,CUSTOM_LOCK_SCREEN_APP_METADATA as l}from"../../../api/device-action/__test-utils__/data";import{HttpFetchApiError as n}from"../../manager-api/model/Errors";import{AxiosManagerApiDataSource as i}from"./AxiosManagerApiDataSource";vi.mock("axios");const d={id:17,target_id:"857735172"},u={id:361,perso:"perso_11"};describe("AxiosManagerApiDataSource",()=>{describe("getAppList",()=>{let r;beforeEach(()=>{r=new i({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a list of applications",()=>{const e=[o,l];vi.spyOn(s,"get").mockResolvedValue({data:e});const t=r.getAppList({targetId:"targetId",provider:42,firmwareVersionName:"firmwareVersionName"});expect(t).resolves.toEqual(a(e))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(s,"get").mockRejectedValue(e);const t=r.getAppList({targetId:"targetId",provider:42,firmwareVersionName:"firmwareVersionName"});expect(t).resolves.toEqual(c(new n(e)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let r;beforeEach(()=>{r=new i({})}),afterEach(()=>{vi.clearAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(s,"post").mockResolvedValue({data:[o]});const e=[p.appFullHash],t=await r.getAppsByHash({hashes:e});expect(t).toEqual(a([o]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(s,"post").mockResolvedValue({data:[]});const e=[],t=await r.getAppsByHash({hashes:e});expect(t).toEqual(a([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(s,"post").mockResolvedValue({data:[o,l]});const e=[p.appFullHash,h.appFullHash],t=await r.getAppsByHash({hashes:e});expect(t).toEqual(a([o,l]))})}),describe("error cases",()=>{afterEach(()=>{vi.clearAllMocks()}),it("should throw an error if the request fails",()=>{const r=new i({}),e=new Error("fetch error");vi.spyOn(s,"post").mockRejectedValue(e);const t=[p.appFullHash],m=r.getAppsByHash({hashes:t});expect(m).resolves.toEqual(c(new n(e)))})})}),describe("getDeviceVersion",()=>{let r;beforeEach(()=>{r=new i({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete device version",()=>{vi.spyOn(s,"get").mockResolvedValue({data:d});const e=r.getDeviceVersion({targetId:"targetId",provider:42});expect(e).resolves.toEqual(a(d))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(s,"get").mockRejectedValue(e);const t=r.getDeviceVersion({targetId:"targetId",provider:42});expect(t).resolves.toEqual(c(new n(e)))})}),describe("getFirmwareVersion",()=>{let r;beforeEach(()=>{r=new i({})}),afterEach(()=>{vi.clearAllMocks()}),it("should return a complete firmware version",()=>{vi.spyOn(s,"get").mockResolvedValue({data:u});const e=r.getFirmwareVersion({version:"versionName",deviceId:42,provider:21});expect(e).resolves.toEqual(a(u))}),it("should return an error if the request fails",()=>{const e=new Error("fetch error");vi.spyOn(s,"get").mockRejectedValue(e);const t=r.getFirmwareVersion({version:"versionName",deviceId:42,provider:21});expect(t).resolves.toEqual(c(new n(e)))})})});
|
2
2
|
//# sourceMappingURL=AxiosManagerApiDataSource.test.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/data/AxiosManagerApiDataSource.test.ts"],
|
4
|
-
"sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { AxiosManagerApiDataSource } from \"./AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"./ManagerApiDataSource\";\n\nvi.mock(\"axios\");\n\nconst mockGetDeviceVersion = {\n id: 17,\n target_id: \"857735172\",\n};\n\nconst mockGetFirmwareVersion = {\n id: 361,\n perso: \"perso_11\",\n};\n\ndescribe(\"AxiosManagerApiDataSource\", () => {\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"with BTC app, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA],\n });\n\n const hashes = [BTC_APP.appFullHash];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(Right([BTC_APP_METADATA]));\n });\n\n it(\"with no apps, should return an empty list\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [],\n });\n\n const hashes: string[] = [];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(Right([]));\n });\n\n it(\"with BTC app and custom lock screen, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n });\n\n const hashes = [\n BTC_APP.appFullHash,\n CUSTOM_LOCK_SCREEN_APP.appFullHash,\n ];\n\n const apps = await api.getAppsByHash(hashes);\n\n expect(apps).toEqual(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n );\n });\n });\n\n describe(\"error cases\", () => {\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should throw an error if the request fails\", () => {\n // given\n const api = new AxiosManagerApiDataSource({} as DmkConfig);\n\n const err = new Error(\"fetch error\");\n vi.spyOn(axios, \"post\").mockRejectedValue(err);\n\n const hashes = [BTC_APP.appFullHash];\n\n // when\n const response = api.getAppsByHash(hashes);\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(err)));\n });\n });\n });\n\n describe(\"getDeviceVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete device version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: mockGetDeviceVersion });\n\n // when\n const response = api.getDeviceVersion(\"targetId\"
|
5
|
-
"mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OACE,WAAAC,EACA,oBAAAC,EACA,0BAAAC,EACA,mCAAAC,MACK,yCAEP,OAAS,qBAAAC,MAAyB,qCAElC,OAAS,6BAAAC,MAAiC,8BAG1C,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAuB,CAC3B,GAAI,GACJ,UAAW,WACb,EAEMC,EAAyB,CAC7B,GAAI,IACJ,MAAO,UACT,EAEA,SAAS,4BAA6B,IAAM,CAC1C,SAAS,gBAAiB,IAAM,CAC9B,SAAS,gBAAiB,IAAM,CAC9B,
|
6
|
-
"names": ["axios", "Left", "Right", "BTC_APP", "BTC_APP_METADATA", "CUSTOM_LOCK_SCREEN_APP", "CUSTOM_LOCK_SCREEN_APP_METADATA", "HttpFetchApiError", "AxiosManagerApiDataSource", "mockGetDeviceVersion", "mockGetFirmwareVersion", "api", "
|
4
|
+
"sourcesContent": ["import axios from \"axios\";\nimport { Left, Right } from \"purify-ts\";\n\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n CUSTOM_LOCK_SCREEN_APP,\n CUSTOM_LOCK_SCREEN_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { AxiosManagerApiDataSource } from \"./AxiosManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"./ManagerApiDataSource\";\n\nvi.mock(\"axios\");\n\nconst mockGetDeviceVersion = {\n id: 17,\n target_id: \"857735172\",\n};\n\nconst mockGetFirmwareVersion = {\n id: 361,\n perso: \"perso_11\",\n};\n\ndescribe(\"AxiosManagerApiDataSource\", () => {\n describe(\"getAppList\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a list of applications\", () => {\n // given\n const apps = [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA];\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: apps });\n\n // when\n const response = api.getAppList({\n targetId: \"targetId\",\n provider: 42,\n firmwareVersionName: \"firmwareVersionName\",\n });\n\n // then\n expect(response).resolves.toEqual(Right(apps));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getAppList({\n targetId: \"targetId\",\n provider: 42,\n firmwareVersionName: \"firmwareVersionName\",\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"with BTC app, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA],\n });\n\n const hashes = [BTC_APP.appFullHash];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(Right([BTC_APP_METADATA]));\n });\n\n it(\"with no apps, should return an empty list\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [],\n });\n\n const hashes: string[] = [];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(Right([]));\n });\n\n it(\"with BTC app and custom lock screen, should return the metadata\", async () => {\n vi.spyOn(axios, \"post\").mockResolvedValue({\n data: [BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA],\n });\n\n const hashes = [\n BTC_APP.appFullHash,\n CUSTOM_LOCK_SCREEN_APP.appFullHash,\n ];\n\n const apps = await api.getAppsByHash({ hashes });\n\n expect(apps).toEqual(\n Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]),\n );\n });\n });\n\n describe(\"error cases\", () => {\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should throw an error if the request fails\", () => {\n // given\n const api = new AxiosManagerApiDataSource({} as DmkConfig);\n\n const err = new Error(\"fetch error\");\n vi.spyOn(axios, \"post\").mockRejectedValue(err);\n\n const hashes = [BTC_APP.appFullHash];\n\n // when\n const response = api.getAppsByHash({ hashes });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(err)));\n });\n });\n });\n\n describe(\"getDeviceVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete device version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({ data: mockGetDeviceVersion });\n\n // when\n const response = api.getDeviceVersion({\n targetId: \"targetId\",\n provider: 42,\n });\n\n // then\n expect(response).resolves.toEqual(Right(mockGetDeviceVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getDeviceVersion({\n targetId: \"targetId\",\n provider: 42,\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n\n describe(\"getFirmwareVersion\", () => {\n let api: ManagerApiDataSource;\n beforeEach(() => {\n api = new AxiosManagerApiDataSource({} as DmkConfig);\n });\n afterEach(() => {\n vi.clearAllMocks();\n });\n it(\"should return a complete firmware version\", () => {\n // given\n vi.spyOn(axios, \"get\").mockResolvedValue({\n data: mockGetFirmwareVersion,\n });\n\n // when\n const response = api.getFirmwareVersion({\n version: \"versionName\",\n deviceId: 42,\n provider: 21,\n });\n\n // then\n expect(response).resolves.toEqual(Right(mockGetFirmwareVersion));\n });\n it(\"should return an error if the request fails\", () => {\n // given\n const error = new Error(\"fetch error\");\n vi.spyOn(axios, \"get\").mockRejectedValue(error);\n\n // when\n const response = api.getFirmwareVersion({\n version: \"versionName\",\n deviceId: 42,\n provider: 21,\n });\n\n // then\n expect(response).resolves.toEqual(Left(new HttpFetchApiError(error)));\n });\n });\n});\n"],
|
5
|
+
"mappings": "AAAA,OAAOA,MAAW,QAClB,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OACE,WAAAC,EACA,oBAAAC,EACA,0BAAAC,EACA,mCAAAC,MACK,yCAEP,OAAS,qBAAAC,MAAyB,qCAElC,OAAS,6BAAAC,MAAiC,8BAG1C,GAAG,KAAK,OAAO,EAEf,MAAMC,EAAuB,CAC3B,GAAI,GACJ,UAAW,WACb,EAEMC,EAAyB,CAC7B,GAAI,IACJ,MAAO,UACT,EAEA,SAAS,4BAA6B,IAAM,CAC1C,SAAS,aAAc,IAAM,CAC3B,IAAIC,EACJ,WAAW,IAAM,CACfA,EAAM,IAAIH,EAA0B,CAAC,CAAc,CACrD,CAAC,EACD,UAAU,IAAM,CACd,GAAG,cAAc,CACnB,CAAC,EACD,GAAG,uCAAwC,IAAM,CAE/C,MAAMI,EAAO,CAACR,EAAkBE,CAA+B,EAC/D,GAAG,MAAMN,EAAO,KAAK,EAAE,kBAAkB,CAAE,KAAMY,CAAK,CAAC,EAGvD,MAAMC,EAAWF,EAAI,WAAW,CAC9B,SAAU,WACV,SAAU,GACV,oBAAqB,qBACvB,CAAC,EAGD,OAAOE,CAAQ,EAAE,SAAS,QAAQX,EAAMU,CAAI,CAAC,CAC/C,CAAC,EACD,GAAG,8CAA+C,IAAM,CAEtD,MAAME,EAAQ,IAAI,MAAM,aAAa,EACrC,GAAG,MAAMd,EAAO,KAAK,EAAE,kBAAkBc,CAAK,EAG9C,MAAMD,EAAWF,E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GAAG,cAAc,CACnB,CAAC,EACD,GAAG,4CAA6C,IAAM,CAEpD,GAAG,MAAMR,EAAO,KAAK,EAAE,kBAAkB,CACvC,KAAMU,CACR,CAAC,EAGD,MAAMG,EAAWF,EAAI,mBAAmB,CACtC,QAAS,cACT,SAAU,GACV,SAAU,EACZ,CAAC,EAGD,OAAOE,CAAQ,EAAE,SAAS,QAAQX,EAAMQ,CAAsB,CAAC,CACjE,CAAC,EACD,GAAG,8CAA+C,IAAM,CAEtD,MAAMI,EAAQ,IAAI,MAAM,aAAa,EACrC,GAAG,MAAMd,EAAO,KAAK,EAAE,kBAAkBc,CAAK,EAG9C,MAAMD,EAAWF,EAAI,mBAAmB,CACtC,QAAS,cACT,SAAU,GACV,SAAU,EACZ,CAAC,EAGD,OAAOE,CAAQ,EAAE,SAAS,QAAQZ,EAAK,IAAIM,EAAkBO,CAAK,CAAC,CAAC,CACtE,CAAC,CACH,CAAC,CACH,CAAC",
|
6
|
+
"names": ["axios", "Left", "Right", "BTC_APP", "BTC_APP_METADATA", "CUSTOM_LOCK_SCREEN_APP", "CUSTOM_LOCK_SCREEN_APP_METADATA", "HttpFetchApiError", "AxiosManagerApiDataSource", "mockGetDeviceVersion", "mockGetFirmwareVersion", "api", "apps", "response", "error", "hashes", "err"]
|
7
7
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/data/ManagerApiDto.ts"],
|
4
|
-
"sourcesContent": ["export type Id = number;\n\nexport enum AppTypeDto {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type ApplicationDto = {\n versionId: Id;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppTypeDto;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n
|
4
|
+
"sourcesContent": ["export type Id = number;\n\nexport enum AppTypeDto {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type ApplicationDto = {\n versionId: Id;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppTypeDto;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n compatibleWallets: string;\n hash: string;\n perso: string;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n category: number;\n parent: number | null;\n parentName: string | null;\n};\n"],
|
5
5
|
"mappings": "AAEO,IAAKA,OACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,KAAO,OAJGA,OAAA",
|
6
6
|
"names": ["AppTypeDto"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
class a{getDeviceVersion=vi.fn();getFirmwareVersion=vi.fn();getAppsByHash=vi.fn()}export{a as AxiosManagerApiDataSource};
|
1
|
+
class a{getAppList=vi.fn();getDeviceVersion=vi.fn();getFirmwareVersion=vi.fn();getAppsByHash=vi.fn()}export{a as AxiosManagerApiDataSource};
|
2
2
|
//# sourceMappingURL=AxiosManagerApiDataSource.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../../src/internal/manager-api/data/__mocks__/AxiosManagerApiDataSource.ts"],
|
4
|
-
"sourcesContent": ["import { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\n\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n getDeviceVersion = vi.fn();\n getFirmwareVersion = vi.fn();\n getAppsByHash = vi.fn();\n}\n"],
|
5
|
-
"mappings": "AAEO,MAAMA,CAA0D,CACrE,iBAAmB,GAAG,GAAG,EACzB,mBAAqB,GAAG,GAAG,EAC3B,cAAgB,GAAG,GAAG,CACxB",
|
4
|
+
"sourcesContent": ["import { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\n\nexport class AxiosManagerApiDataSource implements ManagerApiDataSource {\n getAppList = vi.fn();\n getDeviceVersion = vi.fn();\n getFirmwareVersion = vi.fn();\n getAppsByHash = vi.fn();\n}\n"],
|
5
|
+
"mappings": "AAEO,MAAMA,CAA0D,CACrE,WAAa,GAAG,GAAG,EACnB,iBAAmB,GAAG,GAAG,EACzB,mBAAqB,GAAG,GAAG,EAC3B,cAAgB,GAAG,GAAG,CACxB",
|
6
6
|
"names": ["AxiosManagerApiDataSource"]
|
7
7
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/model/Application.ts"],
|
4
|
-
"sourcesContent": ["export enum AppType {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type Application = {\n versionId: number;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppType;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n
|
4
|
+
"sourcesContent": ["export enum AppType {\n currency = \"currency\",\n plugin = \"plugin\",\n tool = \"tool\",\n swap = \"swap\",\n}\n\nexport type Application = {\n versionId: number;\n versionName: string;\n versionDisplayName: string;\n version: string;\n currencyId: string;\n description: string;\n applicationType: AppType;\n dateModified: string;\n icon: string;\n authorName: string;\n supportURL: string;\n contactURL: string;\n sourceURL: string;\n compatibleWallets: string;\n hash: string;\n perso: string;\n firmware: string;\n firmwareKey: string;\n delete: string;\n deleteKey: string;\n bytes: number;\n warning: string | null;\n isDevTools: boolean;\n category: number;\n parent: number | null;\n parentName: string | null;\n};\n"],
|
5
5
|
"mappings": "AAAO,IAAKA,OACVA,EAAA,SAAW,WACXA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,KAAO,OAJGA,OAAA",
|
6
6
|
"names": ["AppType"]
|
7
7
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=Params.js.map
|
@@ -1,2 +1,2 @@
|
|
1
|
-
var
|
1
|
+
var y=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var n=(i,r,e,t)=>{for(var s=t>1?void 0:t?A(r,e):r,a=i.length-1,p;a>=0;a--)(p=i[a])&&(s=(t?p(r,e,s):p(s))||s);return t&&s&&y(r,e,s),s},m=(i,r)=>(e,t)=>r(e,t,i);import{inject as g,injectable as h}from"inversify";import{EitherAsync as u}from"purify-ts";import{managerApiTypes as V}from"../../manager-api/di/managerApiTypes";import{HttpFetchApiError as c}from"../../manager-api/model/Errors";let o=class{constructor(r){this.dataSource=r}getAppList(r,e){const t={targetId:r.targetId.toString(),provider:e,firmwareVersionName:r.seVersion};return this.dataSource.getAppList(t)}getDeviceVersion(r,e){const t={targetId:r.targetId.toString(),provider:e};return this.dataSource.getDeviceVersion(t)}getFirmwareVersion(r,e,t){const s={version:r.seVersion,deviceId:e.id,provider:t};return this.dataSource.getFirmwareVersion(s)}getAppsByHash(r){const e={hashes:r};return u(async({fromPromise:t,throwE:s})=>{if(e.hashes.length===0)return[];try{return await t(this.dataSource.getAppsByHash(e))}catch(a){return a instanceof c?s(a):s(new c(a))}})}};o=n([h(),m(0,g(V.ManagerApiDataSource))],o);export{o as DefaultManagerApiService};
|
2
2
|
//# sourceMappingURL=DefaultManagerApiService.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/service/DefaultManagerApiService.ts"],
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport {
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,
|
6
|
-
"names": ["inject", "injectable", "EitherAsync", "managerApiTypes", "HttpFetchApiError", "DefaultManagerApiService", "dataSource", "deviceInfo", "provider", "
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync } from \"purify-ts\";\n\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport { type Application } from \"@internal/manager-api/model/Application\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { type ManagerApiService } from \"./ManagerApiService\";\n\n@injectable()\nexport class DefaultManagerApiService implements ManagerApiService {\n constructor(\n @inject(managerApiTypes.ManagerApiDataSource)\n private readonly dataSource: ManagerApiDataSource,\n ) {}\n\n getAppList(\n deviceInfo: GetOsVersionResponse,\n provider: number,\n ): EitherAsync<HttpFetchApiError, Array<Application>> {\n const params: GetAppListParams = {\n targetId: deviceInfo.targetId.toString(),\n provider,\n firmwareVersionName: deviceInfo.seVersion,\n };\n return this.dataSource.getAppList(params);\n }\n\n getDeviceVersion(deviceInfo: GetOsVersionResponse, provider: number) {\n const params: GetDeviceVersionParams = {\n targetId: deviceInfo.targetId.toString(),\n provider,\n };\n return this.dataSource.getDeviceVersion(params);\n }\n\n getFirmwareVersion(\n deviceInfo: GetOsVersionResponse,\n deviceVersion: DeviceVersion,\n provider: number,\n ) {\n const params: GetFirmwareVersionParams = {\n version: deviceInfo.seVersion,\n deviceId: deviceVersion.id,\n provider,\n };\n return this.dataSource.getFirmwareVersion(params);\n }\n\n getAppsByHash(appHashes: Array<string>) {\n const params: GetAppByHashParams = {\n hashes: appHashes,\n };\n return EitherAsync<HttpFetchApiError, Array<Application | null>>(\n async ({ fromPromise, throwE }) => {\n if (params.hashes.length === 0) {\n return [];\n }\n try {\n const response = await fromPromise(\n this.dataSource.getAppsByHash(params),\n );\n return response;\n } catch (error) {\n if (error instanceof HttpFetchApiError) {\n return throwE(error);\n }\n return throwE(new HttpFetchApiError(error));\n }\n },\n );\n }\n}\n"],
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,MAAmB,YAI5B,OAAS,mBAAAC,MAAuB,2CAGhC,OAAS,qBAAAC,MAAyB,qCAW3B,IAAMC,EAAN,KAA4D,CACjE,YAEmBC,EACjB,CADiB,gBAAAA,CAChB,CAEH,WACEC,EACAC,EACoD,CACpD,MAAMC,EAA2B,CAC/B,SAAUF,EAAW,SAAS,SAAS,EACvC,SAAAC,EACA,oBAAqBD,EAAW,SAClC,EACA,OAAO,KAAK,WAAW,WAAWE,CAAM,CAC1C,CAEA,iBAAiBF,EAAkCC,EAAkB,CACnE,MAAMC,EAAiC,CACrC,SAAUF,EAAW,SAAS,SAAS,EACvC,SAAAC,CACF,EACA,OAAO,KAAK,WAAW,iBAAiBC,CAAM,CAChD,CAEA,mBACEF,EACAG,EACAF,EACA,CACA,MAAMC,EAAmC,CACvC,QAASF,EAAW,UACpB,SAAUG,EAAc,GACxB,SAAAF,CACF,EACA,OAAO,KAAK,WAAW,mBAAmBC,CAAM,CAClD,CAEA,cAAcE,EAA0B,CACtC,MAAMF,EAA6B,CACjC,OAAQE,CACV,EACA,OAAOC,EACL,MAAO,CAAE,YAAAC,EAAa,OAAAC,CAAO,IAAM,CACjC,GAAIL,EAAO,OAAO,SAAW,EAC3B,MAAO,CAAC,EAEV,GAAI,CAIF,OAHiB,MAAMI,EACrB,KAAK,WAAW,cAAcJ,CAAM,CACtC,CAEF,OAASM,EAAO,CACd,OAAIA,aAAiBC,EACZF,EAAOC,CAAK,EAEdD,EAAO,IAAIE,EAAkBD,CAAK,CAAC,CAC5C,CACF,CACF,CACF,CACF,EA9DaV,EAANY,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAgB,oBAAoB,IAFnChB",
|
6
|
+
"names": ["inject", "injectable", "EitherAsync", "managerApiTypes", "HttpFetchApiError", "DefaultManagerApiService", "dataSource", "deviceInfo", "provider", "params", "deviceVersion", "appHashes", "EitherAsync", "fromPromise", "throwE", "error", "HttpFetchApiError", "__decorateClass", "injectable", "__decorateParam", "inject", "managerApiTypes"]
|
7
7
|
}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{Left as
|
1
|
+
import{Left as n,Right as r}from"purify-ts";import{getOsVersionCommandResponseMockBuilder as s}from"../../../api/command/os/__mocks__/GetOsVersionCommand";import{DeviceModelId as c}from"../../../api/device/DeviceModel";import{BTC_APP as p,BTC_APP_METADATA as o,ETH_APP as l,ETH_APP_METADATA as d}from"../../../api/device-action/__test-utils__/data";import{AxiosManagerApiDataSource as m}from"../../manager-api/data/AxiosManagerApiDataSource";import{HttpFetchApiError as h}from"../../manager-api/model/Errors";import{DefaultManagerApiService as u}from"./DefaultManagerApiService";vi.mock("@internal/manager-api/data/AxiosManagerApiDataSource");let t,a;describe("ManagerApiService",()=>{beforeEach(()=>{t=new m({}),a=new u(t)}),describe("getAppList",()=>{it("should call api with the correct parameters",()=>{const e=s(c.STAX);a.getAppList(e,42),expect(t.getAppList).toHaveBeenCalledWith({targetId:"857735172",provider:42,firmwareVersionName:"1.3.0"})})}),describe("getAppsByHash",()=>{describe("success cases",()=>{it("with no apps, should return an empty list",async()=>{t.getAppsByHash.mockResolvedValue(r([])),expect(await a.getAppsByHash([])).toEqual(r([]))}),it("with one app, should return the metadata",async()=>{t.getAppsByHash.mockResolvedValue(r([o])),expect(await a.getAppsByHash([p.appFullHash])).toEqual(r([o]))}),it("with two app, should return the metadata of both apps",async()=>{t.getAppsByHash.mockResolvedValue(r([o,d])),expect(await a.getAppsByHash([p,l].map(e=>e.appFullHash))).toEqual(r([o,d]))}),it("with one app and one without `appFullHash`, should return the metadata of the correct app",async()=>{t.getAppsByHash.mockResolvedValue(r([o]));const e={...l,appFullHash:""};expect(await a.getAppsByHash([p,e].map(i=>i.appFullHash))).toEqual(r([o]))})}),describe("error cases",()=>{it("should return an error when the data source fails with a known error",async()=>{const e=new h(new Error("Failed to fetch data"));t.getAppsByHash.mockRejectedValue(e),expect(await a.getAppsByHash([p.appFullHash])).toEqual(n(e))}),it("should return an error when the data source fails with an unknown error",async()=>{const e=new Error("unkown error");t.getAppsByHash.mockRejectedValue(e),expect(await a.getAppsByHash([p.appFullHash])).toEqual(n(new h(e)))})})}),describe("getDeviceVersion",()=>{it("should call api with the correct parameters",()=>{const e=s(c.STAX);a.getDeviceVersion(e,42),expect(t.getDeviceVersion).toHaveBeenCalledWith({targetId:"857735172",provider:42})})}),describe("getFirmwareVersion",()=>{it("should call api with the correct parameters",()=>{const e={id:17,target_id:"857735172"},i=s(c.STAX);a.getFirmwareVersion(i,e,42),expect(t.getFirmwareVersion).toHaveBeenCalledWith({deviceId:17,provider:42,version:"1.3.0"})})})});
|
2
2
|
//# sourceMappingURL=DefaultManagerApiService.test.js.map
|
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/service/DefaultManagerApiService.test.ts"],
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mocked } from \"vitest\";\n\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n ETH_APP,\n ETH_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { AxiosManagerApiDataSource } from \"@internal/manager-api/data/AxiosManagerApiDataSource\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { DefaultManagerApiService } from \"./DefaultManagerApiService\";\nimport { type ManagerApiService } from \"./ManagerApiService\";\n\nvi.mock(\"@internal/manager-api/data/AxiosManagerApiDataSource\");\nlet dataSource: Mocked<AxiosManagerApiDataSource>;\nlet service: ManagerApiService;\ndescribe(\"ManagerApiService\", () => {\n beforeEach(() => {\n dataSource = new AxiosManagerApiDataSource(\n {} as DmkConfig,\n ) as Mocked<AxiosManagerApiDataSource>;\n service = new DefaultManagerApiService(dataSource);\n });\n\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n it(\"with no apps, should return an empty list\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(Right([]));\n expect(await service.getAppsByHash([])).toEqual(Right([]));\n });\n\n it(\"with one app, should return the metadata\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(Right([BTC_APP_METADATA]));\n expect(await service.getAppsByHash([BTC_APP])).toEqual(\n Right([BTC_APP_METADATA]),\n );\n });\n\n it(\"with two app, should return the metadata of both apps\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(\n Right([BTC_APP_METADATA, ETH_APP_METADATA]),\n );\n expect(await service.getAppsByHash([BTC_APP, ETH_APP])).toEqual(
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAG5B,OAAS,0CAAAC,MAA8C,gDACvD,OAAS,iBAAAC,MAAqB,0BAC9B,OACE,WAAAC,EACA,oBAAAC,EACA,WAAAC,EACA,oBAAAC,MACK,yCAEP,OAAS,6BAAAC,MAAiC,uDAC1C,OAAS,qBAAAC,MAAyB,qCAElC,OAAS,4BAAAC,MAAgC,6BAGzC,GAAG,KAAK,sDAAsD,EAC9D,IAAIC,EACAC,EACJ,SAAS,oBAAqB,IAAM,CAClC,WAAW,IAAM,CACfD,EAAa,IAAIH,EACf,CAAC,CACH,EACAI,EAAU,IAAIF,EAAyBC,CAAU,CACnD,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,SAAS,gBAAiB,IAAM,CAC9B,GAAG,4CAA6C,SAAY,CAC1DA,EAAW,cAAc,kBAAkBV,EAAM,CAAC,CAAC,CAAC,EACpD,OAAO,MAAMW,EAAQ,cAAc,CAAC,CAAC,CAAC,EAAE,QAAQX,EAAM,CAAC,CAAC,CAAC,CAC3D,CAAC,EAED,GAAG,2CAA4C,SAAY,CACzDU,EAAW,cAAc,kBAAkBV,EAAM,CAACI,CAAgB,CAAC,CAAC,EACpE,OAAO,MAAMO,EAAQ,cAAc,CAACR,
|
6
|
-
"names": ["Left", "Right", "getOsVersionCommandResponseMockBuilder", "DeviceModelId", "BTC_APP", "BTC_APP_METADATA", "ETH_APP", "ETH_APP_METADATA", "AxiosManagerApiDataSource", "HttpFetchApiError", "DefaultManagerApiService", "dataSource", "service", "
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\nimport { type Mocked } from \"vitest\";\n\nimport { getOsVersionCommandResponseMockBuilder } from \"@api/command/os/__mocks__/GetOsVersionCommand\";\nimport { DeviceModelId } from \"@api/device/DeviceModel\";\nimport {\n BTC_APP,\n BTC_APP_METADATA,\n ETH_APP,\n ETH_APP_METADATA,\n} from \"@api/device-action/__test-utils__/data\";\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { AxiosManagerApiDataSource } from \"@internal/manager-api/data/AxiosManagerApiDataSource\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\n\nimport { DefaultManagerApiService } from \"./DefaultManagerApiService\";\nimport { type ManagerApiService } from \"./ManagerApiService\";\n\nvi.mock(\"@internal/manager-api/data/AxiosManagerApiDataSource\");\nlet dataSource: Mocked<AxiosManagerApiDataSource>;\nlet service: ManagerApiService;\ndescribe(\"ManagerApiService\", () => {\n beforeEach(() => {\n dataSource = new AxiosManagerApiDataSource(\n {} as DmkConfig,\n ) as Mocked<AxiosManagerApiDataSource>;\n service = new DefaultManagerApiService(dataSource);\n });\n\n describe(\"getAppList\", () => {\n it(\"should call api with the correct parameters\", () => {\n // given\n const deviceInfo = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.STAX,\n );\n const provider = 42;\n // when\n service.getAppList(deviceInfo, provider);\n // then\n expect(dataSource.getAppList).toHaveBeenCalledWith({\n targetId: \"857735172\",\n provider: 42,\n firmwareVersionName: \"1.3.0\",\n });\n });\n });\n\n describe(\"getAppsByHash\", () => {\n describe(\"success cases\", () => {\n it(\"with no apps, should return an empty list\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(Right([]));\n expect(await service.getAppsByHash([])).toEqual(Right([]));\n });\n\n it(\"with one app, should return the metadata\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(Right([BTC_APP_METADATA]));\n expect(await service.getAppsByHash([BTC_APP.appFullHash])).toEqual(\n Right([BTC_APP_METADATA]),\n );\n });\n\n it(\"with two app, should return the metadata of both apps\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(\n Right([BTC_APP_METADATA, ETH_APP_METADATA]),\n );\n expect(\n await service.getAppsByHash(\n [BTC_APP, ETH_APP].map((app) => app.appFullHash),\n ),\n ).toEqual(Right([BTC_APP_METADATA, ETH_APP_METADATA]));\n });\n\n it(\"with one app and one without `appFullHash`, should return the metadata of the correct app\", async () => {\n dataSource.getAppsByHash.mockResolvedValue(Right([BTC_APP_METADATA]));\n const APP_WITH_NO_HASH = { ...ETH_APP, appFullHash: \"\" };\n expect(\n await service.getAppsByHash(\n [BTC_APP, APP_WITH_NO_HASH].map((app) => app.appFullHash),\n ),\n ).toEqual(Right([BTC_APP_METADATA]));\n });\n });\n\n describe(\"error cases\", () => {\n it(\"should return an error when the data source fails with a known error\", async () => {\n const error = new HttpFetchApiError(new Error(\"Failed to fetch data\"));\n dataSource.getAppsByHash.mockRejectedValue(error);\n expect(await service.getAppsByHash([BTC_APP.appFullHash])).toEqual(\n Left(error),\n );\n });\n\n it(\"should return an error when the data source fails with an unknown error\", async () => {\n const error = new Error(\"unkown error\");\n dataSource.getAppsByHash.mockRejectedValue(error);\n expect(await service.getAppsByHash([BTC_APP.appFullHash])).toEqual(\n Left(new HttpFetchApiError(error)),\n );\n });\n });\n });\n\n describe(\"getDeviceVersion\", () => {\n it(\"should call api with the correct parameters\", () => {\n // given\n const deviceInfo = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.STAX,\n );\n const provider = 42;\n // when\n service.getDeviceVersion(deviceInfo, provider);\n // then\n expect(dataSource.getDeviceVersion).toHaveBeenCalledWith({\n targetId: \"857735172\",\n provider: 42,\n });\n });\n });\n describe(\"getFirmwareVersion\", () => {\n it(\"should call api with the correct parameters\", () => {\n // given\n const mockGetDeviceVersion = {\n id: 17,\n target_id: \"857735172\",\n };\n const deviceInfo = getOsVersionCommandResponseMockBuilder(\n DeviceModelId.STAX,\n );\n const provider = 42;\n // when\n service.getFirmwareVersion(deviceInfo, mockGetDeviceVersion, provider);\n // then\n expect(dataSource.getFirmwareVersion).toHaveBeenCalledWith({\n deviceId: 17,\n provider: 42,\n version: \"1.3.0\",\n });\n });\n });\n});\n"],
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAG5B,OAAS,0CAAAC,MAA8C,gDACvD,OAAS,iBAAAC,MAAqB,0BAC9B,OACE,WAAAC,EACA,oBAAAC,EACA,WAAAC,EACA,oBAAAC,MACK,yCAEP,OAAS,6BAAAC,MAAiC,uDAC1C,OAAS,qBAAAC,MAAyB,qCAElC,OAAS,4BAAAC,MAAgC,6BAGzC,GAAG,KAAK,sDAAsD,EAC9D,IAAIC,EACAC,EACJ,SAAS,oBAAqB,IAAM,CAClC,WAAW,IAAM,CACfD,EAAa,IAAIH,EACf,CAAC,CACH,EACAI,EAAU,IAAIF,EAAyBC,CAAU,CACnD,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,GAAG,8CAA+C,IAAM,CAEtD,MAAME,EAAaX,EACjBC,EAAc,IAChB,EAGAS,EAAQ,WAAWC,EAFF,EAEsB,EAEvC,OAAOF,EAAW,UAAU,EAAE,qBAAqB,CACjD,SAAU,YACV,SAAU,GACV,oBAAq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AC,CAAC,EAAE,QACzDJ,EAAKgB,CAAK,CACZ,CACF,CAAC,EAED,GAAG,0EAA2E,SAAY,CACxF,MAAMA,EAAQ,IAAI,MAAM,cAAc,EACtCL,EAAW,cAAc,kBAAkBK,CAAK,EAChD,OAAO,MAAMJ,EAAQ,cAAc,CAACR,EAAQ,WAAW,CAAC,CAAC,EAAE,QACzDJ,EAAK,IAAIS,EAAkBO,CAAK,CAAC,CACnC,CACF,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,mBAAoB,IAAM,CACjC,GAAG,8CAA+C,IAAM,CAEtD,MAAMH,EAAaX,EACjBC,EAAc,IAChB,EAGAS,EAAQ,iBAAiBC,EAFR,EAE4B,EAE7C,OAAOF,EAAW,gBAAgB,EAAE,qBAAqB,CACvD,SAAU,YACV,SAAU,EACZ,CAAC,CACH,CAAC,CACH,CAAC,EACD,SAAS,qBAAsB,IAAM,CACnC,GAAG,8CAA+C,IAAM,CAEtD,MAAMM,EAAuB,CAC3B,GAAI,GACJ,UAAW,WACb,EACMJ,EAAaX,EACjBC,EAAc,IAChB,EAGAS,EAAQ,mBAAmBC,EAAYI,EAFtB,EAEoD,EAErE,OAAON,EAAW,kBAAkB,EAAE,qBAAqB,CACzD,SAAU,GACV,SAAU,GACV,QAAS,OACX,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
6
|
+
"names": ["Left", "Right", "getOsVersionCommandResponseMockBuilder", "DeviceModelId", "BTC_APP", "BTC_APP_METADATA", "ETH_APP", "ETH_APP_METADATA", "AxiosManagerApiDataSource", "HttpFetchApiError", "DefaultManagerApiService", "dataSource", "service", "deviceInfo", "app", "APP_WITH_NO_HASH", "error", "mockGetDeviceVersion"]
|
7
7
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* The user interaction required on the device to move further in a device action.
|
3
|
-
* This is used to inform the
|
3
|
+
* This is used to inform the users about the action they need to take on the device.
|
4
4
|
*/
|
5
5
|
export declare enum UserInteractionRequired {
|
6
6
|
None = "none",
|