feat: add plugin/theme harness and admin dashboard

Plugin & Theme System:
- Add plugin type definitions, permissions (30+), and validation constants
- Add IndexedDB storage layer for plugin code, theme CSS, and previews
- Add theme CSS sanitization, injection, and safety validation
- Add HookBus event system with 130+ hooks across 20 domains
- Add plugin ZIP extraction and manifest validation with JS security checks
- Add sandboxed PluginAPI factory with scoped storage, logging, and permission gating
- Add plugin loader with blob URL dynamic import and auto-disable circuit breaker
- Add 3 built-in themes (Nord, Catppuccin, Solarized)
- Add Zustand plugin store with install/uninstall/enable/disable lifecycle
- Add PluginSlot, PluginSlotRenderer, and PluginErrorBoundary components
- Add plugins and themes settings UI panels
- Integrate plugin slots into email viewer, composer, navigation rail, sidebar, and context menu
- Extend theme store with custom theme installation and activation

Admin Dashboard:
- Add admin authentication with scrypt password hashing and AES-256-GCM sessions
- Add rate-limited login (5 attempts/15min per IP)
- Add config manager with admin override > env var > default priority
- Add settings policy system with feature gates and per-setting restrictions
- Add audit logging with rotation
- Add admin API routes (login, logout, config, policy, audit, password change)
- Add admin UI pages (login, dashboard, config, policy, audit)
- Add policy store for client-side feature gate enforcement
- Wire admin password initialization into server instrumentation

Tests:
- Add 139 tests across 10 test files covering all plugin/theme modules
This commit is contained in:
Linus Rath
2026-03-25 00:44:03 +01:00
parent 78bcf8db1b
commit 76b21147e4
63 changed files with 7894 additions and 67 deletions
@@ -0,0 +1,36 @@
'use client';
import React from 'react';
export interface PluginErrorBoundaryProps {
pluginId: string;
children?: React.ReactNode;
fallback?: React.ReactNode;
}
interface PluginErrorBoundaryState {
hasError: boolean;
error?: Error;
}
export class PluginErrorBoundary extends React.Component<PluginErrorBoundaryProps, PluginErrorBoundaryState> {
constructor(props: PluginErrorBoundaryProps) {
super(props);
this.state = { hasError: false };
}
static getDerivedStateFromError(error: Error): PluginErrorBoundaryState {
return { hasError: true, error };
}
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {
console.error(`[plugin:${this.props.pluginId}] Render error:`, error, errorInfo);
}
render(): React.ReactNode {
if (this.state.hasError) {
return this.props.fallback ?? null;
}
return this.props.children;
}
}
@@ -0,0 +1,21 @@
'use client';
import React from 'react';
import type { SlotRegistration } from '@/lib/plugin-types';
import { PluginErrorBoundary } from './plugin-error-boundary';
interface PluginSlotRendererProps {
registration: SlotRegistration;
fallback?: React.ReactNode;
extraProps?: Record<string, unknown>;
}
export function PluginSlotRenderer({ registration, fallback = null, extraProps }: PluginSlotRendererProps) {
const Component = registration.component;
return (
<PluginErrorBoundary pluginId={registration.pluginId} fallback={fallback}>
<Component {...(extraProps ?? {})} />
</PluginErrorBoundary>
);
}
+30
View File
@@ -0,0 +1,30 @@
'use client';
import React from 'react';
import type { SlotName } from '@/lib/plugin-types';
import { usePluginStore } from '@/stores/plugin-store';
import { PluginSlotRenderer } from './plugin-slot-renderer';
interface PluginSlotProps {
name: SlotName;
className?: string;
extraProps?: Record<string, unknown>;
}
export function PluginSlot({ name, className, extraProps }: PluginSlotProps) {
const registrations = usePluginStore(s => s.slots[name]);
if (!registrations || registrations.length === 0) return null;
return (
<div className={className} data-plugin-slot={name}>
{registrations.map((reg, i) => (
<PluginSlotRenderer
key={`${reg.pluginId}-${i}`}
registration={reg}
extraProps={extraProps}
/>
))}
</div>
);
}