@broberg/lens-daemon 0.1.51 → 0.1.53

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@broberg/lens-daemon",
3
- "version": "0.1.51",
3
+ "version": "0.1.53",
4
4
  "description": "The Lens module of the cardmem daemon (flows, critic, coverage, capture sessions, the /lens/* routes and the cardmem-lens MCP) as a package. The daemon mounts createLensRouter(deps) + createLensMcpRouter(deps). Bun runtime.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -15,8 +15,8 @@
15
15
  "sharp": "^0.35.5",
16
16
  "turndown": "^7.2.4",
17
17
  "zod": "^3.23.8",
18
- "@broberg/lens-svg": "0.1.1",
19
- "@broberg/lens-engine": "0.14.1"
18
+ "@broberg/lens-engine": "0.14.1",
19
+ "@broberg/lens-svg": "0.1.1"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@happy-dom/global-registrator": "^20.10.6",
@@ -0,0 +1,34 @@
1
+ // F010.11 — a one-time code field split into one box per character (Microsoft's
2
+ // «Enter your code»). Shared by fill-from-owner and fill-from-mail: the code is
3
+ // typed key by key from the first box and the page's own auto-advance moves focus.
4
+ import type { Locator } from 'playwright';
5
+
6
+ export async function isOneCharBox(loc: Locator): Promise<boolean> {
7
+ return loc.evaluate((el) => (el as HTMLInputElement).maxLength === 1).catch(() => false);
8
+ }
9
+
10
+ /** The joined value of the one-character boxes around `el`. */
11
+ function joinedBoxes(el: Element): string {
12
+ let group: Element | null = el.parentElement;
13
+ while (group && group.querySelectorAll('input').length < 2 && group.parentElement) group = group.parentElement;
14
+ return [...(group?.querySelectorAll('input') ?? [])]
15
+ .filter((i) => (i as HTMLInputElement).maxLength === 1)
16
+ .map((i) => (i as HTMLInputElement).value)
17
+ .join('');
18
+ }
19
+
20
+ /** Type `value` across the boxes and prove the joined boxes hold it. `failure`
21
+ * starts the error message; the value itself is never in it. */
22
+ export async function typeIntoBoxes(loc: Locator, value: string, failure: string, timeout: number): Promise<void> {
23
+ await loc.focus({ timeout });
24
+ await loc.pressSequentially(value, { timeout });
25
+ let got: string;
26
+ try {
27
+ got = await loc.evaluate(joinedBoxes);
28
+ } catch (err) {
29
+ // The last digit often submits the form; the page leaving is the code landing.
30
+ if (/Execution context was destroyed|Cannot find context|has been closed|detached/i.test(err instanceof Error ? err.message : String(err))) return;
31
+ throw err;
32
+ }
33
+ if (got !== value) throw new Error(`${failure} across the boxes, found ${got.length} (value withheld)`);
34
+ }
package/src/mail-fill.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  // spent by then, and hiding it would mean not photographing the form at all.
11
11
  import type { Locator } from 'playwright';
12
12
  import { fillAndVerify } from './fill.ts';
13
+ import { isOneCharBox, typeIntoBoxes } from './code-boxes.ts';
13
14
 
14
15
  export interface MailFrom {
15
16
  to: string;
@@ -112,6 +113,10 @@ export async function fillFromMail(
112
113
  ): Promise<void> {
113
114
  const { code, id } = await waitForMailCode(mf, since, source);
114
115
  consumed.push({ to: mailboxOf(mf.to), id });
116
+ if (code.length > 1 && (await isOneCharBox(loc))) {
117
+ await typeIntoBoxes(loc, code, `fill from mail did not land: expected a ${code.length}-character code`, timeout);
118
+ return;
119
+ }
115
120
  try {
116
121
  await fillAndVerify(loc, code, timeout);
117
122
  } catch {
package/src/owner-fill.ts CHANGED
@@ -13,6 +13,7 @@ import { homedir } from 'node:os';
13
13
  import { join } from 'node:path';
14
14
  import type { Locator } from 'playwright';
15
15
  import { fillAndVerify } from './fill.ts';
16
+ import { isOneCharBox, typeIntoBoxes } from './code-boxes.ts';
16
17
 
17
18
  export type OwnerKind = 'code' | 'password' | 'text';
18
19
 
@@ -87,9 +88,16 @@ export async function fillFromOwner(loc: Locator, of: OwnerFrom, fillTimeout: nu
87
88
  if (res.status === 'expired') throw new Error(`fill from owner: expired — no answer to «${of.question}» in time`);
88
89
  if (res.status === 'error') throw new Error(`fill from owner: ARS failed — ${res.reason}`);
89
90
  if (!res.answer) throw new Error('fill from owner: ARS answered with an empty value');
91
+ // F010.11 — a code field split into one box per character (Microsoft's «Enter your
92
+ // code»): type it key by key from the first box and let the page advance.
93
+ if (res.answer.length > 1 && (await isOneCharBox(loc))) {
94
+ await typeIntoBoxes(loc, res.answer, `fill from owner did not land: expected a ${res.answer.length}-character ${kind}`, fillTimeout);
95
+ return;
96
+ }
90
97
  try {
91
98
  await fillAndVerify(loc, res.answer, fillTimeout);
92
99
  } catch {
93
100
  throw new Error(`fill from owner did not land: expected a ${res.answer.length}-character ${kind} in the field (value withheld)`);
94
101
  }
95
102
  }
103
+