Files
sign/packages/lib/constants/feature-flags.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-01-25 10:48:20 +02:00
import { env } from 'next-runtime-env';
2023-09-28 12:56:53 +10:00
import { APP_BASE_URL } from './app';
2024-01-25 10:48:20 +02:00
const NEXT_PUBLIC_FEATURE_BILLING_ENABLED = env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED');
const NEXT_PUBLIC_POSTHOG_KEY = env('NEXT_PUBLIC_POSTHOG_KEY');
2023-09-20 13:48:30 +10:00
/**
* The flag name for global session recording feature flag.
*/
export const FEATURE_FLAG_GLOBAL_SESSION_RECORDING = 'global_session_recording';
2023-08-18 20:05:14 +10:00
/**
* How frequent to poll for new feature flags in milliseconds.
*/
export const FEATURE_FLAG_POLL_INTERVAL = 30000;
/**
* Feature flags that will be used when PostHog is disabled.
*
* Does not take any person or group properties into account.
*/
export const LOCAL_FEATURE_FLAGS: Record<string, boolean> = {
2024-01-25 10:48:20 +02:00
app_billing: NEXT_PUBLIC_FEATURE_BILLING_ENABLED === 'true',
2023-09-20 13:48:30 +10:00
marketing_header_single_player_mode: false,
2023-08-18 20:05:14 +10:00
} as const;
/**
* Extract the PostHog configuration from the environment.
*/
export function extractPostHogConfig(): { key: string; host: string } | null {
2024-01-25 10:48:20 +02:00
const postHogKey = NEXT_PUBLIC_POSTHOG_KEY;
2023-09-28 12:56:53 +10:00
const postHogHost = `${APP_BASE_URL}/ingest`;
2023-08-18 20:05:14 +10:00
if (!postHogKey || !postHogHost) {
return null;
}
return {
key: postHogKey,
host: postHogHost,
};
}
/**
* Whether feature flags are enabled for the current instance.
*/
export function isFeatureFlagEnabled(): boolean {
return extractPostHogConfig() !== null;
}