@coffre/ui 0.5.1 → 0.6.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 (120) hide show
  1. package/dist/chunks/{affordances-Bqdevf7w.js → affordances-D0GyCT-I.js} +3 -3
  2. package/dist/chunks/affordances-D0GyCT-I.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-Cm5nby5k.js → audit-sentence-CUUMshIp.js} +22 -6
  4. package/dist/chunks/audit-sentence-CUUMshIp.js.map +1 -0
  5. package/dist/chunks/{connected-apps-DTNS7YmY.js → connected-apps-IP0KfUjo.js} +5 -5
  6. package/dist/chunks/{connected-apps-DTNS7YmY.js.map → connected-apps-IP0KfUjo.js.map} +1 -1
  7. package/dist/chunks/{delete-place-CIaOq0mt.js → delete-place-CVv6CN5y.js} +5 -5
  8. package/dist/chunks/{delete-place-CIaOq0mt.js.map → delete-place-CVv6CN5y.js.map} +1 -1
  9. package/dist/chunks/{directory-DSVt5Tya.js → directory-pMVS1m-c.js} +62 -43
  10. package/dist/chunks/directory-pMVS1m-c.js.map +1 -0
  11. package/dist/chunks/{folders-CoGK9oqg.js → folders-hR2Lnk0k.js} +3 -3
  12. package/dist/chunks/{folders-CoGK9oqg.js.map → folders-hR2Lnk0k.js.map} +1 -1
  13. package/dist/chunks/{grants-CRU7yZhL.js → grants-CgC8Ybhu.js} +6 -6
  14. package/dist/chunks/{grants-CRU7yZhL.js.map → grants-CgC8Ybhu.js.map} +1 -1
  15. package/dist/chunks/{offboarding-DVBSiJRZ.js → offboarding-3fzRjKla.js} +5 -5
  16. package/dist/chunks/{offboarding-DVBSiJRZ.js.map → offboarding-3fzRjKla.js.map} +1 -1
  17. package/dist/chunks/{page-DvsgZ2Hd.js → page-JTORvh-N.js} +7 -3
  18. package/dist/chunks/page-JTORvh-N.js.map +1 -0
  19. package/dist/chunks/{principal-BIN-xwZw.js → principal-DFBswTBr.js} +2 -2
  20. package/dist/chunks/{principal-BIN-xwZw.js.map → principal-DFBswTBr.js.map} +1 -1
  21. package/dist/chunks/{principal-page-BEBr_zW7.js → principal-page-CYJIJAdp.js} +17 -19
  22. package/dist/chunks/principal-page-CYJIJAdp.js.map +1 -0
  23. package/dist/chunks/{project-page-B3TZ5_ig.js → project-page-lO5P6iCb.js} +3 -3
  24. package/dist/chunks/{project-page-B3TZ5_ig.js.map → project-page-lO5P6iCb.js.map} +1 -1
  25. package/dist/chunks/{queries-DE5nK2y4.js → queries-gigcQOO_.js} +26 -12
  26. package/dist/chunks/queries-gigcQOO_.js.map +1 -0
  27. package/dist/chunks/{references-uv4Mli9z.js → references-DZ179hTJ.js} +5 -5
  28. package/dist/chunks/{references-uv4Mli9z.js.map → references-DZ179hTJ.js.map} +1 -1
  29. package/dist/chunks/{role-field-DWhkRY6n.js → role-field-DiqiFwm_.js} +14 -7
  30. package/dist/chunks/role-field-DiqiFwm_.js.map +1 -0
  31. package/dist/chunks/{row-state-DOPUsjQK.js → row-state-Zf3kZVhd.js} +13 -5
  32. package/dist/chunks/row-state-Zf3kZVhd.js.map +1 -0
  33. package/dist/chunks/{signin-errors--ykMFuqN.js → signin-errors-TlQmQe0t.js} +2 -2
  34. package/dist/chunks/signin-errors-TlQmQe0t.js.map +1 -0
  35. package/dist/chunks/{theme-DJuz-xLM.js → theme-B6-V9JvY.js} +3 -3
  36. package/dist/chunks/{theme-DJuz-xLM.js.map → theme-B6-V9JvY.js.map} +1 -1
  37. package/dist/chunks/{ui-DJje3gST.js → ui-Br-dNUTc.js} +2 -2
  38. package/dist/chunks/{ui-DJje3gST.js.map → ui-Br-dNUTc.js.map} +1 -1
  39. package/dist/chunks/{use-action-BRgvbUWt.js → use-action-CQGGNqWb.js} +3 -3
  40. package/dist/chunks/{use-action-BRgvbUWt.js.map → use-action-CQGGNqWb.js.map} +1 -1
  41. package/dist/chunks/{use-change-BJ3dCFHb.js → use-change-BdS1gzyo.js} +31 -19
  42. package/dist/chunks/use-change-BdS1gzyo.js.map +1 -0
  43. package/dist/chunks/{use-shell-BO4ZTr1y.js → use-shell-BCU505bx.js} +3 -3
  44. package/dist/chunks/{use-shell-BO4ZTr1y.js.map → use-shell-BCU505bx.js.map} +1 -1
  45. package/dist/index.d.ts +6 -7
  46. package/dist/index.js +8 -9
  47. package/dist/index.js.map +1 -1
  48. package/dist/pages/account.js +12 -13
  49. package/dist/pages/account.js.map +1 -1
  50. package/dist/pages/approval.js +2 -2
  51. package/dist/pages/audit.js +5 -5
  52. package/dist/pages/audit.js.map +1 -1
  53. package/dist/pages/device-login.js +2 -2
  54. package/dist/pages/environment.js +829 -155
  55. package/dist/pages/environment.js.map +1 -1
  56. package/dist/pages/login.js +4 -4
  57. package/dist/pages/oauth-authorize.js +2 -2
  58. package/dist/pages/project-access.js +160 -80
  59. package/dist/pages/project-access.js.map +1 -1
  60. package/dist/pages/project-environments.js +10 -10
  61. package/dist/pages/project-settings.js +8 -8
  62. package/dist/pages/project.js +3 -3
  63. package/dist/pages/projects.js +10 -10
  64. package/dist/pages/projects.js.map +1 -1
  65. package/dist/pages/service-account.js +537 -109
  66. package/dist/pages/service-account.js.map +1 -1
  67. package/dist/pages/service-accounts.js +5 -5
  68. package/dist/pages/settings.js +8 -18
  69. package/dist/pages/settings.js.map +1 -1
  70. package/dist/pages/unregistered.js +3 -3
  71. package/dist/pages/unregistered.js.map +1 -1
  72. package/dist/pages/user.js +6 -6
  73. package/dist/pages/users.js +5 -5
  74. package/package.json +3 -3
  75. package/src/components/affordances.ts +1 -1
  76. package/src/components/directory.tsx +40 -34
  77. package/src/components/generate-value.tsx +362 -0
  78. package/src/components/github-picker.tsx +83 -0
  79. package/src/components/icons.tsx +4 -0
  80. package/src/components/masked.tsx +60 -0
  81. package/src/components/missing.tsx +3 -3
  82. package/src/components/multi-combobox.tsx +94 -0
  83. package/src/components/principal-page.tsx +8 -12
  84. package/src/components/principal-picker.tsx +68 -18
  85. package/src/components/role-field.tsx +7 -5
  86. package/src/components/row-state.tsx +7 -3
  87. package/src/components/shell.tsx +0 -1
  88. package/src/components/trusted-workloads.tsx +157 -62
  89. package/src/lib/audit-sentences.ts +25 -3
  90. package/src/lib/bindings.ts +125 -14
  91. package/src/lib/capabilities.ts +15 -9
  92. package/src/lib/changes.ts +15 -9
  93. package/src/lib/coffre.ts +2 -0
  94. package/src/lib/generate.ts +160 -0
  95. package/src/lib/queries.ts +18 -5
  96. package/src/lib/secret-edit-batch.ts +38 -5
  97. package/src/lib/secret-order.ts +23 -0
  98. package/src/lib/shortcuts.ts +9 -0
  99. package/src/lib/signin-errors.ts +1 -1
  100. package/src/lib/use-github-lookup.ts +70 -0
  101. package/src/pages/account.tsx +1 -2
  102. package/src/pages/audit.tsx +1 -1
  103. package/src/pages/environment.tsx +228 -119
  104. package/src/pages/project-access.tsx +19 -8
  105. package/src/pages/projects.tsx +3 -3
  106. package/src/pages/settings.tsx +0 -10
  107. package/src/pages/unregistered.tsx +1 -1
  108. package/src/parity.ts +3 -1
  109. package/src/shared/models.ts +2 -2
  110. package/src/styles/globals.css +303 -19
  111. package/dist/chunks/affordances-Bqdevf7w.js.map +0 -1
  112. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +0 -1
  113. package/dist/chunks/directory-DSVt5Tya.js.map +0 -1
  114. package/dist/chunks/page-DvsgZ2Hd.js.map +0 -1
  115. package/dist/chunks/principal-page-BEBr_zW7.js.map +0 -1
  116. package/dist/chunks/queries-DE5nK2y4.js.map +0 -1
  117. package/dist/chunks/role-field-DWhkRY6n.js.map +0 -1
  118. package/dist/chunks/row-state-DOPUsjQK.js.map +0 -1
  119. package/dist/chunks/signin-errors--ykMFuqN.js.map +0 -1
  120. package/dist/chunks/use-change-BJ3dCFHb.js.map +0 -1
