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
97 lines
3.2 KiB
TypeScript
97 lines
3.2 KiB
TypeScript
// IndexedDB storage for plugin/theme binary blobs (JS bundles, CSS, previews)
|
|
|
|
const DB_NAME = 'bulwark-plugins';
|
|
const DB_VERSION = 1;
|
|
const STORE_PLUGINS = 'plugin-code';
|
|
const STORE_THEMES = 'theme-css';
|
|
const STORE_PREVIEWS = 'previews';
|
|
|
|
function openDB(): Promise<IDBDatabase> {
|
|
return new Promise((resolve, reject) => {
|
|
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
|
|
request.onupgradeneeded = () => {
|
|
const db = request.result;
|
|
if (!db.objectStoreNames.contains(STORE_PLUGINS)) {
|
|
db.createObjectStore(STORE_PLUGINS);
|
|
}
|
|
if (!db.objectStoreNames.contains(STORE_THEMES)) {
|
|
db.createObjectStore(STORE_THEMES);
|
|
}
|
|
if (!db.objectStoreNames.contains(STORE_PREVIEWS)) {
|
|
db.createObjectStore(STORE_PREVIEWS);
|
|
}
|
|
};
|
|
|
|
request.onsuccess = () => resolve(request.result);
|
|
request.onerror = () => reject(request.error);
|
|
});
|
|
}
|
|
|
|
async function putItem(storeName: string, key: string, value: string | Blob): Promise<void> {
|
|
const db = await openDB();
|
|
return new Promise((resolve, reject) => {
|
|
const tx = db.transaction(storeName, 'readwrite');
|
|
tx.objectStore(storeName).put(value, key);
|
|
tx.oncomplete = () => resolve();
|
|
tx.onerror = () => reject(tx.error);
|
|
});
|
|
}
|
|
|
|
async function getItem<T = string>(storeName: string, key: string): Promise<T | null> {
|
|
const db = await openDB();
|
|
return new Promise((resolve, reject) => {
|
|
const tx = db.transaction(storeName, 'readonly');
|
|
const request = tx.objectStore(storeName).get(key);
|
|
request.onsuccess = () => resolve(request.result ?? null);
|
|
request.onerror = () => reject(request.error);
|
|
});
|
|
}
|
|
|
|
async function deleteItem(storeName: string, key: string): Promise<void> {
|
|
const db = await openDB();
|
|
return new Promise((resolve, reject) => {
|
|
const tx = db.transaction(storeName, 'readwrite');
|
|
tx.objectStore(storeName).delete(key);
|
|
tx.oncomplete = () => resolve();
|
|
tx.onerror = () => reject(tx.error);
|
|
});
|
|
}
|
|
|
|
// ─── Public API ──────────────────────────────────────────────
|
|
|
|
export const pluginStorage = {
|
|
// Plugin JS bundles
|
|
async saveCode(pluginId: string, code: string): Promise<void> {
|
|
await putItem(STORE_PLUGINS, pluginId, code);
|
|
},
|
|
async getCode(pluginId: string): Promise<string | null> {
|
|
return getItem<string>(STORE_PLUGINS, pluginId);
|
|
},
|
|
async deleteCode(pluginId: string): Promise<void> {
|
|
await deleteItem(STORE_PLUGINS, pluginId);
|
|
},
|
|
|
|
// Theme CSS blobs
|
|
async saveThemeCSS(themeId: string, css: string): Promise<void> {
|
|
await putItem(STORE_THEMES, themeId, css);
|
|
},
|
|
async getThemeCSS(themeId: string): Promise<string | null> {
|
|
return getItem<string>(STORE_THEMES, themeId);
|
|
},
|
|
async deleteThemeCSS(themeId: string): Promise<void> {
|
|
await deleteItem(STORE_THEMES, themeId);
|
|
},
|
|
|
|
// Preview images (stored as data URIs)
|
|
async savePreview(id: string, dataUri: string): Promise<void> {
|
|
await putItem(STORE_PREVIEWS, id, dataUri);
|
|
},
|
|
async getPreview(id: string): Promise<string | null> {
|
|
return getItem<string>(STORE_PREVIEWS, id);
|
|
},
|
|
async deletePreview(id: string): Promise<void> {
|
|
await deleteItem(STORE_PREVIEWS, id);
|
|
},
|
|
};
|