diff --git a/.changeset/cool-dancers-join.md b/.changeset/cool-dancers-join.md index 5388f72c4..a0c5b47bc 100644 --- a/.changeset/cool-dancers-join.md +++ b/.changeset/cool-dancers-join.md @@ -5,7 +5,7 @@ "@ledgerhq/device-signer-kit-ethereum": patch "@ledgerhq/tsconfig-dsdk": patch "@ledgerhq/prettier-config-dsdk": patch -"@ledgerhq/device-transport-kit-mock-client": patch +"@ledgerhq/device-mockserver-client": patch "@ledgerhq/eslint-config-dsdk": patch "@ledgerhq/device-sdk-trusted-apps": patch "@ledgerhq/jest-config-dsdk": patch diff --git a/.changeset/lemon-suits-notice.md b/.changeset/lemon-suits-notice.md index 4b4b73bd2..cbdf9897a 100644 --- a/.changeset/lemon-suits-notice.md +++ b/.changeset/lemon-suits-notice.md @@ -2,7 +2,7 @@ "@ledgerhq/device-management-kit-flipper-plugin-client": patch "@ledgerhq/device-signer-kit-solana": patch "@ledgerhq/device-signer-kit-ethereum": patch -"@ledgerhq/device-transport-kit-mock-client": patch +"@ledgerhq/device-mockserver-client": patch "@ledgerhq/device-management-kit": patch "@ledgerhq/device-management-kit-sample": patch --- diff --git a/.changeset/smart-games-brush.md b/.changeset/smart-games-brush.md index 02c9a0e33..f866474a4 100644 --- a/.changeset/smart-games-brush.md +++ b/.changeset/smart-games-brush.md @@ -1,5 +1,5 @@ --- -"@ledgerhq/device-transport-kit-mock-client": patch +"@ledgerhq/device-mockserver-client": patch "@ledgerhq/device-management-kit": patch "@ledgerhq/device-management-kit-sample": patch --- diff --git a/README.md b/README.md index 36d095e55..2ab532031 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ A brief description of this project packages: | @ledgerhq/device-management-kit-flipper-plugin-client | packages/flipper-plugin-client | external package that contains [flipper](https://github.com/facebook/flipper) logger for Device Management Kit | | @ledgerhq/device-transport-kit-web-hid | packages/transport/web-hid | external package that contains the Web Hid transport implementation | | @ledgerhq/device-transport-kit-web-ble | packages/transport/web-ble | external package that contains the Web Ble transport implementation | +| @ledgerhq/device-mockserver-client | packages/mockserver-client | external package that contains the client to interact with the mock-server | # Getting started @@ -180,7 +181,7 @@ Please configure JEST extention accordingly. Each package is built using the following command (at the root of the monorepo). -### Core +### Devie Management Kit Device Management Kit main module. diff --git a/apps/sample/package.json b/apps/sample/package.json index f5eb7be8d..b80f52cb8 100644 --- a/apps/sample/package.json +++ b/apps/sample/package.json @@ -18,9 +18,10 @@ "@ledgerhq/context-module": "workspace:*", "@ledgerhq/device-management-kit": "workspace:*", "@ledgerhq/device-management-kit-flipper-plugin-client": "workspace:*", + "@ledgerhq/device-mockserver-client": "workspace:*", "@ledgerhq/device-signer-kit-ethereum": "workspace:*", "@ledgerhq/device-signer-kit-solana": "workspace:*", - "@ledgerhq/device-transport-kit-mock-client": "workspace:*", + "@ledgerhq/device-transport-kit-mockserver": "workspace:*", "@ledgerhq/device-transport-kit-web-ble": "workspace:*", "@ledgerhq/device-transport-kit-web-hid": "workspace:*", "@ledgerhq/react-ui": "^0.16.2", diff --git a/apps/sample/src/components/MockView/MockDeviceDrawer.tsx b/apps/sample/src/components/MockView/MockDeviceDrawer.tsx index 1176e5453..630ee7dbd 100644 --- a/apps/sample/src/components/MockView/MockDeviceDrawer.tsx +++ b/apps/sample/src/components/MockView/MockDeviceDrawer.tsx @@ -3,7 +3,7 @@ import { type Mock, type MockClient, type Session, -} from "@ledgerhq/device-transport-kit-mock-client"; +} from "@ledgerhq/device-mockserver-client"; import { Button, Divider, Flex, Input, Text } from "@ledgerhq/react-ui"; import styled from "styled-components"; diff --git a/apps/sample/src/components/MockView/MockItem.tsx b/apps/sample/src/components/MockView/MockItem.tsx index 78c3668a1..83848459d 100644 --- a/apps/sample/src/components/MockView/MockItem.tsx +++ b/apps/sample/src/components/MockView/MockItem.tsx @@ -1,5 +1,5 @@ import React, { useState } from "react"; -import { type Mock } from "@ledgerhq/device-transport-kit-mock-client"; +import { type Mock } from "@ledgerhq/device-mockserver-client"; import { Button, Flex, Icons, Input, Text } from "@ledgerhq/react-ui"; type MockItemProps = { diff --git a/apps/sample/src/components/MockView/index.tsx b/apps/sample/src/components/MockView/index.tsx index 085ac28c3..bd728c2a5 100644 --- a/apps/sample/src/components/MockView/index.tsx +++ b/apps/sample/src/components/MockView/index.tsx @@ -1,5 +1,5 @@ import React, { useCallback, useEffect, useState } from "react"; -import { type Session } from "@ledgerhq/device-transport-kit-mock-client"; +import { type Session } from "@ledgerhq/device-mockserver-client"; import { Button, Flex, Text } from "@ledgerhq/react-ui"; import styled from "styled-components"; diff --git a/apps/sample/src/hooks/useMockClient.ts b/apps/sample/src/hooks/useMockClient.ts index 58560561a..1a8a829d4 100644 --- a/apps/sample/src/hooks/useMockClient.ts +++ b/apps/sample/src/hooks/useMockClient.ts @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { MockClient } from "@ledgerhq/device-transport-kit-mock-client"; +import { MockClient } from "@ledgerhq/device-mockserver-client"; export const useMockClient = (url: string): MockClient => { const [client, setClient] = useState(new MockClient(url)); diff --git a/apps/sample/src/providers/DeviceManagementKitProvider/index.tsx b/apps/sample/src/providers/DeviceManagementKitProvider/index.tsx index 5f26284aa..e02a2b455 100644 --- a/apps/sample/src/providers/DeviceManagementKitProvider/index.tsx +++ b/apps/sample/src/providers/DeviceManagementKitProvider/index.tsx @@ -8,8 +8,9 @@ import { WebLogsExporterLogger, } from "@ledgerhq/device-management-kit"; import { FlipperDmkLogger } from "@ledgerhq/device-management-kit-flipper-plugin-client"; -import { WebBleTransport } from "@ledgerhq/device-transport-kit-web-ble"; -import { WebHidTransport } from "@ledgerhq/device-transport-kit-web-hid"; +import { mockserverTransportFactory } from "@ledgerhq/device-transport-kit-mockserver"; +import { webBleTransportFactory } from "@ledgerhq/device-transport-kit-web-ble"; +import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid"; import { useHasChanged } from "@/hooks/useHasChanged"; import { useDmkConfigContext } from "@/providers/DmkConfig"; @@ -19,49 +20,23 @@ const LogsExporterContext = createContext(null); function buildDefaultDmk(logsExporter: WebLogsExporterLogger) { return new DeviceManagementKitBuilder() - .addTransport( - ({ - deviceModelDataSource, - loggerServiceFactory, - apduSenderServiceFactory, - apduReceiverServiceFactory, - }) => - new WebHidTransport( - deviceModelDataSource, - loggerServiceFactory, - apduSenderServiceFactory, - apduReceiverServiceFactory, - ), - ) - .addTransport( - ({ - deviceModelDataSource, - loggerServiceFactory, - apduSenderServiceFactory, - apduReceiverServiceFactory, - }) => - new WebBleTransport( - deviceModelDataSource, - loggerServiceFactory, - apduSenderServiceFactory, - apduReceiverServiceFactory, - ), - ) + .addTransport(webHidTransportFactory) + .addTransport(webBleTransportFactory) .addLogger(new ConsoleLogger()) .addLogger(logsExporter) .addLogger(new FlipperDmkLogger()) .build(); } -// function buildMockDmk(url: string, logsExporter: WebLogsExporterLogger) { -// return new DeviceManagementKitBuilder() -// .addTransport(BuiltinTransports.MOCK_SERVER) -// .addLogger(new ConsoleLogger()) -// .addLogger(logsExporter) -// .addLogger(new FlipperDmkLogger()) -// .addConfig({ mockUrl: url }) -// .build(); -// } +function buildMockDmk(url: string, logsExporter: WebLogsExporterLogger) { + return new DeviceManagementKitBuilder() + .addTransport(mockserverTransportFactory) + .addLogger(new ConsoleLogger()) + .addLogger(logsExporter) + .addLogger(new FlipperDmkLogger()) + .addConfig({ mockUrl: url }) + .build(); +} export const DmkProvider: React.FC = ({ children }) => { const { @@ -71,10 +46,9 @@ export const DmkProvider: React.FC = ({ children }) => { const mockServerEnabled = transport === BuiltinTransports.MOCK_SERVER; const [state, setState] = useState(() => { const logsExporter = new WebLogsExporterLogger(); - // const dmk = mockServerEnabled - // ? buildMockDmk(mockServerUrl, logsExporter) - // : buildDefaultDmk(logsExporter); - const dmk = buildDefaultDmk(logsExporter); + const dmk = mockServerEnabled + ? buildMockDmk(mockServerUrl, logsExporter) + : buildDefaultDmk(logsExporter); return { dmk, logsExporter }; }); @@ -84,10 +58,9 @@ export const DmkProvider: React.FC = ({ children }) => { if (mockServerEnabledChanged || mockServerUrlChanged) { setState(({ logsExporter }) => { return { - dmk: buildDefaultDmk(logsExporter), - // dmk: mockServerEnabled - // ? buildMockDmk(mockServerUrl, logsExporter) - // : buildDefaultDmk(logsExporter), + dmk: mockServerEnabled + ? buildMockDmk(mockServerUrl, logsExporter) + : buildDefaultDmk(logsExporter), logsExporter, }; }); diff --git a/package.json b/package.json index 32ad74c1b..e43261651 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,13 @@ "signer-eth": "pnpm --filter @ledgerhq/device-signer-kit-ethereum", "signer-solana": "pnpm --filter @ledgerhq/device-signer-kit-solana", "signer-utils": "pnpm --filter @ledgerhq/signer-utils", - "mock-client": "pnpm --filter @ledgerhq/device-transport-kit-mock-client", + "mockserver-client": "pnpm --filter @ledgerhq/device-mockserver-client", "trusted-apps": "pnpm --filter @ledgerhq/device-sdk-trusted-apps", "ui": "pnpm --filter @ledgerhq/device-sdk-ui", "transports": "pnpm --filter @ledgerhq/device-transport-*", "transport-web-hid": "pnpm --filter @ledgerhq/device-transport-kit-web-hid", "transport-web-ble": "pnpm --filter @ledgerhq/device-transport-kit-web-ble", + "transport-mockserver": "pnpm --filter @ledgerhq/device-transport-kit-mockserver", "flipper": "pnpm --filter @ledgerhq/device-management-kit-flipper-plugin-client", "sample": "pnpm --filter @ledgerhq/device-management-kit-sample", "bump": "changeset version", diff --git a/packages/device-management-kit/package.json b/packages/device-management-kit/package.json index 66cd4db7f..8c5c8c7d1 100644 --- a/packages/device-management-kit/package.json +++ b/packages/device-management-kit/package.json @@ -36,7 +36,7 @@ "module:create": "pnpm hygen core-module with-prompt" }, "dependencies": { - "@ledgerhq/device-transport-kit-mock-client": "workspace:*", + "@ledgerhq/device-mockserver-client": "workspace:*", "@sentry/minimal": "^6.19.7", "@statelyai/inspect": "^0.4.0", "axios": "^1.7.7", diff --git a/packages/device-management-kit/src/api/index.ts b/packages/device-management-kit/src/api/index.ts index 152fa91f5..fe84208ef 100644 --- a/packages/device-management-kit/src/api/index.ts +++ b/packages/device-management-kit/src/api/index.ts @@ -134,6 +134,7 @@ export { defaultApduSenderServiceStubBuilder } from "@api/device-session/service export { FramerUtils } from "@api/device-session/utils/FramerUtils"; export { DeviceManagementKit } from "@api/DeviceManagementKit"; export { DeviceManagementKitBuilder } from "@api/DeviceManagementKitBuilder"; +export { type DmkConfig } from "@api/DmkConfig"; export { DeviceExchangeError, UnknownDeviceExchangeError } from "@api/Error"; export { type DmkError } from "@api/Error"; export { type LoggerPublisherService } from "@api/logger-publisher/service/LoggerPublisherService"; diff --git a/packages/transport-mock/.prettierignore b/packages/mockserver-client/.prettierignore similarity index 100% rename from packages/transport-mock/.prettierignore rename to packages/mockserver-client/.prettierignore diff --git a/packages/transport-mock/.prettierrc.js b/packages/mockserver-client/.prettierrc.js similarity index 100% rename from packages/transport-mock/.prettierrc.js rename to packages/mockserver-client/.prettierrc.js diff --git a/packages/transport-mock/eslint.config.mjs b/packages/mockserver-client/eslint.config.mjs similarity index 100% rename from packages/transport-mock/eslint.config.mjs rename to packages/mockserver-client/eslint.config.mjs diff --git a/packages/transport-mock/index.ts b/packages/mockserver-client/index.ts similarity index 100% rename from packages/transport-mock/index.ts rename to packages/mockserver-client/index.ts diff --git a/packages/transport-mock/jest.config.ts b/packages/mockserver-client/jest.config.ts similarity index 100% rename from packages/transport-mock/jest.config.ts rename to packages/mockserver-client/jest.config.ts diff --git a/packages/transport-mock/package.json b/packages/mockserver-client/package.json similarity index 96% rename from packages/transport-mock/package.json rename to packages/mockserver-client/package.json index a1fd81fb4..ce160abe7 100644 --- a/packages/transport-mock/package.json +++ b/packages/mockserver-client/package.json @@ -1,5 +1,5 @@ { - "name": "@ledgerhq/device-transport-kit-mock-client", + "name": "@ledgerhq/device-mockserver-client", "private": true, "version": "1.0.0", "license": "Apache-2.0", diff --git a/packages/transport-mock/scripts/build.mjs b/packages/mockserver-client/scripts/build.mjs similarity index 100% rename from packages/transport-mock/scripts/build.mjs rename to packages/mockserver-client/scripts/build.mjs diff --git a/packages/transport-mock/src/DefaultHttpClient.stub.ts b/packages/mockserver-client/src/DefaultHttpClient.stub.ts similarity index 100% rename from packages/transport-mock/src/DefaultHttpClient.stub.ts rename to packages/mockserver-client/src/DefaultHttpClient.stub.ts diff --git a/packages/transport-mock/src/DefaultHttpClient.ts b/packages/mockserver-client/src/DefaultHttpClient.ts similarity index 100% rename from packages/transport-mock/src/DefaultHttpClient.ts rename to packages/mockserver-client/src/DefaultHttpClient.ts diff --git a/packages/transport-mock/src/HttpClient.ts b/packages/mockserver-client/src/HttpClient.ts similarity index 100% rename from packages/transport-mock/src/HttpClient.ts rename to packages/mockserver-client/src/HttpClient.ts diff --git a/packages/transport-mock/src/MockClient.ts b/packages/mockserver-client/src/MockClient.ts similarity index 100% rename from packages/transport-mock/src/MockClient.ts rename to packages/mockserver-client/src/MockClient.ts diff --git a/packages/transport-mock/src/index.ts b/packages/mockserver-client/src/index.ts similarity index 100% rename from packages/transport-mock/src/index.ts rename to packages/mockserver-client/src/index.ts diff --git a/packages/transport-mock/src/model/ComandResponse.test.ts b/packages/mockserver-client/src/model/ComandResponse.test.ts similarity index 100% rename from packages/transport-mock/src/model/ComandResponse.test.ts rename to packages/mockserver-client/src/model/ComandResponse.test.ts diff --git a/packages/transport-mock/src/model/CommandResponse.stub.ts b/packages/mockserver-client/src/model/CommandResponse.stub.ts similarity index 100% rename from packages/transport-mock/src/model/CommandResponse.stub.ts rename to packages/mockserver-client/src/model/CommandResponse.stub.ts diff --git a/packages/transport-mock/src/model/CommandResponse.ts b/packages/mockserver-client/src/model/CommandResponse.ts similarity index 100% rename from packages/transport-mock/src/model/CommandResponse.ts rename to packages/mockserver-client/src/model/CommandResponse.ts diff --git a/packages/transport-mock/src/model/Device.stub.ts b/packages/mockserver-client/src/model/Device.stub.ts similarity index 100% rename from packages/transport-mock/src/model/Device.stub.ts rename to packages/mockserver-client/src/model/Device.stub.ts diff --git a/packages/transport-mock/src/model/Device.ts b/packages/mockserver-client/src/model/Device.ts similarity index 100% rename from packages/transport-mock/src/model/Device.ts rename to packages/mockserver-client/src/model/Device.ts diff --git a/packages/transport-mock/src/model/Mock.stub.ts b/packages/mockserver-client/src/model/Mock.stub.ts similarity index 100% rename from packages/transport-mock/src/model/Mock.stub.ts rename to packages/mockserver-client/src/model/Mock.stub.ts diff --git a/packages/transport-mock/src/model/Mock.ts b/packages/mockserver-client/src/model/Mock.ts similarity index 100% rename from packages/transport-mock/src/model/Mock.ts rename to packages/mockserver-client/src/model/Mock.ts diff --git a/packages/transport-mock/src/model/Session.stub.ts b/packages/mockserver-client/src/model/Session.stub.ts similarity index 100% rename from packages/transport-mock/src/model/Session.stub.ts rename to packages/mockserver-client/src/model/Session.stub.ts diff --git a/packages/transport-mock/src/model/Session.ts b/packages/mockserver-client/src/model/Session.ts similarity index 100% rename from packages/transport-mock/src/model/Session.ts rename to packages/mockserver-client/src/model/Session.ts diff --git a/packages/transport-mock/src/service/ConnectivityService.test.ts b/packages/mockserver-client/src/service/ConnectivityService.test.ts similarity index 100% rename from packages/transport-mock/src/service/ConnectivityService.test.ts rename to packages/mockserver-client/src/service/ConnectivityService.test.ts diff --git a/packages/transport-mock/src/service/ConnectivityService.ts b/packages/mockserver-client/src/service/ConnectivityService.ts similarity index 100% rename from packages/transport-mock/src/service/ConnectivityService.ts rename to packages/mockserver-client/src/service/ConnectivityService.ts diff --git a/packages/transport-mock/src/service/DiscoveryService.test.ts b/packages/mockserver-client/src/service/DiscoveryService.test.ts similarity index 100% rename from packages/transport-mock/src/service/DiscoveryService.test.ts rename to packages/mockserver-client/src/service/DiscoveryService.test.ts diff --git a/packages/transport-mock/src/service/DiscoveryService.ts b/packages/mockserver-client/src/service/DiscoveryService.ts similarity index 100% rename from packages/transport-mock/src/service/DiscoveryService.ts rename to packages/mockserver-client/src/service/DiscoveryService.ts diff --git a/packages/transport-mock/src/service/MockService.ts b/packages/mockserver-client/src/service/MockService.ts similarity index 100% rename from packages/transport-mock/src/service/MockService.ts rename to packages/mockserver-client/src/service/MockService.ts diff --git a/packages/transport-mock/src/service/SendService.ts b/packages/mockserver-client/src/service/SendService.ts similarity index 100% rename from packages/transport-mock/src/service/SendService.ts rename to packages/mockserver-client/src/service/SendService.ts diff --git a/packages/transport-mock/tsconfig.json b/packages/mockserver-client/tsconfig.json similarity index 100% rename from packages/transport-mock/tsconfig.json rename to packages/mockserver-client/tsconfig.json diff --git a/packages/transport-mock/tsconfig.prod.json b/packages/mockserver-client/tsconfig.prod.json similarity index 100% rename from packages/transport-mock/tsconfig.prod.json rename to packages/mockserver-client/tsconfig.prod.json diff --git a/packages/transport/mockserver/.prettierignore b/packages/transport/mockserver/.prettierignore new file mode 100644 index 000000000..2d4df5a66 --- /dev/null +++ b/packages/transport/mockserver/.prettierignore @@ -0,0 +1,2 @@ +lib/* +coverage/* \ No newline at end of file diff --git a/packages/transport/mockserver/.prettierrc.js b/packages/transport/mockserver/.prettierrc.js new file mode 100644 index 000000000..9601e1776 --- /dev/null +++ b/packages/transport/mockserver/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + ...require("@ledgerhq/prettier-config-dsdk"), +}; diff --git a/packages/transport/mockserver/eslint.config.mjs b/packages/transport/mockserver/eslint.config.mjs new file mode 100644 index 000000000..39852fc4b --- /dev/null +++ b/packages/transport/mockserver/eslint.config.mjs @@ -0,0 +1,13 @@ +import config from "@ledgerhq/eslint-config-dsdk"; + +export default [ + ...config, + { + ignores: ["eslint.config.mjs", "lib/*"], + languageOptions: { + parserOptions: { + project: "./tsconfig.json", + }, + }, + }, +]; diff --git a/packages/transport/mockserver/jest.config.ts b/packages/transport/mockserver/jest.config.ts new file mode 100644 index 000000000..10dd23196 --- /dev/null +++ b/packages/transport/mockserver/jest.config.ts @@ -0,0 +1,25 @@ +/* eslint no-restricted-syntax: 0 */ +import { type JestConfigWithTsJest, pathsToModuleNameMapper } from "ts-jest"; + +import { compilerOptions } from "./tsconfig.json"; + +const paths = pathsToModuleNameMapper(compilerOptions.paths, { + prefix: "/", +}); + +const config: JestConfigWithTsJest = { + preset: "@ledgerhq/jest-config-dsdk", + // setupFiles: ["/jest.setup.ts"], + testPathIgnorePatterns: ["/lib/esm/", "/lib/cjs/"], + collectCoverageFrom: [ + "src/**/*.ts", + "!src/**/*.stub.ts", + "!src/index.ts", + "!src/api/index.ts", + ], + moduleNameMapper: { + ...paths, + }, +}; + +export default config; diff --git a/packages/transport/mockserver/package.json b/packages/transport/mockserver/package.json new file mode 100644 index 000000000..26225d720 --- /dev/null +++ b/packages/transport/mockserver/package.json @@ -0,0 +1,56 @@ +{ + "name": "@ledgerhq/device-transport-kit-mockserver", + "version": "0.0.1", + "license": "Apache-2.0", + "private": true, + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "import": "./lib/esm/index.js", + "require": "./lib/cjs/index.js" + }, + "./*": { + "types": "./lib/types/*", + "import": "./lib/esm/*", + "require": "./lib/cjs/*" + } + }, + "files": [ + "./lib" + ], + "scripts": { + "prebuild": "rimraf lib", + "build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web", + "dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"", + "watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web", + "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"", + "lint": "eslint", + "lint:fix": "pnpm lint --fix", + "postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ", + "prettier": "prettier . --check", + "prettier:fix": "prettier . --write", + "typecheck": "tsc --noEmit", + "test": "jest --passWithNoTests", + "test:watch": "pnpm test -- --watch", + "test:coverage": "pnpm test -- --coverage" + }, + "dependencies": { + "@sentry/minimal": "^6.19.7", + "purify-ts": "^2.1.0" + }, + "devDependencies": { + "@ledgerhq/device-management-kit": "workspace:*", + "@ledgerhq/device-mockserver-client": "workspace:*", + "@ledgerhq/esbuild-tools": "workspace:*", + "@ledgerhq/eslint-config-dsdk": "workspace:*", + "@ledgerhq/jest-config-dsdk": "workspace:*", + "@ledgerhq/prettier-config-dsdk": "workspace:*", + "@ledgerhq/tsconfig-dsdk": "workspace:*", + "rxjs": "^7.8.1", + "ts-node": "^10.9.2" + }, + "peerDependencies": { + "@ledgerhq/device-management-kit": "workspace:*", + "rxjs": "^7.8.1" + } +} diff --git a/packages/device-management-kit/src/internal/transport/mockserver/MockserverTransport.ts b/packages/transport/mockserver/src/MockserverTransport.ts similarity index 73% rename from packages/device-management-kit/src/internal/transport/mockserver/MockserverTransport.ts rename to packages/transport/mockserver/src/MockserverTransport.ts index fd2880d96..49ab6406e 100644 --- a/packages/device-management-kit/src/internal/transport/mockserver/MockserverTransport.ts +++ b/packages/transport/mockserver/src/MockserverTransport.ts @@ -1,48 +1,40 @@ -/* istanbul ignore file */ -// pragma to ignore this file from coverage import { - CommandResponse, - Device, - MockClient, - Session, -} from "@ledgerhq/device-transport-kit-mock-client"; -import { inject, injectable } from "inversify"; -import { Either, Left, Right } from "purify-ts"; -import { from, mergeMap, Observable } from "rxjs"; - -import { DeviceId, DeviceModelId } from "@api/device/DeviceModel"; -import { ApduResponse } from "@api/device-session/ApduResponse"; -import type { DmkConfig } from "@api/DmkConfig"; -import { DmkError } from "@api/Error"; -import { LoggerPublisherService } from "@api/logger-publisher/service/LoggerPublisherService"; -import { DisconnectHandler } from "@api/transport/model/DeviceConnection"; -import { - ConnectError, + type ApduResponse, + type ConnectError, + type DeviceId, + type DeviceModelId, DisconnectError, + type DisconnectHandler, + type DmkConfig, + type DmkError, + type LoggerPublisherService, NoAccessibleDeviceError, OpeningConnectionError, -} from "@api/transport/model/Errors"; -import { Transport } from "@api/transport/model/Transport"; -import { TransportConnectedDevice } from "@api/transport/model/TransportConnectedDevice"; -import { TransportDiscoveredDevice } from "@api/transport/model/TransportDiscoveredDevice"; + type Transport, + type TransportConnectedDevice, + type TransportDiscoveredDevice, + type TransportIdentifier, +} from "@ledgerhq/device-management-kit"; +import { type TransportFactory } from "@ledgerhq/device-management-kit/src/api/transport/model/Transport.js"; import { - BuiltinTransports, - TransportIdentifier, -} from "@api/transport/model/TransportIdentifier"; -import { loggerTypes } from "@internal/logger-publisher/di/loggerTypes"; -import { transportDiTypes } from "@internal/transport/di/transportDiTypes"; + type CommandResponse, + type Device, + MockClient, + type Session, +} from "@ledgerhq/device-mockserver-client"; +import { type Either, Left, Right } from "purify-ts"; +import { from, mergeMap, type Observable } from "rxjs"; + +export const mockserverIdentifier: TransportIdentifier = "MOCKSERVER"; -@injectable() export class MockTransport implements Transport { private logger: LoggerPublisherService; private mockClient: MockClient; - private readonly identifier: TransportIdentifier = - BuiltinTransports.MOCK_SERVER; + private readonly identifier: TransportIdentifier = mockserverIdentifier; constructor( - @inject(loggerTypes.LoggerPublisherServiceFactory) loggerServiceFactory: (tag: string) => LoggerPublisherService, - @inject(transportDiTypes.DmkConfig) config: DmkConfig, + config: DmkConfig, ) { this.logger = loggerServiceFactory("MockTransport"); this.mockClient = new MockClient(config.mockUrl); @@ -176,3 +168,8 @@ export class MockTransport implements Transport { } } } + +export const mockserverTransportFactory: TransportFactory = ({ + config, + loggerServiceFactory, +}) => new MockTransport(loggerServiceFactory, config); diff --git a/packages/transport/mockserver/src/index.ts b/packages/transport/mockserver/src/index.ts new file mode 100644 index 000000000..d8e856500 --- /dev/null +++ b/packages/transport/mockserver/src/index.ts @@ -0,0 +1 @@ +export * from "./MockserverTransport"; diff --git a/packages/transport/mockserver/tsconfig.json b/packages/transport/mockserver/tsconfig.json new file mode 100644 index 000000000..3df06a391 --- /dev/null +++ b/packages/transport/mockserver/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "@ledgerhq/tsconfig-dsdk/tsconfig.sdk", + "compilerOptions": { + "baseUrl": ".", + "outDir": "./lib/types", + "module": "esnext", + "target": "esnext", + "moduleResolution": "bundler", + "emitDeclarationOnly": true, + "paths": { + "@api/*": ["./src/api/*"] + }, + "resolveJsonModule": true + }, + "include": ["src", "jest.*.ts"] +} diff --git a/packages/transport/mockserver/tsconfig.prod.json b/packages/transport/mockserver/tsconfig.prod.json new file mode 100644 index 000000000..b90fc83e0 --- /dev/null +++ b/packages/transport/mockserver/tsconfig.prod.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"] +} diff --git a/packages/transport/web-ble/src/api/index.ts b/packages/transport/web-ble/src/api/index.ts index 17c6d054b..de1a1a03a 100644 --- a/packages/transport/web-ble/src/api/index.ts +++ b/packages/transport/web-ble/src/api/index.ts @@ -1,2 +1,6 @@ export * from "./model/Errors"; -export { webBleIdentifier, WebBleTransport } from "./transport/WebBleTransport"; +export { + webBleIdentifier, + WebBleTransport, + webBleTransportFactory, +} from "./transport/WebBleTransport"; diff --git a/packages/transport/web-ble/src/api/transport/WebBleTransport.ts b/packages/transport/web-ble/src/api/transport/WebBleTransport.ts index f72a9378f..63a21bbc4 100644 --- a/packages/transport/web-ble/src/api/transport/WebBleTransport.ts +++ b/packages/transport/web-ble/src/api/transport/WebBleTransport.ts @@ -19,6 +19,7 @@ import { type TransportIdentifier, UnknownDeviceError, } from "@ledgerhq/device-management-kit"; +import { type TransportFactory } from "@ledgerhq/device-management-kit/src/api/transport/model/Transport.js"; import { type Either, EitherAsync, Left, Maybe, Right } from "purify-ts"; import { from, type Observable, switchMap, timer } from "rxjs"; import { v4 as uuid } from "uuid"; @@ -466,3 +467,16 @@ export class WebBleTransport implements Transport { return Promise.resolve(Right(undefined)); } } + +export const webBleTransportFactory: TransportFactory = ({ + deviceModelDataSource, + loggerServiceFactory, + apduSenderServiceFactory, + apduReceiverServiceFactory, +}) => + new WebBleTransport( + deviceModelDataSource, + loggerServiceFactory, + apduSenderServiceFactory, + apduReceiverServiceFactory, + ); diff --git a/packages/transport/web-hid/src/api/index.ts b/packages/transport/web-hid/src/api/index.ts index 73641295f..4e8a10795 100644 --- a/packages/transport/web-hid/src/api/index.ts +++ b/packages/transport/web-hid/src/api/index.ts @@ -2,4 +2,5 @@ export * from "@api/model/Errors"; export { webHidIdentifier, WebHidTransport, + webHidTransportFactory, } from "@api/transport/WebHidTransport"; diff --git a/packages/transport/web-hid/src/api/transport/WebHidTransport.ts b/packages/transport/web-hid/src/api/transport/WebHidTransport.ts index 57c886d3b..a50a22202 100644 --- a/packages/transport/web-hid/src/api/transport/WebHidTransport.ts +++ b/packages/transport/web-hid/src/api/transport/WebHidTransport.ts @@ -20,6 +20,7 @@ import { type TransportIdentifier, UnknownDeviceError, } from "@ledgerhq/device-management-kit"; +import { type TransportFactory } from "@ledgerhq/device-management-kit/src/api/transport/model/Transport.js"; import * as Sentry from "@sentry/minimal"; import { type Either, EitherAsync, Left, Maybe, Right } from "purify-ts"; import { BehaviorSubject, from, map, type Observable, switchMap } from "rxjs"; @@ -556,3 +557,16 @@ export class WebHidTransport implements Transport { this._deviceConnectionsPendingReconnection.clear(); } } + +export const webHidTransportFactory: TransportFactory = ({ + deviceModelDataSource, + loggerServiceFactory, + apduSenderServiceFactory, + apduReceiverServiceFactory, +}) => + new WebHidTransport( + deviceModelDataSource, + loggerServiceFactory, + apduSenderServiceFactory, + apduReceiverServiceFactory, + ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f06160160..1195cef79 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -77,15 +77,18 @@ importers: '@ledgerhq/device-management-kit-flipper-plugin-client': specifier: workspace:* version: link:../../packages/flipper-plugin-client + '@ledgerhq/device-mockserver-client': + specifier: workspace:* + version: link:../../packages/mockserver-client '@ledgerhq/device-signer-kit-ethereum': specifier: workspace:* version: link:../../packages/signer/signer-eth '@ledgerhq/device-signer-kit-solana': specifier: workspace:* version: link:../../packages/signer/signer-solana - '@ledgerhq/device-transport-kit-mock-client': + '@ledgerhq/device-transport-kit-mockserver': specifier: workspace:* - version: link:../../packages/transport-mock + version: link:../../packages/transport/mockserver '@ledgerhq/device-transport-kit-web-ble': specifier: workspace:* version: link:../../packages/transport/web-ble @@ -213,9 +216,9 @@ importers: packages/device-management-kit: dependencies: - '@ledgerhq/device-transport-kit-mock-client': + '@ledgerhq/device-mockserver-client': specifier: workspace:* - version: link:../transport-mock + version: link:../mockserver-client '@sentry/minimal': specifier: ^6.19.7 version: 6.19.7 @@ -303,6 +306,24 @@ importers: specifier: workspace:* version: link:../config/typescript + packages/mockserver-client: + devDependencies: + '@ledgerhq/esbuild-tools': + specifier: workspace:* + version: link:../tools/esbuild-tools + '@ledgerhq/eslint-config-dsdk': + specifier: workspace:* + version: link:../config/eslint + '@ledgerhq/jest-config-dsdk': + specifier: workspace:* + version: link:../config/jest + '@ledgerhq/prettier-config-dsdk': + specifier: workspace:* + version: link:../config/prettier + '@ledgerhq/tsconfig-dsdk': + specifier: workspace:* + version: link:../config/typescript + packages/signer/context-module: dependencies: axios: @@ -544,23 +565,42 @@ importers: specifier: ^1.14.0 version: 1.15.0(esbuild@0.24.0) - packages/transport-mock: + packages/transport/mockserver: + dependencies: + '@sentry/minimal': + specifier: ^6.19.7 + version: 6.19.7 + purify-ts: + specifier: ^2.1.0 + version: 2.1.0 devDependencies: + '@ledgerhq/device-management-kit': + specifier: workspace:* + version: link:../../device-management-kit + '@ledgerhq/device-mockserver-client': + specifier: workspace:* + version: link:../../mockserver-client '@ledgerhq/esbuild-tools': specifier: workspace:* - version: link:../tools/esbuild-tools + version: link:../../tools/esbuild-tools '@ledgerhq/eslint-config-dsdk': specifier: workspace:* - version: link:../config/eslint + version: link:../../config/eslint '@ledgerhq/jest-config-dsdk': specifier: workspace:* - version: link:../config/jest + version: link:../../config/jest '@ledgerhq/prettier-config-dsdk': specifier: workspace:* - version: link:../config/prettier + version: link:../../config/prettier '@ledgerhq/tsconfig-dsdk': specifier: workspace:* - version: link:../config/typescript + version: link:../../config/typescript + rxjs: + specifier: ^7.8.1 + version: 7.8.1 + ts-node: + specifier: ^10.9.2 + version: 10.9.2(@types/node@22.9.0)(typescript@5.6.3) packages/transport/web-ble: dependencies: diff --git a/turbo.json b/turbo.json index 5b4e92a39..10ee890bb 100644 --- a/turbo.json +++ b/turbo.json @@ -8,11 +8,11 @@ "inputs": ["src/**/*.ts", "index.ts"] }, "lint": { - "dependsOn": ["^build"], + "dependsOn": ["build"], "outputs": [] }, "lint:fix": { - "dependsOn": ["^build"], + "dependsOn": ["build"], "outputs": [] }, "prettier": {