@gruu6y/page-clean-login 0.2.9 → 0.2.10
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-exit.mjs +604 -0
- package/lib/account-proxies.mjs +376 -36
- package/lib/agent-surface.mjs +29 -2
- package/lib/renew-hosting.mjs +57 -38
- package/lib/server.mjs +89 -77
- package/lib/signin-flow.mjs +39 -25
- package/package.json +1 -1
- package/ui/account-view.js +38 -5
- package/ui/app.js +19 -2
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
|
]);
|
|
@@ -285,14 +288,54 @@ export function createRenewHosting(options = {}) {
|
|
|
285
288
|
}
|
|
286
289
|
}
|
|
287
290
|
|
|
288
|
-
// The exit hosting will use is
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
// exit
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
291
|
+
// The exit hosting will use is resolved through magpie's providers.json as
|
|
292
|
+
// the single source of truth (supporting custom stored nodes, external URLs,
|
|
293
|
+
// direct, and inherit -> provider.proxy), falling back to the ledger
|
|
294
|
+
// (`exit`, then `lastLogin`) only when providers.json cannot authoritatively
|
|
295
|
+
// answer. Corrupt providers.json or an invalid/missing exit fails explicitly
|
|
296
|
+
// rather than degrading to direct.
|
|
297
|
+
async function resolveExit(provider, key, meta) {
|
|
298
|
+
const resolved = await resolveEffectiveAccountExit({
|
|
299
|
+
env,
|
|
300
|
+
provider,
|
|
301
|
+
key,
|
|
302
|
+
meta,
|
|
303
|
+
store,
|
|
304
|
+
authEntries: readEntries(env),
|
|
305
|
+
fallbackToLedger: true,
|
|
306
|
+
});
|
|
307
|
+
if (!resolved.ok) {
|
|
308
|
+
if (resolved.reason === "providers_invalid" || resolved.reason === "providers_unreadable") {
|
|
309
|
+
return {
|
|
310
|
+
ok: false,
|
|
311
|
+
code: resolved.reason,
|
|
312
|
+
status: 409,
|
|
313
|
+
message:
|
|
314
|
+
resolved.reason === "providers_invalid"
|
|
315
|
+
? "magpie's providers.json is malformed, so the account exit cannot be resolved."
|
|
316
|
+
: "magpie's providers.json could not be read, so the account exit cannot be resolved.",
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
if (resolved.reason === "invalid_exit_url") {
|
|
320
|
+
return {
|
|
321
|
+
ok: false,
|
|
322
|
+
code: "invalid_exit_url",
|
|
323
|
+
status: 409,
|
|
324
|
+
message:
|
|
325
|
+
"The proxy address configured in magpie's providers.json is invalid; fix it before running hosted renewal.",
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
if (resolved.reason === "exit_missing") {
|
|
329
|
+
return {
|
|
330
|
+
ok: false,
|
|
331
|
+
code: "exit_missing",
|
|
332
|
+
status: 409,
|
|
333
|
+
message:
|
|
334
|
+
!store || typeof store.get !== "function"
|
|
335
|
+
? "The proxy list is unavailable, so the login exit cannot be resolved."
|
|
336
|
+
: "The exit this account logged in through is no longer in the proxy list. Add it back, or sign in again through another exit.",
|
|
337
|
+
};
|
|
338
|
+
}
|
|
296
339
|
return {
|
|
297
340
|
ok: false,
|
|
298
341
|
code: "exit_unknown",
|
|
@@ -301,37 +344,13 @@ export function createRenewHosting(options = {}) {
|
|
|
301
344
|
"This account has no recorded login exit. Sign in once more so the exit is recorded, then enable hosting.",
|
|
302
345
|
};
|
|
303
346
|
}
|
|
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
347
|
return {
|
|
325
348
|
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
|
-
},
|
|
349
|
+
proxy: resolved.proxy,
|
|
350
|
+
// Strictly credential-free four-field whitelist (or null for direct):
|
|
351
|
+
// username, password and raw URLs never leave this function into
|
|
352
|
+
// account.json or renew-hosting.json.
|
|
353
|
+
proxyMeta: resolved.proxyMeta,
|
|
335
354
|
};
|
|
336
355
|
}
|
|
337
356
|
|
|
@@ -391,7 +410,7 @@ export function createRenewHosting(options = {}) {
|
|
|
391
410
|
message: "This account has no pinned fingerprint; sign in through clean-login first.",
|
|
392
411
|
};
|
|
393
412
|
}
|
|
394
|
-
const exit = await resolveExit(meta);
|
|
413
|
+
const exit = await resolveExit(provider, key, meta);
|
|
395
414
|
if (!exit.ok) return exit;
|
|
396
415
|
return { ok: true, dir, meta, expiresAt, proxy: exit.proxy, proxyMeta: exit.proxyMeta };
|
|
397
416
|
}
|
package/lib/server.mjs
CHANGED
|
@@ -75,6 +75,15 @@ import {
|
|
|
75
75
|
readAccountExit,
|
|
76
76
|
writeAccountExit,
|
|
77
77
|
} from "./account-proxies.mjs";
|
|
78
|
+
import {
|
|
79
|
+
accountExitProjection,
|
|
80
|
+
buildProxyUrlMap,
|
|
81
|
+
exitDisplayUrl,
|
|
82
|
+
lookupProxyByUrl,
|
|
83
|
+
readProvidersSnapshot,
|
|
84
|
+
resolveAccountProxyName,
|
|
85
|
+
resolveEffectiveAccountExit,
|
|
86
|
+
} from "./account-exit.mjs";
|
|
78
87
|
import { readAuthEntries, readAuthExpiries } from "./signin-writeback.mjs";
|
|
79
88
|
import { createProviderRegistration } from "./provider-registration.mjs";
|
|
80
89
|
import {
|
|
@@ -378,23 +387,6 @@ const EXIT_WRITE_MESSAGES = {
|
|
|
378
387
|
verify_failed: "The exit could not be verified after writing providers.json.",
|
|
379
388
|
};
|
|
380
389
|
|
|
381
|
-
// A display-only view of an exit URL: scheme, host and port, never the
|
|
382
|
-
// credentials. `providers.json` stores a custom exit as a full URL and
|
|
383
|
-
// `provider.proxy` may carry one too, but the page only needs to recognise
|
|
384
|
-
// which exit is in force. Unparseable text yields null rather than an echo,
|
|
385
|
-
// so this can never hand a credential to the page.
|
|
386
|
-
function exitDisplayUrl(value) {
|
|
387
|
-
if (typeof value !== "string") return null;
|
|
388
|
-
const trimmed = value.trim();
|
|
389
|
-
if (!trimmed || trimmed === "direct") return null;
|
|
390
|
-
try {
|
|
391
|
-
const url = new URL(trimmed);
|
|
392
|
-
return url.host ? `${url.protocol}//${url.host}` : null;
|
|
393
|
-
} catch {
|
|
394
|
-
return null;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
390
|
// The service's port is fixed: the page reads it from `window.magpie.options`
|
|
399
391
|
// and has no fallback, so it cannot simply move to a free one. magpie reloads a
|
|
400
392
|
// plugin in a fresh host process after an update, and the host it replaces keeps
|
|
@@ -642,16 +634,16 @@ export async function startServer({
|
|
|
642
634
|
// is a short digest, never the identity object or the directory path.
|
|
643
635
|
// `hostingById` lets the list read the policy file once for every row; a
|
|
644
636
|
// single-account response reads just its own entry.
|
|
645
|
-
async function accountView(entry, keys, hostingById = null,
|
|
637
|
+
async function accountView(entry, keys, hostingById = null, liveExit = undefined, authContext = null) {
|
|
646
638
|
const hosting = hostingById
|
|
647
639
|
? hostingById.get(`${entry.provider}\u0000${entry.key}`) ?? offView(entry.provider, entry.key)
|
|
648
640
|
: await renewHosting.viewOf(entry.provider, entry.key);
|
|
649
641
|
const extras = accountExtras(entry.meta);
|
|
650
|
-
//
|
|
651
|
-
//
|
|
652
|
-
//
|
|
653
|
-
//
|
|
654
|
-
if (
|
|
642
|
+
// magpie's providers.json is the single source of truth for the account's
|
|
643
|
+
// current exit. Whenever providers.json authoritatively resolves this
|
|
644
|
+
// account, its credential-free projection overrides any stale ledger
|
|
645
|
+
// snapshot (`extras.exit`).
|
|
646
|
+
if (liveExit !== undefined) extras.exit = liveExit;
|
|
655
647
|
const runtimeEnv = env ?? process.env;
|
|
656
648
|
const authEntries = authContext?.authEntries ?? readAuthEntries(runtimeEnv);
|
|
657
649
|
const authExpiries = authContext?.authExpiries ?? readAuthExpiries(runtimeEnv);
|
|
@@ -891,6 +883,22 @@ export async function startServer({
|
|
|
891
883
|
return { relogin: "none" };
|
|
892
884
|
}
|
|
893
885
|
|
|
886
|
+
async function liveAccountExit(entry, { authEntries, nativeEntries, providersDoc, proxyByUrl } = {}) {
|
|
887
|
+
const resolved = await resolveEffectiveAccountExit({
|
|
888
|
+
env: effectiveEnv,
|
|
889
|
+
provider: entry.provider,
|
|
890
|
+
key: entry.key,
|
|
891
|
+
meta: entry.meta,
|
|
892
|
+
store,
|
|
893
|
+
authEntries,
|
|
894
|
+
nativeEntries,
|
|
895
|
+
providersDoc,
|
|
896
|
+
proxyByUrl,
|
|
897
|
+
fallbackToLedger: false,
|
|
898
|
+
});
|
|
899
|
+
return accountExitProjection(resolved, accountExtras(entry.meta).exit);
|
|
900
|
+
}
|
|
901
|
+
|
|
894
902
|
// Every known account with its ownership ledger fields and whether its key
|
|
895
903
|
// is signed in. No path and no credential is ever returned. Shared by
|
|
896
904
|
// GET /api/accounts and the compact /api/agent digest, so the two can never
|
|
@@ -910,43 +918,26 @@ export async function startServer({
|
|
|
910
918
|
// An unreadable policy file must not hide the accounts themselves; every
|
|
911
919
|
// row simply shows hosting as off.
|
|
912
920
|
}
|
|
913
|
-
// Read
|
|
914
|
-
//
|
|
915
|
-
//
|
|
921
|
+
// Read identity stores and magpie's providers.json once for the whole
|
|
922
|
+
// table. providers.json is the single source of truth for each account's
|
|
923
|
+
// active exit, so every row projects live state rather than being masked
|
|
924
|
+
// by a stale ledger `exit` snapshot.
|
|
916
925
|
const authEntries = readAuthEntries(effectiveEnv);
|
|
917
926
|
const authExpiries = readAuthExpiries(effectiveEnv);
|
|
918
927
|
const nativeEntries = readNativeLoginsResult(effectiveEnv).entries ?? [];
|
|
919
|
-
|
|
928
|
+
const providersDoc = await readProvidersSnapshot({ env: effectiveEnv });
|
|
929
|
+
const proxyByUrl = providersDoc.ok ? await buildProxyUrlMap(store) : null;
|
|
920
930
|
const accounts = [];
|
|
921
931
|
for (const entry of dirs) {
|
|
922
932
|
if (!entry.meta) continue;
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|| nativeEntries.find((e) => e?.key === key)?.email
|
|
930
|
-
|| "";
|
|
931
|
-
const read = await readAccountExit({ env: effectiveEnv, provider: entry.provider, accountId });
|
|
932
|
-
if (read.ok && read.mode === "custom") {
|
|
933
|
-
// providers.json only holds URL text; the stored records are needed
|
|
934
|
-
// to name the node. Built lazily and once, deduped by URL.
|
|
935
|
-
if (!proxyByUrl) {
|
|
936
|
-
proxyByUrl = new Map();
|
|
937
|
-
for (const item of await store.list()) {
|
|
938
|
-
const record = await store.get(item.id);
|
|
939
|
-
const url = proxyUrlFor(record);
|
|
940
|
-
if (url && !proxyByUrl.has(url)) proxyByUrl.set(url, record);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
fallback = loginSnapshot(proxyByUrl.get(read.url) ?? null, null);
|
|
944
|
-
} else if (read.ok && read.mode === "direct") {
|
|
945
|
-
fallback = loginSnapshot(null, null);
|
|
946
|
-
}
|
|
947
|
-
}
|
|
933
|
+
const liveExit = await liveAccountExit(entry, {
|
|
934
|
+
authEntries,
|
|
935
|
+
nativeEntries,
|
|
936
|
+
providersDoc,
|
|
937
|
+
proxyByUrl,
|
|
938
|
+
});
|
|
948
939
|
accounts.push(
|
|
949
|
-
await accountView(entry, keys, hostingById,
|
|
940
|
+
await accountView(entry, keys, hostingById, liveExit, { authEntries, authExpiries }),
|
|
950
941
|
);
|
|
951
942
|
}
|
|
952
943
|
// Deterministic order: provider, then account key.
|
|
@@ -1602,14 +1593,16 @@ export async function startServer({
|
|
|
1602
1593
|
}
|
|
1603
1594
|
if (req.method === "PATCH") {
|
|
1604
1595
|
const changes = validateUpdate(await readJson(req));
|
|
1596
|
+
const previousUrl = proxyUrlFor(existing);
|
|
1605
1597
|
const updated = await store.update(route.id, changes);
|
|
1606
1598
|
if (!updated) throw new HttpError(404, "not_found", "Proxy not found.");
|
|
1607
1599
|
const connectionChanged =
|
|
1608
1600
|
proxyConnectionKey(existing) !== proxyConnectionKey(updated) ||
|
|
1609
|
-
(existing.password || "") !== (updated.password || "")
|
|
1601
|
+
(existing.password || "") !== (updated.password || "") ||
|
|
1602
|
+
previousUrl !== proxyUrlFor(updated);
|
|
1610
1603
|
if (connectionChanged && typeof accountProxySync.syncProxyUpdate === "function") {
|
|
1611
1604
|
try {
|
|
1612
|
-
await accountProxySync.syncProxyUpdate(updated);
|
|
1605
|
+
await accountProxySync.syncProxyUpdate({ proxyId: updated.id, previousUrl });
|
|
1613
1606
|
} catch {
|
|
1614
1607
|
// Best effort sync of bound accounts in providers.json.
|
|
1615
1608
|
}
|
|
@@ -1855,15 +1848,18 @@ export async function startServer({
|
|
|
1855
1848
|
// directory key. The name comes from the ledger first, then the auth
|
|
1856
1849
|
// file, then the native login ledger; an empty name is passed through
|
|
1857
1850
|
// so the lib reports `account_name_unknown` instead of a 500 here.
|
|
1858
|
-
const
|
|
1859
|
-
const
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1851
|
+
const authEntries = readAuthEntries(effectiveEnv);
|
|
1852
|
+
const nativeEntries = readNativeLoginsResult(effectiveEnv).entries ?? [];
|
|
1853
|
+
const accountId = resolveAccountProxyName({
|
|
1854
|
+
meta,
|
|
1855
|
+
key,
|
|
1856
|
+
authEntries,
|
|
1857
|
+
nativeEntries,
|
|
1858
|
+
env: effectiveEnv,
|
|
1859
|
+
});
|
|
1864
1860
|
// The page's select needs the stored node id, but providers.json only
|
|
1865
|
-
// holds URL text. `
|
|
1866
|
-
//
|
|
1861
|
+
// holds URL text. `buildProxyUrlMap` indexes full records by exact and
|
|
1862
|
+
// canonical URL so matching stays consistent with the accounts list.
|
|
1867
1863
|
async function exitView() {
|
|
1868
1864
|
const read = await readAccountExit({ env: effectiveEnv, provider, accountId });
|
|
1869
1865
|
// Only the fields the page renders leave the service, and never the
|
|
@@ -1882,13 +1878,8 @@ export async function startServer({
|
|
|
1882
1878
|
: { ok: false, reason: read.reason, key: read.key };
|
|
1883
1879
|
let proxyId = null;
|
|
1884
1880
|
if (read.ok && read.mode === "custom") {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
if (proxyUrlFor(record) === read.url) {
|
|
1888
|
-
proxyId = item.id;
|
|
1889
|
-
break;
|
|
1890
|
-
}
|
|
1891
|
-
}
|
|
1881
|
+
const matched = lookupProxyByUrl(await buildProxyUrlMap(store), read.url);
|
|
1882
|
+
proxyId = matched?.id ?? null;
|
|
1892
1883
|
}
|
|
1893
1884
|
return { ...view, proxyId };
|
|
1894
1885
|
}
|
|
@@ -1920,7 +1911,14 @@ export async function startServer({
|
|
|
1920
1911
|
}
|
|
1921
1912
|
exitProxy = stored;
|
|
1922
1913
|
}
|
|
1923
|
-
const result = await writeAccountExit({
|
|
1914
|
+
const result = await writeAccountExit({
|
|
1915
|
+
env: effectiveEnv,
|
|
1916
|
+
provider,
|
|
1917
|
+
accountId,
|
|
1918
|
+
mode,
|
|
1919
|
+
url,
|
|
1920
|
+
dataDir,
|
|
1921
|
+
});
|
|
1924
1922
|
if (!result.ok) {
|
|
1925
1923
|
// The error code is the lib's reason itself, so the page can show
|
|
1926
1924
|
// a specific hint for each failure.
|
|
@@ -1936,9 +1934,10 @@ export async function startServer({
|
|
|
1936
1934
|
// Mirror the change into the plugin's own ledger. `exit` records "the
|
|
1937
1935
|
// exit this account is set to use right now", separate from the
|
|
1938
1936
|
// lastLogin history: the accounts list and hosting renewal both read
|
|
1939
|
-
//
|
|
1940
|
-
//
|
|
1941
|
-
//
|
|
1937
|
+
// providers.json as SSOT and fall back to the ledger only when
|
|
1938
|
+
// providers.json is absent. Only the whitelisted display fields are
|
|
1939
|
+
// stored, exactly like recordCheck above. The updated account record
|
|
1940
|
+
// is projected through the same live resolver as GET /api/accounts.
|
|
1942
1941
|
let updatedAccount = null;
|
|
1943
1942
|
try {
|
|
1944
1943
|
const now = new Date().toISOString();
|
|
@@ -1953,7 +1952,17 @@ export async function startServer({
|
|
|
1953
1952
|
await writeAccountMeta(dir, merged);
|
|
1954
1953
|
return merged;
|
|
1955
1954
|
});
|
|
1956
|
-
|
|
1955
|
+
const liveExit = await liveAccountExit(
|
|
1956
|
+
{ provider, key, dir, meta: updatedMeta },
|
|
1957
|
+
{ authEntries, nativeEntries },
|
|
1958
|
+
);
|
|
1959
|
+
updatedAccount = await accountView(
|
|
1960
|
+
{ provider, key, dir, meta: updatedMeta },
|
|
1961
|
+
keys,
|
|
1962
|
+
null,
|
|
1963
|
+
liveExit,
|
|
1964
|
+
{ authEntries },
|
|
1965
|
+
);
|
|
1957
1966
|
} catch {
|
|
1958
1967
|
// A ledger write failure must not change the reported exit change.
|
|
1959
1968
|
}
|
|
@@ -1985,9 +1994,10 @@ export async function startServer({
|
|
|
1985
1994
|
return merged;
|
|
1986
1995
|
});
|
|
1987
1996
|
const keys = liveAccountKeys();
|
|
1997
|
+
const liveExit = await liveAccountExit({ ...accountTarget, dir, meta: updated });
|
|
1988
1998
|
json(res, 200, {
|
|
1989
1999
|
ok: true,
|
|
1990
|
-
account: await accountView({ ...accountTarget, dir, meta: updated }, keys),
|
|
2000
|
+
account: await accountView({ ...accountTarget, dir, meta: updated }, keys, null, liveExit),
|
|
1991
2001
|
});
|
|
1992
2002
|
return;
|
|
1993
2003
|
}
|
|
@@ -2012,9 +2022,11 @@ export async function startServer({
|
|
|
2012
2022
|
}
|
|
2013
2023
|
try {
|
|
2014
2024
|
if (typeof accountProxySync.clearAccountProxy === "function") {
|
|
2025
|
+
const clearAccountId =
|
|
2026
|
+
resolveAccountProxyName({ meta, key: accountTarget.key, env: effectiveEnv }) || null;
|
|
2015
2027
|
await accountProxySync.clearAccountProxy({
|
|
2016
2028
|
provider: accountTarget.provider,
|
|
2017
|
-
accountId:
|
|
2029
|
+
accountId: clearAccountId,
|
|
2018
2030
|
});
|
|
2019
2031
|
}
|
|
2020
2032
|
} catch {
|
package/lib/signin-flow.mjs
CHANGED
|
@@ -695,34 +695,48 @@ export function createSignInFlow(options = {}) {
|
|
|
695
695
|
// ledger are saved: a magpie without providers.json, or a read-only
|
|
696
696
|
// config directory, must not turn a successful sign-in into an
|
|
697
697
|
// error. Only a credential-free summary is kept, never the URL.
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
current.proxySync = {
|
|
705
|
-
ok: sync?.ok !== false,
|
|
706
|
-
reason: sync?.reason ?? null,
|
|
707
|
-
changed: Array.isArray(sync?.changed) ? sync.changed.length : 0,
|
|
708
|
-
// A credential-free registration report tells the caller whether
|
|
709
|
-
// magpie now offers the provider whose first sign-in happened here.
|
|
710
|
-
registration: sync?.registration
|
|
711
|
-
? {
|
|
712
|
-
ok: sync.registration.ok === true,
|
|
713
|
-
state: sync.registration.state ?? null,
|
|
714
|
-
action: sync.registration.action ?? null,
|
|
715
|
-
reason: sync.registration.reason ?? null,
|
|
716
|
-
}
|
|
717
|
-
: null,
|
|
718
|
-
};
|
|
719
|
-
} catch (error) {
|
|
698
|
+
//
|
|
699
|
+
// Silent runs (hosted renewals) already follow the account's live
|
|
700
|
+
// exit from providers.json; writing back here would turn an
|
|
701
|
+
// `inherit` account using `provider.proxy` into a pinned `custom`
|
|
702
|
+
// override, so skip proxy sync on silent renewals.
|
|
703
|
+
if (current.silent) {
|
|
720
704
|
current.proxySync = {
|
|
721
|
-
ok:
|
|
722
|
-
reason: "
|
|
705
|
+
ok: true,
|
|
706
|
+
reason: "skipped_silent",
|
|
723
707
|
changed: 0,
|
|
724
|
-
|
|
708
|
+
registration: null,
|
|
725
709
|
};
|
|
710
|
+
} else {
|
|
711
|
+
try {
|
|
712
|
+
const sync = await syncAccountProxy({
|
|
713
|
+
provider: current.provider,
|
|
714
|
+
accountId: written.entry?.accountId ?? null,
|
|
715
|
+
proxy: current.proxy,
|
|
716
|
+
});
|
|
717
|
+
current.proxySync = {
|
|
718
|
+
ok: sync?.ok !== false,
|
|
719
|
+
reason: sync?.reason ?? null,
|
|
720
|
+
changed: Array.isArray(sync?.changed) ? sync.changed.length : 0,
|
|
721
|
+
// A credential-free registration report tells the caller whether
|
|
722
|
+
// magpie now offers the provider whose first sign-in happened here.
|
|
723
|
+
registration: sync?.registration
|
|
724
|
+
? {
|
|
725
|
+
ok: sync.registration.ok === true,
|
|
726
|
+
state: sync.registration.state ?? null,
|
|
727
|
+
action: sync.registration.action ?? null,
|
|
728
|
+
reason: sync.registration.reason ?? null,
|
|
729
|
+
}
|
|
730
|
+
: null,
|
|
731
|
+
};
|
|
732
|
+
} catch (error) {
|
|
733
|
+
current.proxySync = {
|
|
734
|
+
ok: false,
|
|
735
|
+
reason: "sync_failed",
|
|
736
|
+
changed: 0,
|
|
737
|
+
error: String(error?.message ?? error),
|
|
738
|
+
};
|
|
739
|
+
}
|
|
726
740
|
}
|
|
727
741
|
current.state = "done";
|
|
728
742
|
current.error = null;
|
package/package.json
CHANGED
package/ui/account-view.js
CHANGED
|
@@ -145,20 +145,53 @@ export function hostingTone(hosting) {
|
|
|
145
145
|
return "none";
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
if (!login || typeof login !== "object") return directText;
|
|
150
|
-
if (login.proxyId === null) return directText;
|
|
148
|
+
function formatNamedExit(login, directText) {
|
|
151
149
|
const region = typeof login.region === "string" ? login.region.trim() : "";
|
|
152
150
|
const name = typeof login.proxyName === "string"
|
|
153
151
|
? login.proxyName.trim()
|
|
154
152
|
: typeof login.name === "string" ? login.name.trim() : "";
|
|
155
|
-
if (!region && !name) return
|
|
153
|
+
if (!region && !name) return "";
|
|
156
154
|
if (name === "直连" || name === directText) return directText;
|
|
157
155
|
if (region && name) {
|
|
158
156
|
if (name.includes(region)) return name;
|
|
159
157
|
return `${region} · ${name}`;
|
|
160
158
|
}
|
|
161
|
-
return name || region
|
|
159
|
+
return name || region;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function formatExit(login, directText = "直连", labels = {}) {
|
|
163
|
+
if (!login || typeof login !== "object") return directText;
|
|
164
|
+
const customText =
|
|
165
|
+
typeof labels?.custom === "string" && labels.custom.trim()
|
|
166
|
+
? labels.custom.trim()
|
|
167
|
+
: "自定义出口";
|
|
168
|
+
const inheritTemplate =
|
|
169
|
+
typeof labels?.inherit === "string" && labels.inherit.trim()
|
|
170
|
+
? labels.inherit.trim()
|
|
171
|
+
: "跟随供应商({exit})";
|
|
172
|
+
const displayUrl = typeof login.displayUrl === "string" ? login.displayUrl.trim() : "";
|
|
173
|
+
const named = formatNamedExit(login, directText);
|
|
174
|
+
|
|
175
|
+
if (login.mode === "inherit") {
|
|
176
|
+
const target =
|
|
177
|
+
login.proxyId !== null && named
|
|
178
|
+
? named
|
|
179
|
+
: displayUrl
|
|
180
|
+
? displayUrl
|
|
181
|
+
: login.custom
|
|
182
|
+
? customText
|
|
183
|
+
: directText;
|
|
184
|
+
return inheritTemplate.includes("{exit}")
|
|
185
|
+
? inheritTemplate.replace("{exit}", target)
|
|
186
|
+
: `${inheritTemplate} · ${target}`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (login.custom) {
|
|
190
|
+
return displayUrl ? `${customText} · ${displayUrl}` : customText;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (login.proxyId === null) return directText;
|
|
194
|
+
return named || directText;
|
|
162
195
|
}
|
|
163
196
|
|
|
164
197
|
// The check job's exposure/summary as display lines. `labels.exposure` is a
|
package/ui/app.js
CHANGED
|
@@ -428,6 +428,7 @@ const messages = {
|
|
|
428
428
|
accountFingerprintPinned: "Pinned {time}",
|
|
429
429
|
accountFingerprintNone: "No pinned fingerprint",
|
|
430
430
|
accountExitDirect: "Direct",
|
|
431
|
+
accountExitCustom: "Custom exit",
|
|
431
432
|
accountLastLoginAt: "{time} · {exit}",
|
|
432
433
|
accountCheckExposure: "{count} places may expose you",
|
|
433
434
|
accountRelogin: "Sign in again",
|
|
@@ -1013,6 +1014,7 @@ const messages = {
|
|
|
1013
1014
|
accountFingerprintPinned: "固定于 {time}",
|
|
1014
1015
|
accountFingerprintNone: "没有固定指纹",
|
|
1015
1016
|
accountExitDirect: "直连",
|
|
1017
|
+
accountExitCustom: "自定义出口",
|
|
1016
1018
|
accountLastLoginAt: "{time} · {exit}",
|
|
1017
1019
|
accountCheckExposure: "{count} 处可能暴露你",
|
|
1018
1020
|
accountRelogin: "重新登录",
|
|
@@ -1598,6 +1600,7 @@ const messages = {
|
|
|
1598
1600
|
accountFingerprintPinned: "固定於 {time}",
|
|
1599
1601
|
accountFingerprintNone: "沒有固定指紋",
|
|
1600
1602
|
accountExitDirect: "直連",
|
|
1603
|
+
accountExitCustom: "自訂出口",
|
|
1601
1604
|
accountLastLoginAt: "{time} · {exit}",
|
|
1602
1605
|
accountCheckExposure: "{count} 處可能暴露你",
|
|
1603
1606
|
accountRelogin: "重新登入",
|
|
@@ -2183,6 +2186,7 @@ const messages = {
|
|
|
2183
2186
|
accountFingerprintPinned: "{time} に固定",
|
|
2184
2187
|
accountFingerprintNone: "固定された指紋がありません",
|
|
2185
2188
|
accountExitDirect: "直接接続",
|
|
2189
|
+
accountExitCustom: "カスタム出口",
|
|
2186
2190
|
accountLastLoginAt: "{time} · {exit}",
|
|
2187
2191
|
accountCheckExposure: "{count} 箇所で情報が漏れる可能性",
|
|
2188
2192
|
accountRelogin: "再ログイン",
|
|
@@ -6557,6 +6561,13 @@ function accountForList(account) {
|
|
|
6557
6561
|
// clear the flag, so it only ever told people their own working account looked
|
|
6558
6562
|
// suspicious.
|
|
6559
6563
|
|
|
6564
|
+
function accountExitLabels() {
|
|
6565
|
+
return {
|
|
6566
|
+
custom: text.accountExitCustom,
|
|
6567
|
+
inherit: text.accountDetailExitInherit,
|
|
6568
|
+
};
|
|
6569
|
+
}
|
|
6570
|
+
|
|
6560
6571
|
function gradeTone(grade) {
|
|
6561
6572
|
if (grade === "A" || grade === "B") return "good";
|
|
6562
6573
|
if (grade === "C") return "warn";
|
|
@@ -6623,7 +6634,10 @@ function accountRow(account) {
|
|
|
6623
6634
|
// there is no current setting does it fall back to the last login's exit.
|
|
6624
6635
|
lastLogin.textContent = text.accountLastLoginAt
|
|
6625
6636
|
.replace("{time}", formatTime(view.lastLogin?.at || view.signedInAt))
|
|
6626
|
-
.replace(
|
|
6637
|
+
.replace(
|
|
6638
|
+
"{exit}",
|
|
6639
|
+
formatExit(view.exit ?? view.lastLogin, text.accountExitDirect, accountExitLabels()),
|
|
6640
|
+
);
|
|
6627
6641
|
|
|
6628
6642
|
const checkCell = accountCell("proxy-score-cell account-cell-check", text.accountColCheck);
|
|
6629
6643
|
if (accountRunningFor(view.provider, view.key)) {
|
|
@@ -7450,7 +7464,10 @@ function renderHostingFacts(view, inspect) {
|
|
|
7450
7464
|
? text.accountHostingNextNone
|
|
7451
7465
|
: text.accountHostingNextOff],
|
|
7452
7466
|
[text.accountHostingLastLabel, last],
|
|
7453
|
-
[
|
|
7467
|
+
[
|
|
7468
|
+
text.accountHostingExitLabel,
|
|
7469
|
+
formatExit(view.exit ?? view.lastLogin, text.accountExitDirect, accountExitLabels()),
|
|
7470
|
+
],
|
|
7454
7471
|
[text.accountHostingFingerprintLabel, view.fingerprint.id || text.accountFingerprintNone],
|
|
7455
7472
|
]) {
|
|
7456
7473
|
const wrap = document.createElement("div");
|