@coffre/ui 0.0.0-stage → 0.1.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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/dist/client/.assetsignore +2 -0
  4. package/dist/client/_coffre/assets/account-C3Zo1l5A.js +1 -0
  5. package/dist/client/_coffre/assets/account-C4bNbeO7.js +2 -0
  6. package/dist/client/_coffre/assets/affordances-DiuJIiR2.js +1 -0
  7. package/dist/client/_coffre/assets/audit-1xLyuxGz.js +2 -0
  8. package/dist/client/_coffre/assets/audit-Dab2GuRj.js +1 -0
  9. package/dist/client/_coffre/assets/auth.device-BfCfeBWe.js +2 -0
  10. package/dist/client/_coffre/assets/auth.device-D2pCLF-X.js +1 -0
  11. package/dist/client/_coffre/assets/coffre-C7qL3HGR.js +1 -0
  12. package/dist/client/_coffre/assets/directory-C2Ou4SQv.js +1 -0
  13. package/dist/client/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
  14. package/dist/client/_coffre/assets/grants-fqTtJ-aW.js +1 -0
  15. package/dist/client/_coffre/assets/index-BpGwbjmM.js +12 -0
  16. package/dist/client/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  17. package/dist/client/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  18. package/dist/client/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  19. package/dist/client/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  20. package/dist/client/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  21. package/dist/client/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  22. package/dist/client/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  23. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  24. package/dist/client/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  25. package/dist/client/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  26. package/dist/client/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  27. package/dist/client/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  28. package/dist/client/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  29. package/dist/client/_coffre/assets/login-CR9CBXlw.js +2 -0
  30. package/dist/client/_coffre/assets/login-DZizFxa4.js +1 -0
  31. package/dist/client/_coffre/assets/offboarding-DOLJQcXU.js +1 -0
  32. package/dist/client/_coffre/assets/page-BxW2MwaX.js +1 -0
  33. package/dist/client/_coffre/assets/preload-helper-BHuP8_FL.js +46 -0
  34. package/dist/client/_coffre/assets/principal-page-xnBZVURr.js +1 -0
  35. package/dist/client/_coffre/assets/project-environments-CfIH5kFM.js +1 -0
  36. package/dist/client/_coffre/assets/projects._project._environment-CrWjQmIA.js +2 -0
  37. package/dist/client/_coffre/assets/projects._project._environment-CwRVG9Ne.js +3 -0
  38. package/dist/client/_coffre/assets/projects._project.index-CCDEuE-z.js +2 -0
  39. package/dist/client/_coffre/assets/projects._project.index-DCJsmnD7.js +1 -0
  40. package/dist/client/_coffre/assets/projects.index-B8eV8JIn.js +1 -0
  41. package/dist/client/_coffre/assets/projects.index-BNEC7Oz8.js +2 -0
  42. package/dist/client/_coffre/assets/settings-2BPsenNM.js +2 -0
  43. package/dist/client/_coffre/assets/settings-BrS0-wEt.js +1 -0
  44. package/dist/client/_coffre/assets/signin-errors-CroZWZgm.js +1 -0
  45. package/dist/client/_coffre/assets/tokens._token-B3-YwuKp.js +2 -0
  46. package/dist/client/_coffre/assets/tokens._token-D_hsbHx6.js +1 -0
  47. package/dist/client/_coffre/assets/tokens.index-BdKE2Jv8.js +2 -0
  48. package/dist/client/_coffre/assets/tokens.index-XvA4XRxh.js +1 -0
  49. package/dist/client/_coffre/assets/unregistered-CTRMtBIy.js +1 -0
  50. package/dist/client/_coffre/assets/use-action-DgAf-tiX.js +1 -0
  51. package/dist/client/_coffre/assets/users._user-BFPXcJ4y.js +2 -0
  52. package/dist/client/_coffre/assets/users._user-DEtMeSoh.js +1 -0
  53. package/dist/client/_coffre/assets/users.index-B03beUHq.js +1 -0
  54. package/dist/client/_coffre/assets/users.index-D8hwzM6P.js +2 -0
  55. package/dist/client/_coffre/assets/validation-9Cl_XS-l.js +1 -0
  56. package/dist/index.d.ts +19 -0
  57. package/dist/server/.vite/manifest.json +572 -0
  58. package/dist/server/_coffre/assets/_tanstack-start-manifest_v-B6CZDfrB.js +133 -0
  59. package/dist/server/_coffre/assets/account-B71_b5xc.js +296 -0
  60. package/dist/server/_coffre/assets/account-BoO6ZqMc.js +176 -0
  61. package/dist/server/_coffre/assets/affordances-BNaXjMOb.js +46 -0
  62. package/dist/server/_coffre/assets/async-local-storage-C0cwgkEr.js +3107 -0
  63. package/dist/server/_coffre/assets/audit-CwRFnSAY.js +74 -0
  64. package/dist/server/_coffre/assets/audit-t1sYjtrf.js +964 -0
  65. package/dist/server/_coffre/assets/auth.device-1IcJ475s.js +208 -0
  66. package/dist/server/_coffre/assets/auth.device-CJwZYYtn.js +29 -0
  67. package/dist/server/_coffre/assets/coffre-1hxT2E_U.js +278 -0
  68. package/dist/server/_coffre/assets/directory-wm_JQUfk.js +396 -0
  69. package/dist/server/_coffre/assets/empty-plugin-adapters-Cq4--YW-.js +5 -0
  70. package/dist/server/_coffre/assets/globals-Dgq4Jy0x.css +1 -0
  71. package/dist/server/_coffre/assets/grants-BmhEY1vz.js +243 -0
  72. package/dist/server/_coffre/assets/inter-cyrillic-ext-opsz-normal-CfYZpDVp.woff2 +0 -0
  73. package/dist/server/_coffre/assets/inter-cyrillic-opsz-normal-BFQXbQ-f.woff2 +0 -0
  74. package/dist/server/_coffre/assets/inter-greek-ext-opsz-normal-BmPQvyvo.woff2 +0 -0
  75. package/dist/server/_coffre/assets/inter-greek-opsz-normal-BM0NlUE_.woff2 +0 -0
  76. package/dist/server/_coffre/assets/inter-latin-ext-opsz-normal-DpK-iCPk.woff2 +0 -0
  77. package/dist/server/_coffre/assets/inter-latin-opsz-normal-BwkfbSeq.woff2 +0 -0
  78. package/dist/server/_coffre/assets/inter-vietnamese-opsz-normal-Ci9T9ieq.woff2 +0 -0
  79. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-ext-wght-normal-EocZY2iu.woff2 +0 -0
  80. package/dist/server/_coffre/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  81. package/dist/server/_coffre/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  82. package/dist/server/_coffre/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  83. package/dist/server/_coffre/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  84. package/dist/server/_coffre/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  85. package/dist/server/_coffre/assets/login-B5O5LPXV.js +100 -0
  86. package/dist/server/_coffre/assets/login-Bvc4gp0X.js +22 -0
  87. package/dist/server/_coffre/assets/offboarding-CvSilnSm.js +330 -0
  88. package/dist/server/_coffre/assets/page-BjXk0Ehu.js +2003 -0
  89. package/dist/server/_coffre/assets/principal-page-DkwNGzM2.js +617 -0
  90. package/dist/server/_coffre/assets/project-environments-lEzFHUt4.js +9 -0
  91. package/dist/server/_coffre/assets/projects._project._environment-7grhqlgq.js +2227 -0
  92. package/dist/server/_coffre/assets/projects._project._environment-ByEf6pmz.js +55 -0
  93. package/dist/server/_coffre/assets/projects._project.index-B1bjowP-.js +932 -0
  94. package/dist/server/_coffre/assets/projects._project.index-DU8wtoHD.js +22 -0
  95. package/dist/server/_coffre/assets/projects.index-B0DoHbCz.js +280 -0
  96. package/dist/server/_coffre/assets/projects.index-kMDA6pMy.js +54 -0
  97. package/dist/server/_coffre/assets/react-dom-qCTiwGGR.js +1352 -0
  98. package/dist/server/_coffre/assets/router-ChU_CwCX.js +2028 -0
  99. package/dist/server/_coffre/assets/settings-CM9-h7in.js +18 -0
  100. package/dist/server/_coffre/assets/settings-Cg5qOGij.js +60 -0
  101. package/dist/server/_coffre/assets/signin-errors-BEFlVDbQ.js +28 -0
  102. package/dist/server/_coffre/assets/start-DR3rN0St.js +4 -0
  103. package/dist/server/_coffre/assets/tokens._token-CCpaPMAk.js +268 -0
  104. package/dist/server/_coffre/assets/tokens._token-Di4OZdAA.js +18 -0
  105. package/dist/server/_coffre/assets/tokens.index-Do3OHR31.js +34 -0
  106. package/dist/server/_coffre/assets/tokens.index-tDKq4AFh.js +10 -0
  107. package/dist/server/_coffre/assets/ui-BNzhIAQP.js +15710 -0
  108. package/dist/server/_coffre/assets/unregistered-BqaWYFJK.js +51 -0
  109. package/dist/server/_coffre/assets/use-action-BkJXC5JM.js +953 -0
  110. package/dist/server/_coffre/assets/useStore-DWGPqzXR.js +892 -0
  111. package/dist/server/_coffre/assets/users._user-BenYva93.js +15 -0
  112. package/dist/server/_coffre/assets/users._user-Cp039Va-.js +10 -0
  113. package/dist/server/_coffre/assets/users.index-BrzG1Ecq.js +10 -0
  114. package/dist/server/_coffre/assets/users.index-DQ_45DQl.js +34 -0
  115. package/dist/server/_coffre/assets/validation-BQtqPe2V.js +27 -0
  116. package/dist/server/index.js +13910 -0
  117. package/package.json +58 -3
  118. package/src/components/affordances.ts +80 -0
  119. package/src/components/agentation.tsx +34 -0
  120. package/src/components/command-palette.tsx +271 -0
  121. package/src/components/directory.tsx +448 -0
  122. package/src/components/grants.tsx +204 -0
  123. package/src/components/icons.tsx +283 -0
  124. package/src/components/offboarding.tsx +286 -0
  125. package/src/components/page.tsx +128 -0
  126. package/src/components/principal-page.tsx +549 -0
  127. package/src/components/principal-picker.tsx +168 -0
  128. package/src/components/principal.tsx +53 -0
  129. package/src/components/route-states.tsx +60 -0
  130. package/src/components/service-tokens.tsx +212 -0
  131. package/src/components/shell.tsx +641 -0
  132. package/src/components/syncs.tsx +581 -0
  133. package/src/components/theme.tsx +141 -0
  134. package/src/components/tile.tsx +22 -0
  135. package/src/components/ui.tsx +440 -0
  136. package/src/entry.ts +19 -0
  137. package/src/lib/access-plan.ts +201 -0
  138. package/src/lib/audit-sentences.ts +468 -0
  139. package/src/lib/capabilities.ts +45 -0
  140. package/src/lib/coffre.ts +57 -0
  141. package/src/lib/project-access.ts +95 -0
  142. package/src/lib/project-environments.ts +23 -0
  143. package/src/lib/reveal.ts +21 -0
  144. package/src/lib/secret-edit-batch.ts +181 -0
  145. package/src/lib/signin-errors.ts +33 -0
  146. package/src/lib/use-action.ts +50 -0
  147. package/src/lib/validation.ts +27 -0
  148. package/src/routeTree.gen.ts +367 -0
  149. package/src/router.tsx +84 -0
  150. package/src/routes/__root.tsx +192 -0
  151. package/src/routes/access.tsx +11 -0
  152. package/src/routes/account.tsx +359 -0
  153. package/src/routes/audit.tsx +545 -0
  154. package/src/routes/auth.device.tsx +200 -0
  155. package/src/routes/index.tsx +15 -0
  156. package/src/routes/login.tsx +129 -0
  157. package/src/routes/projects.$project.$environment.tsx +1659 -0
  158. package/src/routes/projects.$project.index.tsx +917 -0
  159. package/src/routes/projects.index.tsx +353 -0
  160. package/src/routes/settings.tsx +72 -0
  161. package/src/routes/tokens.$token.tsx +35 -0
  162. package/src/routes/tokens.index.tsx +37 -0
  163. package/src/routes/unregistered.tsx +59 -0
  164. package/src/routes/users.$user.tsx +13 -0
  165. package/src/routes/users.index.tsx +37 -0
  166. package/src/shared/models.ts +55 -0
  167. package/src/styles/globals.css +4118 -0
  168. package/src/types.ts +21 -0
