@coffre/ui 0.15.0 → 0.16.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 (139) hide show
  1. package/dist/audit-sentences.d.ts +56 -0
  2. package/dist/audit-sentences.js +886 -0
  3. package/dist/audit-sentences.js.map +1 -0
  4. package/dist/chunks/audit-sentence-C8NnAdjF.js +48 -0
  5. package/dist/chunks/audit-sentence-C8NnAdjF.js.map +1 -0
  6. package/dist/chunks/{connected-apps-CGUQlFMx.js → connected-apps-6sMSgQ9U.js} +5 -5
  7. package/dist/chunks/{connected-apps-CGUQlFMx.js.map → connected-apps-6sMSgQ9U.js.map} +1 -1
  8. package/dist/chunks/{delete-place-CswZ-meh.js → delete-place-T469tSN9.js} +5 -5
  9. package/dist/chunks/{delete-place-CswZ-meh.js.map → delete-place-T469tSN9.js.map} +1 -1
  10. package/dist/chunks/{directory-DrswWQLT.js → directory-B_gVf7UL.js} +18 -17
  11. package/dist/chunks/directory-B_gVf7UL.js.map +1 -0
  12. package/dist/chunks/{folders-A6sbR_PG.js → folders-CVYauIDz.js} +3 -3
  13. package/dist/chunks/{folders-A6sbR_PG.js.map → folders-CVYauIDz.js.map} +1 -1
  14. package/dist/chunks/{grants-C0cb2oii.js → grants-Dn_EW2XW.js} +8 -8
  15. package/dist/chunks/grants-Dn_EW2XW.js.map +1 -0
  16. package/dist/chunks/{multi-combobox-B3SEv1gq.js → multi-combobox-fbBRzi9z.js} +3 -3
  17. package/dist/chunks/{multi-combobox-B3SEv1gq.js.map → multi-combobox-fbBRzi9z.js.map} +1 -1
  18. package/dist/chunks/{offboarding-C1jbG_dk.js → offboarding-CXM464J_.js} +81 -80
  19. package/dist/chunks/offboarding-CXM464J_.js.map +1 -0
  20. package/dist/chunks/{page-CfhC9Hp1.js → page-Cb0ZjGda.js} +7 -12
  21. package/dist/chunks/page-Cb0ZjGda.js.map +1 -0
  22. package/dist/chunks/{personal-tokens-xC9wulhg.js → personal-tokens-CSHMlRHy.js} +7 -7
  23. package/dist/chunks/personal-tokens-CSHMlRHy.js.map +1 -0
  24. package/dist/chunks/{principal-CI17XK13.js → principal-BKJxbAtE.js} +2 -2
  25. package/dist/chunks/{principal-CI17XK13.js.map → principal-BKJxbAtE.js.map} +1 -1
  26. package/dist/chunks/{principal-page-CdSeftGD.js → principal-page-COPmTDVW.js} +132 -19
  27. package/dist/chunks/principal-page-COPmTDVW.js.map +1 -0
  28. package/dist/chunks/{project-page-CHxjBE97.js → project-page-g5_n46Nz.js} +3 -3
  29. package/dist/chunks/{project-page-CHxjBE97.js.map → project-page-g5_n46Nz.js.map} +1 -1
  30. package/dist/chunks/protected-DEWeOrmI.js +77 -0
  31. package/dist/chunks/protected-DEWeOrmI.js.map +1 -0
  32. package/dist/chunks/{queries-D1JuimTu.js → queries-D4_o-bz3.js} +22 -155
  33. package/dist/chunks/queries-D4_o-bz3.js.map +1 -0
  34. package/dist/chunks/{references-D5llUGQL.js → references-wTh_DT0M.js} +27 -23
  35. package/dist/chunks/references-wTh_DT0M.js.map +1 -0
  36. package/dist/chunks/{role-field-CoCv8wse.js → role-field-BiP09qfN.js} +5 -5
  37. package/dist/chunks/role-field-BiP09qfN.js.map +1 -0
  38. package/dist/chunks/{row-state-CYH7kZHl.js → row-state-CYhtmUkc.js} +3 -3
  39. package/dist/chunks/{row-state-CYH7kZHl.js.map → row-state-CYhtmUkc.js.map} +1 -1
  40. package/dist/chunks/{signin-errors-TlQmQe0t.js → signin-errors-BMnox7XD.js} +5 -19
  41. package/dist/chunks/signin-errors-BMnox7XD.js.map +1 -0
  42. package/dist/chunks/{theme-rF44Wbmm.js → theme-imSolE1q.js} +3 -3
  43. package/dist/chunks/{theme-rF44Wbmm.js.map → theme-imSolE1q.js.map} +1 -1
  44. package/dist/chunks/{ui-CGdORVzW.js → ui-Q_Eczt7m.js} +7 -3
  45. package/dist/chunks/{ui-CGdORVzW.js.map → ui-Q_Eczt7m.js.map} +1 -1
  46. package/dist/chunks/{use-action-BxrHTBZw.js → use-action-BfnN-De2.js} +3 -3
  47. package/dist/chunks/{use-action-BxrHTBZw.js.map → use-action-BfnN-De2.js.map} +1 -1
  48. package/dist/chunks/{use-change-BorW2R6C.js → use-change-Cc0X4sF3.js} +6 -4
  49. package/dist/chunks/use-change-Cc0X4sF3.js.map +1 -0
  50. package/dist/chunks/{use-roles-BZnJ9Cq0.js → use-roles-stcv2QFj.js} +13 -56
  51. package/dist/chunks/use-roles-stcv2QFj.js.map +1 -0
  52. package/dist/chunks/{use-shell-CPskgi1k.js → use-shell-DMhLa2sh.js} +3 -3
  53. package/dist/chunks/{use-shell-CPskgi1k.js.map → use-shell-DMhLa2sh.js.map} +1 -1
  54. package/dist/index.d.ts +23 -55
  55. package/dist/index.js +12 -31
  56. package/dist/index.js.map +1 -1
  57. package/dist/pages/account.js +12 -12
  58. package/dist/pages/account.js.map +1 -1
  59. package/dist/pages/approval.js +2 -2
  60. package/dist/pages/audit.js +173 -196
  61. package/dist/pages/audit.js.map +1 -1
  62. package/dist/pages/device-login.js +2 -2
  63. package/dist/pages/environment.js +445 -252
  64. package/dist/pages/environment.js.map +1 -1
  65. package/dist/pages/login.js +6 -15
  66. package/dist/pages/login.js.map +1 -1
  67. package/dist/pages/oauth-authorize.js +2 -2
  68. package/dist/pages/project-access.js +11 -11
  69. package/dist/pages/project-environments.js +359 -28
  70. package/dist/pages/project-environments.js.map +1 -1
  71. package/dist/pages/project-settings.js +8 -8
  72. package/dist/pages/project.js +3 -3
  73. package/dist/pages/projects.js +8 -8
  74. package/dist/pages/service-account.js +19 -16
  75. package/dist/pages/service-account.js.map +1 -1
  76. package/dist/pages/service-accounts.js +6 -7
  77. package/dist/pages/service-accounts.js.map +1 -1
  78. package/dist/pages/settings.d.ts +1 -6
  79. package/dist/pages/settings.js +155 -286
  80. package/dist/pages/settings.js.map +1 -1
  81. package/dist/pages/unregistered.js +2 -2
  82. package/dist/pages/user.js +7 -8
  83. package/dist/pages/user.js.map +1 -1
  84. package/dist/pages/users.js +6 -7
  85. package/dist/pages/users.js.map +1 -1
  86. package/package.json +8 -3
  87. package/src/components/actions-log.tsx +8 -61
  88. package/src/components/directory.tsx +10 -9
  89. package/src/components/grants.tsx +2 -2
  90. package/src/components/icons.tsx +0 -2
  91. package/src/components/offboarding.tsx +9 -16
  92. package/src/components/page.tsx +2 -3
  93. package/src/components/personal-tokens.tsx +5 -2
  94. package/src/components/principal-page.tsx +5 -4
  95. package/src/components/protected.tsx +39 -52
  96. package/src/components/references.tsx +18 -7
  97. package/src/components/role-editor.tsx +68 -99
  98. package/src/components/role-field.tsx +1 -1
  99. package/src/components/trusted-workloads.tsx +6 -5
  100. package/src/components/ui.tsx +5 -0
  101. package/src/lib/audit-proofs.ts +51 -0
  102. package/src/lib/audit-sentences.ts +490 -529
  103. package/src/lib/bindings.ts +6 -0
  104. package/src/lib/changes.ts +3 -1
  105. package/src/lib/coffre.ts +2 -2
  106. package/src/lib/queries.ts +19 -168
  107. package/src/lib/reveal.ts +32 -5
  108. package/src/lib/roles.ts +10 -36
  109. package/src/lib/row-reads.ts +2 -2
  110. package/src/lib/signin-errors.ts +5 -33
  111. package/src/options.ts +3 -19
  112. package/src/pages/account.tsx +1 -1
  113. package/src/pages/audit.tsx +151 -228
  114. package/src/pages/environment.tsx +373 -247
  115. package/src/pages/login.tsx +2 -4
  116. package/src/pages/project-environments.tsx +322 -20
  117. package/src/pages/service-accounts.tsx +1 -1
  118. package/src/pages/settings.tsx +49 -134
  119. package/src/pages/user.tsx +2 -2
  120. package/src/pages/users.tsx +1 -1
  121. package/src/parity.ts +11 -20
  122. package/src/styles/globals.css +107 -273
  123. package/dist/chunks/actions-log-DupYCEyV.js +0 -1134
  124. package/dist/chunks/actions-log-DupYCEyV.js.map +0 -1
  125. package/dist/chunks/directory-DrswWQLT.js.map +0 -1
  126. package/dist/chunks/environment-actions-8rL9Cw6X.js +0 -576
  127. package/dist/chunks/environment-actions-8rL9Cw6X.js.map +0 -1
  128. package/dist/chunks/grants-C0cb2oii.js.map +0 -1
  129. package/dist/chunks/offboarding-C1jbG_dk.js.map +0 -1
  130. package/dist/chunks/page-CfhC9Hp1.js.map +0 -1
  131. package/dist/chunks/personal-tokens-xC9wulhg.js.map +0 -1
  132. package/dist/chunks/principal-page-CdSeftGD.js.map +0 -1
  133. package/dist/chunks/queries-D1JuimTu.js.map +0 -1
  134. package/dist/chunks/references-D5llUGQL.js.map +0 -1
  135. package/dist/chunks/role-field-CoCv8wse.js.map +0 -1
  136. package/dist/chunks/signin-errors-TlQmQe0t.js.map +0 -1
  137. package/dist/chunks/use-change-BorW2R6C.js.map +0 -1
  138. package/dist/chunks/use-roles-BZnJ9Cq0.js.map +0 -1
  139. package/src/components/environment-actions.tsx +0 -508
