@bevel-software/platform-core-frontend 0.19.0 → 0.20.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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +6 -2
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
- package/src/modules/audit/components/AuditLogPage.tsx +373 -0
- package/src/modules/audit/components/principal-grouping.ts +49 -0
- package/src/modules/audit/services/audit.api.ts +98 -0
- package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +2 -1
- package/src/modules/settings/settings-nav-items.tsx +11 -9
- package/src/modules/setup/components/SetupScreen.tsx +11 -0
- package/src/modules/setup/services/setup.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
- package/src/modules/workspace/components/FileViewer.tsx +6 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +60 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +50 -0
- package/src/modules/workspace/services/__tests__/workspace.api.test.ts +78 -1
- package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +0 -266
- package/src/modules/admin/components/ConnectionKeysPage.tsx +0 -269
- package/src/modules/admin/components/connection-keys-grouping.ts +0 -43
- package/src/modules/admin/services/connection-keys.api.ts +0 -47
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import { PageShell } from '../../../shared/components/PageShell';
|
|
3
|
-
import { Dialog } from '../../../shared/components/Dialog';
|
|
4
|
-
import { formatRelativeTime } from '../../../lib/utils';
|
|
5
|
-
import { GITHUB_LINK_KIND } from '../../../shared/marketplace-url';
|
|
6
|
-
import { useAdmin } from '../state/admin.context';
|
|
7
|
-
import {
|
|
8
|
-
listConnectionKeys,
|
|
9
|
-
revokeConnectionKey,
|
|
10
|
-
type AdminConnectionKey,
|
|
11
|
-
} from '../services/connection-keys.api';
|
|
12
|
-
import { groupByAccount } from './connection-keys-grouping';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* The shared formatter, plus the one word it deliberately leaves to the caller:
|
|
16
|
-
* a key that has never been used has no instant to describe.
|
|
17
|
-
*/
|
|
18
|
-
function formatRelative(ts: number | null): string {
|
|
19
|
-
return formatRelativeTime(ts) || 'never';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** The exact instant, for a hover — the row shows the relative form. */
|
|
23
|
-
function formatAbsolute(ts: number | null): string | undefined {
|
|
24
|
-
return ts === null ? undefined : new Date(ts).toLocaleString();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The Connection keys page (`/connection-keys`, admins only): every
|
|
29
|
-
* connection key on the deployment, grouped per account, with when it was
|
|
30
|
-
* created, when it was last used, and a revoke. It exists so a leaked or
|
|
31
|
-
* forgotten key can be cut off without signing in as its owner. Revoking
|
|
32
|
-
* keeps the row (dimmed, "Disconnected") so its last use stays visible;
|
|
33
|
-
* only the owner can delete it for good, from their own External agent
|
|
34
|
-
* access page. Disconnected keys are hidden by default — on a busy
|
|
35
|
-
* deployment they outnumber the live ones — and a toggle brings them back.
|
|
36
|
-
*/
|
|
37
|
-
export function ConnectionKeysPage() {
|
|
38
|
-
const { isAdmin } = useAdmin();
|
|
39
|
-
const [keys, setKeys] = useState<AdminConnectionKey[] | null>(null);
|
|
40
|
-
const [error, setError] = useState<string | null>(null);
|
|
41
|
-
const [showRevoked, setShowRevoked] = useState(false);
|
|
42
|
-
// The key awaiting revoke confirmation; non-null drives the confirm
|
|
43
|
-
// Dialog. `revoking` keeps the confirm open while the request is in flight.
|
|
44
|
-
const [pendingRevoke, setPendingRevoke] = useState<AdminConnectionKey | null>(null);
|
|
45
|
-
const [revoking, setRevoking] = useState(false);
|
|
46
|
-
|
|
47
|
-
// Generation of the newest load. Two revokes in quick succession start two
|
|
48
|
-
// reloads, and the older one can land last — carrying a key the newer one
|
|
49
|
-
// already saw revoked. Only the latest load may write `keys`.
|
|
50
|
-
const loadGen = useRef(0);
|
|
51
|
-
const refresh = useCallback(() => {
|
|
52
|
-
const gen = ++loadGen.current;
|
|
53
|
-
listConnectionKeys()
|
|
54
|
-
.then((rows) => {
|
|
55
|
-
if (gen !== loadGen.current) return;
|
|
56
|
-
setKeys(rows);
|
|
57
|
-
setError(null);
|
|
58
|
-
})
|
|
59
|
-
.catch((err) => {
|
|
60
|
-
if (gen !== loadGen.current) return;
|
|
61
|
-
setError(err instanceof Error ? err.message : "Couldn't load connection keys.");
|
|
62
|
-
// `keys` is deliberately left alone: a reload that fails keeps the
|
|
63
|
-
// rows it had, and a first load that fails stays `null` rather than
|
|
64
|
-
// rendering "No connection keys" for a deployment we cannot reach.
|
|
65
|
-
});
|
|
66
|
-
}, []);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (isAdmin) refresh();
|
|
70
|
-
}, [isAdmin, refresh]);
|
|
71
|
-
|
|
72
|
-
const groups = useMemo(() => (keys ? groupByAccount(keys, showRevoked) : []), [keys, showRevoked]);
|
|
73
|
-
const liveCount = keys?.filter((k) => k.revokedAt === null).length ?? 0;
|
|
74
|
-
const revokedCount = (keys?.length ?? 0) - liveCount;
|
|
75
|
-
|
|
76
|
-
async function confirmRevoke() {
|
|
77
|
-
if (!pendingRevoke || revoking) return;
|
|
78
|
-
setRevoking(true);
|
|
79
|
-
setError(null);
|
|
80
|
-
try {
|
|
81
|
-
const { id } = pendingRevoke;
|
|
82
|
-
await revokeConnectionKey(id);
|
|
83
|
-
// The server has revoked it; say so at once rather than waiting on the
|
|
84
|
-
// reload. If that reload fails, the row must not sit there looking live
|
|
85
|
-
// with a Revoke button — the agent holding this key is already cut off.
|
|
86
|
-
setKeys((prev) =>
|
|
87
|
-
prev
|
|
88
|
-
? prev.map((k) =>
|
|
89
|
-
k.id === id && k.revokedAt === null
|
|
90
|
-
? { ...k, revokedAt: Date.now(), revokedBy: 'admin' as const }
|
|
91
|
-
: k,
|
|
92
|
-
)
|
|
93
|
-
: prev,
|
|
94
|
-
);
|
|
95
|
-
setPendingRevoke(null);
|
|
96
|
-
refresh();
|
|
97
|
-
} catch (err) {
|
|
98
|
-
setPendingRevoke(null);
|
|
99
|
-
setError(err instanceof Error ? err.message : "Couldn't revoke this key.");
|
|
100
|
-
} finally {
|
|
101
|
-
setRevoking(false);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (!isAdmin) {
|
|
106
|
-
return (
|
|
107
|
-
<PageShell title="Connection keys">
|
|
108
|
-
<div className="text-sm text-ink-muted">
|
|
109
|
-
Admins only. Your own keys are on the External agent access page.
|
|
110
|
-
</div>
|
|
111
|
-
</PageShell>
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return (
|
|
116
|
-
<>
|
|
117
|
-
<PageShell title="Connection keys">
|
|
118
|
-
<div className="space-y-4">
|
|
119
|
-
<p className="text-xs text-ink-muted leading-snug">
|
|
120
|
-
Every connection key on this deployment, per account. Revoking a key cuts off the
|
|
121
|
-
external agent using it immediately; the key stays listed as disconnected so you can
|
|
122
|
-
still see when it was last used. Only its owner can delete it for good.
|
|
123
|
-
</p>
|
|
124
|
-
|
|
125
|
-
{error && (
|
|
126
|
-
<div
|
|
127
|
-
className="text-xs text-red-600 bg-red-50 border border-red-200 rounded-sm px-2 py-1.5"
|
|
128
|
-
role="alert"
|
|
129
|
-
>
|
|
130
|
-
{error}
|
|
131
|
-
</div>
|
|
132
|
-
)}
|
|
133
|
-
|
|
134
|
-
{keys !== null && (
|
|
135
|
-
<div className="flex items-center justify-between gap-3 text-xs text-ink-muted">
|
|
136
|
-
<span>
|
|
137
|
-
{liveCount} live {liveCount === 1 ? 'key' : 'keys'}
|
|
138
|
-
{revokedCount > 0 && ` · ${revokedCount} disconnected`}
|
|
139
|
-
</span>
|
|
140
|
-
{revokedCount > 0 && (
|
|
141
|
-
<label className="flex items-center gap-1.5 cursor-pointer select-none">
|
|
142
|
-
<input
|
|
143
|
-
type="checkbox"
|
|
144
|
-
checked={showRevoked}
|
|
145
|
-
onChange={(e) => setShowRevoked(e.target.checked)}
|
|
146
|
-
/>
|
|
147
|
-
Show disconnected keys
|
|
148
|
-
</label>
|
|
149
|
-
)}
|
|
150
|
-
</div>
|
|
151
|
-
)}
|
|
152
|
-
|
|
153
|
-
{keys === null ? (
|
|
154
|
-
error ? null : <div className="text-xs text-ink-muted">Loading…</div>
|
|
155
|
-
) : groups.length === 0 ? (
|
|
156
|
-
<div className="text-xs text-ink-muted">
|
|
157
|
-
{keys.length === 0 ? 'No connection keys on this deployment.' : 'No live connection keys.'}
|
|
158
|
-
</div>
|
|
159
|
-
) : (
|
|
160
|
-
<div className="space-y-4">
|
|
161
|
-
{groups.map((group) => {
|
|
162
|
-
const live = group.keys.filter((k) => k.revokedAt === null).length;
|
|
163
|
-
return (
|
|
164
|
-
<section key={group.user.id} aria-label={`Keys for ${group.user.email}`}>
|
|
165
|
-
<div className="flex items-baseline gap-2 px-1 pb-1.5">
|
|
166
|
-
<span className="text-sm font-medium truncate">{group.user.name}</span>
|
|
167
|
-
<span className="text-meta text-ink-muted truncate">{group.user.email}</span>
|
|
168
|
-
<span className="ml-auto text-meta text-ink-muted whitespace-nowrap">
|
|
169
|
-
{live} live
|
|
170
|
-
</span>
|
|
171
|
-
</div>
|
|
172
|
-
<ul className="divide-y divide-line border border-line rounded-sm">
|
|
173
|
-
{group.keys.map((k) => {
|
|
174
|
-
const revoked = k.revokedAt !== null;
|
|
175
|
-
return (
|
|
176
|
-
<li
|
|
177
|
-
key={k.id}
|
|
178
|
-
className={`flex items-center gap-3 px-3 py-2 text-sm ${
|
|
179
|
-
revoked ? 'opacity-60' : ''
|
|
180
|
-
}`}
|
|
181
|
-
>
|
|
182
|
-
<div className="flex-1 min-w-0">
|
|
183
|
-
<div className="font-medium truncate">
|
|
184
|
-
{k.label}
|
|
185
|
-
{k.kind === GITHUB_LINK_KIND && (
|
|
186
|
-
<span className="ml-1.5 text-meta font-normal text-ink-muted">
|
|
187
|
-
Claude link
|
|
188
|
-
</span>
|
|
189
|
-
)}
|
|
190
|
-
</div>
|
|
191
|
-
<div className="text-meta text-ink-muted">
|
|
192
|
-
<span title={formatAbsolute(k.createdAt)}>
|
|
193
|
-
Created {formatRelative(k.createdAt)}
|
|
194
|
-
</span>
|
|
195
|
-
{' · '}
|
|
196
|
-
<span title={formatAbsolute(k.lastUsedAt)}>
|
|
197
|
-
Last used {formatRelative(k.lastUsedAt)}
|
|
198
|
-
</span>
|
|
199
|
-
{revoked && (
|
|
200
|
-
<>
|
|
201
|
-
{' · '}
|
|
202
|
-
<span title={formatAbsolute(k.revokedAt)}>
|
|
203
|
-
{k.revokedBy === 'admin' ? 'Revoked by an admin' : 'Disconnected by owner'}{' '}
|
|
204
|
-
{formatRelative(k.revokedAt)}
|
|
205
|
-
</span>
|
|
206
|
-
</>
|
|
207
|
-
)}
|
|
208
|
-
</div>
|
|
209
|
-
</div>
|
|
210
|
-
{!revoked && (
|
|
211
|
-
<button
|
|
212
|
-
onClick={() => setPendingRevoke(k)}
|
|
213
|
-
className="text-xs px-2 py-1 rounded-sm text-red-700 hover:bg-red-50 border border-red-200"
|
|
214
|
-
title="Revoke this key. The external agent using it will lose access."
|
|
215
|
-
aria-label={`Revoke ${k.label} for ${group.user.email}`}
|
|
216
|
-
>
|
|
217
|
-
Revoke
|
|
218
|
-
</button>
|
|
219
|
-
)}
|
|
220
|
-
</li>
|
|
221
|
-
);
|
|
222
|
-
})}
|
|
223
|
-
</ul>
|
|
224
|
-
</section>
|
|
225
|
-
);
|
|
226
|
-
})}
|
|
227
|
-
</div>
|
|
228
|
-
)}
|
|
229
|
-
</div>
|
|
230
|
-
</PageShell>
|
|
231
|
-
|
|
232
|
-
<Dialog
|
|
233
|
-
open={pendingRevoke !== null}
|
|
234
|
-
onClose={() => setPendingRevoke(null)}
|
|
235
|
-
title="Revoke connection key"
|
|
236
|
-
size="sm"
|
|
237
|
-
busy={revoking}
|
|
238
|
-
footer={
|
|
239
|
-
<>
|
|
240
|
-
<button
|
|
241
|
-
onClick={() => setPendingRevoke(null)}
|
|
242
|
-
disabled={revoking}
|
|
243
|
-
className="px-3 py-1.5 text-sm rounded-sm text-ink hover:bg-hover border border-line disabled:opacity-50"
|
|
244
|
-
>
|
|
245
|
-
Cancel
|
|
246
|
-
</button>
|
|
247
|
-
<button
|
|
248
|
-
onClick={confirmRevoke}
|
|
249
|
-
disabled={revoking}
|
|
250
|
-
className="px-3 py-1.5 text-sm rounded-sm bg-red-600 hover:bg-red-700 text-white disabled:opacity-50 disabled:hover:bg-red-600"
|
|
251
|
-
>
|
|
252
|
-
{revoking ? 'Revoking…' : 'Revoke key'}
|
|
253
|
-
</button>
|
|
254
|
-
</>
|
|
255
|
-
}
|
|
256
|
-
>
|
|
257
|
-
<p className="text-xs text-ink leading-snug">
|
|
258
|
-
Revoke <span className="font-medium">{pendingRevoke?.label}</span> belonging to{' '}
|
|
259
|
-
<span className="font-medium">
|
|
260
|
-
{pendingRevoke?.user.name} ({pendingRevoke?.user.email})
|
|
261
|
-
</span>
|
|
262
|
-
? Whatever is using it loses access immediately. The key stays listed as disconnected
|
|
263
|
-
so its last use remains visible; its owner can delete it for good from their External
|
|
264
|
-
agent access page.
|
|
265
|
-
</p>
|
|
266
|
-
</Dialog>
|
|
267
|
-
</>
|
|
268
|
-
);
|
|
269
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { AdminConnectionKey } from '../services/connection-keys.api';
|
|
2
|
-
|
|
3
|
-
export interface AccountGroup {
|
|
4
|
-
user: AdminConnectionKey['user'];
|
|
5
|
-
keys: AdminConnectionKey[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* One list from the server, grouped per account in the order the server
|
|
10
|
-
* returned it (owner email). Within an account: live keys first, most
|
|
11
|
-
* recently used at the top, so the row an admin is hunting for — the key
|
|
12
|
-
* that is still being used — is never below the ones that are not.
|
|
13
|
-
*
|
|
14
|
-
* Lives beside {@link ConnectionKeysPage} rather than in it: a component
|
|
15
|
-
* file that also exports a plain function breaks fast refresh.
|
|
16
|
-
*/
|
|
17
|
-
export function groupByAccount(
|
|
18
|
-
keys: AdminConnectionKey[],
|
|
19
|
-
includeRevoked: boolean,
|
|
20
|
-
): AccountGroup[] {
|
|
21
|
-
const groups: AccountGroup[] = [];
|
|
22
|
-
const byUser = new Map<string, AccountGroup>();
|
|
23
|
-
for (const key of keys) {
|
|
24
|
-
if (!includeRevoked && key.revokedAt !== null) continue;
|
|
25
|
-
let group = byUser.get(key.user.id);
|
|
26
|
-
if (!group) {
|
|
27
|
-
group = { user: key.user, keys: [] };
|
|
28
|
-
byUser.set(key.user.id, group);
|
|
29
|
-
groups.push(group);
|
|
30
|
-
}
|
|
31
|
-
group.keys.push(key);
|
|
32
|
-
}
|
|
33
|
-
for (const group of groups) {
|
|
34
|
-
group.keys.sort((a, b) => {
|
|
35
|
-
const aRevoked = a.revokedAt !== null;
|
|
36
|
-
const bRevoked = b.revokedAt !== null;
|
|
37
|
-
if (aRevoked !== bRevoked) return aRevoked ? 1 : -1;
|
|
38
|
-
const byUse = (b.lastUsedAt ?? 0) - (a.lastUsedAt ?? 0);
|
|
39
|
-
return byUse !== 0 ? byUse : b.createdAt - a.createdAt;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
return groups;
|
|
43
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { authFetch } from '../../../lib/api';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* One row of the admin Connection keys overview
|
|
5
|
-
* (`GET /api/admin/connection-keys`): a key plus the account it belongs to.
|
|
6
|
-
* Never carries the plaintext — that was shown to the owner exactly once.
|
|
7
|
-
*/
|
|
8
|
-
export interface AdminConnectionKey {
|
|
9
|
-
id: string;
|
|
10
|
-
label: string;
|
|
11
|
-
/** `key` for a hand-made key; another kind for one a flow minted (a Claude link). */
|
|
12
|
-
kind: string;
|
|
13
|
-
createdAt: number;
|
|
14
|
-
lastUsedAt: number | null;
|
|
15
|
-
revokedAt: number | null;
|
|
16
|
-
/** Who ended it once revoked: the owner, or an admin. Null while live. */
|
|
17
|
-
revokedBy: 'owner' | 'admin' | null;
|
|
18
|
-
user: {
|
|
19
|
-
id: string;
|
|
20
|
-
email: string;
|
|
21
|
-
name: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function readError(res: Response, fallback: string): Promise<string> {
|
|
26
|
-
const body = await res.json().catch(() => ({}));
|
|
27
|
-
return (body as { error?: string }).error || fallback;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Every connection key on the deployment, ordered by owner email then newest-first. */
|
|
31
|
-
export async function listConnectionKeys(): Promise<AdminConnectionKey[]> {
|
|
32
|
-
const res = await authFetch('/api/admin/connection-keys');
|
|
33
|
-
if (!res.ok) throw new Error(await readError(res, 'Could not load connection keys'));
|
|
34
|
-
const body = (await res.json()) as { keys: AdminConnectionKey[] };
|
|
35
|
-
return body.keys;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Revoke (disconnect) any account's key. The row is kept so its last-used
|
|
40
|
-
* time stays auditable; the agent holding the key loses access at once.
|
|
41
|
-
*/
|
|
42
|
-
export async function revokeConnectionKey(id: string): Promise<void> {
|
|
43
|
-
const res = await authFetch(`/api/admin/connection-keys/${encodeURIComponent(id)}`, {
|
|
44
|
-
method: 'DELETE',
|
|
45
|
-
});
|
|
46
|
-
if (!res.ok) throw new Error(await readError(res, 'Could not revoke this key'));
|
|
47
|
-
}
|