@coffre/ui 0.5.0 → 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,33 +1,588 @@
1
1
  import { n as isActiveAccessibleEnvironment } from "../chunks/project-environments-lEzFHUt4.js";
2
- import { a as ErrorLine, c as Notice, d as Tip, i as EmptyState, l as Spinner, m as breakAfterUnderscores, n as ConfirmDialog, o as MenuPopup, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-DJje3gST.js";
3
- import { i as SecretReadOnly } from "../chunks/affordances-Bqdevf7w.js";
4
- import { A as Key, B as MoreHorizontal, C as Eye, D as Hash, F as Lock, G as RotateBack, H as Pencil, K as Search, O as History, Q as Terminal, T as Folder, U as Plus, X as SlashCircle, _ as Check, et as Upload, g as ArrowRight, h as Archive, i as PageHeader, it as X, n as ClosedDoor, o as failureMessage, p as AlertCircle, t as Card, u as useCoffre, w as EyeOff, x as Clock } from "../chunks/page-DvsgZ2Hd.js";
5
- import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-DOPUsjQK.js";
6
- import { g as queries, i as keys, t as affects, x as canRevealSecrets } from "../chunks/queries-DE5nK2y4.js";
7
- import { t as useShell } from "../chunks/use-shell-BO4ZTr1y.js";
8
- import { D as hasSecretEditConflict, O as secretChangeFor, S as restoreSecret, T as saveSecrets, _ as moveSecret, a as archiveSecret, n as useChangeStatus, r as UnsavedEdits, t as useChange } from "../chunks/use-change-BJ3dCFHb.js";
2
+ import { a as ErrorLine, c as Notice, d as Tip, i as EmptyState, l as Spinner, m as breakAfterUnderscores, n as ConfirmDialog, o as MenuPopup, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-Br-dNUTc.js";
3
+ import { i as SecretReadOnly } from "../chunks/affordances-D0GyCT-I.js";
4
+ import { $ as SlashCircle, A as History, D as Generate, E as Folder, G as Plus, H as MoreHorizontal, J as Search, L as Lock, M as Key, S as Clock, T as EyeOff, W as Pencil, Z as Shuffle, _ as Check, g as ArrowRight, h as Archive, i as PageHeader, k as Hash, n as ClosedDoor, o as failureMessage, p as AlertCircle, q as RotateBack, rt as Upload, st as X, t as Card, tt as Terminal, u as useCoffre, w as Eye, x as ChevronsUpDown, y as ChevronDown } from "../chunks/page-JTORvh-N.js";
5
+ import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-Zf3kZVhd.js";
6
+ import { g as queries, i as keys, t as affects, x as canRevealSecrets } from "../chunks/queries-gigcQOO_.js";
7
+ import { t as useShell } from "../chunks/use-shell-BCU505bx.js";
8
+ import { D as companionsOf, O as hasSecretEditConflict, S as restoreSecret, T as saveSecrets, _ as moveSecret, a as archiveSecret, k as secretChangeFor, n as useChangeStatus, r as UnsavedEdits, t as useChange } from "../chunks/use-change-BdS1gzyo.js";
9
9
  import { i as secretKeyProblem } from "../chunks/validation-DiHIwZRA.js";
10
10
  import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
11
- import { t as useAction } from "../chunks/use-action-BRgvbUWt.js";
12
- import { n as FolderRow, r as MoveToFolder, t as FolderMenu } from "../chunks/folders-CoGK9oqg.js";
13
- import { i as ReferenceValue, n as LentReferences, o as archiveBlockers, r as MakeReference, t as ArchiveBlocked } from "../chunks/references-uv4Mli9z.js";
14
- import { useEffect, useRef, useState } from "react";
11
+ import { t as useAction } from "../chunks/use-action-CQGGNqWb.js";
12
+ import { n as FolderRow, r as MoveToFolder, t as FolderMenu } from "../chunks/folders-hR2Lnk0k.js";
13
+ import { i as ReferenceValue, n as LentReferences, o as archiveBlockers, r as MakeReference, t as ArchiveBlocked } from "../chunks/references-DZ179hTJ.js";
14
+ import { useEffect, useId, useRef, useState } from "react";
15
15
  import { Link } from "@tanstack/react-router";
16
16
  import { toast } from "sonner";
17
17
  import { Menu } from "@base-ui/react/menu";
18
18
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
19
19
  import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
20
- import { CoffreError, byFolder, foldersOf, planImport } from "@coffre/client";
20
+ import { CoffreError, ageInDays, byFolder, foldersOf, olderThan, planImport, shownMember } from "@coffre/client";
21
21
  import { parseDotenv } from "@coffre/core/dotenv";
22
22
  //#region src/lib/reveal.ts
23
23
  function revealIsCurrent(reveal, currentVersion) {
24
24
  return reveal !== null && reveal.version === currentVersion;
25
25
  }
26
26
  //#endregion
27
+ //#region src/lib/secret-order.ts
28
+ /**
29
+ * The keys in `sort`'s order, from the listing's, by name. By age, those
30
+ * without a value come last either way, and keys written together keep
31
+ * their names' order.
32
+ */
33
+ function sortKeys(entries, sort) {
34
+ if (sort.by === "key") return sort.descending ? [...entries].reverse() : entries;
35
+ const direction = sort.descending ? -1 : 1;
36
+ return [...entries].sort((a, b) => {
37
+ if (a.updatedAt === b.updatedAt) return 0;
38
+ if (a.updatedAt === null) return 1;
39
+ if (b.updatedAt === null) return -1;
40
+ return a.updatedAt < b.updatedAt ? -direction : direction;
41
+ });
42
+ }
43
+ //#endregion
44
+ //#region src/lib/shortcuts.ts
45
+ /**
46
+ * Whether a key press comes from inside an open dialog, which a page-wide
47
+ * shortcut leaves alone: Cmd/Ctrl+Enter saves the secrets page, and from a
48
+ * dialog it would save behind it and close it, its work unfinished.
49
+ */
50
+ function inDialog(target) {
51
+ const element = target;
52
+ return typeof element?.closest === "function" && element.closest("[role=\"dialog\"], [role=\"alertdialog\"]") !== null;
53
+ }
54
+ //#endregion
55
+ //#region src/lib/generate.ts
56
+ /**
57
+ * Values the browser makes for a secret: random strings, AES keys and EC key
58
+ * pairs, from Web Crypto alone.
59
+ *
60
+ * Nothing here talks to the server. A value made here goes into the row's
61
+ * field like a typed one, and leaves the page only when that row is saved.
62
+ */
63
+ var DEFAULT_RECIPE = {
64
+ kind: "random",
65
+ encoding: "base62",
66
+ bytes: 32
67
+ };
68
+ var ENCODINGS = [
69
+ {
70
+ id: "base62",
71
+ name: "Letters and digits"
72
+ },
73
+ {
74
+ id: "hex",
75
+ name: "Hex"
76
+ },
77
+ {
78
+ id: "base64",
79
+ name: "Base64"
80
+ },
81
+ {
82
+ id: "base64url",
83
+ name: "Base64 URL"
84
+ }
85
+ ];
86
+ /** Strongest first, as a new key should be. */
87
+ var PAIRS = [
88
+ {
89
+ algorithm: "ECDSA",
90
+ curve: "P-521"
91
+ },
92
+ {
93
+ algorithm: "ECDSA",
94
+ curve: "P-384"
95
+ },
96
+ {
97
+ algorithm: "ECDSA",
98
+ curve: "P-256"
99
+ },
100
+ {
101
+ algorithm: "ECDH",
102
+ curve: "P-521"
103
+ },
104
+ {
105
+ algorithm: "ECDH",
106
+ curve: "P-384"
107
+ },
108
+ {
109
+ algorithm: "ECDH",
110
+ curve: "P-256"
111
+ }
112
+ ];
113
+ var BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
114
+ /**
115
+ * The largest multiple of 62 a byte reaches: 248. A byte below it is taken
116
+ * modulo 62, and each of the 62 characters has four bytes that make it. The
117
+ * eight bytes from 248 up are thrown away, as taking them would make the
118
+ * first eight characters a little likelier than the rest.
119
+ */
120
+ var BASE62_LIMIT = 256 - 256 % 62;
121
+ var randomBytes = (bytes) => crypto.getRandomValues(bytes);
122
+ /**
123
+ * How many characters carry `bytes` of entropy. Hex and base64 encode the
124
+ * bytes themselves; base62 draws whole characters, each worth log2(62) bits,
125
+ * so it takes as many as reach the same number of bits: 43 for 32 bytes.
126
+ * Base64 pads to a multiple of four; base64 URL leaves the padding off.
127
+ */
128
+ function encodedLength(encoding, bytes) {
129
+ switch (encoding) {
130
+ case "hex": return bytes * 2;
131
+ case "base64": return Math.ceil(bytes / 3) * 4;
132
+ case "base64url": return Math.ceil(bytes * 8 / 6);
133
+ case "base62": return Math.ceil(bytes * 8 / Math.log2(62));
134
+ }
135
+ }
136
+ /** `length` characters of base62, each drawn uniformly by rejecting the bytes 248 to 255. */
137
+ function base62(length, random = randomBytes) {
138
+ let out = "";
139
+ while (out.length < length) for (const byte of random(new Uint8Array(length - out.length + 8))) {
140
+ if (byte >= BASE62_LIMIT) continue;
141
+ out += BASE62[byte % 62];
142
+ if (out.length === length) break;
143
+ }
144
+ return out;
145
+ }
146
+ function randomValue(encoding, bytes, random = randomBytes) {
147
+ if (encoding === "base62") return base62(encodedLength("base62", bytes), random);
148
+ const drawn = random(new Uint8Array(bytes));
149
+ if (encoding === "hex") return [...drawn].map((byte) => byte.toString(16).padStart(2, "0")).join("");
150
+ const base64 = toBase64(drawn);
151
+ return encoding === "base64" ? base64 : base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
152
+ }
153
+ async function generate(recipe) {
154
+ switch (recipe.kind) {
155
+ case "random": return { value: randomValue(recipe.encoding, recipe.bytes) };
156
+ case "aes": {
157
+ const key = await subtle().generateKey({
158
+ name: "AES-GCM",
159
+ length: recipe.size
160
+ }, true, ["encrypt", "decrypt"]);
161
+ return { value: toBase64(await subtle().exportKey("raw", key)) };
162
+ }
163
+ case "pair": {
164
+ const usages = recipe.algorithm === "ECDSA" ? ["sign", "verify"] : ["deriveBits"];
165
+ const pair = await subtle().generateKey({
166
+ name: recipe.algorithm,
167
+ namedCurve: recipe.curve
168
+ }, true, usages);
169
+ return {
170
+ value: toBase64(await subtle().exportKey("pkcs8", pair.privateKey)),
171
+ publicKey: toBase64(await subtle().exportKey("spki", pair.publicKey))
172
+ };
173
+ }
174
+ }
175
+ }
176
+ /**
177
+ * The name a key pair's public key gets beside its private key's:
178
+ * `JWT_PRIVATE_KEY` gives `JWT_PUBLIC_KEY`, any other name gains `_PUBLIC`.
179
+ */
180
+ function publicKeyName(privateName) {
181
+ const name = privateName.trim();
182
+ if (name === "") return "";
183
+ if (/PRIVATE/.test(name)) return name.replace(/PRIVATE/g, "PUBLIC");
184
+ if (/private/.test(name)) return name.replace(/private/g, "public");
185
+ return `${name}_PUBLIC`;
186
+ }
187
+ /** What stops a key pair's two names from being saved, if anything. */
188
+ function pairNameProblem(privateName, publicName) {
189
+ const names = [privateName.trim(), publicName.trim()];
190
+ if (names.includes("")) return "Give each key a name.";
191
+ for (const name of names) {
192
+ const problem = secretKeyProblem(name);
193
+ if (problem !== null) return `${name}: ${problem}`;
194
+ }
195
+ return names[0] === names[1] ? "The two keys need different names." : null;
196
+ }
197
+ /** Web Crypto's keys need a secure context: HTTPS, or the machine's own address. */
198
+ function subtle() {
199
+ if (globalThis.crypto?.subtle === void 0) throw new Error("This page is not served over HTTPS, so the browser makes no keys here.");
200
+ return globalThis.crypto.subtle;
201
+ }
202
+ function toBase64(bytes) {
203
+ let binary = "";
204
+ for (const byte of new Uint8Array(bytes)) binary += String.fromCharCode(byte);
205
+ return btoa(binary);
206
+ }
207
+ //#endregion
208
+ //#region src/components/masked.tsx
209
+ /**
210
+ * A text field whose contents are masked until asked, for secret values.
211
+ *
212
+ * Where the browser supports it, the mask is CSS on a text input rather than
213
+ * `type="password"`: password fields invite password managers to offer to
214
+ * save or fill them, and a secret being typed into coffre is neither.
215
+ */
216
+ function MaskedInput({ masked, className = "", ...props }) {
217
+ const cssMask = useCssMask();
218
+ return /* @__PURE__ */ jsx("input", {
219
+ ...props,
220
+ type: masked && !cssMask ? "password" : "text",
221
+ className: `${className}${masked && cssMask ? " is-masked" : ""}`,
222
+ autoComplete: "off",
223
+ spellCheck: false,
224
+ "data-1p-ignore": true,
225
+ "data-lpignore": "true",
226
+ "data-bwignore": true
227
+ });
228
+ }
229
+ function useCssMask() {
230
+ const [cssMask, setCssMask] = useState(false);
231
+ useEffect(() => {
232
+ setCssMask(typeof CSS !== "undefined" && CSS.supports("-webkit-text-security", "disc"));
233
+ }, []);
234
+ return cssMask;
235
+ }
236
+ /**
237
+ * MaskedInput for a value with line breaks, which a text input would drop.
238
+ * Without the CSS mask there is no password textarea, so masked text is
239
+ * drawn transparent instead.
240
+ */
241
+ function MaskedTextarea({ masked, className = "", ...props }) {
242
+ const cssMask = useCssMask();
243
+ return /* @__PURE__ */ jsx("textarea", {
244
+ ...props,
245
+ className: `${className}${masked ? cssMask ? " is-masked" : " is-masked-fallback" : ""}`,
246
+ autoComplete: "off",
247
+ spellCheck: false,
248
+ "data-1p-ignore": true,
249
+ "data-lpignore": "true",
250
+ "data-bwignore": true
251
+ });
252
+ }
253
+ //#endregion
254
+ //#region src/components/generate-value.tsx
255
+ var KINDS = [
256
+ {
257
+ id: "random",
258
+ name: "Random value"
259
+ },
260
+ {
261
+ id: "aes",
262
+ name: "AES-GCM key"
263
+ },
264
+ {
265
+ id: "pair",
266
+ name: "Key pair"
267
+ }
268
+ ];
269
+ /**
270
+ * Make a value for a secret's field, in the browser: Use fills the field, as
271
+ * typing would, and the row saves it with the rest.
272
+ *
273
+ * The dialog's content unmounts as it closes, so each opening draws a new
274
+ * value and nothing generated stays in memory behind a cancel.
275
+ */
276
+ function GenerateValue({ open, onOpenChange, name, renamable, companion, onUse }) {
277
+ return /* @__PURE__ */ jsx(Modal, {
278
+ open,
279
+ onOpenChange,
280
+ title: "Generate a value",
281
+ description: "Made in this browser. It is sent only when you save the row.",
282
+ children: /* @__PURE__ */ jsx(GenerateForm, {
283
+ name,
284
+ renamable,
285
+ publicName: companion?.key,
286
+ onCancel: () => onOpenChange(false),
287
+ onUse: (use) => {
288
+ onUse(use);
289
+ onOpenChange(false);
290
+ }
291
+ })
292
+ });
293
+ }
294
+ function GenerateForm({ name, renamable, publicName: pendingPublicName, onCancel, onUse }) {
295
+ const id = useId();
296
+ const [kind, setKind] = useState(pendingPublicName === void 0 ? DEFAULT_RECIPE.kind : "pair");
297
+ const [encoding, setEncoding] = useState("base62");
298
+ const [bytes, setBytes] = useState(32);
299
+ const [bytesText, setBytesText] = useState("32");
300
+ const [size, setSize] = useState(256);
301
+ const [pair, setPair] = useState(0);
302
+ const [round, setRound] = useState(0);
303
+ const [generated, setGenerated] = useState(null);
304
+ const [error, setError] = useState(null);
305
+ const [privateName, setPrivateName] = useState(name);
306
+ const [publicName, setPublicName] = useState(pendingPublicName ?? null);
307
+ const recipe = kind === "random" ? {
308
+ kind,
309
+ encoding,
310
+ bytes
311
+ } : kind === "aes" ? {
312
+ kind,
313
+ size
314
+ } : {
315
+ kind,
316
+ ...PAIRS[pair]
317
+ };
318
+ useEffect(() => {
319
+ let current = true;
320
+ setGenerated(null);
321
+ setError(null);
322
+ generate(recipe).then((made) => current && setGenerated(made), (failure) => current && setError(failure instanceof Error ? failure.message : "The browser made no value."));
323
+ return () => {
324
+ current = false;
325
+ };
326
+ }, [JSON.stringify(recipe), round]);
327
+ const publicKey = publicName ?? publicKeyName(privateName);
328
+ const nameProblem = kind === "pair" ? pairNameProblem(privateName, publicKey) : null;
329
+ const ready = generated !== null && nameProblem === null;
330
+ function use() {
331
+ if (!ready) return;
332
+ onUse(kind === "pair" && generated.publicKey !== void 0 ? {
333
+ value: generated.value,
334
+ name: privateName.trim(),
335
+ companion: {
336
+ key: publicKey.trim(),
337
+ value: generated.publicKey
338
+ }
339
+ } : {
340
+ value: generated.value,
341
+ name
342
+ });
343
+ }
344
+ return /* @__PURE__ */ jsxs("form", {
345
+ className: "form generate",
346
+ onSubmit: (event) => {
347
+ event.preventDefault();
348
+ use();
349
+ },
350
+ children: [
351
+ /* @__PURE__ */ jsxs("div", {
352
+ className: "form-row",
353
+ children: [/* @__PURE__ */ jsxs("label", {
354
+ className: "field",
355
+ children: [/* @__PURE__ */ jsx("span", {
356
+ className: "label",
357
+ children: "Type"
358
+ }), /* @__PURE__ */ jsx("select", {
359
+ className: "select",
360
+ value: kind,
361
+ onChange: (event) => setKind(event.target.value),
362
+ children: KINDS.map((each) => /* @__PURE__ */ jsx("option", {
363
+ value: each.id,
364
+ children: each.name
365
+ }, each.id))
366
+ })]
367
+ }), kind === "random" ? /* @__PURE__ */ jsxs("label", {
368
+ className: "field",
369
+ children: [/* @__PURE__ */ jsx("span", {
370
+ className: "label",
371
+ children: "Characters"
372
+ }), /* @__PURE__ */ jsx("select", {
373
+ className: "select",
374
+ value: encoding,
375
+ onChange: (event) => setEncoding(event.target.value),
376
+ children: ENCODINGS.map((each) => /* @__PURE__ */ jsx("option", {
377
+ value: each.id,
378
+ children: each.name
379
+ }, each.id))
380
+ })]
381
+ }) : kind === "aes" ? /* @__PURE__ */ jsxs("label", {
382
+ className: "field",
383
+ children: [/* @__PURE__ */ jsx("span", {
384
+ className: "label",
385
+ children: "Size"
386
+ }), /* @__PURE__ */ jsxs("select", {
387
+ className: "select",
388
+ value: size,
389
+ onChange: (event) => setSize(Number(event.target.value)),
390
+ children: [/* @__PURE__ */ jsx("option", {
391
+ value: 256,
392
+ children: "256-bit"
393
+ }), /* @__PURE__ */ jsx("option", {
394
+ value: 128,
395
+ children: "128-bit"
396
+ })]
397
+ })]
398
+ }) : /* @__PURE__ */ jsxs("label", {
399
+ className: "field",
400
+ children: [/* @__PURE__ */ jsx("span", {
401
+ className: "label",
402
+ children: "Algorithm"
403
+ }), /* @__PURE__ */ jsx("select", {
404
+ className: "select",
405
+ value: pair,
406
+ onChange: (event) => setPair(Number(event.target.value)),
407
+ children: PAIRS.map((each, index) => /* @__PURE__ */ jsxs("option", {
408
+ value: index,
409
+ children: [
410
+ each.algorithm,
411
+ ", ",
412
+ each.curve
413
+ ]
414
+ }, index))
415
+ })]
416
+ })]
417
+ }),
418
+ kind === "random" && /* @__PURE__ */ jsxs("div", {
419
+ className: "field",
420
+ children: [
421
+ /* @__PURE__ */ jsx("label", {
422
+ className: "label",
423
+ htmlFor: `${id}-bytes`,
424
+ children: "Length"
425
+ }),
426
+ /* @__PURE__ */ jsxs("div", {
427
+ className: "generate-length",
428
+ children: [
429
+ /* @__PURE__ */ jsx("input", {
430
+ className: "range",
431
+ type: "range",
432
+ "aria-label": "Length in bytes",
433
+ "aria-valuetext": `${bytes} bytes`,
434
+ min: 1,
435
+ max: 256,
436
+ value: bytes,
437
+ onChange: (event) => {
438
+ setBytes(Number(event.target.value));
439
+ setBytesText(event.target.value);
440
+ }
441
+ }),
442
+ /* @__PURE__ */ jsx("input", {
443
+ id: `${id}-bytes`,
444
+ className: "input generate-bytes",
445
+ type: "number",
446
+ inputMode: "numeric",
447
+ min: 1,
448
+ max: 256,
449
+ value: bytesText,
450
+ "aria-describedby": `${id}-entropy`,
451
+ onChange: (event) => {
452
+ setBytesText(event.target.value);
453
+ const typed = Number(event.target.value);
454
+ if (Number.isInteger(typed) && typed >= 1 && typed <= 256) setBytes(typed);
455
+ },
456
+ onBlur: () => setBytesText(String(bytes))
457
+ }),
458
+ /* @__PURE__ */ jsx("span", {
459
+ className: "generate-unit",
460
+ children: "bytes"
461
+ })
462
+ ]
463
+ }),
464
+ /* @__PURE__ */ jsxs("p", {
465
+ className: "hint",
466
+ id: `${id}-entropy`,
467
+ children: [
468
+ encodedLength(encoding, bytes),
469
+ " characters",
470
+ encoding === "base62" ? ", A–Z, a–z and 0–9" : "",
471
+ ", ",
472
+ bytes * 8,
473
+ " bits of entropy."
474
+ ]
475
+ })
476
+ ]
477
+ }),
478
+ kind === "pair" ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
479
+ /* @__PURE__ */ jsx(NamedValue, {
480
+ label: "Private key",
481
+ format: "PKCS #8, base64",
482
+ name: privateName,
483
+ onName: renamable ? setPrivateName : void 0,
484
+ value: generated?.value ?? null,
485
+ describedBy: `${id}-names`
486
+ }),
487
+ /* @__PURE__ */ jsx(NamedValue, {
488
+ label: "Public key",
489
+ format: "SPKI, base64",
490
+ name: publicKey,
491
+ onName: setPublicName,
492
+ value: generated?.publicKey ?? null,
493
+ describedBy: `${id}-names`
494
+ }),
495
+ /* @__PURE__ */ jsx("p", {
496
+ className: "hint",
497
+ id: `${id}-names`,
498
+ children: nameProblem ?? "The public key is saved with this row, as a secret of its own."
499
+ })
500
+ ] }) : /* @__PURE__ */ jsx(NamedValue, {
501
+ label: "Value",
502
+ format: kind === "aes" ? `the raw key, base64, ${size === 256 ? 44 : 24} characters` : void 0,
503
+ value: generated?.value ?? null
504
+ }),
505
+ /* @__PURE__ */ jsx(ErrorLine, { error }),
506
+ /* @__PURE__ */ jsxs("div", {
507
+ className: "dialog-actions generate-actions",
508
+ children: [
509
+ /* @__PURE__ */ jsxs("button", {
510
+ className: "btn btn-quiet",
511
+ type: "button",
512
+ onClick: () => setRound((count) => count + 1),
513
+ children: [/* @__PURE__ */ jsx(Shuffle, { size: 14 }), "Generate again"]
514
+ }),
515
+ /* @__PURE__ */ jsx("button", {
516
+ className: "btn",
517
+ type: "button",
518
+ onClick: onCancel,
519
+ children: "Cancel"
520
+ }),
521
+ /* @__PURE__ */ jsx("button", {
522
+ className: "btn btn-primary",
523
+ type: "submit",
524
+ disabled: !ready,
525
+ children: kind === "pair" ? "Use keys" : "Use value"
526
+ })
527
+ ]
528
+ })
529
+ ]
530
+ });
531
+ }
532
+ /** A generated value, masked until shown, and for a key pair the name it is saved under. */
533
+ function NamedValue({ label, format, name, onName, value, describedBy }) {
534
+ const id = useId();
535
+ const [shown, setShown] = useState(false);
536
+ const problem = name === void 0 || name.trim() === "" ? null : secretKeyProblem(name.trim());
537
+ return /* @__PURE__ */ jsxs("div", {
538
+ className: "field",
539
+ children: [
540
+ /* @__PURE__ */ jsxs("label", {
541
+ className: "label",
542
+ htmlFor: `${id}-value`,
543
+ children: [label, format !== void 0 && /* @__PURE__ */ jsxs("span", {
544
+ className: "label-note",
545
+ children: [" · ", format]
546
+ })]
547
+ }),
548
+ name !== void 0 && /* @__PURE__ */ jsx("input", {
549
+ className: "input input-mono",
550
+ "aria-label": `Name of the ${label.toLowerCase()}`,
551
+ "aria-invalid": problem !== null,
552
+ "aria-describedby": describedBy,
553
+ placeholder: "NAME_OF_SECRET",
554
+ spellCheck: false,
555
+ autoComplete: "off",
556
+ value: name,
557
+ disabled: onName === void 0,
558
+ onChange: (event) => onName?.(event.target.value)
559
+ }),
560
+ /* @__PURE__ */ jsxs("div", {
561
+ className: "input-group",
562
+ children: [/* @__PURE__ */ jsx(MaskedInput, {
563
+ id: `${id}-value`,
564
+ className: "input input-mono",
565
+ masked: !shown,
566
+ readOnly: true,
567
+ value: value ?? "",
568
+ placeholder: value === null ? "Generating…" : void 0
569
+ }), /* @__PURE__ */ jsx("button", {
570
+ type: "button",
571
+ className: "btn btn-quiet btn-sm btn-icon input-addon",
572
+ "aria-label": shown ? `Mask the ${label.toLowerCase()}` : `Show the ${label.toLowerCase()}`,
573
+ "aria-pressed": shown,
574
+ onClick: () => setShown((current) => !current),
575
+ children: shown ? /* @__PURE__ */ jsx(EyeOff, { size: 14 }) : /* @__PURE__ */ jsx(Eye, { size: 14 })
576
+ })]
577
+ })
578
+ ]
579
+ });
580
+ }
581
+ //#endregion
27
582
  //#region src/components/missing.tsx
