@coffre/ui 0.2.0 → 0.4.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 (177) hide show
  1. package/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
  2. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
  3. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  4. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  5. package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
  6. package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
  7. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  8. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  9. package/dist/chunks/grants-Cw1FyGID.js +669 -0
  10. package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
  11. package/dist/chunks/offboarding-CE6d7um1.js +305 -0
  12. package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
  13. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  14. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  15. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  16. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  17. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  18. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  19. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
  20. package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
  21. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  22. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  23. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  24. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  25. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  26. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  27. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  28. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  29. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  30. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  31. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  32. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  33. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  34. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  35. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  36. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  37. package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
  38. package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
  39. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  40. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  41. package/dist/chunks/validation-D312_NLf.js +87 -0
  42. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  43. package/dist/index.d.ts +361 -27
  44. package/dist/index.js +188 -98
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/account.d.ts +2 -2
  47. package/dist/pages/account.js +297 -135
  48. package/dist/pages/account.js.map +1 -1
  49. package/dist/pages/approval.d.ts +9 -0
  50. package/dist/pages/approval.js +207 -0
  51. package/dist/pages/approval.js.map +1 -0
  52. package/dist/pages/audit.js +17 -542
  53. package/dist/pages/audit.js.map +1 -1
  54. package/dist/pages/device-login.js +2 -3
  55. package/dist/pages/device-login.js.map +1 -1
  56. package/dist/pages/environment.js +647 -257
  57. package/dist/pages/environment.js.map +1 -1
  58. package/dist/pages/login.js +18 -7
  59. package/dist/pages/login.js.map +1 -1
  60. package/dist/pages/oauth-authorize.d.ts +10 -0
  61. package/dist/pages/oauth-authorize.js +249 -0
  62. package/dist/pages/oauth-authorize.js.map +1 -0
  63. package/dist/pages/project-access.d.ts +6 -0
  64. package/dist/pages/project-access.js +370 -0
  65. package/dist/pages/project-access.js.map +1 -0
  66. package/dist/pages/project-environments.d.ts +4 -0
  67. package/dist/pages/project-environments.js +593 -0
  68. package/dist/pages/project-environments.js.map +1 -0
  69. package/dist/pages/project-settings.d.ts +4 -0
  70. package/dist/pages/project-settings.js +242 -0
  71. package/dist/pages/project-settings.js.map +1 -0
  72. package/dist/pages/project.d.ts +10 -2
  73. package/dist/pages/project.js +57 -934
  74. package/dist/pages/project.js.map +1 -1
  75. package/dist/pages/projects.js +53 -21
  76. package/dist/pages/projects.js.map +1 -1
  77. package/dist/pages/service-account.d.ts +10 -0
  78. package/dist/pages/{token.js → service-account.js} +115 -56
  79. package/dist/pages/service-account.js.map +1 -0
  80. package/dist/pages/service-accounts.d.ts +3 -0
  81. package/dist/pages/service-accounts.js +38 -0
  82. package/dist/pages/service-accounts.js.map +1 -0
  83. package/dist/pages/settings.d.ts +1 -0
  84. package/dist/pages/settings.js +104 -42
  85. package/dist/pages/settings.js.map +1 -1
  86. package/dist/pages/unregistered.js +2 -3
  87. package/dist/pages/unregistered.js.map +1 -1
  88. package/dist/pages/user.d.ts +6 -1
  89. package/dist/pages/user.js +18 -6
  90. package/dist/pages/user.js.map +1 -1
  91. package/dist/pages/users.js +6 -10
  92. package/dist/pages/users.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/components/actions-log.tsx +117 -0
  95. package/src/components/audit-sentence.tsx +55 -0
  96. package/src/components/command-palette.tsx +4 -4
  97. package/src/components/delete-place.tsx +180 -0
  98. package/src/components/directory.tsx +259 -110
  99. package/src/components/every-project.tsx +287 -0
  100. package/src/components/expiry-field.tsx +42 -0
  101. package/src/components/folders.tsx +219 -0
  102. package/src/components/grants.tsx +11 -4
  103. package/src/components/icons.tsx +2 -0
  104. package/src/components/missing.tsx +110 -0
  105. package/src/components/offboarding.tsx +61 -33
  106. package/src/components/page.tsx +4 -1
  107. package/src/components/principal-page.tsx +136 -106
  108. package/src/components/principal-picker.tsx +5 -5
  109. package/src/components/principal.tsx +4 -4
  110. package/src/components/references.tsx +323 -0
  111. package/src/components/service-tokens.tsx +115 -95
  112. package/src/components/shell.tsx +11 -32
  113. package/src/components/tabs.tsx +18 -0
  114. package/src/components/trusted-workloads.tsx +97 -79
  115. package/src/components/ui.tsx +8 -1
  116. package/src/index.ts +13 -2
  117. package/src/layout.tsx +2 -2
  118. package/src/lib/access-plan.ts +2 -2
  119. package/src/lib/audit-sentences.ts +161 -77
  120. package/src/lib/changes.ts +56 -5
  121. package/src/lib/coffre.ts +3 -2
  122. package/src/lib/one-time.ts +32 -0
  123. package/src/lib/project-access.ts +11 -23
  124. package/src/lib/project-page.ts +14 -0
  125. package/src/lib/queries.ts +126 -32
  126. package/src/lib/search.ts +25 -0
  127. package/src/lib/signin-errors.ts +45 -1
  128. package/src/lib/validation.ts +14 -0
  129. package/src/options.ts +187 -35
  130. package/src/pages/account.tsx +274 -129
  131. package/src/pages/approval.tsx +197 -0
  132. package/src/pages/audit.tsx +9 -61
  133. package/src/pages/environment.tsx +585 -286
  134. package/src/pages/login.tsx +8 -2
  135. package/src/pages/oauth-authorize.tsx +233 -0
  136. package/src/pages/project-access.tsx +219 -0
  137. package/src/pages/project-environments.tsx +582 -0
  138. package/src/pages/project-settings.tsx +259 -0
  139. package/src/pages/project.tsx +52 -879
  140. package/src/pages/projects.tsx +55 -18
  141. package/src/pages/service-account.tsx +50 -0
  142. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  143. package/src/pages/settings.tsx +62 -8
  144. package/src/pages/user.tsx +16 -4
  145. package/src/pages/users.tsx +2 -2
  146. package/src/parity.ts +160 -0
  147. package/src/register.ts +58 -9
  148. package/src/router.tsx +4 -0
  149. package/src/shared/models.ts +6 -2
  150. package/src/styles/globals.css +536 -31
  151. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  152. package/dist/chunks/grants-saMQagmG.js +0 -160
  153. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  154. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  155. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  156. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  157. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  158. package/dist/chunks/page-C5HcNqf2.js +0 -190
  159. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  160. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  161. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  162. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  163. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  164. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  165. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  166. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  167. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  168. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  169. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  170. package/dist/pages/token.d.ts +0 -3
  171. package/dist/pages/token.js.map +0 -1
  172. package/dist/pages/tokens.d.ts +0 -3
  173. package/dist/pages/tokens.js +0 -39
  174. package/dist/pages/tokens.js.map +0 -1
  175. package/dist/project-BqIy8gYR.d.ts +0 -5
  176. package/src/lib/instance.ts +0 -13
  177. package/src/pages/token.tsx +0 -34
@@ -1,27 +1,158 @@
1
- import { a as ErrorLine, c as Notice, d as Tip, i as EmptyState, l as Spinner, m as breakAfterUnderscores, o as MenuPopup, r as CopyButton, s as Modal, t as ConfirmButton, u as Timestamp } from "../chunks/ui-DixXLQvQ.js";
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";
2
3
  import { i as SecretReadOnly } from "../chunks/affordances-DAvsVz7u.js";
