@ledgerhq/device-management-kit 0.0.0-develop-20260730002409 → 0.0.0-develop-20260801002526
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
- package/lib/cjs/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js +1 -1
- package/lib/cjs/src/internal/manager-api/data/HttpManagerApiDataSource.js.map +2 -2
- 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 +2 -2
- 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/model/Firmware.js +1 -1
- package/lib/cjs/src/internal/manager-api/model/Firmware.js.map +1 -1
- package/lib/cjs/src/internal/manager-api/service/ManagerApiService.js.map +1 -1
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.js.map +3 -3
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js +1 -1
- package/lib/esm/src/api/device-action/task/GetFirmwareMetadataTask.test.js.map +3 -3
- 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/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts +2 -0
- package/lib/types/src/api/device-action/task/GetFirmwareMetadataTask.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/data/HttpManagerApiDataSource.d.ts +2 -2
- 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 +4 -4
- package/lib/types/src/internal/manager-api/data/ManagerApiDataSource.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/model/Firmware.d.ts +2 -0
- package/lib/types/src/internal/manager-api/model/Firmware.d.ts.map +1 -1
- package/lib/types/src/internal/manager-api/service/DefaultManagerApiService.d.ts +1 -1
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts +3 -3
- package/lib/types/src/internal/manager-api/service/ManagerApiService.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +1 -1
package/lib/cjs/package.json
CHANGED
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
63
63
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
64
64
|
},
|
|
65
|
-
"version": "0.0.0-develop-
|
|
65
|
+
"version": "0.0.0-develop-20260801002526"
|
|
66
66
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var R=(n,e)=>{for(var a in e)p(n,a,{get:e[a],enumerable:!0})},M=(n,e,a,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of v(e))!C.call(n,r)&&r!==a&&p(n,r,{get:()=>e[r],enumerable:!(t=V(e,r))||t.enumerable});return n};var U=n=>M(p({},"__esModule",{value:!0}),n);var G={};R(G,{GetFirmwareMetadataTask:()=>k});module.exports=U(G);var u=require("../../command/model/CommandResult"),F=require("../../command/os/GetBackgroundImageSizeCommand"),l=require("../../command/os/GetOsVersionCommand"),g=require("../../device-action/task/Errors"),m=require("../../model/DmkResult");class k{constructor(e){this.api=e}async run(){const e=await this.api.sendCommand(new l.GetOsVersionCommand);if(!(0,u.isSuccessCommandResult)(e))return(0,m.DmkResultFactory)({error:e.error});const a={mcu:e.data.mcuSephVersion,bootloader:e.data.mcuBootloaderVersion,os:e.data.seVersion,metadata:e.data},t=this.api.getManagerApiService(),r=await t.getDeviceVersion(e.data).chain(f=>t.getFirmwareVersion(e.data,f).map(y=>({deviceVersion:f,currentFirmware:y})));if(r.isLeft())return(0,m.DmkResultFactory)({error:new g.InvalidGetFirmwareMetadataResponseError});const{deviceVersion:o,currentFirmware:i}=r.unsafeCoerce(),s=await this.getAvailableUpdate(t,i,o,a),d={currentFirmware:i,availableUpdate:s};let c={};const w=await this.api.sendCommand(new F.GetBackgroundImageSizeCommand);return(0,u.isSuccessCommandResult)(w)&&(c={size:w.data}),(0,m.DmkResultFactory)({data:{deviceVersion:o,firmware:i,firmwareVersion:a,firmwareUpdateContext:d,customImage:c}})}async getAvailableUpdate(e,a,t,r){const o=await e.getLatestFirmwareVersion(a,t);if(o.isLeft())return;const i=o.unsafeCoerce();if(!i.isNothing())return this.getFirmwareUpdate(e,i.unsafeCoerce(),r)}async getFirmwareUpdate(e,a,t){const r=await e.getNextFirmwareVersion(a);if(r.isLeft())return;const o=await e.getMcuList();if(o.isLeft())return;const i=r.unsafeCoerce(),s=o.unsafeCoerce().find(d=>d.name===t.mcu);return{osuFirmware:a,finalFirmware:i,mcuUpdateRequired:s===void 0||!i.mcuVersions.includes(s.id)}}}0&&(module.exports={GetFirmwareMetadataTask});
|
|
2
2
|
//# sourceMappingURL=GetFirmwareMetadataTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/GetFirmwareMetadataTask.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type CommandErrorResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { GetBackgroundImageSizeCommand } from \"@api/command/os/GetBackgroundImageSizeCommand\";\nimport { GetOsVersionCommand } from \"@api/command/os/GetOsVersionCommand\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport {\n type CustomImage,\n type FirmwareUpdate,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DmkResult, DmkResultFactory } from \"@api/model/DmkResult\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport {
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,4CACPC,EAA8C,yDAC9CC,EAAoC,+CAEpCC,EAAwD,0CAOxDC,EAAiD,
|
|
6
|
-
"names": ["GetFirmwareMetadataTask_exports", "__export", "GetFirmwareMetadataTask", "__toCommonJS", "import_CommandResult", "import_GetBackgroundImageSizeCommand", "import_GetOsVersionCommand", "import_Errors", "import_DmkResult", "api", "osVersion", "firmwareVersion", "manager", "result", "deviceVersion", "currentFirmware", "availableUpdate", "
|
|
4
|
+
"sourcesContent": ["import {\n type CommandErrorResult,\n isSuccessCommandResult,\n} from \"@api/command/model/CommandResult\";\nimport { GetBackgroundImageSizeCommand } from \"@api/command/os/GetBackgroundImageSizeCommand\";\nimport { GetOsVersionCommand } from \"@api/command/os/GetOsVersionCommand\";\nimport type { InternalApi } from \"@api/device-action/DeviceAction\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport {\n type CustomImage,\n type FirmwareUpdate,\n type FirmwareUpdateContext,\n type FirmwareVersion,\n} from \"@api/device-session/DeviceSessionState\";\nimport { type DmkResult, DmkResultFactory } from \"@api/model/DmkResult\";\nimport { type DeviceVersion } from \"@internal/manager-api/model/Device\";\nimport {\n type FinalFirmware,\n type OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nexport type GetFirmwareMetadataTaskResponse = {\n deviceVersion: DeviceVersion;\n firmware: FinalFirmware;\n firmwareVersion: FirmwareVersion;\n firmwareUpdateContext: FirmwareUpdateContext;\n customImage: CustomImage;\n};\n\nexport type GetFirmwareMetadataTaskError =\n | CommandErrorResult[\"error\"]\n | InvalidGetFirmwareMetadataResponseError;\n\nexport type GetFirmwareMetadataTaskResult = DmkResult<\n GetFirmwareMetadataTaskResponse,\n GetFirmwareMetadataTaskError\n>;\n\nexport class GetFirmwareMetadataTask {\n constructor(private readonly api: InternalApi) {}\n\n async run(): Promise<GetFirmwareMetadataTaskResult> {\n // Get installed firmware metadata\n const osVersion = await this.api.sendCommand(new GetOsVersionCommand());\n if (!isSuccessCommandResult(osVersion)) {\n return DmkResultFactory({\n error: osVersion.error,\n });\n }\n const firmwareVersion: FirmwareVersion = {\n mcu: osVersion.data.mcuSephVersion,\n bootloader: osVersion.data.mcuBootloaderVersion,\n os: osVersion.data.seVersion,\n metadata: osVersion.data,\n };\n\n // Fetch current firmware metadata from app store\n const manager = this.api.getManagerApiService();\n const result = await manager\n .getDeviceVersion(osVersion.data)\n .chain((deviceVersion) =>\n manager\n .getFirmwareVersion(osVersion.data, deviceVersion)\n .map((currentFirmware) => ({ deviceVersion, currentFirmware })),\n );\n if (result.isLeft()) {\n return DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n });\n }\n const { deviceVersion, currentFirmware } = result.unsafeCoerce();\n\n const availableUpdate = await this.getAvailableUpdate(\n manager,\n currentFirmware,\n deviceVersion,\n firmwareVersion,\n );\n\n const firmwareUpdateContext = {\n currentFirmware,\n availableUpdate,\n };\n\n // Get custom image metadata\n let customImage: CustomImage = {};\n const imageSize = await this.api.sendCommand(\n new GetBackgroundImageSizeCommand(),\n );\n if (isSuccessCommandResult(imageSize)) {\n customImage = { size: imageSize.data };\n }\n\n // Return firmware metadata\n return DmkResultFactory({\n data: {\n deviceVersion,\n firmware: currentFirmware,\n firmwareVersion,\n firmwareUpdateContext,\n customImage,\n },\n });\n }\n\n private async getAvailableUpdate(\n manager: ManagerApiService,\n currentFirmware: FinalFirmware,\n deviceVersion: DeviceVersion,\n firmwareVersion: FirmwareVersion,\n ): Promise<FirmwareUpdate | undefined> {\n // Fetch latest firmware available, if any\n const maybeOsuFirmwareResult = await manager.getLatestFirmwareVersion(\n currentFirmware,\n deviceVersion,\n );\n if (maybeOsuFirmwareResult.isLeft()) {\n return undefined;\n }\n\n const maybeOsuFirmware = maybeOsuFirmwareResult.unsafeCoerce();\n if (maybeOsuFirmware.isNothing()) {\n return undefined;\n }\n\n return this.getFirmwareUpdate(\n manager,\n maybeOsuFirmware.unsafeCoerce(),\n firmwareVersion,\n );\n }\n\n private async getFirmwareUpdate(\n manager: ManagerApiService,\n osuFirmware: OsuFirmware,\n firmwareVersion: FirmwareVersion,\n ): Promise<FirmwareUpdate | undefined> {\n const finalFirmwareResult =\n await manager.getNextFirmwareVersion(osuFirmware);\n if (finalFirmwareResult.isLeft()) {\n return undefined;\n }\n\n const mcusResult = await manager.getMcuList();\n if (mcusResult.isLeft()) {\n return undefined;\n }\n\n const finalFirmware = finalFirmwareResult.unsafeCoerce();\n const mcu = mcusResult\n .unsafeCoerce()\n .find((candidate) => candidate.name === firmwareVersion.mcu);\n\n return {\n osuFirmware,\n finalFirmware,\n mcuUpdateRequired:\n mcu === undefined || !finalFirmware.mcuVersions.includes(mcu.id),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,G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C3CG,EACAD,CACF,EACA,GAAIM,EAAuB,OAAO,EAChC,OAGF,MAAMC,EAAmBD,EAAuB,aAAa,EAC7D,GAAI,CAAAC,EAAiB,UAAU,EAI/B,OAAO,KAAK,kBACVT,EACAS,EAAiB,aAAa,EAC9BV,CACF,CACF,CAEA,MAAc,kBACZC,EACAU,EACAX,EACqC,CACrC,MAAMY,EACJ,MAAMX,EAAQ,uBAAuBU,CAAW,EAClD,GAAIC,EAAoB,OAAO,EAC7B,OAGF,MAAMC,EAAa,MAAMZ,EAAQ,WAAW,EAC5C,GAAIY,EAAW,OAAO,EACpB,OAGF,MAAMC,EAAgBF,EAAoB,aAAa,EACjDG,EAAMF,EACT,aAAa,EACb,KAAMG,GAAcA,EAAU,OAAShB,EAAgB,GAAG,EAE7D,MAAO,CACL,YAAAW,EACA,cAAAG,EACA,kBACEC,IAAQ,QAAa,CAACD,EAAc,YAAY,SAASC,EAAI,EAAE,CACnE,CACF,CACF",
|
|
6
|
+
"names": ["GetFirmwareMetadataTask_exports", "__export", "GetFirmwareMetadataTask", "__toCommonJS", "import_CommandResult", "import_GetBackgroundImageSizeCommand", "import_GetOsVersionCommand", "import_Errors", "import_DmkResult", "api", "osVersion", "firmwareVersion", "manager", "result", "deviceVersion", "currentFirmware", "availableUpdate", "firmwareUpdateContext", "customImage", "imageSize", "maybeOsuFirmwareResult", "maybeOsuFirmware", "osuFirmware", "finalFirmwareResult", "mcusResult", "finalFirmware", "mcu", "candidate"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=require("purify-ts"),d=require("../../command/Errors"),o=require("../../command/model/CommandResult"),p=require("../../device-action/__test-utils__/makeInternalApi"),V=require("../../device-action/task/Errors"),c=require("../../model/DmkResult"),m=require("./GetFirmwareMetadataTask");describe("GetFirmwareMetadataTask",()=>{const e=(0,p.makeDeviceActionInternalApiMock)(),a={mcuSephVersion:"mcu_version",mcuBootloaderVersion:"bl_version",seVersion:"se_version"},w=97,u={id:7},i={id:361,version:"1.6.0",perso:"perso_11"},l={id:362,perso:"perso_11",notes:"notes"},v={id:363,version:"1.7.0",perso:"perso_11",mcuVersions:[1]},f=[{id:3,name:"other_version",fromBootloaderVersion:"1.0"},{id:1,name:"mcu_version",fromBootloaderVersion:"1.0"}],t={getDeviceVersion:vi.fn(),getFirmwareVersion:vi.fn(),getLatestFirmwareVersion:vi.fn(),getNextFirmwareVersion:vi.fn(),getMcuList:vi.fn()};beforeEach(()=>{vi.resetAllMocks(),e.getManagerApiService.mockReturnValue(t),t.getDeviceVersion.mockReturnValue((0,n.EitherAsync)(async()=>u)),t.getFirmwareVersion.mockReturnValue((0,n.EitherAsync)(async()=>i)),t.getLatestFirmwareVersion.mockReturnValue((0,n.EitherAsync)(async()=>(0,n.Just)(l))),t.getNextFirmwareVersion.mockReturnValue((0,n.EitherAsync)(async()=>v)),t.getMcuList.mockReturnValue((0,n.EitherAsync)(async()=>f))}),it("success with no firmware update available",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({data:w})),t.getLatestFirmwareVersion.mockReturnValueOnce((0,n.EitherAsync)(async()=>n.Nothing));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:void 0},customImage:{size:w}}}))}),it("success with no firmware update when latest firmware cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({data:w})),t.getLatestFirmwareVersion.mockReturnValueOnce((0,n.EitherAsync)(async({throwE:s})=>{s(new Error("error"))}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:void 0},customImage:{size:w}}}))}),it("success with a firmware update available",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:{osuFirmware:l,finalFirmware:v,mcuUpdateRequired:!1}},customImage:{}}})),expect(t.getDeviceVersion).toHaveBeenCalledWith(a),expect(t.getFirmwareVersion).toHaveBeenCalledWith(a,u),expect(t.getLatestFirmwareVersion).toHaveBeenCalledWith(i,u),expect(t.getNextFirmwareVersion).toHaveBeenCalledWith(l)}),it("success with a firmware update available and MCU update",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")}));const r={...v,mcuVersions:[3]};t.getNextFirmwareVersion.mockReturnValue((0,n.EitherAsync)(async()=>r));const s=await new m.GetFirmwareMetadataTask(e).run();expect(s).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:{osuFirmware:l,finalFirmware:r,mcuUpdateRequired:!0}},customImage:{}}}))}),it("success with a firmware update available when current MCU is unknown",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")})),t.getMcuList.mockReturnValueOnce((0,n.EitherAsync)(async()=>[{id:3,name:"other_version",fromBootloaderVersion:"1.0"}]));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:{osuFirmware:l,finalFirmware:v,mcuUpdateRequired:!0}},customImage:{}}}))}),it("success with no firmware update when next firmware cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")})),t.getNextFirmwareVersion.mockReturnValueOnce((0,n.EitherAsync)(async({throwE:s})=>{s(new Error("error"))}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:void 0},customImage:{}}}))}),it("success with no firmware update when MCU list cannot be fetched",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})).mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")})),t.getMcuList.mockReturnValueOnce((0,n.EitherAsync)(async({throwE:s})=>{s(new Error("error"))}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({data:{deviceVersion:u,firmware:i,firmwareVersion:{mcu:"mcu_version",bootloader:"bl_version",os:"se_version",metadata:a},firmwareUpdateContext:{currentFirmware:i,availableUpdate:void 0},customImage:{}}}))}),it("should fail when OS version cannot be retrieved",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({error:new d.InvalidStatusWordError("error")}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({error:new d.InvalidStatusWordError("error")}))}),it("should fail if device version cannot be fetched with InvalidGetFirmwareMetadataResponseError",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})),t.getDeviceVersion.mockReturnValueOnce((0,n.EitherAsync)(async({throwE:s})=>{s(new Error("error"))}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({error:new V.InvalidGetFirmwareMetadataResponseError}))}),it("should fail if firmware version cannot be fetched with InvalidGetFirmwareMetadataResponseError",async()=>{e.sendCommand.mockResolvedValueOnce((0,o.CommandResultFactory)({data:a})),t.getFirmwareVersion.mockReturnValueOnce((0,n.EitherAsync)(async({throwE:s})=>{s(new Error("error"))}));const r=await new m.GetFirmwareMetadataTask(e).run();expect(r).toStrictEqual((0,c.DmkResultFactory)({error:new V.InvalidGetFirmwareMetadataResponseError}))})});
|
|
2
2
|
//# sourceMappingURL=GetFirmwareMetadataTask.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/device-action/task/GetFirmwareMetadataTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { EitherAsync } from \"purify-ts\";\n\nimport { InvalidStatusWordError } from \"@api/command/Errors\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport { DmkResultFactory } from \"@api/model/DmkResult\";\nimport {\n type FinalFirmware,\n type McuFirmware,\n type OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { GetFirmwareMetadataTask } from \"./GetFirmwareMetadataTask\";\n\ndescribe(\"GetFirmwareMetadataTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const OS_VERSION = {\n mcuSephVersion: \"mcu_version\",\n mcuBootloaderVersion: \"bl_version\",\n seVersion: \"se_version\",\n } as GetOsVersionResponse;\n\n const CUSTOM_IMAGE_SIZE = 97;\n\n const DEVICE_VERSION = {\n id: 7,\n };\n\n const FIRMWARE_VERSION = {\n id: 361,\n version: \"1.6.0\",\n perso: \"perso_11\",\n } as FinalFirmware;\n\n const OSU_VERSION = {\n id: 362,\n perso: \"perso_11\",\n } as OsuFirmware;\n\n const NEXT_FIRMWARE_VERSION = {\n id: 363,\n version: \"1.7.0\",\n perso: \"perso_11\",\n mcuVersions: [1],\n } as FinalFirmware;\n\n const MCUS = [\n {\n id: 3,\n name: \"other_version\",\n },\n {\n id: 1,\n name: \"mcu_version\",\n },\n ] as McuFirmware[];\n\n const MANAGER_MOCK = {\n getDeviceVersion: vi.fn(),\n getFirmwareVersion: vi.fn(),\n getLatestFirmwareVersion: vi.fn(),\n getNextFirmwareVersion: vi.fn(),\n getMcuList: vi.fn(),\n };\n\n beforeEach(() => {\n vi.clearAllMocks();\n\n apiMock.getManagerApiService.mockReturnValue(\n MANAGER_MOCK as unknown as ManagerApiService,\n );\n MANAGER_MOCK.getDeviceVersion.mockReturnValue(\n EitherAsync(async () => DEVICE_VERSION),\n );\n MANAGER_MOCK.getFirmwareVersion.mockReturnValue(\n EitherAsync(async () => FIRMWARE_VERSION),\n );\n MANAGER_MOCK.getLatestFirmwareVersion.mockReturnValue(\n EitherAsync(async () => OSU_VERSION),\n );\n MANAGER_MOCK.getNextFirmwareVersion.mockReturnValue(\n EitherAsync(async () => NEXT_FIRMWARE_VERSION),\n );\n MANAGER_MOCK.getMcuList.mockReturnValue(EitherAsync(async () => MCUS));\n });\n\n it(\"success with no firmware update available\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(CommandResultFactory({ data: CUSTOM_IMAGE_SIZE }));\n MANAGER_MOCK.getLatestFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: undefined,\n },\n customImage: { size: CUSTOM_IMAGE_SIZE },\n },\n }),\n );\n });\n\n it(\"success with a firmware update available\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: {\n osuFirmware: OSU_VERSION,\n finalFirmware: NEXT_FIRMWARE_VERSION,\n mcuUpdateRequired: false,\n },\n },\n customImage: {},\n },\n }),\n );\n expect(MANAGER_MOCK.getDeviceVersion).toHaveBeenCalledWith(OS_VERSION);\n expect(MANAGER_MOCK.getFirmwareVersion).toHaveBeenCalledWith(\n OS_VERSION,\n DEVICE_VERSION,\n );\n expect(MANAGER_MOCK.getLatestFirmwareVersion).toHaveBeenCalledWith(\n FIRMWARE_VERSION,\n DEVICE_VERSION,\n );\n expect(MANAGER_MOCK.getNextFirmwareVersion).toHaveBeenCalledWith(\n OSU_VERSION,\n );\n });\n\n it(\"success with a firmware update available and MCU update\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n const nextFirmware = {\n ...NEXT_FIRMWARE_VERSION,\n mcuVersions: [3],\n };\n MANAGER_MOCK.getNextFirmwareVersion.mockReturnValue(\n EitherAsync(async () => nextFirmware),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: {\n osuFirmware: OSU_VERSION,\n finalFirmware: nextFirmware,\n mcuUpdateRequired: true,\n },\n },\n customImage: {},\n },\n }),\n );\n });\n\n it(\"should fail when OS version cannot be retrieved\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n });\n\n it(\"should fail if device version cannot be fetched with InvalidGetFirmwareMetadataResponseError\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: OS_VERSION }),\n );\n MANAGER_MOCK.getDeviceVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n }),\n );\n });\n\n it(\"should fail if firmware version cannot be fetched with InvalidGetFirmwareMetadataResponseError\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: OS_VERSION }),\n );\n MANAGER_MOCK.getFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n }),\n );\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,
|
|
6
|
-
"names": ["import_purify_ts", "import_Errors", "import_CommandResult", "import_makeInternalApi", "import_DmkResult", "import_GetFirmwareMetadataTask", "apiMock", "OS_VERSION", "CUSTOM_IMAGE_SIZE", "DEVICE_VERSION", "FIRMWARE_VERSION", "OSU_VERSION", "NEXT_FIRMWARE_VERSION", "MCUS", "MANAGER_MOCK", "
|
|
4
|
+
"sourcesContent": ["import { EitherAsync, Just, Nothing } from \"purify-ts\";\n\nimport { InvalidStatusWordError } from \"@api/command/Errors\";\nimport { CommandResultFactory } from \"@api/command/model/CommandResult\";\nimport { type GetOsVersionResponse } from \"@api/command/os/GetOsVersionCommand\";\nimport { makeDeviceActionInternalApiMock } from \"@api/device-action/__test-utils__/makeInternalApi\";\nimport { InvalidGetFirmwareMetadataResponseError } from \"@api/device-action/task/Errors\";\nimport { DmkResultFactory } from \"@api/model/DmkResult\";\nimport {\n type FinalFirmware,\n type McuFirmware,\n type OsuFirmware,\n} from \"@internal/manager-api/model/Firmware\";\nimport { type ManagerApiService } from \"@internal/manager-api/service/ManagerApiService\";\n\nimport { GetFirmwareMetadataTask } from \"./GetFirmwareMetadataTask\";\n\ndescribe(\"GetFirmwareMetadataTask\", () => {\n const apiMock = makeDeviceActionInternalApiMock();\n const OS_VERSION = {\n mcuSephVersion: \"mcu_version\",\n mcuBootloaderVersion: \"bl_version\",\n seVersion: \"se_version\",\n } as GetOsVersionResponse;\n\n const CUSTOM_IMAGE_SIZE = 97;\n\n const DEVICE_VERSION = {\n id: 7,\n };\n\n const FIRMWARE_VERSION = {\n id: 361,\n version: \"1.6.0\",\n perso: \"perso_11\",\n } as FinalFirmware;\n\n const OSU_VERSION = {\n id: 362,\n perso: \"perso_11\",\n notes: \"notes\",\n } as OsuFirmware;\n\n const NEXT_FIRMWARE_VERSION = {\n id: 363,\n version: \"1.7.0\",\n perso: \"perso_11\",\n mcuVersions: [1],\n } as FinalFirmware;\n\n const MCUS = [\n {\n id: 3,\n name: \"other_version\",\n fromBootloaderVersion: \"1.0\",\n },\n {\n id: 1,\n name: \"mcu_version\",\n fromBootloaderVersion: \"1.0\",\n },\n ] as McuFirmware[];\n\n const MANAGER_MOCK = {\n getDeviceVersion: vi.fn(),\n getFirmwareVersion: vi.fn(),\n getLatestFirmwareVersion: vi.fn(),\n getNextFirmwareVersion: vi.fn(),\n getMcuList: vi.fn(),\n };\n\n beforeEach(() => {\n vi.resetAllMocks();\n\n apiMock.getManagerApiService.mockReturnValue(\n MANAGER_MOCK as unknown as ManagerApiService,\n );\n MANAGER_MOCK.getDeviceVersion.mockReturnValue(\n EitherAsync(async () => DEVICE_VERSION),\n );\n MANAGER_MOCK.getFirmwareVersion.mockReturnValue(\n EitherAsync(async () => FIRMWARE_VERSION),\n );\n MANAGER_MOCK.getLatestFirmwareVersion.mockReturnValue(\n EitherAsync(async () => Just(OSU_VERSION)),\n );\n MANAGER_MOCK.getNextFirmwareVersion.mockReturnValue(\n EitherAsync(async () => NEXT_FIRMWARE_VERSION),\n );\n MANAGER_MOCK.getMcuList.mockReturnValue(EitherAsync(async () => MCUS));\n });\n\n it(\"success with no firmware update available\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(CommandResultFactory({ data: CUSTOM_IMAGE_SIZE }));\n MANAGER_MOCK.getLatestFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async () => Nothing),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: undefined,\n },\n customImage: { size: CUSTOM_IMAGE_SIZE },\n },\n }),\n );\n });\n\n it(\"success with no firmware update when latest firmware cannot be fetched\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(CommandResultFactory({ data: CUSTOM_IMAGE_SIZE }));\n MANAGER_MOCK.getLatestFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: undefined,\n },\n customImage: { size: CUSTOM_IMAGE_SIZE },\n },\n }),\n );\n });\n\n it(\"success with a firmware update available\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: {\n osuFirmware: OSU_VERSION,\n finalFirmware: NEXT_FIRMWARE_VERSION,\n mcuUpdateRequired: false,\n },\n },\n customImage: {},\n },\n }),\n );\n expect(MANAGER_MOCK.getDeviceVersion).toHaveBeenCalledWith(OS_VERSION);\n expect(MANAGER_MOCK.getFirmwareVersion).toHaveBeenCalledWith(\n OS_VERSION,\n DEVICE_VERSION,\n );\n expect(MANAGER_MOCK.getLatestFirmwareVersion).toHaveBeenCalledWith(\n FIRMWARE_VERSION,\n DEVICE_VERSION,\n );\n expect(MANAGER_MOCK.getNextFirmwareVersion).toHaveBeenCalledWith(\n OSU_VERSION,\n );\n });\n\n it(\"success with a firmware update available and MCU update\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n const nextFirmware = {\n ...NEXT_FIRMWARE_VERSION,\n mcuVersions: [3],\n };\n MANAGER_MOCK.getNextFirmwareVersion.mockReturnValue(\n EitherAsync(async () => nextFirmware),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: {\n osuFirmware: OSU_VERSION,\n finalFirmware: nextFirmware,\n mcuUpdateRequired: true,\n },\n },\n customImage: {},\n },\n }),\n );\n });\n\n it(\"success with a firmware update available when current MCU is unknown\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n MANAGER_MOCK.getMcuList.mockReturnValueOnce(\n EitherAsync(async () => [\n {\n id: 3,\n name: \"other_version\",\n fromBootloaderVersion: \"1.0\",\n },\n ]),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: {\n osuFirmware: OSU_VERSION,\n finalFirmware: NEXT_FIRMWARE_VERSION,\n mcuUpdateRequired: true,\n },\n },\n customImage: {},\n },\n }),\n );\n });\n\n it(\"success with no firmware update when next firmware cannot be fetched\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n MANAGER_MOCK.getNextFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: undefined,\n },\n customImage: {},\n },\n }),\n );\n });\n\n it(\"success with no firmware update when MCU list cannot be fetched\", async () => {\n // GIVEN\n apiMock.sendCommand\n .mockResolvedValueOnce(CommandResultFactory({ data: OS_VERSION }))\n .mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n MANAGER_MOCK.getMcuList.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n data: {\n deviceVersion: DEVICE_VERSION,\n firmware: FIRMWARE_VERSION,\n firmwareVersion: {\n mcu: \"mcu_version\",\n bootloader: \"bl_version\",\n os: \"se_version\",\n metadata: OS_VERSION,\n },\n firmwareUpdateContext: {\n currentFirmware: FIRMWARE_VERSION,\n availableUpdate: undefined,\n },\n customImage: {},\n },\n }),\n );\n });\n\n it(\"should fail when OS version cannot be retrieved\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({ error: new InvalidStatusWordError(\"error\") }),\n );\n });\n\n it(\"should fail if device version cannot be fetched with InvalidGetFirmwareMetadataResponseError\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: OS_VERSION }),\n );\n MANAGER_MOCK.getDeviceVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n }),\n );\n });\n\n it(\"should fail if firmware version cannot be fetched with InvalidGetFirmwareMetadataResponseError\", async () => {\n // GIVEN\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({ data: OS_VERSION }),\n );\n MANAGER_MOCK.getFirmwareVersion.mockReturnValueOnce(\n EitherAsync(async ({ throwE }) => {\n throwE(new Error(\"error\"));\n }),\n );\n\n // WHEN\n const result = await new GetFirmwareMetadataTask(apiMock).run();\n\n // THEN\n expect(result).toStrictEqual(\n DmkResultFactory({\n error: new InvalidGetFirmwareMetadataResponseError(),\n }),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAA2C,qBAE3CC,EAAuC,+BACvCC,EAAqC,4CAErCC,EAAgD,6DAChDF,EAAwD,0CACxDG,EAAiC,gCAQjCC,EAAwC,qCAExC,SAAS,0BAA2B,IAAM,CACxC,MAAMC,KAAU,mCAAgC,EAC1CC,EAAa,CACjB,eAAgB,cAChB,qBAAsB,aACtB,UAAW,YACb,EAEMC,EAAoB,GAEpBC,EAAiB,CACrB,GAAI,CACN,EAEMC,EAAmB,CACvB,GAAI,IACJ,QAAS,QACT,MAAO,UACT,EAEMC,EAAc,CAClB,GAAI,IACJ,MAAO,WACP,MAAO,OACT,EAEMC,EAAwB,CAC5B,GAAI,IACJ,QAAS,QACT,MAAO,WACP,YAAa,CAAC,CAAC,CACjB,EAEMC,EAAO,CACX,CACE,GAAI,EACJ,KAAM,gBACN,sBAAuB,KACzB,EACA,CACE,GAAI,EACJ,KAAM,cACN,sBAAuB,KACzB,CACF,EAEMC,EAAe,CACnB,iBAAkB,GAAG,GAAG,EACxB,mBAAoB,GAAG,GAAG,EAC1B,yBAA0B,GAAG,GAAG,EAChC,uBAAwB,GAAG,GAAG,EAC9B,WAAY,GAAG,GAAG,CACpB,EAEA,WAAW,IAAM,CACf,GAAG,cAAc,EAEjBR,EAAQ,qBAAqB,gBAC3BQ,CACF,EACAA,EAAa,iBAAiB,mBAC5B,eAAY,SAAYL,CAAc,CACxC,EACAK,EAAa,mBAAmB,mBAC9B,eAAY,SAAYJ,CAAgB,CAC1C,EACAI,EAAa,yBAAyB,mBACpC,eAAY,YAAY,QAAKH,CAAW,C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,oBAAiB,CACf,MAAO,IAAI,yCACb,CAAC,CACH,CACF,CAAC,EAED,GAAG,iGAAkG,SAAY,CAE/GT,EAAQ,YAAY,yBAClB,wBAAqB,CAAE,KAAMC,CAAW,CAAC,CAC3C,EACAO,EAAa,mBAAmB,uBAC9B,eAAY,MAAO,CAAE,OAAAE,CAAO,IAAM,CAChCA,EAAO,IAAI,MAAM,OAAO,CAAC,CAC3B,CAAC,CACH,EAGA,MAAMD,EAAS,MAAM,IAAI,0BAAwBT,CAAO,EAAE,IAAI,EAG9D,OAAOS,CAAM,EAAE,iBACb,oBAAiB,CACf,MAAO,IAAI,yCACb,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_purify_ts", "import_Errors", "import_CommandResult", "import_makeInternalApi", "import_DmkResult", "import_GetFirmwareMetadataTask", "apiMock", "OS_VERSION", "CUSTOM_IMAGE_SIZE", "DEVICE_VERSION", "FIRMWARE_VERSION", "OSU_VERSION", "NEXT_FIRMWARE_VERSION", "MCUS", "MANAGER_MOCK", "result", "throwE", "nextFirmware"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var P=(
|
|
1
|
+
"use strict";var y=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var P=(n,e)=>{for(var r in e)y(n,r,{get:e[r],enumerable:!0})},k=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of b(e))!V.call(n,i)&&i!==r&&y(n,i,{get:()=>e[i],enumerable:!(t=h(e,i))||t.enumerable});return n};var I=n=>k(y({},"__esModule",{value:!0}),n),g=(n,e,r,t)=>{for(var i=t>1?void 0:t?h(e,r):e,a=n.length-1,p;a>=0;a--)(p=n[a])&&(i=(t?p(e,r,i):p(i))||i);return t&&i&&y(e,r,i),i},v=(n,e)=>(r,t)=>e(r,t,n);var T={};P(T,{HttpManagerApiDataSource:()=>l});module.exports=I(T);var u=require("inversify"),o=require("purify-ts"),d=require("../../../api/network/DmkNetworkClient"),A=require("../../../api/network/DmkNetworkClientError"),_=require("../../manager-api/di/managerApiTypes"),m=require("../../manager-api/model/Application"),w=require("../../manager-api/model/Const"),D=require("../../manager-api/model/Const"),f=require("../../manager-api/model/Errors"),c=require("./ManagerApiDto");const s=n=>n instanceof A.DmkNetworkClientError&&n.cause!==void 0?new f.HttpFetchApiError(n.cause):new f.HttpFetchApiError(n);let l=class{http;_provider=w.DEFAULT_PROVIDER;_firmwareDistributionSalt=D.DEFAULT_FIRMWARE_DISTRIBUTION_SALT;constructor({managerApiUrl:e,provider:r,firmwareDistributionSalt:t}){this.http=new d.DmkNetworkClient({baseUrl:e}),this._provider=r,this._firmwareDistributionSalt=t}setProvider(e){this._provider===e||e<1||(this._provider=e)}getProvider(){return this._provider}getAppList(e){const{targetId:r,firmwareVersionName:t}=e;return(0,o.EitherAsync)(()=>this.http.get("/v2/apps/by-target",{params:{target_id:r,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(e=>this.mapMcuDtoToMcu(e)).mapLeft(s)}getDeviceVersion(e){const{targetId:r}=e;return(0,o.EitherAsync)(()=>this.http.get("/get_device_version",{params:{target_id:r,provider:this._provider}})).chain(t=>this.mapDeviceVersionDto(t)).mapLeft(s)}getFirmwareVersion(e){const{deviceId:r,version:t}=e;return(0,o.EitherAsync)(()=>this.http.get("/get_firmware_version",{params:{device_version:r,version_name:t,provider:this._provider}})).chain(i=>this.mapFinalFirmwareDto(i)).mapLeft(s)}getFirmwareVersionById(e){return(0,o.EitherAsync)(()=>this.http.get(`/firmware_final_versions/${e}`)).chain(r=>this.mapFinalFirmwareDto(r)).mapLeft(s)}getOsuFirmwareVersion(e){const{deviceId:r,version:t}=e;return(0,o.EitherAsync)(()=>this.http.get("/get_osu_version",{params:{device_version:r,version_name:t,provider:this._provider}})).chain(i=>this.mapOsuFirmwareDto(i)).mapLeft(s)}getLatestFirmwareVersion(e){const r="34.27.0",{currentFinalFirmwareId:t,deviceId:i}=e;return(0,o.EitherAsync)(()=>this.http.get("/get_latest_firmware",{params:{current_se_firmware_final_version:t,device_version:i,provider:this._provider,salt:this._firmwareDistributionSalt,livecommonversion:r}})).chain(a=>this.mapLatestFirmwareDto(a)).mapLeft(s)}getAppsByHash(e){const{hashes:r}=e;return(0,o.EitherAsync)(()=>this.http.post("/v2/apps/hash",r)).chain(t=>this.mapNullableApplicationDtoToApplication(t)).mapLeft(s)}getLanguagePackages(e){const{deviceId:r,currentFinalFirmwareId:t}=e;return(0,o.EitherAsync)(()=>this.http.get("/language-packages",{params:{device_version:r,current_se_firmware_final_version:t}})).chain(i=>this.mapLanguagesDtoToLanguages(i)).mapLeft(s)}mapAppTypeDtoToAppType(e){if(e===null)return null;switch(e){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(e){return(0,o.EitherAsync)(()=>Promise.resolve(e.map(r=>this.mapApplicationDto(r))))}mapNullableApplicationDtoToApplication(e){return(0,o.EitherAsync)(()=>Promise.resolve(e.map(r=>r===null?null:this.mapApplicationDto(r))))}mapApplicationDto(e){if(typeof e!="object"||typeof e.versionId!="number"||typeof e.versionName!="string"||e.versionDisplayName!==null&&typeof e.versionDisplayName!="string"||typeof e.version!="string"||e.currencyId!==null&&typeof e.currencyId!="string"||e.description!==null&&typeof e.description!="string"||e.applicationType!==null&&typeof e.applicationType!="string"||typeof e.dateModified!="string"||e.icon!==null&&typeof e.icon!="string"||e.authorName!==null&&typeof e.authorName!="string"||e.supportURL!==null&&typeof e.supportURL!="string"||e.contactURL!==null&&typeof e.contactURL!="string"||e.sourceURL!==null&&typeof e.sourceURL!="string"||e.compatibleWallets!==null&&typeof e.compatibleWallets!="string"||typeof e.hash!="string"||typeof e.perso!="string"||typeof e.firmware!="string"||typeof e.firmwareKey!="string"||typeof e.delete!="string"||typeof e.deleteKey!="string"||e.bytes!==null&&typeof e.bytes!="number"||e.warning!==null&&typeof e.warning!="string"||typeof e.isDevTools!="boolean"||e.category!==null&&typeof e.category!="number"||e.parent!==null&&typeof e.parent!="number"||e.parentName!==null&&typeof e.parentName!="string")throw new Error(`Incomplete application: ${JSON.stringify(e)}`);const{applicationType:r,hash:t,perso:i,firmware:a,firmwareKey:p,delete:F,deleteKey:E,...L}=e;return{...L,hash:t,perso:i,firmware:a,firmwareKey:p,delete:F,deleteKey:E,applicationType:this.mapAppTypeDtoToAppType(r)}}mapMcuDtoToMcu(e){return(0,o.EitherAsync)(()=>Promise.resolve(e.map(r=>{if(typeof r!="object"||typeof r.id!="number"||typeof r.name!="string"||typeof r.from_bootloader_version!="string")throw new Error(`Incomplete MCU version: ${JSON.stringify(r)}`);return{id:r.id,name:r.name,fromBootloaderVersion:r.from_bootloader_version}})))}mapDeviceVersionDto(e){return(0,o.EitherAsync)(()=>{if(typeof e!="object"||typeof e.id!="number")throw new Error(`Incomplete device version: ${JSON.stringify(e)}`);const r={id:e.id};return Promise.resolve(r)})}mapFinalFirmwareDto(e){return(0,o.EitherAsync)(()=>{if(typeof e!="object"||typeof e.id!="number"||typeof e.version!="string"||typeof e.perso!="string"||e.firmware!==null&&typeof e.firmware!="string"||e.firmware_key!==null&&typeof e.firmware_key!="string"||e.hash!==null&&typeof e.hash!="string"||e.bytes!==null&&typeof e.bytes!="number"||!Array.isArray(e.mcu_versions))throw new Error(`Incomplete final firmware: ${JSON.stringify(e)}`);const r={id:e.id,version:e.version,perso:e.perso,firmware:e.firmware,firmwareKey:e.firmware_key,hash:e.hash,bytes:e.bytes,mcuVersions:e.mcu_versions};return Promise.resolve(r)})}mapLatestFirmwareDto(e){return(0,o.EitherAsync)(()=>{if(e.result==="null")return Promise.resolve(null);if(e.result!=="success"||!e.se_firmware_osu_version)throw new Error(`Latest firmware could not be retrieved: ${e.result}`);const r=e.se_firmware_osu_version;return Promise.resolve(r)}).chain(r=>r===null?(0,o.EitherAsync)(()=>Promise.resolve(o.Nothing)):this.mapOsuFirmwareDto(r).map(t=>(0,o.Just)(t)))}mapOsuFirmwareDto(e){return(0,o.EitherAsync)(()=>{if(typeof e!="object"||typeof e.id!="number"||e.notes!==null&&typeof e.notes!="string"||typeof e.perso!="string"||typeof e.firmware!="string"||typeof e.firmware_key!="string"||e.hash!==null&&typeof e.hash!="string"||typeof e.next_se_firmware_final_version!="number")throw new Error(`Incomplete latest firmware: ${JSON.stringify(e)}`);const r={id:e.id,notes:e.notes,perso:e.perso,firmware:e.firmware,firmwareKey:e.firmware_key,hash:e.hash,nextFinalFirmware:e.next_se_firmware_final_version};return Promise.resolve(r)})}mapLanguagesDtoToLanguages(e){return(0,o.EitherAsync)(()=>Promise.resolve(e.map(r=>this.mapLanguageDto(r))))}mapLanguageDto(e){if(typeof e!="object"||typeof e.language!="string"||typeof e.languagePackageVersionId!="number"||typeof e.version!="string"||typeof e.language_package_id!="number"||typeof e.apdu_install_url!="string"||typeof e.apdu_uninstall_url!="string"||typeof e.bytes!="number"||typeof e.date_creation!="string"||typeof e.date_last_modified!="string")throw new Error(`Incomplete language version: ${JSON.stringify(e)}`);return{language:e.language,languagePackageVersionId:e.languagePackageVersionId,version:e.version,languagePackageId:e.language_package_id,apduInstallUrl:e.apdu_install_url,apduUninstallUrl:e.apdu_uninstall_url,bytes:e.bytes,dateCreation:e.date_creation,dateLastModified:e.date_last_modified}}};l=g([(0,u.injectable)(),v(0,(0,u.inject)(_.managerApiTypes.DmkConfig))],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 } 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, OsuFirmware> {\n const livecommonversion = \"34.27.0\"; // Legacy parameter that should just be a too old\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 livecommonversion,\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 ) {\n throw new Error(`Incomplete MCU version: ${JSON.stringify(mcu)}`);\n }\n const ret: McuFirmware = {\n id: mcu.id,\n name: mcu.name,\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, OsuFirmware> {\n return EitherAsync<Error, FirmwareOsuVersionDto>(() => {\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) => this.mapOsuFirmwareDto(osuDto));\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 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 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,
|
|
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 livecommonversion = \"34.27.0\"; // Legacy parameter that should just be a too old\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 livecommonversion,\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 };\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,qBAGlDC,EAAiC,yCACjCC,EAAsC,8CACtCC,EAAgC,oDAChCC,EAGO,mDACPC,EAAiC,6CACjCA,EAAmD,6CAEnDC,EAAkC,8CAiBlCC,EASO,2BAEP,MAAMC,EAAuBC,GAIvBA,aAAiB,yBAAyBA,EAAM,QAAU,OACrD,IAAI,oBAAkBA,EAAM,KAAK,EAEnC,IAAI,oBAAkBA,CAAK,EAI7B,IAAMC,EAAN,KAA+D,CACnD,KACT,UAAoB,mBACpB,0BACN,qCAEF,YAEE,CAAE,cAAAC,EAAe,SAAAC,EAAU,yBAAAC,CAAyB,EACpD,CACA,KAAK,KAAO,IAAI,mBAAiB,CAAE,QAASF,CAAc,CAAC,EAC3D,KAAK,UAAYC,EACjB,KAAK,0BAA4BC,CACnC,CAEA,YAAYD,EAAwB,CAC9B,KAAK,YAAcA,GAAYA,EAAW,IAG9C,KAAK,UAAYA,EACnB,CAEA,aAAsB,CACpB,OAAO,KAAK,SACd,CAEA,WACEE,EACoD,CACpD,KAAM,CAAE,SAAAC,EAAU,oBAAAC,CAAoB,EAAIF,EAC1C,SAAO,eAAY,IACjB,KAAK,KAAK,IAAI,qBAAsB,CAClC,OAAQ,CACN,UAAWC,EACX,SAAU,KAAK,UACf,sBAAuBC,CACzB,CACF,CAAC,CACH,EACG,MAAOC,GACN,KAAK,+BAA+BA,CAA6B,CACnE,EACC,QAAQT,CAAmB,CAChC,CAEA,YAAiE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GAAa,UACpB,OAAOA,EAAS,UAAa,UAC7B,OAAOA,EAAS,0BAA6B,UAC7C,OAAOA,EAAS,SAAY,UAC5B,OAAOA,EAAS,qBAAwB,UACxC,OAAOA,EAAS,kBAAqB,UACrC,OAAOA,EAAS,oBAAuB,UACvC,OAAOA,EAAS,OAAU,UAC1B,OAAOA,EAAS,eAAkB,UAClC,OAAOA,EAAS,oBAAuB,SAEvC,MAAM,IAAI,MACR,gCAAgC,KAAK,UAAUA,CAAQ,CAAC,EAC1D,EAaF,MAX6B,CAC3B,SAAUA,EAAS,SACnB,yBAA0BA,EAAS,yBACnC,QAASA,EAAS,QAClB,kBAAmBA,EAAS,oBAC5B,eAAgBA,EAAS,iBACzB,iBAAkBA,EAAS,mBAC3B,MAAOA,EAAS,MAChB,aAAcA,EAAS,cACvB,iBAAkBA,EAAS,kBAC7B,CAEF,CACF,EArcajC,EAANkC,EAAA,IADN,cAAW,EAQPC,EAAA,eAAO,kBAAgB,SAAS,IAPxBnC",
|
|
6
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", "livecommonversion", "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 a;beforeEach(()=>{a=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 r=await a.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(r).toEqual((0,s.Right)(e))}),it("should return an error if payload don't match the dto",async()=>{const{versionId:e,...r}=t.BTC_APP_METADATA,n=[{versionId:"invalidVersion",...r}];vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify(n)));const l=await a.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 r=await a.getAppList({targetId:"targetId",firmwareVersionName:"firmwareVersionName"});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let a;beforeEach(()=>{a=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],r=await a.getAppsByHash({hashes:e});expect(r).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=[],r=await a.getAppsByHash({hashes:e});expect(r).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],r=await a.getAppsByHash({hashes:e});expect(r).toEqual((0,s.Right)([t.BTC_APP_METADATA,t.CUSTOM_LOCK_SCREEN_APP_METADATA]))})}),describe("error cases",()=>{let a;beforeEach(()=>{a=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,...r}=t.BTC_APP_METADATA;vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{versionId:"invalidVersion",...r}])));const n=[t.BTC_APP.appFullHash],l=await a.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"}),r=new Error("fetch error");vi.spyOn(globalThis,"fetch").mockRejectedValue(r);const n=[t.BTC_APP.appFullHash],l=await e.getAppsByHash({hashes:n});expect(l).toEqual((0,s.Left)(new o.HttpFetchApiError(r)))})})}),describe("getDeviceVersion",()=>{let a;beforeEach(()=>{a=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 a.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 a.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 r=await a.getDeviceVersion({targetId:"targetId"});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getFirmwareVersion",()=>{let a;beforeEach(()=>{a=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 a.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 a.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 r=await a.getFirmwareVersion({version:"versionName",deviceId:42});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("setProvider",()=>{let a;beforeEach(()=>{a=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=a._provider;a.setProvider(e),expect(a._provider).toBe(e)}),it("should not change the provider if the new value is less than 1",()=>{const e=a._provider;a.setProvider(0),a.setProvider(-5),expect(a._provider).toBe(e)}),it("should update the provider if a valid and different value is provided",()=>{a.setProvider(2),expect(a._provider).toBe(2)})}),describe("getFirmwareVersionById",()=>{let a;beforeEach(()=>{a=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 a.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 a;beforeEach(()=>{a=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",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567}})));const e=await a.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(e).toEqual((0,s.Right)({id:361,perso:"perso_11",firmware:"test",firmwareKey:"testKey",hash:"hash",nextFinalFirmware:567}))}),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 a.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 a.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 r=await a.getLatestFirmwareVersion({currentFinalFirmwareId:200,deviceId:42});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getOsuFirmwareVersion",()=>{let a;beforeEach(()=>{a=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",firmware:"test",firmware_key:"testKey",hash:"hash",next_se_firmware_final_version:567})));const e=await a.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(e).toEqual((0,s.Right)({id:361,perso:"perso_11",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 a.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 r=await a.getOsuFirmwareVersion({version:"versionName",deviceId:42});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getLanguagePackages",()=>{let a;beforeEach(()=>{a=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 a.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 a.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 r=await a.getLanguagePackages({deviceId:1,currentFinalFirmwareId:42});expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getMcuList",()=>{let a;beforeEach(()=>{a=new i.HttpManagerApiDataSource({managerApiUrl:"http://localhost"})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return a the list of MCUs",async()=>{vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response(JSON.stringify([{id:1,mcu:1,name:"1.0",description:null,providers:[],device_versions:[1,2],from_bootloader_version:"",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:[],device_versions:[1,2],from_bootloader_version:"",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 a.getMcuList();expect(e).toEqual((0,s.Right)([{id:1,name:"1.0"},{id:2,name:"1.1"}]))}),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 a.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 r=await a.getMcuList();expect(r).toEqual((0,s.Left)(new o.HttpFetchApiError(e)))})}),describe("getProvider",()=>{let a;beforeEach(()=>{a=new i.HttpManagerApiDataSource({managerApiUrl:"http://fake-url.com",provider:123})}),afterEach(()=>{vi.restoreAllMocks()}),it("should return the initial provider",()=>{expect(a.getProvider()).toBe(123)}),it("should return the updated provider after setProvider is called",()=>{a.setProvider(321),expect(a.getProvider()).toBe(321)})})});
|
|
1
|
+
"use strict";var s=require("purify-ts"),t=require("../../../api/device-action/__test-utils__/data"),i=require("../../manager-api/model/Errors"),o=require("./HttpManagerApiDataSource");describe("HttpManagerApiDataSource",()=>{describe("getAppList",()=>{let r;beforeEach(()=>{r=new o.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 i.HttpFetchApiError(e)))})}),describe("getAppsByHash",()=>{describe("success cases",()=>{let r;beforeEach(()=>{r=new o.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 o.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 o.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 i.HttpFetchApiError(a)))})})}),describe("getDeviceVersion",()=>{let r;beforeEach(()=>{r=new o.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 i.HttpFetchApiError(e)))})}),describe("getFirmwareVersion",()=>{let r;beforeEach(()=>{r=new o.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 i.HttpFetchApiError(e)))})}),describe("setProvider",()=>{let r;beforeEach(()=>{r=new o.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 o.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 o.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 i.HttpFetchApiError(e)))})}),describe("getOsuFirmwareVersion",()=>{let r;beforeEach(()=>{r=new o.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 i.HttpFetchApiError(e)))})}),describe("getLanguagePackages",()=>{let r;beforeEach(()=>{r=new o.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 i.HttpFetchApiError(e)))})}),describe("getMcuList",()=>{let r;beforeEach(()=>{r=new o.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:[],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:[],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"},{id:2,name:"1.1",fromBootloaderVersion:"1.0"}]))}),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 i.HttpFetchApiError(e)))})}),describe("getProvider",()=>{let r;beforeEach(()=>{r=new o.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)})})});
|
|
2
2
|
//# sourceMappingURL=HttpManagerApiDataSource.test.js.map
|