@@ -0,0 +1,932 @@
1
+ import { C as require_react, E as __toESM, i as useRouter, o as require_jsx_runtime } from "./useStore-DWGPqzXR.js";
2
+ import { E as Link, a as ErrorLine, c as Spinner, h as dropdown_menu_exports, i as EmptyState, n as ConfirmDialog, o as Modal, s as Notice } from "./ui-BNzhIAQP.js";
3
+ import { $ as Users, B as RotateBack, C as Key, H as Settings, I as Pencil, N as MoreHorizontal, R as Plus, V as Search, Z as User, i as PageHeader, l as Archive, n as ClosedDoor, t as Card, tt as useLoaderData, u as Check, v as Folder, w as Layers } from "./page-BjXk0Ehu.js";
4
+ import { s as useCoffre, t as Refusal } from "./coffre-1hxT2E_U.js";
5
+ import { r as toast, t as useAction } from "./use-action-BkJXC5JM.js";
6
+ import { t as hasEnvironmentDetails } from "./project-environments-lEzFHUt4.js";
7
+ import { c as PrincipalLink, i as KIND, o as loadDirectory, s as PrincipalAvatar } from "./directory-wm_JQUfk.js";
8
+ import { a as parseProjectAccess, n as GrantsTable, o as projectAccessLabel, r as ensureGrant, s as projectAccessOptions, t as GrantRowView } from "./grants-BmhEY1vz.js";
9
+ import { t as Route } from "./projects._project.index-DU8wtoHD.js";
10
+ import { n as slugProblem } from "./validation-BQtqPe2V.js";
11
+ //#region src/components/principal-picker.tsx
12
+ var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
13
+ var import_jsx_runtime = require_jsx_runtime();
14
+ /**
15
+ * Who a grant is for: picked from the registered users or tokens, each shown
16
+ * with what it already holds on this project, or typed when the list is not
17
+ * yours to read.
18
+ *
19
+ * Only instance owners may list the directory. Asking on anyone else's behalf
20
+ * would write a refusal to the audit log in their name, so they get a text
21
+ * field and the server's answer instead. The list is asked for when the
22
+ * dialog opens rather than with the page, since most visits never open it.
23
+ */
24
+ function PrincipalPicker({ principalType, canList, grants, value, onChange }) {
25
+ const coffre = useCoffre();
26
+ const [directory, setDirectory] = (0, import_react.useState)(null);
27
+ const [query, setQuery] = (0, import_react.useState)("");
28
+ const name = (0, import_react.useId)();
29
+ const kind = KIND[principalType];
30
+ const label = principalType === "user" ? "User" : "Token";
31
+ (0, import_react.useEffect)(() => {
32
+ if (!canList) return;
33
+ let live = true;
34
+ loadDirectory(coffre, true).then((result) => {
35
+ if (live) setDirectory(result);
36
+ });
37
+ return () => {
38
+ live = false;
39
+ };
40
+ }, [canList, coffre]);
41
+ if (!canList || directory?.ok === false) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
42
+ className: "field",
43
+ children: [
44
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
45
+ className: "label",
46
+ children: principalType === "user" ? "Email" : "Service token common name"
47
+ }),
48
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
49
+ className: "input input-mono",
50
+ autoFocus: true,
51
+ spellCheck: false,
52
+ autoComplete: "off",
53
+ placeholder: principalType === "user" ? "someone@acme.example" : "ci-deploy",
54
+ value,
55
+ onChange: (event) => onChange(event.target.value)
56
+ }),
57
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
58
+ className: "hint",
59
+ children: [
60
+ "The ",
61
+ kind,
62
+ " must already be registered under ",
63
+ principalType === "user" ? "Users" : "Tokens",
64
+ "."
65
+ ]
66
+ })
67
+ ]
68
+ });
69
+ const registered = directory?.principals.filter((principal) => principal.principalType === principalType) ?? [];
70
+ const needle = query.trim().toLowerCase();
71
+ const matches = registered.filter((principal) => principal.principalId.toLowerCase().includes(needle));
72
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", {
73
+ className: "field picker",
74
+ children: [
75
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", {
76
+ className: "label",
77
+ children: label
78
+ }),
79
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
80
+ className: "input-group",
81
+ children: [
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
83
+ className: "visually-hidden",
84
+ children: [
85
+ "Filter ",
86
+ kind,
87
+ "s by name"
88
+ ]
89
+ }),
90
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Search, {
91
+ size: 14,
92
+ className: "input-icon"
93
+ }),
94
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
95
+ className: "input",
96
+ type: "search",
97
+ autoFocus: true,
98
+ spellCheck: false,
99
+ autoComplete: "off",
100
+ placeholder: principalType === "user" ? "Filter by email…" : "Filter by name…",
101
+ value: query,
102
+ onChange: (event) => setQuery(event.target.value),
103
+ onKeyDown: (event) => {
104
+ if (event.key === "Enter" && matches.length === 1) {
105
+ event.preventDefault();
106
+ onChange(matches[0].principalId);
107
+ }
108
+ }
109
+ })
110
+ ]
111
+ }),
112
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
113
+ className: "picker-list",
114
+ children: directory === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
115
+ className: "picker-empty",
116
+ children: [
117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 13 }),
118
+ "Loading ",
119
+ kind,
120
+ "s…"
121
+ ]
122
+ }) : registered.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
123
+ className: "picker-empty",
124
+ children: [
125
+ "No ",
126
+ kind,
127
+ "s are registered yet.",
128
+ " ",
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
130
+ to: principalType === "user" ? "/users" : "/tokens",
131
+ children: "Add one"
132
+ }),
133
+ " first."
134
+ ]
135
+ }) : matches.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
136
+ className: "picker-empty",
137
+ children: [
138
+ "No registered ",
139
+ kind,
140
+ " matches “",
141
+ query.trim(),
142
+ "”."
143
+ ]
144
+ }) : matches.map((principal) => {
145
+ const held = grants.filter((grant) => grant.principalType === principalType && grant.principalId === principal.principalId).map(projectAccessLabel);
146
+ const chosen = principal.principalId === value;
147
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
148
+ className: `picker-option${chosen ? " is-chosen" : ""}`,
149
+ children: [
150
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
151
+ type: "radio",
152
+ className: "visually-hidden",
153
+ name,
154
+ value: principal.principalId,
155
+ checked: chosen,
156
+ onChange: () => onChange(principal.principalId)
157
+ }),
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrincipalAvatar, {
159
+ type: principalType,
160
+ id: principal.principalId
161
+ }),
162
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
163
+ className: "picker-name",
164
+ children: principal.principalId
165
+ }),
166
+ held.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
167
+ className: "picker-held",
168
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
169
+ className: "visually-hidden",
170
+ children: "holds"
171
+ }), held.map((access) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
172
+ className: "tag",
173
+ children: access
174
+ }, access))]
175
+ }),
176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, {
177
+ size: 14,
178
+ className: "picker-check"
179
+ })
180
+ ]
181
+ }, principal.principalId);
182
+ })
183
+ })
184
+ ]
185
+ });
186
+ }
187
+ //#endregion
188
+ //#region src/routes/projects.$project.index.tsx?tsr-split=component
189
+ var TABS = [
190
+ {
191
+ key: "environments",
192
+ label: "Environments",
193
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Layers, { size: 15 })
194
+ },
195
+ {
196
+ key: "users",
197
+ label: "Users",
198
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Users, { size: 15 })
199
+ },
200
+ {
201
+ key: "tokens",
202
+ label: "Tokens",
203
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Key, { size: 15 })
204
+ },
205
+ {
206
+ key: "settings",
207
+ label: "Settings",
208
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Settings, { size: 15 })
209
+ }
210
+ ];
211
+ function ProjectPage() {
212
+ const result = Route.useLoaderData();
213
+ const { project: projectSlug } = Route.useParams();
214
+ const search = Route.useSearch();
215
+ if (!result.ok) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClosedDoor, {
216
+ icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Folder, { size: 18 }),
217
+ label: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
218
+ className: "mono",
219
+ children: projectSlug
220
+ }),
221
+ title: "No project here for you",
222
+ actions: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
223
+ className: "btn",
224
+ to: "/projects",
225
+ children: "All projects"
226
+ }),
227
+ children: result.error ?? "There is no such project, or you hold no grant on it. The two look the same on purpose: an answer that told them apart would let anyone list project names."
228
+ });
229
+ const { project, grants, grantsError } = result;
230
+ const canManageProject = project.permissions.includes("project.manage");
231
+ const canManageEnvironments = project.permissions.includes("environment.manage");
232
+ const canManageGrants = project.permissions.includes("grant.manage");
233
+ const allowed = TABS.filter(({ key }) => key === "environments" || (key === "users" || key === "tokens") && canManageGrants || key === "settings" && canManageProject);
234
+ const tab = allowed.find(({ key }) => key === search.tab)?.key ?? "environments";
235
+ const principalType = tab === "users" ? "user" : "service";
236
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
237
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageHeader, {
238
+ tile: project.slug,
239
+ title: project.name,
240
+ aside: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
241
+ className: "page-title-slug",
242
+ children: project.slug
243
+ }),
244
+ actions: tab === "environments" ? canManageEnvironments && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NewEnvironment, { project: project.slug }) : (tab === "users" || tab === "tokens") && grantsError === null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(NewGrant, {
245
+ principalType,
246
+ project: project.slug,
247
+ environments: project.environments,
248
+ grants
249
+ })
250
+ }),
251
+ project.archivedAt !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
252
+ style: { marginBottom: "1.25rem" },
253
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Notice, {
254
+ tone: "bad",
255
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "This project is archived." }), " Its environments serve no reads, to people or to machines, until it is restored."]
256
+ })
257
+ }),
258
+ allowed.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", {
259
+ className: "tabs",
260
+ "aria-label": "Project sections",
261
+ children: allowed.map(({ key, label, icon }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
262
+ to: "/projects/$project",
263
+ params: { project: project.slug },
264
+ search: { tab: key === "environments" ? void 0 : key },
265
+ activeOptions: {
266
+ exact: true,
267
+ explicitUndefined: true
268
+ },
269
+ "aria-current": key === tab ? "page" : void 0,
270
+ children: [icon, label]
271
+ }, key))
272
+ }),
273
+ tab === "environments" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnvironmentsPanel, {
274
+ project,
275
+ canManage: canManageEnvironments
276
+ }),
277
+ (tab === "users" || tab === "tokens") && (grantsError !== null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Notice, {
278
+ tone: "bad",
279
+ children: grantsError
280
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AccessPanel, {
281
+ principalType,
282
+ project: project.slug,
283
+ grants: grants.filter((grant) => grant.principalType === principalType)
284
+ })),
285
+ tab === "settings" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(GeneralSettings, { project }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DangerZone, { project })] })
286
+ ] });
287
+ }
288
+ function EnvironmentsPanel({ project, canManage }) {
289
+ const archived = project.environments.filter(hasEnvironmentDetails).filter((environment) => environment.details.archivedAt !== null);
290
+ const current = project.environments.filter((environment) => environment.details === null || environment.details.archivedAt === null);
291
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [current.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
292
+ className: "card",
293
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyState, {
294
+ title: "No environments yet",
295
+ children: canManage ? "Add the first with Add environment." : "Creating environments needs environment.manage on this project."
296
+ })
297
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
298
+ className: "env-grid",
299
+ "aria-label": "Environments",
300
+ children: current.map((environment) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnvironmentCard, {
301
+ project: project.slug,
302
+ environment,
303
+ isAdmin: canManage
304
+ }) }, `${project.slug}:${environment.slug}`))
305
+ }), archived.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
306
+ "aria-labelledby": "archived-environments",
307
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
308
+ className: "section-title",
309
+ id: "archived-environments",
310
+ children: "Archived"
311
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
312
+ className: "env-grid",
313
+ children: archived.map((environment) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EnvironmentCard, {
314
+ project: project.slug,
315
+ environment,
316
+ isAdmin: canManage
317
+ }) }, environment.slug))
318
+ })]
319
+ })] });
320
+ }
321
+ /**
322
+ * One environment. The whole card opens it when you can; its menu sits above
323
+ * that link.
324
+ */
325
+ function EnvironmentCard({ project, environment, isAdmin }) {
326
+ const [renaming, setRenaming] = (0, import_react.useState)(false);
327
+ const [confirming, setConfirming] = (0, import_react.useState)(false);
328
+ const [slug, setSlug] = (0, import_react.useState)(environment.slug);
329
+ const [name, setName] = (0, import_react.useState)(environment.name);
330
+ const coffre = useCoffre();
331
+ const { pending, error, setError, run } = useAction();
332
+ const details = environment.details;
333
+ const isArchived = details !== null && details.archivedAt !== null;
334
+ const secretCount = details?.secretCount ?? null;
335
+ const opens = details !== null && !isArchived && environment.accessible;
336
+ const manageable = isAdmin && details !== null;
337
+ const slugError = slug === "" ? null : slugProblem(slug);
338
+ (0, import_react.useEffect)(() => {
339
+ if (error !== null && !renaming) toast.error(error);
340
+ }, [error, renaming]);
341
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
342
+ className: `env-card${opens ? " is-link" : " is-muted"}`,
343
+ children: [
344
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
345
+ className: "env-card-text",
346
+ children: [opens ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
347
+ className: "env-card-name stretch",
348
+ to: "/projects/$project/$environment",
349
+ params: {
350
+ project,
351
+ environment: environment.slug
352
+ },
353
+ children: environment.name
354
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
355
+ className: "env-card-name",
356
+ children: environment.name
357
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
358
+ className: "env-card-meta",
359
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
360
+ className: "mono",
361
+ children: environment.slug
362
+ }), isArchived ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
363
+ className: "tag tag-red",
364
+ children: "archived"
365
+ }) : !environment.accessible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
366
+ className: "tag tag-outline",
367
+ children: "no secret access"
368
+ }) : secretCount !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
369
+ secretCount,
370
+ " secret",
371
+ secretCount === 1 ? "" : "s"
372
+ ] })]
373
+ })]
374
+ }),
375
+ manageable && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Root, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Trigger, {
376
+ asChild: true,
377
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
378
+ className: "act act-quiet env-card-menu",
379
+ "aria-label": `Actions for ${environment.slug}`,
380
+ disabled: pending,
381
+ children: pending ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoreHorizontal, { size: 16 })
382
+ })
383
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Content, {
384
+ className: "menu",
385
+ sideOffset: 6,
386
+ align: "end",
387
+ children: [
388
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
389
+ className: "menu-item",
390
+ onSelect: () => {
391
+ setSlug(environment.slug);
392
+ setName(environment.name);
393
+ setRenaming(true);
394
+ },
395
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Pencil, { size: 14 }), "Rename"]
396
+ }),
397
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(dropdown_menu_exports.Separator, { className: "menu-sep" }),
398
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(dropdown_menu_exports.Item, {
399
+ className: `menu-item${isArchived ? "" : " menu-item-danger"}`,
400
+ onSelect: () => setConfirming(true),
401
+ children: [isArchived ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Archive, { size: 14 }), isArchived ? "Restore" : "Archive…"]
402
+ })
403
+ ]
404
+ }) })] }),
405
+ manageable && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Modal, {
406
+ open: renaming,
407
+ onOpenChange: (open) => {
408
+ setRenaming(open);
409
+ if (!open) setError(null);
410
+ },
411
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
412
+ "Rename",
413
+ " ",
414
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
415
+ className: "mono",
416
+ children: [
417
+ project,
418
+ "/",
419
+ environment.slug
420
+ ]
421
+ })
422
+ ] }),
423
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
424
+ className: "form",
425
+ onSubmit: (event) => {
426
+ event.preventDefault();
427
+ run(() => coffre.environments.update(`${project}/${environment.slug}`, {
428
+ slug,
429
+ name
430
+ }), () => {
431
+ setRenaming(false);
432
+ toast.success("Environment renamed");
433
+ });
434
+ },
435
+ children: [
436
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
437
+ className: "field",
438
+ children: [
439
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
440
+ className: "label",
441
+ children: "Slug"
442
+ }),
443
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
444
+ className: "input input-mono",
445
+ autoFocus: true,
446
+ spellCheck: false,
447
+ value: slug,
448
+ "aria-invalid": slugError !== null,
449
+ onChange: (event) => setSlug(event.target.value)
450
+ }),
451
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
452
+ className: `hint${slugError !== null ? " edit-note-error" : ""}`,
453
+ children: slugError ?? `Anything running coffre run ${project}/${environment.slug} will need the new path.`
454
+ })
455
+ ]
456
+ }),
457
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
458
+ className: "field",
459
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
460
+ className: "label",
461
+ children: "Display name"
462
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
463
+ className: "input",
464
+ value: name,
465
+ onChange: (event) => setName(event.target.value)
466
+ })]
467
+ }),
468
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error }),
469
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
470
+ className: "dialog-actions",
471
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
472
+ className: "btn",
473
+ type: "button",
474
+ onClick: () => setRenaming(false),
475
+ children: "Cancel"
476
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
477
+ className: "btn btn-primary",
478
+ type: "submit",
479
+ disabled: pending || slug === "" || slugError !== null || name.trim() === "",
480
+ children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Save"]
481
+ })]
482
+ })
483
+ ]
484
+ })
485
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmDialog, {
486
+ open: confirming,
487
+ onOpenChange: setConfirming,
488
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
489
+ isArchived ? "Restore" : "Archive",
490
+ " ",
491
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
492
+ className: "mono",
493
+ children: [
494
+ project,
495
+ "/",
496
+ environment.slug
497
+ ]
498
+ }),
499
+ "?"
500
+ ] }),
501
+ body: secretCount === null ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "This changes whether the environment serves secrets to principals who have access. Values and history remain stored." }) : isArchived ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
502
+ "The environment starts serving its ",
503
+ secretCount,
504
+ " secret",
505
+ secretCount === 1 ? "" : "s",
506
+ " again, to everyone who holds a grant on it."
507
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
508
+ "Its ",
509
+ secretCount,
510
+ " secret",
511
+ secretCount === 1 ? "" : "s",
512
+ " stop being served, so anything running ",
513
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: "coffre run" }),
514
+ " against",
515
+ " ",
516
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
517
+ className: "mono",
518
+ children: [
519
+ project,
520
+ "/",
521
+ environment.slug
522
+ ]
523
+ }),
524
+ " ",
525
+ "loses them at its next start. Values and history survive, and restoring is one click."
526
+ ] }),
527
+ confirmLabel: isArchived ? "Restore environment" : "Archive environment",
528
+ destructive: !isArchived,
529
+ onConfirm: () => run(() => coffre.environments.update(`${project}/${environment.slug}`, { archived: !isArchived }), () => toast.success(isArchived ? `${environment.slug} restored` : `${environment.slug} archived`))
530
+ })] })
531
+ ]
532
+ });
533
+ }
534
+ function NewEnvironment({ project }) {
535
+ const [open, setOpen] = (0, import_react.useState)(false);
536
+ const [slug, setSlug] = (0, import_react.useState)("");
537
+ const [name, setName] = (0, import_react.useState)("");
538
+ const coffre = useCoffre();
539
+ const { pending, error, setError, run } = useAction();
540
+ const slugError = slug === "" ? null : slugProblem(slug);
541
+ function close() {
542
+ setOpen(false);
543
+ setError(null);
544
+ }
545
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
546
+ className: "btn btn-primary",
547
+ onClick: () => setOpen(true),
548
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { size: 14 }), "Add environment"]
549
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Modal, {
550
+ open,
551
+ onOpenChange: (next) => next ? setOpen(true) : close(),
552
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["New environment in ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
553
+ className: "mono",
554
+ children: project
555
+ })] }),
556
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
557
+ className: "form",
558
+ onSubmit: (event) => {
559
+ event.preventDefault();
560
+ run(async () => {
561
+ const { created } = await coffre.environments.create(`${project}/${slug}`, { name });
562
+ if (!created) throw new Refusal(`An environment named "${slug}" already exists.`);
563
+ }, () => {
564
+ toast.success(`Environment ${slug} added`);
565
+ setSlug("");
566
+ setName("");
567
+ close();
568
+ });
569
+ },
570
+ children: [
571
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
572
+ className: "field",
573
+ children: [
574
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
575
+ className: "label",
576
+ children: "Slug"
577
+ }),
578
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
579
+ className: "input input-mono",
580
+ autoFocus: true,
581
+ spellCheck: false,
582
+ autoComplete: "off",
583
+ placeholder: "staging",
584
+ value: slug,
585
+ "aria-invalid": slugError !== null,
586
+ onChange: (event) => setSlug(event.target.value)
587
+ }),
588
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
589
+ className: `hint${slugError !== null ? " edit-note-error" : ""}`,
590
+ children: slugError ?? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
591
+ "The CLI will address it as",
592
+ " ",
593
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
594
+ className: "mono",
595
+ children: [
596
+ project,
597
+ "/",
598
+ slug === "" ? "staging" : slug
599
+ ]
600
+ }),
601
+ "."
602
+ ] })
603
+ })
604
+ ]
605
+ }),
606
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
607
+ className: "field",
608
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
609
+ className: "label",
610
+ children: "Display name"
611
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
612
+ className: "input",
613
+ placeholder: "Staging",
614
+ value: name,
615
+ onChange: (event) => setName(event.target.value)
616
+ })]
617
+ }),
618
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error }),
619
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
620
+ className: "dialog-actions",
621
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
622
+ className: "btn",
623
+ type: "button",
624
+ onClick: close,
625
+ children: "Cancel"
626
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
627
+ className: "btn btn-primary",
628
+ type: "submit",
629
+ disabled: pending || slug === "" || slugError !== null || name.trim() === "",
630
+ children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Add environment"]
631
+ })]
632
+ })
633
+ ]
634
+ })
635
+ })] });
636
+ }
637
+ function AccessPanel({ principalType, project, grants }) {
638
+ const people = principalType === "user";
639
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", {
640
+ className: "card",
641
+ "aria-label": people ? "Users with access" : "Tokens with access",
642
+ children: grants.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(EmptyState, {
643
+ title: people ? "No user has access" : "No token has access",
644
+ children: [
645
+ "Add ",
646
+ people ? "a user" : "a token",
647
+ " with permissions on the whole project or on one environment."
648
+ ]
649
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GrantsTable, {
650
+ lead: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
651
+ className: "th",
652
+ children: [people ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(User, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Key, { size: 14 }), people ? "Email" : "Name"]
653
+ }),
654
+ children: grants.map((grant, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(GrantRowView, {
655
+ number: index + 1,
656
+ project,
657
+ grant,
658
+ leadLabel: people ? "Email" : "Name",
659
+ lead: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrincipalLink, {
660
+ type: grant.principalType,
661
+ id: grant.principalId
662
+ })
663
+ }, grant.id))
664
+ })
665
+ });
666
+ }
667
+ function NewGrant({ principalType, project, environments, grants }) {
668
+ const { capabilities } = useLoaderData({ from: "__root__" });
669
+ const [open, setOpen] = (0, import_react.useState)(false);
670
+ const [principalId, setPrincipalId] = (0, import_react.useState)("");
671
+ const [permission, setPermission] = (0, import_react.useState)("viewer:");
672
+ const [expiresAt, setExpiresAt] = (0, import_react.useState)("");
673
+ const coffre = useCoffre();
674
+ const { pending, error, setError, run } = useAction();
675
+ const permissionOptions = projectAccessOptions(environments);
676
+ const kind = principalType === "user" ? "user" : "token";
677
+ function close() {
678
+ setOpen(false);
679
+ setError(null);
680
+ }
681
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
682
+ className: "btn btn-primary",
683
+ onClick: () => setOpen(true),
684
+ children: [
685
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Plus, { size: 14 }),
686
+ "Add ",
687
+ kind
688
+ ]
689
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Modal, {
690
+ open,
691
+ onOpenChange: (next) => next ? setOpen(true) : close(),
692
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
693
+ "Give a ",
694
+ kind,
695
+ " access to ",
696
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
697
+ className: "mono",
698
+ children: project
699
+ })
700
+ ] }),
701
+ wide: true,
702
+ description: "Owners manage the whole project and its access. Read and write can cover every environment, or one.",
703
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
704
+ className: "form",
705
+ onSubmit: (event) => {
706
+ event.preventDefault();
707
+ const access = parseProjectAccess(permission);
708
+ run(() => ensureGrant(coffre, {
709
+ project,
710
+ principalType,
711
+ principalId: principalId.trim(),
712
+ role: access.role,
713
+ environmentSlug: access.environmentSlug,
714
+ expiresAt: expiresAt === "" ? null : (/* @__PURE__ */ new Date(`${expiresAt}T23:59:59Z`)).toISOString()
715
+ }), ({ existed }) => {
716
+ const label = permissionOptions.find((option) => option.value === permission)?.label ?? "access";
717
+ toast.success(existed ? `${principalId} already has ${label}` : `${principalId} granted ${label.toLowerCase()}`);
718
+ setPrincipalId("");
719
+ setExpiresAt("");
720
+ setPermission("viewer:");
721
+ close();
722
+ });
723
+ },
724
+ children: [
725
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PrincipalPicker, {
726
+ principalType,
727
+ canList: capabilities.canManageGrants,
728
+ grants,
729
+ value: principalId,
730
+ onChange: setPrincipalId
731
+ }),
732
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
733
+ className: "form-row",
734
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
735
+ className: "field",
736
+ style: { flexGrow: 2 },
737
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
738
+ className: "label",
739
+ children: "Permissions"
740
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
741
+ className: "select",
742
+ value: permission,
743
+ onChange: (event) => setPermission(event.target.value),
744
+ children: permissionOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
745
+ value: option.value,
746
+ children: option.label
747
+ }, option.value))
748
+ })]
749
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
750
+ className: "field",
751
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
752
+ className: "label",
753
+ children: ["Expires ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
754
+ className: "hint",
755
+ children: "(optional)"
756
+ })]
757
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
758
+ className: "input",
759
+ type: "date",
760
+ value: expiresAt,
761
+ onChange: (event) => setExpiresAt(event.target.value)
762
+ })]
763
+ })]
764
+ }),
765
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error }),
766
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
767
+ className: "dialog-actions",
768
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
769
+ className: "btn",
770
+ type: "button",
771
+ onClick: close,
772
+ children: "Cancel"
773
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
774
+ className: "btn btn-primary",
775
+ type: "submit",
776
+ disabled: pending || principalId.trim() === "",
777
+ children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Grant access"]
778
+ })]
779
+ })
780
+ ]
781
+ })
782
+ })] });
783
+ }
784
+ /**
785
+ * The project's name and slug, as a form on the page.
786
+ *
787
+ * Renaming changes paths other people and scripts use, so it is laid out in
788
+ * plain sight with what it does and does not affect, rather than tucked
789
+ * behind a menu.
790
+ */
791
+ function GeneralSettings({ project }) {
792
+ const router = useRouter();
793
+ const [slug, setSlug] = (0, import_react.useState)(project.slug);
794
+ const [name, setName] = (0, import_react.useState)(project.name);
795
+ const coffre = useCoffre();
796
+ const { pending, error, run } = useAction();
797
+ const slugError = slug === "" ? null : slugProblem(slug);
798
+ const dirty = slug !== project.slug || name.trim() !== project.name;
799
+ (0, import_react.useEffect)(() => {
800
+ setSlug(project.slug);
801
+ setName(project.name);
802
+ }, [project.slug, project.name]);
803
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
804
+ className: "card",
805
+ "aria-labelledby": "general-settings",
806
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
807
+ className: "card-head",
808
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
809
+ className: "card-title",
810
+ id: "general-settings",
811
+ children: "General"
812
+ }) })
813
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
814
+ onSubmit: (event) => {
815
+ event.preventDefault();
816
+ run(() => coffre.projects.update(project.slug, {
817
+ slug,
818
+ name
819
+ }), async () => {
820
+ toast.success("Project renamed");
821
+ if (slug !== project.slug) await router.navigate({
822
+ to: "/projects/$project",
823
+ params: { project: slug },
824
+ search: { tab: "settings" }
825
+ });
826
+ });
827
+ },
828
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
829
+ className: "card-body form-row",
830
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
831
+ className: "field",
832
+ children: [
833
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
834
+ className: "label",
835
+ children: "Slug"
836
+ }),
837
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
838
+ className: "input input-mono",
839
+ spellCheck: false,
840
+ value: slug,
841
+ "aria-invalid": slugError !== null,
842
+ onChange: (event) => setSlug(event.target.value)
843
+ }),
844
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
845
+ className: `hint${slugError !== null ? " edit-note-error" : ""}`,
846
+ children: slugError ?? "Scripts that name the old slug will need the new one."
847
+ })
848
+ ]
849
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
850
+ className: "field",
851
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
852
+ className: "label",
853
+ children: "Display name"
854
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
855
+ className: "input",
856
+ value: name,
857
+ onChange: (event) => setName(event.target.value)
858
+ })]
859
+ })]
860
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
861
+ className: "card-foot",
862
+ children: [error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
863
+ className: "hint",
864
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error })
865
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
866
+ className: "btn btn-primary",
867
+ type: "submit",
868
+ disabled: !dirty || pending || slug === "" || slugError !== null || name.trim() === "",
869
+ children: [pending && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}), "Save"]
870
+ })]
871
+ })]
872
+ })]
873
+ });
874
+ }
875
+ function DangerZone({ project }) {
876
+ const [confirming, setConfirming] = (0, import_react.useState)(false);
877
+ const coffre = useCoffre();
878
+ const { pending, error, run } = useAction();
879
+ const isArchived = project.archivedAt !== null;
880
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Card, {
881
+ labelledBy: "danger-zone",
882
+ title: "Danger zone",
883
+ tone: "danger",
884
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
885
+ className: "card-row",
886
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
887
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
888
+ className: "card-row-title",
889
+ children: isArchived ? "Restore project" : "Archive project"
890
+ }),
891
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
892
+ className: "card-row-desc",
893
+ children: isArchived ? "The project reappears in listings and its environments serve reads again, for everyone who holds a grant on it." : "Every environment stops serving reads, including to machine callers already running. Nothing is deleted, and you can restore it here at any time."
894
+ }),
895
+ error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
896
+ style: { marginTop: "0.5rem" },
897
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorLine, { error })
898
+ })
899
+ ] }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
900
+ className: `btn ${isArchived ? "" : "btn-danger-outline"}`,
901
+ onClick: () => setConfirming(true),
902
+ disabled: pending,
903
+ children: [pending ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {}) : isArchived ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RotateBack, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Archive, { size: 14 }), isArchived ? "Restore project" : "Archive project…"]
904
+ })]
905
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ConfirmDialog, {
906
+ open: confirming,
907
+ onOpenChange: setConfirming,
908
+ title: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
909
+ isArchived ? "Restore" : "Archive",
910
+ " ",
911
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
912
+ className: "mono",
913
+ children: project.slug
914
+ }),
915
+ "?"
916
+ ] }),
917
+ body: isArchived ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "The project reappears in listings and its environments start serving reads again, for everyone who holds a grant on it." }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
918
+ "Every environment in ",
919
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
920
+ className: "mono",
921
+ children: project.slug
922
+ }),
923
+ " stops serving reads, including to machine callers already running. Nothing is deleted: values, versions and the audit trail over them stay intact, and you can restore it here at any time."
924
+ ] }),
925
+ confirmLabel: isArchived ? "Restore project" : "Archive project",
926
+ destructive: !isArchived,
927
+ onConfirm: () => run(() => coffre.projects.update(project.slug, { archived: !isArchived }), () => toast.success(isArchived ? `${project.slug} restored` : `${project.slug} archived`))
928
+ })]
929
+ });
930
+ }
931
+ //#endregion
932
+ export { ProjectPage as component };