@@ -2,9 +2,8 @@ import { Link } from '@tanstack/react-router';
2
2
  import { credentialScopeInWords } from '@coffre/core/access';
3
3
  import type { PrincipalReport, RemovedPrincipal } from '../shared/models';
4
4
  import { Card } from './page';
5
- import { EmptyState, Notice, Timestamp } from './ui';
5
+ import { EmptyState, Notice, Timestamp, ofAll } from './ui';
6
6
  import { PrincipalLink } from './principal';
7
- import { ReadsLag } from './actions-log';
8
7
  import { referenceProblem } from './references';
9
8
  import { ChevronRight, Key, User } from './icons';
10
9
  import { serviceName } from '@coffre/client';
@@ -19,8 +18,8 @@ export function PrincipalReportCards({ report }: { report: PrincipalReport }) {
19
18
  return (
20
19
  <>
21
20
  {report.status === 'removed' && <ConsiderRotating report={report} person={person} />}
22
- {report.issuedTokens.length > 0 && <IssuedTokens report={report} />}
23
- {report.references.length > 0 && <MadeReferences report={report} />}
21
+ {report.issuedTokens !== null && report.issuedTokens.length > 0 && <IssuedTokens tokens={report.issuedTokens} total={report.totals.issuedTokens} />}
22
+ {report.references !== null && report.references.length > 0 && <MadeReferences references={report.references} total={report.totals.references} />}
24
23
  </>
25
24
  );
26
25
  }