3
- import { A as Pencil, B as Terminal, C as Lock, G as X, N as RotateBack, O as MoreHorizontal, P as Search, V as Upload, d as Eye, f as EyeOff, g as History, h as Hash, i as Archive, j as Plus, l as Clock, n as AlertCircle, v as Key } from "../chunks/icons-D-PfAfnH.js";
4
- import { i as PageHeader, n as ClosedDoor, o as failureMessage, t as Card, u as useCoffre } from "../chunks/page-C5HcNqf2.js";
5
- import { a as rowClass, i as RowPending, r as RowFailure } from "../chunks/row-state-0PsrEzOL.js";
6
- import { p as canRevealSecrets, r as keys, t as affects, u as queries } from "../chunks/queries-CQ81o4so.js";
7
- import { t as useShell } from "../chunks/use-shell-jxd7Tzd-.js";
8
- import { S as saveSecrets, T as secretChangeFor, a as archiveSecret, n as useChangeStatus, r as UnsavedEdits, t as useChange, w as hasSecretEditConflict, y as restoreSecret } from "../chunks/use-change-c6CeLRin.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 { _ as canRevealSecrets, p as queries, r as keys, t as affects } from "../chunks/queries-DVR_i3rA.js";
7
+ import { t as useShell } from "../chunks/use-shell-rNKfGjdj.js";
8
+ import { D as secretChangeFor, E as hasSecretEditConflict, a as archiveSecret, g as moveSecret, n as useChangeStatus, r as UnsavedEdits, t as useChange, w as saveSecrets, x as restoreSecret } from "../chunks/use-change-DUiGO19U.js";
9
9
  import { t as pageRoute } from "../chunks/page-route-Drfw7lmn.js";
10
- import { t as useAction } from "../chunks/use-action-CWsg_YWU.js";
11
- import { t as secretKeyProblem } from "../chunks/validation-BQtqPe2V.js";
10
+ import { a as useAction, r as secretKeyProblem } from "../chunks/validation-D312_NLf.js";
11
+ import { n as FolderRow, r as MoveToFolder, t as FolderMenu } from "../chunks/folders-DoBmCwOi.js";
12
+ import { i as ReferenceValue, n as LentReferences, o as archiveBlockers, r as MakeReference, t as ArchiveBlocked } from "../chunks/references-B6pLT1uQ.js";
12
13
  import { useEffect, useRef, useState } from "react";
13
14
  import { Link } from "@tanstack/react-router";
14
15
  import { toast } from "sonner";
15
16
  import { Menu } from "@base-ui/react/menu";
16
17
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
17
- import { useSuspenseQuery } from "@tanstack/react-query";
18
- import { CoffreError, planImport } from "@coffre/client";
18
+ import { useQuery, useSuspenseQuery } from "@tanstack/react-query";
19
+ import { CoffreError, byFolder, foldersOf, planImport } from "@coffre/client";
19
20
  import { parseDotenv } from "@coffre/core/dotenv";
20
21
  //#region src/lib/reveal.ts
21
22
  function revealIsCurrent(reveal, currentVersion) {
22
23
  return reveal !== null && reveal.version === currentVersion;
23
24
  }
24
25
  //#endregion
26
+ //#region src/components/missing.tsx
27
+ /**
28
+ * Keys the environment's siblings have and it lacks, of those you read
29
+ * (docs/design/environments.md): each with Add, which opens a new row with
30
+ * its name, and Dismiss, which the whole team then sees, and below them
31
+ * Dismiss all and what was dismissed, each with Restore. Nothing shows when
32
+ * nothing is missing or dismissed.
33
+ */
34
+ function MissingKeys({ project, environment, canWrite, onAdd }) {
35
+ const coffre = useCoffre();
36
+ const place = {
37
+ project,
38
+ environment
39
+ };
40
+ const { data } = useQuery(queries.missing(coffre, place));
41
+ const { run, pending, error } = useAction();
42
+ const [showDismissed, setShowDismissed] = useState(false);
43
+ if (data?.ok !== true || data.missing.length === 0 && data.dismissed.length === 0) return null;
44
+ const { missing, dismissed } = data;
45
+ const path = `${project}/${environment}`;
46
+ const dismiss = (patch) => void run(() => coffre.environments.dismiss(path, patch), { affects: affects.secrets(place) });
47
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Card, {
48
+ wide: true,
49
+ labelledBy: "missing-keys",
50
+ title: missing.length === 0 ? "Nothing missing" : `${missing.length} ${missing.length === 1 ? "key" : "keys"} from other environments ${missing.length === 1 ? "isn't" : "aren't"} here`,
51
+ description: "Compared with the environments you can read.",
52
+ children: [/* @__PURE__ */ jsx("div", {
53
+ className: "dt-wrap",
54
+ children: /* @__PURE__ */ jsx("table", {
55
+ className: "dt stacks missing-keys",
56
+ children: /* @__PURE__ */ jsxs("tbody", { children: [
57
+ missing.map((entry) => /* @__PURE__ */ jsxs("tr", { children: [
58
+ /* @__PURE__ */ jsx("td", {
59
+ className: "mono",
60
+ "data-label": "Key",
61
+ children: entry.key
62
+ }),
63
+ /* @__PURE__ */ jsxs("td", {
64
+ className: "cell-muted",
65
+ "data-label": "In",
66
+ children: [
67
+ "In ",
68
+ entry.in.join(", "),
69
+ entry.folder !== null && /* @__PURE__ */ jsxs(Fragment$1, { children: [
70
+ ", in ",
71
+ entry.folder,
72
+ "/"
73
+ ] })
74
+ ]
75
+ }),
76
+ canWrite && /* @__PURE__ */ jsx("td", {
77
+ className: "col-actions",
78
+ children: /* @__PURE__ */ jsxs("div", {
79
+ className: "acts",
80
+ children: [/* @__PURE__ */ jsx("button", {
81
+ type: "button",
82
+ className: "btn btn-sm",
83
+ onClick: () => onAdd(entry.key),
84
+ children: "Add"
85
+ }), /* @__PURE__ */ jsx("button", {
86
+ type: "button",
87
+ className: "btn btn-sm btn-quiet",
88
+ disabled: pending,
89
+ onClick: () => dismiss({ [entry.key]: true }),
90
+ children: "Dismiss"
91
+ })]
92
+ })
93
+ })
94
+ ] }, entry.key)),
95
+ showDismissed && dismissed.length > 0 && /* @__PURE__ */ jsx("tr", {
96
+ className: "folder-row",
97
+ children: /* @__PURE__ */ jsx("th", {
98
+ colSpan: canWrite ? 3 : 2,
99
+ scope: "rowgroup",
100
+ children: "Dismissed"
101
+ })
102
+ }),
103
+ showDismissed && dismissed.map((entry) => /* @__PURE__ */ jsxs("tr", { children: [
104
+ /* @__PURE__ */ jsx("td", {
105
+ className: "mono",
106
+ "data-label": "Key",
107
+ children: entry.key
108
+ }),
109
+ /* @__PURE__ */ jsxs("td", {
110
+ className: "cell-muted",
111
+ "data-label": "Dismissed",
112
+ children: [
113
+ "By ",
114
+ entry.dismissedBy,
115
+ " ",
116
+ /* @__PURE__ */ jsx(Timestamp, {
117
+ iso: entry.dismissedAt,
118
+ display: "relative"
119
+ }),
120
+ "; in ",
121
+ entry.in.join(", ")
122
+ ]
123
+ }),
124
+ canWrite && /* @__PURE__ */ jsx("td", {
125
+ className: "col-actions",
126
+ children: /* @__PURE__ */ jsx("button", {
127
+ type: "button",
128
+ className: "btn btn-sm",
129
+ disabled: pending,
130
+ onClick: () => dismiss({ [entry.key]: null }),
131
+ children: "Restore"
132
+ })
133
+ })
134
+ ] }, `dismissed:${entry.key}`))
135
+ ] })
136
+ })
137
+ }), error !== null && /* @__PURE__ */ jsx(ErrorLine, { error })]
138
+ }), /* @__PURE__ */ jsxs("div", {
139
+ className: "table-actions",
140
+ children: [canWrite && missing.length > 1 && /* @__PURE__ */ jsx("button", {
141
+ type: "button",
142
+ className: "btn",
143
+ disabled: pending,
144
+ onClick: () => dismiss(Object.fromEntries(missing.map((entry) => [entry.key, true]))),
145
+ children: "Dismiss all"
146
+ }), dismissed.length > 0 && /* @__PURE__ */ jsx("button", {
147
+ type: "button",
148
+ className: "btn btn-quiet",
149
+ "aria-expanded": showDismissed,
150
+ onClick: () => setShowDismissed((open) => !open),
151
+ children: showDismissed ? "Hide dismissed" : `Dismissed (${dismissed.length})`
152
+ })]
153
+ })] });
154
+ }
155
+ //#endregion
25
156
  //#region src/pages/environment.tsx
