@coffre/ui 0.4.5 → 0.5.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 (117) hide show
  1. package/dist/chunks/{affordances-DAvsVz7u.js → affordances-Bqdevf7w.js} +10 -5
  2. package/dist/chunks/affordances-Bqdevf7w.js.map +1 -0
  3. package/dist/chunks/{audit-sentence-BhHmvQX_.js → audit-sentence-Cm5nby5k.js} +115 -8
  4. package/dist/chunks/audit-sentence-Cm5nby5k.js.map +1 -0
  5. package/dist/chunks/{connected-apps-AZsX9Zvv.js → connected-apps-DTNS7YmY.js} +2 -2
  6. package/dist/chunks/{connected-apps-AZsX9Zvv.js.map → connected-apps-DTNS7YmY.js.map} +1 -1
  7. package/dist/chunks/{delete-place-D6LIZkg9.js → delete-place-CIaOq0mt.js} +3 -3
  8. package/dist/chunks/{delete-place-D6LIZkg9.js.map → delete-place-CIaOq0mt.js.map} +1 -1
  9. package/dist/chunks/{directory-B6FuiCir.js → directory-DSVt5Tya.js} +54 -60
  10. package/dist/chunks/directory-DSVt5Tya.js.map +1 -0
  11. package/dist/chunks/{folders-DvSqBhuu.js → folders-CoGK9oqg.js} +2 -2
  12. package/dist/chunks/{folders-DvSqBhuu.js.map → folders-CoGK9oqg.js.map} +1 -1
  13. package/dist/chunks/grants-CRU7yZhL.js +164 -0
  14. package/dist/chunks/grants-CRU7yZhL.js.map +1 -0
  15. package/dist/chunks/{offboarding-CLJaNTcD.js → offboarding-DVBSiJRZ.js} +7 -3
  16. package/dist/chunks/offboarding-DVBSiJRZ.js.map +1 -0
  17. package/dist/chunks/{principal-page-UtNWKCf8.js → principal-page-BEBr_zW7.js} +350 -91
  18. package/dist/chunks/principal-page-BEBr_zW7.js.map +1 -0
  19. package/dist/chunks/{project-page-C4cEaRFa.js → project-page-B3TZ5_ig.js} +2 -2
  20. package/dist/chunks/{project-page-C4cEaRFa.js.map → project-page-B3TZ5_ig.js.map} +1 -1
  21. package/dist/chunks/{queries-Dew8mIeo.js → queries-DE5nK2y4.js} +132 -54
  22. package/dist/chunks/queries-DE5nK2y4.js.map +1 -0
  23. package/dist/chunks/{references-DWDnXNoW.js → references-uv4Mli9z.js} +4 -3
  24. package/dist/chunks/{references-DWDnXNoW.js.map → references-uv4Mli9z.js.map} +1 -1
  25. package/dist/chunks/role-field-DWhkRY6n.js +192 -0
  26. package/dist/chunks/role-field-DWhkRY6n.js.map +1 -0
  27. package/dist/chunks/use-action-BRgvbUWt.js +49 -0
  28. package/dist/chunks/use-action-BRgvbUWt.js.map +1 -0
  29. package/dist/chunks/{use-change-C4bGRhHY.js → use-change-BJ3dCFHb.js} +40 -14
  30. package/dist/chunks/use-change-BJ3dCFHb.js.map +1 -0
  31. package/dist/chunks/{use-shell-Dkv89nW1.js → use-shell-BO4ZTr1y.js} +2 -2
  32. package/dist/chunks/{use-shell-Dkv89nW1.js.map → use-shell-BO4ZTr1y.js.map} +1 -1
  33. package/dist/chunks/validation-DiHIwZRA.js +37 -0
  34. package/dist/chunks/validation-DiHIwZRA.js.map +1 -0
  35. package/dist/index.d.ts +116 -88
  36. package/dist/index.js +40 -21
  37. package/dist/index.js.map +1 -1
  38. package/dist/pages/account.js +8 -7
  39. package/dist/pages/account.js.map +1 -1
  40. package/dist/pages/approval.js +53 -21
  41. package/dist/pages/approval.js.map +1 -1
  42. package/dist/pages/audit.js +2 -2
  43. package/dist/pages/environment.js +8 -7
  44. package/dist/pages/environment.js.map +1 -1
  45. package/dist/pages/login.js +2 -2
  46. package/dist/pages/login.js.map +1 -1
  47. package/dist/pages/project-access.js +7 -7
  48. package/dist/pages/project-environments.js +26 -21
  49. package/dist/pages/project-environments.js.map +1 -1
  50. package/dist/pages/project-settings.js +9 -8
  51. package/dist/pages/project-settings.js.map +1 -1
  52. package/dist/pages/project.js +1 -1
  53. package/dist/pages/projects.js +8 -13
  54. package/dist/pages/projects.js.map +1 -1
  55. package/dist/pages/service-account.js +294 -88
  56. package/dist/pages/service-account.js.map +1 -1
  57. package/dist/pages/service-accounts.js +7 -7
  58. package/dist/pages/service-accounts.js.map +1 -1
  59. package/dist/pages/settings.js +91 -9
  60. package/dist/pages/settings.js.map +1 -1
  61. package/dist/pages/unregistered.d.ts +1 -1
  62. package/dist/pages/unregistered.js +4 -4
  63. package/dist/pages/unregistered.js.map +1 -1
  64. package/dist/pages/user.d.ts +2 -0
  65. package/dist/pages/user.js +21 -3
  66. package/dist/pages/user.js.map +1 -1
  67. package/dist/pages/users.js +4 -4
  68. package/package.json +3 -3
  69. package/src/components/affordances.ts +7 -3
  70. package/src/components/command-palette.tsx +2 -0
  71. package/src/components/directory.tsx +58 -63
  72. package/src/components/grants.tsx +9 -9
  73. package/src/components/offboarding.tsx +3 -1
  74. package/src/components/principal-page.tsx +124 -74
  75. package/src/components/role-field.tsx +183 -0
  76. package/src/components/scope-picker.tsx +73 -0
  77. package/src/components/service-tokens.tsx +20 -9
  78. package/src/components/shell.tsx +6 -10
  79. package/src/components/trusted-workloads.tsx +121 -42
  80. package/src/index.ts +1 -0
  81. package/src/lib/approval.ts +23 -0
  82. package/src/lib/audit-sentences.ts +109 -3
  83. package/src/lib/bindings.ts +33 -10
  84. package/src/lib/capabilities.ts +28 -8
  85. package/src/lib/changes.ts +22 -13
  86. package/src/lib/project-access.ts +21 -0
  87. package/src/lib/queries.ts +121 -44
  88. package/src/lib/service-setup.ts +41 -0
  89. package/src/lib/validation.ts +7 -0
  90. package/src/options.ts +31 -11
  91. package/src/pages/account.tsx +3 -2
  92. package/src/pages/approval.tsx +18 -17
  93. package/src/pages/login.tsx +1 -1
  94. package/src/pages/project-environments.tsx +12 -15
  95. package/src/pages/project-settings.tsx +3 -3
  96. package/src/pages/projects.tsx +1 -5
  97. package/src/pages/service-account.tsx +7 -5
  98. package/src/pages/service-accounts.tsx +8 -4
  99. package/src/pages/settings.tsx +80 -4
  100. package/src/pages/unregistered.tsx +3 -3
  101. package/src/pages/user.tsx +24 -1
  102. package/src/parity.ts +5 -1
  103. package/src/register.ts +3 -1
  104. package/src/shared/models.ts +8 -4
  105. package/src/styles/globals.css +111 -28
  106. package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
  107. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +0 -1
  108. package/dist/chunks/directory-B6FuiCir.js.map +0 -1
  109. package/dist/chunks/grants-9kIV6uZ7.js +0 -669
  110. package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
  111. package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
  112. package/dist/chunks/principal-page-UtNWKCf8.js.map +0 -1
  113. package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
  114. package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
  115. package/dist/chunks/validation-DvPinn8V.js +0 -87
  116. package/dist/chunks/validation-DvPinn8V.js.map +0 -1
  117. package/src/components/every-project.tsx +0 -287
