@coffre/ui 0.6.1 → 0.7.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.
Files changed (119) hide show
  1. package/dist/chunks/{audit-sentence-CUUMshIp.js → audit-sentence-C1_gRxWW.js} +91 -26
  2. package/dist/chunks/audit-sentence-C1_gRxWW.js.map +1 -0
  3. package/dist/chunks/{connected-apps-DTpatjge.js → connected-apps-Bn5rEoV2.js} +4 -4
  4. package/dist/chunks/{connected-apps-DTpatjge.js.map → connected-apps-Bn5rEoV2.js.map} +1 -1
  5. package/dist/chunks/{delete-place-SOOYVt6A.js → delete-place-CQCDHkne.js} +4 -4
  6. package/dist/chunks/{delete-place-SOOYVt6A.js.map → delete-place-CQCDHkne.js.map} +1 -1
  7. package/dist/chunks/{directory-DrtdKny2.js → directory-BQNOdze_.js} +22 -19
  8. package/dist/chunks/directory-BQNOdze_.js.map +1 -0
  9. package/dist/chunks/{folders-hR2Lnk0k.js → folders-Dw240WMJ.js} +2 -2
  10. package/dist/chunks/{folders-hR2Lnk0k.js.map → folders-Dw240WMJ.js.map} +1 -1
  11. package/dist/chunks/{grants-DDBui9YD.js → grants-CJIBrkod.js} +5 -5
  12. package/dist/chunks/{grants-DDBui9YD.js.map → grants-CJIBrkod.js.map} +1 -1
  13. package/dist/chunks/multi-combobox-CsIXihuc.js +99 -0
  14. package/dist/chunks/multi-combobox-CsIXihuc.js.map +1 -0
  15. package/dist/chunks/{offboarding-C7ECW5o0.js → offboarding-CrgwaetA.js} +4 -4
  16. package/dist/chunks/offboarding-CrgwaetA.js.map +1 -0
  17. package/dist/chunks/personal-tokens-B8rkT-DI.js +138 -0
  18. package/dist/chunks/personal-tokens-B8rkT-DI.js.map +1 -0
  19. package/dist/chunks/{principal-page-CB6dAABC.js → principal-page-DDmmV1KQ.js} +37 -27
  20. package/dist/chunks/principal-page-DDmmV1KQ.js.map +1 -0
  21. package/dist/chunks/{project-page-BHNUvr2L.js → project-page-BI--vjt3.js} +2 -2
  22. package/dist/chunks/{project-page-BHNUvr2L.js.map → project-page-BI--vjt3.js.map} +1 -1
  23. package/dist/chunks/{queries-DgQo3mC-.js → queries-epz4MIuW.js} +103 -18
  24. package/dist/chunks/queries-epz4MIuW.js.map +1 -0
  25. package/dist/chunks/{references-BQc35Q9g.js → references-DImfw0cz.js} +4 -4
  26. package/dist/chunks/{references-BQc35Q9g.js.map → references-DImfw0cz.js.map} +1 -1
  27. package/dist/chunks/{role-field-BfWRCqzl.js → role-field-C1KhNaIR.js} +2 -2
  28. package/dist/chunks/{role-field-BfWRCqzl.js.map → role-field-C1KhNaIR.js.map} +1 -1
  29. package/dist/chunks/{row-state-Zf3kZVhd.js → row-state-BsIHspy4.js} +2 -2
  30. package/dist/chunks/{row-state-Zf3kZVhd.js.map → row-state-BsIHspy4.js.map} +1 -1
  31. package/dist/chunks/{theme-B6-V9JvY.js → theme-3b4DnCow.js} +2 -2
  32. package/dist/chunks/{theme-B6-V9JvY.js.map → theme-3b4DnCow.js.map} +1 -1
  33. package/dist/chunks/{ui-Br-dNUTc.js → ui-2kwXXfrX.js} +95 -22
  34. package/dist/chunks/ui-2kwXXfrX.js.map +1 -0
  35. package/dist/chunks/{use-action-DthL5hL8.js → use-action-BB-RcHo1.js} +2 -2
  36. package/dist/chunks/{use-action-DthL5hL8.js.map → use-action-BB-RcHo1.js.map} +1 -1
  37. package/dist/chunks/{use-change-By4cG8bT.js → use-change-CQyDpCqw.js} +323 -31
  38. package/dist/chunks/use-change-CQyDpCqw.js.map +1 -0
  39. package/dist/chunks/{use-shell-D6kjSPls.js → use-shell-C_NmvCt_.js} +2 -2
  40. package/dist/chunks/{use-shell-D6kjSPls.js.map → use-shell-C_NmvCt_.js.map} +1 -1
  41. package/dist/index.d.ts +46 -164
  42. package/dist/index.js +143 -129
  43. package/dist/index.js.map +1 -1
  44. package/dist/pages/account.d.ts +1 -1
  45. package/dist/pages/account.js +29 -12
  46. package/dist/pages/account.js.map +1 -1
  47. package/dist/pages/approval.js +1 -1
  48. package/dist/pages/audit.js +96 -90
  49. package/dist/pages/audit.js.map +1 -1
  50. package/dist/pages/device-login.js +1 -1
  51. package/dist/pages/environment.js +949 -412
  52. package/dist/pages/environment.js.map +1 -1
  53. package/dist/pages/login.js +2 -2
  54. package/dist/pages/oauth-authorize.js +1 -1
  55. package/dist/pages/project-access.js +9 -9
  56. package/dist/pages/project-access.js.map +1 -1
  57. package/dist/pages/project-environments.js +112 -64
  58. package/dist/pages/project-environments.js.map +1 -1
  59. package/dist/pages/project-settings.d.ts +1 -1
  60. package/dist/pages/project-settings.js +54 -75
  61. package/dist/pages/project-settings.js.map +1 -1
  62. package/dist/pages/project.js +3 -7
  63. package/dist/pages/project.js.map +1 -1
  64. package/dist/pages/projects.js +50 -77
  65. package/dist/pages/projects.js.map +1 -1
  66. package/dist/pages/service-account.js +284 -160
  67. package/dist/pages/service-account.js.map +1 -1
  68. package/dist/pages/service-accounts.js +4 -4
  69. package/dist/pages/settings.js +5 -5
  70. package/dist/pages/unregistered.js +1 -1
  71. package/dist/pages/user.js +5 -5
  72. package/dist/pages/users.js +4 -4
  73. package/package.json +3 -3
  74. package/src/components/actions-log.tsx +3 -2
  75. package/src/components/command-palette.tsx +4 -5
  76. package/src/components/directory.tsx +7 -14
  77. package/src/components/generate-value.tsx +15 -7
  78. package/src/components/missing.tsx +63 -67
  79. package/src/components/offboarding.tsx +1 -1
  80. package/src/components/personal-tokens.tsx +131 -0
  81. package/src/components/principal-page.tsx +30 -17
  82. package/src/components/regenerate.tsx +72 -0
  83. package/src/components/service-tokens.tsx +5 -14
  84. package/src/components/shell.tsx +79 -75
  85. package/src/components/trusted-workloads.tsx +179 -19
  86. package/src/components/ui.tsx +35 -25
  87. package/src/lib/audit-sentences.ts +100 -12
  88. package/src/lib/bindings.ts +41 -3
  89. package/src/lib/changes.ts +215 -29
  90. package/src/lib/clipboard.ts +40 -0
  91. package/src/lib/copy-attempts.ts +103 -0
  92. package/src/lib/dismissal.ts +24 -0
  93. package/src/lib/generate.ts +3 -146
  94. package/src/lib/optimistic.ts +3 -1
  95. package/src/lib/queries.ts +121 -17
  96. package/src/lib/recipes.ts +63 -0
  97. package/src/lib/reveal.ts +7 -1
  98. package/src/lib/row-reads.ts +64 -0
  99. package/src/lib/secret-edit-batch.ts +64 -5
  100. package/src/options.ts +43 -51
  101. package/src/pages/account.tsx +27 -5
  102. package/src/pages/audit.tsx +38 -31
  103. package/src/pages/environment.tsx +655 -121
  104. package/src/pages/project-access.tsx +1 -1
  105. package/src/pages/project-environments.tsx +92 -45
  106. package/src/pages/project-settings.tsx +9 -20
  107. package/src/pages/project.tsx +1 -5
  108. package/src/pages/projects.tsx +13 -28
  109. package/src/parity.ts +20 -4
  110. package/src/styles/globals.css +143 -131
  111. package/dist/chunks/audit-sentence-CUUMshIp.js.map +0 -1
  112. package/dist/chunks/directory-DrtdKny2.js.map +0 -1
  113. package/dist/chunks/offboarding-C7ECW5o0.js.map +0 -1
  114. package/dist/chunks/principal-page-CB6dAABC.js.map +0 -1
  115. package/dist/chunks/project-environments-lEzFHUt4.js +0 -11
  116. package/dist/chunks/project-environments-lEzFHUt4.js.map +0 -1
  117. package/dist/chunks/queries-DgQo3mC-.js.map +0 -1
  118. package/dist/chunks/ui-Br-dNUTc.js.map +0 -1
  119. package/dist/chunks/use-change-By4cG8bT.js.map +0 -1
