Skip to content

Commit

Permalink
Merge pull request #7628 from LedgerHQ/chore/switch-to-appstore-get-apis
Browse files Browse the repository at this point in the history
chore(BACK-7633): switch app store API endpoints from POST to GET
  • Loading branch information
jiyuzhuang authored Aug 26, 2024
2 parents 6187fef + 94afd9e commit cd42a80
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 70 deletions.
12 changes: 12 additions & 0 deletions .changeset/modern-pears-remain.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
"&current_se_firmware_final_version=888" +
"&device_version=123" +
"&provider=12",
});
});

Expand Down Expand Up @@ -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",
});
});

Expand Down Expand Up @@ -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",
});
});

Expand Down Expand Up @@ -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",
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
},
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions libs/ledger-live-common/src/appSupportsQuitApp.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
28 changes: 11 additions & 17 deletions libs/ledger-live-common/src/manager/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,16 @@ const getCurrentOSU: (input: {
}) => Promise<OsuFirmware> = 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;
},
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit cd42a80

Please sign in to comment.