26
157
  var Route = pageRoute();
27
158
  /**
@@ -79,6 +210,18 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
79
210
  project,
80
211
  environment
81
212
  }));
213
+ const move = useChange(moveSecret(coffre, {
214
+ project,
215
+ environment
216
+ }));
217
+ const { data: references } = useQuery(queries.references(coffre, `${project}/${environment}`));
218
+ const lentBy = /* @__PURE__ */ new Map();
219
+ for (const reference of references?.ok === true ? references.references : []) {
220
+ const [sourceProject, sourceEnvironment, key] = reference.source.split("/");
221
+ if (sourceProject !== project || sourceEnvironment !== environment) continue;
222
+ lentBy.set(key, [...lentBy.get(key) ?? [], reference]);
223
+ }
224
+ const readable = useShell().projects.flatMap((each) => each.environments.filter(isActiveAccessibleEnvironment).map((one) => `${each.slug}/${one.slug}`));
82
225
  const { status, dismiss } = useChangeStatus(keys.secrets({
83
226
  project,
84
227
  environment
@@ -92,7 +235,30 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
92
235
  const canWrite = permissions.includes("secret.write");
93
236
  const canArchive = permissions.includes("secret.archive");
94
237
  const canReveal = canRevealSecrets(permissions);
95
- const active = keys$1.filter((entry) => !entry.archived);
238
+ const active = byFolder(keys$1.filter((entry) => !entry.archived)).flatMap(([, entries]) => entries);
239
+ const folders = foldersOf(active);
240
+ const refile = useAction();
241
+ const place = `${project}/${environment}`;
242
+ const folderMenu = (folder, count) => canWrite && /* @__PURE__ */ jsx(FolderMenu, {
243
+ folder,
244
+ count,
245
+ what: "key",
246
+ folders,
247
+ onRename: (name) => void refile.run(() => coffre.folders.renameKeys(place, folder, name), {
248
+ affects: affects.secrets({
249
+ project,
250
+ environment
251
+ }),
252
+ onSuccess: () => toast.success(`${folder}/ is ${name}/ now`)
253
+ }),
254
+ onRemove: () => void refile.run(() => coffre.folders.removeKeys(place, folder), {
255
+ affects: affects.secrets({
256
+ project,
257
+ environment
258
+ }),
259
+ onSuccess: () => toast.success(`${folder}/ removed: its keys are in no folder`)
260
+ })
261
+ });
96
262
  const archived = keys$1.filter((entry) => entry.archived);
97
263
  const existing = new Set(keys$1.map((entry) => entry.key));
98
264
  const changedEntries = active.filter((entry) => secretChangeFor(changes, entry.key) !== void 0);
@@ -123,6 +289,45 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
123
289
  return rest;
124
290
  });
125
291
  }
292
+ /**
293
+ * One row's own Save: its change alone goes, and any other row's stays
294
+ * pending. A row opened and left as it was just closes.
295
+ */
296
+ function saveRow(key) {
297
+ const change = secretChangeFor(changes, key);
298
+ dropChange(key);
299
+ if (change === void 0) return;
300
+ sendAlone({
301
+ active,
302
+ drafts: [],
303
+ changes: { [key]: change }
304
+ });
305
+ }
306
+ function saveDraft(draft) {
307
+ setDrafts((rows) => rows.filter((row) => row.id !== draft.id));
308
+ sendAlone({
309
+ active,
310
+ drafts: [draft],
311
+ changes: {}
312
+ });
313
+ }
314
+ /** Whether one row's change could go alone: named, well named, and clashing with nothing. */
315
+ function readyAlone(drafts, changes) {
316
+ const names = [...drafts.map((row) => row.key.trim()), ...Object.values(changes).flatMap((change) => change.archived ? [] : [change.key.trim()])];
317
+ return (drafts.length > 0 || Object.keys(changes).length > 0) && names.every((name) => name !== "" && secretKeyProblem(name) === null) && !hasSecretEditConflict(active, drafts, changes);
318
+ }
319
+ function sendAlone(batch) {
320
+ setSaveError(null);
321
+ save(batch, { onError: (error) => {
322
+ const left = error instanceof UnsavedEdits ? error.outcome : batch;
323
+ setDrafts((rows) => [...rows, ...left.drafts]);
324
+ setChanges((current) => ({
325
+ ...current,
326
+ ...left.changes
327
+ }));
328
+ setSaveError(failureMessage(error));
329
+ } });
330
+ }
126
331
  function dropChange(key) {
127
332
  setChanges((current) => {
128
333
  const { [key]: _, ...rest } = current;
@@ -135,11 +340,11 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
135
340
  });
136
341
  }
137
342
  function addDraft() {
138
- setDrafts((rows) => [{
343
+ setDrafts((rows) => [...rows, {
139
344
  id: nextDraftId.current++,
140
345
  key: "",
141
346
  value: ""
142
- }, ...rows]);
347
+ }]);
143
348
  }
144
349
  function discardAll() {
145
350
  setDrafts([]);
@@ -235,15 +440,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
235
440
  aside: /* @__PURE__ */ jsx(EnvironmentName, {
236
441
  project,
237
442
  environment
238
- }),
239
- actions: /* @__PURE__ */ jsxs(Fragment$1, { children: [canWrite && canReveal && /* @__PURE__ */ jsx(ImportEnv, {
240
- project,
241
- environment
242
- }), canWrite && /* @__PURE__ */ jsxs("button", {
243
- className: "btn btn-primary",
244
- onClick: addDraft,
245
- children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "New secret"]
246
- })] })
443
+ })
247
444
  }),
248
445
  (active.length > 0 || drafts.length > 0) && /* @__PURE__ */ jsxs("div", {
249
446
  className: "toolbar",
@@ -290,19 +487,22 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
290
487
  })
291
488
  })]
292
489
  }),
490
+ /* @__PURE__ */ jsx(MissingKeys, {
491
+ project,
492
+ environment,
493
+ canWrite,
494
+ onAdd: (key) => setDrafts((rows) => [...rows, {
495
+ id: nextDraftId.current++,
496
+ key,
497
+ value: ""
498
+ }])
499
+ }),
500
+ refile.error !== null && /* @__PURE__ */ jsx(ErrorLine, { error: refile.error }),
293
501
  /* @__PURE__ */ jsx("section", {
294
- className: "card",
502
+ className: "card card-wide",
295
503
  "aria-label": "Secrets",
296
504
  children: active.length === 0 && drafts.length === 0 ? /* @__PURE__ */ jsx(EmptyState, {
297
505
  title: "No secrets yet",
298
- actions: canWrite ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
299
- className: "btn btn-primary",
300
- onClick: addDraft,
301
- children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "New secret"]
302
- }), canReveal && /* @__PURE__ */ jsx(ImportEnv, {
303
- project,
304
- environment
305
- })] }) : void 0,
306
506
  children: canWrite ? "Add them one by one, or import an existing .env file. Nothing is written until you save, or until you have seen the import plan." : "Nothing has been written to this environment, and adding the first secret needs secret.write."
307
507
  }) : /* @__PURE__ */ jsx("div", {
308
508
  className: "dt-wrap",
@@ -353,17 +553,12 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
353
553
  })
354
554
  })
