@coffre/ui 0.2.0 → 0.4.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 (177) hide show
  1. package/dist/chunks/audit-sentence-BhHmvQX_.js +660 -0
  2. package/dist/chunks/audit-sentence-BhHmvQX_.js.map +1 -0
  3. package/dist/chunks/delete-place-CRX7ntE8.js +206 -0
  4. package/dist/chunks/delete-place-CRX7ntE8.js.map +1 -0
  5. package/dist/chunks/{directory-CSjWWUQ1.js → directory-zr3ek7Mc.js} +175 -60
  6. package/dist/chunks/directory-zr3ek7Mc.js.map +1 -0
  7. package/dist/chunks/folders-DoBmCwOi.js +207 -0
  8. package/dist/chunks/folders-DoBmCwOi.js.map +1 -0
  9. package/dist/chunks/grants-Cw1FyGID.js +669 -0
  10. package/dist/chunks/grants-Cw1FyGID.js.map +1 -0
  11. package/dist/chunks/offboarding-CE6d7um1.js +305 -0
  12. package/dist/chunks/offboarding-CE6d7um1.js.map +1 -0
  13. package/dist/chunks/one-time-DXEl9hbg.js +35 -0
  14. package/dist/chunks/one-time-DXEl9hbg.js.map +1 -0
  15. package/dist/chunks/page-DvsgZ2Hd.js +391 -0
  16. package/dist/chunks/page-DvsgZ2Hd.js.map +1 -0
  17. package/dist/chunks/principal-BIN-xwZw.js +42 -0
  18. package/dist/chunks/principal-BIN-xwZw.js.map +1 -0
  19. package/dist/chunks/{principal-page-D_91OA0l.js → principal-page-DhjO76GH.js} +245 -251
  20. package/dist/chunks/principal-page-DhjO76GH.js.map +1 -0
  21. package/dist/chunks/project-page-SRCtRe2g.js +17 -0
  22. package/dist/chunks/project-page-SRCtRe2g.js.map +1 -0
  23. package/dist/chunks/{queries-CQ81o4so.js → queries-DVR_i3rA.js} +132 -30
  24. package/dist/chunks/queries-DVR_i3rA.js.map +1 -0
  25. package/dist/chunks/references-B6pLT1uQ.js +343 -0
  26. package/dist/chunks/references-B6pLT1uQ.js.map +1 -0
  27. package/dist/chunks/{row-state-0PsrEzOL.js → row-state-DOPUsjQK.js} +3 -3
  28. package/dist/chunks/{row-state-0PsrEzOL.js.map → row-state-DOPUsjQK.js.map} +1 -1
  29. package/dist/chunks/signin-errors--ykMFuqN.js +57 -0
  30. package/dist/chunks/signin-errors--ykMFuqN.js.map +1 -0
  31. package/dist/chunks/tabs-BmwKfUeK.js +22 -0
  32. package/dist/chunks/tabs-BmwKfUeK.js.map +1 -0
  33. package/dist/chunks/{theme-B2vQolVR.js → theme-DJuz-xLM.js} +3 -3
  34. package/dist/chunks/{theme-B2vQolVR.js.map → theme-DJuz-xLM.js.map} +1 -1
  35. package/dist/chunks/{ui-DixXLQvQ.js → ui-DJje3gST.js} +6 -3
  36. package/dist/chunks/ui-DJje3gST.js.map +1 -0
  37. package/dist/chunks/{use-change-c6CeLRin.js → use-change-DUiGO19U.js} +52 -21
  38. package/dist/chunks/use-change-DUiGO19U.js.map +1 -0
  39. package/dist/chunks/{use-shell-jxd7Tzd-.js → use-shell-rNKfGjdj.js} +3 -3
  40. package/dist/chunks/{use-shell-jxd7Tzd-.js.map → use-shell-rNKfGjdj.js.map} +1 -1
  41. package/dist/chunks/validation-D312_NLf.js +87 -0
  42. package/dist/chunks/validation-D312_NLf.js.map +1 -0
  43. package/dist/index.d.ts +361 -27
  44. package/dist/index.js +188 -98
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/account.d.ts +2 -2
  47. package/dist/pages/account.js +297 -135
  48. package/dist/pages/account.js.map +1 -1
  49. package/dist/pages/approval.d.ts +9 -0
  50. package/dist/pages/approval.js +207 -0
  51. package/dist/pages/approval.js.map +1 -0
  52. package/dist/pages/audit.js +17 -542
  53. package/dist/pages/audit.js.map +1 -1
  54. package/dist/pages/device-login.js +2 -3
  55. package/dist/pages/device-login.js.map +1 -1
  56. package/dist/pages/environment.js +647 -257
  57. package/dist/pages/environment.js.map +1 -1
  58. package/dist/pages/login.js +18 -7
  59. package/dist/pages/login.js.map +1 -1
  60. package/dist/pages/oauth-authorize.d.ts +10 -0
  61. package/dist/pages/oauth-authorize.js +249 -0
  62. package/dist/pages/oauth-authorize.js.map +1 -0
  63. package/dist/pages/project-access.d.ts +6 -0
  64. package/dist/pages/project-access.js +370 -0
  65. package/dist/pages/project-access.js.map +1 -0
  66. package/dist/pages/project-environments.d.ts +4 -0
  67. package/dist/pages/project-environments.js +593 -0
  68. package/dist/pages/project-environments.js.map +1 -0
  69. package/dist/pages/project-settings.d.ts +4 -0
  70. package/dist/pages/project-settings.js +242 -0
  71. package/dist/pages/project-settings.js.map +1 -0
  72. package/dist/pages/project.d.ts +10 -2
  73. package/dist/pages/project.js +57 -934
  74. package/dist/pages/project.js.map +1 -1
  75. package/dist/pages/projects.js +53 -21
  76. package/dist/pages/projects.js.map +1 -1
  77. package/dist/pages/service-account.d.ts +10 -0
  78. package/dist/pages/{token.js → service-account.js} +115 -56
  79. package/dist/pages/service-account.js.map +1 -0
  80. package/dist/pages/service-accounts.d.ts +3 -0
  81. package/dist/pages/service-accounts.js +38 -0
  82. package/dist/pages/service-accounts.js.map +1 -0
  83. package/dist/pages/settings.d.ts +1 -0
  84. package/dist/pages/settings.js +104 -42
  85. package/dist/pages/settings.js.map +1 -1
  86. package/dist/pages/unregistered.js +2 -3
  87. package/dist/pages/unregistered.js.map +1 -1
  88. package/dist/pages/user.d.ts +6 -1
  89. package/dist/pages/user.js +18 -6
  90. package/dist/pages/user.js.map +1 -1
  91. package/dist/pages/users.js +6 -10
  92. package/dist/pages/users.js.map +1 -1
  93. package/package.json +3 -3
  94. package/src/components/actions-log.tsx +117 -0
  95. package/src/components/audit-sentence.tsx +55 -0
  96. package/src/components/command-palette.tsx +4 -4
  97. package/src/components/delete-place.tsx +180 -0
  98. package/src/components/directory.tsx +259 -110
  99. package/src/components/every-project.tsx +287 -0
  100. package/src/components/expiry-field.tsx +42 -0
  101. package/src/components/folders.tsx +219 -0
  102. package/src/components/grants.tsx +11 -4
  103. package/src/components/icons.tsx +2 -0
  104. package/src/components/missing.tsx +110 -0
  105. package/src/components/offboarding.tsx +61 -33
  106. package/src/components/page.tsx +4 -1
  107. package/src/components/principal-page.tsx +136 -106
  108. package/src/components/principal-picker.tsx +5 -5
  109. package/src/components/principal.tsx +4 -4
  110. package/src/components/references.tsx +323 -0
  111. package/src/components/service-tokens.tsx +115 -95
  112. package/src/components/shell.tsx +11 -32
  113. package/src/components/tabs.tsx +18 -0
  114. package/src/components/trusted-workloads.tsx +97 -79
  115. package/src/components/ui.tsx +8 -1
  116. package/src/index.ts +13 -2
  117. package/src/layout.tsx +2 -2
  118. package/src/lib/access-plan.ts +2 -2
  119. package/src/lib/audit-sentences.ts +161 -77
  120. package/src/lib/changes.ts +56 -5
  121. package/src/lib/coffre.ts +3 -2
  122. package/src/lib/one-time.ts +32 -0
  123. package/src/lib/project-access.ts +11 -23
  124. package/src/lib/project-page.ts +14 -0
  125. package/src/lib/queries.ts +126 -32
  126. package/src/lib/search.ts +25 -0
  127. package/src/lib/signin-errors.ts +45 -1
  128. package/src/lib/validation.ts +14 -0
  129. package/src/options.ts +187 -35
  130. package/src/pages/account.tsx +274 -129
  131. package/src/pages/approval.tsx +197 -0
  132. package/src/pages/audit.tsx +9 -61
  133. package/src/pages/environment.tsx +585 -286
  134. package/src/pages/login.tsx +8 -2
  135. package/src/pages/oauth-authorize.tsx +233 -0
  136. package/src/pages/project-access.tsx +219 -0
  137. package/src/pages/project-environments.tsx +582 -0
  138. package/src/pages/project-settings.tsx +259 -0
  139. package/src/pages/project.tsx +52 -879
  140. package/src/pages/projects.tsx +55 -18
  141. package/src/pages/service-account.tsx +50 -0
  142. package/src/pages/{tokens.tsx → service-accounts.tsx} +9 -6
  143. package/src/pages/settings.tsx +62 -8
  144. package/src/pages/user.tsx +16 -4
  145. package/src/pages/users.tsx +2 -2
  146. package/src/parity.ts +160 -0
  147. package/src/register.ts +58 -9
  148. package/src/router.tsx +4 -0
  149. package/src/shared/models.ts +6 -2
  150. package/src/styles/globals.css +536 -31
  151. package/dist/chunks/directory-CSjWWUQ1.js.map +0 -1
  152. package/dist/chunks/grants-saMQagmG.js +0 -160
  153. package/dist/chunks/grants-saMQagmG.js.map +0 -1
  154. package/dist/chunks/icons-D-PfAfnH.js +0 -203
  155. package/dist/chunks/icons-D-PfAfnH.js.map +0 -1
  156. package/dist/chunks/offboarding-C6l30DZR.js +0 -263
  157. package/dist/chunks/offboarding-C6l30DZR.js.map +0 -1
  158. package/dist/chunks/page-C5HcNqf2.js +0 -190
  159. package/dist/chunks/page-C5HcNqf2.js.map +0 -1
  160. package/dist/chunks/principal-page-D_91OA0l.js.map +0 -1
  161. package/dist/chunks/queries-CQ81o4so.js.map +0 -1
  162. package/dist/chunks/signin-errors-BEFlVDbQ.js +0 -30
  163. package/dist/chunks/signin-errors-BEFlVDbQ.js.map +0 -1
  164. package/dist/chunks/ui-DixXLQvQ.js.map +0 -1
  165. package/dist/chunks/use-action-CWsg_YWU.js +0 -49
  166. package/dist/chunks/use-action-CWsg_YWU.js.map +0 -1
  167. package/dist/chunks/use-change-c6CeLRin.js.map +0 -1
  168. package/dist/chunks/validation-BQtqPe2V.js +0 -29
  169. package/dist/chunks/validation-BQtqPe2V.js.map +0 -1
  170. package/dist/pages/token.d.ts +0 -3
  171. package/dist/pages/token.js.map +0 -1
  172. package/dist/pages/tokens.d.ts +0 -3
  173. package/dist/pages/tokens.js +0 -39
  174. package/dist/pages/tokens.js.map +0 -1
  175. package/dist/project-BqIy8gYR.d.ts +0 -5
  176. package/src/lib/instance.ts +0 -13
  177. package/src/pages/token.tsx +0 -34
