@coffre/ui 0.6.1 → 0.6.2
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/chunks/{audit-sentence-CUUMshIp.js → audit-sentence-BVv_9_nq.js} +2 -2
- package/dist/chunks/{audit-sentence-CUUMshIp.js.map → audit-sentence-BVv_9_nq.js.map} +1 -1
- package/dist/chunks/{connected-apps-DTpatjge.js → connected-apps-rBF9XUob.js} +4 -4
- package/dist/chunks/{connected-apps-DTpatjge.js.map → connected-apps-rBF9XUob.js.map} +1 -1
- package/dist/chunks/{delete-place-SOOYVt6A.js → delete-place-CkGezx5R.js} +4 -4
- package/dist/chunks/{delete-place-SOOYVt6A.js.map → delete-place-CkGezx5R.js.map} +1 -1
- package/dist/chunks/{directory-DrtdKny2.js → directory-SRN01yP6.js} +21 -19
- package/dist/chunks/directory-SRN01yP6.js.map +1 -0
- package/dist/chunks/{folders-hR2Lnk0k.js → folders-Dw240WMJ.js} +2 -2
- package/dist/chunks/{folders-hR2Lnk0k.js.map → folders-Dw240WMJ.js.map} +1 -1
- package/dist/chunks/{grants-DDBui9YD.js → grants-1E1vqkM0.js} +5 -5
- package/dist/chunks/{grants-DDBui9YD.js.map → grants-1E1vqkM0.js.map} +1 -1
- package/dist/chunks/multi-combobox-CsIXihuc.js +99 -0
- package/dist/chunks/multi-combobox-CsIXihuc.js.map +1 -0
- package/dist/chunks/{offboarding-C7ECW5o0.js → offboarding-Bt7KSixm.js} +3 -3
- package/dist/chunks/{offboarding-C7ECW5o0.js.map → offboarding-Bt7KSixm.js.map} +1 -1
- package/dist/chunks/{principal-page-CB6dAABC.js → principal-page-Cbx2l6XL.js} +21 -24
- package/dist/chunks/principal-page-Cbx2l6XL.js.map +1 -0
- package/dist/chunks/{project-page-BHNUvr2L.js → project-page-DKo2AFYg.js} +2 -2
- package/dist/chunks/{project-page-BHNUvr2L.js.map → project-page-DKo2AFYg.js.map} +1 -1
- package/dist/chunks/{queries-DgQo3mC-.js → queries-BvSw1xBN.js} +85 -14
- package/dist/chunks/queries-BvSw1xBN.js.map +1 -0
- package/dist/chunks/{references-BQc35Q9g.js → references-DCoSPtvw.js} +4 -4
- package/dist/chunks/{references-BQc35Q9g.js.map → references-DCoSPtvw.js.map} +1 -1
- package/dist/chunks/{role-field-BfWRCqzl.js → role-field-D98CvNEg.js} +2 -2
- package/dist/chunks/{role-field-BfWRCqzl.js.map → role-field-D98CvNEg.js.map} +1 -1
- package/dist/chunks/{row-state-Zf3kZVhd.js → row-state-BsIHspy4.js} +2 -2
- package/dist/chunks/{row-state-Zf3kZVhd.js.map → row-state-BsIHspy4.js.map} +1 -1
- package/dist/chunks/{theme-B6-V9JvY.js → theme-3b4DnCow.js} +2 -2
- package/dist/chunks/{theme-B6-V9JvY.js.map → theme-3b4DnCow.js.map} +1 -1
- package/dist/chunks/{ui-Br-dNUTc.js → ui-2kwXXfrX.js} +95 -22
- package/dist/chunks/ui-2kwXXfrX.js.map +1 -0
- package/dist/chunks/{use-action-DthL5hL8.js → use-action-Bv7yQ0DW.js} +2 -2
- package/dist/chunks/{use-action-DthL5hL8.js.map → use-action-Bv7yQ0DW.js.map} +1 -1
- package/dist/chunks/{use-change-By4cG8bT.js → use-change-DIQTGXER.js} +58 -17
- package/dist/chunks/use-change-DIQTGXER.js.map +1 -0
- package/dist/chunks/{use-shell-D6kjSPls.js → use-shell-DhFoHjDS.js} +2 -2
- package/dist/chunks/{use-shell-D6kjSPls.js.map → use-shell-DhFoHjDS.js.map} +1 -1
- package/dist/index.d.ts +13 -164
- package/dist/index.js +141 -128
- package/dist/index.js.map +1 -1
- package/dist/pages/account.js +8 -8
- package/dist/pages/approval.js +1 -1
- package/dist/pages/audit.js +46 -60
- package/dist/pages/audit.js.map +1 -1
- package/dist/pages/device-login.js +1 -1
- package/dist/pages/environment.js +444 -235
- package/dist/pages/environment.js.map +1 -1
- package/dist/pages/login.js +2 -2
- package/dist/pages/oauth-authorize.js +1 -1
- package/dist/pages/project-access.js +8 -8
- package/dist/pages/project-environments.js +19 -58
- package/dist/pages/project-environments.js.map +1 -1
- package/dist/pages/project-settings.d.ts +1 -1
- package/dist/pages/project-settings.js +54 -75
- package/dist/pages/project-settings.js.map +1 -1
- package/dist/pages/project.js +3 -7
- package/dist/pages/project.js.map +1 -1
- package/dist/pages/projects.js +50 -77
- package/dist/pages/projects.js.map +1 -1
- package/dist/pages/service-account.js +11 -136
- package/dist/pages/service-account.js.map +1 -1
- package/dist/pages/service-accounts.js +4 -4
- package/dist/pages/settings.js +5 -5
- package/dist/pages/unregistered.js +1 -1
- package/dist/pages/user.js +5 -5
- package/dist/pages/users.js +4 -4
- package/package.json +3 -3
- package/src/components/actions-log.tsx +1 -1
- package/src/components/command-palette.tsx +4 -5
- package/src/components/directory.tsx +6 -14
- package/src/components/missing.tsx +63 -67
- package/src/components/principal-page.tsx +10 -14
- package/src/components/service-tokens.tsx +2 -11
- package/src/components/shell.tsx +79 -75
- package/src/components/trusted-workloads.tsx +2 -11
- package/src/components/ui.tsx +35 -25
- package/src/lib/changes.ts +63 -12
- package/src/lib/clipboard.ts +40 -0
- package/src/lib/copy-attempts.ts +103 -0
- package/src/lib/dismissal.ts +24 -0
- package/src/lib/optimistic.ts +3 -1
- package/src/lib/queries.ts +106 -13
- package/src/lib/row-reads.ts +64 -0
- package/src/options.ts +38 -50
- package/src/pages/audit.tsx +15 -24
- package/src/pages/environment.tsx +307 -91
- package/src/pages/project-environments.tsx +8 -34
- package/src/pages/project-settings.tsx +9 -20
- package/src/pages/project.tsx +1 -5
- package/src/pages/projects.tsx +13 -28
- package/src/parity.ts +3 -3
- package/src/styles/globals.css +87 -128
- package/dist/chunks/directory-DrtdKny2.js.map +0 -1
- package/dist/chunks/principal-page-CB6dAABC.js.map +0 -1
- package/dist/chunks/project-environments-lEzFHUt4.js +0 -11
- package/dist/chunks/project-environments-lEzFHUt4.js.map +0 -1
- package/dist/chunks/queries-DgQo3mC-.js.map +0 -1
- package/dist/chunks/ui-Br-dNUTc.js.map +0 -1
- package/dist/chunks/use-change-By4cG8bT.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ageInDays, byFolder, CoffreError, foldersOf, olderThan, planImport, shownMember, type CoffreClient, type ListedReference } from '@coffre/client';
|
|
2
2
|
import { parseDotenv } from '@coffre/core/dotenv';
|
|
3
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
4
|
-
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
|
|
3
|
+
import { useEffect, useReducer, useRef, useState, type ReactNode } from 'react';
|
|
4
|
+
import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
5
5
|
import { Link } from '@tanstack/react-router';
|
|
6
6
|
import { useShell } from '../lib/use-shell';
|
|
7
7
|
import { Menu } from '@base-ui/react/menu';
|
|
8
8
|
import { toast } from 'sonner';
|
|
9
9
|
import { failureMessage, useCoffre } from '../lib/coffre';
|
|
10
|
-
import { archiveSecret, moveSecret, restoreSecret, saveSecrets, UnsavedEdits } from '../lib/changes';
|
|
11
|
-
import type
|
|
10
|
+
import { archiveSecret, moveSecret, restoreSecret, saveSecrets, UnsavedEdits, type SaveSecretsVars } from '../lib/changes';
|
|
11
|
+
import { changeKey, type ItemStatus } from '../lib/optimistic';
|
|
12
12
|
import { affects, keys as queryKeys, queries } from '../lib/queries';
|
|
13
13
|
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
14
14
|
import { RowFailure, RowPending, rowClass } from '../components/row-state';
|
|
@@ -29,10 +29,12 @@ import {
|
|
|
29
29
|
type SecretChange,
|
|
30
30
|
type SecretDraft,
|
|
31
31
|
} from '../lib/secret-edit-batch';
|
|
32
|
+
import { createCopier } from '../lib/copy-attempts';
|
|
32
33
|
import { revealIsCurrent, type Reveal } from '../lib/reveal';
|
|
34
|
+
import { noReads, revealToggleDisabled, rowReads } from '../lib/row-reads';
|
|
33
35
|
import { sortKeys, type Sort } from '../lib/secret-order';
|
|
34
36
|
import { inDialog } from '../lib/shortcuts';
|
|
35
|
-
import { secretKeyProblem } from '../lib/validation';
|
|
37
|
+
import { folderProblem, secretKeyProblem } from '../lib/validation';
|
|
36
38
|
import {
|
|
37
39
|
breakAfterUnderscores,
|
|
38
40
|
ConfirmButton,
|
|
@@ -53,6 +55,7 @@ import { GenerateValue, type GeneratedUse } from '../components/generate-value';
|
|
|
53
55
|
import { MaskedInput, MaskedTextarea } from '../components/masked';
|
|
54
56
|
import { FolderMenu, FolderRow, MoveToFolder } from '../components/folders';
|
|
55
57
|
import { MissingKeys } from '../components/missing';
|
|
58
|
+
import { MultiCombobox } from '../components/multi-combobox';
|
|
56
59
|
import { ArchiveBlocked, archiveBlockers, LentReferences, MakeReference, ReferenceValue } from '../components/references';
|
|
57
60
|
import { isActiveAccessibleEnvironment } from '../lib/project-environments';
|
|
58
61
|
import {
|
|
@@ -95,6 +98,13 @@ const Route = pageRoute<typeof environment>();
|
|
|
95
98
|
*/
|
|
96
99
|
const REVEAL_TTL_SECONDS = 45;
|
|
97
100
|
|
|
101
|
+
/** Why a read of a secret's value failed, as the row says it. */
|
|
102
|
+
function readFailureMessage(failure: unknown): string {
|
|
103
|
+
return failure instanceof CoffreError
|
|
104
|
+
? failureMessage(failure)
|
|
105
|
+
: 'The request could not be sent. Nothing was read.';
|
|
106
|
+
}
|
|
107
|
+
|
|
98
108
|
export function EnvironmentPage() {
|
|
99
109
|
const { project, environment } = Route.useParams();
|
|
100
110
|
const { data: result } = useSuspenseQuery(queries.secrets(useCoffre(), { project, environment }));
|
|
@@ -152,6 +162,7 @@ function EnvironmentLedger({
|
|
|
152
162
|
rotateAfterDays: number | null;
|
|
153
163
|
}) {
|
|
154
164
|
const coffre = useCoffre();
|
|
165
|
+
const queryClient = useQueryClient();
|
|
155
166
|
const { principal } = useShell();
|
|
156
167
|
const save = useChange(saveSecrets(coffre, { project, environment }, principal?.id ?? null));
|
|
157
168
|
const restore = useChange(restoreSecret(coffre, { project, environment }));
|
|
@@ -179,6 +190,7 @@ function EnvironmentLedger({
|
|
|
179
190
|
const [sort, setSort] = useState<Sort>({ by: 'key', descending: false });
|
|
180
191
|
// A column's first click sorts it ascending: names A to Z, the oldest values first.
|
|
181
192
|
const sortBy = (by: Sort['by']) => setSort((current) => ({ by, descending: current.by === by && !current.descending }));
|
|
193
|
+
const [addingFolder, setAddingFolder] = useState(false);
|
|
182
194
|
const nextDraftId = useRef(0);
|
|
183
195
|
|
|
184
196
|
const canWrite = permissions.includes('secret.write');
|
|
@@ -188,6 +200,10 @@ function EnvironmentLedger({
|
|
|
188
200
|
// Listed by folder: those in none first, then each folder by name.
|
|
189
201
|
const active = byFolder(keys.filter((entry) => !entry.archived)).flatMap(([, entries]) => entries);
|
|
190
202
|
const folders = foldersOf(active);
|
|
203
|
+
// What can be filed now: not a secret whose save is on its way, which may
|
|
204
|
+
// not exist yet, nor one with an edit pending, as its menu offers no move
|
|
205
|
+
// while it is edited.
|
|
206
|
+
const settled = active.filter((entry) => status(entry.key).state !== 'pending' && secretChangeFor(changes, entry.key) === undefined);
|
|
191
207
|
// Renaming or removing a folder: everything in it at once, the keys staying where they are.
|
|
192
208
|
const refile = useAction();
|
|
193
209
|
const place = `${project}/${environment}`;
|
|
@@ -285,6 +301,7 @@ function EnvironmentLedger({
|
|
|
285
301
|
save(batch, {
|
|
286
302
|
// What did not go comes back as it was, beside the other pending rows.
|
|
287
303
|
onError: (error) => {
|
|
304
|
+
forgetRefusal(batch);
|
|
288
305
|
const left = error instanceof UnsavedEdits ? error.outcome : batch;
|
|
289
306
|
setDrafts((rows) => [...rows, ...left.drafts]);
|
|
290
307
|
setChanges((current) => ({ ...current, ...left.changes }));
|
|
@@ -315,11 +332,16 @@ function EnvironmentLedger({
|
|
|
315
332
|
setChanges({});
|
|
316
333
|
setEditing(new Set());
|
|
317
334
|
setSaveError(null);
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* A refused save leaves its rows no failure of their own: its edits come
|
|
339
|
+
* back on them, and the bar under the table says why. Every other refused
|
|
340
|
+
* change, a move for one, says why beneath its row.
|
|
341
|
+
*/
|
|
342
|
+
function forgetRefusal(batch: SaveSecretsVars) {
|
|
343
|
+
const saves = queryClient.getMutationCache().findAll({ mutationKey: changeKey(queryKeys.secrets({ project, environment })) });
|
|
344
|
+
for (const each of saves) if (each.state.variables === batch) dismiss(each.mutationId);
|
|
323
345
|
}
|
|
324
346
|
|
|
325
347
|
/**
|
|
@@ -327,7 +349,7 @@ function EnvironmentLedger({
|
|
|
327
349
|
* rest as one patch that lands whole or not at all. The edits show in the
|
|
328
350
|
* list at once, each row marked as saving; whatever did not land comes
|
|
329
351
|
* back as pending, so pressing save again retries exactly that, and the
|
|
330
|
-
*
|
|
352
|
+
* bar under the table says why.
|
|
331
353
|
*/
|
|
332
354
|
function saveChanges() {
|
|
333
355
|
if (!ready) return;
|
|
@@ -338,6 +360,7 @@ function EnvironmentLedger({
|
|
|
338
360
|
setSaveError(null);
|
|
339
361
|
save(batch, {
|
|
340
362
|
onError: (error) => {
|
|
363
|
+
forgetRefusal(batch);
|
|
341
364
|
const left = error instanceof UnsavedEdits ? error.outcome : batch;
|
|
342
365
|
setDrafts(left.drafts);
|
|
343
366
|
setChanges(left.changes);
|
|
@@ -410,7 +433,7 @@ function EnvironmentLedger({
|
|
|
410
433
|
: null;
|
|
411
434
|
|
|
412
435
|
// Filtering narrows what is listed, never what is saved: a pending edit on
|
|
413
|
-
// a row the filter hides still counts, and still shows in the
|
|
436
|
+
// a row the filter hides still counts, and still shows in the bar under the table.
|
|
414
437
|
const needle = query.trim().toLowerCase();
|
|
415
438
|
const listed = sortKeys(
|
|
416
439
|
needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)),
|
|
@@ -420,11 +443,7 @@ function EnvironmentLedger({
|
|
|
420
443
|
|
|
421
444
|
return (
|
|
422
445
|
<>
|
|
423
|
-
<PageHeader
|
|
424
|
-
tile={project}
|
|
425
|
-
title={environment}
|
|
426
|
-
aside={<EnvironmentName project={project} environment={environment} />}
|
|
427
|
-
/>
|
|
446
|
+
<PageHeader tile={project} title={environment} />
|
|
428
447
|
|
|
429
448
|
{(active.length > 0 || drafts.length > 0) && (
|
|
430
449
|
<div className="toolbar">
|
|
@@ -532,6 +551,7 @@ function EnvironmentLedger({
|
|
|
532
551
|
status={state}
|
|
533
552
|
// Not while its save is on its way.
|
|
534
553
|
disabled={state.state === 'pending'}
|
|
554
|
+
onDismiss={dismiss}
|
|
535
555
|
columns={columns}
|
|
536
556
|
onEdit={() => setEditing((current) => new Set(current).add(entry.key))}
|
|
537
557
|
onPatch={(patch) => patchChange(entry, patch)}
|
|
@@ -586,15 +606,33 @@ function EnvironmentLedger({
|
|
|
586
606
|
</table>
|
|
587
607
|
</div>
|
|
588
608
|
)}
|
|
609
|
+
{pendingCount > 0 && (
|
|
610
|
+
<PendingBar
|
|
611
|
+
pending={pending}
|
|
612
|
+
ready={ready}
|
|
613
|
+
error={saveError ?? problem}
|
|
614
|
+
onDiscard={discardAll}
|
|
615
|
+
onSave={saveChanges}
|
|
616
|
+
/>
|
|
617
|
+
)}
|
|
589
618
|
</section>
|
|
590
619
|
|
|
591
620
|
{canWrite && (
|
|
592
621
|
<div className="table-actions">
|
|
593
|
-
<
|
|
594
|
-
<Plus size={14} />
|
|
595
|
-
New secret
|
|
596
|
-
</button>
|
|
622
|
+
<AddButton onAddSecret={() => addDraft()} onAddFolder={() => setAddingFolder(true)} canAddFolder={settled.length > 0} />
|
|
597
623
|
{canReveal && <ImportEnv project={project} environment={environment} />}
|
|
624
|
+
<AddFolder
|
|
625
|
+
open={addingFolder}
|
|
626
|
+
onOpenChange={setAddingFolder}
|
|
627
|
+
keys={settled.map((entry) => entry.key)}
|
|
628
|
+
folders={folders}
|
|
629
|
+
onAdd={(folder, keys) => {
|
|
630
|
+
// As things stand on submit: a secret whose save started since the dialog opened is left out, not raced.
|
|
631
|
+
for (const entry of settled) {
|
|
632
|
+
if (keys.includes(entry.key) && entry.folder !== folder) move({ key: entry.key, folder });
|
|
633
|
+
}
|
|
634
|
+
}}
|
|
635
|
+
/>
|
|
598
636
|
</div>
|
|
599
637
|
)}
|
|
600
638
|
|
|
@@ -654,56 +692,188 @@ function EnvironmentLedger({
|
|
|
654
692
|
</Card>
|
|
655
693
|
)}
|
|
656
694
|
|
|
657
|
-
{pendingCount > 0 && (
|
|
658
|
-
<div className="savebar" role="region" aria-label="Unsaved changes">
|
|
659
|
-
<div className="savebar-inner">
|
|
660
|
-
<span className="savebar-count">
|
|
661
|
-
<span className="dot" aria-hidden />
|
|
662
|
-
{pendingCount} unsaved change{pendingCount === 1 ? '' : 's'}
|
|
663
|
-
</span>
|
|
664
|
-
<span className="savebar-summary">
|
|
665
|
-
{pending.slice(0, 3).map((item, index) => (
|
|
666
|
-
<span key={`${item.key}:${index}`}>
|
|
667
|
-
{index > 0 && ' · '}
|
|
668
|
-
<span className="mono">{item.key}</span> {item.what}
|
|
669
|
-
</span>
|
|
670
|
-
))}
|
|
671
|
-
{pending.length > 3 && ` · and ${pending.length - 3} more`}
|
|
672
|
-
</span>
|
|
673
|
-
<div className="savebar-actions">
|
|
674
|
-
<button className="btn btn-sm" onClick={discardAll}>
|
|
675
|
-
Discard
|
|
676
|
-
</button>
|
|
677
|
-
<button
|
|
678
|
-
className="btn btn-sm btn-primary"
|
|
679
|
-
onClick={saveChanges}
|
|
680
|
-
disabled={!ready}
|
|
681
|
-
title="Save (⌘ Enter or Ctrl Enter)"
|
|
682
|
-
aria-keyshortcuts="Meta+Enter Control+Enter"
|
|
683
|
-
>
|
|
684
|
-
Save {pendingCount === 1 ? 'change' : `${pendingCount} changes`}
|
|
685
|
-
</button>
|
|
686
|
-
</div>
|
|
687
|
-
{(saveError ?? problem) !== null && (
|
|
688
|
-
<p className="savebar-error" role="alert">
|
|
689
|
-
<AlertCircle size={14} />
|
|
690
|
-
<span>{saveError ?? problem}</span>
|
|
691
|
-
</p>
|
|
692
|
-
)}
|
|
693
|
-
</div>
|
|
694
|
-
</div>
|
|
695
|
-
)}
|
|
696
695
|
</>
|
|
697
696
|
);
|
|
698
697
|
}
|
|
699
698
|
|
|
700
|
-
/**
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
699
|
+
/**
|
|
700
|
+
* The pending edits, at the foot of the table they are made in: what they
|
|
701
|
+
* are, Discard and Save. It sticks to the bottom of the window while the
|
|
702
|
+
* table runs past it, so Save stays in reach of any row.
|
|
703
|
+
*/
|
|
704
|
+
function PendingBar({
|
|
705
|
+
pending,
|
|
706
|
+
ready,
|
|
707
|
+
error,
|
|
708
|
+
onDiscard,
|
|
709
|
+
onSave,
|
|
710
|
+
}: {
|
|
711
|
+
pending: Pending[];
|
|
712
|
+
ready: boolean;
|
|
713
|
+
/** Why the last save failed, or why this one cannot go yet. */
|
|
714
|
+
error: string | null;
|
|
715
|
+
onDiscard: () => void;
|
|
716
|
+
onSave: () => void;
|
|
717
|
+
}) {
|
|
718
|
+
const count = pending.length;
|
|
719
|
+
return (
|
|
720
|
+
<div className="pending-bar" role="region" aria-label="Unsaved changes">
|
|
721
|
+
<span className="pending-count">
|
|
722
|
+
<span className="dot" aria-hidden />
|
|
723
|
+
{count} unsaved change{count === 1 ? '' : 's'}
|
|
724
|
+
</span>
|
|
725
|
+
<span className="pending-summary">
|
|
726
|
+
{pending.slice(0, 3).map((item, index) => (
|
|
727
|
+
<span key={`${item.key}:${index}`}>
|
|
728
|
+
{index > 0 && ' · '}
|
|
729
|
+
<span className="mono">{item.key}</span> {item.what}
|
|
730
|
+
</span>
|
|
731
|
+
))}
|
|
732
|
+
{count > 3 && ` · and ${count - 3} more`}
|
|
733
|
+
</span>
|
|
734
|
+
<div className="pending-actions">
|
|
735
|
+
<button className="btn btn-sm" onClick={onDiscard}>
|
|
736
|
+
Discard
|
|
737
|
+
</button>
|
|
738
|
+
<button
|
|
739
|
+
className="btn btn-sm btn-primary"
|
|
740
|
+
onClick={onSave}
|
|
741
|
+
disabled={!ready}
|
|
742
|
+
title="Save (⌘ Enter or Ctrl Enter)"
|
|
743
|
+
aria-keyshortcuts="Meta+Enter Control+Enter"
|
|
744
|
+
>
|
|
745
|
+
Save {count === 1 ? 'change' : `${count} changes`}
|
|
746
|
+
</button>
|
|
747
|
+
</div>
|
|
748
|
+
{error !== null && (
|
|
749
|
+
<p className="pending-error" role="alert">
|
|
750
|
+
<AlertCircle size={14} />
|
|
751
|
+
<span>{error}</span>
|
|
752
|
+
</p>
|
|
753
|
+
)}
|
|
754
|
+
</div>
|
|
755
|
+
);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Add secret, and beside it a menu of the other things to add: a folder.
|
|
760
|
+
* One button in look, two to the keyboard and to a screen reader, the
|
|
761
|
+
* second a menu button.
|
|
762
|
+
*/
|
|
763
|
+
function AddButton({
|
|
764
|
+
onAddSecret,
|
|
765
|
+
onAddFolder,
|
|
766
|
+
canAddFolder,
|
|
767
|
+
}: {
|
|
768
|
+
onAddSecret: () => void;
|
|
769
|
+
onAddFolder: () => void;
|
|
770
|
+
/** Whether there is a secret to file in a new folder. */
|
|
771
|
+
canAddFolder: boolean;
|
|
772
|
+
}) {
|
|
773
|
+
return (
|
|
774
|
+
<div className="split-button">
|
|
775
|
+
<button className="btn btn-primary" onClick={onAddSecret}>
|
|
776
|
+
<Plus size={14} />
|
|
777
|
+
Add secret
|
|
778
|
+
</button>
|
|
779
|
+
<Menu.Root>
|
|
780
|
+
<Menu.Trigger className="btn btn-primary btn-icon" aria-label="More to add">
|
|
781
|
+
<ChevronDown size={14} />
|
|
782
|
+
</Menu.Trigger>
|
|
783
|
+
<MenuPopup align="start">
|
|
784
|
+
<Menu.Item className="menu-item" onClick={onAddFolder} disabled={!canAddFolder}>
|
|
785
|
+
<Folder size={14} />
|
|
786
|
+
Add folder…
|
|
787
|
+
{!canAddFolder && <span className="menu-hint">after a secret</span>}
|
|
788
|
+
</Menu.Item>
|
|
789
|
+
</MenuPopup>
|
|
790
|
+
</Menu.Root>
|
|
791
|
+
</div>
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* A new folder, and the secrets filed in it. A folder is a name on what it
|
|
797
|
+
* holds (docs/design/environments.md), so it is made with its first
|
|
798
|
+
* secrets: one with nothing in it would not be there to see.
|
|
799
|
+
*/
|
|
800
|
+
function AddFolder({
|
|
801
|
+
open,
|
|
802
|
+
onOpenChange,
|
|
803
|
+
keys,
|
|
804
|
+
folders,
|
|
805
|
+
onAdd,
|
|
806
|
+
}: {
|
|
807
|
+
open: boolean;
|
|
808
|
+
onOpenChange: (open: boolean) => void;
|
|
809
|
+
/** The secrets that can be filed, by name. */
|
|
810
|
+
keys: readonly string[];
|
|
811
|
+
/** The folders in use, which a name already in use joins. */
|
|
812
|
+
folders: readonly string[];
|
|
813
|
+
onAdd: (folder: string, keys: string[]) => void;
|
|
814
|
+
}) {
|
|
815
|
+
const [name, setName] = useState('');
|
|
816
|
+
const [chosen, setChosen] = useState<string[]>([]);
|
|
817
|
+
useEffect(() => {
|
|
818
|
+
if (!open) return;
|
|
819
|
+
setName('');
|
|
820
|
+
setChosen([]);
|
|
821
|
+
}, [open]);
|
|
822
|
+
const problem = folderProblem(name);
|
|
823
|
+
const joins = folders.includes(name);
|
|
824
|
+
const ready = name !== '' && problem === null && chosen.length > 0;
|
|
825
|
+
|
|
826
|
+
return (
|
|
827
|
+
<Modal
|
|
828
|
+
open={open}
|
|
829
|
+
onOpenChange={onOpenChange}
|
|
830
|
+
title="Add a folder"
|
|
831
|
+
description="Folders only arrange the list: names, values and access stay as they are."
|
|
832
|
+
>
|
|
833
|
+
<form
|
|
834
|
+
className="form"
|
|
835
|
+
onSubmit={(event) => {
|
|
836
|
+
event.preventDefault();
|
|
837
|
+
if (!ready) return;
|
|
838
|
+
onAdd(name, chosen);
|
|
839
|
+
onOpenChange(false);
|
|
840
|
+
}}
|
|
841
|
+
>
|
|
842
|
+
<label className="field">
|
|
843
|
+
<span className="label">Name</span>
|
|
844
|
+
<input
|
|
845
|
+
className="input"
|
|
846
|
+
autoFocus
|
|
847
|
+
spellCheck={false}
|
|
848
|
+
autoComplete="off"
|
|
849
|
+
value={name}
|
|
850
|
+
aria-invalid={problem !== null}
|
|
851
|
+
onChange={(event) => setName(event.target.value)}
|
|
852
|
+
/>
|
|
853
|
+
<span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
|
|
854
|
+
{problem ?? (joins ? `${name} is in use: the secrets join it.` : 'One level: no slash.')}
|
|
855
|
+
</span>
|
|
856
|
+
</label>
|
|
857
|
+
<MultiCombobox
|
|
858
|
+
label="Secrets in it"
|
|
859
|
+
options={keys}
|
|
860
|
+
value={chosen}
|
|
861
|
+
onChange={setChosen}
|
|
862
|
+
placeholder="Pick one or more…"
|
|
863
|
+
hint="A folder holds at least one secret."
|
|
864
|
+
mono
|
|
865
|
+
/>
|
|
866
|
+
<div className="dialog-actions">
|
|
867
|
+
<button className="btn" type="button" onClick={() => onOpenChange(false)}>
|
|
868
|
+
Cancel
|
|
869
|
+
</button>
|
|
870
|
+
<button className="btn btn-primary" type="submit" disabled={!ready}>
|
|
871
|
+
Add folder
|
|
872
|
+
</button>
|
|
873
|
+
</div>
|
|
874
|
+
</form>
|
|
875
|
+
</Modal>
|
|
876
|
+
);
|
|
707
877
|
}
|
|
708
878
|
|
|
709
879
|
/* -------------------------------------------------------------------------- */
|
|
@@ -891,6 +1061,7 @@ function SecretRow({
|
|
|
891
1061
|
environments,
|
|
892
1062
|
status,
|
|
893
1063
|
disabled,
|
|
1064
|
+
onDismiss,
|
|
894
1065
|
columns,
|
|
895
1066
|
onEdit,
|
|
896
1067
|
onPatch,
|
|
@@ -920,6 +1091,8 @@ function SecretRow({
|
|
|
920
1091
|
/** A save of this row on its way, or refused. */
|
|
921
1092
|
status: ItemStatus;
|
|
922
1093
|
disabled: boolean;
|
|
1094
|
+
/** Forget a refused change once its row has said so. */
|
|
1095
|
+
onDismiss: (mutationId: number) => void;
|
|
923
1096
|
columns: number;
|
|
924
1097
|
onEdit: () => void;
|
|
925
1098
|
onPatch: (patch: Partial<SecretChange>) => void;
|
|
@@ -931,9 +1104,10 @@ function SecretRow({
|
|
|
931
1104
|
saveReady: boolean;
|
|
932
1105
|
onMarkArchive: () => void;
|
|
933
1106
|
}) {
|
|
934
|
-
const [
|
|
1107
|
+
const [reads, dispatch] = useReducer(rowReads, noReads);
|
|
1108
|
+
const { reveal, revealing, error, copyError } = reads;
|
|
1109
|
+
const setReveal = (next: Reveal | null) => dispatch({ type: 'set-reveal', reveal: next });
|
|
935
1110
|
const coffre = useCoffre();
|
|
936
|
-
const [revealing, setRevealing] = useState(false);
|
|
937
1111
|
const [historyOpen, setHistoryOpen] = useState(false);
|
|
938
1112
|
const [moving, setMoving] = useState(false);
|
|
939
1113
|
const [referring, setReferring] = useState(false);
|
|
@@ -948,7 +1122,6 @@ function SecretRow({
|
|
|
948
1122
|
// What a reveal shows: its own version, or, as a reference, its source's.
|
|
949
1123
|
const readVersion = reference === null ? entry.version : reference.version;
|
|
950
1124
|
const holderPath = `${project}/${environment}/${entry.key}`;
|
|
951
|
-
const [error, setError] = useState<string | null>(null);
|
|
952
1125
|
// The current value, loaded on request as the starting point for an edit.
|
|
953
1126
|
// It is not a change until it is edited: saving it untouched would append a
|
|
954
1127
|
// version identical to the one it came from.
|
|
@@ -978,30 +1151,64 @@ function SecretRow({
|
|
|
978
1151
|
|
|
979
1152
|
async function readValue({ show = true } = {}): Promise<string | null> {
|
|
980
1153
|
if (shown !== null) return shown.value;
|
|
981
|
-
|
|
1154
|
+
dispatch({ type: 'read-started' });
|
|
982
1155
|
try {
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
1156
|
+
const value = await fetchValue();
|
|
1157
|
+
dispatch({
|
|
1158
|
+
type: 'read-succeeded',
|
|
1159
|
+
reveal: show ? { value, version: readVersion, at: Date.now() } : null,
|
|
1160
|
+
});
|
|
987
1161
|
return value;
|
|
988
1162
|
} catch (failure) {
|
|
989
|
-
|
|
990
|
-
failure instanceof CoffreError
|
|
991
|
-
? failureMessage(failure)
|
|
992
|
-
: 'The request could not be sent. Nothing was read.',
|
|
993
|
-
);
|
|
1163
|
+
dispatch({ type: 'read-failed', message: readFailureMessage(failure) });
|
|
994
1164
|
return null;
|
|
995
|
-
} finally {
|
|
996
|
-
setRevealing(false);
|
|
997
1165
|
}
|
|
998
1166
|
}
|
|
999
1167
|
|
|
1168
|
+
async function fetchValue(): Promise<string> {
|
|
1169
|
+
const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
|
|
1170
|
+
return values[entry.key];
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1000
1173
|
function toggleReveal() {
|
|
1001
1174
|
if (shown !== null) setReveal(null);
|
|
1002
1175
|
else void readValue();
|
|
1003
1176
|
}
|
|
1004
1177
|
|
|
1178
|
+
// Copy reads a hidden value the way Reveal does (the same audited read) and hands
|
|
1179
|
+
// it to the clipboard, never to the screen or to the row's reveal state: it shares
|
|
1180
|
+
// nothing with Reveal but the endpoint, so neither can change whether a value is
|
|
1181
|
+
// shown or Hide can be pressed. Copies do not lock each other out; the latest one
|
|
1182
|
+
// wins. The row holds the copier, which a remount of the button does not reset,
|
|
1183
|
+
// and only the latest copy may set `copyError` or the button's feedback.
|
|
1184
|
+
const [copier] = useState(() => createCopier());
|
|
1185
|
+
function copyValue() {
|
|
1186
|
+
dispatch({ type: 'copy-started' });
|
|
1187
|
+
// What a failed read said, if the read is what failed rather than the clipboard.
|
|
1188
|
+
const read: { failed: boolean; failure?: unknown } = { failed: false };
|
|
1189
|
+
const text =
|
|
1190
|
+
shown !== null
|
|
1191
|
+
? shown.value
|
|
1192
|
+
: fetchValue().catch((failure: unknown) => {
|
|
1193
|
+
read.failed = true;
|
|
1194
|
+
read.failure = failure;
|
|
1195
|
+
throw failure;
|
|
1196
|
+
});
|
|
1197
|
+
void copier.run(text).then((result) => {
|
|
1198
|
+
if (result.outcome === 'superseded') return;
|
|
1199
|
+
dispatch(
|
|
1200
|
+
result.outcome === 'copied'
|
|
1201
|
+
? { type: 'copy-succeeded' }
|
|
1202
|
+
: {
|
|
1203
|
+
type: 'copy-failed',
|
|
1204
|
+
message: read.failed
|
|
1205
|
+
? readFailureMessage(read.failure)
|
|
1206
|
+
: 'The browser did not allow copying to the clipboard. Reveal the value and copy it by hand.',
|
|
1207
|
+
},
|
|
1208
|
+
);
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1005
1212
|
// An edit starts from the current value, read the way Reveal reads it, so
|
|
1006
1213
|
// the audit log shows who opened it. One that cannot be read starts empty.
|
|
1007
1214
|
const [opening, setOpening] = useState(false);
|
|
@@ -1162,16 +1369,17 @@ function SecretRow({
|
|
|
1162
1369
|
</>
|
|
1163
1370
|
) : (
|
|
1164
1371
|
<>
|
|
1165
|
-
{/* Copy
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1372
|
+
{/* Copy sits left of Reveal, hidden or shown, so Hide stays where
|
|
1373
|
+
Reveal was clicked. Hidden, it copies without showing the value;
|
|
1374
|
+
as for Reveal, it takes secret.read, and a reference copies the
|
|
1375
|
+
value it reads through. */}
|
|
1169
1376
|
<SecretReadOnly canReveal={canReveal}>
|
|
1377
|
+
<CopyButton variant="act" copier={copier} onCopy={copyValue} label={`Copy ${entry.key}`} />
|
|
1170
1378
|
<Tip label={shown === null ? 'Reveal' : 'Hide'}>
|
|
1171
1379
|
<button
|
|
1172
1380
|
className="act act-icon act-accent"
|
|
1173
1381
|
onClick={toggleReveal}
|
|
1174
|
-
disabled={
|
|
1382
|
+
disabled={revealToggleDisabled(reads, shown)}
|
|
1175
1383
|
aria-label={`${shown === null ? 'Reveal' : 'Hide'} ${entry.key}`}
|
|
1176
1384
|
>
|
|
1177
1385
|
{revealing && !opening ? (
|
|
@@ -1371,13 +1579,21 @@ function SecretRow({
|
|
|
1371
1579
|
</tr>
|
|
1372
1580
|
)}
|
|
1373
1581
|
|
|
1374
|
-
{(error ?? actError) !== null
|
|
1582
|
+
{(error ?? actError) !== null || copyError !== null ? (
|
|
1375
1583
|
<tr className="row-error">
|
|
1376
1584
|
<td colSpan={columns}>
|
|
1377
|
-
|
|
1585
|
+
{/* Reveal's refusal and Copy's are independent: neither hides the other. */}
|
|
1586
|
+
<ErrorLine error={error ?? actError} />
|
|
1587
|
+
<ErrorLine error={copyError} />
|
|
1378
1588
|
</td>
|
|
1379
1589
|
</tr>
|
|
1380
|
-
)}
|
|
1590
|
+
) : null}
|
|
1591
|
+
|
|
1592
|
+
<RowFailure
|
|
1593
|
+
status={status}
|
|
1594
|
+
columns={columns}
|
|
1595
|
+
onDismiss={() => status.state === 'failed' && onDismiss(status.mutationId)}
|
|
1596
|
+
/>
|
|
1381
1597
|
</>
|
|
1382
1598
|
);
|
|
1383
1599
|
}
|
|
@@ -1505,7 +1721,7 @@ function DraftRow({
|
|
|
1505
1721
|
<input
|
|
1506
1722
|
className="input input-mono"
|
|
1507
1723
|
// Only the row that just mounted takes focus, which is the one the
|
|
1508
|
-
//
|
|
1724
|
+
// Add secret button created.
|
|
1509
1725
|
autoFocus
|
|
1510
1726
|
aria-label="Name of the new secret"
|
|
1511
1727
|
aria-invalid={keyProblem !== null}
|