@coffre/ui 0.0.0 → 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 +7 -3
  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 -5
  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,917 @@
1
+ import { useEffect, useState, type ReactNode } from 'react';
2
+ import { createFileRoute, Link, useLoaderData, useRouter } from '@tanstack/react-router';
3
+ import { DropdownMenu } from 'radix-ui';
4
+ import { toast } from 'sonner';
5
+ import { Refusal, useCoffre } from '../lib/coffre';
6
+ import { useAction } from '../lib/use-action';
7
+ import type { GrantRow, ProjectSummary } from '../shared/models';
8
+ import {
9
+ hasEnvironmentDetails,
10
+ type ProjectEnvironment,
11
+ } from '../lib/project-environments';
12
+ import { slugProblem } from '../lib/validation';
13
+ import {
14
+ ConfirmDialog,
15
+ EmptyState,
16
+ ErrorLine,
17
+ Modal,
18
+ Notice,
19
+ Spinner,
20
+ } from '../components/ui';
21
+ import { Card, ClosedDoor, PageHeader } from '../components/page';
22
+ import { ensureGrant, GrantRowView, GrantsTable, loadProject } from '../components/grants';
23
+ import { PrincipalLink } from '../components/principal';
24
+ import { PrincipalPicker } from '../components/principal-picker';
25
+ import {
26
+ parseProjectAccess,
27
+ projectAccessOptions,
28
+ } from '../lib/project-access';
29
+ import {
30
+ Archive,
31
+ Folder,
32
+ Key,
33
+ Layers,
34
+ MoreHorizontal,
35
+ Pencil,
36
+ Plus,
37
+ RotateBack,
38
+ Settings,
39
+ User,
40
+ Users,
41
+ } from '../components/icons';
42
+
43
+ type ProjectTab = 'environments' | 'users' | 'tokens' | 'settings';
44
+
45
+ export const Route = createFileRoute('/projects/$project/')({
46
+ // The tab lives in the URL so a link can land on a project's access list.
47
+ // Environments is the default and so has no parameter.
48
+ validateSearch: (search: Record<string, unknown>): { tab?: Exclude<ProjectTab, 'environments'> } => ({
49
+ tab:
50
+ search.tab === 'users' || search.tab === 'tokens' || search.tab === 'settings'
51
+ ? search.tab
52
+ : undefined,
53
+ }),
54
+ loader: ({ context: { client }, params }) => loadProject(client, params.project),
55
+ component: ProjectPage,
56
+ });
57
+
58
+ const TABS: { key: ProjectTab; label: string; icon: ReactNode }[] = [
59
+ { key: 'environments', label: 'Environments', icon: <Layers size={15} /> },
60
+ { key: 'users', label: 'Users', icon: <Users size={15} /> },
61
+ { key: 'tokens', label: 'Tokens', icon: <Key size={15} /> },
62
+ { key: 'settings', label: 'Settings', icon: <Settings size={15} /> },
63
+ ];
64
+
65
+ function ProjectPage() {
66
+ const result = Route.useLoaderData();
67
+ const { project: projectSlug } = Route.useParams();
68
+ const search = Route.useSearch();
69
+
70
+ if (!result.ok) {
71
+ return (
72
+ <ClosedDoor
73
+ icon={<Folder size={18} />}
74
+ label={<span className="mono">{projectSlug}</span>}
75
+ title="No project here for you"
76
+ actions={
77
+ <Link className="btn" to="/projects">
78
+ All projects
79
+ </Link>
80
+ }
81
+ >
82
+ {result.error ??
83
+ '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.'}
84
+ </ClosedDoor>
85
+ );
86
+ }
87
+
88
+ const { project, grants, grantsError } = result;
89
+
90
+ // Each tab is gated on its own permission, not on one blanket "admin".
91
+ // That is what lets an access manager administer grants without being able
92
+ // to rename the project, and vice versa.
93
+ const canManageProject = project.permissions.includes('project.manage');
94
+ const canManageEnvironments = project.permissions.includes('environment.manage');
95
+ const canManageGrants = project.permissions.includes('grant.manage');
96
+ const allowed = TABS.filter(
97
+ ({ key }) =>
98
+ key === 'environments' ||
99
+ ((key === 'users' || key === 'tokens') && canManageGrants) ||
100
+ (key === 'settings' && canManageProject),
101
+ );
102
+ // A tab you may not open falls back to the default rather than to an error:
103
+ // a link someone shared still lands somewhere useful.
104
+ const tab = allowed.find(({ key }) => key === search.tab)?.key ?? 'environments';
105
+ const principalType = tab === 'users' ? 'user' : 'service';
106
+
107
+ return (
108
+ <>
109
+ <PageHeader
110
+ tile={project.slug}
111
+ title={project.name}
112
+ aside={<span className="page-title-slug">{project.slug}</span>}
113
+ actions={
114
+ tab === 'environments'
115
+ ? canManageEnvironments && <NewEnvironment project={project.slug} />
116
+ : (tab === 'users' || tab === 'tokens') &&
117
+ grantsError === null && (
118
+ <NewGrant
119
+ principalType={principalType}
120
+ project={project.slug}
121
+ environments={project.environments}
122
+ grants={grants}
123
+ />
124
+ )
125
+ }
126
+ />
127
+
128
+ {project.archivedAt !== null && (
129
+ <div style={{ marginBottom: '1.25rem' }}>
130
+ <Notice tone="bad">
131
+ <strong>This project is archived.</strong> Its environments serve no reads, to
132
+ people or to machines, until it is restored.
133
+ </Notice>
134
+ </div>
135
+ )}
136
+
137
+ {/* One tab is no choice at all, so a reader-only project shows none. */}
138
+ {allowed.length > 1 && (
139
+ <nav className="tabs" aria-label="Project sections">
140
+ {allowed.map(({ key, label, icon }) => (
141
+ <Link
142
+ key={key}
143
+ to="/projects/$project"
144
+ params={{ project: project.slug }}
145
+ search={{ tab: key === 'environments' ? undefined : key }}
146
+ // Without these, Environments (no parameter) counts as a
147
+ // prefix of every other tab and stays highlighted on all of them.
148
+ activeOptions={{ exact: true, explicitUndefined: true }}
149
+ aria-current={key === tab ? 'page' : undefined}
150
+ >
151
+ {icon}
152
+ {label}
153
+ </Link>
154
+ ))}
155
+ </nav>
156
+ )}
157
+
158
+ {tab === 'environments' && (
159
+ <EnvironmentsPanel project={project} canManage={canManageEnvironments} />
160
+ )}
161
+
162
+ {(tab === 'users' || tab === 'tokens') &&
163
+ (grantsError !== null ? (
164
+ <Notice tone="bad">{grantsError}</Notice>
165
+ ) : (
166
+ <AccessPanel
167
+ principalType={principalType}
168
+ project={project.slug}
169
+ grants={grants.filter((grant) => grant.principalType === principalType)}
170
+ />
171
+ ))}
172
+
173
+ {tab === 'settings' && (
174
+ <>
175
+ <GeneralSettings project={project} />
176
+ <DangerZone project={project} />
177
+ </>
178
+ )}
179
+ </>
180
+ );
181
+ }
182
+
183
+ function EnvironmentsPanel({
184
+ project,
185
+ canManage,
186
+ }: {
187
+ project: ProjectSummary;
188
+ canManage: boolean;
189
+ }) {
190
+ const detailed = project.environments.filter(hasEnvironmentDetails);
191
+ const archived = detailed.filter((environment) => environment.details.archivedAt !== null);
192
+ // Environments you may know by name only sit with the active ones: no grant
193
+ // you hold covers their contents, so they are muted and do not open.
194
+ const current = project.environments.filter(
195
+ (environment) => environment.details === null || environment.details.archivedAt === null,
196
+ );
197
+
198
+ return (
199
+ <>
200
+ {current.length === 0 ? (
201
+ <div className="card">
202
+ <EmptyState title="No environments yet">
203
+ {canManage
204
+ ? 'Add the first with Add environment.'
205
+ : 'Creating environments needs environment.manage on this project.'}
206
+ </EmptyState>
207
+ </div>
208
+ ) : (
209
+ <ul className="env-grid" aria-label="Environments">
210
+ {current.map((environment) => (
211
+ <li key={`${project.slug}:${environment.slug}`}>
212
+ <EnvironmentCard
213
+ project={project.slug}
214
+ environment={environment}
215
+ isAdmin={canManage}
216
+ />
217
+ </li>
218
+ ))}
219
+ </ul>
220
+ )}
221
+
222
+ {archived.length > 0 && (
223
+ <section aria-labelledby="archived-environments">
224
+ <h2 className="section-title" id="archived-environments">
225
+ Archived
226
+ </h2>
227
+ <ul className="env-grid">
228
+ {archived.map((environment) => (
229
+ <li key={environment.slug}>
230
+ <EnvironmentCard
231
+ project={project.slug}
232
+ environment={environment}
233
+ isAdmin={canManage}
234
+ />
235
+ </li>
236
+ ))}
237
+ </ul>
238
+ </section>
239
+ )}
240
+ </>
241
+ );
242
+ }
243
+
244
+ /**
245
+ * One environment. The whole card opens it when you can; its menu sits above
246
+ * that link.
247
+ */
248
+ function EnvironmentCard({
249
+ project,
250
+ environment,
251
+ isAdmin,
252
+ }: {
253
+ project: string;
254
+ environment: ProjectEnvironment;
255
+ isAdmin: boolean;
256
+ }) {
257
+ const [renaming, setRenaming] = useState(false);
258
+ const [confirming, setConfirming] = useState(false);
259
+ const [slug, setSlug] = useState(environment.slug);
260
+ const [name, setName] = useState(environment.name);
261
+ const coffre = useCoffre();
262
+ const { pending, error, setError, run } = useAction();
263
+ const details = environment.details;
264
+ const isArchived = details !== null && details.archivedAt !== null;
265
+ const secretCount = details?.secretCount ?? null;
266
+ const opens = details !== null && !isArchived && environment.accessible;
267
+ const manageable = isAdmin && details !== null;
268
+ const slugError = slug === '' ? null : slugProblem(slug);
269
+
270
+ useEffect(() => {
271
+ if (error !== null && !renaming) toast.error(error);
272
+ }, [error, renaming]);
273
+
274
+ return (
275
+ <div className={`env-card${opens ? ' is-link' : ' is-muted'}`}>
276
+ <div className="env-card-text">
277
+ {opens ? (
278
+ <Link
279
+ className="env-card-name stretch"
280
+ to="/projects/$project/$environment"
281
+ params={{ project, environment: environment.slug }}
282
+ >
283
+ {environment.name}
284
+ </Link>
285
+ ) : (
286
+ <span className="env-card-name">{environment.name}</span>
287
+ )}
288
+ <span className="env-card-meta">
289
+ <span className="mono">{environment.slug}</span>
290
+ {isArchived ? (
291
+ <span className="tag tag-red">archived</span>
292
+ ) : !environment.accessible ? (
293
+ <span className="tag tag-outline">no secret access</span>
294
+ ) : (
295
+ secretCount !== null && (
296
+ <span>
297
+ {secretCount} secret{secretCount === 1 ? '' : 's'}
298
+ </span>
299
+ )
300
+ )}
301
+ </span>
302
+ </div>
303
+
304
+ {manageable && (
305
+ <DropdownMenu.Root>
306
+ <DropdownMenu.Trigger asChild>
307
+ <button
308
+ className="act act-quiet env-card-menu"
309
+ aria-label={`Actions for ${environment.slug}`}
310
+ disabled={pending}
311
+ >
312
+ {pending ? <Spinner size={14} /> : <MoreHorizontal size={16} />}
313
+ </button>
314
+ </DropdownMenu.Trigger>
315
+ <DropdownMenu.Portal>
316
+ <DropdownMenu.Content className="menu" sideOffset={6} align="end">
317
+ <DropdownMenu.Item
318
+ className="menu-item"
319
+ onSelect={() => {
320
+ setSlug(environment.slug);
321
+ setName(environment.name);
322
+ setRenaming(true);
323
+ }}
324
+ >
325
+ <Pencil size={14} />
326
+ Rename
327
+ </DropdownMenu.Item>
328
+ <DropdownMenu.Separator className="menu-sep" />
329
+ <DropdownMenu.Item
330
+ className={`menu-item${isArchived ? '' : ' menu-item-danger'}`}
331
+ onSelect={() => setConfirming(true)}
332
+ >
333
+ {isArchived ? <RotateBack size={14} /> : <Archive size={14} />}
334
+ {isArchived ? 'Restore' : 'Archive…'}
335
+ </DropdownMenu.Item>
336
+ </DropdownMenu.Content>
337
+ </DropdownMenu.Portal>
338
+ </DropdownMenu.Root>
339
+ )}
340
+
341
+ {manageable && (
342
+ <>
343
+ <Modal
344
+ open={renaming}
345
+ onOpenChange={(open) => {
346
+ setRenaming(open);
347
+ if (!open) setError(null);
348
+ }}
349
+ title={
350
+ <>
351
+ Rename{' '}
352
+ <span className="mono">
353
+ {project}/{environment.slug}
354
+ </span>
355
+ </>
356
+ }
357
+ >
358
+ <form
359
+ className="form"
360
+ onSubmit={(event) => {
361
+ event.preventDefault();
362
+ run(
363
+ () =>
364
+ coffre.environments.update(`${project}/${environment.slug}`, { slug, name }),
365
+ () => {
366
+ setRenaming(false);
367
+ toast.success('Environment renamed');
368
+ },
369
+ );
370
+ }}
371
+ >
372
+ <label className="field">
373
+ <span className="label">Slug</span>
374
+ <input
375
+ className="input input-mono"
376
+ autoFocus
377
+ spellCheck={false}
378
+ value={slug}
379
+ aria-invalid={slugError !== null}
380
+ onChange={(event) => setSlug(event.target.value)}
381
+ />
382
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
383
+ {slugError ??
384
+ `Anything running coffre run ${project}/${environment.slug} will need the new path.`}
385
+ </span>
386
+ </label>
387
+ <label className="field">
388
+ <span className="label">Display name</span>
389
+ <input
390
+ className="input"
391
+ value={name}
392
+ onChange={(event) => setName(event.target.value)}
393
+ />
394
+ </label>
395
+
396
+ <ErrorLine error={error} />
397
+
398
+ <div className="dialog-actions">
399
+ <button className="btn" type="button" onClick={() => setRenaming(false)}>
400
+ Cancel
401
+ </button>
402
+ <button
403
+ className="btn btn-primary"
404
+ type="submit"
405
+ disabled={pending || slug === '' || slugError !== null || name.trim() === ''}
406
+ >
407
+ {pending && <Spinner />}
408
+ Save
409
+ </button>
410
+ </div>
411
+ </form>
412
+ </Modal>
413
+
414
+ <ConfirmDialog
415
+ open={confirming}
416
+ onOpenChange={setConfirming}
417
+ title={
418
+ <>
419
+ {isArchived ? 'Restore' : 'Archive'}{' '}
420
+ <span className="mono">
421
+ {project}/{environment.slug}
422
+ </span>
423
+ ?
424
+ </>
425
+ }
426
+ body={
427
+ secretCount === null ? (
428
+ <>
429
+ This changes whether the environment serves secrets to principals who have
430
+ access. Values and history remain stored.
431
+ </>
432
+ ) : isArchived ? (
433
+ <>
434
+ The environment starts serving its {secretCount} secret
435
+ {secretCount === 1 ? '' : 's'} again, to everyone who holds a grant on it.
436
+ </>
437
+ ) : (
438
+ <>
439
+ Its {secretCount} secret{secretCount === 1 ? '' : 's'} stop being served, so
440
+ anything running <code>coffre run</code> against{' '}
441
+ <span className="mono">
442
+ {project}/{environment.slug}
443
+ </span>{' '}
444
+ loses them at its next start. Values and history survive, and restoring is
445
+ one click.
446
+ </>
447
+ )
448
+ }
449
+ confirmLabel={isArchived ? 'Restore environment' : 'Archive environment'}
450
+ destructive={!isArchived}
451
+ onConfirm={() =>
452
+ run(
453
+ () =>
454
+ coffre.environments.update(`${project}/${environment.slug}`, { archived: !isArchived }),
455
+ () =>
456
+ toast.success(
457
+ isArchived ? `${environment.slug} restored` : `${environment.slug} archived`,
458
+ ),
459
+ )
460
+ }
461
+ />
462
+ </>
463
+ )}
464
+ </div>
465
+ );
466
+ }
467
+
468
+ function NewEnvironment({ project }: { project: string }) {
469
+ const [open, setOpen] = useState(false);
470
+ const [slug, setSlug] = useState('');
471
+ const [name, setName] = useState('');
472
+ const coffre = useCoffre();
473
+ const { pending, error, setError, run } = useAction();
474
+ const slugError = slug === '' ? null : slugProblem(slug);
475
+
476
+ function close() {
477
+ setOpen(false);
478
+ setError(null);
479
+ }
480
+
481
+ return (
482
+ <>
483
+ <button className="btn btn-primary" onClick={() => setOpen(true)}>
484
+ <Plus size={14} />
485
+ Add environment
486
+ </button>
487
+
488
+ <Modal
489
+ open={open}
490
+ onOpenChange={(next) => (next ? setOpen(true) : close())}
491
+ title={
492
+ <>
493
+ New environment in <span className="mono">{project}</span>
494
+ </>
495
+ }
496
+ >
497
+ <form
498
+ className="form"
499
+ onSubmit={(event) => {
500
+ event.preventDefault();
501
+ run(
502
+ async () => {
503
+ const { created } = await coffre.environments.create(`${project}/${slug}`, { name });
504
+ if (!created) throw new Refusal(`An environment named "${slug}" already exists.`);
505
+ },
506
+ () => {
507
+ toast.success(`Environment ${slug} added`);
508
+ setSlug('');
509
+ setName('');
510
+ close();
511
+ },
512
+ );
513
+ }}
514
+ >
515
+ <label className="field">
516
+ <span className="label">Slug</span>
517
+ <input
518
+ className="input input-mono"
519
+ autoFocus
520
+ spellCheck={false}
521
+ autoComplete="off"
522
+ placeholder="staging"
523
+ value={slug}
524
+ aria-invalid={slugError !== null}
525
+ onChange={(event) => setSlug(event.target.value)}
526
+ />
527
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
528
+ {slugError ?? (
529
+ <>
530
+ The CLI will address it as{' '}
531
+ <span className="mono">
532
+ {project}/{slug === '' ? 'staging' : slug}
533
+ </span>
534
+ .
535
+ </>
536
+ )}
537
+ </span>
538
+ </label>
539
+ <label className="field">
540
+ <span className="label">Display name</span>
541
+ <input
542
+ className="input"
543
+ placeholder="Staging"
544
+ value={name}
545
+ onChange={(event) => setName(event.target.value)}
546
+ />
547
+ </label>
548
+
549
+ <ErrorLine error={error} />
550
+
551
+ <div className="dialog-actions">
552
+ <button className="btn" type="button" onClick={close}>
553
+ Cancel
554
+ </button>
555
+ <button
556
+ className="btn btn-primary"
557
+ type="submit"
558
+ disabled={pending || slug === '' || slugError !== null || name.trim() === ''}
559
+ >
560
+ {pending && <Spinner />}
561
+ Add environment
562
+ </button>
563
+ </div>
564
+ </form>
565
+ </Modal>
566
+ </>
567
+ );
568
+ }
569
+
570
+ function AccessPanel({
571
+ principalType,
572
+ project,
573
+ grants,
574
+ }: {
575
+ principalType: 'user' | 'service';
576
+ project: string;
577
+ grants: GrantRow[];
578
+ }) {
579
+ const people = principalType === 'user';
580
+ return (
581
+ <section className="card" aria-label={people ? 'Users with access' : 'Tokens with access'}>
582
+ {grants.length === 0 ? (
583
+ <EmptyState title={people ? 'No user has access' : 'No token has access'}>
584
+ Add {people ? 'a user' : 'a token'} with permissions on the whole project or on one
585
+ environment.
586
+ </EmptyState>
587
+ ) : (
588
+ <GrantsTable
589
+ lead={
590
+ <span className="th">
591
+ {people ? <User size={14} /> : <Key size={14} />}
592
+ {people ? 'Email' : 'Name'}
593
+ </span>
594
+ }
595
+ >
596
+ {grants.map((grant, index) => (
597
+ <GrantRowView
598
+ key={grant.id}
599
+ number={index + 1}
600
+ project={project}
601
+ grant={grant}
602
+ leadLabel={people ? 'Email' : 'Name'}
603
+ lead={<PrincipalLink type={grant.principalType} id={grant.principalId} />}
604
+ />
605
+ ))}
606
+ </GrantsTable>
607
+ )}
608
+ </section>
609
+ );
610
+ }
611
+
612
+ function NewGrant({
613
+ principalType,
614
+ project,
615
+ environments,
616
+ grants,
617
+ }: {
618
+ principalType: 'user' | 'service';
619
+ project: string;
620
+ environments: ProjectSummary['environments'];
621
+ grants: GrantRow[];
622
+ }) {
623
+ const { capabilities } = useLoaderData({ from: '__root__' });
624
+ const [open, setOpen] = useState(false);
625
+ const [principalId, setPrincipalId] = useState('');
626
+ const [permission, setPermission] = useState('viewer:');
627
+ const [expiresAt, setExpiresAt] = useState('');
628
+ const coffre = useCoffre();
629
+ const { pending, error, setError, run } = useAction();
630
+ const permissionOptions = projectAccessOptions(environments);
631
+ const kind = principalType === 'user' ? 'user' : 'token';
632
+
633
+ function close() {
634
+ setOpen(false);
635
+ setError(null);
636
+ }
637
+
638
+ return (
639
+ <>
640
+ <button className="btn btn-primary" onClick={() => setOpen(true)}>
641
+ <Plus size={14} />
642
+ Add {kind}
643
+ </button>
644
+
645
+ <Modal
646
+ open={open}
647
+ onOpenChange={(next) => (next ? setOpen(true) : close())}
648
+ title={
649
+ <>
650
+ Give a {kind} access to <span className="mono">{project}</span>
651
+ </>
652
+ }
653
+ wide
654
+ description="Owners manage the whole project and its access. Read and write can cover every environment, or one."
655
+ >
656
+ <form
657
+ className="form"
658
+ onSubmit={(event) => {
659
+ event.preventDefault();
660
+ const access = parseProjectAccess(permission);
661
+ run(
662
+ () =>
663
+ ensureGrant(coffre, {
664
+ project,
665
+ principalType,
666
+ principalId: principalId.trim(),
667
+ role: access.role,
668
+ environmentSlug: access.environmentSlug,
669
+ expiresAt:
670
+ expiresAt === '' ? null : new Date(`${expiresAt}T23:59:59Z`).toISOString(),
671
+ }),
672
+ ({ existed }) => {
673
+ const label =
674
+ permissionOptions.find((option) => option.value === permission)?.label ??
675
+ 'access';
676
+ toast.success(
677
+ existed
678
+ ? `${principalId} already has ${label}`
679
+ : `${principalId} granted ${label.toLowerCase()}`,
680
+ );
681
+ setPrincipalId('');
682
+ setExpiresAt('');
683
+ setPermission('viewer:');
684
+ close();
685
+ },
686
+ );
687
+ }}
688
+ >
689
+ <PrincipalPicker
690
+ principalType={principalType}
691
+ canList={capabilities.canManageGrants}
692
+ grants={grants}
693
+ value={principalId}
694
+ onChange={setPrincipalId}
695
+ />
696
+
697
+ <div className="form-row">
698
+ <label className="field" style={{ flexGrow: 2 }}>
699
+ <span className="label">Permissions</span>
700
+ <select
701
+ className="select"
702
+ value={permission}
703
+ onChange={(event) => setPermission(event.target.value)}
704
+ >
705
+ {permissionOptions.map((option) => (
706
+ <option key={option.value} value={option.value}>
707
+ {option.label}
708
+ </option>
709
+ ))}
710
+ </select>
711
+ </label>
712
+
713
+ <label className="field">
714
+ <span className="label">
715
+ Expires <span className="hint">(optional)</span>
716
+ </span>
717
+ <input
718
+ className="input"
719
+ type="date"
720
+ value={expiresAt}
721
+ onChange={(event) => setExpiresAt(event.target.value)}
722
+ />
723
+ </label>
724
+ </div>
725
+
726
+ <ErrorLine error={error} />
727
+
728
+ <div className="dialog-actions">
729
+ <button className="btn" type="button" onClick={close}>
730
+ Cancel
731
+ </button>
732
+ <button
733
+ className="btn btn-primary"
734
+ type="submit"
735
+ disabled={pending || principalId.trim() === ''}
736
+ >
737
+ {pending && <Spinner />}
738
+ Grant access
739
+ </button>
740
+ </div>
741
+ </form>
742
+ </Modal>
743
+ </>
744
+ );
745
+ }
746
+
747
+ /**
748
+ * The project's name and slug, as a form on the page.
749
+ *
750
+ * Renaming changes paths other people and scripts use, so it is laid out in
751
+ * plain sight with what it does and does not affect, rather than tucked
752
+ * behind a menu.
753
+ */
754
+ function GeneralSettings({ project }: { project: ProjectSummary }) {
755
+ const router = useRouter();
756
+ const [slug, setSlug] = useState(project.slug);
757
+ const [name, setName] = useState(project.name);
758
+ const coffre = useCoffre();
759
+ const { pending, error, run } = useAction();
760
+ const slugError = slug === '' ? null : slugProblem(slug);
761
+ const dirty = slug !== project.slug || name.trim() !== project.name;
762
+
763
+ // Follow a rename made elsewhere (another tab, another person) rather than
764
+ // keep offering the old values back.
765
+ useEffect(() => {
766
+ setSlug(project.slug);
767
+ setName(project.name);
768
+ }, [project.slug, project.name]);
769
+
770
+ return (
771
+ <section className="card" aria-labelledby="general-settings">
772
+ <div className="card-head">
773
+ <div>
774
+ <h2 className="card-title" id="general-settings">
775
+ General
776
+ </h2>
777
+ </div>
778
+ </div>
779
+ <form
780
+ onSubmit={(event) => {
781
+ event.preventDefault();
782
+ run(
783
+ () => coffre.projects.update(project.slug, { slug, name }),
784
+ async () => {
785
+ toast.success('Project renamed');
786
+ // The slug is part of the URL, so a rename has to navigate.
787
+ if (slug !== project.slug) {
788
+ await router.navigate({
789
+ to: '/projects/$project',
790
+ params: { project: slug },
791
+ search: { tab: 'settings' },
792
+ });
793
+ }
794
+ },
795
+ );
796
+ }}
797
+ >
798
+ <div className="card-body form-row">
799
+ <label className="field">
800
+ <span className="label">Slug</span>
801
+ <input
802
+ className="input input-mono"
803
+ spellCheck={false}
804
+ value={slug}
805
+ aria-invalid={slugError !== null}
806
+ onChange={(event) => setSlug(event.target.value)}
807
+ />
808
+ <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`}>
809
+ {slugError ?? 'Scripts that name the old slug will need the new one.'}
810
+ </span>
811
+ </label>
812
+ <label className="field">
813
+ <span className="label">Display name</span>
814
+ <input
815
+ className="input"
816
+ value={name}
817
+ onChange={(event) => setName(event.target.value)}
818
+ />
819
+ </label>
820
+ </div>
821
+ <div className="card-foot">
822
+ {error !== null && (
823
+ <span className="hint">
824
+ <ErrorLine error={error} />
825
+ </span>
826
+ )}
827
+ <button
828
+ className="btn btn-primary"
829
+ type="submit"
830
+ disabled={!dirty || pending || slug === '' || slugError !== null || name.trim() === ''}
831
+ >
832
+ {pending && <Spinner />}
833
+ Save
834
+ </button>
835
+ </div>
836
+ </form>
837
+ </section>
838
+ );
839
+ }
840
+
841
+ function DangerZone({ project }: { project: ProjectSummary }) {
842
+ const [confirming, setConfirming] = useState(false);
843
+ const coffre = useCoffre();
844
+ const { pending, error, run } = useAction();
845
+ const isArchived = project.archivedAt !== null;
846
+
847
+ return (
848
+ <Card labelledBy="danger-zone" title="Danger zone" tone="danger">
849
+ <div className="card-row">
850
+ <div>
851
+ <p className="card-row-title">{isArchived ? 'Restore project' : 'Archive project'}</p>
852
+ <p className="card-row-desc">
853
+ {isArchived
854
+ ? 'The project reappears in listings and its environments serve reads again, for everyone who holds a grant on it.'
855
+ : 'Every environment stops serving reads, including to machine callers already running. Nothing is deleted, and you can restore it here at any time.'}
856
+ </p>
857
+ {error !== null && (
858
+ <div style={{ marginTop: '0.5rem' }}>
859
+ <ErrorLine error={error} />
860
+ </div>
861
+ )}
862
+ </div>
863
+ <button
864
+ className={`btn ${isArchived ? '' : 'btn-danger-outline'}`}
865
+ onClick={() => setConfirming(true)}
866
+ disabled={pending}
867
+ >
868
+ {pending ? (
869
+ <Spinner />
870
+ ) : isArchived ? (
871
+ <RotateBack size={14} />
872
+ ) : (
873
+ <Archive size={14} />
874
+ )}
875
+ {isArchived ? 'Restore project' : 'Archive project…'}
876
+ </button>
877
+ </div>
878
+
879
+ <ConfirmDialog
880
+ open={confirming}
881
+ onOpenChange={setConfirming}
882
+ title={
883
+ <>
884
+ {isArchived ? 'Restore' : 'Archive'} <span className="mono">{project.slug}</span>?
885
+ </>
886
+ }
887
+ body={
888
+ isArchived ? (
889
+ <>
890
+ The project reappears in listings and its environments start serving reads
891
+ again, for everyone who holds a grant on it.
892
+ </>
893
+ ) : (
894
+ <>
895
+ Every environment in <span className="mono">{project.slug}</span> stops serving
896
+ reads, including to machine callers already running. Nothing is deleted: values,
897
+ versions and the audit trail over them stay intact, and you can restore it here
898
+ at any time.
899
+ </>
900
+ )
901
+ }
902
+ confirmLabel={isArchived ? 'Restore project' : 'Archive project'}
903
+ destructive={!isArchived}
904
+ onConfirm={() =>
905
+ run(
906
+ () =>
907
+ coffre.projects.update(project.slug, { archived: !isArchived }),
908
+ () =>
909
+ toast.success(
910
+ isArchived ? `${project.slug} restored` : `${project.slug} archived`,
911
+ ),
912
+ )
913
+ }
914
+ />
915
+ </Card>
916
+ );
917
+ }