@@ -58,12 +57,9 @@ export function RemovedNotice({ report }: { report: PrincipalReport }) {
58
57
  export function RemovedList({
59
58
  principalType,
60
59
  removed,
61
- reads,
62
60
  }: {
63
61
  principalType: RemovedPrincipal['principalType'];
64
62
  removed: RemovedPrincipal[];
65
- /** How far reads are listed, which the counts to rotate are as of (0.15's log). */
66
- reads?: Parameters<typeof ReadsLag>[0]['reads'];
67
63
  }) {
68
64
  const users = principalType === 'user';
69
65
  const rows = removed.filter((principal) => principal.principalType === principalType);
@@ -71,7 +67,6 @@ export function RemovedList({
71
67
  return (
72
68
  <>
73
69
  <h2 className="section-title">Removed</h2>
74
- <ReadsLag reads={reads} />
75
70
  <section className="card" aria-label={users ? 'Removed users' : 'Removed service accounts'}>
76
71
  <div className="dt-wrap">
77
72
  <table className="dt directory stacks">
@@ -132,8 +127,6 @@ function ConsiderRotating({ report, person }: { report: PrincipalReport; person:
132
127
  )
133
128
  }
134
129
  >
135
- {/* Reads sealed since may yet be listed, and named here. */}
136
- <ReadsLag reads={report.reads} />
137
130
  {report.exposed.length === 0 ? (
138
131
  <EmptyState title="Nothing left to rotate">
139
132
  {report.rotated > 0
@@ -186,11 +179,11 @@ function ConsiderRotating({ report, person }: { report: PrincipalReport; person:
186
179
  * environment that holds it, like a value, not to them (D46), so their
187
180
  * leaving ends none. Listed to review.
188
181
  */
189
- function MadeReferences({ report }: { report: PrincipalReport }) {
182
+ function MadeReferences({ references, total }: { references: NonNullable<PrincipalReport['references']>; total: number | null }) {
190
183
  return (
191
184
  <Card
192
185
  labelledBy="made-references"
193
- title="References they made"
186
+ title={`References they made${ofAll(references.length, total)}`}
194
187
  description="These stay after they leave, and whoever reads a reference's environment reads its source through it. Review them: the source's access managers, or whoever writes where one is held, can break it."
195
188
  >
196
189
  <div className="dt-wrap">
@@ -203,7 +196,7 @@ function MadeReferences({ report }: { report: PrincipalReport }) {
203
196
  </tr>
204
197
  </thead>
205
198
  <tbody>
206
- {report.references.map((reference) => (
199
+ {references.map((reference) => (
207
200
  <tr key={reference.id}>
208
201
  <td className="mono" data-label="Reference">{reference.holder}</td>
209
202
  <td data-label="Reads">
@@ -222,11 +215,11 @@ function MadeReferences({ report }: { report: PrincipalReport }) {
222
215
  );
223
216
  }
224
217
 
225
- function IssuedTokens({ report }: { report: PrincipalReport }) {
218
+ function IssuedTokens({ tokens, total }: { tokens: NonNullable<PrincipalReport['issuedTokens']>; total: number | null }) {
226
219
  return (
227
220
  <Card
228
221
  labelledBy="issued-tokens"
229
- title="Bearer tokens they issued"
222
+ title={`Bearer tokens they issued${ofAll(tokens.length, total)}`}
230
223
  description="These still work, and they saw each one when it was issued. Revoke any they may have kept."
231
224
  >
232
225
  <div className="dt-wrap">
@@ -239,7 +232,7 @@ function IssuedTokens({ report }: { report: PrincipalReport }) {
239
232
  </tr>
240
233
  </thead>
241
234
  <tbody>
242
- {report.issuedTokens.map((token) => (
235
+ {tokens.map((token) => (
243
236
  <tr key={token.id}>
244
237
  <td>
245
238
  <span className="cell-stack">
@@ -88,12 +88,11 @@ export function Card({
88
88
  }
89
89
 
90
90
  /** One labelled fact in a card's `dl.facts`. */
91
- export function Fact({ label, children, action }: { label: string; children: ReactNode; /** What changes it, beside it. */ action?: ReactNode }) {
91
+ export function Fact({ label, children }: { label: string; children: ReactNode }) {
92
92
  return (
93
- <div className={action === undefined ? 'fact' : 'fact fact-with-action'}>
93
+ <div className="fact">
94
94
  <dt>{label}</dt>
95
95
  <dd>{children}</dd>
96
- {action}
97
96
  </div>
98
97
  );
99
98
  }
@@ -7,7 +7,7 @@ import { useChange, useChangeStatus } from '../lib/use-change';
7
7
  import { Key, X } from './icons';
8
8
  import { Card } from './page';
9
9
  import { RowFailure, RowPending, rowClass } from './row-state';
10
- import { ConfirmButton, EmptyState, ErrorLine, Timestamp } from './ui';
10
+ import { ConfirmButton, EmptyState, ErrorLine, Timestamp, ofAll } from './ui';
11
11
 
12
12
  /**
13
13
  * Personal tokens, which act as their person within what each reaches:
@@ -21,6 +21,7 @@ export function PersonalTokensCard<TData>({
21
21
  description,
22
22
  empty,
23
23
  emptyActions,
24
+ total = null,
24
25
  }: {
25
26
  tokens: TokenRow[] | { error: string };
26
27
  change: Change<TData, TokenRow, TokenRow, unknown>;
@@ -29,11 +30,13 @@ export function PersonalTokensCard<TData>({
29
30
  empty?: ReactNode;
30
31
  /** Beneath it, what to do about it. */
31
32
  emptyActions?: ReactNode;
33
+ /** How many there are when the list stops short of all of them (a member's report lists 200 at most). */
34
+ total?: number | null;
32
35
  }) {
33
36
  const revoke = useChange(change);
34
37
  const { status, dismiss } = useChangeStatus(change.list.queryKey);
35
38
  return (
36
- <Card labelledBy="personal-tokens" title="Personal tokens" description={description}>
39
+ <Card labelledBy="personal-tokens" title={`Personal tokens${'error' in tokens ? '' : ofAll(tokens.length, total)}`} description={description}>
37
40
  {'error' in tokens ? (
38
41
  <div className="card-body">
39
42
  <ErrorLine error={tokens.error} />
@@ -328,19 +328,20 @@ export function PrincipalAccess({ principalType, principalId }: { principalType:
328
328
  )}
329
329
 
330
330
  {found !== null && <PrincipalReportCards report={found} />}
331
- {/* A report from an instance before 0.7, mid-deploy or rolled back, lists none. */}
331
+ {/* A report from an instance before 0.7, mid-deploy or rolled back, lists none, nor does 0.16's yet (null). */}
332
332
  {found !== null && !removed && (found.personalTokens ?? []).length > 0 && (
333
- <MemberPersonalTokens member={memberRef(principalType, principalId)} tokens={found.personalTokens} />
333
+ <MemberPersonalTokens member={memberRef(principalType, principalId)} tokens={found.personalTokens ?? []} total={found.totals.personalTokens} />
334
334
  )}
335
335
  </>
336
336
  );
337
337
  }
338
338
 
339
339
  /** A person's personal tokens, for whoever runs the instance, who reads their report and may revoke any of them. */
340
- function MemberPersonalTokens({ member, tokens }: { member: string; tokens: TokenRow[] }) {
340
+ function MemberPersonalTokens({ member, tokens, total }: { member: string; tokens: TokenRow[]; total: number | null }) {
341
341
  return (
342
342
  <PersonalTokensCard
343
343
  tokens={tokens}
344
+ total={total}
344
345
  change={revokeMemberToken(useCoffre(), member)}
345
346
  description="Tokens they made, each acting as them within what it reaches. Removing them from coffre revokes every one."
346
347
  />
@@ -356,7 +357,7 @@ function InstanceRoleNote({ access }: { access: MemberAccess }) {
356
357
  <div className="report-notice">
357
358
  <Notice tone="info">
358
359
  <strong>{name}</strong>
359
- {access.scope === null ? '' : unscoped(access.scope) ? ' in every project' : `: ${scopeInWords(access.scope)}`}, from their global role. The
360
+ {access.scope === null ? '' : unscoped(access.scope) ? ' in every project' : `: ${scopeInWords(access.scope)}`}, from their instance role. The
360
361
  grants below add to it.
361
362
  </Notice>
362
363
  </div>
@@ -5,89 +5,76 @@ import { keys } from '../lib/queries';
5
5
  import { protectionInWords } from '../lib/roles';
6
6
  import { useChange, useChangeStatus } from '../lib/use-change';
7
7
  import { useRoles } from '../lib/use-roles';
8
+ import { useShell } from '../lib/use-shell';
8
9
  import { Lock } from './icons';
9
- import { ConfirmDialog, Toggletip } from './ui';
10
+ import { ConfirmButton, Toggletip } from './ui';
10
11
 
11
12
  const MEANING = 'Protected: each person here holds their role’s protected column, which an Owner sets in Settings › Roles. Service accounts hold their role as anywhere else.';
12
13
  const WHO_UNPROTECTS = 'Only an Owner of its project takes protection off.';
13
14
 
14
15
  /**
15
- * Whether you change an environment's protection: whoever manages the
16
- * project's environments protects one, and only an Owner of its project,
17
- * or of the whole instance, takes it off, as the server says
18
- * (`unprotectable`). A personal config has none of its own: it is as its
19
- * parent is.
16
+ * An environment's protection (docs/design/roles.md), on its card and its
17
+ * page. Whoever manages the project's environments protects one, and only
18
+ * an Owner of its project, or of the whole instance, takes it off, as the
19
+ * server says (`unprotectable`): for them the tag is the button that does,
20
+ * behind a confirmation. Everyone else sees the tag, whose
21
+ * note says what it means and who changes it, and nothing while it is off.
22
+ * A personal config has none of its own: it is as its parent is.
20
23
  */
21
- export function changesProtection(projects: readonly { slug: string; permissions: readonly string[] }[], project: string, environment: ProjectEnvironment): boolean {
24
+ export function Protection({ project, environment }: { project: string; environment: ProjectEnvironment }) {
25
+ const { projects } = useShell();
22
26
  const manages = projects.find((entry) => entry.slug === project)?.permissions.includes('environment.manage') === true;
23
- return manages && environment.details !== null && environment.personal !== true && (!environment.protected || environment.unprotectable === true);
24
- }
25
-
26
- /**
27
- * An environment's protection (docs/design/roles.md), while it is on: a
28
- * tag on its page, a lock on its card, whose note says what it means and
29
- * who takes it off. Nothing while it is off. It is changed from the
30
- * environment's actions menu (`ProtectDialog`).
31
- */
32
- export function Protection({ environment, compact = false }: { environment: ProjectEnvironment; compact?: boolean }) {
33
- if (!environment.protected) return null;
27
+ const unprotects = environment.unprotectable === true;
28
+ const guarded = environment.protected;
29
+ if (manages && environment.details !== null && environment.personal !== true && (!guarded || unprotects)) {
30
+ return <ChangeProtection project={project} slug={environment.slug} guarded={guarded} unprotects={unprotects} />;
31
+ }
32
+ if (!guarded) return null;
34
33
  return (
35
34
  <Toggletip label={`${MEANING} ${WHO_UNPROTECTS}`}>
36
- {compact ? (
37
- <button type="button" className="protected-mark" aria-label="Protected">
38
- <Lock size={13} />
39
- </button>
40
- ) : (
41
- <button type="button" className="tag tag-amber tag-button">
42
- <Lock size={11} />
43
- Protected
44
- </button>
45
- )}
35
+ <button type="button" className="tag tag-amber tag-button">
36
+ <Lock size={11} />
37
+ Protected
38
+ </button>
46
39
  </Toggletip>
47
40
  );
48
41
  }
49
42
 
50
- /**
51
- * Protecting the environment, or taking it off, once confirmed: shown at
52
- * once on its card and its page, which say if the server refuses. Once a
53
- * change is on its way, another waits for its answer: the later of two
54
- * would otherwise land as it likes.
55
- */
56
- export function ProtectDialog({
57
- project,
58
- environment,
59
- open,
60
- onOpenChange,
61
- }: {
62
- project: string;
63
- environment: ProjectEnvironment;
64
- open: boolean;
65
- onOpenChange: (open: boolean) => void;
66
- }) {
43
+ /** The tag as the button that protects the environment, or takes it off, once confirmed. */
44
+ function ChangeProtection({ project, slug, guarded, unprotects }: { project: string; slug: string; guarded: boolean; unprotects: boolean }) {
67
45
  const { roles } = useRoles();
68
46
  const protect = useChange(protectEnvironment(useCoffre(), project));
69
47
  const { status } = useChangeStatus(keys.projects);
70
48
  const protection = protectionInWords(roles);
71
- const { slug, protected: guarded } = environment;
49
+ const place = `${project}/${slug}`;
72
50
  return (
73
- <ConfirmDialog
74
- open={open}
75
- onOpenChange={onOpenChange}
51
+ <ConfirmButton
52
+ trigger={
53
+ <button
54
+ type="button"
55
+ className={`tag tag-button tag-control ${guarded ? 'tag-amber' : 'tag-outline'}`}
56
+ aria-label={guarded ? `Protected: unprotect ${place}…` : `Protect ${place}…`}
57
+ >
58
+ <Lock size={11} />
59
+ {guarded ? 'Protected' : 'Protect…'}
60
+ </button>
61
+ }
62
+ // Once a change is on its way, the tag shows it already; another waits for its answer.
63
+ disabled={status(environmentId(project, slug)).state === 'pending'}
76
64
  title={
77
65
  <>
78
- {guarded ? 'Unprotect' : 'Protect'} <span className="mono">{project}/{slug}</span>?
66
+ {guarded ? 'Unprotect' : 'Protect'} <span className="mono">{place}</span>?
79
67
  </>
80
68
  }
81
69
  body={
82
70
  guarded
83
71
  ? 'People holding a role here get its full column again, as in any other environment. Service accounts are unaffected.'
84
72
  : `People holding a role here get its protected column${protection === null ? ', which for now holds what the other does' : `: ${protection}`}. Service accounts are unaffected.${
85
- environment.unprotectable === true ? '' : ` ${WHO_UNPROTECTS}`
73
+ unprotects ? '' : ` ${WHO_UNPROTECTS}`
86
74
  }`
87
75
  }
88
76
  confirmLabel={guarded ? 'Unprotect' : 'Protect'}
89
77
  destructive={guarded}
90
- confirmDisabled={status(environmentId(project, slug)).state === 'pending'}
91
78
  onConfirm={() => protect({ slug, protected: !guarded })}
92
79
  />
93
80
  );
@@ -23,8 +23,6 @@ export function referenceProblem(state: ReferenceView['state']): string | null {
23
23
  return null;
24
24
  case 'broken':
25
25
  return 'Broken';
26
- case 'replaced':
27
- return 'No value';
28
26
  case 'source_archived':
29
27
  return 'Source archived';
30
28
  case 'source_deleted':
@@ -36,6 +34,17 @@ export function referenceProblem(state: ReferenceView['state']): string | null {
36
34
  }
37
35
  }
38
36
 
37
+ /** Who made a reference and how long ago, after `lead`: nothing where its row says no one. */
38
+ function MadeBy({ reference, lead }: { reference: { createdBy: string | null; createdAt: string | null }; lead: string }) {
39
+ if (reference.createdBy === null || reference.createdAt === null) return null;
40
+ return (
41
+ <>
42
+ {lead}
43
+ {reference.createdBy.replace(/^user:/, '')} <Timestamp iso={reference.createdAt} display="relative" />
44
+ </>
45
+ );
46
+ }
47
+
39
48
  /** A secret's path as a link to it, when you can open it there. */
40
49
  function SecretPath({ path, open }: { path: string; open: boolean }) {
41
50
  const [project, environment, key] = path.split('/') as [string, string, string];
@@ -84,8 +93,8 @@ export function LentReferences({ references, onBreak }: { references: ListedRefe
84
93
  {references.map((reference) => (
85
94
  <li key={reference.id}>
86
95
  <span>
87
- Read through <SecretPath path={reference.holder} open={false} />, made by {reference.createdBy.replace(/^user:/, '')}{' '}
88
- <Timestamp iso={reference.createdAt} display="relative" />
96
+ Read through <SecretPath path={reference.holder} open={false} />
97
+ <MadeBy reference={reference} lead=", made by " />
89
98
  {reference.readers !== null && (
90
99
  <span className="cell-muted">
91
100
  {' '}
@@ -225,9 +234,11 @@ export function ReferencesInto({ project }: { project: string }) {
225
234
  <td data-label="Read through">
226
235
  <span className="cell-stack">
227
236
  <span className="mono">{reference.holder}</span>
228
- <small className="cell-muted">
229
- Made by {reference.createdBy.replace(/^user:/, '')} <Timestamp iso={reference.createdAt} display="relative" />
230
- </small>
237
+ {reference.createdBy !== null && (
238
+ <small className="cell-muted">
239
+ <MadeBy reference={reference} lead="Made by " />
240
+ </small>
241
+ )}
231
242
  </span>
232
243
  </td>
233
244
  <td data-label="Readers">
@@ -1,4 +1,4 @@
1
- import { useId, useRef, useState, type ReactNode } from 'react';
1
+ import { useId, useRef, useState } from 'react';
2
2
  import { CoffreError, type RoleImpact, type RoleView } from '@coffre/client';
3
3
  import { definitionProblem, type Permission, type RoleDefinition } from '@coffre/core/access';
4
4
  import { useSuspenseQuery } from '@tanstack/react-query';
@@ -7,7 +7,6 @@ import { toast } from 'sonner';
7
7
  import { useCoffre } from '../lib/coffre';
8
8
  import { affects, queries } from '../lib/queries';
9
9
  import {
10
- CARD_ROWS,
11
10
  columnInWords,
12
11
  GRID_PERMISSIONS,
13
12
  impactExamples,
@@ -15,7 +14,6 @@ import {
15
14
  ordered,
16
15
  PERMISSION_WORDS,
17
16
  projectWide,
18
- reachOf,
19
17
  roleIdFrom,
20
18
  roleIdProblem,
21
19
  sameDefinition,
@@ -24,70 +22,89 @@ import {
24
22
  type Columns,
25
23
  } from '../lib/roles';
26
24
  import { useAction } from '../lib/use-action';
25
+ import { Card } from './page';
27
26
  import { Check, Lock, Pencil, Plus, RotateBack, Trash } from './icons';
28
27
  import { ConfirmDialog, ErrorLine, Modal, Notice, Spinner } from './ui';
29
28
 
30
- // Settings › Roles (docs/design/roles.md): what each role can do, in an
31
- // environment and in a protected one, which a person holds there; a
32
- // service account holds the first everywhere. Any member reads them; an
33
- // Owner of the whole instance edits them, each change weighed first
34
- // (`?dryRun=1`) and said in words before it is confirmed.
29
+ // Settings › Roles (docs/design/roles.md): what each role holds, in two
30
+ // columns, an environment's and a protected one's, which a person holds
31
+ // there; a service account holds the first everywhere. Any member reads
32
+ // them; an Owner of the whole instance edits them, each change weighed
33
+ // first (`?dryRun=1`) and said in words before it is confirmed.
35
34
 
36
- export type Kind = 'role' | 'instance-role';
35
+ type Kind = 'role' | 'instance-role';
37
36
 
38
- /**
39
- * The instance's project roles, or its global roles (instance roles, in
40
- * the code and the API): a card each, which opens its editor, under what
41
- * switches between the two.
42
- */
43
- export function RolesSettings({ kind, switcher }: { kind: Kind; switcher: ReactNode }) {
37
+ /** The instance's roles and instance roles, each a card of rows that open its editor. */
38
+ export function RolesSettings() {
44
39
  const { data } = useSuspenseQuery(queries.roles(useCoffre()));
45
- if (!data.ok) return <ErrorLine error={`The roles could not be read. ${data.error}`} />;
46
- // Keyed by kind: an editor open on one, its draft included, never outlives it into the other's role of the same id.
47
- return <RoleList key={kind} kind={kind} roles={kind === 'role' ? data.roles : data.instanceRoles} editable={data.editable} switcher={switcher} />;
40
+ if (!data.ok) {
41
+ return (
42
+ <Card labelledBy="roles" title="Roles">
43
+ <div className="card-row">
44
+ <ErrorLine error={`The roles could not be read. ${data.error}`} />
45
+ </div>
46
+ </Card>
47
+ );
48
+ }
49
+ return (
50
+ <>
51
+ <RoleList kind="role" roles={data.roles} editable={data.editable} />
52
+ <RoleList kind="instance-role" roles={data.instanceRoles} editable={data.editable} />
53
+ </>
54
+ );
48
55
  }
49
56
 
50
- function RoleList({ kind, roles, editable, switcher }: { kind: Kind; roles: RoleView[]; editable: boolean; switcher: ReactNode }) {
57
+ function RoleList({ kind, roles, editable }: { kind: Kind; roles: RoleView[]; editable: boolean }) {
51
58
  // The role open in the editor, by id, or one being made: never a role's id, which `new` may be.
52
59
  const [open, setOpen] = useState<{ role: string } | { making: true } | null>(null);
53
60
  const project = kind === 'role';
54
61
  const opened = open === null || 'making' in open ? null : roles.find((role) => role.id === open.role);
55
62
  return (
56
- <>
57
- <div className="section-actions">
58
- {switcher}
59
- {project && editable && (
63
+ <Card
64
+ labelledBy={project ? 'roles' : 'instance-roles'}
65
+ title={project ? 'Roles' : 'Instance roles'}
66
+ description={
67
+ <>
68
+ {project
69
+ ? 'What a grant gives, on a project or one of its environments. In a protected environment a person holds the second column; a service account always holds the first.'
70
+ : 'What a person holds, by their instance role, in every project its scope takes in, before any grant adds to it.'}
71
+ {!editable && ' Only an Owner of the whole instance edits them.'}
72
+ </>
73
+ }
74
+ actions={
75
+ project && editable && (
60
76
  <button className="btn" type="button" onClick={() => setOpen({ making: true })}>
61
77
  <Plus size={14} />
62
78
  New role
63
79
  </button>
64
- )}
65
- </div>
66
- <div className="roles-desc">
67
- <p>
68
- {project
69
- ? 'Granted on a project or environment; a person or service account can hold several.'
70
- : 'One per person, across every project in its scope; assigned on Users.'}
71
- </p>
72
- {roles.some((role) => GRID_PERMISSIONS.some((permission) => reachOf(role, permission) === 'unprotected')) && (
73
- <p className="role-legend" aria-hidden>
74
- <Lock size={12} />
75
- Not in protected environments
76
- </p>
77
- )}
78
- </div>
79
- <ul className="role-cards" aria-label={project ? 'Project roles' : 'Global roles'}>
80
+ )
81
+ }
82
+ >
83
+ <ul className="role-list" aria-label={project ? 'Roles' : 'Instance roles'}>
80
84
  {roles.map((role) => (
81
- <li key={role.id} className="role-card">
82
- <p className="role-card-title">
83
- {role.name}
84
- <RoleBadges role={role} />
85
- </p>
86
- {/* A built-in role's own words would go stale as an Owner edits what it can; a custom one's are its maker's. */}
87
- {!role.builtin && role.description !== '' && <p className="role-card-desc">{role.description}</p>}
88
- <RoleReach role={role} />
89
- <div className="role-card-foot">
90
- <span className="role-card-count">{held(kind, role.grants)}</span>
85
+ <li key={role.id} className="card-row role-row">
86
+ <div className="role-row-text">
87
+ <p className="card-row-title role-row-title">
88
+ {role.name}
89
+ <RoleBadges role={role} />
90
+ </p>
91
+ {role.description !== '' && <p className="card-row-desc">{role.description}</p>}
92
+ <dl className="role-columns">
93
+ <div>
94
+ <dt>Holds</dt>
95
+ <dd>{columnInWords(role.permissions)}</dd>
96
+ </div>
97
+ <div>
98
+ <dt>
99
+ <Lock size={12} />
100
+ In protected environments
101
+ </dt>
102
+ <dd>{columnInWords(role.protected)}</dd>
103
+ </div>
104
+ </dl>
105
+ </div>
106
+ <div className="role-row-side">
107
+ <span className="role-row-count">{held(kind, role.grants)}</span>
91
108
  <button
92
109
  className="btn btn-sm"
93
110
  type="button"
@@ -112,7 +129,7 @@ function RoleList({ kind, roles, editable, switcher }: { kind: Kind; roles: Role
112
129
  onClose={() => setOpen(null)}
113
130
  />
114
131
  )}
115
- </>
132
+ </Card>
116
133
  );
117
134
  }
118
135
 
@@ -122,54 +139,6 @@ function held(kind: Kind, count: number): string {
122
139
  return count === 0 ? 'No grants' : count === 1 ? '1 grant' : `${count} grants`;
123
140
  }
124
141
 
125
- /**
126
- * What a role can do, on its card: every permission, in the same place on
127
- * every card, held ones solid, the others a dashed outline, and a lock on
128
- * one it holds only outside protected environments. A screen reader hears
129
- * each in full: "Read values: yes, except in protected environments".
130
- */
131
- function RoleReach({ role }: { role: RoleView }) {
132
- return (
133
- <dl className="role-reach">
134
- {CARD_ROWS.map((row) => (
135
- <div key={row.name}>
136
- <dt>{row.name}</dt>
137
- <dd>
138
- {/* Safari reads a list without bullets as no list, unless told. */}
139
- <ul role="list">
140
- {row.permissions.map((permission) => {
141
- const reach = reachOf(role, permission);
142
- const { label, short } = PERMISSION_WORDS[permission];
143
- const words = reach === 'nowhere' ? 'no' : reach === 'unprotected' ? 'yes, except in protected environments' : 'yes';
144
- return (
145
- <li
146
- key={permission}
147
- className={`role-perm role-perm-${reach}`}
148
- title={reach === 'unprotected' ? `${label}, not in protected environments` : label}
149
- >
150
- <span className="role-perm-shown" aria-hidden>
151
- {short}
152
- {reach === 'unprotected' && <Lock size={11} />}
153
- </span>
154
- {/* Its widest look, unseen: a chip is as wide on every card, whatever the role holds, and wraps alike. */}
155
- <span className="role-perm-widest" aria-hidden>
156
- {short}
157
- {!projectWide(permission) && <Lock size={11} />}
158
- </span>
159
- <span className="visually-hidden">
160
- {label}: {words}
161
- </span>
162
- </li>
163
- );
164
- })}
165
- </ul>
166
- </dd>
167
- </div>
168
- ))}
169
- </dl>
170
- );
171
- }
172
-
173
142
  /** Where a role comes from, and whether it is as it shipped. */
174
143
  function RoleBadges({ role }: { role: RoleView }) {
175
144
  return (
@@ -408,7 +377,7 @@ function RoleEditor({
408
377
  {editable && (
409
378
  <p className="hint">
410
379
  Reading takes using, and a protected environment holds no more than any other: the boxes keep both true.
411
- {instance ? ' A global role reaches every project its holder’s scope takes in.' : ''}
380
+ {instance ? ' An instance role reaches every project its holder’s scope takes in.' : ''}
412
381
  </p>
413
382
  )}
414
383
  {role !== null && role.edited && (
@@ -22,7 +22,7 @@ export function RoleField({ value, onChange }: { value: RoleVars; onChange: (val
22
22
  return (
23
23
  <>
24
24
  <label className="field">
25
- <span className="label">Global role</span>
25
+ <span className="label">Role</span>
26
26
  <select
27
27
  className="select"
28
28
  value={role}
@@ -13,6 +13,7 @@ import {
13
13
  listedIds,
14
14
  listingGap,
15
15
  planned,
16
+ reached,
16
17
  summary,
17
18
  type Form,
18
19
  type GitHubLookup,
@@ -86,7 +87,7 @@ export function TrustedWorkloads({ serviceId, bindings, grants }: { serviceId: s
86
87
  </span>
87
88
  </span>
88
89
  </td>
89
- <td>{binding.scope === null ? 'All its account holds' : credentialScopeInWords(binding.scope)}</td>
90
+ <td>{reached(binding.scope)}</td>
90
91
  <td className="nowrap">
91
92
  <span className="cell-stack">
92
93
  <Timestamp iso={binding.createdAt} />
@@ -379,12 +380,12 @@ function Exposure({ events }: { events: string[] }) {
379
380
 
380
381
  /** What the bindings a plan replaces reached, beside what the new one reaches: the same, unless the person chose again. */
381
382
  function Reached({ plan, bindings }: { plan: BindingPlan; bindings: BindingView[] }) {
382
- const reached = [...new Set(plan.replaces.flatMap((replaced) => {
383
+ const before = [...new Set(plan.replaces.flatMap((replaced) => {
383
384
  const scope = bindings.find((binding) => binding.id === replaced.id)?.scope;
384
- return scope === undefined ? [] : [scope === null ? 'all its account holds' : credentialScopeInWords(scope)];
385
+ return scope === undefined ? [] : [reached(scope)];
385
386
  }))];
386
- if (reached.every((words) => words === credentialScopeInWords(plan.scope))) return <> This one reaches what {plan.replaces.length === 1 ? 'it' : 'they'} did.</>;
387
- return <> {plan.replaces.length === 1 ? 'It' : 'They'} reached {reached.join('; ')}: this one reaches what it says above.</>;
387
+ if (before.every((words) => words === credentialScopeInWords(plan.scope))) return <> This one reaches what {plan.replaces.length === 1 ? 'it' : 'they'} did.</>;
388
+ return <> {plan.replaces.length === 1 ? 'It' : 'They'} reached {before.join('; ')}: this one reaches what it says above.</>;
388
389
  }
389
390
 
390
391
  function TrustWorkload({ serviceId, grants, bindings }: { serviceId: string; grants: HeldGrant[]; bindings: BindingView[] }) {
@@ -462,6 +462,11 @@ function relative(iso: string, now: number, style: 'long' | 'narrow' = 'long'):
462
462
  return RELATIVE[style].format(Math.round(delta / divisor), unit);
463
463
  }
464
464
 
465
+ /** "200 of 1,240" in a list's title, when it stops short of all of them; nothing otherwise. */
466
+ export function ofAll(listed: number, total: number | null): string {
467
+ return total === null || total <= listed ? '' : ` (${listed.toLocaleString('en-US')} of ${total.toLocaleString('en-US')})`;
468
+ }
469
+
465
470
  /** A UTC time as the log writes it: `2026-10-17 08:45:13`, to the millisecond when `precise`. */
466
471
  export function absolute(iso: string, precise: boolean): string {
467
472
  return iso.replace('T', ' ').replace('Z', '').slice(0, precise ? 23 : 19);