@broberg/lens-daemon 0.1.67 → 0.1.70
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 +2 -2
- package/src/flow.ts +11 -4
- package/src/profile-watch.ts +4 -2
- package/src/sign-in.ts +24 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@broberg/lens-daemon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.70",
|
|
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",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"turndown": "^7.2.4",
|
|
17
17
|
"zod": "^3.23.8",
|
|
18
18
|
"@broberg/lens-engine": "0.14.1",
|
|
19
|
-
"@broberg/lens-measure": "0.1.
|
|
19
|
+
"@broberg/lens-measure": "0.1.3",
|
|
20
20
|
"@broberg/lens-svg": "0.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
package/src/flow.ts
CHANGED
|
@@ -1347,6 +1347,15 @@ export const MANUSCRIPT_VERBS = [
|
|
|
1347
1347
|
'waitForPopup', 'waitForPopupClose', 'approve',
|
|
1348
1348
|
] as const;
|
|
1349
1349
|
|
|
1350
|
+
// F011.7 — `fill [x] mads` (no «=») used to fill the empty string and pass; the
|
|
1351
|
+
// flow then failed a step later on an assert that read as an app bug (fysio.work).
|
|
1352
|
+
// `fill [x] =` stays legal: an explicit empty value is a choice, a missing one a typo.
|
|
1353
|
+
function valueAfterEquals(s: string, verb: 'fill' | 'select'): string {
|
|
1354
|
+
const rest = s.replace(/^[^\]]*\]/, '');
|
|
1355
|
+
if (!rest.includes('=')) throw new Error(`${verb} step "${s}" needs "= value" (e.g. "${verb} [x] = mads"); without it the value would be empty.`);
|
|
1356
|
+
return rest.split('=').slice(1).join('=').trim();
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1350
1359
|
function parseManuscriptStep(s: string): FlowStep {
|
|
1351
1360
|
const testid = () => {
|
|
1352
1361
|
const m = s.match(/\[([^\]]+)\]/);
|
|
@@ -1401,12 +1410,10 @@ function parseManuscriptStep(s: string): FlowStep {
|
|
|
1401
1410
|
const kind = from[1]!.toLowerCase();
|
|
1402
1411
|
return { type: 'fill', testid: testid(), valueFrom: kind === 'file' ? { path: src } : kind === 'env' ? { env: src } : { vault: src } };
|
|
1403
1412
|
}
|
|
1404
|
-
|
|
1405
|
-
return { type: 'fill', testid: testid(), value: v };
|
|
1413
|
+
return { type: 'fill', testid: testid(), value: valueAfterEquals(s, 'fill') };
|
|
1406
1414
|
}
|
|
1407
1415
|
case 'select': {
|
|
1408
|
-
|
|
1409
|
-
return { type: 'select', testid: testid(), value: v };
|
|
1416
|
+
return { type: 'select', testid: testid(), value: valueAfterEquals(s, 'select') };
|
|
1410
1417
|
}
|
|
1411
1418
|
case 'clear': return { type: 'clear', testid: testid() };
|
|
1412
1419
|
case 'press': {
|
package/src/profile-watch.ts
CHANGED
|
@@ -79,7 +79,9 @@ export function setProfileNotifier(fn: Notifier | null): void {
|
|
|
79
79
|
* to signed_out only — a profile that stays signed out is silent, and a recovery
|
|
80
80
|
* followed by a new expiry is a new transition. `unknown` (in use, browser error)
|
|
81
81
|
* never notifies and never resets the memory of an earlier signed_out. */
|
|
82
|
-
|
|
82
|
+
/** `quiet` — record the state but tell nobody and start nothing: the caller already
|
|
83
|
+
* knows (a sign-in that just ran reports its own result). */
|
|
84
|
+
export async function checkProfile(name: string, look: Looker, now: () => Date = () => new Date(), opts: { quiet?: boolean } = {}): Promise<ProbeState> {
|
|
83
85
|
const probe = readProbe(name);
|
|
84
86
|
if (!probe) throw new Error(`browser profile "${name}" has no probe — set one with POST /lens/profiles/${name}/probe`);
|
|
85
87
|
const prev = readProbeState(name);
|
|
@@ -94,7 +96,7 @@ export async function checkProfile(name: string, look: Looker, now: () => Date =
|
|
|
94
96
|
// The memory of «he has been told» survives until the profile is seen signed in again.
|
|
95
97
|
const told = res.state !== 'signed_in' && prev?.state !== 'signed_in' ? prev?.notified_at : undefined;
|
|
96
98
|
if (told) next.notified_at = told;
|
|
97
|
-
if (res.state === 'signed_out' && !told && notifier) {
|
|
99
|
+
if (res.state === 'signed_out' && !told && notifier && !opts.quiet) {
|
|
98
100
|
try {
|
|
99
101
|
const renewing = !!(probe.recipe && renewer);
|
|
100
102
|
await notifier({ profile: name, url: probe.url, ...(res.reason ? { reason: res.reason } : {}), ...(renewing ? { renewing } : {}) });
|
package/src/sign-in.ts
CHANGED
|
@@ -27,16 +27,33 @@ const google = (account: string, passwordSecret: string): SignInRecipe => ({
|
|
|
27
27
|
base_url: 'https://accounts.google.com',
|
|
28
28
|
steps: [
|
|
29
29
|
{ type: 'goto', path: '/ServiceLogin?continue=https%3A%2F%2Fmyaccount.google.com%2F' },
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
// The address field is a text input, #identifierId — not type=email (measured 27 Oct).
|
|
31
|
+
{ type: 'conditional', selector: '#identifierId', present: true, timeout: WAIT, steps: [
|
|
32
|
+
{ type: 'fill', target: { css: '#identifierId' }, value: account },
|
|
32
33
|
{ type: 'click', target: { css: '#identifierNext' } },
|
|
33
34
|
] },
|
|
35
|
+
// An account with a passkey is asked for it first: «Try another way» → «Enter your password».
|
|
36
|
+
{ type: 'conditional', selector: 'button:has-text("Try another way")', present: true, timeout: WAIT, steps: [
|
|
37
|
+
{ type: 'click', target: { css: 'button:has-text("Try another way")' } },
|
|
38
|
+
] },
|
|
39
|
+
{ type: 'conditional', selector: '[role=link]:has-text("Enter your password")', present: true, timeout: WAIT, steps: [
|
|
40
|
+
{ type: 'click', target: { css: '[role=link]:has-text("Enter your password") >> nth=-1' } },
|
|
41
|
+
] },
|
|
34
42
|
{ type: 'conditional', selector: 'input[type=password][name=Passwd]', present: true, timeout: WAIT, steps: [
|
|
35
43
|
{ type: 'fill', target: { css: 'input[type=password][name=Passwd]' }, valueFrom: { vault: passwordSecret } },
|
|
36
44
|
{ type: 'click', target: { css: '#passwordNext' } },
|
|
37
45
|
] },
|
|
38
|
-
//
|
|
39
|
-
//
|
|
46
|
+
// After the password Google may offer a different second step first; the
|
|
47
|
+
// authenticator is picked from its list. A phone prompt alone leaves the code
|
|
48
|
+
// step skipped and the probe reports signed_out with where it stopped.
|
|
49
|
+
{ type: 'conditional', selector: 'input[name=totpPin]', present: false, timeout: 20_000, steps: [
|
|
50
|
+
{ type: 'conditional', selector: 'button:has-text("Try another way")', present: true, timeout: 5_000, steps: [
|
|
51
|
+
{ type: 'click', target: { css: 'button:has-text("Try another way")' } },
|
|
52
|
+
] },
|
|
53
|
+
{ type: 'conditional', selector: '[role=link]:has-text("Authenticator")', present: true, timeout: WAIT, steps: [
|
|
54
|
+
{ type: 'click', target: { css: '[role=link]:has-text("Authenticator") >> nth=-1' } },
|
|
55
|
+
] },
|
|
56
|
+
] },
|
|
40
57
|
{ type: 'conditional', selector: 'input[name=totpPin]', present: true, timeout: WAIT, steps: [
|
|
41
58
|
{ type: 'fill', target: { css: 'input[name=totpPin]' }, valueFrom: { owner: { question: `Google (${account}): koden fra Google Authenticator`, kind: 'code' } } },
|
|
42
59
|
{ type: 'click', target: { css: '#totpNext' } },
|
|
@@ -70,7 +87,9 @@ export async function signIn(
|
|
|
70
87
|
const r = await run({ name: `sign-in:${profile}`, base_url: recipe.base_url, mutates: true, browser: { channel, profile }, steps: recipe.steps }, process.env as never, {});
|
|
71
88
|
const failed = r.status !== 'pass' ? r.steps.find((s) => s.status === 'fail') : undefined;
|
|
72
89
|
if (!readProbe(profile)?.recipe) setProbe(profile, { ...recipe.probe, recipe: recipeName });
|
|
73
|
-
|
|
90
|
+
// Quiet: a sign-in reports its own result. A loud check here mailed the owner
|
|
91
|
+
// «expired» about a profile being signed in, and that mail started a second sign-in.
|
|
92
|
+
const state = await checkProfile(profile, look, undefined, { quiet: true });
|
|
74
93
|
return {
|
|
75
94
|
state: state.state,
|
|
76
95
|
...(failed ? { failed_step: `${failed.label}: ${String(failed.detail ?? r.reason ?? '').slice(0, 200)}` } : {}),
|