355
555
  ] }) }), /* @__PURE__ */ jsxs("tbody", { children: [
356
- drafts.map((draft) => /* @__PURE__ */ jsx(DraftRow, {
357
- draft,
358
- existingVersion: keys$1.find((entry) => entry.key === draft.key.trim())?.version ?? null,
359
- disabled: false,
360
- onChange: (patch) => setDrafts((rows) => rows.map((row) => row.id === draft.id ? {
361
- ...row,
362
- ...patch
363
- } : row)),
364
- onRemove: () => setDrafts((rows) => rows.filter((row) => row.id !== draft.id))
365
- }, draft.id)),
366
- listed.map((entry) => {
556
+ byFolder(listed).flatMap(([folder, entries]) => [...folder === null ? [] : [/* @__PURE__ */ jsx(FolderRow, {
557
+ folder,
558
+ count: entries.length,
559
+ columns,
560
+ actions: folderMenu(folder, entries.length)
561
+ }, `folder:${folder}`)], ...entries.map((entry) => {
367
562
  const change = secretChangeFor(changes, entry.key);
368
563
  const state = status(entry.key);
369
564
  return /* @__PURE__ */ jsx(SecretRow, {
@@ -380,12 +575,21 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
380
575
  canWrite,
381
576
  canArchive,
382
577
  canReveal,
578
+ folders,
579
+ onMove: (folder) => move({
580
+ key: entry.key,
581
+ folder
582
+ }),
583
+ lent: lentBy.get(entry.key) ?? [],
584
+ environments: readable,
383
585
  status: state,
384
586
  disabled: state.state === "pending",
385
587
  columns,
386
588
  onEdit: () => setEditing((current) => new Set(current).add(entry.key)),
387
589
  onPatch: (patch) => patchChange(entry, patch),
388
590
  onUndo: () => dropChange(entry.key),
591
+ onSave: () => saveRow(entry.key),
592
+ saveReady: change === void 0 || readyAlone([], { [entry.key]: change }),
389
593
  onMarkArchive: () => {
390
594
  setEditing((current) => {
391
595
  const next = new Set(current);
@@ -402,7 +606,7 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
402
606
  }));
403
607
  }
404
608
  }, entry.key);
405
- }),
609
+ })]),
406
610
  listed.length === 0 && active.length > 0 && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsxs("td", {
407
611
  colSpan: columns,
408
612
  className: "cell-muted",
@@ -412,19 +616,39 @@ function EnvironmentLedger({ project, environment, permissions, keys: keys$1 })
412
616
  query.trim(),
413
617
  "”."
414
618
  ]
415
- }) })
619
+ }) }),
620
+ drafts.map((draft) => /* @__PURE__ */ jsx(DraftRow, {
621
+ draft,
622
+ existingVersion: keys$1.find((entry) => entry.key === draft.key.trim())?.version ?? null,
623
+ disabled: false,
624
+ onChange: (patch) => setDrafts((rows) => rows.map((row) => row.id === draft.id ? {
625
+ ...row,
626
+ ...patch
627
+ } : row)),
628
+ onRemove: () => setDrafts((rows) => rows.filter((row) => row.id !== draft.id)),
629
+ onSave: () => saveDraft(draft),
630
+ saveReady: readyAlone([draft], {})
631
+ }, draft.id))
416
632
  ] })]
417
633
  })
418
634
  })
419
635
  }),
