chore: publish current DataStack updates
Publish the current application, design, and Phase 1 deployment updates. Excludes ignored personal notes, local MCP config, and generated TypeScript build info.
This commit is contained in:
1 parent
d39d9f92f9
commit
fcc4f4db2d
88 files changed
+21181
-2146
No files matched your search
@@ -0,0 +1,13 @@
|
||||
.git
|
||||
.next
|
||||
node_modules
|
||||
coverage
|
||||
notes
|
||||
**/notes
|
||||
storage/data
|
||||
.env*
|
||||
.mcp.json
|
||||
.vscode
|
||||
Design-Files
|
||||
*.log
|
||||
tsconfig.tsbuildinfo
|
||||
@@ -7,3 +7,15 @@ GEMINI_API_KEY="MY_GEMINI_API_KEY"
|
||||
# AI Studio automatically injects this at runtime with the Cloud Run service URL.
|
||||
# Used for self-referential links, OAuth callbacks, and API endpoints.
|
||||
APP_URL="MY_APP_URL"
|
||||
|
||||
# Production Compose requires unique values for these variables. Copy this file to `.env`
|
||||
# and replace every blank value. Never commit `.env` or use generated placeholders in production.
|
||||
DATASTACK_JWT_SECRET=
|
||||
# Use the Compose service host `postgres`, database `datastack_db`, and user `datastack`.
|
||||
DATABASE_URL=
|
||||
POSTGRES_PASSWORD=
|
||||
|
||||
# Required to protect the admin console. Use a long, unique session secret (32+ characters).
|
||||
DATASTACK_ADMIN_EMAIL=
|
||||
DATASTACK_ADMIN_PASSWORD=
|
||||
DATASTACK_ADMIN_SESSION_SECRET=
|
||||
@@ -5,3 +5,4 @@ coverage/
|
||||
*.log
|
||||
.env*
|
||||
!.env.example
|
||||
notes/
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"recommendations": [
|
||||
"gitlab.gitlab-workflow"
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
# AGENTS.md — Component-Only Architecture Rules & System Directives
|
||||
|
||||
## 1. Single Source of Truth Components
|
||||
|
||||
- All UI design styles are designed once as reusable components in `components/ui/` and `components/layout/`.
|
||||
- Pages must never implement isolated, inline styles or custom ad-hoc styling blocks.
|
||||
- Spacing, colors, fonts, borders, buttons, cards, modals, and tables are defined centrally. Any design token alteration automatically cascades across all pages.
|
||||
|
||||
## 2. Decoupled Runtime Split
|
||||
|
||||
- **Port 3000**: Next.js App Router (Frontend UI, `/vcon/*` admin console, streaming CSV export `/api/export`).
|
||||
- **Port 4000**: Express.js + Socket.IO process (WebSocket handshake, JWT verification, real-time ingestion).
|
||||
- **Socket.IO Rule**: Socket.IO must never reside inside Next.js serverless route handlers.
|
||||
|
||||
## 3. Data Storage Rules
|
||||
|
||||
- **Collected Realtime Data**: Strictly stored in rotated CSV files at `/storage/data/{clientId}/{YYYY-MM-DD}.csv`.
|
||||
- **Zero Database Inserts**: Per-row DB inserts are prohibited for collected data streams.
|
||||
- **File Rotation**: Rotates daily or upon reaching 100MB (`-part2.csv`).
|
||||
@@ -18,6 +21,13 @@
|
||||
- **PostgreSQL / Prisma**: Exclusively dedicated to metadata, SDK registrations, and admin settings.
|
||||
|
||||
## 4. Design & Typography Tokens
|
||||
|
||||
- **Font Stack**: `"Segoe UI", "Segoe UI Web", system-ui, -apple-system, "Helvetica Neue", sans-serif`.
|
||||
- **Border Radius**: `--radius: 0rem` strictly across all shadcn and custom UI components.
|
||||
- **Shadows**: None. Clean, soft, compact flat design with subtle 1px borders.
|
||||
|
||||
## 5. Private Development Notes
|
||||
|
||||
- The root `notes/` directory is local-only and must remain ignored by Git.
|
||||
- `notes/` is exclusively for private development-time notes, plans, reports, and update/fix phase logs. Never put public-facing or publishable documentation, Markdown, or public information in this directory.
|
||||
- Before starting any repository update, fix, or addition, record its report and plan in `notes/` first. Keep the relevant steps and phase status/logs updated there as work progresses.
|
||||
@@ -0,0 +1,483 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Data</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg:#0a0a0b;--surface:#111113;--surface-2:#17171a;--surface-3:#1d1d21;
|
||||
--border:#232326;--border-strong:#2e2e33;
|
||||
--text:#e8e8ea;--text-muted:#85858c;--text-faint:#5a5a62;
|
||||
--accent:#a3e635;--accent-soft:rgba(163,230,53,0.08);--accent-text:#a3e635;
|
||||
--danger:#f87171;
|
||||
--font:"Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono:"Consolas","SF Mono","Courier New",monospace;
|
||||
--radius:0;
|
||||
}
|
||||
[data-theme="light"] {
|
||||
--bg:#fafafa;--surface:#fff;--surface-2:#f4f4f5;--surface-3:#ececed;
|
||||
--border:#e2e2e5;--border-strong:#d0d0d3;
|
||||
--text:#111113;--text-muted:#5a5a62;--text-faint:#85858c;
|
||||
--accent:#65a30d;--accent-soft:rgba(101,163,13,0.08);--accent-text:#4d7c0f;
|
||||
--danger:#dc2626;
|
||||
}
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{background:var(--bg);color:var(--text);font-family:var(--font);
|
||||
font-size:13px;line-height:1.5;font-weight:400;-webkit-font-smoothing:antialiased}
|
||||
a{color:inherit;text-decoration:none}
|
||||
button,input,select{font-family:inherit;font-size:inherit;color:inherit}
|
||||
button{cursor:pointer}
|
||||
.icon{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:1.5;
|
||||
stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
|
||||
.icon-sm{width:14px;height:14px}
|
||||
|
||||
/* Layout */
|
||||
.admin{display:grid;grid-template-columns:208px 1fr;min-height:100vh}
|
||||
.sidebar{background:var(--surface);border-right:1px solid var(--border);
|
||||
display:flex;flex-direction:column;height:100vh;position:sticky;top:0;z-index:40}
|
||||
.sidebar-head{height:56px;padding:0 16px;display:flex;align-items:center;
|
||||
justify-content:space-between;border-bottom:1px solid var(--border);flex-shrink:0}
|
||||
.brand{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500}
|
||||
.brand-mark{width:14px;height:14px;background:var(--accent);display:grid;place-items:center}
|
||||
.brand-mark::after{content:"";width:5px;height:5px;background:var(--bg)}
|
||||
.brand-tag{font-size:9px;padding:1px 5px;margin-left:6px;
|
||||
border:1px solid var(--border-strong);color:var(--text-faint);letter-spacing:.5px}
|
||||
.sidebar-nav{flex:1;overflow-y:auto;padding:12px 0}
|
||||
.nav-section{padding:0 12px;margin-bottom:16px}
|
||||
.nav-label{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);padding:4px 8px 6px;display:flex;align-items:center;
|
||||
justify-content:space-between}
|
||||
.nav-label .count{background:var(--surface-2);color:var(--text-muted);padding:0 5px;
|
||||
font-size:9px;letter-spacing:0}
|
||||
.nav-item{display:flex;align-items:center;gap:10px;padding:7px 8px;height:32px;
|
||||
font-size:12.5px;color:var(--text-muted);border-left:2px solid transparent;
|
||||
transition:background .12s,color .12s;user-select:none}
|
||||
.nav-item:hover{background:var(--surface-2);color:var(--text)}
|
||||
.nav-item.active{background:var(--surface-2);color:var(--text);
|
||||
border-left-color:var(--accent)}
|
||||
.nav-item.active .icon{color:var(--accent)}
|
||||
.sidebar-foot{border-top:1px solid var(--border);padding:10px 12px;
|
||||
display:flex;align-items:center;gap:8px}
|
||||
.avatar{width:26px;height:26px;background:var(--surface-3);
|
||||
border:1px solid var(--border-strong);display:grid;place-items:center;
|
||||
font-size:11px;font-weight:500;color:var(--text);flex-shrink:0}
|
||||
.user-meta{flex:1;min-width:0}
|
||||
.user-name{font-size:12px;font-weight:500;color:var(--text);white-space:nowrap;
|
||||
overflow:hidden;text-overflow:ellipsis}
|
||||
.user-role{font-size:10px;color:var(--text-faint);text-transform:uppercase;
|
||||
letter-spacing:.5px}
|
||||
.icon-btn{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:background .12s}
|
||||
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
|
||||
|
||||
/* Main */
|
||||
.admin-main{display:flex;flex-direction:column;min-width:0}
|
||||
.topbar{height:56px;padding:0 24px;background:var(--surface);
|
||||
border-bottom:1px solid var(--border);display:flex;align-items:center;
|
||||
justify-content:space-between;gap:16px;position:sticky;top:0;z-index:30}
|
||||
.topbar-left{display:flex;align-items:center;gap:12px;min-width:0}
|
||||
.menu-btn{display:none}
|
||||
.breadcrumb{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text-faint)}
|
||||
.breadcrumb .sep{color:var(--border-strong)}
|
||||
.breadcrumb .current{color:var(--text)}
|
||||
.topbar-right{display:flex;align-items:center;gap:8px}
|
||||
.live-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 9px;
|
||||
border:1px solid var(--border-strong);font-size:10px;letter-spacing:.5px;
|
||||
text-transform:uppercase;color:var(--text-muted)}
|
||||
.live-dot{width:5px;height:5px;background:var(--accent);animation:pulse 2s infinite}
|
||||
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.35}}
|
||||
.theme-toggle{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted)}
|
||||
.theme-toggle:hover{background:var(--surface-2)}
|
||||
|
||||
/* Content */
|
||||
.content{padding:24px;max-width:1240px;width:100%}
|
||||
.page-head{display:flex;align-items:center;justify-content:space-between;
|
||||
gap:16px;margin-bottom:16px;flex-wrap:wrap}
|
||||
.page-title{font-size:17px;font-weight:500;letter-spacing:-.2px}
|
||||
.page-sub{font-size:12px;color:var(--text-muted);margin-top:2px}
|
||||
.page-actions{display:flex;gap:8px}
|
||||
|
||||
.btn{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;height:30px;
|
||||
font-size:12px;font-weight:400;border:1px solid var(--border-strong);
|
||||
background:transparent;color:var(--text);transition:background .12s,border-color .12s}
|
||||
.btn:hover{background:var(--surface-2)}
|
||||
.btn-primary{background:var(--text);color:var(--bg);border-color:var(--text)}
|
||||
.btn-primary:hover{background:#d0d0d3;border-color:#d0d0d3}
|
||||
.btn-icon{padding:0;width:30px;height:30px;justify-content:center}
|
||||
.btn-sm{padding:4px 9px;height:26px;font-size:11px}
|
||||
|
||||
/* Filter bar */
|
||||
.filterbar{background:var(--surface);border:1px solid var(--border);
|
||||
margin-bottom:12px}
|
||||
.filter-row{display:grid;
|
||||
grid-template-columns:180px 1fr 1fr 1.4fr auto;gap:1px;
|
||||
background:var(--border)}
|
||||
.field{background:var(--surface);padding:8px 12px;min-width:0}
|
||||
.field-label{font-size:9.5px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);margin-bottom:3px}
|
||||
.field-input{width:100%;background:transparent;border:none;outline:none;
|
||||
font-size:12.5px;color:var(--text);padding:0;height:20px}
|
||||
.field-input::placeholder{color:var(--text-faint)}
|
||||
.field-select{width:100%;background:transparent;border:none;outline:none;
|
||||
font-size:12.5px;color:var(--text);padding:0;height:20px;
|
||||
appearance:none;cursor:pointer;
|
||||
background-image:linear-gradient(45deg,transparent 50%,var(--text-muted) 50%),
|
||||
linear-gradient(135deg,var(--text-muted) 50%,transparent 50%);
|
||||
background-position:calc(100% - 8px) 9px,calc(100% - 4px) 9px;
|
||||
background-size:4px 4px;background-repeat:no-repeat}
|
||||
.field-search{position:relative}
|
||||
.field-search .icon{position:absolute;right:12px;top:26px;color:var(--text-faint)}
|
||||
.filter-actions{background:var(--surface);padding:8px 12px;display:flex;
|
||||
align-items:flex-end;gap:6px}
|
||||
|
||||
/* Table */
|
||||
.panel{background:var(--surface);border:1px solid var(--border);
|
||||
display:flex;flex-direction:column}
|
||||
.panel-head{display:flex;align-items:center;justify-content:space-between;
|
||||
padding:10px 14px;border-bottom:1px solid var(--border);gap:12px}
|
||||
.panel-title{font-size:12px;font-weight:500;display:flex;align-items:center;gap:8px}
|
||||
.panel-meta{font-size:11px;color:var(--text-faint)}
|
||||
.panel-meta strong{color:var(--text);font-weight:500}
|
||||
.panel-link{font-size:11px;color:var(--text-muted)}
|
||||
.panel-link:hover{color:var(--text)}
|
||||
|
||||
.table{width:100%;border-collapse:collapse;font-size:12px}
|
||||
.table thead th{text-align:left;padding:8px 14px;font-size:10px;
|
||||
text-transform:uppercase;letter-spacing:.6px;color:var(--text-faint);
|
||||
font-weight:400;background:var(--surface-2);border-bottom:1px solid var(--border);
|
||||
white-space:nowrap}
|
||||
.table thead th.right{text-align:right}
|
||||
.table tbody td{padding:8px 14px;border-bottom:1px solid rgba(35,35,38,.6);
|
||||
color:var(--text-muted);vertical-align:middle}
|
||||
[data-theme="light"] .table tbody td{border-bottom-color:var(--border)}
|
||||
.table tbody tr:last-child td{border-bottom:none}
|
||||
.table tbody tr:hover td{background:var(--surface-2)}
|
||||
.table td.mono{font-family:var(--mono);font-size:11.5px}
|
||||
.table td.client{color:var(--accent-text);font-weight:400}
|
||||
.table td.payload{color:var(--text);max-width:420px;
|
||||
white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-family:var(--mono);
|
||||
font-size:11.5px}
|
||||
.table td.right{text-align:right}
|
||||
.table td.id{color:var(--text-faint);font-family:var(--mono);font-size:11px}
|
||||
.status-badge{display:inline-flex;align-items:center;gap:5px;font-size:10.5px;
|
||||
color:var(--text-muted)}
|
||||
.status-badge .dot{width:5px;height:5px;background:var(--accent)}
|
||||
.status-badge.warn .dot{background:#fbbf24}
|
||||
.status-badge.err .dot{background:var(--danger)}
|
||||
|
||||
/* Pagination */
|
||||
.pagination{display:flex;align-items:center;justify-content:space-between;
|
||||
padding:10px 14px;border-top:1px solid var(--border);background:var(--surface)}
|
||||
.pagination-info{font-size:11.5px;color:var(--text-muted)}
|
||||
.pagination-info strong{color:var(--text);font-weight:500}
|
||||
.pagination-controls{display:flex;align-items:center;gap:4px}
|
||||
.page-btn{min-width:26px;height:26px;padding:0 8px;border:1px solid var(--border);
|
||||
background:transparent;color:var(--text-muted);font-size:11.5px;
|
||||
display:grid;place-items:center;transition:background .12s}
|
||||
.page-btn:hover{background:var(--surface-2);color:var(--text)}
|
||||
.page-btn.active{background:var(--surface-2);color:var(--text);
|
||||
border-color:var(--border-strong)}
|
||||
.page-btn.disabled{opacity:.4;cursor:not-allowed}
|
||||
|
||||
/* Empty / hint */
|
||||
.hint{font-size:11px;color:var(--text-faint);margin-top:8px}
|
||||
|
||||
/* Mobile */
|
||||
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:35}
|
||||
.overlay.open{display:block}
|
||||
@media (max-width:1024px){
|
||||
.admin{grid-template-columns:1fr}
|
||||
.sidebar{position:fixed;top:0;left:0;width:220px;transform:translateX(-100%);
|
||||
transition:transform .2s ease-out}
|
||||
.sidebar.open{transform:translateX(0)}
|
||||
.menu-btn{display:grid}
|
||||
.filter-row{grid-template-columns:1fr 1fr}
|
||||
}
|
||||
@media (max-width:640px){
|
||||
.content{padding:16px}
|
||||
.topbar{padding:0 16px}
|
||||
.filter-row{grid-template-columns:1fr}
|
||||
.live-chip{display:none}
|
||||
.breadcrumb .sep,.breadcrumb .root{display:none}
|
||||
.table td.id,.table td:nth-child(3){display:none}
|
||||
.table thead th:nth-child(3){display:none}
|
||||
.table td.payload{max-width:180px}
|
||||
.panel-meta{display:none}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-grid" viewBox="0 0 16 16"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 16 16"><ellipse cx="8" cy="4" rx="5.5" ry="2"/><path d="M2.5 4v8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2V4"/><path d="M2.5 8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 16 16"><circle cx="6" cy="6" r="2.5"/><path d="M1.5 13.5c0-2.2 2-3.5 4.5-3.5s4.5 1.3 4.5 3.5"/><path d="M11 3.5a2.5 2.5 0 0 1 0 5"/><path d="M12.5 10c1.4.4 2.5 1.4 2.5 3.5"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 16 16"><path d="M8 2v8"/><path d="M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 13.5h11"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 16 16"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.5 3.5l1.4 1.4M11.1 11.1l1.4 1.4M3.5 12.5l1.4-1.4M11.1 4.9l1.4-1.4"/></symbol>
|
||||
<symbol id="i-list" viewBox="0 0 16 16"><path d="M3 4h10M3 8h10M3 12h7"/></symbol>
|
||||
<symbol id="i-book" viewBox="0 0 16 16"><path d="M3 2.5h7.5c1 0 1.5.5 1.5 1.5v10H4.5c-1 0-1.5-.5-1.5-1.5V2.5Z"/><path d="M3 12.5c0-1 .5-1.5 1.5-1.5H12"/></symbol>
|
||||
<symbol id="i-menu" viewBox="0 0 16 16"><path d="M2.5 4h11M2.5 8h11M2.5 12h11"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-refresh" viewBox="0 0 16 16"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.5 2.5v3.5H10"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 16 16"><path d="M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11Z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/></symbol>
|
||||
<symbol id="i-search" viewBox="0 0 16 16"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5 14 14"/></symbol>
|
||||
<symbol id="i-chev-l" viewBox="0 0 16 16"><path d="M10 4l-4 4 4 4"/></symbol>
|
||||
<symbol id="i-chev-r" viewBox="0 0 16 16"><path d="M6 4l4 4-4 4"/></symbol>
|
||||
<symbol id="i-clear" viewBox="0 0 16 16"><path d="M4 4l8 8M12 4l-8 8"/></symbol>
|
||||
</svg>
|
||||
|
||||
<div class="admin">
|
||||
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<a href="/" class="brand"><span class="brand-mark"></span>DataStack<span class="brand-tag">CONSOLE</span></a>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">Main</div>
|
||||
<a href="/vcon/dashboard" class="nav-item"><svg class="icon"><use href="#i-grid"/></svg>Dashboard</a>
|
||||
<a href="/vcon/data" class="nav-item active"><svg class="icon"><use href="#i-db"/></svg>Data</a>
|
||||
<a href="/vcon/clients" class="nav-item"><svg class="icon"><use href="#i-users"/></svg>Clients</a>
|
||||
<a href="/vcon/export" class="nav-item"><svg class="icon"><use href="#i-download"/></svg>Export</a>
|
||||
</div>
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">System <span class="count">3</span></div>
|
||||
<a href="/vcon/logs" class="nav-item"><svg class="icon"><use href="#i-list"/></svg>Logs</a>
|
||||
<a href="/vcon/settings" class="nav-item"><svg class="icon"><use href="#i-settings"/></svg>Settings</a>
|
||||
<a href="/docs" class="nav-item"><svg class="icon"><use href="#i-book"/></svg>Docs</a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="sidebar-foot">
|
||||
<div class="avatar">A</div>
|
||||
<div class="user-meta">
|
||||
<div class="user-name">Admin</div>
|
||||
<div class="user-role">Owner</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="Settings"><svg class="icon icon-sm"><use href="#i-settings"/></svg></button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="overlay" id="overlay" onclick="toggleSidebar()"></div>
|
||||
|
||||
<main class="admin-main">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="icon-btn menu-btn" onclick="toggleSidebar()"><svg class="icon icon-sm"><use href="#i-menu"/></svg></button>
|
||||
<div class="breadcrumb">
|
||||
<span class="root">Console</span>
|
||||
<span class="sep">/</span>
|
||||
<span class="current">Data</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span class="live-chip"><span class="live-dot"></span>Live · 1,284 ev/min</span>
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn" title="Notifications"><svg class="icon icon-sm"><use href="#i-bell"/></svg></button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h1 class="page-title">Data</h1>
|
||||
<div class="page-sub">Collected events across all clients</div>
|
||||
</div>
|
||||
<div class="page-actions">
|
||||
<button class="btn btn-icon" title="Refresh"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<a href="/vcon/export" class="btn btn-primary">
|
||||
<svg class="icon icon-sm"><use href="#i-download"/></svg>
|
||||
Export CSV
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filter bar -->
|
||||
<div class="filterbar">
|
||||
<div class="filter-row">
|
||||
<div class="field">
|
||||
<div class="field-label">Client</div>
|
||||
<select class="field-select">
|
||||
<option>All clients</option>
|
||||
<option>py-client-01</option>
|
||||
<option>py-client-02</option>
|
||||
<option>py-client-03</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label">From</div>
|
||||
<input type="date" class="field-input" value="2026-10-23">
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label">To</div>
|
||||
<input type="date" class="field-input" value="2026-10-23">
|
||||
</div>
|
||||
<div class="field field-search">
|
||||
<div class="field-label">Search payload</div>
|
||||
<input type="text" class="field-input" placeholder="e.g. sensor, user_id">
|
||||
<svg class="icon icon-sm"><use href="#i-search"/></svg>
|
||||
</div>
|
||||
<div class="filter-actions">
|
||||
<button class="btn btn-sm"><svg class="icon icon-sm"><use href="#i-clear"/></svg>Reset</button>
|
||||
<button class="btn btn-sm btn-primary">Apply</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title"><svg class="icon icon-sm"><use href="#i-db"/></svg>Events</div>
|
||||
<div class="panel-meta"><strong>42,891</strong> results · page 1 of 429</div>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Time</th>
|
||||
<th>Client</th>
|
||||
<th>Event ID</th>
|
||||
<th>Payload</th>
|
||||
<th>Size</th>
|
||||
<th class="right">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="mono">14:28:01</td>
|
||||
<td class="client">py-client-01</td>
|
||||
<td class="id">evt_8f3a…c21</td>
|
||||
<td class="payload">{ sensor: "temp", value: 22.4 }</td>
|
||||
<td class="mono">42 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:01</td>
|
||||
<td class="client">py-client-02</td>
|
||||
<td class="id">evt_9b1e…44a</td>
|
||||
<td class="payload">{ user: "u_8291", action: "click" }</td>
|
||||
<td class="mono">38 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:02</td>
|
||||
<td class="client">py-client-01</td>
|
||||
<td class="id">evt_2c7f…88e</td>
|
||||
<td class="payload">{ sensor: "humidity", value: 61 }</td>
|
||||
<td class="mono">40 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:02</td>
|
||||
<td class="client">py-client-03</td>
|
||||
<td class="id">evt_5d0a…1fb</td>
|
||||
<td class="payload">{ order_id: "A-2041", status: "shipped" }</td>
|
||||
<td class="mono">44 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:03</td>
|
||||
<td class="client">py-client-02</td>
|
||||
<td class="id">evt_7e2d…09c</td>
|
||||
<td class="payload">{ user: "u_1840", action: "view" }</td>
|
||||
<td class="mono">36 B</td>
|
||||
<td class="right"><span class="status-badge warn"><span class="dot"></span>retry</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:03</td>
|
||||
<td class="client">py-client-01</td>
|
||||
<td class="id">evt_1a9b…72d</td>
|
||||
<td class="payload">{ sensor: "temp", value: 22.6 }</td>
|
||||
<td class="mono">42 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:04</td>
|
||||
<td class="client">py-client-04</td>
|
||||
<td class="id">evt_3c4e…b81</td>
|
||||
<td class="payload">{ device: "d_01", battery: 87 }</td>
|
||||
<td class="mono">40 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:04</td>
|
||||
<td class="client">py-client-02</td>
|
||||
<td class="id">evt_6f7a…d94</td>
|
||||
<td class="payload">{ user: "u_9903", action: "purchase" }</td>
|
||||
<td class="mono">42 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:05</td>
|
||||
<td class="client">py-client-03</td>
|
||||
<td class="id">evt_0b2c…55f</td>
|
||||
<td class="payload">{ order_id: "A-2042", status: "pending" }</td>
|
||||
<td class="mono">46 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:05</td>
|
||||
<td class="client">py-client-04</td>
|
||||
<td class="id">evt_8d1c…2a3</td>
|
||||
<td class="payload">{ device: "d_02", battery: 92 }</td>
|
||||
<td class="mono">40 B</td>
|
||||
<td class="right"><span class="status-badge err"><span class="dot"></span>failed</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:06</td>
|
||||
<td class="client">py-client-01</td>
|
||||
<td class="id">evt_4e9f…7d0</td>
|
||||
<td class="payload">{ sensor: "temp", value: 22.7 }</td>
|
||||
<td class="mono">42 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="mono">14:28:06</td>
|
||||
<td class="client">py-client-02</td>
|
||||
<td class="id">evt_5c3b…11e</td>
|
||||
<td class="payload">{ user: "u_3312", action: "signup" }</td>
|
||||
<td class="mono">40 B</td>
|
||||
<td class="right"><span class="status-badge"><span class="dot"></span>ok</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="pagination">
|
||||
<div class="pagination-info">Showing <strong>1–12</strong> of <strong>42,891</strong> events</div>
|
||||
<div class="pagination-controls">
|
||||
<button class="page-btn disabled" title="Previous"><svg class="icon icon-sm"><use href="#i-chev-l"/></svg></button>
|
||||
<button class="page-btn active">1</button>
|
||||
<button class="page-btn">2</button>
|
||||
<button class="page-btn">3</button>
|
||||
<button class="page-btn">…</button>
|
||||
<button class="page-btn">429</button>
|
||||
<button class="page-btn" title="Next"><svg class="icon icon-sm"><use href="#i-chev-r"/></svg></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="hint">Data is served from compact CSV files · live updates stream in over WebSocket</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleSidebar(){
|
||||
document.getElementById('sidebar').classList.toggle('open');
|
||||
document.getElementById('overlay').classList.toggle('open');
|
||||
}
|
||||
function toggleTheme(){
|
||||
const html=document.documentElement, icon=document.getElementById('theme-icon');
|
||||
const isDark=html.getAttribute('data-theme')==='dark';
|
||||
html.setAttribute('data-theme',isDark?'light':'dark');
|
||||
icon.innerHTML='<use href="'+(isDark?'#i-moon':'#i-sun')+'"/>';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,626 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Clients</title>
|
||||
<style>
|
||||
:root{
|
||||
--bg:#0a0a0b;--surface:#111113;--surface-2:#17171a;--surface-3:#1d1d21;
|
||||
--border:#232326;--border-strong:#2e2e33;
|
||||
--text:#e8e8ea;--text-muted:#85858c;--text-faint:#5a5a62;
|
||||
--accent:#a3e635;--accent-text:#a3e635;
|
||||
--danger:#f87171;--warn:#fbbf24;
|
||||
--font:"Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono:"Consolas","SF Mono","Courier New",monospace;
|
||||
--radius:0;
|
||||
}
|
||||
[data-theme="light"]{
|
||||
--bg:#fafafa;--surface:#fff;--surface-2:#f4f4f5;--surface-3:#ececed;
|
||||
--border:#e2e2e5;--border-strong:#d0d0d3;
|
||||
--text:#111113;--text-muted:#5a5a62;--text-faint:#85858c;
|
||||
--accent:#65a30d;--accent-text:#4d7c0f;
|
||||
--danger:#dc2626;--warn:#d97706;
|
||||
}
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{background:var(--bg);color:var(--text);font-family:var(--font);
|
||||
font-size:13px;line-height:1.5;font-weight:400;-webkit-font-smoothing:antialiased}
|
||||
a{color:inherit;text-decoration:none}
|
||||
button,input,select{font-family:inherit;font-size:inherit;color:inherit}
|
||||
button{cursor:pointer}
|
||||
.icon{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:1.5;
|
||||
stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
|
||||
.icon-sm{width:14px;height:14px}
|
||||
|
||||
/* Layout */
|
||||
.admin{display:grid;grid-template-columns:208px 1fr;min-height:100vh}
|
||||
.sidebar{background:var(--surface);border-right:1px solid var(--border);
|
||||
display:flex;flex-direction:column;height:100vh;position:sticky;top:0;z-index:40}
|
||||
.sidebar-head{height:56px;padding:0 16px;display:flex;align-items:center;
|
||||
justify-content:space-between;border-bottom:1px solid var(--border);flex-shrink:0}
|
||||
.brand{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500}
|
||||
.brand-mark{width:14px;height:14px;background:var(--accent);display:grid;place-items:center}
|
||||
.brand-mark::after{content:"";width:5px;height:5px;background:var(--bg)}
|
||||
.brand-tag{font-size:9px;padding:1px 5px;margin-left:6px;
|
||||
border:1px solid var(--border-strong);color:var(--text-faint);letter-spacing:.5px}
|
||||
.sidebar-nav{flex:1;overflow-y:auto;padding:12px 0}
|
||||
.nav-section{padding:0 12px;margin-bottom:16px}
|
||||
.nav-label{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);padding:4px 8px 6px;display:flex;align-items:center;
|
||||
justify-content:space-between}
|
||||
.nav-label .count{background:var(--surface-2);color:var(--text-muted);padding:0 5px;
|
||||
font-size:9px;letter-spacing:0}
|
||||
.nav-item{display:flex;align-items:center;gap:10px;padding:7px 8px;height:32px;
|
||||
font-size:12.5px;color:var(--text-muted);border-left:2px solid transparent;
|
||||
transition:background .12s,color .12s;user-select:none}
|
||||
.nav-item:hover{background:var(--surface-2);color:var(--text)}
|
||||
.nav-item.active{background:var(--surface-2);color:var(--text);border-left-color:var(--accent)}
|
||||
.nav-item.active .icon{color:var(--accent)}
|
||||
.sidebar-foot{border-top:1px solid var(--border);padding:10px 12px;
|
||||
display:flex;align-items:center;gap:8px}
|
||||
.avatar{width:26px;height:26px;background:var(--surface-3);border:1px solid var(--border-strong);
|
||||
display:grid;place-items:center;font-size:11px;font-weight:500;color:var(--text);flex-shrink:0}
|
||||
.user-meta{flex:1;min-width:0}
|
||||
.user-name{font-size:12px;font-weight:500;color:var(--text);white-space:nowrap;
|
||||
overflow:hidden;text-overflow:ellipsis}
|
||||
.user-role{font-size:10px;color:var(--text-faint);text-transform:uppercase;letter-spacing:.5px}
|
||||
.icon-btn{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:background .12s}
|
||||
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
|
||||
|
||||
/* Main */
|
||||
.admin-main{display:flex;flex-direction:column;min-width:0}
|
||||
.topbar{height:56px;padding:0 24px;background:var(--surface);border-bottom:1px solid var(--border);
|
||||
display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
position:sticky;top:0;z-index:30}
|
||||
.topbar-left{display:flex;align-items:center;gap:12px;min-width:0}
|
||||
.menu-btn{display:none}
|
||||
.breadcrumb{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text-faint)}
|
||||
.breadcrumb .sep{color:var(--border-strong)}
|
||||
.breadcrumb .current{color:var(--text)}
|
||||
.topbar-right{display:flex;align-items:center;gap:8px}
|
||||
.live-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 9px;
|
||||
border:1px solid var(--border-strong);font-size:10px;letter-spacing:.5px;
|
||||
text-transform:uppercase;color:var(--text-muted)}
|
||||
.live-dot{width:5px;height:5px;background:var(--accent);animation:pulse 2s infinite}
|
||||
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.35}}
|
||||
.theme-toggle{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted)}
|
||||
.theme-toggle:hover{background:var(--surface-2)}
|
||||
|
||||
/* Content */
|
||||
.content{padding:24px;max-width:1240px;width:100%}
|
||||
.page-head{display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
margin-bottom:16px;flex-wrap:wrap}
|
||||
.page-title{font-size:17px;font-weight:500;letter-spacing:-.2px}
|
||||
.page-sub{font-size:12px;color:var(--text-muted);margin-top:2px}
|
||||
.page-actions{display:flex;gap:8px}
|
||||
.btn{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;height:30px;
|
||||
font-size:12px;font-weight:400;border:1px solid var(--border-strong);
|
||||
background:transparent;color:var(--text);transition:background .12s,border-color .12s}
|
||||
.btn:hover{background:var(--surface-2)}
|
||||
.btn-primary{background:var(--text);color:var(--bg);border-color:var(--text)}
|
||||
.btn-primary:hover{background:#d0d0d3;border-color:#d0d0d3}
|
||||
.btn-icon{padding:0;width:30px;height:30px;justify-content:center}
|
||||
.btn-sm{padding:4px 9px;height:26px;font-size:11px}
|
||||
.btn-danger{color:var(--danger);border-color:var(--border)}
|
||||
.btn-danger:hover{background:rgba(248,113,113,.08);border-color:var(--danger)}
|
||||
|
||||
/* Stats strip */
|
||||
.stats-strip{display:grid;grid-template-columns:repeat(4,1fr);gap:1px;
|
||||
background:var(--border);border:1px solid var(--border);margin-bottom:16px}
|
||||
.stat-cell{background:var(--surface);padding:12px 16px}
|
||||
.stat-label{font-size:10px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);margin-bottom:4px}
|
||||
.stat-value{font-size:18px;font-weight:500;letter-spacing:-.3px;color:var(--text);
|
||||
line-height:1.1;display:flex;align-items:center;gap:6px}
|
||||
.stat-value .badge-dot{width:6px;height:6px;background:var(--accent)}
|
||||
.stat-value .badge-dot.off{background:var(--text-faint)}
|
||||
.stat-value .badge-dot.pending{background:var(--warn)}
|
||||
.stat-value .unit{font-size:11px;color:var(--text-muted);font-weight:400}
|
||||
|
||||
/* Filter bar */
|
||||
.filter-bar{display:flex;align-items:center;gap:8px;margin-bottom:12px;flex-wrap:wrap}
|
||||
.search-box{flex:1;max-width:340px;height:30px;border:1px solid var(--border);
|
||||
background:var(--surface);display:flex;align-items:center;padding:0 10px;gap:6px}
|
||||
.search-box .icon{color:var(--text-faint)}
|
||||
.search-box input{flex:1;background:transparent;border:none;outline:none;
|
||||
font-size:12px;color:var(--text)}
|
||||
.search-box input::placeholder{color:var(--text-faint)}
|
||||
.pill-group{display:flex;gap:4px;margin-left:auto}
|
||||
.pill{height:26px;padding:0 10px;border:1px solid var(--border);background:transparent;
|
||||
font-size:11.5px;color:var(--text-muted);display:inline-flex;align-items:center;gap:5px}
|
||||
.pill:hover{background:var(--surface-2);color:var(--text)}
|
||||
.pill.active{background:var(--surface-2);color:var(--text);border-color:var(--border-strong)}
|
||||
.pill .count{font-size:10px;color:var(--text-faint)}
|
||||
|
||||
/* Table */
|
||||
.panel{background:var(--surface);border:1px solid var(--border);display:flex;flex-direction:column}
|
||||
.table{width:100%;border-collapse:collapse;font-size:12px}
|
||||
.table thead th{text-align:left;padding:8px 14px;font-size:10px;
|
||||
text-transform:uppercase;letter-spacing:.6px;color:var(--text-faint);
|
||||
font-weight:400;background:var(--surface-2);border-bottom:1px solid var(--border);
|
||||
white-space:nowrap}
|
||||
.table thead th.right{text-align:right}
|
||||
.table tbody td{padding:9px 14px;border-bottom:1px solid rgba(35,35,38,.6);
|
||||
color:var(--text-muted);vertical-align:middle}
|
||||
[data-theme="light"] .table tbody td{border-bottom-color:var(--border)}
|
||||
.table tbody tr:last-child td{border-bottom:none}
|
||||
.table tbody tr:hover td{background:var(--surface-2)}
|
||||
.table td.mono{font-family:var(--mono);font-size:11.5px}
|
||||
.table td.right{text-align:right}
|
||||
|
||||
/* Client cell */
|
||||
.client-cell{display:flex;align-items:center;gap:10px;min-width:0}
|
||||
.client-dot{width:6px;height:6px;background:var(--accent);flex-shrink:0}
|
||||
.client-dot.offline{background:var(--text-faint)}
|
||||
.client-dot.pending{background:var(--warn)}
|
||||
.client-name{font-size:12.5px;color:var(--text);font-weight:400;line-height:1.2}
|
||||
.client-type{font-size:10.5px;color:var(--text-faint);margin-top:2px}
|
||||
|
||||
/* API key */
|
||||
.api-key-cell{display:flex;align-items:center;gap:6px}
|
||||
.api-key-cell .key{font-family:var(--mono);font-size:11.5px;color:var(--text-muted)}
|
||||
.api-key-cell .copy{width:20px;height:20px;background:transparent;border:none;
|
||||
display:grid;place-items:center;color:var(--text-faint);transition:color .12s}
|
||||
.api-key-cell .copy:hover{color:var(--text)}
|
||||
|
||||
/* Row actions */
|
||||
.row-actions{display:inline-flex;gap:2px}
|
||||
.row-actions .act{width:26px;height:26px;background:transparent;border:1px solid transparent;
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:.12s}
|
||||
.row-actions .act:hover{background:var(--surface-3);color:var(--text);border-color:var(--border)}
|
||||
.row-actions .act.danger:hover{color:var(--danger);border-color:var(--danger)}
|
||||
|
||||
/* Last seen */
|
||||
.last-seen{font-family:var(--mono);font-size:11.5px}
|
||||
.last-seen .rel{color:var(--text-faint);font-size:10.5px;margin-left:4px;font-family:var(--font)}
|
||||
|
||||
/* Empty state hint */
|
||||
.hint{font-size:11px;color:var(--text-faint);margin-top:8px}
|
||||
|
||||
/* Modal */
|
||||
.modal{display:none;position:fixed;inset:0;background:rgba(0,0,0,.6);
|
||||
z-index:100;place-items:center;padding:16px}
|
||||
.modal.open{display:grid}
|
||||
.modal-panel{background:var(--surface);border:1px solid var(--border-strong);
|
||||
width:100%;max-width:440px;display:flex;flex-direction:column}
|
||||
.modal-head{display:flex;align-items:center;justify-content:space-between;
|
||||
padding:12px 16px;border-bottom:1px solid var(--border)}
|
||||
.modal-title{font-size:13px;font-weight:500}
|
||||
.modal-body{padding:16px;display:flex;flex-direction:column;gap:14px}
|
||||
.form-field{display:flex;flex-direction:column;gap:4px}
|
||||
.form-field label{font-size:10px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);display:flex;align-items:center;gap:6px}
|
||||
.form-field label .optional{text-transform:none;letter-spacing:0;color:var(--text-faint);
|
||||
font-size:10px;font-weight:400}
|
||||
.form-field input,.form-field select{width:100%;height:32px;padding:0 10px;
|
||||
background:var(--bg);border:1px solid var(--border);outline:none;font-size:12.5px;
|
||||
color:var(--text);transition:border-color .12s}
|
||||
.form-field input::placeholder{color:var(--text-faint)}
|
||||
.form-field input:focus,.form-field select:focus{border-color:var(--border-strong)}
|
||||
.modal-foot{display:flex;justify-content:flex-end;gap:8px;
|
||||
padding:12px 16px;border-top:1px solid var(--border)}
|
||||
.modal-foot .spacer{flex:1}
|
||||
|
||||
/* Mobile */
|
||||
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:35}
|
||||
.overlay.open{display:block}
|
||||
@media (max-width:1024px){
|
||||
.admin{grid-template-columns:1fr}
|
||||
.sidebar{position:fixed;top:0;left:0;width:220px;transform:translateX(-100%);
|
||||
transition:transform .2s ease-out}
|
||||
.sidebar.open{transform:translateX(0)}
|
||||
.menu-btn{display:grid}
|
||||
.stats-strip{grid-template-columns:repeat(2,1fr)}
|
||||
}
|
||||
@media (max-width:640px){
|
||||
.content{padding:16px}
|
||||
.topbar{padding:0 16px}
|
||||
.live-chip{display:none}
|
||||
.breadcrumb .sep,.breadcrumb .root{display:none}
|
||||
.table td.api-key-cell,.table thead th:nth-child(2){display:none}
|
||||
.table td.storage-cell,.table thead th.storage-cell{display:none}
|
||||
.pill-group{margin-left:0;width:100%;overflow-x:auto}
|
||||
.stats-strip{grid-template-columns:1fr 1fr}
|
||||
.stat-value{font-size:16px}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-grid" viewBox="0 0 16 16"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 16 16"><ellipse cx="8" cy="4" rx="5.5" ry="2"/><path d="M2.5 4v8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2V4"/><path d="M2.5 8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 16 16"><circle cx="6" cy="6" r="2.5"/><path d="M1.5 13.5c0-2.2 2-3.5 4.5-3.5s4.5 1.3 4.5 3.5"/><path d="M11 3.5a2.5 2.5 0 0 1 0 5"/><path d="M12.5 10c1.4.4 2.5 1.4 2.5 3.5"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 16 16"><path d="M8 2v8"/><path d="M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 13.5h11"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 16 16"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.5 3.5l1.4 1.4M11.1 11.1l1.4 1.4M3.5 12.5l1.4-1.4M11.1 4.9l1.4-1.4"/></symbol>
|
||||
<symbol id="i-list" viewBox="0 0 16 16"><path d="M3 4h10M3 8h10M3 12h7"/></symbol>
|
||||
<symbol id="i-book" viewBox="0 0 16 16"><path d="M3 2.5h7.5c1 0 1.5.5 1.5 1.5v10H4.5c-1 0-1.5-.5-1.5-1.5V2.5Z"/><path d="M3 12.5c0-1 .5-1.5 1.5-1.5H12"/></symbol>
|
||||
<symbol id="i-menu" viewBox="0 0 16 16"><path d="M2.5 4h11M2.5 8h11M2.5 12h11"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 16 16"><path d="M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11Z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/></symbol>
|
||||
<symbol id="i-plus" viewBox="0 0 16 16"><path d="M8 3v10M3 8h10"/></symbol>
|
||||
<symbol id="i-search" viewBox="0 0 16 16"><circle cx="7" cy="7" r="4.5"/><path d="M10.5 10.5 14 14"/></symbol>
|
||||
<symbol id="i-copy" viewBox="0 0 16 16"><rect x="5" y="5" width="8" height="9"/><path d="M3 11V3h8"/></symbol>
|
||||
<symbol id="i-refresh" viewBox="0 0 16 16"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.5 2.5v3.5H10"/></symbol>
|
||||
<symbol id="i-trash" viewBox="0 0 16 16"><path d="M3 4h10"/><path d="M5 4V2.5h6V4"/><path d="M4 4l.7 9.5h6.6L12 4"/><path d="M6.5 7v4M9.5 7v4"/></symbol>
|
||||
<symbol id="i-activity" viewBox="0 0 16 16"><path d="M2 8h3l2-5 2 10 2-5h3"/></symbol>
|
||||
<symbol id="i-x" viewBox="0 0 16 16"><path d="M4 4l8 8M12 4l-8 8"/></symbol>
|
||||
</svg>
|
||||
|
||||
<div class="admin">
|
||||
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<a href="/" class="brand"><span class="brand-mark"></span>DataStack<span class="brand-tag">CONSOLE</span></a>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">Main</div>
|
||||
<a href="/vcon/dashboard" class="nav-item"><svg class="icon"><use href="#i-grid"/></svg>Dashboard</a>
|
||||
<a href="/vcon/data" class="nav-item"><svg class="icon"><use href="#i-db"/></svg>Data</a>
|
||||
<a href="/vcon/clients" class="nav-item active"><svg class="icon"><use href="#i-users"/></svg>Clients</a>
|
||||
<a href="/vcon/export" class="nav-item"><svg class="icon"><use href="#i-download"/></svg>Export</a>
|
||||
</div>
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">System <span class="count">3</span></div>
|
||||
<a href="/vcon/logs" class="nav-item"><svg class="icon"><use href="#i-list"/></svg>Logs</a>
|
||||
<a href="/vcon/settings" class="nav-item"><svg class="icon"><use href="#i-settings"/></svg>Settings</a>
|
||||
<a href="/docs" class="nav-item"><svg class="icon"><use href="#i-book"/></svg>Docs</a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="sidebar-foot">
|
||||
<div class="avatar">A</div>
|
||||
<div class="user-meta">
|
||||
<div class="user-name">Admin</div>
|
||||
<div class="user-role">Owner</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="Settings"><svg class="icon icon-sm"><use href="#i-settings"/></svg></button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="overlay" id="overlay" onclick="toggleSidebar()"></div>
|
||||
|
||||
<main class="admin-main">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="icon-btn menu-btn" onclick="toggleSidebar()"><svg class="icon icon-sm"><use href="#i-menu"/></svg></button>
|
||||
<div class="breadcrumb">
|
||||
<span class="root">Console</span>
|
||||
<span class="sep">/</span>
|
||||
<span class="current">Clients</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span class="live-chip"><span class="live-dot"></span>Live · 8 online</span>
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn" title="Notifications"><svg class="icon icon-sm"><use href="#i-bell"/></svg></button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h1 class="page-title">Clients</h1>
|
||||
<div class="page-sub">Registered SDK clients and their API access</div>
|
||||
</div>
|
||||
<div class="page-actions">
|
||||
<button class="btn btn-primary" onclick="openModal()">
|
||||
<svg class="icon icon-sm"><use href="#i-plus"/></svg>
|
||||
New client
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats strip -->
|
||||
<div class="stats-strip">
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Total clients</div>
|
||||
<div class="stat-value">12</div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Online now</div>
|
||||
<div class="stat-value"><span class="badge-dot"></span>8</div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Offline</div>
|
||||
<div class="stat-value"><span class="badge-dot off"></span>3</div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Pending setup</div>
|
||||
<div class="stat-value"><span class="badge-dot pending"></span>1</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Filter bar -->
|
||||
<div class="filter-bar">
|
||||
<div class="search-box">
|
||||
<svg class="icon icon-sm"><use href="#i-search"/></svg>
|
||||
<input type="text" placeholder="Search by name, API key or type…" />
|
||||
</div>
|
||||
<div class="pill-group">
|
||||
<button class="pill active">All <span class="count">12</span></button>
|
||||
<button class="pill">Online <span class="count">8</span></button>
|
||||
<button class="pill">Offline <span class="count">3</span></button>
|
||||
<button class="pill">Pending <span class="count">1</span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table -->
|
||||
<div class="panel">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Client</th>
|
||||
<th>API key</th>
|
||||
<th class="right">Events today</th>
|
||||
<th class="right storage-cell">Storage</th>
|
||||
<th>Last seen</th>
|
||||
<th class="right"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-01</div>
|
||||
<div class="client-type">sensors-app · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••8f3a</span>
|
||||
<button class="copy" title="Copy key"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">18,420</td>
|
||||
<td class="right mono storage-cell">4.2 MB</td>
|
||||
<td class="mono">14:28:01 <span class="rel">2s ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act" title="View events"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act" title="Rotate key"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger" title="Revoke"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-02</div>
|
||||
<div class="client-type">web-analytics · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••3b71</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">12,182</td>
|
||||
<td class="right mono storage-cell">2.8 MB</td>
|
||||
<td class="mono">14:27:58 <span class="rel">4s ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-03</div>
|
||||
<div class="client-type">orders-sync · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••e0c9</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">8,204</td>
|
||||
<td class="right mono storage-cell">1.9 MB</td>
|
||||
<td class="mono">14:28:00 <span class="rel">1s ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-04</div>
|
||||
<div class="client-type">devices-iote · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••7d42</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">2,144</td>
|
||||
<td class="right mono storage-cell">0.5 MB</td>
|
||||
<td class="mono">14:27:52 <span class="rel">8s ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-06</div>
|
||||
<div class="client-type">mobile-backend · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••1a09</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">1,204</td>
|
||||
<td class="right mono storage-cell">0.3 MB</td>
|
||||
<td class="mono">14:27:48 <span class="rel">12s ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot offline"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-05</div>
|
||||
<div class="client-type">staging-test · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_test_••••f5b2</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">340</td>
|
||||
<td class="right mono storage-cell">0.1 MB</td>
|
||||
<td class="mono">12:24:11 <span class="rel">2h ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot offline"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-07</div>
|
||||
<div class="client-type">cron-jobs · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_test_••••9c14</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">82</td>
|
||||
<td class="right mono storage-cell">12 KB</td>
|
||||
<td class="mono">08:12:04 <span class="rel">6h ago</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<div class="client-cell">
|
||||
<span class="client-dot pending"></span>
|
||||
<div>
|
||||
<div class="client-name">py-client-08</div>
|
||||
<div class="client-type">new-proto · Python</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td class="api-key-cell">
|
||||
<span class="key">sk_live_••••4e88</span>
|
||||
<button class="copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</td>
|
||||
<td class="right mono">0</td>
|
||||
<td class="right mono storage-cell">—</td>
|
||||
<td class="mono">— <span class="rel">never</span></td>
|
||||
<td class="right">
|
||||
<div class="row-actions">
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-activity"/></svg></button>
|
||||
<button class="act"><svg class="icon icon-sm"><use href="#i-refresh"/></svg></button>
|
||||
<button class="act danger"><svg class="icon icon-sm"><use href="#i-trash"/></svg></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="hint">Rotating a key invalidates the current one instantly · Revoking disconnects all active sessions</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal" id="modal" onclick="if(event.target===this)closeModal()">
|
||||
<div class="modal-panel">
|
||||
<div class="modal-head">
|
||||
<span class="modal-title">Create client</span>
|
||||
<button class="icon-btn" onclick="closeModal()"><svg class="icon icon-sm"><use href="#i-x"/></svg></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-field">
|
||||
<label>Client name</label>
|
||||
<input type="text" placeholder="e.g. sensors-app" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>SDK type</label>
|
||||
<select>
|
||||
<option>Python</option>
|
||||
<option>Node.js</option>
|
||||
<option>PHP</option>
|
||||
<option>Android</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label>Description <span class="optional">optional</span></label>
|
||||
<input type="text" placeholder="Short description" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-foot">
|
||||
<button class="btn" onclick="closeModal()">Cancel</button>
|
||||
<button class="btn btn-primary">Create client</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleSidebar(){
|
||||
document.getElementById('sidebar').classList.toggle('open');
|
||||
document.getElementById('overlay').classList.toggle('open');
|
||||
}
|
||||
function toggleTheme(){
|
||||
const html=document.documentElement, icon=document.getElementById('theme-icon');
|
||||
const isDark=html.getAttribute('data-theme')==='dark';
|
||||
html.setAttribute('data-theme',isDark?'light':'dark');
|
||||
icon.innerHTML='<use href="'+(isDark?'#i-moon':'#i-sun')+'"/>';
|
||||
}
|
||||
function openModal(){ document.getElementById('modal').classList.add('open'); }
|
||||
function closeModal(){ document.getElementById('modal').classList.remove('open'); }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,538 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Export</title>
|
||||
<style>
|
||||
:root{
|
||||
--bg:#0a0a0b;--surface:#111113;--surface-2:#17171a;--surface-3:#1d1d21;
|
||||
--border:#232326;--border-strong:#2e2e33;
|
||||
--text:#e8e8ea;--text-muted:#85858c;--text-faint:#5a5a62;
|
||||
--accent:#a3e635;--accent-text:#a3e635;
|
||||
--danger:#f87171;--warn:#fbbf24;
|
||||
--font:"Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono:"Consolas","SF Mono","Courier New",monospace;
|
||||
--radius:0;
|
||||
}
|
||||
[data-theme="light"]{
|
||||
--bg:#fafafa;--surface:#fff;--surface-2:#f4f4f5;--surface-3:#ececed;
|
||||
--border:#e2e2e5;--border-strong:#d0d0d3;
|
||||
--text:#111113;--text-muted:#5a5a62;--text-faint:#85858c;
|
||||
--accent:#65a30d;--accent-text:#4d7c0f;
|
||||
--danger:#dc2626;--warn:#d97706;
|
||||
}
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{background:var(--bg);color:var(--text);font-family:var(--font);
|
||||
font-size:13px;line-height:1.5;font-weight:400;-webkit-font-smoothing:antialiased}
|
||||
a{color:inherit;text-decoration:none}
|
||||
button,input,select{font-family:inherit;font-size:inherit;color:inherit}
|
||||
button{cursor:pointer}
|
||||
.icon{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:1.5;
|
||||
stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
|
||||
.icon-sm{width:14px;height:14px}
|
||||
|
||||
/* Layout */
|
||||
.admin{display:grid;grid-template-columns:208px 1fr;min-height:100vh}
|
||||
.sidebar{background:var(--surface);border-right:1px solid var(--border);
|
||||
display:flex;flex-direction:column;height:100vh;position:sticky;top:0;z-index:40}
|
||||
.sidebar-head{height:56px;padding:0 16px;display:flex;align-items:center;
|
||||
justify-content:space-between;border-bottom:1px solid var(--border);flex-shrink:0}
|
||||
.brand{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500}
|
||||
.brand-mark{width:14px;height:14px;background:var(--accent);display:grid;place-items:center}
|
||||
.brand-mark::after{content:"";width:5px;height:5px;background:var(--bg)}
|
||||
.brand-tag{font-size:9px;padding:1px 5px;margin-left:6px;
|
||||
border:1px solid var(--border-strong);color:var(--text-faint);letter-spacing:.5px}
|
||||
.sidebar-nav{flex:1;overflow-y:auto;padding:12px 0}
|
||||
.nav-section{padding:0 12px;margin-bottom:16px}
|
||||
.nav-label{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);padding:4px 8px 6px;display:flex;align-items:center;
|
||||
justify-content:space-between}
|
||||
.nav-label .count{background:var(--surface-2);color:var(--text-muted);padding:0 5px;
|
||||
font-size:9px;letter-spacing:0}
|
||||
.nav-item{display:flex;align-items:center;gap:10px;padding:7px 8px;height:32px;
|
||||
font-size:12.5px;color:var(--text-muted);border-left:2px solid transparent;
|
||||
transition:background .12s,color .12s;user-select:none}
|
||||
.nav-item:hover{background:var(--surface-2);color:var(--text)}
|
||||
.nav-item.active{background:var(--surface-2);color:var(--text);border-left-color:var(--accent)}
|
||||
.nav-item.active .icon{color:var(--accent)}
|
||||
.sidebar-foot{border-top:1px solid var(--border);padding:10px 12px;
|
||||
display:flex;align-items:center;gap:8px}
|
||||
.avatar{width:26px;height:26px;background:var(--surface-3);border:1px solid var(--border-strong);
|
||||
display:grid;place-items:center;font-size:11px;font-weight:500;color:var(--text);flex-shrink:0}
|
||||
.user-meta{flex:1;min-width:0}
|
||||
.user-name{font-size:12px;font-weight:500;color:var(--text);white-space:nowrap;
|
||||
overflow:hidden;text-overflow:ellipsis}
|
||||
.user-role{font-size:10px;color:var(--text-faint);text-transform:uppercase;letter-spacing:.5px}
|
||||
.icon-btn{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:background .12s}
|
||||
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
|
||||
|
||||
/* Main */
|
||||
.admin-main{display:flex;flex-direction:column;min-width:0}
|
||||
.topbar{height:56px;padding:0 24px;background:var(--surface);border-bottom:1px solid var(--border);
|
||||
display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
position:sticky;top:0;z-index:30}
|
||||
.topbar-left{display:flex;align-items:center;gap:12px;min-width:0}
|
||||
.menu-btn{display:none}
|
||||
.breadcrumb{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text-faint)}
|
||||
.breadcrumb .sep{color:var(--border-strong)}
|
||||
.breadcrumb .current{color:var(--text)}
|
||||
.topbar-right{display:flex;align-items:center;gap:8px}
|
||||
.live-chip{display:inline-flex;align-items:center;gap:6px;padding:4px 9px;
|
||||
border:1px solid var(--border-strong);font-size:10px;letter-spacing:.5px;
|
||||
text-transform:uppercase;color:var(--text-muted)}
|
||||
.live-dot{width:5px;height:5px;background:var(--accent);animation:pulse 2s infinite}
|
||||
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.35}}
|
||||
.theme-toggle{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted)}
|
||||
.theme-toggle:hover{background:var(--surface-2)}
|
||||
|
||||
/* Content */
|
||||
.content{padding:24px;max-width:1240px;width:100%}
|
||||
.page-head{display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
margin-bottom:16px;flex-wrap:wrap}
|
||||
.page-title{font-size:17px;font-weight:500;letter-spacing:-.2px}
|
||||
.page-sub{font-size:12px;color:var(--text-muted);margin-top:2px}
|
||||
.page-actions{display:flex;gap:8px}
|
||||
.btn{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;height:30px;
|
||||
font-size:12px;font-weight:400;border:1px solid var(--border-strong);
|
||||
background:transparent;color:var(--text);transition:background .12s,border-color .12s}
|
||||
.btn:hover{background:var(--surface-2)}
|
||||
.btn-primary{background:var(--text);color:var(--bg);border-color:var(--text)}
|
||||
.btn-primary:hover{background:#d0d0d3;border-color:#d0d0d3}
|
||||
.btn-icon{padding:0;width:30px;height:30px;justify-content:center}
|
||||
.btn-sm{padding:4px 9px;height:26px;font-size:11px}
|
||||
|
||||
/* Stats strip */
|
||||
.stats-strip{display:grid;grid-template-columns:repeat(4,1fr);gap:1px;
|
||||
background:var(--border);border:1px solid var(--border);margin-bottom:16px}
|
||||
.stat-cell{background:var(--surface);padding:12px 16px}
|
||||
.stat-label{font-size:10px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);margin-bottom:4px}
|
||||
.stat-value{font-size:18px;font-weight:500;letter-spacing:-.3px;color:var(--text);line-height:1.1}
|
||||
.stat-value .unit{font-size:11px;color:var(--text-muted);font-weight:400;margin-left:2px}
|
||||
|
||||
/* Grid */
|
||||
.grid-2{display:grid;grid-template-columns:1.6fr 1fr;gap:12px;align-items:start}
|
||||
|
||||
/* Panel */
|
||||
.panel{background:var(--surface);border:1px solid var(--border);display:flex;flex-direction:column}
|
||||
.panel-head{display:flex;align-items:center;justify-content:space-between;
|
||||
padding:10px 14px;border-bottom:1px solid var(--border);gap:12px}
|
||||
.panel-title{font-size:12px;font-weight:500;display:flex;align-items:center;gap:8px}
|
||||
.panel-title .icon{color:var(--text-muted)}
|
||||
.panel-meta{font-size:11px;color:var(--text-faint)}
|
||||
.panel-link{font-size:11px;color:var(--text-muted)}
|
||||
.panel-link:hover{color:var(--text)}
|
||||
.panel-body{padding:16px;display:flex;flex-direction:column;gap:14px}
|
||||
.panel-foot{display:flex;align-items:center;justify-content:flex-end;gap:6px;
|
||||
padding:10px 14px;border-top:1px solid var(--border)}
|
||||
.panel-foot .spacer{flex:1}
|
||||
|
||||
/* Section label */
|
||||
.section-label{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);margin-bottom:-4px}
|
||||
|
||||
/* Preset row */
|
||||
.preset-row{display:flex;align-items:center;gap:4px;flex-wrap:wrap}
|
||||
.preset-label{font-size:10px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);margin-right:6px}
|
||||
.pill{height:24px;padding:0 9px;border:1px solid var(--border);background:transparent;
|
||||
font-size:11px;color:var(--text-muted);display:inline-flex;align-items:center;
|
||||
transition:background .12s,color .12s,border-color .12s}
|
||||
.pill:hover{background:var(--surface-2);color:var(--text)}
|
||||
.pill.active{background:var(--surface-2);color:var(--text);border-color:var(--border-strong)}
|
||||
|
||||
/* Fields */
|
||||
.field-row{display:grid;grid-template-columns:1.2fr 1fr 1fr;gap:1px;
|
||||
background:var(--border);border:1px solid var(--border)}
|
||||
.field{background:var(--surface);padding:8px 12px;min-width:0}
|
||||
.field-label{font-size:9.5px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint);margin-bottom:3px}
|
||||
.field-input,.field-select{width:100%;background:transparent;border:none;outline:none;
|
||||
font-size:12.5px;color:var(--text);padding:0;height:20px}
|
||||
.field-input::placeholder{color:var(--text-faint)}
|
||||
.field-select{appearance:none;cursor:pointer;
|
||||
background-image:linear-gradient(45deg,transparent 50%,var(--text-muted) 50%),
|
||||
linear-gradient(135deg,var(--text-muted) 50%,transparent 50%);
|
||||
background-position:calc(100% - 8px) 9px,calc(100% - 4px) 9px;
|
||||
background-size:4px 4px;background-repeat:no-repeat}
|
||||
|
||||
/* Format cards */
|
||||
.format-row{display:grid;grid-template-columns:1fr 1fr;gap:8px}
|
||||
.format-opt{cursor:pointer;display:block}
|
||||
.format-opt input{display:none}
|
||||
.format-inner{border:1px solid var(--border);padding:10px 12px;display:flex;
|
||||
align-items:center;gap:10px;transition:border-color .12s,background .12s}
|
||||
.format-opt:hover .format-inner{border-color:var(--border-strong)}
|
||||
.format-opt input:checked + .format-inner{
|
||||
border-color:var(--border-strong);background:var(--surface-2)}
|
||||
.format-opt input:checked + .format-inner .format-icon{
|
||||
color:var(--accent-text);border-color:var(--border-strong)}
|
||||
.format-icon{width:26px;height:26px;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:color .12s}
|
||||
.format-name{font-size:12.5px;font-weight:500;color:var(--text);line-height:1.2}
|
||||
.format-hint{font-size:10.5px;color:var(--text-faint);margin-top:2px}
|
||||
|
||||
/* Options */
|
||||
.options-row{display:flex;flex-wrap:wrap;gap:14px 20px}
|
||||
.check{display:flex;align-items:center;gap:8px;font-size:11.5px;
|
||||
color:var(--text-muted);cursor:pointer;user-select:none}
|
||||
.check input{display:none}
|
||||
.check-box{width:14px;height:14px;border:1px solid var(--border-strong);
|
||||
flex-shrink:0;position:relative;transition:background .12s,border-color .12s}
|
||||
.check-box::after{content:"";position:absolute;left:4px;top:2px;width:5px;height:8px;
|
||||
border-right:1.5px solid var(--bg);border-bottom:1.5px solid var(--bg);
|
||||
transform:rotate(45deg);opacity:0}
|
||||
.check input:checked + .check-box{background:var(--accent);border-color:var(--accent)}
|
||||
.check input:checked + .check-box::after{opacity:1}
|
||||
|
||||
/* Preview strip */
|
||||
.preview-strip{display:flex;align-items:center;gap:8px;
|
||||
border:1px solid var(--border);border-left:2px solid var(--accent);
|
||||
background:var(--surface-2);padding:9px 12px;
|
||||
font-family:var(--mono);font-size:11.5px;color:var(--text-muted)}
|
||||
.preview-strip .icon{color:var(--accent-text)}
|
||||
.preview-strip strong{color:var(--text);font-weight:500}
|
||||
|
||||
/* Recent exports */
|
||||
.export-item{display:flex;align-items:center;gap:10px;padding:9px 14px;
|
||||
border-bottom:1px solid rgba(35,35,38,.6);transition:background .12s}
|
||||
[data-theme="light"] .export-item{border-bottom-color:var(--border)}
|
||||
.export-item:last-child{border-bottom:none}
|
||||
.export-item:hover{background:var(--surface-2)}
|
||||
.fmt-badge{font-family:var(--mono);font-size:9px;letter-spacing:.5px;padding:2px 5px;
|
||||
border:1px solid var(--border-strong);color:var(--text-muted);flex-shrink:0;
|
||||
text-transform:uppercase}
|
||||
.export-meta{flex:1;min-width:0}
|
||||
.export-name{font-size:11.5px;color:var(--text);font-family:var(--mono);
|
||||
white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
||||
.export-sub{font-size:10.5px;color:var(--text-faint);margin-top:2px}
|
||||
.export-dl{width:22px;height:22px;background:transparent;border:none;
|
||||
display:grid;place-items:center;color:var(--text-muted);flex-shrink:0;transition:color .12s}
|
||||
.export-item:hover .export-dl{color:var(--accent-text)}
|
||||
|
||||
/* Hint */
|
||||
.hint{font-size:11px;color:var(--text-faint);margin-top:8px}
|
||||
|
||||
/* Mobile */
|
||||
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:35}
|
||||
.overlay.open{display:block}
|
||||
@media (max-width:1024px){
|
||||
.admin{grid-template-columns:1fr}
|
||||
.sidebar{position:fixed;top:0;left:0;width:220px;transform:translateX(-100%);
|
||||
transition:transform .2s ease-out}
|
||||
.sidebar.open{transform:translateX(0)}
|
||||
.menu-btn{display:grid}
|
||||
.stats-strip{grid-template-columns:repeat(2,1fr)}
|
||||
.grid-2{grid-template-columns:1fr}
|
||||
}
|
||||
@media (max-width:640px){
|
||||
.content{padding:16px}
|
||||
.topbar{padding:0 16px}
|
||||
.live-chip{display:none}
|
||||
.breadcrumb .sep,.breadcrumb .root{display:none}
|
||||
.field-row{grid-template-columns:1fr}
|
||||
.format-row{grid-template-columns:1fr}
|
||||
.stats-strip{grid-template-columns:1fr 1fr}
|
||||
.stat-value{font-size:16px}
|
||||
.panel-body{padding:14px;gap:12px}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-grid" viewBox="0 0 16 16"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 16 16"><ellipse cx="8" cy="4" rx="5.5" ry="2"/><path d="M2.5 4v8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2V4"/><path d="M2.5 8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 16 16"><circle cx="6" cy="6" r="2.5"/><path d="M1.5 13.5c0-2.2 2-3.5 4.5-3.5s4.5 1.3 4.5 3.5"/><path d="M11 3.5a2.5 2.5 0 0 1 0 5"/><path d="M12.5 10c1.4.4 2.5 1.4 2.5 3.5"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 16 16"><path d="M8 2v8"/><path d="M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 13.5h11"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 16 16"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.5 3.5l1.4 1.4M11.1 11.1l1.4 1.4M3.5 12.5l1.4-1.4M11.1 4.9l1.4-1.4"/></symbol>
|
||||
<symbol id="i-list" viewBox="0 0 16 16"><path d="M3 4h10M3 8h10M3 12h7"/></symbol>
|
||||
<symbol id="i-book" viewBox="0 0 16 16"><path d="M3 2.5h7.5c1 0 1.5.5 1.5 1.5v10H4.5c-1 0-1.5-.5-1.5-1.5V2.5Z"/><path d="M3 12.5c0-1 .5-1.5 1.5-1.5H12"/></symbol>
|
||||
<symbol id="i-menu" viewBox="0 0 16 16"><path d="M2.5 4h11M2.5 8h11M2.5 12h11"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 16 16"><path d="M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11Z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/></symbol>
|
||||
<symbol id="i-file" viewBox="0 0 16 16"><path d="M4 2.5h5L12.5 6v7.5h-8.5Z"/><path d="M9 2.5V6h3.5"/></symbol>
|
||||
<symbol id="i-braces" viewBox="0 0 16 16"><path d="M6 3H4.5c-.5 0-.5.5-.5.5V7c0 1-1 1-1 1s1 0 1 1v3.5c0 .5.5.5 1 .5H6"/><path d="M10 3h1.5c.5 0 .5.5.5.5V7c0 1 1 1 1 1s-1 0-1 1v3.5c0 .5-.5.5-1 .5H10"/></symbol>
|
||||
<symbol id="i-info" viewBox="0 0 16 16"><circle cx="8" cy="8" r="5.5"/><path d="M8 7.5v4"/><circle cx="8" cy="5" r=".5" fill="currentColor"/></symbol>
|
||||
<symbol id="i-sparkle" viewBox="0 0 16 16"><path d="M8 2v4M8 10v4M2 8h4M10 8h4M4.5 4.5l2 2M9.5 9.5l2 2M4.5 11.5l2-2M9.5 6.5l2-2"/></symbol>
|
||||
</svg>
|
||||
|
||||
<div class="admin">
|
||||
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<a href="/" class="brand"><span class="brand-mark"></span>DataStack<span class="brand-tag">CONSOLE</span></a>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">Main</div>
|
||||
<a href="/vcon/dashboard" class="nav-item"><svg class="icon"><use href="#i-grid"/></svg>Dashboard</a>
|
||||
<a href="/vcon/data" class="nav-item"><svg class="icon"><use href="#i-db"/></svg>Data</a>
|
||||
<a href="/vcon/clients" class="nav-item"><svg class="icon"><use href="#i-users"/></svg>Clients</a>
|
||||
<a href="/vcon/export" class="nav-item active"><svg class="icon"><use href="#i-download"/></svg>Export</a>
|
||||
</div>
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">System <span class="count">3</span></div>
|
||||
<a href="/vcon/logs" class="nav-item"><svg class="icon"><use href="#i-list"/></svg>Logs</a>
|
||||
<a href="/vcon/settings" class="nav-item"><svg class="icon"><use href="#i-settings"/></svg>Settings</a>
|
||||
<a href="/docs" class="nav-item"><svg class="icon"><use href="#i-book"/></svg>Docs</a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="sidebar-foot">
|
||||
<div class="avatar">A</div>
|
||||
<div class="user-meta">
|
||||
<div class="user-name">Admin</div>
|
||||
<div class="user-role">Owner</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="Settings"><svg class="icon icon-sm"><use href="#i-settings"/></svg></button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="overlay" id="overlay" onclick="toggleSidebar()"></div>
|
||||
|
||||
<main class="admin-main">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="icon-btn menu-btn" onclick="toggleSidebar()"><svg class="icon icon-sm"><use href="#i-menu"/></svg></button>
|
||||
<div class="breadcrumb">
|
||||
<span class="root">Console</span>
|
||||
<span class="sep">/</span>
|
||||
<span class="current">Export</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span class="live-chip"><span class="live-dot"></span>Estimate live</span>
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn" title="Notifications"><svg class="icon icon-sm"><use href="#i-bell"/></svg></button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h1 class="page-title">Export</h1>
|
||||
<div class="page-sub">Generate CSV or JSON exports from collected data</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Stats strip -->
|
||||
<div class="stats-strip">
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Exports today</div>
|
||||
<div class="stat-value">24</div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Last export</div>
|
||||
<div class="stat-value">2h<span class="unit">ago</span></div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Total exported</div>
|
||||
<div class="stat-value">1.2<span class="unit">GB</span></div>
|
||||
</div>
|
||||
<div class="stat-cell">
|
||||
<div class="stat-label">Retention</div>
|
||||
<div class="stat-value">30<span class="unit">days</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid-2">
|
||||
|
||||
<!-- Export builder -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title">
|
||||
<svg class="icon icon-sm"><use href="#i-sparkle"/></svg>
|
||||
Export builder
|
||||
</div>
|
||||
<span class="panel-meta">Estimate updates on change</span>
|
||||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
|
||||
<!-- Quick presets -->
|
||||
<div class="preset-row">
|
||||
<span class="preset-label">Quick range</span>
|
||||
<button class="pill active">Today</button>
|
||||
<button class="pill">Last 7d</button>
|
||||
<button class="pill">Last 30d</button>
|
||||
<button class="pill">All</button>
|
||||
</div>
|
||||
|
||||
<!-- Filter fields -->
|
||||
<div class="field-row">
|
||||
<div class="field">
|
||||
<div class="field-label">Client</div>
|
||||
<select class="field-select">
|
||||
<option>All clients</option>
|
||||
<option>py-client-01</option>
|
||||
<option>py-client-02</option>
|
||||
<option>py-client-03</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label">From</div>
|
||||
<input type="date" class="field-input" value="2026-10-23">
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label">To</div>
|
||||
<input type="date" class="field-input" value="2026-10-23">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Format -->
|
||||
<div class="section-label">Format</div>
|
||||
<div class="format-row">
|
||||
<label class="format-opt">
|
||||
<input type="radio" name="format" checked>
|
||||
<div class="format-inner">
|
||||
<div class="format-icon"><svg class="icon icon-sm"><use href="#i-file"/></svg></div>
|
||||
<div>
|
||||
<div class="format-name">CSV</div>
|
||||
<div class="format-hint">Comma-separated values</div>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
<label class="format-opt">
|
||||
<input type="radio" name="format">
|
||||
<div class="format-inner">
|
||||
<div class="format-icon"><svg class="icon icon-sm"><use href="#i-braces"/></svg></div>
|
||||
<div>
|
||||
<div class="format-name">JSON</div>
|
||||
<div class="format-hint">Structured array</div>
|
||||
</div>
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Options -->
|
||||
<div class="section-label">Options</div>
|
||||
<div class="options-row">
|
||||
<label class="check">
|
||||
<input type="checkbox" checked>
|
||||
<span class="check-box"></span>
|
||||
Include header row
|
||||
</label>
|
||||
<label class="check">
|
||||
<input type="checkbox">
|
||||
<span class="check-box"></span>
|
||||
Gzip compress
|
||||
</label>
|
||||
<label class="check">
|
||||
<input type="checkbox" checked>
|
||||
<span class="check-box"></span>
|
||||
Include metadata
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Preview -->
|
||||
<div class="preview-strip">
|
||||
<svg class="icon icon-sm"><use href="#i-info"/></svg>
|
||||
<span><strong>42,891</strong> rows · <strong>~18.2 MB</strong> · <strong>3</strong> CSV files</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="panel-foot">
|
||||
<button class="btn btn-sm">Reset</button>
|
||||
<button class="btn btn-sm">Preview</button>
|
||||
<button class="btn btn-primary btn-sm">
|
||||
<svg class="icon icon-sm"><use href="#i-download"/></svg>
|
||||
Download
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Recent exports -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title">Recent exports</div>
|
||||
<button class="panel-link">View all →</button>
|
||||
</div>
|
||||
<div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">CSV</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct23_sensors_01.csv</div>
|
||||
<div class="export-sub">2h ago · 4,120 rows · 1.2 MB</div>
|
||||
</div>
|
||||
<button class="export-dl" title="Download"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">JSON</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct23_web_analytics.json</div>
|
||||
<div class="export-sub">3h ago · 8,204 rows · 2.4 MB</div>
|
||||
</div>
|
||||
<button class="export-dl"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">CSV</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct22_all_clients.csv</div>
|
||||
<div class="export-sub">18h ago · 22,140 rows · 9.1 MB</div>
|
||||
</div>
|
||||
<button class="export-dl"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">CSV</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct21_orders_sync.csv</div>
|
||||
<div class="export-sub">1d ago · 6,022 rows · 2.1 MB</div>
|
||||
</div>
|
||||
<button class="export-dl"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">CSV</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct20_failed_only.csv</div>
|
||||
<div class="export-sub">2d ago · 84 rows · 12 KB</div>
|
||||
</div>
|
||||
<button class="export-dl"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
<div class="export-item">
|
||||
<span class="fmt-badge">JSON</span>
|
||||
<div class="export-meta">
|
||||
<div class="export-name">oct19_devices_snapshot.json</div>
|
||||
<div class="export-sub">3d ago · 1,204 rows · 340 KB</div>
|
||||
</div>
|
||||
<button class="export-dl"><svg class="icon icon-sm"><use href="#i-download"/></svg></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="hint">Exports are generated from CSV files on disk · Estimates are approximations · Files over 100 MB download via streaming</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleSidebar(){
|
||||
document.getElementById('sidebar').classList.toggle('open');
|
||||
document.getElementById('overlay').classList.toggle('open');
|
||||
}
|
||||
function toggleTheme(){
|
||||
const html=document.documentElement, icon=document.getElementById('theme-icon');
|
||||
const isDark=html.getAttribute('data-theme')==='dark';
|
||||
html.setAttribute('data-theme',isDark?'light':'dark');
|
||||
icon.innerHTML='<use href="'+(isDark?'#i-moon':'#i-sun')+'"/>';
|
||||
}
|
||||
// Pill interactions
|
||||
document.querySelectorAll('.preset-row .pill').forEach(p => {
|
||||
p.addEventListener('click', () => {
|
||||
document.querySelectorAll('.preset-row .pill').forEach(x => x.classList.remove('active'));
|
||||
p.classList.add('active');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,714 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Settings</title>
|
||||
<style>
|
||||
:root{
|
||||
--bg:#0a0a0b;--surface:#111113;--surface-2:#17171a;--surface-3:#1d1d21;
|
||||
--border:#232326;--border-strong:#2e2e33;
|
||||
--text:#e8e8ea;--text-muted:#85858c;--text-faint:#5a5a62;
|
||||
--accent:#a3e635;--accent-text:#a3e635;
|
||||
--danger:#f87171;--warn:#fbbf24;
|
||||
--font:"Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono:"Consolas","SF Mono","Courier New",monospace;
|
||||
--radius:0;
|
||||
}
|
||||
[data-theme="light"]{
|
||||
--bg:#fafafa;--surface:#fff;--surface-2:#f4f4f5;--surface-3:#ececed;
|
||||
--border:#e2e2e5;--border-strong:#d0d0d3;
|
||||
--text:#111113;--text-muted:#5a5a62;--text-faint:#85858c;
|
||||
--accent:#65a30d;--accent-text:#4d7c0f;
|
||||
--danger:#dc2626;--warn:#d97706;
|
||||
}
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{background:var(--bg);color:var(--text);font-family:var(--font);
|
||||
font-size:13px;line-height:1.5;font-weight:400;-webkit-font-smoothing:antialiased}
|
||||
a{color:inherit;text-decoration:none}
|
||||
button,input,select,textarea{font-family:inherit;font-size:inherit;color:inherit}
|
||||
button{cursor:pointer}
|
||||
.icon{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:1.5;
|
||||
stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
|
||||
.icon-sm{width:14px;height:14px}
|
||||
|
||||
/* Layout */
|
||||
.admin{display:grid;grid-template-columns:208px 1fr;min-height:100vh}
|
||||
.sidebar{background:var(--surface);border-right:1px solid var(--border);
|
||||
display:flex;flex-direction:column;height:100vh;position:sticky;top:0;z-index:40}
|
||||
.sidebar-head{height:56px;padding:0 16px;display:flex;align-items:center;
|
||||
justify-content:space-between;border-bottom:1px solid var(--border);flex-shrink:0}
|
||||
.brand{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500}
|
||||
.brand-mark{width:14px;height:14px;background:var(--accent);display:grid;place-items:center}
|
||||
.brand-mark::after{content:"";width:5px;height:5px;background:var(--bg)}
|
||||
.brand-tag{font-size:9px;padding:1px 5px;margin-left:6px;
|
||||
border:1px solid var(--border-strong);color:var(--text-faint);letter-spacing:.5px}
|
||||
.sidebar-nav{flex:1;overflow-y:auto;padding:12px 0}
|
||||
.nav-section{padding:0 12px;margin-bottom:16px}
|
||||
.nav-label{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);padding:4px 8px 6px;display:flex;align-items:center;
|
||||
justify-content:space-between}
|
||||
.nav-label .count{background:var(--surface-2);color:var(--text-muted);padding:0 5px;
|
||||
font-size:9px;letter-spacing:0}
|
||||
.nav-item{display:flex;align-items:center;gap:10px;padding:7px 8px;height:32px;
|
||||
font-size:12.5px;color:var(--text-muted);border-left:2px solid transparent;
|
||||
transition:background .12s,color .12s;user-select:none}
|
||||
.nav-item:hover{background:var(--surface-2);color:var(--text)}
|
||||
.nav-item.active{background:var(--surface-2);color:var(--text);border-left-color:var(--accent)}
|
||||
.nav-item.active .icon{color:var(--accent)}
|
||||
.sidebar-foot{border-top:1px solid var(--border);padding:10px 12px;
|
||||
display:flex;align-items:center;gap:8px}
|
||||
.avatar{width:26px;height:26px;background:var(--surface-3);border:1px solid var(--border-strong);
|
||||
display:grid;place-items:center;font-size:11px;font-weight:500;color:var(--text);flex-shrink:0}
|
||||
.user-meta{flex:1;min-width:0}
|
||||
.user-name{font-size:12px;font-weight:500;color:var(--text);white-space:nowrap;
|
||||
overflow:hidden;text-overflow:ellipsis}
|
||||
.user-role{font-size:10px;color:var(--text-faint);text-transform:uppercase;letter-spacing:.5px}
|
||||
.icon-btn{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted);transition:background .12s}
|
||||
.icon-btn:hover{background:var(--surface-2);color:var(--text)}
|
||||
|
||||
/* Main */
|
||||
.admin-main{display:flex;flex-direction:column;min-width:0}
|
||||
.topbar{height:56px;padding:0 24px;background:var(--surface);border-bottom:1px solid var(--border);
|
||||
display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
position:sticky;top:0;z-index:30}
|
||||
.topbar-left{display:flex;align-items:center;gap:12px;min-width:0}
|
||||
.menu-btn{display:none}
|
||||
.breadcrumb{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text-faint)}
|
||||
.breadcrumb .sep{color:var(--border-strong)}
|
||||
.breadcrumb .current{color:var(--text)}
|
||||
.topbar-right{display:flex;align-items:center;gap:8px}
|
||||
.theme-toggle{width:28px;height:28px;background:transparent;border:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-muted)}
|
||||
.theme-toggle:hover{background:var(--surface-2)}
|
||||
|
||||
/* Content */
|
||||
.content{padding:24px;max-width:1080px;width:100%}
|
||||
.page-head{display:flex;align-items:center;justify-content:space-between;gap:16px;
|
||||
margin-bottom:16px;flex-wrap:wrap}
|
||||
.page-title{font-size:17px;font-weight:500;letter-spacing:-.2px}
|
||||
.page-sub{font-size:12px;color:var(--text-muted);margin-top:2px}
|
||||
.page-actions{display:flex;gap:8px}
|
||||
|
||||
.btn{display:inline-flex;align-items:center;gap:6px;padding:6px 12px;height:30px;
|
||||
font-size:12px;font-weight:400;border:1px solid var(--border-strong);
|
||||
background:transparent;color:var(--text);transition:background .12s,border-color .12s}
|
||||
.btn:hover{background:var(--surface-2)}
|
||||
.btn-primary{background:var(--text);color:var(--bg);border-color:var(--text)}
|
||||
.btn-primary:hover{background:#d0d0d3;border-color:#d0d0d3}
|
||||
.btn-danger{color:var(--danger);border-color:var(--border)}
|
||||
.btn-danger:hover{background:rgba(248,113,113,.08);border-color:var(--danger)}
|
||||
.btn-sm{padding:4px 9px;height:26px;font-size:11px}
|
||||
|
||||
/* Tabs */
|
||||
.tabs{display:flex;border-bottom:1px solid var(--border);margin-bottom:0;
|
||||
overflow-x:auto;scrollbar-width:none}
|
||||
.tabs::-webkit-scrollbar{display:none}
|
||||
.tab{padding:9px 14px;font-size:12px;color:var(--text-muted);border-bottom:2px solid transparent;
|
||||
margin-bottom:-1px;background:transparent;border-top:none;border-left:none;border-right:none;
|
||||
cursor:pointer;white-space:nowrap;transition:color .12s,border-color .12s}
|
||||
.tab:hover{color:var(--text)}
|
||||
.tab.active{color:var(--text);border-bottom-color:var(--accent)}
|
||||
.tab .tab-count{font-size:10px;color:var(--text-faint);margin-left:5px}
|
||||
|
||||
/* Panel */
|
||||
.panel{background:var(--surface);border:1px solid var(--border);border-top:none}
|
||||
.tab-content{display:none}
|
||||
.tab-content.active{display:block}
|
||||
|
||||
.section{padding:16px}
|
||||
.section + .section{border-top:1px solid var(--border)}
|
||||
.section-title{font-size:10px;text-transform:uppercase;letter-spacing:.8px;
|
||||
color:var(--text-faint);margin-bottom:12px;display:flex;align-items:center;gap:6px}
|
||||
.section-title .section-desc{text-transform:none;letter-spacing:0;font-size:11px;
|
||||
color:var(--text-faint);margin-left:auto}
|
||||
|
||||
/* Field row */
|
||||
.field{display:grid;grid-template-columns:220px 1fr;gap:20px;padding:8px 0;
|
||||
align-items:start}
|
||||
.field:first-of-type{padding-top:0}
|
||||
.field:last-of-type{padding-bottom:0}
|
||||
.field-label-wrap{min-width:0;padding-top:1px}
|
||||
.field-label{font-size:12.5px;color:var(--text);font-weight:400;line-height:1.4}
|
||||
.field-hint{font-size:11px;color:var(--text-faint);margin-top:2px;line-height:1.5}
|
||||
.field-control{min-width:0}
|
||||
.field-control input,
|
||||
.field-control select,
|
||||
.field-control textarea{
|
||||
width:100%;height:30px;padding:0 10px;
|
||||
background:var(--bg);border:1px solid var(--border);
|
||||
outline:none;font-size:12.5px;color:var(--text);
|
||||
transition:border-color .12s,background .12s;
|
||||
}
|
||||
.field-control textarea{height:auto;padding:8px 10px;font-family:var(--mono);font-size:11.5px;
|
||||
resize:vertical;min-height:60px;line-height:1.5}
|
||||
.field-control input::placeholder,
|
||||
.field-control textarea::placeholder{color:var(--text-faint)}
|
||||
.field-control input:focus,
|
||||
.field-control select:focus,
|
||||
.field-control textarea:focus{border-color:var(--border-strong)}
|
||||
.field-control input[readonly]{background:var(--surface-2);color:var(--text-muted);cursor:default}
|
||||
.field-control select{appearance:none;cursor:pointer;
|
||||
background-image:linear-gradient(45deg,transparent 50%,var(--text-muted) 50%),
|
||||
linear-gradient(135deg,var(--text-muted) 50%,transparent 50%);
|
||||
background-position:calc(100% - 10px) 12px,calc(100% - 6px) 12px;
|
||||
background-size:4px 4px;background-repeat:no-repeat;
|
||||
padding-right:24px}
|
||||
|
||||
/* Inline group (input + button) */
|
||||
.control-group{display:flex;gap:6px;align-items:stretch}
|
||||
.control-group input{flex:1;min-width:0}
|
||||
.control-group .btn{height:30px;flex-shrink:0}
|
||||
.control-suffix{display:flex;align-items:center;padding:0 10px;height:30px;
|
||||
border:1px solid var(--border);border-left:none;
|
||||
background:var(--surface-2);color:var(--text-muted);font-size:11.5px}
|
||||
|
||||
/* Mono input for secrets */
|
||||
.mono-input{font-family:var(--mono);font-size:11.5px}
|
||||
|
||||
/* Checkbox inline */
|
||||
.check{display:flex;align-items:center;gap:8px;font-size:12px;
|
||||
color:var(--text-muted);cursor:pointer;user-select:none;padding:4px 0}
|
||||
.check input{display:none}
|
||||
.check-box{width:14px;height:14px;border:1px solid var(--border-strong);
|
||||
flex-shrink:0;position:relative;transition:background .12s,border-color .12s}
|
||||
.check-box::after{content:"";position:absolute;left:4px;top:2px;width:5px;height:8px;
|
||||
border-right:1.5px solid var(--bg);border-bottom:1.5px solid var(--bg);
|
||||
transform:rotate(45deg);opacity:0}
|
||||
.check input:checked + .check-box{background:var(--accent);border-color:var(--accent)}
|
||||
.check input:checked + .check-box::after{opacity:1}
|
||||
|
||||
/* Danger zone */
|
||||
.danger-zone{border:1px solid var(--danger);padding:12px 16px;
|
||||
display:flex;align-items:center;justify-content:space-between;gap:12px;
|
||||
margin-top:8px}
|
||||
.danger-zone .dz-title{font-size:12.5px;font-weight:500;color:var(--text);margin-bottom:2px}
|
||||
.danger-zone .dz-desc{font-size:11px;color:var(--text-faint);line-height:1.5}
|
||||
|
||||
/* Save bar */
|
||||
.save-bar{display:flex;align-items:center;gap:8px;padding:10px 16px;
|
||||
border-top:1px solid var(--border);background:var(--surface)}
|
||||
.save-status{flex:1;font-size:11.5px;color:var(--text-muted);
|
||||
display:flex;align-items:center;gap:6px}
|
||||
.save-status .dot{width:6px;height:6px;background:var(--accent)}
|
||||
.save-status.dirty .dot{background:var(--warn)}
|
||||
|
||||
/* Hint */
|
||||
.hint{font-size:11px;color:var(--text-faint);margin-top:12px;
|
||||
display:flex;align-items:center;gap:6px}
|
||||
|
||||
/* Mobile */
|
||||
.overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:35}
|
||||
.overlay.open{display:block}
|
||||
@media (max-width:1024px){
|
||||
.admin{grid-template-columns:1fr}
|
||||
.sidebar{position:fixed;top:0;left:0;width:220px;transform:translateX(-100%);
|
||||
transition:transform .2s ease-out}
|
||||
.sidebar.open{transform:translateX(0)}
|
||||
.menu-btn{display:grid}
|
||||
}
|
||||
@media (max-width:720px){
|
||||
.field{grid-template-columns:1fr;gap:6px}
|
||||
.content{padding:16px}
|
||||
.topbar{padding:0 16px}
|
||||
.breadcrumb .sep,.breadcrumb .root{display:none}
|
||||
.section{padding:14px}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-grid" viewBox="0 0 16 16"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 16 16"><ellipse cx="8" cy="4" rx="5.5" ry="2"/><path d="M2.5 4v8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2V4"/><path d="M2.5 8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 16 16"><circle cx="6" cy="6" r="2.5"/><path d="M1.5 13.5c0-2.2 2-3.5 4.5-3.5s4.5 1.3 4.5 3.5"/><path d="M11 3.5a2.5 2.5 0 0 1 0 5"/><path d="M12.5 10c1.4.4 2.5 1.4 2.5 3.5"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 16 16"><path d="M8 2v8"/><path d="M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 13.5h11"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 16 16"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.5 3.5l1.4 1.4M11.1 11.1l1.4 1.4M3.5 12.5l1.4-1.4M11.1 4.9l1.4-1.4"/></symbol>
|
||||
<symbol id="i-list" viewBox="0 0 16 16"><path d="M3 4h10M3 8h10M3 12h7"/></symbol>
|
||||
<symbol id="i-book" viewBox="0 0 16 16"><path d="M3 2.5h7.5c1 0 1.5.5 1.5 1.5v10H4.5c-1 0-1.5-.5-1.5-1.5V2.5Z"/><path d="M3 12.5c0-1 .5-1.5 1.5-1.5H12"/></symbol>
|
||||
<symbol id="i-menu" viewBox="0 0 16 16"><path d="M2.5 4h11M2.5 8h11M2.5 12h11"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 16 16"><path d="M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11Z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/></symbol>
|
||||
<symbol id="i-copy" viewBox="0 0 16 16"><rect x="5" y="5" width="8" height="9"/><path d="M3 11V3h8"/></symbol>
|
||||
<symbol id="i-refresh" viewBox="0 0 16 16"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.5 2.5v3.5H10"/></symbol>
|
||||
<symbol id="i-eye" viewBox="0 0 16 16"><path d="M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8Z"/><circle cx="8" cy="8" r="2"/></symbol>
|
||||
<symbol id="i-trash" viewBox="0 0 16 16"><path d="M3 4h10"/><path d="M5 4V2.5h6V4"/><path d="M4 4l.7 9.5h6.6L12 4"/><path d="M6.5 7v4M9.5 7v4"/></symbol>
|
||||
<symbol id="i-info" viewBox="0 0 16 16"><circle cx="8" cy="8" r="5.5"/><path d="M8 7.5v4"/><circle cx="8" cy="5" r=".5" fill="currentColor"/></symbol>
|
||||
<symbol id="i-check" viewBox="0 0 16 16"><path d="M3 8l3.5 3.5L13 5"/></symbol>
|
||||
</svg>
|
||||
|
||||
<div class="admin">
|
||||
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<a href="/" class="brand"><span class="brand-mark"></span>DataStack<span class="brand-tag">CONSOLE</span></a>
|
||||
</div>
|
||||
<nav class="sidebar-nav">
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">Main</div>
|
||||
<a href="/vcon/dashboard" class="nav-item"><svg class="icon"><use href="#i-grid"/></svg>Dashboard</a>
|
||||
<a href="/vcon/data" class="nav-item"><svg class="icon"><use href="#i-db"/></svg>Data</a>
|
||||
<a href="/vcon/clients" class="nav-item"><svg class="icon"><use href="#i-users"/></svg>Clients</a>
|
||||
<a href="/vcon/export" class="nav-item"><svg class="icon"><use href="#i-download"/></svg>Export</a>
|
||||
</div>
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">System <span class="count">3</span></div>
|
||||
<a href="/vcon/logs" class="nav-item"><svg class="icon"><use href="#i-list"/></svg>Logs</a>
|
||||
<a href="/vcon/settings" class="nav-item active"><svg class="icon"><use href="#i-settings"/></svg>Settings</a>
|
||||
<a href="/docs" class="nav-item"><svg class="icon"><use href="#i-book"/></svg>Docs</a>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="sidebar-foot">
|
||||
<div class="avatar">A</div>
|
||||
<div class="user-meta">
|
||||
<div class="user-name">Admin</div>
|
||||
<div class="user-role">Owner</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="Settings"><svg class="icon icon-sm"><use href="#i-settings"/></svg></button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="overlay" id="overlay" onclick="toggleSidebar()"></div>
|
||||
|
||||
<main class="admin-main">
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="icon-btn menu-btn" onclick="toggleSidebar()"><svg class="icon icon-sm"><use href="#i-menu"/></svg></button>
|
||||
<div class="breadcrumb">
|
||||
<span class="root">Console</span>
|
||||
<span class="sep">/</span>
|
||||
<span class="current">Settings</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn" title="Notifications"><svg class="icon icon-sm"><use href="#i-bell"/></svg></button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h1 class="page-title">Settings</h1>
|
||||
<div class="page-sub">Configure your DataStack instance</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
<div class="tabs">
|
||||
<button class="tab active" data-tab="general">General</button>
|
||||
<button class="tab" data-tab="connections">Connections</button>
|
||||
<button class="tab" data-tab="storage">Storage</button>
|
||||
<button class="tab" data-tab="security">Security</button>
|
||||
<button class="tab" data-tab="notifications">Notifications</button>
|
||||
</div>
|
||||
|
||||
<!-- Panel -->
|
||||
<div class="panel">
|
||||
|
||||
<!-- GENERAL -->
|
||||
<div class="tab-content active" id="tab-general">
|
||||
<div class="section">
|
||||
<div class="section-title">Identity</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Instance name</div>
|
||||
<div class="field-hint">Shown in dashboard headers and emails</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" value="DataStack" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Base URL</div>
|
||||
<div class="field-hint">Used in SDK setup and export links</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" value="https://your-host.com" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Instance ID</div>
|
||||
<div class="field-hint">Immutable · used in SDK fingerprint</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="text" class="mono-input" value="inst_7d2f9a4c1e8b" readonly />
|
||||
<button class="btn btn-sm" title="Copy"><svg class="icon icon-sm"><use href="#i-copy"/></svg></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Locale</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Timezone</div>
|
||||
<div class="field-hint">Applied to dashboard and exports</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<select>
|
||||
<option>UTC+00:00 — London</option>
|
||||
<option>UTC+06:00 — Dhaka</option>
|
||||
<option>UTC+09:00 — Tokyo</option>
|
||||
<option>UTC-08:00 — Los Angeles</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Date format</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<select>
|
||||
<option>YYYY-MM-DD (ISO)</option>
|
||||
<option>DD/MM/YYYY</option>
|
||||
<option>MM/DD/YYYY</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Language</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<select>
|
||||
<option>English</option>
|
||||
<option>বাংলা</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CONNECTIONS -->
|
||||
<div class="tab-content" id="tab-connections">
|
||||
<div class="section">
|
||||
<div class="section-title">WebSocket server</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Public WebSocket URL</div>
|
||||
<div class="field-hint">Clients connect here (behind Nginx)</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="wss://your-host.com:4000" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Socket port</div>
|
||||
<div class="field-hint">Internal Express process port</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="4000" />
|
||||
<span class="control-suffix">TCP</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Heartbeat interval</div>
|
||||
<div class="field-hint">Disconnect clients that miss 2 beats</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="25" />
|
||||
<span class="control-suffix">sec</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Redis</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Redis URL</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="redis://localhost:6379" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Key prefix</div>
|
||||
<div class="field-hint">Prevents collisions on shared Redis</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="ds:" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Buffer flush</div>
|
||||
<div class="field-hint">Trigger CSV write on rows or timer</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="500" placeholder="rows" />
|
||||
<input type="number" class="mono-input" value="2" placeholder="sec" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STORAGE -->
|
||||
<div class="tab-content" id="tab-storage">
|
||||
<div class="section">
|
||||
<div class="section-title">CSV files</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Root path</div>
|
||||
<div class="field-hint">Files written at /{clientId}/{date}.csv</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="/var/datastack/storage" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">File rotation</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<select>
|
||||
<option>Per day</option>
|
||||
<option>Per size</option>
|
||||
<option>Per day + size</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Max file size</div>
|
||||
<div class="field-hint">Rotate file when threshold is hit</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="100" />
|
||||
<span class="control-suffix">MB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Retention</div>
|
||||
<div class="field-hint">Older files auto-deleted by worker</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="30" />
|
||||
<span class="control-suffix">days</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Compress completed files</div>
|
||||
<div class="field-hint">Gzip closed CSV files (saves ~70%)</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<label class="check">
|
||||
<input type="checkbox" checked>
|
||||
<span class="check-box"></span>
|
||||
Enable gzip on rotation
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Schema</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Row format</div>
|
||||
<div class="field-hint">Fixed for version 1.0</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="clientId, eventId, timestamp, payload" readonly />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- SECURITY -->
|
||||
<div class="tab-content" id="tab-security">
|
||||
<div class="section">
|
||||
<div class="section-title">Authentication</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">JWT secret</div>
|
||||
<div class="field-hint">Rotating invalidates all live sessions</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="text" class="mono-input" value="sk_sec_••••••••8f3a" readonly />
|
||||
<button class="btn btn-sm"><svg class="icon icon-sm"><use href="#i-refresh"/></svg>Rotate</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">JWT TTL</div>
|
||||
<div class="field-hint">Clients re-handshake after expiry</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="24" />
|
||||
<span class="control-suffix">hours</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Rate limiting</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Events per second</div>
|
||||
<div class="field-hint">Per-client cap · excess dropped silently</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="100" />
|
||||
<span class="control-suffix">ev/s</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Max payload size</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<div class="control-group">
|
||||
<input type="number" class="mono-input" value="100" />
|
||||
<span class="control-suffix">KB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Allowed origins</div>
|
||||
<div class="field-hint">Comma-separated · * allows all</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="text" class="mono-input" value="*" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Danger zone</div>
|
||||
<div class="danger-zone">
|
||||
<div>
|
||||
<div class="dz-title">Delete all collected data</div>
|
||||
<div class="dz-desc">Permanently removes every CSV file and Redis buffer. Admin config is preserved.</div>
|
||||
</div>
|
||||
<button class="btn btn-danger btn-sm"><svg class="icon icon-sm"><use href="#i-trash"/></svg>Delete data</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- NOTIFICATIONS -->
|
||||
<div class="tab-content" id="tab-notifications">
|
||||
<div class="section">
|
||||
<div class="section-title">Delivery</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Alert email</div>
|
||||
<div class="field-hint">Where critical alerts are sent</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="email" value="admin@example.com" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Webhook URL</div>
|
||||
<div class="field-hint">POST JSON on every event below</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<input type="url" class="mono-input" value="https://hooks.example.com/ds" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-title">Events to notify</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">Client events</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<label class="check"><input type="checkbox" checked><span class="check-box"></span>Client connected</label>
|
||||
<label class="check"><input type="checkbox" checked><span class="check-box"></span>Client disconnected unexpectedly</label>
|
||||
<label class="check"><input type="checkbox"><span class="check-box"></span>New client registered</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="field-label-wrap">
|
||||
<div class="field-label">System events</div>
|
||||
</div>
|
||||
<div class="field-control">
|
||||
<label class="check"><input type="checkbox" checked><span class="check-box"></span>Rate limit hit</label>
|
||||
<label class="check"><input type="checkbox" checked><span class="check-box"></span>CSV write failure</label>
|
||||
<label class="check"><input type="checkbox"><span class="check-box"></span>Export completed</label>
|
||||
<label class="check"><input type="checkbox"><span class="check-box"></span>Daily digest at 00:00</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Save bar -->
|
||||
<div class="save-bar">
|
||||
<div class="save-status">
|
||||
<span class="dot"></span>
|
||||
All changes saved
|
||||
</div>
|
||||
<button class="btn btn-sm">Discard</button>
|
||||
<button class="btn btn-primary btn-sm">Save changes</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="hint">
|
||||
<svg class="icon icon-sm"><use href="#i-info"/></svg>
|
||||
Some settings require a service restart to take effect — restart via systemctl or Docker
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleSidebar(){
|
||||
document.getElementById('sidebar').classList.toggle('open');
|
||||
document.getElementById('overlay').classList.toggle('open');
|
||||
}
|
||||
function toggleTheme(){
|
||||
const html=document.documentElement, icon=document.getElementById('theme-icon');
|
||||
const isDark=html.getAttribute('data-theme')==='dark';
|
||||
html.setAttribute('data-theme',isDark?'light':'dark');
|
||||
icon.innerHTML='<use href="'+(isDark?'#i-moon':'#i-sun')+'"/>';
|
||||
}
|
||||
// Tab switching
|
||||
document.querySelectorAll('.tab').forEach(tab => {
|
||||
tab.addEventListener('click', () => {
|
||||
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
|
||||
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
||||
tab.classList.add('active');
|
||||
document.getElementById('tab-' + tab.dataset.tab).classList.add('active');
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,546 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Console</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0a0a0b;
|
||||
--surface: #111113;
|
||||
--surface-2: #17171a;
|
||||
--surface-3: #1d1d21;
|
||||
--border: #232326;
|
||||
--border-strong: #2e2e33;
|
||||
--text: #e8e8ea;
|
||||
--text-muted: #85858c;
|
||||
--text-faint: #5a5a62;
|
||||
--accent: #a3e635;
|
||||
--accent-soft: rgba(163,230,53,0.08);
|
||||
--accent-text: #a3e635;
|
||||
--font: "Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono: "Consolas","SF Mono","Courier New",monospace;
|
||||
--radius: 0;
|
||||
}
|
||||
[data-theme="light"] {
|
||||
--bg: #fafafa;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #f4f4f5;
|
||||
--surface-3: #ececed;
|
||||
--border: #e2e2e5;
|
||||
--border-strong: #d0d0d3;
|
||||
--text: #111113;
|
||||
--text-muted: #5a5a62;
|
||||
--text-faint: #85858c;
|
||||
--accent: #65a30d;
|
||||
--accent-soft: rgba(101,163,13,0.08);
|
||||
--accent-text: #4d7c0f;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
html, body {
|
||||
background: var(--bg); color: var(--text);
|
||||
font-family: var(--font); font-size: 13px;
|
||||
line-height: 1.5; font-weight: 400;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
a { color: inherit; text-decoration: none; }
|
||||
button { font-family: inherit; cursor: pointer; }
|
||||
.icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
|
||||
.icon-sm { width: 14px; height: 14px; }
|
||||
|
||||
/* ---------- Layout ---------- */
|
||||
.admin {
|
||||
display: grid;
|
||||
grid-template-columns: 208px 1fr;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ---------- Sidebar ---------- */
|
||||
.sidebar {
|
||||
background: var(--surface);
|
||||
border-right: 1px solid var(--border);
|
||||
display: flex; flex-direction: column;
|
||||
height: 100vh; position: sticky; top: 0;
|
||||
z-index: 40;
|
||||
}
|
||||
.sidebar-head {
|
||||
height: 56px; padding: 0 16px;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
border-bottom: 1px solid var(--border);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
|
||||
.brand-mark { width: 14px; height: 14px; background: var(--accent); display: grid; place-items: center; }
|
||||
.brand-mark::after { content: ""; width: 5px; height: 5px; background: var(--bg); }
|
||||
.brand-tag {
|
||||
font-size: 9px; padding: 1px 5px; margin-left: 6px;
|
||||
border: 1px solid var(--border-strong);
|
||||
color: var(--text-faint); letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
|
||||
.nav-section { padding: 0 12px; margin-bottom: 16px; }
|
||||
.nav-label {
|
||||
font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
|
||||
color: var(--text-faint); padding: 4px 8px 6px;
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
}
|
||||
.nav-label .count {
|
||||
background: var(--surface-2); color: var(--text-muted);
|
||||
padding: 0 5px; font-size: 9px; letter-spacing: 0;
|
||||
}
|
||||
.nav-item {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 7px 8px; height: 32px;
|
||||
font-size: 12.5px; color: var(--text-muted);
|
||||
border-left: 2px solid transparent;
|
||||
transition: background 0.12s, color 0.12s;
|
||||
user-select: none;
|
||||
}
|
||||
.nav-item:hover { background: var(--surface-2); color: var(--text); }
|
||||
.nav-item.active {
|
||||
background: var(--surface-2);
|
||||
color: var(--text);
|
||||
border-left-color: var(--accent);
|
||||
}
|
||||
.nav-item.active .icon { color: var(--accent); }
|
||||
|
||||
.sidebar-foot {
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 10px 12px;
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
}
|
||||
.avatar {
|
||||
width: 26px; height: 26px; background: var(--surface-3);
|
||||
border: 1px solid var(--border-strong);
|
||||
display: grid; place-items: center;
|
||||
font-size: 11px; font-weight: 500; color: var(--text);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.user-meta { flex: 1; min-width: 0; }
|
||||
.user-name { font-size: 12px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.user-role { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.5px; }
|
||||
.icon-btn {
|
||||
width: 28px; height: 28px;
|
||||
background: transparent; border: 1px solid var(--border);
|
||||
display: grid; place-items: center;
|
||||
color: var(--text-muted); transition: background 0.12s;
|
||||
}
|
||||
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
|
||||
|
||||
/* ---------- Main ---------- */
|
||||
.admin-main { display: flex; flex-direction: column; min-width: 0; }
|
||||
|
||||
.topbar {
|
||||
height: 56px; padding: 0 24px;
|
||||
background: var(--surface);
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
gap: 16px; position: sticky; top: 0; z-index: 30;
|
||||
}
|
||||
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
||||
.menu-btn { display: none; }
|
||||
.breadcrumb {
|
||||
display: flex; align-items: center; gap: 6px;
|
||||
font-size: 12px; color: var(--text-faint);
|
||||
}
|
||||
.breadcrumb .sep { color: var(--border-strong); }
|
||||
.breadcrumb .current { color: var(--text); font-weight: 400; }
|
||||
|
||||
.topbar-right { display: flex; align-items: center; gap: 8px; }
|
||||
.live-chip {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 4px 9px; border: 1px solid var(--border-strong);
|
||||
font-size: 10px; letter-spacing: 0.5px; text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.live-dot { width: 5px; height: 5px; background: var(--accent); animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.35;} }
|
||||
.theme-toggle { width: 28px; height: 28px; background: transparent; border: 1px solid var(--border); display: grid; place-items: center; color: var(--text-muted); }
|
||||
.theme-toggle:hover { background: var(--surface-2); }
|
||||
|
||||
/* ---------- Content ---------- */
|
||||
.content { padding: 24px; max-width: 1240px; width: 100%; }
|
||||
|
||||
.page-head {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
|
||||
}
|
||||
.page-title { font-size: 17px; font-weight: 500; letter-spacing: -0.2px; }
|
||||
.page-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
|
||||
.page-actions { display: flex; gap: 8px; }
|
||||
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 6px 12px; height: 30px;
|
||||
font-size: 12px; font-weight: 400; font-family: inherit;
|
||||
border: 1px solid var(--border-strong);
|
||||
background: transparent; color: var(--text);
|
||||
transition: background 0.12s, border-color 0.12s;
|
||||
}
|
||||
.btn:hover { background: var(--surface-2); }
|
||||
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
|
||||
.btn-primary:hover { background: #d0d0d3; border-color: #d0d0d3; }
|
||||
.btn-icon { padding: 0; width: 30px; height: 30px; justify-content: center; }
|
||||
|
||||
/* ---------- Stats ---------- */
|
||||
.stats {
|
||||
display: grid; grid-template-columns: repeat(4, 1fr);
|
||||
gap: 12px; margin-bottom: 16px;
|
||||
}
|
||||
.stat {
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
padding: 14px 16px;
|
||||
}
|
||||
.stat-label {
|
||||
font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px;
|
||||
color: var(--text-faint); margin-bottom: 6px;
|
||||
display: flex; align-items: center; gap: 5px;
|
||||
}
|
||||
.stat-value {
|
||||
font-size: 22px; font-weight: 500; letter-spacing: -0.5px;
|
||||
color: var(--text); line-height: 1.1;
|
||||
}
|
||||
.stat-value .unit { font-size: 11px; color: var(--text-muted); font-weight: 400; margin-left: 3px; }
|
||||
.stat-meta { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 11px; color: var(--text-muted); }
|
||||
.delta-pos { color: var(--accent-text); }
|
||||
.delta-neg { color: #f87171; }
|
||||
[data-theme="light"] .delta-neg { color: #dc2626; }
|
||||
|
||||
/* ---------- Two column ---------- */
|
||||
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
|
||||
|
||||
.panel {
|
||||
background: var(--surface); border: 1px solid var(--border);
|
||||
display: flex; flex-direction: column;
|
||||
}
|
||||
.panel-head {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 12px 16px; border-bottom: 1px solid var(--border);
|
||||
gap: 12px;
|
||||
}
|
||||
.panel-title {
|
||||
font-size: 12px; font-weight: 500; color: var(--text);
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
}
|
||||
.panel-title .live-dot { width: 5px; height: 5px; }
|
||||
.panel-meta { font-size: 11px; color: var(--text-faint); }
|
||||
.panel-body { flex: 1; min-height: 0; }
|
||||
.panel-link { font-size: 11px; color: var(--text-muted); border-bottom: 1px solid transparent; }
|
||||
.panel-link:hover { color: var(--text); border-bottom-color: var(--text-muted); }
|
||||
|
||||
/* ---------- Stream ---------- */
|
||||
.stream { font-family: var(--mono); font-size: 11.5px; }
|
||||
.stream-row {
|
||||
display: grid;
|
||||
grid-template-columns: 58px 96px 1fr 44px;
|
||||
gap: 10px; padding: 7px 16px;
|
||||
border-bottom: 1px solid rgba(35,35,38,0.6);
|
||||
align-items: center;
|
||||
}
|
||||
[data-theme="light"] .stream-row { border-bottom-color: var(--border); }
|
||||
.stream-row:last-child { border-bottom: none; }
|
||||
.stream-row .time { color: var(--text-faint); }
|
||||
.stream-row .client { color: var(--accent-text); }
|
||||
.stream-row .payload { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.stream-row .size { text-align: right; color: var(--text-faint); }
|
||||
|
||||
/* ---------- Client list (right col) ---------- */
|
||||
.list-row {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 9px 16px; border-bottom: 1px solid rgba(35,35,38,0.6);
|
||||
gap: 10px;
|
||||
}
|
||||
[data-theme="light"] .list-row { border-bottom-color: var(--border); }
|
||||
.list-row:last-child { border-bottom: none; }
|
||||
.list-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
|
||||
.list-dot { width: 6px; height: 6px; background: var(--accent); flex-shrink: 0; }
|
||||
.list-dot.offline { background: var(--text-faint); }
|
||||
.list-name { font-size: 12px; color: var(--text); }
|
||||
.list-meta { font-size: 11px; color: var(--text-faint); margin-top: 1px; }
|
||||
.list-right { font-size: 11px; color: var(--text-muted); text-align: right; flex-shrink: 0; }
|
||||
.list-right strong { color: var(--text); font-weight: 500; }
|
||||
|
||||
/* ---------- Storage ---------- */
|
||||
.storage { padding: 14px 16px; }
|
||||
.storage-bar {
|
||||
height: 4px; background: var(--surface-3);
|
||||
margin: 8px 0 6px; position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.storage-fill { height: 100%; background: var(--accent); width: 34%; }
|
||||
.storage-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); }
|
||||
.storage-labels span:last-child { color: var(--text-faint); }
|
||||
|
||||
/* ---------- Mobile ---------- */
|
||||
.overlay {
|
||||
display: none; position: fixed; inset: 0;
|
||||
background: rgba(0,0,0,0.55); z-index: 35;
|
||||
}
|
||||
.overlay.open { display: block; }
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.admin { grid-template-columns: 1fr; }
|
||||
.sidebar {
|
||||
position: fixed; top: 0; left: 0;
|
||||
width: 220px; transform: translateX(-100%);
|
||||
transition: transform 0.2s ease-out;
|
||||
}
|
||||
.sidebar.open { transform: translateX(0); }
|
||||
.menu-btn { display: grid; }
|
||||
.stats { grid-template-columns: repeat(2, 1fr); }
|
||||
.grid-2 { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.content { padding: 16px; }
|
||||
.topbar { padding: 0 16px; }
|
||||
.stats { gap: 8px; }
|
||||
.stat { padding: 12px; }
|
||||
.stat-value { font-size: 18px; }
|
||||
.live-chip { display: none; }
|
||||
.breadcrumb .sep, .breadcrumb .root { display: none; }
|
||||
.stream-row { grid-template-columns: 50px 80px 1fr; padding: 6px 12px; font-size: 10.5px; }
|
||||
.stream-row .size { display: none; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<!-- SVG sprite -->
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-grid" viewBox="0 0 16 16"><rect x="2.5" y="2.5" width="4.5" height="4.5"/><rect x="9" y="2.5" width="4.5" height="4.5"/><rect x="2.5" y="9" width="4.5" height="4.5"/><rect x="9" y="9" width="4.5" height="4.5"/></symbol>
|
||||
<symbol id="i-db" viewBox="0 0 16 16"><ellipse cx="8" cy="4" rx="5.5" ry="2"/><path d="M2.5 4v8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2V4"/><path d="M2.5 8c0 1.1 2.5 2 5.5 2s5.5-.9 5.5-2"/></symbol>
|
||||
<symbol id="i-users" viewBox="0 0 16 16"><circle cx="6" cy="6" r="2.5"/><path d="M1.5 13.5c0-2.2 2-3.5 4.5-3.5s4.5 1.3 4.5 3.5"/><path d="M11 3.5a2.5 2.5 0 0 1 0 5"/><path d="M12.5 10c1.4.4 2.5 1.4 2.5 3.5"/></symbol>
|
||||
<symbol id="i-download" viewBox="0 0 16 16"><path d="M8 2v8"/><path d="M4.5 6.5 8 10l3.5-3.5"/><path d="M2.5 13.5h11"/></symbol>
|
||||
<symbol id="i-settings" viewBox="0 0 16 16"><circle cx="8" cy="8" r="2.2"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.5 3.5l1.4 1.4M11.1 11.1l1.4 1.4M3.5 12.5l1.4-1.4M11.1 4.9l1.4-1.4"/></symbol>
|
||||
<symbol id="i-list" viewBox="0 0 16 16"><path d="M3 4h10M3 8h10M3 12h7"/></symbol>
|
||||
<symbol id="i-book" viewBox="0 0 16 16"><path d="M3 2.5h7.5c1 0 1.5.5 1.5 1.5v10H4.5c-1 0-1.5-.5-1.5-1.5V2.5Z"/><path d="M3 12.5c0-1 .5-1.5 1.5-1.5H12"/></symbol>
|
||||
<symbol id="i-menu" viewBox="0 0 16 16"><path d="M2.5 4h11M2.5 8h11M2.5 12h11"/></symbol>
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-refresh" viewBox="0 0 16 16"><path d="M13.5 8a5.5 5.5 0 1 1-1.6-3.9"/><path d="M13.5 2.5v3.5H10"/></symbol>
|
||||
<symbol id="i-plus" viewBox="0 0 16 16"><path d="M8 3v10M3 8h10"/></symbol>
|
||||
<symbol id="i-bell" viewBox="0 0 16 16"><path d="M4 11V7a4 4 0 0 1 8 0v4l1 1.5H3L4 11Z"/><path d="M6.5 13.5a1.5 1.5 0 0 0 3 0"/></symbol>
|
||||
<symbol id="i-arrow-r" viewBox="0 0 16 16"><path d="M6 4l4 4-4 4"/></symbol>
|
||||
</svg>
|
||||
|
||||
<div class="admin">
|
||||
|
||||
<!-- SIDEBAR (FROZEN STANDARD) -->
|
||||
<aside class="sidebar" id="sidebar">
|
||||
<div class="sidebar-head">
|
||||
<a href="/" class="brand">
|
||||
<span class="brand-mark"></span>
|
||||
DataStack
|
||||
<span class="brand-tag">CONSOLE</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<nav class="sidebar-nav">
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">Main</div>
|
||||
<a href="/vcon/dashboard" class="nav-item active">
|
||||
<svg class="icon"><use href="#i-grid"/></svg>
|
||||
Dashboard
|
||||
</a>
|
||||
<a href="/vcon/data" class="nav-item">
|
||||
<svg class="icon"><use href="#i-db"/></svg>
|
||||
Data
|
||||
</a>
|
||||
<a href="/vcon/clients" class="nav-item">
|
||||
<svg class="icon"><use href="#i-users"/></svg>
|
||||
Clients
|
||||
</a>
|
||||
<a href="/vcon/export" class="nav-item">
|
||||
<svg class="icon"><use href="#i-download"/></svg>
|
||||
Export
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="nav-section">
|
||||
<div class="nav-label">System <span class="count">3</span></div>
|
||||
<a href="/vcon/logs" class="nav-item">
|
||||
<svg class="icon"><use href="#i-list"/></svg>
|
||||
Logs
|
||||
</a>
|
||||
<a href="/vcon/settings" class="nav-item">
|
||||
<svg class="icon"><use href="#i-settings"/></svg>
|
||||
Settings
|
||||
</a>
|
||||
<a href="/docs" class="nav-item">
|
||||
<svg class="icon"><use href="#i-book"/></svg>
|
||||
Docs
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="sidebar-foot">
|
||||
<div class="avatar">A</div>
|
||||
<div class="user-meta">
|
||||
<div class="user-name">Admin</div>
|
||||
<div class="user-role">Owner</div>
|
||||
</div>
|
||||
<button class="icon-btn" title="Settings">
|
||||
<svg class="icon icon-sm"><use href="#i-settings"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<div class="overlay" id="overlay" onclick="toggleSidebar()"></div>
|
||||
|
||||
<!-- MAIN -->
|
||||
<main class="admin-main">
|
||||
|
||||
<!-- TOPBAR -->
|
||||
<header class="topbar">
|
||||
<div class="topbar-left">
|
||||
<button class="icon-btn menu-btn" onclick="toggleSidebar()">
|
||||
<svg class="icon icon-sm"><use href="#i-menu"/></svg>
|
||||
</button>
|
||||
<div class="breadcrumb">
|
||||
<span class="root">Console</span>
|
||||
<span class="sep">/</span>
|
||||
<span class="current">Dashboard</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<span class="live-chip"><span class="live-dot"></span>Live · 1,284 ev/min</span>
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
<button class="icon-btn" title="Notifications">
|
||||
<svg class="icon icon-sm"><use href="#i-bell"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<!-- CONTENT -->
|
||||
<div class="content">
|
||||
|
||||
<div class="page-head">
|
||||
<div>
|
||||
<h1 class="page-title">Dashboard</h1>
|
||||
<div class="page-sub">Last 24 hours · UTC</div>
|
||||
</div>
|
||||
<div class="page-actions">
|
||||
<button class="btn btn-icon" title="Refresh">
|
||||
<svg class="icon icon-sm"><use href="#i-refresh"/></svg>
|
||||
</button>
|
||||
<button class="btn btn-primary">
|
||||
<svg class="icon icon-sm"><use href="#i-plus"/></svg>
|
||||
New client
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- STATS -->
|
||||
<div class="stats">
|
||||
<div class="stat">
|
||||
<div class="stat-label">Events today</div>
|
||||
<div class="stat-value">42,891</div>
|
||||
<div class="stat-meta"><span class="delta-pos">+12.4%</span> vs yesterday</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">Clients online</div>
|
||||
<div class="stat-value">8<span class="unit">/ 12</span></div>
|
||||
<div class="stat-meta">4 offline · 2 pending</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">Storage used</div>
|
||||
<div class="stat-value">18.2<span class="unit">MB</span></div>
|
||||
<div class="stat-meta">3 CSV files · today</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div class="stat-label">Last export</div>
|
||||
<div class="stat-value">2h<span class="unit">ago</span></div>
|
||||
<div class="stat-meta">2026-10-23 · CSV · 4,120 rows</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- GRID -->
|
||||
<div class="grid-2">
|
||||
|
||||
<!-- LIVE STREAM -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title"><span class="live-dot"></span>Live ingestion</div>
|
||||
<div style="display:flex;align-items:center;gap:14px">
|
||||
<span class="panel-meta">1,284 ev/min</span>
|
||||
<a href="/vcon/data" class="panel-link">View all →</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-body stream">
|
||||
<div class="stream-row"><span class="time">14:28:01</span><span class="client">py-client-01</span><span class="payload">{ sensor: "temp", value: 22.4 }</span><span class="size">42B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:01</span><span class="client">py-client-02</span><span class="payload">{ user: "u_8291", action: "click" }</span><span class="size">38B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:02</span><span class="client">py-client-01</span><span class="payload">{ sensor: "humidity", value: 61 }</span><span class="size">40B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:02</span><span class="client">py-client-03</span><span class="payload">{ order_id: "A-2041", status: "shipped" }</span><span class="size">44B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:03</span><span class="client">py-client-02</span><span class="payload">{ user: "u_1840", action: "view" }</span><span class="size">36B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:03</span><span class="client">py-client-01</span><span class="payload">{ sensor: "temp", value: 22.6 }</span><span class="size">42B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:04</span><span class="client">py-client-04</span><span class="payload">{ device: "d_01", battery: 87 }</span><span class="size">40B</span></div>
|
||||
<div class="stream-row"><span class="time">14:28:04</span><span class="client">py-client-02</span><span class="payload">{ user: "u_9903", action: "purchase" }</span><span class="size">42B</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- RIGHT COLUMN -->
|
||||
<div style="display:flex;flex-direction:column;gap:12px">
|
||||
|
||||
<!-- Active clients -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title">Active clients</div>
|
||||
<a href="/vcon/clients" class="panel-link">All →</a>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="list-row">
|
||||
<div class="list-left"><span class="list-dot"></span><div><div class="list-name">py-client-01</div><div class="list-meta">sensors-app</div></div></div>
|
||||
<div class="list-right"><strong>18.4k</strong></div>
|
||||
</div>
|
||||
<div class="list-row">
|
||||
<div class="list-left"><span class="list-dot"></span><div><div class="list-name">py-client-02</div><div class="list-meta">web-analytics</div></div></div>
|
||||
<div class="list-right"><strong>12.1k</strong></div>
|
||||
</div>
|
||||
<div class="list-row">
|
||||
<div class="list-left"><span class="list-dot"></span><div><div class="list-name">py-client-03</div><div class="list-meta">orders-sync</div></div></div>
|
||||
<div class="list-right"><strong>8.2k</strong></div>
|
||||
</div>
|
||||
<div class="list-row">
|
||||
<div class="list-left"><span class="list-dot offline"></span><div><div class="list-name">py-client-05</div><div class="list-meta">staging-test</div></div></div>
|
||||
<div class="list-right">offline</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Storage -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<div class="panel-title">Storage</div>
|
||||
<span class="panel-meta">34% of 50 GB</span>
|
||||
</div>
|
||||
<div class="storage">
|
||||
<div class="storage-bar"><div class="storage-fill"></div></div>
|
||||
<div class="storage-labels"><span>18.2 GB used</span><span>31.8 GB free</span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleSidebar() {
|
||||
document.getElementById('sidebar').classList.toggle('open');
|
||||
document.getElementById('overlay').classList.toggle('open');
|
||||
}
|
||||
function toggleTheme() {
|
||||
const html = document.documentElement;
|
||||
const icon = document.getElementById('theme-icon');
|
||||
const isDark = html.getAttribute('data-theme') === 'dark';
|
||||
html.setAttribute('data-theme', isDark ? 'light' : 'dark');
|
||||
icon.innerHTML = '<use href="' + (isDark ? '#i-moon' : '#i-sun') + '"/>';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,290 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Self-hosted realtime data collection</title>
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0a0a0b;
|
||||
--surface: #111113;
|
||||
--surface-2: #17171a;
|
||||
--border: #232326;
|
||||
--border-strong: #2e2e33;
|
||||
--text: #e8e8ea;
|
||||
--text-muted: #85858c;
|
||||
--text-faint: #5a5a62;
|
||||
--accent: #a3e635;
|
||||
--accent-soft: rgba(163,230,53,0.08);
|
||||
--font: "Segoe UI", "Segoe UI Web", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
|
||||
--radius: 0rem;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
html, body {
|
||||
background: var(--bg); color: var(--text);
|
||||
font-family: var(--font); font-size: 14px;
|
||||
line-height: 1.5; font-weight: 400;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
a { color: inherit; text-decoration: none; }
|
||||
.container { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
|
||||
|
||||
/* Nav */
|
||||
.nav {
|
||||
position: sticky; top: 0; z-index: 50;
|
||||
background: rgba(10,10,11,0.85);
|
||||
backdrop-filter: blur(8px);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.nav-inner {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
height: 56px;
|
||||
}
|
||||
.brand { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; }
|
||||
.brand-mark { width: 16px; height: 16px; background: var(--accent); display: grid; place-items: center; }
|
||||
.brand-mark::after { content: ""; width: 6px; height: 6px; background: var(--bg); }
|
||||
.nav-links { display: flex; align-items: center; gap: 24px; font-size: 13px; color: var(--text-muted); }
|
||||
.nav-links a:hover { color: var(--text); }
|
||||
.nav-cta { display: flex; align-items: center; gap: 8px; }
|
||||
|
||||
.btn {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 7px 14px; font-size: 13px; font-weight: 400;
|
||||
border: 1px solid var(--border-strong);
|
||||
background: transparent; color: var(--text);
|
||||
cursor: pointer; transition: background 0.15s, border-color 0.15s;
|
||||
font-family: inherit; border-radius: var(--radius);
|
||||
}
|
||||
.btn:hover { background: var(--surface-2); border-color: var(--text-faint); }
|
||||
.btn-primary { background: var(--text); color: var(--bg); border-color: var(--text); }
|
||||
.btn-primary:hover { background: #d0d0d3; border-color: #d0d0d3; }
|
||||
.btn-sm { padding: 5px 10px; font-size: 12px; }
|
||||
|
||||
/* Hero */
|
||||
.hero { padding: 56px 0 40px; border-bottom: 1px solid var(--border); }
|
||||
.status-pill {
|
||||
display: inline-flex; align-items: center; gap: 6px;
|
||||
padding: 3px 10px; border: 1px solid var(--border-strong);
|
||||
font-size: 11px; color: var(--text-muted);
|
||||
letter-spacing: 0.3px; text-transform: uppercase;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.status-dot { width: 6px; height: 6px; background: var(--accent); animation: pulse 2s infinite; }
|
||||
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:0.4;} }
|
||||
|
||||
.hero h1 {
|
||||
font-size: 36px; font-weight: 500; letter-spacing: -0.5px;
|
||||
line-height: 1.2; margin-bottom: 16px; max-width: 640px;
|
||||
}
|
||||
.hero h1 span { color: var(--text-muted); }
|
||||
.hero p { font-size: 15px; color: var(--text-muted); max-width: 520px; margin-bottom: 24px; line-height: 1.6; }
|
||||
.hero-ctas { display: flex; gap: 8px; flex-wrap: wrap; }
|
||||
|
||||
/* Live preview */
|
||||
.preview { margin-top: 32px; border: 1px solid var(--border); background: var(--surface); }
|
||||
.preview-head {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
padding: 10px 14px; border-bottom: 1px solid var(--border);
|
||||
font-size: 12px; color: var(--text-muted);
|
||||
}
|
||||
.preview-head-left { display: flex; align-items: center; gap: 8px; }
|
||||
.live-dot { width: 6px; height: 6px; background: var(--accent); animation: pulse 2s infinite; }
|
||||
.preview-body { padding: 4px 0; font-family: "Consolas","Courier New",monospace; font-size: 12px; }
|
||||
.row {
|
||||
display: grid; grid-template-columns: 70px 100px 1fr 60px;
|
||||
gap: 12px; padding: 6px 14px;
|
||||
border-bottom: 1px solid rgba(35,35,38,0.5);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.row:last-child { border-bottom: none; }
|
||||
.row .time { color: var(--text-faint); }
|
||||
.row .client { color: var(--accent); }
|
||||
.row .payload { color: var(--text); }
|
||||
.row .size { text-align: right; color: var(--text-faint); }
|
||||
|
||||
/* Sections */
|
||||
.section { padding: 40px 0; border-bottom: 1px solid var(--border); }
|
||||
.section-head {
|
||||
display: flex; align-items: baseline; justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.section-head h2 { font-size: 16px; font-weight: 500; letter-spacing: -0.2px; }
|
||||
.section-head .num { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.5px; }
|
||||
|
||||
/* Features */
|
||||
.features {
|
||||
display: grid; grid-template-columns: repeat(3, 1fr);
|
||||
gap: 1px; background: var(--border); border: 1px solid var(--border);
|
||||
}
|
||||
.feature { background: var(--surface); padding: 20px; }
|
||||
.feature .icon {
|
||||
width: 22px; height: 22px; border: 1px solid var(--border-strong);
|
||||
display: grid; place-items: center; margin-bottom: 12px;
|
||||
color: var(--accent); font-size: 12px;
|
||||
}
|
||||
.feature h3 { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
|
||||
.feature p { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
|
||||
|
||||
/* Code */
|
||||
.code-wrap {
|
||||
display: grid; grid-template-columns: 1fr 1fr;
|
||||
gap: 1px; background: var(--border); border: 1px solid var(--border);
|
||||
}
|
||||
.code-block {
|
||||
background: var(--surface); padding: 16px 18px;
|
||||
font-family: "Consolas","Courier New",monospace;
|
||||
font-size: 12px; line-height: 1.7; overflow-x: auto; color: var(--text-muted);
|
||||
}
|
||||
.code-block .comment { color: var(--text-faint); }
|
||||
.code-block .kw { color: var(--text); }
|
||||
.code-block .str { color: var(--accent); }
|
||||
.code-block .fn { color: var(--text); }
|
||||
.code-desc { background: var(--surface); padding: 20px; }
|
||||
.code-desc .label {
|
||||
font-size: 11px; color: var(--text-faint);
|
||||
text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px;
|
||||
}
|
||||
.code-desc h3 { font-size: 14px; font-weight: 500; margin-bottom: 8px; }
|
||||
.code-desc p { font-size: 12px; color: var(--text-muted); line-height: 1.6; }
|
||||
|
||||
/* Bottom CTA */
|
||||
.cta-bottom {
|
||||
padding: 40px 0; display: flex; align-items: center;
|
||||
justify-content: space-between; gap: 24px; flex-wrap: wrap;
|
||||
}
|
||||
.cta-bottom h2 { font-size: 20px; font-weight: 500; letter-spacing: -0.3px; margin-bottom: 4px; }
|
||||
.cta-bottom p { font-size: 13px; color: var(--text-muted); }
|
||||
|
||||
/* Footer */
|
||||
.footer { border-top: 1px solid var(--border); padding: 24px 0; }
|
||||
.footer-inner {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-faint);
|
||||
}
|
||||
.footer-links { display: flex; gap: 20px; }
|
||||
.footer-links a:hover { color: var(--text-muted); }
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 800px) {
|
||||
.hero h1 { font-size: 26px; }
|
||||
.features { grid-template-columns: 1fr; }
|
||||
.code-wrap { grid-template-columns: 1fr; }
|
||||
.nav-links { display: none; }
|
||||
.row { grid-template-columns: 55px 80px 1fr 50px; font-size: 11px; gap: 8px; padding: 6px 10px; }
|
||||
.cta-bottom { flex-direction: column; align-items: flex-start; }
|
||||
.preview-body { font-size: 11px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="nav">
|
||||
<div class="container nav-inner">
|
||||
<a href="/" class="brand"><span class="brand-mark"></span>DataStack</a>
|
||||
<div class="nav-links">
|
||||
<a href="#features">Features</a>
|
||||
<a href="#sdk">SDK</a>
|
||||
<a href="#docs">Docs</a>
|
||||
</div>
|
||||
<div class="nav-cta">
|
||||
<a href="/vcon/" class="btn btn-sm">Sign in</a>
|
||||
<a href="/vcon/" class="btn btn-primary btn-sm">Open Console</a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section class="hero">
|
||||
<div class="container">
|
||||
<span class="status-pill"><span class="status-dot"></span>Self-hosted · v1.0</span>
|
||||
<h1>Realtime data collection,<br><span>without the database overhead.</span></h1>
|
||||
<p>Stream events from any client over WebSocket. Store them compactly as CSV. Query, monitor and export — all from one lightweight portal.</p>
|
||||
<div class="hero-ctas">
|
||||
<a href="/vcon/" class="btn btn-primary">Open Console</a>
|
||||
<a href="#sdk" class="btn">Read the Docs →</a>
|
||||
</div>
|
||||
|
||||
<div class="preview">
|
||||
<div class="preview-head">
|
||||
<div class="preview-head-left"><span class="live-dot"></span><span>Live ingestion stream</span></div>
|
||||
<span>1,284 events / min</span>
|
||||
</div>
|
||||
<div class="preview-body">
|
||||
<div class="row"><span class="time">14:28:01</span><span class="client">py-client-01</span><span class="payload">{ sensor: "temp", value: 22.4 }</span><span class="size">42 B</span></div>
|
||||
<div class="row"><span class="time">14:28:01</span><span class="client">py-client-02</span><span class="payload">{ user: "u_8291", action: "click" }</span><span class="size">38 B</span></div>
|
||||
<div class="row"><span class="time">14:28:02</span><span class="client">py-client-01</span><span class="payload">{ sensor: "humidity", value: 61 }</span><span class="size">40 B</span></div>
|
||||
<div class="row"><span class="time">14:28:02</span><span class="client">py-client-03</span><span class="payload">{ order_id: "A-2041", status: "shipped" }</span><span class="size">44 B</span></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section" id="features">
|
||||
<div class="container">
|
||||
<div class="section-head">
|
||||
<h2>Built for ingestion at scale.</h2>
|
||||
<span class="num">01 — Features</span>
|
||||
</div>
|
||||
<div class="features">
|
||||
<div class="feature"><div class="icon">⚡</div><h3>Realtime over WebSocket</h3><p>Durable Socket.IO connections. No polling, no repeated API calls.</p></div>
|
||||
<div class="feature"><div class="icon">▤</div><h3>CSV-first storage</h3><p>Compact per-day rotation. Minimal database load, easy to export.</p></div>
|
||||
<div class="feature"><div class="icon">⚿</div><h3>JWT authentication</h3><p>Every SDK client verified before a single byte is accepted.</p></div>
|
||||
<div class="feature"><div class="icon">◈</div><h3>Redis buffer & cache</h3><p>Batch writes to disk. Pub/Sub ready for horizontal scale-out.</p></div>
|
||||
<div class="feature"><div class="icon">◐</div><h3>Live dashboard</h3><p>Watch events arrive in real time. Filter by client, date or payload.</p></div>
|
||||
<div class="feature"><div class="icon">⇩</div><h3>One-click export</h3><p>Download filtered ranges as CSV or JSON. Streaming, not blocking.</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section" id="sdk">
|
||||
<div class="container">
|
||||
<div class="section-head">
|
||||
<h2>Drop in the SDK. Start streaming.</h2>
|
||||
<span class="num">02 — Python SDK</span>
|
||||
</div>
|
||||
<div class="code-wrap">
|
||||
<div class="code-block"><span class="comment"># pip install datastack-sdk</span>
|
||||
<span class="kw">from</span> datastack <span class="kw">import</span> Client
|
||||
|
||||
client = Client(
|
||||
url=<span class="str">"wss://your-host:4000"</span>,
|
||||
api_key=<span class="str">"sk_live_..."</span>
|
||||
)
|
||||
|
||||
client.connect()
|
||||
|
||||
<span class="kw">while</span> running:
|
||||
client.send({
|
||||
<span class="str">"sensor"</span>: <span class="str">"temp"</span>,
|
||||
<span class="str">"value"</span>: <span class="fn">22.4</span>
|
||||
})</div>
|
||||
<div class="code-desc">
|
||||
<div class="label">How it works</div>
|
||||
<h3>A single line to send data.</h3>
|
||||
<p>The SDK holds a durable WebSocket connection, auto-reconnects on network drops, and batches events under backpressure. The server verifies your JWT, buffers events in Redis, and appends them to a per-client CSV file.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="container">
|
||||
<div class="cta-bottom">
|
||||
<div>
|
||||
<h2>Ready to self-host?</h2>
|
||||
<p>Deploy with Docker in minutes. Full source, no vendor lock-in.</p>
|
||||
</div>
|
||||
<div class="hero-ctas">
|
||||
<a href="/vcon/" class="btn btn-primary">Open Console</a>
|
||||
<a href="#docs" class="btn">View Docs</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container footer-inner">
|
||||
<span>© 2026 DataStack · Self-hosted</span>
|
||||
<div class="footer-links"><a href="#">GitHub</a><a href="#">Docs</a><a href="#">Status</a></div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,293 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>DataStack — Sign in</title>
|
||||
<style>
|
||||
:root{
|
||||
--bg:#0a0a0b;--surface:#111113;--surface-2:#17171a;--surface-3:#1d1d21;
|
||||
--border:#232326;--border-strong:#2e2e33;
|
||||
--text:#e8e8ea;--text-muted:#85858c;--text-faint:#5a5a62;
|
||||
--accent:#a3e635;--accent-text:#a3e635;
|
||||
--danger:#f87171;
|
||||
--font:"Segoe UI","Segoe UI Web",system-ui,-apple-system,"Helvetica Neue",Arial,sans-serif;
|
||||
--mono:"Consolas","SF Mono","Courier New",monospace;
|
||||
--radius:0;
|
||||
}
|
||||
[data-theme="light"]{
|
||||
--bg:#fafafa;--surface:#fff;--surface-2:#f4f4f5;--surface-3:#ececed;
|
||||
--border:#e2e2e5;--border-strong:#d0d0d3;
|
||||
--text:#111113;--text-muted:#5a5a62;--text-faint:#85858c;
|
||||
--accent:#65a30d;--accent-text:#4d7c0f;
|
||||
--danger:#dc2626;
|
||||
}
|
||||
*{box-sizing:border-box;margin:0;padding:0}
|
||||
html,body{background:var(--bg);color:var(--text);font-family:var(--font);
|
||||
font-size:13px;line-height:1.5;font-weight:400;-webkit-font-smoothing:antialiased;
|
||||
min-height:100vh}
|
||||
a{color:inherit;text-decoration:none}
|
||||
button,input{font-family:inherit;font-size:inherit;color:inherit}
|
||||
button{cursor:pointer}
|
||||
.icon{width:16px;height:16px;stroke:currentColor;fill:none;stroke-width:1.5;
|
||||
stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
|
||||
.icon-sm{width:14px;height:14px}
|
||||
|
||||
/* Page shell */
|
||||
.page{min-height:100vh;display:grid;place-items:center;padding:24px;position:relative}
|
||||
.page::before{content:"";position:absolute;inset:0;
|
||||
background-image:
|
||||
linear-gradient(var(--border) 1px,transparent 1px),
|
||||
linear-gradient(90deg,var(--border) 1px,transparent 1px);
|
||||
background-size:64px 64px;opacity:.14;pointer-events:none;
|
||||
mask-image:radial-gradient(ellipse at center,black 30%,transparent 75%);
|
||||
-webkit-mask-image:radial-gradient(ellipse at center,black 30%,transparent 75%)}
|
||||
|
||||
/* Theme toggle — top right */
|
||||
.theme-toggle{position:fixed;top:16px;right:16px;width:28px;height:28px;
|
||||
background:transparent;border:1px solid var(--border);display:grid;place-items:center;
|
||||
color:var(--text-muted);transition:background .12s;z-index:10}
|
||||
.theme-toggle:hover{background:var(--surface-2);color:var(--text)}
|
||||
|
||||
/* Card */
|
||||
.card{background:var(--surface);border:1px solid var(--border);
|
||||
width:100%;max-width:340px;position:relative;z-index:1}
|
||||
|
||||
/* Card head */
|
||||
.card-head{padding:20px 20px 16px;border-bottom:1px solid var(--border);
|
||||
display:flex;flex-direction:column;gap:14px}
|
||||
.brand{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:500}
|
||||
.brand-mark{width:14px;height:14px;background:var(--accent);display:grid;place-items:center}
|
||||
.brand-mark::after{content:"";width:5px;height:5px;background:var(--bg)}
|
||||
.brand-tag{font-size:9px;padding:1px 5px;margin-left:6px;
|
||||
border:1px solid var(--border-strong);color:var(--text-faint);letter-spacing:.5px}
|
||||
.card-title{font-size:15px;font-weight:500;letter-spacing:-.2px}
|
||||
.card-sub{font-size:12px;color:var(--text-muted);margin-top:2px}
|
||||
|
||||
/* Card body */
|
||||
.card-body{padding:16px 20px 20px;display:flex;flex-direction:column;gap:12px}
|
||||
|
||||
/* Error bar */
|
||||
.error-bar{display:none;align-items:flex-start;gap:7px;
|
||||
padding:8px 10px;border:1px solid var(--danger);
|
||||
background:rgba(248,113,113,.06);font-size:11.5px;color:var(--danger);line-height:1.5}
|
||||
.error-bar.show{display:flex}
|
||||
.error-bar .icon{margin-top:1px}
|
||||
[data-theme="light"] .error-bar{background:rgba(220,38,38,.05)}
|
||||
|
||||
/* Field */
|
||||
.field{display:flex;flex-direction:column;gap:5px}
|
||||
.field-label{font-size:10px;text-transform:uppercase;letter-spacing:.6px;
|
||||
color:var(--text-faint)}
|
||||
.field-wrap{position:relative;display:flex;align-items:stretch}
|
||||
.field input{width:100%;height:32px;padding:0 10px;
|
||||
background:var(--bg);border:1px solid var(--border);outline:none;
|
||||
font-size:12.5px;color:var(--text);transition:border-color .12s,background .12s}
|
||||
.field input::placeholder{color:var(--text-faint)}
|
||||
.field input:focus{border-color:var(--border-strong)}
|
||||
.field input.error{border-color:var(--danger)}
|
||||
.field .toggle-pw{position:absolute;right:0;top:0;height:32px;width:32px;
|
||||
background:transparent;border:none;border-left:1px solid var(--border);
|
||||
display:grid;place-items:center;color:var(--text-faint);transition:color .12s}
|
||||
.field .toggle-pw:hover{color:var(--text)}
|
||||
.field input.has-toggle{padding-right:38px}
|
||||
|
||||
/* Meta row */
|
||||
.meta-row{display:flex;align-items:center;justify-content:space-between;
|
||||
font-size:11.5px;margin-top:2px}
|
||||
.check{display:flex;align-items:center;gap:7px;color:var(--text-muted);
|
||||
cursor:pointer;user-select:none}
|
||||
.check input{display:none}
|
||||
.check-box{width:13px;height:13px;border:1px solid var(--border-strong);
|
||||
flex-shrink:0;position:relative;transition:background .12s,border-color .12s}
|
||||
.check-box::after{content:"";position:absolute;left:3.5px;top:1.5px;width:4.5px;height:8px;
|
||||
border-right:1.5px solid var(--bg);border-bottom:1.5px solid var(--bg);
|
||||
transform:rotate(45deg);opacity:0}
|
||||
.check input:checked + .check-box{background:var(--accent);border-color:var(--accent)}
|
||||
.check input:checked + .check-box::after{opacity:1}
|
||||
.forgot{color:var(--text-muted);font-size:11.5px}
|
||||
.forgot:hover{color:var(--text);text-decoration:underline;text-underline-offset:2px}
|
||||
|
||||
/* Submit */
|
||||
.btn-submit{width:100%;height:34px;margin-top:4px;
|
||||
background:var(--text);color:var(--bg);border:1px solid var(--text);
|
||||
font-size:12.5px;font-weight:500;display:flex;align-items:center;
|
||||
justify-content:center;gap:6px;transition:background .12s,border-color .12s}
|
||||
.btn-submit:hover{background:#d0d0d3;border-color:#d0d0d3}
|
||||
.btn-submit:disabled{opacity:.7;cursor:not-allowed}
|
||||
.btn-submit .spinner{width:12px;height:12px;border:1.5px solid currentColor;
|
||||
border-top-color:transparent;border-radius:50%;animation:spin .7s linear infinite}
|
||||
@keyframes spin{to{transform:rotate(360deg)}}
|
||||
|
||||
/* Divider */
|
||||
.divider{display:flex;align-items:center;gap:10px;font-size:10px;
|
||||
text-transform:uppercase;letter-spacing:.8px;color:var(--text-faint);margin:2px 0}
|
||||
.divider::before,.divider::after{content:"";flex:1;height:1px;background:var(--border)}
|
||||
|
||||
/* Alt action */
|
||||
.btn-alt{width:100%;height:32px;
|
||||
background:transparent;color:var(--text);border:1px solid var(--border-strong);
|
||||
font-size:12px;display:flex;align-items:center;justify-content:center;gap:6px;
|
||||
transition:background .12s}
|
||||
.btn-alt:hover{background:var(--surface-2)}
|
||||
|
||||
/* Card foot */
|
||||
.card-foot{padding:10px 20px;border-top:1px solid var(--border);
|
||||
display:flex;align-items:center;justify-content:space-between;
|
||||
font-size:10.5px;color:var(--text-faint)}
|
||||
.card-foot .dot{width:5px;height:5px;background:var(--accent);display:inline-block;
|
||||
margin-right:5px;vertical-align:middle}
|
||||
|
||||
/* Page footer */
|
||||
.page-foot{position:fixed;bottom:16px;left:0;right:0;text-align:center;
|
||||
font-size:10.5px;color:var(--text-faint);letter-spacing:.3px;
|
||||
display:flex;align-items:center;justify-content:center;gap:6px;z-index:1}
|
||||
.page-foot .sep{color:var(--border-strong)}
|
||||
.page-foot a:hover{color:var(--text-muted)}
|
||||
|
||||
@media (max-width:480px){
|
||||
.page{padding:16px}
|
||||
.card-head{padding:16px 16px 14px}
|
||||
.card-body{padding:14px 16px 16px}
|
||||
.card-foot{padding:9px 16px}
|
||||
.page-foot{bottom:10px;font-size:10px}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<svg width="0" height="0" style="position:absolute">
|
||||
<symbol id="i-sun" viewBox="0 0 16 16"><circle cx="8" cy="8" r="3"/><path d="M8 1.5v1.5M8 13v1.5M1.5 8H3M13 8h1.5M3.5 3.5l1 1M11.5 11.5l1 1M3.5 12.5l1-1M11.5 4.5l1-1"/></symbol>
|
||||
<symbol id="i-moon" viewBox="0 0 16 16"><path d="M13.5 10A6 6 0 1 1 6 2.5c-.3 0-.5 0-.7.1a5.5 5.5 0 0 0 8.2 7.4Z"/></symbol>
|
||||
<symbol id="i-eye" viewBox="0 0 16 16"><path d="M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8Z"/><circle cx="8" cy="8" r="2"/></symbol>
|
||||
<symbol id="i-eye-off" viewBox="0 0 16 16"><path d="M2 2l12 12"/><path d="M6.5 6.5a2 2 0 0 0 2.9 2.9"/><path d="M4 4.3C2.5 5.5 1.5 8 1.5 8s2.5 4.5 6.5 4.5c1 0 1.9-.3 2.7-.7"/><path d="M6.5 3.7A6.3 6.3 0 0 1 8 3.5c4 0 6.5 4.5 6.5 4.5s-.6 1.1-1.7 2.2"/></symbol>
|
||||
<symbol id="i-alert" viewBox="0 0 16 16"><circle cx="8" cy="8" r="6"/><path d="M8 4.5v4"/><circle cx="8" cy="11" r=".7" fill="currentColor"/></symbol>
|
||||
<symbol id="i-key" viewBox="0 0 16 16"><circle cx="5.5" cy="10.5" r="3"/><path d="M7.7 8.3 13 3M11 5l2 2M12 4l2 2"/></symbol>
|
||||
<symbol id="i-arrow" viewBox="0 0 16 16"><path d="M3 8h10M9 4l4 4-4 4"/></symbol>
|
||||
</svg>
|
||||
|
||||
<button class="theme-toggle" onclick="toggleTheme()" title="Toggle theme">
|
||||
<svg class="icon icon-sm" id="theme-icon"><use href="#i-sun"/></svg>
|
||||
</button>
|
||||
|
||||
<div class="page">
|
||||
<div class="card">
|
||||
|
||||
<!-- Head -->
|
||||
<div class="card-head">
|
||||
<a href="/" class="brand">
|
||||
<span class="brand-mark"></span>
|
||||
DataStack
|
||||
<span class="brand-tag">CONSOLE</span>
|
||||
</a>
|
||||
<div>
|
||||
<div class="card-title">Sign in</div>
|
||||
<div class="card-sub">Access your admin console</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Body -->
|
||||
<form class="card-body" onsubmit="handleSubmit(event)">
|
||||
|
||||
<!-- Error state (hidden by default) -->
|
||||
<div class="error-bar" id="errorBar">
|
||||
<svg class="icon icon-sm"><use href="#i-alert"/></svg>
|
||||
<span>Invalid email or password. Try again or reset your credentials.</span>
|
||||
</div>
|
||||
|
||||
<!-- Email -->
|
||||
<div class="field">
|
||||
<label class="field-label" for="email">Email</label>
|
||||
<div class="field-wrap">
|
||||
<input id="email" type="email" placeholder="admin@example.com" autocomplete="username" required />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Password -->
|
||||
<div class="field">
|
||||
<label class="field-label" for="password">Password</label>
|
||||
<div class="field-wrap">
|
||||
<input id="password" type="password" class="has-toggle" placeholder="••••••••" autocomplete="current-password" required />
|
||||
<button type="button" class="toggle-pw" onclick="togglePw()" title="Show password" id="pwToggle">
|
||||
<svg class="icon icon-sm" id="pwIcon"><use href="#i-eye"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Meta -->
|
||||
<div class="meta-row">
|
||||
<label class="check">
|
||||
<input type="checkbox" checked>
|
||||
<span class="check-box"></span>
|
||||
Remember me
|
||||
</label>
|
||||
<a href="#" class="forgot">Forgot password?</a>
|
||||
</div>
|
||||
|
||||
<!-- Submit -->
|
||||
<button type="submit" class="btn-submit" id="submitBtn">
|
||||
Sign in
|
||||
<svg class="icon icon-sm"><use href="#i-arrow"/></svg>
|
||||
</button>
|
||||
|
||||
<!-- Divider -->
|
||||
<div class="divider">or</div>
|
||||
|
||||
<!-- Alt action -->
|
||||
<button type="button" class="btn-alt">
|
||||
<svg class="icon icon-sm"><use href="#i-key"/></svg>
|
||||
Sign in with API key
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<!-- Foot -->
|
||||
<div class="card-foot">
|
||||
<span><span class="dot"></span>Server online</span>
|
||||
<a href="/docs" style="color:var(--text-muted)">Docs →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="page-foot">
|
||||
<span>DataStack v1.0.0</span>
|
||||
<span class="sep">·</span>
|
||||
<a href="#">Self-hosted</a>
|
||||
<span class="sep">·</span>
|
||||
<a href="#">GitHub</a>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleTheme(){
|
||||
const html=document.documentElement, icon=document.getElementById('theme-icon');
|
||||
const isDark=html.getAttribute('data-theme')==='dark';
|
||||
html.setAttribute('data-theme',isDark?'light':'dark');
|
||||
icon.innerHTML='<use href="'+(isDark?'#i-moon':'#i-sun')+'"/>';
|
||||
}
|
||||
function togglePw(){
|
||||
const pw=document.getElementById('password');
|
||||
const icon=document.getElementById('pwIcon');
|
||||
const btn=document.getElementById('pwToggle');
|
||||
const show=pw.type==='password';
|
||||
pw.type=show?'text':'password';
|
||||
icon.innerHTML='<use href="'+(show?'#i-eye-off':'#i-eye')+'"/>';
|
||||
btn.title=show?'Hide password':'Show password';
|
||||
}
|
||||
function handleSubmit(e){
|
||||
e.preventDefault();
|
||||
const btn=document.getElementById('submitBtn');
|
||||
const err=document.getElementById('errorBar');
|
||||
err.classList.remove('show');
|
||||
btn.disabled=true;
|
||||
btn.innerHTML='<span class="spinner"></span>Signing in…';
|
||||
// Demo: show error after 1.2s
|
||||
setTimeout(()=>{
|
||||
btn.disabled=false;
|
||||
btn.innerHTML='Sign in <svg class="icon icon-sm"><use href="#i-arrow"/></svg>';
|
||||
err.classList.add('show');
|
||||
}, 1200);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -5,24 +5,28 @@ DataStack is a high-throughput, self-hosted data collection platform designed fo
|
||||
## Architecture
|
||||
|
||||
| Process | Port | Role |
|
||||
| :--- | :--- | :--- |
|
||||
| :---------------------- | :--- | :----------------------------------------------------------------------- |
|
||||
| **Next.js App Router** | 3000 | Frontend UI, `/vcon/*` admin console, streaming CSV export `/api/export` |
|
||||
| **Express + Socket.IO** | 4000 | WebSocket handshake, JWT client auth, event intake |
|
||||
| **CSV Writer Worker** | — | In-memory buffer flush to CSV (`500 rows / 2s`) |
|
||||
|
||||
## Data Persistence
|
||||
|
||||
- **CSV Storage Path**: `/storage/data/{clientId}/{YYYY-MM-DD}.csv`
|
||||
- **Schema**: `clientId, eventId, timestamp(ISO), payload(JSON)`
|
||||
- **Rotation Rule**: Per-day OR 100MB threshold (whichever triggers first).
|
||||
- **PostgreSQL**: Used strictly for SDK client registration and admin settings. Zero collected data is inserted into the database.
|
||||
- **PostgreSQL**: Reserved for SDK client registration and admin settings. Runtime persistence is not wired yet; collected data is never inserted into PostgreSQL.
|
||||
|
||||
## Python SDK
|
||||
|
||||
Install the client:
|
||||
|
||||
```bash
|
||||
pip install ./sdk-python
|
||||
```
|
||||
|
||||
Usage:
|
||||
|
||||
```python
|
||||
from datastack_sdk import DataStackClient
|
||||
|
||||
@@ -33,6 +37,7 @@ if client.connect():
|
||||
```
|
||||
|
||||
## Running the Platform
|
||||
|
||||
```bash
|
||||
# Terminal 1: Web Interface & Admin Console
|
||||
npm run dev
|
||||
@@ -40,3 +45,20 @@ npm run dev
|
||||
# Terminal 2: Express Socket.IO Ingestion Engine
|
||||
npm run server
|
||||
```
|
||||
|
||||
## Production Containers
|
||||
|
||||
Docker Compose builds the standalone Next.js web image and the separate Socket.IO ingestion image. Docker Engine with the Compose plugin is required.
|
||||
|
||||
1. Copy `.env.example` to `.env` and set unique values for `DATASTACK_JWT_SECRET`, `DATASTACK_ADMIN_SESSION_SECRET`, `DATASTACK_ADMIN_EMAIL`, `DATASTACK_ADMIN_PASSWORD`, `DATABASE_URL`, and `POSTGRES_PASSWORD`. Keep `.env` private and out of source control.
|
||||
`DATABASE_URL` must use the `postgres` service host and a password matching `POSTGRES_PASSWORD`.
|
||||
2. From the repository root, validate and start the stack:
|
||||
|
||||
```powershell
|
||||
docker compose --env-file .env -f docker/docker-compose.yml config
|
||||
docker compose --env-file .env -f docker/docker-compose.yml up --build -d
|
||||
```
|
||||
|
||||
The web console is published on port 3000 and the ingestion service on port 4000. Redis and PostgreSQL are private to the Compose network. CSV files written by the ingestion container persist in the `datastack-data` named volume; PostgreSQL metadata persists in `pgdata`.
|
||||
|
||||
The current web process still has a separate in-memory buffer and container-local storage view. Redis and Prisma/PostgreSQL are not yet used by application code, and the web process does not yet read the ingestion volume. Cross-process event visibility and shared storage are Phase P4 work; metadata persistence is Phase P5 work. Do not treat this Compose stack as production-ready until those phases and runtime checks are complete.
|
||||
@@ -0,0 +1,16 @@
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { Features } from '@/components/sections/Features';
|
||||
import { Hero } from '@/components/sections/Hero';
|
||||
import { LandingAbout } from '@/components/sections/LandingAbout';
|
||||
import { SdkSection } from '@/components/sections/SdkSection';
|
||||
|
||||
export default function LandingPage() {
|
||||
return (
|
||||
<MainLayout>
|
||||
<Hero />
|
||||
<Features />
|
||||
<SdkSection />
|
||||
<LandingAbout />
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { createAdminSessionToken } from "@/core/auth/adminSession";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createHash, timingSafeEqual } from "node:crypto";
|
||||
|
||||
const SESSION_COOKIE = "datastack_admin_session";
|
||||
const SESSION_SECONDS = 8 * 60 * 60;
|
||||
const REMEMBERED_SESSION_SECONDS = 30 * 24 * 60 * 60;
|
||||
|
||||
function constantTimeEqual(left: string, right: string) {
|
||||
const leftHash = createHash("sha256").update(left).digest();
|
||||
const rightHash = createHash("sha256").update(right).digest();
|
||||
return timingSafeEqual(leftHash, rightHash);
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const adminEmail = process.env.DATASTACK_ADMIN_EMAIL;
|
||||
const adminPassword = process.env.DATASTACK_ADMIN_PASSWORD;
|
||||
const sessionSecret = process.env.DATASTACK_ADMIN_SESSION_SECRET;
|
||||
|
||||
if (
|
||||
!adminEmail ||
|
||||
!adminPassword ||
|
||||
!sessionSecret ||
|
||||
sessionSecret.length < 32
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error:
|
||||
"Admin login is not configured. Set the required server environment variables.",
|
||||
},
|
||||
{ status: 503 },
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
const email =
|
||||
typeof body.email === "string" ? body.email.trim().toLowerCase() : "";
|
||||
const password = typeof body.password === "string" ? body.password : "";
|
||||
|
||||
if (
|
||||
!constantTimeEqual(email, adminEmail.trim().toLowerCase()) ||
|
||||
!constantTimeEqual(password, adminPassword)
|
||||
) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid email or password." },
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
const remember = body.remember === true;
|
||||
const maxAge = remember ? REMEMBERED_SESSION_SECONDS : SESSION_SECONDS;
|
||||
const expiresAt = Date.now() + maxAge * 1000;
|
||||
const token = await createAdminSessionToken(
|
||||
email,
|
||||
sessionSecret,
|
||||
expiresAt,
|
||||
);
|
||||
const response = NextResponse.json({ success: true });
|
||||
|
||||
response.cookies.set(SESSION_COOKIE, token, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "strict",
|
||||
path: "/",
|
||||
maxAge,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid login request." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +1,58 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { SDKManager } from '@/core/sdk/sdkManager';
|
||||
import { SDKManager } from "@/core/sdk/sdkManager";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const client = SDKManager.getClient(id);
|
||||
if (!client) {
|
||||
return NextResponse.json({ error: 'Client not found' }, { status: 404 });
|
||||
return NextResponse.json({ error: "Client not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ client });
|
||||
const { secret, token, ...clientSummary } = client;
|
||||
return NextResponse.json({ client: clientSummary });
|
||||
}
|
||||
|
||||
export async function PATCH(
|
||||
req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
try {
|
||||
const body = await req.json();
|
||||
|
||||
// Special action: regenerate token
|
||||
if (body.action === 'regenerate_token') {
|
||||
if (body.action === "regenerate_token") {
|
||||
const refreshed = SDKManager.regenerateToken(id);
|
||||
if (!refreshed) {
|
||||
return NextResponse.json({ error: 'Client not found' }, { status: 404 });
|
||||
return NextResponse.json(
|
||||
{ error: "Client not found" },
|
||||
{ status: 404 },
|
||||
);
|
||||
}
|
||||
return NextResponse.json({ client: refreshed });
|
||||
}
|
||||
|
||||
const updated = SDKManager.updateClient(id, body);
|
||||
if (!updated) {
|
||||
return NextResponse.json({ error: 'Client not found' }, { status: 404 });
|
||||
return NextResponse.json({ error: "Client not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ client: updated });
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Update failed';
|
||||
const message = err instanceof Error ? err.message : "Update failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
_req: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
const deleted = SDKManager.deleteClient(id);
|
||||
if (!deleted) {
|
||||
return NextResponse.json({ error: 'Client not found' }, { status: 404 });
|
||||
return NextResponse.json({ error: "Client not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ success: true, message: `Client ${id} deleted` });
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { SDKManager } from '@/core/sdk/sdkManager';
|
||||
import { SDKManager } from "@/core/sdk/sdkManager";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const clients = SDKManager.listClients();
|
||||
const clients = SDKManager.listClients().map(
|
||||
({ secret, token, ...client }) => client,
|
||||
);
|
||||
return NextResponse.json({ clients, count: clients.length });
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Failed to list clients';
|
||||
const message =
|
||||
err instanceof Error ? err.message : "Failed to list clients";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -18,8 +21,8 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
if (!clientId || !name) {
|
||||
return NextResponse.json(
|
||||
{ error: 'clientId and name are required' },
|
||||
{ status: 400 }
|
||||
{ error: "clientId and name are required" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,7 +30,7 @@ export async function POST(req: NextRequest) {
|
||||
if (existing) {
|
||||
return NextResponse.json(
|
||||
{ error: `Client '${clientId}' already exists` },
|
||||
{ status: 409 }
|
||||
{ status: 409 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,7 +42,8 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
return NextResponse.json({ client: newClient }, { status: 201 });
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Client creation failed';
|
||||
const message =
|
||||
err instanceof Error ? err.message : "Client creation failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { DataBufferEngine } from "@/core/data/buffer";
|
||||
import { CSVStorageManager } from "@/core/Storage/csvStorage";
|
||||
import { parse } from "csv-parse";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createReadStream, readdirSync, statSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
|
||||
interface DataEvent {
|
||||
clientId: string;
|
||||
eventId: string;
|
||||
timestamp: string;
|
||||
payload: string;
|
||||
status: "stored" | "buffered";
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const clientId = searchParams.get("clientId") || "all";
|
||||
const from = searchParams.get("from") || "";
|
||||
const to = searchParams.get("to") || "";
|
||||
const search = (searchParams.get("search") || "").toLowerCase();
|
||||
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
||||
const pageSize = Math.min(
|
||||
100,
|
||||
Math.max(1, Number(searchParams.get("pageSize")) || 12),
|
||||
);
|
||||
const offset = (page - 1) * pageSize;
|
||||
const selectedRows: DataEvent[] = [];
|
||||
const eventIds = new Set<string>();
|
||||
let total = 0;
|
||||
|
||||
const addIfMatching = (event: DataEvent) => {
|
||||
const eventDate = event.timestamp.slice(0, 10);
|
||||
if (
|
||||
(clientId !== "all" && event.clientId !== clientId) ||
|
||||
(from && eventDate < from) ||
|
||||
(to && eventDate > to) ||
|
||||
(search && !event.payload.toLowerCase().includes(search)) ||
|
||||
eventIds.has(event.eventId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
eventIds.add(event.eventId);
|
||||
total += 1;
|
||||
|
||||
let low = 0;
|
||||
let high = selectedRows.length;
|
||||
while (low < high) {
|
||||
const middle = (low + high) >>> 1;
|
||||
if (selectedRows[middle].timestamp >= event.timestamp) low = middle + 1;
|
||||
else high = middle;
|
||||
}
|
||||
|
||||
if (low < offset + pageSize) {
|
||||
selectedRows.splice(low, 0, event);
|
||||
if (selectedRows.length > offset + pageSize) selectedRows.pop();
|
||||
}
|
||||
};
|
||||
|
||||
const storageDir = CSVStorageManager.baseStorageDir;
|
||||
let clientDirs: string[] = [];
|
||||
try {
|
||||
clientDirs = readdirSync(storageDir);
|
||||
} catch {
|
||||
clientDirs = [];
|
||||
}
|
||||
|
||||
for (const storedClientId of clientDirs) {
|
||||
if (clientId !== "all" && storedClientId !== clientId) continue;
|
||||
|
||||
const clientDir = path.join(storageDir, storedClientId);
|
||||
if (!statSync(clientDir).isDirectory()) continue;
|
||||
|
||||
let filenames: string[];
|
||||
try {
|
||||
filenames = readdirSync(clientDir).filter((filename) =>
|
||||
/^\d{4}-\d{2}-\d{2}(?:-part\d+)?\.csv$/.test(filename),
|
||||
);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const filename of filenames) {
|
||||
const fileDate = filename.slice(0, 10);
|
||||
if ((from && fileDate < from) || (to && fileDate > to)) continue;
|
||||
|
||||
const parser = createReadStream(path.join(clientDir, filename)).pipe(
|
||||
parse({ columns: true, skip_empty_lines: true, bom: true }),
|
||||
);
|
||||
|
||||
try {
|
||||
for await (const record of parser as AsyncIterable<
|
||||
Record<string, string>
|
||||
>) {
|
||||
const event = {
|
||||
clientId: record.clientId || storedClientId,
|
||||
eventId: record.eventId || "",
|
||||
timestamp: record.timestamp || `${fileDate}T00:00:00.000Z`,
|
||||
payload: record.payload || "",
|
||||
status: "stored" as const,
|
||||
};
|
||||
if (event.eventId) addIfMatching(event);
|
||||
}
|
||||
} catch {
|
||||
parser.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const event of DataBufferEngine.getRecentEvents(200)) {
|
||||
addIfMatching({ ...event, status: "buffered" });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
events: selectedRows.slice(offset),
|
||||
total,
|
||||
page,
|
||||
pageSize,
|
||||
pageCount: Math.max(1, Math.ceil(total / pageSize)),
|
||||
});
|
||||
} catch (error) {
|
||||
const message =
|
||||
error instanceof Error ? error.message : "Data retrieval failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
+140
-54
@@ -1,76 +1,162 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { CSVStorageManager } from '@/core/Storage/csvStorage';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
CSVStorageManager,
|
||||
type StorageFileMeta,
|
||||
} from "@/core/Storage/csvStorage";
|
||||
import { parse } from "csv-parse";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { createReadStream } from "node:fs";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
type ExportFormat = "csv" | "json";
|
||||
type CsvRecord = Record<string, string>;
|
||||
type StreamChunk = string | Uint8Array;
|
||||
|
||||
function toByteStream(chunks: AsyncIterable<StreamChunk>) {
|
||||
const iterator = chunks[Symbol.asyncIterator]();
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
return new ReadableStream<Uint8Array>({
|
||||
async pull(controller) {
|
||||
try {
|
||||
const { searchParams } = new URL(req.url);
|
||||
const clientId = searchParams.get('clientId');
|
||||
const filename = searchParams.get('filename');
|
||||
|
||||
// Single specific file export
|
||||
if (clientId && filename) {
|
||||
const content = CSVStorageManager.getFileContent(clientId, filename);
|
||||
if (!content) {
|
||||
return NextResponse.json({ error: 'CSV file not found' }, { status: 404 });
|
||||
const result = await iterator.next();
|
||||
if (result.done) {
|
||||
controller.close();
|
||||
} else {
|
||||
controller.enqueue(
|
||||
typeof result.value === "string"
|
||||
? encoder.encode(result.value)
|
||||
: result.value,
|
||||
);
|
||||
}
|
||||
|
||||
return new NextResponse(content, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': `attachment; filename="${filename}"`,
|
||||
} catch (error) {
|
||||
controller.error(error);
|
||||
}
|
||||
},
|
||||
async cancel() {
|
||||
await iterator.return?.();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Stream aggregate or list files
|
||||
const allFiles = CSVStorageManager.listAllFiles();
|
||||
const filtered = clientId && clientId !== 'all'
|
||||
? allFiles.filter((f) => f.clientId === clientId)
|
||||
: allFiles;
|
||||
async function* readFileRecords(
|
||||
file: StorageFileMeta,
|
||||
): AsyncGenerator<CsvRecord> {
|
||||
const parser = createReadStream(file.filePath).pipe(
|
||||
parse({ columns: true, skip_empty_lines: true, bom: true }),
|
||||
);
|
||||
|
||||
if (filtered.length === 0) {
|
||||
const emptyCsv = 'clientId,eventId,timestamp,payload\n';
|
||||
return new NextResponse(emptyCsv, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': `attachment; filename="datastack_export_${Date.now()}.csv"`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Combine matching files with a single header
|
||||
let combined = 'clientId,eventId,timestamp,payload\n';
|
||||
for (const f of filtered) {
|
||||
try {
|
||||
const raw = fs.readFileSync(f.filePath, 'utf8');
|
||||
const lines = raw.split('\n');
|
||||
// skip header on subsequent lines
|
||||
const dataLines = lines.slice(1).filter((l) => l.trim().length > 0);
|
||||
if (dataLines.length > 0) {
|
||||
combined += dataLines.join('\n') + '\n';
|
||||
for await (const record of parser as AsyncIterable<CsvRecord>) {
|
||||
yield record;
|
||||
}
|
||||
} catch {
|
||||
// continue
|
||||
parser.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
const exportFileName = clientId && clientId !== 'all'
|
||||
? `${clientId}_export_${new Date().toISOString().split('T')[0]}.csv`
|
||||
: `datastack_universal_export_${new Date().toISOString().split('T')[0]}.csv`;
|
||||
function makeExportStream(
|
||||
files: StorageFileMeta[],
|
||||
format: ExportFormat,
|
||||
includeHeader: boolean,
|
||||
) {
|
||||
const fields = ["clientId", "eventId", "timestamp", "payload"];
|
||||
const chunks = (async function* () {
|
||||
let isFirst = true;
|
||||
|
||||
return new NextResponse(combined, {
|
||||
if (format === "json") {
|
||||
yield "[";
|
||||
} else if (includeHeader) {
|
||||
yield `${fields.join(",")}\n`;
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
for await (const record of readFileRecords(file)) {
|
||||
if (format === "json") {
|
||||
const payload = record.payload ?? "";
|
||||
let parsedPayload: unknown = payload;
|
||||
try {
|
||||
parsedPayload = JSON.parse(payload);
|
||||
} catch {
|
||||
// Keep non-JSON payloads as strings.
|
||||
}
|
||||
yield `${isFirst ? "" : ","}${JSON.stringify({ ...record, payload: parsedPayload })}`;
|
||||
} else {
|
||||
const line = fields
|
||||
.map((field) => `"${(record[field] ?? "").replaceAll('"', '""')}"`)
|
||||
.join(",");
|
||||
yield `${line}\n`;
|
||||
}
|
||||
isFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (format === "json") yield "]";
|
||||
})();
|
||||
|
||||
return toByteStream(chunks);
|
||||
}
|
||||
|
||||
function streamFile(file: StorageFileMeta) {
|
||||
async function* chunks() {
|
||||
for await (const chunk of createReadStream(file.filePath)) {
|
||||
yield new Uint8Array(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return toByteStream(chunks());
|
||||
}
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const clientId = searchParams.get("clientId") || "all";
|
||||
const filename = searchParams.get("filename");
|
||||
const from = searchParams.get("from") || "";
|
||||
const to = searchParams.get("to") || "";
|
||||
const format: ExportFormat =
|
||||
searchParams.get("format") === "json" ? "json" : "csv";
|
||||
const includeHeader = searchParams.get("includeHeader") !== "false";
|
||||
|
||||
let files = CSVStorageManager.listAllFiles();
|
||||
if (clientId !== "all")
|
||||
files = files.filter((file) => file.clientId === clientId);
|
||||
|
||||
if (filename) {
|
||||
const file = files.find((candidate) => candidate.filename === filename);
|
||||
if (!file)
|
||||
return NextResponse.json(
|
||||
{ error: "CSV file not found" },
|
||||
{ status: 404 },
|
||||
);
|
||||
return new NextResponse(streamFile(file), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/csv; charset=utf-8',
|
||||
'Content-Disposition': `attachment; filename="${exportFileName}"`,
|
||||
"Content-Type": "text/csv; charset=utf-8",
|
||||
"Content-Disposition": `attachment; filename="${file.filename}"`,
|
||||
},
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Export failed';
|
||||
}
|
||||
|
||||
files = files.filter(
|
||||
(file) => (!from || file.date >= from) && (!to || file.date <= to),
|
||||
);
|
||||
const datePart = new Date().toISOString().slice(0, 10);
|
||||
const safeClientId = clientId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
||||
const baseName =
|
||||
clientId === "all" ? "datastack_export" : `${safeClientId}_export`;
|
||||
|
||||
return new NextResponse(makeExportStream(files, format, includeHeader), {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type":
|
||||
format === "json"
|
||||
? "application/json; charset=utf-8"
|
||||
: "text/csv; charset=utf-8",
|
||||
"Content-Disposition": `attachment; filename="${baseName}_${datePart}.${format}"`,
|
||||
"Cache-Control": "no-store",
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Export failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { SettingsManager } from '@/core/adminSettings/settingsManager';
|
||||
import { SettingsManager } from "@/core/adminSettings/settingsManager";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const settings = SettingsManager.getSettings();
|
||||
const settings = SettingsManager.getPublicSettings();
|
||||
return NextResponse.json({ settings });
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Settings read failed';
|
||||
const message = err instanceof Error ? err.message : "Settings read failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,14 @@ export async function GET() {
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const updated = SettingsManager.updateSettings(body);
|
||||
return NextResponse.json({ settings: updated, success: true });
|
||||
SettingsManager.updateSettings(body);
|
||||
return NextResponse.json({
|
||||
settings: SettingsManager.getPublicSettings(),
|
||||
success: true,
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Settings update failed';
|
||||
const message =
|
||||
err instanceof Error ? err.message : "Settings update failed";
|
||||
return NextResponse.json({ error: message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
+80
-55
@@ -2,73 +2,89 @@
|
||||
|
||||
:root {
|
||||
--radius: 0rem;
|
||||
--font-weight-semibold: 500;
|
||||
--font-weight-bold: 500;
|
||||
--font-weight-extrabold: 500;
|
||||
--font-sans: "Segoe UI", "Segoe UI Web", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
|
||||
--font-mono: ui-monospace, "SF Mono", "Liberation Mono", Menlo, Consolas, monospace;
|
||||
--font-mono: "Consolas", "Courier New", monospace;
|
||||
--container-width: 1080px;
|
||||
--console-width: 1240px;
|
||||
--surface-3: #1d1d21;
|
||||
--accent-text: var(--accent);
|
||||
|
||||
/* Theme tokens - Dark Mode (Sleek Graphite Workbench) */
|
||||
--bg-main: #0c0e12;
|
||||
--bg-sidebar: #0f1117;
|
||||
--bg-activity: #131720;
|
||||
--bg-elevated: #161b24;
|
||||
--bg-hover: #1c2230;
|
||||
--bg-active: #242c3d;
|
||||
--border: #212836;
|
||||
--border-strong: #2e374a;
|
||||
--text: #e6ebf2;
|
||||
--text-muted: #8c96a8;
|
||||
--text-dim: #5c6577;
|
||||
--accent: #3b82f6;
|
||||
--accent-soft: rgba(59, 130, 246, 0.08);
|
||||
--accent-hover: #60a5fa;
|
||||
--text-on-accent: #ffffff;
|
||||
--success: #10b981;
|
||||
--success-soft: rgba(16, 185, 129, 0.08);
|
||||
--warning: #f59e0b;
|
||||
--warning-soft: rgba(245, 158, 11, 0.08);
|
||||
--danger: #ef4444;
|
||||
--danger-soft: rgba(239, 68, 68, 0.08);
|
||||
--bg: #0a0a0b;
|
||||
--surface: #111113;
|
||||
--surface-2: #17171a;
|
||||
--border: #232326;
|
||||
--border-strong: #2e2e33;
|
||||
--text: #e8e8ea;
|
||||
--text-muted: #85858c;
|
||||
--text-faint: #5a5a62;
|
||||
--accent: #a3e635;
|
||||
--accent-soft: rgba(163, 230, 53, 0.08);
|
||||
--font: var(--font-sans);
|
||||
--radius: 0rem;
|
||||
--bg-main: var(--bg);
|
||||
--bg-sidebar: var(--surface);
|
||||
--bg-activity: var(--surface);
|
||||
--bg-elevated: var(--surface);
|
||||
--bg-hover: var(--surface-2);
|
||||
--bg-active: var(--surface-2);
|
||||
--text-dim: var(--text-faint);
|
||||
--accent-hover: var(--accent);
|
||||
--text-on-accent: var(--bg);
|
||||
--success: var(--accent);
|
||||
--success-soft: var(--accent-soft);
|
||||
--warning: var(--text-muted);
|
||||
--warning-soft: transparent;
|
||||
--danger: var(--text-muted);
|
||||
--danger-soft: transparent;
|
||||
}
|
||||
|
||||
html.light, body.light {
|
||||
/* Theme tokens - Light Mode (Clean, soft contrast) */
|
||||
--bg-main: #ffffff;
|
||||
--bg-sidebar: #f8fafc;
|
||||
--bg-activity: #f1f5f9;
|
||||
--bg-elevated: #ffffff;
|
||||
--bg-hover: #f1f5f9;
|
||||
--bg-active: #e2e8f0;
|
||||
--border: #e2e8f0;
|
||||
--border-strong: #cbd5e1;
|
||||
--text: #0f172a;
|
||||
--text-muted: #475569;
|
||||
--text-dim: #94a3b8;
|
||||
--accent: #2563eb;
|
||||
--accent-soft: rgba(37, 99, 235, 0.06);
|
||||
--accent-hover: #1d4ed8;
|
||||
--text-on-accent: #ffffff;
|
||||
--success: #059669;
|
||||
--success-soft: rgba(5, 150, 105, 0.08);
|
||||
--warning: #d97706;
|
||||
--warning-soft: rgba(217, 119, 6, 0.08);
|
||||
--danger: #dc2626;
|
||||
--danger-soft: rgba(220, 38, 38, 0.08);
|
||||
--bg: #fafafa;
|
||||
--surface: #f4f4f5;
|
||||
--surface-2: #ececed;
|
||||
--surface-3: #ececed;
|
||||
--border: #e2e2e5;
|
||||
--border-strong: #d0d0d3;
|
||||
--text: #111113;
|
||||
--text-muted: #5a5a62;
|
||||
--text-faint: #85858c;
|
||||
--accent: #65a30d;
|
||||
--accent-soft: rgba(101, 163, 13, 0.08);
|
||||
--accent-text: #4d7c0f;
|
||||
--font: var(--font-sans);
|
||||
--bg-main: var(--bg);
|
||||
--bg-sidebar: var(--surface);
|
||||
--bg-activity: var(--surface);
|
||||
--bg-elevated: var(--surface);
|
||||
--bg-hover: var(--surface-2);
|
||||
--bg-active: var(--surface-2);
|
||||
--text-dim: var(--text-faint);
|
||||
--accent-hover: var(--accent);
|
||||
--text-on-accent: var(--bg);
|
||||
--success: var(--accent);
|
||||
--success-soft: var(--accent-soft);
|
||||
--warning: var(--text-muted);
|
||||
--warning-soft: transparent;
|
||||
--danger: var(--text-muted);
|
||||
--danger-soft: transparent;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border-radius: 0 !important;
|
||||
box-shadow: none !important;
|
||||
text-shadow: none !important;
|
||||
}
|
||||
|
||||
html, body {
|
||||
font-family: var(--font-sans) !important;
|
||||
font-family: var(--font) !important;
|
||||
background-color: var(--bg-main);
|
||||
color: var(--text);
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
@@ -82,7 +98,11 @@ h1, h2, h3, h4, h5, h6 {
|
||||
font-family: var(--font-sans) !important;
|
||||
font-weight: 500;
|
||||
color: var(--text);
|
||||
letter-spacing: -0.01em;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
b, strong {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Code & pre font */
|
||||
@@ -92,8 +112,8 @@ pre, code, kbd, samp {
|
||||
|
||||
/* Scrollbar clean styling */
|
||||
::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
height: 5px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
@@ -107,8 +127,13 @@ pre, code, kbd, samp {
|
||||
|
||||
/* Interactive focus */
|
||||
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
|
||||
outline: 1px solid var(--accent);
|
||||
outline-offset: 1px;
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: var(--accent-soft);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
/* Hide floating dev badges */
|
||||
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
import { ToastProvider } from '@/components/ui/Toast';
|
||||
import type { Metadata } from 'next';
|
||||
import './globals.css';
|
||||
import { ToastProvider } from '@/components/ui/Toast';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'DataStack - Realtime Data Collection Platform',
|
||||
description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, JWT client auth, CSV batch rotation, and /vcon/ admin panel.',
|
||||
description: 'A self-hosted workspace for collecting, reviewing, and exporting realtime data.',
|
||||
manifest: '/manifest.json',
|
||||
openGraph: {
|
||||
title: 'DataStack - Realtime Data Collection Platform',
|
||||
description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion, Redis buffer, and CSV batch storage.',
|
||||
description: 'Collect, review, and export realtime data from one clear workspace.',
|
||||
type: 'website',
|
||||
},
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
title: 'DataStack - Realtime Data Collection Platform',
|
||||
description: 'Self-hosted universal realtime data collection engine with Socket.IO ingestion.',
|
||||
description: 'A clear workspace for collecting, reviewing, and exporting realtime data.',
|
||||
},
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
<html lang="en" className="dark">
|
||||
<head>
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<meta name="theme-color" content="#2563eb" />
|
||||
<meta name="theme-color" content="#0a0a0b" />
|
||||
</head>
|
||||
<body suppressHydrationWarning className="min-h-screen bg-[var(--bg-main)] text-[var(--text)] antialiased">
|
||||
<ToastProvider>{children}</ToastProvider>
|
||||
|
||||
+1
-7
@@ -1,7 +1,6 @@
|
||||
import React from 'react';
|
||||
import Link from 'next/link';
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
@@ -17,11 +16,6 @@ export default function NotFound() {
|
||||
Return Home
|
||||
</Button>
|
||||
</Link>
|
||||
<Link href="/vcon/dashboard">
|
||||
<Button variant="primary" size="sm">
|
||||
Admin Console
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</MainLayout>
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import React from 'react';
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { Hero } from '@/components/sections/Hero';
|
||||
import { Features } from '@/components/sections/Features';
|
||||
import { Architecture } from '@/components/sections/Architecture';
|
||||
|
||||
export default function RootHomePage() {
|
||||
return (
|
||||
<MainLayout>
|
||||
<div className="flex flex-col gap-4">
|
||||
<Hero />
|
||||
<Architecture />
|
||||
<Features />
|
||||
</div>
|
||||
</MainLayout>
|
||||
);
|
||||
}
|
||||
+76
-363
@@ -1,393 +1,106 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { AdminPageHeader } from '@/components/layout/AdminPageHeader';
|
||||
import type { ClientItem, ClientStatusFilter } from '@/components/sections/clients/types';
|
||||
import { ClientsFilters } from '@/components/sections/ClientsFilters';
|
||||
import { ClientsTable } from '@/components/sections/ClientsTable';
|
||||
import { NewClientModal } from '@/components/sections/NewClientModal';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import {
|
||||
TableWrap,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
|
||||
interface ClientItem {
|
||||
clientId: string;
|
||||
name: string;
|
||||
secret: string;
|
||||
token: string;
|
||||
rateLimit: number;
|
||||
status: 'active' | 'revoked';
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
import { StatStrip } from '@/components/ui/StatStrip';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
export default function ClientsPage() {
|
||||
const { success, error, warning } = useToast();
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
const [clients, setClients] = useState<ClientItem[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
// Modals
|
||||
const [createModalOpen, setCreateModalOpen] = useState(false);
|
||||
const [tokenModalOpen, setTokenModalOpen] = useState(false);
|
||||
const [selectedClient, setSelectedClient] = useState<ClientItem | null>(null);
|
||||
|
||||
// Form State
|
||||
const [newClientId, setNewClientId] = useState('');
|
||||
const [newClientName, setNewClientName] = useState('');
|
||||
const [newRateLimit, setNewRateLimit] = useState('100');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [search, setSearch] = useState('');
|
||||
const [statusFilter, setStatusFilter] = useState<ClientStatusFilter>('all');
|
||||
const [now, setNow] = useState(0);
|
||||
|
||||
const fetchClients = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/clients');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
const response = await fetch('/api/clients');
|
||||
if (!response.ok) throw new Error('Unable to load clients');
|
||||
const data = await response.json();
|
||||
setClients(data.clients || []);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchClients();
|
||||
fetchClients().catch(() => setClients([]));
|
||||
}, [fetchClients]);
|
||||
|
||||
const handleCreateClient = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!newClientId.trim() || !newClientName.trim()) {
|
||||
error('Validation Error', 'Client ID and Client Name are required');
|
||||
return;
|
||||
}
|
||||
useEffect(() => {
|
||||
const updateClock = () => setNow(Date.now());
|
||||
updateClock();
|
||||
const interval = setInterval(updateClock, 15_000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const res = await fetch('/api/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clientId: newClientId.trim(),
|
||||
name: newClientName.trim(),
|
||||
rateLimit: Number(newRateLimit) || 100,
|
||||
}),
|
||||
const visibleClients = useMemo(() => {
|
||||
const query = search.trim().toLowerCase();
|
||||
return clients.filter((client) => {
|
||||
const matchesSearch = !query ||
|
||||
client.clientId.toLowerCase().includes(query) ||
|
||||
client.name.toLowerCase().includes(query);
|
||||
const online = client.status === 'active' && Boolean(client.lastActive) &&
|
||||
now - new Date(client.lastActive!).getTime() < 60_000;
|
||||
const pending = client.status === 'active' && !client.lastActive;
|
||||
const matchesStatus = statusFilter === 'all' ||
|
||||
(statusFilter === 'online' && online) ||
|
||||
(statusFilter === 'offline' && !online && !pending) ||
|
||||
(statusFilter === 'pending' && pending);
|
||||
return matchesSearch && matchesStatus;
|
||||
});
|
||||
}, [clients, now, search, statusFilter]);
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
success('Client Registered', `Client ${data.client.clientId} created successfully`);
|
||||
setCreateModalOpen(false);
|
||||
setNewClientId('');
|
||||
setNewClientName('');
|
||||
setNewRateLimit('100');
|
||||
fetchClients();
|
||||
// Open token modal immediately
|
||||
setSelectedClient(data.client);
|
||||
setTokenModalOpen(true);
|
||||
} else {
|
||||
const errData = await res.json();
|
||||
error('Registration Failed', errData.error || 'Unknown error');
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Error', err.message);
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleStatus = async (client: ClientItem) => {
|
||||
const newStatus = client.status === 'active' ? 'revoked' : 'active';
|
||||
try {
|
||||
const res = await fetch(`/api/clients/${client.clientId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status: newStatus }),
|
||||
});
|
||||
if (res.ok) {
|
||||
warning(
|
||||
`Status Changed`,
|
||||
`Client ${client.clientId} is now ${newStatus.toUpperCase()}`
|
||||
);
|
||||
fetchClients();
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Update Failed', err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegenerateToken = async (client: ClientItem) => {
|
||||
try {
|
||||
const res = await fetch(`/api/clients/${client.clientId}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'regenerate_token' }),
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
success('Token Regenerated', `New JWT issued for ${client.clientId}`);
|
||||
setSelectedClient(data.client);
|
||||
setTokenModalOpen(true);
|
||||
fetchClients();
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Regeneration Failed', err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteClient = async (client: ClientItem) => {
|
||||
if (!confirm(`Are you sure you want to delete client '${client.clientId}'?`)) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(`/api/clients/${client.clientId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (res.ok) {
|
||||
success('Client Removed', `Client ${client.clientId} deleted`);
|
||||
fetchClients();
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Deletion Failed', err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = (text: string, label: string) => {
|
||||
navigator.clipboard.writeText(text);
|
||||
success('Copied to Clipboard', `${label} copied`);
|
||||
};
|
||||
const onlineCount = clients.filter((client) =>
|
||||
client.status === 'active' && client.lastActive &&
|
||||
now - new Date(client.lastActive).getTime() < 60_000
|
||||
).length;
|
||||
const pendingCount = clients.filter((client) =>
|
||||
client.status === 'active' && !client.lastActive
|
||||
).length;
|
||||
const offlineCount = clients.length - onlineCount - pendingCount;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
Client SDKs
|
||||
</h1>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="primary"
|
||||
icon="Plus"
|
||||
onClick={() => setCreateModalOpen(true)}
|
||||
className="self-start sm:self-auto"
|
||||
>
|
||||
Register Client
|
||||
</Button>
|
||||
<div className="w-full max-w-[var(--console-width)]">
|
||||
<div className="mb-3 flex items-center gap-1.5 text-xs text-[var(--text-faint)]" aria-label="Breadcrumb">
|
||||
<span>Console</span>
|
||||
<span aria-hidden="true" className="text-[var(--border-strong)]">/</span>
|
||||
<span aria-current="page" className="text-[var(--text)]">Clients</span>
|
||||
</div>
|
||||
|
||||
{/* Clients Table */}
|
||||
<TableWrap>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client ID</TableHead>
|
||||
<TableHead>Client Name</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Rate Limit</TableHead>
|
||||
<TableHead>Total Ingested</TableHead>
|
||||
<TableHead>Created</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{clients.length === 0 ? (
|
||||
<TableEmpty colSpan={7} message="No registered SDK clients yet." />
|
||||
) : (
|
||||
clients.map((client) => (
|
||||
<TableRow key={client.clientId}>
|
||||
<TableCell className="font-mono text-[11px] font-medium text-[var(--accent)]">
|
||||
{client.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="text-[11.5px] text-[var(--text)]">
|
||||
{client.name}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span
|
||||
className={`text-[9.5px] font-mono px-1.5 py-0.5 border ${
|
||||
client.status === 'active'
|
||||
? 'border-[var(--success)] text-[var(--success)] bg-[var(--success-soft)]'
|
||||
: 'border-[var(--danger)] text-[var(--danger)] bg-[var(--danger-soft)]'
|
||||
}`}
|
||||
>
|
||||
{client.status.toUpperCase()}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--text-muted)]">
|
||||
{client.rateLimit} req/s
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--text)]">
|
||||
{client.totalEvents.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
|
||||
{new Date(client.createdAt).toLocaleDateString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Key"
|
||||
onClick={() => {
|
||||
setSelectedClient(client);
|
||||
setTokenModalOpen(true);
|
||||
}}
|
||||
>
|
||||
Token
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
onClick={() => handleToggleStatus(client)}
|
||||
>
|
||||
{client.status === 'active' ? 'Revoke' : 'Activate'}
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Trash2"
|
||||
className="text-[var(--danger)]"
|
||||
onClick={() => handleDeleteClient(client)}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
{/* Register Client Modal */}
|
||||
<Modal
|
||||
isOpen={createModalOpen}
|
||||
onClose={() => setCreateModalOpen(false)}
|
||||
title="Register Client SDK"
|
||||
footer={
|
||||
<>
|
||||
<Button variant="ghost" size="sm" onClick={() => setCreateModalOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
loading={submitting}
|
||||
onClick={handleCreateClient}
|
||||
>
|
||||
Confirm
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form onSubmit={handleCreateClient} className="flex flex-col gap-3">
|
||||
<Input
|
||||
label="Client Identifier"
|
||||
placeholder="e.g. py_order_service_04"
|
||||
value={newClientId}
|
||||
onChange={(e) => setNewClientId(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Client Name"
|
||||
placeholder="e.g. Order Service"
|
||||
value={newClientName}
|
||||
onChange={(e) => setNewClientName(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Rate Limit (req/s)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="5000"
|
||||
value={newRateLimit}
|
||||
onChange={(e) => setNewRateLimit(e.target.value)}
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
{/* View Token & Credentials Modal */}
|
||||
<Modal
|
||||
isOpen={tokenModalOpen}
|
||||
onClose={() => setTokenModalOpen(false)}
|
||||
title={`Credentials: ${selectedClient?.clientId}`}
|
||||
footer={
|
||||
<Button variant="secondary" size="sm" onClick={() => setTokenModalOpen(false)}>
|
||||
Close
|
||||
<AdminPageHeader
|
||||
title="Clients"
|
||||
subtitle="Registered SDK clients and their API access"
|
||||
actions={
|
||||
<Button type="button" variant="primary" size="sm" onClick={() => setModalOpen(true)}>
|
||||
<Plus className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
New client
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{selectedClient && (
|
||||
<div className="flex flex-col gap-3 font-mono text-[11px]">
|
||||
<div>
|
||||
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
|
||||
Client ID
|
||||
</span>
|
||||
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] flex items-center justify-between">
|
||||
<span>{selectedClient.clientId}</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
onClick={() => copyToClipboard(selectedClient.clientId, 'Client ID')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
|
||||
Client Secret Key
|
||||
</span>
|
||||
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] flex items-center justify-between">
|
||||
<span className="truncate">{selectedClient.secret}</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Copy"
|
||||
onClick={() => copyToClipboard(selectedClient.secret, 'Client Secret')}
|
||||
<StatStrip
|
||||
items={[
|
||||
{ label: 'Total clients', value: clients.length },
|
||||
{ label: 'Online now', value: onlineCount, dot: 'ok' },
|
||||
{ label: 'Offline', value: offlineCount, dot: 'off' },
|
||||
{ label: 'Pending setup', value: pendingCount, dot: 'pending' },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider">
|
||||
JWT Handshake Bearer Token
|
||||
</span>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="RefreshCw"
|
||||
onClick={() => handleRegenerateToken(selectedClient)}
|
||||
>
|
||||
Regenerate
|
||||
</Button>
|
||||
</div>
|
||||
<textarea
|
||||
readOnly
|
||||
value={selectedClient.token}
|
||||
rows={4}
|
||||
className="w-full bg-[var(--bg-main)] border border-[var(--border)] p-2 text-[10.5px] text-[var(--accent)] resize-none"
|
||||
<ClientsFilters
|
||||
search={search}
|
||||
onSearchChange={setSearch}
|
||||
status={statusFilter}
|
||||
onStatusChange={setStatusFilter}
|
||||
counts={{ all: clients.length, online: onlineCount, offline: offlineCount, pending: pendingCount }}
|
||||
/>
|
||||
<ClientsTable clients={visibleClients} now={now} onStatusChange={fetchClients} />
|
||||
<NewClientModal
|
||||
open={modalOpen}
|
||||
onClose={() => setModalOpen(false)}
|
||||
onCreated={fetchClients}
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
icon="Copy"
|
||||
className="mt-1 w-full"
|
||||
onClick={() => copyToClipboard(selectedClient.token, 'JWT Token')}
|
||||
>
|
||||
Copy JWT Token
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+2
-518
@@ -1,521 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import {
|
||||
TableWrap,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
|
||||
interface EventItem {
|
||||
eventId: string;
|
||||
clientId: string;
|
||||
timestamp: string;
|
||||
payload: string;
|
||||
}
|
||||
|
||||
const INITIAL_EVENTS: EventItem[] = [
|
||||
{
|
||||
eventId: 'evt_10482_a8',
|
||||
clientId: 'py_telemetry_agent_01',
|
||||
timestamp: '16:11:33',
|
||||
payload: '{"action":"crawler_metric","pages_scraped":38,"latency_ms":24,"status":200}',
|
||||
},
|
||||
{
|
||||
eventId: 'evt_10481_f2',
|
||||
clientId: 'py_scraper_prod_02',
|
||||
timestamp: '16:11:19',
|
||||
payload: '{"spider":"market_catalog","items":114,"parse_time_s":1.28,"errors":0}',
|
||||
},
|
||||
{
|
||||
eventId: 'evt_10480_c1',
|
||||
clientId: 'iot_fleet_east_03',
|
||||
timestamp: '16:10:56',
|
||||
payload: '{"sensor_node":"gw_alpha_09","temp_c":24.3,"humidity_pct":58.1,"battery_v":3.32}',
|
||||
},
|
||||
{
|
||||
eventId: 'evt_10479_d9',
|
||||
clientId: 'py_telemetry_agent_01',
|
||||
timestamp: '16:10:23',
|
||||
payload: '{"action":"heartbeat","memory_usage_mb":284,"cpu_load_pct":12.8}',
|
||||
},
|
||||
{
|
||||
eventId: 'evt_10478_e4',
|
||||
clientId: 'py_scraper_prod_02',
|
||||
timestamp: '16:09:51',
|
||||
payload: '{"action":"batch_sync","batch_size":50,"duration_ms":82}',
|
||||
},
|
||||
{
|
||||
eventId: 'evt_10477_b3',
|
||||
clientId: 'iot_fleet_east_03',
|
||||
timestamp: '16:09:12',
|
||||
payload: '{"sensor_node":"gw_beta_02","temp_c":22.8,"humidity_pct":61.4,"battery_v":3.30}',
|
||||
},
|
||||
];
|
||||
import { DashboardOverview } from '@/components/sections/DashboardOverview';
|
||||
|
||||
export default function DashboardPage() {
|
||||
const { success, error, info } = useToast();
|
||||
|
||||
// Pre-seed realistic live state immediately to prevent empty voids on initial render
|
||||
const [metrics, setMetrics] = useState<any>({
|
||||
activeSockets: 3,
|
||||
totalClients: 3,
|
||||
activeClients: 3,
|
||||
bufferStats: {
|
||||
currentBufferSize: 18,
|
||||
batchFlushThreshold: 500,
|
||||
batchFlushIntervalMs: 2000,
|
||||
totalIngested: 1438,
|
||||
totalFlushed: 1420,
|
||||
},
|
||||
storageStats: {
|
||||
totalMB: '0.74',
|
||||
totalFiles: 3,
|
||||
totalRows: 1420,
|
||||
},
|
||||
});
|
||||
|
||||
const [recentEvents, setRecentEvents] = useState<EventItem[]>(INITIAL_EVENTS);
|
||||
|
||||
const [storageFiles, setStorageFiles] = useState<any[]>([
|
||||
{ filename: '2026-10-23.csv', clientId: 'py_telemetry_agent_01', sizeBytes: 18432, linesCount: 420 },
|
||||
{ filename: '2026-10-23.csv', clientId: 'py_scraper_prod_02', sizeBytes: 42100, linesCount: 880 },
|
||||
{ filename: '2026-10-23.csv', clientId: 'iot_fleet_east_03', sizeBytes: 12840, linesCount: 120 },
|
||||
]);
|
||||
|
||||
const [simulating, setSimulating] = useState(false);
|
||||
const [flushing, setFlushing] = useState(false);
|
||||
const [inspectModalOpen, setInspectModalOpen] = useState(false);
|
||||
const [inspectEvent, setInspectEvent] = useState<EventItem | null>(null);
|
||||
|
||||
// Sparkline rate values
|
||||
const [throughputBars, setThroughputBars] = useState([
|
||||
18, 24, 20, 38, 45, 32, 60, 52, 68, 58, 75, 70, 62, 54, 48, 64
|
||||
]);
|
||||
|
||||
const fetchMetrics = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/metrics');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setMetrics(data);
|
||||
}
|
||||
const evtRes = await fetch('/api/events?limit=8');
|
||||
if (evtRes.ok) {
|
||||
const evtData = await evtRes.json();
|
||||
if (evtData.events && evtData.events.length > 0) {
|
||||
setRecentEvents(evtData.events);
|
||||
}
|
||||
}
|
||||
const storRes = await fetch('/api/storage');
|
||||
if (storRes.ok) {
|
||||
const storData = await storRes.json();
|
||||
if (storData.files && storData.files.length > 0) {
|
||||
setStorageFiles(storData.files);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// transient network handling
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchMetrics();
|
||||
const interval = setInterval(fetchMetrics, 3000);
|
||||
return () => clearInterval(interval);
|
||||
}, [fetchMetrics]);
|
||||
|
||||
// Tick sparkline bars smoothly
|
||||
useEffect(() => {
|
||||
const t = setInterval(() => {
|
||||
setThroughputBars((prev) => {
|
||||
const nextVal = Math.floor(Math.random() * 40) + 25;
|
||||
return [...prev.slice(1), nextVal];
|
||||
});
|
||||
}, 2000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
|
||||
const handleQuickSimulate = async () => {
|
||||
setSimulating(true);
|
||||
try {
|
||||
const res = await fetch('/api/events', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clientId: 'py_telemetry_agent_01',
|
||||
data: {
|
||||
event: 'crawler_metric',
|
||||
pages_scraped: Math.floor(Math.random() * 50) + 15,
|
||||
latency_ms: Math.floor(Math.random() * 45) + 10,
|
||||
status: 200,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
success('Telemetry Ingested', `Event ${data.event.eventId} buffered to Redis`);
|
||||
fetchMetrics();
|
||||
} else {
|
||||
const errData = await res.json();
|
||||
error('Simulation Failed', errData.error || 'Server error');
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Network Error', err.message);
|
||||
} finally {
|
||||
setSimulating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleManualFlush = async () => {
|
||||
setFlushing(true);
|
||||
try {
|
||||
const res = await fetch('/api/storage', { method: 'POST' });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
success('Buffer Flushed', `Appended ${data.flushedCount} events to rotated CSV files`);
|
||||
fetchMetrics();
|
||||
} else {
|
||||
error('Flush Failed', 'Could not flush buffer to disk');
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Error', err.message);
|
||||
} finally {
|
||||
setFlushing(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5">
|
||||
{/* Top Action Bar */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="w-2 h-2 bg-[var(--success)] inline-block" />
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
Telemetry Overview
|
||||
</h1>
|
||||
<span className="text-[9.5px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1.5 py-0.2 bg-[var(--bg-elevated)]">
|
||||
LIVE INTAKE
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1.5 self-start sm:self-auto">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="RotateCw"
|
||||
onClick={fetchMetrics}
|
||||
>
|
||||
Refresh
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="HardDrive"
|
||||
loading={flushing}
|
||||
onClick={handleManualFlush}
|
||||
>
|
||||
Flush Buffer
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="primary"
|
||||
icon="Play"
|
||||
loading={simulating}
|
||||
onClick={handleQuickSimulate}
|
||||
>
|
||||
Simulate Event
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 4 Compact Metric Cards */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5">
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
|
||||
<span>Ingest Socket</span>
|
||||
<Icon name="Radio" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<div className="flex items-baseline gap-1">
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">:4000</span>
|
||||
<span className="text-[9px] text-[var(--success)] font-mono">Online</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
|
||||
<span>Buffer Queue</span>
|
||||
<Icon name="Cpu" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<div className="flex items-baseline gap-1">
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
{metrics?.bufferStats?.currentBufferSize ?? 18}
|
||||
</span>
|
||||
<span className="text-[9px] text-[var(--text-dim)] font-mono">/ 500</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
|
||||
<span>Total Flushed</span>
|
||||
<Icon name="CheckCircle" size={11} className="text-[var(--success)]" />
|
||||
</div>
|
||||
<div className="flex items-baseline gap-1">
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
{(metrics?.bufferStats?.totalFlushed ?? 1420).toLocaleString()}
|
||||
</span>
|
||||
<span className="text-[9px] text-[var(--text-dim)] font-mono">rows</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] text-[var(--text-dim)] font-medium uppercase tracking-wider">
|
||||
<span>Disk Storage</span>
|
||||
<Icon name="HardDrive" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<div className="flex items-baseline gap-1">
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
{metrics?.storageStats?.totalMB ?? '0.74'}
|
||||
</span>
|
||||
<span className="text-[9px] text-[var(--text-dim)] font-mono">MB ({metrics?.storageStats?.totalFiles ?? 3} files)</span>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Main 2-Column Split Console Workbench (Zero Dead Space) */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-12 gap-2">
|
||||
{/* Left Column (8 cols): Throughput Sparkline & Live Stream Table */}
|
||||
<div className="lg:col-span-8 flex flex-col gap-2">
|
||||
{/* Realtime Throughput Activity Strip */}
|
||||
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Icon name="Activity" size={11} className="text-[var(--accent)]" />
|
||||
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
|
||||
Throughput Rate (events / sec)
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-end gap-1 h-[42px] pt-1 px-1">
|
||||
{throughputBars.map((val, idx) => (
|
||||
<div key={idx} className="flex-1 flex flex-col items-center gap-0.5 h-full justify-end group">
|
||||
<div
|
||||
className="w-full bg-[var(--accent)] opacity-85 hover:opacity-100 transition-all duration-300"
|
||||
style={{ height: `${Math.max(14, val)}%` }}
|
||||
/>
|
||||
<span className="text-[7px] font-mono text-[var(--text-dim)] hidden sm:block">
|
||||
{val}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Recent Buffered Ingestion Events */}
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Icon name="List" size={11} className="text-[var(--accent)]" />
|
||||
<h2 className="text-[11.5px] font-semibold text-[var(--text)]">
|
||||
Live Buffer Stream
|
||||
</h2>
|
||||
</div>
|
||||
<Link href="/vcon/data">
|
||||
<Button size="xs" variant="ghost" icon="ArrowRight" iconPosition="right">
|
||||
Full Stream
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<TableWrap>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Event ID</TableHead>
|
||||
<TableHead>Client ID</TableHead>
|
||||
<TableHead>Time</TableHead>
|
||||
<TableHead>Payload Preview</TableHead>
|
||||
<TableHead className="text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{recentEvents.map((evt, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell className="font-mono text-[9.5px] text-[var(--text)]">
|
||||
{evt.eventId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[9.5px] text-[var(--accent)]">
|
||||
{evt.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[9px]">
|
||||
{evt.timestamp ? (evt.timestamp.includes('T') ? new Date(evt.timestamp).toLocaleTimeString() : evt.timestamp) : 'now'}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[9px] text-[var(--text-muted)] max-w-[200px] sm:max-w-[260px] truncate">
|
||||
{evt.payload}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Maximize2"
|
||||
onClick={() => {
|
||||
setInspectEvent(evt);
|
||||
setInspectModalOpen(true);
|
||||
}}
|
||||
>
|
||||
View
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column (4 cols): Runtime Health, Client SDKs, Disk Partitions */}
|
||||
<div className="lg:col-span-4 flex flex-col gap-2">
|
||||
{/* Process Allocation & Health Card */}
|
||||
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
|
||||
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
|
||||
Runtime Subsystems
|
||||
</span>
|
||||
<span className="text-[8px] font-mono text-[var(--success)] border border-[var(--success)] px-1 py-0.2">
|
||||
Healthy
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-0.5 text-[9.5px] font-mono">
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-medium text-[var(--text)]">Express Socket.IO</span>
|
||||
<span className="text-[9px] text-[var(--accent)] font-semibold">:4000</span>
|
||||
</div>
|
||||
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-medium text-[var(--text)]">Next.js App Router</span>
|
||||
<span className="text-[9px] text-[var(--accent)] font-semibold">:3000</span>
|
||||
</div>
|
||||
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-medium text-[var(--text)]">CSV Disk Worker</span>
|
||||
<span className="text-[9px] text-[var(--success)] font-semibold">Active</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Active SDK Clients Mini Table */}
|
||||
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
|
||||
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
|
||||
Registered Clients
|
||||
</span>
|
||||
<Link href="/vcon/clients" className="text-[8.5px] text-[var(--accent)] hover:underline">
|
||||
Manage
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-0.5 text-[9.5px]">
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-mono text-[var(--text)] text-[9px] truncate">
|
||||
py_telemetry_agent_01
|
||||
</span>
|
||||
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">150 req/s</span>
|
||||
</div>
|
||||
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-mono text-[var(--text)] text-[9px] truncate">
|
||||
py_scraper_prod_02
|
||||
</span>
|
||||
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">200 req/s</span>
|
||||
</div>
|
||||
|
||||
<div className="p-1.5 border border-[var(--border)] bg-[var(--bg-main)] flex items-center justify-between">
|
||||
<span className="font-mono text-[var(--text)] text-[9px] truncate">
|
||||
iot_fleet_east_03
|
||||
</span>
|
||||
<span className="text-[8px] font-mono text-[var(--success)] shrink-0">50 req/s</span>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Quick Storage Partitions Preview */}
|
||||
<Card compact className="p-2 bg-[var(--bg-elevated)] flex flex-col gap-1">
|
||||
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
|
||||
<span className="text-[9.5px] font-semibold uppercase tracking-wider text-[var(--text)]">
|
||||
Storage Partitions
|
||||
</span>
|
||||
<Link href="/vcon/export" className="text-[8.5px] text-[var(--accent)] hover:underline">
|
||||
Export CSV
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-0.5 text-[9px] font-mono">
|
||||
{storageFiles.slice(0, 3).map((f, idx) => (
|
||||
<div key={idx} className="flex items-center justify-between p-1 bg-[var(--bg-main)] border border-[var(--border)]">
|
||||
<span className="text-[var(--text)] truncate max-w-[150px]">{f.clientId}/{f.filename}</span>
|
||||
<span className="text-[var(--text-dim)]">{(f.sizeBytes / 1024).toFixed(1)} KB</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Inspect Event Modal */}
|
||||
<Modal
|
||||
isOpen={inspectModalOpen}
|
||||
onClose={() => setInspectModalOpen(false)}
|
||||
title={`Event: ${inspectEvent?.eventId}`}
|
||||
description={`Origin Client: ${inspectEvent?.clientId}`}
|
||||
footer={
|
||||
<Button variant="secondary" size="sm" onClick={() => setInspectModalOpen(false)}>
|
||||
Close
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{inspectEvent && (
|
||||
<div className="flex flex-col gap-2 font-mono text-[10.5px]">
|
||||
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] flex flex-col gap-1">
|
||||
<div>
|
||||
<span className="text-[var(--text-dim)]">Timestamp: </span>
|
||||
<span className="text-[var(--text)]">{inspectEvent.timestamp}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-[var(--text-dim)]">Client: </span>
|
||||
<span className="text-[var(--accent)]">{inspectEvent.clientId}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-[9.5px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
|
||||
JSON Payload
|
||||
</span>
|
||||
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] overflow-x-auto max-h-[220px]">
|
||||
{(() => {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(inspectEvent.payload), null, 2);
|
||||
} catch {
|
||||
return inspectEvent.payload;
|
||||
}
|
||||
})()}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
return <DashboardOverview />;
|
||||
}
|
||||
+3
-284
@@ -1,286 +1,5 @@
|
||||
'use client';
|
||||
import { DataBrowser } from '@/components/sections';
|
||||
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Input, Select } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import {
|
||||
TableWrap,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
|
||||
interface StreamEvent {
|
||||
clientId: string;
|
||||
eventId: string;
|
||||
timestamp: string;
|
||||
payload: string;
|
||||
}
|
||||
|
||||
export default function LiveDataPage() {
|
||||
const { success, error } = useToast();
|
||||
const [events, setEvents] = useState<StreamEvent[]>([]);
|
||||
const [clients, setClients] = useState<{ clientId: string; name: string }[]>([]);
|
||||
const [selectedClient, setSelectedClient] = useState<string>('all');
|
||||
const [searchQuery, setSearchQuery] = useState<string>('');
|
||||
const [isPaused, setIsPaused] = useState<boolean>(false);
|
||||
const [selectedEvent, setSelectedEvent] = useState<StreamEvent | null>(null);
|
||||
const [modalOpen, setModalOpen] = useState(false);
|
||||
|
||||
const fetchClients = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/clients');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setClients(data.clients || []);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, []);
|
||||
|
||||
const fetchEvents = useCallback(async () => {
|
||||
if (isPaused) return;
|
||||
try {
|
||||
const url = selectedClient !== 'all'
|
||||
? `/api/events?clientId=${encodeURIComponent(selectedClient)}&limit=100`
|
||||
: '/api/events?limit=100';
|
||||
const res = await fetch(url);
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
setEvents(data.events || []);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}, [isPaused, selectedClient]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchClients();
|
||||
}, [fetchClients]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchEvents();
|
||||
const interval = setInterval(fetchEvents, 2000);
|
||||
return () => clearInterval(interval);
|
||||
}, [fetchEvents]);
|
||||
|
||||
const handleSimulate = async () => {
|
||||
try {
|
||||
const targetClientId = selectedClient !== 'all' ? selectedClient : 'py_telemetry_agent_01';
|
||||
const res = await fetch('/api/events', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clientId: targetClientId,
|
||||
data: {
|
||||
source: 'live_stream_simulator',
|
||||
reading: +(Math.random() * 100).toFixed(2),
|
||||
status: 'OK',
|
||||
timestamp_ms: Date.now(),
|
||||
},
|
||||
}),
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
success('Stream Event Emitted', `Event ${data.event.eventId} pushed`);
|
||||
fetchEvents();
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Failed to emit', err.message);
|
||||
}
|
||||
};
|
||||
|
||||
const filteredEvents = events.filter((e) => {
|
||||
if (!searchQuery) return true;
|
||||
const q = searchQuery.toLowerCase();
|
||||
return (
|
||||
e.eventId.toLowerCase().includes(q) ||
|
||||
e.clientId.toLowerCase().includes(q) ||
|
||||
e.payload.toLowerCase().includes(q)
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
Live Stream
|
||||
</h1>
|
||||
|
||||
<div className="flex items-center gap-1.5 self-start sm:self-auto">
|
||||
<Button
|
||||
size="xs"
|
||||
variant={isPaused ? 'primary' : 'secondary'}
|
||||
icon={isPaused ? 'Play' : 'Pause'}
|
||||
onClick={() => setIsPaused((prev) => !prev)}
|
||||
>
|
||||
{isPaused ? 'Resume' : 'Pause'}
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Radio"
|
||||
onClick={handleSimulate}
|
||||
>
|
||||
Emit Event
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filter Toolbar */}
|
||||
<Card compact className="p-2.5 bg-[var(--bg-elevated)] flex flex-wrap items-center justify-between gap-3">
|
||||
<div className="flex flex-wrap items-center gap-2.5 flex-1 min-w-[240px]">
|
||||
<div className="w-[180px]">
|
||||
<Select
|
||||
value={selectedClient}
|
||||
onChange={(e) => setSelectedClient(e.target.value)}
|
||||
>
|
||||
<option value="all">All Clients</option>
|
||||
{clients.map((c) => (
|
||||
<option key={c.clientId} value={c.clientId}>
|
||||
{c.clientId}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 min-w-[160px] max-w-[340px]">
|
||||
<Input
|
||||
placeholder="Search eventId or payload content..."
|
||||
icon="Search"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 text-[11px] font-mono text-[var(--text-dim)]">
|
||||
<span className="flex items-center gap-1.5">
|
||||
<span
|
||||
className={`w-2 h-2 inline-block ${
|
||||
isPaused ? 'bg-[var(--warning)]' : 'bg-[var(--success)] animate-pulse'
|
||||
}`}
|
||||
/>
|
||||
<span>{isPaused ? 'PAUSED' : 'STREAMING'}</span>
|
||||
</span>
|
||||
<span>|</span>
|
||||
<span>{filteredEvents.length} events</span>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Events Table */}
|
||||
<TableWrap>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Event ID</TableHead>
|
||||
<TableHead>Client ID</TableHead>
|
||||
<TableHead>Ingestion Timestamp</TableHead>
|
||||
<TableHead>Payload Preview</TableHead>
|
||||
<TableHead className="text-right">Inspect</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{filteredEvents.length === 0 ? (
|
||||
<TableEmpty
|
||||
colSpan={5}
|
||||
message={
|
||||
isPaused
|
||||
? 'Stream is paused.'
|
||||
: 'No incoming events in memory buffer yet. Click "Emit Event" above or sync via Python SDK.'
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
filteredEvents.map((evt, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--text)]">
|
||||
{evt.eventId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
|
||||
{evt.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[10.5px]">
|
||||
{evt.timestamp}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[10.5px] text-[var(--text-muted)] max-w-[300px] truncate">
|
||||
{evt.payload}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
icon="Maximize2"
|
||||
onClick={() => {
|
||||
setSelectedEvent(evt);
|
||||
setModalOpen(true);
|
||||
}}
|
||||
>
|
||||
Inspect
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
{/* Inspect Event Modal */}
|
||||
<Modal
|
||||
isOpen={modalOpen}
|
||||
onClose={() => setModalOpen(false)}
|
||||
title={`Event Inspector: ${selectedEvent?.eventId}`}
|
||||
description={`Origin Client: ${selectedEvent?.clientId}`}
|
||||
footer={
|
||||
<Button variant="secondary" size="sm" onClick={() => setModalOpen(false)}>
|
||||
Close
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{selectedEvent && (
|
||||
<div className="flex flex-col gap-3 font-mono text-[11px]">
|
||||
<div className="grid grid-cols-2 gap-2 text-[10.5px] p-2 bg-[var(--bg-main)] border border-[var(--border)]">
|
||||
<div>
|
||||
<span className="text-[var(--text-dim)]">Event ID: </span>
|
||||
<span className="text-[var(--text)] font-semibold">{selectedEvent.eventId}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-[var(--text-dim)]">Client: </span>
|
||||
<span className="text-[var(--accent)] font-semibold">{selectedEvent.clientId}</span>
|
||||
</div>
|
||||
<div className="col-span-2">
|
||||
<span className="text-[var(--text-dim)]">Timestamp: </span>
|
||||
<span className="text-[var(--text)]">{selectedEvent.timestamp}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span className="text-[10px] text-[var(--text-dim)] uppercase tracking-wider block mb-1">
|
||||
JSON Payload Structure
|
||||
</span>
|
||||
<pre className="p-3 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] text-[11px] overflow-x-auto max-h-[300px]">
|
||||
{(() => {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(selectedEvent.payload), null, 2);
|
||||
} catch {
|
||||
return selectedEvent.payload;
|
||||
}
|
||||
})()}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
export default function DataPage() {
|
||||
return <DataBrowser />;
|
||||
}
|
||||
+2
-193
@@ -1,196 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Select } from '@/components/ui/Input';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import {
|
||||
TableWrap,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { ExportWorkspace } from '@/components/sections/ExportWorkspace';
|
||||
|
||||
export default function ExportPage() {
|
||||
const { success, info } = useToast();
|
||||
const [clients, setClients] = useState<{ clientId: string; name: string }[]>([]);
|
||||
const [selectedClient, setSelectedClient] = useState<string>('all');
|
||||
const [files, setFiles] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const fetchData = useCallback(async () => {
|
||||
try {
|
||||
const clientRes = await fetch('/api/clients');
|
||||
if (clientRes.ok) {
|
||||
const clientData = await clientRes.json();
|
||||
setClients(clientData.clients || []);
|
||||
}
|
||||
|
||||
const storageRes = await fetch(`/api/storage?clientId=${encodeURIComponent(selectedClient)}`);
|
||||
if (storageRes.ok) {
|
||||
const storageData = await storageRes.json();
|
||||
setFiles(storageData.files || []);
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [selectedClient]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [fetchData]);
|
||||
|
||||
const handleExportAll = () => {
|
||||
const url = `/api/export?clientId=${encodeURIComponent(selectedClient)}`;
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', `${selectedClient}_export.csv`);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
info('Export Initiated', `Streaming CSV download for client ${selectedClient}`);
|
||||
};
|
||||
|
||||
const handleDownloadFile = (clientId: string, filename: string) => {
|
||||
const url = `/api/export?clientId=${encodeURIComponent(clientId)}&filename=${encodeURIComponent(filename)}`;
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.setAttribute('download', filename);
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
success('File Download Started', filename);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
CSV Exporter
|
||||
</h1>
|
||||
|
||||
<Button
|
||||
size="xs"
|
||||
variant="primary"
|
||||
icon="Download"
|
||||
onClick={handleExportAll}
|
||||
className="self-start sm:self-auto"
|
||||
>
|
||||
Download All CSV
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Filter and Endpoint Specs */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-2">
|
||||
<Card compact className="flex flex-col gap-1.5 p-2 bg-[var(--bg-elevated)]">
|
||||
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
|
||||
<CardTitle className="text-[11px]">Filter Scope</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-1.5">
|
||||
<Select
|
||||
value={selectedClient}
|
||||
onChange={(e) => setSelectedClient(e.target.value)}
|
||||
>
|
||||
<option value="all">All Clients</option>
|
||||
{clients.map((c) => (
|
||||
<option key={c.clientId} value={c.clientId}>
|
||||
{c.clientId}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
<div className="text-[9.5px] text-[var(--text-dim)] font-mono">
|
||||
Files: {files.length}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card compact className="md:col-span-2 flex flex-col gap-1 p-2 bg-[var(--bg-elevated)] font-mono text-[10px]">
|
||||
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
|
||||
<CardTitle className="text-[11px]">API Export Endpoint</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-1">
|
||||
<div className="p-1.5 bg-[var(--bg-main)] border border-[var(--border)] flex items-center justify-between">
|
||||
<span className="text-[var(--accent)]">GET /api/export?clientId={selectedClient}</span>
|
||||
<span className="text-[9px] text-[var(--text-dim)]">Stream</span>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Partitioned Files List */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-[13px] font-semibold text-[var(--text)]">
|
||||
Stored CSV Partitions
|
||||
</h2>
|
||||
<span className="text-[10.5px] text-[var(--text-dim)] font-mono">
|
||||
/storage/data/{clientId}/{YYYY-MM-DD}.csv
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<TableWrap>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>File Name</TableHead>
|
||||
<TableHead>Client ID</TableHead>
|
||||
<TableHead>Date Partition</TableHead>
|
||||
<TableHead>Approx. Rows</TableHead>
|
||||
<TableHead>Size (KB)</TableHead>
|
||||
<TableHead>Last Modified</TableHead>
|
||||
<TableHead className="text-right">Action</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.length === 0 ? (
|
||||
<TableEmpty colSpan={7} message="No CSV partitions found for selected client." />
|
||||
) : (
|
||||
files.map((file, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
|
||||
{file.filename}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
|
||||
{file.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px]">
|
||||
{file.date}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px]">
|
||||
{file.linesCount.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px]">
|
||||
{(file.sizeBytes / 1024).toFixed(1)} KB
|
||||
</TableCell>
|
||||
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
|
||||
{new Date(file.modifiedAt).toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<Button
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
icon="Download"
|
||||
onClick={() => handleDownloadFile(file.clientId, file.filename)}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return <ExportWorkspace />;
|
||||
}
|
||||
+5
-1
@@ -1,8 +1,12 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import { MainLayout } from '@/components/layout/MainLayout';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import React from 'react';
|
||||
|
||||
export default function VconLayout({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname();
|
||||
if (pathname === '/vcon/login') return <>{children}</>;
|
||||
|
||||
return <MainLayout showSidebar={true}>{children}</MainLayout>;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { AdminLogin } from '@/components/sections/AdminLogin';
|
||||
|
||||
export default function LoginPage() {
|
||||
return <AdminLogin />;
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card';
|
||||
import { Select } from '@/components/ui/Input';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function SdkGuidePage() {
|
||||
const { success } = useToast();
|
||||
@@ -73,7 +72,7 @@ if client.connect():
|
||||
<div className="flex flex-col gap-4 max-w-[960px]">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
<h1 className="text-[22px] font-semibold text-[var(--text)]">
|
||||
Python SDK
|
||||
</h1>
|
||||
|
||||
@@ -89,8 +88,8 @@ if client.connect():
|
||||
</div>
|
||||
|
||||
{/* Installation Step */}
|
||||
<Card compact className="flex flex-col gap-1.5 font-mono text-[10.5px]">
|
||||
<div className="p-2 bg-[var(--bg-main)] border border-[var(--border)] flex items-center justify-between">
|
||||
<Card compact className="flex flex-col gap-3 font-mono text-[13px]">
|
||||
<div className="p-3 bg-[var(--bg-main)] border border-[var(--border)] flex items-center justify-between">
|
||||
<span className="text-[var(--accent)]">pip install ./sdk-python</span>
|
||||
<Button
|
||||
size="xs"
|
||||
@@ -105,7 +104,7 @@ if client.connect():
|
||||
<Card compact className="flex flex-col gap-2">
|
||||
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 w-full">
|
||||
<CardTitle className="text-[11.5px]">Client Code Example</CardTitle>
|
||||
<CardTitle>Client Code Example</CardTitle>
|
||||
{clients.length > 0 && (
|
||||
<div className="w-[180px]">
|
||||
<Select
|
||||
@@ -126,7 +125,7 @@ if client.connect():
|
||||
|
||||
<CardContent className="p-0 flex flex-col gap-1">
|
||||
<div className="relative">
|
||||
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] text-[10.5px] font-mono overflow-x-auto leading-relaxed">
|
||||
<pre className="p-4 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] text-[12px] font-mono overflow-x-auto leading-relaxed">
|
||||
{pythonSnippet}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
+2
-207
@@ -1,210 +1,5 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Form, FormRow, FormSwitch } from '@/components/ui/Form';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { SettingsWorkspace } from '@/components/sections/SettingsWorkspace';
|
||||
|
||||
export default function SettingsPage() {
|
||||
const { success, error } = useToast();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
// Settings State
|
||||
const [maxEventsPerSec, setMaxEventsPerSec] = useState('100');
|
||||
const [maxPayloadSizeKb, setMaxPayloadSizeKb] = useState('100');
|
||||
const [batchFlushThreshold, setBatchFlushThreshold] = useState('500');
|
||||
const [batchFlushIntervalMs, setBatchFlushIntervalMs] = useState('2000');
|
||||
const [fileRotationMb, setFileRotationMb] = useState('100');
|
||||
const [jwtSecret, setJwtSecret] = useState('datastack-universal-secret-key-2026');
|
||||
const [enableIdempotency, setEnableIdempotency] = useState(true);
|
||||
const [autoPruneDays, setAutoPruneDays] = useState('30');
|
||||
|
||||
useEffect(() => {
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const res = await fetch('/api/settings');
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
const s = data.settings;
|
||||
setMaxEventsPerSec(String(s.maxEventsPerSec ?? 100));
|
||||
setMaxPayloadSizeKb(String(s.maxPayloadSizeKb ?? 100));
|
||||
setBatchFlushThreshold(String(s.batchFlushThreshold ?? 500));
|
||||
setBatchFlushIntervalMs(String(s.batchFlushIntervalMs ?? 2000));
|
||||
setFileRotationMb(String(s.fileRotationMb ?? 100));
|
||||
setJwtSecret(s.jwtSecret ?? 'datastack-universal-secret-key-2026');
|
||||
setEnableIdempotency(Boolean(s.enableIdempotency ?? true));
|
||||
setAutoPruneDays(String(s.autoPruneDays ?? 30));
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
loadSettings();
|
||||
}, []);
|
||||
|
||||
const handleSave = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
const res = await fetch('/api/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
maxEventsPerSec: Number(maxEventsPerSec),
|
||||
maxPayloadSizeKb: Number(maxPayloadSizeKb),
|
||||
batchFlushThreshold: Number(batchFlushThreshold),
|
||||
batchFlushIntervalMs: Number(batchFlushIntervalMs),
|
||||
fileRotationMb: Number(fileRotationMb),
|
||||
jwtSecret,
|
||||
enableIdempotency,
|
||||
autoPruneDays: Number(autoPruneDays),
|
||||
}),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
success('Settings Saved', 'Core engine configuration updated and propagated');
|
||||
} else {
|
||||
error('Save Failed', 'Server rejected configuration payload');
|
||||
}
|
||||
} catch (err: any) {
|
||||
error('Error', err.message);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 max-w-[900px]">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
Settings
|
||||
</h1>
|
||||
|
||||
<Button
|
||||
size="xs"
|
||||
variant="primary"
|
||||
icon="Save"
|
||||
loading={saving}
|
||||
onClick={handleSave}
|
||||
className="self-start sm:self-auto"
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Form onSubmit={handleSave}>
|
||||
{/* Ingestion & Rate Limit Group */}
|
||||
<Card compact className="flex flex-col gap-3">
|
||||
<CardHeader className="p-0 pb-1.5 mb-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon name="Activity" size={14} className="text-[var(--accent)]" />
|
||||
<CardTitle>Throughput & Safety Limits</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-3">
|
||||
<FormRow>
|
||||
<Input
|
||||
label="Global Max Events / Second (Rate Limit)"
|
||||
type="number"
|
||||
min="10"
|
||||
max="10000"
|
||||
value={maxEventsPerSec}
|
||||
onChange={(e) => setMaxEventsPerSec(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Max Payload Size per Event (KB)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="5120"
|
||||
value={maxPayloadSizeKb}
|
||||
onChange={(e) => setMaxPayloadSizeKb(e.target.value)}
|
||||
/>
|
||||
</FormRow>
|
||||
<FormSwitch
|
||||
label="Enable Idempotency Key Deduplication"
|
||||
description="clientId + eventId combinations are rejected within 5-minute TTL window"
|
||||
checked={enableIdempotency}
|
||||
onChange={setEnableIdempotency}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Buffer & CSV Rotation Group */}
|
||||
<Card compact className="flex flex-col gap-3">
|
||||
<CardHeader className="p-0 pb-1.5 mb-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon name="HardDrive" size={14} className="text-[var(--accent)]" />
|
||||
<CardTitle>Redis In-Memory Buffer & CSV Partitioning</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-3">
|
||||
<FormRow>
|
||||
<Input
|
||||
label="Batch Flush Threshold (Row Count)"
|
||||
type="number"
|
||||
min="50"
|
||||
max="5000"
|
||||
value={batchFlushThreshold}
|
||||
onChange={(e) => setBatchFlushThreshold(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Batch Flush Timer Interval (Milliseconds)"
|
||||
type="number"
|
||||
min="500"
|
||||
max="10000"
|
||||
value={batchFlushIntervalMs}
|
||||
onChange={(e) => setBatchFlushIntervalMs(e.target.value)}
|
||||
/>
|
||||
</FormRow>
|
||||
<FormRow>
|
||||
<Input
|
||||
label="File Rotation Threshold (MB)"
|
||||
type="number"
|
||||
min="10"
|
||||
max="1000"
|
||||
value={fileRotationMb}
|
||||
onChange={(e) => setFileRotationMb(e.target.value)}
|
||||
/>
|
||||
<Input
|
||||
label="Log Archive Retention (Days)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="365"
|
||||
value={autoPruneDays}
|
||||
onChange={(e) => setAutoPruneDays(e.target.value)}
|
||||
/>
|
||||
</FormRow>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Security & Token Group */}
|
||||
<Card compact className="flex flex-col gap-3">
|
||||
<CardHeader className="p-0 pb-1.5 mb-1.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<Icon name="Key" size={14} className="text-[var(--accent)]" />
|
||||
<CardTitle>Authentication Secret</CardTitle>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-3">
|
||||
<Input
|
||||
label="JWT Signature Secret Key"
|
||||
type="password"
|
||||
value={jwtSecret}
|
||||
onChange={(e) => setJwtSecret(e.target.value)}
|
||||
/>
|
||||
<div className="text-[10.5px] text-[var(--text-dim)] font-mono">
|
||||
Note: Updating this secret invalidates existing client handshake tokens immediately.
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Form>
|
||||
</div>
|
||||
);
|
||||
return <SettingsWorkspace />;
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card';
|
||||
import { Select, Textarea } from '@/components/ui/Input';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export default function SimulatorPage() {
|
||||
const { success, error } = useToast();
|
||||
@@ -112,7 +111,7 @@ export default function SimulatorPage() {
|
||||
<div className="flex flex-col gap-4 max-w-[960px]">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
<h1 className="text-[22px] font-semibold text-[var(--text)]">
|
||||
Simulator
|
||||
</h1>
|
||||
|
||||
@@ -137,11 +136,11 @@ export default function SimulatorPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
|
||||
<div className="grid grid-cols-1 xl:grid-cols-2 gap-4">
|
||||
{/* Editor Card */}
|
||||
<Card compact className="flex flex-col gap-2 p-2 bg-[var(--bg-elevated)]">
|
||||
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
|
||||
<CardTitle className="text-[11px]">Payload Configuration</CardTitle>
|
||||
<CardTitle>Payload Configuration</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-2">
|
||||
<Select
|
||||
@@ -164,13 +163,13 @@ export default function SimulatorPage() {
|
||||
</Card>
|
||||
|
||||
{/* Response Inspector */}
|
||||
<Card compact className="flex flex-col gap-1.5 p-2 bg-[var(--bg-elevated)] font-mono text-[10px]">
|
||||
<Card compact className="flex flex-col gap-3 bg-[var(--bg-elevated)] font-mono text-[12px]">
|
||||
<CardHeader className="p-0 pb-1 mb-0 border-b-0">
|
||||
<CardTitle className="text-[11px]">Pipeline Response</CardTitle>
|
||||
<CardTitle>Pipeline Response</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 flex flex-col gap-1">
|
||||
{lastResponse ? (
|
||||
<pre className="p-2.5 bg-[var(--bg-main)] border border-[var(--border)] text-[var(--text)] overflow-x-auto max-h-[240px]">
|
||||
<pre className="p-4 bg-[var(--bg-main)] border border-[var(--border)] text-[12px] text-[var(--text)] overflow-x-auto max-h-[320px]">
|
||||
{JSON.stringify(lastResponse, null, 2)}
|
||||
</pre>
|
||||
) : (
|
||||
|
||||
+22
-23
@@ -1,20 +1,19 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import {
|
||||
TableWrap,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableHead,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableWrap,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
export default function StoragePage() {
|
||||
const { success, error } = useToast();
|
||||
@@ -64,7 +63,7 @@ export default function StoragePage() {
|
||||
<div className="flex flex-col gap-4">
|
||||
{/* Header */}
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2 border-b border-[var(--border)] pb-2">
|
||||
<h1 className="text-[14px] font-semibold text-[var(--text)] tracking-tight">
|
||||
<h1 className="text-[22px] font-semibold text-[var(--text)]">
|
||||
CSV Storage
|
||||
</h1>
|
||||
|
||||
@@ -90,31 +89,31 @@ export default function StoragePage() {
|
||||
</div>
|
||||
|
||||
{/* Storage Summary Cards */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-3">
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Disk Usage</span>
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Disk Usage</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalMB ?? '0.00'} MB
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">CSV Files</span>
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">CSV Files</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalFiles ?? 0}
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Persisted Rows</span>
|
||||
<span className="text-[15px] font-semibold text-[var(--text)] font-mono">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Persisted Rows</span>
|
||||
<span className="text-[22px] font-semibold text-[var(--text)] font-mono">
|
||||
{stats?.totalRows ? stats.totalRows.toLocaleString() : 0}
|
||||
</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<span className="text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">Rotation Rule</span>
|
||||
<span className="text-[13px] font-semibold text-[var(--accent)] font-mono">
|
||||
<span className="text-[12px] uppercase text-[var(--text-muted)] font-medium">Rotation Rule</span>
|
||||
<span className="text-[17px] font-semibold text-[var(--accent)] font-mono">
|
||||
100MB / Daily
|
||||
</span>
|
||||
</Card>
|
||||
@@ -122,7 +121,7 @@ export default function StoragePage() {
|
||||
|
||||
{/* Partition Files Table */}
|
||||
<div className="flex flex-col gap-2">
|
||||
<h2 className="text-[13px] font-semibold text-[var(--text)]">
|
||||
<h2 className="text-[17px] font-semibold text-[var(--text)]">
|
||||
CSV Files on Disk
|
||||
</h2>
|
||||
|
||||
@@ -143,19 +142,19 @@ export default function StoragePage() {
|
||||
) : (
|
||||
files.map((file, idx) => (
|
||||
<TableRow key={idx}>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
|
||||
<TableCell className="font-mono text-[12px] text-[var(--accent)]">
|
||||
{file.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] font-medium text-[var(--text)]">
|
||||
<TableCell className="font-mono text-[12px] font-medium text-[var(--text)]">
|
||||
{file.filename}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px]">
|
||||
<TableCell className="font-mono text-[12px]">
|
||||
{(file.sizeBytes / 1024).toFixed(1)} KB
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px]">
|
||||
<TableCell className="font-mono text-[12px]">
|
||||
{file.linesCount.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="text-[10.5px] text-[var(--text-dim)] font-mono">
|
||||
<TableCell className="text-[12px] text-[var(--text-dim)] font-mono">
|
||||
{new Date(file.modifiedAt).toLocaleString()}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
|
||||
interface AdminPageHeaderProps {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
actions?: React.ReactNode;
|
||||
}
|
||||
|
||||
export function AdminPageHeader({ title, subtitle, actions }: AdminPageHeaderProps) {
|
||||
return (
|
||||
<header className="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-base font-medium tracking-tight text-[var(--text)]">{title}</h1>
|
||||
{subtitle && <p className="mt-0.5 text-xs text-[var(--text-muted)]">{subtitle}</p>}
|
||||
</div>
|
||||
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +1,44 @@
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
export const Footer: React.FC = () => {
|
||||
interface FooterProps {
|
||||
isAdmin?: boolean;
|
||||
}
|
||||
|
||||
export const Footer: React.FC<FooterProps> = ({ isAdmin = false }) => {
|
||||
return (
|
||||
<footer className="shrink-0 h-[26px] bg-[var(--bg-activity)] border-t border-[var(--border)] px-3 sm:px-4 flex items-center justify-between text-[10px] text-[var(--text-dim)] select-none">
|
||||
<footer className="shrink-0 min-h-10 bg-[var(--bg-activity)] border-t border-[var(--border)] px-4 sm:px-6 py-2 flex flex-wrap items-center justify-between gap-2 text-[11px] text-[var(--text-dim)] select-none">
|
||||
{isAdmin ? (
|
||||
<>
|
||||
<div className="flex items-center gap-1.5 truncate min-w-0 pr-2">
|
||||
<span className="font-semibold text-[var(--text-muted)] tracking-tight">DataStack</span>
|
||||
<span className="text-[var(--border-strong)]">/</span>
|
||||
<span className="font-mono text-[9px] truncate">
|
||||
<span className="hidden sm:inline font-mono text-[10px] truncate">
|
||||
storage/data/{clientId}/{YYYY-MM-DD}.csv
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 font-mono text-[9.5px] shrink-0 ml-auto">
|
||||
<div className="flex items-center gap-2 font-mono text-[10.5px] shrink-0 ml-auto">
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="w-1.5 h-1.5 bg-[var(--success)] inline-block" />
|
||||
<span className="text-[var(--text-muted)]">:4000</span>
|
||||
</span>
|
||||
<span className="text-[var(--border-strong)]">•</span>
|
||||
<span className="text-[var(--border-strong)]">|</span>
|
||||
<span className="flex items-center gap-1">
|
||||
<span className="w-1.5 h-1.5 bg-[var(--accent)] inline-block" />
|
||||
<span className="text-[var(--text-muted)]">:3000</span>
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span>DataStack · Self-hosted</span>
|
||||
<nav aria-label="Footer navigation" className="flex items-center gap-5">
|
||||
<Link href="#features" className="hover:text-[var(--text-muted)]">Features</Link>
|
||||
<Link href="#sdk" className="hover:text-[var(--text-muted)]">SDK</Link>
|
||||
<Link href="#about" className="hover:text-[var(--text-muted)]">About</Link>
|
||||
</nav>
|
||||
</>
|
||||
)}
|
||||
</footer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
import React, { useState } from 'react';
|
||||
import { Footer } from './Footer';
|
||||
import { Navbar } from './Navbar';
|
||||
import { Sidebar } from './Sidebar';
|
||||
import { Footer } from './Footer';
|
||||
|
||||
interface MainLayoutProps {
|
||||
children: React.ReactNode;
|
||||
@@ -17,24 +18,29 @@ export const MainLayout: React.FC<MainLayoutProps> = ({
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-[var(--bg-main)] text-[var(--text)] antialiased">
|
||||
<div className="min-h-dvh flex flex-col bg-[var(--bg-main)] text-[var(--text)] antialiased">
|
||||
<Navbar
|
||||
showSidebarToggle={showSidebar}
|
||||
onToggleSidebar={() => setSidebarOpen((prev) => !prev)}
|
||||
/>
|
||||
|
||||
<div className="flex-1 flex min-h-0 overflow-hidden">
|
||||
<div className="flex-1 flex min-h-0 min-w-0 overflow-hidden">
|
||||
{showSidebar && (
|
||||
<Sidebar
|
||||
isOpen={sidebarOpen}
|
||||
onClose={() => setSidebarOpen(false)}
|
||||
/>
|
||||
)}
|
||||
<main className="flex-1 overflow-y-auto flex flex-col min-w-0">
|
||||
<div className="flex-1 p-2 sm:p-3.5 max-w-[1360px] w-full mx-auto">
|
||||
<main className="flex-1 min-h-0 overflow-y-auto flex flex-col min-w-0">
|
||||
<div className={cn(
|
||||
'flex-1 min-w-0 w-full mx-auto',
|
||||
showSidebar
|
||||
? 'max-w-[1600px] px-4 py-4 sm:px-6 sm:py-6 xl:px-8 xl:py-7'
|
||||
: 'max-w-[var(--container-width)] px-6 py-0'
|
||||
)}>
|
||||
{children}
|
||||
</div>
|
||||
<Footer />
|
||||
<Footer isAdmin={showSidebar} />
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface NavbarProps {
|
||||
onToggleSidebar?: () => void;
|
||||
@@ -47,58 +47,51 @@ export const Navbar: React.FC<NavbarProps> = ({
|
||||
const isVcon = pathname?.startsWith('/vcon');
|
||||
|
||||
return (
|
||||
<header className="h-[38px] shrink-0 bg-[var(--bg-activity)] border-b border-[var(--border)] px-3 sm:px-4 flex items-center justify-between z-40 select-none">
|
||||
<header className="h-14 shrink-0 bg-[var(--bg-activity)] border-b border-[var(--border)] px-4 sm:px-6 flex items-center justify-between gap-3 z-40 select-none">
|
||||
{/* Left: Mobile hamburger + Brand */}
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
{showSidebarToggle && (
|
||||
<button
|
||||
onClick={onToggleSidebar}
|
||||
className="md:hidden w-[26px] h-[26px] flex items-center justify-center text-[var(--text-muted)] hover:text-[var(--text)] border border-[var(--border)] bg-[var(--bg-elevated)] cursor-pointer"
|
||||
className="lg:hidden w-9 h-9 shrink-0 flex items-center justify-center text-[var(--text-muted)] hover:text-[var(--text)] border border-[var(--border)] bg-[var(--bg-elevated)] cursor-pointer"
|
||||
aria-label="Toggle Navigation"
|
||||
>
|
||||
<Icon name="Menu" size={13} />
|
||||
</button>
|
||||
)}
|
||||
|
||||
<Link href="/" className="flex items-center gap-1.5">
|
||||
<div className="w-[17px] h-[17px] bg-[var(--accent)] text-[var(--text-on-accent)] flex items-center justify-center text-[9.5px] font-bold">
|
||||
DS
|
||||
</div>
|
||||
<span className="text-[12px] font-semibold text-[var(--text)] tracking-tight">
|
||||
<Link href="/" className="flex items-center gap-2 min-w-0 text-[14px] font-medium">
|
||||
<span className="grid h-4 w-4 shrink-0 place-items-center bg-[var(--accent)]">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--bg)]" />
|
||||
</span>
|
||||
<span className="truncate text-[var(--text)]">
|
||||
DataStack
|
||||
</span>
|
||||
<span className="hidden sm:inline text-[9px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1 py-0.2">
|
||||
{isVcon && (
|
||||
<span className="hidden lg:inline text-[11px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1.5 py-1">
|
||||
v2.4
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{/* Middle: Links */}
|
||||
<nav className="hidden sm:flex items-center gap-1 text-[11px]">
|
||||
<Link
|
||||
href="/"
|
||||
className={`px-2.5 py-1 transition-colors border-b-2 ${
|
||||
pathname === '/'
|
||||
? 'border-[var(--accent)] text-[var(--text)] font-medium'
|
||||
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
|
||||
}`}
|
||||
>
|
||||
<nav className="hidden sm:flex items-center gap-6 text-[13px]">
|
||||
{isVcon ? (
|
||||
<>
|
||||
<Link href="/" className="text-[var(--text-muted)] hover:text-[var(--text)]">
|
||||
Overview
|
||||
</Link>
|
||||
<Link
|
||||
href="/vcon/dashboard"
|
||||
className={`px-2.5 py-1 transition-colors border-b-2 flex items-center gap-1.5 ${
|
||||
isVcon
|
||||
? 'border-[var(--accent)] text-[var(--text)] font-medium'
|
||||
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
|
||||
}`}
|
||||
className="px-3 py-2 transition-colors border-b-2 flex items-center gap-2 border-[var(--accent)] text-[var(--text)] font-medium"
|
||||
>
|
||||
<span>Admin Console</span>
|
||||
<span className="w-1.5 h-1.5 bg-[var(--success)] shrink-0" />
|
||||
</Link>
|
||||
<Link
|
||||
href="/vcon/export"
|
||||
className={`px-2.5 py-1 transition-colors border-b-2 ${
|
||||
className={`px-3 py-2 transition-colors border-b-2 ${
|
||||
pathname === '/vcon/export'
|
||||
? 'border-[var(--accent)] text-[var(--text)] font-medium'
|
||||
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'
|
||||
@@ -106,30 +99,40 @@ export const Navbar: React.FC<NavbarProps> = ({
|
||||
>
|
||||
CSV Exporter
|
||||
</Link>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Link href="#features" className="text-[var(--text-muted)] hover:text-[var(--text)]">Features</Link>
|
||||
<Link href="#sdk" className="text-[var(--text-muted)] hover:text-[var(--text)]">SDK</Link>
|
||||
<Link href="#about" className="text-[var(--text-muted)] hover:text-[var(--text)]">About</Link>
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
|
||||
{/* Right: Port Badges + Theme Toggle + Console Action */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<div className="hidden lg:flex items-center gap-1.5 text-[9.5px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-1.5 py-0.5 bg-[var(--bg-main)]">
|
||||
{/* Right: Admin runtime indicators or public feature action */}
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{isVcon && (
|
||||
<div className="hidden xl:flex items-center gap-2 text-[11px] text-[var(--text-dim)] font-mono border border-[var(--border)] px-2.5 py-1.5 bg-[var(--bg-main)]">
|
||||
<span className="w-1.5 h-1.5 bg-[var(--success)] inline-block" />
|
||||
<span>:4000</span>
|
||||
<span className="text-[var(--border-strong)]">|</span>
|
||||
<span className="w-1.5 h-1.5 bg-[var(--accent)] inline-block" />
|
||||
<span>:3000</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
onClick={toggleTheme}
|
||||
aria-label="Toggle Theme"
|
||||
className="w-[26px] h-[26px] flex items-center justify-center border border-[var(--border)] bg-[var(--bg-elevated)] text-[var(--text-muted)] hover:text-[var(--text)] cursor-pointer"
|
||||
className="w-9 h-9 flex items-center justify-center border border-[var(--border)] bg-[var(--bg-elevated)] text-[var(--text-muted)] hover:text-[var(--text)] cursor-pointer"
|
||||
>
|
||||
<Icon name={theme === 'dark' ? 'Sun' : 'Moon'} size={12} />
|
||||
</button>
|
||||
|
||||
{!isVcon && (
|
||||
<Link href="/vcon/dashboard">
|
||||
<Button size="xs" variant="primary" icon="Terminal">
|
||||
/vcon/
|
||||
<Link href="#sdk">
|
||||
<Button size="sm" variant="primary">
|
||||
Read the SDK guide
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { cn } from '@/lib/utils';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
|
||||
interface SidebarProps {
|
||||
isOpen?: boolean;
|
||||
@@ -19,29 +19,42 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
|
||||
const navigation = [
|
||||
{
|
||||
group: 'Core Telemetry',
|
||||
group: 'Monitoring',
|
||||
items: [
|
||||
{ name: 'Dashboard', href: '/vcon/dashboard', icon: 'LayoutDashboard' },
|
||||
{ name: 'Live Data Sync', href: '/vcon/data', icon: 'Activity', badge: 'Live' },
|
||||
{ name: 'CSV Exporter', href: '/vcon/export', icon: 'Download' },
|
||||
],
|
||||
},
|
||||
{
|
||||
group: 'Management',
|
||||
group: 'Data',
|
||||
items: [
|
||||
{ name: 'CSV Exporter', href: '/vcon/export', icon: 'Download' },
|
||||
{ name: 'CSV Storage & Disk', href: '/vcon/storage', icon: 'HardDrive' },
|
||||
],
|
||||
},
|
||||
{
|
||||
group: 'Administration',
|
||||
items: [
|
||||
{ name: 'Client SDKs', href: '/vcon/clients', icon: 'Key' },
|
||||
{ name: 'CSV Storage & Disk', href: '/vcon/storage', icon: 'HardDrive' },
|
||||
{ name: 'Engine Settings', href: '/vcon/settings', icon: 'Sliders' },
|
||||
],
|
||||
},
|
||||
{
|
||||
group: 'Integration',
|
||||
group: 'Developer Tools',
|
||||
items: [
|
||||
{ name: 'Python SDK Guide', href: '/vcon/sdk', icon: 'FileCode2' },
|
||||
{ name: 'Live Simulator', href: '/vcon/simulator', icon: 'Play' },
|
||||
],
|
||||
},
|
||||
];
|
||||
const activeGroup = navigation.find((section) =>
|
||||
section.items.some((item) => item.href === pathname)
|
||||
)?.group;
|
||||
const [openGroup, setOpenGroup] = useState(activeGroup ?? navigation[0].group);
|
||||
|
||||
useEffect(() => {
|
||||
if (activeGroup) setOpenGroup(activeGroup);
|
||||
}, [activeGroup]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -49,28 +62,28 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
{isOpen && (
|
||||
<div
|
||||
onClick={onClose}
|
||||
className="fixed inset-0 z-40 bg-black/60 md:hidden backdrop-blur-[1px]"
|
||||
className="fixed inset-x-0 top-14 bottom-0 z-40 bg-black/50 lg:hidden"
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Sidebar Container */}
|
||||
<aside
|
||||
className={cn(
|
||||
'fixed inset-y-0 left-0 z-50 md:static w-[210px] shrink-0 bg-[var(--bg-sidebar)] border-r border-[var(--border)] flex flex-col transition-transform duration-150 ease-in-out md:translate-x-0',
|
||||
'fixed left-0 top-14 bottom-0 z-50 w-[264px] shrink-0 overflow-hidden bg-[var(--bg-sidebar)] border-r border-[var(--border)] flex flex-col transition-transform duration-150 ease-in-out lg:static lg:w-[264px] lg:translate-x-0',
|
||||
isOpen ? 'translate-x-0' : '-translate-x-full'
|
||||
)}
|
||||
>
|
||||
{/* Top Header */}
|
||||
<div className="h-[38px] px-3 flex items-center justify-between border-b border-[var(--border)] bg-[var(--bg-activity)] shrink-0">
|
||||
<div className="flex items-center gap-1.5 min-w-0">
|
||||
<div className="h-[52px] px-4 flex items-center justify-between border-b border-[var(--border)] bg-[var(--bg-activity)] shrink-0">
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<span className="w-1.5 h-1.5 bg-[var(--accent)] shrink-0" />
|
||||
<span className="text-[10.5px] font-semibold text-[var(--text)] tracking-wider uppercase truncate">
|
||||
<span className="text-[12px] font-semibold text-[var(--text)] uppercase truncate">
|
||||
VCON ADMIN
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className="md:hidden text-[var(--text-dim)] hover:text-[var(--text)] p-1 cursor-pointer"
|
||||
className="lg:hidden text-[var(--text-dim)] hover:text-[var(--text)] p-1 cursor-pointer"
|
||||
aria-label="Close menu"
|
||||
>
|
||||
<Icon name="X" size={13} />
|
||||
@@ -78,13 +91,29 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
</div>
|
||||
|
||||
{/* Navigation items */}
|
||||
<div className="flex-1 overflow-y-auto p-1.5 flex flex-col gap-2">
|
||||
{navigation.map((section, idx) => (
|
||||
<div key={idx} className="flex flex-col gap-0.5">
|
||||
<span className="text-[9px] font-semibold text-[var(--text-dim)] uppercase tracking-wider px-2 py-0.5">
|
||||
{section.group}
|
||||
</span>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<nav aria-label="Admin navigation" className="flex-1 min-h-0 overflow-y-auto p-2.5 flex flex-col">
|
||||
{navigation.map((section) => {
|
||||
const isExpanded = openGroup === section.group;
|
||||
const groupId = `nav-${section.group.toLowerCase().replaceAll(' ', '-')}`;
|
||||
|
||||
return (
|
||||
<div key={section.group} className="border-b border-[var(--border)] last:border-b-0">
|
||||
<button
|
||||
type="button"
|
||||
aria-expanded={isExpanded}
|
||||
aria-controls={groupId}
|
||||
onClick={() => setOpenGroup(isExpanded ? '' : section.group)}
|
||||
className="w-full min-h-[42px] px-3 flex items-center justify-between gap-2 text-left text-[12px] font-medium text-[var(--text-muted)] hover:text-[var(--text)] transition-colors cursor-pointer"
|
||||
>
|
||||
<span className="truncate">{section.group}</span>
|
||||
<Icon
|
||||
name="ChevronDown"
|
||||
size={12}
|
||||
className={cn('transition-transform', isExpanded && 'rotate-180')}
|
||||
/>
|
||||
</button>
|
||||
{isExpanded && (
|
||||
<div id={groupId} className="pb-1.5 flex flex-col gap-1">
|
||||
{section.items.map((item) => {
|
||||
const isActive = pathname === item.href;
|
||||
return (
|
||||
@@ -93,7 +122,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
href={item.href}
|
||||
onClick={onClose}
|
||||
className={cn(
|
||||
'flex items-center justify-between px-2 py-1 text-[11px] transition-colors border',
|
||||
'flex min-h-10 min-w-0 items-center justify-between gap-2 px-3 py-2 text-[13px] transition-colors border',
|
||||
isActive
|
||||
? 'bg-[var(--accent-soft)] text-[var(--accent-hover)] font-medium border-[var(--accent)]'
|
||||
: 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)] hover:bg-[var(--bg-hover)]'
|
||||
@@ -102,13 +131,13 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
<div className="flex items-center gap-2 min-w-0">
|
||||
<Icon
|
||||
name={item.icon}
|
||||
size={12}
|
||||
size={16}
|
||||
className={isActive ? 'text-[var(--accent)]' : 'text-[var(--text-dim)]'}
|
||||
/>
|
||||
<span className="truncate">{item.name}</span>
|
||||
</div>
|
||||
{item.badge && (
|
||||
<span className="text-[8px] px-1 py-0.2 bg-[var(--success-soft)] text-[var(--success)] font-mono border border-[var(--success)] shrink-0">
|
||||
<span className="text-[10px] px-1.5 py-0.5 bg-[var(--success-soft)] text-[var(--success)] font-mono border border-[var(--success)] shrink-0">
|
||||
{item.badge}
|
||||
</span>
|
||||
)}
|
||||
@@ -116,12 +145,14 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
|
||||
{/* Footer info */}
|
||||
<div className="p-2 border-t border-[var(--border)] bg-[var(--bg-main)] text-[9.5px] text-[var(--text-dim)] font-mono flex flex-col gap-1 shrink-0">
|
||||
<div className="p-3 border-t border-[var(--border)] bg-[var(--bg-main)] text-[11px] text-[var(--text-dim)] font-mono flex flex-col gap-1.5 shrink-0">
|
||||
<div className="flex items-center justify-between">
|
||||
<span>Buffer Worker</span>
|
||||
<span className="text-[var(--success)] flex items-center gap-1 font-semibold">
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { FormSwitch } from '@/components/ui/Form';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
function safeNextPath() {
|
||||
const value = new URLSearchParams(window.location.search).get('next');
|
||||
return value && value.startsWith('/') && !value.startsWith('//') && value !== '/vcon/login'
|
||||
? value
|
||||
: '/vcon/dashboard';
|
||||
}
|
||||
|
||||
export function AdminLogin() {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [remember, setRemember] = useState(true);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
const [theme, setTheme] = useState<'dark' | 'light'>('dark');
|
||||
|
||||
useEffect(() => {
|
||||
const savedTheme = localStorage.getItem('datastack-theme');
|
||||
const initialTheme = savedTheme === 'light' ? 'light' : 'dark';
|
||||
setTheme(initialTheme);
|
||||
document.documentElement.classList.toggle('light', initialTheme === 'light');
|
||||
document.documentElement.classList.toggle('dark', initialTheme === 'dark');
|
||||
}, []);
|
||||
|
||||
const toggleTheme = () => {
|
||||
const nextTheme = theme === 'dark' ? 'light' : 'dark';
|
||||
setTheme(nextTheme);
|
||||
localStorage.setItem('datastack-theme', nextTheme);
|
||||
document.documentElement.classList.toggle('light', nextTheme === 'light');
|
||||
document.documentElement.classList.toggle('dark', nextTheme === 'dark');
|
||||
};
|
||||
|
||||
const submit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setErrorMessage('');
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password, remember }),
|
||||
});
|
||||
const body = await response.json();
|
||||
if (!response.ok) throw new Error(body.error || 'Sign in failed.');
|
||||
router.replace(safeNextPath());
|
||||
router.refresh();
|
||||
} catch (submitError) {
|
||||
setErrorMessage(submitError instanceof Error ? submitError.message : 'Unable to sign in.');
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="relative grid min-h-dvh place-items-center bg-[var(--bg)] p-4 text-[var(--text)] sm:p-6">
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon={theme === 'dark' ? 'Sun' : 'Moon'}
|
||||
aria-label="Toggle theme"
|
||||
title="Toggle theme"
|
||||
className="fixed right-4 top-4 z-10 h-7 w-7 border border-[var(--border)] text-[var(--text-muted)]"
|
||||
onClick={toggleTheme}
|
||||
/>
|
||||
<section className="z-0 w-full max-w-xs border border-[var(--border)] bg-[var(--surface)]">
|
||||
<header className="flex flex-col gap-3.5 border-b border-[var(--border)] px-5 pb-4 pt-5">
|
||||
<Link href="/" className="flex items-center gap-2 text-[13px] font-medium text-[var(--text)]">
|
||||
<span className="grid h-3.5 w-3.5 place-items-center bg-[var(--accent)]" aria-hidden="true">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--bg)]" />
|
||||
</span>
|
||||
DataStack
|
||||
<span className="ml-1 border border-[var(--border-strong)] px-1 py-px text-[9px] tracking-wider text-[var(--text-faint)]">CONSOLE</span>
|
||||
</Link>
|
||||
<div>
|
||||
<h1 className="text-[15px] font-medium tracking-tight text-[var(--text)]">Sign in</h1>
|
||||
<p className="mt-0.5 text-xs text-[var(--text-muted)]">Access your admin console</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form onSubmit={submit} className="flex flex-col gap-3 px-5 py-4">
|
||||
{errorMessage && (
|
||||
<div role="alert" className="flex items-start gap-2 border border-[var(--border-strong)] bg-[var(--surface-2)] px-2.5 py-2 text-xs leading-relaxed text-[var(--text-muted)]">
|
||||
<span className="mt-1 h-1.5 w-1.5 shrink-0 bg-[var(--text-muted)]" aria-hidden="true" />
|
||||
<span>{errorMessage}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Input
|
||||
label="Email"
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
placeholder="admin@example.com"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
compact
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
|
||||
<div className="flex flex-col gap-1">
|
||||
<label htmlFor="admin-password" className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">Password</label>
|
||||
<div className="relative">
|
||||
<Input
|
||||
id="admin-password"
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
autoComplete="current-password"
|
||||
placeholder="Enter password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
compact
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 pr-10 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon={showPassword ? 'EyeOff' : 'Eye'}
|
||||
aria-label={showPassword ? 'Hide password' : 'Show password'}
|
||||
title={showPassword ? 'Hide password' : 'Show password'}
|
||||
className="absolute right-0 top-0 h-8 w-8 border-l border-[var(--border)] text-[var(--text-faint)]"
|
||||
onClick={() => setShowPassword((current) => !current)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<FormSwitch label="Remember me" checked={remember} onChange={setRemember} />
|
||||
<span className="shrink-0 text-[11px] text-[var(--text-faint)]">Server-managed access</span>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
variant="primary"
|
||||
size="sm"
|
||||
icon="ArrowRight"
|
||||
iconPosition="right"
|
||||
loading={isSubmitting}
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 h-[34px] w-full justify-center text-[12.5px]"
|
||||
>
|
||||
Sign in
|
||||
</Button>
|
||||
|
||||
<div className="my-0.5 flex items-center gap-2.5 text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
<span className="h-px flex-1 bg-[var(--border)]" />
|
||||
Admin access
|
||||
<span className="h-px flex-1 bg-[var(--border)]" />
|
||||
</div>
|
||||
<p className="text-center text-[11px] leading-relaxed text-[var(--text-faint)]">
|
||||
Credentials are configured by the server operator.
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<footer className="flex items-center justify-between border-t border-[var(--border)] px-5 py-2.5 text-[10.5px] text-[var(--text-faint)]">
|
||||
<span><span className="mr-1.5 inline-block h-1 w-1 bg-[var(--accent)] align-middle" />Protected session</span>
|
||||
<Link href="/" className="text-[var(--text-muted)] hover:text-[var(--text)]">Home <ArrowRight className="inline h-3 w-3" aria-hidden="true" /></Link>
|
||||
</footer>
|
||||
</section>
|
||||
|
||||
<footer className="fixed bottom-3 left-0 right-0 flex items-center justify-center gap-2 text-[10.5px] text-[var(--text-faint)]">
|
||||
<span>DataStack</span>
|
||||
<span className="text-[var(--border-strong)]">·</span>
|
||||
<span>Self-hosted</span>
|
||||
</footer>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
'use client';
|
||||
|
||||
import { Pill } from '@/components/ui/Pill';
|
||||
import { Search } from 'lucide-react';
|
||||
import type { ClientStatusFilter } from './clients/types';
|
||||
|
||||
interface ClientsFiltersProps {
|
||||
search: string;
|
||||
onSearchChange: (value: string) => void;
|
||||
status: ClientStatusFilter;
|
||||
onStatusChange: (status: ClientStatusFilter) => void;
|
||||
counts: Record<ClientStatusFilter, number>;
|
||||
}
|
||||
|
||||
const FILTERS: { key: ClientStatusFilter; label: string }[] = [
|
||||
{ key: 'all', label: 'All' },
|
||||
{ key: 'online', label: 'Online' },
|
||||
{ key: 'offline', label: 'Offline' },
|
||||
{ key: 'pending', label: 'Pending' },
|
||||
];
|
||||
|
||||
export function ClientsFilters({
|
||||
search,
|
||||
onSearchChange,
|
||||
status,
|
||||
onStatusChange,
|
||||
counts,
|
||||
}: ClientsFiltersProps) {
|
||||
return (
|
||||
<div className="mb-3 flex flex-wrap items-center gap-2">
|
||||
<div className="flex h-8 w-full flex-1 items-center gap-1.5 border border-[var(--border)] bg-[var(--surface)] px-2.5 sm:max-w-xs">
|
||||
<Search className="h-3.5 w-3.5 shrink-0 text-[var(--text-faint)]" aria-hidden="true" />
|
||||
<input
|
||||
type="search"
|
||||
aria-label="Search clients"
|
||||
value={search}
|
||||
onChange={(event) => onSearchChange(event.target.value)}
|
||||
placeholder="Search by name or client ID"
|
||||
className="min-w-0 flex-1 bg-transparent text-xs text-[var(--text)] outline-none placeholder:text-[var(--text-faint)]"
|
||||
/>
|
||||
</div>
|
||||
<div className="ml-auto flex min-w-0 gap-1 overflow-x-auto" role="group" aria-label="Filter clients by status">
|
||||
{FILTERS.map((filter) => (
|
||||
<Pill
|
||||
key={filter.key}
|
||||
active={status === filter.key}
|
||||
onClick={() => onStatusChange(filter.key)}
|
||||
>
|
||||
{filter.label}
|
||||
<span className="text-[10px] text-[var(--text-faint)]">
|
||||
{counts[filter.key].toLocaleString()}
|
||||
</span>
|
||||
</Pill>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,475 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Input, Textarea } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableWrap,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
interface Client {
|
||||
clientId: string;
|
||||
name: string;
|
||||
rateLimit: number;
|
||||
status: 'active' | 'revoked';
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
interface ClientCredentials extends Client {
|
||||
secret: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
type ClientFilter = 'all' | 'online' | 'offline' | 'pending';
|
||||
|
||||
function isOnline(client: Client) {
|
||||
return Boolean(
|
||||
client.status === 'active' &&
|
||||
client.lastActive &&
|
||||
Date.now() - new Date(client.lastActive).getTime() < 60_000
|
||||
);
|
||||
}
|
||||
|
||||
function isPending(client: Client) {
|
||||
return client.status === 'active' && !client.lastActive;
|
||||
}
|
||||
|
||||
function relativeTime(timestamp?: string) {
|
||||
if (!timestamp) return 'Never';
|
||||
|
||||
const elapsedSeconds = Math.max(0, Math.floor((Date.now() - new Date(timestamp).getTime()) / 1000));
|
||||
if (elapsedSeconds < 10) return 'Just now';
|
||||
if (elapsedSeconds < 60) return `${elapsedSeconds}s ago`;
|
||||
if (elapsedSeconds < 3600) return `${Math.floor(elapsedSeconds / 60)}m ago`;
|
||||
if (elapsedSeconds < 86_400) return `${Math.floor(elapsedSeconds / 3600)}h ago`;
|
||||
return `${Math.floor(elapsedSeconds / 86_400)}d ago`;
|
||||
}
|
||||
|
||||
export function ClientsManager() {
|
||||
const { success, error, warning } = useToast();
|
||||
const [clients, setClients] = useState<Client[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
const [search, setSearch] = useState('');
|
||||
const [filter, setFilter] = useState<ClientFilter>('all');
|
||||
const [createModalOpen, setCreateModalOpen] = useState(false);
|
||||
const [credentialsModalOpen, setCredentialsModalOpen] = useState(false);
|
||||
const [selectedClient, setSelectedClient] = useState<ClientCredentials | null>(null);
|
||||
const [newClientId, setNewClientId] = useState('');
|
||||
const [newClientName, setNewClientName] = useState('');
|
||||
const [newRateLimit, setNewRateLimit] = useState('100');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const fetchClients = useCallback(async () => {
|
||||
try {
|
||||
const response = await fetch('/api/clients');
|
||||
if (!response.ok) throw new Error('Unable to load clients');
|
||||
const data = await response.json();
|
||||
setClients(data.clients || []);
|
||||
setLoadError('');
|
||||
} catch (fetchError) {
|
||||
setLoadError(fetchError instanceof Error ? fetchError.message : 'Unable to load clients');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchClients();
|
||||
}, [fetchClients]);
|
||||
|
||||
const onlineCount = clients.filter(isOnline).length;
|
||||
const pendingCount = clients.filter(isPending).length;
|
||||
const offlineCount = clients.length - onlineCount - pendingCount;
|
||||
const eventCount = clients.reduce((sum, client) => sum + client.totalEvents, 0);
|
||||
|
||||
const visibleClients = useMemo(() => {
|
||||
const query = search.trim().toLowerCase();
|
||||
|
||||
return clients.filter((client) => {
|
||||
const matchesSearch =
|
||||
!query ||
|
||||
client.clientId.toLowerCase().includes(query) ||
|
||||
client.name.toLowerCase().includes(query);
|
||||
const matchesFilter =
|
||||
filter === 'all' ||
|
||||
(filter === 'online' && isOnline(client)) ||
|
||||
(filter === 'offline' && !isOnline(client) && !isPending(client)) ||
|
||||
(filter === 'pending' && isPending(client));
|
||||
|
||||
return matchesSearch && matchesFilter;
|
||||
});
|
||||
}, [clients, filter, search]);
|
||||
|
||||
const handleCreateClient = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
if (!newClientId.trim() || !newClientName.trim()) {
|
||||
error('Validation error', 'Client ID and client name are required.');
|
||||
return;
|
||||
}
|
||||
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const response = await fetch('/api/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
clientId: newClientId.trim(),
|
||||
name: newClientName.trim(),
|
||||
rateLimit: Number(newRateLimit) || 100,
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Client registration failed');
|
||||
|
||||
setSelectedClient(data.client);
|
||||
setCreateModalOpen(false);
|
||||
setCredentialsModalOpen(true);
|
||||
setNewClientId('');
|
||||
setNewClientName('');
|
||||
setNewRateLimit('100');
|
||||
success('Client registered', `${data.client.clientId} is ready to connect.`);
|
||||
await fetchClients();
|
||||
} catch (submitError) {
|
||||
error('Registration failed', submitError instanceof Error ? submitError.message : 'Unknown error');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleStatus = async (client: Client) => {
|
||||
const status = client.status === 'active' ? 'revoked' : 'active';
|
||||
if (status === 'revoked' && !window.confirm(`Revoke access for ${client.clientId}?`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to update client status');
|
||||
warning('Client status updated', `${client.clientId} is now ${status}.`);
|
||||
await fetchClients();
|
||||
} catch (updateError) {
|
||||
error('Status update failed', updateError instanceof Error ? updateError.message : 'Unknown error');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRotateKey = async (client: Client) => {
|
||||
if (!window.confirm(`Rotate credentials for ${client.clientId}? Existing credentials will stop working.`)) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'regenerate_token' }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to rotate client credentials');
|
||||
setSelectedClient(data.client);
|
||||
setCredentialsModalOpen(true);
|
||||
success('Credentials rotated', `New credentials issued for ${client.clientId}.`);
|
||||
await fetchClients();
|
||||
} catch (rotateError) {
|
||||
error('Credential rotation failed', rotateError instanceof Error ? rotateError.message : 'Unknown error');
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = async (value: string, label: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
success('Copied', `${label} copied to clipboard.`);
|
||||
} catch {
|
||||
error('Copy failed', 'Clipboard access is unavailable in this browser.');
|
||||
}
|
||||
};
|
||||
|
||||
const filters: { id: ClientFilter; label: string; count: number }[] = [
|
||||
{ id: 'all', label: 'All', count: clients.length },
|
||||
{ id: 'online', label: 'Online', count: onlineCount },
|
||||
{ id: 'offline', label: 'Offline', count: offlineCount },
|
||||
{ id: 'pending', label: 'Pending', count: pendingCount },
|
||||
];
|
||||
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-[var(--container-width)] flex-col gap-4">
|
||||
<nav aria-label="Breadcrumb" className="flex items-center gap-1.5 text-xs text-[var(--text-faint)]">
|
||||
<span>Console</span>
|
||||
<span aria-hidden="true" className="text-[var(--border-strong)]">/</span>
|
||||
<span aria-current="page" className="text-[var(--text)]">Clients</span>
|
||||
</nav>
|
||||
<header className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-base font-medium tracking-tight text-[var(--text)]">Clients</h1>
|
||||
<p className="mt-0.5 text-xs text-[var(--text-muted)]">Registered SDK clients and their API access</p>
|
||||
</div>
|
||||
<Button type="button" variant="primary" size="sm" icon="Plus" onClick={() => setCreateModalOpen(true)}>
|
||||
New client
|
||||
</Button>
|
||||
</header>
|
||||
|
||||
<Card compact className="!p-0">
|
||||
<div className="grid grid-cols-2 gap-px bg-[var(--border)] lg:grid-cols-4">
|
||||
<StatCell label="Total clients" value={clients.length.toLocaleString()} />
|
||||
<StatCell label="Online now" value={onlineCount.toLocaleString()} status="online" />
|
||||
<StatCell label="Offline" value={offlineCount.toLocaleString()} status="offline" />
|
||||
<StatCell label="Pending setup" value={pendingCount.toLocaleString()} status="pending" />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||
<Input
|
||||
compact
|
||||
aria-label="Search clients"
|
||||
placeholder="Search by name or client ID"
|
||||
icon="Search"
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
className="bg-[var(--surface)] sm:max-w-xs"
|
||||
/>
|
||||
<div className="flex min-w-0 gap-1 overflow-x-auto sm:ml-auto" role="group" aria-label="Filter clients by status">
|
||||
{filters.map((item) => (
|
||||
<Button
|
||||
key={item.id}
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="secondary"
|
||||
aria-pressed={filter === item.id}
|
||||
className={filter === item.id ? 'border-[var(--border-strong)] bg-[var(--surface-2)] text-[var(--text)]' : 'text-[var(--text-muted)]'}
|
||||
onClick={() => setFilter(item.id)}
|
||||
>
|
||||
{item.label}<span className="text-[var(--text-faint)]">{item.count}</span>
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TableWrap>
|
||||
<Table className="min-w-[760px] text-xs">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>API key</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead className="text-right">Events</TableHead>
|
||||
<TableHead>Last seen</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
<TableEmpty colSpan={6} message="Loading clients..." />
|
||||
) : loadError ? (
|
||||
<TableEmpty colSpan={6} message={loadError} />
|
||||
) : visibleClients.length === 0 ? (
|
||||
<TableEmpty colSpan={6} message={search || filter !== 'all' ? 'No clients match these filters.' : 'No registered SDK clients yet.'} />
|
||||
) : (
|
||||
visibleClients.map((client) => (
|
||||
<TableRow key={client.clientId}>
|
||||
<TableCell>
|
||||
<div className="flex min-w-0 items-center gap-2.5">
|
||||
<span className={`h-1.5 w-1.5 shrink-0 ${client.status === 'active' ? 'bg-[var(--accent)]' : 'bg-[var(--text-faint)]'}`} />
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-[var(--text)]">{client.name}</div>
|
||||
<div className="truncate font-mono text-[11px] text-[var(--text-faint)]">{client.clientId}</div>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[var(--text-muted)]" title="Secret keys are hidden. Rotate credentials to issue a new key.">
|
||||
sec_••••••••
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<span className="inline-flex items-center gap-1.5 text-[var(--text-muted)]">
|
||||
<span className={`h-1.5 w-1.5 ${client.status === 'active' ? 'bg-[var(--accent)]' : 'bg-[var(--text-faint)]'}`} />
|
||||
{client.status}
|
||||
</span>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-[var(--text)]">
|
||||
{client.totalEvents.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--text-muted)]">
|
||||
{relativeTime(client.lastActive)}
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<div className="inline-flex items-center gap-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="Activity"
|
||||
className="h-7 w-7 border border-[var(--border)]"
|
||||
title={`View events for ${client.clientId}`}
|
||||
aria-label={`View events for ${client.clientId}`}
|
||||
onClick={() => window.location.assign(`/vcon/data?clientId=${encodeURIComponent(client.clientId)}`)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="RotateCw"
|
||||
className="h-7 w-7 border border-[var(--border)]"
|
||||
title={`Rotate key for ${client.clientId}`}
|
||||
aria-label={`Rotate key for ${client.clientId}`}
|
||||
onClick={() => handleRotateKey(client)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon={client.status === 'active' ? 'ShieldOff' : 'ShieldCheck'}
|
||||
className="h-7 w-7 border border-[var(--border)]"
|
||||
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
onClick={() => handleToggleStatus(client)}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
<Modal
|
||||
isOpen={createModalOpen}
|
||||
onClose={() => setCreateModalOpen(false)}
|
||||
title="Create client"
|
||||
footer={
|
||||
<>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={() => setCreateModalOpen(false)}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button type="submit" form="create-client-form" variant="primary" size="sm" loading={submitting}>
|
||||
Create client
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="create-client-form" onSubmit={handleCreateClient} className="flex flex-col gap-3">
|
||||
<Input
|
||||
label="Client ID"
|
||||
placeholder="e.g. py_order_service_04"
|
||||
value={newClientId}
|
||||
onChange={(event) => setNewClientId(event.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Client name"
|
||||
placeholder="e.g. Order Service"
|
||||
value={newClientName}
|
||||
onChange={(event) => setNewClientName(event.target.value)}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
label="Rate limit (requests per second)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="5000"
|
||||
value={newRateLimit}
|
||||
onChange={(event) => setNewRateLimit(event.target.value)}
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
isOpen={credentialsModalOpen}
|
||||
onClose={() => setCredentialsModalOpen(false)}
|
||||
title={`Credentials: ${selectedClient?.clientId || ''}`}
|
||||
description="Copy these credentials now. The secret key is only shown after creation or rotation."
|
||||
footer={
|
||||
<Button type="button" variant="secondary" size="sm" onClick={() => setCredentialsModalOpen(false)}>
|
||||
Close
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{selectedClient && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<CredentialField
|
||||
label="Client ID"
|
||||
value={selectedClient.clientId}
|
||||
onCopy={() => copyToClipboard(selectedClient.clientId, 'Client ID')}
|
||||
/>
|
||||
<CredentialField
|
||||
label="Client secret key"
|
||||
value={selectedClient.secret}
|
||||
onCopy={() => copyToClipboard(selectedClient.secret, 'Client secret key')}
|
||||
/>
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<label htmlFor="client-token" className="text-xs uppercase text-[var(--text-faint)]">
|
||||
JWT handshake bearer token
|
||||
</label>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="xs"
|
||||
icon="Copy"
|
||||
onClick={() => copyToClipboard(selectedClient.token, 'JWT token')}
|
||||
>
|
||||
Copy
|
||||
</Button>
|
||||
</div>
|
||||
<Textarea id="client-token" readOnly value={selectedClient.token} rows={4} className="font-mono text-xs text-[var(--accent)]" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function StatCell({
|
||||
label,
|
||||
value,
|
||||
status,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
status?: 'online' | 'offline' | 'pending';
|
||||
}) {
|
||||
return (
|
||||
<div className="bg-[var(--surface)] px-4 py-3">
|
||||
<div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--text-faint)]">{label}</div>
|
||||
<div className="flex items-center gap-2 text-lg font-medium leading-none tracking-tight text-[var(--text)]">
|
||||
{status && (
|
||||
<span className={`h-1.5 w-1.5 ${status === 'online' ? 'bg-[var(--accent)]' : 'bg-[var(--text-faint)]'}`} />
|
||||
)}
|
||||
{value}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CredentialField({
|
||||
label,
|
||||
value,
|
||||
onCopy,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
onCopy: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<label className="text-xs uppercase text-[var(--text-faint)]">{label}</label>
|
||||
<div className="flex min-w-0 items-center justify-between gap-2 border border-[var(--border)] bg-[var(--bg)] p-2.5">
|
||||
<code className="min-w-0 truncate font-mono text-xs text-[var(--text)]">{value}</code>
|
||||
<Button type="button" variant="icon" size="icon" icon="Copy" className="h-7 w-7" title={`Copy ${label}`} aria-label={`Copy ${label}`} onClick={onCopy} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { CopyButton } from '@/components/ui/CopyButton';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableWrap,
|
||||
} from '@/components/ui/Table';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useState } from 'react';
|
||||
import type { ClientCredentials, ClientItem } from './clients/types';
|
||||
|
||||
interface ClientsTableProps {
|
||||
clients: ClientItem[];
|
||||
now: number;
|
||||
onStatusChange: () => Promise<void>;
|
||||
}
|
||||
|
||||
function relativeTime(timestamp: string | undefined, now: number) {
|
||||
if (!timestamp) return 'Never';
|
||||
const seconds = Math.max(0, Math.floor((now - new Date(timestamp).getTime()) / 1000));
|
||||
if (seconds < 10) return 'Just now';
|
||||
if (seconds < 60) return `${seconds}s ago`;
|
||||
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
|
||||
if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h ago`;
|
||||
return `${Math.floor(seconds / 86_400)}d ago`;
|
||||
}
|
||||
|
||||
export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps) {
|
||||
const { success, error } = useToast();
|
||||
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
|
||||
|
||||
const rotateKey = async (client: ClientItem) => {
|
||||
if (!window.confirm(`Rotate credentials for ${client.clientId}? Existing credentials will stop working.`)) return;
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ action: 'regenerate_token' }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to rotate credentials');
|
||||
setCredentials(data.client);
|
||||
success('Credentials rotated', `New credentials issued for ${client.clientId}.`);
|
||||
await onStatusChange();
|
||||
} catch (rotateError) {
|
||||
error('Credential rotation failed', rotateError instanceof Error ? rotateError.message : 'Unknown error');
|
||||
}
|
||||
};
|
||||
|
||||
const toggleStatus = async (client: ClientItem) => {
|
||||
const status = client.status === 'active' ? 'revoked' : 'active';
|
||||
if (status === 'revoked' && !window.confirm(`Revoke access for ${client.clientId}?`)) return;
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Unable to update client status');
|
||||
success('Client status updated', `${client.clientId} is now ${status}.`);
|
||||
await onStatusChange();
|
||||
} catch (statusError) {
|
||||
error('Status update failed', statusError instanceof Error ? statusError.message : 'Unknown error');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableWrap>
|
||||
<Table className="min-w-[760px] text-xs">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>API key</TableHead>
|
||||
<TableHead className="text-right">Events</TableHead>
|
||||
<TableHead>Last seen</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{clients.length === 0 ? (
|
||||
<TableEmpty colSpan={5} message="No clients match these filters." />
|
||||
) : (
|
||||
clients.map((client) => {
|
||||
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)]';
|
||||
|
||||
return (
|
||||
<TableRow key={client.clientId} className="border-b border-[var(--border)] last:border-b-0 hover:bg-[var(--surface-2)]">
|
||||
<TableCell className="px-3.5 py-2.5">
|
||||
<div className="flex min-w-0 items-center gap-2.5">
|
||||
<span className={`h-1.5 w-1.5 shrink-0 ${dotClass}`} title={label} />
|
||||
<div className="min-w-0 leading-tight">
|
||||
<div className="truncate text-[12.5px] text-[var(--text)]">{client.name}</div>
|
||||
<div className="mt-0.5 truncate font-mono text-[10.5px] text-[var(--text-faint)]">{client.clientId}</div>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="px-3.5 py-2.5 font-mono text-[11.5px] text-[var(--text-muted)]" title="Secret keys are hidden. Rotate credentials to issue a new key.">
|
||||
sec_••••••••
|
||||
</TableCell>
|
||||
<TableCell className="px-3.5 py-2.5 text-right font-mono text-[11.5px] text-[var(--text-muted)]">
|
||||
{client.totalEvents.toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell className="px-3.5 py-2.5 font-mono text-[11.5px] text-[var(--text-muted)]">
|
||||
{client.lastActive ? new Date(client.lastActive).toLocaleTimeString([], { hour12: false }) : '—'}
|
||||
<span className="ml-1 font-sans text-[10.5px] text-[var(--text-faint)]">{relativeTime(client.lastActive, now)}</span>
|
||||
</TableCell>
|
||||
<TableCell className="px-3.5 py-2.5 text-right">
|
||||
<div className="inline-flex gap-0.5">
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="Activity"
|
||||
className="h-[26px] w-[26px] border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
||||
title={`View events for ${client.clientId}`}
|
||||
aria-label={`View events for ${client.clientId}`}
|
||||
onClick={() => window.location.assign(`/vcon/data?clientId=${encodeURIComponent(client.clientId)}`)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="RefreshCw"
|
||||
className="h-[26px] w-[26px] border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
||||
title={`Rotate key for ${client.clientId}`}
|
||||
aria-label={`Rotate key for ${client.clientId}`}
|
||||
onClick={() => rotateKey(client)}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon={client.status === 'active' ? 'Trash2' : 'ShieldCheck'}
|
||||
className={`h-[26px] w-[26px] border border-transparent ${client.status === 'active' ? 'hover:border-[var(--danger)] hover:text-[var(--danger)]' : 'hover:border-[var(--border)] hover:bg-[var(--surface-2)]'}`}
|
||||
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
onClick={() => toggleStatus(client)}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
|
||||
<Modal
|
||||
isOpen={Boolean(credentials)}
|
||||
onClose={() => setCredentials(null)}
|
||||
title={`Credentials: ${credentials?.clientId || ''}`}
|
||||
description="Copy the new credentials now. The secret is only shown after rotation."
|
||||
footer={<Button type="button" size="sm" onClick={() => setCredentials(null)}>Close</Button>}
|
||||
>
|
||||
{credentials && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Credential label="Client ID" value={credentials.clientId} />
|
||||
<Credential label="Client secret key" value={credentials.secret} />
|
||||
<Credential label="JWT token" value={credentials.token} />
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Credential({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<span className="text-xs uppercase text-[var(--text-faint)]">{label}</span>
|
||||
<div className="flex min-w-0 items-center justify-between gap-2 border border-[var(--border)] bg-[var(--bg)] p-2.5">
|
||||
<code className="min-w-0 break-all font-mono text-xs text-[var(--text)]">{value}</code>
|
||||
<CopyButton value={value} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { ClientList, type ClientListItem } from '@/components/ui/ClientList';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import { StatCard } from '@/components/ui/StatCard';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableWrap,
|
||||
} from '@/components/ui/Table';
|
||||
import Link from 'next/link';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
type EventItem = {
|
||||
eventId: string;
|
||||
clientId: string;
|
||||
timestamp: string;
|
||||
payload: string;
|
||||
};
|
||||
|
||||
type DashboardMetrics = {
|
||||
activeClients: number;
|
||||
totalClients: number;
|
||||
bufferStats: {
|
||||
currentBufferSize: number;
|
||||
totalFlushed: number;
|
||||
};
|
||||
storageStats: {
|
||||
totalMB: string;
|
||||
totalBytes: number;
|
||||
totalFiles: number;
|
||||
totalRows: number;
|
||||
};
|
||||
};
|
||||
|
||||
type StorageFile = {
|
||||
clientId: string;
|
||||
date: string;
|
||||
filename: string;
|
||||
sizeBytes: number;
|
||||
linesCount: number;
|
||||
};
|
||||
|
||||
export const DashboardOverview: React.FC = () => {
|
||||
const [metrics, setMetrics] = useState<DashboardMetrics | null>(null);
|
||||
const [events, setEvents] = useState<EventItem[]>([]);
|
||||
const [clients, setClients] = useState<ClientListItem[]>([]);
|
||||
const [files, setFiles] = useState<StorageFile[]>([]);
|
||||
const [isRefreshing, setIsRefreshing] = useState(false);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setIsRefreshing(true);
|
||||
try {
|
||||
const [metricsResponse, eventsResponse, storageResponse, clientsResponse] = await Promise.all([
|
||||
fetch('/api/metrics', { cache: 'no-store' }),
|
||||
fetch('/api/events?limit=8', { cache: 'no-store' }),
|
||||
fetch('/api/storage', { cache: 'no-store' }),
|
||||
fetch('/api/clients', { cache: 'no-store' }),
|
||||
]);
|
||||
|
||||
if (metricsResponse.ok) setMetrics(await metricsResponse.json());
|
||||
if (eventsResponse.ok) {
|
||||
const data = await eventsResponse.json();
|
||||
setEvents(data.events ?? []);
|
||||
}
|
||||
if (storageResponse.ok) {
|
||||
const data = await storageResponse.json();
|
||||
setFiles(data.files ?? []);
|
||||
}
|
||||
if (clientsResponse.ok) {
|
||||
const data = await clientsResponse.json();
|
||||
setClients(data.clients ?? []);
|
||||
}
|
||||
} catch {
|
||||
// Keep the last successful dashboard snapshot when one request fails.
|
||||
} finally {
|
||||
setIsRefreshing(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
void refresh();
|
||||
const interval = window.setInterval(() => void refresh(), 5000);
|
||||
return () => window.clearInterval(interval);
|
||||
}, [refresh]);
|
||||
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
const storedRecordsToday = files
|
||||
.filter((file) => file.date === today)
|
||||
.reduce((total, file) => total + file.linesCount, 0);
|
||||
const eventsToday = storedRecordsToday + (metrics?.bufferStats.currentBufferSize ?? 0);
|
||||
const activeClients = metrics?.activeClients ?? clients.filter((client) => client.status === 'active').length;
|
||||
const totalClients = metrics?.totalClients ?? clients.length;
|
||||
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;
|
||||
const storageUnit = totalStorageBytes < 1024 * 1024 ? 'KB' : 'MB';
|
||||
const totalFiles = metrics?.storageStats.totalFiles ?? files.length;
|
||||
const totalRows = metrics?.storageStats.totalRows ?? files.reduce((sum, file) => sum + file.linesCount, 0);
|
||||
|
||||
return (
|
||||
<section className="flex w-full max-w-[var(--console-width)] flex-col gap-4">
|
||||
<header className="flex flex-wrap items-center justify-between gap-4">
|
||||
<div>
|
||||
<nav aria-label="Breadcrumb" className="mb-1 flex items-center gap-2 text-[11px] text-[var(--text-faint)]">
|
||||
<span>Console</span>
|
||||
<span>/</span>
|
||||
<span className="text-[var(--text)]">Dashboard</span>
|
||||
</nav>
|
||||
<h1 className="text-[17px] font-medium text-[var(--text)]">Dashboard</h1>
|
||||
<p className="mt-0.5 text-[12px] text-[var(--text-muted)]">Last 24 hours · UTC</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="mr-2 inline-flex items-center gap-2 text-[10px] uppercase text-[var(--text-muted)]">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--accent)]" />
|
||||
{metrics ? `${metrics.bufferStats.currentBufferSize} buffered` : 'Connecting'}
|
||||
</span>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="secondary"
|
||||
icon="RefreshCw"
|
||||
aria-label="Refresh dashboard"
|
||||
title="Refresh dashboard"
|
||||
loading={isRefreshing}
|
||||
onClick={() => void refresh()}
|
||||
/>
|
||||
<a href="/api/export?clientId=all" download>
|
||||
<Button size="sm" variant="secondary" icon="Download">Quick export</Button>
|
||||
</a>
|
||||
<Link href="/vcon/clients">
|
||||
<Button size="sm" variant="primary" icon="Plus">New client</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<StatCard
|
||||
label="Events today"
|
||||
value={eventsToday.toLocaleString()}
|
||||
meta={`${metrics?.bufferStats.currentBufferSize ?? 0} waiting in buffer`}
|
||||
/>
|
||||
<StatCard
|
||||
label="Active clients"
|
||||
value={`${activeClients} / ${totalClients}`}
|
||||
meta="registered clients"
|
||||
/>
|
||||
<StatCard
|
||||
label="Storage used"
|
||||
value={storageValue}
|
||||
unit={storageUnit}
|
||||
meta="across stored CSV files"
|
||||
/>
|
||||
<StatCard
|
||||
label="Stored rows"
|
||||
value={totalRows.toLocaleString()}
|
||||
meta={`${totalFiles} CSV files`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid min-w-0 grid-cols-1 gap-3 xl:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]">
|
||||
<Panel
|
||||
title="Live ingestion"
|
||||
meta={`${events.length} recent events`}
|
||||
action={<Link href="/vcon/data" className="text-[11px] text-[var(--text-muted)] hover:text-[var(--text)]">View all →</Link>}
|
||||
>
|
||||
<TableWrap className="border-0 bg-transparent">
|
||||
<Table className="min-w-[600px] text-[11.5px]">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Time</TableHead>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead>Payload</TableHead>
|
||||
<TableHead className="text-right">Size</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{events.map((event) => (
|
||||
<TableRow key={event.eventId}>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--text-faint)]">
|
||||
{event.timestamp.includes('T') ? new Date(event.timestamp).toLocaleTimeString() : event.timestamp}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[11px] text-[var(--accent)]">
|
||||
{event.clientId}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-[420px] truncate font-mono text-[11px] text-[var(--text)]">
|
||||
{event.payload}
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono text-[11px] text-[var(--text-faint)]">
|
||||
{new TextEncoder().encode(event.payload).length} B
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
</Panel>
|
||||
|
||||
<div className="flex min-w-0 flex-col gap-3">
|
||||
<Panel
|
||||
title="Recent clients"
|
||||
action={<Link href="/vcon/clients" className="text-[11px] text-[var(--text-muted)] hover:text-[var(--text)]">All →</Link>}
|
||||
>
|
||||
<ClientList clients={clients} limit={4} />
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
title="Storage"
|
||||
meta={`${totalFiles} files`}
|
||||
action={<a href="/api/export?clientId=all" download className="text-[11px] text-[var(--text-muted)] hover:text-[var(--text)]">Quick export ↓</a>}
|
||||
>
|
||||
<div className="divide-y divide-[var(--border)]">
|
||||
{files.slice(0, 3).map((file) => (
|
||||
<div key={`${file.clientId}/${file.filename}`} className="flex items-center justify-between gap-3 px-4 py-2">
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-[12px] text-[var(--text)]">{file.filename}</p>
|
||||
<p className="truncate font-mono text-[10px] text-[var(--text-faint)]">{file.clientId}</p>
|
||||
</div>
|
||||
<span className="shrink-0 font-mono text-[11px] text-[var(--text-muted)]">
|
||||
{(file.sizeBytes / 1024).toFixed(1)} KB
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{files.length === 0 && (
|
||||
<p className="px-4 py-5 text-[12px] text-[var(--text-faint)]">No CSV files yet.</p>
|
||||
)}
|
||||
</div>
|
||||
</Panel>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default DashboardOverview;
|
||||
@@ -0,0 +1,353 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Input, Select } from '@/components/ui/Input';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableEmpty,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableWrap,
|
||||
} from '@/components/ui/Table';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
interface StreamEvent {
|
||||
clientId: string;
|
||||
eventId: string;
|
||||
timestamp: string;
|
||||
payload: string;
|
||||
status: 'stored' | 'buffered';
|
||||
}
|
||||
|
||||
interface Client {
|
||||
clientId: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
const PAGE_SIZE = 12;
|
||||
|
||||
export function DataBrowser() {
|
||||
const [events, setEvents] = useState<StreamEvent[]>([]);
|
||||
const [clients, setClients] = useState<Client[]>([]);
|
||||
const [total, setTotal] = useState(0);
|
||||
const [pageCount, setPageCount] = useState(1);
|
||||
const [clientFilter, setClientFilter] = useState('all');
|
||||
const [fromFilter, setFromFilter] = useState('');
|
||||
const [toFilter, setToFilter] = useState('');
|
||||
const [searchFilter, setSearchFilter] = useState('');
|
||||
const [appliedFilters, setAppliedFilters] = useState({
|
||||
clientId: 'all',
|
||||
from: '',
|
||||
to: '',
|
||||
search: '',
|
||||
});
|
||||
const [page, setPage] = useState(1);
|
||||
const [filtersReady, setFiltersReady] = useState(false);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
|
||||
const fetchEvents = useCallback(async () => {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
clientId: appliedFilters.clientId,
|
||||
from: appliedFilters.from,
|
||||
to: appliedFilters.to,
|
||||
search: appliedFilters.search,
|
||||
page: String(page),
|
||||
pageSize: String(PAGE_SIZE),
|
||||
});
|
||||
const response = await fetch(`/api/data?${params}`);
|
||||
if (!response.ok) throw new Error('Unable to load events');
|
||||
const data = await response.json();
|
||||
setEvents(data.events || []);
|
||||
setTotal(data.total || 0);
|
||||
setPageCount(data.pageCount || 1);
|
||||
setErrorMessage('');
|
||||
} catch (error) {
|
||||
setErrorMessage(error instanceof Error ? error.message : 'Unable to load events');
|
||||
}
|
||||
}, [appliedFilters, page]);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/clients')
|
||||
.then((response) => (response.ok ? response.json() : { clients: [] }))
|
||||
.then((data) => setClients(data.clients || []))
|
||||
.catch(() => setClients([]));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const clientId = new URLSearchParams(window.location.search).get('clientId');
|
||||
if (clientId) {
|
||||
setClientFilter(clientId);
|
||||
setAppliedFilters((current) => ({ ...current, clientId }));
|
||||
}
|
||||
setFiltersReady(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!filtersReady) return;
|
||||
fetchEvents();
|
||||
}, [fetchEvents, filtersReady]);
|
||||
|
||||
const firstVisible = total === 0 ? 0 : (page - 1) * PAGE_SIZE + 1;
|
||||
const lastVisible = Math.min(page * PAGE_SIZE, total);
|
||||
const firstPage = Math.max(1, Math.min(page - 1, pageCount - 2));
|
||||
const visiblePages = Array.from(
|
||||
{ length: Math.min(3, pageCount) },
|
||||
(_, index) => firstPage + index
|
||||
);
|
||||
|
||||
const applyFilters = () => {
|
||||
setAppliedFilters({
|
||||
clientId: clientFilter,
|
||||
from: fromFilter,
|
||||
to: toFilter,
|
||||
search: searchFilter,
|
||||
});
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const resetFilters = () => {
|
||||
setClientFilter('all');
|
||||
setFromFilter('');
|
||||
setToFilter('');
|
||||
setSearchFilter('');
|
||||
setAppliedFilters({ clientId: 'all', from: '', to: '', search: '' });
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const refresh = async () => {
|
||||
setRefreshing(true);
|
||||
await fetchEvents();
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="mx-auto flex w-full max-w-[var(--console-width)] flex-col gap-4">
|
||||
<header className="flex flex-wrap items-center justify-between gap-3">
|
||||
<div>
|
||||
<h1 className="text-base font-medium tracking-[-0.3px] text-[var(--text)]">Data</h1>
|
||||
<p className="mt-0.5 text-xs text-[var(--text-muted)]">Collected events across all clients</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="RefreshCw"
|
||||
className="h-8 w-8 border border-[var(--border)]"
|
||||
title="Refresh events"
|
||||
aria-label="Refresh events"
|
||||
loading={refreshing}
|
||||
onClick={refresh}
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="primary"
|
||||
size="sm"
|
||||
icon="Download"
|
||||
onClick={() => window.location.assign('/vcon/export')}
|
||||
>
|
||||
Export CSV
|
||||
</Button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<Card compact className="!p-0">
|
||||
<div className="grid grid-cols-1 gap-px bg-[var(--border)] sm:grid-cols-2 lg:grid-cols-5">
|
||||
<div className="bg-[var(--surface)] p-3">
|
||||
<Select
|
||||
label="Client"
|
||||
compact
|
||||
value={clientFilter}
|
||||
onChange={(event) => setClientFilter(event.target.value)}
|
||||
>
|
||||
<option value="all">All clients</option>
|
||||
{clients.map((client) => (
|
||||
<option key={client.clientId} value={client.clientId}>
|
||||
{client.name || client.clientId}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-3">
|
||||
<Input
|
||||
label="From"
|
||||
compact
|
||||
type="date"
|
||||
value={fromFilter}
|
||||
onChange={(event) => setFromFilter(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-3">
|
||||
<Input
|
||||
label="To"
|
||||
compact
|
||||
type="date"
|
||||
value={toFilter}
|
||||
onChange={(event) => setToFilter(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="bg-[var(--surface)] p-3">
|
||||
<Input
|
||||
label="Search payload"
|
||||
compact
|
||||
placeholder="e.g. sensor, user_id"
|
||||
icon="Search"
|
||||
value={searchFilter}
|
||||
onChange={(event) => setSearchFilter(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-end justify-end gap-2 bg-[var(--surface)] p-3">
|
||||
<Button type="button" size="xs" icon="X" onClick={resetFilters}>
|
||||
Reset
|
||||
</Button>
|
||||
<Button type="button" size="xs" variant="primary" onClick={applyFilters}>
|
||||
Apply
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Panel
|
||||
title="Events"
|
||||
meta={`${total.toLocaleString()} results · page ${page} of ${pageCount}`}
|
||||
bodyClassName="overflow-hidden"
|
||||
>
|
||||
<TableWrap className="border-0">
|
||||
<Table className="min-w-[760px] text-xs">
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Time</TableHead>
|
||||
<TableHead>Client</TableHead>
|
||||
<TableHead className="hidden sm:table-cell">Event ID</TableHead>
|
||||
<TableHead>Payload</TableHead>
|
||||
<TableHead className="hidden md:table-cell">Size</TableHead>
|
||||
<TableHead className="text-right">Status</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{errorMessage ? (
|
||||
<TableEmpty colSpan={6} message={errorMessage} />
|
||||
) : events.length === 0 ? (
|
||||
<TableEmpty colSpan={6} message="No events match these filters." />
|
||||
) : (
|
||||
events.map((event) => (
|
||||
<TableRow key={event.eventId}>
|
||||
<TableCell className="font-mono text-[var(--text)]">
|
||||
{new Date(event.timestamp).toLocaleTimeString([], {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false,
|
||||
})}
|
||||
</TableCell>
|
||||
<TableCell className="font-mono text-[var(--accent)]">{event.clientId}</TableCell>
|
||||
<TableCell className="hidden font-mono text-[var(--text-faint)] sm:table-cell">
|
||||
{event.eventId}
|
||||
</TableCell>
|
||||
<TableCell className="max-w-0 truncate font-mono text-[var(--text)]">
|
||||
{event.payload}
|
||||
</TableCell>
|
||||
<TableCell className="hidden font-mono md:table-cell">
|
||||
{new TextEncoder().encode(event.payload).length} 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>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableWrap>
|
||||
<footer className="flex flex-wrap items-center justify-between gap-3 border-t border-[var(--border)] px-4 py-2.5">
|
||||
<p className="text-xs text-[var(--text-muted)]">
|
||||
Showing <strong className="font-medium text-[var(--text)]">{firstVisible}–{lastVisible}</strong> of{' '}
|
||||
<strong className="font-medium text-[var(--text)]">{total.toLocaleString()}</strong> events
|
||||
</p>
|
||||
<nav className="flex items-center gap-1" aria-label="Event pages">
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="ChevronLeft"
|
||||
className="h-7 w-7 border border-[var(--border)]"
|
||||
aria-label="Previous page"
|
||||
disabled={page <= 1}
|
||||
onClick={() => setPage((current) => Math.max(1, current - 1))}
|
||||
/>
|
||||
{firstPage > 1 && (
|
||||
<>
|
||||
<PageButton pageNumber={1} active={page === 1} onSelect={setPage} />
|
||||
{firstPage > 2 && <span className="px-1 text-xs text-[var(--text-faint)]">…</span>}
|
||||
</>
|
||||
)}
|
||||
{visiblePages.map((pageNumber) => (
|
||||
<PageButton
|
||||
key={pageNumber}
|
||||
pageNumber={pageNumber}
|
||||
active={page === pageNumber}
|
||||
onSelect={setPage}
|
||||
/>
|
||||
))}
|
||||
{firstPage + visiblePages.length - 1 < pageCount && (
|
||||
<>
|
||||
{firstPage + visiblePages.length < pageCount && (
|
||||
<span className="px-1 text-xs text-[var(--text-faint)]">…</span>
|
||||
)}
|
||||
<PageButton
|
||||
pageNumber={pageCount}
|
||||
active={page === pageCount}
|
||||
onSelect={setPage}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon="ChevronRight"
|
||||
className="h-7 w-7 border border-[var(--border)]"
|
||||
aria-label="Next page"
|
||||
disabled={page >= pageCount}
|
||||
onClick={() => setPage((current) => Math.min(pageCount, current + 1))}
|
||||
/>
|
||||
</nav>
|
||||
</footer>
|
||||
</Panel>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function PageButton({
|
||||
pageNumber,
|
||||
active,
|
||||
onSelect,
|
||||
}: {
|
||||
pageNumber: number;
|
||||
active: boolean;
|
||||
onSelect: (page: number) => void;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
aria-current={active ? 'page' : undefined}
|
||||
className={`grid h-7 min-w-7 place-items-center border px-2 text-xs transition-colors ${
|
||||
active
|
||||
? 'border-[var(--border-strong)] bg-[var(--surface-2)] text-[var(--text)]'
|
||||
: 'border-[var(--border)] text-[var(--text-muted)] hover:bg-[var(--surface-2)] hover:text-[var(--text)]'
|
||||
}`}
|
||||
onClick={() => onSelect(pageNumber)}
|
||||
>
|
||||
{pageNumber}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
'use client';
|
||||
|
||||
import { AdminPageHeader } from '@/components/layout/AdminPageHeader';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Input, Select } from '@/components/ui/Input';
|
||||
import { Panel } from '@/components/ui/Panel';
|
||||
import { Pill } from '@/components/ui/Pill';
|
||||
import { StatStrip } from '@/components/ui/StatStrip';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { Braces, FileText, Info } from 'lucide-react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
interface Client {
|
||||
clientId: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface StorageFile {
|
||||
clientId: string;
|
||||
date: string;
|
||||
filename: string;
|
||||
sizeBytes: number;
|
||||
linesCount: number;
|
||||
modifiedAt: string;
|
||||
}
|
||||
|
||||
type ExportFormat = 'csv' | 'json';
|
||||
type RangePreset = 'today' | '7d' | '30d' | 'all' | 'custom';
|
||||
|
||||
function dateString(date: Date) {
|
||||
return date.toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number) {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 ** 2) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
if (bytes < 1024 ** 3) return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
|
||||
return `${(bytes / 1024 ** 3).toFixed(1)} GB`;
|
||||
}
|
||||
|
||||
function relativeTime(value: string, now: number) {
|
||||
const elapsedSeconds = Math.max(0, Math.floor((now - new Date(value).getTime()) / 1000));
|
||||
if (elapsedSeconds < 60) return `${elapsedSeconds}s ago`;
|
||||
if (elapsedSeconds < 3600) return `${Math.floor(elapsedSeconds / 60)}m ago`;
|
||||
if (elapsedSeconds < 86_400) return `${Math.floor(elapsedSeconds / 3600)}h ago`;
|
||||
return `${Math.floor(elapsedSeconds / 86_400)}d ago`;
|
||||
}
|
||||
|
||||
export function ExportWorkspace() {
|
||||
const { error, info } = useToast();
|
||||
const [clients, setClients] = useState<Client[]>([]);
|
||||
const [files, setFiles] = useState<StorageFile[]>([]);
|
||||
const [selectedClient, setSelectedClient] = useState('all');
|
||||
const [fromDate, setFromDate] = useState('');
|
||||
const [toDate, setToDate] = useState('');
|
||||
const [format, setFormat] = useState<ExportFormat>('csv');
|
||||
const [preset, setPreset] = useState<RangePreset>('today');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadError, setLoadError] = useState('');
|
||||
const [now, setNow] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const today = dateString(new Date());
|
||||
setFromDate(today);
|
||||
setToDate(today);
|
||||
|
||||
Promise.all([
|
||||
fetch('/api/clients').then(async (response) => {
|
||||
if (!response.ok) throw new Error('Unable to load clients');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/storage').then(async (response) => {
|
||||
if (!response.ok) throw new Error('Unable to load stored files');
|
||||
return response.json();
|
||||
}),
|
||||
])
|
||||
.then(([clientData, storageData]) => {
|
||||
setClients(clientData.clients || []);
|
||||
setFiles(storageData.files || []);
|
||||
setLoadError('');
|
||||
})
|
||||
.catch((fetchError) => {
|
||||
setLoadError(fetchError instanceof Error ? fetchError.message : 'Unable to load export data');
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const updateClock = () => setNow(Date.now());
|
||||
updateClock();
|
||||
const interval = setInterval(updateClock, 30_000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
const filteredFiles = useMemo(() => files.filter((file) =>
|
||||
(selectedClient === 'all' || file.clientId === selectedClient) &&
|
||||
(!fromDate || file.date >= fromDate) &&
|
||||
(!toDate || file.date <= toDate)
|
||||
), [files, fromDate, selectedClient, toDate]);
|
||||
|
||||
const preview = useMemo(() => ({
|
||||
rows: filteredFiles.reduce((total, file) => total + file.linesCount, 0),
|
||||
bytes: filteredFiles.reduce((total, file) => total + file.sizeBytes, 0),
|
||||
files: filteredFiles.length,
|
||||
}), [filteredFiles]);
|
||||
|
||||
const stats = useMemo(() => ({
|
||||
rows: files.reduce((total, file) => total + file.linesCount, 0),
|
||||
bytes: files.reduce((total, file) => total + file.sizeBytes, 0),
|
||||
clients: new Set(files.map((file) => file.clientId)).size,
|
||||
}), [files]);
|
||||
|
||||
const sortedRecentFiles = useMemo(() => [...files]
|
||||
.sort((left, right) => new Date(right.modifiedAt).getTime() - new Date(left.modifiedAt).getTime())
|
||||
.slice(0, 6), [files]);
|
||||
|
||||
const setQuickRange = (nextPreset: Exclude<RangePreset, 'custom'>) => {
|
||||
setPreset(nextPreset);
|
||||
if (nextPreset === 'all') {
|
||||
setFromDate('');
|
||||
setToDate('');
|
||||
return;
|
||||
}
|
||||
|
||||
const today = new Date();
|
||||
const start = new Date(today);
|
||||
if (nextPreset === '7d') start.setDate(today.getDate() - 6);
|
||||
if (nextPreset === '30d') start.setDate(today.getDate() - 29);
|
||||
setFromDate(dateString(start));
|
||||
setToDate(dateString(today));
|
||||
};
|
||||
|
||||
const exportUrl = useMemo(() => {
|
||||
const params = new URLSearchParams({ clientId: selectedClient, format });
|
||||
if (fromDate) params.set('from', fromDate);
|
||||
if (toDate) params.set('to', toDate);
|
||||
return `/api/export?${params.toString()}`;
|
||||
}, [format, fromDate, selectedClient, toDate]);
|
||||
|
||||
const downloadExport = () => {
|
||||
if (fromDate && toDate && fromDate > toDate) {
|
||||
error('Invalid date range', 'The start date must be on or before the end date.');
|
||||
return;
|
||||
}
|
||||
window.location.assign(exportUrl);
|
||||
info('Export started', `${format.toUpperCase()} download for ${preview.rows.toLocaleString()} rows.`);
|
||||
};
|
||||
|
||||
const downloadFile = (file: StorageFile) => {
|
||||
window.location.assign(
|
||||
`/api/export?clientId=${encodeURIComponent(file.clientId)}&filename=${encodeURIComponent(file.filename)}`
|
||||
);
|
||||
};
|
||||
|
||||
const rangeChanged = (setter: (value: string) => void, value: string) => {
|
||||
setter(value);
|
||||
setPreset('custom');
|
||||
};
|
||||
|
||||
const resetExport = () => {
|
||||
setSelectedClient('all');
|
||||
setFormat('csv');
|
||||
setQuickRange('all');
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-[var(--container-width)]">
|
||||
<nav aria-label="Breadcrumb" className="mb-3 flex items-center gap-1.5 text-xs text-[var(--text-faint)]">
|
||||
<span>Console</span>
|
||||
<span aria-hidden="true" className="text-[var(--border-strong)]">/</span>
|
||||
<span aria-current="page" className="text-[var(--text)]">Export</span>
|
||||
</nav>
|
||||
<AdminPageHeader title="Export" subtitle="Generate CSV or JSON exports from collected data" />
|
||||
|
||||
<StatStrip
|
||||
items={[
|
||||
{ label: 'Stored files', value: files.length.toLocaleString() },
|
||||
{ label: 'Stored rows', value: stats.rows.toLocaleString() },
|
||||
{ label: 'Storage used', value: formatBytes(stats.bytes) },
|
||||
{ label: 'Clients', value: stats.clients.toLocaleString() },
|
||||
]}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-1 items-start gap-3 xl:grid-cols-5">
|
||||
<Panel title="Export builder" meta="Estimate updates on change" bodyClassName="flex flex-col gap-4 p-4" className="min-w-0 xl:col-span-3">
|
||||
<div className="flex flex-wrap items-center gap-1">
|
||||
<span className="mr-1.5 text-[10px] uppercase tracking-wider text-[var(--text-faint)]">Quick range</span>
|
||||
{([
|
||||
['today', 'Today'],
|
||||
['7d', 'Last 7d'],
|
||||
['30d', 'Last 30d'],
|
||||
['all', 'All'],
|
||||
] as const).map(([id, label]) => (
|
||||
<Pill key={id} active={preset === id} onClick={() => setQuickRange(id)}>{label}</Pill>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 gap-px border border-[var(--border)] bg-[var(--border)] md:grid-cols-[1.2fr_1fr_1fr]">
|
||||
<div className="min-w-0 bg-[var(--surface)] p-3">
|
||||
<Select
|
||||
label="Client"
|
||||
compact
|
||||
value={selectedClient}
|
||||
onChange={(event) => setSelectedClient(event.target.value)}
|
||||
className="border-0 bg-transparent px-0 focus:border-transparent"
|
||||
>
|
||||
<option value="all">All clients</option>
|
||||
{clients.map((client) => <option key={client.clientId} value={client.clientId}>{client.name}</option>)}
|
||||
</Select>
|
||||
</div>
|
||||
<div className="min-w-0 bg-[var(--surface)] p-3">
|
||||
<Input label="From" compact type="date" value={fromDate} onChange={(event) => rangeChanged(setFromDate, event.target.value)} className="border-0 bg-transparent px-0 focus:border-transparent" />
|
||||
</div>
|
||||
<div className="min-w-0 bg-[var(--surface)] p-3">
|
||||
<Input label="To" compact type="date" value={toDate} onChange={(event) => rangeChanged(setToDate, event.target.value)} className="border-0 bg-transparent px-0 focus:border-transparent" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<fieldset className="flex flex-col gap-2">
|
||||
<legend className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">Format</legend>
|
||||
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2" role="radiogroup" aria-label="Export format">
|
||||
<FormatOption value="csv" selected={format === 'csv'} label="CSV" hint="Comma-separated values" onSelect={setFormat} />
|
||||
<FormatOption value="json" selected={format === 'json'} label="JSON" hint="Structured array" onSelect={setFormat} />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">Preview</span>
|
||||
<div className="flex flex-wrap items-center gap-x-2 gap-y-1 border border-l-2 border-[var(--border)] border-l-[var(--accent)] bg-[var(--surface-2)] px-3 py-2 font-mono text-xs text-[var(--text-muted)]">
|
||||
<Info className="h-3.5 w-3.5 text-[var(--accent)]" aria-hidden="true" />
|
||||
<span><strong className="font-medium text-[var(--text)]">{preview.rows.toLocaleString()}</strong> rows</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<span><strong className="font-medium text-[var(--text)]">~{formatBytes(preview.bytes)}</strong> source size</span>
|
||||
<span aria-hidden="true">·</span>
|
||||
<span><strong className="font-medium text-[var(--text)]">{preview.files}</strong> files</span>
|
||||
</div>
|
||||
{loadError && <p role="alert" className="text-xs text-[var(--text-muted)]">{loadError}</p>}
|
||||
{fromDate && toDate && fromDate > toDate && (
|
||||
<p role="alert" className="text-xs text-[var(--text-muted)]">Start date must be on or before end date.</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center justify-end gap-2 border-t border-[var(--border)] pt-3">
|
||||
<Button type="button" size="xs" onClick={resetExport}>Reset</Button>
|
||||
<Button type="button" variant="primary" size="xs" icon="Download" disabled={loading || Boolean(fromDate && toDate && fromDate > toDate)} onClick={downloadExport}>
|
||||
Download {format.toUpperCase()}
|
||||
</Button>
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
title="Recent exports"
|
||||
action={<a href="/vcon/storage" className="text-xs text-[var(--text-muted)] hover:text-[var(--text)]">View all</a>}
|
||||
bodyClassName="divide-y divide-[var(--border)]"
|
||||
className="min-w-0 xl:col-span-2"
|
||||
>
|
||||
{loading ? (
|
||||
<p className="px-4 py-5 text-xs text-[var(--text-faint)]">Loading stored files...</p>
|
||||
) : sortedRecentFiles.length === 0 ? (
|
||||
<p className="px-4 py-5 text-xs text-[var(--text-faint)]">No stored files available to export.</p>
|
||||
) : (
|
||||
sortedRecentFiles.map((file) => (
|
||||
<div key={`${file.clientId}/${file.filename}`} className="flex items-center gap-2.5 px-3.5 py-2.5 transition-colors hover:bg-[var(--surface-2)]">
|
||||
<span className="shrink-0 border border-[var(--border-strong)] px-1.5 py-0.5 font-mono text-[9px] uppercase tracking-wider text-[var(--text-muted)]">CSV</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate font-mono text-xs text-[var(--text)]">{file.filename}</div>
|
||||
<div className="mt-0.5 truncate text-[10.5px] text-[var(--text-faint)]">
|
||||
{file.clientId} · {relativeTime(file.modifiedAt, now)} · {file.linesCount.toLocaleString()} rows · {formatBytes(file.sizeBytes)}
|
||||
</div>
|
||||
</div>
|
||||
<Button type="button" variant="icon" size="icon" icon="Download" className="h-6 w-6 shrink-0" aria-label={`Download ${file.filename}`} title={`Download ${file.filename}`} onClick={() => downloadFile(file)} />
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</Panel>
|
||||
</div>
|
||||
|
||||
<p className="mt-2 text-[11px] text-[var(--text-faint)]">
|
||||
Exports are generated from CSV files on disk · Estimates are approximate · Large downloads are streamed
|
||||
</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function FormatOption({
|
||||
value,
|
||||
selected,
|
||||
label,
|
||||
hint,
|
||||
onSelect,
|
||||
}: {
|
||||
value: ExportFormat;
|
||||
selected: boolean;
|
||||
label: string;
|
||||
hint: string;
|
||||
onSelect: (value: ExportFormat) => void;
|
||||
}) {
|
||||
const FormatIcon = value === 'csv' ? FileText : Braces;
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={selected}
|
||||
className={`flex min-w-0 items-center gap-2.5 border px-3 py-2.5 text-left transition-colors ${selected ? 'border-[var(--border-strong)] bg-[var(--surface-2)]' : 'border-[var(--border)] hover:border-[var(--border-strong)]'}`}
|
||||
onClick={() => onSelect(value)}
|
||||
>
|
||||
<span className={`grid h-7 w-7 shrink-0 place-items-center border ${selected ? 'border-[var(--border-strong)] text-[var(--accent)]' : 'border-[var(--border)] text-[var(--text-muted)]'}`}>
|
||||
<FormatIcon className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
</span>
|
||||
<span className="min-w-0">
|
||||
<span className="block text-xs font-medium leading-tight text-[var(--text)]">{label}</span>
|
||||
<span className="mt-0.5 block truncate text-[10.5px] text-[var(--text-faint)]">{hint}</span>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -1,66 +1,26 @@
|
||||
import { FeatureItem } from '@/components/ui/FeatureItem';
|
||||
import { SectionHeading } from '@/components/ui/SectionHeading';
|
||||
import React from 'react';
|
||||
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
|
||||
export const Features: React.FC = () => {
|
||||
const items = [
|
||||
{
|
||||
icon: 'Zap',
|
||||
title: 'Decoupled Runtime Split',
|
||||
desc: 'Port 4000 WebSocket intake; Port 3000 Web & export.',
|
||||
},
|
||||
{
|
||||
icon: 'HardDrive',
|
||||
title: 'CSV File Persistence',
|
||||
desc: 'Streams directly to rotated CSV files on disk (Zero DB inserts).',
|
||||
},
|
||||
{
|
||||
icon: 'ShieldCheck',
|
||||
title: 'JWT SDK Authentication',
|
||||
desc: 'Signed tokens verify client IDs and rate limits on handshake.',
|
||||
},
|
||||
{
|
||||
icon: 'Cpu',
|
||||
title: 'In-Memory Buffer',
|
||||
desc: 'Aggregates 500 records or 2000ms intervals before async disk flush.',
|
||||
},
|
||||
{
|
||||
icon: 'CheckCheck',
|
||||
title: 'Idempotency Dedup',
|
||||
desc: 'Rejects duplicate clientId + eventId in 5-minute sliding TTL window.',
|
||||
},
|
||||
{
|
||||
icon: 'FileCode2',
|
||||
title: 'Python Client SDK',
|
||||
desc: 'datastack-sdk package with auto-reconnection and batch streaming.',
|
||||
},
|
||||
{ icon: 'Activity', title: 'Realtime over WebSocket', description: 'Durable connections. No polling or repeated API calls.' },
|
||||
{ icon: 'HardDrive', title: 'CSV-first storage', description: 'Compact per-day records that stay simple to export.' },
|
||||
{ icon: 'ShieldCheck', title: 'Verified sources', description: 'Each registered client is checked before sending activity.' },
|
||||
{ icon: 'Layers3', title: 'Buffered writes', description: 'Batch incoming events to keep collection steady.' },
|
||||
{ icon: 'ChartNoAxesCombined', title: 'Live dashboard', description: 'Watch activity arrive and filter by source or content.' },
|
||||
{ icon: 'Download', title: 'One-click export', description: 'Download the records you need without blocking the workflow.' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5 py-1">
|
||||
<div className="flex items-center justify-between border-b border-[var(--border)] pb-1">
|
||||
<h2 className="text-[11px] font-semibold text-[var(--text)] uppercase tracking-wider">
|
||||
Platform Architecture
|
||||
</h2>
|
||||
<span className="text-[9px] text-[var(--text-dim)] font-mono">6 SUBSYSTEMS</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-1.5">
|
||||
{items.map((item, idx) => (
|
||||
<Card key={idx} compact className="flex flex-col gap-0.5 p-2">
|
||||
<CardHeader className="p-0 pb-0.5 mb-0 border-b-0 flex items-center gap-1.5">
|
||||
<div className="p-0.5 bg-[var(--bg-main)] text-[var(--accent)] border border-[var(--border-strong)] shrink-0">
|
||||
<Icon name={item.icon} size={11} />
|
||||
</div>
|
||||
<CardTitle className="text-[11px]">{item.title}</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-0 text-[10px] text-[var(--text-muted)] leading-tight">
|
||||
{item.desc}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<section id="features" className="border-b border-[var(--border)] py-10">
|
||||
<SectionHeading index="01" label="Features" title="Built for ingestion at scale." />
|
||||
<div className="grid grid-cols-1 gap-px border border-[var(--border)] bg-[var(--border)] sm:grid-cols-2 lg:grid-cols-3">
|
||||
{items.map((item) => (
|
||||
<FeatureItem key={item.title} {...item} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,90 +1,31 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { ActivityPreview } from '@/components/ui/ActivityPreview';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
export const Hero: React.FC = () => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const handleCopy = () => {
|
||||
navigator.clipboard.writeText('pip install ./sdk-python');
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 py-1">
|
||||
{/* Title */}
|
||||
<div className="flex flex-col gap-1">
|
||||
<h1 className="text-[16px] sm:text-[18px] font-semibold tracking-tight text-[var(--text)]">
|
||||
Realtime Data Collection Platform
|
||||
export const Hero: React.FC = () => (
|
||||
<section aria-labelledby="hero-title" className="border-b border-[var(--border)] py-10 sm:py-14">
|
||||
<span className="mb-5 inline-flex items-center gap-2 border border-[var(--border-strong)] px-2.5 py-1 text-[11px] uppercase text-[var(--text-muted)]">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--accent)]" />
|
||||
Self-hosted event collection
|
||||
</span>
|
||||
<h1 id="hero-title" className="mb-4 max-w-[640px] text-[28px] font-medium leading-tight text-[var(--text)] sm:text-[36px]">
|
||||
Realtime data collection,<br />
|
||||
<span className="text-[var(--text-muted)]">without the operational clutter.</span>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
<Link href="/vcon/dashboard">
|
||||
<Button size="xs" variant="primary" icon="Terminal">
|
||||
Console (/vcon/)
|
||||
</Button>
|
||||
<p className="mb-6 max-w-[520px] text-[15px] leading-relaxed text-[var(--text-muted)]">
|
||||
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>
|
||||
<Link href="/vcon/data">
|
||||
<Button size="xs" variant="secondary" icon="Activity">
|
||||
Live Stream
|
||||
</Button>
|
||||
<Link href="#sdk">
|
||||
<Button variant="secondary" size="sm">Python SDK</Button>
|
||||
</Link>
|
||||
<div className="flex items-center gap-1.5 border border-[var(--border)] bg-[var(--bg-elevated)] px-2 py-0.5 text-[10px] font-mono text-[var(--text)]">
|
||||
<span className="text-[var(--text-dim)]">$</span>
|
||||
<span>pip install ./sdk-python</span>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
className="text-[var(--text-dim)] hover:text-[var(--text)] ml-0.5 cursor-pointer"
|
||||
aria-label="Copy install command"
|
||||
>
|
||||
<Icon name={copied ? 'Check' : 'Copy'} size={11} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 4 Clean Metric Cards */}
|
||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-1.5 pt-0.5">
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
|
||||
<span>Ingestion</span>
|
||||
<Icon name="Radio" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">:4000 (ws)</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
|
||||
<span>Web & API</span>
|
||||
<Icon name="LayoutDashboard" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">:3000 (http)</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
|
||||
<span>Storage Engine</span>
|
||||
<Icon name="HardDrive" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">Rotated CSV</span>
|
||||
</Card>
|
||||
|
||||
<Card compact className="p-2 flex flex-col gap-0.5 bg-[var(--bg-elevated)]">
|
||||
<div className="flex items-center justify-between text-[8.5px] uppercase tracking-wider text-[var(--text-dim)] font-medium">
|
||||
<span>Buffer Limit</span>
|
||||
<Icon name="Cpu" size={11} className="text-[var(--accent)]" />
|
||||
</div>
|
||||
<span className="text-[12.5px] font-semibold text-[var(--text)] font-mono">500 rows / 2s</span>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
<ActivityPreview />
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default Hero;
|
||||
@@ -0,0 +1,17 @@
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
export const LandingAbout: React.FC = () => (
|
||||
<section id="about" className="flex flex-wrap items-center justify-between gap-6 py-10">
|
||||
<div>
|
||||
<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>
|
||||
</section>
|
||||
);
|
||||
|
||||
export default LandingAbout;
|
||||
@@ -0,0 +1,132 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { CopyButton } from '@/components/ui/CopyButton';
|
||||
import { Input, Textarea } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useState } from 'react';
|
||||
import type { ClientCredentials } from './clients/types';
|
||||
|
||||
interface NewClientModalProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
onCreated: () => Promise<void>;
|
||||
}
|
||||
|
||||
export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps) {
|
||||
const { success, error } = useToast();
|
||||
const [clientId, setClientId] = useState('');
|
||||
const [name, setName] = useState('');
|
||||
const [rateLimit, setRateLimit] = useState('100');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
|
||||
|
||||
const createClient = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const response = await fetch('/api/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ clientId: clientId.trim(), name: name.trim(), rateLimit: Number(rateLimit) || 100 }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Client registration failed');
|
||||
|
||||
setCredentials(data.client as ClientCredentials);
|
||||
setClientId('');
|
||||
setName('');
|
||||
setRateLimit('100');
|
||||
onClose();
|
||||
success('Client registered', `${data.client.clientId} is ready to connect.`);
|
||||
await onCreated();
|
||||
} catch (createError) {
|
||||
error('Registration failed', createError instanceof Error ? createError.message : 'Unknown error');
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
isOpen={open}
|
||||
onClose={onClose}
|
||||
title="Create client"
|
||||
maxWidth="xs"
|
||||
footer={
|
||||
<>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
|
||||
<Button type="submit" form="new-client-form" variant="primary" size="sm" loading={submitting}>Create client</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="new-client-form" onSubmit={createClient} className="flex flex-col gap-3.5">
|
||||
<Input
|
||||
compact
|
||||
label="Client ID"
|
||||
placeholder="e.g. py_order_service_04"
|
||||
value={clientId}
|
||||
onChange={(event) => setClientId(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Client name"
|
||||
placeholder="e.g. Order Service"
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Rate limit (requests per second)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="5000"
|
||||
value={rateLimit}
|
||||
onChange={(event) => setRateLimit(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
isOpen={Boolean(credentials)}
|
||||
onClose={() => setCredentials(null)}
|
||||
title={`Credentials: ${credentials?.clientId || ''}`}
|
||||
description="Copy these credentials now. The secret is only shown after creation."
|
||||
footer={<Button type="button" size="sm" onClick={() => setCredentials(null)}>Close</Button>}
|
||||
>
|
||||
{credentials && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Credential label="Client ID" value={credentials.clientId} />
|
||||
<Credential label="Client secret key" value={credentials.secret} />
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<label htmlFor="new-client-token" className="text-xs uppercase text-[var(--text-faint)]">JWT handshake bearer token</label>
|
||||
<CopyButton value={credentials.token} />
|
||||
</div>
|
||||
<Textarea id="new-client-token" readOnly value={credentials.token} rows={4} className="font-mono text-xs text-[var(--accent)]" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Credential({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<span className="text-xs uppercase text-[var(--text-faint)]">{label}</span>
|
||||
<div className="flex min-w-0 items-center justify-between gap-2 border border-[var(--border)] bg-[var(--bg)] p-2.5">
|
||||
<code className="min-w-0 truncate font-mono text-xs text-[var(--text)]">{value}</code>
|
||||
<CopyButton value={value} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { CodeBlock } from '@/components/ui/CodeBlock';
|
||||
import { SectionHeading } from '@/components/ui/SectionHeading';
|
||||
import React from 'react';
|
||||
|
||||
export const SdkSection: React.FC = () => (
|
||||
<section id="sdk" className="border-b border-[var(--border)] py-10">
|
||||
<SectionHeading index="02" label="Python SDK" title="Drop in the SDK. Start streaming." />
|
||||
<div className="grid grid-cols-1 gap-px border border-[var(--border)] bg-[var(--border)] md:grid-cols-2">
|
||||
<CodeBlock>
|
||||
<span className="text-[var(--text-faint)]"># Install the client</span>{'\n'}
|
||||
<span className="text-[var(--text)]">pip install ./sdk-python</span>{'\n\n'}
|
||||
<span className="text-[var(--text-faint)]"># Send an event</span>{'\n'}
|
||||
<span className="text-[var(--text)]">from datastack_sdk import DataStackClient</span>{'\n\n'}
|
||||
<span className="text-[var(--text)]">client = DataStackClient(</span>{'\n'}
|
||||
{' '}server_url=<span className="text-[var(--accent)]">"YOUR_SERVER_URL"</span>,{'\n'}
|
||||
{' '}token=<span className="text-[var(--accent)]">"YOUR_CLIENT_TOKEN"</span>,{'\n'}
|
||||
<span className="text-[var(--text)]">)</span>{'\n\n'}
|
||||
<span className="text-[var(--text)]">if client.connect():</span>{'\n'}
|
||||
{' '}client.sync({'{'}<span className="text-[var(--accent)]">"event"</span>: <span className="text-[var(--accent)]">"package_received"</span>{'}'}){'\n'}
|
||||
{' '}client.disconnect()
|
||||
</CodeBlock>
|
||||
<div className="bg-[var(--surface)] p-5 sm:p-6">
|
||||
<p className="mb-2 text-[11px] uppercase text-[var(--text-faint)]">How it works</p>
|
||||
<h3 className="mb-2 text-[14px] font-medium text-[var(--text)]">A small client. A clear workflow.</h3>
|
||||
<p className="text-[12px] leading-relaxed text-[var(--text-muted)]">
|
||||
Connect a Python source, send individual or batched events, then review and export activity from one workspace.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
export default SdkSection;
|
||||
@@ -0,0 +1,273 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { FormSwitch } from '@/components/ui/Form';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { SettingsField, SettingsGroup, SettingsTabs } from '@/components/ui/SettingsLayout';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
interface EditableSettings {
|
||||
maxEventsPerSec: number;
|
||||
maxPayloadSizeKb: number;
|
||||
batchFlushThreshold: number;
|
||||
batchFlushIntervalMs: number;
|
||||
fileRotationMb: number;
|
||||
enableIdempotency: boolean;
|
||||
autoPruneDays: number;
|
||||
}
|
||||
|
||||
interface PublicSettings extends EditableSettings {
|
||||
serverPort: number;
|
||||
webPort: number;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
const DEFAULT_SETTINGS: EditableSettings = {
|
||||
maxEventsPerSec: 100,
|
||||
maxPayloadSizeKb: 100,
|
||||
batchFlushThreshold: 500,
|
||||
batchFlushIntervalMs: 2000,
|
||||
fileRotationMb: 100,
|
||||
enableIdempotency: true,
|
||||
autoPruneDays: 30,
|
||||
};
|
||||
|
||||
const TABS = [
|
||||
{ id: 'general', label: 'General' },
|
||||
{ id: 'connections', label: 'Connections' },
|
||||
{ id: 'storage', label: 'Storage' },
|
||||
{ id: 'security', label: 'Security' },
|
||||
{ id: 'notifications', label: 'Notifications' },
|
||||
];
|
||||
|
||||
type TabId = (typeof TABS)[number]['id'];
|
||||
|
||||
export function SettingsWorkspace() {
|
||||
const { success, error } = useToast();
|
||||
const [settings, setSettings] = useState<EditableSettings>(DEFAULT_SETTINGS);
|
||||
const [savedSettings, setSavedSettings] = useState<EditableSettings>(DEFAULT_SETTINGS);
|
||||
const [activeTab, setActiveTab] = useState<TabId>('general');
|
||||
const [jwtSecret, setJwtSecret] = useState('');
|
||||
const [storagePath, setStoragePath] = useState('');
|
||||
const [baseUrl, setBaseUrl] = useState('');
|
||||
const [webSocketUrl, setWebSocketUrl] = useState('');
|
||||
const [serverPort, setServerPort] = useState(4000);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setBaseUrl(window.location.origin);
|
||||
setWebSocketUrl(`${window.location.protocol === 'https:' ? 'wss' : 'ws'}://${window.location.hostname}:4000`);
|
||||
|
||||
Promise.all([
|
||||
fetch('/api/settings').then(async (response) => {
|
||||
if (!response.ok) throw new Error('Unable to load settings');
|
||||
return response.json();
|
||||
}),
|
||||
fetch('/api/storage').then(async (response) => {
|
||||
if (!response.ok) throw new Error('Unable to load storage information');
|
||||
return response.json();
|
||||
}),
|
||||
])
|
||||
.then(([settingsData, storageData]) => {
|
||||
const loaded: EditableSettings = {
|
||||
maxEventsPerSec: Number(settingsData.settings.maxEventsPerSec ?? DEFAULT_SETTINGS.maxEventsPerSec),
|
||||
maxPayloadSizeKb: Number(settingsData.settings.maxPayloadSizeKb ?? DEFAULT_SETTINGS.maxPayloadSizeKb),
|
||||
batchFlushThreshold: Number(settingsData.settings.batchFlushThreshold ?? DEFAULT_SETTINGS.batchFlushThreshold),
|
||||
batchFlushIntervalMs: Number(settingsData.settings.batchFlushIntervalMs ?? DEFAULT_SETTINGS.batchFlushIntervalMs),
|
||||
fileRotationMb: Number(settingsData.settings.fileRotationMb ?? DEFAULT_SETTINGS.fileRotationMb),
|
||||
enableIdempotency: Boolean(settingsData.settings.enableIdempotency ?? DEFAULT_SETTINGS.enableIdempotency),
|
||||
autoPruneDays: Number(settingsData.settings.autoPruneDays ?? DEFAULT_SETTINGS.autoPruneDays),
|
||||
};
|
||||
setSettings(loaded);
|
||||
setSavedSettings(loaded);
|
||||
setServerPort(Number((settingsData.settings as PublicSettings).serverPort ?? 4000));
|
||||
setStoragePath(String(storageData.stats?.storageDirectory ?? ''));
|
||||
})
|
||||
.catch((loadError) => {
|
||||
error('Settings unavailable', loadError instanceof Error ? loadError.message : 'Unable to load settings');
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
}, [error]);
|
||||
|
||||
const isDirty = useMemo(
|
||||
() => jwtSecret.trim().length > 0 || JSON.stringify(settings) !== JSON.stringify(savedSettings),
|
||||
[jwtSecret, savedSettings, settings]
|
||||
);
|
||||
|
||||
const updateNumber = (key: keyof EditableSettings, value: string) => {
|
||||
setSettings((current) => ({ ...current, [key]: Number(value) || 0 }));
|
||||
};
|
||||
|
||||
const saveSettings = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setSaving(true);
|
||||
try {
|
||||
const response = await fetch('/api/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
...settings,
|
||||
...(jwtSecret.trim() ? { jwtSecret: jwtSecret.trim() } : {}),
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Settings update failed');
|
||||
setSavedSettings(settings);
|
||||
setJwtSecret('');
|
||||
success('Settings saved', 'Supported runtime settings have been applied.');
|
||||
} catch (saveError) {
|
||||
error('Save failed', saveError instanceof Error ? saveError.message : 'Unable to save settings');
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const discardChanges = () => {
|
||||
setSettings(savedSettings);
|
||||
setJwtSecret('');
|
||||
};
|
||||
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-[var(--container-width)]">
|
||||
<nav aria-label="Breadcrumb" className="mb-3 flex items-center gap-1.5 text-xs text-[var(--text-faint)]">
|
||||
<span>Console</span>
|
||||
<span aria-hidden="true" className="text-[var(--border-strong)]">/</span>
|
||||
<span aria-current="page" className="text-[var(--text)]">Settings</span>
|
||||
</nav>
|
||||
<header className="mb-4">
|
||||
<h1 className="text-base font-medium tracking-tight text-[var(--text)]">Settings</h1>
|
||||
<p className="mt-0.5 text-xs text-[var(--text-muted)]">Configure your DataStack instance</p>
|
||||
</header>
|
||||
|
||||
<SettingsTabs items={TABS} value={activeTab} onChange={(tab) => setActiveTab(tab as TabId)} />
|
||||
|
||||
<form onSubmit={saveSettings}>
|
||||
<div
|
||||
id={`settings-panel-${activeTab}`}
|
||||
role="tabpanel"
|
||||
aria-labelledby={`settings-tab-${activeTab}`}
|
||||
className="border border-t-0 border-[var(--border)] bg-[var(--surface)]"
|
||||
>
|
||||
{loading ? (
|
||||
<p className="p-4 text-xs text-[var(--text-faint)]">Loading settings...</p>
|
||||
) : (
|
||||
<>
|
||||
{activeTab === 'general' && (
|
||||
<>
|
||||
<SettingsGroup title="Identity">
|
||||
<SettingsField label="Instance name" hint="Shown in dashboard headers and emails">
|
||||
<Input compact value="DataStack" readOnly className="border-[var(--border)] bg-[var(--surface-2)] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
<SettingsField label="Base URL" hint="Current browser origin">
|
||||
<Input compact value={baseUrl} readOnly className="border-[var(--border)] bg-[var(--surface-2)] font-mono text-[11.5px] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
<SettingsField label="Instance ID" hint="Instance identifier is not configured">
|
||||
<Input compact value="Not configured" readOnly className="border-[var(--border)] bg-[var(--surface-2)] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
<SettingsGroup title="Throughput">
|
||||
<SettingsField label="Events per second" hint="Global cap; client limits may be lower">
|
||||
<Input compact type="number" min="1" max="10000" value={settings.maxEventsPerSec} onChange={(event) => updateNumber('maxEventsPerSec', event.target.value)} />
|
||||
</SettingsField>
|
||||
<SettingsField label="Enable idempotency" hint="Reject duplicate clientId + eventId combinations">
|
||||
<FormSwitch label="Deduplicate incoming events" checked={settings.enableIdempotency} onChange={(enableIdempotency) => setSettings((current) => ({ ...current, enableIdempotency }))} />
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'connections' && (
|
||||
<>
|
||||
<SettingsGroup title="WebSocket server">
|
||||
<SettingsField label="Public WebSocket URL" hint="Clients connect through the configured host">
|
||||
<Input compact value={webSocketUrl} readOnly className="border-[var(--border)] bg-[var(--surface-2)] font-mono text-[11.5px] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
<SettingsField label="Socket port" hint="Express process port">
|
||||
<Input compact type="number" value={serverPort} readOnly className="border-[var(--border)] bg-[var(--surface-2)] font-mono text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
<SettingsGroup title="Event buffer">
|
||||
<SettingsField label="Batch flush threshold" hint="Write buffered rows to CSV at this count">
|
||||
<Input compact type="number" min="1" value={settings.batchFlushThreshold} onChange={(event) => updateNumber('batchFlushThreshold', event.target.value)} />
|
||||
</SettingsField>
|
||||
<SettingsField label="Flush interval" hint="Maximum time before buffered rows are written">
|
||||
<div className="flex items-center gap-0">
|
||||
<Input compact type="number" min="100" value={settings.batchFlushIntervalMs} onChange={(event) => updateNumber('batchFlushIntervalMs', event.target.value)} className="border-[var(--border)] font-mono" />
|
||||
<span className="flex h-9 items-center border border-l-0 border-[var(--border)] bg-[var(--surface-2)] px-2.5 text-xs text-[var(--text-muted)]">ms</span>
|
||||
</div>
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'storage' && (
|
||||
<>
|
||||
<SettingsGroup title="CSV files">
|
||||
<SettingsField label="Root path" hint="Current server storage directory">
|
||||
<Input compact value={storagePath || 'Unavailable'} readOnly className="border-[var(--border)] bg-[var(--surface-2)] font-mono text-[11.5px] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
<SettingsField label="File rotation" hint="Files rotate daily and at the configured size limit">
|
||||
<div className="flex items-center gap-0">
|
||||
<Input compact type="number" min="1" value={settings.fileRotationMb} onChange={(event) => updateNumber('fileRotationMb', event.target.value)} className="border-[var(--border)] font-mono" />
|
||||
<span className="flex h-9 items-center border border-l-0 border-[var(--border)] bg-[var(--surface-2)] px-2.5 text-xs text-[var(--text-muted)]">MB</span>
|
||||
</div>
|
||||
</SettingsField>
|
||||
<SettingsField label="Retention" hint="Retention value is stored; automatic pruning is not enabled">
|
||||
<div className="flex items-center gap-0">
|
||||
<Input compact type="number" min="1" max="365" value={settings.autoPruneDays} onChange={(event) => updateNumber('autoPruneDays', event.target.value)} className="border-[var(--border)] font-mono" />
|
||||
<span className="flex h-9 items-center border border-l-0 border-[var(--border)] bg-[var(--surface-2)] px-2.5 text-xs text-[var(--text-muted)]">days</span>
|
||||
</div>
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
<SettingsGroup title="Schema">
|
||||
<SettingsField label="Row format" hint="Fixed CSV schema">
|
||||
<Input compact value="clientId, eventId, timestamp, payload" readOnly className="border-[var(--border)] bg-[var(--surface-2)] font-mono text-[11.5px] text-[var(--text-muted)]" />
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'security' && (
|
||||
<>
|
||||
<SettingsGroup title="Authentication">
|
||||
<SettingsField label="JWT secret" hint="Changing the secret invalidates existing client tokens">
|
||||
<Input compact type="password" autoComplete="new-password" value={jwtSecret} onChange={(event) => setJwtSecret(event.target.value)} placeholder="Leave blank to keep the current secret" />
|
||||
</SettingsField>
|
||||
<SettingsField label="Payload size limit" hint="Maximum accepted event payload size">
|
||||
<div className="flex items-center gap-0">
|
||||
<Input compact type="number" min="1" max="5120" value={settings.maxPayloadSizeKb} onChange={(event) => updateNumber('maxPayloadSizeKb', event.target.value)} className="border-[var(--border)] font-mono" />
|
||||
<span className="flex h-9 items-center border border-l-0 border-[var(--border)] bg-[var(--surface-2)] px-2.5 text-xs text-[var(--text-muted)]">KB</span>
|
||||
</div>
|
||||
</SettingsField>
|
||||
</SettingsGroup>
|
||||
<SettingsGroup title="Configuration">
|
||||
<p className="text-xs leading-relaxed text-[var(--text-faint)]">Allowed origins and token expiration are controlled by deployment configuration and are not editable from this console.</p>
|
||||
</SettingsGroup>
|
||||
</>
|
||||
)}
|
||||
|
||||
{activeTab === 'notifications' && (
|
||||
<SettingsGroup title="Delivery">
|
||||
<p className="text-xs leading-relaxed text-[var(--text-faint)]">Email and webhook notification delivery are not configured for this instance.</p>
|
||||
</SettingsGroup>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<footer className="flex flex-wrap items-center gap-2 border border-t-0 border-[var(--border)] bg-[var(--surface)] px-4 py-2.5">
|
||||
<div className="flex flex-1 items-center gap-1.5 text-xs text-[var(--text-muted)]" role="status">
|
||||
<span className={`h-1.5 w-1.5 ${isDirty ? 'bg-[var(--warning)]' : 'bg-[var(--accent)]'}`} />
|
||||
{loading ? 'Loading settings' : isDirty ? 'Unsaved changes' : 'All changes saved'}
|
||||
</div>
|
||||
<Button type="button" size="xs" disabled={!isDirty || saving} onClick={discardChanges}>Discard</Button>
|
||||
<Button type="submit" variant="primary" size="xs" icon="Save" loading={saving} disabled={loading || !isDirty}>Save changes</Button>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
<p className="mt-3 text-[11px] text-[var(--text-faint)]">Some settings require a service restart to take effect.</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
export interface ClientItem {
|
||||
clientId: string;
|
||||
name: string;
|
||||
rateLimit: number;
|
||||
status: "active" | "revoked";
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface ClientCredentials extends ClientItem {
|
||||
secret: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
export type ClientStatusFilter = "all" | "online" | "offline" | "pending";
|
||||
@@ -0,0 +1,8 @@
|
||||
export * from "./AdminLogin";
|
||||
export * from "./ClientsFilters";
|
||||
export * from "./ClientsManager";
|
||||
export * from "./ClientsTable";
|
||||
export * from "./DataBrowser";
|
||||
export * from "./ExportWorkspace";
|
||||
export * from "./NewClientModal";
|
||||
export * from "./SettingsWorkspace";
|
||||
@@ -0,0 +1,35 @@
|
||||
import React from 'react';
|
||||
|
||||
const sampleRows = [
|
||||
{ time: '14:28:01', source: 'Source A', payload: '{ metric: "temperature", value: 22.4 }', size: '42 B' },
|
||||
{ time: '14:28:01', source: 'Source B', payload: '{ action: "package_received", count: 3 }', size: '38 B' },
|
||||
{ time: '14:28:02', source: 'Source A', payload: '{ metric: "humidity", value: 61 }', size: '40 B' },
|
||||
{ time: '14:28:02', source: 'Source C', payload: '{ status: "complete", duration_ms: 184 }', size: '44 B' },
|
||||
];
|
||||
|
||||
export const ActivityPreview: React.FC = () => (
|
||||
<section aria-label="Example activity" className="mt-8 overflow-hidden border border-[var(--border)] bg-[var(--surface)]">
|
||||
<div className="flex items-center justify-between gap-3 border-b border-[var(--border)] px-3 py-2.5 sm:px-4">
|
||||
<div className="flex items-center gap-2 text-[12px] text-[var(--text-muted)]">
|
||||
<span className="h-1.5 w-1.5 bg-[var(--accent)]" />
|
||||
Example activity
|
||||
</div>
|
||||
<span className="text-[11px] text-[var(--text-faint)]">Sample records</span>
|
||||
</div>
|
||||
<div className="divide-y divide-[var(--border)]">
|
||||
{sampleRows.map((row) => (
|
||||
<div
|
||||
key={`${row.time}-${row.source}-${row.payload}`}
|
||||
className="grid grid-cols-[4.5rem_minmax(0,1fr)_3rem] items-center gap-x-3 px-3 py-2 font-mono text-[11px] sm:grid-cols-[5rem_6rem_minmax(0,1fr)_3.5rem] sm:px-4"
|
||||
>
|
||||
<span className="text-[var(--text-faint)]">{row.time}</span>
|
||||
<span className="hidden text-[var(--accent)] sm:block">{row.source}</span>
|
||||
<span className="truncate text-[var(--text)]">{row.payload}</span>
|
||||
<span className="text-right text-[var(--text-faint)]">{row.size}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
export default ActivityPreview;
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
@@ -30,7 +30,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
|
||||
const variantStyles = {
|
||||
primary:
|
||||
'bg-[var(--accent)] text-[var(--text-on-accent)] hover:bg-[var(--accent-hover)] border-[var(--accent)]',
|
||||
'bg-[var(--text)] text-[var(--bg)] hover:opacity-90 border-[var(--text)]',
|
||||
secondary:
|
||||
'bg-[var(--bg-elevated)] text-[var(--text)] border-[var(--border-strong)] hover:bg-[var(--bg-hover)]',
|
||||
ghost:
|
||||
@@ -42,10 +42,10 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
};
|
||||
|
||||
const sizeStyles = {
|
||||
default: 'h-[32px] px-[14px] text-[12.5px] gap-[7px]',
|
||||
sm: 'h-[27px] px-[10px] text-[11.5px] gap-[5px]',
|
||||
xs: 'h-[24px] px-[7px] text-[10.5px] gap-[4px]',
|
||||
icon: 'w-[30px] h-[30px] p-0',
|
||||
default: 'min-h-10 px-4 text-[13.5px] gap-2',
|
||||
sm: 'h-9 px-3 text-[12.5px] gap-1.5',
|
||||
xs: 'h-8 px-2.5 text-[12px] gap-1.5',
|
||||
icon: 'w-9 h-9 p-0',
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
export interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
variant?: 'default' | 'subtle' | 'dashed' | 'active';
|
||||
@@ -25,8 +25,8 @@ export const Card: React.FC<CardProps> = ({
|
||||
className={cn(
|
||||
'transition-colors',
|
||||
variantStyles[variant],
|
||||
compact ? 'p-2.5' : 'p-3.5 sm:p-4',
|
||||
className
|
||||
className,
|
||||
compact ? 'p-4' : 'p-5 sm:p-6'
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
@@ -42,7 +42,7 @@ export const CardHeader: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
}) => (
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-between gap-2.5 pb-2.5 mb-2.5 border-b border-[var(--border)]',
|
||||
'flex items-center justify-between gap-3 pb-3 mb-3 border-b border-[var(--border)]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -56,7 +56,7 @@ export const CardTitle: React.FC<React.HTMLAttributes<HTMLHeadingElement>> = ({
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<h3 className={cn('text-[13px] font-semibold text-[var(--text)] leading-tight', className)} {...props}>
|
||||
<h3 className={cn('text-[15px] font-semibold text-[var(--text)] leading-snug', className)} {...props}>
|
||||
{children}
|
||||
</h3>
|
||||
);
|
||||
@@ -66,7 +66,7 @@ export const CardDescription: React.FC<React.HTMLAttributes<HTMLParagraphElement
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<p className={cn('text-[11px] text-[var(--text-muted)] leading-normal', className)} {...props}>
|
||||
<p className={cn('text-[13px] text-[var(--text-muted)] leading-relaxed', className)} {...props}>
|
||||
{children}
|
||||
</p>
|
||||
);
|
||||
@@ -76,7 +76,7 @@ export const CardContent: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<div className={cn('text-[12px]', className)} {...props}>
|
||||
<div className={cn('text-[14px]', className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
@@ -88,7 +88,7 @@ export const CardFooter: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
}) => (
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-between gap-2 pt-2.5 mt-2.5 border-t border-[var(--border)] text-[11px]',
|
||||
'flex items-center justify-between gap-3 pt-3 mt-3 border-t border-[var(--border)] text-[13px]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface ClientListItem {
|
||||
clientId: string;
|
||||
name: string;
|
||||
status: 'active' | 'revoked';
|
||||
totalEvents: number;
|
||||
}
|
||||
|
||||
interface ClientListProps {
|
||||
clients: ClientListItem[];
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export const ClientList: React.FC<ClientListProps> = ({ clients, limit = 4 }) => (
|
||||
<div className="divide-y divide-[var(--border)]">
|
||||
{clients.slice(0, limit).map((client) => (
|
||||
<div key={client.clientId} className="flex min-w-0 items-center justify-between gap-3 px-4 py-2">
|
||||
<div className="flex min-w-0 items-center gap-2">
|
||||
<span className={client.status === 'active' ? 'h-1.5 w-1.5 shrink-0 bg-[var(--accent)]' : 'h-1.5 w-1.5 shrink-0 bg-[var(--text-faint)]'} />
|
||||
<div className="min-w-0">
|
||||
<p className="truncate text-[12px] font-medium text-[var(--text)]">{client.name}</p>
|
||||
<p className="truncate font-mono text-[10px] text-[var(--text-faint)]">{client.clientId}</p>
|
||||
</div>
|
||||
</div>
|
||||
<span className="shrink-0 font-mono text-[11px] text-[var(--text-muted)]">
|
||||
{client.totalEvents.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
{clients.length === 0 && (
|
||||
<p className="px-4 py-5 text-[12px] text-[var(--text-faint)]">No registered clients.</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
export default ClientList;
|
||||
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
|
||||
interface CodeBlockProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export const CodeBlock: React.FC<CodeBlockProps> = ({ children, className = '' }) => (
|
||||
<pre className={`overflow-x-auto bg-[var(--surface)] p-4 font-mono text-[12px] leading-relaxed text-[var(--text-muted)] ${className}`}>
|
||||
<code>{children}</code>
|
||||
</pre>
|
||||
);
|
||||
|
||||
export default CodeBlock;
|
||||
@@ -0,0 +1,49 @@
|
||||
'use client';
|
||||
|
||||
import { Check, Copy } from 'lucide-react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
type CopyState = 'idle' | 'copied' | 'failed';
|
||||
|
||||
export function CopyButton({ value }: { value: string }) {
|
||||
const [state, setState] = useState<CopyState>('idle');
|
||||
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
useEffect(() => () => {
|
||||
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
||||
}, []);
|
||||
|
||||
const copyValue = async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
setState('copied');
|
||||
} catch {
|
||||
setState('failed');
|
||||
}
|
||||
|
||||
if (timeoutRef.current) clearTimeout(timeoutRef.current);
|
||||
timeoutRef.current = setTimeout(() => setState('idle'), 1200);
|
||||
};
|
||||
|
||||
const label = state === 'copied'
|
||||
? 'Copied to clipboard'
|
||||
: state === 'failed'
|
||||
? 'Clipboard unavailable'
|
||||
: 'Copy to clipboard';
|
||||
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={copyValue}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className="grid h-5 w-5 shrink-0 place-items-center text-[var(--text-faint)] transition-colors hover:text-[var(--text)]"
|
||||
>
|
||||
{state === 'copied'
|
||||
? <Check className="h-3 w-3" aria-hidden="true" />
|
||||
: <Copy className="h-3 w-3" aria-hidden="true" />}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
export default CopyButton;
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
interface FeatureItemProps {
|
||||
icon: string;
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export const FeatureItem: React.FC<FeatureItemProps> = ({ icon, title, description }) => (
|
||||
<article className="min-h-full bg-[var(--surface)] p-5">
|
||||
<div className="mb-3 grid h-[22px] w-[22px] place-items-center border border-[var(--border-strong)] text-[var(--accent)]">
|
||||
<Icon name={icon} size={13} />
|
||||
</div>
|
||||
<h3 className="mb-1 text-[13px] font-medium text-[var(--text)]">{title}</h3>
|
||||
<p className="text-[12px] leading-relaxed text-[var(--text-muted)]">{description}</p>
|
||||
</article>
|
||||
);
|
||||
|
||||
export default FeatureItem;
|
||||
@@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
export const Form: React.FC<React.FormHTMLAttributes<HTMLFormElement>> = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<form className={cn('flex flex-col gap-3', className)} {...props}>
|
||||
<form className={cn('flex flex-col gap-5', className)} {...props}>
|
||||
{children}
|
||||
</form>
|
||||
);
|
||||
@@ -16,7 +16,7 @@ export const FormField: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<div className={cn('flex flex-col gap-1 w-full', className)} {...props}>
|
||||
<div className={cn('flex flex-col gap-2 w-full', className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
@@ -26,7 +26,7 @@ export const FormRow: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<div className={cn('grid grid-cols-1 sm:grid-cols-2 gap-3 w-full', className)} {...props}>
|
||||
<div className={cn('grid grid-cols-1 sm:grid-cols-2 gap-4 w-full', className)} {...props}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
@@ -40,20 +40,20 @@ export const FormSwitch: React.FC<{
|
||||
}> = ({ label, checked, onChange, description, disabled = false }) => (
|
||||
<label
|
||||
className={cn(
|
||||
'flex items-center justify-between p-2.5 border border-[var(--border)] bg-[var(--bg-main)] cursor-pointer select-none transition-colors hover:bg-[var(--bg-hover)]',
|
||||
'flex items-center justify-between gap-4 p-4 border border-[var(--border)] bg-[var(--bg-main)] cursor-pointer select-none transition-colors hover:bg-[var(--bg-hover)]',
|
||||
disabled && 'opacity-50 cursor-not-allowed'
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<span className="text-[12px] font-medium text-[var(--text)]">{label}</span>
|
||||
{description && <span className="text-[10.5px] text-[var(--text-dim)]">{description}</span>}
|
||||
<span className="text-[14px] font-medium text-[var(--text)]">{label}</span>
|
||||
{description && <span className="text-[12px] text-[var(--text-muted)]">{description}</span>}
|
||||
</div>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange(e.target.checked)}
|
||||
className="w-4 h-4 accent-[var(--accent)] cursor-pointer"
|
||||
className="w-5 h-5 accent-[var(--accent)] cursor-pointer shrink-0"
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
|
||||
@@ -18,7 +18,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={inputId}
|
||||
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
|
||||
className="text-[12px] font-medium text-[var(--text-muted)]"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
@@ -34,7 +34,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] placeholder:text-[var(--text-dim)] transition-colors focus:outline-none focus:border-[var(--accent)] disabled:opacity-50 disabled:cursor-not-allowed',
|
||||
compact ? 'h-[28px] px-2 text-[11px]' : 'h-[32px] px-2.5 text-[12px]',
|
||||
compact ? 'h-9 px-3 text-[13px]' : 'h-10 px-3.5 text-[14px]',
|
||||
icon && 'pl-8',
|
||||
error && 'border-[var(--danger)]',
|
||||
className
|
||||
@@ -42,7 +42,7 @@ export const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
|
||||
{error && <span className="text-[12px] text-[var(--danger)]">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={textareaId}
|
||||
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
|
||||
className="text-[12px] font-medium text-[var(--text-muted)]"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
@@ -73,13 +73,13 @@ export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
||||
id={textareaId}
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] p-2.5 text-[12px] placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--accent)] min-h-[64px] resize-y font-mono',
|
||||
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] p-3.5 text-[14px] placeholder:text-[var(--text-dim)] focus:outline-none focus:border-[var(--accent)] min-h-[96px] resize-y font-mono',
|
||||
error && 'border-[var(--danger)]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
|
||||
{error && <span className="text-[12px] text-[var(--danger)]">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
|
||||
{label && (
|
||||
<label
|
||||
htmlFor={selectId}
|
||||
className="text-[10.5px] font-semibold text-[var(--text-muted)] uppercase tracking-wider"
|
||||
className="text-[12px] font-medium text-[var(--text-muted)]"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
@@ -113,7 +113,7 @@ export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
|
||||
ref={ref}
|
||||
className={cn(
|
||||
'w-full bg-[var(--bg-main)] text-[var(--text)] border border-[var(--border-strong)] focus:outline-none focus:border-[var(--accent)] cursor-pointer',
|
||||
compact ? 'h-[28px] px-1.5 text-[11px]' : 'h-[32px] px-2 text-[11.5px]',
|
||||
compact ? 'h-9 px-2.5 text-[13px]' : 'h-10 px-3 text-[14px]',
|
||||
error && 'border-[var(--danger)]',
|
||||
className
|
||||
)}
|
||||
@@ -127,7 +127,7 @@ export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
|
||||
))
|
||||
: children}
|
||||
</select>
|
||||
{error && <span className="text-[10.5px] text-[var(--danger)]">{error}</span>}
|
||||
{error && <span className="text-[12px] text-[var(--danger)]">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+15
-14
@@ -1,7 +1,7 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { Icon } from './Icon';
|
||||
import React, { useEffect } from 'react';
|
||||
import { Button } from './Button';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export interface ModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -10,7 +10,7 @@ export interface ModalProps {
|
||||
description?: string;
|
||||
children: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
maxWidth?: 'sm' | 'md' | 'lg';
|
||||
maxWidth?: 'xs' | 'sm' | 'md' | 'lg';
|
||||
}
|
||||
|
||||
export const Modal: React.FC<ModalProps> = ({
|
||||
@@ -41,24 +41,25 @@ export const Modal: React.FC<ModalProps> = ({
|
||||
if (!isOpen) return null;
|
||||
|
||||
const maxWidthStyles = {
|
||||
sm: 'max-w-[440px]',
|
||||
md: 'max-w-[520px]',
|
||||
lg: 'max-w-[640px]',
|
||||
xs: 'max-w-[440px]',
|
||||
sm: 'max-w-[480px]',
|
||||
md: 'max-w-[640px]',
|
||||
lg: 'max-w-[800px]',
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-3.5 bg-black/60 backdrop-blur-[1px]">
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-6 bg-black/60">
|
||||
<div
|
||||
className={cn(
|
||||
'w-full bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] flex flex-col max-h-[min(84dvh,680px)] overflow-hidden animate-in fade-in zoom-in-95 duration-100',
|
||||
'w-full bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] flex flex-col max-h-[calc(100dvh-1.5rem)] sm:max-h-[min(88dvh,800px)] overflow-hidden animate-in fade-in zoom-in-95 duration-150',
|
||||
maxWidthStyles[maxWidth]
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-3 p-3.5 sm:px-4 sm:py-3.5 border-b border-[var(--border)] shrink-0">
|
||||
<div className="flex items-start justify-between gap-4 p-4 sm:px-6 sm:py-5 border-b border-[var(--border)] shrink-0">
|
||||
<div className="min-w-0">
|
||||
<h2 className="text-[14px] font-semibold text-[var(--text)] leading-tight">{title}</h2>
|
||||
<h2 className="text-[18px] font-semibold text-[var(--text)] leading-snug">{title}</h2>
|
||||
{description && (
|
||||
<p className="text-[11px] text-[var(--text-muted)] mt-1">{description}</p>
|
||||
<p className="text-[13px] text-[var(--text-muted)] mt-1.5">{description}</p>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
@@ -66,18 +67,18 @@ export const Modal: React.FC<ModalProps> = ({
|
||||
variant="ghost"
|
||||
onClick={onClose}
|
||||
aria-label="Close dialog"
|
||||
className="w-7 h-7 text-[var(--text-dim)] hover:text-[var(--text)]"
|
||||
className="w-9 h-9 text-[var(--text-dim)] hover:text-[var(--text)]"
|
||||
>
|
||||
<Icon name="X" size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="p-3.5 sm:p-4 overflow-y-auto flex-1 text-[12px] flex flex-col gap-3">
|
||||
<div className="p-4 sm:p-6 overflow-y-auto flex-1 text-[14px] flex flex-col gap-4">
|
||||
{children}
|
||||
</div>
|
||||
|
||||
{footer && (
|
||||
<div className="flex items-center justify-end gap-2 p-3 sm:px-4 border-t border-[var(--border)] bg-[var(--bg-sidebar)] shrink-0">
|
||||
<div className="flex flex-wrap items-center justify-end gap-2 p-4 sm:px-6 border-t border-[var(--border)] bg-[var(--bg-sidebar)] shrink-0">
|
||||
{footer}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
interface PanelProps extends React.HTMLAttributes<HTMLElement> {
|
||||
title: string;
|
||||
action?: React.ReactNode;
|
||||
meta?: string;
|
||||
children: React.ReactNode;
|
||||
bodyClassName?: string;
|
||||
}
|
||||
|
||||
export const Panel: React.FC<PanelProps> = ({
|
||||
title,
|
||||
action,
|
||||
meta,
|
||||
children,
|
||||
className,
|
||||
bodyClassName,
|
||||
...props
|
||||
}) => (
|
||||
<section className={cn('flex min-w-0 flex-col border border-[var(--border)] bg-[var(--surface)]', className)} {...props}>
|
||||
<header className="flex min-h-11 items-center justify-between gap-3 border-b border-[var(--border)] px-4 py-2.5">
|
||||
<h2 className="text-[12px] font-medium text-[var(--text)]">{title}</h2>
|
||||
<div className="flex items-center gap-3">
|
||||
{meta && <span className="text-[11px] text-[var(--text-faint)]">{meta}</span>}
|
||||
{action}
|
||||
</div>
|
||||
</header>
|
||||
<div className={cn('min-w-0', bodyClassName)}>{children}</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
export default Panel;
|
||||
@@ -0,0 +1,29 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
export interface PillProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
||||
active?: boolean;
|
||||
}
|
||||
|
||||
export const Pill = React.forwardRef<HTMLButtonElement, PillProps>(
|
||||
({ active = false, className, children, type = 'button', ...props }, ref) => (
|
||||
<button
|
||||
ref={ref}
|
||||
type={type}
|
||||
className={cn(
|
||||
'inline-flex h-[26px] shrink-0 items-center gap-1.5 border px-2.5 text-[11.5px] transition-colors disabled:cursor-not-allowed disabled:opacity-50',
|
||||
active
|
||||
? 'border-[var(--border-strong)] bg-[var(--surface-2)] text-[var(--text)]'
|
||||
: 'border-[var(--border)] bg-transparent text-[var(--text-muted)] hover:bg-[var(--surface-2)] hover:text-[var(--text)]',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
);
|
||||
|
||||
Pill.displayName = 'Pill';
|
||||
|
||||
export default Pill;
|
||||
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
|
||||
interface SectionHeadingProps {
|
||||
index: string;
|
||||
label: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export const SectionHeading: React.FC<SectionHeadingProps> = ({ index, label, title }) => (
|
||||
<div className="mb-5 flex items-baseline justify-between gap-4">
|
||||
<h2 className="text-[16px] font-medium text-[var(--text)]">{title}</h2>
|
||||
<span className="shrink-0 text-[11px] uppercase text-[var(--text-faint)]">
|
||||
{index} / {label}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default SectionHeading;
|
||||
@@ -0,0 +1,72 @@
|
||||
import React from 'react';
|
||||
|
||||
export interface SettingsTabItem {
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export function SettingsTabs({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
items: SettingsTabItem[];
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex overflow-x-auto border-b border-[var(--border)]" role="tablist" aria-label="Settings categories">
|
||||
{items.map((item) => (
|
||||
<button
|
||||
key={item.id}
|
||||
id={`settings-tab-${item.id}`}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={value === item.id}
|
||||
aria-controls={`settings-panel-${item.id}`}
|
||||
className={`mb-[-1px] shrink-0 border-b-2 px-3.5 py-2.5 text-xs transition-colors ${value === item.id ? 'border-[var(--accent)] text-[var(--text)]' : 'border-transparent text-[var(--text-muted)] hover:text-[var(--text)]'}`}
|
||||
onClick={() => onChange(item.id)}
|
||||
>
|
||||
{item.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsGroup({
|
||||
title,
|
||||
children,
|
||||
}: {
|
||||
title: string;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<section className="border-b border-[var(--border)] p-4 last:border-b-0">
|
||||
<h2 className="mb-3 flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
{title}
|
||||
</h2>
|
||||
<div className="flex flex-col">{children}</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsField({
|
||||
label,
|
||||
hint,
|
||||
children,
|
||||
}: {
|
||||
label: string;
|
||||
hint?: string;
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 items-start gap-1.5 py-2 sm:grid-cols-[1fr_2fr] sm:gap-5">
|
||||
<div className="min-w-0 pt-px">
|
||||
<div className="text-[12.5px] leading-snug text-[var(--text)]">{label}</div>
|
||||
{hint && <div className="mt-0.5 text-[11px] leading-normal text-[var(--text-faint)]">{hint}</div>}
|
||||
</div>
|
||||
<div className="min-w-0">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { Card } from './Card';
|
||||
|
||||
interface StatCardProps {
|
||||
label: string;
|
||||
value: string | number;
|
||||
unit?: string;
|
||||
meta: string;
|
||||
}
|
||||
|
||||
export const StatCard: React.FC<StatCardProps> = ({ label, value, unit, meta }) => (
|
||||
<Card compact className="bg-[var(--surface)]">
|
||||
<div className="mb-1.5 text-[10px] uppercase text-[var(--text-faint)]">{label}</div>
|
||||
<div className="text-[22px] font-medium leading-tight text-[var(--text)]">
|
||||
{value}
|
||||
{unit && <span className="ml-1 text-[11px] font-normal text-[var(--text-muted)]">{unit}</span>}
|
||||
</div>
|
||||
<div className="mt-2 text-[11px] text-[var(--text-muted)]">{meta}</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
export default StatCard;
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
type Dot = 'ok' | 'off' | 'pending';
|
||||
type Item = { label: string; value: ReactNode; dot?: Dot };
|
||||
|
||||
const DOT_CLASS: Record<Dot, string> = {
|
||||
ok: 'bg-[var(--accent)]',
|
||||
off: 'bg-[var(--text-faint)]',
|
||||
pending: 'bg-[var(--warning)]',
|
||||
};
|
||||
|
||||
export function StatStrip({ items }: { items: Item[] }) {
|
||||
return (
|
||||
<div className="mb-4 grid grid-cols-2 gap-px border border-[var(--border)] bg-[var(--border)] md:grid-cols-4">
|
||||
{items.map((item) => (
|
||||
<div key={item.label} className="bg-[var(--surface)] px-4 py-3">
|
||||
<div className="mb-1 text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
{item.label}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 text-lg font-medium leading-none tracking-tight text-[var(--text)]">
|
||||
{item.dot && <span aria-hidden="true" className={`h-1.5 w-1.5 ${DOT_CLASS[item.dot]}`} />}
|
||||
{item.value}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
export const TableWrap: React.FC<React.HTMLAttributes<HTMLDivElement>> = ({
|
||||
className,
|
||||
@@ -24,7 +24,7 @@ export const Table: React.FC<React.TableHTMLAttributes<HTMLTableElement>> = ({
|
||||
}) => (
|
||||
<table
|
||||
className={cn(
|
||||
'w-full min-w-[540px] border-collapse text-left text-[11px] whitespace-nowrap',
|
||||
'w-full min-w-[680px] border-collapse text-left text-[13px] whitespace-nowrap',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -40,7 +40,7 @@ export const TableHeader: React.FC<React.HTMLAttributes<HTMLTableSectionElement>
|
||||
}) => (
|
||||
<thead
|
||||
className={cn(
|
||||
'bg-[var(--bg-sidebar)] border-b border-[var(--border)] text-[9.5px] font-semibold text-[var(--text-dim)] uppercase tracking-wider',
|
||||
'bg-[var(--bg-sidebar)] border-b border-[var(--border)] text-[12px] font-medium text-[var(--text-muted)] uppercase',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@@ -76,7 +76,7 @@ export const TableHead: React.FC<React.ThHTMLAttributes<HTMLTableCellElement>> =
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<th className={cn('px-2.5 py-1.5 font-medium', className)} {...props}>
|
||||
<th className={cn('px-3 py-2.5 font-medium', className)} {...props}>
|
||||
{children}
|
||||
</th>
|
||||
);
|
||||
@@ -86,7 +86,7 @@ export const TableCell: React.FC<React.TdHTMLAttributes<HTMLTableCellElement>> =
|
||||
children,
|
||||
...props
|
||||
}) => (
|
||||
<td className={cn('px-2.5 py-1.5 text-[var(--text-muted)] align-middle', className)} {...props}>
|
||||
<td className={cn('px-3 py-2.5 text-[var(--text-muted)] align-middle', className)} {...props}>
|
||||
{children}
|
||||
</td>
|
||||
);
|
||||
@@ -98,7 +98,7 @@ export const TableEmpty: React.FC<{ colSpan: number; message?: string }> = ({
|
||||
<tr>
|
||||
<td
|
||||
colSpan={colSpan}
|
||||
className="px-3 py-6 text-center text-[10.5px] text-[var(--text-dim)] italic"
|
||||
className="px-4 py-10 text-center text-[13px] text-[var(--text-dim)]"
|
||||
>
|
||||
{message}
|
||||
</td>
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
|
||||
interface TextProps extends React.HTMLAttributes<HTMLElement> {
|
||||
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'p' | 'span' | 'label' | 'code' | 'div';
|
||||
@@ -15,15 +15,15 @@ export const Text: React.FC<TextProps> = ({
|
||||
...props
|
||||
}) => {
|
||||
const variantStyles = {
|
||||
h1: 'text-[18px] font-semibold tracking-tight text-[var(--text)]',
|
||||
h2: 'text-[15px] font-semibold text-[var(--text)]',
|
||||
h3: 'text-[13px] font-medium text-[var(--text)]',
|
||||
body: 'text-[12.5px] font-normal text-[var(--text)]',
|
||||
muted: 'text-[11.5px] font-normal text-[var(--text-muted)]',
|
||||
dim: 'text-[10.5px] font-normal text-[var(--text-dim)]',
|
||||
label: 'text-[11px] font-medium uppercase tracking-wider text-[var(--text-dim)]',
|
||||
code: 'text-[11px] font-mono text-[var(--accent)] bg-[var(--bg-hover)] px-1.5 py-0.5 border border-[var(--border)]',
|
||||
badge: 'text-[10px] font-medium px-1.5 py-0.5 border border-[var(--border)] text-[var(--text-muted)] inline-flex items-center gap-1',
|
||||
h1: 'text-[24px] font-semibold text-[var(--text)]',
|
||||
h2: 'text-[20px] font-semibold text-[var(--text)]',
|
||||
h3: 'text-[17px] font-medium text-[var(--text)]',
|
||||
body: 'text-[14px] font-normal text-[var(--text)]',
|
||||
muted: 'text-[13px] font-normal text-[var(--text-muted)]',
|
||||
dim: 'text-[12px] font-normal text-[var(--text-dim)]',
|
||||
label: 'text-[12px] font-medium uppercase text-[var(--text-muted)]',
|
||||
code: 'text-[12px] font-mono text-[var(--accent)] bg-[var(--bg-hover)] px-2 py-1 border border-[var(--border)]',
|
||||
badge: 'text-[11.5px] font-medium px-2 py-1 border border-[var(--border)] text-[var(--text-muted)] inline-flex items-center gap-1',
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import React, { createContext, useContext, useState, useCallback } from 'react';
|
||||
import { cn } from '@/lib/utils';
|
||||
import React, { createContext, useCallback, useContext, useState } from 'react';
|
||||
import { Icon } from './Icon';
|
||||
|
||||
export type ToastType = 'success' | 'error' | 'warning' | 'info';
|
||||
@@ -53,7 +53,7 @@ export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ childre
|
||||
return (
|
||||
<ToastContext.Provider value={{ toast: addToast, success, error, warning, info }}>
|
||||
{children}
|
||||
<div className="fixed bottom-4 right-4 z-[9999] flex flex-col gap-2 max-w-[340px] pointer-events-none">
|
||||
<div className="fixed bottom-4 left-4 right-4 sm:left-auto sm:right-6 sm:bottom-6 z-[9999] flex flex-col gap-2 max-w-[420px] pointer-events-none">
|
||||
{toasts.map((t) => {
|
||||
const typeBorder = {
|
||||
success: 'border-l-[3px] border-l-[var(--success)]',
|
||||
@@ -80,17 +80,17 @@ export const ToastProvider: React.FC<{ children: React.ReactNode }> = ({ childre
|
||||
<div
|
||||
key={t.id}
|
||||
className={cn(
|
||||
'pointer-events-auto flex items-start gap-2.5 p-3 bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] text-[12px] transition-all',
|
||||
'pointer-events-auto flex items-start gap-3 p-4 bg-[var(--bg-elevated)] border border-[var(--border-strong)] text-[var(--text)] text-[13px] transition-all',
|
||||
typeBorder
|
||||
)}
|
||||
>
|
||||
<div className="mt-0.5 shrink-0">
|
||||
<Icon name={typeIcon} size={14} color={iconColor} />
|
||||
<Icon name={typeIcon} size={17} color={iconColor} />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="font-medium text-[var(--text)] leading-tight">{t.title}</div>
|
||||
{t.message && (
|
||||
<div className="text-[11px] text-[var(--text-muted)] mt-0.5 leading-normal break-words">
|
||||
<div className="text-[12px] text-[var(--text-muted)] mt-1 leading-normal break-words">
|
||||
{t.message}
|
||||
</div>
|
||||
)}
|
||||
|
||||
+20
-9
@@ -1,9 +1,20 @@
|
||||
export * from './Button';
|
||||
export * from './Input';
|
||||
export * from './Card';
|
||||
export * from './Modal';
|
||||
export * from './Table';
|
||||
export * from './Form';
|
||||
export * from './Text';
|
||||
export * from './Icon';
|
||||
export * from './Toast';
|
||||
export * from "./ActivityPreview";
|
||||
export * from "./Button";
|
||||
export * from "./Card";
|
||||
export * from "./ClientList";
|
||||
export * from "./CodeBlock";
|
||||
export * from "./CopyButton";
|
||||
export * from "./FeatureItem";
|
||||
export * from "./Form";
|
||||
export * from "./Icon";
|
||||
export * from "./Input";
|
||||
export * from "./Modal";
|
||||
export * from "./Panel";
|
||||
export * from "./Pill";
|
||||
export * from "./SectionHeading";
|
||||
export * from "./SettingsLayout";
|
||||
export * from "./StatCard";
|
||||
export * from "./StatStrip";
|
||||
export * from "./Table";
|
||||
export * from "./Text";
|
||||
export * from "./Toast";
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SDKManager } from '../sdk/sdkManager';
|
||||
import { SettingsManager } from '../adminSettings/settingsManager';
|
||||
import { SettingsManager } from "../adminSettings/settingsManager";
|
||||
import { SDKManager } from "../sdk/sdkManager";
|
||||
|
||||
/**
|
||||
* Database Module (PostgreSQL + Prisma abstraction)
|
||||
@@ -11,18 +11,18 @@ export class DatabaseEngine {
|
||||
|
||||
public static async getHealth() {
|
||||
return {
|
||||
status: 'healthy',
|
||||
type: 'PostgreSQL + Prisma Schema Managed',
|
||||
database: 'datastack_db',
|
||||
role: 'Metadata & SDK Registrations Only',
|
||||
collectedDataStorage: 'Strictly CSV (/storage/data)',
|
||||
status: "healthy",
|
||||
type: "PostgreSQL + Prisma Schema Managed",
|
||||
database: "datastack_db",
|
||||
role: "Metadata & SDK Registrations Only",
|
||||
collectedDataStorage: "Strictly CSV (/storage/data)",
|
||||
};
|
||||
}
|
||||
|
||||
public static async syncState() {
|
||||
return {
|
||||
clientsCount: SDKManager.listClients().length,
|
||||
settings: SettingsManager.getSettings(),
|
||||
settings: SettingsManager.getPublicSettings(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+31
-11
@@ -1,16 +1,26 @@
|
||||
export interface ValidationResult {
|
||||
allowed: boolean;
|
||||
reason?: string;
|
||||
code?: 'RATE_LIMIT_EXCEEDED' | 'PAYLOAD_TOO_LARGE' | 'DUPLICATE_EVENT' | 'MALFORMED_PAYLOAD';
|
||||
code?:
|
||||
| "RATE_LIMIT_EXCEEDED"
|
||||
| "PAYLOAD_TOO_LARGE"
|
||||
| "DUPLICATE_EVENT"
|
||||
| "MALFORMED_PAYLOAD";
|
||||
}
|
||||
|
||||
export class SecurityEngine {
|
||||
public static maxEventsPerSec = 100;
|
||||
public static enableIdempotency = true;
|
||||
|
||||
// Idempotency cache: key -> timestamp (expires after TTL)
|
||||
private static idempotencySet = new Map<string, number>();
|
||||
private static readonly IDEMPOTENCY_TTL_MS = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
// Rate limiter: clientId -> { count, windowStart }
|
||||
private static rateLimitMap = new Map<string, { count: number; windowStart: number }>();
|
||||
private static rateLimitMap = new Map<
|
||||
string,
|
||||
{ count: number; windowStart: number }
|
||||
>();
|
||||
|
||||
// Default Max payload size (100KB)
|
||||
public static maxPayloadSizeBytes = 100 * 1024;
|
||||
@@ -49,7 +59,10 @@ export class SecurityEngine {
|
||||
* Rate Limit Check:
|
||||
* Enforces max events per second per client.
|
||||
*/
|
||||
public static checkRateLimit(clientId: string, maxEventsPerSec = 100): boolean {
|
||||
public static checkRateLimit(
|
||||
clientId: string,
|
||||
maxEventsPerSec = this.maxEventsPerSec,
|
||||
): boolean {
|
||||
const now = Date.now();
|
||||
const current = this.rateLimitMap.get(clientId);
|
||||
|
||||
@@ -74,33 +87,40 @@ export class SecurityEngine {
|
||||
clientId: string,
|
||||
eventId: string,
|
||||
payload: unknown,
|
||||
clientMaxRate = 100
|
||||
clientMaxRate = 100,
|
||||
): ValidationResult {
|
||||
// 1. Check idempotency
|
||||
const isUnique = this.checkIdempotency(clientId, eventId);
|
||||
const isUnique =
|
||||
!this.enableIdempotency || this.checkIdempotency(clientId, eventId);
|
||||
if (!isUnique) {
|
||||
return { allowed: false, reason: 'Duplicate event dropped silently', code: 'DUPLICATE_EVENT' };
|
||||
return {
|
||||
allowed: false,
|
||||
reason: "Duplicate event dropped silently",
|
||||
code: "DUPLICATE_EVENT",
|
||||
};
|
||||
}
|
||||
|
||||
// 2. Check rate limit
|
||||
const withinLimit = this.checkRateLimit(clientId, clientMaxRate);
|
||||
const effectiveRateLimit = Math.min(clientMaxRate, this.maxEventsPerSec);
|
||||
const withinLimit = this.checkRateLimit(clientId, effectiveRateLimit);
|
||||
if (!withinLimit) {
|
||||
return {
|
||||
allowed: false,
|
||||
reason: `Rate limit of ${clientMaxRate} events/sec exceeded for client ${clientId}`,
|
||||
code: 'RATE_LIMIT_EXCEEDED',
|
||||
code: "RATE_LIMIT_EXCEEDED",
|
||||
};
|
||||
}
|
||||
|
||||
// 3. Check payload size
|
||||
const payloadStr = typeof payload === 'string' ? payload : JSON.stringify(payload);
|
||||
const byteLength = Buffer.byteLength(payloadStr, 'utf8');
|
||||
const payloadStr =
|
||||
typeof payload === "string" ? payload : JSON.stringify(payload);
|
||||
const byteLength = Buffer.byteLength(payloadStr, "utf8");
|
||||
|
||||
if (byteLength > this.maxPayloadSizeBytes) {
|
||||
return {
|
||||
allowed: false,
|
||||
reason: `Payload size (${(byteLength / 1024).toFixed(1)} KB) exceeds limit of ${this.maxPayloadSizeBytes / 1024} KB`,
|
||||
code: 'PAYLOAD_TOO_LARGE',
|
||||
code: "PAYLOAD_TOO_LARGE",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SecurityEngine } from '../Security/security';
|
||||
import { DataBufferEngine } from '../data/buffer';
|
||||
import { AuthService } from '../auth/jwt';
|
||||
import { CSVStorageManager } from '../Storage/csvStorage';
|
||||
import { AuthService } from "../auth/jwt";
|
||||
import { DataBufferEngine } from "../data/buffer";
|
||||
import { SecurityEngine } from "../Security/security";
|
||||
import { CSVStorageManager } from "../Storage/csvStorage";
|
||||
|
||||
export interface AdminSettings {
|
||||
serverPort: number;
|
||||
@@ -26,7 +26,7 @@ export class SettingsManager {
|
||||
batchFlushThreshold: 500,
|
||||
batchFlushIntervalMs: 2000,
|
||||
fileRotationMb: 100,
|
||||
jwtSecret: 'datastack-universal-secret-key-2026',
|
||||
jwtSecret: process.env.DATASTACK_JWT_SECRET || "",
|
||||
enableIdempotency: true,
|
||||
autoPruneDays: 30,
|
||||
updatedAt: new Date().toISOString(),
|
||||
@@ -36,6 +36,22 @@ export class SettingsManager {
|
||||
return { ...this.settings };
|
||||
}
|
||||
|
||||
public static getPublicSettings(): Omit<AdminSettings, "jwtSecret"> {
|
||||
const settings = this.settings;
|
||||
return {
|
||||
serverPort: settings.serverPort,
|
||||
webPort: settings.webPort,
|
||||
maxEventsPerSec: settings.maxEventsPerSec,
|
||||
maxPayloadSizeKb: settings.maxPayloadSizeKb,
|
||||
batchFlushThreshold: settings.batchFlushThreshold,
|
||||
batchFlushIntervalMs: settings.batchFlushIntervalMs,
|
||||
fileRotationMb: settings.fileRotationMb,
|
||||
enableIdempotency: settings.enableIdempotency,
|
||||
autoPruneDays: settings.autoPruneDays,
|
||||
updatedAt: settings.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
public static updateSettings(updates: Partial<AdminSettings>): AdminSettings {
|
||||
this.settings = {
|
||||
...this.settings,
|
||||
@@ -44,6 +60,12 @@ export class SettingsManager {
|
||||
};
|
||||
|
||||
// Apply live updates to subsystems
|
||||
if (updates.maxEventsPerSec !== undefined) {
|
||||
SecurityEngine.maxEventsPerSec = updates.maxEventsPerSec;
|
||||
}
|
||||
if (updates.enableIdempotency !== undefined) {
|
||||
SecurityEngine.enableIdempotency = updates.enableIdempotency;
|
||||
}
|
||||
if (updates.maxPayloadSizeKb !== undefined) {
|
||||
SecurityEngine.maxPayloadSizeBytes = updates.maxPayloadSizeKb * 1024;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
interface AdminSessionPayload {
|
||||
email: string;
|
||||
expiresAt: number;
|
||||
}
|
||||
|
||||
function encodeBase64Url(bytes: Uint8Array) {
|
||||
let binary = "";
|
||||
for (let index = 0; index < bytes.length; index += 1) {
|
||||
binary += String.fromCharCode(bytes[index]);
|
||||
}
|
||||
return btoa(binary).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
||||
}
|
||||
|
||||
function decodeBase64Url(value: string) {
|
||||
const base64 = value.replace(/-/g, "+").replace(/_/g, "/");
|
||||
const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
|
||||
const binary = atob(padded);
|
||||
return Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
||||
}
|
||||
|
||||
async function importKey(secret: string) {
|
||||
return crypto.subtle.importKey(
|
||||
"raw",
|
||||
encoder.encode(secret),
|
||||
{ name: "HMAC", hash: "SHA-256" },
|
||||
false,
|
||||
["sign", "verify"],
|
||||
);
|
||||
}
|
||||
|
||||
export async function createAdminSessionToken(
|
||||
email: string,
|
||||
secret: string,
|
||||
expiresAt: number,
|
||||
) {
|
||||
const payload = encodeBase64Url(
|
||||
encoder.encode(JSON.stringify({ email, expiresAt })),
|
||||
);
|
||||
const signature = await crypto.subtle.sign(
|
||||
"HMAC",
|
||||
await importKey(secret),
|
||||
encoder.encode(payload),
|
||||
);
|
||||
return `${payload}.${encodeBase64Url(new Uint8Array(signature))}`;
|
||||
}
|
||||
|
||||
export async function verifyAdminSessionToken(token: string, secret: string) {
|
||||
const [payload, signature, extra] = token.split(".");
|
||||
if (!payload || !signature || extra) return false;
|
||||
|
||||
try {
|
||||
const valid = await crypto.subtle.verify(
|
||||
"HMAC",
|
||||
await importKey(secret),
|
||||
decodeBase64Url(signature),
|
||||
encoder.encode(payload),
|
||||
);
|
||||
if (!valid) return false;
|
||||
|
||||
const session = JSON.parse(
|
||||
new TextDecoder().decode(decodeBase64Url(payload)),
|
||||
) as AdminSessionPayload;
|
||||
return (
|
||||
typeof session.email === "string" &&
|
||||
typeof session.expiresAt === "number" &&
|
||||
session.expiresAt > Date.now()
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+26
-7
@@ -1,4 +1,4 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
export interface ClientTokenPayload {
|
||||
clientId: string;
|
||||
@@ -8,7 +8,7 @@ export interface ClientTokenPayload {
|
||||
exp?: number;
|
||||
}
|
||||
|
||||
const DEFAULT_SECRET = process.env.DATASTACK_JWT_SECRET || 'datastack-universal-secret-key-2026';
|
||||
const DEFAULT_SECRET = process.env.DATASTACK_JWT_SECRET || "";
|
||||
|
||||
export class AuthService {
|
||||
private static secret: string = DEFAULT_SECRET;
|
||||
@@ -26,7 +26,16 @@ export class AuthService {
|
||||
/**
|
||||
* Generates a signed JWT for client SDK authentication.
|
||||
*/
|
||||
public static generateClientToken(payload: { clientId: string; name?: string; rateLimit?: number }, expiresIn = '30d'): string {
|
||||
public static generateClientToken(
|
||||
payload: { clientId: string; name?: string; rateLimit?: number },
|
||||
expiresIn = "30d",
|
||||
): string {
|
||||
if (!this.secret) {
|
||||
throw new Error(
|
||||
"DATASTACK_JWT_SECRET must be configured before generating client tokens.",
|
||||
);
|
||||
}
|
||||
|
||||
return jwt.sign(
|
||||
{
|
||||
clientId: payload.clientId,
|
||||
@@ -34,20 +43,30 @@ export class AuthService {
|
||||
rateLimit: payload.rateLimit || 100,
|
||||
},
|
||||
this.secret,
|
||||
{ expiresIn: expiresIn as jwt.SignOptions['expiresIn'] }
|
||||
{ expiresIn: expiresIn as jwt.SignOptions["expiresIn"] },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies and decodes incoming token from Socket.IO handshake.
|
||||
*/
|
||||
public static verifyClientToken(token: string): { valid: boolean; payload?: ClientTokenPayload; error?: string } {
|
||||
public static verifyClientToken(token: string): {
|
||||
valid: boolean;
|
||||
payload?: ClientTokenPayload;
|
||||
error?: string;
|
||||
} {
|
||||
if (!this.secret) {
|
||||
return { valid: false, error: "DATASTACK_JWT_SECRET is not configured." };
|
||||
}
|
||||
|
||||
try {
|
||||
const cleanToken = token.startsWith('Bearer ') ? token.slice(7).trim() : token.trim();
|
||||
const cleanToken = token.startsWith("Bearer ")
|
||||
? token.slice(7).trim()
|
||||
: token.trim();
|
||||
const decoded = jwt.verify(cleanToken, this.secret) as ClientTokenPayload;
|
||||
return { valid: true, payload: decoded };
|
||||
} catch (err: unknown) {
|
||||
const message = err instanceof Error ? err.message : 'Invalid token';
|
||||
const message = err instanceof Error ? err.message : "Invalid token";
|
||||
return { valid: false, error: message };
|
||||
}
|
||||
}
|
||||
|
||||
+28
-16
@@ -1,4 +1,4 @@
|
||||
import { AuthService } from '../auth/jwt';
|
||||
import { AuthService } from "../auth/jwt";
|
||||
|
||||
export interface ClientSDK {
|
||||
clientId: string;
|
||||
@@ -6,7 +6,7 @@ export interface ClientSDK {
|
||||
secret: string;
|
||||
token: string;
|
||||
rateLimit: number; // max events per sec
|
||||
status: 'active' | 'revoked';
|
||||
status: "active" | "revoked";
|
||||
totalEvents: number;
|
||||
lastActive?: string;
|
||||
createdAt: string;
|
||||
@@ -19,29 +19,31 @@ export class SDKManager {
|
||||
static {
|
||||
const seedClients = [
|
||||
{
|
||||
clientId: 'py_telemetry_agent_01',
|
||||
name: 'Python Telemetry Agent (US-East)',
|
||||
clientId: "py_telemetry_agent_01",
|
||||
name: "Python Telemetry Agent (US-East)",
|
||||
rateLimit: 150,
|
||||
},
|
||||
{
|
||||
clientId: 'py_scraper_prod_02',
|
||||
name: 'Python Web Scraper Engine',
|
||||
clientId: "py_scraper_prod_02",
|
||||
name: "Python Web Scraper Engine",
|
||||
rateLimit: 200,
|
||||
},
|
||||
{
|
||||
clientId: 'iot_fleet_east_03',
|
||||
name: 'IoT Sensor Gateway Node',
|
||||
clientId: "iot_fleet_east_03",
|
||||
name: "IoT Sensor Gateway Node",
|
||||
rateLimit: 50,
|
||||
},
|
||||
];
|
||||
|
||||
for (const c of seedClients) {
|
||||
const secret = `sec_${c.clientId}_${Math.random().toString(36).substring(2, 10)}`;
|
||||
const token = AuthService.generateClientToken({
|
||||
const token = AuthService.getSecret()
|
||||
? AuthService.generateClientToken({
|
||||
clientId: c.clientId,
|
||||
name: c.name,
|
||||
rateLimit: c.rateLimit,
|
||||
});
|
||||
})
|
||||
: "";
|
||||
|
||||
SDKManager.clients.set(c.clientId, {
|
||||
clientId: c.clientId,
|
||||
@@ -49,10 +51,10 @@ export class SDKManager {
|
||||
secret,
|
||||
token,
|
||||
rateLimit: c.rateLimit,
|
||||
status: 'active',
|
||||
status: "active",
|
||||
totalEvents: 4280,
|
||||
lastActive: new Date().toISOString(),
|
||||
createdAt: '2026-10-20T10:00:00.000Z',
|
||||
createdAt: "2026-10-20T10:00:00.000Z",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -65,8 +67,15 @@ export class SDKManager {
|
||||
return this.clients.get(clientId);
|
||||
}
|
||||
|
||||
public static registerClient(data: { clientId: string; name: string; rateLimit?: number }): ClientSDK {
|
||||
const safeClientId = data.clientId.trim().toLowerCase().replace(/[^a-z0-9_-]/g, '_');
|
||||
public static registerClient(data: {
|
||||
clientId: string;
|
||||
name: string;
|
||||
rateLimit?: number;
|
||||
}): ClientSDK {
|
||||
const safeClientId = data.clientId
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9_-]/g, "_");
|
||||
const secret = `sec_${safeClientId}_${Math.random().toString(36).substring(2, 10)}`;
|
||||
const rateLimit = data.rateLimit || 100;
|
||||
|
||||
@@ -82,7 +91,7 @@ export class SDKManager {
|
||||
secret,
|
||||
token,
|
||||
rateLimit,
|
||||
status: 'active',
|
||||
status: "active",
|
||||
totalEvents: 0,
|
||||
createdAt: new Date().toISOString(),
|
||||
};
|
||||
@@ -106,7 +115,10 @@ export class SDKManager {
|
||||
return client;
|
||||
}
|
||||
|
||||
public static updateClient(clientId: string, updates: Partial<Pick<ClientSDK, 'name' | 'rateLimit' | 'status'>>): ClientSDK | null {
|
||||
public static updateClient(
|
||||
clientId: string,
|
||||
updates: Partial<Pick<ClientSDK, "name" | "rateLimit" | "status">>,
|
||||
): ClientSDK | null {
|
||||
const client = this.clients.get(clientId);
|
||||
if (!client) return null;
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
FROM node:22-alpine AS dependencies
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci --omit=dev
|
||||
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV PORT_SOCKET=4000
|
||||
RUN mkdir -p /app/storage/data \
|
||||
&& chown -R node:node /app/storage
|
||||
COPY --from=dependencies --chown=node:node /app/node_modules ./node_modules
|
||||
COPY --chown=node:node server ./server
|
||||
USER node
|
||||
EXPOSE 4000
|
||||
CMD ["node", "server/index.js"]
|
||||
@@ -0,0 +1,28 @@
|
||||
FROM node:22-alpine AS dependencies
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
FROM node:22-alpine AS builder
|
||||
WORKDIR /app
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
COPY --from=dependencies /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
FROM node:22-alpine AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
RUN addgroup -S -g 1001 nodejs \
|
||||
&& adduser -S -u 1001 -G nodejs nextjs
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
RUN mkdir -p /app/storage/data \
|
||||
&& chown -R nextjs:nodejs /app/storage
|
||||
USER nextjs
|
||||
EXPOSE 3000
|
||||
CMD ["node", "server.js"]
|
||||
+51
-24
@@ -1,5 +1,3 @@
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
# Next.js Frontend & Admin Console (Port 3000)
|
||||
web:
|
||||
@@ -9,13 +7,26 @@ services:
|
||||
ports:
|
||||
- "3000:3000"
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- DATASTACK_JWT_SECRET=datastack-universal-secret-key-2026
|
||||
- DATABASE_URL=postgresql://datastack:securepass@postgres:5432/datastack_db
|
||||
NODE_ENV: production
|
||||
PORT: "3000"
|
||||
DATASTACK_JWT_SECRET: "${DATASTACK_JWT_SECRET:?Set DATASTACK_JWT_SECRET in .env}"
|
||||
DATASTACK_ADMIN_EMAIL: "${DATASTACK_ADMIN_EMAIL:?Set DATASTACK_ADMIN_EMAIL in .env}"
|
||||
DATASTACK_ADMIN_PASSWORD: "${DATASTACK_ADMIN_PASSWORD:?Set DATASTACK_ADMIN_PASSWORD in .env}"
|
||||
DATASTACK_ADMIN_SESSION_SECRET: "${DATASTACK_ADMIN_SESSION_SECRET:?Set DATASTACK_ADMIN_SESSION_SECRET in .env}"
|
||||
DATABASE_URL: "${DATABASE_URL:?Set DATABASE_URL in .env}"
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- redis
|
||||
- postgres
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD",
|
||||
"node",
|
||||
"-e",
|
||||
"fetch('http://127.0.0.1:3000/').then((response) => process.exit(response.ok ? 0 : 1)).catch(() => process.exit(1))",
|
||||
]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 30s
|
||||
|
||||
# Express + Socket.IO Ingestion Engine (Port 4000)
|
||||
ingestion:
|
||||
@@ -25,35 +36,51 @@ services:
|
||||
ports:
|
||||
- "4000:4000"
|
||||
volumes:
|
||||
- ../storage:/app/storage
|
||||
- datastack-data:/app/storage
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
- PORT_SOCKET=4000
|
||||
- DATASTACK_JWT_SECRET=datastack-universal-secret-key-2026
|
||||
- REDIS_URL=redis://redis:6379
|
||||
NODE_ENV: production
|
||||
PORT_SOCKET: "4000"
|
||||
DATASTACK_JWT_SECRET: "${DATASTACK_JWT_SECRET:?Set DATASTACK_JWT_SECRET in .env}"
|
||||
restart: unless-stopped
|
||||
depends_on:
|
||||
- redis
|
||||
healthcheck:
|
||||
test:
|
||||
[
|
||||
"CMD",
|
||||
"node",
|
||||
"-e",
|
||||
"fetch('http://127.0.0.1:4000/health').then((response) => process.exit(response.ok ? 0 : 1)).catch(() => process.exit(1))",
|
||||
]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
start_period: 10s
|
||||
|
||||
# Redis In-Memory Buffer Broker
|
||||
# Reserved for the planned shared buffer integration; not consumed by the current runtime.
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
# PostgreSQL for Admin Metadata Only (NOT collected data)
|
||||
# Reserved for the planned metadata integration; not consumed by the current runtime.
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
- POSTGRES_USER=datastack
|
||||
- POSTGRES_PASSWORD=securepass
|
||||
- POSTGRES_DB=datastack_db
|
||||
POSTGRES_USER: datastack
|
||||
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}"
|
||||
POSTGRES_DB: datastack_db
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U datastack -d datastack_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
datastack-data:
|
||||
pgdata:
|
||||
+17
-5
@@ -1,8 +1,20 @@
|
||||
# Docker Deployment Manifest
|
||||
|
||||
## Purpose
|
||||
Containerization specs for the split architecture runtime:
|
||||
- `web`: Next.js frontend + Admin console on Port 3000
|
||||
- `ingestion`: Express + Socket.IO process on Port 4000
|
||||
- `redis`: In-memory buffer broker and pub/sub
|
||||
- `postgres`: Dedicated database for administrative metadata and client registrations (no collected data)
|
||||
|
||||
Production container definitions for the split architecture:
|
||||
|
||||
- `web`: standalone Next.js frontend and admin console on port 3000, running as a non-root user.
|
||||
- `ingestion`: Express + Socket.IO process on port 4000, running as a non-root user.
|
||||
- `redis`: private Compose service reserved for the planned shared-buffer integration; current application code does not consume it.
|
||||
- `postgres`: private Compose service reserved for metadata integration; current application code does not use Prisma at runtime. Collected events must remain in CSV files.
|
||||
|
||||
## Build and Run
|
||||
|
||||
- Run from the repository root with Docker Engine and the Compose plugin installed.
|
||||
- Copy `.env.example` to `.env` and provide non-empty deployment values; Compose deliberately has no committed secret defaults.
|
||||
- Validate and start with `docker compose --env-file .env -f docker/docker-compose.yml config` and `docker compose --env-file .env -f docker/docker-compose.yml up --build -d`.
|
||||
- Only the web and ingestion ports are published. PostgreSQL and Redis remain private to the Compose network.
|
||||
- The `datastack-data` named volume persists ingestion CSVs; `pgdata` persists PostgreSQL files.
|
||||
- The web container does not yet share/read `datastack-data`, and neither Redis nor PostgreSQL is wired into runtime code. Those are later roadmap phases, so cross-process reads and metadata durability are not established by these images.
|
||||
- Health checks probe the public landing route, ingestion `/health`, Redis ping, and PostgreSQL readiness. These checks do not establish application-level shared-storage readiness.
|
||||
@@ -0,0 +1,51 @@
|
||||
import { verifyAdminSessionToken } from "@/core/auth/adminSession";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const SESSION_COOKIE = "datastack_admin_session";
|
||||
|
||||
function isProtectedApi(pathname: string, method: string) {
|
||||
if (pathname === "/api/auth/login") return false;
|
||||
if (pathname === "/api/events" && method === "POST") return false;
|
||||
return pathname.startsWith("/api/");
|
||||
}
|
||||
|
||||
export async function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
const isLoginPage = pathname === "/vcon/login";
|
||||
const isConsolePage =
|
||||
(pathname === "/vcon" || pathname.startsWith("/vcon/")) && !isLoginPage;
|
||||
const isAdminApi = isProtectedApi(pathname, request.method);
|
||||
|
||||
if (!isConsolePage && !isAdminApi && !isLoginPage) return NextResponse.next();
|
||||
|
||||
const sessionSecret = process.env.DATASTACK_ADMIN_SESSION_SECRET;
|
||||
const token = request.cookies.get(SESSION_COOKIE)?.value;
|
||||
const authenticated = Boolean(
|
||||
sessionSecret &&
|
||||
token &&
|
||||
(await verifyAdminSessionToken(token, sessionSecret)),
|
||||
);
|
||||
|
||||
if (isLoginPage) {
|
||||
if (authenticated)
|
||||
return NextResponse.redirect(new URL("/vcon/dashboard", request.url));
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
if (authenticated) return NextResponse.next();
|
||||
|
||||
if (isAdminApi) {
|
||||
return NextResponse.json(
|
||||
{ error: "Authentication required." },
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
const loginUrl = new URL("/vcon/login", request.url);
|
||||
loginUrl.searchParams.set("next", `${pathname}${request.nextUrl.search}`);
|
||||
return NextResponse.redirect(loginUrl);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/vcon", "/vcon/:path*", "/api/:path*"],
|
||||
};
|
||||
Generated
+13691
File diff suppressed because it is too large.
Load diff
@@ -17,6 +17,7 @@
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cors": "^2.8.6",
|
||||
"csv-parse": "^7.0.3",
|
||||
"express": "^5.3.0",
|
||||
"json2csv": "^6.0.0-alpha.2",
|
||||
"jsonwebtoken": "^9.0.3",
|
||||
|
||||
+33
-14
@@ -1,7 +1,12 @@
|
||||
const jwt = require('jsonwebtoken');
|
||||
const jwt = require("jsonwebtoken");
|
||||
|
||||
function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
const jwtSecret = options.jwtSecret || process.env.DATASTACK_JWT_SECRET || 'datastack-universal-secret-key-2026';
|
||||
const jwtSecret = options.jwtSecret || process.env.DATASTACK_JWT_SECRET;
|
||||
if (!jwtSecret) {
|
||||
throw new Error(
|
||||
"DATASTACK_JWT_SECRET must be configured before starting the socket server.",
|
||||
);
|
||||
}
|
||||
const idempotencyMap = new Map();
|
||||
const rateLimitMap = new Map();
|
||||
|
||||
@@ -13,11 +18,13 @@ function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
socket.handshake.query?.token;
|
||||
|
||||
if (!authHeader) {
|
||||
return next(new Error('AUTH_REQUIRED: Handshake missing JWT'));
|
||||
return next(new Error("AUTH_REQUIRED: Handshake missing JWT"));
|
||||
}
|
||||
|
||||
try {
|
||||
const cleanToken = authHeader.startsWith('Bearer ') ? authHeader.slice(7) : authHeader;
|
||||
const cleanToken = authHeader.startsWith("Bearer ")
|
||||
? authHeader.slice(7)
|
||||
: authHeader;
|
||||
const decoded = jwt.verify(cleanToken, jwtSecret);
|
||||
socket.data.clientId = decoded.clientId;
|
||||
socket.data.rateLimit = decoded.rateLimit || 100;
|
||||
@@ -27,21 +34,24 @@ function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
}
|
||||
});
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
io.on("connection", (socket) => {
|
||||
const clientId = socket.data.clientId;
|
||||
const rateLimit = socket.data.rateLimit;
|
||||
socket.join(`client:${clientId}`);
|
||||
|
||||
// Single event
|
||||
socket.on('sync_data', (payload, callback) => {
|
||||
socket.on("sync_data", (payload, callback) => {
|
||||
try {
|
||||
const eventId = payload.eventId || `evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
||||
const eventId =
|
||||
payload.eventId ||
|
||||
`evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
||||
const timestamp = payload.timestamp || new Date().toISOString();
|
||||
|
||||
// Idempotency
|
||||
const key = `${clientId}:${eventId}`;
|
||||
if (idempotencyMap.has(key)) {
|
||||
if (callback) callback({ success: true, eventId, note: 'DUPLICATE_DROPPED' });
|
||||
if (callback)
|
||||
callback({ success: true, eventId, note: "DUPLICATE_DROPPED" });
|
||||
return;
|
||||
}
|
||||
idempotencyMap.set(key, Date.now());
|
||||
@@ -52,7 +62,8 @@ function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
if (!rl || now - rl.start >= 1000) {
|
||||
rateLimitMap.set(clientId, { count: 1, start: now });
|
||||
} else if (rl.count >= rateLimit) {
|
||||
if (callback) callback({ success: false, error: 'RATE_LIMIT_EXCEEDED' });
|
||||
if (callback)
|
||||
callback({ success: false, error: "RATE_LIMIT_EXCEEDED" });
|
||||
return;
|
||||
} else {
|
||||
rl.count += 1;
|
||||
@@ -62,7 +73,10 @@ function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
clientId,
|
||||
eventId,
|
||||
timestamp,
|
||||
payload: typeof payload.data === 'string' ? payload.data : JSON.stringify(payload.data),
|
||||
payload:
|
||||
typeof payload.data === "string"
|
||||
? payload.data
|
||||
: JSON.stringify(payload.data),
|
||||
};
|
||||
|
||||
bufferQueue.push(event);
|
||||
@@ -74,22 +88,27 @@ function setupSocketHandlers(io, bufferQueue, worker, options = {}) {
|
||||
});
|
||||
|
||||
// Batch event
|
||||
socket.on('batch_sync', (batch, callback) => {
|
||||
socket.on("batch_sync", (batch, callback) => {
|
||||
if (!Array.isArray(batch)) {
|
||||
if (callback) callback({ success: false, error: 'Expected array' });
|
||||
if (callback) callback({ success: false, error: "Expected array" });
|
||||
return;
|
||||
}
|
||||
|
||||
let count = 0;
|
||||
for (const item of batch) {
|
||||
const eventId = item.eventId || `evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
||||
const eventId =
|
||||
item.eventId ||
|
||||
`evt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`;
|
||||
const timestamp = item.timestamp || new Date().toISOString();
|
||||
|
||||
bufferQueue.push({
|
||||
clientId,
|
||||
eventId,
|
||||
timestamp,
|
||||
payload: typeof item.data === 'string' ? item.data : JSON.stringify(item.data),
|
||||
payload:
|
||||
typeof item.data === "string"
|
||||
? item.data
|
||||
: JSON.stringify(item.data),
|
||||
});
|
||||
count++;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user