Files
console/src/lib/flags.ts
T
2025-08-31 20:02:41 +05:30

23 lines
775 B
TypeScript

import { env } from '$env/dynamic/public';
import type { Account } from './stores/user';
import type { Organization } from './stores/organization';
// Parse feature flags from env as a string array (exact match only)
const flagsRaw = (env.PUBLIC_CONSOLE_FEATURE_FLAGS ?? '').split(',');
// @ts-expect-error: unused method!
function isFlagEnabled(name: string) {
// loose generic to allow safe access while retaining type safety
return <T extends { account?: Account; organization?: Organization }>(data: T) => {
const { account, organization } = data;
return !!(
flagsRaw.includes(name) ||
account?.prefs?.[`flags-${name}`] ||
organization?.prefs?.[`flags-${name}`]
);
};
}
export const flags = {};