import { Settings as SettingsIcon, Bell, Shield, Globe, Palette, Check, Copy, RotateCcw } from 'lucide-react'; import { useEffect, useState, useCallback } from 'react'; type Prefs = { notifications: { syncFailures: boolean; partialRuns: boolean; connectionErrors: boolean; digestEmail: string; }; access: { requireMfa: boolean; sessionMinutes: number; vaultPolicy: 'tight' | 'standard' | 'loose'; }; api: { keys: { id: string; label: string; created: string; preview: string }[]; webhookUrl: string; }; appearance: { density: 'compact' | 'comfortable' | 'spacious'; accent: 'cyan' | 'blue' | 'amber' | 'emerald'; reduceMotion: boolean; }; }; const DEFAULTS: Prefs = { notifications: { syncFailures: true, partialRuns: true, connectionErrors: true, digestEmail: '' }, access: { requireMfa: false, sessionMinutes: 60, vaultPolicy: 'standard' }, api: { keys: [], webhookUrl: '' }, appearance: { density: 'comfortable', accent: 'cyan', reduceMotion: false }, }; const STORAGE_KEY = 'conduit.settings.v1'; function loadPrefs(): Prefs { if (typeof window === 'undefined') return DEFAULTS; try { const raw = window.localStorage.getItem(STORAGE_KEY); if (!raw) return DEFAULTS; const parsed = JSON.parse(raw); return { ...DEFAULTS, ...parsed, notifications: { ...DEFAULTS.notifications, ...(parsed.notifications || {}) }, access: { ...DEFAULTS.access, ...(parsed.access || {}) }, api: { ...DEFAULTS.api, ...(parsed.api || {}) }, appearance: { ...DEFAULTS.appearance, ...(parsed.appearance || {}) } }; } catch { return DEFAULTS; } } function savePrefs(p: Prefs) { if (typeof window === 'undefined') return; try { window.localStorage.setItem(STORAGE_KEY, JSON.stringify(p)); } catch { /* quota or disabled — ignore */ } } function genKey() { const bytes = new Uint8Array(24); (globalThis.crypto || (window as any).crypto).getRandomValues(bytes); return 'cdu_' + Array.from(bytes).map((b) => b.toString(16).padStart(2, '0')).join(''); } function Toggle({ checked, onChange, label, sub }: { checked: boolean; onChange: (v: boolean) => void; label: string; sub?: string }) { return ( onChange(!checked)} className={`mt-0.5 w-9 h-5 rounded-full border transition-colors flex-shrink-0 ${checked ? 'bg-primary/80 border-primary' : 'bg-muted border-border'}`} > {label} {sub ? {sub} : null} ); } function SavedBadge({ visible }: { visible: boolean }) { return ( Saved ); } export default function Settings() { const [prefs, setPrefs] = useState(DEFAULTS); const [hydrated, setHydrated] = useState(false); const [savedAt, setSavedAt] = useState(0); const [copiedKey, setCopiedKey] = useState(null); useEffect(() => { setPrefs(loadPrefs()); setHydrated(true); }, []); const update = useCallback((section: K, patch: Partial) => { setPrefs((curr) => { const next = { ...curr, [section]: { ...curr[section], ...patch } }; savePrefs(next); setSavedAt(Date.now()); return next; }); }, []); const showSaved = hydrated && Date.now() - savedAt < 1800; const issueKey = useCallback(() => { const full = genKey(); const id = full.slice(0, 12); update('api', { keys: [...prefs.api.keys, { id, label: `key-${prefs.api.keys.length + 1}`, created: new Date().toISOString(), preview: full }] }); void navigator.clipboard?.writeText(full).then(() => setCopiedKey(id)).catch(() => undefined); setTimeout(() => setCopiedKey(null), 2000); }, [prefs.api.keys, update]); const revokeKey = useCallback((id: string) => { update('api', { keys: prefs.api.keys.filter((k) => k.id !== id) }); }, [prefs.api.keys, update]); const reset = useCallback(() => { if (typeof window !== 'undefined' && window.confirm('Reset all settings to defaults?')) { savePrefs(DEFAULTS); setPrefs(DEFAULTS); setSavedAt(Date.now()); } }, []); return ( Settings Global configuration for Amaru. Stored locally on this device. Reset NotificationsAlerts for sync failures, partial runs, connection errors. update('notifications', { syncFailures: v })} label="Sync failures" sub="A destination push fails fully." /> update('notifications', { partialRuns: v })} label="Partial runs" sub="Some destinations succeed and some fail in one run." /> update('notifications', { connectionErrors: v })} label="Connection errors" sub="A connector cannot reach its target." /> Digest email (daily summary) update('notifications', { digestEmail: e.target.value })} placeholder="ops@example.com" className="w-full px-3 py-2 text-sm rounded-md bg-muted border border-border focus:border-primary/60 focus:outline-none" /> Access ControlOperator session and credential vault policy. update('access', { requireMfa: v })} label="Require MFA on sign-in" sub="Operators must present a second factor." /> Session timeout — {prefs.access.sessionMinutes} minutes update('access', { sessionMinutes: Number(e.target.value) })} className="w-full accent-[var(--color-conduit-cyan,#22d3ee)]" /> 15m4h8h Vault policy {(['tight', 'standard', 'loose'] as const).map((p) => ( update('access', { vaultPolicy: p })} className={`px-2 py-1.5 text-xs rounded-md border capitalize transition-colors ${prefs.access.vaultPolicy === p ? 'bg-primary/15 border-primary/50 text-primary' : 'bg-muted border-border text-muted-foreground hover:border-foreground/30'}`}>{p} ))} API & WebhooksIssue keys for external triggers and outbound webhooks. + Issue key Outbound webhook URL update('api', { webhookUrl: e.target.value })} placeholder="https://your-system.example/hooks/conduit" className="w-full px-3 py-2 text-sm font-mono rounded-md bg-muted border border-border focus:border-primary/60 focus:outline-none" /> {prefs.api.keys.length === 0 ? ( No keys issued yet. Issue one — it'll be copied to your clipboard once. ) : ( prefs.api.keys.map((k) => ( {k.preview.slice(0, 16)}…{k.preview.slice(-4)} { void navigator.clipboard?.writeText(k.preview); setCopiedKey(k.id); setTimeout(() => setCopiedKey(null), 1500); }} className="text-muted-foreground hover:text-foreground" title="Copy"> {copiedKey === k.id ? : } revokeKey(k.id)} className="text-muted-foreground hover:text-red-400 px-1.5">Revoke )) )} AppearanceTheme and display preferences for this browser. Density {(['compact', 'comfortable', 'spacious'] as const).map((d) => ( update('appearance', { density: d })} className={`px-2 py-1.5 text-xs rounded-md border capitalize transition-colors ${prefs.appearance.density === d ? 'bg-primary/15 border-primary/50 text-primary' : 'bg-muted border-border text-muted-foreground hover:border-foreground/30'}`}>{d} ))} Accent {([ { id: 'cyan' as const, hex: '#22d3ee' }, { id: 'blue' as const, hex: '#60a5fa' }, { id: 'amber' as const, hex: '#fbbf24' }, { id: 'emerald' as const, hex: '#34d399' }, ]).map((c) => ( update('appearance', { accent: c.id })} aria-label={c.id} className={`w-7 h-7 rounded-full border-2 transition-transform ${prefs.appearance.accent === c.id ? 'border-foreground scale-110' : 'border-transparent hover:border-foreground/40'}`} style={{ background: c.hex }} /> ))} update('appearance', { reduceMotion: v })} label="Reduce motion" sub="Disable animations and transitions." /> About Amaru Version1.0.0 Environmentdevelopment API Base/api/amaru Destinations13 supported ); }
Global configuration for Amaru. Stored locally on this device.