@@ -1,12 +1,6 @@
1
- import { byFolder, CoffreError, foldersOf, planImport, type CoffreClient, type ListedReference } from '@coffre/client';
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 {
4
- useEffect,
5
- useRef,
6
- useState,
7
- type InputHTMLAttributes,
8
- type TextareaHTMLAttributes,
9
- } from 'react';
3
+ import { useEffect, useRef, useState, type ReactNode } from 'react';
10
4
  import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
11
5
  import { Link } from '@tanstack/react-router';
12
6
  import { useShell } from '../lib/use-shell';
@@ -28,12 +22,16 @@ import type {
28
22
  } from '../shared/models';
29
23
  import { canRevealSecrets } from '../lib/capabilities';
30
24
  import {
25
+ companionsOf,
31
26
  hasSecretEditConflict,
32
27
  secretChangeFor,
28
+ type Companion,
33
29
  type SecretChange,
34
30
  type SecretDraft,
35
31
  } from '../lib/secret-edit-batch';
36
32
  import { revealIsCurrent, type Reveal } from '../lib/reveal';
33
+ import { sortKeys, type Sort } from '../lib/secret-order';
34
+ import { inDialog } from '../lib/shortcuts';
37
35
  import { secretKeyProblem } from '../lib/validation';
38
36
  import {
39
37
  breakAfterUnderscores,
@@ -51,6 +49,8 @@ import {
51
49
  } from '../components/ui';
52
50
  import { Card, ClosedDoor, PageHeader } from '../components/page';
53
51
  import { SecretReadOnly } from '../components/affordances';
52
+ import { GenerateValue, type GeneratedUse } from '../components/generate-value';
53
+ import { MaskedInput, MaskedTextarea } from '../components/masked';
54
54
  import { FolderMenu, FolderRow, MoveToFolder } from '../components/folders';
55
55
  import { MissingKeys } from '../components/missing';
56
56
  import { ArchiveBlocked, archiveBlockers, LentReferences, MakeReference, ReferenceValue } from '../components/references';
@@ -62,8 +62,11 @@ import {
62
62
  Clock,
63
63
  Eye,
64
64
  ArrowRight,
65
+ ChevronDown,
66
+ ChevronsUpDown,
65
67
  EyeOff,
66
68
  Folder,
69
+ Generate,
67
70
  Hash,
68
71
  History,
69
72
  Key,
@@ -127,6 +130,7 @@ export function EnvironmentPage() {
127
130
  environment={environment}
128
131
  permissions={result.permissions}
129
132
  keys={result.keys}
133
+ rotateAfterDays={result.rotateAfterDays}
130
134
  />
131
135
  );
132
136
  }
@@ -138,11 +142,14 @@ function EnvironmentLedger({
138
142
  environment,
139
143
  permissions,
140
144
  keys,
145
+ rotateAfterDays,
141
146
  }: {
142
147
  project: string;
143
148
  environment: string;
144
149
  permissions: Permission[];
145
150
  keys: SecretKey[];
151
+ /** Days a value may go unchanged before it is flagged for rotation; null for no flag. */
152
+ rotateAfterDays: number | null;
146
153
  }) {
147
154
  const coffre = useCoffre();
148
155
  const { principal } = useShell();
@@ -169,6 +176,9 @@ function EnvironmentLedger({
169
176
  const [editing, setEditing] = useState<ReadonlySet<string>>(() => new Set());
170
177
  const [saveError, setSaveError] = useState<string | null>(null);
171
178
  const [query, setQuery] = useState(Route.useSearch().filter ?? '');
179
+ const [sort, setSort] = useState<Sort>({ by: 'key', descending: false });
180
+ // A column's first click sorts it ascending: names A to Z, the oldest values first.
181
+ const sortBy = (by: Sort['by']) => setSort((current) => ({ by, descending: current.by === by && !current.descending }));
172
182
  const nextDraftId = useRef(0);
173
183
 
174
184
  const canWrite = permissions.includes('secret.write');
@@ -202,6 +212,7 @@ function EnvironmentLedger({
202
212
  );
203
213
  const archived = keys.filter((entry) => entry.archived);
204
214
  const existing = new Set(keys.map((entry) => entry.key));
215
+ const versionOf = (key: string) => keys.find((entry) => entry.key === key.trim())?.version ?? null;
205
216
 
206
217
  const changedEntries = active.filter(
207
218
  (entry) => secretChangeFor(changes, entry.key) !== undefined,
@@ -215,6 +226,7 @@ function EnvironmentLedger({
215
226
  const change = secretChangeFor(changes, entry.key);
216
227
  return change === undefined || change.archived ? [] : [change.key.trim()];
217
228
  }),
229
+ ...companionsOf(active, drafts, changes).map((companion) => companion.key.trim()),
218
230
  ];
219
231
  const unnamed = pendingNames.some((name) => name === '');
220
232
  const invalid = pendingNames.some((name) => name !== '' && secretKeyProblem(name) !== null);
@@ -259,6 +271,7 @@ function EnvironmentLedger({
259
271
  const names = [
260
272
  ...drafts.map((row) => row.key.trim()),
261
273
  ...Object.values(changes).flatMap((change) => (change.archived ? [] : [change.key.trim()])),
274
+ ...companionsOf(active, drafts, changes).map((companion) => companion.key.trim()),
262
275
  ];
263
276
  return (
264
277
  (drafts.length > 0 || Object.keys(changes).length > 0) &&
@@ -292,9 +305,9 @@ function EnvironmentLedger({
292
305
  });
293
306
  }
294
307
 
295
- function addDraft() {
308
+ function addDraft(key = '') {
296
309
  // New rows go last, by the button that made them, in the order they were added.
297
- setDrafts((rows) => [...rows, { id: nextDraftId.current++, key: '', value: '' }]);
310
+ setDrafts((rows) => [...rows, { id: nextDraftId.current++, key, value: '' }]);
298
311
  }
299
312
 
300
313
  function discardAll() {
@@ -351,13 +364,14 @@ function EnvironmentLedger({
351
364
  );
352
365
  }
353
366
 
354
- // Cmd/Ctrl+Enter saves from anywhere on the page while edits are pending.
367
+ // Cmd/Ctrl+Enter saves from anywhere on the page while edits are pending,
368
+ // but for an open dialog, such as Generate's.
355
369
  const saveRef = useRef(saveChanges);
356
370
  saveRef.current = saveChanges;
357
371
  useEffect(() => {
358
372
  if (pendingCount === 0) return;
359
373
  function onKeyDown(event: KeyboardEvent) {
360
- if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
374
+ if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && !inDialog(event.target)) {
361
375
  event.preventDefault();
362
376
  saveRef.current();
363
377
  }
@@ -366,20 +380,22 @@ function EnvironmentLedger({
366
380
  return () => document.removeEventListener('keydown', onKeyDown);
367
381
  }, [pendingCount]);
368
382
 
383
+ const withCompanion = (what: string, companion: Companion | undefined) =>
384
+ companion === undefined ? what : `${what}, with ${companion.key.trim()}`;
369
385
  const pending: Pending[] = [
370
386
  ...drafts.map((draft) => ({
371
387
  key: draft.key.trim() || 'unnamed',
372
- what: existing.has(draft.key.trim()) ? 'new version' : 'added',
388
+ what: withCompanion(existing.has(draft.key.trim()) ? 'new version' : 'added', draft.companion),
373
389
  })),
374
390
  ...changedEntries.map((entry) => {
375
391
  const change = secretChangeFor(changes, entry.key)!;
376
392
  if (change.archived) return { key: entry.key, what: 'archived' };
377
393
  const renamed = change.key.trim() !== entry.key;
378
394
  if (renamed && change.value !== null) {
379
- return { key: entry.key, what: `→ ${change.key.trim()}, new value` };
395
+ return { key: entry.key, what: withCompanion(`→ ${change.key.trim()}, new value`, change.companion) };
380
396
  }
381
397
  if (renamed) return { key: entry.key, what: `→ ${change.key.trim()}` };
382
- return { key: entry.key, what: 'new value' };
398
+ return { key: entry.key, what: withCompanion('new value', change.companion) };
383
399
  }),
384
400
  ];
385
401
 
@@ -396,8 +412,10 @@ function EnvironmentLedger({
396
412
  // Filtering narrows what is listed, never what is saved: a pending edit on
397
413
  // a row the filter hides still counts, and still shows in the save bar.
398
414
  const needle = query.trim().toLowerCase();
399
- const listed =
400
- needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle));
415
+ const listed = sortKeys(
416
+ needle === '' ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)),
417
+ sort,
418
+ );
401
419
  const columns = 6;
402
420
 
403
421
  return (
@@ -442,7 +460,7 @@ function EnvironmentLedger({
442
460
  project={project}
443
461
  environment={environment}
444
462
  canWrite={canWrite}
445
- onAdd={(key) => setDrafts((rows) => [...rows, { id: nextDraftId.current++, key, value: '' }])}
463
+ onAdd={addDraft}
446
464
  />
447
465
 
448
466
  {refile.error !== null && <ErrorLine error={refile.error} />}
@@ -455,16 +473,14 @@ function EnvironmentLedger({
455
473
  </EmptyState>
456
474
  ) : (
457
475
  <div className="dt-wrap">
458
- <table className="dt secrets stacks">
476
+ <table className="dt secrets stacks sortable">
459
477
  <thead>
460
478
  <tr>
461
479
  <th className="n">#</th>
462
- <th className="col-key">
463
- <span className="th">
464
- <Key size={14} />
465
- Key
466
- </span>
467
- </th>
480
+ <SortHeader className="col-key" by="key" sort={sort} onSort={sortBy}>
481
+ <Key size={14} />
482
+ Key
483
+ </SortHeader>
468
484
  <th>
469
485
  <span className="th">
470
486
  <Lock size={14} />
@@ -478,12 +494,10 @@ function EnvironmentLedger({
478
494
  Version
479
495
  </span>
480
496
  </th>
481
- <th className="col-written col-hide-narrow">
482
- <span className="th">
483
- <Clock size={14} />
484
- Last written
485
- </span>
486
- </th>
497
+ <SortHeader className="col-written" by="written" sort={sort} onSort={sortBy}>
498
+ <Clock size={14} />
499
+ Last written
500
+ </SortHeader>
487
501
  <th className="col-actions">
488
502
  <span className="visually-hidden">Actions</span>
489
503
  </th>
@@ -502,6 +516,7 @@ function EnvironmentLedger({
502
516
  project={project}
503
517
  environment={environment}
504
518
  entry={entry}
519
+ rotateAfterDays={rotateAfterDays}
505
520
  change={change ?? { key: entry.key, value: null, archived: false }}
506
521
  editing={
507
522
  change?.archived !== true &&
@@ -522,6 +537,7 @@ function EnvironmentLedger({
522
537
  onPatch={(patch) => patchChange(entry, patch)}
523
538
  onUndo={() => dropChange(entry.key)}
524
539
  onSave={() => saveRow(entry.key)}
540
+ versionOf={versionOf}
525
541
  saveReady={
526
542
  change === undefined || readyAlone([], { [entry.key]: change })
527
543
  }
@@ -553,9 +569,7 @@ function EnvironmentLedger({
553
569
  <DraftRow
554
570
  key={draft.id}
555
571
  draft={draft}
556
- existingVersion={
557
- keys.find((entry) => entry.key === draft.key.trim())?.version ?? null
558
- }
572
+ existingVersion={versionOf(draft.key)}
559
573
  disabled={false}
560
574
  onChange={(patch) =>
561
575
  setDrafts((rows) =>
@@ -564,6 +578,7 @@ function EnvironmentLedger({
564
578
  }
565
579
  onRemove={() => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))}
566
580
  onSave={() => saveDraft(draft)}
581
+ versionOf={versionOf}
567
582
  saveReady={readyAlone([draft], {})}
568
583
  />
569
584
  ))}
@@ -575,7 +590,7 @@ function EnvironmentLedger({
575
590
 
576
591
  {canWrite && (
577
592
  <div className="table-actions">
578
- <button className="btn btn-primary" onClick={addDraft}>
593
+ <button className="btn btn-primary" onClick={() => addDraft()}>
579
594
  <Plus size={14} />
580
595
  New secret
581
596
  </button>
@@ -695,65 +710,6 @@ function EnvironmentName({ project, environment }: { project: string; environmen
695
710
  /* Rows */
696
711
  /* -------------------------------------------------------------------------- */
697
712
 
698
- /**
699
- * A text field whose contents are masked until asked, for secret values.
700
- *
701
- * Where the browser supports it, the mask is CSS on a text input rather than
702
- * `type="password"`: password fields invite password managers to offer to
703
- * save or fill them, and a secret being typed into coffre is neither.
704
- */
705
- function MaskedInput({
706
- masked,
707
- className = '',
708
- ...props
709
- }: Omit<InputHTMLAttributes<HTMLInputElement>, 'type'> & { masked: boolean }) {
710
- const cssMask = useCssMask();
711
- return (
712
- <input
713
- {...props}
714
- type={masked && !cssMask ? 'password' : 'text'}
715
- className={`${className}${masked && cssMask ? ' is-masked' : ''}`}
716
- autoComplete="off"
717
- spellCheck={false}
718
- data-1p-ignore
719
- data-lpignore="true"
720
- data-bwignore
721
- />
722
- );
723
- }
724
-
725
- function useCssMask(): boolean {
726
- const [cssMask, setCssMask] = useState(false);
727
- useEffect(() => {
728
- setCssMask(typeof CSS !== 'undefined' && CSS.supports('-webkit-text-security', 'disc'));
729
- }, []);
730
- return cssMask;
731
- }
732
-
733
- /**
734
- * MaskedInput for a value with line breaks, which a text input would drop.
735
- * Without the CSS mask there is no password textarea, so masked text is
736
- * drawn transparent instead.
737
- */
738
- function MaskedTextarea({
739
- masked,
740
- className = '',
741
- ...props
742
- }: TextareaHTMLAttributes<HTMLTextAreaElement> & { masked: boolean }) {
743
- const cssMask = useCssMask();
744
- return (
745
- <textarea
746
- {...props}
747
- className={`${className}${masked ? (cssMask ? ' is-masked' : ' is-masked-fallback') : ''}`}
748
- autoComplete="off"
749
- spellCheck={false}
750
- data-1p-ignore
751
- data-lpignore="true"
752
- data-bwignore
753
- />
754
- );
755
- }
756
-
757
713
  const lineCount = (text: string) => text.split('\n').length;
758
714
 
759
715
  function ValueField({
@@ -765,6 +721,7 @@ function ValueField({
765
721
  disabled,
766
722
  autoFocus,
767
723
  onEscape,
724
+ generate,
768
725
  }: {
769
726
  label: string;
770
727
  value: string;
@@ -775,8 +732,23 @@ function ValueField({
775
732
  disabled: boolean;
776
733
  autoFocus?: boolean;
777
734
  onEscape?: () => void;
735
+ /** The row Generate fills: its name, whether that can change, and what Use does. */
736
+ generate: {
737
+ name: string;
738
+ renamable: boolean;
739
+ /** The public key a pair generated here before writes with the row. */
740
+ companion: Companion | undefined;
741
+ onUse: (use: GeneratedUse) => void;
742
+ };
778
743
  }) {
779
744
  const [shown, setShown] = useState(false);
745
+ const [generating, setGenerating] = useState(false);
746
+ // A value with a line break is edited in a textarea, and stays in one to
747
+ // the end of the edit: taking its last line break out moves no focus.
748
+ const [lines, setLines] = useState(() => start.includes('\n') || value.includes('\n'));
749
+ if (!lines && value.includes('\n')) setLines(true);
750
+ // Where the caret goes in the textarea a paste opened.
751
+ const caret = useRef<number | null>(null);
780
752
  const field = {
781
753
  className: 'input input-mono',
782
754
  masked: !shown,
@@ -791,18 +763,51 @@ function ValueField({
791
763
  },
792
764
  };
793
765
  return (
794
- <div className="input-group">
766
+ <div className="input-group has-generate">
795
767
  {/* A value with line breaks opens one line tall, as tall as the row it
796
- replaces, and grows only by the lines typed into it. */}
797
- {start.includes('\n') ? (
768
+ replaces, and grows only by the lines typed or pasted into it. */}
769
+ {lines ? (
798
770
  <MaskedTextarea
799
771
  {...field}
772
+ ref={(node) => {
773
+ if (node === null || caret.current === null) return;
774
+ node.focus();
775
+ node.setSelectionRange(caret.current, caret.current);
776
+ caret.current = null;
777
+ }}
800
778
  className="input input-mono value-lines"
801
779
  rows={Math.min(8, 1 + Math.max(0, lineCount(value) - lineCount(start)))}
802
780
  />
803
781
  ) : (
804
- <MaskedInput {...field} />
782
+ <MaskedInput
783
+ {...field}
784
+ // A text input drops a pasted value's line breaks, a PEM key's
785
+ // included. Such a paste goes into the value here instead, and the
786
+ // field turns into a textarea, focused, its caret after the paste.
787
+ // Line breaks are \n, as a textarea keeps them: \r\n is one \n.
788
+ onPaste={(event) => {
789
+ const pasted = event.clipboardData.getData('text/plain');
790
+ if (!/[\r\n]/.test(pasted)) return;
791
+ event.preventDefault();
792
+ const text = pasted.replace(/\r\n?/g, '\n');
793
+ const from = event.currentTarget.selectionStart ?? value.length;
794
+ const to = event.currentTarget.selectionEnd ?? from;
795
+ caret.current = from + text.length;
796
+ onChange(value.slice(0, from) + text + value.slice(to));
797
+ }}
798
+ />
805
799
  )}
800
+ <Tip label="Generate a value">
801
+ <button
802
+ type="button"
803
+ className="btn btn-quiet btn-sm btn-icon input-addon input-addon-generate"
804
+ aria-label={`Generate a value for ${generate.name.trim() === '' ? 'the new secret' : generate.name.trim()}`}
805
+ disabled={disabled}
806
+ onClick={() => setGenerating(true)}
807
+ >
808
+ <Generate size={14} />
809
+ </button>
810
+ </Tip>
806
811
  <button
807
812
  type="button"
808
813
  className="btn btn-quiet btn-sm btn-icon input-addon"
@@ -812,10 +817,38 @@ function ValueField({
812
817
  >
813
818
  {shown ? <EyeOff size={14} /> : <Eye size={14} />}
814
819
  </button>
820
+ <GenerateValue
821
+ open={generating}
822
+ onOpenChange={setGenerating}
823
+ name={generate.name}
824
+ renamable={generate.renamable}
825
+ companion={generate.companion}
826
+ onUse={generate.onUse}
827
+ />
815
828
  </div>
816
829
  );
817
830
  }
818
831
 
832
+ /** Under a row's value: the public key that saves with it, and the version it makes. */
833
+ function CompanionNote({
834
+ companion,
835
+ versionOf,
836
+ }: {
837
+ companion: Companion | undefined;
838
+ versionOf: (key: string) => number | null;
839
+ }) {
840
+ if (companion === undefined) return null;
841
+ const version = versionOf(companion.key);
842
+ return (
843
+ <span className="edit-note">
844
+ <span>
845
+ Saves its public key as <span className="mono">{companion.key.trim()}</span>
846
+ {version === null ? ', a new secret' : `, v${version} → v${version + 1}`}
847
+ </span>
848
+ </span>
849
+ );
850
+ }
851
+
819
852
  function useSecondsLeft(reveal: Reveal | null): number {
820
853
  const [now, setNow] = useState(() => Date.now());
821
854
  useEffect(() => {
@@ -833,6 +866,7 @@ function SecretRow({
833
866
  project,
834
867
  environment,
835
868
  entry,
869
+ rotateAfterDays,
836
870
  change,
837
871
  editing,
838
872
  canWrite,
@@ -849,6 +883,7 @@ function SecretRow({
849
883
  onPatch,
850
884
  onUndo,
851
885
  onSave,
886
+ versionOf,
852
887
  saveReady,
853
888
  onMarkArchive,
854
889
  }: {
@@ -856,6 +891,7 @@ function SecretRow({
856
891
  project: string;
857
892
  environment: string;
858
893
  entry: SecretKey;
894
+ rotateAfterDays: number | null;
859
895
  change: SecretChange;
860
896
  editing: boolean;
861
897
  canWrite: boolean;
@@ -877,6 +913,8 @@ function SecretRow({
877
913
  onUndo: () => void;
878
914
  /** This row's change alone, saved now. */
879
915
  onSave: () => void;
916
+ /** The current version of a key in this environment, for a companion's note. */
917
+ versionOf: (key: string) => number | null;
880
918
  saveReady: boolean;
881
919
  onMarkArchive: () => void;
882
920
  }) {
@@ -1045,11 +1083,20 @@ function SecretRow({
1045
1083
  placeholder={canReveal ? 'Value' : 'New value; the current one is hidden from you'}
1046
1084
  disabled={disabled}
1047
1085
  autoFocus={!focusName}
1086
+ // A value typed over a generated private key no longer matches its public key.
1048
1087
  onChange={(value) =>
1049
- onPatch({ value: value === (editBase?.value ?? '') ? null : value })
1088
+ onPatch({ value: value === (editBase?.value ?? '') ? null : value, companion: undefined })
1050
1089
  }
1051
1090
  onEscape={onUndo}
1091
+ generate={{
1092
+ // A pending rename is the name it saves under.
1093
+ name: change.key,
1094
+ renamable: false,
1095
+ companion: change.companion,
1096
+ onUse: ({ value, companion }) => onPatch({ value, companion }),
1097
+ }}
1052
1098
  />
1099
+ <CompanionNote companion={change.companion} versionOf={versionOf} />
1053
1100
  {reference !== null && reference.state === 'live' && (
1054
1101
  <span className="edit-note">
1055
1102
  Saving a value stops following <span className="mono">{reference.source}</span>
@@ -1155,8 +1202,8 @@ function SecretRow({
1155
1202
  )}
1156
1203
  </td>
1157
1204
 
1158
- <td className="col-written col-hide-narrow" data-label="Last written">
1159
- <Written entry={reference === null ? entry : { ...entry, updatedBy: reference.createdBy.replace(/^user:/, ''), updatedAt: reference.createdAt }} />
1205
+ <td className="col-written" data-label="Last written">
1206
+ <Written entry={entry} rotateAfterDays={rotateAfterDays} />
1160
1207
  </td>
1161
1208
 
1162
1209
  <td className="col-actions">
@@ -1323,29 +1370,80 @@ function SecretRow({
1323
1370
  }
1324
1371
 
1325
1372
  /**
1326
- * Who wrote the current version and how long ago, on one line: the local part
1327
- * of the email is enough to recognise a colleague, and the full address and
1328
- * the exact time are a hover away.
1373
+ * A column header that orders the table: its first click ascending, the
1374
+ * next descending. Below the width where rows stack, the sortable headers
1375
+ * stay, a row of their own above the keys.
1329
1376
  */
1330
- function Written({ entry }: { entry: SecretKey }) {
1331
- if (entry.updatedBy === null && entry.updatedAt === null) {
1332
- return <span className="cell-muted">—</span>;
1377
+ function SortHeader({
1378
+ className,
1379
+ by,
1380
+ sort,
1381
+ onSort,
1382
+ children,
1383
+ }: {
1384
+ className: string;
1385
+ by: Sort['by'];
1386
+ sort: Sort;
1387
+ onSort: (by: Sort['by']) => void;
1388
+ children: ReactNode;
1389
+ }) {
1390
+ const sorted = sort.by === by;
1391
+ return (
1392
+ <th className={`${className} th-sortable`} aria-sort={sorted ? (sort.descending ? 'descending' : 'ascending') : undefined}>
1393
+ <button type="button" className="th th-sort" onClick={() => onSort(by)}>
1394
+ {children}
1395
+ {sorted ? (
1396
+ <ChevronDown size={13} className={sort.descending ? 'sort-mark' : 'sort-mark is-ascending'} />
1397
+ ) : (
1398
+ <ChevronsUpDown size={13} className="sort-mark is-idle" />
1399
+ )}
1400
+ </button>
1401
+ </th>
1402
+ );
1403
+ }
1404
+
1405
+ /**
1406
+ * Who wrote the value a key reads and how long ago, on one line: the local
1407
+ * part of the email is enough to recognise a colleague, and the full address
1408
+ * and the exact time are a hover away. A reference's value is its source's,
1409
+ * as old as the version it reads, and who made the reference is a hover
1410
+ * away too. A value unchanged past the deployment's `rotateAfterDays` gets a
1411
+ * quiet tag, its age in days a hover away: it is due for rotation.
1412
+ */
1413
+ function Written({ entry, rotateAfterDays }: { entry: SecretKey; rotateAfterDays: number | null }) {
1414
+ const { reference } = entry;
1415
+ const made = reference === null
1416
+ ? undefined
1417
+ : `Reference made by ${shownMember(reference.createdBy).replace(/^user:/, '')} on ${reference.createdAt.slice(0, 10)}`;
1418
+ if (entry.updatedAt === null) {
1419
+ return <span className="cell-muted" title={made}>—</span>;
1333
1420
  }
1334
1421
  const by = entry.updatedBy ?? 'unknown';
1422
+ const due = rotateAfterDays !== null && olderThan(entry, rotateAfterDays);
1423
+ const age = ageInDays(entry);
1335
1424
  return (
1336
1425
  <span className="written">
1337
- <span className="written-by" title={by}>
1338
- {by.split('@')[0]}
1426
+ {reference === null ? (
1427
+ <span className="written-by" title={by}>
1428
+ {by.split('@')[0]}
1429
+ </span>
1430
+ ) : (
1431
+ <span className="written-by cell-muted" title={`Its source's current version. ${made}`}>
1432
+ source
1433
+ </span>
1434
+ )}
1435
+ <span className="cell-muted" aria-hidden>
1436
+ ·
1339
1437
  </span>
1340
- {entry.updatedAt !== null && (
1341
- <>
1342
- <span className="cell-muted" aria-hidden>
1343
- ·
1344
- </span>
1345
- <span className="cell-muted">
1346
- <Timestamp iso={entry.updatedAt} display="relative" />
1438
+ <span className="cell-muted">
1439
+ <Timestamp iso={entry.updatedAt} display="relative" />
1440
+ </span>
1441
+ {due && (
1442
+ <Tip label={`Unchanged for ${age} days, past the ${rotateAfterDays} this deployment allows: rotate it`}>
1443
+ <span className="tag tag-amber written-flag" tabIndex={0}>
1444
+ Rotate
1347
1445
  </span>
1348
- </>
1446
+ </Tip>
1349
1447
  )}
1350
1448
  </span>
1351
1449
  );
@@ -1365,6 +1463,7 @@ function DraftRow({
1365
1463
  onChange,
1366
1464
  onRemove,
1367
1465
  onSave,
1466
+ versionOf,
1368
1467
  saveReady,
1369
1468
  }: {
1370
1469
  draft: SecretDraft;
@@ -1374,6 +1473,8 @@ function DraftRow({
1374
1473
  onRemove: () => void;
1375
1474
  /** This new secret alone, saved now. */
1376
1475
  onSave: () => void;
1476
+ /** The current version of a key in this environment, for a companion's note. */
1477
+ versionOf: (key: string) => number | null;
1377
1478
  saveReady: boolean;
1378
1479
  }) {
1379
1480
  const [touched, setTouched] = useState(false);
@@ -1423,9 +1524,17 @@ function DraftRow({
1423
1524
  value={draft.value}
1424
1525
  placeholder="Value"
1425
1526
  disabled={disabled}
1426
- onChange={(value) => onChange({ value })}
1527
+ // A value typed over a generated private key no longer matches its public key.
1528
+ onChange={(value) => onChange({ value, companion: undefined })}
1427
1529
  onEscape={onRemove}
1530
+ generate={{
1531
+ name: draft.key,
1532
+ renamable: true,
1533
+ companion: draft.companion,
1534
+ onUse: ({ value, name, companion }) => onChange({ key: name, value, companion }),
1535
+ }}
1428
1536
  />
1537
+ <CompanionNote companion={draft.companion} versionOf={versionOf} />
1429
1538
  </div>
1430
1539
  </div>
1431
1540
  <div className="acts value-acts">
@@ -1505,7 +1614,7 @@ function ArchivedRow({
1505
1614
  <span className="version-shift">{entry.version === null ? '—' : `v${entry.version}`}</span>
1506
1615
  </td>
1507
1616
  <td className="col-written col-hide-narrow" data-label="Last written">
1508
- <Written entry={entry} />
1617
+ <Written entry={entry} rotateAfterDays={null} />
1509
1618
  </td>
1510
1619
  <td className="col-actions">
1511
1620
  {state.state === 'pending' ? (