@@ -1,16 +1,19 @@
1
1
  import { Fragment, useState } from 'react';
2
+ import { useQuery } from '@tanstack/react-query';
2
3
  import { Menu } from '@base-ui/react/menu';
3
4
  import { changeRole, directoryList, invite, removeMember, type InviteVars } from '../lib/changes';
4
5
  import { memberRef, useCoffre } from '../lib/coffre';
6
+ import { queries } from '../lib/queries';
7
+ import { useShell } from '../lib/use-shell';
5
8
  import { useChange, useChangeStatus } from '../lib/use-change';
6
9
  import type { DirectoryPrincipal } from '../shared/models';
7
10
  import { RowFailure, RowPending, rowClass } from './row-state';
8
- import { ConfirmDialog, EmptyState, MenuPopup, Modal, Spinner, Toggletip } from './ui';
11
+ import { ConfirmDialog, EmptyState, MenuPopup, Modal, Spinner, Timestamp, Toggletip } from './ui';
9
12
  import { PrincipalLink } from './principal';
10
- import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from './icons';
13
+ import { Clock, Folder, GitHub, Key, Link, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from './icons';
11
14
 
12
15
  /**
13
- * The instance directory, shared by the Users and Tokens pages.
16
+ * The instance directory, shared by the Users and Service accounts pages.
14
17
  *
15
18
  * Both are rows in the same table on the server (principals, typed user or
16
19
  * service); the pages split them because people and machines are looked after
@@ -19,7 +22,7 @@ import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from '.
19
22
 
20
23
  type PrincipalType = DirectoryPrincipal['principalType'];
21
24
 
22
- /** How the directory, and its changes, name someone: `user:…`, `token:…`. */
25
+ /** How the directory, and its changes, name someone to the API: `user:…`, `token:…` (shown `service:…`). */
23
26
  export const memberOf = (principal: Pick<DirectoryPrincipal, 'principalType' | 'principalId'>) =>
24
27
  memberRef(principal.principalType, principal.principalId);
25
28
 
@@ -32,7 +35,7 @@ export const ROLE_LABEL: Record<DirectoryPrincipal['instanceRole'], string> = {
32
35
  /** What each kind of principal is called in the interface. */
33
36
  export const KIND: Record<PrincipalType, string> = {
34
37
  user: 'user',
35
- service: 'token',
38
+ service: 'service account',
36
39
  };
37
40
 
38
41
  export function DirectoryTable({
@@ -46,109 +49,224 @@ export function DirectoryTable({
46
49
  hasRemoved?: boolean;
47
50
  }) {
48
51
  const users = principalType === 'user';
49
- const columns = users ? 4 : 3;
52
+ const columns = users ? 4 : 6;
50
53
  const { status, failedAdds, dismiss } = useChangeStatus(directoryList.queryKey);
51
54
  const refused = failedAdds<InviteVars>(principals.map(memberOf)).filter(
52
55
  ({ vars }) => vars.principalType === principalType,
53
56
  );
54
57
  return (
55
- <section className="card" aria-label={users ? 'Users' : 'Tokens'}>
56
- {principals.length === 0 && refused.length === 0 ? (
57
- <EmptyState
58
- title={
59
- hasRemoved
60
- ? `No active ${KIND[principalType]}s`
61
- : users
62
- ? 'Nobody is registered'
63
- : 'No tokens yet'
64
- }
65
- >
66
- {hasRemoved ? `Add a ${KIND[principalType]}` : `Add the first ${KIND[principalType]}`} to let
67
- it through the door. Project access is a separate step, granted from each project's page.
68
- </EmptyState>
69
- ) : (
70
- <div className="dt-wrap">
71
- <table className={`dt directory directory-${principalType} stacks`}>
72
- <thead>
73
- <tr>
74
- <th className="n">#</th>
75
- <th className="col-principal">
76
- <span className="th">
77
- {users ? <User size={14} /> : <Key size={14} />}
78
- {users ? 'Email' : 'Name'}
79
- </span>
80
- </th>
81
- {users && (
82
- <th className="col-role">
58
+ <>
59
+ <section className="card" aria-label={users ? 'Users' : 'Service accounts'}>
60
+ {principals.length === 0 && refused.length === 0 ? (
61
+ <EmptyState
62
+ title={
63
+ hasRemoved
64
+ ? `No active ${KIND[principalType]}s`
65
+ : users
66
+ ? 'Nobody is registered'
67
+ : 'No service accounts yet'
68
+ }
69
+ >
70
+ {hasRemoved ? `Add a ${KIND[principalType]}` : `Add the first ${KIND[principalType]}`} to let
71
+ it through the door. Project access is a separate step, granted from each project's page.
72
+ </EmptyState>
73
+ ) : (
74
+ <div className="dt-wrap">
75
+ <table className={`dt directory directory-${principalType} stacks${users ? '' : ' stacks-inline'}`}>
76
+ <thead>
77
+ <tr>
78
+ <th className="n">#</th>
79
+ <th className="col-principal">
83
80
  <span className="th">
84
- <ShieldCheck size={14} />
85
- Instance role
81
+ {users ? <User size={14} /> : <Key size={14} />}
82
+ {users ? 'Email' : 'Name'}
86
83
  </span>
87
84
  </th>
88
- )}
89
- <th className="col-actions">
90
- <span className="visually-hidden">Actions</span>
91
- </th>
92
- </tr>
93
- </thead>
94
- <tbody>
95
- {principals.map((principal, index) => {
96
- const state = status(memberOf(principal));
97
- return (
98
- <Fragment key={principal.principalId}>
99
- <tr className={`row-link ${rowClass(state)}`}>
100
- <td className="n">{index + 1}</td>
101
- <td
102
- className="col-lead"
103
- data-label={principal.principalType === 'user' ? 'Email' : 'Name'}
104
- >
105
- <PrincipalLink
106
- type={principal.principalType}
107
- id={principal.principalId}
108
- stretch
109
- />
110
- </td>
111
- {users && (
112
- <td className="col-role" data-label="Instance role">
113
- <InstanceRole principal={principal} />
85
+ {users ? (
86
+ <th className="col-role">
87
+ <span className="th">
88
+ <ShieldCheck size={14} />
89
+ Instance role
90
+ </span>
91
+ </th>
92
+ ) : (
93
+ <>
94
+ <th className="col-signin">
95
+ <span className="th">
96
+ <Link size={14} />
97
+ Signs in with
98
+ </span>
99
+ </th>
100
+ <th className="col-access">
101
+ <span className="th">
102
+ <Folder size={14} />
103
+ Access
104
+ </span>
105
+ </th>
106
+ <th className="col-used">
107
+ <span className="th">
108
+ <Clock size={14} />
109
+ Last used
110
+ </span>
111
+ </th>
112
+ </>
113
+ )}
114
+ <th className="col-actions">
115
+ <span className="visually-hidden">Actions</span>
116
+ </th>
117
+ </tr>
118
+ </thead>
119
+ <tbody>
120
+ {principals.map((principal, index) => {
121
+ const state = status(memberOf(principal));
122
+ return (
123
+ <Fragment key={principal.principalId}>
124
+ <tr className={`row-link ${rowClass(state)}`}>
125
+ <td className="n">{index + 1}</td>
126
+ <td
127
+ className="col-lead"
128
+ data-label={principal.principalType === 'user' ? 'Email' : 'Name'}
129
+ >
130
+ <PrincipalLink
131
+ type={principal.principalType}
132
+ id={principal.principalId}
133
+ stretch
134
+ />
114
135
  </td>
115
- )}
116
- <td className="col-actions">
117
- {state.state === 'pending' ? (
118
- <RowPending status={state} />
136
+ {users ? (
137
+ <td className="col-role" data-label="Instance role">
138
+ <InstanceRole principal={principal} />
139
+ </td>
119
140
  ) : (
120
- <PrincipalActions principal={principal} />
141
+ <ServiceCells principal={principal} />
121
142
  )}
122
- </td>
123
- </tr>
124
- <RowFailure
125
- status={state}
126
- columns={columns}
127
- onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
128
- />
129
- </Fragment>
130
- );
131
- })}
132
- {refused.map(({ mutationId, vars, status: failed }) => (
133
- <RowFailure
134
- key={mutationId}
135
- status={failed}
136
- columns={columns}
137
- onDismiss={() => dismiss(mutationId)}
138
- >
139
- {vars.principalId} was not added.
140
- </RowFailure>
141
- ))}
142
- </tbody>
143
- </table>
144
- </div>
145
- )}
146
- </section>
143
+ <td className="col-actions">
144
+ {state.state === 'pending' ? (
145
+ <RowPending status={state} />
146
+ ) : (
147
+ <PrincipalActions principal={principal} />
148
+ )}
149
+ </td>
150
+ </tr>
151
+ <RowFailure
152
+ status={state}
153
+ columns={columns}
154
+ onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
155
+ />
156
+ </Fragment>
157
+ );
158
+ })}
159
+ {refused.map(({ mutationId, vars, status: failed }) => (
160
+ <RowFailure
161
+ key={mutationId}
162
+ status={failed}
163
+ columns={columns}
164
+ onDismiss={() => dismiss(mutationId)}
165
+ >
166
+ {vars.principalId} was not added.
167
+ </RowFailure>
168
+ ))}
169
+ </tbody>
170
+ </table>
171
+ </div>
172
+ )}
173
+ </section>
174
+ <div className="table-actions">
175
+ <AddPrincipal principalType={principalType} />
176
+ </div>
177
+ </>
178
+ );
179
+ }
180
+
181
+ const PLATFORM: Record<string, string> = {
182
+ github: 'GitHub',
183
+ 'github-reusable': 'GitHub',
184
+ 'github-reusable-organization': 'GitHub',
185
+ gitlab: 'GitLab',
186
+ custom: 'OIDC',
187
+ };
188
+
189
+ /**
190
+ * What someone scanning service accounts wants of each: how it signs in, where
191
+ * it reaches, and whether it is still in use. Access comes with the list; the
192
+ * bindings and tokens are read per row, as its own page reads them.
193
+ */
194
+ function ServiceCells({ principal }: { principal: DirectoryPrincipal }) {
195
+ const client = useCoffre();
196
+ const { auth, capabilities, features } = useShell();
197
+ const member = memberOf(principal);
198
+ // As `loadServiceDirectory` read them, so these come from its cache.
199
+ const allowed = capabilities.canManageGrants && auth.signin !== null;
200
+ // Not suspended: an account added here is shown at once, its facts when they come.
201
+ const { data: bindings } = useQuery(queries.bindings(client, member, capabilities.canManageGrants && features.workloads));
202
+ const { data: credentials } = useQuery(queries.credentials(client, member, allowed));
203
+
204
+ const platforms = new Map<string, number>();
205
+ const bindingList = bindings?.ok === true ? bindings.bindings : [];
206
+ for (const binding of bindingList) {
207
+ const platform = PLATFORM[binding.profile] ?? 'OIDC';
208
+ platforms.set(platform, (platforms.get(platform) ?? 0) + 1);
209
+ }
210
+ const now = Date.now();
211
+ const tokenList = credentials?.ok === true ? credentials.tokens : [];
212
+ const activeTokens = tokenList.filter((token) => new Date(token.expiresAt).getTime() > now).length;
213
+ const lastUsed = [...bindingList, ...tokenList]
214
+ .map((credential) => credential.lastUsedAt)
215
+ .filter((at): at is string => at !== null)
216
+ .sort()
217
+ .at(-1);
218
+
219
+ const places = [
220
+ ...new Set(
221
+ (principal.grants ?? []).map(({ project, environment }) =>
222
+ environment === null ? project : `${project}/${environment}`,
223
+ ),
224
+ ),
225
+ ];
226
+ const projects = new Set((principal.grants ?? []).map((grant) => grant.project));
227
+ const loaded = bindings !== undefined && credentials !== undefined;
228
+
229
+ return (
230
+ <>
231
+ <td className="col-signin" data-label="Signs in with">
232
+ {!loaded ? null : platforms.size === 0 && activeTokens === 0 ? (
233
+ <span className="cell-muted">Nothing yet</span>
234
+ ) : (
235
+ <span className="signin-list">
236
+ {[...platforms].map(([platform, count]) => (
237
+ <span key={platform} className="signin-item">
238
+ {platform === 'GitHub' && <GitHub size={12} />}
239
+ {platform}
240
+ {count > 1 && ` ×${count}`}
241
+ </span>
242
+ ))}
243
+ {activeTokens > 0 && (
244
+ <span className="signin-item">
245
+ <Key size={12} />
246
+ {activeTokens} token{activeTokens === 1 ? '' : 's'}
247
+ </span>
248
+ )}
249
+ </span>
250
+ )}
251
+ </td>
252
+ <td className="col-access" data-label="Access" title={places.join(', ')}>
253
+ {places.length === 0 ? (
254
+ <span className="cell-muted">None</span>
255
+ ) : places.length <= 2 ? (
256
+ <span className="mono">{places.join(', ')}</span>
257
+ ) : (
258
+ `${projects.size} project${projects.size === 1 ? '' : 's'}`
259
+ )}
260
+ </td>
261
+ <td className="col-used cell-muted" data-label="Last used">
262
+ {!loaded ? null : lastUsed === undefined ? 'Never' : <Timestamp iso={lastUsed} display="relative" />}
263
+ </td>
264
+ </>
147
265
  );
148
266
  }
149
267
 
150
268
  /**
151
- * A user's instance role. Tokens have none worth showing: every one is a
269
+ * A user's instance role. Service accounts have none worth showing: every one is a
152
270
  * plain member. A root admin's role comes from the deployment, so its tag says
153
271
  * so on hover or tap instead of offering a menu that could not work.
154
272
  */
@@ -296,21 +414,7 @@ export function PrincipalActions({
296
414
  Remove <span className="mono">{principal.principalId}</span>?
297
415
  </>
298
416
  }
299
- body={
300
- principal.principalType === 'user' ? (
301
- <>
302
- They are signed out everywhere, and their CLI logins, linked sign-in accounts and
303
- project permissions are revoked at once. Their past actions stay in the audit log,
304
- and their page then lists the values they saw, to rotate.
305
- </>
306
- ) : (
307
- <>
308
- Every token issued to it stops working and its project permissions are revoked at
309
- once, including for anything running with it right now. Its past actions stay in
310
- the audit log, and its page then lists the values it read, to rotate.
311
- </>
312
- )
313
- }
417
+ body={<RemovalPreview principal={principal} open={confirming} />}
314
418
  confirmLabel={`Remove ${kind}`}
315
419
  onConfirm={() => remove(principal)}
316
420
  />
@@ -318,6 +422,51 @@ export function PrincipalActions({
318
422
  );
319
423
  }
320
424
 
425
+ const plural = (count: number, one: string) => `${count} ${one}${count === 1 ? '' : 's'}`;
426
+
427
+ /**
428
+ * What removing someone would do, read when its dialog opens, as `coffre
429
+ * offboard` previews it before `--apply`: every way in it revokes, and what
430
+ * they leave behind to rotate.
431
+ */
432
+ function RemovalPreview({ principal, open }: { principal: DirectoryPrincipal; open: boolean }) {
433
+ const { capabilities } = useShell();
434
+ const person = principal.principalType === 'user';
435
+ const { data, isPending } = useQuery({
436
+ ...queries.report(useCoffre(), memberOf(principal), capabilities.canManageGrants),
437
+ enabled: open,
438
+ });
439
+ const report = data?.ok === true ? data.report : null;
440
+ if (isPending) {
441
+ return (
442
+ <>
443
+ <Spinner size={13} /> Reading what {person ? 'they hold' : 'it holds'}…
444
+ </>
445
+ );
446
+ }
447
+ if (report === null) {
448
+ return person
449
+ ? 'They are signed out everywhere, and their sign-in accounts and project access are revoked at once.'
450
+ : 'Its bearer tokens and trust bindings stop working, and its project access is revoked at once.';
451
+ }
452
+ const { live } = report;
453
+ const revokes = person
454
+ ? [plural(live.grants, 'grant'), plural(live.sessions, 'session'), plural(live.identities, 'linked sign-in account')]
455
+ : [plural(live.grants, 'grant'), plural(live.tokens, 'bearer token')];
456
+ return (
457
+ <>
458
+ Removing revokes {revokes.join(', ')} at once
459
+ {person ? '' : ', and its trust bindings, including for anything running as it now'}.{' '}
460
+ {report.exposed.length === 0
461
+ ? `No value ${person ? 'they' : 'it'} saw is still current.`
462
+ : `${plural(report.exposed.length, 'value')} ${person ? 'they' : 'it'} saw ${report.exposed.length === 1 ? 'is' : 'are'} still current: ${person ? 'their' : 'its'} page lists them, to rotate.`}
463
+ {report.issuedTokens.length > 0 &&
464
+ ` ${plural(report.issuedTokens.length, 'bearer token')} ${person ? 'they' : 'it'} issued still ${report.issuedTokens.length === 1 ? 'works' : 'work'}.`}{' '}
465
+ {person ? 'Their' : 'Its'} past actions stay in the audit log.
466
+ </>
467
+ );
468
+ }
469
+
321
470
  export function AddPrincipal({ principalType }: { principalType: PrincipalType }) {
322
471
  const [open, setOpen] = useState(false);
323
472
  const [principalId, setPrincipalId] = useState('');
@@ -355,7 +504,7 @@ export function AddPrincipal({ principalType }: { principalType: PrincipalType }
355
504
  >
356
505
  <label className="field">
357
506
  <span className="label">
358
- {principalType === 'user' ? 'Cloudflare Access email' : 'Service token common name'}
507
+ {principalType === 'user' ? 'Cloudflare Access email' : 'Service account name'}
359
508
  </span>
360
509
  <input
361
510
  className="input input-mono"
@@ -407,7 +556,7 @@ function RoleField({
407
556
  <option value="owner">Owner</option>
408
557
  </select>
409
558
  <span className="hint">
410
- Owners manage users and tokens, can create projects, and read the whole audit log.
559
+ Owners manage users and service accounts, can create projects, and read the whole audit log.
411
560
  Neither role reads a secret without a project grant.
412
561
  </span>
413
562
  </label>