Files
ALwrity/frontend/src/utils/demoMode.ts
ajaysi edd92ec85b Deprecate legacy feature flags, use ALWRITY_ENABLED_FEATURES only
- Remove fallback to ALWRITY_FEATURE_PROFILE, ALWRITY_ROUTER_PROFILE
- Primary env var is now ALWRITY_ENABLED_FEATURES (backend)
- Primary env var is REACT_APP_ENABLED_FEATURES (frontend)
- Add deprecation comments to all get_enabled_features() functions
- Update demoMode.ts with clear deprecation notes

Usage:
  ALWRITY_ENABLED_FEATURES=podcast      # Podcast only
  ALWRITY_ENABLED_FEATURES=all          # All features (default)
2026-03-31 18:45:52 +05:30

84 lines
2.3 KiB
TypeScript

/**
* Consolidated feature mode detection utilities.
*
* Primary: REACT_APP_ENABLED_FEATURES (format: "all" or "podcast,core")
*
* DEPRECATED (fallback order):
* - REACT_APP_APP_MODE
* - REACT_APP_DEMO_MODE
* - REACT_APP_PODCAST_ONLY_DEMO_MODE
*/
const ENABLED_FEATURES_STORAGE_KEYS = [
'enabled_features', // Primary
'app_mode',
'demo_mode',
'podcast_only_demo_mode',
];
const ENABLED_FEATURES_ENV_KEYS = [
'REACT_APP_ENABLED_FEATURES', // Primary - use this!
'REACT_APP_APP_MODE', // DEPRECATED
'REACT_APP_DEMO_MODE', // DEPRECATED
'REACT_APP_PODCAST_ONLY_DEMO_MODE', // DEPRECATED
];
/**
* Get enabled features from localStorage or environment.
* Returns a set of enabled feature names.
*/
export function getEnabledFeatures(): Set<string> {
// Check localStorage first
for (const key of ENABLED_FEATURES_STORAGE_KEYS) {
const value = localStorage.getItem(key);
if (value) {
const features = value.toLowerCase().split(',').map(f => f.trim());
if (features.includes('all')) {
return new Set(['all']);
}
return new Set(features.filter(f => f));
}
}
// Check environment variables
for (const key of ENABLED_FEATURES_ENV_KEYS) {
const value = process.env[key];
if (value) {
const features = value.toLowerCase().split(',').map(f => f.trim());
if (features.includes('all')) {
return new Set(['all']);
}
return new Set(features.filter(f => f));
}
}
// Default: all features enabled
return new Set(['all']);
}
/**
* Check if a specific feature is enabled.
*/
export function isFeatureEnabled(feature: string): boolean {
const enabled = getEnabledFeatures();
return enabled.has('all') || enabled.has(feature);
}
/**
* Check if podcast-only mode is enabled.
* Returns true when podcast is enabled but not "all".
*/
export function isPodcastOnlyDemoMode(): boolean {
const enabled = getEnabledFeatures();
return enabled.has('podcast') && !enabled.has('all');
}
/**
* Check if the app should skip onboarding entirely.
* Returns true in podcast-only demo mode or when not using all features.
*/
export function shouldSkipOnboarding(): boolean {
const enabled = getEnabledFeatures();
return enabled.has('podcast') || !enabled.has('all');
}