@coffre/ui 0.1.10 → 0.1.12
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.
- package/dist/client/_coffre/assets/account-CyJDFhek.js +2 -0
- package/dist/client/_coffre/assets/account-DHSs5h2f.js +1 -0
- package/dist/client/_coffre/assets/affordances-BQD5B421.js +1 -0
- package/dist/client/_coffre/assets/audit-Bcyp_dU1.js +2 -0
- package/dist/client/_coffre/assets/audit-rMy9mU9Q.js +1 -0
- package/dist/client/_coffre/assets/auth.device-DuvaComb.js +1 -0
- package/dist/client/_coffre/assets/auth.device-yBt_sLZW.js +2 -0
- package/dist/client/_coffre/assets/directory-C4BMGC7-.js +1 -0
- package/dist/client/_coffre/assets/dist-BNkBTkxj.js +1 -0
- package/dist/client/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/client/_coffre/assets/grants-CyDW25eX.js +1 -0
- package/dist/client/_coffre/assets/icons-BRl8DlXW.js +1 -0
- package/dist/client/_coffre/assets/index-CA1mtrIx.js +12 -0
- package/dist/client/_coffre/assets/link-CqlAJWBd.js +1 -0
- package/dist/client/_coffre/assets/login-B73b6bsJ.js +1 -0
- package/dist/client/_coffre/assets/login-BO1KAGPU.js +2 -0
- package/dist/client/_coffre/assets/offboarding--5vSKNHv.js +1 -0
- package/dist/client/_coffre/assets/page-Dngv8FMr.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-DBha3tys.js +1 -0
- package/dist/client/_coffre/assets/principal-page-C4qDD-d8.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-eBKxOZ0_.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-or_AX6o5.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-DHdXfEh-.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-iynQgenH.js +1 -0
- package/dist/client/_coffre/assets/projects.index-CGW8mRil.js +1 -0
- package/dist/client/_coffre/assets/row-state-BlarvG7E.js +1 -0
- package/dist/client/_coffre/assets/settings-D-7RJIDf.js +1 -0
- package/dist/client/_coffre/assets/suspense-q_eJaZ18.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-0u7midqA.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-C53NqScg.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-DBZTLnbi.js +1 -0
- package/dist/client/_coffre/assets/ui-BPWFJNz7.js +46 -0
- package/dist/client/_coffre/assets/unregistered-CLhgtwUt.js +1 -0
- package/dist/client/_coffre/assets/use-action-LULgF26O.js +1 -0
- package/dist/client/_coffre/assets/use-change-Bd6NZJj9.js +1 -0
- package/dist/client/_coffre/assets/use-shell-Dx92Huhb.js +1 -0
- package/dist/client/_coffre/assets/useQuery-BIIZz1CB.js +1 -0
- package/dist/client/_coffre/assets/useSuspenseQuery-tP9HFZ8w.js +1 -0
- package/dist/client/_coffre/assets/users._user-BXtaL8Ee.js +2 -0
- package/dist/client/_coffre/assets/users._user-CNYVkXaY.js +1 -0
- package/dist/client/_coffre/assets/users.index-Cs9tibIv.js +1 -0
- package/dist/server/.vite/manifest.json +342 -246
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-T9tMsCwo.js +162 -0
- package/dist/server/_coffre/assets/{account-CUQYGCYh.js → account-BUhhOS5-.js} +150 -117
- package/dist/server/_coffre/assets/{account-DMlUoBxQ.js → account-B_h55GCs.js} +10 -24
- package/dist/server/_coffre/assets/{affordances-BNaXjMOb.js → affordances-CKANXDTG.js} +2 -22
- package/dist/server/_coffre/assets/{async-local-storage-C0cwgkEr.js → async-local-storage-C10uQtMM.js} +3 -2
- package/dist/server/_coffre/assets/{audit-CCdSLmvK.js → audit-B8Ck358-.js} +46 -16
- package/dist/server/_coffre/assets/audit-DFsXfeAQ.js +31 -0
- package/dist/server/_coffre/assets/{auth.device-BoFM1jcf.js → auth.device-BXf_JjT7.js} +5 -5
- package/dist/server/_coffre/assets/{auth.device-C05u5ROO.js → auth.device-cqjWACvB.js} +7 -5
- package/dist/server/_coffre/assets/{directory-GsnYkse0.js → directory-C9SfNgpM.js} +87 -112
- package/dist/server/_coffre/assets/{use-action-DwEmf58L.js → dist-CnnV3t2g.js} +3 -48
- package/dist/server/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/server/_coffre/assets/grants--315KmXu.js +158 -0
- package/dist/server/_coffre/assets/{page-BdnhpwvH.js → icons-CWsTEfpn.js} +125 -436
- package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +480 -0
- package/dist/server/_coffre/assets/link-42ZWdjzZ.js +422 -0
- package/dist/server/_coffre/assets/{login-DUtCQju5.js → login-CQSkYW_D.js} +7 -5
- package/dist/server/_coffre/assets/{login-B2njIq_o.js → login-LBpXXfsQ.js} +2 -2
- package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +56 -0
- package/dist/server/_coffre/assets/{offboarding-8yMa7ViM.js → offboarding-CykelNis.js} +11 -79
- package/dist/server/_coffre/assets/page-BGeDoQO5.js +3531 -0
- package/dist/server/_coffre/assets/{principal-page-B8zPcS2b.js → principal-page-CRdoAQOq.js} +51 -42
- package/dist/server/_coffre/assets/{projects._project._environment-DdIOc7wx.js → projects._project._environment-BXU1Mee5.js} +4 -11
- package/dist/server/_coffre/assets/{projects._project._environment-BZ5Z80V8.js → projects._project._environment-BrDqn8kW.js} +129 -748
- package/dist/server/_coffre/assets/{projects._project.index-CuEAUwGn.js → projects._project.index-CAxBU4tY.js} +134 -96
- package/dist/server/_coffre/assets/{projects._project.index-DvbcU1kh.js → projects._project.index-CYyUVTCl.js} +5 -4
- package/dist/server/_coffre/assets/{projects.index-5HI0wOuG.js → projects.index-D6ZoDE_0.js} +57 -55
- package/dist/server/_coffre/assets/{react-dom-qCTiwGGR.js → react-dom-bBoJXlK2.js} +417 -51
- package/dist/server/_coffre/assets/{router-CQDoql8s.js → router-Bu2qtyqw.js} +376 -92
- package/dist/server/_coffre/assets/row-state-CAItu3n_.js +117 -0
- package/dist/server/_coffre/assets/{settings-BVz78wjP.js → settings-ByeF6hBa.js} +8 -6
- package/dist/server/_coffre/assets/suspense-beD01bb8.js +602 -0
- package/dist/server/_coffre/assets/tokens._token-CM01QPCq.js +10 -0
- package/dist/server/_coffre/assets/{tokens._token-CWs3Mtki.js → tokens._token-D2E4P3Qc.js} +97 -79
- package/dist/server/_coffre/assets/{tokens.index-Ck0LN7aC.js → tokens.index-Cmrgn3mU.js} +9 -6
- package/dist/server/_coffre/assets/{ui-D_slKpSF.js → ui-DvlGkmaH.js} +7 -836
- package/dist/server/_coffre/assets/{unregistered-Z17da4Rc.js → unregistered-DSArejP9.js} +5 -3
- package/dist/server/_coffre/assets/use-action-C2wz34kq.js +47 -0
- package/dist/server/_coffre/assets/use-change-CJpGSNIq.js +1212 -0
- package/dist/server/_coffre/assets/use-shell-C3iYcyP1.js +462 -0
- package/dist/server/_coffre/assets/useQuery-ChxaQ4Cb.js +8 -0
- package/dist/server/_coffre/assets/{useStore-DWGPqzXR.js → useRouter-CaUSUNsw.js} +1 -420
- package/dist/server/_coffre/assets/useSuspenseQuery-BjAmlGZl.js +117 -0
- package/dist/server/_coffre/assets/users._user-BVeR9fZP.js +10 -0
- package/dist/server/_coffre/assets/{users._user-CMwj-VI9.js → users._user-Cih2Etf4.js} +4 -5
- package/dist/server/_coffre/assets/{users.index-fWHv6A30.js → users.index-Bo2_a95G.js} +9 -6
- package/dist/server/index.js +6 -5
- package/package.json +5 -3
- package/src/components/directory.tsx +75 -104
- package/src/components/grants.tsx +60 -112
- package/src/components/icons.tsx +0 -34
- package/src/components/offboarding.tsx +1 -52
- package/src/components/principal-page.tsx +54 -67
- package/src/components/principal-picker.tsx +7 -16
- package/src/components/row-state.tsx +95 -0
- package/src/components/service-tokens.tsx +75 -64
- package/src/components/shell.tsx +1 -1
- package/src/lib/announce.ts +36 -0
- package/src/lib/changes.ts +498 -0
- package/src/lib/coffre.ts +1 -1
- package/src/lib/optimistic.ts +233 -0
- package/src/lib/queries.ts +385 -0
- package/src/lib/use-action.ts +20 -15
- package/src/lib/use-change.ts +42 -0
- package/src/lib/use-shell.ts +17 -0
- package/src/router.tsx +17 -9
- package/src/routes/__root.tsx +8 -38
- package/src/routes/account.tsx +163 -154
- package/src/routes/audit.tsx +51 -72
- package/src/routes/auth.device.tsx +4 -2
- package/src/routes/login.tsx +3 -2
- package/src/routes/projects.$project.$environment.tsx +223 -238
- package/src/routes/projects.$project.index.tsx +136 -118
- package/src/routes/projects.index.tsx +117 -145
- package/src/routes/settings.tsx +7 -7
- package/src/routes/tokens.$token.tsx +14 -17
- package/src/routes/tokens.index.tsx +8 -4
- package/src/routes/unregistered.tsx +3 -2
- package/src/routes/users.$user.tsx +4 -4
- package/src/routes/users.index.tsx +8 -4
- package/src/shared/models.ts +1 -5
- package/src/styles/globals.css +80 -50
- package/dist/client/_coffre/assets/account-B48wuSF8.js +0 -1
- package/dist/client/_coffre/assets/account-BkNyIDT7.js +0 -2
- package/dist/client/_coffre/assets/affordances-CmoY-8Xf.js +0 -1
- package/dist/client/_coffre/assets/audit-BvwKYb-5.js +0 -2
- package/dist/client/_coffre/assets/audit-D02H-zxS.js +0 -1
- package/dist/client/_coffre/assets/auth.device-BP5FY0K1.js +0 -1
- package/dist/client/_coffre/assets/auth.device-DYOONgFF.js +0 -2
- package/dist/client/_coffre/assets/coffre-BBp7cKVa.js +0 -1
- package/dist/client/_coffre/assets/directory-Bu0EIxqI.js +0 -1
- package/dist/client/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/client/_coffre/assets/grants-DavcwofW.js +0 -1
- package/dist/client/_coffre/assets/index-CDPlq5rM.js +0 -12
- package/dist/client/_coffre/assets/login-C-wTm_t1.js +0 -2
- package/dist/client/_coffre/assets/login-CLLv1om9.js +0 -1
- package/dist/client/_coffre/assets/offboarding-DWsE2FSa.js +0 -1
- package/dist/client/_coffre/assets/page-DbSS7pYH.js +0 -1
- package/dist/client/_coffre/assets/preload-helper-DduCCcmc.js +0 -46
- package/dist/client/_coffre/assets/principal-page-Bp_iwuSd.js +0 -1
- package/dist/client/_coffre/assets/projects._project._environment-BMeX_B8l.js +0 -2
- package/dist/client/_coffre/assets/projects._project._environment-CT0A-hIU.js +0 -3
- package/dist/client/_coffre/assets/projects._project.index-C_xYOGLT.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-Chcf-cUd.js +0 -1
- package/dist/client/_coffre/assets/projects.index-CfOtb1X5.js +0 -2
- package/dist/client/_coffre/assets/projects.index-DSjOhLDh.js +0 -1
- package/dist/client/_coffre/assets/settings-BC9cUJNK.js +0 -1
- package/dist/client/_coffre/assets/settings-Bkj_E21y.js +0 -2
- package/dist/client/_coffre/assets/tokens._token-BA0KqvaW.js +0 -1
- package/dist/client/_coffre/assets/tokens._token-Dh9jLOkm.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-BgAMWkHT.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-CHueIAv1.js +0 -1
- package/dist/client/_coffre/assets/unregistered-D5go1AfR.js +0 -1
- package/dist/client/_coffre/assets/use-action-l__xZDYY.js +0 -1
- package/dist/client/_coffre/assets/users._user-Dwqa0gv5.js +0 -1
- package/dist/client/_coffre/assets/users._user-xJAb3T6Y.js +0 -2
- package/dist/client/_coffre/assets/users.index-BJoF-L37.js +0 -2
- package/dist/client/_coffre/assets/users.index-YUjtbTGy.js +0 -1
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-BKg2AlPu.js +0 -133
- package/dist/server/_coffre/assets/audit-CThXn2v7.js +0 -74
- package/dist/server/_coffre/assets/coffre-C2ANsTAz.js +0 -281
- package/dist/server/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/server/_coffre/assets/grants-B6k4Fu9z.js +0 -243
- package/dist/server/_coffre/assets/projects.index-uiomWX_l.js +0 -54
- package/dist/server/_coffre/assets/settings-4oRyDizv.js +0 -18
- package/dist/server/_coffre/assets/tokens._token-CF_deAwq.js +0 -18
- package/dist/server/_coffre/assets/tokens.index-DF_07KEe.js +0 -10
- package/dist/server/_coffre/assets/users._user-DUzwkSKT.js +0 -10
- package/dist/server/_coffre/assets/users.index-BbuweTwH.js +0 -10
- package/src/components/syncs.tsx +0 -581
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { Fragment, useState } from 'react';
|
|
3
2
|
import { DropdownMenu } from 'radix-ui';
|
|
4
|
-
import {
|
|
5
|
-
import { memberRef,
|
|
6
|
-
import {
|
|
3
|
+
import { changeRole, directoryList, invite, removeMember, type InviteVars } from '../lib/changes';
|
|
4
|
+
import { memberRef, useCoffre } from '../lib/coffre';
|
|
5
|
+
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
7
6
|
import type { DirectoryPrincipal } from '../shared/models';
|
|
8
|
-
import {
|
|
7
|
+
import { RowFailure, RowPending, rowClass } from './row-state';
|
|
8
|
+
import { ConfirmDialog, EmptyState, Modal, Spinner, Toggletip } from './ui';
|
|
9
9
|
import { PrincipalLink } from './principal';
|
|
10
10
|
import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from './icons';
|
|
11
11
|
|
|
@@ -19,21 +19,9 @@ import { Key, Lock, MoreHorizontal, Pencil, Plus, ShieldCheck, User, X } from '.
|
|
|
19
19
|
|
|
20
20
|
type PrincipalType = DirectoryPrincipal['principalType'];
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* owners' own, and asking for anyone else would only log a refusal.
|
|
26
|
-
*/
|
|
27
|
-
export async function loadDirectory(client: CoffreClient, canManage: boolean) {
|
|
28
|
-
if (!canManage) return { ok: false as const, error: 'Only owners can manage users and service accounts.' };
|
|
29
|
-
return uiResult(async () => {
|
|
30
|
-
const { members, removed } = await client.members.list();
|
|
31
|
-
const principals: DirectoryPrincipal[] = members.map(
|
|
32
|
-
({ principalType, principalId, instanceRole, isRootAdmin, tampered }) => ({ principalType, principalId, instanceRole, isRootAdmin, tampered }),
|
|
33
|
-
);
|
|
34
|
-
return { principals, removed };
|
|
35
|
-
});
|
|
36
|
-
}
|
|
22
|
+
/** How the directory, and its changes, name someone: `user:…`, `token:…`. */
|
|
23
|
+
export const memberOf = (principal: Pick<DirectoryPrincipal, 'principalType' | 'principalId'>) =>
|
|
24
|
+
memberRef(principal.principalType, principal.principalId);
|
|
37
25
|
|
|
38
26
|
export const ROLE_LABEL: Record<DirectoryPrincipal['instanceRole'], string> = {
|
|
39
27
|
'root-admin': 'Root admin',
|
|
@@ -58,9 +46,14 @@ export function DirectoryTable({
|
|
|
58
46
|
hasRemoved?: boolean;
|
|
59
47
|
}) {
|
|
60
48
|
const users = principalType === 'user';
|
|
49
|
+
const columns = users ? 4 : 3;
|
|
50
|
+
const { status, failedAdds, dismiss } = useChangeStatus(directoryList.queryKey);
|
|
51
|
+
const refused = failedAdds<InviteVars>(principals.map(memberOf)).filter(
|
|
52
|
+
({ vars }) => vars.principalType === principalType,
|
|
53
|
+
);
|
|
61
54
|
return (
|
|
62
55
|
<section className="card" aria-label={users ? 'Users' : 'Tokens'}>
|
|
63
|
-
{principals.length === 0 ? (
|
|
56
|
+
{principals.length === 0 && refused.length === 0 ? (
|
|
64
57
|
<EmptyState
|
|
65
58
|
title={
|
|
66
59
|
hasRemoved
|
|
@@ -99,28 +92,52 @@ export function DirectoryTable({
|
|
|
99
92
|
</tr>
|
|
100
93
|
</thead>
|
|
101
94
|
<tbody>
|
|
102
|
-
{principals.map((principal, index) =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
<
|
|
106
|
-
className=
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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} />
|
|
114
|
+
</td>
|
|
115
|
+
)}
|
|
116
|
+
<td className="col-actions">
|
|
117
|
+
{state.state === 'pending' ? (
|
|
118
|
+
<RowPending status={state} />
|
|
119
|
+
) : (
|
|
120
|
+
<PrincipalActions principal={principal} />
|
|
121
|
+
)}
|
|
122
|
+
</td>
|
|
123
|
+
</tr>
|
|
124
|
+
<RowFailure
|
|
125
|
+
status={state}
|
|
126
|
+
columns={columns}
|
|
127
|
+
onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
|
|
113
128
|
/>
|
|
114
|
-
</
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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>
|
|
124
141
|
))}
|
|
125
142
|
</tbody>
|
|
126
143
|
</table>
|
|
@@ -184,12 +201,10 @@ export function InstanceRole({ principal }: { principal: DirectoryPrincipal }) {
|
|
|
184
201
|
export function PrincipalActions({
|
|
185
202
|
principal,
|
|
186
203
|
trigger = 'act act-quiet act-menu',
|
|
187
|
-
onRemoved,
|
|
188
204
|
}: {
|
|
189
205
|
principal: DirectoryPrincipal;
|
|
190
206
|
/** The menu button's classes: a row action in tables, a button in a page head. */
|
|
191
207
|
trigger?: string;
|
|
192
|
-
onRemoved?: () => unknown;
|
|
193
208
|
}) {
|
|
194
209
|
const [editing, setEditing] = useState(false);
|
|
195
210
|
const [confirming, setConfirming] = useState(false);
|
|
@@ -197,13 +212,12 @@ export function PrincipalActions({
|
|
|
197
212
|
principal.instanceRole === 'owner' ? 'owner' : 'user',
|
|
198
213
|
);
|
|
199
214
|
const coffre = useCoffre();
|
|
200
|
-
const
|
|
215
|
+
const setRole = useChange(changeRole(coffre));
|
|
216
|
+
const remove = useChange(removeMember(coffre));
|
|
217
|
+
const { status } = useChangeStatus(directoryList.queryKey);
|
|
218
|
+
const pending = status(memberOf(principal)).state === 'pending';
|
|
201
219
|
const kind = KIND[principal.principalType];
|
|
202
220
|
|
|
203
|
-
useEffect(() => {
|
|
204
|
-
if (error !== null && !editing) toast.error(error);
|
|
205
|
-
}, [editing, error]);
|
|
206
|
-
|
|
207
221
|
if (principal.isRootAdmin) return null;
|
|
208
222
|
|
|
209
223
|
return (
|
|
@@ -249,10 +263,7 @@ export function PrincipalActions({
|
|
|
249
263
|
{principal.principalType === 'user' && (
|
|
250
264
|
<Modal
|
|
251
265
|
open={editing}
|
|
252
|
-
onOpenChange={
|
|
253
|
-
setEditing(open);
|
|
254
|
-
if (!open) setError(null);
|
|
255
|
-
}}
|
|
266
|
+
onOpenChange={setEditing}
|
|
256
267
|
title={
|
|
257
268
|
<>
|
|
258
269
|
Role of <span className="mono">{principal.principalId}</span>
|
|
@@ -263,28 +274,17 @@ export function PrincipalActions({
|
|
|
263
274
|
className="form"
|
|
264
275
|
onSubmit={(event) => {
|
|
265
276
|
event.preventDefault();
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
owner: instanceRole === 'owner',
|
|
270
|
-
}),
|
|
271
|
-
() => {
|
|
272
|
-
toast.success(
|
|
273
|
-
`${principal.principalId} is now ${ROLE_LABEL[instanceRole].toLowerCase()}`,
|
|
274
|
-
);
|
|
275
|
-
setEditing(false);
|
|
276
|
-
},
|
|
277
|
-
);
|
|
277
|
+
// Shown in the list at once; the row says if the server refuses.
|
|
278
|
+
setRole({ principalId: principal.principalId, owner: instanceRole === 'owner' });
|
|
279
|
+
setEditing(false);
|
|
278
280
|
}}
|
|
279
281
|
>
|
|
280
282
|
<RoleField value={instanceRole} onChange={setInstanceRole} />
|
|
281
|
-
<ErrorLine error={error} />
|
|
282
283
|
<div className="dialog-actions">
|
|
283
284
|
<button className="btn" type="button" onClick={() => setEditing(false)}>
|
|
284
285
|
Cancel
|
|
285
286
|
</button>
|
|
286
|
-
<button className="btn btn-primary" type="submit"
|
|
287
|
-
{pending && <Spinner />}
|
|
287
|
+
<button className="btn btn-primary" type="submit">
|
|
288
288
|
Save
|
|
289
289
|
</button>
|
|
290
290
|
</div>
|
|
@@ -316,15 +316,7 @@ export function PrincipalActions({
|
|
|
316
316
|
)
|
|
317
317
|
}
|
|
318
318
|
confirmLabel={`Remove ${kind}`}
|
|
319
|
-
onConfirm={() =>
|
|
320
|
-
void run(
|
|
321
|
-
() => coffre.members.remove(memberRef(principal.principalType, principal.principalId)),
|
|
322
|
-
async () => {
|
|
323
|
-
toast.success(`${principal.principalId} removed`);
|
|
324
|
-
await onRemoved?.();
|
|
325
|
-
},
|
|
326
|
-
)
|
|
327
|
-
}
|
|
319
|
+
onConfirm={() => remove(principal)}
|
|
328
320
|
/>
|
|
329
321
|
</>
|
|
330
322
|
);
|
|
@@ -334,15 +326,13 @@ export function AddPrincipal({ principalType }: { principalType: PrincipalType }
|
|
|
334
326
|
const [open, setOpen] = useState(false);
|
|
335
327
|
const [principalId, setPrincipalId] = useState('');
|
|
336
328
|
const [instanceRole, setInstanceRole] = useState<'user' | 'owner'>('user');
|
|
337
|
-
const
|
|
338
|
-
const { pending, error, setError, run } = useAction();
|
|
329
|
+
const add = useChange(invite(useCoffre()));
|
|
339
330
|
const kind = KIND[principalType];
|
|
340
331
|
|
|
341
332
|
function close() {
|
|
342
333
|
setOpen(false);
|
|
343
334
|
setPrincipalId('');
|
|
344
335
|
setInstanceRole('user');
|
|
345
|
-
setError(null);
|
|
346
336
|
}
|
|
347
337
|
|
|
348
338
|
return (
|
|
@@ -362,22 +352,9 @@ export function AddPrincipal({ principalType }: { principalType: PrincipalType }
|
|
|
362
352
|
className="form"
|
|
363
353
|
onSubmit={(event) => {
|
|
364
354
|
event.preventDefault();
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
// someone already here; this form is only for someone new.
|
|
369
|
-
const member = memberRef(principalType, principalId.trim());
|
|
370
|
-
const { members } = await coffre.members.list();
|
|
371
|
-
if (members.some((entry) => entry.member === member)) {
|
|
372
|
-
throw new Refusal('That principal already exists.');
|
|
373
|
-
}
|
|
374
|
-
await coffre.members.add(member, { owner: principalType === 'user' && instanceRole === 'owner' });
|
|
375
|
-
},
|
|
376
|
-
() => {
|
|
377
|
-
toast.success(`${principalId.trim()} added`);
|
|
378
|
-
close();
|
|
379
|
-
},
|
|
380
|
-
);
|
|
355
|
+
// Shown in the list at once; the list says if the server refuses.
|
|
356
|
+
add({ principalType, principalId: principalId.trim(), owner: instanceRole === 'owner' });
|
|
357
|
+
close();
|
|
381
358
|
}}
|
|
382
359
|
>
|
|
383
360
|
<label className="field">
|
|
@@ -401,17 +378,11 @@ export function AddPrincipal({ principalType }: { principalType: PrincipalType }
|
|
|
401
378
|
<RoleField value={instanceRole} onChange={setInstanceRole} />
|
|
402
379
|
)}
|
|
403
380
|
|
|
404
|
-
<ErrorLine error={error} />
|
|
405
381
|
<div className="dialog-actions">
|
|
406
382
|
<button className="btn" type="button" onClick={close}>
|
|
407
383
|
Cancel
|
|
408
384
|
</button>
|
|
409
|
-
<button
|
|
410
|
-
className="btn btn-primary"
|
|
411
|
-
type="submit"
|
|
412
|
-
disabled={pending || principalId.trim() === ''}
|
|
413
|
-
>
|
|
414
|
-
{pending && <Spinner />}
|
|
385
|
+
<button className="btn btn-primary" type="submit" disabled={principalId.trim() === ''}>
|
|
415
386
|
Add {kind}
|
|
416
387
|
</button>
|
|
417
388
|
</div>
|
|
@@ -1,79 +1,15 @@
|
|
|
1
|
-
import type { CoffreClient } from '@coffre/client';
|
|
2
|
-
import type { Role } from '@coffre/core/access';
|
|
3
1
|
import type { ReactNode } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { grantId, revokeGrant, type GrantVars } from '../lib/changes';
|
|
3
|
+
import type { FailedAdd } from '../lib/optimistic';
|
|
4
|
+
import { useCoffre } from '../lib/coffre';
|
|
7
5
|
import { projectAccessLabel } from '../lib/project-access';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import { keys } from '../lib/queries';
|
|
7
|
+
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
8
|
+
import type { GrantRow } from '../shared/models';
|
|
9
|
+
import { RowFailure, RowPending, rowClass } from './row-state';
|
|
10
|
+
import { ConfirmButton } from './ui';
|
|
10
11
|
import { Clock, ShieldCheck } from './icons';
|
|
11
12
|
|
|
12
|
-
/**
|
|
13
|
-
* One project and, when you manage its access, its grants. A project that is
|
|
14
|
-
* not there for you fails with no message: the page words that itself.
|
|
15
|
-
*/
|
|
16
|
-
export async function loadProject(client: CoffreClient, slug: string) {
|
|
17
|
-
let project: ProjectSummary | undefined;
|
|
18
|
-
try {
|
|
19
|
-
project = (await client.projects.list()).projects.find((entry) => entry.slug === slug);
|
|
20
|
-
} catch (error) {
|
|
21
|
-
return uiFailure(error);
|
|
22
|
-
}
|
|
23
|
-
if (project === undefined) return { ok: false as const, error: null };
|
|
24
|
-
if (!project.permissions.includes('grant.manage')) {
|
|
25
|
-
return { ok: true as const, project, grants: [] as GrantRow[], grantsError: null };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const { members } = await client.members.list(slug);
|
|
30
|
-
const grants: GrantRow[] = members.flatMap((member) =>
|
|
31
|
-
member.grants.map((grant) => ({
|
|
32
|
-
id: grant.id,
|
|
33
|
-
principalType: member.principalType,
|
|
34
|
-
principalId: member.principalId,
|
|
35
|
-
role: grant.role,
|
|
36
|
-
roleName: grant.roleName,
|
|
37
|
-
permissions: grant.permissions,
|
|
38
|
-
scope: grant.environment === null ? ('project' as const) : ('environment' as const),
|
|
39
|
-
environmentSlug: grant.environment,
|
|
40
|
-
expiresAt: grant.expiresAt,
|
|
41
|
-
})),
|
|
42
|
-
);
|
|
43
|
-
return { ok: true as const, project, grants, grantsError: null };
|
|
44
|
-
} catch (error) {
|
|
45
|
-
return { ok: true as const, project, grants: [] as GrantRow[], grantsError: failureMessage(error) };
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Where a grant applies, as the API names it: `market`, or `market/prod`. */
|
|
50
|
-
export function grantPlace(project: string, environmentSlug: string | null): string {
|
|
51
|
-
return environmentSlug === null ? project : `${project}/${environmentSlug}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Give someone a role at one place. Access is declarative, so asking for what
|
|
56
|
-
* they already hold is not an error, whoever asked first: `existed` says so.
|
|
57
|
-
*/
|
|
58
|
-
export async function ensureGrant(
|
|
59
|
-
coffre: CoffreClient,
|
|
60
|
-
data: {
|
|
61
|
-
project: string;
|
|
62
|
-
principalType: GrantRow['principalType'];
|
|
63
|
-
principalId: string;
|
|
64
|
-
role: string;
|
|
65
|
-
environmentSlug: string | null;
|
|
66
|
-
expiresAt: string | null;
|
|
67
|
-
},
|
|
68
|
-
): Promise<{ existed: boolean }> {
|
|
69
|
-
const place = grantPlace(data.project, data.environmentSlug);
|
|
70
|
-
const role = data.role as Role;
|
|
71
|
-
const { changes } = await coffre.access.set(memberRef(data.principalType, data.principalId), {
|
|
72
|
-
[place]: data.expiresAt === null ? role : { role, until: data.expiresAt },
|
|
73
|
-
});
|
|
74
|
-
return { existed: changes[place] === 'unchanged' };
|
|
75
|
-
}
|
|
76
|
-
|
|
77
13
|
/**
|
|
78
14
|
* Grants as a table: who or where in the first column, then the access, when
|
|
79
15
|
* it lapses, and a revoke.
|
|
@@ -125,14 +61,15 @@ export function GrantRowView({
|
|
|
125
61
|
lead: ReactNode;
|
|
126
62
|
leadLabel: string;
|
|
127
63
|
}) {
|
|
128
|
-
const
|
|
129
|
-
const {
|
|
64
|
+
const revoke = useChange(revokeGrant(useCoffre(), project));
|
|
65
|
+
const { status, dismiss } = useChangeStatus(keys.grants(project));
|
|
66
|
+
const state = status(grantId(grant));
|
|
130
67
|
const label = projectAccessLabel(grant);
|
|
131
68
|
const expired = grant.expiresAt !== null && new Date(grant.expiresAt).getTime() < Date.now();
|
|
132
69
|
|
|
133
70
|
return (
|
|
134
71
|
<>
|
|
135
|
-
<tr>
|
|
72
|
+
<tr className={rowClass(state)}>
|
|
136
73
|
<td className="n">{number}</td>
|
|
137
74
|
<td className="col-lead" data-label={leadLabel}>
|
|
138
75
|
{lead}
|
|
@@ -160,45 +97,56 @@ export function GrantRowView({
|
|
|
160
97
|
)}
|
|
161
98
|
</td>
|
|
162
99
|
<td className="col-actions">
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
run(
|
|
185
|
-
() =>
|
|
186
|
-
coffre.access.set(memberRef(grant.principalType, grant.principalId), {
|
|
187
|
-
[grantPlace(project, grant.environmentSlug)]: null,
|
|
188
|
-
}),
|
|
189
|
-
() => toast.success(`Revoked ${label} on ${project} from ${grant.principalId}`),
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
/>
|
|
100
|
+
{state.state === 'pending' ? (
|
|
101
|
+
<RowPending status={state} />
|
|
102
|
+
) : (
|
|
103
|
+
<ConfirmButton
|
|
104
|
+
trigger={<button className="act act-danger">Revoke</button>}
|
|
105
|
+
title={
|
|
106
|
+
<>
|
|
107
|
+
Revoke {label} from <span className="mono">{grant.principalId}</span>?
|
|
108
|
+
</>
|
|
109
|
+
}
|
|
110
|
+
body={
|
|
111
|
+
<>
|
|
112
|
+
They lose <strong>{label}</strong> on <span className="mono">{project}</span>{' '}
|
|
113
|
+
immediately, including any process using it right now. Other grants they hold
|
|
114
|
+
still apply.
|
|
115
|
+
</>
|
|
116
|
+
}
|
|
117
|
+
confirmLabel="Revoke access"
|
|
118
|
+
onConfirm={() => revoke(grant)}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
193
121
|
</td>
|
|
194
122
|
</tr>
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
</tr>
|
|
201
|
-
)}
|
|
123
|
+
<RowFailure
|
|
124
|
+
status={state}
|
|
125
|
+
columns={5}
|
|
126
|
+
onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
|
|
127
|
+
/>
|
|
202
128
|
</>
|
|
203
129
|
);
|
|
204
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Grants the server refused to give: rolled back, so no row of theirs is
|
|
134
|
+
* left, and listed here, after the table's rows, saying why.
|
|
135
|
+
*/
|
|
136
|
+
export function RefusedGrants({ refused }: { refused: RefusedGrant[] }) {
|
|
137
|
+
return refused.map(({ mutationId, vars, status, dismiss }) => (
|
|
138
|
+
<RowFailure key={mutationId} status={status} columns={5} onDismiss={dismiss}>
|
|
139
|
+
{vars.principalId} was not given {vars.roleName.toLowerCase()}.
|
|
140
|
+
</RowFailure>
|
|
141
|
+
));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
type RefusedGrant = FailedAdd<GrantVars> & { dismiss: () => void };
|
|
145
|
+
|
|
146
|
+
/** The grants of one kind the server refused to give in a project, still to be said. */
|
|
147
|
+
export function useRefusedGrants(project: string, grants: GrantRow[], principalType?: GrantRow['principalType']): RefusedGrant[] {
|
|
148
|
+
const { failedAdds, dismiss } = useChangeStatus(keys.grants(project));
|
|
149
|
+
return failedAdds<GrantVars>(grants.map(grantId))
|
|
150
|
+
.filter(({ vars }) => principalType === undefined || vars.principalType === principalType)
|
|
151
|
+
.map((refused) => ({ ...refused, dismiss: () => dismiss(refused.mutationId) }));
|
|
152
|
+
}
|
package/src/components/icons.tsx
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
CircleAlert,
|
|
12
12
|
CircleCheck,
|
|
13
13
|
Clock as ClockGlyph,
|
|
14
|
-
Cloud as CloudGlyph,
|
|
15
14
|
Copy as CopyGlyph,
|
|
16
15
|
Ellipsis,
|
|
17
16
|
Eye as EyeGlyph,
|
|
@@ -35,7 +34,6 @@ import {
|
|
|
35
34
|
Pencil as PencilGlyph,
|
|
36
35
|
Play as PlayGlyph,
|
|
37
36
|
Plus as PlusGlyph,
|
|
38
|
-
RefreshCw,
|
|
39
37
|
RotateCcw,
|
|
40
38
|
ScrollText,
|
|
41
39
|
Search as SearchGlyph,
|
|
@@ -43,7 +41,6 @@ import {
|
|
|
43
41
|
ShieldCheck as ShieldCheckGlyph,
|
|
44
42
|
Sun as SunGlyph,
|
|
45
43
|
Terminal as TerminalGlyph,
|
|
46
|
-
TrainFront,
|
|
47
44
|
TriangleAlert,
|
|
48
45
|
Upload as UploadGlyph,
|
|
49
46
|
User as UserGlyph,
|
|
@@ -161,7 +158,6 @@ export const Archive = lucide(ArchiveGlyph);
|
|
|
161
158
|
export const History = lucide(HistoryGlyph);
|
|
162
159
|
export const RotateBack = lucide(RotateCcw);
|
|
163
160
|
export const Upload = lucide(UploadGlyph);
|
|
164
|
-
export const Sync = lucide(RefreshCw);
|
|
165
161
|
export const Pause = lucide(PauseGlyph);
|
|
166
162
|
export const Play = lucide(PlayGlyph);
|
|
167
163
|
export const Lock = lucide(LockGlyph);
|
|
@@ -244,36 +240,6 @@ export function Microsoft({ size = 16, className, style }: IconProps) {
|
|
|
244
240
|
);
|
|
245
241
|
}
|
|
246
242
|
|
|
247
|
-
/** Vercel's triangle. */
|
|
248
|
-
export function Vercel({ size = 16, className, style }: IconProps) {
|
|
249
|
-
return (
|
|
250
|
-
<svg width={size} height={size} viewBox="0 0 24 24" fill="currentColor" className={className} style={style} aria-hidden>
|
|
251
|
-
<path d="M12 2.5 23 21.5H1Z" />
|
|
252
|
-
</svg>
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Railway and Cloudflare marks are detailed enough that a redraw would be a
|
|
257
|
-
// guess; a plain glyph stands in for them.
|
|
258
|
-
const Cloud = lucide(CloudGlyph);
|
|
259
|
-
const Train = lucide(TrainFront);
|
|
260
|
-
|
|
261
|
-
/** The mark beside a sync provider; any other brand gets the sync glyph. */
|
|
262
|
-
export function SyncMark({ brand, size = 16 }: { brand: string; size?: number }) {
|
|
263
|
-
switch (brand) {
|
|
264
|
-
case 'github':
|
|
265
|
-
return <GitHub size={size} />;
|
|
266
|
-
case 'vercel':
|
|
267
|
-
return <Vercel size={size} />;
|
|
268
|
-
case 'railway':
|
|
269
|
-
return <Train size={size} />;
|
|
270
|
-
case 'cloudflare':
|
|
271
|
-
return <Cloud size={size} />;
|
|
272
|
-
default:
|
|
273
|
-
return <Sync size={size} />;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
243
|
/** The mark on a provider's button; any other OpenID Connect issuer gets a key. */
|
|
278
244
|
export function ProviderMark({ brand, size = 16 }: { brand: string; size?: number }) {
|
|
279
245
|
switch (brand) {
|
|
@@ -3,7 +3,7 @@ import type { PrincipalReport, RemovedPrincipal } from '../shared/models';
|
|
|
3
3
|
import { Card } from './page';
|
|
4
4
|
import { EmptyState, Notice, Timestamp } from './ui';
|
|
5
5
|
import { PrincipalLink } from './principal';
|
|
6
|
-
import { ChevronRight, Key,
|
|
6
|
+
import { ChevronRight, Key, User } from './icons';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The part of a user's or token's page that answers "if they left, what would
|
|
@@ -16,7 +16,6 @@ export function PrincipalReportCards({ report }: { report: PrincipalReport }) {
|
|
|
16
16
|
return (
|
|
17
17
|
<>
|
|
18
18
|
<SeenValues report={report} removed={removed} person={person} />
|
|
19
|
-
{report.syncs.length > 0 && <CreatedSyncs report={report} person={person} />}
|
|
20
19
|
{report.issuedTokens.length > 0 && <IssuedTokens report={report} />}
|
|
21
20
|
</>
|
|
22
21
|
);
|
|
@@ -187,56 +186,6 @@ function SeenValues({
|
|
|
187
186
|
);
|
|
188
187
|
}
|
|
189
188
|
|
|
190
|
-
function CreatedSyncs({ report, person }: { report: PrincipalReport; person: boolean }) {
|
|
191
|
-
return (
|
|
192
|
-
<Card
|
|
193
|
-
labelledBy="created-syncs"
|
|
194
|
-
title={person ? 'Syncs they set up' : 'Syncs it set up'}
|
|
195
|
-
description="A sync keeps pushing every change to the destination it names, whoever set it up. Check each one still points somewhere you control."
|
|
196
|
-
>
|
|
197
|
-
<div className="dt-wrap">
|
|
198
|
-
<table className="dt syncs">
|
|
199
|
-
<thead>
|
|
200
|
-
<tr>
|
|
201
|
-
<th>Destination</th>
|
|
202
|
-
<th className="col-shrink">From</th>
|
|
203
|
-
<th className="col-shrink col-hide-narrow">Token</th>
|
|
204
|
-
</tr>
|
|
205
|
-
</thead>
|
|
206
|
-
<tbody>
|
|
207
|
-
{report.syncs.map((sync) => (
|
|
208
|
-
<tr key={sync.id}>
|
|
209
|
-
<td>
|
|
210
|
-
<span className="cell-account">
|
|
211
|
-
<SyncMark brand={sync.brand} size={15} />
|
|
212
|
-
<span className="cell-stack">
|
|
213
|
-
<span>
|
|
214
|
-
{sync.providerLabel}
|
|
215
|
-
{sync.paused && <span className="tag">Paused</span>}
|
|
216
|
-
</span>
|
|
217
|
-
<small className="mono">{sync.destination}</small>
|
|
218
|
-
</span>
|
|
219
|
-
</span>
|
|
220
|
-
</td>
|
|
221
|
-
<td className="col-shrink">
|
|
222
|
-
<Link
|
|
223
|
-
className="cell-link mono"
|
|
224
|
-
to="/projects/$project/$environment"
|
|
225
|
-
params={{ project: sync.project, environment: sync.environment }}
|
|
226
|
-
>
|
|
227
|
-
{sync.project}/{sync.environment}
|
|
228
|
-
</Link>
|
|
229
|
-
</td>
|
|
230
|
-
<td className="col-shrink col-hide-narrow cell-mono cell-muted">{sync.credential}</td>
|
|
231
|
-
</tr>
|
|
232
|
-
))}
|
|
233
|
-
</tbody>
|
|
234
|
-
</table>
|
|
235
|
-
</div>
|
|
236
|
-
</Card>
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
189
|
function IssuedTokens({ report }: { report: PrincipalReport }) {
|
|
241
190
|
return (
|
|
242
191
|
<Card
|