636
+ canWrite && /* @__PURE__ */ jsxs("div", {
637
+ className: "table-actions",
638
+ children: [/* @__PURE__ */ jsxs("button", {
639
+ className: "btn btn-primary",
640
+ onClick: addDraft,
641
+ children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "New secret"]
642
+ }), canReveal && /* @__PURE__ */ jsx(ImportEnv, {
643
+ project,
644
+ environment
645
+ })]
646
+ }),
420
647
  archived.length > 0 && /* @__PURE__ */ jsx(Card, {
648
+ wide: true,
421
649
  labelledBy: "archived-secrets",
422
650
  title: "Archived",
423
- description: /* @__PURE__ */ jsxs(Fragment$1, { children: [
424
- "Retired, so no longer served or injected by ",
425
- /* @__PURE__ */ jsx("code", { children: "coffre run" }),
426
- ". Their history and audit trail are intact, and restoring is immediate."
427
- ] }),
651
+ description: "No longer served; restoring one brings it back with its history.",
428
652
  children: /* @__PURE__ */ jsx("div", {
429
653
  className: "dt-wrap",
430
654
  children: /* @__PURE__ */ jsxs("table", {
@@ -546,14 +770,35 @@ function EnvironmentName({ project, environment }) {
546
770
  * save or fill them, and a secret being typed into coffre is neither.
547
771
  */
548
772
  function MaskedInput({ masked, className = "", ...props }) {
773
+ const cssMask = useCssMask();
774
+ return /* @__PURE__ */ jsx("input", {
775
+ ...props,
776
+ type: masked && !cssMask ? "password" : "text",
777
+ className: `${className}${masked && cssMask ? " is-masked" : ""}`,
778
+ autoComplete: "off",
779
+ spellCheck: false,
780
+ "data-1p-ignore": true,
781
+ "data-lpignore": "true",
782
+ "data-bwignore": true
783
+ });
784
+ }
785
+ function useCssMask() {
549
786
  const [cssMask, setCssMask] = useState(false);
550
787
  useEffect(() => {
551
788
  setCssMask(typeof CSS !== "undefined" && CSS.supports("-webkit-text-security", "disc"));
552
789
  }, []);
553
- return /* @__PURE__ */ jsx("input", {
790
+ return cssMask;
791
+ }
792
+ /**
793
+ * MaskedInput for a value with line breaks, which a text input would drop.
794
+ * Without the CSS mask there is no password textarea, so masked text is
795
+ * drawn transparent instead.
796
+ */
797
+ function MaskedTextarea({ masked, className = "", ...props }) {
798
+ const cssMask = useCssMask();
799
+ return /* @__PURE__ */ jsx("textarea", {
554
800
  ...props,
555
- type: masked && !cssMask ? "password" : "text",
556
- className: `${className}${masked && cssMask ? " is-masked" : ""}`,
801
+ className: `${className}${masked ? cssMask ? " is-masked" : " is-masked-fallback" : ""}`,
557
802
  autoComplete: "off",
558
803
  spellCheck: false,
559
804
  "data-1p-ignore": true,
@@ -561,23 +806,29 @@ function MaskedInput({ masked, className = "", ...props }) {
561
806
  "data-bwignore": true
562
807
  });
563
808
  }
564
- function ValueField({ label, value, onChange, placeholder, disabled, autoFocus, onEscape }) {
809
+ var lineCount = (text) => text.split("\n").length;
810
+ function ValueField({ label, value, start = "", onChange, placeholder, disabled, autoFocus, onEscape }) {
565
811
  const [shown, setShown] = useState(false);
812
+ const field = {
813
+ className: "input input-mono",
814
+ masked: !shown,
815
+ "aria-label": label,
816
+ placeholder,
817
+ value,
818
+ disabled,
819
+ autoFocus,
820
+ onChange: (event) => onChange(event.target.value),
821
+ onKeyDown: (event) => {
822
+ if (event.key === "Escape" && onEscape !== void 0) onEscape();
823
+ }
824
+ };
566
825
  return /* @__PURE__ */ jsxs("div", {
567
826
  className: "input-group",
568
- children: [/* @__PURE__ */ jsx(MaskedInput, {
569
- className: "input input-mono",
570
- masked: !shown,
571
- "aria-label": label,
572
- placeholder,
573
- value,
574
- disabled,
575
- autoFocus,
576
- onChange: (event) => onChange(event.target.value),
577
- onKeyDown: (event) => {
578
- if (event.key === "Escape" && onEscape !== void 0) onEscape();
579
- }
580
- }), /* @__PURE__ */ jsx("button", {
827
+ children: [start.includes("\n") ? /* @__PURE__ */ jsx(MaskedTextarea, {
828
+ ...field,
829
+ className: "input input-mono value-lines",
830
+ rows: Math.min(8, 1 + Math.max(0, lineCount(value) - lineCount(start)))
831
+ }) : /* @__PURE__ */ jsx(MaskedInput, { ...field }), /* @__PURE__ */ jsx("button", {
581
832
  type: "button",
582
833
  className: "btn btn-quiet btn-sm btn-icon input-addon",
583
834
  "aria-label": shown ? "Mask the value" : "Show the value",
@@ -598,37 +849,47 @@ function useSecondsLeft(reveal) {
598
849
  if (reveal === null) return 0;
599
850
  return Math.max(0, Math.ceil(REVEAL_TTL_SECONDS - (now - reveal.at) / 1e3));
600
851
  }
601
- function SecretRow({ number, project, environment, entry, change, editing, canWrite, canArchive, canReveal, status, disabled, columns, onEdit, onPatch, onUndo, onMarkArchive }) {
852
+ function SecretRow({ number, project, environment, entry, change, editing, canWrite, canArchive, canReveal, folders, onMove, lent, environments, status, disabled, columns, onEdit, onPatch, onUndo, onSave, saveReady, onMarkArchive }) {
602
853
  const [reveal, setReveal] = useState(null);
603
854
  const coffre = useCoffre();
604
855
  const [revealing, setRevealing] = useState(false);
605
856
  const [historyOpen, setHistoryOpen] = useState(false);
857
+ const [moving, setMoving] = useState(false);
858
+ const [referring, setReferring] = useState(false);
859
+ const [breaking, setBreaking] = useState(null);
860
+ const [lentOpen, setLentOpen] = useState(false);
861
+ const [archiveBlocked, setArchiveBlocked] = useState(false);
862
+ const blockers = archiveBlockers(`${project}/${environment}/${entry.key}`, lent);
863
+ const { run: act, error: actError } = useAction();
864
+ const { reference } = entry;
865
+ const readVersion = reference === null ? entry.version : reference.version;
866
+ const holderPath = `${project}/${environment}/${entry.key}`;
606
867
  const [error, setError] = useState(null);
607
868
  const [base, setBase] = useState(null);
608
- const shown = revealIsCurrent(reveal, entry.version) ? reveal : null;
869
+ const shown = revealIsCurrent(reveal, readVersion) ? reveal : null;
609
870
  useEffect(() => {
610
- if (reveal !== null && !revealIsCurrent(reveal, entry.version)) setReveal(null);
611
- }, [reveal, entry.version]);
871
+ if (reveal !== null && !revealIsCurrent(reveal, readVersion)) setReveal(null);
872
+ }, [reveal, readVersion]);
612
873
  useEffect(() => {
613
874
  if (reveal === null) return;
614
875
  const timer = setTimeout(() => setReveal(null), REVEAL_TTL_SECONDS * 1e3);
615
876
  return () => clearTimeout(timer);
616
877
  }, [reveal]);
617
878
  const secondsLeft = useSecondsLeft(shown);
618
- const editBase = editing && revealIsCurrent(base, entry.version) ? base : null;
879
+ const editBase = editing && revealIsCurrent(base, readVersion) ? base : null;
619
880
  useEffect(() => {
620
881
  if (!editing) setBase(null);
621
882
  }, [editing]);
622
- async function readValue() {
883
+ async function readValue({ show = true } = {}) {
623
884
  if (shown !== null) return shown.value;
624
885
  setRevealing(true);
625
886
  try {
626
887
  const { values } = await coffre.secrets.reveal(`${project}/${environment}/${entry.key}`);
627
888
  const value = values[entry.key];
628
889
  setError(null);
629
- setReveal({
890
+ if (show) setReveal({
630
891
  value,
631
- version: entry.version,
892
+ version: readVersion,
632
893
  at: Date.now()
633
894
  });
634
895
  return value;
@@ -643,6 +904,24 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
643
904
  if (shown !== null) setReveal(null);
644
905
  else readValue();
645
906
  }
907
+ const [opening, setOpening] = useState(false);
908
+ const [focusName, setFocusName] = useState(false);
909
+ async function startEdit({ name = false } = {}) {
910
+ setFocusName(name);
911
+ if (canReveal) {
912
+ setOpening(true);
913
+ const value = await readValue({ show: false });
914
+ setOpening(false);
915
+ if (value === null) return;
916
+ setBase({
917
+ value,
918
+ version: readVersion,
919
+ at: Date.now()
920
+ });
921
+ }
922
+ setReveal(null);
923
+ onEdit();
924
+ }
646
925
  const leaving = change.archived;
647
926
  const renamed = change.key !== entry.key;
648
927
  const valueChanged = change.value !== null;
@@ -664,6 +943,7 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
664
943
  className: "edit-stack",
665
944
  children: [/* @__PURE__ */ jsx("input", {
666
945
  className: "input input-mono",
946
+ autoFocus: focusName,
667
947
  "aria-label": `Name for ${entry.key}`,
668
948
  "aria-invalid": keyProblem !== null,
669
949
  spellCheck: false,
@@ -683,66 +963,127 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
683
963
  })]
684
964
  }) : /* @__PURE__ */ jsxs("div", {
685
965
  className: "key-cell",
686
- children: [/* @__PURE__ */ jsx("span", { children: breakAfterUnderscores(entry.key) }), leaving && /* @__PURE__ */ jsx("span", {
687
- className: "tag tag-red",
688
- children: "will be archived"
689
- })]
966
+ children: [
967
+ /* @__PURE__ */ jsx("span", { children: breakAfterUnderscores(entry.key) }),
968
+ leaving && /* @__PURE__ */ jsx("span", {
969
+ className: "tag tag-red",
970
+ children: "Will be archived"
971
+ }),
972
+ lent.length > 0 && /* @__PURE__ */ jsxs("button", {
973
+ type: "button",
974
+ className: "tag tag-button tag-violet",
975
+ "aria-expanded": lentOpen,
976
+ onClick: () => setLentOpen((open) => !open),
977
+ children: [
978
+ lent.length,
979
+ " ",
980
+ lent.length === 1 ? "reference" : "references"
981
+ ]
982
+ })
983
+ ]
690
984
  })
691
985
  }),
692
986
  /* @__PURE__ */ jsx("td", {
693
987
  "data-label": "Value",
694
- children: editing && canWrite ? /* @__PURE__ */ jsxs("div", {
695
- className: "edit-stack",
696
- children: [/* @__PURE__ */ jsx(ValueField, {
697
- label: `New value for ${entry.key}`,
698
- value: change.value ?? editBase?.value ?? "",
699
- placeholder: "New value",
700
- disabled,
701
- autoFocus: true,
702
- onChange: (value) => onPatch({ value: value === (editBase?.value ?? "") ? null : value }),
703
- onEscape: onUndo
704
- }), /* @__PURE__ */ jsxs("span", {
705
- className: "edit-note",
706
- children: [/* @__PURE__ */ jsx("span", { children: valueChanged ? `Saving appends v${version + 1}; v${version} stays restorable.` : editBase !== null ? `This is v${version}. Change it to append v${version + 1}.` : `Nothing is decrypted to edit. Left empty, v${version} stays current.` }), canReveal && !valueChanged && editBase === null && /* @__PURE__ */ jsxs("button", {
707
- type: "button",
708
- className: "act",
709
- disabled: revealing,
710
- onClick: async () => {
711
- const value = await readValue();
712
- if (value !== null) setBase({
713
- value,
714
- version: entry.version,
715
- at: Date.now()
716
- });
717
- },
718
- children: [revealing && /* @__PURE__ */ jsx(Spinner, { size: 12 }), "Start from current value"]
719
- })]
720
- })]
721
- }) : shown !== null && !leaving ? /* @__PURE__ */ jsxs("div", {
722
- className: "revealed",
723
- style: { ["--reveal-ttl"]: `${REVEAL_TTL_SECONDS}s` },
724
- children: [
725
- /* @__PURE__ */ jsx("span", {
726
- className: "revealed-value",
727
- children: shown.value === "" ? "(empty)" : shown.value
728
- }),
729
- /* @__PURE__ */ jsxs("span", {
730
- className: "revealed-note",
988
+ children: /* @__PURE__ */ jsxs("div", {
989
+ className: "value-cell",
990
+ children: [/* @__PURE__ */ jsx("div", {
991
+ className: "value-content",
992
+ children: editing && canWrite ? /* @__PURE__ */ jsxs("div", {
993
+ className: "edit-stack",
994
+ children: [/* @__PURE__ */ jsx(ValueField, {
995
+ label: `New value for ${entry.key}`,
996
+ value: change.value ?? editBase?.value ?? "",
997
+ start: editBase?.value,
998
+ placeholder: canReveal ? "Value" : "New value; the current one is hidden from you",
999
+ disabled,
1000
+ autoFocus: !focusName,
1001
+ onChange: (value) => onPatch({ value: value === (editBase?.value ?? "") ? null : value }),
1002
+ onEscape: onUndo
1003
+ }), reference !== null && reference.state === "live" && /* @__PURE__ */ jsxs("span", {
1004
+ className: "edit-note",
1005
+ children: ["Saving a value stops following ", /* @__PURE__ */ jsx("span", {
1006
+ className: "mono",
1007
+ children: reference.source
1008
+ })]
1009
+ })]
1010
+ }) : shown !== null && !leaving ? /* @__PURE__ */ jsxs("div", {
1011
+ className: "revealed",
1012
+ style: { ["--reveal-ttl"]: `${REVEAL_TTL_SECONDS}s` },
731
1013
  children: [
732
- "Hides in ",
733
- secondsLeft,
734
- "s"
1014
+ /* @__PURE__ */ jsx("span", {
1015
+ className: "revealed-value",
1016
+ children: shown.value === "" ? "(empty)" : shown.value
1017
+ }),
1018
+ /* @__PURE__ */ jsxs("span", {
1019
+ className: "revealed-note",
1020
+ children: [
1021
+ "Hides in ",
1022
+ secondsLeft,
1023
+ "s"
1024
+ ]
1025
+ }),
1026
+ /* @__PURE__ */ jsx("span", {
1027
+ className: "revealed-meter",
1028
+ "aria-hidden": true
1029
+ })
735
1030
  ]
736
- }),
737
- /* @__PURE__ */ jsx("span", {
738
- className: "revealed-meter",
739
- "aria-hidden": true
1031
+ }) : reference !== null ? /* @__PURE__ */ jsx(ReferenceValue, { reference }) : /* @__PURE__ */ jsx("span", {
1032
+ className: "mask",
1033
+ "aria-label": "Hidden",
1034
+ children: "••••••••••••"
740
1035
  })
741
- ]
742
- }) : /* @__PURE__ */ jsx("span", {
743
- className: "mask",
744
- "aria-label": "Hidden",
745
- children: "••••••••••••"
1036
+ }), status.state !== "pending" && /* @__PURE__ */ jsx("div", {
1037
+ className: "acts value-acts",
1038
+ children: editing || leaving ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(Tip, {
1039
+ label: leaving ? "Archive now" : "Save",
1040
+ children: /* @__PURE__ */ jsx("button", {
1041
+ className: "act act-icon act-accent",
1042
+ onClick: onSave,
1043
+ disabled: disabled || !saveReady,
1044
+ "aria-label": `${leaving ? "Archive" : "Save"} ${entry.key} now`,
1045
+ children: /* @__PURE__ */ jsx(Check, { size: 15 })
1046
+ })
1047
+ }), /* @__PURE__ */ jsx(Tip, {
1048
+ label: leaving ? "Keep" : "Cancel",
1049
+ children: /* @__PURE__ */ jsx("button", {
1050
+ className: "act act-icon act-quiet",
1051
+ onClick: onUndo,
1052
+ disabled,
1053
+ "aria-label": leaving ? `Keep ${entry.key}` : `Cancel editing ${entry.key}`,
1054
+ children: /* @__PURE__ */ jsx(X, { size: 15 })
1055
+ })
1056
+ })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
1057
+ shown !== null && /* @__PURE__ */ jsx(CopyButton, {
1058
+ variant: "act",
1059
+ value: shown.value,
1060
+ label: `Copy ${entry.key}`
1061
+ }),
1062
+ /* @__PURE__ */ jsx(SecretReadOnly, {
1063
+ canReveal,
1064
+ children: /* @__PURE__ */ jsx(Tip, {
1065
+ label: shown === null ? "Reveal" : "Hide",
1066
+ children: /* @__PURE__ */ jsx("button", {
1067
+ className: "act act-icon act-accent",
1068
+ onClick: toggleReveal,
1069
+ disabled: revealing,
1070
+ "aria-label": `${shown === null ? "Reveal" : "Hide"} ${entry.key}`,
1071
+ children: revealing && !opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : shown === null ? /* @__PURE__ */ jsx(Eye, { size: 15 }) : /* @__PURE__ */ jsx(EyeOff, { size: 15 })
1072
+ })
1073
+ })
1074
+ }),
1075
+ canWrite && /* @__PURE__ */ jsx(Tip, {
1076
+ label: "Edit",
1077
+ children: /* @__PURE__ */ jsx("button", {
1078
+ className: "act act-icon",
1079
+ onClick: () => void startEdit(),
1080
+ disabled: disabled || revealing,
1081
+ "aria-label": `Edit ${entry.key}`,
1082
+ children: opening ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : /* @__PURE__ */ jsx(Pencil, { size: 14 })
1083
+ })
1084
+ })
1085
+ ] })
1086
+ })]
746
1087
  })
747
1088
  }),
748
1089
  /* @__PURE__ */ jsx("td", {
@@ -758,104 +1099,143 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
758
1099
  ]
759
1100
  }) : /* @__PURE__ */ jsx("span", {
760
1101
  className: "version-shift",
761
- children: entry.version === null ? "—" : `v${entry.version}`
1102
+ title: reference === null ? void 0 : "The source's version",
1103
+ children: readVersion === null ? "—" : `v${readVersion}`
762
1104
  })
763
1105
  }),
764
1106
  /* @__PURE__ */ jsx("td", {
765
1107
  className: "col-written col-hide-narrow",
766
1108
  "data-label": "Last written",
767
- children: /* @__PURE__ */ jsx(Written, { entry })
1109
+ children: /* @__PURE__ */ jsx(Written, { entry: reference === null ? entry : {
1110
+ ...entry,
1111
+ updatedBy: reference.createdBy.replace(/^user:/, ""),
1112
+ updatedAt: reference.createdAt
1113
+ } })
768
1114
  }),
769
1115
  /* @__PURE__ */ jsx("td", {
770
1116
  className: "col-actions",
771
- children: status.state === "pending" ? /* @__PURE__ */ jsx(RowPending, { status }) : /* @__PURE__ */ jsx("div", {
772
- className: "acts",
773
- children: leaving ? /* @__PURE__ */ jsx(Tip, {
774
- label: "Keep",
775
- children: /* @__PURE__ */ jsx("button", {
776
- className: "act act-icon act-quiet",
777
- onClick: onUndo,
778
- disabled,
779
- "aria-label": `Keep ${entry.key}`,
780
- children: /* @__PURE__ */ jsx(RotateBack, { size: 14 })
781
- })
782
- }) : editing ? /* @__PURE__ */ jsx(Tip, {
783
- label: renamed || valueChanged ? "Undo changes" : "Cancel",
784
- children: /* @__PURE__ */ jsx("button", {
785
- className: "act act-icon act-quiet",
786
- onClick: onUndo,
787
- disabled,
788
- "aria-label": `${renamed || valueChanged ? "Undo changes to" : "Stop editing"} ${entry.key}`,
789
- children: renamed || valueChanged ? /* @__PURE__ */ jsx(RotateBack, { size: 14 }) : /* @__PURE__ */ jsx(X, { size: 15 })
790
- })
791
- }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [
792
- shown !== null && /* @__PURE__ */ jsx(CopyButton, {
793
- variant: "act",
794
- value: shown.value,
795
- label: `Copy ${entry.key}`
796
- }),
1117
+ children: status.state === "pending" ? /* @__PURE__ */ jsx(RowPending, { status }) : (canReveal || canWrite && !editing && !leaving || canArchive && !leaving) && /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, {
1118
+ className: "act act-icon act-quiet",
1119
+ "aria-label": `More for ${entry.key}`,
1120
+ disabled,
1121
+ children: /* @__PURE__ */ jsx(MoreHorizontal, { size: 16 })
1122
+ }), /* @__PURE__ */ jsxs(MenuPopup, {
1123
+ align: "end",
1124
+ children: [
797
1125
  /* @__PURE__ */ jsx(SecretReadOnly, {
798
1126
  canReveal,
799
- children: /* @__PURE__ */ jsx(Tip, {
800
- label: shown === null ? "Reveal" : "Hide",
801
- children: /* @__PURE__ */ jsx("button", {
802
- className: "act act-icon act-accent",
803
- onClick: toggleReveal,
804
- disabled: revealing,
805
- "aria-label": `${shown === null ? "Reveal" : "Hide"} ${entry.key}`,
806
- children: revealing ? /* @__PURE__ */ jsx(Spinner, { size: 13 }) : shown === null ? /* @__PURE__ */ jsx(Eye, { size: 15 }) : /* @__PURE__ */ jsx(EyeOff, { size: 15 })
807
- })
1127
+ children: /* @__PURE__ */ jsxs(Menu.Item, {
1128
+ className: "menu-item",
1129
+ onClick: () => setHistoryOpen((open) => !open),
1130
+ children: [/* @__PURE__ */ jsx(History, { size: 14 }), historyOpen ? "Hide history" : "Version history"]
808
1131
  })
809
1132
  }),
810
- canWrite && /* @__PURE__ */ jsx(Tip, {
811
- label: "Edit",
812
- children: /* @__PURE__ */ jsx("button", {
813
- className: "act act-icon",
814
- onClick: () => {
815
- if (shown !== null) setBase(shown);
816
- setReveal(null);
817
- onEdit();
818
- },
819
- disabled,
820
- "aria-label": `Edit ${entry.key}`,
821
- children: /* @__PURE__ */ jsx(Pencil, { size: 14 })
822
- })
1133
+ canWrite && !editing && !leaving && /* @__PURE__ */ jsxs(Menu.Item, {
1134
+ className: "menu-item",
1135
+ onClick: () => void startEdit({ name: true }),
1136
+ children: [/* @__PURE__ */ jsx(Pencil, { size: 14 }), "Rename"]
823
1137
  }),
824
- (canReveal || canArchive) && /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, {
825
- className: "act act-icon act-quiet",
826
- "aria-label": `More for ${entry.key}`,
827
- disabled,
828
- children: /* @__PURE__ */ jsx(MoreHorizontal, { size: 16 })
829
- }), /* @__PURE__ */ jsxs(MenuPopup, {
830
- align: "end",
831
- children: [/* @__PURE__ */ jsx(SecretReadOnly, {
832
- canReveal,
833
- children: /* @__PURE__ */ jsxs(Menu.Item, {
834
- className: "menu-item",
835
- onClick: () => setHistoryOpen((open) => !open),
836
- children: [/* @__PURE__ */ jsx(History, { size: 14 }), historyOpen ? "Hide history" : "Version history"]
1138
+ canWrite && !editing && !leaving && /* @__PURE__ */ jsxs(Menu.Item, {
1139
+ className: "menu-item",
1140
+ onClick: () => setMoving(true),
1141
+ children: [/* @__PURE__ */ jsx(Folder, { size: 14 }), "Move to folder…"]
1142
+ }),
1143
+ canWrite && !editing && !leaving && /* @__PURE__ */ jsxs(Menu.Item, {
1144
+ className: "menu-item",
1145
+ onClick: () => setReferring(true),
1146
+ children: [/* @__PURE__ */ jsx(ArrowRight, { size: 14 }), reference === null ? "Make a reference…" : "Point elsewhere…"]
1147
+ }),
1148
+ canWrite && !editing && !leaving && reference !== null && reference.state === "live" && /* @__PURE__ */ jsxs(Menu.Item, {
1149
+ className: "menu-item",
1150
+ onClick: () => setBreaking(holderPath),
1151
+ children: [/* @__PURE__ */ jsx(SlashCircle, { size: 14 }), "Break reference…"]
1152
+ }),
1153
+ canArchive && !leaving && /* @__PURE__ */ jsxs(Fragment$1, { children: [(canReveal || canWrite) && /* @__PURE__ */ jsx(Menu.Separator, { className: "menu-sep" }), /* @__PURE__ */ jsxs(Menu.Item, {
1154
+ className: "menu-item menu-item-danger",
1155
+ onClick: () => {
1156
+ setReveal(null);
1157
+ if (blockers.length > 0) setArchiveBlocked(true);
1158
+ else onMarkArchive();
1159
+ },
1160
+ children: [
1161
+ /* @__PURE__ */ jsx(Archive, { size: 14 }),
1162
+ "Archive",
1163
+ /* @__PURE__ */ jsx("span", {
1164
+ className: "menu-hint",
1165
+ children: "on save"
837
1166
  })
838
- }), canArchive && /* @__PURE__ */ jsxs(Fragment$1, { children: [canReveal && /* @__PURE__ */ jsx(Menu.Separator, { className: "menu-sep" }), /* @__PURE__ */ jsxs(Menu.Item, {
839
- className: "menu-item menu-item-danger",
840
- onClick: () => {
841
- setReveal(null);
842
- onMarkArchive();
843
- },
844
- children: [
845
- /* @__PURE__ */ jsx(Archive, { size: 14 }),
846
- "Archive",
847
- /* @__PURE__ */ jsx("span", {
848
- className: "menu-hint",
849
- children: "on save"
850
- })
851
- ]
852
- })] })]
1167
+ ]
853
1168
  })] })
854
- ] })
855
- })
1169
+ ]
1170
+ })] })
856
1171
  })
857
1172
  ]
858
1173
  }),
1174
+ canWrite && /* @__PURE__ */ jsx(MakeReference, {
1175
+ open: referring,
1176
+ onOpenChange: setReferring,
1177
+ holder: holderPath,
1178
+ environments,
1179
+ onMake: (source) => act(() => coffre.secrets.set(`${project}/${environment}`, { [entry.key]: { ref: source } }), {
1180
+ affects: affects.secrets({
1181
+ project,
1182
+ environment
1183
+ }),
1184
+ onSuccess: () => toast.success(`${entry.key} reads ${source}`)
1185
+ })
1186
+ }),
1187
+ /* @__PURE__ */ jsx(ConfirmDialog, {
1188
+ open: archiveBlocked,
1189
+ onOpenChange: setArchiveBlocked,
1190
+ title: /* @__PURE__ */ jsxs(Fragment$1, { children: [
1191
+ "Archive ",
1192
+ /* @__PURE__ */ jsx("span", {
1193
+ className: "mono",
1194
+ children: entry.key
1195
+ }),
1196
+ "?"
1197
+ ] }),
1198
+ body: `It is marked to archive when you save: ${project}/${environment} stops serving it, and its versions stay.`,
1199
+ detail: /* @__PURE__ */ jsx(ArchiveBlocked, { references: blockers }),
1200
+ confirmLabel: "Archive on save",
1201
+ confirmDisabled: blockers.length > 0,
1202
+ onConfirm: onMarkArchive
1203
+ }),
1204
+ /* @__PURE__ */ jsx(ConfirmDialog, {
1205
+ open: breaking !== null,
1206
+ onOpenChange: (open) => !open && setBreaking(null),
1207
+ title: "Break this reference?",
1208
+ body: breaking === holderPath ? `Whoever reads ${project}/${environment} stops reading ${reference?.source ?? "its source"} through ${entry.key}, and a run of ${project}/${environment} refuses until ${entry.key} gets a value.` : `Whoever reads ${breaking ?? ""}'s environment stops reading ${project}/${environment}/${entry.key} through it, and a run there refuses until it gets a value.`,
1209
+ confirmLabel: "Break",
1210
+ onConfirm: () => {
1211
+ const path = breaking;
1212
+ act(() => coffre.references.break(path), {
1213
+ affects: affects.secrets({
1214
+ project,
1215
+ environment
1216
+ }),
1217
+ onSuccess: () => toast.success(`Broke ${path}`)
1218
+ });
1219
+ }
1220
+ }),
1221
+ lentOpen && lent.length > 0 && /* @__PURE__ */ jsx("tr", {
1222
+ className: "detail-row",
1223
+ children: /* @__PURE__ */ jsx("td", {
1224
+ colSpan: columns,
1225
+ children: /* @__PURE__ */ jsx(LentReferences, {
1226
+ references: lent,
1227
+ onBreak: (each) => setBreaking(each.holder)
1228
+ })
1229
+ })
1230
+ }),
1231
+ canWrite && /* @__PURE__ */ jsx(MoveToFolder, {
1232
+ open: moving,
1233
+ onOpenChange: setMoving,
1234
+ what: entry.key,
1235
+ current: entry.folder,
1236
+ folders,
1237
+ onMove
1238
+ }),
859
1239
  historyOpen && canReveal && /* @__PURE__ */ jsx("tr", {
860
1240
  className: "detail-row",
861
1241
  children: /* @__PURE__ */ jsx("td", {
@@ -871,11 +1251,11 @@ function SecretRow({ number, project, environment, entry, change, editing, canWr
871
1251
  })
872
1252
  })
873
1253
  }),
874
- error !== null && /* @__PURE__ */ jsx("tr", {
1254
+ (error ?? actError) !== null && /* @__PURE__ */ jsx("tr", {
875
1255
  className: "row-error",
876
1256
  children: /* @__PURE__ */ jsx("td", {
877
1257
  colSpan: columns,
878
- children: /* @__PURE__ */ jsx(ErrorLine, { error })
1258
+ children: /* @__PURE__ */ jsx(ErrorLine, { error: error ?? actError })
879
1259
  })
880
1260
  })
881
1261
  ] });
@@ -917,7 +1297,7 @@ function Written({ entry }) {
917
1297
  * from the list to add to it, and only ever accepted one key at a time; a row
918
1298
  * in place accepts as many as you want to queue.
919
1299
  */
920
- function DraftRow({ draft, existingVersion, disabled, onChange, onRemove }) {
1300
+ function DraftRow({ draft, existingVersion, disabled, onChange, onRemove, onSave, saveReady }) {
921
1301
  const [touched, setTouched] = useState(false);
922
1302
  const trimmed = draft.key.trim();
923
1303
  const keyProblem = trimmed === "" ? touched ? "Give it a name." : null : secretKeyProblem(trimmed);
@@ -958,16 +1338,43 @@ function DraftRow({ draft, existingVersion, disabled, onChange, onRemove }) {
958
1338
  }),
959
1339
  /* @__PURE__ */ jsx("td", {
960
1340
  "data-label": "Value",
961
- children: /* @__PURE__ */ jsx("div", {
962
- className: "edit-stack",
963
- children: /* @__PURE__ */ jsx(ValueField, {
964
- label: `Value for ${trimmed === "" ? "the new secret" : trimmed}`,
965
- value: draft.value,
966
- placeholder: "Value",
967
- disabled,
968
- onChange: (value) => onChange({ value }),
969
- onEscape: onRemove
970
- })
1341
+ children: /* @__PURE__ */ jsxs("div", {
1342
+ className: "value-cell",
1343
+ children: [/* @__PURE__ */ jsx("div", {
1344
+ className: "value-content",
1345
+ children: /* @__PURE__ */ jsx("div", {
1346
+ className: "edit-stack",
1347
+ children: /* @__PURE__ */ jsx(ValueField, {
1348
+ label: `Value for ${trimmed === "" ? "the new secret" : trimmed}`,
1349
+ value: draft.value,
1350
+ placeholder: "Value",
1351
+ disabled,
1352
+ onChange: (value) => onChange({ value }),
1353
+ onEscape: onRemove
1354
+ })
1355
+ })
1356
+ }), /* @__PURE__ */ jsxs("div", {
1357
+ className: "acts value-acts",
1358
+ children: [/* @__PURE__ */ jsx(Tip, {
1359
+ label: "Save",
1360
+ children: /* @__PURE__ */ jsx("button", {
1361
+ className: "act act-icon act-accent",
1362
+ onClick: onSave,
1363
+ disabled: disabled || !saveReady,
1364
+ "aria-label": trimmed === "" ? "Save this new secret now" : `Save ${trimmed} now`,
1365
+ children: /* @__PURE__ */ jsx(Check, { size: 15 })
1366
+ })
1367
+ }), /* @__PURE__ */ jsx(Tip, {
1368
+ label: "Cancel",
1369
+ children: /* @__PURE__ */ jsx("button", {
1370
+ className: "act act-icon act-quiet",
1371
+ onClick: onRemove,
1372
+ disabled,
1373
+ "aria-label": trimmed === "" ? "Remove this new secret" : `Remove new secret ${trimmed}`,
1374
+ children: /* @__PURE__ */ jsx(X, { size: 15 })
1375
+ })
1376
+ })]
1377
+ })]
971
1378
  })
972
1379
  }),
973
1380
  /* @__PURE__ */ jsx("td", {
@@ -990,22 +1397,7 @@ function DraftRow({ draft, existingVersion, disabled, onChange, onRemove }) {
990
1397
  children: "—"
991
1398
  })
992
1399
  }),
993
- /* @__PURE__ */ jsx("td", {
994
- className: "col-actions",
995
- children: /* @__PURE__ */ jsx("div", {
996
- className: "acts",
997
- children: /* @__PURE__ */ jsx(Tip, {
998
- label: "Remove",
999
- children: /* @__PURE__ */ jsx("button", {
1000
- className: "act act-icon act-quiet",
1001
- onClick: onRemove,
1002
- disabled,
1003
- "aria-label": trimmed === "" ? "Remove this new secret" : `Remove new secret ${trimmed}`,
1004
- children: /* @__PURE__ */ jsx(X, { size: 15 })
1005
- })
1006
- })
1007
- })
1008
- })
1400
+ /* @__PURE__ */ jsx("td", { className: "col-actions" })
1009
1401
  ]
1010
1402
  });
1011
1403
  }
@@ -1039,29 +1431,27 @@ function ArchivedRow({ number, project, environment, entry, canArchive, canRevea
1039
1431
  }),
1040
1432
  /* @__PURE__ */ jsx("td", {
1041
1433
  className: "col-actions",
1042
- children: /* @__PURE__ */ jsxs("div", {
1434
+ children: state.state === "pending" ? /* @__PURE__ */ jsx(RowPending, { status: state }) : (canReveal || canArchive) && /* @__PURE__ */ jsx("div", {
1043
1435
  className: "acts",
1044
- children: [/* @__PURE__ */ jsx(SecretReadOnly, {
1045
- canReveal,
1046
- children: /* @__PURE__ */ jsx(Tip, {
1047
- label: historyOpen ? "Hide history" : "Version history",
1048
- children: /* @__PURE__ */ jsx("button", {
1049
- className: "act act-icon act-quiet",
1436
+ children: /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsx(Menu.Trigger, {
1437
+ className: "act act-icon act-quiet",
1438
+ "aria-label": `More for ${entry.key}`,
1439
+ children: /* @__PURE__ */ jsx(MoreHorizontal, { size: 16 })
1440
+ }), /* @__PURE__ */ jsxs(MenuPopup, {
1441
+ align: "end",
1442
+ children: [/* @__PURE__ */ jsx(SecretReadOnly, {
1443
+ canReveal,
1444
+ children: /* @__PURE__ */ jsxs(Menu.Item, {
1445
+ className: "menu-item",
1050
1446
  onClick: () => setHistoryOpen((open) => !open),
1051
- "aria-label": `${historyOpen ? "Hide history of" : "Version history of"} ${entry.key}`,
1052
- "aria-expanded": historyOpen,
1053
- children: /* @__PURE__ */ jsx(History, { size: 15 })
1447
+ children: [/* @__PURE__ */ jsx(History, { size: 14 }), historyOpen ? "Hide history" : "Version history"]
1054
1448
  })
1055
- })
1056
- }), canArchive && (state.state === "pending" ? /* @__PURE__ */ jsx(RowPending, { status: state }) : /* @__PURE__ */ jsx(Tip, {
1057
- label: "Restore",
1058
- children: /* @__PURE__ */ jsx("button", {
1059
- className: "act act-icon",
1449
+ }), canArchive && /* @__PURE__ */ jsxs(Fragment$1, { children: [canReveal && /* @__PURE__ */ jsx(Menu.Separator, { className: "menu-sep" }), /* @__PURE__ */ jsxs(Menu.Item, {
1450
+ className: "menu-item",
1060
1451
  onClick: onRestore,
1061
- "aria-label": `Restore ${entry.key}`,
1062
- children: /* @__PURE__ */ jsx(RotateBack, { size: 14 })
1063
- })
1064
- }))]
1452
+ children: [/* @__PURE__ */ jsx(RotateBack, { size: 14 }), "Restore"]
1453
+ })] })]
1454
+ })] })
1065
1455
  })
1066
1456
  })
1067
1457
  ]
@@ -1174,7 +1564,7 @@ function VersionHistory({ project, environment, secretKey, currentVersion, canWr
1174
1564
  " ",
1175
1565
  version.current && /* @__PURE__ */ jsx("span", {
1176
1566
  className: "tag tag-blue",
1177
- children: "current"
1567
+ children: "Current"
1178
1568
  })
1179
1569
  ]
1180
1570
  }),