openreader/src/lib/server/runtime-config.ts
Richard R 876ca7d774 feat(admin,config,ui,db): introduce runtime-editable site config and admin-managed TTS providers
Add database-backed runtime configuration for feature flags and TTS provider credentials, editable via a new admin UI panel. Replace static NEXT_PUBLIC_* and TTS provider env vars with admin-managed settings stored in the database and injected at SSR for client access. Implement admin-only panels for managing shared TTS provider credentials (with encrypted API keys) and live site feature flags. Add schema migrations, API routes, React contexts, and hooks for SSR-injected runtime config and live updates. Update client and server logic to resolve configuration from the database at runtime, enforcing admin restrictions and supporting migration from legacy env-based config.

BREAKING CHANGE: Feature flags and TTS provider credentials are now managed at runtime via the admin UI. Environment variables are only used for initial seeding and are ignored after first boot. Existing deployments must migrate configuration to the admin panel.
2026-05-12 22:39:24 -06:00

31 lines
951 B
TypeScript

import 'server-only';
import { ensureAdminSeed } from '@/lib/server/admin/seed';
import {
getRuntimeConfig,
getRuntimeConfigWithSources,
type RuntimeConfig,
type RuntimeConfigKey,
type RuntimeConfigSource,
} from '@/lib/server/admin/settings';
export type ResolvedRuntimeConfig = RuntimeConfig;
/**
* Returns the resolved site-wide runtime config in the shape consumed by
* the client via SSR injection. Triggers the boot-time seed on first call
* so env values land in the DB before the first read.
*/
export async function getResolvedRuntimeConfig(): Promise<ResolvedRuntimeConfig> {
await ensureAdminSeed();
return getRuntimeConfig();
}
export async function getResolvedRuntimeConfigWithSources(): Promise<{
values: RuntimeConfig;
sources: Record<RuntimeConfigKey, RuntimeConfigSource | 'default'>;
}> {
await ensureAdminSeed();
return getRuntimeConfigWithSources();
}
export type { RuntimeConfig, RuntimeConfigKey };