@broberg/lens-daemon 0.1.67 → 0.1.68
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 +3 -3
- 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.68",
|
|
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,9 +15,9 @@
|
|
|
15
15
|
"sharp": "^0.35.5",
|
|
16
16
|
"turndown": "^7.2.4",
|
|
17
17
|
"zod": "^3.23.8",
|
|
18
|
-
"@broberg/lens-engine": "0.14.1",
|
|
19
18
|
"@broberg/lens-measure": "0.1.2",
|
|
20
|
-
"@broberg/lens-svg": "0.1.1"
|
|
19
|
+
"@broberg/lens-svg": "0.1.1",
|
|
20
|
+
"@broberg/lens-engine": "0.14.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@happy-dom/global-registrator": "^20.10.6",
|
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)}` } : {}),
|