@coffre/ui 0.4.6 → 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 (113) 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-DIztXvbU.js → audit-sentence-Cm5nby5k.js} +105 -7
  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-1yMztIcc.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 +111 -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/audit.js +2 -2
  41. package/dist/pages/environment.js +8 -7
  42. package/dist/pages/environment.js.map +1 -1
  43. package/dist/pages/login.js +2 -2
  44. package/dist/pages/login.js.map +1 -1
  45. package/dist/pages/project-access.js +7 -7
  46. package/dist/pages/project-environments.js +26 -21
  47. package/dist/pages/project-environments.js.map +1 -1
  48. package/dist/pages/project-settings.js +9 -8
  49. package/dist/pages/project-settings.js.map +1 -1
  50. package/dist/pages/project.js +1 -1
  51. package/dist/pages/projects.js +8 -13
  52. package/dist/pages/projects.js.map +1 -1
  53. package/dist/pages/service-account.js +294 -88
  54. package/dist/pages/service-account.js.map +1 -1
  55. package/dist/pages/service-accounts.js +7 -7
  56. package/dist/pages/service-accounts.js.map +1 -1
  57. package/dist/pages/settings.js +91 -9
  58. package/dist/pages/settings.js.map +1 -1
  59. package/dist/pages/unregistered.d.ts +1 -1
  60. package/dist/pages/unregistered.js +4 -4
  61. package/dist/pages/unregistered.js.map +1 -1
  62. package/dist/pages/user.d.ts +2 -0
  63. package/dist/pages/user.js +21 -3
  64. package/dist/pages/user.js.map +1 -1
  65. package/dist/pages/users.js +4 -4
  66. package/package.json +3 -3
  67. package/src/components/affordances.ts +7 -3
  68. package/src/components/command-palette.tsx +2 -0
  69. package/src/components/directory.tsx +58 -63
  70. package/src/components/grants.tsx +9 -9
  71. package/src/components/offboarding.tsx +3 -1
  72. package/src/components/principal-page.tsx +124 -74
  73. package/src/components/role-field.tsx +183 -0
  74. package/src/components/scope-picker.tsx +73 -0
  75. package/src/components/service-tokens.tsx +20 -9
  76. package/src/components/shell.tsx +6 -10
  77. package/src/components/trusted-workloads.tsx +121 -42
  78. package/src/index.ts +1 -0
  79. package/src/lib/audit-sentences.ts +104 -3
  80. package/src/lib/bindings.ts +33 -10
  81. package/src/lib/capabilities.ts +28 -8
  82. package/src/lib/changes.ts +22 -13
  83. package/src/lib/project-access.ts +21 -0
  84. package/src/lib/queries.ts +121 -44
  85. package/src/lib/service-setup.ts +41 -0
  86. package/src/lib/validation.ts +7 -0
  87. package/src/options.ts +31 -11
  88. package/src/pages/account.tsx +3 -2
  89. package/src/pages/login.tsx +1 -1
  90. package/src/pages/project-environments.tsx +12 -15
  91. package/src/pages/project-settings.tsx +3 -3
  92. package/src/pages/projects.tsx +1 -5
  93. package/src/pages/service-account.tsx +7 -5
  94. package/src/pages/service-accounts.tsx +8 -4
  95. package/src/pages/settings.tsx +80 -4
  96. package/src/pages/unregistered.tsx +3 -3
  97. package/src/pages/user.tsx +24 -1
  98. package/src/parity.ts +5 -1
  99. package/src/register.ts +3 -1
  100. package/src/shared/models.ts +8 -4
  101. package/src/styles/globals.css +100 -27
  102. package/dist/chunks/affordances-DAvsVz7u.js.map +0 -1
  103. package/dist/chunks/audit-sentence-DIztXvbU.js.map +0 -1
  104. package/dist/chunks/directory-B6FuiCir.js.map +0 -1
  105. package/dist/chunks/grants-9kIV6uZ7.js +0 -669
  106. package/dist/chunks/grants-9kIV6uZ7.js.map +0 -1
  107. package/dist/chunks/offboarding-CLJaNTcD.js.map +0 -1
  108. package/dist/chunks/principal-page-1yMztIcc.js.map +0 -1
  109. package/dist/chunks/queries-Dew8mIeo.js.map +0 -1
  110. package/dist/chunks/use-change-C4bGRhHY.js.map +0 -1
  111. package/dist/chunks/validation-DvPinn8V.js +0 -87
  112. package/dist/chunks/validation-DvPinn8V.js.map +0 -1
  113. package/src/components/every-project.tsx +0 -287
