@ledgerhq/device-management-kit 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.js.map +3 -3
- package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/cjs/src/api/DeviceManagementKit.test.js.map +2 -2
- package/lib/cjs/src/api/DmkConfig.js.map +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
- package/lib/cjs/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
- package/lib/cjs/src/api/device-session/use-case/DisableDeviceSessionRefresher.test.js +1 -1
- package/lib/cjs/src/api/device-session/use-case/DisableDeviceSessionRefresher.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
- package/lib/cjs/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/use-case/CloseSessionsUseCase.test.js +1 -1
- package/lib/cjs/src/internal/device-session/use-case/CloseSessionsUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js +1 -1
- package/lib/cjs/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/DisconnectUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js +1 -1
- package/lib/cjs/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/ManagerApiDataSource.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiModule.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/di/managerApiTypes.js +1 -1
- package/lib/cjs/src/internal/manager-api/di/managerApiTypes.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/cjs/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +2 -2
- package/lib/cjs/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.js +2 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.js.map +7 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.js +2 -0
- package/lib/cjs/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.js.map +7 -0
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/DeviceManagementKit.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.js.map +3 -3
- package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
- package/lib/esm/src/api/DeviceManagementKit.test.js.map +2 -2
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js +1 -1
- package/lib/esm/src/api/command/use-case/SendCommandUseCase.test.js.map +2 -2
- package/lib/esm/src/api/device-session/use-case/DisableDeviceSessionRefresher.test.js +1 -1
- package/lib/esm/src/api/device-session/use-case/DisableDeviceSessionRefresher.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js +1 -1
- package/lib/esm/src/internal/device-session/service/DefaultDeviceSessionService.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/use-case/CloseSessionsUseCase.test.js +1 -1
- package/lib/esm/src/internal/device-session/use-case/CloseSessionsUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js +1 -1
- package/lib/esm/src/internal/device-session/use-case/GetDeviceSessionStateUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/DisconnectUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js +1 -1
- package/lib/esm/src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js +1 -1
- package/lib/esm/src/internal/manager-api/data/HttpManagerApiDataSource.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.js +1 -1
- package/lib/esm/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.js.map +2 -2
- package/lib/esm/src/internal/manager-api/di/managerApiModule.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiModule.js.map +3 -3
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiModule.test.js.map +3 -3
- package/lib/esm/src/internal/manager-api/di/managerApiTypes.js +1 -1
- package/lib/esm/src/internal/manager-api/di/managerApiTypes.js.map +2 -2
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js +1 -1
- package/lib/esm/src/internal/manager-api/service/DefaultManagerApiService.test.js.map +2 -2
- package/lib/esm/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.js +2 -0
- package/lib/esm/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.js.map +7 -0
- package/lib/esm/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.js +2 -0
- package/lib/esm/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.js.map +7 -0
- package/lib/types/src/api/DeviceManagementKit.d.ts +16 -0
- package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
- package/lib/types/src/api/DmkConfig.d.ts +4 -0
- package/lib/types/src/api/DmkConfig.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts +5 -1
- package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts +11 -0
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.d.ts +2 -0
- package/lib/types/src/internal/manager-api/data/__mocks__/HttpManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/di/managerApiModule.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/di/managerApiTypes.d.ts +1 -0
- package/lib/types/src/internal/manager-api/di/managerApiTypes.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.d.ts +16 -0
- package/lib/types/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.d.ts.map +1 -0
- package/lib/types/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.d.ts +2 -0
- package/lib/types/src/internal/manager-api/use-case/SetFirmwareDistributionSaltUseCase.test.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("purify-ts"),D=require("../../../api/transport/model/__mocks__/TransportMock"),S=require("../../../api/transport/model/Errors"),y=require("../../../api/transport/model/TransportConnectedDevice.stub"),u=require("../../device-session/data/DeviceSessionRefresherConst"),v=require("../../device-session/model/DeviceSession.stub"),C=require("../../device-session/model/Errors"),h=require("../../device-session/service/DefaultDeviceSessionService"),w=require("../../logger-publisher/service/DefaultLoggerPublisherService"),g=require("../../manager-api/data/HttpManagerApiDataSource"),T=require("../../manager-api/service/DefaultManagerApiService"),k=require("../../secure-channel/data/DefaultSecureChannelDataSource"),A=require("../../secure-channel/service/DefaultSecureChannelService"),E=require("../../transport/service/DefaultTransportService"),a=require("./DisconnectUseCase");vi.mock("@internal/transport/service/DefaultTransportService");let e,p,s=[];const
|
|
1
|
+
"use strict";var t=require("purify-ts"),D=require("../../../api/transport/model/__mocks__/TransportMock"),S=require("../../../api/transport/model/Errors"),y=require("../../../api/transport/model/TransportConnectedDevice.stub"),u=require("../../device-session/data/DeviceSessionRefresherConst"),v=require("../../device-session/model/DeviceSession.stub"),C=require("../../device-session/model/Errors"),h=require("../../device-session/service/DefaultDeviceSessionService"),w=require("../../logger-publisher/service/DefaultLoggerPublisherService"),g=require("../../manager-api/data/HttpManagerApiDataSource"),T=require("../../manager-api/service/DefaultManagerApiService"),k=require("../../secure-channel/data/DefaultSecureChannelDataSource"),A=require("../../secure-channel/service/DefaultSecureChannelService"),E=require("../../transport/service/DefaultTransportService"),a=require("./DisconnectUseCase");vi.mock("@internal/transport/service/DefaultTransportService");let e,p,s=[];const r=vi.fn().mockReturnValue(new w.DefaultLoggerPublisherService([],"DisconnectUseCaseTest"));let c,m,f,d,l;const i="sessionId";describe("DisconnectUseCase",()=>{beforeAll(()=>{p=new D.TransportMock,s=[p],e=new h.DefaultDeviceSessionService(r),c=new E.DefaultTransportService,vi.spyOn(c,"getTransport").mockReturnValue(t.Maybe.of(p))}),it("should disconnect from a device",async()=>{const n=(0,y.connectedDeviceStubBuilder)();f=new g.HttpManagerApiDataSource({},r),m=new T.DefaultManagerApiService(f),d=new k.DefaultSecureChannelDataSource({}),l=new A.DefaultSecureChannelService(d);const o=(0,v.deviceSessionStubBuilder)({id:i,connectedDevice:n},r,m,l,u.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS);vi.spyOn(e,"getDeviceSessionById").mockImplementation(()=>(0,t.Right)(o)),vi.spyOn(o,"close"),vi.spyOn(e,"removeDeviceSession"),vi.spyOn(s[0],"disconnect").mockImplementation(()=>Promise.resolve((0,t.Right)(void 0))),await new a.DisconnectUseCase(c,e,r).execute({sessionId:i}),expect(o.close).toHaveBeenCalled(),expect(e.removeDeviceSession).toHaveBeenCalledWith(i),expect(s[0].disconnect).toHaveBeenCalledWith({connectedDevice:n})}),it("should throw an error when deviceSession not found",async()=>{const n=new a.DisconnectUseCase(c,e,r);try{await n.execute({sessionId:i})}catch(o){expect(o).toStrictEqual(new C.DeviceSessionNotFound)}}),it("should throw an error if usb hid disconnection fails",async()=>{vi.spyOn(e,"getDeviceSessionById").mockImplementation(()=>(0,t.Right)((0,v.deviceSessionStubBuilder)({id:i},r,m,l,u.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS))),vi.spyOn(s[0],"disconnect").mockResolvedValue((0,t.Left)(new S.DisconnectError));const n=new a.DisconnectUseCase(c,e,r);try{await n.execute({sessionId:i})}catch(o){expect(o).toStrictEqual(new S.DisconnectError)}})});
|
|
2
2
|
//# sourceMappingURL=DisconnectUseCase.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/DisconnectUseCase.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Maybe, Right } from \"purify-ts\";\n\nimport { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { DisconnectError } from \"@api/transport/model/Errors\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport type { DmkConfig, Transport } from \"@api/types\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { DefaultTransportService } from \"@internal/transport/service/DefaultTransportService\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nimport { DisconnectUseCase } from \"./DisconnectUseCase\";\n\nvi.mock(\"@internal/transport/service/DefaultTransportService\");\n\nlet sessionService: DefaultDeviceSessionService;\n// TODO test several transports\nlet transport: Transport;\nlet transports: Transport[] = [];\nconst loggerFactory = vi\n .fn()\n .mockReturnValue(\n new DefaultLoggerPublisherService([], \"DisconnectUseCaseTest\"),\n );\nlet transportService: TransportService;\nlet managerApi: ManagerApiService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst sessionId = \"sessionId\";\n\ndescribe(\"DisconnectUseCase\", () => {\n beforeAll(() => {\n transport = new TransportMock();\n transports = [transport];\n sessionService = new DefaultDeviceSessionService(loggerFactory);\n // @ts-expect-error mock\n transportService = new DefaultTransportService();\n vi.spyOn(transportService, \"getTransport\").mockReturnValue(\n Maybe.of(transport),\n );\n });\n\n it(\"should disconnect from a device\", async () => {\n // Given\n const connectedDevice = connectedDeviceStubBuilder();\n managerApiDataSource = new HttpManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n const deviceSession = deviceSessionStubBuilder(\n {\n id: sessionId,\n connectedDevice,\n },\n loggerFactory,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n vi.spyOn(sessionService, \"getDeviceSessionById\").mockImplementation(() =>\n Right(deviceSession),\n );\n vi.spyOn(deviceSession, \"close\");\n vi.spyOn(sessionService, \"removeDeviceSession\");\n vi.spyOn(transports[0]!, \"disconnect\").mockImplementation(() =>\n Promise.resolve(Right(undefined)),\n );\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n // When\n await disconnectUseCase.execute({ sessionId });\n\n // Then\n expect(deviceSession.close).toHaveBeenCalled();\n expect(sessionService.removeDeviceSession).toHaveBeenCalledWith(sessionId);\n expect(transports[0]!.disconnect).toHaveBeenCalledWith({\n connectedDevice,\n });\n });\n\n it(\"should throw an error when deviceSession not found\", async () => {\n // Given\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n\n // When\n try {\n await disconnectUseCase.execute({ sessionId });\n } catch (e) {\n // Then\n expect(e).toStrictEqual(new DeviceSessionNotFound());\n }\n });\n\n it(\"should throw an error if usb hid disconnection fails\", async () => {\n // Given\n vi.spyOn(sessionService, \"getDeviceSessionById\").mockImplementation(() =>\n Right(\n deviceSessionStubBuilder(\n { id: sessionId },\n loggerFactory,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ),\n ),\n );\n\n vi.spyOn(transports[0]!, \"disconnect\").mockResolvedValue(\n Left(new DisconnectError()),\n );\n\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n\n // When\n try {\n await disconnectUseCase.execute({ sessionId });\n } catch (e) {\n // Then\n expect(e).toStrictEqual(new DisconnectError());\n }\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,EAAmC,qBAEnCC,EAA8B,wDAC9BC,EAAgC,uCAChCC,EAA2C,8DAE3CC,EAAyD,qEACzDC,EAAyC,6DACzCH,EAAsC,iDACtCI,EAA4C,wEAC5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAE5CC,EAAwC,+DAGxCC,EAAkC,+BAElC,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EAEAC,EACAC,EAA0B,CAAC,EAC/B,MAAMC,EAAgB,GACnB,GAAG,EACH,gBACC,IAAI,gCAA8B,CAAC,EAAG,uBAAuB,CAC/D,EACF,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAY,YAElB,SAAS,oBAAqB,IAAM,CAClC,UAAU,IAAM,CACdR,EAAY,IAAI,gBAChBC,EAAa,CAACD,CAAS,EACvBD,EAAiB,IAAI,8BAA4BG,CAAa,EAE9DC,EAAmB,IAAI,0BACvB,GAAG,MAAMA,EAAkB,cAAc,EAAE,gBACzC,QAAM,GAAGH,CAAS,CACpB,CACF,CAAC,EAED,GAAG,kCAAmC,SAAY,CAEhD,MAAMS,KAAkB,8BAA2B,EACnDJ,EAAuB,IAAI,
|
|
4
|
+
"sourcesContent": ["import { Left, Maybe, Right } from \"purify-ts\";\n\nimport { TransportMock } from \"@api/transport/model/__mocks__/TransportMock\";\nimport { DisconnectError } from \"@api/transport/model/Errors\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport type { DmkConfig, Transport } from \"@api/types\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DeviceSessionNotFound } from \"@internal/device-session/model/Errors\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { DefaultTransportService } from \"@internal/transport/service/DefaultTransportService\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\n\nimport { DisconnectUseCase } from \"./DisconnectUseCase\";\n\nvi.mock(\"@internal/transport/service/DefaultTransportService\");\n\nlet sessionService: DefaultDeviceSessionService;\n// TODO test several transports\nlet transport: Transport;\nlet transports: Transport[] = [];\nconst loggerFactory = vi\n .fn()\n .mockReturnValue(\n new DefaultLoggerPublisherService([], \"DisconnectUseCaseTest\"),\n );\nlet transportService: TransportService;\nlet managerApi: ManagerApiService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst sessionId = \"sessionId\";\n\ndescribe(\"DisconnectUseCase\", () => {\n beforeAll(() => {\n transport = new TransportMock();\n transports = [transport];\n sessionService = new DefaultDeviceSessionService(loggerFactory);\n // @ts-expect-error mock\n transportService = new DefaultTransportService();\n vi.spyOn(transportService, \"getTransport\").mockReturnValue(\n Maybe.of(transport),\n );\n });\n\n it(\"should disconnect from a device\", async () => {\n // Given\n const connectedDevice = connectedDeviceStubBuilder();\n managerApiDataSource = new HttpManagerApiDataSource(\n {} as DmkConfig,\n loggerFactory,\n );\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n const deviceSession = deviceSessionStubBuilder(\n {\n id: sessionId,\n connectedDevice,\n },\n loggerFactory,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n vi.spyOn(sessionService, \"getDeviceSessionById\").mockImplementation(() =>\n Right(deviceSession),\n );\n vi.spyOn(deviceSession, \"close\");\n vi.spyOn(sessionService, \"removeDeviceSession\");\n vi.spyOn(transports[0]!, \"disconnect\").mockImplementation(() =>\n Promise.resolve(Right(undefined)),\n );\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n // When\n await disconnectUseCase.execute({ sessionId });\n\n // Then\n expect(deviceSession.close).toHaveBeenCalled();\n expect(sessionService.removeDeviceSession).toHaveBeenCalledWith(sessionId);\n expect(transports[0]!.disconnect).toHaveBeenCalledWith({\n connectedDevice,\n });\n });\n\n it(\"should throw an error when deviceSession not found\", async () => {\n // Given\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n\n // When\n try {\n await disconnectUseCase.execute({ sessionId });\n } catch (e) {\n // Then\n expect(e).toStrictEqual(new DeviceSessionNotFound());\n }\n });\n\n it(\"should throw an error if usb hid disconnection fails\", async () => {\n // Given\n vi.spyOn(sessionService, \"getDeviceSessionById\").mockImplementation(() =>\n Right(\n deviceSessionStubBuilder(\n { id: sessionId },\n loggerFactory,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n ),\n ),\n );\n\n vi.spyOn(transports[0]!, \"disconnect\").mockResolvedValue(\n Left(new DisconnectError()),\n );\n\n const disconnectUseCase = new DisconnectUseCase(\n transportService,\n sessionService,\n loggerFactory,\n );\n\n // When\n try {\n await disconnectUseCase.execute({ sessionId });\n } catch (e) {\n // Then\n expect(e).toStrictEqual(new DisconnectError());\n }\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAAmC,qBAEnCC,EAA8B,wDAC9BC,EAAgC,uCAChCC,EAA2C,8DAE3CC,EAAyD,qEACzDC,EAAyC,6DACzCH,EAAsC,iDACtCI,EAA4C,wEAC5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAE5CC,EAAwC,+DAGxCC,EAAkC,+BAElC,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EAEAC,EACAC,EAA0B,CAAC,EAC/B,MAAMC,EAAgB,GACnB,GAAG,EACH,gBACC,IAAI,gCAA8B,CAAC,EAAG,uBAAuB,CAC/D,EACF,IAAIC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAY,YAElB,SAAS,oBAAqB,IAAM,CAClC,UAAU,IAAM,CACdR,EAAY,IAAI,gBAChBC,EAAa,CAACD,CAAS,EACvBD,EAAiB,IAAI,8BAA4BG,CAAa,EAE9DC,EAAmB,IAAI,0BACvB,GAAG,MAAMA,EAAkB,cAAc,EAAE,gBACzC,QAAM,GAAGH,CAAS,CACpB,CACF,CAAC,EAED,GAAG,kCAAmC,SAAY,CAEhD,MAAMS,KAAkB,8BAA2B,EACnDJ,EAAuB,IAAI,2BACzB,CAAC,EACDH,CACF,EACAE,EAAa,IAAI,2BAAyBC,CAAoB,EAC9DC,EAA0B,IAAI,iCAC5B,CAAC,CACH,EACAC,EAAgB,IAAI,8BAA4BD,CAAuB,EACvE,MAAMI,KAAgB,4BACpB,CACE,GAAIF,EACJ,gBAAAC,CACF,EACAP,EACAE,EACAG,EACA,0CACF,EACA,GAAG,MAAMR,EAAgB,sBAAsB,EAAE,mBAAmB,OAClE,SAAMW,CAAa,CACrB,EACA,GAAG,MAAMA,EAAe,OAAO,EAC/B,GAAG,MAAMX,EAAgB,qBAAqB,EAC9C,GAAG,MAAME,EAAW,CAAC,EAAI,YAAY,EAAE,mBAAmB,IACxD,QAAQ,WAAQ,SAAM,MAAS,CAAC,CAClC,EAOA,MAN0B,IAAI,oBAC5BE,EACAJ,EACAG,CACF,EAEwB,QAAQ,CAAE,UAAAM,CAAU,CAAC,EAG7C,OAAOE,EAAc,KAAK,EAAE,iBAAiB,EAC7C,OAAOX,EAAe,mBAAmB,EAAE,qBAAqBS,CAAS,EACzE,OAAOP,EAAW,CAAC,EAAG,UAAU,EAAE,qBAAqB,CACrD,gBAAAQ,CACF,CAAC,CACH,CAAC,EAED,GAAG,qDAAsD,SAAY,CAEnE,MAAME,EAAoB,IAAI,oBAC5BR,EACAJ,EACAG,CACF,EAGA,GAAI,CACF,MAAMS,EAAkB,QAAQ,CAAE,UAAAH,CAAU,CAAC,CAC/C,OAASI,EAAG,CAEV,OAAOA,CAAC,EAAE,cAAc,IAAI,uBAAuB,CACrD,CACF,CAAC,EAED,GAAG,uDAAwD,SAAY,CAErE,GAAG,MAAMb,EAAgB,sBAAsB,EAAE,mBAAmB,OAClE,YACE,4BACE,CAAE,GAAIS,CAAU,EAChBN,EACAE,EACAG,EACA,0CACF,CACF,CACF,EAEA,GAAG,MAAMN,EAAW,CAAC,EAAI,YAAY,EAAE,qBACrC,QAAK,IAAI,iBAAiB,CAC5B,EAEA,MAAMU,EAAoB,IAAI,oBAC5BR,EACAJ,EACAG,CACF,EAGA,GAAI,CACF,MAAMS,EAAkB,QAAQ,CAAE,UAAAH,CAAU,CAAC,CAC/C,OAASI,EAAG,CAEV,OAAOA,CAAC,EAAE,cAAc,IAAI,iBAAiB,CAC/C,CACF,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_purify_ts", "import_TransportMock", "import_Errors", "import_TransportConnectedDevice", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_DefaultDeviceSessionService", "import_DefaultLoggerPublisherService", "import_HttpManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "import_DefaultTransportService", "import_DisconnectUseCase", "sessionService", "transport", "transports", "loggerFactory", "transportService", "managerApi", "managerApiDataSource", "secureChannelDataSource", "secureChannel", "sessionId", "connectedDevice", "deviceSession", "disconnectUseCase", "e"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var a=require("../../../api/transport/model/ConnectedDevice"),s=require("../../device-session/data/DeviceSessionRefresherConst"),S=require("../../device-session/model/DeviceSession.stub"),v=require("../../device-session/service/DefaultDeviceSessionService"),f=require("../../logger-publisher/service/DefaultLoggerPublisherService"),l=require("../../manager-api/data/HttpManagerApiDataSource"),D=require("../../manager-api/service/DefaultManagerApiService"),d=require("../../secure-channel/data/DefaultSecureChannelDataSource"),g=require("../../secure-channel/service/DefaultSecureChannelService"),m=require("./GetConnectedDeviceUseCase");vi.mock("@internal/manager-api/data/HttpManagerApiDataSource");let
|
|
1
|
+
"use strict";var a=require("../../../api/transport/model/ConnectedDevice"),s=require("../../device-session/data/DeviceSessionRefresherConst"),S=require("../../device-session/model/DeviceSession.stub"),v=require("../../device-session/service/DefaultDeviceSessionService"),f=require("../../logger-publisher/service/DefaultLoggerPublisherService"),l=require("../../manager-api/data/HttpManagerApiDataSource"),D=require("../../manager-api/service/DefaultManagerApiService"),d=require("../../secure-channel/data/DefaultSecureChannelDataSource"),g=require("../../secure-channel/service/DefaultSecureChannelService"),m=require("./GetConnectedDeviceUseCase");vi.mock("@internal/manager-api/data/HttpManagerApiDataSource");let e,o,p,n,u,c;const i="fakeSessionId";describe("GetConnectedDevice",()=>{beforeEach(()=>{e=new f.DefaultLoggerPublisherService([],"get-connected-device-use-case"),p=new l.HttpManagerApiDataSource({},()=>e),n=new D.DefaultManagerApiService(p),u=new d.DefaultSecureChannelDataSource({}),c=new g.DefaultSecureChannelService(u),o=new v.DefaultDeviceSessionService(()=>e)}),it("should retrieve an instance of ConnectedDevice",()=>{const r=(0,S.deviceSessionStubBuilder)({id:i},()=>e,n,c,s.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS);o.addDeviceSession(r);const t=new m.GetConnectedDeviceUseCase(o,()=>e).execute({sessionId:i});r.close(),expect(t).toBeInstanceOf(a.ConnectedDevice)}),it("should retrieve correct device from session",()=>{const r=(0,S.deviceSessionStubBuilder)({id:i},()=>e,n,c,s.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS);o.addDeviceSession(r);const t=new m.GetConnectedDeviceUseCase(o,()=>e).execute({sessionId:i});r.close(),expect(t).toStrictEqual(new a.ConnectedDevice({sessionId:i,transportConnectedDevice:r.connectedDevice}))})});
|
|
2
2
|
//# sourceMappingURL=GetConnectedDeviceUseCase.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/GetConnectedDeviceUseCase.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { GetConnectedDeviceUseCase } from \"./GetConnectedDeviceUseCase\";\n\nvi.mock(\"@internal/manager-api/data/HttpManagerApiDataSource\");\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst fakeSessionId = \"fakeSessionId\";\n\ndescribe(\"GetConnectedDevice\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"get-connected-device-use-case\",\n );\n managerApiDataSource = new HttpManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should retrieve an instance of ConnectedDevice\", () => {\n // given\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession);\n const useCase = new GetConnectedDeviceUseCase(sessionService, () => logger);\n\n // when\n const response = useCase.execute({\n sessionId: fakeSessionId,\n });\n\n deviceSession.close();\n\n // then\n expect(response).toBeInstanceOf(ConnectedDevice);\n });\n\n it(\"should retrieve correct device from session\", () => {\n // given\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession);\n const useCase = new GetConnectedDeviceUseCase(sessionService, () => logger);\n\n // when\n const response = useCase.execute({\n sessionId: fakeSessionId,\n });\n\n deviceSession.close();\n\n // then\n expect(response).toStrictEqual(\n new ConnectedDevice({\n sessionId: fakeSessionId,\n transportConnectedDevice: deviceSession.connectedDevice,\n }),\n );\n });\n});\n"],
|
|
5
|
-
"mappings": "aAEA,IAAAA,EAAgC,gDAChCC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAG5CC,EAA0C,uCAE1C,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAgB,gBAEtB,SAAS,qBAAsB,IAAM,CACnC,WAAW,IAAM,CACfN,EAAS,IAAI,gCACX,CAAC,EACD,+BACF,EACAE,EAAuB,IAAI,
|
|
4
|
+
"sourcesContent": ["import { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nimport { GetConnectedDeviceUseCase } from \"./GetConnectedDeviceUseCase\";\n\nvi.mock(\"@internal/manager-api/data/HttpManagerApiDataSource\");\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst fakeSessionId = \"fakeSessionId\";\n\ndescribe(\"GetConnectedDevice\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"get-connected-device-use-case\",\n );\n managerApiDataSource = new HttpManagerApiDataSource(\n {} as DmkConfig,\n () => logger,\n );\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should retrieve an instance of ConnectedDevice\", () => {\n // given\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession);\n const useCase = new GetConnectedDeviceUseCase(sessionService, () => logger);\n\n // when\n const response = useCase.execute({\n sessionId: fakeSessionId,\n });\n\n deviceSession.close();\n\n // then\n expect(response).toBeInstanceOf(ConnectedDevice);\n });\n\n it(\"should retrieve correct device from session\", () => {\n // given\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession);\n const useCase = new GetConnectedDeviceUseCase(sessionService, () => logger);\n\n // when\n const response = useCase.execute({\n sessionId: fakeSessionId,\n });\n\n deviceSession.close();\n\n // then\n expect(response).toStrictEqual(\n new ConnectedDevice({\n sessionId: fakeSessionId,\n transportConnectedDevice: deviceSession.connectedDevice,\n }),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "aAEA,IAAAA,EAAgC,gDAChCC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAG5CC,EAA0C,uCAE1C,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAgB,gBAEtB,SAAS,qBAAsB,IAAM,CACnC,WAAW,IAAM,CACfN,EAAS,IAAI,gCACX,CAAC,EACD,+BACF,EACAE,EAAuB,IAAI,2BACzB,CAAC,EACD,IAAMF,CACR,EACAG,EAAa,IAAI,2BAAyBD,CAAoB,EAC9DE,EAA0B,IAAI,iCAC5B,CAAC,CACH,EACAC,EAAgB,IAAI,8BAA4BD,CAAuB,EACvEH,EAAiB,IAAI,8BAA4B,IAAMD,CAAM,CAC/D,CAAC,EAED,GAAG,iDAAkD,IAAM,CAEzD,MAAMO,KAAgB,4BACpB,CAAE,GAAID,CAAc,EACpB,IAAMN,EACNG,EACAE,EACA,0CACF,EACAJ,EAAe,iBAAiBM,CAAa,EAI7C,MAAMC,EAHU,IAAI,4BAA0BP,EAAgB,IAAMD,CAAM,EAGjD,QAAQ,CAC/B,UAAWM,CACb,CAAC,EAEDC,EAAc,MAAM,EAGpB,OAAOC,CAAQ,EAAE,eAAe,iBAAe,CACjD,CAAC,EAED,GAAG,8CAA+C,IAAM,CAEtD,MAAMD,KAAgB,4BACpB,CAAE,GAAID,CAAc,EACpB,IAAMN,EACNG,EACAE,EACA,0CACF,EACAJ,EAAe,iBAAiBM,CAAa,EAI7C,MAAMC,EAHU,IAAI,4BAA0BP,EAAgB,IAAMD,CAAM,EAGjD,QAAQ,CAC/B,UAAWM,CACb,CAAC,EAEDC,EAAc,MAAM,EAGpB,OAAOC,CAAQ,EAAE,cACf,IAAI,kBAAgB,CAClB,UAAWF,EACX,yBAA0BC,EAAc,eAC1C,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_ConnectedDevice", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_DefaultDeviceSessionService", "import_DefaultLoggerPublisherService", "import_HttpManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "import_GetConnectedDeviceUseCase", "logger", "sessionService", "managerApiDataSource", "managerApi", "secureChannelDataSource", "secureChannel", "fakeSessionId", "deviceSession", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var n=require("../../../api/transport/model/ConnectedDevice"),c=require("../../device-session/data/DeviceSessionRefresherConst"),a=require("../../device-session/model/DeviceSession.stub"),u=require("../../device-session/service/DefaultDeviceSessionService"),S=require("../../discovery/use-case/ListConnectedDevicesUseCase"),l=require("../../logger-publisher/service/DefaultLoggerPublisherService"),v=require("../../manager-api/data/HttpManagerApiDataSource"),D=require("../../manager-api/service/DefaultManagerApiService"),f=require("../../secure-channel/data/DefaultSecureChannelDataSource"),d=require("../../secure-channel/service/DefaultSecureChannelService");let
|
|
1
|
+
"use strict";var n=require("../../../api/transport/model/ConnectedDevice"),c=require("../../device-session/data/DeviceSessionRefresherConst"),a=require("../../device-session/model/DeviceSession.stub"),u=require("../../device-session/service/DefaultDeviceSessionService"),S=require("../../discovery/use-case/ListConnectedDevicesUseCase"),l=require("../../logger-publisher/service/DefaultLoggerPublisherService"),v=require("../../manager-api/data/HttpManagerApiDataSource"),D=require("../../manager-api/service/DefaultManagerApiService"),f=require("../../secure-channel/data/DefaultSecureChannelDataSource"),d=require("../../secure-channel/service/DefaultSecureChannelService");let e,o,m,s,p,t;describe("ListDeviceSessionsUseCase",()=>{beforeEach(()=>{e=new l.DefaultLoggerPublisherService([],"list-device-sessions-use-case-test"),m=new v.HttpManagerApiDataSource({},()=>e),s=new D.DefaultManagerApiService(m),p=new f.DefaultSecureChannelDataSource({}),t=new d.DefaultSecureChannelService(p),o=new u.DefaultDeviceSessionService(()=>e)}),it("should list all device sessions",()=>{const i=(0,a.deviceSessionStubBuilder)({id:"1"},()=>e,s,t,c.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),r=(0,a.deviceSessionStubBuilder)({id:"2"},()=>e,s,t,c.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS);o.addDeviceSession(i),o.addDeviceSession(r);const C=new S.ListConnectedDevicesUseCase(o,()=>e).execute();i.close(),r.close(),expect(C).toStrictEqual([new n.ConnectedDevice({transportConnectedDevice:i.connectedDevice,sessionId:i.id}),new n.ConnectedDevice({transportConnectedDevice:r.connectedDevice,sessionId:r.id})])}),it("should return empty array if no device sessions",()=>{const r=new S.ListConnectedDevicesUseCase(o,()=>e).execute();expect(r).toStrictEqual([])})});
|
|
2
2
|
//# sourceMappingURL=ListConnectedDevicesUseCase.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/ListConnectedDevicesUseCase.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { type DmkConfig } from \"@root/src\";\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\ndescribe(\"ListDeviceSessionsUseCase\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"list-device-sessions-use-case-test\",\n );\n managerApiDataSource = new HttpManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should list all device sessions\", () => {\n // given\n const deviceSession1 = deviceSessionStubBuilder(\n { id: \"1\" },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const deviceSession2 = deviceSessionStubBuilder(\n { id: \"2\" },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession1);\n sessionService.addDeviceSession(deviceSession2);\n const useCase = new ListConnectedDevicesUseCase(\n sessionService,\n () => logger,\n );\n\n // when\n const response = useCase.execute();\n\n deviceSession1.close();\n deviceSession2.close();\n\n // then\n expect(response).toStrictEqual([\n new ConnectedDevice({\n transportConnectedDevice: deviceSession1.connectedDevice,\n sessionId: deviceSession1.id,\n }),\n new ConnectedDevice({\n transportConnectedDevice: deviceSession2.connectedDevice,\n sessionId: deviceSession2.id,\n }),\n ]);\n });\n\n it(\"should return empty array if no device sessions\", () => {\n // given\n const useCase = new ListConnectedDevicesUseCase(\n sessionService,\n () => logger,\n );\n\n // when\n const response = useCase.execute();\n\n // then\n expect(response).toStrictEqual([]);\n });\n});\n"],
|
|
5
|
-
"mappings": "aACA,IAAAA,EAAgC,gDAChCC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA4C,oEAC5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAI5C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,SAAS,4BAA6B,IAAM,CAC1C,WAAW,IAAM,CACfL,EAAS,IAAI,gCACX,CAAC,EACD,oCACF,EACAE,EAAuB,IAAI,
|
|
4
|
+
"sourcesContent": ["import { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\nimport { type DmkConfig } from \"@root/src\";\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\ndescribe(\"ListDeviceSessionsUseCase\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"list-device-sessions-use-case-test\",\n );\n managerApiDataSource = new HttpManagerApiDataSource(\n {} as DmkConfig,\n () => logger,\n );\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should list all device sessions\", () => {\n // given\n const deviceSession1 = deviceSessionStubBuilder(\n { id: \"1\" },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const deviceSession2 = deviceSessionStubBuilder(\n { id: \"2\" },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n sessionService.addDeviceSession(deviceSession1);\n sessionService.addDeviceSession(deviceSession2);\n const useCase = new ListConnectedDevicesUseCase(\n sessionService,\n () => logger,\n );\n\n // when\n const response = useCase.execute();\n\n deviceSession1.close();\n deviceSession2.close();\n\n // then\n expect(response).toStrictEqual([\n new ConnectedDevice({\n transportConnectedDevice: deviceSession1.connectedDevice,\n sessionId: deviceSession1.id,\n }),\n new ConnectedDevice({\n transportConnectedDevice: deviceSession2.connectedDevice,\n sessionId: deviceSession2.id,\n }),\n ]);\n });\n\n it(\"should return empty array if no device sessions\", () => {\n // given\n const useCase = new ListConnectedDevicesUseCase(\n sessionService,\n () => logger,\n );\n\n // when\n const response = useCase.execute();\n\n // then\n expect(response).toStrictEqual([]);\n });\n});\n"],
|
|
5
|
+
"mappings": "aACA,IAAAA,EAAgC,gDAChCC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA4C,oEAC5CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAI5C,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,SAAS,4BAA6B,IAAM,CAC1C,WAAW,IAAM,CACfL,EAAS,IAAI,gCACX,CAAC,EACD,oCACF,EACAE,EAAuB,IAAI,2BACzB,CAAC,EACD,IAAMF,CACR,EACAG,EAAa,IAAI,2BAAyBD,CAAoB,EAC9DE,EAA0B,IAAI,iCAC5B,CAAC,CACH,EACAC,EAAgB,IAAI,8BAA4BD,CAAuB,EACvEH,EAAiB,IAAI,8BAA4B,IAAMD,CAAM,CAC/D,CAAC,EAED,GAAG,kCAAmC,IAAM,CAE1C,MAAMM,KAAiB,4BACrB,CAAE,GAAI,GAAI,EACV,IAAMN,EACNG,EACAE,EACA,0CACF,EACME,KAAiB,4BACrB,CAAE,GAAI,GAAI,EACV,IAAMP,EACNG,EACAE,EACA,0CACF,EACAJ,EAAe,iBAAiBK,CAAc,EAC9CL,EAAe,iBAAiBM,CAAc,EAO9C,MAAMC,EANU,IAAI,8BAClBP,EACA,IAAMD,CACR,EAGyB,QAAQ,EAEjCM,EAAe,MAAM,EACrBC,EAAe,MAAM,EAGrB,OAAOC,CAAQ,EAAE,cAAc,CAC7B,IAAI,kBAAgB,CAClB,yBAA0BF,EAAe,gBACzC,UAAWA,EAAe,EAC5B,CAAC,EACD,IAAI,kBAAgB,CAClB,yBAA0BC,EAAe,gBACzC,UAAWA,EAAe,EAC5B,CAAC,CACH,CAAC,CACH,CAAC,EAED,GAAG,kDAAmD,IAAM,CAQ1D,MAAMC,EANU,IAAI,8BAClBP,EACA,IAAMD,CACR,EAGyB,QAAQ,EAGjC,OAAOQ,CAAQ,EAAE,cAAc,CAAC,CAAC,CACnC,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_ConnectedDevice", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_DefaultDeviceSessionService", "import_ListConnectedDevicesUseCase", "import_DefaultLoggerPublisherService", "import_HttpManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "logger", "sessionService", "managerApiDataSource", "managerApi", "secureChannelDataSource", "secureChannel", "deviceSession1", "deviceSession2", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var m=require("../../../api/transport/model/ConnectedDevice"),S=require("../../../api/transport/model/TransportConnectedDevice.stub"),p=require("../../device-session/data/DeviceSessionRefresherConst"),u=require("../../device-session/model/DeviceSession.stub"),l=require("../../device-session/service/DefaultDeviceSessionService"),v=require("../../discovery/use-case/ListenToConnectedDeviceUseCase"),f=require("../../logger-publisher/service/DefaultLoggerPublisherService"),D=require("../../manager-api/data/HttpManagerApiDataSource"),d=require("../../manager-api/service/DefaultManagerApiService"),g=require("../../secure-channel/data/DefaultSecureChannelDataSource"),C=require("../../secure-channel/service/DefaultSecureChannelService");vi.mock("@internal/manager-api/data/HttpManagerApiDataSource");let e,r,t,n,c,a;const s="test-list-connected-device-session-id";describe("ListenToConnectedDevice",()=>{beforeEach(()=>{e=new f.DefaultLoggerPublisherService([],"listen-to-connected-device-use-case"),t=new D.HttpManagerApiDataSource({}),n=new d.DefaultManagerApiService(t),c=new g.DefaultSecureChannelDataSource({}),a=new C.DefaultSecureChannelService(c),r=new l.DefaultDeviceSessionService(()=>e)}),it("should emit an instance of ConnectedDevice",()=>new Promise((b,h)=>{const i=(0,S.connectedDeviceStubBuilder)({id:"test-list-connected-device-id"}),o=(0,u.deviceSessionStubBuilder)({id:s,connectedDevice:i},()=>e,n,a,p.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),A=new v.ListenToConnectedDeviceUseCase(r,()=>e).execute().subscribe({next(E){try{expect(E).toEqual(new m.ConnectedDevice({transportConnectedDevice:i,sessionId:s})),w()}catch(y){h(y)}}});function w(){A.unsubscribe(),o.close(),b()}r.addDeviceSession(o)}))});
|
|
1
|
+
"use strict";var m=require("../../../api/transport/model/ConnectedDevice"),S=require("../../../api/transport/model/TransportConnectedDevice.stub"),p=require("../../device-session/data/DeviceSessionRefresherConst"),u=require("../../device-session/model/DeviceSession.stub"),l=require("../../device-session/service/DefaultDeviceSessionService"),v=require("../../discovery/use-case/ListenToConnectedDeviceUseCase"),f=require("../../logger-publisher/service/DefaultLoggerPublisherService"),D=require("../../manager-api/data/HttpManagerApiDataSource"),d=require("../../manager-api/service/DefaultManagerApiService"),g=require("../../secure-channel/data/DefaultSecureChannelDataSource"),C=require("../../secure-channel/service/DefaultSecureChannelService");vi.mock("@internal/manager-api/data/HttpManagerApiDataSource");let e,r,t,n,c,a;const s="test-list-connected-device-session-id";describe("ListenToConnectedDevice",()=>{beforeEach(()=>{e=new f.DefaultLoggerPublisherService([],"listen-to-connected-device-use-case"),t=new D.HttpManagerApiDataSource({},()=>e),n=new d.DefaultManagerApiService(t),c=new g.DefaultSecureChannelDataSource({}),a=new C.DefaultSecureChannelService(c),r=new l.DefaultDeviceSessionService(()=>e)}),it("should emit an instance of ConnectedDevice",()=>new Promise((b,h)=>{const i=(0,S.connectedDeviceStubBuilder)({id:"test-list-connected-device-id"}),o=(0,u.deviceSessionStubBuilder)({id:s,connectedDevice:i},()=>e,n,a,p.DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS),A=new v.ListenToConnectedDeviceUseCase(r,()=>e).execute().subscribe({next(E){try{expect(E).toEqual(new m.ConnectedDevice({transportConnectedDevice:i,sessionId:s})),w()}catch(y){h(y)}}});function w(){A.unsubscribe(),o.close(),b()}r.addDeviceSession(o)}))});
|
|
2
2
|
//# sourceMappingURL=ListenToConnectedDeviceUseCase.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/discovery/use-case/ListenToConnectedDeviceUseCase.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nvi.mock(\"@internal/manager-api/data/HttpManagerApiDataSource\");\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst fakeSessionId = \"test-list-connected-device-session-id\";\n\ndescribe(\"ListenToConnectedDevice\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"listen-to-connected-device-use-case\",\n );\n managerApiDataSource = new HttpManagerApiDataSource({} as DmkConfig);\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should emit an instance of ConnectedDevice\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const connectedDevice = connectedDeviceStubBuilder({\n id: \"test-list-connected-device-id\",\n });\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId, connectedDevice },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const observable = new ListenToConnectedDeviceUseCase(\n sessionService,\n () => logger,\n ).execute();\n\n const subscription = observable.subscribe({\n next(emittedConnectedDevice) {\n // then\n try {\n expect(emittedConnectedDevice).toEqual(\n new ConnectedDevice({\n transportConnectedDevice: connectedDevice,\n sessionId: fakeSessionId,\n }),\n );\n terminate();\n } catch (error) {\n reject(error);\n }\n },\n });\n\n function terminate() {\n subscription.unsubscribe();\n deviceSession.close();\n resolve();\n }\n\n // when\n sessionService.addDeviceSession(deviceSession);\n }));\n});\n"],
|
|
5
|
-
"mappings": "aAEA,IAAAA,EAAgC,gDAChCC,EAA2C,8DAC3CC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA+C,uEAC/CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAG5C,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAgB,wCAEtB,SAAS,0BAA2B,IAAM,CACxC,WAAW,IAAM,CACfN,EAAS,IAAI,gCACX,CAAC,EACD,qCACF,EACAE,EAAuB,IAAI,
|
|
4
|
+
"sourcesContent": ["import { type DmkConfig } from \"@api/DmkConfig\";\nimport { type LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport { connectedDeviceStubBuilder } from \"@api/transport/model/TransportConnectedDevice.stub\";\nimport { DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS } from \"@internal/device-session/data/DeviceSessionRefresherConst\";\nimport { deviceSessionStubBuilder } from \"@internal/device-session/model/DeviceSession.stub\";\nimport { DefaultDeviceSessionService } from \"@internal/device-session/service/DefaultDeviceSessionService\";\nimport { type DeviceSessionService } from \"@internal/device-session/service/DeviceSessionService\";\nimport { ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\nimport { HttpManagerApiDataSource } from \"@internal/manager-api/data/HttpManagerApiDataSource\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { DefaultManagerApiService } from \"@internal/manager-api/service/DefaultManagerApiService\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\nimport { DefaultSecureChannelDataSource } from \"@internal/secure-channel/data/DefaultSecureChannelDataSource\";\nimport { type SecureChannelDataSource } from \"@internal/secure-channel/data/SecureChannelDataSource\";\nimport { DefaultSecureChannelService } from \"@internal/secure-channel/service/DefaultSecureChannelService\";\nimport { type SecureChannelService } from \"@internal/secure-channel/service/SecureChannelService\";\n\nvi.mock(\"@internal/manager-api/data/HttpManagerApiDataSource\");\n\nlet logger: LoggerPublisherService;\nlet sessionService: DeviceSessionService;\nlet managerApiDataSource: ManagerApiDataSource;\nlet managerApi: ManagerApiService;\nlet secureChannelDataSource: SecureChannelDataSource;\nlet secureChannel: SecureChannelService;\n\nconst fakeSessionId = \"test-list-connected-device-session-id\";\n\ndescribe(\"ListenToConnectedDevice\", () => {\n beforeEach(() => {\n logger = new DefaultLoggerPublisherService(\n [],\n \"listen-to-connected-device-use-case\",\n );\n managerApiDataSource = new HttpManagerApiDataSource(\n {} as DmkConfig,\n () => logger,\n );\n managerApi = new DefaultManagerApiService(managerApiDataSource);\n secureChannelDataSource = new DefaultSecureChannelDataSource(\n {} as DmkConfig,\n );\n secureChannel = new DefaultSecureChannelService(secureChannelDataSource);\n sessionService = new DefaultDeviceSessionService(() => logger);\n });\n\n it(\"should emit an instance of ConnectedDevice\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const connectedDevice = connectedDeviceStubBuilder({\n id: \"test-list-connected-device-id\",\n });\n const deviceSession = deviceSessionStubBuilder(\n { id: fakeSessionId, connectedDevice },\n () => logger,\n managerApi,\n secureChannel,\n DEVICE_SESSION_REFRESHER_DEFAULT_OPTIONS,\n );\n const observable = new ListenToConnectedDeviceUseCase(\n sessionService,\n () => logger,\n ).execute();\n\n const subscription = observable.subscribe({\n next(emittedConnectedDevice) {\n // then\n try {\n expect(emittedConnectedDevice).toEqual(\n new ConnectedDevice({\n transportConnectedDevice: connectedDevice,\n sessionId: fakeSessionId,\n }),\n );\n terminate();\n } catch (error) {\n reject(error);\n }\n },\n });\n\n function terminate() {\n subscription.unsubscribe();\n deviceSession.close();\n resolve();\n }\n\n // when\n sessionService.addDeviceSession(deviceSession);\n }));\n});\n"],
|
|
5
|
+
"mappings": "aAEA,IAAAA,EAAgC,gDAChCC,EAA2C,8DAC3CC,EAAyD,qEACzDC,EAAyC,6DACzCC,EAA4C,wEAE5CC,EAA+C,uEAC/CC,EAA8C,4EAC9CC,EAAyC,+DAEzCC,EAAyC,kEAEzCC,EAA+C,wEAE/CC,EAA4C,wEAG5C,GAAG,KAAK,qDAAqD,EAE7D,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,MAAMC,EAAgB,wCAEtB,SAAS,0BAA2B,IAAM,CACxC,WAAW,IAAM,CACfN,EAAS,IAAI,gCACX,CAAC,EACD,qCACF,EACAE,EAAuB,IAAI,2BACzB,CAAC,EACD,IAAMF,CACR,EACAG,EAAa,IAAI,2BAAyBD,CAAoB,EAC9DE,EAA0B,IAAI,iCAC5B,CAAC,CACH,EACAC,EAAgB,IAAI,8BAA4BD,CAAuB,EACvEH,EAAiB,IAAI,8BAA4B,IAAMD,CAAM,CAC/D,CAAC,EAED,GAAG,6CAA8C,IAC/C,IAAI,QAAc,CAACO,EAASC,IAAW,CAErC,MAAMC,KAAkB,8BAA2B,CACjD,GAAI,+BACN,CAAC,EACKC,KAAgB,4BACpB,CAAE,GAAIJ,EAAe,gBAAAG,CAAgB,EACrC,IAAMT,EACNG,EACAE,EACA,0CACF,EAMMM,EALa,IAAI,iCACrBV,EACA,IAAMD,CACR,EAAE,QAAQ,EAEsB,UAAU,CACxC,KAAKY,EAAwB,CAE3B,GAAI,CACF,OAAOA,CAAsB,EAAE,QAC7B,IAAI,kBAAgB,CAClB,yBAA0BH,EAC1B,UAAWH,CACb,CAAC,CACH,EACAO,EAAU,CACZ,OAASC,EAAO,CACdN,EAAOM,CAAK,CACd,CACF,CACF,CAAC,EAED,SAASD,GAAY,CACnBF,EAAa,YAAY,EACzBD,EAAc,MAAM,EACpBH,EAAQ,CACV,CAGAN,EAAe,iBAAiBS,CAAa,CAC/C,CAAC,CAAC,CACN,CAAC",
|
|
6
6
|
"names": ["import_ConnectedDevice", "import_TransportConnectedDevice", "import_DeviceSessionRefresherConst", "import_DeviceSession", "import_DefaultDeviceSessionService", "import_ListenToConnectedDeviceUseCase", "import_DefaultLoggerPublisherService", "import_HttpManagerApiDataSource", "import_DefaultManagerApiService", "import_DefaultSecureChannelDataSource", "import_DefaultSecureChannelService", "logger", "sessionService", "managerApiDataSource", "managerApi", "secureChannelDataSource", "secureChannel", "fakeSessionId", "resolve", "reject", "connectedDevice", "deviceSession", "subscription", "emittedConnectedDevice", "terminate", "error"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var y=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var k=(n,r)=>{for(var e in r)y(n,e,{get:r[e],enumerable:!0})},T=(n,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of P(r))!V.call(n,i)&&i!==e&&y(n,i,{get:()=>r[i],enumerable:!(t=h(r,i))||t.enumerable});return n};var I=n=>T(y({},"__esModule",{value:!0}),n),v=(n,r,e,t)=>{for(var i=t>1?void 0:t?h(r,e):r,a=n.length-1,p;a>=0;a--)(p=n[a])&&(i=(t?p(r,e,i):p(i))||i);return t&&i&&y(r,e,i),i},g=(n,r)=>(e,t)=>r(e,t,n);var O={};k(O,{HttpManagerApiDataSource:()=>l});module.exports=I(O);var u=require("inversify"),o=require("purify-ts"),d=require("../../../api/network/DmkNetworkClient"),_=require("../../../api/network/DmkNetworkClientError"),w=require("../../logger-publisher/di/loggerTypes"),A=require("../../manager-api/di/managerApiTypes"),m=require("../../manager-api/model/Application"),D=require("../../manager-api/model/Const"),b=require("../../manager-api/model/Const"),f=require("../../manager-api/model/Errors"),c=require("./ManagerApiDto");const s=n=>n instanceof _.DmkNetworkClientError&&n.cause!==void 0?new f.HttpFetchApiError(n.cause):new f.HttpFetchApiError(n);let l=class{http;_provider=D.DEFAULT_PROVIDER;_firmwareDistributionSalt=b.DEFAULT_FIRMWARE_DISTRIBUTION_SALT;_logger;constructor({managerApiUrl:r,provider:e,firmwareDistributionSalt:t},i){this.http=new d.DmkNetworkClient({baseUrl:r}),this._provider=e,this._firmwareDistributionSalt=t,this._logger=i("HttpManagerApiDataSource")}setProvider(r){this._provider===r||r<1||(this._provider=r)}getProvider(){return this._provider}setFirmwareDistributionSalt(r){this._firmwareDistributionSalt===r||r.trim()===""||(this._firmwareDistributionSalt=r)}getFirmwareDistributionSalt(){return this._firmwareDistributionSalt}getAppList(r){const{targetId:e,firmwareVersionName:t}=r;return(0,o.EitherAsync)(()=>this.http.get("/v2/apps/by-target",{params:{target_id:e,provider:this._provider,firmware_version_name:t}})).chain(i=>this.mapApplicationDtoToApplication(i)).mapLeft(s)}getMcuList(){return(0,o.EitherAsync)(()=>this.http.get("/mcu_versions")).chain(r=>this.mapMcuDtoToMcu(r)).mapLeft(s)}getDeviceVersion(r){const{targetId:e}=r;return(0,o.EitherAsync)(()=>this.http.get("/get_device_version",{params:{target_id:e,provider:this._provider}})).chain(t=>this.mapDeviceVersionDto(t)).mapLeft(s)}getFirmwareVersion(r){const{deviceId:e,version:t}=r;return(0,o.EitherAsync)(()=>this.http.get("/get_firmware_version",{params:{device_version:e,version_name:t,provider:this._provider}})).chain(i=>this.mapFinalFirmwareDto(i)).mapLeft(s)}getFirmwareVersionById(r){return(0,o.EitherAsync)(()=>this.http.get(`/firmware_final_versions/${r}`)).chain(e=>this.mapFinalFirmwareDto(e)).mapLeft(s)}getOsuFirmwareVersion(r){const{deviceId:e,version:t}=r;return(0,o.EitherAsync)(()=>this.http.get("/get_osu_version",{params:{device_version:e,version_name:t,provider:this._provider}})).chain(i=>this.mapOsuFirmwareDto(i)).mapLeft(s)}getLatestFirmwareVersion(r){const{currentFinalFirmwareId:e,deviceId:t}=r;return(0,o.EitherAsync)(()=>{const i=this._firmwareDistributionSalt;return this._logger.info("Requesting latest firmware",{data:{salt:i}}),this.http.get("/get_latest_firmware",{params:{current_se_firmware_final_version:e,device_version:t,provider:this._provider,salt:i}})}).chain(i=>this.mapLatestFirmwareDto(i)).mapLeft(s)}getAppsByHash(r){const{hashes:e}=r;return(0,o.EitherAsync)(()=>this.http.post("/v2/apps/hash",e)).chain(t=>this.mapNullableApplicationDtoToApplication(t)).mapLeft(s)}getLanguagePackages(r){const{deviceId:e,currentFinalFirmwareId:t}=r;return(0,o.EitherAsync)(()=>this.http.get("/language-packages",{params:{device_version:e,current_se_firmware_final_version:t}})).chain(i=>this.mapLanguagesDtoToLanguages(i)).mapLeft(s)}mapAppTypeDtoToAppType(r){if(r===null)return null;switch(r){case c.AppTypeDto.currency:return m.AppType.currency;case c.AppTypeDto.plugin:return m.AppType.plugin;case c.AppTypeDto.tool:return m.AppType.tool;case c.AppTypeDto.swap:return m.AppType.swap}}mapApplicationDtoToApplication(r){return(0,o.EitherAsync)(()=>Promise.resolve(r.map(e=>this.mapApplicationDto(e))))}mapNullableApplicationDtoToApplication(r){return(0,o.EitherAsync)(()=>Promise.resolve(r.map(e=>e===null?null:this.mapApplicationDto(e))))}mapApplicationDto(r){if(typeof r!="object"||typeof r.versionId!="number"||typeof r.versionName!="string"||r.versionDisplayName!==null&&typeof r.versionDisplayName!="string"||typeof r.version!="string"||r.currencyId!==null&&typeof r.currencyId!="string"||r.description!==null&&typeof r.description!="string"||r.applicationType!==null&&typeof r.applicationType!="string"||typeof r.dateModified!="string"||r.icon!==null&&typeof r.icon!="string"||r.authorName!==null&&typeof r.authorName!="string"||r.supportURL!==null&&typeof r.supportURL!="string"||r.contactURL!==null&&typeof r.contactURL!="string"||r.sourceURL!==null&&typeof r.sourceURL!="string"||r.compatibleWallets!==null&&typeof r.compatibleWallets!="string"||typeof r.hash!="string"||typeof r.perso!="string"||typeof r.firmware!="string"||typeof r.firmwareKey!="string"||typeof r.delete!="string"||typeof r.deleteKey!="string"||r.bytes!==null&&typeof r.bytes!="number"||r.warning!==null&&typeof r.warning!="string"||typeof r.isDevTools!="boolean"||r.category!==null&&typeof r.category!="number"||r.parent!==null&&typeof r.parent!="number"||r.parentName!==null&&typeof r.parentName!="string")throw new Error(`Incomplete application: ${JSON.stringify(r)}`);const{applicationType:e,hash:t,perso:i,firmware:a,firmwareKey:p,delete:F,deleteKey:L,...E}=r;return{...E,hash:t,perso:i,firmware:a,firmwareKey:p,delete:F,deleteKey:L,applicationType:this.mapAppTypeDtoToAppType(e)}}mapMcuDtoToMcu(r){return(0,o.EitherAsync)(()=>Promise.resolve(r.map(e=>{if(typeof e!="object"||typeof e.id!="number"||typeof e.name!="string"||typeof e.from_bootloader_version!="string")throw new Error(`Incomplete MCU version: ${JSON.stringify(e)}`);return{id:e.id,name:e.name,fromBootloaderVersion:e.from_bootloader_version,providers:e.providers}})))}mapDeviceVersionDto(r){return(0,o.EitherAsync)(()=>{if(typeof r!="object"||typeof r.id!="number")throw new Error(`Incomplete device version: ${JSON.stringify(r)}`);const e={id:r.id};return Promise.resolve(e)})}mapFinalFirmwareDto(r){return(0,o.EitherAsync)(()=>{if(typeof r!="object"||typeof r.id!="number"||typeof r.version!="string"||typeof r.perso!="string"||r.firmware!==null&&typeof r.firmware!="string"||r.firmware_key!==null&&typeof r.firmware_key!="string"||r.hash!==null&&typeof r.hash!="string"||r.bytes!==null&&typeof r.bytes!="number"||!Array.isArray(r.mcu_versions))throw new Error(`Incomplete final firmware: ${JSON.stringify(r)}`);const e={id:r.id,version:r.version,perso:r.perso,firmware:r.firmware,firmwareKey:r.firmware_key,hash:r.hash,bytes:r.bytes,mcuVersions:r.mcu_versions};return Promise.resolve(e)})}mapLatestFirmwareDto(r){return(0,o.EitherAsync)(()=>{if(r.result==="null")return Promise.resolve(null);if(r.result!=="success"||!r.se_firmware_osu_version)throw new Error(`Latest firmware could not be retrieved: ${r.result}`);const e=r.se_firmware_osu_version;return Promise.resolve(e)}).chain(e=>e===null?(0,o.EitherAsync)(()=>Promise.resolve(o.Nothing)):this.mapOsuFirmwareDto(e).map(t=>(0,o.Just)(t)))}mapOsuFirmwareDto(r){return(0,o.EitherAsync)(()=>{if(typeof r!="object"||typeof r.id!="number"||r.notes!==null&&typeof r.notes!="string"||typeof r.perso!="string"||typeof r.firmware!="string"||typeof r.firmware_key!="string"||r.hash!==null&&typeof r.hash!="string"||typeof r.next_se_firmware_final_version!="number")throw new Error(`Incomplete latest firmware: ${JSON.stringify(r)}`);const e={id:r.id,notes:r.notes,perso:r.perso,firmware:r.firmware,firmwareKey:r.firmware_key,hash:r.hash,nextFinalFirmware:r.next_se_firmware_final_version};return Promise.resolve(e)})}mapLanguagesDtoToLanguages(r){return(0,o.EitherAsync)(()=>Promise.resolve(r.map(e=>this.mapLanguageDto(e))))}mapLanguageDto(r){if(typeof r!="object"||typeof r.language!="string"||typeof r.languagePackageVersionId!="number"||typeof r.version!="string"||typeof r.language_package_id!="number"||typeof r.apdu_install_url!="string"||typeof r.apdu_uninstall_url!="string"||typeof r.bytes!="number"||typeof r.date_creation!="string"||typeof r.date_last_modified!="string")throw new Error(`Incomplete language version: ${JSON.stringify(r)}`);return{language:r.language,languagePackageVersionId:r.languagePackageVersionId,version:r.version,languagePackageId:r.language_package_id,apduInstallUrl:r.apdu_install_url,apduUninstallUrl:r.apdu_uninstall_url,bytes:r.bytes,dateCreation:r.date_creation,dateLastModified:r.date_last_modified}}};l=v([(0,u.injectable)(),g(0,(0,u.inject)(A.managerApiTypes.DmkConfig)),g(1,(0,u.inject)(w.loggerTypes.LoggerPublisherServiceFactory))],l);0&&(module.exports={HttpManagerApiDataSource});
|
|
2
2
|
//# sourceMappingURL=HttpManagerApiDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/manager-api/data/HttpManagerApiDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync, Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { DmkNetworkClient } from \"@api/network/DmkNetworkClient\";\nimport { DmkNetworkClientError } from \"@api/network/DmkNetworkClientError\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { DEFAULT_PROVIDER } from \"@internal/manager-api/model/Const\";\nimport { DEFAULT_FIRMWARE_DISTRIBUTION_SALT } from \"@internal/manager-api/model/Const\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport type {\n FinalFirmware,\n McuFirmware,\n OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type LanguagePackage } from \"@internal/manager-api/model/Language\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n type GetLanguagePackagesParams,\n type GetLatestFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport {\n ApplicationDto,\n AppTypeDto,\n DeviceVersionDto,\n FirmwareFinalVersionDto,\n FirmwareOsuVersionDto,\n LanguagePackageVersionDto,\n LatestFirmwareOsuVersionResponseDto,\n McuVersionDto,\n} from \"./ManagerApiDto\";\n\nconst toHttpFetchApiError = (error: unknown): HttpFetchApiError => {\n // The network client wraps fetch errors in DmkNetworkClientError. Unwrap the\n // original cause when available so consumers (and tests) keep seeing the\n // underlying error.\n if (error instanceof DmkNetworkClientError && error.cause !== undefined) {\n return new HttpFetchApiError(error.cause);\n }\n return new HttpFetchApiError(error);\n};\n\n@injectable()\nexport class HttpManagerApiDataSource implements ManagerApiDataSource {\n private readonly http: DmkNetworkClient;\n private _provider: number = DEFAULT_PROVIDER;\n private _firmwareDistributionSalt: string =\n DEFAULT_FIRMWARE_DISTRIBUTION_SALT;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl, provider, firmwareDistributionSalt }: DmkConfig,\n ) {\n this.http = new DmkNetworkClient({ baseUrl: managerApiUrl });\n this._provider = provider;\n this._firmwareDistributionSalt = firmwareDistributionSalt;\n }\n\n setProvider(provider: number): void {\n if (this._provider === provider || provider < 1) {\n return;\n }\n this._provider = provider;\n }\n\n getProvider(): number {\n return this._provider;\n }\n\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Array<Application>> {\n const { targetId, firmwareVersionName } = params;\n return EitherAsync(() =>\n this.http.get(\"/v2/apps/by-target\", {\n params: {\n target_id: targetId,\n provider: this._provider,\n firmware_version_name: firmwareVersionName,\n },\n }),\n )\n .chain((apps) =>\n this.mapApplicationDtoToApplication(apps as Array<ApplicationDto>),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getMcuList(): EitherAsync<HttpFetchApiError, Array<McuFirmware>> {\n return EitherAsync(() => this.http.get(\"/mcu_versions\"))\n .chain((mcus) => this.mapMcuDtoToMcu(mcus as Array<McuVersionDto>))\n .mapLeft(toHttpFetchApiError);\n }\n\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n const { targetId } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_device_version\", {\n params: { target_id: targetId, provider: this._provider },\n }),\n )\n .chain((deviceVersion) =>\n this.mapDeviceVersionDto(deviceVersion as DeviceVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n const { deviceId, version } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_firmware_version\", {\n params: {\n device_version: deviceId,\n version_name: version,\n provider: this._provider,\n },\n }),\n )\n .chain((finalFirmware) =>\n this.mapFinalFirmwareDto(finalFirmware as FirmwareFinalVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getFirmwareVersionById(\n finalFirmwareId: number,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n return EitherAsync(() =>\n this.http.get(`/firmware_final_versions/${finalFirmwareId}`),\n )\n .chain((finalFirmware) =>\n this.mapFinalFirmwareDto(finalFirmware as FirmwareFinalVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getOsuFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, OsuFirmware> {\n const { deviceId, version } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_osu_version\", {\n params: {\n device_version: deviceId,\n version_name: version,\n provider: this._provider,\n },\n }),\n )\n .chain((osuFirmware) =>\n this.mapOsuFirmwareDto(osuFirmware as FirmwareOsuVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getLatestFirmwareVersion(\n params: GetLatestFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, Maybe<OsuFirmware>> {\n const { currentFinalFirmwareId, deviceId } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_latest_firmware\", {\n params: {\n current_se_firmware_final_version: currentFinalFirmwareId,\n device_version: deviceId,\n provider: this._provider,\n salt: this._firmwareDistributionSalt,\n },\n }),\n )\n .chain((latestFirmware) =>\n this.mapLatestFirmwareDto(\n latestFirmware as LatestFirmwareOsuVersionResponseDto,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n const { hashes } = params;\n return EitherAsync(() => this.http.post(\"/v2/apps/hash\", hashes))\n .chain((apps) =>\n this.mapNullableApplicationDtoToApplication(\n apps as Array<ApplicationDto | null>,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getLanguagePackages(\n params: GetLanguagePackagesParams,\n ): EitherAsync<HttpFetchApiError, Array<LanguagePackage>> {\n const { deviceId, currentFinalFirmwareId } = params;\n return EitherAsync(() =>\n this.http.get(\"/language-packages\", {\n params: {\n device_version: deviceId,\n current_se_firmware_final_version: currentFinalFirmwareId,\n },\n }),\n )\n .chain((apps) =>\n this.mapLanguagesDtoToLanguages(\n apps as Array<LanguagePackageVersionDto>,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto | null): AppType | null {\n if (appType === null) {\n return null;\n }\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>,\n ): EitherAsync<Error, Array<Application>> {\n return EitherAsync(() =>\n Promise.resolve(apps.map((app) => this.mapApplicationDto(app))),\n );\n }\n\n private mapNullableApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): EitherAsync<Error, Array<Application | null>> {\n return EitherAsync(() =>\n Promise.resolve(\n apps.map((app) => {\n if (app === null) {\n return null;\n }\n return this.mapApplicationDto(app);\n }),\n ),\n );\n }\n\n private mapApplicationDto(app: ApplicationDto): Application {\n if (\n typeof app !== \"object\" ||\n typeof app.versionId !== \"number\" ||\n typeof app.versionName !== \"string\" ||\n (app.versionDisplayName !== null &&\n typeof app.versionDisplayName !== \"string\") ||\n typeof app.version !== \"string\" ||\n (app.currencyId !== null && typeof app.currencyId !== \"string\") ||\n (app.description !== null && typeof app.description !== \"string\") ||\n (app.applicationType !== null &&\n typeof app.applicationType !== \"string\") ||\n typeof app.dateModified !== \"string\" ||\n (app.icon !== null && typeof app.icon !== \"string\") ||\n (app.authorName !== null && typeof app.authorName !== \"string\") ||\n (app.supportURL !== null && typeof app.supportURL !== \"string\") ||\n (app.contactURL !== null && typeof app.contactURL !== \"string\") ||\n (app.sourceURL !== null && typeof app.sourceURL !== \"string\") ||\n (app.compatibleWallets !== null &&\n typeof app.compatibleWallets !== \"string\") ||\n typeof app.hash !== \"string\" ||\n typeof app.perso !== \"string\" ||\n typeof app.firmware !== \"string\" ||\n typeof app.firmwareKey !== \"string\" ||\n typeof app.delete !== \"string\" ||\n typeof app.deleteKey !== \"string\" ||\n (app.bytes !== null && typeof app.bytes !== \"number\") ||\n (app.warning !== null && typeof app.warning !== \"string\") ||\n typeof app.isDevTools !== \"boolean\" ||\n (app.category !== null && typeof app.category !== \"number\") ||\n (app.parent !== null && typeof app.parent !== \"number\") ||\n (app.parentName !== null && typeof app.parentName !== \"string\")\n ) {\n throw new Error(`Incomplete application: ${JSON.stringify(app)}`);\n }\n const {\n applicationType,\n hash,\n perso,\n firmware,\n firmwareKey,\n delete: del,\n deleteKey,\n ...rest\n } = app;\n const ret: Application = {\n ...rest,\n hash: hash!,\n perso: perso!,\n firmware: firmware!,\n firmwareKey: firmwareKey!,\n delete: del!,\n deleteKey: deleteKey!,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n return ret;\n }\n\n private mapMcuDtoToMcu(\n mcus: Array<McuVersionDto>,\n ): EitherAsync<Error, Array<McuFirmware>> {\n return EitherAsync(() =>\n Promise.resolve(\n mcus.map((mcu) => {\n if (\n typeof mcu !== \"object\" ||\n typeof mcu.id !== \"number\" ||\n typeof mcu.name !== \"string\" ||\n typeof mcu.from_bootloader_version !== \"string\"\n ) {\n throw new Error(`Incomplete MCU version: ${JSON.stringify(mcu)}`);\n }\n const ret: McuFirmware = {\n id: mcu.id,\n name: mcu.name,\n fromBootloaderVersion: mcu.from_bootloader_version,\n providers: mcu.providers,\n };\n return ret;\n }),\n ),\n );\n }\n\n private mapDeviceVersionDto(\n deviceVersion: DeviceVersionDto,\n ): EitherAsync<Error, DeviceVersion> {\n return EitherAsync(() => {\n if (\n typeof deviceVersion !== \"object\" ||\n typeof deviceVersion.id !== \"number\"\n ) {\n throw new Error(\n `Incomplete device version: ${JSON.stringify(deviceVersion)}`,\n );\n }\n const ret: DeviceVersion = {\n id: deviceVersion.id,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapFinalFirmwareDto(\n finalFirmware: FirmwareFinalVersionDto,\n ): EitherAsync<Error, FinalFirmware> {\n return EitherAsync(() => {\n if (\n typeof finalFirmware !== \"object\" ||\n typeof finalFirmware.id !== \"number\" ||\n typeof finalFirmware.version !== \"string\" ||\n typeof finalFirmware.perso !== \"string\" ||\n (finalFirmware.firmware !== null &&\n typeof finalFirmware.firmware !== \"string\") ||\n (finalFirmware.firmware_key !== null &&\n typeof finalFirmware.firmware_key !== \"string\") ||\n (finalFirmware.hash !== null &&\n typeof finalFirmware.hash !== \"string\") ||\n (finalFirmware.bytes !== null &&\n typeof finalFirmware.bytes !== \"number\") ||\n !Array.isArray(finalFirmware.mcu_versions)\n ) {\n throw new Error(\n `Incomplete final firmware: ${JSON.stringify(finalFirmware)}`,\n );\n }\n const ret: FinalFirmware = {\n id: finalFirmware.id,\n version: finalFirmware.version,\n perso: finalFirmware.perso,\n firmware: finalFirmware.firmware,\n firmwareKey: finalFirmware.firmware_key,\n hash: finalFirmware.hash,\n bytes: finalFirmware.bytes,\n mcuVersions: finalFirmware.mcu_versions,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapLatestFirmwareDto(\n latestFirmware: LatestFirmwareOsuVersionResponseDto,\n ): EitherAsync<Error, Maybe<OsuFirmware>> {\n return EitherAsync<Error, FirmwareOsuVersionDto | null>(() => {\n /**\n * This is how we know that there is no update available.\n * See the {@link https://github.com/LedgerHQ/ledger-live/blob/develop/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts#L59-L61 | ledger-live implementation}.\n */\n if (latestFirmware.result === \"null\") {\n return Promise.resolve(null);\n }\n if (\n latestFirmware.result !== \"success\" ||\n !latestFirmware.se_firmware_osu_version\n ) {\n throw new Error(\n `Latest firmware could not be retrieved: ${latestFirmware.result}`,\n );\n }\n const osuDto = latestFirmware.se_firmware_osu_version;\n return Promise.resolve(osuDto);\n }).chain((osuDto) => {\n if (null === osuDto) {\n return EitherAsync(() => Promise.resolve(Nothing));\n }\n return this.mapOsuFirmwareDto(osuDto).map((osuFirmware) =>\n Just(osuFirmware),\n );\n });\n }\n\n private mapOsuFirmwareDto(\n osuDto: FirmwareOsuVersionDto,\n ): EitherAsync<Error, OsuFirmware> {\n return EitherAsync(() => {\n if (\n typeof osuDto !== \"object\" ||\n typeof osuDto.id !== \"number\" ||\n (osuDto.notes !== null && typeof osuDto.notes !== \"string\") ||\n typeof osuDto.perso !== \"string\" ||\n typeof osuDto.firmware !== \"string\" ||\n typeof osuDto.firmware_key !== \"string\" ||\n (osuDto.hash !== null && typeof osuDto.hash !== \"string\") ||\n typeof osuDto.next_se_firmware_final_version !== \"number\"\n ) {\n throw new Error(\n `Incomplete latest firmware: ${JSON.stringify(osuDto)}`,\n );\n }\n const ret: OsuFirmware = {\n id: osuDto.id,\n notes: osuDto.notes,\n perso: osuDto.perso,\n firmware: osuDto.firmware,\n firmwareKey: osuDto.firmware_key,\n hash: osuDto.hash,\n nextFinalFirmware: osuDto.next_se_firmware_final_version,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapLanguagesDtoToLanguages(\n languages: Array<LanguagePackageVersionDto>,\n ): EitherAsync<Error, Array<LanguagePackage>> {\n return EitherAsync(() =>\n Promise.resolve(\n languages.map((language) => this.mapLanguageDto(language)),\n ),\n );\n }\n\n private mapLanguageDto(language: LanguagePackageVersionDto): LanguagePackage {\n if (\n typeof language !== \"object\" ||\n typeof language.language !== \"string\" ||\n typeof language.languagePackageVersionId !== \"number\" ||\n typeof language.version !== \"string\" ||\n typeof language.language_package_id !== \"number\" ||\n typeof language.apdu_install_url !== \"string\" ||\n typeof language.apdu_uninstall_url !== \"string\" ||\n typeof language.bytes !== \"number\" ||\n typeof language.date_creation !== \"string\" ||\n typeof language.date_last_modified !== \"string\"\n ) {\n throw new Error(\n `Incomplete language version: ${JSON.stringify(language)}`,\n );\n }\n const ret: LanguagePackage = {\n language: language.language,\n languagePackageVersionId: language.languagePackageVersionId,\n version: language.version,\n languagePackageId: language.language_package_id,\n apduInstallUrl: language.apdu_install_url,\n apduUninstallUrl: language.apdu_uninstall_url,\n bytes: language.bytes,\n dateCreation: language.date_creation,\n dateLastModified: language.date_last_modified,\n };\n return ret;\n }\n}\n"],
|
|
5
|
-
"mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAAkD,
|
|
6
|
-
"names": ["HttpManagerApiDataSource_exports", "__export", "HttpManagerApiDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_DmkNetworkClient", "import_DmkNetworkClientError", "import_managerApiTypes", "import_Application", "import_Const", "import_Errors", "import_ManagerApiDto", "toHttpFetchApiError", "error", "HttpManagerApiDataSource", "managerApiUrl", "provider", "firmwareDistributionSalt", "params", "targetId", "firmwareVersionName", "apps", "mcus", "deviceVersion", "deviceId", "version", "finalFirmware", "finalFirmwareId", "osuFirmware", "currentFinalFirmwareId", "latestFirmware", "hashes", "appType", "app", "applicationType", "hash", "perso", "firmware", "firmwareKey", "del", "deleteKey", "rest", "mcu", "ret", "osuDto", "languages", "language", "__decorateClass", "__decorateParam"]
|
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync, Just, Maybe, Nothing } from \"purify-ts\";\n\nimport { type DmkConfig } from \"@api/DmkConfig\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { DmkNetworkClient } from \"@api/network/DmkNetworkClient\";\nimport { DmkNetworkClientError } from \"@api/network/DmkNetworkClientError\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport {\n type Application,\n AppType,\n} from \"@internal/manager-api/model/Application\";\nimport { DEFAULT_PROVIDER } from \"@internal/manager-api/model/Const\";\nimport { DEFAULT_FIRMWARE_DISTRIBUTION_SALT } from \"@internal/manager-api/model/Const\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport { HttpFetchApiError } from \"@internal/manager-api/model/Errors\";\nimport type {\n FinalFirmware,\n McuFirmware,\n OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type LanguagePackage } from \"@internal/manager-api/model/Language\";\nimport {\n type GetAppByHashParams,\n type GetAppListParams,\n type GetDeviceVersionParams,\n type GetFirmwareVersionParams,\n type GetLanguagePackagesParams,\n type GetLatestFirmwareVersionParams,\n} from \"@internal/manager-api/model/Params\";\n\nimport { ManagerApiDataSource } from \"./ManagerApiDataSource\";\nimport {\n ApplicationDto,\n AppTypeDto,\n DeviceVersionDto,\n FirmwareFinalVersionDto,\n FirmwareOsuVersionDto,\n LanguagePackageVersionDto,\n LatestFirmwareOsuVersionResponseDto,\n McuVersionDto,\n} from \"./ManagerApiDto\";\n\nconst toHttpFetchApiError = (error: unknown): HttpFetchApiError => {\n // The network client wraps fetch errors in DmkNetworkClientError. Unwrap the\n // original cause when available so consumers (and tests) keep seeing the\n // underlying error.\n if (error instanceof DmkNetworkClientError && error.cause !== undefined) {\n return new HttpFetchApiError(error.cause);\n }\n return new HttpFetchApiError(error);\n};\n\n@injectable()\nexport class HttpManagerApiDataSource implements ManagerApiDataSource {\n private readonly http: DmkNetworkClient;\n private _provider: number = DEFAULT_PROVIDER;\n private _firmwareDistributionSalt: string =\n DEFAULT_FIRMWARE_DISTRIBUTION_SALT;\n\n private readonly _logger: LoggerPublisherService;\n\n constructor(\n @inject(managerApiTypes.DmkConfig)\n { managerApiUrl, provider, firmwareDistributionSalt }: DmkConfig,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerFactory: (tag: string) => LoggerPublisherService,\n ) {\n this.http = new DmkNetworkClient({ baseUrl: managerApiUrl });\n this._provider = provider;\n this._firmwareDistributionSalt = firmwareDistributionSalt;\n this._logger = loggerFactory(\"HttpManagerApiDataSource\");\n }\n\n setProvider(provider: number): void {\n if (this._provider === provider || provider < 1) {\n return;\n }\n this._provider = provider;\n }\n\n getProvider(): number {\n return this._provider;\n }\n\n setFirmwareDistributionSalt(salt: string): void {\n if (this._firmwareDistributionSalt === salt || salt.trim() === \"\") {\n return;\n }\n this._firmwareDistributionSalt = salt;\n }\n\n getFirmwareDistributionSalt(): string {\n return this._firmwareDistributionSalt;\n }\n\n getAppList(\n params: GetAppListParams,\n ): EitherAsync<HttpFetchApiError, Array<Application>> {\n const { targetId, firmwareVersionName } = params;\n return EitherAsync(() =>\n this.http.get(\"/v2/apps/by-target\", {\n params: {\n target_id: targetId,\n provider: this._provider,\n firmware_version_name: firmwareVersionName,\n },\n }),\n )\n .chain((apps) =>\n this.mapApplicationDtoToApplication(apps as Array<ApplicationDto>),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getMcuList(): EitherAsync<HttpFetchApiError, Array<McuFirmware>> {\n return EitherAsync(() => this.http.get(\"/mcu_versions\"))\n .chain((mcus) => this.mapMcuDtoToMcu(mcus as Array<McuVersionDto>))\n .mapLeft(toHttpFetchApiError);\n }\n\n getDeviceVersion(\n params: GetDeviceVersionParams,\n ): EitherAsync<HttpFetchApiError, DeviceVersion> {\n const { targetId } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_device_version\", {\n params: { target_id: targetId, provider: this._provider },\n }),\n )\n .chain((deviceVersion) =>\n this.mapDeviceVersionDto(deviceVersion as DeviceVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n const { deviceId, version } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_firmware_version\", {\n params: {\n device_version: deviceId,\n version_name: version,\n provider: this._provider,\n },\n }),\n )\n .chain((finalFirmware) =>\n this.mapFinalFirmwareDto(finalFirmware as FirmwareFinalVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getFirmwareVersionById(\n finalFirmwareId: number,\n ): EitherAsync<HttpFetchApiError, FinalFirmware> {\n return EitherAsync(() =>\n this.http.get(`/firmware_final_versions/${finalFirmwareId}`),\n )\n .chain((finalFirmware) =>\n this.mapFinalFirmwareDto(finalFirmware as FirmwareFinalVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getOsuFirmwareVersion(\n params: GetFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, OsuFirmware> {\n const { deviceId, version } = params;\n return EitherAsync(() =>\n this.http.get(\"/get_osu_version\", {\n params: {\n device_version: deviceId,\n version_name: version,\n provider: this._provider,\n },\n }),\n )\n .chain((osuFirmware) =>\n this.mapOsuFirmwareDto(osuFirmware as FirmwareOsuVersionDto),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getLatestFirmwareVersion(\n params: GetLatestFirmwareVersionParams,\n ): EitherAsync<HttpFetchApiError, Maybe<OsuFirmware>> {\n const { currentFinalFirmwareId, deviceId } = params;\n return EitherAsync(() => {\n const salt = this._firmwareDistributionSalt;\n this._logger.info(\"Requesting latest firmware\", { data: { salt } });\n return this.http.get(\"/get_latest_firmware\", {\n params: {\n current_se_firmware_final_version: currentFinalFirmwareId,\n device_version: deviceId,\n provider: this._provider,\n salt,\n },\n });\n })\n .chain((latestFirmware) =>\n this.mapLatestFirmwareDto(\n latestFirmware as LatestFirmwareOsuVersionResponseDto,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getAppsByHash(\n params: GetAppByHashParams,\n ): EitherAsync<HttpFetchApiError, Array<Application | null>> {\n const { hashes } = params;\n return EitherAsync(() => this.http.post(\"/v2/apps/hash\", hashes))\n .chain((apps) =>\n this.mapNullableApplicationDtoToApplication(\n apps as Array<ApplicationDto | null>,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n getLanguagePackages(\n params: GetLanguagePackagesParams,\n ): EitherAsync<HttpFetchApiError, Array<LanguagePackage>> {\n const { deviceId, currentFinalFirmwareId } = params;\n return EitherAsync(() =>\n this.http.get(\"/language-packages\", {\n params: {\n device_version: deviceId,\n current_se_firmware_final_version: currentFinalFirmwareId,\n },\n }),\n )\n .chain((apps) =>\n this.mapLanguagesDtoToLanguages(\n apps as Array<LanguagePackageVersionDto>,\n ),\n )\n .mapLeft(toHttpFetchApiError);\n }\n\n private mapAppTypeDtoToAppType(appType: AppTypeDto | null): AppType | null {\n if (appType === null) {\n return null;\n }\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>,\n ): EitherAsync<Error, Array<Application>> {\n return EitherAsync(() =>\n Promise.resolve(apps.map((app) => this.mapApplicationDto(app))),\n );\n }\n\n private mapNullableApplicationDtoToApplication(\n apps: Array<ApplicationDto | null>,\n ): EitherAsync<Error, Array<Application | null>> {\n return EitherAsync(() =>\n Promise.resolve(\n apps.map((app) => {\n if (app === null) {\n return null;\n }\n return this.mapApplicationDto(app);\n }),\n ),\n );\n }\n\n private mapApplicationDto(app: ApplicationDto): Application {\n if (\n typeof app !== \"object\" ||\n typeof app.versionId !== \"number\" ||\n typeof app.versionName !== \"string\" ||\n (app.versionDisplayName !== null &&\n typeof app.versionDisplayName !== \"string\") ||\n typeof app.version !== \"string\" ||\n (app.currencyId !== null && typeof app.currencyId !== \"string\") ||\n (app.description !== null && typeof app.description !== \"string\") ||\n (app.applicationType !== null &&\n typeof app.applicationType !== \"string\") ||\n typeof app.dateModified !== \"string\" ||\n (app.icon !== null && typeof app.icon !== \"string\") ||\n (app.authorName !== null && typeof app.authorName !== \"string\") ||\n (app.supportURL !== null && typeof app.supportURL !== \"string\") ||\n (app.contactURL !== null && typeof app.contactURL !== \"string\") ||\n (app.sourceURL !== null && typeof app.sourceURL !== \"string\") ||\n (app.compatibleWallets !== null &&\n typeof app.compatibleWallets !== \"string\") ||\n typeof app.hash !== \"string\" ||\n typeof app.perso !== \"string\" ||\n typeof app.firmware !== \"string\" ||\n typeof app.firmwareKey !== \"string\" ||\n typeof app.delete !== \"string\" ||\n typeof app.deleteKey !== \"string\" ||\n (app.bytes !== null && typeof app.bytes !== \"number\") ||\n (app.warning !== null && typeof app.warning !== \"string\") ||\n typeof app.isDevTools !== \"boolean\" ||\n (app.category !== null && typeof app.category !== \"number\") ||\n (app.parent !== null && typeof app.parent !== \"number\") ||\n (app.parentName !== null && typeof app.parentName !== \"string\")\n ) {\n throw new Error(`Incomplete application: ${JSON.stringify(app)}`);\n }\n const {\n applicationType,\n hash,\n perso,\n firmware,\n firmwareKey,\n delete: del,\n deleteKey,\n ...rest\n } = app;\n const ret: Application = {\n ...rest,\n hash: hash!,\n perso: perso!,\n firmware: firmware!,\n firmwareKey: firmwareKey!,\n delete: del!,\n deleteKey: deleteKey!,\n applicationType: this.mapAppTypeDtoToAppType(applicationType),\n };\n return ret;\n }\n\n private mapMcuDtoToMcu(\n mcus: Array<McuVersionDto>,\n ): EitherAsync<Error, Array<McuFirmware>> {\n return EitherAsync(() =>\n Promise.resolve(\n mcus.map((mcu) => {\n if (\n typeof mcu !== \"object\" ||\n typeof mcu.id !== \"number\" ||\n typeof mcu.name !== \"string\" ||\n typeof mcu.from_bootloader_version !== \"string\"\n ) {\n throw new Error(`Incomplete MCU version: ${JSON.stringify(mcu)}`);\n }\n const ret: McuFirmware = {\n id: mcu.id,\n name: mcu.name,\n fromBootloaderVersion: mcu.from_bootloader_version,\n providers: mcu.providers,\n };\n return ret;\n }),\n ),\n );\n }\n\n private mapDeviceVersionDto(\n deviceVersion: DeviceVersionDto,\n ): EitherAsync<Error, DeviceVersion> {\n return EitherAsync(() => {\n if (\n typeof deviceVersion !== \"object\" ||\n typeof deviceVersion.id !== \"number\"\n ) {\n throw new Error(\n `Incomplete device version: ${JSON.stringify(deviceVersion)}`,\n );\n }\n const ret: DeviceVersion = {\n id: deviceVersion.id,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapFinalFirmwareDto(\n finalFirmware: FirmwareFinalVersionDto,\n ): EitherAsync<Error, FinalFirmware> {\n return EitherAsync(() => {\n if (\n typeof finalFirmware !== \"object\" ||\n typeof finalFirmware.id !== \"number\" ||\n typeof finalFirmware.version !== \"string\" ||\n typeof finalFirmware.perso !== \"string\" ||\n (finalFirmware.firmware !== null &&\n typeof finalFirmware.firmware !== \"string\") ||\n (finalFirmware.firmware_key !== null &&\n typeof finalFirmware.firmware_key !== \"string\") ||\n (finalFirmware.hash !== null &&\n typeof finalFirmware.hash !== \"string\") ||\n (finalFirmware.bytes !== null &&\n typeof finalFirmware.bytes !== \"number\") ||\n !Array.isArray(finalFirmware.mcu_versions)\n ) {\n throw new Error(\n `Incomplete final firmware: ${JSON.stringify(finalFirmware)}`,\n );\n }\n const ret: FinalFirmware = {\n id: finalFirmware.id,\n version: finalFirmware.version,\n perso: finalFirmware.perso,\n firmware: finalFirmware.firmware,\n firmwareKey: finalFirmware.firmware_key,\n hash: finalFirmware.hash,\n bytes: finalFirmware.bytes,\n mcuVersions: finalFirmware.mcu_versions,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapLatestFirmwareDto(\n latestFirmware: LatestFirmwareOsuVersionResponseDto,\n ): EitherAsync<Error, Maybe<OsuFirmware>> {\n return EitherAsync<Error, FirmwareOsuVersionDto | null>(() => {\n /**\n * This is how we know that there is no update available.\n * See the {@link https://github.com/LedgerHQ/ledger-live/blob/develop/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts#L59-L61 | ledger-live implementation}.\n */\n if (latestFirmware.result === \"null\") {\n return Promise.resolve(null);\n }\n if (\n latestFirmware.result !== \"success\" ||\n !latestFirmware.se_firmware_osu_version\n ) {\n throw new Error(\n `Latest firmware could not be retrieved: ${latestFirmware.result}`,\n );\n }\n const osuDto = latestFirmware.se_firmware_osu_version;\n return Promise.resolve(osuDto);\n }).chain((osuDto) => {\n if (null === osuDto) {\n return EitherAsync(() => Promise.resolve(Nothing));\n }\n return this.mapOsuFirmwareDto(osuDto).map((osuFirmware) =>\n Just(osuFirmware),\n );\n });\n }\n\n private mapOsuFirmwareDto(\n osuDto: FirmwareOsuVersionDto,\n ): EitherAsync<Error, OsuFirmware> {\n return EitherAsync(() => {\n if (\n typeof osuDto !== \"object\" ||\n typeof osuDto.id !== \"number\" ||\n (osuDto.notes !== null && typeof osuDto.notes !== \"string\") ||\n typeof osuDto.perso !== \"string\" ||\n typeof osuDto.firmware !== \"string\" ||\n typeof osuDto.firmware_key !== \"string\" ||\n (osuDto.hash !== null && typeof osuDto.hash !== \"string\") ||\n typeof osuDto.next_se_firmware_final_version !== \"number\"\n ) {\n throw new Error(\n `Incomplete latest firmware: ${JSON.stringify(osuDto)}`,\n );\n }\n const ret: OsuFirmware = {\n id: osuDto.id,\n notes: osuDto.notes,\n perso: osuDto.perso,\n firmware: osuDto.firmware,\n firmwareKey: osuDto.firmware_key,\n hash: osuDto.hash,\n nextFinalFirmware: osuDto.next_se_firmware_final_version,\n };\n return Promise.resolve(ret);\n });\n }\n\n private mapLanguagesDtoToLanguages(\n languages: Array<LanguagePackageVersionDto>,\n ): EitherAsync<Error, Array<LanguagePackage>> {\n return EitherAsync(() =>\n Promise.resolve(\n languages.map((language) => this.mapLanguageDto(language)),\n ),\n );\n }\n\n private mapLanguageDto(language: LanguagePackageVersionDto): LanguagePackage {\n if (\n typeof language !== \"object\" ||\n typeof language.language !== \"string\" ||\n typeof language.languagePackageVersionId !== \"number\" ||\n typeof language.version !== \"string\" ||\n typeof language.language_package_id !== \"number\" ||\n typeof language.apdu_install_url !== \"string\" ||\n typeof language.apdu_uninstall_url !== \"string\" ||\n typeof language.bytes !== \"number\" ||\n typeof language.date_creation !== \"string\" ||\n typeof language.date_last_modified !== \"string\"\n ) {\n throw new Error(\n `Incomplete language version: ${JSON.stringify(language)}`,\n );\n }\n const ret: LanguagePackage = {\n language: language.language,\n languagePackageVersionId: language.languagePackageVersionId,\n version: language.version,\n languagePackageId: language.language_package_id,\n apduInstallUrl: language.apdu_install_url,\n apduUninstallUrl: language.apdu_uninstall_url,\n bytes: language.bytes,\n dateCreation: language.date_creation,\n dateLastModified: language.date_last_modified,\n };\n return ret;\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["HttpManagerApiDataSource_exports", "__export", "HttpManagerApiDataSource", "__toCommonJS", "import_inversify", "import_purify_ts", "import_DmkNetworkClient", "import_DmkNetworkClientError", "import_loggerTypes", "import_managerApiTypes", "import_Application", "import_Const", "import_Errors", "import_ManagerApiDto", "toHttpFetchApiError", "error", "HttpManagerApiDataSource", "managerApiUrl", "provider", "firmwareDistributionSalt", "loggerFactory", "salt", "params", "targetId", "firmwareVersionName", "apps", "mcus", "deviceVersion", "deviceId", "version", "finalFirmware", "finalFirmwareId", "osuFirmware", "currentFinalFirmwareId", "latestFirmware", "hashes", "appType", "app", "applicationType", "hash", "perso", "firmware", "firmwareKey", "del", "deleteKey", "rest", "mcu", "ret", "osuDto", "languages", "language", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=require("purify-ts"),t=require("../../../api/device-action/__test-utils__/data"),o=require("../../manager-api/model/Errors"),i=require("./HttpManagerApiDataSource");describe("HttpManagerApiDataSource",()=>{describe("getAppList",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a list of applications",async()=>{const e=[t.BTC_APP_METADATA,t.ETH_APP_METADATA];vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify(e)));const a=await r.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(a).toEqual((0,s.Right)(e))}),it("should return an error if payload don't match the dto",async()=>{const{versionId:e,...a}=t.BTC_APP_METADATA,n=[{versionId:"invalidVersion",...a}];vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify(n)));const l=await r.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(l.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([t.BTC_APP_METADATA])));const e=[t.BTC_APP.appFullHash],a=await r.getAppsByHash({hashes:e});expect(a).toEqual((0,s.Right)([t.BTC_APP_METADATA]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([])));const e=[],a=await r.getAppsByHash({hashes:e});expect(a).toEqual((0,s.Right)([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([t.BTC_APP_METADATA,t.CUSTOM_LOCK_SCREEN_APP_METADATA])));const e=[t.BTC_APP.appFullHash,t.CUSTOM_LOCK_SCREEN_APP.appFullHash],a=await r.getAppsByHash({hashes:e});expect(a).toEqual((0,s.Right)([t.BTC_APP_METADATA,t.CUSTOM_LOCK_SCREEN_APP_METADATA]))})}),describe("error cases",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("with BTC app, should fail if payload don't match the dto",async()=>{const{versionId:e,...a}=t.BTC_APP_METADATA;vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{versionId:"invalidVersion",...a}])));const n=[t.BTC_APP.appFullHash],l=await r.getAppsByHash({hashes:n});expect(l.isRight()).toEqual(!1)}),it("should throw an error if the request fails",async()=>{const e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"}),a=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(a);const n=[t.BTC_APP.appFullHash],l=await e.getAppsByHash({hashes:n});expect(l).toEqual((0,s.Left)(new o.HttpFetchApiError(a)))})})}),describe("getDeviceVersion",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete device version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:17,target_id:"857735172"})));const e=await r.getDeviceVersion({targetId:"targetId"});expect(e).toEqual((0,s.Right)({id:17}))}),it("should return an error if payload don't match dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({target_id:"857735172"})));const e=await r.getDeviceVersion({targetId:"targetId"});expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getDeviceVersion({targetId:"targetId"});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getFirmwareVersion",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const e=await r.getFirmwareVersion({version:"versionName",deviceId:42});expect(e).toEqual((0,s.Right)({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmwareKey:"testKey",hash:"hash",bytes:194,mcuVersions:[1,5,7]}))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:"invalidId",version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const e=await r.getFirmwareVersion({version:"versionName",deviceId:42});expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getFirmwareVersion({version:"versionName",deviceId:42});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("setProvider",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",provider:1})}),it("should not change the provider if the new value is the same",()=>{const e=r._provider;r.setProvider(e),expect(r._provider).toBe(e)}),it("should not change the provider if the new value is less than 1",()=>{const e=r._provider;r.setProvider(0),r.setProvider(-5),expect(r._provider).toBe(e)}),it("should update the provider if a valid and different value is provided",()=>{r.setProvider(2),expect(r._provider).toBe(2)})}),describe("getFirmwareVersionById",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const e=await r.getFirmwareVersionById(42);expect(e).toEqual((0,s.Right)({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmwareKey:"testKey",hash:"hash",bytes:194,mcuVersions:[1,5,7]}))})}),describe("getLatestFirmwareVersion",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the latest firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"success",se_firmware_osu_version:{id:361,perso:"perso_11",notes:"notes",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567}})));const e=await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(e).toEqual((0,s.Right)((0,s.Just)({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmwareKey:"testKey",hash:"hash",nextFinalFirmware:567})))}),it("should return nothing when no latest firmware version is available",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"null",se_firmware_osu_version:null})));const e=await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(e).toEqual((0,s.Right)(s.Nothing))}),it("should return an error if result is not success",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"failed",se_firmware_osu_version:null})));const e=await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(e.isRight()).toEqual(!1)}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"success",se_firmware_osu_version:{id:"InvalidId",perso:"perso_11",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567}})));const e=await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))}),it("should request the firmware params without the legacy livecommonversion param",async()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost",provider:82,firmwareDistributionSalt:"distribution-salt"});const e=vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"null",se_firmware_osu_version:null})));await r.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});const a=new URL(String(e.mock.calls[0][0]));expect(a.pathname).toEqual("/get_latest_firmware"),expect(a.searchParams.has("livecommonversion")).toEqual(!1),expect(Object.fromEntries(a.searchParams)).toEqual({current_se_firmware_final_version:"200",device_version:"42",provider:"82",salt:"distribution-salt"})})}),describe("getOsuFirmwareVersion",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete OSU firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567})));const e=await r.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(e).toEqual((0,s.Right)({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmwareKey:"testKey",hash:"hash",nextFinalFirmware:567}))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:"invalidId",perso:"perso_11",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567})));const e=await r.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getLanguagePackages",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the langage packages version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{language:"turkish",languagePackageVersionId:474,version:"0.0.4",language_package_id:57,apdu_install_url:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr.apdu",apdu_uninstall_url:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr_del.apdu",device_versions:[17],se_firmware_final_versions:[432],bytes:20800,date_creation:"2025-03-04T10:48:27.910630Z",date_last_modified:"2025-03-04T10:48:27.910630Z"},{language:"russian",languagePackageVersionId:470,version:"0.0.4",language_package_id:56,apdu_install_url:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru.apdu",apdu_uninstall_url:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru_del.apdu",device_versions:[17],se_firmware_final_versions:[432],bytes:46592,date_creation:"2025-03-04T10:48:26.218729Z",date_last_modified:"2025-03-04T10:48:26.218729Z"}])));const e=await r.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(e).toEqual((0,s.Right)([{language:"turkish",languagePackageVersionId:474,version:"0.0.4",languagePackageId:57,apduInstallUrl:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr.apdu",apduUninstallUrl:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr_del.apdu",bytes:20800,dateCreation:"2025-03-04T10:48:27.910630Z",dateLastModified:"2025-03-04T10:48:27.910630Z"},{language:"russian",languagePackageVersionId:470,version:"0.0.4",languagePackageId:56,apduInstallUrl:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru.apdu",apduUninstallUrl:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru_del.apdu",bytes:46592,dateCreation:"2025-03-04T10:48:26.218729Z",dateLastModified:"2025-03-04T10:48:26.218729Z"}]))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{language:"turkish",version:"0.0.4",language_package_id:"invalid"}])));const e=await r.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getMcuList",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the list of MCUs",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{id:1,mcu:1,name:"1.0",description:null,providers:[1],device_versions:[1,2],from_bootloader_version:"1.0",from_bootloader_version_id:2,se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.156394Z",date_last_modified:"2018-09-20T13:30:50.156453Z"},{id:2,mcu:1,name:"1.1",description:null,providers:[1,2],device_versions:[1,2],from_bootloader_version:"1.0",from_bootloader_version_id:2,se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.339966Z",date_last_modified:"2018-09-20T13:30:50.340031Z"}])));const e=await r.getMcuList();expect(e).toEqual((0,s.Right)([{id:1,name:"1.0",fromBootloaderVersion:"1.0",providers:[1]},{id:2,name:"1.1",fromBootloaderVersion:"1.0",providers:[1,2]}]))}),it("should return an error when the payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{id:"invalid id",mcu:1,name:"1.0",description:null,providers:[],se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.156394Z",date_last_modified:"2018-09-20T13:30:50.156453Z"}])));const e=await r.getMcuList();expect(e.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const e=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(e);const a=await r.getMcuList();expect(a).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getProvider",()=>{let r;beforeEach(()=>{r=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",provider:123})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the initial provider",()=>{expect(r.getProvider()).toBe(123)}),it("should return the updated provider after setProvider is called",()=>{r.setProvider(321),expect(r.getProvider()).toBe(321)})})});
|
|
1
|
+
"use strict";var t=require("purify-ts"),s=require("../../../api/device-action/__test-utils__/data"),p=require("../../logger-publisher/service/DefaultLoggerPublisherService"),n=require("../../manager-api/model/Errors"),i=require("./HttpManagerApiDataSource");const d=new p.DefaultLoggerPublisherService([],"HttpManagerApiDataSourceTest"),o=()=>d;describe("HttpManagerApiDataSource",()=>{describe("getAppList",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a list of applications",async()=>{const r=[s.BTC_APP_METADATA,s.ETH_APP_METADATA];vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify(r)));const a=await e.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(a).toEqual((0,t.Right)(r))}),it("should return an error if payload don't match the dto",async()=>{const{versionId:r,...a}=s.BTC_APP_METADATA,l=[{versionId:"invalidVersion",...a}];vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify(l)));const c=await e.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(c.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("with BTC app, should return the metadata",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([s.BTC_APP_METADATA])));const r=[s.BTC_APP.appFullHash],a=await e.getAppsByHash({hashes:r});expect(a).toEqual((0,t.Right)([s.BTC_APP_METADATA]))}),it("with no apps, should return an empty list",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([])));const r=[],a=await e.getAppsByHash({hashes:r});expect(a).toEqual((0,t.Right)([]))}),it("with BTC app and custom lock screen, should return the metadata",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([s.BTC_APP_METADATA,s.CUSTOM_LOCK_SCREEN_APP_METADATA])));const r=[s.BTC_APP.appFullHash,s.CUSTOM_LOCK_SCREEN_APP.appFullHash],a=await e.getAppsByHash({hashes:r});expect(a).toEqual((0,t.Right)([s.BTC_APP_METADATA,s.CUSTOM_LOCK_SCREEN_APP_METADATA]))})}),describe("error cases",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("with BTC app, should fail if payload don't match the dto",async()=>{const{versionId:r,...a}=s.BTC_APP_METADATA;vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{versionId:"invalidVersion",...a}])));const l=[s.BTC_APP.appFullHash],c=await e.getAppsByHash({hashes:l});expect(c.isRight()).toEqual(!1)}),it("should throw an error if the request fails",async()=>{const r=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o),a=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(a);const l=[s.BTC_APP.appFullHash],c=await r.getAppsByHash({hashes:l});expect(c).toEqual((0,t.Left)(new n.HttpFetchApiError(a)))})})}),describe("getDeviceVersion",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete device version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:17,target_id:"857735172"})));const r=await e.getDeviceVersion({targetId:"targetId"});expect(r).toEqual((0,t.Right)({id:17}))}),it("should return an error if payload don't match dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({target_id:"857735172"})));const r=await e.getDeviceVersion({targetId:"targetId"});expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getDeviceVersion({targetId:"targetId"});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("getFirmwareVersion",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const r=await e.getFirmwareVersion({version:"versionName",deviceId:42});expect(r).toEqual((0,t.Right)({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmwareKey:"testKey",hash:"hash",bytes:194,mcuVersions:[1,5,7]}))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:"invalidId",version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const r=await e.getFirmwareVersion({version:"versionName",deviceId:42});expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getFirmwareVersion({version:"versionName",deviceId:42});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("setProvider",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",provider:1},o)}),it("should not change the provider if the new value is the same",()=>{const r=e._provider;e.setProvider(r),expect(e._provider).toBe(r)}),it("should not change the provider if the new value is less than 1",()=>{const r=e._provider;e.setProvider(0),e.setProvider(-5),expect(e._provider).toBe(r)}),it("should update the provider if a valid and different value is provided",()=>{e.setProvider(2),expect(e._provider).toBe(2)})}),describe("getFirmwareVersionById",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmware_key:"testKey",hash:"hash",bytes:194,mcu_versions:[1,5,7]})));const r=await e.getFirmwareVersionById(42);expect(r).toEqual((0,t.Right)({id:361,version:"1.6.0",perso:"perso_11",firmware:null,firmwareKey:"testKey",hash:"hash",bytes:194,mcuVersions:[1,5,7]}))})}),describe("getLatestFirmwareVersion",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the latest firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"success",se_firmware_osu_version:{id:361,perso:"perso_11",notes:"notes",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567}})));const r=await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(r).toEqual((0,t.Right)((0,t.Just)({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmwareKey:"testKey",hash:"hash",nextFinalFirmware:567})))}),it("should return nothing when no latest firmware version is available",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"null",se_firmware_osu_version:null})));const r=await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(r).toEqual((0,t.Right)(t.Nothing))}),it("should return an error if result is not success",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"failed",se_firmware_osu_version:null})));const r=await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(r.isRight()).toEqual(!1)}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"success",se_firmware_osu_version:{id:"InvalidId",perso:"perso_11",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567}})));const r=await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))}),it("should request the firmware params without the legacy livecommonversion param",async()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost",provider:82,firmwareDistributionSalt:"distribution-salt"},o);const r=vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"null",se_firmware_osu_version:null})));await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});const a=new URL(String(r.mock.calls[0][0]));expect(a.pathname).toEqual("/get_latest_firmware"),expect(a.searchParams.has("livecommonversion")).toEqual(!1),expect(Object.fromEntries(a.searchParams)).toEqual({current_se_firmware_final_version:"200",device_version:"42",provider:"82",salt:"distribution-salt"})}),it("should request and log the salt set at runtime",async()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost",provider:82,firmwareDistributionSalt:"distribution-salt"},o),e.setFirmwareDistributionSalt("runtime-salt");const r=vi.spyOn(d,"info"),a=vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({result:"null",se_firmware_osu_version:null})));await e.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});const l=new URL(String(a.mock.calls[0][0]));expect(l.searchParams.get("salt")).toEqual("runtime-salt"),expect(r).toHaveBeenCalledWith("Requesting latest firmware",{data:{salt:"runtime-salt"}})})}),describe("getOsuFirmwareVersion",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a complete OSU firmware version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567})));const r=await e.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(r).toEqual((0,t.Right)({id:361,perso:"perso_11",notes:"notes",firmware:"test",firmwareKey:"testKey",hash:"hash",nextFinalFirmware:567}))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify({id:"invalidId",perso:"perso_11",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567})));const r=await e.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("getLanguagePackages",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the langage packages version",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{language:"turkish",languagePackageVersionId:474,version:"0.0.4",language_package_id:57,apdu_install_url:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr.apdu",apdu_uninstall_url:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr_del.apdu",device_versions:[17],se_firmware_final_versions:[432],bytes:20800,date_creation:"2025-03-04T10:48:27.910630Z",date_last_modified:"2025-03-04T10:48:27.910630Z"},{language:"russian",languagePackageVersionId:470,version:"0.0.4",language_package_id:56,apdu_install_url:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru.apdu",apdu_uninstall_url:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru_del.apdu",device_versions:[17],se_firmware_final_versions:[432],bytes:46592,date_creation:"2025-03-04T10:48:26.218729Z",date_last_modified:"2025-03-04T10:48:26.218729Z"}])));const r=await e.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(r).toEqual((0,t.Right)([{language:"turkish",languagePackageVersionId:474,version:"0.0.4",languagePackageId:57,apduInstallUrl:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr.apdu",apduUninstallUrl:"https://download.languages.ledger.com/stax/turkish/bolos_1.6.2_pack_0.0.4_tr_del.apdu",bytes:20800,dateCreation:"2025-03-04T10:48:27.910630Z",dateLastModified:"2025-03-04T10:48:27.910630Z"},{language:"russian",languagePackageVersionId:470,version:"0.0.4",languagePackageId:56,apduInstallUrl:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru.apdu",apduUninstallUrl:"https://download.languages.ledger.com/stax/russian/bolos_1.6.2_pack_0.0.4_ru_del.apdu",bytes:46592,dateCreation:"2025-03-04T10:48:26.218729Z",dateLastModified:"2025-03-04T10:48:26.218729Z"}]))}),it("should return an error if payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{language:"turkish",version:"0.0.4",language_package_id:"invalid"}])));const r=await e.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("getMcuList",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the list of MCUs",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{id:1,mcu:1,name:"1.0",description:null,providers:[1],device_versions:[1,2],from_bootloader_version:"1.0",from_bootloader_version_id:2,se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.156394Z",date_last_modified:"2018-09-20T13:30:50.156453Z"},{id:2,mcu:1,name:"1.1",description:null,providers:[1,2],device_versions:[1,2],from_bootloader_version:"1.0",from_bootloader_version_id:2,se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.339966Z",date_last_modified:"2018-09-20T13:30:50.340031Z"}])));const r=await e.getMcuList();expect(r).toEqual((0,t.Right)([{id:1,name:"1.0",fromBootloaderVersion:"1.0",providers:[1]},{id:2,name:"1.1",fromBootloaderVersion:"1.0",providers:[1,2]}]))}),it("should return an error when the payload don't match the dto",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{id:"invalid id",mcu:1,name:"1.0",description:null,providers:[],se_firmware_final_versions:[7,12,13,14,15],date_creation:"2018-09-20T13:30:50.156394Z",date_last_modified:"2018-09-20T13:30:50.156453Z"}])));const r=await e.getMcuList();expect(r.isRight()).toEqual(!1)}),it("should return an error if the request fails",async()=>{const r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const a=await e.getMcuList();expect(a).toEqual((0,t.Left)(new n.HttpFetchApiError(r)))})}),describe("getProvider",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",provider:123},o)}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the initial provider",()=>{expect(e.getProvider()).toBe(123)}),it("should return the updated provider after setProvider is called",()=>{e.setProvider(321),expect(e.getProvider()).toBe(321)})}),describe("setFirmwareDistributionSalt / getFirmwareDistributionSalt",()=>{let e;beforeEach(()=>{e=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",firmwareDistributionSalt:"initial-salt"},o)}),it("should return the initial salt",()=>{expect(e.getFirmwareDistributionSalt()).toBe("initial-salt")}),it("should return the updated salt after setFirmwareDistributionSalt is called",()=>{e.setFirmwareDistributionSalt("new-salt"),expect(e.getFirmwareDistributionSalt()).toBe("new-salt")}),it("should not change the salt if the new value is empty",()=>{e.setFirmwareDistributionSalt(""),e.setFirmwareDistributionSalt(" "),expect(e.getFirmwareDistributionSalt()).toBe("initial-salt")})})});
|
|
2
2
|
//# sourceMappingURL=HttpManagerApiDataSource.test.js.map
|