28
583
  /**
29
- * Keys the environment's siblings have and it lacks, of those you read
30
- * (docs/design/environments.md): each with Add, which opens a new row with
584
+ * Keys the environment's siblings have and it lacks, by name, whether you
585
+ * read them or not (docs/design/environments.md): each with Add, which opens a new row with
31
586
  * its name, and Dismiss, which the whole team then sees, and below them
32
587
  * Dismiss all and what was dismissed, each with Restore. Nothing shows when
33
588
  * nothing is missing or dismissed.
@@ -49,7 +604,7 @@ function MissingKeys({ project, environment, canWrite, onAdd }) {
49
604
  wide: true,
50
605
  labelledBy: "missing-keys",
51
606
  title: missing.length === 0 ? "Nothing missing" : `${missing.length} ${missing.length === 1 ? "key" : "keys"} from other environments ${missing.length === 1 ? "isn't" : "aren't"} here`,
52
- description: "Compared with the environments you can read.",
607
+ description: "Compared with every other environment of the project, by key name.",
53
608
  children: [/* @__PURE__ */ jsx("div", {
54
609
  className: "dt-wrap",
55
610
  children: /* @__PURE__ */ jsx("table", {
@@ -193,10 +748,11 @@ function EnvironmentPage() {
193
748
  project,
194
749
  environment,
195
750
  permissions: result.permissions,
196
- keys: result.keys
751
+ keys: result.keys,
752
+ rotateAfterDays: result.rotateAfterDays
197
753
  }, `${project}/${environment}`);
198
754
  }
199
- function EnvironmentLedger({ project, environment, permissions, keys: keys$1 }) {
755
+ function EnvironmentLedger({ project, environment, permissions, keys: keys$1, rotateAfterDays }) {
200
756
  const coffre = useCoffre();
201
757
  const { principal } = useShell();
202
758
  const save = useChange(saveSecrets(coffre, {
@@ -232,6 +788,14 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
232
788
  const [editing, setEditing] = useState(() => /* @__PURE__ */ new Set());
233
789
  const [saveError, setSaveError] = useState(null);
234
790
  const [query, setQuery] = useState(Route.useSearch().filter ?? "");
791
+ const [sort, setSort] = useState({
792
+ by: "key",
793
+ descending: false
794
+ });
795
+ const sortBy = (by) => setSort((current) => ({
796
+ by,
797
+ descending: current.by === by && !current.descending
798
+ }));
235
799
  const nextDraftId = useRef(0);
236
800
  const canWrite = permissions.includes("secret.write");
237
801
  const canArchive = permissions.includes("secret.archive");
@@ -262,12 +826,17 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
262
826
  });
263
827
  const archived = keys$1.filter((entry) => entry.archived);
264
828
  const existing = new Set(keys$1.map((entry) => entry.key));
829
+ const versionOf = (key) => keys$1.find((entry) => entry.key === key.trim())?.version ?? null;
265
830
  const changedEntries = active.filter((entry) => secretChangeFor(changes, entry.key) !== void 0);
266
831
  const hasConflict = hasSecretEditConflict(active, drafts, changes);
267
- const pendingNames = [...drafts.map((row) => row.key.trim()), ...changedEntries.flatMap((entry) => {
268
- const change = secretChangeFor(changes, entry.key);
269
- return change === void 0 || change.archived ? [] : [change.key.trim()];
270
- })];
832
+ const pendingNames = [
833
+ ...drafts.map((row) => row.key.trim()),
834
+ ...changedEntries.flatMap((entry) => {
835
+ const change = secretChangeFor(changes, entry.key);
836
+ return change === void 0 || change.archived ? [] : [change.key.trim()];
837
+ }),
838
+ ...companionsOf(active, drafts, changes).map((companion) => companion.key.trim())
839
+ ];
271
840
  const unnamed = pendingNames.some((name) => name === "");
272
841
  const invalid = pendingNames.some((name) => name !== "" && secretKeyProblem(name) !== null);
273
842
  const pendingCount = drafts.length + changedEntries.length;
@@ -314,7 +883,11 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
314
883
  }
315
884
  /** Whether one row's change could go alone: named, well named, and clashing with nothing. */
316
885
  function readyAlone(drafts, changes) {
317
- const names = [...drafts.map((row) => row.key.trim()), ...Object.values(changes).flatMap((change) => change.archived ? [] : [change.key.trim()])];
886
+ const names = [
887
+ ...drafts.map((row) => row.key.trim()),
888
+ ...Object.values(changes).flatMap((change) => change.archived ? [] : [change.key.trim()]),
889
+ ...companionsOf(active, drafts, changes).map((companion) => companion.key.trim())
890
+ ];
318
891
  return (drafts.length > 0 || Object.keys(changes).length > 0) && names.every((name) => name !== "" && secretKeyProblem(name) === null) && !hasSecretEditConflict(active, drafts, changes);
319
892
  }
320
893
  function sendAlone(batch) {
@@ -340,10 +913,10 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
340
913
  return next;
341
914
  });
342
915
  }
343
- function addDraft() {
916
+ function addDraft(key = "") {
344
917
  setDrafts((rows) => [...rows, {
345
918
  id: nextDraftId.current++,
346
- key: "",
919
+ key,
347
920
  value: ""
348
921
  }]);
349
922
  }
@@ -399,7 +972,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
399
972
  useEffect(() => {
400
973
  if (pendingCount === 0) return;
401
974
  function onKeyDown(event) {
402
- if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
975
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && !inDialog(event.target)) {
403
976
  event.preventDefault();
404
977
  saveRef.current();
405
978
  }
@@ -407,9 +980,10 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
407
980
  document.addEventListener("keydown", onKeyDown);
408
981
  return () => document.removeEventListener("keydown", onKeyDown);
409
982
  }, [pendingCount]);
983
+ const withCompanion = (what, companion) => companion === void 0 ? what : `${what}, with ${companion.key.trim()}`;
410
984
  const pending = [...drafts.map((draft) => ({
411
985
  key: draft.key.trim() || "unnamed",
412
- what: existing.has(draft.key.trim()) ? "new version" : "added"
986
+ what: withCompanion(existing.has(draft.key.trim()) ? "new version" : "added", draft.companion)
413
987
  })), ...changedEntries.map((entry) => {
414
988
  const change = secretChangeFor(changes, entry.key);
415
989
  if (change.archived) return {
@@ -419,7 +993,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
419
993
  const renamed = change.key.trim() !== entry.key;
420
994
  if (renamed && change.value !== null) return {
421
995
  key: entry.key,
422
- what: `→ ${change.key.trim()}, new value`
996
+ what: withCompanion(`→ ${change.key.trim()}, new value`, change.companion)
423
997
  };
424
998
  if (renamed) return {
425
999
  key: entry.key,
@@ -427,12 +1001,12 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
427
1001
  };
428
1002
  return {
429
1003
  key: entry.key,
430
- what: "new value"
1004
+ what: withCompanion("new value", change.companion)
431
1005
  };
432
1006
  })];
433
1007
  const problem = unnamed ? null : hasConflict ? "Two pending edits would end up with the same name. Secret names are unique in an environment." : invalid ? "Names are letters, digits and underscores, and cannot start with a digit." : null;
434
1008
  const needle = query.trim().toLowerCase();
435
- const listed = needle === "" ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle));
1009
+ const listed = sortKeys(needle === "" ? active : active.filter((entry) => entry.key.toLowerCase().includes(needle)), sort);
436
1010
  const columns = 6;
437
1011
  return /* @__PURE__ */ jsxs(Fragment$1, { children: [
438
1012
  /* @__PURE__ */ jsx(PageHeader, {
@@ -492,11 +1066,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
492
1066
  project,
493
1067
  environment,
494
1068
  canWrite,
495
- onAdd: (key) => setDrafts((rows) => [...rows, {
496
- id: nextDraftId.current++,
497
- key,
498
- value: ""
499
- }])
1069
+ onAdd: addDraft
500
1070
  }),
501
1071
  refile.error !== null && /* @__PURE__ */ jsx(ErrorLine, { error: refile.error }),
502
1072
  /* @__PURE__ */ jsx("section", {
@@ -508,18 +1078,18 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
508
1078
  }) : /* @__PURE__ */ jsx("div", {
509
1079
  className: "dt-wrap",
510
1080
  children: /* @__PURE__ */ jsxs("table", {
511
- className: "dt secrets stacks",
1081
+ className: "dt secrets stacks sortable",
512
1082
  children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
513
1083
  /* @__PURE__ */ jsx("th", {
514
1084
  className: "n",
515
1085
  children: "#"
516
1086
  }),
517
- /* @__PURE__ */ jsx("th", {
1087
+ /* @__PURE__ */ jsxs(SortHeader, {
518
1088
  className: "col-key",
519
- children: /* @__PURE__ */ jsxs("span", {
520
- className: "th",
521
- children: [/* @__PURE__ */ jsx(Key, { size: 14 }), "Key"]
522
- })
1089
+ by: "key",
1090
+ sort,
1091
+ onSort: sortBy,
1092
+ children: [/* @__PURE__ */ jsx(Key, { size: 14 }), "Key"]
523
1093
  }),
524
1094
  /* @__PURE__ */ jsx("th", { children: /* @__PURE__ */ jsxs("span", {
525
1095
  className: "th",
@@ -539,12 +1109,12 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
539
1109
  children: [/* @__PURE__ */ jsx(Hash, { size: 14 }), "Version"]
540
1110
  })
541
1111
  }),
542
- /* @__PURE__ */ jsx("th", {
543
- className: "col-written col-hide-narrow",
544
- children: /* @__PURE__ */ jsxs("span", {
545
- className: "th",
546
- children: [/* @__PURE__ */ jsx(Clock, { size: 14 }), "Last written"]
547
- })
1112
+ /* @__PURE__ */ jsxs(SortHeader, {
1113
+ className: "col-written",
1114
+ by: "written",
1115
+ sort,
1116
+ onSort: sortBy,
1117
+ children: [/* @__PURE__ */ jsx(Clock, { size: 14 }), "Last written"]
548
1118
  }),
549
1119
  /* @__PURE__ */ jsx("th", {
550
1120
  className: "col-actions",
@@ -567,6 +1137,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
567
1137
  project,
568
1138
  environment,
569
1139
  entry,
1140
+ rotateAfterDays,
570
1141
  change: change ?? {
571
1142
  key: entry.key,
572
1143
  value: null,
@@ -590,6 +1161,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
590
1161
  onPatch: (patch) => patchChange(entry, patch),
591
1162
  onUndo: () => dropChange(entry.key),
592
1163
  onSave: () => saveRow(entry.key),
1164
+ versionOf,
593
1165
  saveReady: change === void 0 || readyAlone([], { [entry.key]: change }),
594
1166
  onMarkArchive: () => {
595
1167
  setEditing((current) => {
@@ -620,7 +1192,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
620
1192
  }) }),
621
1193
  drafts.map((draft) => /* @__PURE__ */ jsx(DraftRow, {
622
1194
  draft,
623
- existingVersion: keys$1.find((entry) => entry.key === draft.key.trim())?.version ?? null,
1195
+ existingVersion: versionOf(draft.key),
624
1196
  disabled: false,
625
1197
  onChange: (patch) => setDrafts((rows) => rows.map((row) => row.id === draft.id ? {
626
1198
  ...row,
@@ -628,6 +1200,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
628
1200
  } : row)),
629
1201
  onRemove: () => setDrafts((rows) => rows.filter((row) => row.id !== draft.id)),
630
1202
  onSave: () => saveDraft(draft),
1203
+ versionOf,
631
1204
  saveReady: readyAlone([draft], {})
632
1205
  }, draft.id))
633
1206
  ] })]
@@ -638,7 +1211,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
638
1211
  className: "table-actions",
639
1212
  children: [/* @__PURE__ */ jsxs("button", {
640
1213
  className: "btn btn-primary",
641
- onClick: addDraft,
1214
+ onClick: () => addDraft(),
642
1215
  children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "New secret"]
643
1216
  }), canReveal && /* @__PURE__ */ jsx(ImportEnv, {
644
1217
  project,
@@ -763,53 +1336,13 @@ function EnvironmentName({ project, environment }) {
763
1336
  const name = projects.find((entry) => entry.slug === project)?.environments.find((entry) => entry.slug === environment)?.name;
764
1337
  return name === void 0 ? null : /* @__PURE__ */ jsx(Fragment$1, { children: name });
765
1338
  }
766
- /**
767
- * A text field whose contents are masked until asked, for secret values.
768
- *
769
- * Where the browser supports it, the mask is CSS on a text input rather than
770
- * `type="password"`: password fields invite password managers to offer to
771
- * save or fill them, and a secret being typed into coffre is neither.
772
- */
773
- function MaskedInput({ masked, className = "", ...props }) {
774
- const cssMask = useCssMask();
775
- return /* @__PURE__ */ jsx("input", {
776
- ...props,
777
- type: masked && !cssMask ? "password" : "text",
778
- className: `${className}${masked && cssMask ? " is-masked" : ""}`,
779
- autoComplete: "off",
780
- spellCheck: false,
781
- "data-1p-ignore": true,
782
- "data-lpignore": "true",
783
- "data-bwignore": true
784
- });
785
- }
786
- function useCssMask() {
787
- const [cssMask, setCssMask] = useState(false);
788
- useEffect(() => {
789
- setCssMask(typeof CSS !== "undefined" && CSS.supports("-webkit-text-security", "disc"));
790
- }, []);
791
- return cssMask;
792
- }
793
- /**
794
- * MaskedInput for a value with line breaks, which a text input would drop.
795
- * Without the CSS mask there is no password textarea, so masked text is
796
- * drawn transparent instead.
797
- */
798
- function MaskedTextarea({ masked, className = "", ...props }) {
799
- const cssMask = useCssMask();
800
- return /* @__PURE__ */ jsx("textarea", {
801
- ...props,
802
- className: `${className}${masked ? cssMask ? " is-masked" : " is-masked-fallback" : ""}`,
803
- autoComplete: "off",
804
- spellCheck: false,
805
- "data-1p-ignore": true,
806
- "data-lpignore": "true",
807
- "data-bwignore": true
808
- });
809
- }
810
1339
  var lineCount = (text) => text.split("\n").length;
811
- function ValueField({ label, value, start = "", onChange, placeholder, disabled, autoFocus, onEscape }) {
1340
+ function ValueField({ label, value, start = "", onChange, placeholder, disabled, autoFocus, onEscape, generate }) {
812
1341
  const [shown, setShown] = useState(false);
1342
+ const [generating, setGenerating] = useState(false);
1343
+ const [lines, setLines] = useState(() => start.includes("\n") || value.includes("\n"));
1344
+ if (!lines && value.includes("\n")) setLines(true);
1345
+ const caret = useRef(null);
813
1346
  const field = {
814
1347
  className: "input input-mono",
815
1348
  masked: !shown,
@@ -824,19 +1357,75 @@ function ValueField({ label, value, start = "", onChange, placeholder, disabled,
824
1357
  }
825
1358
  };
826
1359
  return /* @__PURE__ */ jsxs("div", {
827
- className: "input-group",
828
- children: [start.includes("\n") ? /* @__PURE__ */ jsx(MaskedTextarea, {
829
- ...field,
830
- className: "input input-mono value-lines",
831
- rows: Math.min(8, 1 + Math.max(0, lineCount(value) - lineCount(start)))
832
- }) : /* @__PURE__ */ jsx(MaskedInput, { ...field }), /* @__PURE__ */ jsx("button", {
833
- type: "button",
834
- className: "btn btn-quiet btn-sm btn-icon input-addon",
835
- "aria-label": shown ? "Mask the value" : "Show the value",
836
- "aria-pressed": shown,
837
- onClick: () => setShown((current) => !current),
838
- children: shown ? /* @__PURE__ */ jsx(EyeOff, { size: 14 }) : /* @__PURE__ */ jsx(Eye, { size: 14 })
839
- })]
1360
+ className: "input-group has-generate",
1361
+ children: [
1362
+ lines ? /* @__PURE__ */ jsx(MaskedTextarea, {
1363
+ ...field,
1364
+ ref: (node) => {
1365
+ if (node === null || caret.current === null) return;
1366
+ node.focus();
1367
+ node.setSelectionRange(caret.current, caret.current);
1368
+ caret.current = null;
1369
+ },
1370
+ className: "input input-mono value-lines",
1371
+ rows: Math.min(8, 1 + Math.max(0, lineCount(value) - lineCount(start)))
1372
+ }) : /* @__PURE__ */ jsx(MaskedInput, {
1373
+ ...field,
1374
+ onPaste: (event) => {
1375
+ const pasted = event.clipboardData.getData("text/plain");
1376
+ if (!/[\r\n]/.test(pasted)) return;
1377
+ event.preventDefault();
1378
+ const text = pasted.replace(/\r\n?/g, "\n");
1379
+ const from = event.currentTarget.selectionStart ?? value.length;
1380
+ const to = event.currentTarget.selectionEnd ?? from;
1381
+ caret.current = from + text.length;
1382
+ onChange(value.slice(0, from) + text + value.slice(to));
1383
+ }
1384
+ }),
1385
+ /* @__PURE__ */ jsx(Tip, {
1386
+ label: "Generate a value",
1387
+ children: /* @__PURE__ */ jsx("button", {
1388
+ type: "button",
1389
+ className: "btn btn-quiet btn-sm btn-icon input-addon input-addon-generate",
1390
+ "aria-label": `Generate a value for ${generate.name.trim() === "" ? "the new secret" : generate.name.trim()}`,
1391
+ disabled,
1392
+ onClick: () => setGenerating(true),
1393
+ children: /* @__PURE__ */ jsx(Generate, { size: 14 })
1394
+ })
1395
+ }),
1396
+ /* @__PURE__ */ jsx("button", {
1397
+ type: "button",
1398
+ className: "btn btn-quiet btn-sm btn-icon input-addon",
1399
+ "aria-label": shown ? "Mask the value" : "Show the value",
1400
+ "aria-pressed": shown,
1401
+ onClick: () => setShown((current) => !current),
1402
+ children: shown ? /* @__PURE__ */ jsx(EyeOff, { size: 14 }) : /* @__PURE__ */ jsx(Eye, { size: 14 })
1403
+ }),
1404
+ /* @__PURE__ */ jsx(GenerateValue, {
1405
+ open: generating,
1406
+ onOpenChange: setGenerating,
1407
+ name: generate.name,
1408
+ renamable: generate.renamable,
1409
+ companion: generate.companion,
1410
+ onUse: generate.onUse
1411
+ })
1412
+ ]
1413
+ });
1414
+ }
1415
+ /** Under a row's value: the public key that saves with it, and the version it makes. */
1416
+ function CompanionNote({ companion, versionOf }) {
1417
+ if (companion === void 0) return null;
1418
+ const version = versionOf(companion.key);
1419
+ return /* @__PURE__ */ jsx("span", {
1420
+ className: "edit-note",
1421
+ children: /* @__PURE__ */ jsxs("span", { children: [
1422
+ "Saves its public key as ",
1423
+ /* @__PURE__ */ jsx("span", {
1424
+ className: "mono",
1425
+ children: companion.key.trim()
1426
+ }),
1427
+ version === null ? ", a new secret" : `, v${version} → v${version + 1}`
1428
+ ] })
840
1429
  });
841
1430
  }
842
1431
  function useSecondsLeft(reveal) {
@@ -850,7 +1439,7 @@ function useSecondsLeft(reveal) {
850
1439
  if (reveal === null) return 0;
851
1440
  return Math.max(0, Math.ceil(REVEAL_TTL_SECONDS - (now - reveal.at) / 1e3));
852
1441
  }
853
- function SecretRow({ number, project, environment, entry, change, editing, canWrite, canArchive, canReveal, folders, onMove, lent, environments, status, disabled, columns, onEdit, onPatch, onUndo, onSave, saveReady, onMarkArchive }) {
1442
+ function SecretRow({ number, project, environment, entry, rotateAfterDays, change, editing, canWrite, canArchive, canReveal, folders, onMove, lent, environments, status, disabled, columns, onEdit, onPatch, onUndo, onSave, versionOf, saveReady, onMarkArchive }) {
854
1443
  const [reveal, setReveal] = useState(null);
855
1444
  const coffre = useCoffre();
856
1445
  const [revealing, setRevealing] = useState(false);
@@ -992,22 +1581,41 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
992
1581
  className: "value-content",
993
1582
  children: editing && canWrite ? /* @__PURE__ */ jsxs("div", {
994
1583
  className: "edit-stack",
995
- children: [/* @__PURE__ */ jsx(ValueField, {
996
- label: `New value for ${entry.key}`,
997
- value: change.value ?? editBase?.value ?? "",
998
- start: editBase?.value,
999
- placeholder: canReveal ? "Value" : "New value; the current one is hidden from you",
1000
- disabled,
1001
- autoFocus: !focusName,
1002
- onChange: (value) => onPatch({ value: value === (editBase?.value ?? "") ? null : value }),
1003
- onEscape: onUndo
1004
- }), reference !== null && reference.state === "live" && /* @__PURE__ */ jsxs("span", {
1005
- className: "edit-note",
1006
- children: ["Saving a value stops following ", /* @__PURE__ */ jsx("span", {
1007
- className: "mono",
1008
- children: reference.source
1009
- })]
1010
- })]
1584
+ children: [
1585
+ /* @__PURE__ */ jsx(ValueField, {
1586
+ label: `New value for ${entry.key}`,
1587
+ value: change.value ?? editBase?.value ?? "",
1588
+ start: editBase?.value,
1589
+ placeholder: canReveal ? "Value" : "New value; the current one is hidden from you",
1590
+ disabled,
1591
+ autoFocus: !focusName,
1592
+ onChange: (value) => onPatch({
1593
+ value: value === (editBase?.value ?? "") ? null : value,
1594
+ companion: void 0
1595
+ }),
1596
+ onEscape: onUndo,
1597
+ generate: {
1598
+ name: change.key,
1599
+ renamable: false,
1600
+ companion: change.companion,
1601
+ onUse: ({ value, companion }) => onPatch({
1602
+ value,
1603
+ companion
1604
+ })
1605
+ }
1606
+ }),
1607
+ /* @__PURE__ */ jsx(CompanionNote, {
1608
+ companion: change.companion,
1609
+ versionOf
1610
+ }),
1611
+ reference !== null && reference.state === "live" && /* @__PURE__ */ jsxs("span", {
1612
+ className: "edit-note",
1613
+ children: ["Saving a value stops following ", /* @__PURE__ */ jsx("span", {
1614
+ className: "mono",
1615
+ children: reference.source
1616
+ })]
1617
+ })
1618
+ ]
1011
1619
  }) : shown !== null && !leaving ? /* @__PURE__ */ jsxs("div", {
1012
1620
  className: "revealed",
1013
1621
  style: { ["--reveal-ttl"]: `${REVEAL_TTL_SECONDS}s` },
@@ -1105,13 +1713,12 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
1105
1713
  })
1106
1714
  }),
1107
1715
  /* @__PURE__ */ jsx("td", {
1108
- className: "col-written col-hide-narrow",
1716
+ className: "col-written",
1109
1717
  "data-label": "Last written",
1110
- children: /* @__PURE__ */ jsx(Written, { entry: reference === null ? entry : {
1111
- ...entry,
1112
- updatedBy: reference.createdBy.replace(/^user:/, ""),
1113
- updatedAt: reference.createdAt
1114
- } })
1718
+ children: /* @__PURE__ */ jsx(Written, {
1719
+ entry,
1720
+ rotateAfterDays
1721
+ })
1115
1722
  }),
1116
1723
  /* @__PURE__ */ jsx("td", {
1117
1724
  className: "col-actions",
@@ -1262,33 +1869,81 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
1262
1869
  ] });
1263
1870
  }
1264
1871
  /**
1265
- * Who wrote the current version and how long ago, on one line: the local part
1266
- * of the email is enough to recognise a colleague, and the full address and
1267
- * the exact time are a hover away.
1872
+ * A column header that orders the table: its first click ascending, the
1873
+ * next descending. Below the width where rows stack, the sortable headers
1874
+ * stay, a row of their own above the keys.
1268
1875
  */
1269
- function Written({ entry }) {
1270
- if (entry.updatedBy === null && entry.updatedAt === null) return /* @__PURE__ */ jsx("span", {
1876
+ function SortHeader({ className, by, sort, onSort, children }) {
1877
+ const sorted = sort.by === by;
1878
+ return /* @__PURE__ */ jsx("th", {
1879
+ className: `${className} th-sortable`,
1880
+ "aria-sort": sorted ? sort.descending ? "descending" : "ascending" : void 0,
1881
+ children: /* @__PURE__ */ jsxs("button", {
1882
+ type: "button",
1883
+ className: "th th-sort",
1884
+ onClick: () => onSort(by),
1885
+ children: [children, sorted ? /* @__PURE__ */ jsx(ChevronDown, {
1886
+ size: 13,
1887
+ className: sort.descending ? "sort-mark" : "sort-mark is-ascending"
1888
+ }) : /* @__PURE__ */ jsx(ChevronsUpDown, {
1889
+ size: 13,
1890
+ className: "sort-mark is-idle"
1891
+ })]
1892
+ })
1893
+ });
1894
+ }
1895
+ /**
1896
+ * Who wrote the value a key reads and how long ago, on one line: the local
1897
+ * part of the email is enough to recognise a colleague, and the full address
1898
+ * and the exact time are a hover away. A reference's value is its source's,
1899
+ * as old as the version it reads, and who made the reference is a hover
1900
+ * away too. A value unchanged past the deployment's `rotateAfterDays` gets a
1901
+ * quiet tag, its age in days a hover away: it is due for rotation.
1902
+ */
1903
+ function Written({ entry, rotateAfterDays }) {
1904
+ const { reference } = entry;
1905
+ const made = reference === null ? void 0 : `Reference made by ${shownMember(reference.createdBy).replace(/^user:/, "")} on ${reference.createdAt.slice(0, 10)}`;
1906
+ if (entry.updatedAt === null) return /* @__PURE__ */ jsx("span", {
1271
1907
  className: "cell-muted",
1908
+ title: made,
1272
1909
  children: "—"
1273
1910
  });
1274
1911
  const by = entry.updatedBy ?? "unknown";
1912
+ const due = rotateAfterDays !== null && olderThan(entry, rotateAfterDays);
1913
+ const age = ageInDays(entry);
1275
1914
  return /* @__PURE__ */ jsxs("span", {
1276
1915
  className: "written",
1277
- children: [/* @__PURE__ */ jsx("span", {
1278
- className: "written-by",
1279
- title: by,
1280
- children: by.split("@")[0]
1281
- }), entry.updatedAt !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
1282
- className: "cell-muted",
1283
- "aria-hidden": true,
1284
- children: "·"
1285
- }), /* @__PURE__ */ jsx("span", {
1286
- className: "cell-muted",
1287
- children: /* @__PURE__ */ jsx(Timestamp, {
1288
- iso: entry.updatedAt,
1289
- display: "relative"
1916
+ children: [
1917
+ reference === null ? /* @__PURE__ */ jsx("span", {
1918
+ className: "written-by",
1919
+ title: by,
1920
+ children: by.split("@")[0]
1921
+ }) : /* @__PURE__ */ jsx("span", {
1922
+ className: "written-by cell-muted",
1923
+ title: `Its source's current version. ${made}`,
1924
+ children: "source"
1925
+ }),
1926
+ /* @__PURE__ */ jsx("span", {
1927
+ className: "cell-muted",
1928
+ "aria-hidden": true,
1929
+ children: "·"
1930
+ }),
1931
+ /* @__PURE__ */ jsx("span", {
1932
+ className: "cell-muted",
1933
+ children: /* @__PURE__ */ jsx(Timestamp, {
1934
+ iso: entry.updatedAt,
1935
+ display: "relative"
1936
+ })
1937
+ }),
1938
+ due && /* @__PURE__ */ jsx(Tip, {
1939
+ label: `Unchanged for ${age} days, past the ${rotateAfterDays} this deployment allows: rotate it`,
1940
+ children: /* @__PURE__ */ jsx("span", {
1941
+ className: "tag tag-amber written-flag",
1942
+ tabIndex: 0,
1943
+ children: "Rotate"
1944
+ })
1290
1945
  })
1291
- })] })]
1946
+ ]
1292
1947
  });
1293
1948
  }
1294
1949
  /**
@@ -1298,7 +1953,7 @@ function Written({ entry }) {
1298
1953
  * from the list to add to it, and only ever accepted one key at a time; a row
1299
1954
  * in place accepts as many as you want to queue.
1300
1955
  */
1301
- function DraftRow({ draft, existingVersion, disabled, onChange, onRemove, onSave, saveReady }) {
1956
+ function DraftRow({ draft, existingVersion, disabled, onChange, onRemove, onSave, versionOf, saveReady }) {
1302
1957
  const [touched, setTouched] = useState(false);
1303
1958
  const trimmed = draft.key.trim();
1304
1959
  const keyProblem = trimmed === "" ? touched ? "Give it a name." : null : secretKeyProblem(trimmed);
@@ -1343,16 +1998,32 @@ function DraftRow({ draft, existingVersion, disabled, onChange, onRemove, onSave
1343
1998
  className: "value-cell",
1344
1999
  children: [/* @__PURE__ */ jsx("div", {
1345
2000
  className: "value-content",
1346
- children: /* @__PURE__ */ jsx("div", {
2001
+ children: /* @__PURE__ */ jsxs("div", {
1347
2002
  className: "edit-stack",
1348
- children: /* @__PURE__ */ jsx(ValueField, {
2003
+ children: [/* @__PURE__ */ jsx(ValueField, {
1349
2004
  label: `Value for ${trimmed === "" ? "the new secret" : trimmed}`,
1350
2005
  value: draft.value,
1351
2006
  placeholder: "Value",
1352
2007
  disabled,
1353
- onChange: (value) => onChange({ value }),
1354
- onEscape: onRemove
1355
- })
2008
+ onChange: (value) => onChange({
2009
+ value,
2010
+ companion: void 0
2011
+ }),
2012
+ onEscape: onRemove,
2013
+ generate: {
2014
+ name: draft.key,
2015
+ renamable: true,
2016
+ companion: draft.companion,
2017
+ onUse: ({ value, name, companion }) => onChange({
2018
+ key: name,
2019
+ value,
2020
+ companion
2021
+ })
2022
+ }
2023
+ }), /* @__PURE__ */ jsx(CompanionNote, {
2024
+ companion: draft.companion,
2025
+ versionOf
2026
+ })]
1356
2027
  })
1357
2028
  }), /* @__PURE__ */ jsxs("div", {
1358
2029
  className: "acts value-acts",
@@ -1428,7 +2099,10 @@ function ArchivedRow({ number, project, environment, entry, canArchive, canRevea
1428
2099
  /* @__PURE__ */ jsx("td", {
1429
2100
  className: "col-written col-hide-narrow",
1430
2101
  "data-label": "Last written",
1431
- children: /* @__PURE__ */ jsx(Written, { entry })
2102
+ children: /* @__PURE__ */ jsx(Written, {
2103
+ entry,
2104
+ rotateAfterDays: null
2105
+ })
1432
2106
  }),
1433
2107
  /* @__PURE__ */ jsx("td", {
1434
2108
  className: "col-actions",