@gruu6y/page-clean-login 0.2.9 → 0.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/account-browser.mjs +459 -0
- package/lib/account-exit.mjs +604 -0
- package/lib/account-proxies.mjs +376 -36
- package/lib/agent-cli.mjs +22 -0
- package/lib/agent-surface.mjs +41 -2
- package/lib/browser-launcher.mjs +142 -36
- package/lib/renew-hosting.mjs +90 -38
- package/lib/server.mjs +247 -83
- package/lib/signin-flow.mjs +51 -25
- package/package.json +1 -1
- package/ui/account-view.js +178 -6
- package/ui/app.js +422 -2
- package/ui/index.html +5 -0
- package/ui/style.css +33 -0
package/lib/agent-surface.mjs
CHANGED
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
// request block inside the service until the job settles (or a bound elapses)
|
|
21
21
|
// and answer once.
|
|
22
22
|
|
|
23
|
+
import { exitDisplayUrl } from "./account-proxies.mjs";
|
|
24
|
+
|
|
23
25
|
// The longest a single request may block. A caller can ask for more; the
|
|
24
26
|
// service clamps to this so one request cannot hold a connection open
|
|
25
27
|
// indefinitely.
|
|
@@ -55,6 +57,9 @@ export const AGENT_COMMANDS = Object.freeze([
|
|
|
55
57
|
Object.freeze({ command: "proxies", http: "GET /api/agent", args: "", summary: "Stored proxies, compact, without credentials." }),
|
|
56
58
|
Object.freeze({ command: "proxies import", http: "POST /api/proxies/bulk", args: "[--file <path> | <text>] [--type T] [--prefix P]", summary: "Bulk import proxies from text lines." }),
|
|
57
59
|
Object.freeze({ command: "accounts", http: "GET /api/agent", args: "", summary: "Known accounts and whether each is signed in." }),
|
|
60
|
+
Object.freeze({ command: "accounts browser", http: "GET /api/accounts/:provider/:key/browser", args: "<provider> <key>", summary: "Status of one account's fingerprint browser." }),
|
|
61
|
+
Object.freeze({ command: "accounts browser open", http: "POST /api/accounts/:provider/:key/browser", args: "<provider> <key> [--target <url>]", summary: "Open one account's fingerprint browser." }),
|
|
62
|
+
Object.freeze({ command: "accounts browser close", http: "DELETE /api/accounts/:provider/:key/browser", args: "<provider> <key>", summary: "Close one account's fingerprint browser." }),
|
|
58
63
|
Object.freeze({ command: "signin start", http: "POST /api/signin", args: "--provider <id> [--proxy <id>] [--method <label>] [--input k=v]... [--single] [--wait ms]", summary: "Start a sign-in, optionally waiting until it settles." }),
|
|
59
64
|
Object.freeze({ command: "signin status", http: "GET /api/signin?wait=ms", args: "[--wait ms]", summary: "The current sign-in flow." }),
|
|
60
65
|
Object.freeze({ command: "signin code", http: "POST /api/signin/code", args: "<code>", summary: "Hand a one-time code back to a waiting flow." }),
|
|
@@ -182,9 +187,41 @@ export function compactProxy(proxy) {
|
|
|
182
187
|
};
|
|
183
188
|
}
|
|
184
189
|
|
|
185
|
-
//
|
|
186
|
-
//
|
|
190
|
+
// Credential-free projection of an account's current effective exit.
|
|
191
|
+
// `displayUrl` is re-sanitized through `exitDisplayUrl` so credentials can
|
|
192
|
+
// never slip into `/api/agent` or CLI output.
|
|
193
|
+
function compactExit(exit) {
|
|
194
|
+
if (!exit || typeof exit !== "object") return null;
|
|
195
|
+
const displayUrl = exitDisplayUrl(exit.displayUrl);
|
|
196
|
+
return {
|
|
197
|
+
mode:
|
|
198
|
+
exit.mode === "inherit"
|
|
199
|
+
? "inherit"
|
|
200
|
+
: exit.custom || (typeof exit.proxyId === "string" && exit.proxyId)
|
|
201
|
+
? "custom"
|
|
202
|
+
: "direct",
|
|
203
|
+
proxyId: typeof exit.proxyId === "string" && exit.proxyId ? exit.proxyId : null,
|
|
204
|
+
proxyName: typeof exit.proxyName === "string" ? exit.proxyName : "",
|
|
205
|
+
region: typeof exit.region === "string" ? exit.region : "",
|
|
206
|
+
type: typeof exit.type === "string" && exit.type ? exit.type : null,
|
|
207
|
+
...(exit.custom ? { custom: true } : {}),
|
|
208
|
+
...(displayUrl ? { displayUrl } : {}),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// One account, compact: identity, whether it is signed in, its note, its
|
|
213
|
+
// current credential-free exit (when present), and its standalone browser
|
|
214
|
+
// status (when open). No path, no fingerprint detail, no history arrays.
|
|
187
215
|
export function compactAccount(account) {
|
|
216
|
+
const exit = compactExit(account?.exit);
|
|
217
|
+
const browser =
|
|
218
|
+
account?.browser?.open === true
|
|
219
|
+
? {
|
|
220
|
+
open: true,
|
|
221
|
+
openedAt: account.browser.openedAt ?? null,
|
|
222
|
+
exitChanged: Boolean(account.browser.exitChanged),
|
|
223
|
+
}
|
|
224
|
+
: null;
|
|
188
225
|
return {
|
|
189
226
|
provider: account?.provider ?? "",
|
|
190
227
|
key: account?.key ?? "",
|
|
@@ -194,6 +231,8 @@ export function compactAccount(account) {
|
|
|
194
231
|
accountId: account?.accountId ?? null,
|
|
195
232
|
note: account?.note ?? "",
|
|
196
233
|
lastCheckedAt: account?.lastCheck?.at ?? null,
|
|
234
|
+
...(exit ? { exit } : {}),
|
|
235
|
+
...(browser ? { browser } : {}),
|
|
197
236
|
};
|
|
198
237
|
}
|
|
199
238
|
|
package/lib/browser-launcher.mjs
CHANGED
|
@@ -196,18 +196,67 @@ async function defaultCheckExecutable(executablePath) {
|
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
|
|
199
|
+
const ACCOUNT_PURPOSE = "account";
|
|
200
|
+
const BLANK_URL = "about:blank";
|
|
201
|
+
|
|
202
|
+
function normalizePurpose(purpose) {
|
|
203
|
+
return purpose === ACCOUNT_PURPOSE ? ACCOUNT_PURPOSE : "signin";
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function normalizeLaunchUrl(url, purpose) {
|
|
207
|
+
if (purpose !== ACCOUNT_PURPOSE) {
|
|
208
|
+
if (typeof url !== "string" || !url) {
|
|
209
|
+
throw new SignInBrowserError("url_missing", "The sign-in method returned no URL.", 502);
|
|
210
|
+
}
|
|
211
|
+
return url;
|
|
212
|
+
}
|
|
213
|
+
if (url === undefined || url === null) return BLANK_URL;
|
|
214
|
+
if (typeof url !== "string") {
|
|
215
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL must be a string.", 400);
|
|
216
|
+
}
|
|
217
|
+
const trimmed = url.trim();
|
|
218
|
+
if (!trimmed || trimmed.toLowerCase() === BLANK_URL) return BLANK_URL;
|
|
219
|
+
if (/[\u0000-\u001f\u007f]/.test(trimmed)) {
|
|
220
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL is invalid.", 400);
|
|
221
|
+
}
|
|
222
|
+
let parsed;
|
|
223
|
+
try {
|
|
224
|
+
parsed = new URL(trimmed);
|
|
225
|
+
} catch {
|
|
226
|
+
throw new SignInBrowserError("invalid_url", "The account browser URL is invalid.", 400);
|
|
227
|
+
}
|
|
228
|
+
if ((parsed.protocol !== "http:" && parsed.protocol !== "https:") || !parsed.hostname) {
|
|
229
|
+
throw new SignInBrowserError(
|
|
230
|
+
"invalid_url",
|
|
231
|
+
"The account browser only opens http:, https:, or about:blank URLs.",
|
|
232
|
+
400,
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
if (parsed.username || parsed.password) {
|
|
236
|
+
throw new SignInBrowserError(
|
|
237
|
+
"invalid_url",
|
|
238
|
+
"The account browser URL must not contain embedded credentials.",
|
|
239
|
+
400,
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
return parsed.href;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function assertExecutable(executablePath, check, { isAccount = false } = {}) {
|
|
246
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
200
247
|
if (typeof executablePath !== "string" || !executablePath) {
|
|
201
248
|
throw new SignInBrowserError(
|
|
202
249
|
"executable_missing",
|
|
203
|
-
|
|
250
|
+
`The ${browserLabel} is not installed; prepare it on the Providers page first.`,
|
|
204
251
|
503,
|
|
205
252
|
);
|
|
206
253
|
}
|
|
207
254
|
if (!(await check(executablePath))) {
|
|
208
255
|
throw new SignInBrowserError(
|
|
209
256
|
"executable_missing",
|
|
210
|
-
|
|
257
|
+
isAccount
|
|
258
|
+
? "The account browser executable was not found; prepare it on the Providers page first."
|
|
259
|
+
: `The ${browserLabel} executable was not found at ${executablePath}.`,
|
|
211
260
|
503,
|
|
212
261
|
);
|
|
213
262
|
}
|
|
@@ -224,19 +273,21 @@ export async function openSignInBrowser({
|
|
|
224
273
|
modelDir,
|
|
225
274
|
headless = false,
|
|
226
275
|
navTimeoutMs = DEFAULT_NAVIGATION_TIMEOUT_MS,
|
|
276
|
+
purpose = "signin",
|
|
227
277
|
deps = {},
|
|
228
278
|
} = {}) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
279
|
+
const normalizedPurpose = normalizePurpose(purpose);
|
|
280
|
+
const isAccount = normalizedPurpose === ACCOUNT_PURPOSE;
|
|
281
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
282
|
+
const targetUrl = normalizeLaunchUrl(url, normalizedPurpose);
|
|
232
283
|
if (!profileDir) {
|
|
233
284
|
throw new SignInBrowserError("profile_missing", "The account has no browser profile directory.", 500);
|
|
234
285
|
}
|
|
235
286
|
const navigationTimeoutMs = normalizeNavTimeoutMs(navTimeoutMs);
|
|
236
|
-
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable);
|
|
287
|
+
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable, { isAccount });
|
|
237
288
|
await mkdir(profileDir, { recursive: true, mode: 0o700 });
|
|
238
289
|
|
|
239
|
-
const input = buildLaunchInput({ url, profileDir, identity, proxy, modelDir, headless });
|
|
290
|
+
const input = buildLaunchInput({ url: targetUrl, profileDir, identity, proxy, modelDir, headless });
|
|
240
291
|
// fpgen resolves its model directory as `configuredDir || FPGEN_DATA_DIR ||
|
|
241
292
|
// userCacheDir("fpgen")`, with one module-level `configuredDir`. Setting the
|
|
242
293
|
// correctly named FPGEN_DATA_DIR here is only a fallback: importing camoufox
|
|
@@ -250,7 +301,9 @@ export async function openSignInBrowser({
|
|
|
250
301
|
} catch (error) {
|
|
251
302
|
throw new SignInBrowserError(
|
|
252
303
|
"runtime_missing",
|
|
253
|
-
|
|
304
|
+
isAccount
|
|
305
|
+
? "The account browser runtime could not be loaded."
|
|
306
|
+
: `The ${browserLabel} runtime could not be loaded: ${String(error?.message ?? error)}`,
|
|
254
307
|
503,
|
|
255
308
|
);
|
|
256
309
|
}
|
|
@@ -266,7 +319,9 @@ export async function openSignInBrowser({
|
|
|
266
319
|
} catch (error) {
|
|
267
320
|
throw new SignInBrowserError(
|
|
268
321
|
"runtime_missing",
|
|
269
|
-
|
|
322
|
+
isAccount
|
|
323
|
+
? "The fingerprint runtime could not be loaded."
|
|
324
|
+
: `The fingerprint runtime could not be loaded: ${String(error?.message ?? error)}`,
|
|
270
325
|
503,
|
|
271
326
|
);
|
|
272
327
|
}
|
|
@@ -277,11 +332,14 @@ export async function openSignInBrowser({
|
|
|
277
332
|
} catch (error) {
|
|
278
333
|
throw new SignInBrowserError(
|
|
279
334
|
"runtime_missing",
|
|
280
|
-
|
|
335
|
+
isAccount
|
|
336
|
+
? "The browser automation runtime could not be loaded."
|
|
337
|
+
: `playwright-core could not be loaded: ${String(error?.message ?? error)}`,
|
|
281
338
|
503,
|
|
282
339
|
);
|
|
283
340
|
}
|
|
284
341
|
|
|
342
|
+
const shouldNavigate = !isAccount || targetUrl !== BLANK_URL;
|
|
285
343
|
let context;
|
|
286
344
|
let page;
|
|
287
345
|
try {
|
|
@@ -301,8 +359,8 @@ export async function openSignInBrowser({
|
|
|
301
359
|
headless: Boolean(headless),
|
|
302
360
|
});
|
|
303
361
|
page = context.pages?.()[0] ?? (await context.newPage());
|
|
304
|
-
if (!page || typeof page.goto !== "function") {
|
|
305
|
-
throw new Error(
|
|
362
|
+
if (!page || (shouldNavigate && typeof page.goto !== "function")) {
|
|
363
|
+
throw new Error(`The ${browserLabel} opened no page.`);
|
|
306
364
|
}
|
|
307
365
|
} catch (error) {
|
|
308
366
|
try {
|
|
@@ -312,26 +370,34 @@ export async function openSignInBrowser({
|
|
|
312
370
|
}
|
|
313
371
|
throw new SignInBrowserError(
|
|
314
372
|
"launch_failed",
|
|
315
|
-
|
|
373
|
+
isAccount
|
|
374
|
+
? "The account browser could not be opened."
|
|
375
|
+
: `The ${browserLabel} could not be opened: ${String(error?.message ?? error)}`,
|
|
316
376
|
502,
|
|
317
377
|
);
|
|
318
378
|
}
|
|
319
379
|
|
|
320
380
|
// Navigation is a separate phase: once the browser and page exist, a slow
|
|
321
381
|
// page must not be reported as a failed launch or close the user's window.
|
|
382
|
+
// For account browsers opening on `about:blank`, skip navigation altogether
|
|
383
|
+
// to avoid unnecessary network traffic or timeouts.
|
|
322
384
|
let navigationError = null;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
385
|
+
if (shouldNavigate) {
|
|
386
|
+
try {
|
|
387
|
+
await page.goto(targetUrl, { waitUntil: NAVIGATION_WAIT_UNTIL, timeout: navigationTimeoutMs });
|
|
388
|
+
} catch (error) {
|
|
389
|
+
const seconds = Math.ceil(navigationTimeoutMs / 1000);
|
|
390
|
+
navigationError = new SignInBrowserError(
|
|
391
|
+
NAVIGATION_ERROR_CODE,
|
|
392
|
+
isAccount
|
|
393
|
+
? `The account browser is open, but the page did not finish loading within ${seconds} seconds. You can continue using the open window.`
|
|
394
|
+
: `The login browser is open, but the page did not finish loading within ${seconds} seconds. You can still complete the sign-in in the open window.`,
|
|
395
|
+
NAVIGATION_STATUS,
|
|
396
|
+
);
|
|
397
|
+
navigationError.timeoutMs = navigationTimeoutMs;
|
|
398
|
+
navigationError.waitUntil = NAVIGATION_WAIT_UNTIL;
|
|
399
|
+
navigationError.detail = String(error?.message ?? error);
|
|
400
|
+
}
|
|
335
401
|
}
|
|
336
402
|
|
|
337
403
|
let closed = false;
|
|
@@ -366,17 +432,19 @@ export async function launchSignInBrowser({
|
|
|
366
432
|
// A hosted renewal has no user watching it: the same profile, the same
|
|
367
433
|
// pinned fingerprint and the same exit, but no window on the desktop.
|
|
368
434
|
headless = false,
|
|
435
|
+
purpose = "signin",
|
|
369
436
|
env = process.env,
|
|
370
437
|
platform = process.platform,
|
|
371
438
|
deps = {},
|
|
372
439
|
} = {}) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
440
|
+
const normalizedPurpose = normalizePurpose(purpose);
|
|
441
|
+
const isAccount = normalizedPurpose === ACCOUNT_PURPOSE;
|
|
442
|
+
const browserLabel = isAccount ? "account browser" : "login browser";
|
|
443
|
+
const targetUrl = normalizeLaunchUrl(url, normalizedPurpose);
|
|
376
444
|
if (!profileDir) {
|
|
377
445
|
throw new SignInBrowserError("profile_missing", "The account has no browser profile directory.", 500);
|
|
378
446
|
}
|
|
379
|
-
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable);
|
|
447
|
+
await assertExecutable(executablePath, deps.checkExecutable ?? defaultCheckExecutable, { isAccount });
|
|
380
448
|
await mkdir(profileDir, { recursive: true, mode: 0o700 });
|
|
381
449
|
|
|
382
450
|
const resolvedModelDir = modelDir ?? fingerprintModelDir(env);
|
|
@@ -386,13 +454,14 @@ export async function launchSignInBrowser({
|
|
|
386
454
|
// inside the profile directory and has to be cleaned up on every path.
|
|
387
455
|
const payload = JSON.stringify({
|
|
388
456
|
executablePath,
|
|
389
|
-
url,
|
|
457
|
+
url: targetUrl,
|
|
390
458
|
profileDir,
|
|
391
459
|
identity,
|
|
392
460
|
proxy,
|
|
393
461
|
modelDir: resolvedModelDir,
|
|
394
462
|
navTimeoutMs: navigationTimeoutMs,
|
|
395
463
|
headless: Boolean(headless),
|
|
464
|
+
purpose: normalizedPurpose,
|
|
396
465
|
});
|
|
397
466
|
|
|
398
467
|
const spawnHost = deps.fork ?? fork;
|
|
@@ -412,7 +481,9 @@ export async function launchSignInBrowser({
|
|
|
412
481
|
} catch (error) {
|
|
413
482
|
throw new SignInBrowserError(
|
|
414
483
|
"launch_failed",
|
|
415
|
-
|
|
484
|
+
isAccount
|
|
485
|
+
? "The account browser host could not be started."
|
|
486
|
+
: `The ${browserLabel} host could not be started: ${String(error?.message ?? error)}`,
|
|
416
487
|
502,
|
|
417
488
|
);
|
|
418
489
|
}
|
|
@@ -432,7 +503,7 @@ export async function launchSignInBrowser({
|
|
|
432
503
|
fn(value);
|
|
433
504
|
};
|
|
434
505
|
const timer = setTimeout(
|
|
435
|
-
() => done(reject, new SignInBrowserError("launch_timeout",
|
|
506
|
+
() => done(reject, new SignInBrowserError("launch_timeout", `The ${browserLabel} did not open in time.`, 504)),
|
|
436
507
|
timeoutMs,
|
|
437
508
|
);
|
|
438
509
|
child.on("message", (message) => {
|
|
@@ -440,15 +511,50 @@ export async function launchSignInBrowser({
|
|
|
440
511
|
warning = message.warning ?? null;
|
|
441
512
|
done(resolve);
|
|
442
513
|
} else if (message?.type === "error") {
|
|
443
|
-
|
|
514
|
+
const code = typeof message.code === "string" && message.code ? message.code : "launch_failed";
|
|
515
|
+
let safeMessage = String(message.message ?? `The ${browserLabel} failed to open.`);
|
|
516
|
+
if (isAccount) {
|
|
517
|
+
if (code === "executable_missing") {
|
|
518
|
+
safeMessage =
|
|
519
|
+
"The account browser executable was not found; prepare it on the Providers page first.";
|
|
520
|
+
} else if (code === "runtime_missing") {
|
|
521
|
+
safeMessage = "The account browser runtime could not be loaded.";
|
|
522
|
+
} else if (code === "invalid_url") {
|
|
523
|
+
safeMessage = "The account browser only opens http:, https:, or about:blank URLs.";
|
|
524
|
+
} else if (code === "launch_timeout") {
|
|
525
|
+
safeMessage = "The account browser did not open in time.";
|
|
526
|
+
} else {
|
|
527
|
+
safeMessage = "The account browser could not be opened.";
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
done(
|
|
531
|
+
reject,
|
|
532
|
+
new SignInBrowserError(code, safeMessage, message.status ?? 502),
|
|
533
|
+
);
|
|
444
534
|
}
|
|
445
535
|
});
|
|
446
536
|
child.once("error", (error) =>
|
|
447
|
-
done(
|
|
537
|
+
done(
|
|
538
|
+
reject,
|
|
539
|
+
new SignInBrowserError(
|
|
540
|
+
"launch_failed",
|
|
541
|
+
isAccount
|
|
542
|
+
? "The account browser host failed."
|
|
543
|
+
: `The ${browserLabel} host failed: ${String(error?.message ?? error)}`,
|
|
544
|
+
502,
|
|
545
|
+
),
|
|
546
|
+
),
|
|
448
547
|
);
|
|
449
548
|
child.once("exit", (code) => {
|
|
450
549
|
if (!settled) {
|
|
451
|
-
done(
|
|
550
|
+
done(
|
|
551
|
+
reject,
|
|
552
|
+
new SignInBrowserError(
|
|
553
|
+
"launch_failed",
|
|
554
|
+
`The ${browserLabel} host exited before it opened the browser (code ${code}).`,
|
|
555
|
+
502,
|
|
556
|
+
),
|
|
557
|
+
);
|
|
452
558
|
}
|
|
453
559
|
});
|
|
454
560
|
});
|
package/lib/renew-hosting.mjs
CHANGED
|
@@ -40,6 +40,7 @@ import { readAuthKeys } from "./account-keys.mjs";
|
|
|
40
40
|
import { readNativeLoginKeys } from "./magpie-logins.mjs";
|
|
41
41
|
import { readAuthEntries, readAuthExpiries } from "./signin-writeback.mjs";
|
|
42
42
|
import { SIGNIN_TERMINAL_STATES } from "./signin-flow.mjs";
|
|
43
|
+
import { resolveEffectiveAccountExit } from "./account-exit.mjs";
|
|
43
44
|
|
|
44
45
|
export const RENEW_HOSTING_FILE = "renew-hosting.json";
|
|
45
46
|
export const RENEW_HOSTING_VERSION = 1;
|
|
@@ -103,6 +104,8 @@ const NEEDS_USER = new Set([
|
|
|
103
104
|
"identity_missing",
|
|
104
105
|
"exit_unknown",
|
|
105
106
|
"exit_missing",
|
|
107
|
+
"providers_invalid",
|
|
108
|
+
"invalid_exit_url",
|
|
106
109
|
"no_expiry",
|
|
107
110
|
"not_renewable",
|
|
108
111
|
]);
|
|
@@ -212,6 +215,8 @@ export function createRenewHosting(options = {}) {
|
|
|
212
215
|
signIn = null,
|
|
213
216
|
store = null,
|
|
214
217
|
identityCheck = null,
|
|
218
|
+
accountBrowser = null,
|
|
219
|
+
isAccountBrowserOpen = null,
|
|
215
220
|
now = () => Date.now(),
|
|
216
221
|
tickMs = HOSTING_TICK_MS,
|
|
217
222
|
leadMs = HOSTING_LEAD_MS,
|
|
@@ -285,14 +290,54 @@ export function createRenewHosting(options = {}) {
|
|
|
285
290
|
}
|
|
286
291
|
}
|
|
287
292
|
|
|
288
|
-
// The exit hosting will use is
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
// exit
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
// The exit hosting will use is resolved through magpie's providers.json as
|
|
294
|
+
// the single source of truth (supporting custom stored nodes, external URLs,
|
|
295
|
+
// direct, and inherit -> provider.proxy), falling back to the ledger
|
|
296
|
+
// (`exit`, then `lastLogin`) only when providers.json cannot authoritatively
|
|
297
|
+
// answer. Corrupt providers.json or an invalid/missing exit fails explicitly
|
|
298
|
+
// rather than degrading to direct.
|
|
299
|
+
async function resolveExit(provider, key, meta) {
|
|
300
|
+
const resolved = await resolveEffectiveAccountExit({
|
|
301
|
+
env,
|
|
302
|
+
provider,
|
|
303
|
+
key,
|
|
304
|
+
meta,
|
|
305
|
+
store,
|
|
306
|
+
authEntries: readEntries(env),
|
|
307
|
+
fallbackToLedger: true,
|
|
308
|
+
});
|
|
309
|
+
if (!resolved.ok) {
|
|
310
|
+
if (resolved.reason === "providers_invalid" || resolved.reason === "providers_unreadable") {
|
|
311
|
+
return {
|
|
312
|
+
ok: false,
|
|
313
|
+
code: resolved.reason,
|
|
314
|
+
status: 409,
|
|
315
|
+
message:
|
|
316
|
+
resolved.reason === "providers_invalid"
|
|
317
|
+
? "magpie's providers.json is malformed, so the account exit cannot be resolved."
|
|
318
|
+
: "magpie's providers.json could not be read, so the account exit cannot be resolved.",
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (resolved.reason === "invalid_exit_url") {
|
|
322
|
+
return {
|
|
323
|
+
ok: false,
|
|
324
|
+
code: "invalid_exit_url",
|
|
325
|
+
status: 409,
|
|
326
|
+
message:
|
|
327
|
+
"The proxy address configured in magpie's providers.json is invalid; fix it before running hosted renewal.",
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
if (resolved.reason === "exit_missing") {
|
|
331
|
+
return {
|
|
332
|
+
ok: false,
|
|
333
|
+
code: "exit_missing",
|
|
334
|
+
status: 409,
|
|
335
|
+
message:
|
|
336
|
+
!store || typeof store.get !== "function"
|
|
337
|
+
? "The proxy list is unavailable, so the login exit cannot be resolved."
|
|
338
|
+
: "The exit this account logged in through is no longer in the proxy list. Add it back, or sign in again through another exit.",
|
|
339
|
+
};
|
|
340
|
+
}
|
|
296
341
|
return {
|
|
297
342
|
ok: false,
|
|
298
343
|
code: "exit_unknown",
|
|
@@ -301,37 +346,13 @@ export function createRenewHosting(options = {}) {
|
|
|
301
346
|
"This account has no recorded login exit. Sign in once more so the exit is recorded, then enable hosting.",
|
|
302
347
|
};
|
|
303
348
|
}
|
|
304
|
-
const proxyId = typeof picked.proxyId === "string" && picked.proxyId ? picked.proxyId : null;
|
|
305
|
-
if (!proxyId) return { ok: true, proxy: null, proxyMeta: null };
|
|
306
|
-
if (!store || typeof store.get !== "function") {
|
|
307
|
-
return {
|
|
308
|
-
ok: false,
|
|
309
|
-
code: "exit_missing",
|
|
310
|
-
status: 409,
|
|
311
|
-
message: "The proxy list is unavailable, so the login exit cannot be resolved.",
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
const stored = await store.get(proxyId);
|
|
315
|
-
if (!stored) {
|
|
316
|
-
return {
|
|
317
|
-
ok: false,
|
|
318
|
-
code: "exit_missing",
|
|
319
|
-
status: 409,
|
|
320
|
-
message:
|
|
321
|
-
"The exit this account logged in through is no longer in the proxy list. Add it back, or sign in again through another exit.",
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
349
|
return {
|
|
325
350
|
ok: true,
|
|
326
|
-
proxy:
|
|
327
|
-
//
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
name: typeof stored.name === "string" ? stored.name : "",
|
|
332
|
-
region: typeof stored.region === "string" ? stored.region : "",
|
|
333
|
-
type: typeof stored.type === "string" ? stored.type : null,
|
|
334
|
-
},
|
|
351
|
+
proxy: resolved.proxy,
|
|
352
|
+
// Strictly credential-free four-field whitelist (or null for direct):
|
|
353
|
+
// username, password and raw URLs never leave this function into
|
|
354
|
+
// account.json or renew-hosting.json.
|
|
355
|
+
proxyMeta: resolved.proxyMeta,
|
|
335
356
|
};
|
|
336
357
|
}
|
|
337
358
|
|
|
@@ -391,7 +412,7 @@ export function createRenewHosting(options = {}) {
|
|
|
391
412
|
message: "This account has no pinned fingerprint; sign in through clean-login first.",
|
|
392
413
|
};
|
|
393
414
|
}
|
|
394
|
-
const exit = await resolveExit(meta);
|
|
415
|
+
const exit = await resolveExit(provider, key, meta);
|
|
395
416
|
if (!exit.ok) return exit;
|
|
396
417
|
return { ok: true, dir, meta, expiresAt, proxy: exit.proxy, proxyMeta: exit.proxyMeta };
|
|
397
418
|
}
|
|
@@ -446,6 +467,18 @@ export function createRenewHosting(options = {}) {
|
|
|
446
467
|
return Boolean(identityCheck.status()?.browserOpen);
|
|
447
468
|
}
|
|
448
469
|
|
|
470
|
+
// An account's standalone fingerprint browser holds the same `profile/` dir,
|
|
471
|
+
// so hosted renewal must never launch on top of it.
|
|
472
|
+
function accountBrowserOpen(provider, key) {
|
|
473
|
+
if (typeof isAccountBrowserOpen === "function") {
|
|
474
|
+
return Boolean(isAccountBrowserOpen(provider, key));
|
|
475
|
+
}
|
|
476
|
+
if (accountBrowser && typeof accountBrowser.isOpen === "function") {
|
|
477
|
+
return Boolean(accountBrowser.isOpen(provider, key));
|
|
478
|
+
}
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
|
|
449
482
|
async function record(entry, attempt) {
|
|
450
483
|
entry.lastAt = attempt.at;
|
|
451
484
|
entry.lastOutcome = attempt.outcome;
|
|
@@ -611,6 +644,13 @@ export function createRenewHosting(options = {}) {
|
|
|
611
644
|
// The one-at-a-time and sign-in exclusion guards still apply.
|
|
612
645
|
async function runNow(provider, key) {
|
|
613
646
|
assertAccount(provider, key);
|
|
647
|
+
if (accountBrowserOpen(provider, key)) {
|
|
648
|
+
throw new RenewHostingError(
|
|
649
|
+
"browser_open",
|
|
650
|
+
"Close this account's fingerprint browser before running hosted renewal.",
|
|
651
|
+
409,
|
|
652
|
+
);
|
|
653
|
+
}
|
|
614
654
|
if (startingRun || running || signInBusy() || identityCheckBusy()) {
|
|
615
655
|
throw new RenewHostingError("busy", "A sign-in is already running; try again when it finishes.", 409);
|
|
616
656
|
}
|
|
@@ -623,6 +663,13 @@ export function createRenewHosting(options = {}) {
|
|
|
623
663
|
}
|
|
624
664
|
const check = await eligibility(provider, key);
|
|
625
665
|
if (!check.ok) throw new RenewHostingError(check.code, check.message, check.status);
|
|
666
|
+
if (accountBrowserOpen(provider, key)) {
|
|
667
|
+
throw new RenewHostingError(
|
|
668
|
+
"browser_open",
|
|
669
|
+
"Close this account's fingerprint browser before running hosted renewal.",
|
|
670
|
+
409,
|
|
671
|
+
);
|
|
672
|
+
}
|
|
626
673
|
running = { provider: entry.provider, key: entry.key, startedAt: now(), manual: true };
|
|
627
674
|
void perform(entry, check, { manual: true });
|
|
628
675
|
return { ok: true, running: publicRunning() };
|
|
@@ -682,6 +729,10 @@ export function createRenewHosting(options = {}) {
|
|
|
682
729
|
if (at < expiresAt - lead) continue;
|
|
683
730
|
if (isFiniteNumber(entry.nextDueAt) && at < entry.nextDueAt) continue;
|
|
684
731
|
if (isFiniteNumber(entry.lastAt) && at - entry.lastAt < minGapMs) continue;
|
|
732
|
+
// Skip this due account while its standalone fingerprint browser is
|
|
733
|
+
// open: no fail-streak penalty, no pause, and other due accounts in the
|
|
734
|
+
// loop still proceed.
|
|
735
|
+
if (accountBrowserOpen(entry.provider, entry.key)) continue;
|
|
685
736
|
if (dirty) {
|
|
686
737
|
await save();
|
|
687
738
|
dirty = false;
|
|
@@ -691,6 +742,7 @@ export function createRenewHosting(options = {}) {
|
|
|
691
742
|
await record(entry, { at, outcome: "error", code: check.code, message: check.message });
|
|
692
743
|
continue;
|
|
693
744
|
}
|
|
745
|
+
if (accountBrowserOpen(entry.provider, entry.key)) continue;
|
|
694
746
|
await perform(entry, check, { manual: false });
|
|
695
747
|
return { ran: true, provider: entry.provider, key: entry.key };
|
|
696
748
|
}
|