/** * Feature Flag Evaluation Engine * * Core engine for evaluating feature flags with rules, targeting, and rollouts. * This will be moved to @plyaz/core when the package structure is finalized. * * @fileoverview Core feature flag evaluation engine * @version 1.0.0 */ import type { FeatureFlag, FeatureFlagRule, FeatureFlagContext, FeatureFlagEvaluation, FeatureFlagValue } from '@plyaz/types'; /** * Core feature flag evaluation engine. * Handles all the logic for evaluating feature flags including rules, targeting, and rollouts. * * @class FeatureFlagEngine * * @example * ```typescript * const engine = new FeatureFlagEngine(defaultFlags, true); * engine.setFlags(flagsFromDatabase); * engine.setRules(rulesFromDatabase); * * const evaluation = engine.evaluate('AUTH_GOOGLE', context); * console.log(evaluation.isEnabled); // true/false * ``` */ export declare class FeatureFlagEngine { private defaults; private isLoggingEnabled; /** Logger instance */ private readonly logger; /** Storage for active feature flags */ private flags; /** Storage for targeting rules, organized by flag key */ private rules; /** Storage for manual overrides (useful for testing) */ private overrides; /** * Creates a new feature flag evaluation engine. * * @param defaults - Default flag values to fall back to * @param isLoggingEnabled - Whether to enable debug logging */ constructor(defaults: Record, isLoggingEnabled?: boolean); /** * Sets the active feature flags for evaluation. * Clears existing flags and rules before setting new ones. * * @param flags - Array of feature flags to activate */ setFlags(flags: FeatureFlag[]): void; /** * Sets the targeting rules for feature flags. * Rules are automatically sorted by priority (higher numbers first). * * @param rules - Array of feature flag rules */ setRules(rules: FeatureFlagRule[]): void; /** * Gets all targeting rules. * * @returns Array of all feature flag rules */ getRules(): FeatureFlagRule[]; /** * Sets a manual override for a specific flag. * Overrides take precedence over all other evaluation logic. * * @param key - The flag key to override * @param value - The value to force for this flag */ setOverride(key: FeatureFlagKey, value: FeatureFlagValue): void; /** * Removes a manual override for a specific flag. * * @param key - The flag key to remove override for */ removeOverride(key: FeatureFlagKey): void; /** * Updates the default values for feature flags. * This is useful when the FEATURES constant is updated at runtime. * * @param newDefaults - New default values */ updateDefaults(newDefaults: Record): void; /** * Clears all manual overrides. */ clearOverrides(): void; /** * Gets all current flags. * * @returns Array of all feature flags */ getFlags(): FeatureFlag[]; /** * Evaluates a feature flag and returns the complete evaluation result. * * @param key - The feature flag key to evaluate * @param context - Optional context for targeting * @returns Complete evaluation result with value and metadata */ evaluate(key: FeatureFlagKey, context?: FeatureFlagContext): FeatureFlagEvaluation; /** * Checks for manual override and returns evaluation if found. * * @private * @param key - The feature flag key * @param evaluatedAt - Evaluation timestamp * @returns Evaluation result or null if no override */ private checkOverride; /** * Creates default evaluation result. * * @private * @param key - The feature flag key * @param evaluatedAt - Evaluation timestamp * @returns Default evaluation result */ private createDefaultEvaluation; /** * Creates disabled evaluation result. * * @private * @param key - The feature flag key * @param evaluatedAt - Evaluation timestamp * @returns Disabled evaluation result */ private createDisabledEvaluation; /** * Creates flag evaluation result. * * @private * @param key - The feature flag key * @param flag - The feature flag * @param evaluatedAt - Evaluation timestamp * @returns Flag evaluation result */ private createFlagEvaluation; /** * Checks if environment matches for flag evaluation. * * @private * @param flag - The feature flag * @param context - Evaluation context * @returns true if environment matches */ private isEnvironmentMatch; /** * Checks if user is in flag-level rollout. * * @private * @param key - The feature flag key * @param flag - The feature flag * @param context - Evaluation context * @returns true if user is in rollout */ private isInFlagRollout; /** * Evaluates all rules for a flag. * * @private * @param key - The feature flag key * @param context - Evaluation context * @param evaluatedAt - Evaluation timestamp * @returns Rule evaluation result or null if no match */ private evaluateRules; /** * Evaluates a single matching rule and returns result if it passes. * * @private * @param key - The feature flag key * @param rule - The rule to evaluate * @param context - Evaluation context * @param evaluatedAt - Evaluation timestamp * @returns Rule evaluation result or null if no match */ private evaluateMatchingRule; /** * Evaluates a single rule against the provided context. * All conditions in the rule must match (AND logic). * * @private * @param rule - The rule to evaluate * @param context - Context to evaluate against * @returns true if the rule matches the context */ private evaluateRule; /** * Evaluates a single condition against the provided context. * * @private * @param condition - The condition to evaluate * @param context - Context to evaluate against * @returns true if the condition matches */ private evaluateCondition; /** * Logs debug information if logging is enabled. * * @private * @param args - Arguments to log */ private log; } //# sourceMappingURL=engine.d.ts.map