refactor(auth): standardize session management and security
- Centralize secret retrieval using `getAdminSessionSecret` - Replace manual session parsing with `verifyRequestAdminSession` utility - Tighten API validation and improve security headers handling - Enforce environment variable security for production deployments
This commit is contained in:
1 parent
34519c07df
commit
177ed4a844
78 files changed
+6748
-3157
No files matched your search
@@ -19,8 +19,8 @@ export function AdminLogin({
|
||||
}: {
|
||||
showDemoHint?: boolean;
|
||||
}) {
|
||||
const [email, setEmail] = useState(showDemoHint ? 'admin@datastack.dev' : '');
|
||||
const [password, setPassword] = useState(showDemoHint ? 'admin12345678' : '');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [remember, setRemember] = useState(true);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
|
||||
@@ -17,6 +17,7 @@ const FILTERS: { key: ClientStatusFilter; label: string }[] = [
|
||||
{ key: 'online', label: 'Online' },
|
||||
{ key: 'offline', label: 'Offline' },
|
||||
{ key: 'pending', label: 'Pending' },
|
||||
{ key: 'revoked', label: 'Revoked' },
|
||||
];
|
||||
|
||||
export function ClientsFilters({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { CopyButton } from '@/components/ui/CopyButton';
|
||||
import { Textarea } from '@/components/ui/Input';
|
||||
import { Input, Textarea } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import {
|
||||
Table,
|
||||
@@ -43,8 +43,61 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
type: 'rotate' | 'revoke' | 'delete';
|
||||
client: ClientItem;
|
||||
} | null>(null);
|
||||
const [editClient, setEditClient] = useState<ClientItem | null>(null);
|
||||
const [editName, setEditName] = useState('');
|
||||
const [editRateLimit, setEditRateLimit] = useState('100');
|
||||
const [editError, setEditError] = useState('');
|
||||
const [processing, setProcessing] = useState(false);
|
||||
|
||||
const openEditModal = (client: ClientItem) => {
|
||||
setEditClient(client);
|
||||
setEditName(client.name);
|
||||
setEditRateLimit(String(client.rateLimit || 100));
|
||||
setEditError('');
|
||||
};
|
||||
|
||||
const executeEditClient = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (!editClient) return;
|
||||
|
||||
const trimmedName = editName.trim();
|
||||
const numericRateLimit = Number(editRateLimit);
|
||||
if (!trimmedName) {
|
||||
setEditError('Display name is required.');
|
||||
return;
|
||||
}
|
||||
if (!Number.isFinite(numericRateLimit) || numericRateLimit < 1 || numericRateLimit > 10000) {
|
||||
setEditError('Rate limit must be between 1 and 10,000 events/s.');
|
||||
return;
|
||||
}
|
||||
|
||||
setEditError('');
|
||||
setProcessing(true);
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(editClient.clientId)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name: trimmedName,
|
||||
rateLimit: Math.floor(numericRateLimit),
|
||||
}),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to update client');
|
||||
success('Client updated', `${editClient.clientId} settings saved.`);
|
||||
setEditClient(null);
|
||||
await onStatusChange();
|
||||
} catch (updateError) {
|
||||
error('Client update failed', updateError instanceof Error ? updateError.message : 'Unknown error');
|
||||
} finally {
|
||||
setProcessing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const executeRotateKey = async (client: ClientItem) => {
|
||||
setProcessing(true);
|
||||
try {
|
||||
@@ -53,6 +106,10 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'regenerate_token' }),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to rotate credentials');
|
||||
setConfirmAction(null);
|
||||
@@ -74,6 +131,10 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to update client status');
|
||||
setConfirmAction(null);
|
||||
@@ -92,6 +153,10 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to delete client');
|
||||
setConfirmAction(null);
|
||||
@@ -130,7 +195,7 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>API key</TableHead>
|
||||
<TableHead>Credentials</TableHead>
|
||||
<TableHead className="text-right">Events</TableHead>
|
||||
<TableHead>Last seen</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
@@ -141,15 +206,18 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
<TableEmpty colSpan={5} message="No matching clients" />
|
||||
) : (
|
||||
clients.map((client) => {
|
||||
const revoked = client.status === 'revoked';
|
||||
const online = client.status === 'active' && Boolean(client.lastActive) &&
|
||||
now - new Date(client.lastActive!).getTime() < 60_000;
|
||||
const pending = client.status === 'active' && !client.lastActive;
|
||||
const label = pending ? 'pending' : online ? 'online' : 'offline';
|
||||
const dotClass = online
|
||||
? 'bg-[var(--accent)]'
|
||||
: pending
|
||||
? 'bg-[var(--warning)]'
|
||||
: 'bg-[var(--text-faint)]';
|
||||
const label = revoked ? 'revoked' : pending ? 'pending' : online ? 'online' : 'offline';
|
||||
const dotClass = revoked
|
||||
? 'bg-[var(--danger)]'
|
||||
: online
|
||||
? 'bg-[var(--accent)]'
|
||||
: pending
|
||||
? 'bg-[var(--warning)]'
|
||||
: 'bg-[var(--text-faint)]';
|
||||
|
||||
return (
|
||||
<TableRow key={client.clientId}>
|
||||
@@ -157,13 +225,25 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className={`h-1.5 w-1.5 shrink-0 ${dotClass}`} title={label} />
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div className="truncate font-medium text-[var(--text)]">{client.name}</div>
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate font-medium text-[var(--text)]">{client.name}</span>
|
||||
{revoked && (
|
||||
<span className="border border-[var(--danger)] bg-[var(--danger-soft)] px-1 py-0 text-[9px] uppercase tracking-wider text-[var(--danger)]">
|
||||
revoked
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-0.5 truncate font-mono text-[10.5px] text-[var(--text-faint)]">{client.clientId}</div>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono">
|
||||
sec_••••••••
|
||||
<div className="truncate text-[11px] text-[var(--text)]">
|
||||
{client.tokenPreview || 'JWT Active'}
|
||||
</div>
|
||||
<div className="mt-0.5 text-[10px] text-[var(--text-faint)]">
|
||||
{client.rateLimit}/s limit
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono tabular-nums">
|
||||
{client.totalEvents.toLocaleString()}
|
||||
@@ -184,6 +264,16 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
aria-label={`View events for ${client.clientId}`}
|
||||
onClick={() => router.push(`/vcon/data?clientId=${encodeURIComponent(client.clientId)}`)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="Pencil"
|
||||
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
||||
title={`Edit ${client.clientId}`}
|
||||
aria-label={`Edit ${client.clientId}`}
|
||||
onClick={() => openEditModal(client)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
@@ -224,6 +314,55 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
<Modal
|
||||
isOpen={Boolean(editClient)}
|
||||
onClose={() => !processing && setEditClient(null)}
|
||||
title={`Edit client: ${editClient?.clientId || ''}`}
|
||||
maxWidth="xs"
|
||||
footer={
|
||||
<>
|
||||
<Button type="button" variant="ghost" size="xs" disabled={processing} onClick={() => setEditClient(null)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
form="edit-client-form"
|
||||
variant="primary"
|
||||
size="xs"
|
||||
loading={processing}
|
||||
>
|
||||
Save changes
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="edit-client-form" onSubmit={executeEditClient} className="flex flex-col gap-2.5">
|
||||
<Input
|
||||
label="Display name"
|
||||
compact
|
||||
value={editName}
|
||||
onChange={(event) => setEditName(event.target.value)}
|
||||
placeholder="Service display name"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Rate limit (events/s)"
|
||||
compact
|
||||
type="number"
|
||||
min="1"
|
||||
max="10000"
|
||||
value={editRateLimit}
|
||||
onChange={(event) => setEditRateLimit(event.target.value)}
|
||||
required
|
||||
/>
|
||||
{editError && (
|
||||
<p role="alert" className="text-[11px] text-[var(--danger)]">
|
||||
{editError}
|
||||
</p>
|
||||
)}
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
isOpen={Boolean(confirmAction)}
|
||||
onClose={() => !processing && setConfirmAction(null)}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
@@ -26,6 +27,7 @@ type EventItem = {
|
||||
};
|
||||
|
||||
type DashboardMetrics = {
|
||||
activeSockets?: number;
|
||||
activeClients: number;
|
||||
totalClients: number;
|
||||
bufferStats: {
|
||||
@@ -62,6 +64,7 @@ export const DashboardOverview: React.FC = () => {
|
||||
getCached<StorageFile[]>('vcon:storage-files', [])
|
||||
);
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
const [fetchError, setFetchError] = useState('');
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setIsRefreshing(true);
|
||||
@@ -74,25 +77,58 @@ export const DashboardOverview: React.FC = () => {
|
||||
fetch('/api/clients', { cache: 'no-store' }),
|
||||
]);
|
||||
|
||||
if (
|
||||
metricsResponse.status === 401 ||
|
||||
eventsResponse.status === 401 ||
|
||||
storageResponse.status === 401 ||
|
||||
clientsResponse.status === 401
|
||||
) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
|
||||
const errors: string[] = [];
|
||||
|
||||
if (metricsResponse.ok) {
|
||||
const nextMetrics = await metricsResponse.json();
|
||||
setMetrics(setCached('vcon:metrics', nextMetrics));
|
||||
} else {
|
||||
errors.push('metrics');
|
||||
}
|
||||
|
||||
if (eventsResponse.ok) {
|
||||
const data = await eventsResponse.json();
|
||||
setEvents(setCached('vcon:dashboard-events', data.events ?? []));
|
||||
} else {
|
||||
errors.push('events');
|
||||
}
|
||||
|
||||
if (storageResponse.ok) {
|
||||
const data = await storageResponse.json();
|
||||
setFiles(setCached('vcon:storage-files', data.files ?? []));
|
||||
if (data.stats) setCached('vcon:storage-stats', data.stats);
|
||||
} else {
|
||||
errors.push('storage');
|
||||
}
|
||||
|
||||
if (clientsResponse.ok) {
|
||||
const data = await clientsResponse.json();
|
||||
setClients(setCached('vcon:clients', data.clients ?? []));
|
||||
} else {
|
||||
errors.push('clients');
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
setFetchError(
|
||||
`Partial telemetry refresh failed (${errors.join(', ')}). Showing last available snapshot.`
|
||||
);
|
||||
} else {
|
||||
setFetchError('');
|
||||
}
|
||||
} catch {
|
||||
// Keep the last successful dashboard snapshot when one request fails.
|
||||
setFetchError(
|
||||
'Unable to reach telemetry endpoints. Showing last available snapshot.'
|
||||
);
|
||||
} finally {
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
@@ -108,18 +144,21 @@ export const DashboardOverview: React.FC = () => {
|
||||
const storedRecordsToday = files
|
||||
.filter((file) => file.date === today)
|
||||
.reduce((total, file) => total + file.linesCount, 0);
|
||||
const eventsToday =
|
||||
storedRecordsToday + (metrics?.bufferStats.currentBufferSize ?? 0);
|
||||
const bufferedCount = metrics?.bufferStats.currentBufferSize ?? 0;
|
||||
const eventsToday = storedRecordsToday + bufferedCount;
|
||||
const activeClients =
|
||||
metrics?.activeClients ??
|
||||
clients.filter((client) => client.status === 'active').length;
|
||||
const totalClients = metrics?.totalClients ?? clients.length;
|
||||
const activeSockets = metrics?.activeSockets ?? 0;
|
||||
const totalStorage = metrics?.storageStats.totalMB ?? '0.00';
|
||||
const totalStorageBytes = metrics?.storageStats.totalBytes ?? 0;
|
||||
const storageValue =
|
||||
totalStorageBytes < 1024 * 1024
|
||||
? String(Math.max(1, Math.round(totalStorageBytes / 1024)))
|
||||
: totalStorage;
|
||||
totalStorageBytes === 0
|
||||
? '0'
|
||||
: totalStorageBytes < 1024 * 1024
|
||||
? String(Math.max(1, Math.round(totalStorageBytes / 1024)))
|
||||
: totalStorage;
|
||||
const storageUnit = totalStorageBytes < 1024 * 1024 ? 'KB' : 'MB';
|
||||
const totalFiles = metrics?.storageStats.totalFiles ?? files.length;
|
||||
const totalRows =
|
||||
@@ -153,13 +192,22 @@ export const DashboardOverview: React.FC = () => {
|
||||
</>
|
||||
}
|
||||
>
|
||||
{fetchError && (
|
||||
<div
|
||||
role="alert"
|
||||
className="mb-3 border border-[var(--danger)] bg-[var(--danger-soft)] px-3 py-2 text-[11.5px] text-[var(--text)]"
|
||||
>
|
||||
{fetchError}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<StatStrip
|
||||
items={[
|
||||
{ label: 'Events today', value: eventsToday.toLocaleString() },
|
||||
{
|
||||
label: 'Active clients',
|
||||
value: `${activeClients} / ${totalClients}`,
|
||||
dot: activeClients > 0 ? 'ok' : 'off',
|
||||
label: 'Active clients · Sockets',
|
||||
value: `${activeClients} / ${totalClients} · ${activeSockets} ws`,
|
||||
dot: activeClients > 0 || activeSockets > 0 ? 'ok' : 'off',
|
||||
},
|
||||
{ label: 'Storage used', value: `${storageValue} ${storageUnit}` },
|
||||
{ label: 'Stored rows', value: totalRows.toLocaleString() },
|
||||
@@ -169,7 +217,11 @@ export const DashboardOverview: React.FC = () => {
|
||||
<div className="grid min-w-0 grid-cols-1 gap-3 lg:grid-cols-[minmax(0,1.85fr)_minmax(0,1fr)]">
|
||||
<Panel
|
||||
title="Recent events"
|
||||
meta={`${events.length}`}
|
||||
meta={
|
||||
bufferedCount > 0
|
||||
? `${events.length} · ${bufferedCount} buffered`
|
||||
: `${events.length}`
|
||||
}
|
||||
action={
|
||||
<Link
|
||||
href="/vcon/data"
|
||||
@@ -190,24 +242,28 @@ export const DashboardOverview: React.FC = () => {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{events.map((event) => (
|
||||
<TableRow key={event.eventId}>
|
||||
<TableCell className="font-mono tabular-nums text-[var(--text-faint)]">
|
||||
{event.timestamp.includes('T')
|
||||
? new Date(event.timestamp).toLocaleTimeString()
|
||||
: event.timestamp}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[var(--accent)]">
|
||||
{event.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[380px] truncate font-mono text-[var(--text)]">
|
||||
{event.payload}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono tabular-nums text-[var(--text-faint)]">
|
||||
{new TextEncoder().encode(event.payload).length} B
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
{events.length === 0 ? (
|
||||
<TableEmpty colSpan={4} message="No recent events" />
|
||||
) : (
|
||||
events.map((event) => (
|
||||
<TableRow key={event.eventId}>
|
||||
<TableCell className="font-mono tabular-nums text-[var(--text-faint)]">
|
||||
{event.timestamp.includes('T')
|
||||
? new Date(event.timestamp).toLocaleTimeString()
|
||||
: event.timestamp}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[var(--accent)]">
|
||||
{event.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[380px] truncate font-mono text-[var(--text)]">
|
||||
{event.payload}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono tabular-nums text-[var(--text-faint)]">
|
||||
{new TextEncoder().encode(event.payload).length} B
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
import { PageShell } from '@/components/layout/PageShell';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { CodeBlock } from '@/components/ui/CodeBlock';
|
||||
import { CopyButton } from '@/components/ui/CopyButton';
|
||||
import { Input, Select } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import { Pill } from '@/components/ui/Pill';
|
||||
import {
|
||||
@@ -34,6 +37,18 @@ interface Client {
|
||||
|
||||
const PAGE_SIZE = 12;
|
||||
|
||||
function formatEventPayload(raw: string): string {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(raw), null, 2);
|
||||
} catch {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
function getPayloadBytes(raw: string): number {
|
||||
return new TextEncoder().encode(raw).length;
|
||||
}
|
||||
|
||||
export function DataBrowser() {
|
||||
const router = useRouter();
|
||||
const [events, setEvents] = useState<StreamEvent[]>([]);
|
||||
@@ -54,6 +69,7 @@ export function DataBrowser() {
|
||||
const [filtersReady, setFiltersReady] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
const [selectedEvent, setSelectedEvent] = useState<StreamEvent | null>(null);
|
||||
|
||||
const fetchEvents = useCallback(async () => {
|
||||
try {
|
||||
@@ -65,7 +81,11 @@ export function DataBrowser() {
|
||||
page: String(page),
|
||||
pageSize: String(PAGE_SIZE),
|
||||
});
|
||||
const response = await fetch(`/api/data?${params}`);
|
||||
const response = await fetch(`/api/data?${params}`, { cache: 'no-store' });
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
if (!response.ok) throw new Error('Unable to load events');
|
||||
const data = await response.json();
|
||||
setEvents(data.events || []);
|
||||
@@ -78,8 +98,14 @@ export function DataBrowser() {
|
||||
}, [appliedFilters, page]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/clients')
|
||||
.then((response) => (response.ok ? response.json() : { clients: [] }))
|
||||
fetch('/api/clients', { cache: 'no-store' })
|
||||
.then((response) => {
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return { clients: [] };
|
||||
}
|
||||
return response.ok ? response.json() : { clients: [] };
|
||||
})
|
||||
.then((data) => setClients(data.clients || []))
|
||||
.catch(() => setClients([]));
|
||||
}, []);
|
||||
@@ -131,6 +157,10 @@ export function DataBrowser() {
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
const formattedSelectedPayload = selectedEvent
|
||||
? formatEventPayload(selectedEvent.payload)
|
||||
: '';
|
||||
|
||||
return (
|
||||
<PageShell
|
||||
title="Events"
|
||||
@@ -238,7 +268,11 @@ export function DataBrowser() {
|
||||
<TableEmpty colSpan={6} message="No matching events" />
|
||||
) : (
|
||||
events.map((event) => (
|
||||
<TableRow key={event.eventId}>
|
||||
<TableRow
|
||||
key={`${event.clientId}:${event.eventId}`}
|
||||
className="cursor-pointer"
|
||||
onClick={() => setSelectedEvent(event)}
|
||||
>
|
||||
<TableCell className="font-mono tabular-nums text-[var(--text)]">
|
||||
{new Date(event.timestamp).toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
@@ -257,13 +291,34 @@ export function DataBrowser() {
|
||||
{event.payload}
|
||||
</TableCell>
|
||||
<TableCell className="hidden font-mono tabular-nums md:table-cell">
|
||||
{new TextEncoder().encode(event.payload).length} B
|
||||
{getPayloadBytes(event.payload)} B
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<span className="inline-flex items-center gap-1.5 text-[var(--text-muted)]">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--accent)]" />
|
||||
{event.status}
|
||||
</span>
|
||||
<div className="inline-flex items-center gap-2">
|
||||
<span className="inline-flex items-center gap-1.5 text-[var(--text-muted)]">
|
||||
<span
|
||||
className={`h-1.5 w-1.5 ${
|
||||
event.status === 'buffered'
|
||||
? 'bg-[var(--warning)]'
|
||||
: 'bg-[var(--accent)]'
|
||||
}`}
|
||||
/>
|
||||
{event.status}
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="Eye"
|
||||
className="h-5 w-5 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
||||
title={`Inspect event ${event.eventId}`}
|
||||
aria-label={`Inspect event ${event.eventId}`}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setSelectedEvent(event);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
@@ -338,6 +393,69 @@ export function DataBrowser() {
|
||||
</nav>
|
||||
</footer>
|
||||
</Panel>
|
||||
|
||||
<Modal
|
||||
isOpen={Boolean(selectedEvent)}
|
||||
onClose={() => setSelectedEvent(null)}
|
||||
title={`Event payload: ${selectedEvent?.eventId || ''}`}
|
||||
maxWidth="lg"
|
||||
footer={
|
||||
<Button type="button" size="xs" onClick={() => setSelectedEvent(null)}>
|
||||
Close
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{selectedEvent && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="grid grid-cols-2 gap-px border border-[var(--border)] bg-[var(--border)] sm:grid-cols-4">
|
||||
<div className="bg-[var(--surface)] p-2">
|
||||
<div className="text-[9.5px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
Client
|
||||
</div>
|
||||
<div className="truncate font-mono text-[11.5px] text-[var(--accent)]">
|
||||
{selectedEvent.clientId}
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-2">
|
||||
<div className="text-[9.5px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
Status
|
||||
</div>
|
||||
<div className="font-mono text-[11.5px] text-[var(--text)]">
|
||||
{selectedEvent.status}
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-2">
|
||||
<div className="text-[9.5px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
Size
|
||||
</div>
|
||||
<div className="font-mono text-[11.5px] tabular-nums text-[var(--text)]">
|
||||
{getPayloadBytes(selectedEvent.payload)} B
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-2">
|
||||
<div className="text-[9.5px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
Timestamp
|
||||
</div>
|
||||
<div className="truncate font-mono text-[11px] tabular-nums text-[var(--text-muted)]">
|
||||
{selectedEvent.timestamp}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
JSON / Raw Payload
|
||||
</span>
|
||||
<CopyButton value={formattedSelectedPayload} />
|
||||
</div>
|
||||
<CodeBlock className="max-h-[340px] border border-[var(--border)] text-[11px]">
|
||||
{formattedSelectedPayload}
|
||||
</CodeBlock>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -56,6 +56,7 @@ export function ExportWorkspace() {
|
||||
const [files, setFiles] = useState<StorageFile[]>(() =>
|
||||
getCached<StorageFile[]>('vcon:storage-files', [])
|
||||
);
|
||||
const [bufferedCount, setBufferedCount] = useState<number>(0);
|
||||
const [selectedClient, setSelectedClient] = useState('all');
|
||||
const [fromDate, setFromDate] = useState('');
|
||||
const [toDate, setToDate] = useState('');
|
||||
@@ -69,19 +70,33 @@ export function ExportWorkspace() {
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([
|
||||
fetch('/api/clients').then(async (response) => {
|
||||
fetch('/api/clients', { cache: 'no-store' }).then(async (response) => {
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return { clients: [] };
|
||||
}
|
||||
if (!response.ok) throw new Error('Unable to load clients');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/storage').then(async (response) => {
|
||||
fetch('/api/storage', { cache: 'no-store' }).then(async (response) => {
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return { files: [] };
|
||||
}
|
||||
if (!response.ok) throw new Error('Unable to load stored files');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/metrics', { cache: 'no-store' })
|
||||
.then(async (response) => (response.ok ? response.json() : null))
|
||||
.catch(() => null),
|
||||
])
|
||||
.then(([clientData, storageData]) => {
|
||||
.then(([clientData, storageData, metricsData]) => {
|
||||
setClients(setCached('vcon:clients', clientData.clients || []));
|
||||
setFiles(setCached('vcon:storage-files', storageData.files || []));
|
||||
if (storageData.stats) setCached('vcon:storage-stats', storageData.stats);
|
||||
if (metricsData?.bufferStats) {
|
||||
setBufferedCount(Number(metricsData.bufferStats.currentBufferSize) || 0);
|
||||
}
|
||||
setLoadError('');
|
||||
})
|
||||
.catch((fetchError) => {
|
||||
@@ -162,15 +177,24 @@ export function ExportWorkspace() {
|
||||
return `/api/export?${params.toString()}`;
|
||||
}, [format, fromDate, selectedClient, toDate]);
|
||||
|
||||
const invalidRange = Boolean(fromDate && toDate && fromDate > toDate);
|
||||
const nothingToExport = preview.rows === 0 && bufferedCount === 0;
|
||||
|
||||
const downloadExport = () => {
|
||||
if (fromDate && toDate && fromDate > toDate) {
|
||||
if (invalidRange) {
|
||||
error('Invalid date range', 'Start date must be on or before end date.');
|
||||
return;
|
||||
}
|
||||
if (nothingToExport) {
|
||||
error('Nothing to export', 'No stored rows or buffered events match the selected filters.');
|
||||
return;
|
||||
}
|
||||
window.location.assign(exportUrl);
|
||||
info(
|
||||
'Export started',
|
||||
`${format.toUpperCase()} download for ${preview.rows.toLocaleString()} rows.`
|
||||
bufferedCount > 0
|
||||
? `${format.toUpperCase()} download (${preview.rows.toLocaleString()} stored + ${bufferedCount} buffered auto-flushed).`
|
||||
: `${format.toUpperCase()} download for ${preview.rows.toLocaleString()} rows.`
|
||||
);
|
||||
};
|
||||
|
||||
@@ -307,17 +331,30 @@ export function ExportWorkspace() {
|
||||
</strong>{' '}
|
||||
files
|
||||
</span>
|
||||
{bufferedCount > 0 && (
|
||||
<>
|
||||
<span aria-hidden="true">·</span>
|
||||
<span className="text-[var(--warning)]">
|
||||
+{bufferedCount} buffered (flushed on export)
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{loadError && (
|
||||
<p role="alert" className="text-[11px] text-[var(--text-muted)]">
|
||||
<p role="alert" className="text-[11px] text-[var(--danger)]">
|
||||
{loadError}
|
||||
</p>
|
||||
)}
|
||||
{fromDate && toDate && fromDate > toDate && (
|
||||
<p role="alert" className="text-[11px] text-[var(--text-muted)]">
|
||||
{invalidRange && (
|
||||
<p role="alert" className="text-[11px] text-[var(--danger)]">
|
||||
Start date must be on or before end date.
|
||||
</p>
|
||||
)}
|
||||
{!loading && !invalidRange && nothingToExport && (
|
||||
<p role="status" className="text-[11px] text-[var(--text-faint)]">
|
||||
No stored rows or buffered events match the selected filters.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-end gap-1.5 border-t border-[var(--border)] pt-2.5">
|
||||
<Button type="button" size="xs" onClick={resetExport}>
|
||||
@@ -328,7 +365,7 @@ export function ExportWorkspace() {
|
||||
variant="primary"
|
||||
size="xs"
|
||||
icon="Download"
|
||||
disabled={loading || Boolean(fromDate && toDate && fromDate > toDate)}
|
||||
disabled={loading || invalidRange || nothingToExport}
|
||||
onClick={downloadExport}
|
||||
>
|
||||
Download {format.toUpperCase()}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ActivityPreview } from '@/components/ui/ActivityPreview';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { buttonClassNames } from '@/components/ui/Button';
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
@@ -17,11 +17,11 @@ export const Hero: React.FC = () => (
|
||||
Keep activity organized, review the records that matter, and export them when you need them.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<Link href="#features">
|
||||
<Button variant="primary" size="sm">Explore features</Button>
|
||||
<Link href="/#features" className={buttonClassNames({ variant: 'primary', size: 'sm' })}>
|
||||
Explore features
|
||||
</Link>
|
||||
<Link href="#sdk">
|
||||
<Button variant="secondary" size="sm">Python SDK</Button>
|
||||
<Link href="/#sdk" className={buttonClassNames({ variant: 'secondary', size: 'sm' })}>
|
||||
Python SDK
|
||||
</Link>
|
||||
</div>
|
||||
<ActivityPreview />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { buttonClassNames } from '@/components/ui/Button';
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
@@ -8,8 +8,8 @@ export const LandingAbout: React.FC = () => (
|
||||
<h2 className="mb-1 text-[20px] font-medium text-[var(--text)]">Ready to simplify your data workflow?</h2>
|
||||
<p className="text-[13px] text-[var(--text-muted)]">Start with the SDK guide and make the workspace your own.</p>
|
||||
</div>
|
||||
<Link href="#sdk">
|
||||
<Button variant="primary" size="sm">View Python SDK</Button>
|
||||
<Link href="/#sdk" className={buttonClassNames({ variant: 'primary', size: 'sm' })}>
|
||||
View Python SDK
|
||||
</Link>
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@ import { PageShell } from '@/components/layout/PageShell';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { FormSwitch } from '@/components/ui/Form';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import {
|
||||
SettingsField,
|
||||
SettingsFooter,
|
||||
@@ -14,7 +15,7 @@ import {
|
||||
import { StatStrip } from '@/components/ui/StatStrip';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { getCached, setCached } from '@/lib/vconCache';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
interface EditableSettings {
|
||||
maxEventsPerSec: number;
|
||||
@@ -50,6 +51,7 @@ const TABS = [
|
||||
];
|
||||
|
||||
type TabId = (typeof TABS)[number]['id'];
|
||||
type SocketHealthState = 'idle' | 'checking' | 'online' | 'offline';
|
||||
|
||||
export function SettingsWorkspace() {
|
||||
const { success, error } = useToast();
|
||||
@@ -61,11 +63,15 @@ export function SettingsWorkspace() {
|
||||
);
|
||||
const [activeTab, setActiveTab] = useState<TabId>('general');
|
||||
const [jwtSecret, setJwtSecret] = useState('');
|
||||
const [jwtError, setJwtError] = useState('');
|
||||
const [confirmRotateOpen, setConfirmRotateOpen] = useState(false);
|
||||
const [storagePath, setStoragePath] = useState(() =>
|
||||
getCached<string>('vcon:storage-path', '')
|
||||
);
|
||||
const [baseUrl, setBaseUrl] = useState('');
|
||||
const [webSocketUrl, setWebSocketUrl] = useState('');
|
||||
const [socketStatus, setSocketStatus] = useState<SocketHealthState>('idle');
|
||||
const [activeSockets, setActiveSockets] = useState<number>(0);
|
||||
const [serverPort, setServerPort] = useState(() =>
|
||||
getCached<number>('vcon:server-port', 4000)
|
||||
);
|
||||
@@ -74,26 +80,60 @@ export function SettingsWorkspace() {
|
||||
);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
const probeSocketServer = useCallback(async (port: number) => {
|
||||
setSocketStatus('checking');
|
||||
const isLocalDev = window.location.port === '3000';
|
||||
const httpHost = isLocalDev
|
||||
? `${window.location.hostname}:${port}`
|
||||
: window.location.host;
|
||||
const healthUrl = `${window.location.protocol}//${httpHost}/health`;
|
||||
|
||||
try {
|
||||
const response = await fetch(healthUrl, {
|
||||
cache: 'no-store',
|
||||
signal: AbortSignal.timeout(1500),
|
||||
});
|
||||
setSocketStatus(response.ok ? 'online' : 'offline');
|
||||
} catch {
|
||||
setSocketStatus('offline');
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setBaseUrl(window.location.origin);
|
||||
const isLocalDev = window.location.port === '3000';
|
||||
const socketProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
const socketHost = isLocalDev
|
||||
? `${window.location.hostname}:4000`
|
||||
? `${window.location.hostname}:${serverPort}`
|
||||
: window.location.host;
|
||||
setWebSocketUrl(`${socketProtocol}://${socketHost}`);
|
||||
|
||||
Promise.all([
|
||||
fetch('/api/settings').then(async (response) => {
|
||||
fetch('/api/settings', { cache: 'no-store' }).then(async (response) => {
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return null;
|
||||
}
|
||||
if (!response.ok) throw new Error('Unable to load settings');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/storage').then(async (response) => {
|
||||
fetch('/api/storage', { cache: 'no-store' }).then(async (response) => {
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return null;
|
||||
}
|
||||
if (!response.ok) throw new Error('Unable to load storage information');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/metrics', { cache: 'no-store' })
|
||||
.then(async (response) => (response.ok ? response.json() : null))
|
||||
.catch(() => null),
|
||||
])
|
||||
.then(([settingsData, storageData]) => {
|
||||
.then(([settingsData, storageData, metricsData]) => {
|
||||
if (!settingsData || !storageData) return;
|
||||
const loadedPort = Number(
|
||||
(settingsData.settings as PublicSettings).serverPort ?? 4000
|
||||
);
|
||||
const loaded: EditableSettings = {
|
||||
maxEventsPerSec: Number(
|
||||
settingsData.settings.maxEventsPerSec ??
|
||||
@@ -126,25 +166,26 @@ export function SettingsWorkspace() {
|
||||
};
|
||||
setSettings(setCached('vcon:settings', loaded));
|
||||
setSavedSettings(loaded);
|
||||
setServerPort(
|
||||
setCached(
|
||||
'vcon:server-port',
|
||||
Number((settingsData.settings as PublicSettings).serverPort ?? 4000)
|
||||
)
|
||||
);
|
||||
setServerPort(setCached('vcon:server-port', loadedPort));
|
||||
setStoragePath(
|
||||
setCached(
|
||||
'vcon:storage-path',
|
||||
String(storageData.stats?.storageDirectory ?? '')
|
||||
)
|
||||
);
|
||||
if (metricsData && typeof metricsData.activeSockets === 'number') {
|
||||
setActiveSockets(metricsData.activeSockets);
|
||||
if (metricsData.activeSockets > 0) {
|
||||
setSocketStatus('online');
|
||||
}
|
||||
}
|
||||
setCached('vcon:settings-loaded', true);
|
||||
})
|
||||
.catch(() => {
|
||||
error('Settings load failed', 'Using default runtime settings.');
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, [error]);
|
||||
}, [error, serverPort]);
|
||||
|
||||
const isDirty = useMemo(
|
||||
() =>
|
||||
@@ -157,9 +198,9 @@ export function SettingsWorkspace() {
|
||||
setSettings((current) => ({ ...current, [key]: Number(value) || 0 }));
|
||||
};
|
||||
|
||||
const saveSettings = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const normalized: EditableSettings = {
|
||||
const buildNormalizedSettings = (): EditableSettings => {
|
||||
const parsedPrune = Number(settings.autoPruneDays);
|
||||
return {
|
||||
maxEventsPerSec: Math.max(
|
||||
1,
|
||||
Math.min(
|
||||
@@ -187,11 +228,16 @@ export function SettingsWorkspace() {
|
||||
settings.fileRotationMb || DEFAULT_SETTINGS.fileRotationMb
|
||||
),
|
||||
enableIdempotency: settings.enableIdempotency,
|
||||
autoPruneDays: Math.max(
|
||||
1,
|
||||
Math.min(365, settings.autoPruneDays || DEFAULT_SETTINGS.autoPruneDays)
|
||||
),
|
||||
autoPruneDays: Number.isFinite(parsedPrune)
|
||||
? Math.max(0, Math.min(365, Math.floor(parsedPrune)))
|
||||
: DEFAULT_SETTINGS.autoPruneDays,
|
||||
};
|
||||
};
|
||||
|
||||
const executeSave = async () => {
|
||||
const normalized = buildNormalizedSettings();
|
||||
const trimmedSecret = jwtSecret.trim();
|
||||
setConfirmRotateOpen(false);
|
||||
setSaving(true);
|
||||
try {
|
||||
const response = await fetch('/api/settings', {
|
||||
@@ -199,15 +245,25 @@ export function SettingsWorkspace() {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
...normalized,
|
||||
...(jwtSecret.trim() ? { jwtSecret: jwtSecret.trim() } : {}),
|
||||
...(trimmedSecret ? { jwtSecret: trimmedSecret } : {}),
|
||||
}),
|
||||
});
|
||||
if (response.status === 401) {
|
||||
window.location.assign('/vcon/login');
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Settings update failed');
|
||||
setSettings(setCached('vcon:settings', normalized));
|
||||
setSavedSettings(normalized);
|
||||
setJwtSecret('');
|
||||
success('Settings saved', 'Runtime settings updated.');
|
||||
setJwtError('');
|
||||
success(
|
||||
'Settings saved',
|
||||
trimmedSecret
|
||||
? 'Runtime settings saved and client JWT credentials rotated.'
|
||||
: 'Runtime settings updated.'
|
||||
);
|
||||
} catch (saveError) {
|
||||
error(
|
||||
'Save failed',
|
||||
@@ -220,9 +276,30 @@ export function SettingsWorkspace() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleFormSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const trimmedSecret = jwtSecret.trim();
|
||||
if (trimmedSecret.length > 0 && trimmedSecret.length < 32) {
|
||||
const message = 'JWT secret must be at least 32 characters.';
|
||||
setJwtError(message);
|
||||
setActiveTab('security');
|
||||
error('Invalid JWT secret', message);
|
||||
return;
|
||||
}
|
||||
|
||||
setJwtError('');
|
||||
if (trimmedSecret.length >= 32) {
|
||||
setConfirmRotateOpen(true);
|
||||
return;
|
||||
}
|
||||
|
||||
await executeSave();
|
||||
};
|
||||
|
||||
const discardChanges = () => {
|
||||
setSettings(savedSettings);
|
||||
setJwtSecret('');
|
||||
setJwtError('');
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -237,7 +314,9 @@ export function SettingsWorkspace() {
|
||||
},
|
||||
{
|
||||
label: 'CSV rotation',
|
||||
value: `${settings.fileRotationMb}MB · ${settings.autoPruneDays}d`,
|
||||
value: `${settings.fileRotationMb}MB · ${
|
||||
settings.autoPruneDays === 0 ? 'Keep all' : `${settings.autoPruneDays}d`
|
||||
}`,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
@@ -249,7 +328,7 @@ export function SettingsWorkspace() {
|
||||
onChange={(tab) => setActiveTab(tab as TabId)}
|
||||
/>
|
||||
|
||||
<form onSubmit={saveSettings} className="w-full">
|
||||
<form onSubmit={handleFormSubmit} className="w-full">
|
||||
<SettingsPanel
|
||||
id={`settings-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
@@ -307,6 +386,40 @@ export function SettingsWorkspace() {
|
||||
{activeTab === 'connections' && (
|
||||
<>
|
||||
<SettingsGroup title="WebSocket server">
|
||||
<SettingsField label="Live health">
|
||||
<div className="flex items-center justify-between gap-2 border border-[var(--border)] bg-[var(--surface-2)] px-2.5 py-1.5">
|
||||
<span className="inline-flex items-center gap-1.5 font-mono text-[11.5px] text-[var(--text)]">
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`h-1.5 w-1.5 ${
|
||||
socketStatus === 'online'
|
||||
? 'bg-[var(--accent)]'
|
||||
: socketStatus === 'checking'
|
||||
? 'bg-[var(--warning)]'
|
||||
: socketStatus === 'offline'
|
||||
? 'bg-[var(--danger)]'
|
||||
: 'bg-[var(--text-faint)]'
|
||||
}`}
|
||||
/>
|
||||
{socketStatus === 'online'
|
||||
? `Online (Port ${serverPort} · ${activeSockets} active)`
|
||||
: socketStatus === 'checking'
|
||||
? 'Probing ingestion server...'
|
||||
: socketStatus === 'offline'
|
||||
? `Offline (Port ${serverPort} unreachable)`
|
||||
: `Port ${serverPort} · ${activeSockets} active socket(s)`}
|
||||
</span>
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="RefreshCw"
|
||||
onClick={() => void probeSocketServer(serverPort)}
|
||||
>
|
||||
Probe
|
||||
</Button>
|
||||
</div>
|
||||
</SettingsField>
|
||||
<SettingsField label="WebSocket URL">
|
||||
<Input
|
||||
compact
|
||||
@@ -378,11 +491,11 @@ export function SettingsWorkspace() {
|
||||
className="font-mono"
|
||||
/>
|
||||
</SettingsField>
|
||||
<SettingsField label="Retention">
|
||||
<SettingsField label="Retention (0 = never prune)">
|
||||
<Input
|
||||
compact
|
||||
type="number"
|
||||
min="1"
|
||||
min="0"
|
||||
max="365"
|
||||
suffix="days"
|
||||
value={settings.autoPruneDays}
|
||||
@@ -408,14 +521,21 @@ export function SettingsWorkspace() {
|
||||
|
||||
{activeTab === 'security' && (
|
||||
<SettingsGroup title="Authentication">
|
||||
<SettingsField label="JWT secret">
|
||||
<SettingsField label="JWT secret (min 32 chars)">
|
||||
<Input
|
||||
compact
|
||||
type="password"
|
||||
autoComplete="new-password"
|
||||
value={jwtSecret}
|
||||
onChange={(event) => setJwtSecret(event.target.value)}
|
||||
placeholder="New secret..."
|
||||
error={jwtError}
|
||||
onChange={(event) => {
|
||||
const val = event.target.value;
|
||||
setJwtSecret(val);
|
||||
if (!val.trim() || val.trim().length >= 32) {
|
||||
setJwtError('');
|
||||
}
|
||||
}}
|
||||
placeholder="Minimum 32 characters to rotate..."
|
||||
/>
|
||||
</SettingsField>
|
||||
<SettingsField label="Payload size limit">
|
||||
@@ -471,6 +591,39 @@ export function SettingsWorkspace() {
|
||||
</SettingsPanel>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
isOpen={confirmRotateOpen}
|
||||
onClose={() => !saving && setConfirmRotateOpen(false)}
|
||||
title="Confirm JWT secret rotation"
|
||||
maxWidth="xs"
|
||||
footer={
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
disabled={saving}
|
||||
onClick={() => setConfirmRotateOpen(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="danger"
|
||||
size="xs"
|
||||
loading={saving}
|
||||
onClick={() => void executeSave()}
|
||||
>
|
||||
Rotate & Save
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<p className="text-[12px] text-[var(--text-muted)]">
|
||||
Rotating the signing JWT secret will immediately re-sign registered client tokens and invalidate all older SDK JWT tokens and active WebSocket sessions. Continue?
|
||||
</p>
|
||||
</Modal>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ export interface ClientItem {
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
createdAt: string;
|
||||
tokenPreview?: string;
|
||||
}
|
||||
|
||||
export interface ClientCredentials extends ClientItem {
|
||||
@@ -13,4 +14,9 @@ export interface ClientCredentials extends ClientItem {
|
||||
token: string;
|
||||
}
|
||||
|
||||
export type ClientStatusFilter = "all" | "online" | "offline" | "pending";
|
||||
export type ClientStatusFilter =
|
||||
| "all"
|
||||
| "online"
|
||||
| "offline"
|
||||
| "pending"
|
||||
| "revoked";
|
||||
Reference in new issue
Block a user