@ledgerhq/device-mockserver-client 1.2.0 → 1.3.0
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.
- package/lib/cjs/package.json +2 -2
- package/lib/cjs/src/DmkNetworkClient.stub.js +1 -1
- package/lib/cjs/src/DmkNetworkClient.stub.js.map +3 -3
- package/lib/cjs/src/MockClient.js +1 -1
- package/lib/cjs/src/MockClient.js.map +3 -3
- package/lib/cjs/src/MockClient.test.js +1 -1
- package/lib/cjs/src/MockClient.test.js.map +3 -3
- package/lib/cjs/src/index.js +1 -1
- package/lib/cjs/src/index.js.map +1 -1
- package/lib/cjs/src/model/Device.js +1 -1
- package/lib/cjs/src/model/Device.js.map +2 -2
- package/lib/cjs/src/model/Speculos.js +1 -1
- package/lib/cjs/src/model/Speculos.js.map +1 -1
- package/lib/esm/package.json +2 -2
- package/lib/esm/src/DmkNetworkClient.stub.js +1 -1
- package/lib/esm/src/DmkNetworkClient.stub.js.map +3 -3
- package/lib/esm/src/MockClient.js +1 -1
- package/lib/esm/src/MockClient.js.map +3 -3
- package/lib/esm/src/MockClient.test.js +1 -1
- package/lib/esm/src/MockClient.test.js.map +3 -3
- package/lib/esm/src/index.js +1 -1
- package/lib/esm/src/index.js.map +1 -1
- package/lib/esm/src/model/Device.js +1 -1
- package/lib/esm/src/model/Device.js.map +2 -2
- package/lib/esm/src/model/Speculos.js +1 -1
- package/lib/esm/src/model/Speculos.js.map +1 -1
- package/lib/types/src/DmkNetworkClient.stub.d.ts +7 -1
- package/lib/types/src/DmkNetworkClient.stub.d.ts.map +1 -1
- package/lib/types/src/MockClient.d.ts +11 -1
- package/lib/types/src/MockClient.d.ts.map +1 -1
- package/lib/types/src/index.d.ts +1 -1
- package/lib/types/src/index.d.ts.map +1 -1
- package/lib/types/src/model/Auth.d.ts +2 -0
- package/lib/types/src/model/Auth.d.ts.map +1 -1
- package/lib/types/src/model/Device.d.ts +24 -0
- package/lib/types/src/model/Device.d.ts.map +1 -1
- package/lib/types/src/model/Session.d.ts +2 -0
- package/lib/types/src/model/Session.d.ts.map +1 -1
- package/lib/types/src/model/SessionExport.d.ts +2 -0
- package/lib/types/src/model/SessionExport.d.ts.map +1 -1
- package/lib/types/src/model/Speculos.d.ts +7 -0
- package/lib/types/src/model/Speculos.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
package/lib/cjs/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"main": "lib/index.js",
|
|
30
30
|
"name": "@ledgerhq/device-mockserver-client",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@ledgerhq/device-management-kit": "^1.
|
|
32
|
+
"@ledgerhq/device-management-kit": "^1.9.0"
|
|
33
33
|
},
|
|
34
34
|
"private": false,
|
|
35
35
|
"repository": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
53
53
|
},
|
|
54
54
|
"types": "lib/index.d.ts",
|
|
55
|
-
"version": "1.
|
|
55
|
+
"version": "1.3.0"
|
|
56
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(
|
|
1
|
+
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var c=(t,e)=>{for(var s in e)r(t,s,{get:e[s],enumerable:!0})},u=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of h(e))!p.call(t,n)&&n!==s&&r(t,n,{get:()=>e[n],enumerable:!(o=i(e,n))||o.enumerable});return t};var m=t=>u(r({},"__esModule",{value:!0}),t);var g={};c(g,{httpClientStubBuilder:()=>d});module.exports=m(g);const d=()=>new class{responses;calls;configs;constructor(){this.responses={get:{},post:{},patch:{},delete:{}},this.calls=[],this.configs=[]}get(e,s){return this.calls.push({method:"get",endpoint:e}),this.configs.push({method:"get",endpoint:e,config:s}),Promise.resolve(this.responses.get[e])}post(e,s,o){return this.calls.push({method:"post",endpoint:e,body:s}),this.configs.push({method:"post",endpoint:e,config:o}),Promise.resolve(this.responses.post[e])}patch(e,s,o){return this.calls.push({method:"patch",endpoint:e,body:s}),this.configs.push({method:"patch",endpoint:e,config:o}),Promise.resolve(this.responses.patch[e])}delete(e,s){return this.calls.push({method:"delete",endpoint:e}),this.configs.push({method:"delete",endpoint:e,config:s}),Promise.resolve(this.responses.delete[e])}mockResponse({method:e,endpoint:s,response:o}){return this.responses={...this.responses,[e]:{...this.responses[e],[s]:o}},this}};0&&(module.exports={httpClientStubBuilder});
|
|
2
2
|
//# sourceMappingURL=DmkNetworkClient.stub.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DmkNetworkClient.stub.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type DmkNetworkClient,\n type DmkRequestConfig,\n} from \"@ledgerhq/device-management-kit\";\n\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\";\n\nexport type DmkNetworkClientStub = DmkNetworkClient & {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n mockResponse(args: {\n method: Method;\n endpoint: string;\n response: object;\n }): DmkNetworkClientStub;\n};\n\nexport const httpClientStubBuilder = (): DmkNetworkClientStub => {\n const stub = new (class {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n\n constructor() {\n this.responses = { get: {}, post: {}, patch: {}, delete: {} };\n this.calls = [];\n }\n\n get(endpoint: string,
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,
|
|
6
|
-
"names": ["DmkNetworkClient_stub_exports", "__export", "httpClientStubBuilder", "__toCommonJS", "endpoint", "
|
|
4
|
+
"sourcesContent": ["import {\n type DmkNetworkClient,\n type DmkRequestConfig,\n} from \"@ledgerhq/device-management-kit\";\n\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\";\n\nexport type DmkNetworkClientStub = DmkNetworkClient & {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n /** Per-call request config, kept aside so `calls` stays easy to match on. */\n configs: { method: Method; endpoint: string; config?: DmkRequestConfig }[];\n mockResponse(args: {\n method: Method;\n endpoint: string;\n response: object;\n }): DmkNetworkClientStub;\n};\n\nexport const httpClientStubBuilder = (): DmkNetworkClientStub => {\n const stub = new (class {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n configs: { method: Method; endpoint: string; config?: DmkRequestConfig }[];\n\n constructor() {\n this.responses = { get: {}, post: {}, patch: {}, delete: {} };\n this.calls = [];\n this.configs = [];\n }\n\n get(endpoint: string, config?: DmkRequestConfig): Promise<unknown> {\n this.calls.push({ method: \"get\", endpoint });\n this.configs.push({ method: \"get\", endpoint, config });\n return Promise.resolve(this.responses.get[endpoint]);\n }\n\n post(\n endpoint: string,\n body?: unknown,\n config?: DmkRequestConfig,\n ): Promise<unknown> {\n this.calls.push({ method: \"post\", endpoint, body: body as object });\n this.configs.push({ method: \"post\", endpoint, config });\n return Promise.resolve(this.responses.post[endpoint]);\n }\n\n patch(\n endpoint: string,\n body?: unknown,\n config?: DmkRequestConfig,\n ): Promise<unknown> {\n this.calls.push({ method: \"patch\", endpoint, body: body as object });\n this.configs.push({ method: \"patch\", endpoint, config });\n return Promise.resolve(this.responses.patch[endpoint]);\n }\n\n delete(endpoint: string, config?: DmkRequestConfig): Promise<unknown> {\n this.calls.push({ method: \"delete\", endpoint });\n this.configs.push({ method: \"delete\", endpoint, config });\n return Promise.resolve(this.responses.delete[endpoint]);\n }\n\n mockResponse({\n method,\n endpoint,\n response,\n }: {\n method: Method;\n endpoint: string;\n response: object;\n }) {\n this.responses = {\n ...this.responses,\n [method]: {\n ...this.responses[method],\n [endpoint]: response,\n },\n };\n return this;\n }\n })();\n\n return stub as unknown as DmkNetworkClientStub;\n};\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAmBO,MAAME,EAAwB,IACtB,IAAK,KAAM,CACtB,UACA,MACA,QAEA,aAAc,CACZ,KAAK,UAAY,CAAE,IAAK,CAAC,EAAG,KAAM,CAAC,EAAG,MAAO,CAAC,EAAG,OAAQ,CAAC,CAAE,EAC5D,KAAK,MAAQ,CAAC,EACd,KAAK,QAAU,CAAC,CAClB,CAEA,IAAIE,EAAkBC,EAA6C,CACjE,YAAK,MAAM,KAAK,CAAE,OAAQ,MAAO,SAAAD,CAAS,CAAC,EAC3C,KAAK,QAAQ,KAAK,CAAE,OAAQ,MAAO,SAAAA,EAAU,OAAAC,CAAO,CAAC,EAC9C,QAAQ,QAAQ,KAAK,UAAU,IAAID,CAAQ,CAAC,CACrD,CAEA,KACEA,EACAE,EACAD,EACkB,CAClB,YAAK,MAAM,KAAK,CAAE,OAAQ,OAAQ,SAAAD,EAAU,KAAME,CAAe,CAAC,EAClE,KAAK,QAAQ,KAAK,CAAE,OAAQ,OAAQ,SAAAF,EAAU,OAAAC,CAAO,CAAC,EAC/C,QAAQ,QAAQ,KAAK,UAAU,KAAKD,CAAQ,CAAC,CACtD,CAEA,MACEA,EACAE,EACAD,EACkB,CAClB,YAAK,MAAM,KAAK,CAAE,OAAQ,QAAS,SAAAD,EAAU,KAAME,CAAe,CAAC,EACnE,KAAK,QAAQ,KAAK,CAAE,OAAQ,QAAS,SAAAF,EAAU,OAAAC,CAAO,CAAC,EAChD,QAAQ,QAAQ,KAAK,UAAU,MAAMD,CAAQ,CAAC,CACvD,CAEA,OAAOA,EAAkBC,EAA6C,CACpE,YAAK,MAAM,KAAK,CAAE,OAAQ,SAAU,SAAAD,CAAS,CAAC,EAC9C,KAAK,QAAQ,KAAK,CAAE,OAAQ,SAAU,SAAAA,EAAU,OAAAC,CAAO,CAAC,EACjD,QAAQ,QAAQ,KAAK,UAAU,OAAOD,CAAQ,CAAC,CACxD,CAEA,aAAa,CACX,OAAAG,EACA,SAAAH,EACA,SAAAI,CACF,EAIG,CACD,YAAK,UAAY,CACf,GAAG,KAAK,UACR,CAACD,CAAM,EAAG,CACR,GAAG,KAAK,UAAUA,CAAM,EACxB,CAACH,CAAQ,EAAGI,CACd,CACF,EACO,IACT,CACF",
|
|
6
|
+
"names": ["DmkNetworkClient_stub_exports", "__export", "httpClientStubBuilder", "__toCommonJS", "endpoint", "config", "body", "method", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var v=(a,e)=>{for(var t in e)d(a,t,{get:e[t],enumerable:!0})},y=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of g(e))!k.call(a,i)&&i!==t&&d(a,i,{get:()=>e[i],enumerable:!(s=w(e,i))||s.enumerable});return a};var P=a=>y(d({},"__esModule",{value:!0}),a);var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var v=(a,e)=>{for(var t in e)d(a,t,{get:e[t],enumerable:!0})},y=(a,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of g(e))!k.call(a,i)&&i!==t&&d(a,i,{get:()=>e[i],enumerable:!(s=w(e,i))||s.enumerable});return a};var P=a=>y(d({},"__esModule",{value:!0}),a);var C={};v(C,{MockClient:()=>f});module.exports=P(C);var r=require("@ledgerhq/device-management-kit"),h=require("purify-ts"),c=require("./model/Auth"),l=require("./model/CommandResponse"),n=require("./model/Device"),o=require("./model/Mock"),p=require("./model/Session"),u=require("./model/SessionExport"),m=require("./model/Speculos");class f{client;token;authPromise;constructor(e,t={}){this.client=t.httpClient??new r.DmkNetworkClient({baseUrl:this.normalizeUrl(e)}),this.token=t.token}async authenticate(){const e=await this.client.post("auth",{}),t=this.decode(c.authResponseCodec,e).token;return this.token=t,t}getToken(){return this.token}async listDevices(){const e=await this.client.get("devices",{headers:await this.authHeaders()});return this.decode((0,h.array)(n.deviceCodec),e)}async addDevice(e={}){const t=await this.client.post("devices",e,{headers:await this.authHeaders()});return this.decode(n.deviceCodec,t)}async getDevice(e){const t=await this.client.get(`devices/${e}`,{headers:await this.authHeaders()});return this.decode(n.deviceCodec,t)}async editDevice(e,t){const s=await this.client.patch(`devices/${e}`,t,{headers:await this.authHeaders()});return this.decode(n.deviceCodec,s)}async deleteDevice(e){return await this.client.delete(`devices/${e}`,{headers:await this.authHeaders()}),!0}async connect(e){const t=await this.client.post(`devices/${e}/connect`,{},{headers:await this.authHeaders()});return this.decode(c.connectionStateCodec,t)}async disconnect(e){return await this.client.post(`devices/${e}/disconnect`,{},{headers:await this.authHeaders()}),!0}async disconnectAll(){const e=await this.listDevices();return await Promise.all(e.filter(t=>t.connected).map(t=>this.disconnect(t.id))),!0}async sendApdu(e,t){const s=typeof t=="string"?t:(0,r.bufferToHexaString)(t,!1),i=await this.client.post(`devices/${e}/apdu`,{apdu:s},{headers:await this.authHeaders()});return this.decode(l.commandResponseCodec,i)}async listMocks(e){const t=await this.client.get(`devices/${e}/mocks`,{headers:await this.authHeaders()});return this.decode((0,h.array)(o.mockCodec),t)}async addMock(e,t){const s=await this.client.post(`devices/${e}/mocks`,t,{headers:await this.authHeaders()});return this.decode(o.mockCodec,s)}async editMock(e,t,s){const i=await this.client.patch(`devices/${e}/mocks/${t}`,s,{headers:await this.authHeaders()});return this.decode(o.mockCodec,i)}async deleteMock(e,t){return await this.client.delete(`devices/${e}/mocks/${t}`,{headers:await this.authHeaders()}),!0}async clearMocks(e){return await this.client.delete(`devices/${e}/mocks`,{headers:await this.authHeaders()}),!0}async getSpeculos(e){const t=await this.client.get(`devices/${e}/speculos`,{headers:await this.authHeaders()});return this.decode(m.speculosInstanceCodec,t)}async getScreenshot(e){return await this.client.get(`devices/${e}/speculos/screenshot`,{headers:await this.authHeaders(),responseType:"blob"})}async pressButton(e,t,s="press-and-release"){await this.client.post(`devices/${e}/speculos/button/${t}`,{action:s},{headers:await this.authHeaders()})}async touchScreen(e,t,s,i="press-and-release"){await this.client.post(`devices/${e}/speculos/finger`,{action:i,x:t,y:s},{headers:await this.authHeaders()})}async getSession(){const e=await this.client.get("sessions/current",{headers:await this.authHeaders()});return this.decode(p.sessionCodec,e)}async disposeSession(){return await this.client.delete("sessions/current",{headers:await this.authHeaders()}),this.token=void 0,this.authPromise=void 0,!0}async exportSession(){const e=await this.client.get("export",{headers:await this.authHeaders()});return this.decode(u.sessionExportCodec,e)}async importSession(e){const t=await this.client.post("import",e,{headers:await this.authHeaders()});return this.decode(u.sessionExportCodec,t)}decode(e,t){return e.decode(t).caseOf({Left:s=>{throw new Error(`MockClient: invalid server response (${s})`)},Right:s=>s})}async authHeaders(){return{Authorization:`Bearer ${await this.ensureToken()}`}}ensureToken(){return this.token?Promise.resolve(this.token):(this.authPromise||(this.authPromise=this.authenticate()),this.authPromise)}normalizeUrl(e){return e.endsWith("/")?e:`${e}/`}}0&&(module.exports={MockClient});
|
|
2
2
|
//# sourceMappingURL=MockClient.js.map
|
|
@@ -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 { type SpeculosInstance, speculosInstanceCodec } 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 // --- 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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,2CACPC,EAAkC,qBAElCC,EAIO,wBACPC,EAGO,mCACPC,EAA4D,0BAC5DC,EAAsD,wBACtDC,EAA2C,2BAC3CC,EAAuD,iCACvDC,
|
|
6
|
-
"names": ["MockClient_exports", "__export", "MockClient", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_Auth", "import_CommandResponse", "import_Device", "import_Mock", "import_Session", "import_SessionExport", "import_Speculos", "baseUrl", "options", "data", "token", "config", "deviceId", "devices", "device", "apdu", "hex", "mockId", "snapshot", "codec", "error", "value"]
|
|
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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAGO,2CACPC,EAAkC,qBAElCC,EAIO,wBACPC,EAGO,mCACPC,EAA4D,0BAC5DC,EAAsD,wBACtDC,EAA2C,2BAC3CC,EAAuD,iCACvDC,EAKO,4BAqBA,MAAMV,CAAW,CACL,OACT,MACA,YAER,YAAYW,EAAiBC,EAA6B,CAAC,EAAG,CAC5D,KAAK,OACHA,EAAQ,YACR,IAAI,mBAAiB,CAAE,QAAS,KAAK,aAAaD,CAAO,CAAE,CAAC,EAC9D,KAAK,MAAQC,EAAQ,KACvB,CAKA,MAAM,cAAgC,CACpC,MAAMC,EAAO,MAAM,KAAK,OAAO,KAAK,OAAQ,CAAC,CAAC,EACxCC,EAAQ,KAAK,OAAO,oBAAmBD,CAAI,EAAE,MACnD,YAAK,MAAQC,EACNA,CACT,CAGA,UAA+B,CAC7B,OAAO,KAAK,KACd,CAIA,MAAM,aAAiC,CACrC,MAAMD,EAAO,MAAM,KAAK,OAAO,IAAI,UAAW,CAC5C,QAAS,MAAM,KAAK,YAAY,CAClC,CAAC,EACD,OAAO,KAAK,UAAO,SAAM,aAAW,EAAGA,CAAI,CAC7C,CAEA,MAAM,UAAUE,EAAuB,CAAC,EAAoB,CAC1D,MAAMF,EAAO,MAAM,KAA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M,IAAI,MAAM,wCAAwCA,CAAK,GAAG,CAClE,EACA,MAAQC,GAAUA,CACpB,CAAC,CACH,CAEA,MAAc,aAA+C,CAE3D,MAAO,CAAE,cAAe,UADV,MAAM,KAAK,YAAY,CACE,EAAG,CAC5C,CAEQ,aAA+B,CACrC,OAAI,KAAK,MACA,QAAQ,QAAQ,KAAK,KAAK,GAE9B,KAAK,cACR,KAAK,YAAc,KAAK,aAAa,GAEhC,KAAK,YACd,CAEQ,aAAalB,EAAyB,CAC5C,OAAOA,EAAQ,SAAS,GAAG,EAAIA,EAAU,GAAGA,CAAO,GACrD,CACF",
|
|
6
|
+
"names": ["MockClient_exports", "__export", "MockClient", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_Auth", "import_CommandResponse", "import_Device", "import_Mock", "import_Session", "import_SessionExport", "import_Speculos", "baseUrl", "options", "data", "token", "config", "deviceId", "devices", "device", "apdu", "hex", "mockId", "button", "action", "x", "y", "snapshot", "codec", "error", "value"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=require("./DmkNetworkClient.stub"),n=require("./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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-123",expires_at:42}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-abc",expires_at:99}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-shared",expires_at:1}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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.MockClient("http://localhost:8080",{httpClient:(0,s.httpClientStubBuilder)()});expect(e.getToken()).toBeUndefined()})}),describe("constructor",()=>{it("normalizes a base url without a trailing slash",()=>{const e=new n.MockClient("http://localhost:8080/"),t=new n.MockClient("http://localhost:8080");expect(e.getToken()).toBeUndefined(),expect(t.getToken()).toBeUndefined()})}),describe("devices",()=>{it("lists devices",async()=>{const e=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices",response:[i()]}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices",response:i()}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1",response:i()}),o=await new n.MockClient("http://localhost:8080",{token:"tok",httpClient:e}).getDevice("dev-1");expect(o.id).toBe("dev-1")}),it("edits a device",async()=>{const e=(0,s.httpClientStubBuilder)().mockResponse({method:"patch",endpoint:"devices/dev-1",response:i({name:"Renamed"})}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/connect",response:{device:i(),connected:!0}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}),t=new n.MockClient("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnect("dev-1")).resolves.toBe(!0)}),it("disconnects every connected device",async()=>{const e=(0,s.httpClientStubBuilder)().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.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1/mocks",response:[{id:"m1",prefix:"e0010000",responses:["9000"]}]}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/mocks",response:{id:"m1",prefix:"e0010000",responses:["9000"]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"patch",endpoint:"devices/dev-1/mocks/m1",response:{id:"m1",prefix:"e0010000",responses:["6985"]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks/m1",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1/speculos",response:{run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"}}),o=await new n.MockClient("http://localhost:8080",{token:"tok",httpClient:e}).getSpeculos("dev-1");expect(o).toEqual({run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"})})}),describe("session",()=>{it("fetches the current session",async()=>{const e=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"sessions/current",response:{id:"sess-1",created_at:1,expires_at:2,devices:[i()]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"sessions/current",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1",response:{id:123}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"export",response:e}),c=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"import",response:e}),c=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/apdu",response:{response:"9000"}}),o=await new n.MockClient("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
|
+
"use strict";var s=require("./DmkNetworkClient.stub"),n=require("./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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-123",expires_at:42}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-abc",expires_at:99}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"auth",response:{token:"tok-shared",expires_at:1}}).mockResponse({method:"get",endpoint:"devices",response:[]}),t=new n.MockClient("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.MockClient("http://localhost:8080",{httpClient:(0,s.httpClientStubBuilder)()});expect(e.getToken()).toBeUndefined()})}),describe("constructor",()=>{it("normalizes a base url without a trailing slash",()=>{const e=new n.MockClient("http://localhost:8080/"),t=new n.MockClient("http://localhost:8080");expect(e.getToken()).toBeUndefined(),expect(t.getToken()).toBeUndefined()})}),describe("devices",()=>{it("lists devices",async()=>{const e=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices",response:[i()]}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices",response:i()}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1",response:i()}),o=await new n.MockClient("http://localhost:8080",{token:"tok",httpClient:e}).getDevice("dev-1");expect(o.id).toBe("dev-1")}),it("edits a device",async()=>{const e=(0,s.httpClientStubBuilder)().mockResponse({method:"patch",endpoint:"devices/dev-1",response:i({name:"Renamed"})}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/connect",response:{device:i(),connected:!0}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/disconnect",response:{}}),t=new n.MockClient("http://localhost:8080",{token:"tok",httpClient:e});await expect(t.disconnect("dev-1")).resolves.toBe(!0)}),it("disconnects every connected device",async()=>{const e=(0,s.httpClientStubBuilder)().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.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1/mocks",response:[{id:"m1",prefix:"e0010000",responses:["9000"]}]}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/mocks",response:{id:"m1",prefix:"e0010000",responses:["9000"]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"patch",endpoint:"devices/dev-1/mocks/m1",response:{id:"m1",prefix:"e0010000",responses:["6985"]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks/m1",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"devices/dev-1/mocks",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1/speculos",response:{run_id:"run-1",speculos_url:"https://speculos:5000",model:"stax"}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1/speculos/screenshot",response:e}),c=await new n.MockClient("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=(0,s.httpClientStubBuilder)();await new n.MockClient("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=(0,s.httpClientStubBuilder)();await new n.MockClient("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=(0,s.httpClientStubBuilder)();await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"sessions/current",response:{id:"sess-1",created_at:1,expires_at:2,devices:[i()]}}),o=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"delete",endpoint:"sessions/current",response:{}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"devices/dev-1",response:{id:123}}),t=new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"get",endpoint:"export",response:e}),c=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"import",response:e}),c=await new n.MockClient("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=(0,s.httpClientStubBuilder)().mockResponse({method:"post",endpoint:"devices/dev-1/apdu",response:{response:"9000"}}),o=await new n.MockClient("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\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).toContain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AK,EAAI,EAC3D,OAAOD,EAAK,KAAK,EAAE,eAAe,CAChC,OAAQ,SACR,SAAU,qBACZ,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,WAAY,IAAM,CACzB,GAAG,uDAAwD,SAAY,CACrE,MAAMA,KAAO,yBAAsB,EAAE,aAAa,CAChD,OAAQ,MACR,SAAU,yBACV,SAAU,CACR,OAAQ,QACR,aAAc,wBACd,MAAO,MACT,CACF,CAAC,EAMKa,EAAW,MALF,IAAI,aAAW,wBAAyB,CACrD,MAAO,MACP,WAAYb,CACd,CAAC,EAE6B,YAAY,OAAO,EAEjD,OAAOa,CAAQ,EAAE,QAAQ,CACvB,OAAQ,QACR,aAAc,wBACd,MAAO,MACT,CAAC,CACH,CAAC,CACH,CAAC,EAED,SAAS,UAAW,IAAM,CACxB,GAAG,8BAA+B,SAAY,CAC5C,
|
|
6
|
-
"names": ["import_DmkNetworkClient", "import_MockClient", "aDevice", "overrides", "http", "client", "devices", "call", "token", "authCalls", "withSlash", "withoutSlash", "device", "state", "disconnectCalls", "mocks", "mock", "instance", "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(\"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,IAAAA,EAAsC,mCACtCC,EAA2B,wBAE3B,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,C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M,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": ["import_DmkNetworkClient", "import_MockClient", "aDevice", "overrides", "http", "client", "devices", "call", "token", "authCalls", "withSlash", "withoutSlash", "device", "state", "disconnectCalls", "mocks", "mock", "instance", "png", "screenshot", "request", "endpoint", "session", "snapshot", "result"]
|
|
7
7
|
}
|
package/lib/cjs/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var l=(o,e)=>{for(var p in e)c(o,p,{get:e[p],enumerable:!0})},d=(o,e,p,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of y(e))!f.call(o,t)&&t!==p&&c(o,t,{get:()=>e[t],enumerable:!(i=C(e,t))||i.enumerable});return o};var x=o=>d(c({},"__esModule",{value:!0}),o);var a={};l(a,{MockClient:()=>s.MockClient,catalogAppCodec:()=>n.catalogAppCodec,deviceConfigCodec:()=>n.deviceConfigCodec,mockConfigCodec:()=>r.mockConfigCodec,sessionExportCodec:()=>m.sessionExportCodec});module.exports=x(a);var s=require("./MockClient"),n=require("./model/Device"),r=require("./model/Mock"),m=require("./model/SessionExport");0&&(module.exports={MockClient,catalogAppCodec,deviceConfigCodec,mockConfigCodec,sessionExportCodec});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/src/index.js.map
CHANGED
|
@@ -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 {
|
|
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
5
|
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gNAAAE,EAAAF,GACA,IAAAG,EAA2B,wBAG3BC,EAQO,0BACPC,EAA4D,wBAE5DC,EAAuD",
|
|
6
6
|
"names": ["src_exports", "__export", "__toCommonJS", "import_MockClient", "import_Device", "import_Mock", "import_SessionExport"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var g=(o,n)=>{for(var a in n)i(o,a,{get:n[a],enumerable:!0})},m=(o,n,a,c)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of y(n))!l.call(o,r)&&r!==a&&i(o,r,{get:()=>n[r],enumerable:!(c=p(n,r))||c.enumerable});return o};var v=o=>m(i({},"__esModule",{value:!0}),o);var _={};g(_,{catalogAppCodec:()=>s,deviceAppCodec:()=>t,deviceCodec:()=>f,deviceConfigCodec:()=>C});module.exports=v(_);var e=require("purify-ts"),d=require("./Mock");const t=e.Codec.interface({name:e.string,version:e.string,hash:(0,e.optional)(e.string)}),s=e.Codec.interface({hash:e.string,name:e.string,version:e.string}),f=e.Codec.interface({id:e.string,name:e.string,device_type:e.string,connectivity_type:e.string,firmware_version:(0,e.optional)(e.string),apps:(0,e.optional)((0,e.array)(t)),masks:(0,e.optional)((0,e.array)(e.number)),connected:(0,e.optional)(e.boolean),onboarded:(0,e.optional)(e.boolean),language:(0,e.optional)(e.string)}),C=e.Codec.interface({name:(0,e.optional)(e.string),device_type:(0,e.optional)(e.string),connectivity_type:(0,e.optional)(e.string),firmware_version:(0,e.optional)(e.string),apps:(0,e.optional)((0,e.array)(t)),masks:(0,e.optional)((0,e.array)(e.number)),mocks:(0,e.optional)((0,e.array)(d.mockConfigCodec)),catalog:(0,e.optional)((0,e.array)(s)),onboarded:(0,e.optional)(e.boolean),language:(0,e.optional)(e.string)});0&&(module.exports={catalogAppCodec,deviceAppCodec,deviceCodec,deviceConfigCodec});
|
|
2
2
|
//# sourceMappingURL=Device.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/model/Device.ts"],
|
|
4
|
-
"sourcesContent": ["import { array, boolean, Codec, number, optional, string } from \"purify-ts\";\n\nimport { type MockConfig, mockConfigCodec } from \"./Mock\";\n\nexport type DeviceConnectivityType = \"USB\" | \"BLE\";\n\nexport interface DeviceApp {\n readonly name: string;\n readonly version: string;\n readonly hash?: string;\n}\n\nexport const deviceAppCodec = Codec.interface({\n name: string,\n version: string,\n hash: optional(string),\n});\n\n/**\n * An installable app known to the mock \"app store\", keyed by its install\n * `hash`. The secure-channel install flow resolves the hash sent by DMK to one\n * of these entries to learn which app is being installed.\n */\nexport interface CatalogApp {\n readonly hash: string;\n readonly name: string;\n readonly version: string;\n}\n\nexport const catalogAppCodec = Codec.interface({\n hash: string,\n name: string,\n version: string,\n});\n\n/**\n * A mocked device attached to a session.\n *\n * The device exposes rich metadata (firmware\n * version, installed applications, memory masks) so DMK can build a realistic\n * device session.\n */\nexport interface Device {\n readonly id: string;\n readonly name: string;\n /** DeviceModelId enum value, e.g. \"nanoX\", \"stax\", \"flex\". */\n readonly device_type: string;\n readonly connectivity_type: string;\n readonly firmware_version?: string;\n readonly apps?: DeviceApp[];\n readonly masks?: number[];\n readonly connected?: boolean;\n}\n\nexport const deviceCodec = Codec.interface({\n id: string,\n name: string,\n device_type: string,\n connectivity_type: string,\n firmware_version: optional(string),\n apps: optional(array(deviceAppCodec)),\n masks: optional(array(number)),\n connected: optional(boolean),\n});\n\n/**\n * Payload used to attach (POST /devices) or edit (PATCH /devices/:id) a device.\n */\nexport interface DeviceConfig {\n readonly name?: string;\n readonly device_type?: string;\n readonly connectivity_type?: string;\n readonly firmware_version?: string;\n readonly apps?: DeviceApp[];\n readonly masks?: number[];\n /** Device-scoped APDU mocks, used when attaching (POST) or importing a device. */\n readonly mocks?: MockConfig[];\n /** Installable apps the mock \"app store\" can resolve from an install hash. */\n readonly catalog?: CatalogApp[];\n}\n\nexport const deviceConfigCodec = Codec.interface({\n name: optional(string),\n device_type: optional(string),\n connectivity_type: optional(string),\n firmware_version: optional(string),\n apps: optional(array(deviceAppCodec)),\n masks: optional(array(number)),\n mocks: optional(array(mockConfigCodec)),\n catalog: optional(array(catalogAppCodec)),\n});\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAgE,qBAEhEC,EAAiD,kBAU1C,MAAML,EAAiB,QAAM,UAAU,CAC5C,KAAM,SACN,QAAS,SACT,QAAM,YAAS,QAAM,CACvB,CAAC,EAaYD,EAAkB,QAAM,UAAU,CAC7C,KAAM,SACN,KAAM,SACN,QAAS,QACX,CAAC,
|
|
4
|
+
"sourcesContent": ["import { array, boolean, Codec, number, optional, string } from \"purify-ts\";\n\nimport { type MockConfig, mockConfigCodec } from \"./Mock\";\n\nexport type DeviceConnectivityType = \"USB\" | \"BLE\";\n\nexport interface DeviceApp {\n readonly name: string;\n readonly version: string;\n readonly hash?: string;\n}\n\nexport const deviceAppCodec = Codec.interface({\n name: string,\n version: string,\n hash: optional(string),\n});\n\n/**\n * An installable app known to the mock \"app store\", keyed by its install\n * `hash`. The secure-channel install flow resolves the hash sent by DMK to one\n * of these entries to learn which app is being installed.\n */\nexport interface CatalogApp {\n readonly hash: string;\n readonly name: string;\n readonly version: string;\n}\n\nexport const catalogAppCodec = Codec.interface({\n hash: string,\n name: string,\n version: string,\n});\n\n/**\n * A mocked device attached to a session.\n *\n * The device exposes rich metadata (firmware\n * version, installed applications, memory masks) so DMK can build a realistic\n * device session.\n */\nexport interface Device {\n readonly id: string;\n readonly name: string;\n /** DeviceModelId enum value, e.g. \"nanoX\", \"stax\", \"flex\". */\n readonly device_type: string;\n readonly connectivity_type: string;\n readonly firmware_version?: string;\n readonly apps?: DeviceApp[];\n readonly masks?: number[];\n readonly connected?: boolean;\n /**\n * Whether the device is onboarded. Omitted/`true` reports a normal onboarded\n * device; `false` starts the onboarding simulation (the device reports itself\n * as not onboarded and auto-advances through the onboarding steps as it is\n * polled).\n */\n readonly onboarded?: boolean;\n /**\n * The installed language pack, by name (`\"french\"`, `\"german\"`, \u2026). Omitted\n * means the device runs on its built-in English, as one with no pack\n * installed does. Installing a pack over the wire sets it.\n */\n readonly language?: string;\n}\n\nexport const deviceCodec = Codec.interface({\n id: string,\n name: string,\n device_type: string,\n connectivity_type: string,\n firmware_version: optional(string),\n apps: optional(array(deviceAppCodec)),\n masks: optional(array(number)),\n connected: optional(boolean),\n onboarded: optional(boolean),\n language: optional(string),\n});\n\n/**\n * Payload used to attach (POST /devices) or edit (PATCH /devices/:id) a device.\n */\nexport interface DeviceConfig {\n readonly name?: string;\n readonly device_type?: string;\n readonly connectivity_type?: string;\n readonly firmware_version?: string;\n readonly apps?: DeviceApp[];\n readonly masks?: number[];\n /** Device-scoped APDU mocks, used when attaching (POST) or importing a device. */\n readonly mocks?: MockConfig[];\n /** Installable apps the mock \"app store\" can resolve from an install hash. */\n readonly catalog?: CatalogApp[];\n /**\n * Whether the device is onboarded. Omitted/`true` reports a normal onboarded\n * device; `false` starts the onboarding simulation.\n */\n readonly onboarded?: boolean;\n /** The installed language pack, by name (`\"french\"`, `\"german\"`, \u2026). */\n readonly language?: string;\n}\n\nexport const deviceConfigCodec = Codec.interface({\n name: optional(string),\n device_type: optional(string),\n connectivity_type: optional(string),\n firmware_version: optional(string),\n apps: optional(array(deviceAppCodec)),\n masks: optional(array(number)),\n mocks: optional(array(mockConfigCodec)),\n catalog: optional(array(catalogAppCodec)),\n onboarded: optional(boolean),\n language: optional(string),\n});\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,mBAAAC,EAAA,gBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAgE,qBAEhEC,EAAiD,kBAU1C,MAAML,EAAiB,QAAM,UAAU,CAC5C,KAAM,SACN,QAAS,SACT,QAAM,YAAS,QAAM,CACvB,CAAC,EAaYD,EAAkB,QAAM,UAAU,CAC7C,KAAM,SACN,KAAM,SACN,QAAS,QACX,CAAC,EAkCYE,EAAc,QAAM,UAAU,CACzC,GAAI,SACJ,KAAM,SACN,YAAa,SACb,kBAAmB,SACnB,oBAAkB,YAAS,QAAM,EACjC,QAAM,eAAS,SAAMD,CAAc,CAAC,EACpC,SAAO,eAAS,SAAM,QAAM,CAAC,EAC7B,aAAW,YAAS,SAAO,EAC3B,aAAW,YAAS,SAAO,EAC3B,YAAU,YAAS,QAAM,CAC3B,CAAC,EAyBYE,EAAoB,QAAM,UAAU,CAC/C,QAAM,YAAS,QAAM,EACrB,eAAa,YAAS,QAAM,EAC5B,qBAAmB,YAAS,QAAM,EAClC,oBAAkB,YAAS,QAAM,EACjC,QAAM,eAAS,SAAMF,CAAc,CAAC,EACpC,SAAO,eAAS,SAAM,QAAM,CAAC,EAC7B,SAAO,eAAS,SAAM,iBAAe,CAAC,EACtC,WAAS,eAAS,SAAMD,CAAe,CAAC,EACxC,aAAW,YAAS,SAAO,EAC3B,YAAU,YAAS,QAAM,CAC3B,CAAC",
|
|
6
6
|
"names": ["Device_exports", "__export", "catalogAppCodec", "deviceAppCodec", "deviceCodec", "deviceConfigCodec", "__toCommonJS", "import_purify_ts", "import_Mock"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var n=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var u=(r,e)=>{for(var t in e)n(r,t,{get:e[t],enumerable:!0})},a=(r,e,t,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of c(e))!i.call(r,s)&&s!==t&&n(r,s,{get:()=>e[s],enumerable:!(l=p(e,s))||l.enumerable});return r};var d=r=>a(n({},"__esModule",{value:!0}),r);var y={};u(y,{speculosInstanceCodec:()=>g});module.exports=d(y);var o=require("purify-ts");const g=o.Codec.interface({run_id:o.string,speculos_url:o.string,model:o.string});0&&(module.exports={speculosInstanceCodec});
|
|
2
2
|
//# sourceMappingURL=Speculos.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/model/Speculos.ts"],
|
|
4
|
-
"sourcesContent": ["import { Codec, string } from \"purify-ts\";\n\n/**\n * The live Speculos emulator instance backing a device, returned by\n * `GET /devices/:id/speculos`. Control calls are proxied through\n * `/devices/:id/speculos/*`.\n */\nexport interface SpeculosInstance {\n /** Speculinho run id owning the emulator pod. */\n readonly run_id: string;\n /** Per-pod emulator URL (reachable from the mock server). */\n readonly speculos_url: string;\n /** Device model (e.g. \"nanoX\", \"stax\", \"flex\"). */\n readonly model: string;\n}\n\nexport const speculosInstanceCodec = Codec.interface({\n run_id: string,\n speculos_url: string,\n model: string,\n});\n"],
|
|
4
|
+
"sourcesContent": ["import { Codec, string } from \"purify-ts\";\n\n/**\n * The live Speculos emulator instance backing a device, returned by\n * `GET /devices/:id/speculos`. Control calls are proxied through\n * `/devices/:id/speculos/*`.\n */\nexport interface SpeculosInstance {\n /** Speculinho run id owning the emulator pod. */\n readonly run_id: string;\n /** Per-pod emulator URL (reachable from the mock server). */\n readonly speculos_url: string;\n /** Device model (e.g. \"nanoX\", \"stax\", \"flex\"). */\n readonly model: string;\n}\n\nexport const speculosInstanceCodec = Codec.interface({\n run_id: string,\n speculos_url: string,\n model: string,\n});\n\n/** A physical button on a button-driven device. */\nexport type SpeculosButton = \"left\" | \"right\" | \"both\";\n\n/**\n * How an input is delivered. `press-and-release` covers a normal click or tap;\n * the split variants exist for flows that require a held input.\n */\nexport type SpeculosAction = \"press\" | \"release\" | \"press-and-release\";\n"],
|
|
5
5
|
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,qBAgBvB,MAAMF,EAAwB,QAAM,UAAU,CACnD,OAAQ,SACR,aAAc,SACd,MAAO,QACT,CAAC",
|
|
6
6
|
"names": ["Speculos_exports", "__export", "speculosInstanceCodec", "__toCommonJS", "import_purify_ts"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"main": "lib/index.js",
|
|
30
30
|
"name": "@ledgerhq/device-mockserver-client",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@ledgerhq/device-management-kit": "^1.
|
|
32
|
+
"@ledgerhq/device-management-kit": "^1.9.0"
|
|
33
33
|
},
|
|
34
34
|
"private": false,
|
|
35
35
|
"repository": {
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
53
53
|
},
|
|
54
54
|
"types": "lib/index.d.ts",
|
|
55
|
-
"version": "1.
|
|
55
|
+
"version": "1.3.0"
|
|
56
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const n=()=>new class{responses;calls;constructor(){this.responses={get:{},post:{},patch:{},delete:{}},this.calls=[]}get(e,
|
|
1
|
+
const n=()=>new class{responses;calls;configs;constructor(){this.responses={get:{},post:{},patch:{},delete:{}},this.calls=[],this.configs=[]}get(e,s){return this.calls.push({method:"get",endpoint:e}),this.configs.push({method:"get",endpoint:e,config:s}),Promise.resolve(this.responses.get[e])}post(e,s,t){return this.calls.push({method:"post",endpoint:e,body:s}),this.configs.push({method:"post",endpoint:e,config:t}),Promise.resolve(this.responses.post[e])}patch(e,s,t){return this.calls.push({method:"patch",endpoint:e,body:s}),this.configs.push({method:"patch",endpoint:e,config:t}),Promise.resolve(this.responses.patch[e])}delete(e,s){return this.calls.push({method:"delete",endpoint:e}),this.configs.push({method:"delete",endpoint:e,config:s}),Promise.resolve(this.responses.delete[e])}mockResponse({method:e,endpoint:s,response:t}){return this.responses={...this.responses,[e]:{...this.responses[e],[s]:t}},this}};export{n as httpClientStubBuilder};
|
|
2
2
|
//# sourceMappingURL=DmkNetworkClient.stub.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/DmkNetworkClient.stub.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type DmkNetworkClient,\n type DmkRequestConfig,\n} from \"@ledgerhq/device-management-kit\";\n\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\";\n\nexport type DmkNetworkClientStub = DmkNetworkClient & {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n mockResponse(args: {\n method: Method;\n endpoint: string;\n response: object;\n }): DmkNetworkClientStub;\n};\n\nexport const httpClientStubBuilder = (): DmkNetworkClientStub => {\n const stub = new (class {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n\n constructor() {\n this.responses = { get: {}, post: {}, patch: {}, delete: {} };\n this.calls = [];\n }\n\n get(endpoint: string,
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["httpClientStubBuilder", "endpoint", "
|
|
4
|
+
"sourcesContent": ["import {\n type DmkNetworkClient,\n type DmkRequestConfig,\n} from \"@ledgerhq/device-management-kit\";\n\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\";\n\nexport type DmkNetworkClientStub = DmkNetworkClient & {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n /** Per-call request config, kept aside so `calls` stays easy to match on. */\n configs: { method: Method; endpoint: string; config?: DmkRequestConfig }[];\n mockResponse(args: {\n method: Method;\n endpoint: string;\n response: object;\n }): DmkNetworkClientStub;\n};\n\nexport const httpClientStubBuilder = (): DmkNetworkClientStub => {\n const stub = new (class {\n responses: Record<Method, Record<string, unknown>>;\n calls: { method: Method; endpoint: string; body?: object }[];\n configs: { method: Method; endpoint: string; config?: DmkRequestConfig }[];\n\n constructor() {\n this.responses = { get: {}, post: {}, patch: {}, delete: {} };\n this.calls = [];\n this.configs = [];\n }\n\n get(endpoint: string, config?: DmkRequestConfig): Promise<unknown> {\n this.calls.push({ method: \"get\", endpoint });\n this.configs.push({ method: \"get\", endpoint, config });\n return Promise.resolve(this.responses.get[endpoint]);\n }\n\n post(\n endpoint: string,\n body?: unknown,\n config?: DmkRequestConfig,\n ): Promise<unknown> {\n this.calls.push({ method: \"post\", endpoint, body: body as object });\n this.configs.push({ method: \"post\", endpoint, config });\n return Promise.resolve(this.responses.post[endpoint]);\n }\n\n patch(\n endpoint: string,\n body?: unknown,\n config?: DmkRequestConfig,\n ): Promise<unknown> {\n this.calls.push({ method: \"patch\", endpoint, body: body as object });\n this.configs.push({ method: \"patch\", endpoint, config });\n return Promise.resolve(this.responses.patch[endpoint]);\n }\n\n delete(endpoint: string, config?: DmkRequestConfig): Promise<unknown> {\n this.calls.push({ method: \"delete\", endpoint });\n this.configs.push({ method: \"delete\", endpoint, config });\n return Promise.resolve(this.responses.delete[endpoint]);\n }\n\n mockResponse({\n method,\n endpoint,\n response,\n }: {\n method: Method;\n endpoint: string;\n response: object;\n }) {\n this.responses = {\n ...this.responses,\n [method]: {\n ...this.responses[method],\n [endpoint]: response,\n },\n };\n return this;\n }\n })();\n\n return stub as unknown as DmkNetworkClientStub;\n};\n"],
|
|
5
|
+
"mappings": "AAmBO,MAAMA,EAAwB,IACtB,IAAK,KAAM,CACtB,UACA,MACA,QAEA,aAAc,CACZ,KAAK,UAAY,CAAE,IAAK,CAAC,EAAG,KAAM,CAAC,EAAG,MAAO,CAAC,EAAG,OAAQ,CAAC,CAAE,EAC5D,KAAK,MAAQ,CAAC,EACd,KAAK,QAAU,CAAC,CAClB,CAEA,IAAIC,EAAkBC,EAA6C,CACjE,YAAK,MAAM,KAAK,CAAE,OAAQ,MAAO,SAAAD,CAAS,CAAC,EAC3C,KAAK,QAAQ,KAAK,CAAE,OAAQ,MAAO,SAAAA,EAAU,OAAAC,CAAO,CAAC,EAC9C,QAAQ,QAAQ,KAAK,UAAU,IAAID,CAAQ,CAAC,CACrD,CAEA,KACEA,EACAE,EACAD,EACkB,CAClB,YAAK,MAAM,KAAK,CAAE,OAAQ,OAAQ,SAAAD,EAAU,KAAME,CAAe,CAAC,EAClE,KAAK,QAAQ,KAAK,CAAE,OAAQ,OAAQ,SAAAF,EAAU,OAAAC,CAAO,CAAC,EAC/C,QAAQ,QAAQ,KAAK,UAAU,KAAKD,CAAQ,CAAC,CACtD,CAEA,MACEA,EACAE,EACAD,EACkB,CAClB,YAAK,MAAM,KAAK,CAAE,OAAQ,QAAS,SAAAD,EAAU,KAAME,CAAe,CAAC,EACnE,KAAK,QAAQ,KAAK,CAAE,OAAQ,QAAS,SAAAF,EAAU,OAAAC,CAAO,CAAC,EAChD,QAAQ,QAAQ,KAAK,UAAU,MAAMD,CAAQ,CAAC,CACvD,CAEA,OAAOA,EAAkBC,EAA6C,CACpE,YAAK,MAAM,KAAK,CAAE,OAAQ,SAAU,SAAAD,CAAS,CAAC,EAC9C,KAAK,QAAQ,KAAK,CAAE,OAAQ,SAAU,SAAAA,EAAU,OAAAC,CAAO,CAAC,EACjD,QAAQ,QAAQ,KAAK,UAAU,OAAOD,CAAQ,CAAC,CACxD,CAEA,aAAa,CACX,OAAAG,EACA,SAAAH,EACA,SAAAI,CACF,EAIG,CACD,YAAK,UAAY,CACf,GAAG,KAAK,UACR,CAACD,CAAM,EAAG,CACR,GAAG,KAAK,UAAUA,CAAM,EACxB,CAACH,CAAQ,EAAGI,CACd,CACF,EACO,IACT,CACF",
|
|
6
|
+
"names": ["httpClientStubBuilder", "endpoint", "config", "body", "method", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{bufferToHexaString as c,DmkNetworkClient as d}from"@ledgerhq/device-management-kit";import{array as o}from"purify-ts";import{authResponseCodec as h,connectionStateCodec as u}from"./model/Auth";import{commandResponseCodec as
|
|
1
|
+
import{bufferToHexaString as c,DmkNetworkClient as d}from"@ledgerhq/device-management-kit";import{array as o}from"purify-ts";import{authResponseCodec as h,connectionStateCodec as u}from"./model/Auth";import{commandResponseCodec as l}from"./model/CommandResponse";import{deviceCodec as a}from"./model/Device";import{mockCodec as n}from"./model/Mock";import{sessionCodec as p}from"./model/Session";import{sessionExportCodec as r}from"./model/SessionExport";import{speculosInstanceCodec as m}from"./model/Speculos";class ${client;token;authPromise;constructor(e,t={}){this.client=t.httpClient??new d({baseUrl:this.normalizeUrl(e)}),this.token=t.token}async authenticate(){const e=await this.client.post("auth",{}),t=this.decode(h,e).token;return this.token=t,t}getToken(){return this.token}async listDevices(){const e=await this.client.get("devices",{headers:await this.authHeaders()});return this.decode(o(a),e)}async addDevice(e={}){const t=await this.client.post("devices",e,{headers:await this.authHeaders()});return this.decode(a,t)}async getDevice(e){const t=await this.client.get(`devices/${e}`,{headers:await this.authHeaders()});return this.decode(a,t)}async editDevice(e,t){const s=await this.client.patch(`devices/${e}`,t,{headers:await this.authHeaders()});return this.decode(a,s)}async deleteDevice(e){return await this.client.delete(`devices/${e}`,{headers:await this.authHeaders()}),!0}async connect(e){const t=await this.client.post(`devices/${e}/connect`,{},{headers:await this.authHeaders()});return this.decode(u,t)}async disconnect(e){return await this.client.post(`devices/${e}/disconnect`,{},{headers:await this.authHeaders()}),!0}async disconnectAll(){const e=await this.listDevices();return await Promise.all(e.filter(t=>t.connected).map(t=>this.disconnect(t.id))),!0}async sendApdu(e,t){const s=typeof t=="string"?t:c(t,!1),i=await this.client.post(`devices/${e}/apdu`,{apdu:s},{headers:await this.authHeaders()});return this.decode(l,i)}async listMocks(e){const t=await this.client.get(`devices/${e}/mocks`,{headers:await this.authHeaders()});return this.decode(o(n),t)}async addMock(e,t){const s=await this.client.post(`devices/${e}/mocks`,t,{headers:await this.authHeaders()});return this.decode(n,s)}async editMock(e,t,s){const i=await this.client.patch(`devices/${e}/mocks/${t}`,s,{headers:await this.authHeaders()});return this.decode(n,i)}async deleteMock(e,t){return await this.client.delete(`devices/${e}/mocks/${t}`,{headers:await this.authHeaders()}),!0}async clearMocks(e){return await this.client.delete(`devices/${e}/mocks`,{headers:await this.authHeaders()}),!0}async getSpeculos(e){const t=await this.client.get(`devices/${e}/speculos`,{headers:await this.authHeaders()});return this.decode(m,t)}async getScreenshot(e){return await this.client.get(`devices/${e}/speculos/screenshot`,{headers:await this.authHeaders(),responseType:"blob"})}async pressButton(e,t,s="press-and-release"){await this.client.post(`devices/${e}/speculos/button/${t}`,{action:s},{headers:await this.authHeaders()})}async touchScreen(e,t,s,i="press-and-release"){await this.client.post(`devices/${e}/speculos/finger`,{action:i,x:t,y:s},{headers:await this.authHeaders()})}async getSession(){const e=await this.client.get("sessions/current",{headers:await this.authHeaders()});return this.decode(p,e)}async disposeSession(){return await this.client.delete("sessions/current",{headers:await this.authHeaders()}),this.token=void 0,this.authPromise=void 0,!0}async exportSession(){const e=await this.client.get("export",{headers:await this.authHeaders()});return this.decode(r,e)}async importSession(e){const t=await this.client.post("import",e,{headers:await this.authHeaders()});return this.decode(r,t)}decode(e,t){return e.decode(t).caseOf({Left:s=>{throw new Error(`MockClient: invalid server response (${s})`)},Right:s=>s})}async authHeaders(){return{Authorization:`Bearer ${await this.ensureToken()}`}}ensureToken(){return this.token?Promise.resolve(this.token):(this.authPromise||(this.authPromise=this.authenticate()),this.authPromise)}normalizeUrl(e){return e.endsWith("/")?e:`${e}/`}}export{$ as MockClient};
|
|
2
2
|
//# sourceMappingURL=MockClient.js.map
|