@ledgerhq/device-mockserver-client 0.0.0-develop-20261102000856 → 0.0.0-develop-20261104000847

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/MockClient.ts"],
4
- "sourcesContent": ["import {\n bufferToHexaString,\n DmkNetworkClient,\n} from \"@ledgerhq/device-management-kit\";\nimport { array, type Codec } from \"purify-ts\";\n\nimport {\n authResponseCodec,\n type ConnectionState,\n connectionStateCodec,\n} from \"./model/Auth\";\nimport {\n type CommandResponse,\n commandResponseCodec,\n} from \"./model/CommandResponse\";\nimport { type Device, deviceCodec, type DeviceConfig } from \"./model/Device\";\nimport { type Mock, mockCodec, type MockConfig } from \"./model/Mock\";\nimport { type Session, sessionCodec } from \"./model/Session\";\nimport { type SessionExport, sessionExportCodec } from \"./model/SessionExport\";\nimport {\n type SpeculosAction,\n type SpeculosButton,\n type SpeculosInstance,\n speculosInstanceCodec,\n} from \"./model/Speculos\";\n\nexport interface MockClientOptions {\n /**\n * An existing mock server session token. When provided the client operates\n * within that session; when omitted the client lazily creates its own session\n * through POST /auth.\n */\n readonly token?: string;\n /** Inject a custom network client (mainly for testing). */\n readonly httpClient?: DmkNetworkClient;\n}\n\n/**\n * HTTP client for the device mock server.\n *\n * Implements the bearer-token contract: the session is\n * resolved from an `Authorization: Bearer <token>` header rather than a\n * `session_id` header, and sessions, devices and mocks are exposed as REST\n * resources. The token can be injected or self-provisioned via /auth.\n */\nexport class MockClient {\n private readonly client: DmkNetworkClient;\n private token?: string;\n private authPromise?: Promise<string>;\n\n constructor(baseUrl: string, options: MockClientOptions = {}) {\n this.client =\n options.httpClient ??\n new DmkNetworkClient({ baseUrl: this.normalizeUrl(baseUrl) });\n this.token = options.token;\n }\n\n // --- Authentication -------------------------------------------------------\n\n /** Create a session and store the returned bearer token. */\n async authenticate(): Promise<string> {\n const data = await this.client.post(\"auth\", {});\n const token = this.decode(authResponseCodec, data).token;\n this.token = token;\n return token;\n }\n\n /** The current bearer token, if a session has been established. */\n getToken(): string | undefined {\n return this.token;\n }\n\n // --- Devices --------------------------------------------------------------\n\n async listDevices(): Promise<Device[]> {\n const data = await this.client.get(\"devices\", {\n headers: await this.authHeaders(),\n });\n return this.decode(array(deviceCodec), data);\n }\n\n async addDevice(config: DeviceConfig = {}): Promise<Device> {\n const data = await this.client.post(\"devices\", config, {\n headers: await this.authHeaders(),\n });\n return this.decode(deviceCodec, data);\n }\n\n async getDevice(deviceId: string): Promise<Device> {\n const data = await this.client.get(`devices/${deviceId}`, {\n headers: await this.authHeaders(),\n });\n return this.decode(deviceCodec, data);\n }\n\n async editDevice(deviceId: string, config: DeviceConfig): Promise<Device> {\n const data = await this.client.patch(`devices/${deviceId}`, config, {\n headers: await this.authHeaders(),\n });\n return this.decode(deviceCodec, data);\n }\n\n async deleteDevice(deviceId: string): Promise<boolean> {\n await this.client.delete(`devices/${deviceId}`, {\n headers: await this.authHeaders(),\n });\n return true;\n }\n\n // --- Connection state -----------------------------------------------------\n\n async connect(deviceId: string): Promise<ConnectionState> {\n const data = await this.client.post(\n `devices/${deviceId}/connect`,\n {},\n { headers: await this.authHeaders() },\n );\n return this.decode(connectionStateCodec, data);\n }\n\n async disconnect(deviceId: string): Promise<boolean> {\n await this.client.post(\n `devices/${deviceId}/disconnect`,\n {},\n { headers: await this.authHeaders() },\n );\n return true;\n }\n\n /** Disconnect every device attached to the session. */\n async disconnectAll(): Promise<boolean> {\n const devices = await this.listDevices();\n await Promise.all(\n devices\n .filter((device) => device.connected)\n .map((device) => this.disconnect(device.id)),\n );\n return true;\n }\n\n // --- APDU simulation ------------------------------------------------------\n\n async sendApdu(\n deviceId: string,\n apdu: Uint8Array | string,\n ): Promise<CommandResponse> {\n const hex =\n typeof apdu === \"string\" ? apdu : bufferToHexaString(apdu, false);\n const data = await this.client.post(\n `devices/${deviceId}/apdu`,\n { apdu: hex },\n { headers: await this.authHeaders() },\n );\n return this.decode(commandResponseCodec, data);\n }\n\n // --- Mocks (device-scoped) ------------------------------------------------\n\n async listMocks(deviceId: string): Promise<Mock[]> {\n const data = await this.client.get(`devices/${deviceId}/mocks`, {\n headers: await this.authHeaders(),\n });\n return this.decode(array(mockCodec), data);\n }\n\n async addMock(deviceId: string, config: MockConfig): Promise<Mock> {\n const data = await this.client.post(`devices/${deviceId}/mocks`, config, {\n headers: await this.authHeaders(),\n });\n return this.decode(mockCodec, data);\n }\n\n async editMock(\n deviceId: string,\n mockId: string,\n config: MockConfig,\n ): Promise<Mock> {\n const data = await this.client.patch(\n `devices/${deviceId}/mocks/${mockId}`,\n config,\n { headers: await this.authHeaders() },\n );\n return this.decode(mockCodec, data);\n }\n\n async deleteMock(deviceId: string, mockId: string): Promise<boolean> {\n await this.client.delete(`devices/${deviceId}/mocks/${mockId}`, {\n headers: await this.authHeaders(),\n });\n return true;\n }\n\n async clearMocks(deviceId: string): Promise<boolean> {\n await this.client.delete(`devices/${deviceId}/mocks`, {\n headers: await this.authHeaders(),\n });\n return true;\n }\n\n // --- Speculos -------------------------------------------------------------\n\n /**\n * Resolve the live Speculos instance backing a device (the one currently\n * proxying its APDUs). Throws if the device has no active instance.\n */\n async getSpeculos(deviceId: string): Promise<SpeculosInstance> {\n const data = await this.client.get(`devices/${deviceId}/speculos`, {\n headers: await this.authHeaders(),\n });\n return this.decode(speculosInstanceCodec, data);\n }\n\n /**\n * Capture the device's current screen as a PNG. Throws with status 409 when\n * the device has no active instance, which is the case whenever no app is\n * running.\n */\n async getScreenshot(deviceId: string): Promise<Blob> {\n const data = await this.client.get(\n `devices/${deviceId}/speculos/screenshot`,\n { headers: await this.authHeaders(), responseType: \"blob\" },\n );\n return data as Blob;\n }\n\n /** Actuate a physical button on a button-driven device. */\n async pressButton(\n deviceId: string,\n button: SpeculosButton,\n action: SpeculosAction = \"press-and-release\",\n ): Promise<void> {\n await this.client.post(\n `devices/${deviceId}/speculos/button/${button}`,\n { action },\n { headers: await this.authHeaders() },\n );\n }\n\n /** Tap a touchscreen device, in device screen pixels. */\n async touchScreen(\n deviceId: string,\n x: number,\n y: number,\n action: SpeculosAction = \"press-and-release\",\n ): Promise<void> {\n await this.client.post(\n `devices/${deviceId}/speculos/finger`,\n { action, x, y },\n { headers: await this.authHeaders() },\n );\n }\n\n // --- Session --------------------------------------------------------------\n\n async getSession(): Promise<Session> {\n const data = await this.client.get(\"sessions/current\", {\n headers: await this.authHeaders(),\n });\n return this.decode(sessionCodec, data);\n }\n\n async disposeSession(): Promise<boolean> {\n await this.client.delete(\"sessions/current\", {\n headers: await this.authHeaders(),\n });\n this.token = undefined;\n this.authPromise = undefined;\n return true;\n }\n\n // --- Import / Export ------------------------------------------------------\n\n /** Export the session's devices and mocks as a portable snapshot. */\n async exportSession(): Promise<SessionExport> {\n const data = await this.client.get(\"export\", {\n headers: await this.authHeaders(),\n });\n return this.decode(sessionExportCodec, data);\n }\n\n /**\n * Replace the session's devices and mocks with a previously exported\n * snapshot, returning the resulting (normalized) state.\n */\n async importSession(snapshot: SessionExport): Promise<SessionExport> {\n const data = await this.client.post(\"import\", snapshot, {\n headers: await this.authHeaders(),\n });\n return this.decode(sessionExportCodec, data);\n }\n\n // --- Helpers --------------------------------------------------------------\n\n private decode<T>(codec: Codec<T>, data: unknown): T {\n return codec.decode(data).caseOf({\n Left: (error) => {\n throw new Error(`MockClient: invalid server response (${error})`);\n },\n Right: (value) => value,\n });\n }\n\n private async authHeaders(): Promise<Record<string, string>> {\n const token = await this.ensureToken();\n return { Authorization: `Bearer ${token}` };\n }\n\n private ensureToken(): Promise<string> {\n if (this.token) {\n return Promise.resolve(this.token);\n }\n if (!this.authPromise) {\n this.authPromise = this.authenticate();\n }\n return this.authPromise;\n }\n\n private normalizeUrl(baseUrl: string): string {\n return baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\n }\n}\n"],
5
- "mappings": "AAAA,OACE,sBAAAA,EACA,oBAAAC,MACK,kCAC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AIA,EAAU,GAAGA,CAAO,GACrD,CACF",
6
- "names": ["bufferToHexaString", "DmkNetworkClient", "array", "authResponseCodec", "connectionStateCodec", "commandResponseCodec", "deviceCodec", "mockCodec", "sessionCodec", "sessionExportCodec", "speculosInstanceCodec", "MockClient", "baseUrl", "options", "data", "token", "config", "deviceId", "devices", "device", "apdu", "hex", "mockId", "button", "action", "x", "y", "snapshot", "codec", "error", "value"]
4
+ "sourcesContent": ["import {\n bufferToHexaString,\n DmkNetworkClient,\n type DmkRequestConfig,\n} from \"@ledgerhq/device-management-kit\";\nimport { array, type Codec } from \"purify-ts\";\n\nimport {\n authResponseCodec,\n type ConnectionState,\n connectionStateCodec,\n} from \"./model/Auth\";\nimport {\n type CommandResponse,\n commandResponseCodec,\n} from \"./model/CommandResponse\";\nimport { type Device, deviceCodec, type DeviceConfig } from \"./model/Device\";\nimport { type Health, healthCodec } from \"./model/Health\";\nimport { type Mock, mockCodec, type MockConfig } from \"./model/Mock\";\nimport { type Session, sessionCodec } from \"./model/Session\";\nimport { type SessionExport, sessionExportCodec } from \"./model/SessionExport\";\nimport {\n type SpeculosAction,\n type SpeculosButton,\n type SpeculosInstance,\n speculosInstanceCodec,\n} from \"./model/Speculos\";\n\nexport interface MockClientOptions {\n /**\n * An existing mock server session token. When provided the client operates\n * within that session; when omitted the client lazily creates its own session\n * through POST /auth.\n */\n readonly token?: string;\n /** Inject a custom network client (mainly for testing). */\n readonly httpClient?: DmkNetworkClient;\n /** Abort each request after this many milliseconds. Unset means no timeout. */\n readonly timeoutMs?: number;\n}\n\n/**\n * HTTP client for the device mock server.\n *\n * Implements the bearer-token contract: the session is\n * resolved from an `Authorization: Bearer <token>` header rather than a\n * `session_id` header, and sessions, devices and mocks are exposed as REST\n * resources. The token can be injected or self-provisioned via /auth.\n */\nexport class MockClient {\n private readonly client: DmkNetworkClient;\n private readonly timeoutMs?: number;\n private token?: string;\n private authPromise?: Promise<string>;\n\n constructor(baseUrl: string, options: MockClientOptions = {}) {\n this.client =\n options.httpClient ??\n new DmkNetworkClient({ baseUrl: this.normalizeUrl(baseUrl) });\n this.token = options.token;\n this.timeoutMs = options.timeoutMs;\n }\n\n // --- Health ---------------------------------------------------------------\n\n async getHealth(): Promise<Health> {\n const data = await this.client.get(\"health\", this.requestConfig());\n return this.decode(healthCodec, data);\n }\n\n // --- Authentication -------------------------------------------------------\n\n /** Create a session and store the returned bearer token. */\n async authenticate(): Promise<string> {\n const data = await this.client.post(\"auth\", {}, this.requestConfig());\n const token = this.decode(authResponseCodec, data).token;\n this.token = token;\n return token;\n }\n\n /** The current bearer token, if a session has been established. */\n getToken(): string | undefined {\n return this.token;\n }\n\n // --- Devices --------------------------------------------------------------\n\n async listDevices(): Promise<Device[]> {\n const data = await this.client.get(\n \"devices\",\n await this.authRequestConfig(),\n );\n return this.decode(array(deviceCodec), data);\n }\n\n async addDevice(config: DeviceConfig = {}): Promise<Device> {\n const data = await this.client.post(\n \"devices\",\n config,\n await this.authRequestConfig(),\n );\n return this.decode(deviceCodec, data);\n }\n\n async getDevice(deviceId: string): Promise<Device> {\n const data = await this.client.get(\n `devices/${deviceId}`,\n await this.authRequestConfig(),\n );\n return this.decode(deviceCodec, data);\n }\n\n async editDevice(deviceId: string, config: DeviceConfig): Promise<Device> {\n const data = await this.client.patch(\n `devices/${deviceId}`,\n config,\n await this.authRequestConfig(),\n );\n return this.decode(deviceCodec, data);\n }\n\n async deleteDevice(deviceId: string): Promise<boolean> {\n await this.client.delete(\n `devices/${deviceId}`,\n await this.authRequestConfig(),\n );\n return true;\n }\n\n // --- Connection state -----------------------------------------------------\n\n async connect(deviceId: string): Promise<ConnectionState> {\n const data = await this.client.post(\n `devices/${deviceId}/connect`,\n {},\n await this.authRequestConfig(),\n );\n return this.decode(connectionStateCodec, data);\n }\n\n async disconnect(deviceId: string): Promise<boolean> {\n await this.client.post(\n `devices/${deviceId}/disconnect`,\n {},\n await this.authRequestConfig(),\n );\n return true;\n }\n\n /** Disconnect every device attached to the session. */\n async disconnectAll(): Promise<boolean> {\n const devices = await this.listDevices();\n await Promise.all(\n devices\n .filter((device) => device.connected)\n .map((device) => this.disconnect(device.id)),\n );\n return true;\n }\n\n // --- APDU simulation ------------------------------------------------------\n\n async sendApdu(\n deviceId: string,\n apdu: Uint8Array | string,\n ): Promise<CommandResponse> {\n const hex =\n typeof apdu === \"string\" ? apdu : bufferToHexaString(apdu, false);\n const data = await this.client.post(\n `devices/${deviceId}/apdu`,\n { apdu: hex },\n await this.authRequestConfig(),\n );\n return this.decode(commandResponseCodec, data);\n }\n\n // --- Mocks (device-scoped) ------------------------------------------------\n\n async listMocks(deviceId: string): Promise<Mock[]> {\n const data = await this.client.get(\n `devices/${deviceId}/mocks`,\n await this.authRequestConfig(),\n );\n return this.decode(array(mockCodec), data);\n }\n\n async addMock(deviceId: string, config: MockConfig): Promise<Mock> {\n const data = await this.client.post(\n `devices/${deviceId}/mocks`,\n config,\n await this.authRequestConfig(),\n );\n return this.decode(mockCodec, data);\n }\n\n async editMock(\n deviceId: string,\n mockId: string,\n config: MockConfig,\n ): Promise<Mock> {\n const data = await this.client.patch(\n `devices/${deviceId}/mocks/${mockId}`,\n config,\n await this.authRequestConfig(),\n );\n return this.decode(mockCodec, data);\n }\n\n async deleteMock(deviceId: string, mockId: string): Promise<boolean> {\n await this.client.delete(\n `devices/${deviceId}/mocks/${mockId}`,\n await this.authRequestConfig(),\n );\n return true;\n }\n\n async clearMocks(deviceId: string): Promise<boolean> {\n await this.client.delete(\n `devices/${deviceId}/mocks`,\n await this.authRequestConfig(),\n );\n return true;\n }\n\n // --- Speculos -------------------------------------------------------------\n\n /**\n * Resolve the live Speculos instance backing a device (the one currently\n * proxying its APDUs). Throws if the device has no active instance.\n */\n async getSpeculos(deviceId: string): Promise<SpeculosInstance> {\n const data = await this.client.get(\n `devices/${deviceId}/speculos`,\n await this.authRequestConfig(),\n );\n return this.decode(speculosInstanceCodec, data);\n }\n\n /**\n * Capture the device's current screen as a PNG. Throws with status 409 when\n * the device has no active instance, which is the case whenever no app is\n * running.\n */\n async getScreenshot(deviceId: string): Promise<Blob> {\n const data = await this.client.get(\n `devices/${deviceId}/speculos/screenshot`,\n { ...(await this.authRequestConfig()), responseType: \"blob\" },\n );\n return data as Blob;\n }\n\n /** Actuate a physical button on a button-driven device. */\n async pressButton(\n deviceId: string,\n button: SpeculosButton,\n action: SpeculosAction = \"press-and-release\",\n ): Promise<void> {\n await this.client.post(\n `devices/${deviceId}/speculos/button/${button}`,\n { action },\n await this.authRequestConfig(),\n );\n }\n\n /** Tap a touchscreen device, in device screen pixels. */\n async touchScreen(\n deviceId: string,\n x: number,\n y: number,\n action: SpeculosAction = \"press-and-release\",\n ): Promise<void> {\n await this.client.post(\n `devices/${deviceId}/speculos/finger`,\n { action, x, y },\n await this.authRequestConfig(),\n );\n }\n\n // --- Session --------------------------------------------------------------\n\n async getSession(): Promise<Session> {\n const data = await this.client.get(\n \"sessions/current\",\n await this.authRequestConfig(),\n );\n return this.decode(sessionCodec, data);\n }\n\n /**\n * Set the BIP39 mnemonic of the Speculos instances the session starts next.\n * Use test mnemonics only: the server keeps the seed in plaintext.\n */\n async setSeed(seed: string): Promise<void> {\n await this.client.put(\n \"sessions/current/seed\",\n { seed },\n await this.authRequestConfig(),\n );\n }\n\n async disposeSession(): Promise<boolean> {\n await this.client.delete(\n \"sessions/current\",\n await this.authRequestConfig(),\n );\n this.token = undefined;\n this.authPromise = undefined;\n return true;\n }\n\n // --- Import / Export ------------------------------------------------------\n\n /** Export the session's devices and mocks as a portable snapshot. */\n async exportSession(): Promise<SessionExport> {\n const data = await this.client.get(\n \"export\",\n await this.authRequestConfig(),\n );\n return this.decode(sessionExportCodec, data);\n }\n\n /**\n * Replace the session's devices and mocks with a previously exported\n * snapshot, returning the resulting (normalized) state.\n */\n async importSession(snapshot: SessionExport): Promise<SessionExport> {\n const data = await this.client.post(\n \"import\",\n snapshot,\n await this.authRequestConfig(),\n );\n return this.decode(sessionExportCodec, data);\n }\n\n // --- Helpers --------------------------------------------------------------\n\n private decode<T>(codec: Codec<T>, data: unknown): T {\n return codec.decode(data).caseOf({\n Left: (error) => {\n throw new Error(`MockClient: invalid server response (${error})`);\n },\n Right: (value) => value,\n });\n }\n\n private requestConfig(): DmkRequestConfig {\n return { timeoutMs: this.timeoutMs };\n }\n\n private async authRequestConfig(): Promise<DmkRequestConfig> {\n const token = await this.ensureToken();\n return {\n ...this.requestConfig(),\n headers: { Authorization: `Bearer ${token}` },\n };\n }\n\n private ensureToken(): Promise<string> {\n if (this.token) {\n return Promise.resolve(this.token);\n }\n if (!this.authPromise) {\n this.authPromise = this.authenticate();\n }\n return this.authPromise;\n }\n\n private normalizeUrl(baseUrl: string): string {\n return baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`;\n }\n}\n"],
5
+ "mappings": "AAAA,OACE,sBAAAA,EACA,oBAAAC,MAEK,kCACP,OAAS,SAAAC,MAAyB,YAElC,OACE,qBAAAC,EAEA,wBAAAC,MACK,eACP,OAEE,wBAAAC,MACK,0BACP,OAAsB,eAAAC,MAAsC,iBAC5D,OAAsB,eAAAC,MAAmB,iBACzC,OAAoB,aAAAC,MAAkC,eACtD,OAAuB,gBAAAC,MAAoB,kBAC3C,OAA6B,sBAAAC,MAA0B,wBACvD,OAIE,yBAAAC,MACK,mBAuBA,MAAMC,CAAW,CACL,OACA,UACT,MACA,YAER,YAAYC,EAAiBC,EAA6B,CAAC,EAAG,CAC5D,KAAK,OACHA,EAAQ,YACR,IAAIb,EAAiB,CAAE,QAAS,KAAK,aAAaY,CAAO,CAAE,CAAC,EAC9D,KAAK,MAAQC,EAAQ,MACrB,KAAK,UAAYA,EAAQ,SAC3B,CAIA,MAAM,WAA6B,CACjC,MAAMC,EAAO,MAAM,KAAK,OAAO,IAAI,SAAU,KAAK,cAAc,CAAC,EACjE,OAAO,KAAK,OAAOR,EAAaQ,CAAI,CACtC,CAKA,MAAM,cAAgC,CACpC,MAAMA,EAAO,MAAM,KAAK,OAAO,KAAK,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nE,MAAMd,EAAO,MAAM,KAAK,OAAO,KAC7B,SACAc,EACA,MAAM,KAAK,kBAAkB,CAC/B,EACA,OAAO,KAAK,OAAOnB,EAAoBK,CAAI,CAC7C,CAIQ,OAAUe,EAAiBf,EAAkB,CACnD,OAAOe,EAAM,OAAOf,CAAI,EAAE,OAAO,CAC/B,KAAOgB,GAAU,CACf,MAAM,IAAI,MAAM,wCAAwCA,CAAK,GAAG,CAClE,EACA,MAAQC,GAAUA,CACpB,CAAC,CACH,CAEQ,eAAkC,CACxC,MAAO,CAAE,UAAW,KAAK,SAAU,CACrC,CAEA,MAAc,mBAA+C,CAC3D,MAAMhB,EAAQ,MAAM,KAAK,YAAY,EACrC,MAAO,CACL,GAAG,KAAK,cAAc,EACtB,QAAS,CAAE,cAAe,UAAUA,CAAK,EAAG,CAC9C,CACF,CAEQ,aAA+B,CACrC,OAAI,KAAK,MACA,QAAQ,QAAQ,KAAK,KAAK,GAE9B,KAAK,cACR,KAAK,YAAc,KAAK,aAAa,GAEhC,KAAK,YACd,CAEQ,aAAaH,EAAyB,CAC5C,OAAOA,EAAQ,SAAS,GAAG,EAAIA,EAAU,GAAGA,CAAO,GACrD,CACF",
6
+ "names": ["bufferToHexaString", "DmkNetworkClient", "array", "authResponseCodec", "connectionStateCodec", "commandResponseCodec", "deviceCodec", "healthCodec", "mockCodec", "sessionCodec", "sessionExportCodec", "speculosInstanceCodec", "MockClient", "baseUrl", "options", "data", "token", "config", "deviceId", "devices", "device", "apdu", "hex", "mockId", "button", "action", "x", "y", "seed", "snapshot", "codec", "error", "value"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{httpClientStubBuilder as s}from"./DmkNetworkClient.stub";import{MockClient as n}from"./MockClient";const i=(e={})=>({id:"dev-1",name:"Ledger Nano X",device_type:"nanoX",connectivity_type:"USB",...e});describe("MockClient",()=>{describe("authentication",()=>{it("lazily creates a session via /auth when no token is provided",async()=>{const e=s().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-123",expires_at:42}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n("http://localhost:8080",{httpClient:e}),o=await t.listDevices();expect(t.getToken()).toBe("tok-123"),expect(e.calls).toContainEqual({method:"post",endpoint:"auth",body:{}}),expect(o).toEqual([])}),it("does not call /auth when a token is injected",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n("http://localhost:8080",{token:"injected",httpClient:e});await t.listDevices(),expect(t.getToken()).toBe("injected"),expect(e.calls.find(o=>o.endpoint==="auth")).toBeUndefined()}),it("returns the token from an explicit authenticate() call",async()=>{const e=s().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-abc",expires_at:99}}),t=new n("http://localhost:8080",{httpClient:e}),o=await t.authenticate();expect(o).toBe("tok-abc"),expect(t.getToken()).toBe("tok-abc")}),it("reuses a single in-flight /auth call for concurrent requests",async()=>{const e=s().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-shared",expires_at:1}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n("http://localhost:8080",{httpClient:e});await Promise.all([t.listDevices(),t.listDevices()]);const o=e.calls.filter(c=>c.endpoint==="auth");expect(o).toHaveLength(1)}),it("returns undefined token before any session is established",()=>{const e=new n("http://localhost:8080",{httpClient:s()});expect(e.getToken()).toBeUndefined()})}),describe("constructor",()=>{it("normalizes a base url without a trailing slash",()=>{const e=new n("http://localhost:8080/"),t=new n("http://localhost:8080");expect(e.getToken()).toBeUndefined(),expect(t.getToken()).toBeUndefined()})}),describe("devices",()=>{it("lists devices",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices",response:[i()]}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).listDevices();expect(o).toEqual([expect.objectContaining({id:"dev-1"})])}),it("adds a device with a default empty config",async()=>{const e=s().mockResponse({method:"post",endpoint:"devices",response:i()}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).addDevice();expect(o.id).toBe("dev-1"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices",body:{}})}),it("gets a single device",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices/dev-1",response:i()}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).getDevice("dev-1");expect(o.id).toBe("dev-1")}),it("edits a device",async()=>{const e=s().mockResponse({method:"patch",endpoint:"devices/dev-1",response:i({name:"Renamed"})}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).editDevice("dev-1",{name:"Renamed"});expect(o.name).toBe("Renamed"),expect(e.calls).toContainEqual({method:"patch",endpoint:"devices/dev-1",body:{name:"Renamed"}})}),it("deletes a device",async()=>{const e=s().mockResponse({method:"delete",endpoint:"devices/dev-1",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.deleteDevice("dev-1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1"})})}),describe("connection state",()=>{it("connects a device",async()=>{const e=s().mockResponse({method:"post",endpoint:"devices/dev-1/connect",response:{device:i(),connected:!0}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).connect("dev-1");expect(o.connected).toBe(!0),expect(o.device.id).toBe("dev-1")}),it("disconnects a device",async()=>{const e=s().mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnect("dev-1")).resolves.toBe(!0)}),it("disconnects every connected device",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices",response:[i({id:"dev-1",connected:!0}),i({id:"dev-2",connected:!1}),i({id:"dev-3",connected:!0})]}).mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}).mockResponse({method:"post",endpoint:"devices/dev-3/disconnect",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnectAll()).resolves.toBe(!0);const o=e.calls.filter(c=>c.endpoint.endsWith("/disconnect"));expect(o.map(c=>c.endpoint)).toEqual(["devices/dev-1/disconnect","devices/dev-3/disconnect"])})}),describe("mocks",()=>{it("lists device-scoped mocks",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices/dev-1/mocks",response:[{id:"m1",prefix:"e0010000",responses:["9000"]}]}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).listMocks("dev-1");expect(o).toEqual([expect.objectContaining({id:"m1"})])}),it("creates a device-scoped mock",async()=>{const e=s().mockResponse({method:"post",endpoint:"devices/dev-1/mocks",response:{id:"m1",prefix:"e0010000",responses:["9000"]}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).addMock("dev-1",{prefix:"e0010000",response:"9000"});expect(o.id).toBe("m1"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/mocks",body:{prefix:"e0010000",response:"9000"}})}),it("edits a mock",async()=>{const e=s().mockResponse({method:"patch",endpoint:"devices/dev-1/mocks/m1",response:{id:"m1",prefix:"e0010000",responses:["6985"]}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).editMock("dev-1","m1",{prefix:"e0010000",response:"6985"});expect(o.responses).toEqual(["6985"]),expect(e.calls).toContainEqual({method:"patch",endpoint:"devices/dev-1/mocks/m1",body:{prefix:"e0010000",response:"6985"}})}),it("deletes a single mock",async()=>{const e=s().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks/m1",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.deleteMock("dev-1","m1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1/mocks/m1"})}),it("clears all mocks of a device",async()=>{const e=s().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.clearMocks("dev-1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1/mocks"})})}),describe("speculos",()=>{it("resolves the live speculos instance backing a device",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices/dev-1/speculos",response:{run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).getSpeculos("dev-1");expect(o).toEqual({run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"})}),it("requests the screenshot as a blob",async()=>{const e=new Blob([new Uint8Array([137,80])],{type:"image/png"}),t=s().mockResponse({method:"get",endpoint:"devices/dev-1/speculos/screenshot",response:e}),c=await new n("http://localhost:8080",{token:"tok",httpClient:t}).getScreenshot("dev-1");expect(c).toBe(e);const p=t.configs.find(({endpoint:d})=>d==="devices/dev-1/speculos/screenshot");expect(p?.config?.responseType).toBe("blob")}),it("presses a button",async()=>{const e=s();await new n("http://localhost:8080",{token:"tok",httpClient:e}).pressButton("dev-1","both"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/button/both",body:{action:"press-and-release"}})}),it("forwards an explicit button action",async()=>{const e=s();await new n("http://localhost:8080",{token:"tok",httpClient:e}).pressButton("dev-1","left","press"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/button/left",body:{action:"press"}})}),it("taps the screen at device coordinates",async()=>{const e=s();await new n("http://localhost:8080",{token:"tok",httpClient:e}).touchScreen("dev-1",200,537),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/finger",body:{action:"press-and-release",x:200,y:537}})})}),describe("session",()=>{it("fetches the current session",async()=>{const e=s().mockResponse({method:"get",endpoint:"sessions/current",response:{id:"sess-1",created_at:1,expires_at:2,devices:[i()]}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).getSession();expect(o.id).toBe("sess-1"),expect(o.devices).toHaveLength(1)}),it("disposes the session and clears the stored token",async()=>{const e=s().mockResponse({method:"delete",endpoint:"sessions/current",response:{}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disposeSession()).resolves.toBe(!0),expect(t.getToken()).toBeUndefined()})}),describe("response validation",()=>{it("throws a descriptive error when the server response is malformed",async()=>{const e=s().mockResponse({method:"get",endpoint:"devices/dev-1",response:{id:123}}),t=new n("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.getDevice("dev-1")).rejects.toThrow(/MockClient: invalid server response/)})}),describe("import/export",()=>{it("exports the session snapshot",async()=>{const e={devices:[{name:"Ledger Stax",device_type:"stax",mocks:[{prefix:"ff",responses:["9000"]}]}]},t=s().mockResponse({method:"get",endpoint:"export",response:e}),c=await new n("http://localhost:8080",{token:"tok",httpClient:t}).exportSession();expect(c).toEqual(e)}),it("posts a snapshot to the import endpoint",async()=>{const e={devices:[{name:"Ledger Flex",device_type:"flex",mocks:[{prefix:"e0010000",responses:["aa9000","5515"]}]}]},t=s().mockResponse({method:"post",endpoint:"import",response:e}),c=await new n("http://localhost:8080",{token:"tok",httpClient:t}).importSession(e);expect(c).toEqual(e),expect(t.calls).toContainEqual({method:"post",endpoint:"import",body:e})})}),describe("apdu",()=>{it("sends a binary APDU as hex to the device apdu endpoint",async()=>{const e=s().mockResponse({method:"post",endpoint:"devices/dev-1/apdu",response:{response:"9000"}}),o=await new n("http://localhost:8080",{token:"tok",httpClient:e}).sendApdu("dev-1",Uint8Array.from([224,1,0,0]));expect(o.response).toBe("9000"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/apdu",body:{apdu:"e0010000"}})})})});
1
+ import{httpClientStubBuilder as n}from"./DmkNetworkClient.stub";import{MockClient as s}from"./MockClient";const i=(e={})=>({id:"dev-1",name:"Ledger Nano X",device_type:"nanoX",connectivity_type:"USB",...e});describe("MockClient",()=>{describe("authentication",()=>{it("lazily creates a session via /auth when no token is provided",async()=>{const e=n().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-123",expires_at:42}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new s("http://localhost:8080",{httpClient:e}),o=await t.listDevices();expect(t.getToken()).toBe("tok-123"),expect(e.calls).toContainEqual({method:"post",endpoint:"auth",body:{}}),expect(o).toEqual([])}),it("does not call /auth when a token is injected",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices",response:[]}),t=new s("http://localhost:8080",{token:"injected",httpClient:e});await t.listDevices(),expect(t.getToken()).toBe("injected"),expect(e.calls.find(o=>o.endpoint==="auth")).toBeUndefined()}),it("returns the token from an explicit authenticate() call",async()=>{const e=n().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-abc",expires_at:99}}),t=new s("http://localhost:8080",{httpClient:e}),o=await t.authenticate();expect(o).toBe("tok-abc"),expect(t.getToken()).toBe("tok-abc")}),it("reuses a single in-flight /auth call for concurrent requests",async()=>{const e=n().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-shared",expires_at:1}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new s("http://localhost:8080",{httpClient:e});await Promise.all([t.listDevices(),t.listDevices()]);const o=e.calls.filter(c=>c.endpoint==="auth");expect(o).toHaveLength(1)}),it("returns undefined token before any session is established",()=>{const e=new s("http://localhost:8080",{httpClient:n()});expect(e.getToken()).toBeUndefined()})}),describe("constructor",()=>{it("normalizes a base url without a trailing slash",()=>{const e=new s("http://localhost:8080/"),t=new s("http://localhost:8080");expect(e.getToken()).toBeUndefined(),expect(t.getToken()).toBeUndefined()})}),describe("health",()=>{it("checks the server health without creating a session",async()=>{const e=n().mockResponse({method:"get",endpoint:"health",response:{status:"ok",sessions:3}}),o=await new s("http://localhost:8080",{httpClient:e}).getHealth();expect(o).toEqual({status:"ok",sessions:3}),expect(e.calls).toEqual([{method:"get",endpoint:"health"}]),expect(e.configs[0]?.config?.headers).toBeUndefined()})}),describe("timeout",()=>{it("applies the timeout to every request, the implicit /auth included",async()=>{const e=n().mockResponse({method:"post",endpoint:"auth",response:{token:"tok",expires_at:1}}).mockResponse({method:"get",endpoint:"devices",response:[]});await new s("http://localhost:8080",{httpClient:e,timeoutMs:4e3}).listDevices(),expect(e.configs.map(({config:o})=>o?.timeoutMs)).toEqual([4e3,4e3])}),it("sets no timeout by default",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices",response:[]});await new s("http://localhost:8080",{token:"tok",httpClient:e}).listDevices(),expect(e.configs[0]?.config?.timeoutMs).toBeUndefined()})}),describe("devices",()=>{it("lists devices",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices",response:[i()]}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).listDevices();expect(o).toEqual([expect.objectContaining({id:"dev-1"})])}),it("adds a device with a default empty config",async()=>{const e=n().mockResponse({method:"post",endpoint:"devices",response:i()}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).addDevice();expect(o.id).toBe("dev-1"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices",body:{}})}),it("gets a single device",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices/dev-1",response:i()}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).getDevice("dev-1");expect(o.id).toBe("dev-1")}),it("edits a device",async()=>{const e=n().mockResponse({method:"patch",endpoint:"devices/dev-1",response:i({name:"Renamed"})}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).editDevice("dev-1",{name:"Renamed"});expect(o.name).toBe("Renamed"),expect(e.calls).toContainEqual({method:"patch",endpoint:"devices/dev-1",body:{name:"Renamed"}})}),it("deletes a device",async()=>{const e=n().mockResponse({method:"delete",endpoint:"devices/dev-1",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.deleteDevice("dev-1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1"})})}),describe("connection state",()=>{it("connects a device",async()=>{const e=n().mockResponse({method:"post",endpoint:"devices/dev-1/connect",response:{device:i(),connected:!0}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).connect("dev-1");expect(o.connected).toBe(!0),expect(o.device.id).toBe("dev-1")}),it("disconnects a device",async()=>{const e=n().mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnect("dev-1")).resolves.toBe(!0)}),it("disconnects every connected device",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices",response:[i({id:"dev-1",connected:!0}),i({id:"dev-2",connected:!1}),i({id:"dev-3",connected:!0})]}).mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}).mockResponse({method:"post",endpoint:"devices/dev-3/disconnect",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnectAll()).resolves.toBe(!0);const o=e.calls.filter(c=>c.endpoint.endsWith("/disconnect"));expect(o.map(c=>c.endpoint)).toEqual(["devices/dev-1/disconnect","devices/dev-3/disconnect"])})}),describe("mocks",()=>{it("lists device-scoped mocks",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices/dev-1/mocks",response:[{id:"m1",prefix:"e0010000",responses:["9000"]}]}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).listMocks("dev-1");expect(o).toEqual([expect.objectContaining({id:"m1"})])}),it("creates a device-scoped mock",async()=>{const e=n().mockResponse({method:"post",endpoint:"devices/dev-1/mocks",response:{id:"m1",prefix:"e0010000",responses:["9000"]}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).addMock("dev-1",{prefix:"e0010000",response:"9000"});expect(o.id).toBe("m1"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/mocks",body:{prefix:"e0010000",response:"9000"}})}),it("edits a mock",async()=>{const e=n().mockResponse({method:"patch",endpoint:"devices/dev-1/mocks/m1",response:{id:"m1",prefix:"e0010000",responses:["6985"]}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).editMock("dev-1","m1",{prefix:"e0010000",response:"6985"});expect(o.responses).toEqual(["6985"]),expect(e.calls).toContainEqual({method:"patch",endpoint:"devices/dev-1/mocks/m1",body:{prefix:"e0010000",response:"6985"}})}),it("deletes a single mock",async()=>{const e=n().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks/m1",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.deleteMock("dev-1","m1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1/mocks/m1"})}),it("clears all mocks of a device",async()=>{const e=n().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.clearMocks("dev-1")).resolves.toBe(!0),expect(e.calls).toContainEqual({method:"delete",endpoint:"devices/dev-1/mocks"})})}),describe("speculos",()=>{it("resolves the live speculos instance backing a device",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices/dev-1/speculos",response:{run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).getSpeculos("dev-1");expect(o).toEqual({run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"})}),it("requests the screenshot as a blob",async()=>{const e=new Blob([new Uint8Array([137,80])],{type:"image/png"}),t=n().mockResponse({method:"get",endpoint:"devices/dev-1/speculos/screenshot",response:e}),c=await new s("http://localhost:8080",{token:"tok",httpClient:t}).getScreenshot("dev-1");expect(c).toBe(e);const p=t.configs.find(({endpoint:d})=>d==="devices/dev-1/speculos/screenshot");expect(p?.config?.responseType).toBe("blob")}),it("presses a button",async()=>{const e=n();await new s("http://localhost:8080",{token:"tok",httpClient:e}).pressButton("dev-1","both"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/button/both",body:{action:"press-and-release"}})}),it("forwards an explicit button action",async()=>{const e=n();await new s("http://localhost:8080",{token:"tok",httpClient:e}).pressButton("dev-1","left","press"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/button/left",body:{action:"press"}})}),it("taps the screen at device coordinates",async()=>{const e=n();await new s("http://localhost:8080",{token:"tok",httpClient:e}).touchScreen("dev-1",200,537),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/speculos/finger",body:{action:"press-and-release",x:200,y:537}})})}),describe("session",()=>{it("fetches the current session",async()=>{const e=n().mockResponse({method:"get",endpoint:"sessions/current",response:{id:"sess-1",created_at:1,expires_at:2,devices:[i()]}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).getSession();expect(o.id).toBe("sess-1"),expect(o.devices).toHaveLength(1)}),it("sets the session seed with the bearer token",async()=>{const e=n();await new s("http://localhost:8080",{token:"tok",httpClient:e}).setSeed("abandon abandon about"),expect(e.calls).toEqual([{method:"put",endpoint:"sessions/current/seed",body:{seed:"abandon abandon about"}}]),expect(e.configs[0]?.config?.headers).toEqual({Authorization:"Bearer tok"})}),it("disposes the session and clears the stored token",async()=>{const e=n().mockResponse({method:"delete",endpoint:"sessions/current",response:{}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disposeSession()).resolves.toBe(!0),expect(t.getToken()).toBeUndefined()})}),describe("response validation",()=>{it("throws a descriptive error when the server response is malformed",async()=>{const e=n().mockResponse({method:"get",endpoint:"devices/dev-1",response:{id:123}}),t=new s("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.getDevice("dev-1")).rejects.toThrow(/MockClient: invalid server response/)})}),describe("import/export",()=>{it("exports the session snapshot",async()=>{const e={devices:[{name:"Ledger Stax",device_type:"stax",mocks:[{prefix:"ff",responses:["9000"]}]}]},t=n().mockResponse({method:"get",endpoint:"export",response:e}),c=await new s("http://localhost:8080",{token:"tok",httpClient:t}).exportSession();expect(c).toEqual(e)}),it("posts a snapshot to the import endpoint",async()=>{const e={devices:[{name:"Ledger Flex",device_type:"flex",mocks:[{prefix:"e0010000",responses:["aa9000","5515"]}]}]},t=n().mockResponse({method:"post",endpoint:"import",response:e}),c=await new s("http://localhost:8080",{token:"tok",httpClient:t}).importSession(e);expect(c).toEqual(e),expect(t.calls).toContainEqual({method:"post",endpoint:"import",body:e})})}),describe("apdu",()=>{it("sends a binary APDU as hex to the device apdu endpoint",async()=>{const e=n().mockResponse({method:"post",endpoint:"devices/dev-1/apdu",response:{response:"9000"}}),o=await new s("http://localhost:8080",{token:"tok",httpClient:e}).sendApdu("dev-1",Uint8Array.from([224,1,0,0]));expect(o.response).toBe("9000"),expect(e.calls).toContainEqual({method:"post",endpoint:"devices/dev-1/apdu",body:{apdu:"e0010000"}})})})});
2
2
  //# sourceMappingURL=MockClient.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/MockClient.test.ts"],
4
- "sourcesContent": ["import { httpClientStubBuilder } from \"./DmkNetworkClient.stub\";\nimport { MockClient } from \"./MockClient\";\n\nconst aDevice = (overrides: Record<string, unknown> = {}) => ({\n id: \"dev-1\",\n name: \"Ledger Nano X\",\n device_type: \"nanoX\",\n connectivity_type: \"USB\",\n ...overrides,\n});\n\ndescribe(\"MockClient\", () => {\n describe(\"authentication\", () => {\n it(\"lazily creates a session via /auth when no token is provided\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-123\", expires_at: 42 },\n })\n .mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n const devices = await client.listDevices();\n\n expect(client.getToken()).toBe(\"tok-123\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"auth\",\n body: {},\n });\n expect(devices).toEqual([]);\n });\n\n it(\"does not call /auth when a token is injected\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"injected\",\n httpClient: http,\n });\n\n await client.listDevices();\n\n expect(client.getToken()).toBe(\"injected\");\n expect(\n http.calls.find((call) => call.endpoint === \"auth\"),\n ).toBeUndefined();\n });\n\n it(\"returns the token from an explicit authenticate() call\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-abc\", expires_at: 99 },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n const token = await client.authenticate();\n\n expect(token).toBe(\"tok-abc\");\n expect(client.getToken()).toBe(\"tok-abc\");\n });\n\n it(\"reuses a single in-flight /auth call for concurrent requests\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-shared\", expires_at: 1 },\n })\n .mockResponse({ method: \"get\", endpoint: \"devices\", response: [] });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n await Promise.all([client.listDevices(), client.listDevices()]);\n\n const authCalls = http.calls.filter((call) => call.endpoint === \"auth\");\n expect(authCalls).toHaveLength(1);\n });\n\n it(\"returns undefined token before any session is established\", () => {\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: httpClientStubBuilder(),\n });\n\n expect(client.getToken()).toBeUndefined();\n });\n });\n\n describe(\"constructor\", () => {\n it(\"normalizes a base url without a trailing slash\", () => {\n const withSlash = new MockClient(\"http://localhost:8080/\");\n const withoutSlash = new MockClient(\"http://localhost:8080\");\n\n expect(withSlash.getToken()).toBeUndefined();\n expect(withoutSlash.getToken()).toBeUndefined();\n });\n });\n\n describe(\"devices\", () => {\n it(\"lists devices\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [aDevice()],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const devices = await client.listDevices();\n\n expect(devices).toEqual([expect.objectContaining({ id: \"dev-1\" })]);\n });\n\n it(\"adds a device with a default empty config\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices\",\n response: aDevice(),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.addDevice();\n\n expect(device.id).toBe(\"dev-1\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices\",\n body: {},\n });\n });\n\n it(\"gets a single device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1\",\n response: aDevice(),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.getDevice(\"dev-1\");\n\n expect(device.id).toBe(\"dev-1\");\n });\n\n it(\"edits a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"patch\",\n endpoint: \"devices/dev-1\",\n response: aDevice({ name: \"Renamed\" }),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.editDevice(\"dev-1\", { name: \"Renamed\" });\n\n expect(device.name).toBe(\"Renamed\");\n expect(http.calls).toContainEqual({\n method: \"patch\",\n endpoint: \"devices/dev-1\",\n body: { name: \"Renamed\" },\n });\n });\n\n it(\"deletes a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.deleteDevice(\"dev-1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1\",\n });\n });\n });\n\n describe(\"connection state\", () => {\n it(\"connects a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/connect\",\n response: { device: aDevice(), connected: true },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const state = await client.connect(\"dev-1\");\n\n expect(state.connected).toBe(true);\n expect(state.device.id).toBe(\"dev-1\");\n });\n\n it(\"disconnects a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/disconnect\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disconnect(\"dev-1\")).resolves.toBe(true);\n });\n\n it(\"disconnects every connected device\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [\n aDevice({ id: \"dev-1\", connected: true }),\n aDevice({ id: \"dev-2\", connected: false }),\n aDevice({ id: \"dev-3\", connected: true }),\n ],\n })\n .mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/disconnect\",\n response: {},\n })\n .mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-3/disconnect\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disconnectAll()).resolves.toBe(true);\n\n const disconnectCalls = http.calls.filter((call) =>\n call.endpoint.endsWith(\"/disconnect\"),\n );\n expect(disconnectCalls.map((call) => call.endpoint)).toEqual([\n \"devices/dev-1/disconnect\",\n \"devices/dev-3/disconnect\",\n ]);\n });\n });\n\n describe(\"mocks\", () => {\n it(\"lists device-scoped mocks\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/mocks\",\n response: [{ id: \"m1\", prefix: \"e0010000\", responses: [\"9000\"] }],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mocks = await client.listMocks(\"dev-1\");\n\n expect(mocks).toEqual([expect.objectContaining({ id: \"m1\" })]);\n });\n\n it(\"creates a device-scoped mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/mocks\",\n response: { id: \"m1\", prefix: \"e0010000\", responses: [\"9000\"] },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mock = await client.addMock(\"dev-1\", {\n prefix: \"e0010000\",\n response: \"9000\",\n });\n\n expect(mock.id).toBe(\"m1\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/mocks\",\n body: { prefix: \"e0010000\", response: \"9000\" },\n });\n });\n\n it(\"edits a mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"patch\",\n endpoint: \"devices/dev-1/mocks/m1\",\n response: { id: \"m1\", prefix: \"e0010000\", responses: [\"6985\"] },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mock = await client.editMock(\"dev-1\", \"m1\", {\n prefix: \"e0010000\",\n response: \"6985\",\n });\n\n expect(mock.responses).toEqual([\"6985\"]);\n expect(http.calls).toContainEqual({\n method: \"patch\",\n endpoint: \"devices/dev-1/mocks/m1\",\n body: { prefix: \"e0010000\", response: \"6985\" },\n });\n });\n\n it(\"deletes a single mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks/m1\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.deleteMock(\"dev-1\", \"m1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks/m1\",\n });\n });\n\n it(\"clears all mocks of a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.clearMocks(\"dev-1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks\",\n });\n });\n });\n\n describe(\"speculos\", () => {\n it(\"resolves the live speculos instance backing a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/speculos\",\n response: {\n run_id: \"run-1\",\n speculos_url: \"https://speculos:5000\",\n model: \"stax\",\n },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const instance = await client.getSpeculos(\"dev-1\");\n\n expect(instance).toEqual({\n run_id: \"run-1\",\n speculos_url: \"https://speculos:5000\",\n model: \"stax\",\n });\n });\n\n it(\"requests the screenshot as a blob\", async () => {\n const png = new Blob([new Uint8Array([0x89, 0x50])], {\n type: \"image/png\",\n });\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/speculos/screenshot\",\n response: png,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const screenshot = await client.getScreenshot(\"dev-1\");\n\n expect(screenshot).toBe(png);\n // Anything but \"blob\" would decode the PNG as text and corrupt it.\n const request = http.configs.find(\n ({ endpoint }) => endpoint === \"devices/dev-1/speculos/screenshot\",\n );\n expect(request?.config?.responseType).toBe(\"blob\");\n });\n\n it(\"presses a button\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.pressButton(\"dev-1\", \"both\");\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/button/both\",\n body: { action: \"press-and-release\" },\n });\n });\n\n it(\"forwards an explicit button action\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.pressButton(\"dev-1\", \"left\", \"press\");\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/button/left\",\n body: { action: \"press\" },\n });\n });\n\n it(\"taps the screen at device coordinates\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.touchScreen(\"dev-1\", 200, 537);\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/finger\",\n body: { action: \"press-and-release\", x: 200, y: 537 },\n });\n });\n });\n\n describe(\"session\", () => {\n it(\"fetches the current session\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"sessions/current\",\n response: {\n id: \"sess-1\",\n created_at: 1,\n expires_at: 2,\n devices: [aDevice()],\n },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const session = await client.getSession();\n\n expect(session.id).toBe(\"sess-1\");\n expect(session.devices).toHaveLength(1);\n });\n\n it(\"disposes the session and clears the stored token\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"sessions/current\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disposeSession()).resolves.toBe(true);\n expect(client.getToken()).toBeUndefined();\n });\n });\n\n describe(\"response validation\", () => {\n it(\"throws a descriptive error when the server response is malformed\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1\",\n response: { id: 123 } as unknown as object,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.getDevice(\"dev-1\")).rejects.toThrow(\n /MockClient: invalid server response/,\n );\n });\n });\n\n describe(\"import/export\", () => {\n it(\"exports the session snapshot\", async () => {\n const snapshot = {\n devices: [\n {\n name: \"Ledger Stax\",\n device_type: \"stax\",\n mocks: [{ prefix: \"ff\", responses: [\"9000\"] }],\n },\n ],\n };\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"export\",\n response: snapshot,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.exportSession();\n\n expect(result).toEqual(snapshot);\n });\n\n it(\"posts a snapshot to the import endpoint\", async () => {\n const snapshot = {\n devices: [\n {\n name: \"Ledger Flex\",\n device_type: \"flex\",\n mocks: [{ prefix: \"e0010000\", responses: [\"aa9000\", \"5515\"] }],\n },\n ],\n };\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"import\",\n response: snapshot,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.importSession(snapshot);\n\n expect(result).toEqual(snapshot);\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"import\",\n body: snapshot,\n });\n });\n });\n\n describe(\"apdu\", () => {\n it(\"sends a binary APDU as hex to the device apdu endpoint\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/apdu\",\n response: { response: \"9000\" },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.sendApdu(\n \"dev-1\",\n Uint8Array.from([0xe0, 0x01, 0x00, 0x00]),\n );\n\n expect(result.response).toBe(\"9000\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/apdu\",\n body: { apdu: \"e0010000\" },\n });\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAAS,yBAAAA,MAA6B,0BACtC,OAAS,cAAAC,MAAkB,eAE3B,MAAMC,EAAU,CAACC,EAAqC,CAAC,KAAO,CAC5D,GAAI,QACJ,KAAM,gBACN,YAAa,QACb,kBAAmB,MACnB,GAAGA,CACL,GAEA,SAAS,aAAc,IAAM,CAC3B,SAAS,iBAAkB,IAAM,CAC/B,GAAG,+DAAgE,SAAY,CAC7E,MAAMC,EAAOJ,EAAsB,EAChC,aAAa,CACZ,OAAQ,OACR,SAAU,OACV,SAAU,CAAE,MAAO,UAAW,WAAY,EAAG,CAC/C,CAAC,EACA,aAAa,CACZ,OAAQ,MACR,SAAU,UACV,SAAU,CAAC,CACb,CAAC,EACGK,EAAS,IAAIJ,EAAW,wBAAyB,CACrD,WAAYG,CACd,CAAC,EAEKE,EAAU,MAAMD,EAAO,YAAY,EAEzC,OAAOA,EAAO,SAAS,CAAC,EAAE,KAAK,SAAS,EACxC,OAAOD,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,OACR,SAAU,OACV,KAAM,CAAC,CACT,CAAC,EACD,OAAOE,CAAO,EAAE,QAAQ,CAAC,CAAC,CAC5B,CAAC,EAED,GAAG,+CAAgD,SAAY,CAC7D,MAAMF,EAAOJ,EAAsB,EAAE,aAAa,CAChD,OAAQ,MACR,SAAU,UACV,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,CACxD,MAAMA,EAAW,CACf,QAAS,CACP,CACE,KAAM,cACN,YAAa,OACb,MAAO,CAAC,CAAE,OAAQ,WAAY,UAAW,CAAC,SAAU,MAAM,CAAE,CAAC,CAC/D,CACF,CACF,EACMnB,EAAOJ,EAAsB,EAAE,aAAa,CAChD,OAAQ,OACR,SAAU,SACV,SAAUuB,CACZ,CAAC,EAMKC,EAAS,MALA,IAAIvB,EAAW,wBAAyB,CACrD,MAAO,MACP,WAAYG,CACd,CAAC,EAE2B,cAAcmB,CAAQ,EAElD,OAAOC,CAAM,EAAE,QAAQD,CAAQ,EAC/B,OAAOnB,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,OACR,SAAU,SACV,KAAMmB,CACR,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,OAAQ,IAAM,CACrB,GAAG,yDAA0D,SAAY,CACvE,MAAMnB,EAAOJ,EAAsB,EAAE,aAAa,CAChD,OAAQ,OACR,SAAU,qBACV,SAAU,CAAE,SAAU,MAAO,CAC/B,CAAC,EAMKwB,EAAS,MALA,IAAIvB,EAAW,wBAAyB,CACrD,MAAO,MACP,WAAYG,CACd,CAAC,EAE2B,SAC1B,QACA,WAAW,KAAK,CAAC,IAAM,EAAM,EAAM,CAAI,CAAC,CAC1C,EAEA,OAAOoB,EAAO,QAAQ,EAAE,KAAK,MAAM,EACnC,OAAOpB,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,OACR,SAAU,qBACV,KAAM,CAAE,KAAM,UAAW,CAC3B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["httpClientStubBuilder", "MockClient", "aDevice", "overrides", "http", "client", "devices", "call", "token", "authCalls", "withSlash", "withoutSlash", "device", "state", "disconnectCalls", "mocks", "mock", "instance", "png", "screenshot", "request", "endpoint", "session", "snapshot", "result"]
4
+ "sourcesContent": ["import { httpClientStubBuilder } from \"./DmkNetworkClient.stub\";\nimport { MockClient } from \"./MockClient\";\n\nconst aDevice = (overrides: Record<string, unknown> = {}) => ({\n id: \"dev-1\",\n name: \"Ledger Nano X\",\n device_type: \"nanoX\",\n connectivity_type: \"USB\",\n ...overrides,\n});\n\ndescribe(\"MockClient\", () => {\n describe(\"authentication\", () => {\n it(\"lazily creates a session via /auth when no token is provided\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-123\", expires_at: 42 },\n })\n .mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n const devices = await client.listDevices();\n\n expect(client.getToken()).toBe(\"tok-123\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"auth\",\n body: {},\n });\n expect(devices).toEqual([]);\n });\n\n it(\"does not call /auth when a token is injected\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"injected\",\n httpClient: http,\n });\n\n await client.listDevices();\n\n expect(client.getToken()).toBe(\"injected\");\n expect(\n http.calls.find((call) => call.endpoint === \"auth\"),\n ).toBeUndefined();\n });\n\n it(\"returns the token from an explicit authenticate() call\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-abc\", expires_at: 99 },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n const token = await client.authenticate();\n\n expect(token).toBe(\"tok-abc\");\n expect(client.getToken()).toBe(\"tok-abc\");\n });\n\n it(\"reuses a single in-flight /auth call for concurrent requests\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok-shared\", expires_at: 1 },\n })\n .mockResponse({ method: \"get\", endpoint: \"devices\", response: [] });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n await Promise.all([client.listDevices(), client.listDevices()]);\n\n const authCalls = http.calls.filter((call) => call.endpoint === \"auth\");\n expect(authCalls).toHaveLength(1);\n });\n\n it(\"returns undefined token before any session is established\", () => {\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: httpClientStubBuilder(),\n });\n\n expect(client.getToken()).toBeUndefined();\n });\n });\n\n describe(\"constructor\", () => {\n it(\"normalizes a base url without a trailing slash\", () => {\n const withSlash = new MockClient(\"http://localhost:8080/\");\n const withoutSlash = new MockClient(\"http://localhost:8080\");\n\n expect(withSlash.getToken()).toBeUndefined();\n expect(withoutSlash.getToken()).toBeUndefined();\n });\n });\n\n describe(\"health\", () => {\n it(\"checks the server health without creating a session\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"health\",\n response: { status: \"ok\", sessions: 3 },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n });\n\n const health = await client.getHealth();\n\n expect(health).toEqual({ status: \"ok\", sessions: 3 });\n expect(http.calls).toEqual([{ method: \"get\", endpoint: \"health\" }]);\n expect(http.configs[0]?.config?.headers).toBeUndefined();\n });\n });\n\n describe(\"timeout\", () => {\n it(\"applies the timeout to every request, the implicit /auth included\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"post\",\n endpoint: \"auth\",\n response: { token: \"tok\", expires_at: 1 },\n })\n .mockResponse({ method: \"get\", endpoint: \"devices\", response: [] });\n const client = new MockClient(\"http://localhost:8080\", {\n httpClient: http,\n timeoutMs: 4000,\n });\n\n await client.listDevices();\n\n expect(http.configs.map(({ config }) => config?.timeoutMs)).toEqual([\n 4000, 4000,\n ]);\n });\n\n it(\"sets no timeout by default\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.listDevices();\n\n expect(http.configs[0]?.config?.timeoutMs).toBeUndefined();\n });\n });\n\n describe(\"devices\", () => {\n it(\"lists devices\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [aDevice()],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const devices = await client.listDevices();\n\n expect(devices).toEqual([expect.objectContaining({ id: \"dev-1\" })]);\n });\n\n it(\"adds a device with a default empty config\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices\",\n response: aDevice(),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.addDevice();\n\n expect(device.id).toBe(\"dev-1\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices\",\n body: {},\n });\n });\n\n it(\"gets a single device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1\",\n response: aDevice(),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.getDevice(\"dev-1\");\n\n expect(device.id).toBe(\"dev-1\");\n });\n\n it(\"edits a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"patch\",\n endpoint: \"devices/dev-1\",\n response: aDevice({ name: \"Renamed\" }),\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const device = await client.editDevice(\"dev-1\", { name: \"Renamed\" });\n\n expect(device.name).toBe(\"Renamed\");\n expect(http.calls).toContainEqual({\n method: \"patch\",\n endpoint: \"devices/dev-1\",\n body: { name: \"Renamed\" },\n });\n });\n\n it(\"deletes a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.deleteDevice(\"dev-1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1\",\n });\n });\n });\n\n describe(\"connection state\", () => {\n it(\"connects a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/connect\",\n response: { device: aDevice(), connected: true },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const state = await client.connect(\"dev-1\");\n\n expect(state.connected).toBe(true);\n expect(state.device.id).toBe(\"dev-1\");\n });\n\n it(\"disconnects a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/disconnect\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disconnect(\"dev-1\")).resolves.toBe(true);\n });\n\n it(\"disconnects every connected device\", async () => {\n const http = httpClientStubBuilder()\n .mockResponse({\n method: \"get\",\n endpoint: \"devices\",\n response: [\n aDevice({ id: \"dev-1\", connected: true }),\n aDevice({ id: \"dev-2\", connected: false }),\n aDevice({ id: \"dev-3\", connected: true }),\n ],\n })\n .mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/disconnect\",\n response: {},\n })\n .mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-3/disconnect\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disconnectAll()).resolves.toBe(true);\n\n const disconnectCalls = http.calls.filter((call) =>\n call.endpoint.endsWith(\"/disconnect\"),\n );\n expect(disconnectCalls.map((call) => call.endpoint)).toEqual([\n \"devices/dev-1/disconnect\",\n \"devices/dev-3/disconnect\",\n ]);\n });\n });\n\n describe(\"mocks\", () => {\n it(\"lists device-scoped mocks\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/mocks\",\n response: [{ id: \"m1\", prefix: \"e0010000\", responses: [\"9000\"] }],\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mocks = await client.listMocks(\"dev-1\");\n\n expect(mocks).toEqual([expect.objectContaining({ id: \"m1\" })]);\n });\n\n it(\"creates a device-scoped mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/mocks\",\n response: { id: \"m1\", prefix: \"e0010000\", responses: [\"9000\"] },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mock = await client.addMock(\"dev-1\", {\n prefix: \"e0010000\",\n response: \"9000\",\n });\n\n expect(mock.id).toBe(\"m1\");\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/mocks\",\n body: { prefix: \"e0010000\", response: \"9000\" },\n });\n });\n\n it(\"edits a mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"patch\",\n endpoint: \"devices/dev-1/mocks/m1\",\n response: { id: \"m1\", prefix: \"e0010000\", responses: [\"6985\"] },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const mock = await client.editMock(\"dev-1\", \"m1\", {\n prefix: \"e0010000\",\n response: \"6985\",\n });\n\n expect(mock.responses).toEqual([\"6985\"]);\n expect(http.calls).toContainEqual({\n method: \"patch\",\n endpoint: \"devices/dev-1/mocks/m1\",\n body: { prefix: \"e0010000\", response: \"6985\" },\n });\n });\n\n it(\"deletes a single mock\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks/m1\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.deleteMock(\"dev-1\", \"m1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks/m1\",\n });\n });\n\n it(\"clears all mocks of a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.clearMocks(\"dev-1\")).resolves.toBe(true);\n expect(http.calls).toContainEqual({\n method: \"delete\",\n endpoint: \"devices/dev-1/mocks\",\n });\n });\n });\n\n describe(\"speculos\", () => {\n it(\"resolves the live speculos instance backing a device\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/speculos\",\n response: {\n run_id: \"run-1\",\n speculos_url: \"https://speculos:5000\",\n model: \"stax\",\n },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const instance = await client.getSpeculos(\"dev-1\");\n\n expect(instance).toEqual({\n run_id: \"run-1\",\n speculos_url: \"https://speculos:5000\",\n model: \"stax\",\n });\n });\n\n it(\"requests the screenshot as a blob\", async () => {\n const png = new Blob([new Uint8Array([0x89, 0x50])], {\n type: \"image/png\",\n });\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1/speculos/screenshot\",\n response: png,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const screenshot = await client.getScreenshot(\"dev-1\");\n\n expect(screenshot).toBe(png);\n // Anything but \"blob\" would decode the PNG as text and corrupt it.\n const request = http.configs.find(\n ({ endpoint }) => endpoint === \"devices/dev-1/speculos/screenshot\",\n );\n expect(request?.config?.responseType).toBe(\"blob\");\n });\n\n it(\"presses a button\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.pressButton(\"dev-1\", \"both\");\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/button/both\",\n body: { action: \"press-and-release\" },\n });\n });\n\n it(\"forwards an explicit button action\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.pressButton(\"dev-1\", \"left\", \"press\");\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/button/left\",\n body: { action: \"press\" },\n });\n });\n\n it(\"taps the screen at device coordinates\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.touchScreen(\"dev-1\", 200, 537);\n\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"devices/dev-1/speculos/finger\",\n body: { action: \"press-and-release\", x: 200, y: 537 },\n });\n });\n });\n\n describe(\"session\", () => {\n it(\"fetches the current session\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"sessions/current\",\n response: {\n id: \"sess-1\",\n created_at: 1,\n expires_at: 2,\n devices: [aDevice()],\n },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const session = await client.getSession();\n\n expect(session.id).toBe(\"sess-1\");\n expect(session.devices).toHaveLength(1);\n });\n\n it(\"sets the session seed with the bearer token\", async () => {\n const http = httpClientStubBuilder();\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await client.setSeed(\"abandon abandon about\");\n\n expect(http.calls).toEqual([\n {\n method: \"put\",\n endpoint: \"sessions/current/seed\",\n body: { seed: \"abandon abandon about\" },\n },\n ]);\n expect(http.configs[0]?.config?.headers).toEqual({\n Authorization: \"Bearer tok\",\n });\n });\n\n it(\"disposes the session and clears the stored token\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"delete\",\n endpoint: \"sessions/current\",\n response: {},\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.disposeSession()).resolves.toBe(true);\n expect(client.getToken()).toBeUndefined();\n });\n });\n\n describe(\"response validation\", () => {\n it(\"throws a descriptive error when the server response is malformed\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"devices/dev-1\",\n response: { id: 123 } as unknown as object,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n await expect(client.getDevice(\"dev-1\")).rejects.toThrow(\n /MockClient: invalid server response/,\n );\n });\n });\n\n describe(\"import/export\", () => {\n it(\"exports the session snapshot\", async () => {\n const snapshot = {\n devices: [\n {\n name: \"Ledger Stax\",\n device_type: \"stax\",\n mocks: [{ prefix: \"ff\", responses: [\"9000\"] }],\n },\n ],\n };\n const http = httpClientStubBuilder().mockResponse({\n method: \"get\",\n endpoint: \"export\",\n response: snapshot,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.exportSession();\n\n expect(result).toEqual(snapshot);\n });\n\n it(\"posts a snapshot to the import endpoint\", async () => {\n const snapshot = {\n devices: [\n {\n name: \"Ledger Flex\",\n device_type: \"flex\",\n mocks: [{ prefix: \"e0010000\", responses: [\"aa9000\", \"5515\"] }],\n },\n ],\n };\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"import\",\n response: snapshot,\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.importSession(snapshot);\n\n expect(result).toEqual(snapshot);\n expect(http.calls).toContainEqual({\n method: \"post\",\n endpoint: \"import\",\n body: snapshot,\n });\n });\n });\n\n describe(\"apdu\", () => {\n it(\"sends a binary APDU as hex to the device apdu endpoint\", async () => {\n const http = httpClientStubBuilder().mockResponse({\n method: \"post\",\n endpoint: \"devices/dev-1/apdu\",\n response: { response: \"9000\" },\n });\n const client = new MockClient(\"http://localhost:8080\", {\n token: \"tok\",\n httpClient: http,\n });\n\n const result = await client.sendApdu(\n \"dev-1\",\n Uint8Array.from([0xe0, 0x01, 0x00, 0x00]),\n );\n\n expect(result.response).toBe(\"9000\");\n expect(http.calls).toContainEqual({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,CACjC,CAAC,EAED,GAAG,0CAA2C,SAAY,CACxD,MAAMA,EAAW,CACf,QAAS,CACP,CACE,KAAM,cACN,YAAa,OACb,MAAO,CAAC,CAAE,OAAQ,WAAY,UAAW,CAAC,SAAU,MAAM,CAAE,CAAC,CAC/D,CACF,CACF,EACMrB,EAAOJ,EAAsB,EAAE,aAAa,CAChD,OAAQ,OACR,SAAU,SACV,SAAUyB,CACZ,CAAC,EAMKC,EAAS,MALA,IAAIzB,EAAW,wBAAyB,CACrD,MAAO,MACP,WAAYG,CACd,CAAC,EAE2B,cAAcqB,CAAQ,EAElD,OAAOC,CAAM,EAAE,QAAQD,CAAQ,EAC/B,OAAOrB,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,OACR,SAAU,SACV,KAAMqB,CACR,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,OAAQ,IAAM,CACrB,GAAG,yDAA0D,SAAY,CACvE,MAAMrB,EAAOJ,EAAsB,EAAE,aAAa,CAChD,OAAQ,OACR,SAAU,qBACV,SAAU,CAAE,SAAU,MAAO,CAC/B,CAAC,EAMK0B,EAAS,MALA,IAAIzB,EAAW,wBAAyB,CACrD,MAAO,MACP,WAAYG,CACd,CAAC,EAE2B,SAC1B,QACA,WAAW,KAAK,CAAC,IAAM,EAAM,EAAM,CAAI,CAAC,CAC1C,EAEA,OAAOsB,EAAO,QAAQ,EAAE,KAAK,MAAM,EACnC,OAAOtB,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,OACR,SAAU,qBACV,KAAM,CAAE,KAAM,UAAW,CAC3B,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["httpClientStubBuilder", "MockClient", "aDevice", "overrides", "http", "client", "devices", "call", "token", "authCalls", "withSlash", "withoutSlash", "health", "config", "device", "state", "disconnectCalls", "mocks", "mock", "instance", "png", "screenshot", "request", "endpoint", "session", "snapshot", "result"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{MockClient as t}from"./MockClient";import{catalogAppCodec as n,deviceConfigCodec as c}from"./model/Device";import{mockConfigCodec as s}from"./model/Mock";import{sessionExportCodec as m}from"./model/SessionExport";export{t as MockClient,n as catalogAppCodec,c as deviceConfigCodec,s as mockConfigCodec,m as sessionExportCodec};
1
+ import{MockClient as t}from"./MockClient";import{catalogAppCodec as n,deviceConfigCodec as c}from"./model/Device";import{mockConfigCodec as i}from"./model/Mock";import{sessionExportCodec as m}from"./model/SessionExport";export{t as MockClient,n as catalogAppCodec,c as deviceConfigCodec,i as mockConfigCodec,m as sessionExportCodec};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/index.ts"],
4
- "sourcesContent": ["export type { MockClientOptions } from \"./MockClient\";\nexport { MockClient } from \"./MockClient\";\nexport type { AuthResponse, ConnectionState } from \"./model/Auth\";\nexport type { CommandResponse } from \"./model/CommandResponse\";\nexport {\n type CatalogApp,\n catalogAppCodec,\n type Device,\n type DeviceApp,\n type DeviceConfig,\n deviceConfigCodec,\n type DeviceConnectivityType,\n} from \"./model/Device\";\nexport { type Mock, type MockConfig, mockConfigCodec } from \"./model/Mock\";\nexport type { Session } from \"./model/Session\";\nexport { type SessionExport, sessionExportCodec } from \"./model/SessionExport\";\nexport type {\n SpeculosAction,\n SpeculosButton,\n SpeculosInstance,\n} from \"./model/Speculos\";\n"],
5
- "mappings": "AACA,OAAS,cAAAA,MAAkB,eAG3B,OAEE,mBAAAC,EAIA,qBAAAC,MAEK,iBACP,OAAqC,mBAAAC,MAAuB,eAE5D,OAA6B,sBAAAC,MAA0B",
4
+ "sourcesContent": ["export type { MockClientOptions } from \"./MockClient\";\nexport { MockClient } from \"./MockClient\";\nexport type { AuthResponse, ConnectionState } from \"./model/Auth\";\nexport type { CommandResponse } from \"./model/CommandResponse\";\nexport {\n type CatalogApp,\n catalogAppCodec,\n type Device,\n type DeviceApp,\n type DeviceConfig,\n deviceConfigCodec,\n type DeviceConnectivityType,\n} from \"./model/Device\";\nexport type { Health } from \"./model/Health\";\nexport { type Mock, type MockConfig, mockConfigCodec } from \"./model/Mock\";\nexport type { Session } from \"./model/Session\";\nexport { type SessionExport, sessionExportCodec } from \"./model/SessionExport\";\nexport type {\n SpeculosAction,\n SpeculosButton,\n SpeculosInstance,\n} from \"./model/Speculos\";\n"],
5
+ "mappings": "AACA,OAAS,cAAAA,MAAkB,eAG3B,OAEE,mBAAAC,EAIA,qBAAAC,MAEK,iBAEP,OAAqC,mBAAAC,MAAuB,eAE5D,OAA6B,sBAAAC,MAA0B",
6
6
  "names": ["MockClient", "catalogAppCodec", "deviceConfigCodec", "mockConfigCodec", "sessionExportCodec"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import{Codec as e,number as s,string as t}from"purify-ts";const n=e.interface({status:t,sessions:s});export{n as healthCodec};
2
+ //# sourceMappingURL=Health.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/model/Health.ts"],
4
+ "sourcesContent": ["import { Codec, number, string } from \"purify-ts\";\n\n/** Response of GET /health. */\nexport interface Health {\n readonly status: string;\n readonly sessions: number;\n}\n\nexport const healthCodec = Codec.interface({\n status: string,\n sessions: number,\n});\n"],
5
+ "mappings": "AAAA,OAAS,SAAAA,EAAO,UAAAC,EAAQ,UAAAC,MAAc,YAQ/B,MAAMC,EAAcH,EAAM,UAAU,CACzC,OAAQE,EACR,SAAUD,CACZ,CAAC",
6
+ "names": ["Codec", "number", "string", "healthCodec"]
7
+ }
@@ -1,5 +1,5 @@
1
1
  import { type DmkNetworkClient, type DmkRequestConfig } from "@ledgerhq/device-management-kit";
2
- type Method = "get" | "post" | "patch" | "delete";
2
+ type Method = "get" | "post" | "put" | "patch" | "delete";
3
3
  export type DmkNetworkClientStub = DmkNetworkClient & {
4
4
  responses: Record<Method, Record<string, unknown>>;
5
5
  calls: {
@@ -1 +1 @@
1
- {"version":3,"file":"DmkNetworkClient.stub.d.ts","sourceRoot":"","sources":["../../../src/DmkNetworkClient.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,KAAK,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAElD,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7D,6EAA6E;IAC7E,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE,EAAE,CAAC;IAC3E,YAAY,CAAC,IAAI,EAAE;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,oBAAoB,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,oBAiExC,CAAC"}
1
+ {"version":3,"file":"DmkNetworkClient.stub.d.ts","sourceRoot":"","sources":["../../../src/DmkNetworkClient.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC;AAEzC,KAAK,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1D,MAAM,MAAM,oBAAoB,GAAG,gBAAgB,GAAG;IACpD,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACnD,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC7D,6EAA6E;IAC7E,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE,EAAE,CAAC;IAC3E,YAAY,CAAC,IAAI,EAAE;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,oBAAoB,CAAC;CAC1B,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,oBA2ExC,CAAC"}
@@ -2,6 +2,7 @@ import { DmkNetworkClient } from "@ledgerhq/device-management-kit";
2
2
  import { type ConnectionState } from "./model/Auth";
3
3
  import { type CommandResponse } from "./model/CommandResponse";
4
4
  import { type Device, type DeviceConfig } from "./model/Device";
5
+ import { type Health } from "./model/Health";
5
6
  import { type Mock, type MockConfig } from "./model/Mock";
6
7
  import { type Session } from "./model/Session";
7
8
  import { type SessionExport } from "./model/SessionExport";
@@ -15,6 +16,8 @@ export interface MockClientOptions {
15
16
  readonly token?: string;
16
17
  /** Inject a custom network client (mainly for testing). */
17
18
  readonly httpClient?: DmkNetworkClient;
19
+ /** Abort each request after this many milliseconds. Unset means no timeout. */
20
+ readonly timeoutMs?: number;
18
21
  }
19
22
  /**
20
23
  * HTTP client for the device mock server.
@@ -26,9 +29,11 @@ export interface MockClientOptions {
26
29
  */
27
30
  export declare class MockClient {
28
31
  private readonly client;
32
+ private readonly timeoutMs?;
29
33
  private token?;
30
34
  private authPromise?;
31
35
  constructor(baseUrl: string, options?: MockClientOptions);
36
+ getHealth(): Promise<Health>;
32
37
  /** Create a session and store the returned bearer token. */
33
38
  authenticate(): Promise<string>;
34
39
  /** The current bearer token, if a session has been established. */
@@ -64,6 +69,11 @@ export declare class MockClient {
64
69
  /** Tap a touchscreen device, in device screen pixels. */
65
70
  touchScreen(deviceId: string, x: number, y: number, action?: SpeculosAction): Promise<void>;
66
71
  getSession(): Promise<Session>;
72
+ /**
73
+ * Set the BIP39 mnemonic of the Speculos instances the session starts next.
74
+ * Use test mnemonics only: the server keeps the seed in plaintext.
75
+ */
76
+ setSeed(seed: string): Promise<void>;
67
77
  disposeSession(): Promise<boolean>;
68
78
  /** Export the session's devices and mocks as a portable snapshot. */
69
79
  exportSession(): Promise<SessionExport>;
@@ -73,7 +83,8 @@ export declare class MockClient {
73
83
  */
74
84
  importSession(snapshot: SessionExport): Promise<SessionExport>;
75
85
  private decode;
76
- private authHeaders;
86
+ private requestConfig;
87
+ private authRequestConfig;
77
88
  private ensureToken;
78
89
  private normalizeUrl;
79
90
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MockClient.d.ts","sourceRoot":"","sources":["../../../src/MockClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EACjB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,MAAM,EAAe,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,KAAK,IAAI,EAAa,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,KAAK,OAAO,EAAgB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,KAAK,aAAa,EAAsB,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EAEtB,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAA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AAC,IAAI,CAAC;IAQhB,yDAAyD;IACnD,WAAW,CACf,QAAQ,EAAE,MAAM,EAChB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,GAAE,cAAoC,GAC3C,OAAO,CAAC,IAAI,CAAC;IAUV,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAQpC;;;OAGG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpC,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC;IAYxC,qEAAqE;IAC/D,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC;IAQ7C;;;OAGG;IACG,aAAa,CAAC,QAAQ,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAWpE,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,aAAa;YAIP,iBAAiB;IAQ/B,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,YAAY;CAGrB"}
@@ -3,6 +3,7 @@ export { MockClient } from "./MockClient";
3
3
  export type { AuthResponse, ConnectionState } from "./model/Auth";
4
4
  export type { CommandResponse } from "./model/CommandResponse";
5
5
  export { type CatalogApp, catalogAppCodec, type Device, type DeviceApp, type DeviceConfig, deviceConfigCodec, type DeviceConnectivityType, } from "./model/Device";
6
+ export type { Health } from "./model/Health";
6
7
  export { type Mock, type MockConfig, mockConfigCodec } from "./model/Mock";
7
8
  export type { Session } from "./model/Session";
8
9
  export { type SessionExport, sessionExportCodec } from "./model/SessionExport";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAClE,YAAY,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;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import { Codec } from "purify-ts";
2
+ /** Response of GET /health. */
3
+ export interface Health {
4
+ readonly status: string;
5
+ readonly sessions: number;
6
+ }
7
+ export declare const healthCodec: Codec<{
8
+ status: string;
9
+ sessions: number;
10
+ }>;
11
+ //# sourceMappingURL=Health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Health.d.ts","sourceRoot":"","sources":["../../../../src/model/Health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAkB,MAAM,WAAW,CAAC;AAElD,+BAA+B;AAC/B,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,WAAW;;;EAGtB,CAAC"}