@ledgerhq/speculos-device-controller 0.2.3 → 0.4.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/README.md +4 -2
- package/lib/cjs/package.json +4 -5
- package/lib/cjs/src/api/DeviceController.js +1 -1
- package/lib/cjs/src/api/DeviceController.js.map +2 -2
- package/lib/cjs/src/api/DeviceController.test.js +1 -1
- package/lib/cjs/src/api/DeviceController.test.js.map +3 -3
- package/lib/cjs/src/internal/adapters/DefaultButtonController.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultButtonController.js.map +2 -2
- package/lib/cjs/src/internal/adapters/DefaultButtonController.test.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultButtonController.test.js.map +3 -3
- package/lib/cjs/src/internal/adapters/DefaultTouchController.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultTouchController.js.map +2 -2
- package/lib/cjs/src/internal/adapters/DefaultTouchController.test.js +1 -1
- package/lib/cjs/src/internal/adapters/DefaultTouchController.test.js.map +3 -3
- package/lib/cjs/src/internal/core/types.js +1 -1
- package/lib/cjs/src/internal/core/types.js.map +2 -2
- package/lib/cjs/src/internal/di.js +1 -1
- package/lib/cjs/src/internal/di.js.map +3 -3
- package/lib/cjs/src/internal/di.test.js +1 -1
- package/lib/cjs/src/internal/di.test.js.map +3 -3
- package/lib/cjs/src/internal/use-cases/touchUseCases.js +1 -1
- package/lib/cjs/src/internal/use-cases/touchUseCases.js.map +3 -3
- package/lib/cjs/src/internal/use-cases/touchUseCases.test.js +1 -1
- package/lib/cjs/src/internal/use-cases/touchUseCases.test.js.map +3 -3
- package/lib/esm/package.json +4 -5
- package/lib/esm/src/api/DeviceController.js +1 -1
- package/lib/esm/src/api/DeviceController.js.map +3 -3
- package/lib/esm/src/api/DeviceController.test.js +1 -1
- package/lib/esm/src/api/DeviceController.test.js.map +3 -3
- package/lib/esm/src/internal/adapters/DefaultButtonController.js.map +2 -2
- package/lib/esm/src/internal/adapters/DefaultButtonController.test.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultButtonController.test.js.map +3 -3
- package/lib/esm/src/internal/adapters/DefaultTouchController.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultTouchController.js.map +2 -2
- package/lib/esm/src/internal/adapters/DefaultTouchController.test.js +1 -1
- package/lib/esm/src/internal/adapters/DefaultTouchController.test.js.map +3 -3
- package/lib/esm/src/internal/core/types.js.map +2 -2
- package/lib/esm/src/internal/di.js +1 -1
- package/lib/esm/src/internal/di.js.map +3 -3
- package/lib/esm/src/internal/di.test.js +1 -1
- package/lib/esm/src/internal/di.test.js.map +3 -3
- package/lib/esm/src/internal/use-cases/touchUseCases.js +1 -1
- package/lib/esm/src/internal/use-cases/touchUseCases.js.map +3 -3
- package/lib/esm/src/internal/use-cases/touchUseCases.test.js +1 -1
- package/lib/esm/src/internal/use-cases/touchUseCases.test.js.map +3 -3
- package/lib/types/src/api/DeviceController.d.ts +7 -0
- package/lib/types/src/api/DeviceController.d.ts.map +1 -1
- package/lib/types/src/internal/adapters/DefaultButtonController.d.ts +2 -3
- package/lib/types/src/internal/adapters/DefaultButtonController.d.ts.map +1 -1
- package/lib/types/src/internal/adapters/DefaultTouchController.d.ts +2 -3
- package/lib/types/src/internal/adapters/DefaultTouchController.d.ts.map +1 -1
- package/lib/types/src/internal/core/types.d.ts +4 -0
- package/lib/types/src/internal/core/types.d.ts.map +1 -1
- package/lib/types/src/internal/di.d.ts.map +1 -1
- package/lib/types/src/internal/use-cases/touchUseCases.d.ts +6 -0
- package/lib/types/src/internal/use-cases/touchUseCases.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -40,8 +40,9 @@ Under the hood, percentages are clamped to [0, 100] and converted to pixels usin
|
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
42
|
const deviceClient = deviceControllerClientFactory("http://localhost:4000", {
|
|
43
|
-
timeoutMs: 2000, // optional
|
|
43
|
+
timeoutMs: 2000, // optional fetch timeout
|
|
44
44
|
clientHeader: "ldmk-transport-speculos", // optional header
|
|
45
|
+
bearerToken: sessionToken, // optional, sent as `Authorization: Bearer <token>`, e.g. a protected Speculinho session
|
|
45
46
|
screens: {
|
|
46
47
|
// override by default keys
|
|
47
48
|
flex: { width: 256, height: 256 },
|
|
@@ -91,8 +92,9 @@ type DeviceControllerClient = {
|
|
|
91
92
|
type DeviceControllerClientFactory = (
|
|
92
93
|
baseURL: string,
|
|
93
94
|
opts?: {
|
|
94
|
-
timeoutMs?: number; //
|
|
95
|
+
timeoutMs?: number; // fetch timeout (ms)
|
|
95
96
|
clientHeader?: string; // "X-Ledger-Client-Version" header
|
|
97
|
+
bearerToken?: string; // sent as "Authorization: Bearer <token>" with every request
|
|
96
98
|
screens?: DeviceScreens<string>;
|
|
97
99
|
},
|
|
98
100
|
) => DeviceControllerClient;
|
package/lib/cjs/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@ledgerhq/device-management-kit": "
|
|
4
|
-
"@sentry/minimal": "catalog:"
|
|
5
|
-
"axios": "catalog:"
|
|
3
|
+
"@ledgerhq/device-management-kit": "^1.11.0",
|
|
4
|
+
"@sentry/minimal": "catalog:"
|
|
6
5
|
},
|
|
7
6
|
"devDependencies": {
|
|
8
7
|
"@ledgerhq/eslint-config-dsdk": "workspace:^",
|
|
@@ -30,7 +29,7 @@
|
|
|
30
29
|
"license": "Apache-2.0",
|
|
31
30
|
"name": "@ledgerhq/speculos-device-controller",
|
|
32
31
|
"peerDependencies": {
|
|
33
|
-
"@ledgerhq/device-management-kit": "
|
|
32
|
+
"@ledgerhq/device-management-kit": "^1.11.0"
|
|
34
33
|
},
|
|
35
34
|
"private": false,
|
|
36
35
|
"repository": {
|
|
@@ -53,5 +52,5 @@
|
|
|
53
52
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
54
53
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
55
54
|
},
|
|
56
|
-
"version": "0.
|
|
55
|
+
"version": "0.4.0"
|
|
57
56
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var B=(i,n)=>{for(var r in n)l(i,r,{get:n[r],enumerable:!0})},P=(i,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of v(n))!g.call(i,t)&&t!==r&&l(i,t,{get:()=>n[t],enumerable:!(s=p(n,t))||s.enumerable});return i};var C=i=>P(l({},"__esModule",{value:!0}),i);var b={};B(b,{deviceControllerClientFactory:()=>S});module.exports=C(b);var d=require("../internal/config/defaultScreens"),u=require("../../src/internal/di"),c=require("../../src/internal/use-cases/buttonUseCases"),e=require("../../src/internal/use-cases/touchUseCases");const S=(i,n={})=>{const r={screens:n.screens??d.DEFAULT_SCREENS,timeoutMs:n.timeoutMs,clientHeader:n.clientHeader,bearerToken:n.bearerToken},{buttons:s,touch:t}=(0,u.createDefaultControllers)(i,r),a=(0,c.pressButtons)(s);return{buttonFactory:()=>({press:o=>s.press(o),left:()=>a.left(),right:()=>a.right(),both:()=>a.both(),pressSequence:(o,m)=>(0,c.pressSequence)(s,o,m)}),tapFactory:o=>({tapQuick:(0,e.tapQuick)(t,o),tapLong:(0,e.tapLong)(t,o),sign:(0,e.sign)(t,o),reject:(0,e.reject)(t,o),navigateNext:(0,e.navigateNext)(t,o),navigatePrevious:(0,e.navigatePrevious)(t,o),mainButton:(0,e.mainButton)(t,o),secondaryButton:(0,e.secondaryButton)(t,o),enterMenu:(0,e.enterMenu)(t,o),exitMenu:(0,e.exitMenu)(t,o),enableBlindSigningSettings:(0,e.enableBlindSigningSettings)(t,o),continueToBlindSigning:(0,e.continueToBlindSigning)(t,o),acceptBlindSigning:(0,e.acceptBlindSigning)(t,o),confirmAddressBookReview:(0,e.confirmAddressBookReview)(t,o)})}};0&&(module.exports={deviceControllerClientFactory});
|
|
2
2
|
//# sourceMappingURL=DeviceController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/DeviceController.ts"],
|
|
4
|
-
"sourcesContent": ["import { DEFAULT_SCREENS } from \"@internal/config/defaultScreens\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n} from \"@internal/core/types\";\nimport { createDefaultControllers } from \"@root/src/internal/di\";\nimport {\n pressButtons,\n pressSequence,\n} from \"@root/src/internal/use-cases/buttonUseCases\";\nimport {\n mainButton,\n navigateNext,\n navigatePrevious,\n reject,\n secondaryButton,\n sign,\n tapLong,\n tapQuick,\n} from \"@root/src/internal/use-cases/touchUseCases\";\n\nexport type ButtonFactory = () => ButtonController & {\n left(): Promise<void>;\n right(): Promise<void>;\n both(): Promise<void>;\n pressSequence(keys: ButtonKey[], delayMs?: number): Promise<void>;\n};\n\nexport type TapFactory = (deviceKey: string) => {\n tapQuick: (point: PercentCoordinates) => Promise<void>;\n tapLong: (point: PercentCoordinates, delayMs?: number) => Promise<void>;\n sign: (delayMs?: number) => Promise<void>;\n reject: () => Promise<void>;\n navigateNext: () => Promise<void>;\n navigatePrevious: () => Promise<void>;\n mainButton: () => Promise<void>;\n secondaryButton: () => Promise<void>;\n};\n\nexport type DeviceControllerClientFactory = (\n baseURL: string,\n opts?: {\n timeoutMs?: number;\n clientHeader?: string;\n screens?: DeviceScreens<string>;\n },\n) => DeviceControllerClient;\n\nexport type DeviceControllerClient = {\n buttonFactory: ButtonFactory;\n tapFactory: TapFactory;\n};\n\nexport const deviceControllerClientFactory: DeviceControllerClientFactory = (\n baseURL,\n opts = {},\n) => {\n const resolved: DeviceControllerOptions = {\n screens: opts.screens ?? DEFAULT_SCREENS,\n timeoutMs: opts.timeoutMs,\n clientHeader: opts.clientHeader,\n };\n\n const { buttons, touch } = createDefaultControllers(baseURL, resolved);\n const press = pressButtons(buttons);\n\n return {\n buttonFactory: () => ({\n press: (key) => buttons.press(key),\n left: () => press.left(),\n right: () => press.right(),\n both: () => press.both(),\n pressSequence: (keys, delayMs) => pressSequence(buttons, keys, delayMs),\n }),\n tapFactory: (key) => ({\n tapQuick: tapQuick(touch, key),\n tapLong: tapLong(touch, key),\n sign: sign(touch, key),\n reject: reject(touch, key),\n navigateNext: navigateNext(touch, key),\n navigatePrevious: navigatePrevious(touch, key),\n mainButton: mainButton(touch, key),\n secondaryButton: secondaryButton(touch, key),\n }),\n };\n};\n\nexport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n};\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,2CAQhCC,EAAyC,iCACzCC,EAGO,uDACPC,
|
|
4
|
+
"sourcesContent": ["import { DEFAULT_SCREENS } from \"@internal/config/defaultScreens\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n} from \"@internal/core/types\";\nimport { createDefaultControllers } from \"@root/src/internal/di\";\nimport {\n pressButtons,\n pressSequence,\n} from \"@root/src/internal/use-cases/buttonUseCases\";\nimport {\n acceptBlindSigning,\n confirmAddressBookReview,\n continueToBlindSigning,\n enableBlindSigningSettings,\n enterMenu,\n exitMenu,\n mainButton,\n navigateNext,\n navigatePrevious,\n reject,\n secondaryButton,\n sign,\n tapLong,\n tapQuick,\n} from \"@root/src/internal/use-cases/touchUseCases\";\n\nexport type ButtonFactory = () => ButtonController & {\n left(): Promise<void>;\n right(): Promise<void>;\n both(): Promise<void>;\n pressSequence(keys: ButtonKey[], delayMs?: number): Promise<void>;\n};\n\nexport type TapFactory = (deviceKey: string) => {\n tapQuick: (point: PercentCoordinates) => Promise<void>;\n tapLong: (point: PercentCoordinates, delayMs?: number) => Promise<void>;\n sign: (delayMs?: number) => Promise<void>;\n reject: () => Promise<void>;\n navigateNext: () => Promise<void>;\n navigatePrevious: () => Promise<void>;\n mainButton: () => Promise<void>;\n secondaryButton: () => Promise<void>;\n enterMenu: () => Promise<void>;\n exitMenu: () => Promise<void>;\n enableBlindSigningSettings: () => Promise<void>;\n continueToBlindSigning: () => Promise<void>;\n acceptBlindSigning: () => Promise<void>;\n confirmAddressBookReview: () => Promise<void>;\n};\n\nexport type DeviceControllerClientFactory = (\n baseURL: string,\n opts?: {\n timeoutMs?: number;\n clientHeader?: string;\n bearerToken?: string;\n screens?: DeviceScreens<string>;\n },\n) => DeviceControllerClient;\n\nexport type DeviceControllerClient = {\n buttonFactory: ButtonFactory;\n tapFactory: TapFactory;\n};\n\nexport const deviceControllerClientFactory: DeviceControllerClientFactory = (\n baseURL,\n opts = {},\n) => {\n const resolved: DeviceControllerOptions = {\n screens: opts.screens ?? DEFAULT_SCREENS,\n timeoutMs: opts.timeoutMs,\n clientHeader: opts.clientHeader,\n bearerToken: opts.bearerToken,\n };\n\n const { buttons, touch } = createDefaultControllers(baseURL, resolved);\n const press = pressButtons(buttons);\n\n return {\n buttonFactory: () => ({\n press: (key) => buttons.press(key),\n left: () => press.left(),\n right: () => press.right(),\n both: () => press.both(),\n pressSequence: (keys, delayMs) => pressSequence(buttons, keys, delayMs),\n }),\n tapFactory: (key) => ({\n tapQuick: tapQuick(touch, key),\n tapLong: tapLong(touch, key),\n sign: sign(touch, key),\n reject: reject(touch, key),\n navigateNext: navigateNext(touch, key),\n navigatePrevious: navigatePrevious(touch, key),\n mainButton: mainButton(touch, key),\n secondaryButton: secondaryButton(touch, key),\n enterMenu: enterMenu(touch, key),\n exitMenu: exitMenu(touch, key),\n enableBlindSigningSettings: enableBlindSigningSettings(touch, key),\n continueToBlindSigning: continueToBlindSigning(touch, key),\n acceptBlindSigning: acceptBlindSigning(touch, key),\n confirmAddressBookReview: confirmAddressBookReview(touch, key),\n }),\n };\n};\n\nexport type {\n ButtonKey,\n DeviceControllerOptions,\n DeviceScreens,\n PercentCoordinates,\n};\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,2CAQhCC,EAAyC,iCACzCC,EAGO,uDACPC,EAeO,sDAyCA,MAAML,EAA+D,CAC1EM,EACAC,EAAO,CAAC,IACL,CACH,MAAMC,EAAoC,CACxC,QAASD,EAAK,SAAW,kBACzB,UAAWA,EAAK,UAChB,aAAcA,EAAK,aACnB,YAAaA,EAAK,WACpB,EAEM,CAAE,QAAAE,EAAS,MAAAC,CAAM,KAAI,4BAAyBJ,EAASE,CAAQ,EAC/DG,KAAQ,gBAAaF,CAAO,EAElC,MAAO,CACL,cAAe,KAAO,CACpB,MAAQG,GAAQH,EAAQ,MAAMG,CAAG,EACjC,KAAM,IAAMD,EAAM,KAAK,EACvB,MAAO,IAAMA,EAAM,MAAM,EACzB,KAAM,IAAMA,EAAM,KAAK,EACvB,cAAe,CAACE,EAAMC,OAAY,iBAAcL,EAASI,EAAMC,CAAO,CACxE,GACA,WAAaF,IAAS,CACpB,YAAU,YAASF,EAAOE,CAAG,EAC7B,WAAS,WAAQF,EAAOE,CAAG,EAC3B,QAAM,QAAKF,EAAOE,CAAG,EACrB,UAAQ,UAAOF,EAAOE,CAAG,EACzB,gBAAc,gBAAaF,EAAOE,CAAG,EACrC,oBAAkB,oBAAiBF,EAAOE,CAAG,EAC7C,cAAY,cAAWF,EAAOE,CAAG,EACjC,mBAAiB,mBAAgBF,EAAOE,CAAG,EAC3C,aAAW,aAAUF,EAAOE,CAAG,EAC/B,YAAU,YAASF,EAAOE,CAAG,EAC7B,8BAA4B,8BAA2BF,EAAOE,CAAG,EACjE,0BAAwB,0BAAuBF,EAAOE,CAAG,EACzD,sBAAoB,sBAAmBF,EAAOE,CAAG,EACjD,4BAA0B,4BAAyBF,EAAOE,CAAG,CAC/D,EACF,CACF",
|
|
6
6
|
"names": ["DeviceController_exports", "__export", "deviceControllerClientFactory", "__toCommonJS", "import_defaultScreens", "import_di", "import_buttonUseCases", "import_touchUseCases", "baseURL", "opts", "resolved", "buttons", "touch", "press", "key", "keys", "delayMs"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var o=require("./DeviceController");describe("deviceControllerClientFactory",()=>{it("returns a DeviceControllerdeviceClient with the expected shape",()=>{const e=(0,o.deviceControllerClientFactory)("http://localhost:0");expect(e).toBeDefined(),expect(e).toHaveProperty("buttonFactory"),expect(e).toHaveProperty("tapFactory");const t=e.buttonFactory();expect(typeof t.press).toBe("function"),expect(typeof t.left).toBe("function"),expect(typeof t.right).toBe("function"),expect(typeof t.both).toBe("function"),expect(typeof t.pressSequence).toBe("function");const c=e.tapFactory("flex");expect(typeof c.tapQuick).toBe("function"),expect(typeof c.tapLong).toBe("function")}),it("does not throw when created with custom options",()=>{const t=(0,o.deviceControllerClientFactory)("http://127.0.0.1:0",{clientHeader:"test-suite",timeoutMs:200,screens:{custom:{width:128,height:64},stax:{width:400,height:672}}});expect(t).toBeTruthy()}),it("creates independent instances (no accidental shared state)",()=>{const e=(0,o.deviceControllerClientFactory)("http://localhost:0"),t=(0,o.deviceControllerClientFactory)("http://localhost:0");expect(e).not.toBe(t),expect(e.buttonFactory().press).not.toBe(t.buttonFactory().press),expect(e.tapFactory("flex").tapQuick).not.toBe(t.tapFactory("flex").tapQuick)})});
|
|
1
|
+
"use strict";var o=require("./DeviceController");describe("deviceControllerClientFactory",()=>{it("returns a DeviceControllerdeviceClient with the expected shape",()=>{const e=(0,o.deviceControllerClientFactory)("http://localhost:0");expect(e).toBeDefined(),expect(e).toHaveProperty("buttonFactory"),expect(e).toHaveProperty("tapFactory");const t=e.buttonFactory();expect(typeof t.press).toBe("function"),expect(typeof t.left).toBe("function"),expect(typeof t.right).toBe("function"),expect(typeof t.both).toBe("function"),expect(typeof t.pressSequence).toBe("function");const c=e.tapFactory("flex");expect(typeof c.tapQuick).toBe("function"),expect(typeof c.tapLong).toBe("function")}),it("does not throw when created with custom options",()=>{const t=(0,o.deviceControllerClientFactory)("http://127.0.0.1:0",{clientHeader:"test-suite",timeoutMs:200,screens:{custom:{width:128,height:64},stax:{width:400,height:672}}});expect(t).toBeTruthy()}),it("creates independent instances (no accidental shared state)",()=>{const e=(0,o.deviceControllerClientFactory)("http://localhost:0"),t=(0,o.deviceControllerClientFactory)("http://localhost:0");expect(e).not.toBe(t),expect(e.buttonFactory().press).not.toBe(t.buttonFactory().press),expect(e.tapFactory("flex").tapQuick).not.toBe(t.tapFactory("flex").tapQuick)}),it("sends the bearer token with every request",async()=>{const e=vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}"));await(0,o.deviceControllerClientFactory)("http://localhost:0",{bearerToken:"session-token"}).buttonFactory().press("both"),expect(e).toHaveBeenCalledWith("http://localhost:0/button/both",expect.objectContaining({headers:expect.objectContaining({Authorization:"Bearer session-token"})})),e.mockRestore()})});
|
|
2
2
|
//# sourceMappingURL=DeviceController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/DeviceController.test.ts"],
|
|
4
|
-
"sourcesContent": ["import type { DeviceScreens } from \"@internal/core/types\";\n\nimport { deviceControllerClientFactory } from \"./DeviceController\";\n\ndescribe(\"deviceControllerClientFactory\", () => {\n it(\"returns a DeviceControllerdeviceClient with the expected shape\", () => {\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(deviceClient).toBeDefined();\n expect(deviceClient).toHaveProperty(\"buttonFactory\");\n expect(deviceClient).toHaveProperty(\"tapFactory\");\n\n const deviceButtons = deviceClient.buttonFactory();\n\n // button surfaces\n expect(typeof deviceButtons.press).toBe(\"function\");\n expect(typeof deviceButtons.left).toBe(\"function\");\n expect(typeof deviceButtons.right).toBe(\"function\");\n expect(typeof deviceButtons.both).toBe(\"function\");\n expect(typeof deviceButtons.pressSequence).toBe(\"function\");\n\n const deviceTaps = deviceClient.tapFactory(\"flex\");\n\n // tap surfaces\n expect(typeof deviceTaps.tapQuick).toBe(\"function\");\n expect(typeof deviceTaps.tapLong).toBe(\"function\");\n });\n\n it(\"does not throw when created with custom options\", () => {\n const screens: DeviceScreens<string> = {\n custom: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n };\n const deviceClient = deviceControllerClientFactory(\"http://127.0.0.1:0\", {\n clientHeader: \"test-suite\",\n timeoutMs: 200,\n screens,\n });\n expect(deviceClient).toBeTruthy();\n });\n\n it(\"creates independent instances (no accidental shared state)\", () => {\n const a = deviceControllerClientFactory(\"http://localhost:0\");\n const b = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(a).not.toBe(b);\n expect(a.buttonFactory().press).not.toBe(b.buttonFactory().press);\n expect(a.tapFactory(\"flex\").tapQuick).not.toBe(\n b.tapFactory(\"flex\").tapQuick,\n );\n });\n});\n"],
|
|
5
|
-
"mappings": "aAEA,IAAAA,EAA8C,8BAE9C,SAAS,gCAAiC,IAAM,CAC9C,GAAG,iEAAkE,IAAM,CACzE,MAAMC,KAAe,iCAA8B,oBAAoB,EAEvE,OAAOA,CAAY,EAAE,YAAY,EACjC,OAAOA,CAAY,EAAE,eAAe,eAAe,EACnD,OAAOA,CAAY,EAAE,eAAe,YAAY,EAEhD,MAAMC,EAAgBD,EAAa,cAAc,EAGjD,OAAO,OAAOC,EAAc,KAAK,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAc,IAAI,EAAE,KAAK,UAAU,EACjD,OAAO,OAAOA,EAAc,KAAK,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAc,IAAI,EAAE,KAAK,UAAU,EACjD,OAAO,OAAOA,EAAc,aAAa,EAAE,KAAK,UAAU,EAE1D,MAAMC,EAAaF,EAAa,WAAW,MAAM,EAGjD,OAAO,OAAOE,EAAW,QAAQ,EAAE,KAAK,UAAU,EAClD,OAAO,OAAOA,EAAW,OAAO,EAAE,KAAK,UAAU,CACnD,CAAC,EAED,GAAG,kDAAmD,IAAM,CAK1D,MAAMF,KAAe,iCAA8B,qBAAsB,CACvE,aAAc,aACd,UAAW,IACX,QAPqC,CACrC,OAAQ,CAAE,MAAO,IAAK,OAAQ,EAAG,EACjC,KAAM,CAAE,MAAO,IAAK,OAAQ,GAAI,CAClC,CAKA,CAAC,EACD,OAAOA,CAAY,EAAE,WAAW,CAClC,CAAC,EAED,GAAG,6DAA8D,IAAM,CACrE,MAAMG,KAAI,iCAA8B,oBAAoB,EACtDC,KAAI,iCAA8B,oBAAoB,EAE5D,OAAOD,CAAC,EAAE,IAAI,KAAKC,CAAC,EACpB,OAAOD,EAAE,cAAc,EAAE,KAAK,EAAE,IAAI,KAAKC,EAAE,cAAc,EAAE,KAAK,EAChE,OAAOD,EAAE,WAAW,MAAM,EAAE,QAAQ,EAAE,IAAI,KACxCC,EAAE,WAAW,MAAM,EAAE,QACvB,CACF,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["import_DeviceController", "deviceClient", "deviceButtons", "deviceTaps", "a", "b"]
|
|
4
|
+
"sourcesContent": ["import type { DeviceScreens } from \"@internal/core/types\";\n\nimport { deviceControllerClientFactory } from \"./DeviceController\";\n\ndescribe(\"deviceControllerClientFactory\", () => {\n it(\"returns a DeviceControllerdeviceClient with the expected shape\", () => {\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(deviceClient).toBeDefined();\n expect(deviceClient).toHaveProperty(\"buttonFactory\");\n expect(deviceClient).toHaveProperty(\"tapFactory\");\n\n const deviceButtons = deviceClient.buttonFactory();\n\n // button surfaces\n expect(typeof deviceButtons.press).toBe(\"function\");\n expect(typeof deviceButtons.left).toBe(\"function\");\n expect(typeof deviceButtons.right).toBe(\"function\");\n expect(typeof deviceButtons.both).toBe(\"function\");\n expect(typeof deviceButtons.pressSequence).toBe(\"function\");\n\n const deviceTaps = deviceClient.tapFactory(\"flex\");\n\n // tap surfaces\n expect(typeof deviceTaps.tapQuick).toBe(\"function\");\n expect(typeof deviceTaps.tapLong).toBe(\"function\");\n });\n\n it(\"does not throw when created with custom options\", () => {\n const screens: DeviceScreens<string> = {\n custom: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n };\n const deviceClient = deviceControllerClientFactory(\"http://127.0.0.1:0\", {\n clientHeader: \"test-suite\",\n timeoutMs: 200,\n screens,\n });\n expect(deviceClient).toBeTruthy();\n });\n\n it(\"creates independent instances (no accidental shared state)\", () => {\n const a = deviceControllerClientFactory(\"http://localhost:0\");\n const b = deviceControllerClientFactory(\"http://localhost:0\");\n\n expect(a).not.toBe(b);\n expect(a.buttonFactory().press).not.toBe(b.buttonFactory().press);\n expect(a.tapFactory(\"flex\").tapQuick).not.toBe(\n b.tapFactory(\"flex\").tapQuick,\n );\n });\n\n it(\"sends the bearer token with every request\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n const deviceClient = deviceControllerClientFactory(\"http://localhost:0\", {\n bearerToken: \"session-token\",\n });\n\n await deviceClient.buttonFactory().press(\"both\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"http://localhost:0/button/both\",\n expect.objectContaining({\n headers: expect.objectContaining({\n Authorization: \"Bearer session-token\",\n }),\n }),\n );\n fetchSpy.mockRestore();\n });\n});\n"],
|
|
5
|
+
"mappings": "aAEA,IAAAA,EAA8C,8BAE9C,SAAS,gCAAiC,IAAM,CAC9C,GAAG,iEAAkE,IAAM,CACzE,MAAMC,KAAe,iCAA8B,oBAAoB,EAEvE,OAAOA,CAAY,EAAE,YAAY,EACjC,OAAOA,CAAY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c,EAAE,MAAM,MAAM,EAE/C,OAAOA,CAAQ,EAAE,qBACf,iCACA,OAAO,iBAAiB,CACtB,QAAS,OAAO,iBAAiB,CAC/B,cAAe,sBACjB,CAAC,CACH,CAAC,CACH,EACAA,EAAS,YAAY,CACvB,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_DeviceController", "deviceClient", "deviceButtons", "deviceTaps", "a", "b", "fetchSpy"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var r=Object.defineProperty;var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var s=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var u=(o,t)=>{for(var n in t)r(o,n,{get:t[n],enumerable:!0})},a=(o,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of s(t))!c.call(o,e)&&e!==n&&r(o,e,{get:()=>t[e],enumerable:!(l=p(t,e))||l.enumerable});return o};var m=o=>a(r({},"__esModule",{value:!0}),o);var B={};u(B,{DefaultButtonController:()=>y});module.exports=m(B);var i=require("../core/types");class y{constructor(t){this.client=t}async press(t){await this.client.post(`/button/${t}`,{action:i.SpeculosActions.PRESS_AND_RELEASE})}}0&&(module.exports={DefaultButtonController});
|
|
2
2
|
//# sourceMappingURL=DefaultButtonController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultButtonController.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,
|
|
4
|
+
"sourcesContent": ["import type { ButtonController } from \"@internal/core/ButtonController\";\nimport {\n type ButtonKey,\n type HttpClient,\n SpeculosActions,\n} from \"@internal/core/types\";\n\nexport class DefaultButtonController implements ButtonController {\n constructor(private readonly client: HttpClient) {}\n\n async press(key: ButtonKey): Promise<void> {\n await this.client.post(`/button/${key}`, {\n action: SpeculosActions.PRESS_AND_RELEASE,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GACA,IAAAI,EAIO,gCAEA,MAAMF,CAAoD,CAC/D,YAA6BG,EAAoB,CAApB,YAAAA,CAAqB,CAElD,MAAM,MAAMC,EAA+B,CACzC,MAAM,KAAK,OAAO,KAAK,WAAWA,CAAG,GAAI,CACvC,OAAQ,kBAAgB,iBAC1B,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["DefaultButtonController_exports", "__export", "DefaultButtonController", "__toCommonJS", "import_types", "client", "key"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("./DefaultButtonController");describe("DefaultButtonController",()=>{let e,n,o;beforeEach(()=>{e=vi.fn().mockResolvedValue(void 0),n={post:e},o=new r.DefaultButtonController(n)});const l=["left","right","both"];it.each(l)("press(%s) posts expected payload",async t=>{await o.press(t),expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith(`/button/${t}`,{action:"press-and-release"})}),it("propagates HTTP errors",async()=>{const t=new Error("oups");e.mockRejectedValueOnce(t),await expect(o.press("left")).rejects.toBe(t)})});
|
|
2
2
|
//# sourceMappingURL=DefaultButtonController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultButtonController.test.ts"],
|
|
4
|
-
"sourcesContent": ["import type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_DefaultButtonController", "postMock", "
|
|
4
|
+
"sourcesContent": ["import type { ButtonKey, HttpClient } from \"@internal/core/types\";\n\nimport { DefaultButtonController } from \"./DefaultButtonController\";\n\ndescribe(\"DefaultButtonController\", () => {\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n let controller: DefaultButtonController;\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n controller = new DefaultButtonController(httpClient);\n });\n\n const keys: ButtonKey[] = [\"left\", \"right\", \"both\"];\n\n it.each<ButtonKey>(keys)(\n \"press(%s) posts expected payload\",\n async (key: ButtonKey) => {\n await controller.press(key);\n\n expect(postMock).toHaveBeenCalledTimes(1);\n expect(postMock).toHaveBeenCalledWith(`/button/${key}`, {\n action: \"press-and-release\",\n });\n },\n );\n\n it(\"propagates HTTP errors\", async () => {\n const error = new Error(\"oups\");\n postMock.mockRejectedValueOnce(error);\n\n await expect(controller.press(\"left\" as ButtonKey)).rejects.toBe(error);\n });\n});\n"],
|
|
5
|
+
"mappings": "aAEA,IAAAA,EAAwC,qCAExC,SAAS,0BAA2B,IAAM,CACxC,IAAIC,EACAC,EACAC,EAEJ,WAAW,IAAM,CACfF,EAAW,GAAG,GAAG,EAAE,kBAAkB,MAAS,EAC9CC,EAAa,CAAE,KAAMD,CAAS,EAC9BE,EAAa,IAAI,0BAAwBD,CAAU,CACrD,CAAC,EAED,MAAME,EAAoB,CAAC,OAAQ,QAAS,MAAM,EAElD,GAAG,KAAgBA,CAAI,EACrB,mCACA,MAAOC,GAAmB,CACxB,MAAMF,EAAW,MAAME,CAAG,EAE1B,OAAOJ,CAAQ,EAAE,sBAAsB,CAAC,EACxC,OAAOA,CAAQ,EAAE,qBAAqB,WAAWI,CAAG,GAAI,CACtD,OAAQ,mBACV,CAAC,CACH,CACF,EAEA,GAAG,yBAA0B,SAAY,CACvC,MAAMC,EAAQ,IAAI,MAAM,MAAM,EAC9BL,EAAS,sBAAsBK,CAAK,EAEpC,MAAM,OAAOH,EAAW,MAAM,MAAmB,CAAC,EAAE,QAAQ,KAAKG,CAAK,CACxE,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_DefaultButtonController", "postMock", "httpClient", "controller", "keys", "key", "error"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var p=(i,t)=>{for(var e in t)s(i,e,{get:t[e],enumerable:!0})},h=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of c(t))!l.call(i,n)&&n!==e&&s(i,n,{get:()=>t[n],enumerable:!(o=a(t,n))||o.enumerable});return i};var d=i=>h(s({},"__esModule",{value:!0}),i);var m={};p(m,{DefaultTouchController:()=>u});module.exports=d(m);var r=require("../core/types");class u{constructor(t,e){this.client=t;this.axes=e}assertPercentPoint({x:t,y:e}){const o=n=>Number.isFinite(n)&&n>=0&&n<=100;if(!o(t)||!o(e))throw new Error(`[Touch] percent values must be within 0\u2013100. Received x=${t}, y=${e}`)}toAbs(t,e){const o=this.axes[t];if(!o){const n=Object.keys(this.axes);throw new Error(`[Touch] Unknown device key "${String(t)}". Known keys: ${n.join(", ")||"<none>"}`)}return this.assertPercentPoint(e),o.xy(e.x,e.y)}async tapAndRelease(t,e){const o=this.toAbs(t,e);await this.client.post("/finger",{action:r.SpeculosActions.PRESS_AND_RELEASE,...o})}async tap(t,e){const o=this.toAbs(t,e);await this.client.post("/finger",{action:r.SpeculosActions.PRESS,...o})}async release(t,e){const o=this.toAbs(t,e);await this.client.post("/finger",{action:r.SpeculosActions.RELEASE,...o})}}0&&(module.exports={DefaultTouchController});
|
|
2
2
|
//# sourceMappingURL=DefaultTouchController.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultTouchController.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,
|
|
4
|
+
"sourcesContent": ["import {\n type HttpClient,\n type PercentCoordinates,\n SpeculosActions,\n} from \"@internal/core/types\";\nimport type { AxisMap } from \"@internal/utils/axisClamp\";\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nexport class DefaultTouchController<K extends string>\n implements TouchController<K>\n{\n constructor(\n private readonly client: HttpClient,\n private readonly axes: AxisMap<K>,\n ) {}\n\n private assertPercentPoint({ x, y }: PercentCoordinates): void {\n const inRange = (v: number) => Number.isFinite(v) && v >= 0 && v <= 100;\n if (!inRange(x) || !inRange(y)) {\n throw new Error(\n `[Touch] percent values must be within 0\u2013100. Received x=${x}, y=${y}`,\n );\n }\n }\n\n private toAbs(deviceKey: K, p: PercentCoordinates) {\n const axis = this.axes[deviceKey];\n if (!axis) {\n const known = Object.keys(this.axes as Record<string, unknown>);\n throw new Error(\n `[Touch] Unknown device key \"${String(deviceKey)}\". Known keys: ${known.join(\", \") || \"<none>\"}`,\n );\n }\n this.assertPercentPoint(p);\n return axis.xy(p.x, p.y);\n }\n\n async tapAndRelease(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.PRESS_AND_RELEASE,\n ...abs,\n });\n }\n\n async tap(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.PRESS,\n ...abs,\n });\n }\n\n async release(deviceKey: K, point: PercentCoordinates): Promise<void> {\n const abs = this.toAbs(deviceKey, point);\n await this.client.post(`/finger`, {\n action: SpeculosActions.RELEASE,\n ...abs,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAIO,gCAIA,MAAMF,CAEb,CACE,YACmBG,EACAC,EACjB,CAFiB,YAAAD,EACA,UAAAC,CAChB,CAEK,mBAAmB,CAAE,EAAAC,EAAG,EAAAC,CAAE,EAA6B,CAC7D,MAAMC,EAAWC,GAAc,OAAO,SAASA,CAAC,GAAKA,GAAK,GAAKA,GAAK,IACpE,GAAI,CAACD,EAAQF,CAAC,GAAK,CAACE,EAAQD,CAAC,EAC3B,MAAM,IAAI,MACR,gEAA2DD,CAAC,OAAOC,CAAC,EACtE,CAEJ,CAEQ,MAAMG,EAAcC,EAAuB,CACjD,MAAMC,EAAO,KAAK,KAAKF,CAAS,EAChC,GAAI,CAACE,EAAM,CACT,MAAMC,EAAQ,OAAO,KAAK,KAAK,IAA+B,EAC9D,MAAM,IAAI,MACR,+BAA+B,OAAOH,CAAS,CAAC,kBAAkBG,EAAM,KAAK,IAAI,GAAK,QAAQ,EAChG,CACF,CACA,YAAK,mBAAmBF,CAAC,EAClBC,EAAK,GAAGD,EAAE,EAAGA,EAAE,CAAC,CACzB,CAEA,MAAM,cAAcD,EAAcI,EAA0C,CAC1E,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQ,kBAAgB,kBACxB,GAAGC,CACL,CAAC,CACH,CAEA,MAAM,IAAIL,EAAcI,EAA0C,CAChE,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQ,kBAAgB,MACxB,GAAGC,CACL,CAAC,CACH,CAEA,MAAM,QAAQL,EAAcI,EAA0C,CACpE,MAAMC,EAAM,KAAK,MAAML,EAAWI,CAAK,EACvC,MAAM,KAAK,OAAO,KAAK,UAAW,CAChC,OAAQ,kBAAgB,QACxB,GAAGC,CACL,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["DefaultTouchController_exports", "__export", "DefaultTouchController", "__toCommonJS", "import_types", "client", "axes", "x", "y", "inRange", "v", "deviceKey", "p", "axis", "known", "point", "abs"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var l=require("./DefaultTouchController");describe("DefaultTouchController",()=>{let e,s;const o={xy:vi.fn((
|
|
1
|
+
"use strict";var l=require("./DefaultTouchController");describe("DefaultTouchController",()=>{let e,s;const o={xy:vi.fn((a,i)=>({x:Math.round(a*10),y:Math.round(i*20)}))},r={xy:vi.fn((a,i)=>({x:Math.round(100+a),y:Math.round(200+i)}))};let c,n;beforeEach(()=>{e=vi.fn().mockResolvedValue(void 0),s={post:e},o.xy.mockClear(),r.xy.mockClear(),c={devA:o,devB:r},n=new l.DefaultTouchController(s,c)});const t={x:12,y:45};it("tapAndRelease: converts percent to absolute via axes and POSTs expected body",async()=>{await n.tapAndRelease("devA",t),expect(o.xy).toHaveBeenCalledTimes(1),expect(o.xy).toHaveBeenCalledWith(t.x,t.y);const a=o.xy.mock.results[0].value;expect(e).toHaveBeenCalledTimes(1),expect(e).toHaveBeenCalledWith("/finger",{action:"press-and-release",...a})}),it("tap: converts via axes and POSTs action 'press'",async()=>{await n.tap("devB",t),expect(r.xy).toHaveBeenCalledWith(t.x,t.y);const a=r.xy.mock.results[0]?.value;expect(e).toHaveBeenCalledWith("/finger",{action:"press",...a})}),it("release: converts via axes and POSTs action 'release'",async()=>{await n.release("devA",t);const a=o.xy.mock.results[0].value;expect(e).toHaveBeenCalledWith("/finger",{action:"release",...a})}),it("throws an error when device key is unknown",async()=>{await expect(n.tap("unknownDevice",t)).rejects.toThrow(/\[Touch] Unknown device key "unknownDevice".*Known keys: devA, devB/),expect(e).not.toHaveBeenCalled()}),it("propagates HTTP errors",async()=>{const a=new Error("backend down");e.mockRejectedValueOnce(a),await expect(n.tapAndRelease("devA",t)).rejects.toBe(a)})});describe("percent validation",()=>{let e,s,o;const r={xy:vi.fn((n,t)=>({x:n,y:t}))},c={devA:r};beforeEach(()=>{s=vi.fn().mockResolvedValue(void 0),o={post:s},r.xy.mockClear(),e=new l.DefaultTouchController(o,c)}),it("accepts boundary values 0 and 100",async()=>{await e.tapAndRelease("devA",{x:0,y:100}),await e.tap("devA",{x:100,y:0}),await e.release("devA",{x:50,y:99}),expect(s).toHaveBeenCalledTimes(3)}),it("rejects values outside [0, 100], non-finite, negative and non-integer",async()=>{const n=[{x:140,y:50},{x:-1,y:50},{x:50,y:120},{x:50,y:-.01}];for(const t of n)await expect(e.tapAndRelease("devA",t)).rejects.toThrow();expect(s).not.toHaveBeenCalled()}),it("rejects NaN or non-finite values",async()=>{const n=[{x:Number.NaN,y:50},{x:50,y:Number.NaN},{x:Number.POSITIVE_INFINITY,y:10},{x:10,y:Number.NEGATIVE_INFINITY}];for(const t of n)await expect(e.tap("devA",t)).rejects.toThrow(/percent/i);expect(s).not.toHaveBeenCalled()})});
|
|
2
2
|
//# sourceMappingURL=DefaultTouchController.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/adapters/DefaultTouchController.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport type {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["import_DefaultTouchController", "postMock", "
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\nimport type { HttpClient, PercentCoordinates } from \"../core/types\";\nimport { DefaultTouchController } from \"./DefaultTouchController\";\n\ndescribe(\"DefaultTouchController\", () => {\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n\n const axisA = {\n xy: vi.fn((xPct: number, yPct: number) => ({\n x: Math.round(xPct * 10),\n y: Math.round(yPct * 20),\n })),\n };\n const axisB = {\n xy: vi.fn((xPct: number, yPct: number) => ({\n x: Math.round(100 + xPct),\n y: Math.round(200 + yPct),\n })),\n };\n let axesFake: Record<\n string,\n { xy: (x: number, y: number) => { x: number; y: number } }\n >;\n\n let controller: DefaultTouchController<string>;\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n\n axisA.xy.mockClear();\n axisB.xy.mockClear();\n\n axesFake = { devA: axisA, devB: axisB };\n controller = new DefaultTouchController(httpClient, axesFake as any);\n });\n\n const point: PercentCoordinates = { x: 12, y: 45 };\n\n it(\"tapAndRelease: converts percent to absolute via axes and POSTs expected body\", async () => {\n await controller.tapAndRelease(\"devA\", point);\n\n expect(axisA.xy).toHaveBeenCalledTimes(1);\n expect(axisA.xy).toHaveBeenCalledWith(point.x, point.y);\n\n const expectedAbs = (axisA.xy.mock.results as any)[0].value;\n expect(postMock).toHaveBeenCalledTimes(1);\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"press-and-release\",\n ...expectedAbs,\n });\n });\n\n it(\"tap: converts via axes and POSTs action 'press'\", async () => {\n await controller.tap(\"devB\", point);\n\n expect(axisB.xy).toHaveBeenCalledWith(point.x, point.y);\n const expectedAbs = axisB.xy.mock.results[0]?.value;\n\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"press\",\n ...expectedAbs,\n });\n });\n\n it(\"release: converts via axes and POSTs action 'release'\", async () => {\n await controller.release(\"devA\", point);\n\n const expectedAbs = axisA.xy.mock.results[0]!.value;\n expect(postMock).toHaveBeenCalledWith(\"/finger\", {\n action: \"release\",\n ...expectedAbs,\n });\n });\n\n it(\"throws an error when device key is unknown\", async () => {\n await expect(controller.tap(\"unknownDevice\" as any, point)).rejects.toThrow(\n /\\[Touch] Unknown device key \"unknownDevice\".*Known keys: devA, devB/,\n );\n expect(postMock).not.toHaveBeenCalled();\n });\n\n it(\"propagates HTTP errors\", async () => {\n const boom = new Error(\"backend down\");\n postMock.mockRejectedValueOnce(boom);\n\n await expect(controller.tapAndRelease(\"devA\", point)).rejects.toBe(boom);\n });\n});\n\ndescribe(\"percent validation\", () => {\n let controller: DefaultTouchController<string>;\n let postMock: ReturnType<typeof vi.fn>;\n let httpClient: HttpClient;\n\n const axis = {\n xy: vi.fn((xPct: number, yPct: number) => ({ x: xPct, y: yPct })),\n };\n const axesFake = { devA: axis };\n\n beforeEach(() => {\n postMock = vi.fn().mockResolvedValue(undefined);\n httpClient = { post: postMock };\n axis.xy.mockClear();\n controller = new DefaultTouchController(httpClient, axesFake as any);\n });\n\n it(\"accepts boundary values 0 and 100\", async () => {\n await controller.tapAndRelease(\"devA\", { x: 0, y: 100 });\n await controller.tap(\"devA\", { x: 100, y: 0 });\n await controller.release(\"devA\", { x: 50, y: 99 });\n\n // should have sent 3 HTTP calls if all accepted\n expect(postMock).toHaveBeenCalledTimes(3);\n });\n\n it(\"rejects values outside [0, 100], non-finite, negative and non-integer\", async () => {\n const badPoints = [\n { x: 140, y: 50 },\n { x: -1, y: 50 },\n { x: 50, y: 120 },\n { x: 50, y: -0.01 },\n ];\n\n for (const p of badPoints) {\n await expect(\n controller.tapAndRelease(\"devA\", p as any),\n ).rejects.toThrow();\n }\n\n // no HTTP calls should be made for invalid input\n expect(postMock).not.toHaveBeenCalled();\n });\n\n it(\"rejects NaN or non-finite values\", async () => {\n const badPoints = [\n { x: Number.NaN, y: 50 },\n { x: 50, y: Number.NaN },\n { x: Number.POSITIVE_INFINITY, y: 10 },\n { x: 10, y: Number.NEGATIVE_INFINITY },\n ];\n\n for (const p of badPoints) {\n await expect(controller.tap(\"devA\", p as any)).rejects.toThrow(\n /percent/i,\n );\n }\n expect(postMock).not.toHaveBeenCalled();\n });\n});\n"],
|
|
5
|
+
"mappings": "aAKA,IAAAA,EAAuC,oCAEvC,SAAS,yBAA0B,IAAM,CACvC,IAAIC,EACAC,EAEJ,MAAMC,EAAQ,CACZ,GAAI,GAAG,GAAG,CAACC,EAAcC,KAAkB,CACzC,EAAG,KAAK,MAAMD,EAAO,EAAE,EACvB,EAAG,KAAK,MAAMC,EAAO,EAAE,CACzB,EAAE,C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,CAAE,EAAG,GAAI,EAAG,GAAI,EAChB,CAAE,EAAG,GAAI,EAAG,IAAM,CACpB,EAEA,UAAWC,KAAKD,EACd,MAAM,OACJL,EAAW,cAAc,OAAQM,CAAQ,CAC3C,EAAE,QAAQ,QAAQ,EAIpB,OAAOb,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,EAED,GAAG,mCAAoC,SAAY,CACjD,MAAMY,EAAY,CAChB,CAAE,EAAG,OAAO,IAAK,EAAG,EAAG,EACvB,CAAE,EAAG,GAAI,EAAG,OAAO,GAAI,EACvB,CAAE,EAAG,OAAO,kBAAmB,EAAG,EAAG,EACrC,CAAE,EAAG,GAAI,EAAG,OAAO,iBAAkB,CACvC,EAEA,UAAWC,KAAKD,EACd,MAAM,OAAOL,EAAW,IAAI,OAAQM,CAAQ,CAAC,EAAE,QAAQ,QACrD,UACF,EAEF,OAAOb,CAAQ,EAAE,IAAI,iBAAiB,CACxC,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_DefaultTouchController", "postMock", "httpClient", "axisA", "xPct", "yPct", "axisB", "axesFake", "controller", "point", "expectedAbs", "boom", "axis", "badPoints", "p"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var a=(t,e)=>{for(var c in e)s(t,c,{get:e[c],enumerable:!0})},g=(t,e,c,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of i(e))!x.call(t,r)&&r!==c&&s(t,r,{get:()=>e[r],enumerable:!(n=o(e,r))||n.enumerable});return t};var d=t=>g(s({},"__esModule",{value:!0}),t);var y={};a(y,{SpeculosActions:()=>p});module.exports=d(y);var p=(n=>(n.PRESS="press",n.RELEASE="release",n.PRESS_AND_RELEASE="press-and-release",n))(p||{});0&&(module.exports={SpeculosActions});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/core/types.ts"],
|
|
4
|
-
"sourcesContent": ["export type ButtonKey = \"left\" | \"right\" | \"both\";\n\nexport type ScreenSpec = Readonly<{ width: number; height: number }>;\n\nexport type DeviceScreens<K extends string = string> = Readonly<\n Record<K, ScreenSpec>\n>;\n\nexport type Range<\n N extends number,\n Acc extends number[] = [],\n> = Acc[\"length\"] extends N ? Acc[number] : Range<N, [...Acc, Acc[\"length\"]]>;\nexport type Percent = Range<101>;\n\nexport type PercentCoordinates = { x: Percent; y: Percent };\n\nexport type DeviceControllerOptions<K extends string = string> = {\n screens: DeviceScreens<K>;\n timeoutMs?: number;\n clientHeader?: string;\n};\n\nexport enum SpeculosActions {\n PRESS = \"press\",\n RELEASE = \"release\",\n PRESS_AND_RELEASE = \"press-and-release\",\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,
|
|
4
|
+
"sourcesContent": ["export type ButtonKey = \"left\" | \"right\" | \"both\";\n\nexport type ScreenSpec = Readonly<{ width: number; height: number }>;\n\nexport type DeviceScreens<K extends string = string> = Readonly<\n Record<K, ScreenSpec>\n>;\n\nexport type Range<\n N extends number,\n Acc extends number[] = [],\n> = Acc[\"length\"] extends N ? Acc[number] : Range<N, [...Acc, Acc[\"length\"]]>;\nexport type Percent = Range<101>;\n\nexport type PercentCoordinates = { x: Percent; y: Percent };\n\nexport type DeviceControllerOptions<K extends string = string> = {\n screens: DeviceScreens<K>;\n timeoutMs?: number;\n clientHeader?: string;\n bearerToken?: string;\n};\n\nexport interface HttpClient {\n post(url: string, data?: unknown): Promise<unknown>;\n}\n\nexport enum SpeculosActions {\n PRESS = \"press\",\n RELEASE = \"release\",\n PRESS_AND_RELEASE = \"press-and-release\",\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GA2BO,IAAKE,OACVA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,kBAAoB,oBAHVA,OAAA",
|
|
6
6
|
"names": ["types_exports", "__export", "SpeculosActions", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var T=(o,t)=>{for(var e in t)l(o,e,{get:t[e],enumerable:!0})},w=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of k(t))!y.call(o,r)&&r!==e&&l(o,r,{get:()=>t[r],enumerable:!(n=h(t,r))||n.enumerable});return o};var x=o=>w(l({},"__esModule",{value:!0}),o);var D={};T(D,{createDefaultControllers:()=>B});module.exports=x(D);var i=require("@ledgerhq/device-management-kit"),s=require("./adapters/DefaultButtonController"),c=require("./adapters/DefaultTouchController"),u=require("./utils/axisClamp");function B(o,t){const e=t.timeoutMs??1500,n=new i.DmkNetworkClient({baseUrl:o,headers:{"X-Ledger-Client-Version":t.clientHeader??"ldmk-transport-speculos",...t.bearerToken?{Authorization:`Bearer ${t.bearerToken}`}:{}}}),r={async post(m,f){return n.post(m,f,{timeoutMs:e})}},a=(0,u.createAxes)(t.screens),p=new s.DefaultButtonController(r),C=new c.DefaultTouchController(r,a);return{buttons:p,touch:C}}0&&(module.exports={createDefaultControllers});
|
|
2
2
|
//# sourceMappingURL=di.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/di.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["di_exports", "__export", "createDefaultControllers", "__toCommonJS", "
|
|
4
|
+
"sourcesContent": ["import { DmkNetworkClient } from \"@ledgerhq/device-management-kit\";\n\nimport { DefaultButtonController } from \"@internal/adapters/DefaultButtonController\";\nimport { DefaultTouchController } from \"@internal/adapters/DefaultTouchController\";\nimport type { ButtonController } from \"@internal/core/ButtonController\";\nimport type { DeviceControllerOptions, HttpClient } from \"@internal/core/types\";\nimport { type AxisMap, createAxes } from \"@internal/utils/axisClamp\";\nimport type { TouchController } from \"@root/src/internal/core/TouchController\";\n\nexport type ControllersContainer = {\n buttons: ButtonController;\n touch: TouchController;\n};\n\nexport function createDefaultControllers(\n baseURL: string,\n opts: DeviceControllerOptions,\n): ControllersContainer {\n const timeoutMs = opts.timeoutMs ?? 1500;\n const client = new DmkNetworkClient({\n baseUrl: baseURL,\n headers: {\n \"X-Ledger-Client-Version\": opts.clientHeader ?? \"ldmk-transport-speculos\",\n ...(opts.bearerToken\n ? { Authorization: `Bearer ${opts.bearerToken}` }\n : {}),\n },\n });\n\n const http: HttpClient = {\n async post(url: string, data?: unknown): Promise<unknown> {\n return client.post(url, data, { timeoutMs });\n },\n };\n\n const axes: AxisMap = createAxes(opts.screens);\n\n const buttons: ButtonController = new DefaultButtonController(http);\n const touch: TouchController = new DefaultTouchController(http, axes);\n\n return { buttons, touch };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAiC,2CAEjCC,EAAwC,sDACxCC,EAAuC,qDAGvCC,EAAyC,qCAQlC,SAASL,EACdM,EACAC,EACsB,CACtB,MAAMC,EAAYD,EAAK,WAAa,KAC9BE,EAAS,IAAI,mBAAiB,CAClC,QAASH,EACT,QAAS,CACP,0BAA2BC,EAAK,cAAgB,0BAChD,GAAIA,EAAK,YACL,CAAE,cAAe,UAAUA,EAAK,WAAW,EAAG,EAC9C,CAAC,CACP,CACF,CAAC,EAEKG,EAAmB,CACvB,MAAM,KAAKC,EAAaC,EAAkC,CACxD,OAAOH,EAAO,KAAKE,EAAKC,EAAM,CAAE,UAAAJ,CAAU,CAAC,CAC7C,CACF,EAEMK,KAAgB,cAAWN,EAAK,OAAO,EAEvCO,EAA4B,IAAI,0BAAwBJ,CAAI,EAC5DK,EAAyB,IAAI,yBAAuBL,EAAMG,CAAI,EAEpE,MAAO,CAAE,QAAAC,EAAS,MAAAC,CAAM,CAC1B",
|
|
6
|
+
"names": ["di_exports", "__export", "createDefaultControllers", "__toCommonJS", "import_device_management_kit", "import_DefaultButtonController", "import_DefaultTouchController", "import_axisClamp", "baseURL", "opts", "timeoutMs", "client", "http", "url", "data", "axes", "buttons", "touch"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("vitest"),a=require("./adapters/DefaultButtonController"),c=require("./adapters/DefaultTouchController"),s=require("./di");const n={flex:{width:128,height:64},stax:{width:400,height:672}};(0,e.afterEach)(()=>{e.vi.restoreAllMocks()});(0,e.describe)("createDefaultControllers - fetch configuration",()=>{(0,e.it)("configures with custom timeout and header",async()=>{const t=e.vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=(0,s.createDefaultControllers)("https://example.com/api",{screens:n,timeoutMs:2345,clientHeader:"test-client"});await o.press("left"),(0,e.expect)(t).toHaveBeenCalledTimes(1),(0,e.expect)(t).toHaveBeenCalledWith("https://example.com/api/button/left",e.expect.objectContaining({method:"POST",headers:e.expect.objectContaining({"X-Ledger-Client-Version":"test-client"})}))}),(0,e.it)("applies default timeout and client header when not provided",async()=>{const t=e.vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=(0,s.createDefaultControllers)("https://localhost:1234",{screens:n});await o.press("left"),(0,e.expect)(t).toHaveBeenCalledWith("https://localhost:1234/button/left",e.expect.objectContaining({method:"POST",headers:e.expect.objectContaining({"X-Ledger-Client-Version":"ldmk-transport-speculos"})}))}),(0,e.it)("sends the bearer token alongside the client header",async()=>{const t=e.vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{touch:o}=(0,s.createDefaultControllers)("https://localhost:1234",{screens:n,clientHeader:"test-client",bearerToken:"session-token"});await o.tap("stax",{x:50,y:50}),(0,e.expect)(t).toHaveBeenCalledWith("https://localhost:1234/finger",e.expect.objectContaining({headers:e.expect.objectContaining({Authorization:"Bearer session-token","X-Ledger-Client-Version":"test-client"})}))})});(0,e.describe)("createDefaultControllers - wiring",()=>{(0,e.it)("returns correct controller implementations",()=>{const{buttons:t,touch:o}=(0,s.createDefaultControllers)("https://x",{screens:n});(0,e.expect)(t).toBeInstanceOf(a.DefaultButtonController),(0,e.expect)(o).toBeInstanceOf(c.DefaultTouchController),(0,e.expect)(typeof t.press).toBe("function")}),(0,e.it)("creates fresh instances per invocation",()=>{const t=(0,s.createDefaultControllers)("https://x",{screens:n}),o=(0,s.createDefaultControllers)("https://x",{screens:n});(0,e.expect)(t.buttons).not.toBe(o.buttons),(0,e.expect)(t.touch).not.toBe(o.touch)}),(0,e.it)("button.press posts the correct payload",async()=>{const t=e.vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{buttons:o}=(0,s.createDefaultControllers)("https://x",{screens:n});await o.press("left"),(0,e.expect)(t).toHaveBeenCalledWith("https://x/button/left",e.expect.objectContaining({method:"POST",body:JSON.stringify({action:"press-and-release"})}))}),(0,e.it)("touch.tapAndRelease maps percent to absolute coords",async()=>{const t=e.vi.spyOn(globalThis,"fetch").mockResolvedValue(new Response("{}")),{touch:o}=(0,s.createDefaultControllers)("https://x",{screens:n});await o.tapAndRelease("flex",{x:50,y:50}),(0,e.expect)(t).toHaveBeenCalledWith("https://x/finger",e.expect.objectContaining({method:"POST",body:JSON.stringify({action:"press-and-release",x:64,y:32})}))})});
|
|
2
2
|
//# sourceMappingURL=di.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/di.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { afterEach, describe, expect, it, vi } from \"vitest\";\n\nimport { DefaultButtonController } from \"@internal/adapters/DefaultButtonController\";\nimport { DefaultTouchController } from \"@internal/adapters/DefaultTouchController\";\n\nimport { createDefaultControllers } from \"./di\";\n\nconst SCREENS = {\n flex: { width: 128, height: 64 },\n stax: { width: 400, height: 672 },\n} as const;\n\nafterEach(() => {\n vi.restoreAllMocks();\n});\n\ndescribe(\"createDefaultControllers - fetch configuration\", () => {\n it(\"configures with custom timeout and header\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://example.com/api\", {\n screens: SCREENS,\n timeoutMs: 2345,\n clientHeader: \"test-client\",\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledTimes(1);\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://example.com/api/button/left\",\n expect.objectContaining({\n method: \"POST\",\n headers: expect.objectContaining({\n \"X-Ledger-Client-Version\": \"test-client\",\n }),\n }),\n );\n });\n\n it(\"applies default timeout and client header when not provided\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://localhost:1234\", {\n screens: SCREENS,\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://localhost:1234/button/left\",\n expect.objectContaining({\n method: \"POST\",\n headers: expect.objectContaining({\n \"X-Ledger-Client-Version\": \"ldmk-transport-speculos\",\n }),\n }),\n );\n });\n\n it(\"sends the bearer token alongside the client header\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { touch } = createDefaultControllers(\"https://localhost:1234\", {\n screens: SCREENS,\n clientHeader: \"test-client\",\n bearerToken: \"session-token\",\n });\n\n await touch.tap(\"stax\", { x: 50, y: 50 });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://localhost:1234/finger\",\n expect.objectContaining({\n headers: expect.objectContaining({\n Authorization: \"Bearer session-token\",\n \"X-Ledger-Client-Version\": \"test-client\",\n }),\n }),\n );\n });\n});\n\ndescribe(\"createDefaultControllers - wiring\", () => {\n it(\"returns correct controller implementations\", () => {\n const { buttons, touch } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n expect(buttons).toBeInstanceOf(DefaultButtonController);\n expect(touch).toBeInstanceOf(DefaultTouchController);\n expect(typeof buttons.press).toBe(\"function\");\n });\n\n it(\"creates fresh instances per invocation\", () => {\n const a = createDefaultControllers(\"https://x\", { screens: SCREENS });\n const b = createDefaultControllers(\"https://x\", { screens: SCREENS });\n\n expect(a.buttons).not.toBe(b.buttons);\n expect(a.touch).not.toBe(b.touch);\n });\n\n it(\"button.press posts the correct payload\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { buttons } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n await buttons.press(\"left\");\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://x/button/left\",\n expect.objectContaining({\n method: \"POST\",\n body: JSON.stringify({ action: \"press-and-release\" }),\n }),\n );\n });\n\n it(\"touch.tapAndRelease maps percent to absolute coords\", async () => {\n const fetchSpy = vi\n .spyOn(globalThis, \"fetch\")\n .mockResolvedValue(new Response(\"{}\"));\n\n const { touch } = createDefaultControllers(\"https://x\", {\n screens: SCREENS,\n });\n\n // 50% of 128x64 \u2192 (64, 32)\n await touch.tapAndRelease(\"flex\", { x: 50 as any, y: 50 as any });\n\n expect(fetchSpy).toHaveBeenCalledWith(\n \"https://x/finger\",\n expect.objectContaining({\n method: \"POST\",\n body: JSON.stringify({\n action: \"press-and-release\",\n x: 64,\n y: 32,\n }),\n }),\n );\n });\n});\n"],
|
|
5
|
+
"mappings": "aACA,IAAAA,EAAoD,kBAEpDC,EAAwC,sDACxCC,EAAuC,qDAEvCC,EAAyC,gBAEzC,MAAMC,EAAU,CACd,KAAM,CAAE,MAAO,IAAK,OAAQ,EAAG,EAC/B,KAAM,CAAE,MAAO,IAAK,OAAQ,GAAI,CAClC,KAEA,aAAU,IAAM,CACd,KAAG,gBAAgB,CACrB,CAAC,KAED,YAAS,iDAAkD,IAAM,IAC/D,MAAG,4CAA6C,SAAY,CAC1D,MAAMC,EAAW,KACd,MAAM,WAAY,OAAO,EACzB,kBAAkB,IAAI,SAAS,IAAI,CAAC,EAEjC,CAAE,QAAAC,CAAQ,KAAI,4BAAyB,0BAA2B,CACtE,QAASF,EACT,UAAW,KACX,aAAc,aAChB,CAAC,EAED,MAAME,EAAQ,MAAM,MAAM,KAE1B,UAAOD,CAAQ,EAAE,sBAAsB,CAAC,KACxC,UAAOA,CAAQ,EAAE,qBACf,sCACA,SAAO,iBAAiB,CACtB,OAAQ,OACR,QAAS,SAAO,iBAAiB,CAC/B,0BAA2B,aAC7B,CAAC,CACH,CAAC,CACH,CACF,CAAC,KAED,MAAG,8DAA+D,SAAY,CAC5E,MAAMA,EAAW,KACd,MAAM,WAAY,OAAO,EACzB,kBAAkB,IAAI,SAAS,IAAI,CAAC,EAEjC,CAAE,QAAAC,CAAQ,KAAI,4BAAyB,yBAA0B,CACrE,QAASF,CACX,CAAC,EAED,MAAME,EAAQ,MAAM,MAAM,KAE1B,UAAOD,CAAQ,EAAE,qBACf,qCACA,SAAO,iBAAiB,CACtB,OAAQ,OACR,QAAS,SAAO,iBAAiB,CAC/B,0BAA2B,yBAC7B,CAAC,CACH,CAAC,CACH,CACF,CAAC,KAED,MAAG,qDAAsD,SAAY,CACnE,MAAMA,EAAW,KACd,MAAM,WAAY,OAAO,EACzB,kBAA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CACH,CACF,CAAC,KAED,MAAG,sDAAuD,SAAY,CACpE,MAAMA,EAAW,KACd,MAAM,WAAY,OAAO,EACzB,kBAAkB,IAAI,SAAS,IAAI,CAAC,EAEjC,CAAE,MAAAE,CAAM,KAAI,4BAAyB,YAAa,CACtD,QAASH,CACX,CAAC,EAGD,MAAMG,EAAM,cAAc,OAAQ,CAAE,EAAG,GAAW,EAAG,EAAU,CAAC,KAEhE,UAAOF,CAAQ,EAAE,qBACf,mBACA,SAAO,iBAAiB,CACtB,OAAQ,OACR,KAAM,KAAK,UAAU,CACnB,OAAQ,oBACR,EAAG,GACH,EAAG,EACL,CAAC,CACH,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["import_vitest", "import_DefaultButtonController", "import_DefaultTouchController", "import_di", "SCREENS", "fetchSpy", "buttons", "touch", "a", "b"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var d=(n,t)=>{for(var o in t)i(n,o,{get:t[o],enumerable:!0})},C=(n,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!g.call(n,s)&&s!==o&&i(n,s,{get:()=>t[s],enumerable:!(r=y(t,s))||r.enumerable});return n};var p=n=>C(i({},"__esModule",{value:!0}),n);var L={};d(L,{acceptBlindSigning:()=>A,confirmAddressBookReview:()=>G,continueToBlindSigning:()=>I,enableBlindSigningSettings:()=>f,enterMenu:()=>h,exitMenu:()=>B,mainButton:()=>_,navigateNext:()=>T,navigatePrevious:()=>S,reject:()=>u,secondaryButton:()=>w,sign:()=>O,tapLong:()=>c,tapQuick:()=>e});module.exports=p(L);const a=5e3,c=(n,t)=>async(o,r=a)=>{await n.tap(t,o),await new Promise(s=>setTimeout(s,r)),await n.release(t,o)},e=(n,t)=>async o=>await n.tapAndRelease(t,o),O=(n,t)=>async(o=a)=>await c(n,t)({x:85,y:80},o),u=(n,t)=>async()=>await e(n,t)({x:20,y:90}),T=(n,t)=>async()=>await e(n,t)({x:90,y:90}),S=(n,t)=>async()=>await e(n,t)({x:45,y:90}),_=(n,t)=>async()=>await e(n,t)({x:50,y:80}),w=(n,t)=>async()=>await e(n,t)({x:50,y:90}),h=(n,t)=>async()=>await e(n,t)({x:85,y:8}),B=(n,t)=>async()=>await e(n,t)({x:10,y:4}),x={stax:{x:88,y:51},flex:{x:88,y:58},apex:{x:88,y:58}},D=n=>Object.hasOwn(x,n),R={x:88,y:51},f=(n,t)=>async()=>{const o=D(t)?x[t]:R;await e(n,t)(o)},K={stax:{x:50,y:77},flex:{x:50,y:72}},N=n=>Object.hasOwn(K,n),m={x:50,y:72},G=(n,t)=>async()=>{const o=N(t)?K[t]:m;await e(n,t)(o)},I=(n,t)=>async()=>await e(n,t)({x:50,y:94}),A=(n,t)=>async()=>await e(n,t)({x:50,y:94});0&&(module.exports={acceptBlindSigning,confirmAddressBookReview,continueToBlindSigning,enableBlindSigningSettings,enterMenu,exitMenu,mainButton,navigateNext,navigatePrevious,reject,secondaryButton,sign,tapLong,tapQuick});
|
|
2
2
|
//# sourceMappingURL=touchUseCases.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/use-cases/touchUseCases.ts"],
|
|
4
|
-
"sourcesContent": ["import type { PercentCoordinates } from \"@internal/core/types\";\nimport { type TouchController } from \"@root/src/internal/core/TouchController\";\n\nconst TAP_LONG_TIME_MS = 5000;\n\nexport const tapLong =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates, delayMs: number = TAP_LONG_TIME_MS) => {\n await touch.tap(deviceKey, point);\n await new Promise((r) => setTimeout(r, delayMs));\n await touch.release(deviceKey, point);\n };\n\nexport const tapQuick =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates) =>\n await touch.tapAndRelease(deviceKey, point);\n\nexport const sign =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (delayMs: number = TAP_LONG_TIME_MS) =>\n await tapLong(touch, deviceKey)({ x: 85, y: 80 }, delayMs);\n\nexport const reject =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 20, y: 90 });\n\nexport const navigateNext =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 90, y: 90 });\n\nexport const navigatePrevious =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 45, y: 90 });\n\nexport const mainButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 80 });\n\nexport const secondaryButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 90 });\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
6
|
-
"names": ["touchUseCases_exports", "__export", "mainButton", "navigateNext", "navigatePrevious", "reject", "secondaryButton", "sign", "tapLong", "tapQuick", "__toCommonJS", "TAP_LONG_TIME_MS", "touch", "deviceKey", "point", "delayMs", "r"]
|
|
4
|
+
"sourcesContent": ["import type { PercentCoordinates } from \"@internal/core/types\";\nimport { type TouchController } from \"@root/src/internal/core/TouchController\";\n\nconst TAP_LONG_TIME_MS = 5000;\n\nexport const tapLong =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates, delayMs: number = TAP_LONG_TIME_MS) => {\n await touch.tap(deviceKey, point);\n await new Promise((r) => setTimeout(r, delayMs));\n await touch.release(deviceKey, point);\n };\n\nexport const tapQuick =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (point: PercentCoordinates) =>\n await touch.tapAndRelease(deviceKey, point);\n\nexport const sign =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async (delayMs: number = TAP_LONG_TIME_MS) =>\n await tapLong(touch, deviceKey)({ x: 85, y: 80 }, delayMs);\n\nexport const reject =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 20, y: 90 });\n\nexport const navigateNext =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 90, y: 90 });\n\nexport const navigatePrevious =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 45, y: 90 });\n\nexport const mainButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 80 });\n\nexport const secondaryButton =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 90 });\n\nexport const enterMenu =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 85, y: 8 });\n\nexport const exitMenu =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 10, y: 4 });\n\nconst BLIND_SIGNING_TOGGLE_COORDS = {\n stax: { x: 88, y: 51 },\n flex: { x: 88, y: 58 },\n apex: { x: 88, y: 58 },\n} as const satisfies Record<string, PercentCoordinates>;\n\ntype BlindSigningTouchKey = keyof typeof BLIND_SIGNING_TOGGLE_COORDS;\n\nconst isBlindSigningTouchKey = (key: string): key is BlindSigningTouchKey =>\n Object.hasOwn(BLIND_SIGNING_TOGGLE_COORDS, key);\n\nconst DEFAULT_BLIND_SIGNING_TOGGLE_COORDS: PercentCoordinates = {\n x: 88,\n y: 51,\n};\n\nexport const enableBlindSigningSettings =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () => {\n const point = isBlindSigningTouchKey(deviceKey)\n ? BLIND_SIGNING_TOGGLE_COORDS[deviceKey]\n : DEFAULT_BLIND_SIGNING_TOGGLE_COORDS;\n await tapQuick(touch, deviceKey)(point);\n };\n\n/**\n * Confirm button of the Address Book review (REGISTER IDENTITY). NBGL's\n * \"review light\" puts this button above the page footer rather than in it, so\n * neither mainButton() nor secondaryButton() reaches it. Measured on Speculos:\n * flex 480x600 -> button centre y=436 (72%), stax 400x672 -> y=520 (77%).\n */\nconst ADDRESS_BOOK_CONFIRM_COORDS = {\n stax: { x: 50, y: 77 },\n flex: { x: 50, y: 72 },\n} as const satisfies Record<string, PercentCoordinates>;\n\ntype AddressBookConfirmKey = keyof typeof ADDRESS_BOOK_CONFIRM_COORDS;\n\nconst isAddressBookConfirmKey = (key: string): key is AddressBookConfirmKey =>\n Object.hasOwn(ADDRESS_BOOK_CONFIRM_COORDS, key);\n\n/** Flex's placement, used for any touchscreen model not measured above. */\nconst DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS: PercentCoordinates = {\n x: 50,\n y: 72,\n};\n\nexport const confirmAddressBookReview =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () => {\n const point = isAddressBookConfirmKey(deviceKey)\n ? ADDRESS_BOOK_CONFIRM_COORDS[deviceKey]\n : DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS;\n await tapQuick(touch, deviceKey)(point);\n };\n\nexport const continueToBlindSigning =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 94 });\n\nexport const acceptBlindSigning =\n <K extends string>(touch: TouchController<K>, deviceKey: K) =>\n async () =>\n await tapQuick(touch, deviceKey)({ x: 50, y: 94 });\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,6BAAAC,EAAA,2BAAAC,EAAA,+BAAAC,EAAA,cAAAC,EAAA,aAA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AI,EAAG,CAAE,CAAC,EAEvCZ,EACX,CAAmBW,EAA2BC,IAC9C,SACE,MAAMJ,EAASG,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,CAAE,CAAC,EAE9CI,EAA8B,CAClC,KAAM,CAAE,EAAG,GAAI,EAAG,EAAG,EACrB,KAAM,CAAE,EAAG,GAAI,EAAG,EAAG,EACrB,KAAM,CAAE,EAAG,GAAI,EAAG,EAAG,CACvB,EAIMC,EAA0BC,GAC9B,OAAO,OAAOF,EAA6BE,CAAG,EAE1CC,EAA0D,CAC9D,EAAG,GACH,EAAG,EACL,EAEarB,EACX,CAAmBa,EAA2BC,IAC9C,SAAY,CACV,MAAMC,EAAQI,EAAuBL,CAAS,EAC1CI,EAA4BJ,CAAS,EACrCO,EACJ,MAAMX,EAASG,EAAOC,CAAS,EAAEC,CAAK,CACxC,EAQIO,EAA8B,CAClC,KAAM,CAAE,EAAG,GAAI,EAAG,EAAG,EACrB,KAAM,CAAE,EAAG,GAAI,EAAG,EAAG,CACvB,EAIMC,EAA2BH,GAC/B,OAAO,OAAOE,EAA6BF,CAAG,EAG1CI,EAA0D,CAC9D,EAAG,GACH,EAAG,EACL,EAEa1B,EACX,CAAmBe,EAA2BC,IAC9C,SAAY,CACV,MAAMC,EAAQQ,EAAwBT,CAAS,EAC3CQ,EAA4BR,CAAS,EACrCU,EACJ,MAAMd,EAASG,EAAOC,CAAS,EAAEC,CAAK,CACxC,EAEWhB,EACX,CAAmBc,EAA2BC,IAC9C,SACE,MAAMJ,EAASG,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC,EAExCjB,EACX,CAAmBgB,EAA2BC,IAC9C,SACE,MAAMJ,EAASG,EAAOC,CAAS,EAAE,CAAE,EAAG,GAAI,EAAG,EAAG,CAAC",
|
|
6
|
+
"names": ["touchUseCases_exports", "__export", "acceptBlindSigning", "confirmAddressBookReview", "continueToBlindSigning", "enableBlindSigningSettings", "enterMenu", "exitMenu", "mainButton", "navigateNext", "navigatePrevious", "reject", "secondaryButton", "sign", "tapLong", "tapQuick", "__toCommonJS", "TAP_LONG_TIME_MS", "touch", "deviceKey", "point", "delayMs", "r", "BLIND_SIGNING_TOGGLE_COORDS", "isBlindSigningTouchKey", "key", "DEFAULT_BLIND_SIGNING_TOGGLE_COORDS", "ADDRESS_BOOK_CONFIRM_COORDS", "isAddressBookConfirmKey", "DEFAULT_ADDRESS_BOOK_CONFIRM_COORDS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=require("./touchUseCases");describe("touchUsecases",()=>{const s="devA",i={x:50,y:30};let e;beforeEach(()=>{e={tap:vi.fn().mockResolvedValue(void 0),release:vi.fn().mockResolvedValue(void 0),tapAndRelease:vi.fn().mockResolvedValue(void 0)},vi.restoreAllMocks(),vi.useRealTimers()}),it("tapQuick calls tapAndRelease with the same deviceKey and point",async()=>{await(0,t.tapQuick)(e,s)(i),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(s,i),expect(e.tap).not.toHaveBeenCalled(),expect(e.release).not.toHaveBeenCalled()}),it("tapLong taps, waits default timeout, then releases",async()=>{vi.useFakeTimers();const a=vi.spyOn(globalThis,"setTimeout"),o=(0,t.tapLong)(e,s)(i);await Promise.resolve(),expect(e.tap).toHaveBeenCalledTimes(1),expect(e.tap).toHaveBeenCalledWith(s,i),expect(a).toHaveBeenCalledTimes(1),expect(a).toHaveBeenLastCalledWith(expect.any(Function),5e3),expect(e.release).not.toHaveBeenCalled(),await vi.advanceTimersByTimeAsync(5e3),await o,expect(e.release).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledWith(s,i)}),it("tapLong uses the provided delayMs value",async()=>{vi.useFakeTimers();const a=vi.spyOn(globalThis,"setTimeout"),n=1234,l=(0,t.tapLong)(e,s)(i,n);await Promise.resolve(),expect(e.tap).toHaveBeenCalledTimes(1),expect(e.tap).toHaveBeenCalledWith(s,i),expect(a).toHaveBeenCalledTimes(1),expect(a).toHaveBeenLastCalledWith(expect.any(Function),n),expect(e.release).not.toHaveBeenCalled(),await vi.advanceTimersByTimeAsync(n),await l,expect(e.release).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledWith(s,i)}),it("tapLong propagates error if tap() rejects (no release)",async()=>{vi.useFakeTimers();const a=new Error("tap failed");e.tap.mockRejectedValueOnce(a);const o=(0,t.tapLong)(e,s)(i);await expect(o).rejects.toThrow("tap failed"),expect(e.release).not.toHaveBeenCalled()}),it("tapLong propagates error if release() rejects",async()=>{vi.useFakeTimers();const a=new Error("release failed");e.release.mockRejectedValueOnce(a);const n=(0,t.tapLong)(e,s)(i),o=expect(n).rejects.toThrow("release failed");await Promise.resolve(),await vi.advanceTimersByTimeAsync(5e3),await o,expect(e.tap).toHaveBeenCalledTimes(1),expect(e.release).toHaveBeenCalledTimes(1)}),describe("enableBlindSigningSettings",()=>{it.each([["stax",{x:88,y:51}],["flex",{x:88,y:58}],["apex",{x:88,y:58}]])("taps the blind-signing toggle at the %s coordinates",async(a,n)=>{await(0,t.enableBlindSigningSettings)(e,a)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(a,n)}),it("falls back to default coordinates for an unknown device key",async()=>{const a="unknown";await(0,t.enableBlindSigningSettings)(e,a)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(a,{x:88,y:51})})}),describe("fixed-coordinate taps",()=>{it.each([["reject",t.reject,{x:20,y:90}],["navigateNext",t.navigateNext,{x:90,y:90}],["navigatePrevious",t.navigatePrevious,{x:45,y:90}],["mainButton",t.mainButton,{x:50,y:80}],["secondaryButton",t.secondaryButton,{x:50,y:90}],["enterMenu",t.enterMenu,{x:85,y:8}],["exitMenu",t.exitMenu,{x:10,y:4}],["continueToBlindSigning",t.continueToBlindSigning,{x:50,y:94}],["acceptBlindSigning",t.acceptBlindSigning,{x:50,y:94}]])("%s taps %o",async(a,n,o)=>{await n(e,s)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(s,o)})}),describe("sign",()=>{const a={x:85,y:80};it("holds the sign button for the default 5s",async()=>{vi.useFakeTimers();const n=vi.spyOn(globalThis,"setTimeout"),o=(0,t.sign)(e,s)();await Promise.resolve(),expect(e.tap).toHaveBeenCalledWith(s,a),expect(n).toHaveBeenLastCalledWith(expect.any(Function),5e3),await vi.advanceTimersByTimeAsync(5e3),await o,expect(e.release).toHaveBeenCalledWith(s,a)}),it("holds the sign button for the provided delay",async()=>{vi.useFakeTimers();const n=vi.spyOn(globalThis,"setTimeout"),o=250,l=(0,t.sign)(e,s)(o);await Promise.resolve(),expect(n).toHaveBeenLastCalledWith(expect.any(Function),o),await vi.advanceTimersByTimeAsync(o),await l,expect(e.release).toHaveBeenCalledTimes(1)})}),describe("confirmAddressBookReview",()=>{it.each([["stax",{x:50,y:77}],["flex",{x:50,y:72}]])("taps the Confirm button at the %s coordinates",async(a,n)=>{await(0,t.confirmAddressBookReview)(e,a)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(a,n)}),it("falls back to Flex coordinates for an unmeasured device key",async()=>{const a="apex";await(0,t.confirmAddressBookReview)(e,a)(),expect(e.tapAndRelease).toHaveBeenCalledTimes(1),expect(e.tapAndRelease).toHaveBeenCalledWith(a,{x:50,y:72})})})});
|
|
2
2
|
//# sourceMappingURL=touchUseCases.test.js.map
|