@coffre/ui 0.14.7 → 0.16.0
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/dist/audit-sentences.d.ts +56 -0
- package/dist/audit-sentences.js +886 -0
- package/dist/audit-sentences.js.map +1 -0
- package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
- package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
- package/dist/chunks/{connected-apps-IJdunsu8.js → connected-apps-6sMSgQ9U.js} +5 -5
- package/dist/chunks/{connected-apps-IJdunsu8.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
- package/dist/chunks/{delete-place-dIVoK87I.js → delete-place-T469tSN9.js} +5 -5
- package/dist/chunks/{delete-place-dIVoK87I.js.map → delete-place-T469tSN9.js.map} +1 -1
- package/dist/chunks/{directory-BM8yoiJN.js → directory-B_gVf7UL.js} +13 -12
- package/dist/chunks/{directory-BM8yoiJN.js.map → directory-B_gVf7UL.js.map} +1 -1
- package/dist/chunks/{folders-D3A1NGpt.js → folders-CVYauIDz.js} +3 -3
- package/dist/chunks/{folders-D3A1NGpt.js.map → folders-CVYauIDz.js.map} +1 -1
- package/dist/chunks/{grants-CjVmOgb2.js → grants-Dn_EW2XW.js} +6 -6
- package/dist/chunks/{grants-CjVmOgb2.js.map → grants-Dn_EW2XW.js.map} +1 -1
- package/dist/chunks/{multi-combobox-B0JzP1QN.js → multi-combobox-fbBRzi9z.js} +3 -3
- package/dist/chunks/{multi-combobox-B0JzP1QN.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
- package/dist/chunks/{offboarding-DbozhPym.js → offboarding-CXM464J_.js} +19 -13
- package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
- package/dist/chunks/{page-JTORvh-N.js → page-Cb0ZjGda.js} +2 -2
- package/dist/chunks/{page-JTORvh-N.js.map → page-Cb0ZjGda.js.map} +1 -1
- package/dist/chunks/{personal-tokens-zWZOzLIC.js → personal-tokens-CSHMlRHy.js} +7 -7
- package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
- package/dist/chunks/{principal-DFBswTBr.js → principal-BKJxbAtE.js} +2 -2
- package/dist/chunks/{principal-DFBswTBr.js.map → principal-BKJxbAtE.js.map} +1 -1
- package/dist/chunks/{principal-page-jJ0RVFg8.js → principal-page-COPmTDVW.js} +20 -17
- package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
- package/dist/chunks/{project-page-BjwEoXfU.js → project-page-g5_n46Nz.js} +3 -3
- package/dist/chunks/{project-page-BjwEoXfU.js.map → project-page-g5_n46Nz.js.map} +1 -1
- package/dist/chunks/{protected-y7KVhtHd.js → protected-DEWeOrmI.js} +7 -7
- package/dist/chunks/{protected-y7KVhtHd.js.map → protected-DEWeOrmI.js.map} +1 -1
- package/dist/chunks/{queries-2jdgTwfZ.js → queries-D4_o-bz3.js} +11 -88
- package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
- package/dist/chunks/{references-CRT2BsOS.js → references-wTh_DT0M.js} +27 -23
- package/dist/chunks/references-wTh_DT0M.js.map +1 -0
- package/dist/chunks/{role-field-DswIpPqY.js → role-field-BiP09qfN.js} +4 -4
- package/dist/chunks/{role-field-DswIpPqY.js.map → role-field-BiP09qfN.js.map} +1 -1
- package/dist/chunks/{row-state-xtRGFnDc.js → row-state-CYhtmUkc.js} +3 -3
- package/dist/chunks/{row-state-xtRGFnDc.js.map → row-state-CYhtmUkc.js.map} +1 -1
- package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
- package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
- package/dist/chunks/{theme-Ck45wzWB.js → theme-imSolE1q.js} +3 -3
- package/dist/chunks/{theme-Ck45wzWB.js.map → theme-imSolE1q.js.map} +1 -1
- package/dist/chunks/{ui-D-blFWfx.js → ui-Q_Eczt7m.js} +7 -3
- package/dist/chunks/{ui-D-blFWfx.js.map → ui-Q_Eczt7m.js.map} +1 -1
- package/dist/chunks/{use-action-CXEFFjx5.js → use-action-BfnN-De2.js} +3 -3
- package/dist/chunks/{use-action-CXEFFjx5.js.map → use-action-BfnN-De2.js.map} +1 -1
- package/dist/chunks/{use-change-BC4xo02c.js → use-change-Cc0X4sF3.js} +6 -4
- package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
- package/dist/chunks/{use-roles-DswiNxBk.js → use-roles-stcv2QFj.js} +3 -3
- package/dist/chunks/{use-roles-DswiNxBk.js.map → use-roles-stcv2QFj.js.map} +1 -1
- package/dist/chunks/{use-shell-zpjE_MKh.js → use-shell-DMhLa2sh.js} +3 -3
- package/dist/chunks/{use-shell-zpjE_MKh.js.map → use-shell-DMhLa2sh.js.map} +1 -1
- package/dist/index.d.ts +22 -10
- package/dist/index.js +7 -7
- package/dist/pages/account.js +11 -11
- package/dist/pages/approval.js +2 -2
- package/dist/pages/audit.js +163 -152
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +2 -2
- package/dist/pages/environment.js +67 -35
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +6 -15
- package/dist/pages/login.js.map +1 -1
- package/dist/pages/oauth-authorize.js +2 -2
- package/dist/pages/project-access.js +11 -11
- package/dist/pages/project-environments.js +12 -12
- package/dist/pages/project-settings.js +8 -8
- package/dist/pages/project.js +3 -3
- package/dist/pages/projects.js +8 -8
- package/dist/pages/service-account.js +19 -15
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +5 -5
- package/dist/pages/settings.js +26 -37
- package/dist/pages/settings.js.map +1 -1
- package/dist/pages/unregistered.js +2 -2
- package/dist/pages/user.js +7 -7
- package/dist/pages/user.js.map +1 -1
- package/dist/pages/users.js +5 -5
- package/package.json +8 -3
- package/src/components/directory.tsx +5 -4
- package/src/components/offboarding.tsx +9 -9
- package/src/components/personal-tokens.tsx +5 -2
- package/src/components/principal-page.tsx +4 -3
- package/src/components/references.tsx +18 -7
- package/src/components/trusted-workloads.tsx +6 -5
- package/src/components/ui.tsx +5 -0
- package/src/lib/audit-proofs.ts +51 -0
- package/src/lib/audit-sentences.ts +473 -509
- package/src/lib/bindings.ts +6 -0
- package/src/lib/changes.ts +3 -1
- package/src/lib/coffre.ts +2 -2
- package/src/lib/queries.ts +9 -94
- package/src/lib/reveal.ts +32 -5
- package/src/lib/row-reads.ts +2 -2
- package/src/lib/signin-errors.ts +5 -33
- package/src/pages/audit.tsx +145 -182
- package/src/pages/environment.tsx +21 -20
- package/src/pages/login.tsx +2 -4
- package/src/pages/settings.tsx +6 -10
- package/src/pages/user.tsx +2 -2
- package/src/parity.ts +0 -2
- package/src/styles/globals.css +18 -2
- package/dist/chunks/audit-sentence-JgJEwQEC.js +0 -969
- package/dist/chunks/audit-sentence-JgJEwQEC.js.map +0 -1
- package/dist/chunks/offboarding-DbozhPym.js.map +0 -1
- package/dist/chunks/personal-tokens-zWZOzLIC.js.map +0 -1
- package/dist/chunks/principal-page-jJ0RVFg8.js.map +0 -1
- package/dist/chunks/queries-2jdgTwfZ.js.map +0 -1
- package/dist/chunks/references-CRT2BsOS.js.map +0 -1
- package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
- package/dist/chunks/use-change-BC4xo02c.js.map +0 -1
package/src/lib/bindings.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CoffreError, type BindingPlan, type BindingView } from '@coffre/client';
|
|
2
|
+
import { credentialScopeInWords } from '@coffre/core/access';
|
|
2
3
|
import { claimValues, fullRef, githubReusable, githubWorkflow, gitlabProject, type BearerProfile, type BindingClaims } from '@coffre/core/workloads';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -30,6 +31,11 @@ export function summary(binding: Pick<BindingView, 'profile' | 'issuer' | 'claim
|
|
|
30
31
|
return { title: issuerName(binding.issuer), detail: `sub ${claims.sub}` };
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/** What a binding's credentials reach, in words; a null scope, one 0.4 made and never sealed, reaches nothing. */
|
|
35
|
+
export function reached(scope: BindingView['scope']): string {
|
|
36
|
+
return credentialScopeInWords(scope ?? {});
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
/** An issuer as a title: its host, when it is a URL; a binding that carries its keys may name any string. */
|
|
34
40
|
function issuerName(issuer: string): string {
|
|
35
41
|
try {
|
package/src/lib/changes.ts
CHANGED
|
@@ -564,8 +564,9 @@ export function saveSecrets(
|
|
|
564
564
|
reference: null,
|
|
565
565
|
archived: false,
|
|
566
566
|
version: inherited ? null : (entry?.version ?? 0) + 1,
|
|
567
|
-
// Known once the list is read back: until then, nothing regenerates it.
|
|
567
|
+
// Known once the list is read back: until then, nothing regenerates it, and no value read is shown.
|
|
568
568
|
versionId: null,
|
|
569
|
+
secret: null,
|
|
569
570
|
updatedAt: now,
|
|
570
571
|
updatedBy: author,
|
|
571
572
|
generated: generations.get(key) ?? null,
|
|
@@ -681,6 +682,7 @@ export function regenerateSecret(
|
|
|
681
682
|
reference: null,
|
|
682
683
|
version: inherited ? null : (entry.version ?? 0) + 1,
|
|
683
684
|
versionId: null,
|
|
685
|
+
secret: null,
|
|
684
686
|
updatedAt: now,
|
|
685
687
|
updatedBy: author,
|
|
686
688
|
generated: vars.generated,
|
package/src/lib/coffre.ts
CHANGED
|
@@ -31,8 +31,8 @@ export function failureMessage(error: unknown): string {
|
|
|
31
31
|
if (!(error instanceof CoffreError)) return 'The request could not be sent. Nothing was changed.';
|
|
32
32
|
if (error.status === 401) return 'Your session has ended. Sign in again, then retry.';
|
|
33
33
|
if (error.code === 'cross_origin') return 'coffre refused a change that did not come from this page. Reload, then retry.';
|
|
34
|
-
//
|
|
35
|
-
if (error.code === 'vault_refused' && error.reason === 'not_allowed') return error.message
|
|
34
|
+
// Only an Owner of the whole instance makes, changes or removes an Owner: the API's sentence says so, where a 403's would say a grant is missing.
|
|
35
|
+
if (error.code === 'vault_refused' && error.reason === 'not_allowed') return error.message;
|
|
36
36
|
if (error.status === 403) {
|
|
37
37
|
return 'You hold no grant that covers this. Someone with grant.manage on the project can add one.';
|
|
38
38
|
}
|
package/src/lib/queries.ts
CHANGED
|
@@ -296,9 +296,9 @@ export const queries = {
|
|
|
296
296
|
queryOptions({ queryKey: keys.apps, queryFn: () => uiResult(() => client.apps.list()) }),
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
|
-
* What the keys an operator keeps are checked against: the vault's
|
|
300
|
-
*
|
|
301
|
-
*
|
|
299
|
+
* What the keys an operator keeps are checked against: the vault's keys
|
|
300
|
+
* by ID and its signing keys' checks, no secret. Null for anyone but
|
|
301
|
+
* those who run the instance, who alone may ask.
|
|
302
302
|
*/
|
|
303
303
|
auditKeys: (client: CoffreClient, allowed: boolean) =>
|
|
304
304
|
queryOptions({
|
|
@@ -321,7 +321,7 @@ export const queries = {
|
|
|
321
321
|
roles: (client: CoffreClient) =>
|
|
322
322
|
queryOptions({ queryKey: keys.roles, queryFn: () => uiResult(() => client.roles.list()) }),
|
|
323
323
|
|
|
324
|
-
/** A page of the log, as filtered: always read fresh. */
|
|
324
|
+
/** A page of the log, as filtered, its entries proven against the head it names: always read fresh. */
|
|
325
325
|
auditEntries: (client: CoffreClient, search: AuditSearch) =>
|
|
326
326
|
queryOptions({
|
|
327
327
|
queryKey: [...keys.audit, 'entries', search],
|
|
@@ -338,16 +338,6 @@ export const queries = {
|
|
|
338
338
|
),
|
|
339
339
|
}),
|
|
340
340
|
|
|
341
|
-
/**
|
|
342
|
-
* Whether the log holds: verified with each visit, and rendered with the
|
|
343
|
-
* page, the loader's read to carry to the browser: it is not asked again on
|
|
344
|
-
* mount, and not for a filter change or a hover, which `FRESH_MS` covers.
|
|
345
|
-
* It reads what was written since the newest checkpoint, so it takes as
|
|
346
|
-
* long as five minutes of the log, however long the log. It never rejects:
|
|
347
|
-
* a check that could not run is its verdict (`unknown`).
|
|
348
|
-
*/
|
|
349
|
-
auditChain: (client: CoffreClient) =>
|
|
350
|
-
queryOptions({ queryKey: [...keys.audit, 'chain'], refetchOnMount: false, queryFn: () => verifyChain(client) }),
|
|
351
341
|
/** What deleting `market` or `market/prod` would take, asked afresh each time it is shown. */
|
|
352
342
|
deletion: (client: CoffreClient, path: string) =>
|
|
353
343
|
queryOptions({
|
|
@@ -364,76 +354,6 @@ export const queries = {
|
|
|
364
354
|
}),
|
|
365
355
|
};
|
|
366
356
|
|
|
367
|
-
/**
|
|
368
|
-
* Whether the log holds, or why that is not known. Verifying is for those
|
|
369
|
-
* who read the whole log (an Auditor, Admin or Owner whose scope narrows
|
|
370
|
-
* nothing): anyone else reads their projects' part of it, and a part cannot be
|
|
371
|
-
* checked as a chain, so for them it is a fact about the page, not a fault.
|
|
372
|
-
*/
|
|
373
|
-
async function verifyChain(client: CoffreClient) {
|
|
374
|
-
try {
|
|
375
|
-
return chainResult(await client.audit.verify(), false);
|
|
376
|
-
} catch (error) {
|
|
377
|
-
return chainUnknown(error);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* A verdict as the page shows it: `whole` when it comes from the walk
|
|
383
|
-
* from the first entry, which someone asked for, not from the newest
|
|
384
|
-
* checkpoint's.
|
|
385
|
-
*/
|
|
386
|
-
export function chainResult(result: Awaited<ReturnType<CoffreClient['audit']['verify']>>, whole: boolean) {
|
|
387
|
-
return result.ok
|
|
388
|
-
? {
|
|
389
|
-
integrity: 'intact' as const,
|
|
390
|
-
whole,
|
|
391
|
-
through: result.through,
|
|
392
|
-
entries: result.entries,
|
|
393
|
-
// A server older than 0.10.1 checked from the first entry, and reached the head.
|
|
394
|
-
from: result.from ?? 0,
|
|
395
|
-
remaining: result.remaining ?? 0,
|
|
396
|
-
checkpoint: result.checkpoint,
|
|
397
|
-
pending: result.pending ?? 0,
|
|
398
|
-
}
|
|
399
|
-
: {
|
|
400
|
-
integrity: 'broken' as const,
|
|
401
|
-
through: result.through,
|
|
402
|
-
failedAtSeq: result.failedAtSeq,
|
|
403
|
-
author: result.author,
|
|
404
|
-
reason: result.reason,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
* What the page shows, of the check from the newest checkpoint (`quick`)
|
|
410
|
-
* and the walk from the first entry, once someone ran it (`whole`). A break
|
|
411
|
-
* the walk found stands; otherwise the newer check says how the log is now,
|
|
412
|
-
* broken, partly checked or not checked at all; and only while it found the
|
|
413
|
-
* log whole too does the walk's verdict, which read further back, stand
|
|
414
|
-
* over it.
|
|
415
|
-
*
|
|
416
|
-
* whole broken → whole
|
|
417
|
-
* whole intact, quick intact with 0 remaining → whole
|
|
418
|
-
* whole intact, quick anything else → quick
|
|
419
|
-
*/
|
|
420
|
-
export function shownChain(quick: ChainResult, whole: ChainResult | null): ChainResult {
|
|
421
|
-
if (whole === null || whole.integrity === 'broken') return whole ?? quick;
|
|
422
|
-
return quick.integrity === 'intact' && quick.remaining === 0 && whole.integrity === 'intact' ? whole : quick;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/** Why the log's verdict is not known: closed to the caller, or no answer. */
|
|
426
|
-
export function chainUnknown(error: unknown) {
|
|
427
|
-
const status = statusOf(error);
|
|
428
|
-
if (status === 403) return { integrity: 'owners-only' as const };
|
|
429
|
-
return {
|
|
430
|
-
integrity: 'unknown' as const,
|
|
431
|
-
problem: status === undefined ? 'the request never got an answer' : `the request failed with HTTP ${status}`,
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
export type ChainResult = Awaited<ReturnType<typeof verifyChain>>;
|
|
436
|
-
|
|
437
357
|
/**
|
|
438
358
|
* Who is looking, how this instance signs people in, and the projects they
|
|
439
359
|
* can see: what the shell needs on every screen. For someone signed out or
|
|
@@ -549,17 +469,11 @@ export async function loadEnvironment(queryClient: QueryClient, client: CoffreCl
|
|
|
549
469
|
}
|
|
550
470
|
|
|
551
471
|
/**
|
|
552
|
-
* What the audit page reads: a page of the log
|
|
553
|
-
* the
|
|
554
|
-
* arrives with the page. The verification never fails the load: a check that
|
|
555
|
-
* could not run is its verdict.
|
|
472
|
+
* What the audit page reads: a page of the log, each entry with its proof
|
|
473
|
+
* against the head the vault signed, which the same answer carries.
|
|
556
474
|
*/
|
|
557
475
|
export async function loadAudit(queryClient: QueryClient, client: CoffreClient, search: AuditSearch) {
|
|
558
|
-
|
|
559
|
-
queryClient.fetchQuery(queries.auditEntries(client, search)),
|
|
560
|
-
queryClient.fetchQuery(queries.auditChain(client)),
|
|
561
|
-
]);
|
|
562
|
-
return entries;
|
|
476
|
+
return queryClient.fetchQuery(queries.auditEntries(client, search));
|
|
563
477
|
}
|
|
564
478
|
|
|
565
479
|
/** The directory pages' read: the directory, for owners. */
|
|
@@ -702,7 +616,8 @@ export function signInWays(shell: Shell, access: MemberAccessResult): { tokens:
|
|
|
702
616
|
*/
|
|
703
617
|
export function hasAppsTab(shell: Shell, report: MemberReport): boolean {
|
|
704
618
|
const found = report?.ok === true ? report.report : null;
|
|
705
|
-
|
|
619
|
+
// A report that does not list their apps (0.16's, so far) has nothing for the tab to show.
|
|
620
|
+
return Boolean(shell.features.mcp) && shell.capabilities.runsInstance && found !== null && found.status !== 'removed' && found.apps !== null;
|
|
706
621
|
}
|
|
707
622
|
|
|
708
623
|
export function managedProjects(projects: ProjectSummary[]): ProjectSummary[] {
|
package/src/lib/reveal.ts
CHANGED
|
@@ -10,10 +10,12 @@ export type Reveal = {
|
|
|
10
10
|
value: string;
|
|
11
11
|
version: number | null;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* The id of the secret the value was held in. One number can name two
|
|
14
|
+
* values: a fork's key reset to its parent's reads another secret's v1,
|
|
15
|
+
* and an override written after reads its own next number, which the
|
|
16
|
+
* parent's may have too.
|
|
15
17
|
*/
|
|
16
|
-
from
|
|
18
|
+
from: string | null;
|
|
17
19
|
/** When the read happened, in ms since the epoch; drives the auto-hide. */
|
|
18
20
|
at: number;
|
|
19
21
|
};
|
|
@@ -21,7 +23,32 @@ export type Reveal = {
|
|
|
21
23
|
export function revealIsCurrent(
|
|
22
24
|
reveal: Reveal | null,
|
|
23
25
|
currentVersion: number | null,
|
|
24
|
-
currentFrom
|
|
26
|
+
currentFrom: string | null,
|
|
25
27
|
): reveal is Reveal {
|
|
26
|
-
return reveal !== null && reveal.version === currentVersion && reveal.from === currentFrom;
|
|
28
|
+
return reveal !== null && reveal.from !== null && reveal.version === currentVersion && reveal.from === currentFrom;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What a read opened: the value, and the version it opened, by number and by the secret it is held in. */
|
|
32
|
+
export type Read = { value: string; version: number | null; from: string | null };
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A value read for the row `row` was when asked, stamped with the version it
|
|
36
|
+
* opened. A read that opened another number than the row's has outrun the
|
|
37
|
+
* listing, or the listing it: `refetch` brings the listing up to date first,
|
|
38
|
+
* so that once the value shows, the row says its number too. If the listing
|
|
39
|
+
* has moved past it by then, the value hides, as it is no longer the value.
|
|
40
|
+
*
|
|
41
|
+
* It is stamped with the secret the read says it opened, never the row's:
|
|
42
|
+
* a read across a reset, an override or a repointed reference opened
|
|
43
|
+
* another secret, maybe at the very number the row shows by then, and
|
|
44
|
+
* hides rather than show that secret's value as this one's.
|
|
45
|
+
*/
|
|
46
|
+
export async function stampedRead(
|
|
47
|
+
row: { version: number | null; from: string | null },
|
|
48
|
+
read: () => Promise<Read>,
|
|
49
|
+
refetch: () => Promise<unknown>,
|
|
50
|
+
): Promise<Reveal> {
|
|
51
|
+
const { value, version, from } = await read();
|
|
52
|
+
if (version !== row.version || from !== row.from) await refetch();
|
|
53
|
+
return { value, version, from, at: Date.now() };
|
|
27
54
|
}
|
package/src/lib/row-reads.ts
CHANGED
|
@@ -70,7 +70,7 @@ export function revealToggleDisabled(state: RowReads, shown: Reveal | null): boo
|
|
|
70
70
|
* whose reason the row says. It always opens: writing a value takes no read
|
|
71
71
|
* of the one it replaces.
|
|
72
72
|
*/
|
|
73
|
-
export async function valueToEdit(row: { value: string | null; readable: boolean }, read: () => Promise<
|
|
74
|
-
if (row.value !== null) return row.value;
|
|
73
|
+
export async function valueToEdit<T>(row: { value: string | null; readable: boolean }, read: () => Promise<T | null>, listed: (value: string) => T): Promise<T | null> {
|
|
74
|
+
if (row.value !== null) return listed(row.value);
|
|
75
75
|
return row.readable ? read() : null;
|
|
76
76
|
}
|
package/src/lib/signin-errors.ts
CHANGED
|
@@ -27,51 +27,23 @@ const MESSAGES: Record<string, string> = {
|
|
|
27
27
|
link_session: 'Your session changed while linking. Sign in again, then retry.',
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
* Where an email already signs in, for `account_mismatch`: the providers by
|
|
32
|
-
* the label the sign-in page shows them under, and the one just tried. What
|
|
33
|
-
* the visitor may know: the provider has just verified the email is theirs.
|
|
34
|
-
*/
|
|
35
|
-
export type Already = { providers: readonly string[]; via?: string };
|
|
36
|
-
|
|
37
|
-
export function signinErrorMessage(code: string | undefined, already?: Already): string | null {
|
|
30
|
+
export function signinErrorMessage(code: string | undefined): string | null {
|
|
38
31
|
if (code === undefined) return null;
|
|
39
|
-
if (code === 'account_mismatch' && already !== undefined && already.providers.length > 0) return mismatch(already);
|
|
40
32
|
return MESSAGES[code] ?? 'The sign-in did not complete. Try again.';
|
|
41
33
|
}
|
|
42
34
|
|
|
43
|
-
|
|
44
|
-
function mismatch({ providers, via }: Already): string {
|
|
45
|
-
const link = 'then link this account from your account page.';
|
|
46
|
-
// The same provider, another account of it: a second GitHub account, say.
|
|
47
|
-
if (providers.length === 1 && providers[0] === via) {
|
|
48
|
-
return `Your email already signs in with another ${via} account. Sign in with that one, ${link}`;
|
|
49
|
-
}
|
|
50
|
-
const named = providers.map((provider) => (provider === via ? `another ${provider} account` : provider));
|
|
51
|
-
const list = named.length < 3 ? named.join(' and ') : `${named.slice(0, -1).join(', ')} and ${named.at(-1)}`;
|
|
52
|
-
return named.length === 1
|
|
53
|
-
? `Your email already signs in with ${list}. Sign in with ${list}, ${link}`
|
|
54
|
-
: `Your email already signs in with ${list}. Sign in with one of them, ${link}`;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export type LoginSearch = { next?: string; error?: string; with?: string; via?: string };
|
|
58
|
-
|
|
59
|
-
/** A sign-in provider's id, as the instance configures it. */
|
|
60
|
-
const PROVIDER_ID = /^[a-z0-9_-]{1,40}$/;
|
|
35
|
+
export type LoginSearch = { next?: string; error?: string };
|
|
61
36
|
|
|
62
37
|
/**
|
|
63
38
|
* `/login`'s search: where to resume after signing in, same-origin paths
|
|
64
39
|
* only, since an absolute URL accepted here would make the sign-in page an
|
|
65
|
-
* open redirect; and the sign-in's `error`,
|
|
66
|
-
*
|
|
40
|
+
* open redirect; and the sign-in's `error`, shown once, then taken out of
|
|
41
|
+
* the URL.
|
|
67
42
|
*/
|
|
68
43
|
export function loginSearch(search: Record<string, unknown>): LoginSearch {
|
|
69
44
|
const out: LoginSearch = {};
|
|
70
|
-
const { next, error
|
|
45
|
+
const { next, error } = search;
|
|
71
46
|
if (typeof next === 'string' && next.startsWith('/') && !next.startsWith('//')) out.next = next;
|
|
72
47
|
if (typeof error === 'string' && /^[a-z_]{1,40}$/.test(error)) out.error = error;
|
|
73
|
-
const providers = typeof search.with === 'string' ? search.with.split(',').filter((id) => PROVIDER_ID.test(id)).slice(0, 8) : [];
|
|
74
|
-
if (providers.length > 0) out.with = providers.join(',');
|
|
75
|
-
if (typeof via === 'string' && PROVIDER_ID.test(via)) out.via = via;
|
|
76
48
|
return out;
|
|
77
49
|
}
|