diff --git a/.changeset/green-jobs-pay.md b/.changeset/green-jobs-pay.md new file mode 100644 index 000000000..139f89e3b --- /dev/null +++ b/.changeset/green-jobs-pay.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/device-management-kit": patch +--- + +Get manager API service from internal API diff --git a/packages/device-management-kit/src/api/device-action/DeviceAction.ts b/packages/device-management-kit/src/api/device-action/DeviceAction.ts index 32d5a22ca..9d7f0ee79 100644 --- a/packages/device-management-kit/src/api/device-action/DeviceAction.ts +++ b/packages/device-management-kit/src/api/device-action/DeviceAction.ts @@ -17,7 +17,7 @@ export type InternalApi = { readonly setDeviceSessionState: ( state: DeviceSessionState, ) => DeviceSessionState; - getMetadataForAppHashes: ManagerApiService["getAppsByHash"]; + readonly getManagerApiService: () => ManagerApiService; }; export type DeviceActionIntermediateValue = { diff --git a/packages/device-management-kit/src/api/device-action/__test-utils__/makeInternalApi.ts b/packages/device-management-kit/src/api/device-action/__test-utils__/makeInternalApi.ts index 08209a960..f12344c9d 100644 --- a/packages/device-management-kit/src/api/device-action/__test-utils__/makeInternalApi.ts +++ b/packages/device-management-kit/src/api/device-action/__test-utils__/makeInternalApi.ts @@ -4,7 +4,7 @@ const sendCommandMock = jest.fn(); const apiGetDeviceSessionStateMock = jest.fn(); const apiGetDeviceSessionStateObservableMock = jest.fn(); const setDeviceSessionStateMock = jest.fn(); -const getMetadataForAppHashesMock = jest.fn(); +const getManagerApiServiceMock = jest.fn(); export function makeDeviceActionInternalApiMock(): jest.Mocked { return { @@ -12,6 +12,6 @@ export function makeDeviceActionInternalApiMock(): jest.Mocked { getDeviceSessionState: apiGetDeviceSessionStateMock, getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock, setDeviceSessionState: setDeviceSessionStateMock, - getMetadataForAppHashes: getMetadataForAppHashesMock, + getManagerApiService: getManagerApiServiceMock, }; } diff --git a/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.ts b/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.ts index 8856c1f7c..ed1a3e09f 100644 --- a/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.ts +++ b/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.test.ts @@ -17,6 +17,7 @@ import { UserInteractionRequired } from "@api/device-action/model/UserInteractio import { UnknownDAError } from "@api/device-action/os/Errors"; import { DeviceSessionStateType } from "@api/device-session/DeviceSessionState"; import { HttpFetchApiError } from "@internal/manager-api/model/Errors"; +import { type ManagerApiService } from "@internal/manager-api/service/ManagerApiService"; import { ListAppsWithMetadataDeviceAction } from "./ListAppsWithMetadataDeviceAction"; import { type ListAppsWithMetadataDAState } from "./types"; @@ -24,11 +25,8 @@ import { type ListAppsWithMetadataDAState } from "./types"; jest.mock("@api/device-action/os/ListApps/ListAppsDeviceAction"); describe("ListAppsWithMetadataDeviceAction", () => { - const { - getMetadataForAppHashes: getMetadataForAppHashesMock, - // getDeviceSessionState: apiGetDeviceSessionStateMock, - // setDeviceSessionState: apiSetDeviceSessionStateMock, - } = makeDeviceActionInternalApiMock(); + const { getManagerApiService: getManagerApiServiceMock } = + makeDeviceActionInternalApiMock(); const saveSessionStateMock = jest.fn(); const getDeviceSessionStateMock = jest.fn(); @@ -54,7 +52,9 @@ describe("ListAppsWithMetadataDeviceAction", () => { input: {}, }); - getMetadataForAppHashesMock.mockResolvedValue(Right([])); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest.fn().mockResolvedValue(Right([])), + } as unknown as ManagerApiService); const expectedStates: Array = [ { @@ -90,7 +90,9 @@ describe("ListAppsWithMetadataDeviceAction", () => { input: {}, }); - getMetadataForAppHashesMock.mockResolvedValue(Right([BTC_APP_METADATA])); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest.fn().mockResolvedValue(Right([BTC_APP_METADATA])), + } as unknown as ManagerApiService); const expectedStates: Array = [ { @@ -138,9 +140,11 @@ describe("ListAppsWithMetadataDeviceAction", () => { input: {}, }); - getMetadataForAppHashesMock.mockResolvedValue( - Right([BTC_APP_METADATA, ETH_APP_METADATA]), - ); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest + .fn() + .mockResolvedValue(Right([BTC_APP_METADATA, ETH_APP_METADATA])), + } as unknown as ManagerApiService); const expectedStates: Array = [ { @@ -188,9 +192,13 @@ describe("ListAppsWithMetadataDeviceAction", () => { input: {}, }); - getMetadataForAppHashesMock.mockResolvedValue( - Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]), - ); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest + .fn() + .mockResolvedValue( + Right([BTC_APP_METADATA, CUSTOM_LOCK_SCREEN_APP_METADATA]), + ), + } as unknown as ManagerApiService); const expectedStates: Array = [ { @@ -274,9 +282,11 @@ describe("ListAppsWithMetadataDeviceAction", () => { input: {}, }); - getMetadataForAppHashesMock.mockRejectedValue( - new UnknownDAError("getAppsByHash failed"), - ); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest + .fn() + .mockRejectedValue(new UnknownDAError("getAppsByHash failed")), + } as unknown as ManagerApiService); const expectedStates: Array = [ { @@ -320,7 +330,9 @@ describe("ListAppsWithMetadataDeviceAction", () => { const error = new HttpFetchApiError(new Error("Failed to fetch data")); - getMetadataForAppHashesMock.mockResolvedValue(Left(error)); + getManagerApiServiceMock.mockReturnValue({ + getAppsByHash: jest.fn().mockResolvedValue(Left(error)), + } as unknown as ManagerApiService); const expectedStates: Array = [ { diff --git a/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.ts b/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.ts index 924e3773b..3aa816ff2 100644 --- a/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.ts +++ b/packages/device-management-kit/src/api/device-action/os/ListAppsWithMetadata/ListAppsWithMetadataDeviceAction.ts @@ -290,7 +290,8 @@ export class ListAppsWithMetadataDeviceAction extends XStateDeviceAction< extractDependencies(internalApi: InternalApi): MachineDependencies { return { - getAppsByHash: ({ input }) => internalApi.getMetadataForAppHashes(input), + getAppsByHash: ({ input }) => + internalApi.getManagerApiService().getAppsByHash(input), getDeviceSessionState: () => internalApi.getDeviceSessionState(), saveSessionState: (state: DeviceSessionState) => internalApi.setDeviceSessionState(state), diff --git a/packages/device-management-kit/src/internal/device-session/model/DeviceSession.ts b/packages/device-management-kit/src/internal/device-session/model/DeviceSession.ts index 0b9d22996..f4debfd0c 100644 --- a/packages/device-management-kit/src/internal/device-session/model/DeviceSession.ts +++ b/packages/device-management-kit/src/internal/device-session/model/DeviceSession.ts @@ -4,7 +4,6 @@ import { v4 as uuidv4 } from "uuid"; import { type Command } from "@api/command/Command"; import { type CommandResult } from "@api/command/model/CommandResult"; -import { type ListAppsResponse } from "@api/command/os/ListAppsCommand"; import { CommandUtils } from "@api/command/utils/CommandUtils"; import { DeviceStatus } from "@api/device/DeviceStatus"; import { @@ -165,8 +164,7 @@ export class DeviceSession { this.setDeviceSessionState(state); return this._deviceState.getValue(); }, - getMetadataForAppHashes: (apps: ListAppsResponse) => - this._managerApiService.getAppsByHash(apps), + getManagerApiService: () => this._managerApiService, }); return { diff --git a/packages/signer/signer-btc/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts b/packages/signer/signer-btc/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts index 08104df33..e149e6be5 100644 --- a/packages/signer/signer-btc/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts +++ b/packages/signer/signer-btc/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts @@ -4,7 +4,7 @@ const sendCommandMock = jest.fn(); const apiGetDeviceSessionStateMock = jest.fn(); const apiGetDeviceSessionStateObservableMock = jest.fn(); const setDeviceSessionStateMock = jest.fn(); -const getMetadataForAppHashesMock = jest.fn(); +const getManagerApiServiceMock = jest.fn(); export function makeDeviceActionInternalApiMock(): jest.Mocked { return { @@ -12,6 +12,6 @@ export function makeDeviceActionInternalApiMock(): jest.Mocked { getDeviceSessionState: apiGetDeviceSessionStateMock, getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock, setDeviceSessionState: setDeviceSessionStateMock, - getMetadataForAppHashes: getMetadataForAppHashesMock, + getManagerApiService: getManagerApiServiceMock, }; } diff --git a/packages/signer/signer-eth/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts b/packages/signer/signer-eth/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts index 08104df33..e149e6be5 100644 --- a/packages/signer/signer-eth/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts +++ b/packages/signer/signer-eth/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts @@ -4,7 +4,7 @@ const sendCommandMock = jest.fn(); const apiGetDeviceSessionStateMock = jest.fn(); const apiGetDeviceSessionStateObservableMock = jest.fn(); const setDeviceSessionStateMock = jest.fn(); -const getMetadataForAppHashesMock = jest.fn(); +const getManagerApiServiceMock = jest.fn(); export function makeDeviceActionInternalApiMock(): jest.Mocked { return { @@ -12,6 +12,6 @@ export function makeDeviceActionInternalApiMock(): jest.Mocked { getDeviceSessionState: apiGetDeviceSessionStateMock, getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock, setDeviceSessionState: setDeviceSessionStateMock, - getMetadataForAppHashes: getMetadataForAppHashesMock, + getManagerApiService: getManagerApiServiceMock, }; } diff --git a/packages/signer/signer-solana/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts b/packages/signer/signer-solana/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts index 08104df33..e149e6be5 100644 --- a/packages/signer/signer-solana/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts +++ b/packages/signer/signer-solana/src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts @@ -4,7 +4,7 @@ const sendCommandMock = jest.fn(); const apiGetDeviceSessionStateMock = jest.fn(); const apiGetDeviceSessionStateObservableMock = jest.fn(); const setDeviceSessionStateMock = jest.fn(); -const getMetadataForAppHashesMock = jest.fn(); +const getManagerApiServiceMock = jest.fn(); export function makeDeviceActionInternalApiMock(): jest.Mocked { return { @@ -12,6 +12,6 @@ export function makeDeviceActionInternalApiMock(): jest.Mocked { getDeviceSessionState: apiGetDeviceSessionStateMock, getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock, setDeviceSessionState: setDeviceSessionStateMock, - getMetadataForAppHashes: getMetadataForAppHashesMock, + getManagerApiService: getManagerApiServiceMock, }; }