@@ -1,14 +1,15 @@
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';
5
- import { Link } from '@tanstack/react-router';
3
+ import type { Generation } from '@coffre/core/recipe';
4
+ import { useEffect, useReducer, useRef, useState, type ReactNode } from 'react';
5
+ import { useQuery, useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
6
+ import { Link, useNavigate } from '@tanstack/react-router';
6
7
  import { useShell } from '../lib/use-shell';
7
8
  import { Menu } from '@base-ui/react/menu';
8
9
  import { toast } from 'sonner';
9
10
  import { failureMessage, useCoffre } from '../lib/coffre';
10
- import { archiveSecret, moveSecret, restoreSecret, saveSecrets, UnsavedEdits } from '../lib/changes';
11
- import type { ItemStatus } from '../lib/optimistic';
11
+ import { archiveSecret, forkKey, moveSecret, regenerateSecret, restoreSecret, saveSecrets, UnsavedEdits, type ForkAction, type SaveSecretsVars } from '../lib/changes';
12
+ import { changeKey, type ItemStatus } from '../lib/optimistic';
12
13
  import { affects, keys as queryKeys, queries } from '../lib/queries';
13
14
  import { useChange, useChangeStatus } from '../lib/use-change';
14
15
  import { RowFailure, RowPending, rowClass } from '../components/row-state';
@@ -29,10 +30,12 @@ import {
29
30
  type SecretChange,
30
31
  type SecretDraft,
31
32
  } from '../lib/secret-edit-batch';
33
+ import { createCopier } from '../lib/copy-attempts';
32
34
  import { revealIsCurrent, type Reveal } from '../lib/reveal';
35
+ import { noReads, revealToggleDisabled, rowReads } from '../lib/row-reads';
33
36
  import { sortKeys, type Sort } from '../lib/secret-order';
34
37
  import { inDialog } from '../lib/shortcuts';
35
- import { secretKeyProblem } from '../lib/validation';
38
+ import { folderProblem, secretKeyProblem } from '../lib/validation';
36
39
  import {
37
40
  breakAfterUnderscores,
38
41
  ConfirmButton,
@@ -50,9 +53,12 @@ import {
50
53
  import { Card, ClosedDoor, PageHeader } from '../components/page';
51
54
  import { SecretReadOnly } from '../components/affordances';
52
55
  import { GenerateValue, type GeneratedUse } from '../components/generate-value';
56
+ import { RecipeMark, RegenerateSecret } from '../components/regenerate';
57
+ import { liveGeneration, regeneratedKeys, regenerateWaits } from '../lib/recipes';
53
58
  import { MaskedInput, MaskedTextarea } from '../components/masked';
54
59
  import { FolderMenu, FolderRow, MoveToFolder } from '../components/folders';
55
60
  import { MissingKeys } from '../components/missing';
61
+ import { MultiCombobox } from '../components/multi-combobox';
56
62
  import { ArchiveBlocked, archiveBlockers, LentReferences, MakeReference, ReferenceValue } from '../components/references';
57
63
  import { isActiveAccessibleEnvironment } from '../lib/project-environments';
58
64
  import {
@@ -78,6 +84,7 @@ import {
78
84
  Search,
79
85
  SlashCircle,
80
86
  Terminal,
87
+ Trash,
81
88
  Upload,
82
89
  X,
83
90
  } from '../components/icons';
@@ -95,6 +102,13 @@ const Route = pageRoute<typeof environment>();
95
102
  */
96
103
  const REVEAL_TTL_SECONDS = 45;
97
104
 
105
+ /** Why a read of a secret's value failed, as the row says it. */
106
+ function readFailureMessage(failure: unknown): string {
107
+ return failure instanceof CoffreError
108
+ ? failureMessage(failure)
109
+ : 'The request could not be sent. Nothing was read.';
110
+ }
111
+
98
112
  export function EnvironmentPage() {
99
113
  const { project, environment } = Route.useParams();
100
114
  const { data: result } = useSuspenseQuery(queries.secrets(useCoffre(), { project, environment }));
@@ -120,6 +134,9 @@ export function EnvironmentPage() {
120
134
  );
121
135
  }
122
136
 
137
+ // `dev@me` while you have none: what one is, and making it, rather than dev's own keys under your name.
138
+ if (result.personal?.fallback === true) return <NoPersonalConfig project={project} of={result.personal.of} />;
139
+
123
140
  // Keyed by location: pending edits belong to the environment they were
124
141
  // started in. The route component is reused across params, so without the
125
142
  // key they would follow you into the next environment and be written there.
@@ -130,6 +147,8 @@ export function EnvironmentPage() {
130
147
  environment={environment}
131
148
  permissions={result.permissions}
132
149
  keys={result.keys}
150
+ parents={result.parents ?? []}
151
+ personal={result.personal != null}
133
152
  rotateAfterDays={result.rotateAfterDays}
134
153
  />
135
154
  );
@@ -142,21 +161,36 @@ function EnvironmentLedger({
142
161
  environment,
143
162
  permissions,
144
163
  keys,
164
+ parents,
165
+ personal,
145
166
  rotateAfterDays,
146
167
  }: {
147
168
  project: string;
148
169
  environment: string;
149
170
  permissions: Permission[];
150
171
  keys: SecretKey[];
172
+ /** The environments it inherits from, nearest first: a fork's (docs/design/forking.md). */
173
+ parents: string[];
174
+ /** Your personal config, `dev@me`: its values yours alone. */
175
+ personal: boolean;
151
176
  /** Days a value may go unchanged before it is flagged for rotation; null for no flag. */
152
177
  rotateAfterDays: number | null;
153
178
  }) {
154
179
  const coffre = useCoffre();
180
+ const queryClient = useQueryClient();
155
181
  const { principal } = useShell();
156
182
  const save = useChange(saveSecrets(coffre, { project, environment }, principal?.id ?? null));
157
183
  const restore = useChange(restoreSecret(coffre, { project, environment }));
158
184
  const archive = useChange(archiveSecret(coffre, { project, environment }));
159
185
  const move = useChange(moveSecret(coffre, { project, environment }));
186
+ const regenerate = useChange(regenerateSecret(coffre, { project, environment }, principal?.id ?? null));
187
+ // A fork's keys, against its parent's: each action shows at once, with its opposite as Undo.
188
+ const forkChanges = {
189
+ remove: useChange(forkKey(coffre, { project, environment }, 'remove')),
190
+ restore: useChange(forkKey(coffre, { project, environment }, 'restore')),
191
+ reset: useChange(forkKey(coffre, { project, environment }, 'reset')),
192
+ override: useChange(forkKey(coffre, { project, environment }, 'override')),
193
+ };
160
194
  // The references that read this environment's secrets from elsewhere, and the environments you read.
161
195
  const { data: references } = useQuery(queries.references(coffre, `${project}/${environment}`));
162
196
  const lentBy = new Map<string, ListedReference[]>();
@@ -165,8 +199,9 @@ function EnvironmentLedger({
165
199
  if (sourceProject !== project || sourceEnvironment !== environment) continue;
166
200
  lentBy.set(key, [...(lentBy.get(key) ?? []), reference]);
167
201
  }
202
+ // A personal config is no reference's source: its values are its owner's alone.
168
203
  const readable = useShell().projects.flatMap((each) => each.environments
169
- .filter(isActiveAccessibleEnvironment)
204
+ .filter((one) => isActiveAccessibleEnvironment(one) && !one.personal)
170
205
  .map((one) => `${each.slug}/${one.slug}`));
171
206
  const { status, dismiss } = useChangeStatus(queryKeys.secrets({ project, environment }));
172
207
  const [drafts, setDrafts] = useState<SecretDraft[]>([]);
@@ -179,6 +214,7 @@ function EnvironmentLedger({
179
214
  const [sort, setSort] = useState<Sort>({ by: 'key', descending: false });
180
215
  // A column's first click sorts it ascending: names A to Z, the oldest values first.
181
216
  const sortBy = (by: Sort['by']) => setSort((current) => ({ by, descending: current.by === by && !current.descending }));
217
+ const [addingFolder, setAddingFolder] = useState(false);
182
218
  const nextDraftId = useRef(0);
183
219
 
184
220
  const canWrite = permissions.includes('secret.write');
@@ -188,11 +224,17 @@ function EnvironmentLedger({
188
224
  // Listed by folder: those in none first, then each folder by name.
189
225
  const active = byFolder(keys.filter((entry) => !entry.archived)).flatMap(([, entries]) => entries);
190
226
  const folders = foldersOf(active);
227
+ // In a fork, an inherited key is filed where its parent files it: only the keys held here are filed here.
228
+ const heldHere = (entry: SecretKey) => entry.parent === null || entry.parent.state === 'overridden';
229
+ // What can be filed now: not a secret whose save is on its way, which may
230
+ // not exist yet, nor one with an edit pending, as its menu offers no move
231
+ // while it is edited.
232
+ const settled = active.filter((entry) => heldHere(entry) && status(entry.key).state !== 'pending' && secretChangeFor(changes, entry.key) === undefined);
191
233
  // Renaming or removing a folder: everything in it at once, the keys staying where they are.
192
234
  const refile = useAction();
193
235
  const place = `${project}/${environment}`;
194
236
  const folderMenu = (folder: string, count: number) =>
195
- canWrite && (
237
+ canWrite && count > 0 && (
196
238
  <FolderMenu
197
239
  folder={folder}
198
240
  count={count}
@@ -213,6 +255,13 @@ function EnvironmentLedger({
213
255
  const archived = keys.filter((entry) => entry.archived);
214
256
  const existing = new Set(keys.map((entry) => entry.key));
215
257
  const versionOf = (key: string) => keys.find((entry) => entry.key === key.trim())?.version ?? null;
258
+ /** The listed version id of each key, those with one: what a regenerate replaces. */
259
+ const versionIdOf = (name: string) => active.find((entry) => entry.key === name)?.versionId ?? null;
260
+ const versionsOf = (names: readonly string[]) =>
261
+ Object.fromEntries(names.flatMap((name) => {
262
+ const version = versionIdOf(name);
263
+ return version === null ? [] : [[name, version] as const];
264
+ }));
216
265
 
217
266
  const changedEntries = active.filter(
218
267
  (entry) => secretChangeFor(changes, entry.key) !== undefined,
@@ -285,6 +334,7 @@ function EnvironmentLedger({
285
334
  save(batch, {
286
335
  // What did not go comes back as it was, beside the other pending rows.
287
336
  onError: (error) => {
337
+ forgetRefusal(batch);
288
338
  const left = error instanceof UnsavedEdits ? error.outcome : batch;
289
339
  setDrafts((rows) => [...rows, ...left.drafts]);
290
340
  setChanges((current) => ({ ...current, ...left.changes }));
@@ -315,11 +365,16 @@ function EnvironmentLedger({
315
365
  setChanges({});
316
366
  setEditing(new Set());
317
367
  setSaveError(null);
318
- // A refused save, given up: its rows stop saying so.
319
- for (const entry of keys) {
320
- const state = status(entry.key);
321
- if (state.state === 'failed') dismiss(state.mutationId);
322
- }
368
+ }
369
+
370
+ /**
371
+ * A refused save leaves its rows no failure of their own: its edits come
372
+ * back on them, and the bar under the table says why. Every other refused
373
+ * change, a move for one, says why beneath its row.
374
+ */
375
+ function forgetRefusal(batch: SaveSecretsVars) {
376
+ const saves = queryClient.getMutationCache().findAll({ mutationKey: changeKey(queryKeys.secrets({ project, environment })) });
377
+ for (const each of saves) if (each.state.variables === batch) dismiss(each.mutationId);
323
378
  }
324
379
 
325
380
  /**
@@ -327,7 +382,7 @@ function EnvironmentLedger({
327
382
  * rest as one patch that lands whole or not at all. The edits show in the
328
383
  * list at once, each row marked as saving; whatever did not land comes
329
384
  * back as pending, so pressing save again retries exactly that, and the
330
- * save bar says why.
385
+ * bar under the table says why.
331
386
  */
332
387
  function saveChanges() {
333
388
  if (!ready) return;
@@ -338,6 +393,7 @@ function EnvironmentLedger({
338
393
  setSaveError(null);
339
394
  save(batch, {
340
395
  onError: (error) => {
396
+ forgetRefusal(batch);
341
397
  const left = error instanceof UnsavedEdits ? error.outcome : batch;
342
398
  setDrafts(left.drafts);
343
399
  setChanges(left.changes);
@@ -364,6 +420,31 @@ function EnvironmentLedger({
364
420
  );
365
421
  }
366
422
 
423
+ /**
424
+ * In a fork, a key against its parent's: removed, restored, reset to the
425
+ * parent's value or overriding it again. Each is undone by its opposite,
426
+ * so it gets an Undo rather than a confirmation dialog in front of it.
427
+ */
428
+ function forkAction(entry: SecretKey, action: ForkAction) {
429
+ const from = entry.parent?.from ?? parents[0] ?? 'its parent';
430
+ const undo: Record<ForkAction, ForkAction> = { remove: 'restore', restore: 'remove', reset: 'override', override: 'reset' };
431
+ const said: Record<ForkAction, string> = {
432
+ remove: `${entry.key} removed: ${environment} does without ${from}'s`,
433
+ restore: `${entry.key} inherited from ${from} again`,
434
+ reset: `${entry.key} reads ${from}'s value again; its own is kept`,
435
+ override: `${entry.key} overrides ${from} again`,
436
+ };
437
+ forkChanges[action](
438
+ { key: entry.key },
439
+ {
440
+ onSuccess: () =>
441
+ toast.success(said[action], {
442
+ action: { label: 'Undo', onClick: () => forkChanges[undo[action]]({ key: entry.key }) },
443
+ }),
444
+ },
445
+ );
446
+ }
447
+
367
448
  // Cmd/Ctrl+Enter saves from anywhere on the page while edits are pending,
368
449
  // but for an open dialog, such as Generate's.
369
450
  const saveRef = useRef(saveChanges);
@@ -395,6 +476,8 @@ function EnvironmentLedger({
395
476
  return { key: entry.key, what: withCompanion(`→ ${change.key.trim()}, new value`, change.companion) };
396
477
  }
397
478
  if (renamed) return { key: entry.key, what: `→ ${change.key.trim()}` };
479
+ // In a fork, a value written over the parent's overrides it.
480
+ if (entry.parent !== null && entry.parent.state !== 'overridden') return { key: entry.key, what: withCompanion(`overrides ${entry.parent.from}`, change.companion) };
398
481
  return { key: entry.key, what: withCompanion('new value', change.companion) };
399
482
  }),
400
483
  ];
@@ -410,7 +493,7 @@ function EnvironmentLedger({
410
493
  : null;
411
494
 
412
495
  // 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 save bar.
496
+ // a row the filter hides still counts, and still shows in the bar under the table.
414
497
  const needle = query.trim().toLowerCase();
415
498
  const listed = sortKeys(
416
499
  needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)),
@@ -423,7 +506,32 @@ function EnvironmentLedger({
423
506
  <PageHeader
424
507
  tile={project}
425
508
  title={environment}
426
- aside={<EnvironmentName project={project} environment={environment} />}
509
+ actions={personal ? (
510
+ <DeletePersonal project={project} environment={environment} of={parents[0]!} />
511
+ ) : principal?.type === 'user' && canReveal && (
512
+ <Link className="btn btn-sm" to="/projects/$project/$environment" params={{ project, environment: `${environment}@me` }}>
513
+ <Key size={14} />
514
+ My own {environment}
515
+ </Link>
516
+ )}
517
+ description={personal ? (
518
+ <span className="inherits">
519
+ Your own{' '}
520
+ <Link className="mono" to="/projects/$project/$environment" params={{ project, environment: parents[0]! }}>
521
+ {project}/{parents[0]}
522
+ </Link>
523
+ : what you set here, only you read, while you read {parents[0]}; the rest is {parents[0]}'s, as it changes.
524
+ </span>
525
+ ) : parents.length > 0 && (
526
+ <span className="inherits">
527
+ Inherits from{' '}
528
+ <Link className="mono" to="/projects/$project/$environment" params={{ project, environment: parents[0]! }}>
529
+ {project}/{parents[0]}
530
+ </Link>
531
+ {parents.length > 1 && <>, which inherits from {parents.slice(1).map((parent) => `${project}/${parent}`).join(', then ')}</>}
532
+ : its keys, as they change, but for those set or removed here.
533
+ </span>
534
+ )}
427
535
  />
428
536
 
429
537
  {(active.length > 0 || drafts.length > 0) && (
@@ -505,7 +613,7 @@ function EnvironmentLedger({
505
613
  </thead>
506
614
  <tbody>
507
615
  {byFolder(listed).flatMap(([folder, entries]) => [
508
- ...(folder === null ? [] : [<FolderRow key={`folder:${folder}`} folder={folder} count={entries.length} columns={columns} actions={folderMenu(folder, entries.length)} />]),
616
+ ...(folder === null ? [] : [<FolderRow key={`folder:${folder}`} folder={folder} count={entries.length} columns={columns} actions={folderMenu(folder, entries.filter(heldHere).length)} />]),
509
617
  ...entries.map((entry) => {
510
618
  const change = secretChangeFor(changes, entry.key);
511
619
  const state = status(entry.key);
@@ -516,6 +624,23 @@ function EnvironmentLedger({
516
624
  project={project}
517
625
  environment={environment}
518
626
  entry={entry}
627
+ generated={liveGeneration(entry, active)}
628
+ // Being edited, written by a new row or its companion, or with a save on its way:
629
+ // a key pair's Regenerate waits for both halves.
630
+ busy={(key) =>
631
+ status(key).state === 'pending' ||
632
+ editing.has(key) ||
633
+ secretChangeFor(changes, key) !== undefined ||
634
+ drafts.some((draft) => draft.key.trim() === key || draft.companion?.key.trim() === key) ||
635
+ // Written here and not yet read back: no version to say it replaces.
636
+ versionIdOf(key) === null
637
+ }
638
+ onRegenerate={(generated) =>
639
+ regenerate(
640
+ { key: entry.key, generated, versions: versionsOf(regeneratedKeys(entry.key, generated)) },
641
+ { onSuccess: () => toast.success(`Regenerated ${regeneratedKeys(entry.key, generated).join(' and ')}`) },
642
+ )
643
+ }
519
644
  rotateAfterDays={rotateAfterDays}
520
645
  change={change ?? { key: entry.key, value: null, archived: false }}
521
646
  editing={
@@ -528,11 +653,14 @@ function EnvironmentLedger({
528
653
  folders={folders}
529
654
  onMove={(folder) => move({ key: entry.key, folder })}
530
655
  lent={lentBy.get(entry.key) ?? []}
531
- environments={readable}
656
+ // A personal config holds values only: no reference.
657
+ environments={personal ? [] : readable}
532
658
  status={state}
533
659
  // Not while its save is on its way.
534
660
  disabled={state.state === 'pending'}
661
+ onDismiss={dismiss}
535
662
  columns={columns}
663
+ onFork={(action) => forkAction(entry, action)}
536
664
  onEdit={() => setEditing((current) => new Set(current).add(entry.key))}
537
665
  onPatch={(patch) => patchChange(entry, patch)}
538
666
  onUndo={() => dropChange(entry.key)}
@@ -586,15 +714,33 @@ function EnvironmentLedger({
586
714
  </table>
587
715
  </div>
588
716
  )}
717
+ {pendingCount > 0 && (
718
+ <PendingBar
719
+ pending={pending}
720
+ ready={ready}
721
+ error={saveError ?? problem}
722
+ onDiscard={discardAll}
723
+ onSave={saveChanges}
724
+ />
725
+ )}
589
726
  </section>
590
727
 
591
728
  {canWrite && (
592
729
  <div className="table-actions">
593
- <button className="btn btn-primary" onClick={() => addDraft()}>
594
- <Plus size={14} />
595
- New secret
596
- </button>
730
+ <AddButton onAddSecret={() => addDraft()} onAddFolder={() => setAddingFolder(true)} canAddFolder={settled.length > 0} />
597
731
  {canReveal && <ImportEnv project={project} environment={environment} />}
732
+ <AddFolder
733
+ open={addingFolder}
734
+ onOpenChange={setAddingFolder}
735
+ keys={settled.map((entry) => entry.key)}
736
+ folders={folders}
737
+ onAdd={(folder, keys) => {
738
+ // As things stand on submit: a secret whose save started since the dialog opened is left out, not raced.
739
+ for (const entry of settled) {
740
+ if (keys.includes(entry.key) && entry.folder !== folder) move({ key: entry.key, folder });
741
+ }
742
+ }}
743
+ />
598
744
  </div>
599
745
  )}
600
746
 
@@ -654,56 +800,188 @@ function EnvironmentLedger({
654
800
  </Card>
655
801
  )}
656
802
 
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
803
  </>
697
804
  );
698
805
  }
699
806
 
700
- /** The display name sits beside the slug; it comes from the shell's project tree. */
701
- function EnvironmentName({ project, environment }: { project: string; environment: string }) {
702
- const { projects } = useShell();
703
- const name = projects
704
- .find((entry) => entry.slug === project)
705
- ?.environments.find((entry) => entry.slug === environment)?.name;
706
- return name === undefined ? null : <>{name}</>;
807
+ /**
808
+ * The pending edits, at the foot of the table they are made in: what they
809
+ * are, Discard and Save. It sticks to the bottom of the window while the
810
+ * table runs past it, so Save stays in reach of any row.
811
+ */
812
+ function PendingBar({
813
+ pending,
814
+ ready,
815
+ error,
816
+ onDiscard,
817
+ onSave,
818
+ }: {
819
+ pending: Pending[];
820
+ ready: boolean;
821
+ /** Why the last save failed, or why this one cannot go yet. */
822
+ error: string | null;
823
+ onDiscard: () => void;
824
+ onSave: () => void;
825
+ }) {
826
+ const count = pending.length;
827
+ return (
828
+ <div className="pending-bar" role="region" aria-label="Unsaved changes">
829
+ <span className="pending-count">
830
+ <span className="dot" aria-hidden />
831
+ {count} unsaved change{count === 1 ? '' : 's'}
832
+ </span>
833
+ <span className="pending-summary">
834
+ {pending.slice(0, 3).map((item, index) => (
835
+ <span key={`${item.key}:${index}`}>
836
+ {index > 0 && ' · '}
837
+ <span className="mono">{item.key}</span> {item.what}
838
+ </span>
839
+ ))}
840
+ {count > 3 && ` · and ${count - 3} more`}
841
+ </span>
842
+ <div className="pending-actions">
843
+ <button className="btn btn-sm" onClick={onDiscard}>
844
+ Discard
845
+ </button>
846
+ <button
847
+ className="btn btn-sm btn-primary"
848
+ onClick={onSave}
849
+ disabled={!ready}
850
+ title="Save (⌘ Enter or Ctrl Enter)"
851
+ aria-keyshortcuts="Meta+Enter Control+Enter"
852
+ >
853
+ Save {count === 1 ? 'change' : `${count} changes`}
854
+ </button>
855
+ </div>
856
+ {error !== null && (
857
+ <p className="pending-error" role="alert">
858
+ <AlertCircle size={14} />
859
+ <span>{error}</span>
860
+ </p>
861
+ )}
862
+ </div>
863
+ );
864
+ }
865
+
866
+ /**
867
+ * Add secret, and beside it a menu of the other things to add: a folder.
868
+ * One button in look, two to the keyboard and to a screen reader, the
869
+ * second a menu button.
870
+ */
871
+ function AddButton({
872
+ onAddSecret,
873
+ onAddFolder,
874
+ canAddFolder,
875
+ }: {
876
+ onAddSecret: () => void;
877
+ onAddFolder: () => void;
878
+ /** Whether there is a secret to file in a new folder. */
879
+ canAddFolder: boolean;
880
+ }) {
881
+ return (
882
+ <div className="split-button">
883
+ <button className="btn btn-primary" onClick={onAddSecret}>
884
+ <Plus size={14} />
885
+ Add secret
886
+ </button>
887
+ <Menu.Root>
888
+ <Menu.Trigger className="btn btn-primary btn-icon" aria-label="More to add">
889
+ <ChevronDown size={14} />
890
+ </Menu.Trigger>
891
+ <MenuPopup align="start">
892
+ <Menu.Item className="menu-item" onClick={onAddFolder} disabled={!canAddFolder}>
893
+ <Folder size={14} />
894
+ Add folder…
895
+ {!canAddFolder && <span className="menu-hint">after a secret</span>}
896
+ </Menu.Item>
897
+ </MenuPopup>
898
+ </Menu.Root>
899
+ </div>
900
+ );
901
+ }
902
+
903
+ /**
904
+ * A new folder, and the secrets filed in it. A folder is a name on what it
905
+ * holds (docs/design/environments.md), so it is made with its first
906
+ * secrets: one with nothing in it would not be there to see.
907
+ */
908
+ function AddFolder({
909
+ open,
910
+ onOpenChange,
911
+ keys,
912
+ folders,
913
+ onAdd,
914
+ }: {
915
+ open: boolean;
916
+ onOpenChange: (open: boolean) => void;
917
+ /** The secrets that can be filed, by name. */
918
+ keys: readonly string[];
919
+ /** The folders in use, which a name already in use joins. */
920
+ folders: readonly string[];
921
+ onAdd: (folder: string, keys: string[]) => void;
922
+ }) {
923
+ const [name, setName] = useState('');
924
+ const [chosen, setChosen] = useState<string[]>([]);
925
+ useEffect(() => {
926
+ if (!open) return;
927
+ setName('');
928
+ setChosen([]);
929
+ }, [open]);
930
+ const problem = folderProblem(name);
931
+ const joins = folders.includes(name);
932
+ const ready = name !== '' && problem === null && chosen.length > 0;
933
+
934
+ return (
935
+ <Modal
936
+ open={open}
937
+ onOpenChange={onOpenChange}
938
+ title="Add a folder"
939
+ description="Folders only arrange the list: names, values and access stay as they are."
940
+ >
941
+ <form
942
+ className="form"
943
+ onSubmit={(event) => {
944
+ event.preventDefault();
945
+ if (!ready) return;
946
+ onAdd(name, chosen);
947
+ onOpenChange(false);
948
+ }}
949
+ >
950
+ <label className="field">
951
+ <span className="label">Name</span>
952
+ <input
953
+ className="input"
954
+ autoFocus
955
+ spellCheck={false}
956
+ autoComplete="off"
957
+ value={name}
958
+ aria-invalid={problem !== null}
959
+ onChange={(event) => setName(event.target.value)}
960
+ />
961
+ <span className={`hint${problem !== null ? ' edit-note-error' : ''}`}>
962
+ {problem ?? (joins ? `${name} is in use: the secrets join it.` : 'One level: no slash.')}
963
+ </span>
964
+ </label>
965
+ <MultiCombobox
966
+ label="Secrets in it"
967
+ options={keys}
968
+ value={chosen}
969
+ onChange={setChosen}
970
+ placeholder="Pick one or more…"
971
+ hint="A folder holds at least one secret."
972
+ mono
973
+ />
974
+ <div className="dialog-actions">
975
+ <button className="btn" type="button" onClick={() => onOpenChange(false)}>
976
+ Cancel
977
+ </button>
978
+ <button className="btn btn-primary" type="submit" disabled={!ready}>
979
+ Add folder
980
+ </button>
981
+ </div>
982
+ </form>
983
+ </Modal>
984
+ );
707
985
  }
708
986
 
709
987
  /* -------------------------------------------------------------------------- */
@@ -879,6 +1157,9 @@ function SecretRow({
879
1157
  project,
880
1158
  environment,
881
1159
  entry,
1160
+ generated,
1161
+ busy,
1162
+ onRegenerate,
882
1163
  rotateAfterDays,
883
1164
  change,
884
1165
  editing,
@@ -891,7 +1172,9 @@ function SecretRow({
891
1172
  environments,
892
1173
  status,
893
1174
  disabled,
1175
+ onDismiss,
894
1176
  columns,
1177
+ onFork,
895
1178
  onEdit,
896
1179
  onPatch,
897
1180
  onUndo,
@@ -904,6 +1187,12 @@ function SecretRow({
904
1187
  project: string;
905
1188
  environment: string;
906
1189
  entry: SecretKey;
1190
+ /** Its recipe, as the page may regenerate it by: a key pair's while both halves are listed alike (`liveGeneration`). */
1191
+ generated: Generation | null;
1192
+ /** Whether a key in this environment is being edited, or has a save on its way. */
1193
+ busy: (key: string) => boolean;
1194
+ /** Regenerate it by its recipe, a tracked save of every key it writes. */
1195
+ onRegenerate: (generated: Generation) => void;
907
1196
  rotateAfterDays: number | null;
908
1197
  change: SecretChange;
909
1198
  editing: boolean;
@@ -920,7 +1209,11 @@ function SecretRow({
920
1209
  /** A save of this row on its way, or refused. */
921
1210
  status: ItemStatus;
922
1211
  disabled: boolean;
1212
+ /** Forget a refused change once its row has said so. */
1213
+ onDismiss: (mutationId: number) => void;
923
1214
  columns: number;
1215
+ /** In a fork, the key against its parent's: removed, restored, reset or overriding it again. */
1216
+ onFork: (action: ForkAction) => void;
924
1217
  onEdit: () => void;
925
1218
  onPatch: (patch: Partial<SecretChange>) => void;
926
1219
  onUndo: () => void;
@@ -931,24 +1224,36 @@ function SecretRow({
931
1224
  saveReady: boolean;
932
1225
  onMarkArchive: () => void;
933
1226
  }) {
934
- const [reveal, setReveal] = useState<Reveal | null>(null);
1227
+ const [reads, dispatch] = useReducer(rowReads, noReads);
1228
+ const { reveal, revealing, error, copyError } = reads;
1229
+ const setReveal = (next: Reveal | null) => dispatch({ type: 'set-reveal', reveal: next });
935
1230
  const coffre = useCoffre();
936
- const [revealing, setRevealing] = useState(false);
937
1231
  const [historyOpen, setHistoryOpen] = useState(false);
938
1232
  const [moving, setMoving] = useState(false);
939
1233
  const [referring, setReferring] = useState(false);
940
1234
  const [breaking, setBreaking] = useState<string | null>(null);
1235
+ const [regenerating, setRegenerating] = useState(false);
941
1236
  const [lentOpen, setLentOpen] = useState(false);
942
1237
  // Archiving a key others read through references waits until they are broken (D41).
943
1238
  const [archiveBlocked, setArchiveBlocked] = useState(false);
944
1239
  const blockers = archiveBlockers(`${project}/${environment}/${entry.key}`, lent);
945
1240
  // Making or breaking a reference: its refusal shows under the row, as a reveal's does.
946
1241
  const { run: act, error: actError } = useAction();
947
- const { reference } = entry;
1242
+ const { reference, parent } = entry;
1243
+ // In a fork (docs/design/forking.md): a key it inherits has no row of its
1244
+ // own, one it overrides has, and one it removed is not served.
1245
+ const inherited = parent?.state === 'inherited';
1246
+ const removed = parent?.state === 'removed';
1247
+ const overridden = parent?.state === 'overridden';
1248
+ const own = !inherited && !removed;
1249
+ // Inherited from a parent you do not read: its name is yours to know, its value is not.
1250
+ const parentHidden = inherited && entry.version === null && reference === null;
1251
+ const canRead = canReveal && !removed && !parentHidden;
948
1252
  // What a reveal shows: its own version, or, as a reference, its source's.
949
1253
  const readVersion = reference === null ? entry.version : reference.version;
1254
+ // And where that version is held: a reset, an override or a new reference changes it under the same number.
1255
+ const readFrom = `${inherited ? parent!.from : '.'}:${reference?.source ?? ''}`;
950
1256
  const holderPath = `${project}/${environment}/${entry.key}`;
951
- const [error, setError] = useState<string | null>(null);
952
1257
  // The current value, loaded on request as the starting point for an edit.
953
1258
  // It is not a change until it is edited: saving it untouched would append a
954
1259
  // version identical to the one it came from.
@@ -958,10 +1263,10 @@ function SecretRow({
958
1263
  // different version -- saved here, rolled back, or written by someone else
959
1264
  // and picked up on refresh -- the old plaintext is not the value any more,
960
1265
  // and must not stay on screen pretending to be.
961
- const shown = revealIsCurrent(reveal, readVersion) ? reveal : null;
1266
+ const shown = revealIsCurrent(reveal, readVersion, readFrom) ? reveal : null;
962
1267
  useEffect(() => {
963
- if (reveal !== null && !revealIsCurrent(reveal, readVersion)) setReveal(null);
964
- }, [reveal, readVersion]);
1268
+ if (reveal !== null && !revealIsCurrent(reveal, readVersion, readFrom)) setReveal(null);
1269
+ }, [reveal, readVersion, readFrom]);
965
1270
 
966
1271
  useEffect(() => {
967
1272
  if (reveal === null) return;
@@ -971,37 +1276,71 @@ function SecretRow({
971
1276
 
972
1277
  const secondsLeft = useSecondsLeft(shown);
973
1278
 
974
- const editBase = editing && revealIsCurrent(base, readVersion) ? base : null;
1279
+ const editBase = editing && revealIsCurrent(base, readVersion, readFrom) ? base : null;
975
1280
  useEffect(() => {
976
1281
  if (!editing) setBase(null);
977
1282
  }, [editing]);
978
1283
 
979
1284
  async function readValue({ show = true } = {}): Promise<string | null> {
980
1285
  if (shown !== null) return shown.value;
981
- setRevealing(true);
1286
+ dispatch({ type: 'read-started' });
982
1287
  try {
983
- const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
984
- const value = values[entry.key];
985
- setError(null);
986
- if (show) setReveal({ value, version: readVersion, at: Date.now() });
1288
+ const value = await fetchValue();
1289
+ dispatch({
1290
+ type: 'read-succeeded',
1291
+ reveal: show ? { value, version: readVersion, from: readFrom, at: Date.now() } : null,
1292
+ });
987
1293
  return value;
988
1294
  } catch (failure) {
989
- setError(
990
- failure instanceof CoffreError
991
- ? failureMessage(failure)
992
- : 'The request could not be sent. Nothing was read.',
993
- );
1295
+ dispatch({ type: 'read-failed', message: readFailureMessage(failure) });
994
1296
  return null;
995
- } finally {
996
- setRevealing(false);
997
1297
  }
998
1298
  }
999
1299
 
1300
+ async function fetchValue(): Promise<string> {
1301
+ const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
1302
+ return values[entry.key];
1303
+ }
1304
+
1000
1305
  function toggleReveal() {
1001
1306
  if (shown !== null) setReveal(null);
1002
1307
  else void readValue();
1003
1308
  }
1004
1309
 
1310
+ // Copy reads a hidden value the way Reveal does (the same audited read) and hands
1311
+ // it to the clipboard, never to the screen or to the row's reveal state: it shares
1312
+ // nothing with Reveal but the endpoint, so neither can change whether a value is
1313
+ // shown or Hide can be pressed. Copies do not lock each other out; the latest one
1314
+ // wins. The row holds the copier, which a remount of the button does not reset,
1315
+ // and only the latest copy may set `copyError` or the button's feedback.
1316
+ const [copier] = useState(() => createCopier());
1317
+ function copyValue() {
1318
+ dispatch({ type: 'copy-started' });
1319
+ // What a failed read said, if the read is what failed rather than the clipboard.
1320
+ const read: { failed: boolean; failure?: unknown } = { failed: false };
1321
+ const text =
1322
+ shown !== null
1323
+ ? shown.value
1324
+ : fetchValue().catch((failure: unknown) => {
1325
+ read.failed = true;
1326
+ read.failure = failure;
1327
+ throw failure;
1328
+ });
1329
+ void copier.run(text).then((result) => {
1330
+ if (result.outcome === 'superseded') return;
1331
+ dispatch(
1332
+ result.outcome === 'copied'
1333
+ ? { type: 'copy-succeeded' }
1334
+ : {
1335
+ type: 'copy-failed',
1336
+ message: read.failed
1337
+ ? readFailureMessage(read.failure)
1338
+ : 'The browser did not allow copying to the clipboard. Reveal the value and copy it by hand.',
1339
+ },
1340
+ );
1341
+ });
1342
+ }
1343
+
1005
1344
  // An edit starts from the current value, read the way Reveal reads it, so
1006
1345
  // the audit log shows who opened it. One that cannot be read starts empty.
1007
1346
  const [opening, setOpening] = useState(false);
@@ -1009,12 +1348,12 @@ function SecretRow({
1009
1348
  const [focusName, setFocusName] = useState(false);
1010
1349
  async function startEdit({ name = false } = {}) {
1011
1350
  setFocusName(name);
1012
- if (canReveal) {
1351
+ if (canRead) {
1013
1352
  setOpening(true);
1014
1353
  const value = await readValue({ show: false });
1015
1354
  setOpening(false);
1016
1355
  if (value === null) return;
1017
- setBase({ value, version: readVersion, at: Date.now() });
1356
+ setBase({ value, version: readVersion, from: readFrom, at: Date.now() });
1018
1357
  }
1019
1358
  setReveal(null);
1020
1359
  onEdit();
@@ -1030,7 +1369,11 @@ function SecretRow({
1030
1369
  ? ' is-changed'
1031
1370
  : shown !== null
1032
1371
  ? ' is-revealed'
1033
- : '';
1372
+ : removed
1373
+ ? ' is-removed'
1374
+ : inherited
1375
+ ? ' is-inherited'
1376
+ : '';
1034
1377
  const version = entry.version ?? 0;
1035
1378
 
1036
1379
  return (
@@ -1038,7 +1381,8 @@ function SecretRow({
1038
1381
  <tr className={`secret-row${state} ${rowClass(status)}`}>
1039
1382
  <td className="n">{number}</td>
1040
1383
  <td className="cell-key" data-label="Key">
1041
- {editing && canWrite ? (
1384
+ {/* An inherited key has no row here to rename: overriding it keeps its name. */}
1385
+ {editing && canWrite && own ? (
1042
1386
  <div className="edit-stack">
1043
1387
  <input
1044
1388
  className="input input-mono"
@@ -1067,7 +1411,9 @@ function SecretRow({
1067
1411
  ) : (
1068
1412
  <div className="key-cell">
1069
1413
  <span>{breakAfterUnderscores(entry.key)}</span>
1414
+ {generated !== null && <RecipeMark generated={generated} />}
1070
1415
  {leaving && <span className="tag tag-red">Will be archived</span>}
1416
+ {parent !== null && <Standing project={project} secretKey={entry.key} parent={parent} />}
1071
1417
  {lent.length > 0 && (
1072
1418
  <button
1073
1419
  type="button"
@@ -1096,9 +1442,9 @@ function SecretRow({
1096
1442
  placeholder={canReveal ? 'Value' : 'New value; the current one is hidden from you'}
1097
1443
  disabled={disabled}
1098
1444
  autoFocus={!focusName}
1099
- // A value typed over a generated private key no longer matches its public key.
1445
+ // A value typed over a generated one has no recipe, and a private key's no longer matches its public key.
1100
1446
  onChange={(value) =>
1101
- onPatch({ value: value === (editBase?.value ?? '') ? null : value, companion: undefined })
1447
+ onPatch({ value: value === (editBase?.value ?? '') ? null : value, companion: undefined, recipe: undefined })
1102
1448
  }
1103
1449
  onEscape={onUndo}
1104
1450
  generate={{
@@ -1106,10 +1452,13 @@ function SecretRow({
1106
1452
  name: change.key,
1107
1453
  renamable: false,
1108
1454
  companion: change.companion,
1109
- onUse: ({ value, companion }) => onPatch({ value, companion }),
1455
+ onUse: ({ value, companion, recipe }) => onPatch({ value, companion, recipe }),
1110
1456
  }}
1111
1457
  />
1112
1458
  <CompanionNote companion={change.companion} versionOf={versionOf} />
1459
+ {!overridden && parent !== null && (
1460
+ <span className="edit-note">Saved here, over {parent.from}'s value</span>
1461
+ )}
1113
1462
  {reference !== null && reference.state === 'live' && (
1114
1463
  <span className="edit-note">
1115
1464
  Saving a value stops following <span className="mono">{reference.source}</span>
@@ -1127,6 +1476,8 @@ function SecretRow({
1127
1476
  </span>
1128
1477
  <span className="revealed-meter" aria-hidden />
1129
1478
  </div>
1479
+ ) : removed ? (
1480
+ <span className="cell-muted">Not served here</span>
1130
1481
  ) : reference !== null ? (
1131
1482
  <ReferenceValue reference={reference} />
1132
1483
  ) : (
@@ -1160,18 +1511,26 @@ function SecretRow({
1160
1511
  </button>
1161
1512
  </Tip>
1162
1513
  </>
1514
+ ) : removed ? (
1515
+ canWrite && (
1516
+ <button type="button" className="btn btn-sm" onClick={() => onFork('restore')} disabled={disabled}>
1517
+ Restore
1518
+ </button>
1519
+ )
1163
1520
  ) : (
1164
1521
  <>
1165
- {/* Copy comes in to the left, so Hide stays where Reveal was clicked. */}
1166
- {shown !== null && (
1167
- <CopyButton variant="act" value={shown.value} label={`Copy ${entry.key}`} />
1168
- )}
1169
- <SecretReadOnly canReveal={canReveal}>
1522
+ {/* Copy sits left of Reveal, hidden or shown, so Hide stays where
1523
+ Reveal was clicked. Hidden, it copies without showing the value;
1524
+ as for Reveal, it takes secret.read, and a reference copies the
1525
+ value it reads through; an inherited key, its parent's, which
1526
+ takes read there too. */}
1527
+ <SecretReadOnly canReveal={canRead}>
1528
+ <CopyButton variant="act" copier={copier} onCopy={copyValue} label={`Copy ${entry.key}`} />
1170
1529
  <Tip label={shown === null ? 'Reveal' : 'Hide'}>
1171
1530
  <button
1172
1531
  className="act act-icon act-accent"
1173
1532
  onClick={toggleReveal}
1174
- disabled={revealing}
1533
+ disabled={revealToggleDisabled(reads, shown)}
1175
1534
  aria-label={`${shown === null ? 'Reveal' : 'Hide'} ${entry.key}`}
1176
1535
  >
1177
1536
  {revealing && !opening ? (
@@ -1185,12 +1544,12 @@ function SecretRow({
1185
1544
  </Tip>
1186
1545
  </SecretReadOnly>
1187
1546
  {canWrite && (
1188
- <Tip label="Edit">
1547
+ <Tip label={inherited ? `Override ${parent!.from}'s` : 'Edit'}>
1189
1548
  <button
1190
1549
  className="act act-icon"
1191
1550
  onClick={() => void startEdit()}
1192
1551
  disabled={disabled || revealing}
1193
- aria-label={`Edit ${entry.key}`}
1552
+ aria-label={inherited ? `Override ${entry.key}` : `Edit ${entry.key}`}
1194
1553
  >
1195
1554
  {opening ? <Spinner size={13} /> : <Pencil size={14} />}
1196
1555
  </button>
@@ -1204,26 +1563,33 @@ function SecretRow({
1204
1563
  </td>
1205
1564
 
1206
1565
  <td className="col-version" data-label="Version">
1207
- {editing && valueChanged ? (
1566
+ {editing && valueChanged && !overridden && parent !== null ? (
1567
+ <span className="version-shift">
1568
+ <b>own</b>
1569
+ </span>
1570
+ ) : editing && valueChanged ? (
1208
1571
  <span className="version-shift">
1209
1572
  v{version} → <b>v{version + 1}</b>
1210
1573
  </span>
1211
1574
  ) : (
1212
- <span className="version-shift" title={reference === null ? undefined : "The source's version"}>
1575
+ <span
1576
+ className="version-shift"
1577
+ title={inherited ? `${parent!.from}'s version` : reference === null ? undefined : "The source's version"}
1578
+ >
1213
1579
  {readVersion === null ? '—' : `v${readVersion}`}
1214
1580
  </span>
1215
1581
  )}
1216
1582
  </td>
1217
1583
 
1218
1584
  <td className="col-written" data-label="Last written">
1219
- <Written entry={entry} rotateAfterDays={rotateAfterDays} />
1585
+ {!removed && <Written entry={entry} rotateAfterDays={rotateAfterDays} />}
1220
1586
  </td>
1221
1587
 
1222
1588
  <td className="col-actions">
1223
1589
  {status.state === 'pending' ? (
1224
1590
  <RowPending status={status} />
1225
1591
  ) : (
1226
- (canReveal || (canWrite && !editing && !leaving) || (canArchive && !leaving)) && (
1592
+ !removed && (canReveal || (canWrite && !editing && !leaving) || (canArchive && !leaving && own && !overridden)) && (
1227
1593
  <Menu.Root>
1228
1594
  <Menu.Trigger
1229
1595
  className="act act-icon act-quiet"
@@ -1233,37 +1599,72 @@ function SecretRow({
1233
1599
  <MoreHorizontal size={16} />
1234
1600
  </Menu.Trigger>
1235
1601
  <MenuPopup align="end">
1236
- <SecretReadOnly canReveal={canReveal}>
1602
+ <SecretReadOnly canReveal={canReveal && own}>
1237
1603
  <Menu.Item className="menu-item" onClick={() => setHistoryOpen((open) => !open)}>
1238
1604
  <History size={14} />
1239
1605
  {historyOpen ? 'Hide history' : 'Version history'}
1240
1606
  </Menu.Item>
1241
1607
  </SecretReadOnly>
1242
- {canWrite && !editing && !leaving && (
1608
+ {canWrite && !editing && inherited && (
1609
+ <>
1610
+ <Menu.Item className="menu-item" onClick={() => void startEdit()}>
1611
+ <Pencil size={14} />
1612
+ Override…
1613
+ </Menu.Item>
1614
+ {parent!.reset && (
1615
+ <Menu.Item className="menu-item" onClick={() => onFork('override')}>
1616
+ <RotateBack size={14} />
1617
+ Use its own value again
1618
+ </Menu.Item>
1619
+ )}
1620
+ <Menu.Item className="menu-item" onClick={() => onFork('remove')}>
1621
+ <SlashCircle size={14} />
1622
+ Remove from {environment}
1623
+ </Menu.Item>
1624
+ </>
1625
+ )}
1626
+ {canWrite && !editing && !leaving && overridden && (
1627
+ <Menu.Item className="menu-item" onClick={() => onFork('reset')}>
1628
+ <RotateBack size={14} />
1629
+ Reset to {parent!.from}
1630
+ </Menu.Item>
1631
+ )}
1632
+ {canWrite && !editing && !leaving && own && (
1243
1633
  <Menu.Item className="menu-item" onClick={() => void startEdit({ name: true })}>
1244
1634
  <Pencil size={14} />
1245
1635
  Rename
1246
1636
  </Menu.Item>
1247
1637
  )}
1248
- {canWrite && !editing && !leaving && (
1638
+ {canWrite && !editing && !leaving && generated !== null && (
1639
+ <Menu.Item
1640
+ className="menu-item"
1641
+ disabled={regenerateWaits(entry.key, generated, busy)}
1642
+ onClick={() => setRegenerating(true)}
1643
+ >
1644
+ <Generate size={14} />
1645
+ Regenerate…
1646
+ </Menu.Item>
1647
+ )}
1648
+ {canWrite && !editing && !leaving && own && (
1249
1649
  <Menu.Item className="menu-item" onClick={() => setMoving(true)}>
1250
1650
  <Folder size={14} />
1251
1651
  Move to folder…
1252
1652
  </Menu.Item>
1253
1653
  )}
1254
- {canWrite && !editing && !leaving && (
1654
+ {canWrite && !editing && !leaving && own && environments.length > 0 && (
1255
1655
  <Menu.Item className="menu-item" onClick={() => setReferring(true)}>
1256
1656
  <ArrowRight size={14} />
1257
1657
  {reference === null ? 'Make a reference…' : 'Point elsewhere…'}
1258
1658
  </Menu.Item>
1259
1659
  )}
1260
- {canWrite && !editing && !leaving && reference !== null && reference.state === 'live' && (
1660
+ {canWrite && !editing && !leaving && own && reference !== null && reference.state === 'live' && (
1261
1661
  <Menu.Item className="menu-item" onClick={() => setBreaking(holderPath)}>
1262
1662
  <SlashCircle size={14} />
1263
1663
  Break reference…
1264
1664
  </Menu.Item>
1265
1665
  )}
1266
- {canArchive && !leaving && (
1666
+ {/* An override's way out is Reset, which keeps it; archiving there would be the same, by more. */}
1667
+ {canArchive && !leaving && own && !overridden && (
1267
1668
  <>
1268
1669
  {(canReveal || canWrite) && <Menu.Separator className="menu-sep" />}
1269
1670
  <Menu.Item
@@ -1302,6 +1703,20 @@ function SecretRow({
1302
1703
  />
1303
1704
  )}
1304
1705
 
1706
+ {canWrite && generated !== null && (
1707
+ <RegenerateSecret
1708
+ open={regenerating}
1709
+ onOpenChange={setRegenerating}
1710
+ place={`${project}/${environment}`}
1711
+ entry={entry}
1712
+ generated={generated}
1713
+ onConfirm={() => {
1714
+ setReveal(null);
1715
+ onRegenerate(generated);
1716
+ }}
1717
+ />
1718
+ )}
1719
+
1305
1720
  <ConfirmDialog
1306
1721
  open={archiveBlocked}
1307
1722
  onOpenChange={setArchiveBlocked}
@@ -1371,17 +1786,129 @@ function SecretRow({
1371
1786
  </tr>
1372
1787
  )}
1373
1788
 
1374
- {(error ?? actError) !== null && (
1789
+ {(error ?? actError) !== null || copyError !== null ? (
1375
1790
  <tr className="row-error">
1376
1791
  <td colSpan={columns}>
1377
- <ErrorLine error={(error ?? actError)!} />
1792
+ {/* Reveal's refusal and Copy's are independent: neither hides the other. */}
1793
+ <ErrorLine error={error ?? actError} />
1794
+ <ErrorLine error={copyError} />
1378
1795
  </td>
1379
1796
  </tr>
1380
- )}
1797
+ ) : null}
1798
+
1799
+ <RowFailure
1800
+ status={status}
1801
+ columns={columns}
1802
+ onDismiss={() => status.state === 'failed' && onDismiss(status.mutationId)}
1803
+ />
1804
+ </>
1805
+ );
1806
+ }
1807
+
1808
+ /** Delete your personal config, from its page: its values erased; dev itself untouched. */
1809
+ function DeletePersonal({ project, environment, of }: { project: string; environment: string; of: string }) {
1810
+ const coffre = useCoffre();
1811
+ const navigate = useNavigate();
1812
+ const [open, setOpen] = useState(false);
1813
+ const { error, run } = useAction();
1814
+ return (
1815
+ <>
1816
+ <button type="button" className="btn btn-sm" onClick={() => setOpen(true)}>
1817
+ <Trash size={14} />
1818
+ Delete…
1819
+ </button>
1820
+ {error !== null && <ErrorLine error={error} />}
1821
+ <ConfirmDialog
1822
+ open={open}
1823
+ onOpenChange={setOpen}
1824
+ title={<>Delete your own <span className="mono">{of}</span>?</>}
1825
+ body={`The values you set in ${project}/${environment} are erased for good. ${project}/${of} is untouched, and ${environment} reads it again.`}
1826
+ confirmLabel="Delete"
1827
+ onConfirm={() =>
1828
+ void run(() => coffre.environments.delete(`${project}/${environment}`), {
1829
+ affects: [...affects.secrets({ project, environment }), ...affects.places()],
1830
+ onSuccess: () => {
1831
+ toast.success(`Your own ${of} is deleted`);
1832
+ void navigate({ to: '/projects/$project/$environment', params: { project, environment: of } });
1833
+ },
1834
+ })}
1835
+ />
1381
1836
  </>
1382
1837
  );
1383
1838
  }
1384
1839
 
1840
+ /**
1841
+ * `dev@me` while you have no personal dev: what one is, and Make, which
1842
+ * makes it empty; your first write would make it too. A read of
1843
+ * `market/dev@me` meanwhile is dev's, so scripts can name it either way.
1844
+ */
1845
+ function NoPersonalConfig({ project, of }: { project: string; of: string }) {
1846
+ const coffre = useCoffre();
1847
+ const { pending, error, run } = useAction();
1848
+ return (
1849
+ <>
1850
+ <PageHeader tile={project} title={`${of}@me`} />
1851
+ <Card labelledBy="no-personal-config" title={`You have no personal ${of} yet`}>
1852
+ <div className="card-row">
1853
+ <div>
1854
+ <p className="card-row-desc">
1855
+ A personal config is your own <span className="mono">{project}/{of}</span>: it reads {of}'s keys as they change,
1856
+ and the values you set or remove there are yours alone. No one else reads them, an Owner included, and you read
1857
+ them only while you read {of}. Until you make one, <span className="mono">{project}/{of}@me</span> reads {of} itself,
1858
+ so a script can name it either way.
1859
+ </p>
1860
+ {error !== null && <ErrorLine error={error} />}
1861
+ </div>
1862
+ <button
1863
+ type="button"
1864
+ className="btn btn-primary"
1865
+ disabled={pending}
1866
+ onClick={() => void run(() => coffre.environments.create(`${project}/${of}@me`), {
1867
+ affects: [...affects.secrets({ project, environment: `${of}@me` }), ...affects.places()],
1868
+ onSuccess: () => toast.success(`Your own ${of} is made: what you set there is yours alone`),
1869
+ })}
1870
+ >
1871
+ {pending ? <Spinner size={13} /> : <Plus size={14} />}
1872
+ Make my own {of}
1873
+ </button>
1874
+ </div>
1875
+ </Card>
1876
+ </>
1877
+ );
1878
+ }
1879
+
1880
+ /**
1881
+ * Where a fork's key stands to its parent's (docs/design/forking.md):
1882
+ * inherited from it, overriding it, perhaps since it changed, or removed.
1883
+ * The parent links to its own row of the key.
1884
+ */
1885
+ function Standing({ project, secretKey, parent }: { project: string; secretKey: string; parent: NonNullable<SecretKey['parent']> }) {
1886
+ const from = (
1887
+ <Link className="tag-link" to="/projects/$project/$environment" params={{ project, environment: parent.from }} search={{ filter: secretKey }}>
1888
+ {parent.from}
1889
+ </Link>
1890
+ );
1891
+ switch (parent.state) {
1892
+ case 'inherited':
1893
+ return <span className="tag tag-outline">from {from}</span>;
1894
+ case 'removed':
1895
+ return <span className="tag tag-outline">removed · {from} {parent.held ? 'has it' : 'dropped it'}</span>;
1896
+ case 'overridden':
1897
+ return (
1898
+ <>
1899
+ <span className="tag tag-outline">overrides {from}</span>
1900
+ {parent.changed && (
1901
+ <Tip label={`${parent.from} has written a newer value since this one: check the override still holds`}>
1902
+ <span className="tag tag-amber" tabIndex={0}>
1903
+ {parent.from} changed since
1904
+ </span>
1905
+ </Tip>
1906
+ )}
1907
+ </>
1908
+ );
1909
+ }
1910
+ }
1911
+
1385
1912
  /**
1386
1913
  * A column header that orders the table: its first click ascending, the
1387
1914
  * next descending. Below the width where rows stack, the sortable headers
@@ -1505,7 +2032,7 @@ function DraftRow({
1505
2032
  <input
1506
2033
  className="input input-mono"
1507
2034
  // Only the row that just mounted takes focus, which is the one the
1508
- // New secret button created.
2035
+ // Add secret button created.
1509
2036
  autoFocus
1510
2037
  aria-label="Name of the new secret"
1511
2038
  aria-invalid={keyProblem !== null}
@@ -1537,14 +2064,14 @@ function DraftRow({
1537
2064
  value={draft.value}
1538
2065
  placeholder="Value"
1539
2066
  disabled={disabled}
1540
- // A value typed over a generated private key no longer matches its public key.
1541
- onChange={(value) => onChange({ value, companion: undefined })}
2067
+ // A value typed over a generated one has no recipe, and a private key's no longer matches its public key.
2068
+ onChange={(value) => onChange({ value, companion: undefined, recipe: undefined })}
1542
2069
  onEscape={onRemove}
1543
2070
  generate={{
1544
2071
  name: draft.key,
1545
2072
  renamable: true,
1546
2073
  companion: draft.companion,
1547
- onUse: ({ value, name, companion }) => onChange({ key: name, value, companion }),
2074
+ onUse: ({ value, name, companion, recipe }) => onChange({ key: name, value, companion, recipe }),
1548
2075
  }}
1549
2076
  />
1550
2077
  <CompanionNote companion={draft.companion} versionOf={versionOf} />
@@ -1786,7 +2313,14 @@ function VersionHistory({
1786
2313
  <td className="nowrap">
1787
2314
  <Timestamp iso={version.createdAt} />
1788
2315
  </td>
1789
- <td>{version.createdBy}</td>
2316
+ <td>
2317
+ {version.createdBy}
2318
+ {version.recipe !== null && (
2319
+ <span className="cell-muted">
2320
+ {' '}· generated, <span className="mono">{version.recipe}</span>
2321
+ </span>
2322
+ )}
2323
+ </td>
1790
2324
  <td className="cell-mono cell-muted nowrap">{version.kek}</td>
1791
2325
  <td className="col-actions">
1792
2326
  {canWrite && !version.current && (