feature flags
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
/**
|
||||
* FeatureFlagService - Manages feature flags for both server and client
|
||||
*
|
||||
*
|
||||
* Automatic Alpha Mode Integration:
|
||||
* When NEXT_PUBLIC_GRIDPILOT_MODE=alpha, all features are automatically enabled.
|
||||
* This eliminates the need to manually set FEATURE_FLAGS for alpha deployments.
|
||||
*
|
||||
* Server: Reads from process.env.FEATURE_FLAGS (comma-separated)
|
||||
* OR auto-enables all features if in alpha mode
|
||||
* Client: Reads from session context or provides mock implementation
|
||||
*/
|
||||
|
||||
@@ -15,7 +20,7 @@ export class FeatureFlagService {
|
||||
} else {
|
||||
// Parse from environment variable
|
||||
const flagsEnv = process.env.FEATURE_FLAGS;
|
||||
this.flags = flagsEnv
|
||||
this.flags = flagsEnv
|
||||
? new Set(flagsEnv.split(',').map(f => f.trim()))
|
||||
: new Set();
|
||||
}
|
||||
@@ -37,8 +42,31 @@ export class FeatureFlagService {
|
||||
|
||||
/**
|
||||
* Factory method to create service with environment flags
|
||||
* Automatically enables all features if in alpha mode
|
||||
* FEATURE_FLAGS can override alpha mode defaults
|
||||
*/
|
||||
static fromEnv(): FeatureFlagService {
|
||||
const mode = process.env.NEXT_PUBLIC_GRIDPILOT_MODE;
|
||||
const flagsEnv = process.env.FEATURE_FLAGS;
|
||||
|
||||
// If FEATURE_FLAGS is explicitly set, use it (overrides alpha mode)
|
||||
if (flagsEnv) {
|
||||
return new FeatureFlagService();
|
||||
}
|
||||
|
||||
// If in alpha mode, automatically enable all features
|
||||
if (mode === 'alpha') {
|
||||
return new FeatureFlagService([
|
||||
'driver_profiles',
|
||||
'team_profiles',
|
||||
'wallets',
|
||||
'sponsors',
|
||||
'team_feature',
|
||||
'alpha_features'
|
||||
]);
|
||||
}
|
||||
|
||||
// Otherwise, use FEATURE_FLAGS environment variable (empty if not set)
|
||||
return new FeatureFlagService();
|
||||
}
|
||||
}
|
||||
@@ -67,4 +95,12 @@ export class MockFeatureFlagService implements FeatureFlagContextType {
|
||||
}
|
||||
|
||||
// Default mock instance for client-side usage
|
||||
export const mockFeatureFlags = new MockFeatureFlagService(['alpha_features']);
|
||||
// Enables all features for development/demo mode
|
||||
export const mockFeatureFlags = new MockFeatureFlagService([
|
||||
'driver_profiles',
|
||||
'team_profiles',
|
||||
'wallets',
|
||||
'sponsors',
|
||||
'team_feature',
|
||||
'alpha_features'
|
||||
]);
|
||||
Reference in New Issue
Block a user