feat(auth): implement RBAC audit logging and session security
Integrate granular audit logging for admin actions, transition to role-based API access via `requireAdminApiSession`, and update session tokens to persist user roles and IDs for consistent multi-admin management.
This commit is contained in:
1 parent
2873b9904a
commit
5c977d6977
37 files changed
+5939
-349
No files matched your search
@@ -0,0 +1,5 @@
|
||||
import { AuditLogViewer } from '@/components/sections/AuditLogViewer';
|
||||
|
||||
export default function AuditPage() {
|
||||
return <AuditLogViewer />;
|
||||
}
|
||||
+220
-37
@@ -20,8 +20,11 @@ interface SdkClientItem {
|
||||
token?: string;
|
||||
}
|
||||
|
||||
type SdkLanguageTab = 'python' | 'node' | 'curl';
|
||||
|
||||
export default function SdkGuidePage() {
|
||||
const { success, error } = useToast();
|
||||
const [activeTab, setActiveTab] = useState<SdkLanguageTab>('python');
|
||||
const [clients, setClients] = useState<SdkClientItem[]>(() =>
|
||||
getCached<SdkClientItem[]>('vcon:clients', [])
|
||||
);
|
||||
@@ -128,13 +131,14 @@ export default function SdkGuidePage() {
|
||||
const sampleToken = loadingToken
|
||||
? 'LOADING_CLIENT_JWT_TOKEN...'
|
||||
: resolvedToken || 'YOUR_SIGNED_CLIENT_JWT_TOKEN';
|
||||
const clientIdValue = activeClient?.clientId || '';
|
||||
|
||||
const configSnippet = `# config.datastack.py — Place in your Python project root
|
||||
const pythonConfigSnippet = `# config.datastack.py — Place in your Python project root
|
||||
DATASTACK_CONFIG = {
|
||||
"SERVER_URL": "${serverUrl}",
|
||||
"API_URL": "${apiUrl}",
|
||||
"CLIENT_TOKEN": "${sampleToken}",
|
||||
"CLIENT_ID": "${activeClient?.clientId || ''}",
|
||||
"CLIENT_ID": "${clientIdValue}",
|
||||
"AUTO_CONNECT": True,
|
||||
"ENABLE_HTTP_FALLBACK": True,
|
||||
"HEARTBEAT_INTERVAL_SEC": 5.0,
|
||||
@@ -173,6 +177,109 @@ print("SDK Status:", client.status())
|
||||
|
||||
client.disconnect()`;
|
||||
|
||||
const nodeConfigSnippet = `// datastack.config.json — Place in your Node.js / TypeScript project root
|
||||
{
|
||||
"serverUrl": "${serverUrl}",
|
||||
"apiUrl": "${apiUrl}",
|
||||
"clientToken": "${sampleToken}",
|
||||
"clientId": "${clientIdValue}",
|
||||
"autoConnect": true,
|
||||
"enableHttpFallback": true,
|
||||
"heartbeatIntervalMs": 5000,
|
||||
"maxRetries": 3,
|
||||
"batchChunkSize": 250,
|
||||
"offlineSpoolEnabled": true,
|
||||
"offlineSpoolDir": ".datastack_spool"
|
||||
}`;
|
||||
|
||||
const nodeSnippet = `import { DataStack } from '@datastack/sdk';
|
||||
|
||||
// Loads datastack.config.json or explicit constructor options
|
||||
const client = new DataStack({
|
||||
serverUrl: '${serverUrl}',
|
||||
apiUrl: '${apiUrl}',
|
||||
token: '${sampleToken}',
|
||||
clientId: '${clientIdValue}',
|
||||
autoConnect: true,
|
||||
});
|
||||
|
||||
// 1. Single Event (Socket.IO Primary + Auto HTTP Fallback + Offline Spool)
|
||||
const res = await client.send({
|
||||
event_type: 'checkout_completed',
|
||||
order_id: 'ord_9942',
|
||||
amount_usd: 149.5,
|
||||
});
|
||||
console.log('Event response:', res);
|
||||
|
||||
// 2. Batch Events (Auto-chunked & 413/429 resilient)
|
||||
const batchRes = await client.sendBatch([
|
||||
{ sensor: 'temp', value: 24.5, unit: 'C' },
|
||||
{ sensor: 'humidity', value: 61.2, unit: '%' },
|
||||
]);
|
||||
console.log('Batch response:', batchRes);
|
||||
|
||||
// 3. Direct File Ingestion (.csv, .json, .jsonl, .ndjson with SHA-256 deterministic eventId)
|
||||
const fileRes = await client.sendFile('./events_dataset.csv', { chunkSize: 250 });
|
||||
console.log('File ingestion:', fileRes);
|
||||
|
||||
// 4. Graceful Shutdown Drain (awaits in-flight + drains offline spool)
|
||||
await client.shutdown(5000);`;
|
||||
|
||||
const curlConfigSnippet = `# Environment exports for HTTP / cURL ingestion
|
||||
export DATASTACK_API_URL="${apiUrl}"
|
||||
export DATASTACK_CLIENT_ID="${clientIdValue}"
|
||||
export DATASTACK_CLIENT_TOKEN="${sampleToken}"`;
|
||||
|
||||
const curlSnippet = `# 1. Single Event Ingestion via HTTP POST /api/events
|
||||
curl -X POST "${apiUrl}/api/events" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer ${sampleToken}" \\
|
||||
-d '{
|
||||
"clientId": "${clientIdValue}",
|
||||
"data": {
|
||||
"event_type": "deployment_finished",
|
||||
"service": "billing-api",
|
||||
"status": "healthy"
|
||||
}
|
||||
}'
|
||||
|
||||
# 2. Batch Event Ingestion via HTTP POST /api/events
|
||||
curl -X POST "${apiUrl}/api/events" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "Authorization: Bearer ${sampleToken}" \\
|
||||
-d '{
|
||||
"clientId": "${clientIdValue}",
|
||||
"batch": [
|
||||
{ "data": { "metric": "cpu_pct", "value": 31.4 } },
|
||||
{ "data": { "metric": "mem_pct", "value": 58.2 } }
|
||||
]
|
||||
}'`;
|
||||
|
||||
const activeConfigSnippet =
|
||||
activeTab === 'node'
|
||||
? nodeConfigSnippet
|
||||
: activeTab === 'curl'
|
||||
? curlConfigSnippet
|
||||
: pythonConfigSnippet;
|
||||
const activeCodeSnippet =
|
||||
activeTab === 'node'
|
||||
? nodeSnippet
|
||||
: activeTab === 'curl'
|
||||
? curlSnippet
|
||||
: pythonSnippet;
|
||||
const activeConfigLabel =
|
||||
activeTab === 'node'
|
||||
? 'datastack.config.json'
|
||||
: activeTab === 'curl'
|
||||
? 'Environment Variables'
|
||||
: 'config.datastack.py';
|
||||
const activeCodeLabel =
|
||||
activeTab === 'node'
|
||||
? 'Node.js / TypeScript SDK snippet'
|
||||
: activeTab === 'curl'
|
||||
? 'cURL REST snippet'
|
||||
: 'Python SDK snippet';
|
||||
|
||||
const copySnippet = async (text: string, label: string) => {
|
||||
try {
|
||||
if (!navigator?.clipboard?.writeText) {
|
||||
@@ -192,7 +299,7 @@ client.disconnect()`;
|
||||
|
||||
return (
|
||||
<PageShell
|
||||
title="Python SDK"
|
||||
title="Client SDKs (Python & Node.js / TypeScript)"
|
||||
actions={
|
||||
<>
|
||||
{resolvedToken && (
|
||||
@@ -211,7 +318,7 @@ client.disconnect()`;
|
||||
variant="secondary"
|
||||
icon="FileCode"
|
||||
disabled={loadingToken}
|
||||
onClick={() => void copySnippet(configSnippet, 'config.datastack.py')}
|
||||
onClick={() => void copySnippet(activeConfigSnippet, activeConfigLabel)}
|
||||
>
|
||||
Copy Config
|
||||
</Button>
|
||||
@@ -219,7 +326,7 @@ client.disconnect()`;
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Copy"
|
||||
onClick={() => void copySnippet(pythonSnippet, 'Python SDK snippet')}
|
||||
onClick={() => void copySnippet(activeCodeSnippet, activeCodeLabel)}
|
||||
>
|
||||
Copy Code
|
||||
</Button>
|
||||
@@ -228,7 +335,16 @@ client.disconnect()`;
|
||||
>
|
||||
<StatStrip
|
||||
items={[
|
||||
{ label: 'SDK package', value: 'datastack (v2.2.0)', dot: 'ok' },
|
||||
{
|
||||
label: 'SDK packages',
|
||||
value:
|
||||
activeTab === 'node'
|
||||
? '@datastack/sdk (v2.2.0)'
|
||||
: activeTab === 'curl'
|
||||
? 'REST HTTP/1.1 & HTTP/2'
|
||||
: 'datastack (v2.2.0)',
|
||||
dot: 'ok',
|
||||
},
|
||||
{ label: 'Transport', value: 'WS + HTTP Fallback + Offline Spool' },
|
||||
{ label: 'Server endpoint', value: serverUrl },
|
||||
{
|
||||
@@ -243,36 +359,103 @@ client.disconnect()`;
|
||||
]}
|
||||
/>
|
||||
|
||||
<Card
|
||||
compact
|
||||
className="flex w-full flex-col gap-1.5 bg-[var(--surface)] px-3 py-2.5"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 font-mono text-[11.5px]">
|
||||
<span className="truncate text-[var(--accent)]">
|
||||
pip install /path/to/datastack/sdk/python/datastack
|
||||
</span>
|
||||
<div className="mb-3 flex flex-wrap items-center justify-between gap-2 border border-[var(--border)] bg-[var(--surface)] px-3 py-2">
|
||||
<div className="flex items-center gap-1.5" role="tablist" aria-label="SDK Language Selector">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
aria-label="Copy pip install command"
|
||||
onClick={() =>
|
||||
void copySnippet(
|
||||
'pip install /path/to/datastack/sdk/python/datastack',
|
||||
'Pip command'
|
||||
)
|
||||
}
|
||||
/>
|
||||
variant={activeTab === 'python' ? 'primary' : 'secondary'}
|
||||
onClick={() => setActiveTab('python')}
|
||||
>
|
||||
Python SDK (v2.2.0)
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant={activeTab === 'node' ? 'primary' : 'secondary'}
|
||||
onClick={() => setActiveTab('node')}
|
||||
>
|
||||
Node.js / TypeScript SDK (v2.2.0)
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant={activeTab === 'curl' ? 'primary' : 'secondary'}
|
||||
onClick={() => setActiveTab('curl')}
|
||||
>
|
||||
HTTP / cURL
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-[11px] text-[var(--text-faint)]">
|
||||
Self-hosted package bundled in <code className="font-mono text-[var(--text-muted)]">sdk/python/datastack</code>. From inside the repo run{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">pip install ./sdk/python/datastack</code>, or build a portable wheel with{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">pip wheel ./sdk/python/datastack -w dist/</code> for external projects.
|
||||
</p>
|
||||
</Card>
|
||||
<span className="font-mono text-[10.5px] text-[var(--text-faint)]">
|
||||
{activeTab === 'node'
|
||||
? 'sdk/node/datastack'
|
||||
: activeTab === 'curl'
|
||||
? 'POST /api/events'
|
||||
: 'sdk/python/datastack'}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{activeTab === 'python' && (
|
||||
<Card
|
||||
compact
|
||||
className="flex w-full flex-col gap-1.5 bg-[var(--surface)] px-3 py-2.5"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 font-mono text-[11.5px]">
|
||||
<span className="truncate text-[var(--accent)]">
|
||||
pip install /path/to/datastack/sdk/python/datastack
|
||||
</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
aria-label="Copy pip install command"
|
||||
onClick={() =>
|
||||
void copySnippet(
|
||||
'pip install /path/to/datastack/sdk/python/datastack',
|
||||
'Pip command'
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-[11px] text-[var(--text-faint)]">
|
||||
Self-hosted package bundled in <code className="font-mono text-[var(--text-muted)]">sdk/python/datastack</code>. From inside the repo run{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">pip install ./sdk/python/datastack</code>, or build a portable wheel with{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">pip wheel ./sdk/python/datastack -w dist/</code> for external projects.
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{activeTab === 'node' && (
|
||||
<Card
|
||||
compact
|
||||
className="flex w-full flex-col gap-1.5 bg-[var(--surface)] px-3 py-2.5"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-2 font-mono text-[11.5px]">
|
||||
<span className="truncate text-[var(--accent)]">
|
||||
npm install /path/to/datastack/sdk/node/datastack
|
||||
</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
aria-label="Copy npm install command"
|
||||
onClick={() =>
|
||||
void copySnippet(
|
||||
'npm install /path/to/datastack/sdk/node/datastack',
|
||||
'NPM command'
|
||||
)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-[11px] text-[var(--text-faint)]">
|
||||
Official Node.js & TypeScript package bundled in{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">sdk/node/datastack</code> (Node >= 20). Supports Socket.IO primary streaming, automatic{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">POST /api/events</code> fallback, deterministic{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">sendFile()</code> SHA-256 deduplication, offline disk spooling, and graceful{' '}
|
||||
<code className="font-mono text-[var(--text-muted)]">await client.shutdown()</code>.
|
||||
</p>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Panel
|
||||
title="Step 1 — config.datastack.py"
|
||||
title={`Step 1 — ${activeConfigLabel}`}
|
||||
className="w-full"
|
||||
action={
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -296,14 +479,14 @@ client.disconnect()`;
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
aria-label="Copy config.datastack.py"
|
||||
aria-label={`Copy ${activeConfigLabel}`}
|
||||
disabled={loadingToken}
|
||||
onClick={() => void copySnippet(configSnippet, 'config.datastack.py')}
|
||||
onClick={() => void copySnippet(activeConfigSnippet, activeConfigLabel)}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<CodeBlock>{configSnippet}</CodeBlock>
|
||||
<CodeBlock>{activeConfigSnippet}</CodeBlock>
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
@@ -314,12 +497,12 @@ client.disconnect()`;
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
aria-label="Copy Python SDK snippet"
|
||||
onClick={() => void copySnippet(pythonSnippet, 'Python SDK snippet')}
|
||||
aria-label={`Copy ${activeCodeLabel}`}
|
||||
onClick={() => void copySnippet(activeCodeSnippet, activeCodeLabel)}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<CodeBlock>{pythonSnippet}</CodeBlock>
|
||||
<CodeBlock>{activeCodeSnippet}</CodeBlock>
|
||||
</Panel>
|
||||
</PageShell>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { TeamWorkspace } from '@/components/sections/TeamWorkspace';
|
||||
|
||||
export default function TeamPage() {
|
||||
return <TeamWorkspace />;
|
||||
}
|
||||
Reference in new issue
Block a user