From 94afd9e0742d0e227b1e6ff953edee7a66ad61a3 Mon Sep 17 00:00:00 2001 From: Julien Nicoulaud Date: Tue, 20 Aug 2024 12:35:19 +0200 Subject: [PATCH] chore(BACK-7633): switch app store API endpoints from POST to GET when applicable This change will reduce load on the backend service and improve latency for clients. Related: - https://github.com/LedgerHQ/nano-appstore/releases/tag/v1.7.0 - https://github.com/LedgerHQ/tf-aws-production/pull/3546 --- .changeset/modern-pears-remain.md | 12 ++++ .../HttpManagerApiRepository.test.ts | 55 ++++++++++--------- .../repositories/HttpManagerApiRepository.ts | 38 +++++-------- .../src/appSupportsQuitApp.ts | 6 +- libs/ledger-live-common/src/manager/api.ts | 28 ++++------ 5 files changed, 69 insertions(+), 70 deletions(-) create mode 100644 .changeset/modern-pears-remain.md diff --git a/.changeset/modern-pears-remain.md b/.changeset/modern-pears-remain.md new file mode 100644 index 000000000000..2ce033057cac --- /dev/null +++ b/.changeset/modern-pears-remain.md @@ -0,0 +1,12 @@ +--- +"@ledgerhq/live-common": patch +"@ledgerhq/device-core": patch +--- + +chore(BACK-7633): switch app store API endpoints from POST to GET when applicable + +This change will reduce load on the backend service and improve latency for clients. + +Related: + - https://github.com/LedgerHQ/nano-appstore/releases/tag/v1.7.0 + - https://github.com/LedgerHQ/tf-aws-production/pull/3546 diff --git a/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.test.ts b/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.test.ts index 4310062fbac9..b4ca93508060 100644 --- a/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.test.ts +++ b/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.test.ts @@ -43,13 +43,14 @@ describe("HttpManagerApiRepository", () => { }); expect(networkSpy).toHaveBeenCalledWith({ - method: "POST", - url: "http://managerApiBase.com/get_latest_firmware?livecommonversion=1.2.3&salt=mockedFirmwareSalt", - data: { - current_se_firmware_final_version: 888, - device_version: 123, - provider: 12, - }, + method: "GET", + url: + "http://managerApiBase.com/get_latest_firmware" + + "?livecommonversion=1.2.3" + + "&salt=mockedFirmwareSalt" + + "¤t_se_firmware_final_version=888" + + "&device_version=123" + + "&provider=12", }); }); @@ -128,12 +129,12 @@ describe("HttpManagerApiRepository", () => { }); expect(networkSpy).toHaveBeenCalledWith({ - method: "POST", - url: "http://managerApiBase.com/get_device_version?livecommonversion=1.2.3", - data: { - target_id: 123, - provider: 12, - }, + method: "GET", + url: + "http://managerApiBase.com/get_device_version" + + "?livecommonversion=1.2.3" + + "&provider=12" + + "&target_id=123", }); }); @@ -190,13 +191,13 @@ describe("HttpManagerApiRepository", () => { }); expect(networkSpy).toHaveBeenCalledWith({ - method: "POST", - url: "http://managerApiBase.com/get_osu_version?livecommonversion=1.2.3", - data: { - device_version: 123, - provider: 12, - version_name: "mockedVersion-osu", - }, + method: "GET", + url: + "http://managerApiBase.com/get_osu_version" + + "?livecommonversion=1.2.3" + + "&device_version=123" + + "&version_name=mockedVersion-osu" + + "&provider=12", }); }); @@ -226,13 +227,13 @@ describe("HttpManagerApiRepository", () => { }); expect(networkSpy).toHaveBeenCalledWith({ - method: "POST", - url: "http://managerApiBase.com/get_firmware_version?livecommonversion=1.2.3", - data: { - device_version: 123, - provider: 12, - version_name: "mockedVersion", - }, + method: "GET", + url: + "http://managerApiBase.com/get_firmware_version" + + "?livecommonversion=1.2.3" + + "&device_version=123" + + "&version_name=mockedVersion" + + "&provider=12", }); }); diff --git a/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts b/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts index 866715d53cbf..76a4b05cb00e 100644 --- a/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts +++ b/libs/device-core/src/managerApi/repositories/HttpManagerApiRepository.ts @@ -37,19 +37,17 @@ export class HttpManagerApiRepository implements ManagerApiRepository { se_firmware_osu_version: OsuFirmware; }; } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${this.managerApiBase}/get_latest_firmware`, query: { livecommonversion: this.liveCommonVersion, salt, + current_se_firmware_final_version, + device_version, + provider: providerId, }, }), - data: { - current_se_firmware_final_version, - device_version, - provider: providerId, - }, }); if (data.result === "null") { @@ -84,17 +82,15 @@ export class HttpManagerApiRepository implements ManagerApiRepository { }: { data: DeviceVersionEntity; } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${this.managerApiBase}/get_device_version`, query: { livecommonversion: this.liveCommonVersion, + provider: providerId, + target_id: targetId, }, }), - data: { - provider: providerId, - target_id: targetId, - }, }).catch(error => { const status = error?.status || error?.response?.status; @@ -113,18 +109,16 @@ export class HttpManagerApiRepository implements ManagerApiRepository { readonly getCurrentOSU: ManagerApiRepository["getCurrentOSU"] = makeLRUCache( async input => { const { data } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${this.managerApiBase}/get_osu_version`, query: { livecommonversion: this.liveCommonVersion, + device_version: input.deviceId, + version_name: `${input.version}-osu`, + provider: input.providerId, }, }), - data: { - device_version: input.deviceId, - version_name: `${input.version}-osu`, - provider: input.providerId, - }, }); return data; }, @@ -138,18 +132,16 @@ export class HttpManagerApiRepository implements ManagerApiRepository { }: { data: FinalFirmware; } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${this.managerApiBase}/get_firmware_version`, query: { livecommonversion: this.liveCommonVersion, + device_version: input.deviceId, + version_name: input.version, + provider: input.providerId, }, }), - data: { - device_version: input.deviceId, - version_name: input.version, - provider: input.providerId, - }, }).catch(error => { const status = error?.status || error?.response?.status; diff --git a/libs/ledger-live-common/src/appSupportsQuitApp.ts b/libs/ledger-live-common/src/appSupportsQuitApp.ts index 5267c20b6b89..f4a5c991aba7 100644 --- a/libs/ledger-live-common/src/appSupportsQuitApp.ts +++ b/libs/ledger-live-common/src/appSupportsQuitApp.ts @@ -1,9 +1,9 @@ import semver from "semver"; import type { AppAndVersion } from "./hw/connectApp"; export const req = { - method: "POST", - url: "https://appstore.aws.prd.ldg-tech.com/api/get_apps", - data: { + method: "GET", + url: "https://manager.api.live.ledger.com/api/get_apps", + query: { current_se_firmware_final_version: 118, device_version: 10, provider: 1, diff --git a/libs/ledger-live-common/src/manager/api.ts b/libs/ledger-live-common/src/manager/api.ts index e437db76bffb..f15f7374b8f9 100644 --- a/libs/ledger-live-common/src/manager/api.ts +++ b/libs/ledger-live-common/src/manager/api.ts @@ -211,18 +211,16 @@ const getCurrentOSU: (input: { }) => Promise = makeLRUCache( async input => { const { data } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${getEnv("MANAGER_API_BASE")}/get_osu_version`, query: { livecommonversion, + device_version: input.deviceId, + version_name: `${input.version}-osu`, + provider: input.provider, }, }), - data: { - device_version: input.deviceId, - version_name: `${input.version}-osu`, - provider: input.provider, - }, }); return data; }, @@ -239,18 +237,16 @@ const getCurrentFirmware: (input: { }: { data: FinalFirmware; } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${getEnv("MANAGER_API_BASE")}/get_firmware_version`, query: { livecommonversion, + device_version: input.deviceId, + version_name: input.version, + provider: input.provider, }, }), - data: { - device_version: input.deviceId, - version_name: input.version, - provider: input.provider, - }, }).catch(error => { const status = error?.status || error?.response?.status; @@ -290,17 +286,15 @@ const getDeviceVersion: (targetId: string | number, provider: number) => Promise }: { data: DeviceVersion; } = await network({ - method: "POST", + method: "GET", url: URL.format({ pathname: `${getEnv("MANAGER_API_BASE")}/get_device_version`, query: { livecommonversion, + provider, + target_id: targetId, }, }), - data: { - provider, - target_id: targetId, - }, }).catch(error => { const status = error?.status || error?.response?.status;