/** * In-memory feature flag registry for product backends. * * Products call createFlagRegistry() with their default flags, * then use isFeatureEnabled/getAllFlags/setFlag as needed. */ export interface FlagRegistry { isFeatureEnabled(flag: string, userId?: string): boolean; getAllFlags(): Record; setFlag(flag: string, value: boolean): void; } export interface FlagRegistryOptions { /** Default flag values. */ defaults: Record; /** Master switch — when false, flags are still resolved from defaults but * the registry won't attempt remote/dynamic flag resolution (future use). */ enabled?: boolean; } export function createFlagRegistry(opts: FlagRegistryOptions): FlagRegistry { const flags: Map = new Map(Object.entries(opts.defaults)); return { isFeatureEnabled(flag: string, _userId?: string): boolean { return flags.get(flag) ?? false; }, getAllFlags(): Record { return Object.fromEntries(flags); }, setFlag(flag: string, value: boolean): void { flags.set(flag, value); }, }; }