@@ -1,669 +0,0 @@
1
- import { a as ErrorLine, c as Notice, l as Spinner, s as Modal, t as ConfirmButton } from "./ui-DJje3gST.js";
2
- import { J as ShieldCheck, U as Plus, it as X, j as Layers, s as memberRef, u as useCoffre, x as Clock } from "./page-DvsgZ2Hd.js";
3
- import { a as rowClass, i as RowPending, r as RowFailure } from "./row-state-DOPUsjQK.js";
4
- import { p as queries, r as keys, t as affects } from "./queries-Dew8mIeo.js";
5
- import { t as useShell } from "./use-shell-Dkv89nW1.js";
6
- import { A as projectAccessLabel, h as grantId, n as useChangeStatus, t as useChange, w as revokeGrant } from "./use-change-C4bGRhHY.js";
7
- import { a as useAction, i as slugProblem } from "./validation-DvPinn8V.js";
8
- import { useState } from "react";
9
- import { toast } from "sonner";
10
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
- import { useSuspenseQuery } from "@tanstack/react-query";
12
- import { EVERY_PROJECT, ROLES, ROLE_NAMES, assignableToEnvironment } from "@coffre/core/access";
13
- //#region src/lib/access-plan.ts
14
- /** An environment's access in a plan; slugs like `constructor` are not inherited. */
15
- function environmentAccess(plan, slug) {
16
- return Object.hasOwn(plan.environments, slug) ? plan.environments[slug] : null;
17
- }
18
- /**
19
- * Read what a principal holds on a project back into the editor's terms.
20
- * `environments` are the ones the editor can set: live, and not archived.
21
- */
22
- function planFromGrants(grants, environments) {
23
- if (grants.length === 0) return {
24
- level: "none",
25
- expiresAt: null,
26
- environments: {}
27
- };
28
- const [only] = grants;
29
- if (grants.length === 1 && only.environmentSlug === null && (only.role === "owner" || only.role === "viewer" || only.role === "developer")) return {
30
- level: only.role,
31
- expiresAt: only.expiresAt,
32
- environments: {}
33
- };
34
- const perEnvironment = {};
35
- for (const grant of grants) {
36
- const slug = grant.environmentSlug;
37
- if (slug === null || !environments.includes(slug) || Object.hasOwn(perEnvironment, slug) || grant.role !== "viewer" && grant.role !== "developer") return {
38
- level: "custom",
39
- expiresAt: null,
40
- environments: {}
41
- };
42
- perEnvironment[slug] = {
43
- role: grant.role,
44
- expiresAt: grant.expiresAt
45
- };
46
- }
47
- return {
48
- level: "env",
49
- expiresAt: null,
50
- environments: perEnvironment
51
- };
52
- }
53
- /**
54
- * Switch a plan's level. Going from read or write everywhere to per
55
- * environment starts every environment at that level and expiry, so the
56
- * switch alone keeps the same reach.
57
- */
58
- function withLevel(plan, level, environments) {
59
- if (level === "env" && (plan.level === "viewer" || plan.level === "developer") && Object.keys(plan.environments).length === 0) {
60
- const access = {
61
- role: plan.level,
62
- expiresAt: plan.expiresAt
63
- };
64
- return {
65
- ...plan,
66
- level,
67
- environments: Object.fromEntries(environments.map((slug) => [slug, access]))
68
- };
69
- }
70
- return {
71
- ...plan,
72
- level
73
- };
74
- }
75
- /** Set one environment's access, or take it away with `null`. */
76
- function withEnvironment(plan, slug, access) {
77
- const environments = { ...plan.environments };
78
- if (access === null) delete environments[slug];
79
- else environments[slug] = access;
80
- return {
81
- ...plan,
82
- environments
83
- };
84
- }
85
- function grantsFor(plan) {
86
- switch (plan.level) {
87
- case "none":
88
- case "custom": return [];
89
- case "owner":
90
- case "viewer":
91
- case "developer": return [{
92
- role: plan.level,
93
- environmentSlug: null,
94
- expiresAt: plan.expiresAt
95
- }];
96
- case "env": return Object.entries(plan.environments).map(([environmentSlug, access]) => ({
97
- environmentSlug,
98
- ...access
99
- }));
100
- }
101
- }
102
- /** The server and the date field spell the same instant differently. */
103
- function sameExpiry(a, b) {
104
- return a === b || a !== null && b !== null && Date.parse(a) === Date.parse(b);
105
- }
106
- /**
107
- * The changes that take what is held to the plan: grants to create, grants
108
- * whose expiry moves, and grants to revoke, in that order. Asking for what is
109
- * already held yields nothing, so applying the same plan twice is a no-op.
110
- */
111
- function accessChanges(grants, plan) {
112
- if (plan.level === "custom") return [];
113
- const key = (grant) => `${grant.role}@${grant.environmentSlug ?? ""}`;
114
- const wanted = new Map(grantsFor(plan).map((grant) => [key(grant), grant]));
115
- const held = new Map(grants.map((grant) => [key(grant), grant]));
116
- const changes = [];
117
- for (const [id, grant] of wanted) if (!held.has(id)) changes.push({
118
- kind: "create",
119
- ...grant
120
- });
121
- for (const [id, grant] of held) {
122
- const want = wanted.get(id);
123
- if (want !== void 0 && !sameExpiry(grant.expiresAt, want.expiresAt)) changes.push({
124
- kind: "expiry",
125
- grant,
126
- expiresAt: want.expiresAt
127
- });
128
- }
129
- for (const [id, grant] of held) if (!wanted.has(id)) changes.push({
130
- kind: "revoke",
131
- grant
132
- });
133
- return changes;
134
- }
135
- /**
136
- * The changes as the API's access patch for one project: each place it
137
- * touches, and the role to hold there until when, or `null` for none.
138
- *
139
- * { "market": null, "market/dev": { "role": "developer", "until": "2026-12-31T23:59:59.000Z" } }
140
- *
141
- * A place holds one role, so where a level changes, the revoke of the old
142
- * role and the create of the new land on the same place, and the new role
143
- * wins: the server replaces one with the other, never passing through none.
144
- */
145
- function accessPatch(project, changes) {
146
- const place = (environmentSlug) => environmentSlug === null ? project : `${project}/${environmentSlug}`;
147
- const holding = (role, expiresAt) => expiresAt === null ? role : {
148
- role,
149
- until: expiresAt
150
- };
151
- const patch = {};
152
- for (const change of changes) if (change.kind === "revoke") patch[place(change.grant.environmentSlug)] = null;
153
- for (const change of changes) {
154
- if (change.kind === "expiry") patch[place(change.grant.environmentSlug)] = holding(change.grant.role, change.expiresAt);
155
- if (change.kind === "create") patch[place(change.environmentSlug)] = holding(change.role, change.expiresAt);
156
- }
157
- return patch;
158
- }
159
- /** A date field's value as the instant access ends: the close of that day, UTC. */
160
- function expiryFromDate(date) {
161
- return date === "" ? null : (/* @__PURE__ */ new Date(`${date}T23:59:59Z`)).toISOString();
162
- }
163
- /** A date field's value for an expiry. Expiries are shown as UTC dates everywhere. */
164
- function dateFromExpiry(expiresAt) {
165
- return expiresAt === null ? "" : expiresAt.slice(0, 10);
166
- }
167
- //#endregion
168
- //#region src/components/expiry-field.tsx
169
- /**
170
- * When one grant ends, as a date: access lasts through that day, UTC. Blank
171
- * reads "Never" where the browser lets the empty field be restyled.
172
- */
173
- function ExpiryField({ label, expiresAt, onChange }) {
174
- const date = dateFromExpiry(expiresAt);
175
- return /* @__PURE__ */ jsxs("span", {
176
- className: `expiry${date === "" ? " is-never" : ""}`,
177
- children: [
178
- /* @__PURE__ */ jsx("input", {
179
- className: "input select-sm",
180
- type: "date",
181
- "aria-label": label,
182
- min: (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
183
- value: date,
184
- onChange: (event) => onChange(expiryFromDate(event.target.value))
185
- }),
186
- /* @__PURE__ */ jsx("span", {
187
- className: "expiry-never",
188
- "aria-hidden": "true",
189
- children: "Never"
190
- }),
191
- /* @__PURE__ */ jsx("button", {
192
- className: "btn btn-quiet btn-sm btn-icon",
193
- type: "button",
194
- "aria-label": `${label}: never`,
195
- title: "Never expires",
196
- onClick: () => onChange(null),
197
- children: /* @__PURE__ */ jsx(X, { size: 12 })
198
- })
199
- ]
200
- });
201
- }
202
- //#endregion
203
- //#region src/components/every-project.tsx
204
- /**
205
- * Grants on every project (`*`, the projects made later too) and on one
206
- * environment slug in every project (`*` and the slug): only owners give
207
- * and take them, here, from the CLI or the API; the pages show who holds
208
- * them to whoever sees the grants of a project they reach.
209
- */
210
- /** Where a grant on every project is, as people read it: "All projects", or "dev in every project". */
211
- function everyProjectPlace(environmentSlug) {
212
- return environmentSlug === null ? "All projects" : `${environmentSlug} in every project`;
213
- }
214
- /** The slug a grant on every project covers, from its path: null for `*`. */
215
- function slugOf(place) {
216
- return place === "*" ? null : place.slice(2);
217
- }
218
- /** The grants on every project, for those shown them: who makes places, and who manages access. */
219
- function useEveryProject() {
220
- const { data } = useSuspenseQuery(queries.projects(useCoffre()));
221
- return data.ok ? data.everyProject : [];
222
- }
223
- /** Those grants that reach a place: a project (`environment` null), or an environment of that slug. */
224
- function reaching(grants, environment) {
225
- return grants.filter((grant) => grant.place === "*" || environment !== null && slugOf(grant.place) === environment);
226
- }
227
- /** A member as a line names them: `ada@acme.example`, or a token's name. */
228
- function who(member) {
229
- return member.slice(member.indexOf(":") + 1);
230
- }
231
- /**
232
- * Who reaches a place through grants on every project, said in its dialog
233
- * before it is made or renamed: making a place there gives them access at once.
234
- */
235
- function ReachedBy({ grants, lead }) {
236
- if (grants.length === 0) return null;
237
- return /* @__PURE__ */ jsxs(Notice, {
238
- tone: "info",
239
- children: [
240
- lead,
241
- " ",
242
- grants.map((grant, index) => /* @__PURE__ */ jsxs("span", { children: [
243
- index > 0 && ", ",
244
- /* @__PURE__ */ jsx("strong", {
245
- className: "mono",
246
- children: who(grant.member)
247
- }),
248
- " (",
249
- grant.roleName.toLowerCase(),
250
- ",",
251
- " ",
252
- everyProjectPlace(slugOf(grant.place)).toLowerCase(),
253
- ")"
254
- ] }, `${grant.member} ${grant.place}`)),
255
- "."
256
- ]
257
- });
258
- }
259
- /**
260
- * One member's grants on every project, on their Access tab: "All projects ·
261
- * Developer". Owners grant and revoke them here; whoever else sees them, as
262
- * on a project they reach, sees them only.
263
- */
264
- function EveryProjectGrants({ principalType, principalId }) {
265
- const member = memberRef(principalType, principalId);
266
- const { capabilities } = useShell();
267
- const owner = capabilities.canManageGrants;
268
- const grants = useEveryProject().filter((grant) => grant.member === member);
269
- if (grants.length === 0 && !owner) return null;
270
- return /* @__PURE__ */ jsxs("section", {
271
- className: "every-project",
272
- "aria-label": "Access to every project",
273
- children: [
274
- /* @__PURE__ */ jsx("h2", {
275
- className: "section-title",
276
- children: "Every project"
277
- }),
278
- grants.length > 0 && /* @__PURE__ */ jsx("section", {
279
- className: "card",
280
- children: /* @__PURE__ */ jsx(GrantsTable, {
281
- lead: /* @__PURE__ */ jsxs("span", {
282
- className: "th",
283
- children: [/* @__PURE__ */ jsx(Layers, { size: 14 }), "Where"]
284
- }),
285
- children: grants.map((grant, index) => /* @__PURE__ */ jsx(EveryProjectRow, {
286
- number: index + 1,
287
- grant,
288
- principalId,
289
- owner
290
- }, grant.place))
291
- })
292
- }),
293
- owner ? /* @__PURE__ */ jsx("div", {
294
- className: "table-actions",
295
- children: /* @__PURE__ */ jsx(GrantEveryProject, {
296
- principalType,
297
- principalId
298
- })
299
- }) : /* @__PURE__ */ jsx("p", {
300
- className: "hint section-foot",
301
- children: "Only owners grant or revoke on every project."
302
- })
303
- ]
304
- });
305
- }
306
- function EveryProjectRow({ number, grant, principalId, owner }) {
307
- const coffre = useCoffre();
308
- const { pending, error, run } = useAction();
309
- const where = everyProjectPlace(slugOf(grant.place));
310
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("tr", { children: [
311
- /* @__PURE__ */ jsx("td", {
312
- className: "n",
313
- children: number
314
- }),
315
- /* @__PURE__ */ jsx("td", {
316
- className: "col-lead",
317
- "data-label": "Where",
318
- children: where
319
- }),
320
- /* @__PURE__ */ jsx("td", {
321
- className: "col-access",
322
- "data-label": "Permissions",
323
- children: /* @__PURE__ */ jsx("span", {
324
- className: `tag${grant.role === "owner" ? " tag-violet" : ""}`,
325
- children: grant.roleName
326
- })
327
- }),
328
- /* @__PURE__ */ jsx("td", {
329
- className: `col-expires cell-mono cell-muted${grant.expiresAt === null ? " is-never" : ""}`,
330
- "data-label": "Expires",
331
- children: grant.expiresAt === null ? "Never" : grant.expiresAt.slice(0, 10)
332
- }),
333
- /* @__PURE__ */ jsx("td", {
334
- className: "col-actions",
335
- children: owner && /* @__PURE__ */ jsx(ConfirmButton, {
336
- trigger: /* @__PURE__ */ jsx("button", {
337
- className: "act act-danger",
338
- disabled: pending,
339
- children: "Revoke"
340
- }),
341
- title: /* @__PURE__ */ jsxs(Fragment$1, { children: [
342
- "Revoke ",
343
- grant.roleName.toLowerCase(),
344
- " on ",
345
- where.toLowerCase(),
346
- " from ",
347
- /* @__PURE__ */ jsx("span", {
348
- className: "mono",
349
- children: principalId
350
- }),
351
- "?"
352
- ] }),
353
- body: /* @__PURE__ */ jsx(Fragment$1, { children: "They lose it at once, wherever it reaches, including any process using it right now. Grants they hold on projects themselves still apply." }),
354
- confirmLabel: "Revoke access",
355
- onConfirm: () => run(() => coffre.access.set(grant.member, { [grant.place]: null }), {
356
- affects: affects.everyProject(grant.member),
357
- onSuccess: () => toast.success(`Revoked ${grant.roleName.toLowerCase()} on ${where.toLowerCase()}`)
358
- })
359
- })
360
- })
361
- ] }), error !== null && /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
362
- colSpan: 5,
363
- children: /* @__PURE__ */ jsx(ErrorLine, { error })
364
- }) })] });
365
- }
366
- /** The roles a grant on every project takes: all of them, or, on one environment name, those an environment can hold. */
367
- var ROLE_CHOICES = ROLE_NAMES.map((role) => ({
368
- role,
369
- name: ROLES[role].name,
370
- environment: assignableToEnvironment(role)
371
- }));
372
- /**
373
- * Give a member a role on every project, the ones created later too, or on
374
- * one environment name in every project. Owners only, as the API.
375
- */
376
- function GrantEveryProject({ principalType, principalId }) {
377
- const coffre = useCoffre();
378
- const member = memberRef(principalType, principalId);
379
- const [open, setOpen] = useState(false);
380
- const [environment, setEnvironment] = useState("");
381
- const [role, setRole] = useState("viewer");
382
- const [expiresAt, setExpiresAt] = useState(null);
383
- const { pending, error, setError, run } = useAction();
384
- const slug = environment.trim();
385
- const slugError = slug === "" ? null : slugProblem(slug);
386
- const roles = ROLE_CHOICES.filter((choice) => slug === "" || choice.environment);
387
- const chosen = roles.some((choice) => choice.role === role) ? role : "viewer";
388
- const where = everyProjectPlace(slug === "" ? null : slug);
389
- function close() {
390
- setOpen(false);
391
- setEnvironment("");
392
- setRole("viewer");
393
- setExpiresAt(null);
394
- setError(null);
395
- }
396
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("button", {
397
- className: "btn",
398
- onClick: () => setOpen(true),
399
- children: [/* @__PURE__ */ jsx(Plus, { size: 14 }), "Grant on every project"]
400
- }), /* @__PURE__ */ jsx(Modal, {
401
- open,
402
- onOpenChange: (next) => next ? setOpen(true) : close(),
403
- title: /* @__PURE__ */ jsxs(Fragment$1, { children: [
404
- "Grant ",
405
- /* @__PURE__ */ jsx("span", {
406
- className: "mono",
407
- children: principalId
408
- }),
409
- " on every project"
410
- ] }),
411
- description: "A role on every project, including ones created later. With an environment name, only the environment of that name in each project.",
412
- children: /* @__PURE__ */ jsxs("form", {
413
- className: "form",
414
- onSubmit: (event) => {
415
- event.preventDefault();
416
- const place = slug === "" ? EVERY_PROJECT : `${EVERY_PROJECT}/${slug}`;
417
- run(() => coffre.access.set(member, { [place]: expiresAt === null ? chosen : {
418
- role: chosen,
419
- until: expiresAt
420
- } }), {
421
- affects: affects.everyProject(member),
422
- onSuccess: () => {
423
- toast.success(`Granted ${ROLES[chosen].name.toLowerCase()} on ${where.toLowerCase()}`);
424
- close();
425
- }
426
- });
427
- },
428
- children: [
429
- /* @__PURE__ */ jsxs("label", {
430
- className: "field",
431
- children: [
432
- /* @__PURE__ */ jsx("span", {
433
- className: "label",
434
- children: "Environment name"
435
- }),
436
- /* @__PURE__ */ jsx("input", {
437
- className: "input input-mono",
438
- spellCheck: false,
439
- autoComplete: "off",
440
- placeholder: "Every environment",
441
- value: environment,
442
- "aria-invalid": slugError !== null,
443
- "aria-describedby": "every-project-environment-hint",
444
- onChange: (event) => setEnvironment(event.target.value)
445
- }),
446
- /* @__PURE__ */ jsx("span", {
447
- className: `hint${slugError !== null ? " edit-note-error" : ""}`,
448
- id: "every-project-environment-hint",
449
- children: slugError ?? (slug === "" ? "Every environment of every project." : `Only the environment named ${slug} in each project, including projects created later.`)
450
- })
451
- ]
452
- }),
453
- /* @__PURE__ */ jsxs("div", {
454
- className: "form-row",
455
- children: [/* @__PURE__ */ jsxs("label", {
456
- className: "field",
457
- style: { flexGrow: 2 },
458
- children: [/* @__PURE__ */ jsx("span", {
459
- className: "label",
460
- children: "Role"
461
- }), /* @__PURE__ */ jsx("select", {
462
- className: "select",
463
- value: chosen,
464
- onChange: (event) => setRole(event.target.value),
465
- children: roles.map((choice) => /* @__PURE__ */ jsx("option", {
466
- value: choice.role,
467
- children: choice.name
468
- }, choice.role))
469
- })]
470
- }), /* @__PURE__ */ jsxs("label", {
471
- className: "field",
472
- children: [/* @__PURE__ */ jsx("span", {
473
- className: "label",
474
- children: "Expires"
475
- }), /* @__PURE__ */ jsx(ExpiryField, {
476
- label: "Expires",
477
- expiresAt,
478
- onChange: setExpiresAt
479
- })]
480
- })]
481
- }),
482
- /* @__PURE__ */ jsxs("p", {
483
- className: "hint",
484
- children: [
485
- where,
486
- " · ",
487
- ROLES[chosen].name,
488
- ": ",
489
- ROLES[chosen].description
490
- ]
491
- }),
492
- /* @__PURE__ */ jsx(ErrorLine, { error }),
493
- /* @__PURE__ */ jsxs("div", {
494
- className: "dialog-actions",
495
- children: [/* @__PURE__ */ jsx("button", {
496
- className: "btn",
497
- type: "button",
498
- onClick: close,
499
- children: "Cancel"
500
- }), /* @__PURE__ */ jsx("button", {
501
- className: "btn btn-primary",
502
- type: "submit",
503
- disabled: pending || slugError !== null,
504
- children: pending ? /* @__PURE__ */ jsx(Spinner, {}) : "Grant"
505
- })]
506
- })
507
- ]
508
- })
509
- })] });
510
- }
511
- //#endregion
512
- //#region src/components/grants.tsx
513
- /**
514
- * Grants as a table: who or where in the first column, then the access, when
515
- * it lapses, and a revoke.
516
- *
517
- * A project's page leads each row with the principal; a user's page leads with
518
- * the project. Everything after the first column is the same grant either way.
519
- */
520
- function GrantsTable({ lead, children }) {
521
- return /* @__PURE__ */ jsx("div", {
522
- className: "dt-wrap",
523
- children: /* @__PURE__ */ jsxs("table", {
524
- className: "dt grants stacks",
525
- children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
526
- /* @__PURE__ */ jsx("th", {
527
- className: "n",
528
- children: "#"
529
- }),
530
- /* @__PURE__ */ jsx("th", {
531
- className: "col-principal",
532
- children: lead
533
- }),
534
- /* @__PURE__ */ jsx("th", { children: /* @__PURE__ */ jsxs("span", {
535
- className: "th",
536
- children: [/* @__PURE__ */ jsx(ShieldCheck, { size: 14 }), "Permissions"]
537
- }) }),
538
- /* @__PURE__ */ jsx("th", {
539
- className: "col-expires",
540
- children: /* @__PURE__ */ jsxs("span", {
541
- className: "th",
542
- children: [/* @__PURE__ */ jsx(Clock, { size: 14 }), "Expires"]
543
- })
544
- }),
545
- /* @__PURE__ */ jsx("th", {
546
- className: "col-actions",
547
- children: /* @__PURE__ */ jsx("span", {
548
- className: "visually-hidden",
549
- children: "Actions"
550
- })
551
- })
552
- ] }) }), /* @__PURE__ */ jsx("tbody", { children })]
553
- })
554
- });
555
- }
556
- function GrantRowView({ number, project, grant, lead, leadLabel }) {
557
- const revoke = useChange(revokeGrant(useCoffre(), project));
558
- const { status, dismiss } = useChangeStatus(keys.grants(project));
559
- const state = status(grantId(grant));
560
- const everywhere = grant.scope === "every-project";
561
- const label = everywhere ? `${everyProjectPlace(grant.environmentSlug)} · ${grant.roleName}` : projectAccessLabel(grant);
562
- const expired = grant.expiresAt !== null && new Date(grant.expiresAt).getTime() < Date.now();
563
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("tr", {
564
- className: rowClass(state),
565
- children: [
566
- /* @__PURE__ */ jsx("td", {
567
- className: "n",
568
- children: number
569
- }),
570
- /* @__PURE__ */ jsx("td", {
571
- className: "col-lead",
572
- "data-label": leadLabel,
573
- children: lead
574
- }),
575
- /* @__PURE__ */ jsx("td", {
576
- className: "col-access",
577
- "data-label": "Permissions",
578
- children: /* @__PURE__ */ jsx("span", {
579
- className: `tag${grant.role === "owner" ? " tag-violet" : ""}`,
580
- children: label
581
- })
582
- }),
583
- /* @__PURE__ */ jsx("td", {
584
- className: `col-expires cell-mono cell-muted${grant.expiresAt === null ? " is-never" : ""}`,
585
- "data-label": "Expires",
586
- children: grant.expiresAt === null ? "Never" : /* @__PURE__ */ jsxs(Fragment$1, { children: [
587
- /* @__PURE__ */ jsx("span", {
588
- className: "narrow-only",
589
- children: "Expires "
590
- }),
591
- grant.expiresAt.slice(0, 10),
592
- expired && /* @__PURE__ */ jsxs(Fragment$1, { children: [" ", /* @__PURE__ */ jsx("span", {
593
- className: "tag tag-red",
594
- children: "Expired"
595
- })] })
596
- ] })
597
- }),
598
- /* @__PURE__ */ jsx("td", {
599
- className: "col-actions",
600
- children: state.state === "pending" ? /* @__PURE__ */ jsx(RowPending, { status: state }) : everywhere ? /* @__PURE__ */ jsx("span", {
601
- className: "cell-muted every-project-note",
602
- title: "Owners change grants on every project with coffre grant '*' and coffre revoke '*'",
603
- children: "every project"
604
- }) : /* @__PURE__ */ jsx(ConfirmButton, {
605
- trigger: /* @__PURE__ */ jsx("button", {
606
- className: "act act-danger",
607
- children: "Revoke"
608
- }),
609
- title: /* @__PURE__ */ jsxs(Fragment$1, { children: [
610
- "Revoke ",
611
- label,
612
- " from ",
613
- /* @__PURE__ */ jsx("span", {
614
- className: "mono",
615
- children: grant.principalId
616
- }),
617
- "?"
618
- ] }),
619
- body: /* @__PURE__ */ jsxs(Fragment$1, { children: [
620
- "They lose ",
621
- /* @__PURE__ */ jsx("strong", { children: label }),
622
- " on ",
623
- /* @__PURE__ */ jsx("span", {
624
- className: "mono",
625
- children: project
626
- }),
627
- " ",
628
- "immediately, including any process using it right now. Other grants they hold still apply."
629
- ] }),
630
- confirmLabel: "Revoke access",
631
- onConfirm: () => revoke(grant)
632
- })
633
- })
634
- ]
635
- }), /* @__PURE__ */ jsx(RowFailure, {
636
- status: state,
637
- columns: 5,
638
- onDismiss: () => state.state === "failed" && dismiss(state.mutationId)
639
- })] });
640
- }
641
- /**
642
- * Grants the server refused to give: rolled back, so no row of theirs is
643
- * left, and listed here, after the table's rows, saying why.
644
- */
645
- function RefusedGrants({ refused }) {
646
- return refused.map(({ mutationId, vars, status, dismiss }) => /* @__PURE__ */ jsxs(RowFailure, {
647
- status,
648
- columns: 5,
649
- onDismiss: dismiss,
650
- children: [
651
- vars.principalId,
652
- " was not given ",
653
- vars.roleName.toLowerCase(),
654
- "."
655
- ]
656
- }, mutationId));
657
- }
658
- /** The grants of one kind the server refused to give in a project, still to be said. */
659
- function useRefusedGrants(project, grants, principalType) {
660
- const { failedAdds, dismiss } = useChangeStatus(keys.grants(project));
661
- return failedAdds(grants.map(grantId)).filter(({ vars }) => principalType === void 0 || vars.principalType === principalType).map((refused) => ({
662
- ...refused,
663
- dismiss: () => dismiss(refused.mutationId)
664
- }));
665
- }
666
- //#endregion
667
- export { EveryProjectGrants as a, useEveryProject as c, accessPatch as d, dateFromExpiry as f, withLevel as g, withEnvironment as h, useRefusedGrants as i, ExpiryField as l, planFromGrants as m, GrantsTable as n, ReachedBy as o, environmentAccess as p, RefusedGrants as r, reaching as s, GrantRowView as t, accessChanges as u };
668
-
669
- //# sourceMappingURL=grants-9kIV6uZ7.js.map