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

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2025-01-02 15:33:37 +11:00
import { env } from '@documenso/lib/utils/env';
2024-01-25 10:48:20 +02:00
2025-01-02 15:33:37 +11:00
import { NEXT_PUBLIC_WEBAPP_URL } from './app';
2023-09-28 12:56:53 +10:00
const NEXT_PUBLIC_FEATURE_BILLING_ENABLED = () => env('NEXT_PUBLIC_FEATURE_BILLING_ENABLED');
const NEXT_PUBLIC_POSTHOG_KEY = () => env('NEXT_PUBLIC_POSTHOG_KEY');
2024-01-25 10:48:20 +02:00
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> = {
app_allow_encrypted_documents: false,
app_billing: NEXT_PUBLIC_FEATURE_BILLING_ENABLED() === 'true',
2024-02-19 14:31:26 +11:00
app_document_page_view_history_sheet: false,
2025-01-02 15:33:37 +11:00
app_passkey: true,
2024-06-06 14:46:48 +10:00
app_public_profile: true,
2023-09-20 13:48:30 +10:00
marketing_header_single_player_mode: false,
2024-02-29 13:22:21 +11:00
marketing_profiles_announcement_bar: true,
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 {
const postHogKey = NEXT_PUBLIC_POSTHOG_KEY();
2025-01-02 15:33:37 +11:00
const postHogHost = `${NEXT_PUBLIC_WEBAPP_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;
}