@@ -1,287 +0,0 @@
1
- import { useState } from 'react';
2
- import { useSuspenseQuery } from '@tanstack/react-query';
3
- import { toast } from 'sonner';
4
- import type { InheritedGrant } from '@coffre/client';
5
- import { assignableToEnvironment, EVERY_PROJECT, ROLE_NAMES, ROLES, type Role } from '@coffre/core/access';
6
- import { memberRef, useCoffre } from '../lib/coffre';
7
- import { affects, queries } from '../lib/queries';
8
- import { useAction } from '../lib/use-action';
9
- import { useShell } from '../lib/use-shell';
10
- import { slugProblem } from '../lib/validation';
11
- import { ExpiryField } from './expiry-field';
12
- import { GrantsTable } from './grants';
13
- import { Layers, Plus } from './icons';
14
- import { ConfirmButton, ErrorLine, Modal, Notice, Spinner } from './ui';
15
-
16
- /**
17
- * Grants on every project (`*`, the projects made later too) and on one
18
- * environment slug in every project (`*` and the slug): only owners give
19
- * and take them, here, from the CLI or the API; the pages show who holds
20
- * them to whoever sees the grants of a project they reach.
21
- */
22
-
23
- /** Where a grant on every project is, as people read it: "All projects", or "dev in every project". */
24
- export function everyProjectPlace(environmentSlug: string | null): string {
25
- return environmentSlug === null ? 'All projects' : `${environmentSlug} in every project`;
26
- }
27
-
28
- /** The slug a grant on every project covers, from its path: null for `*`. */
29
- function slugOf(place: string): string | null {
30
- return place === '*' ? null : place.slice('*/'.length);
31
- }
32
-
33
- /** The grants on every project, for those shown them: who makes places, and who manages access. */
34
- export function useEveryProject(): InheritedGrant[] {
35
- const { data } = useSuspenseQuery(queries.projects(useCoffre()));
36
- return data.ok ? data.everyProject : [];
37
- }
38
-
39
- /** Those grants that reach a place: a project (`environment` null), or an environment of that slug. */
40
- export function reaching(grants: InheritedGrant[], environment: string | null): InheritedGrant[] {
41
- return grants.filter((grant) => grant.place === '*' || (environment !== null && slugOf(grant.place) === environment));
42
- }
43
-
44
- /** A member as a line names them: `ada@acme.example`, or a token's name. */
45
- function who(member: string): string {
46
- return member.slice(member.indexOf(':') + 1);
47
- }
48
-
49
- /**
50
- * Who reaches a place through grants on every project, said in its dialog
51
- * before it is made or renamed: making a place there gives them access at once.
52
- */
53
- export function ReachedBy({ grants, lead }: { grants: InheritedGrant[]; lead: string }) {
54
- if (grants.length === 0) return null;
55
- return (
56
- <Notice tone="info">
57
- {lead}{' '}
58
- {grants.map((grant, index) => (
59
- <span key={`${grant.member} ${grant.place}`}>
60
- {index > 0 && ', '}
61
- <strong className="mono">{who(grant.member)}</strong> ({grant.roleName.toLowerCase()},{' '}
62
- {everyProjectPlace(slugOf(grant.place)).toLowerCase()})
63
- </span>
64
- ))}
65
- .
66
- </Notice>
67
- );
68
- }
69
-
70
- /**
71
- * One member's grants on every project, on their Access tab: "All projects ·
72
- * Developer". Owners grant and revoke them here; whoever else sees them, as
73
- * on a project they reach, sees them only.
74
- */
75
- export function EveryProjectGrants({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
76
- const member = memberRef(principalType, principalId);
77
- const { capabilities } = useShell();
78
- const owner = capabilities.canManageGrants;
79
- const grants = useEveryProject().filter((grant) => grant.member === member);
80
- if (grants.length === 0 && !owner) return null;
81
- return (
82
- <section className="every-project" aria-label="Access to every project">
83
- <h2 className="section-title">Every project</h2>
84
- {grants.length > 0 && (
85
- <section className="card">
86
- <GrantsTable
87
- lead={
88
- <span className="th">
89
- <Layers size={14} />
90
- Where
91
- </span>
92
- }
93
- >
94
- {grants.map((grant, index) => (
95
- <EveryProjectRow key={grant.place} number={index + 1} grant={grant} principalId={principalId} owner={owner} />
96
- ))}
97
- </GrantsTable>
98
- </section>
99
- )}
100
- {owner ? (
101
- <div className="table-actions">
102
- <GrantEveryProject principalType={principalType} principalId={principalId} />
103
- </div>
104
- ) : (
105
- <p className="hint section-foot">Only owners grant or revoke on every project.</p>
106
- )}
107
- </section>
108
- );
109
- }
110
-
111
- function EveryProjectRow({ number, grant, principalId, owner }: { number: number; grant: InheritedGrant; principalId: string; owner: boolean }) {
112
- const coffre = useCoffre();
113
- const { pending, error, run } = useAction();
114
- const where = everyProjectPlace(slugOf(grant.place));
115
- return (
116
- <>
117
- <tr>
118
- <td className="n">{number}</td>
119
- <td className="col-lead" data-label="Where">
120
- {where}
121
- </td>
122
- <td className="col-access" data-label="Permissions">
123
- <span className={`tag${grant.role === 'owner' ? ' tag-violet' : ''}`}>{grant.roleName}</span>
124
- </td>
125
- <td className={`col-expires cell-mono cell-muted${grant.expiresAt === null ? ' is-never' : ''}`} data-label="Expires">
126
- {grant.expiresAt === null ? 'Never' : grant.expiresAt.slice(0, 10)}
127
- </td>
128
- <td className="col-actions">
129
- {owner && (
130
- <ConfirmButton
131
- trigger={
132
- <button className="act act-danger" disabled={pending}>
133
- Revoke
134
- </button>
135
- }
136
- title={
137
- <>
138
- Revoke {grant.roleName.toLowerCase()} on {where.toLowerCase()} from <span className="mono">{principalId}</span>?
139
- </>
140
- }
141
- body={
142
- <>
143
- They lose it at once, wherever it reaches, including any process using it right now.
144
- Grants they hold on projects themselves still apply.
145
- </>
146
- }
147
- confirmLabel="Revoke access"
148
- onConfirm={() =>
149
- run(() => coffre.access.set(grant.member, { [grant.place]: null }), {
150
- affects: affects.everyProject(grant.member),
151
- onSuccess: () => toast.success(`Revoked ${grant.roleName.toLowerCase()} on ${where.toLowerCase()}`),
152
- })
153
- }
154
- />
155
- )}
156
- </td>
157
- </tr>
158
- {error !== null && (
159
- <tr>
160
- <td colSpan={5}>
161
- <ErrorLine error={error} />
162
- </td>
163
- </tr>
164
- )}
165
- </>
166
- );
167
- }
168
-
169
- /** The roles a grant on every project takes: all of them, or, on one environment name, those an environment can hold. */
170
- const ROLE_CHOICES: { role: Role; name: string; environment: boolean }[] = ROLE_NAMES.map((role) => ({
171
- role,
172
- name: ROLES[role].name,
173
- environment: assignableToEnvironment(role),
174
- }));
175
-
176
- /**
177
- * Give a member a role on every project, the ones created later too, or on
178
- * one environment name in every project. Owners only, as the API.
179
- */
180
- function GrantEveryProject({ principalType, principalId }: { principalType: 'user' | 'service'; principalId: string }) {
181
- const coffre = useCoffre();
182
- const member = memberRef(principalType, principalId);
183
- const [open, setOpen] = useState(false);
184
- const [environment, setEnvironment] = useState('');
185
- const [role, setRole] = useState<Role>('viewer');
186
- const [expiresAt, setExpiresAt] = useState<string | null>(null);
187
- const { pending, error, setError, run } = useAction();
188
- const slug = environment.trim();
189
- const slugError = slug === '' ? null : slugProblem(slug);
190
- const roles = ROLE_CHOICES.filter((choice) => slug === '' || choice.environment);
191
- const chosen = roles.some((choice) => choice.role === role) ? role : 'viewer';
192
- const where = everyProjectPlace(slug === '' ? null : slug);
193
-
194
- function close() {
195
- setOpen(false);
196
- setEnvironment('');
197
- setRole('viewer');
198
- setExpiresAt(null);
199
- setError(null);
200
- }
201
-
202
- return (
203
- <>
204
- <button className="btn" onClick={() => setOpen(true)}>
205
- <Plus size={14} />
206
- Grant on every project
207
- </button>
208
-
209
- <Modal
210
- open={open}
211
- onOpenChange={(next) => (next ? setOpen(true) : close())}
212
- title={
213
- <>
214
- Grant <span className="mono">{principalId}</span> on every project
215
- </>
216
- }
217
- description="A role on every project, including ones created later. With an environment name, only the environment of that name in each project."
218
- >
219
- <form
220
- className="form"
221
- onSubmit={(event) => {
222
- event.preventDefault();
223
- const place = slug === '' ? EVERY_PROJECT : `${EVERY_PROJECT}/${slug}`;
224
- run(() => coffre.access.set(member, { [place]: expiresAt === null ? chosen : { role: chosen, until: expiresAt } }), {
225
- affects: affects.everyProject(member),
226
- onSuccess: () => {
227
- toast.success(`Granted ${ROLES[chosen].name.toLowerCase()} on ${where.toLowerCase()}`);
228
- close();
229
- },
230
- });
231
- }}
232
- >
233
- <label className="field">
234
- <span className="label">Environment name</span>
235
- <input
236
- className="input input-mono"
237
- spellCheck={false}
238
- autoComplete="off"
239
- placeholder="Every environment"
240
- value={environment}
241
- aria-invalid={slugError !== null}
242
- aria-describedby="every-project-environment-hint"
243
- onChange={(event) => setEnvironment(event.target.value)}
244
- />
245
- <span className={`hint${slugError !== null ? ' edit-note-error' : ''}`} id="every-project-environment-hint">
246
- {slugError ??
247
- (slug === ''
248
- ? 'Every environment of every project.'
249
- : `Only the environment named ${slug} in each project, including projects created later.`)}
250
- </span>
251
- </label>
252
-
253
- <div className="form-row">
254
- <label className="field" style={{ flexGrow: 2 }}>
255
- <span className="label">Role</span>
256
- <select className="select" value={chosen} onChange={(event) => setRole(event.target.value as Role)}>
257
- {roles.map((choice) => (
258
- <option key={choice.role} value={choice.role}>
259
- {choice.name}
260
- </option>
261
- ))}
262
- </select>
263
- </label>
264
- <label className="field">
265
- <span className="label">Expires</span>
266
- <ExpiryField label="Expires" expiresAt={expiresAt} onChange={setExpiresAt} />
267
- </label>
268
- </div>
269
-
270
- <p className="hint">
271
- {where} · {ROLES[chosen].name}: {ROLES[chosen].description}
272
- </p>
273
- <ErrorLine error={error} />
274
-
275
- <div className="dialog-actions">
276
- <button className="btn" type="button" onClick={close}>
277
- Cancel
278
- </button>
279
- <button className="btn btn-primary" type="submit" disabled={pending || slugError !== null}>
280
- {pending ? <Spinner /> : 'Grant'}
281
- </button>
282
- </div>
283
- </form>
284
- </Modal>
285
- </>
286
- );
287
- }