/** * Feature Flag Provider - Core Implementation * * Main provider class that orchestrates feature flag evaluation and management. * This will be moved to @plyaz/core when the package structure is finalized. * * @fileoverview Core feature flag provider implementation * @version 1.0.0 */ import type { FeatureFlagProvider as IFeatureFlagProvider, FeatureFlagConfig, FeatureFlagContext, FeatureFlagEvaluation, FeatureFlagValue, FetchFeatureFlagDataResponse, FeatureFlag, FeatureFlagRule, CreateFlagRequest } from '@plyaz/types'; import { FeatureFlagEngine } from '@engine/featureFlags/engine'; import { CacheManager } from '@base/cache/index'; /** * Subscription callback function type */ export type SubscriptionCallback = () => void; /** * Core feature flag provider that implements the main business logic. * This class orchestrates between the evaluation engine, caching, and data providers. * * @class FeatureFlagProvider * @implements {IFeatureFlagProvider} * * @example * ```typescript * const provider = new MemoryFeatureFlagProvider(config, FEATURES); * await provider.initialize(); * * const isEnabled = await provider.isEnabled('AUTH_GOOGLE', context); * const value = await provider.getValue('ROLLOUT_PERCENTAGE', context); * ``` */ export declare abstract class FeatureFlagProvider implements IFeatureFlagProvider { protected config: FeatureFlagConfig; protected engine: FeatureFlagEngine; protected cacheManager: CacheManager; protected subscribers: Set; protected refreshTimer?: ReturnType; protected isInitialized: boolean; protected features: Record; protected initializePromise?: Promise; /** * Creates a new feature flag provider. * * @param config - Provider configuration * @param features - Record of feature flag keys to their default values */ constructor(config: FeatureFlagConfig, features: Record); /** * Abstract method to fetch flags and rules from the provider's data source. * Must be implemented by concrete provider classes. * * @protected * @abstract * @returns Promise resolving to flags and rules */ protected abstract fetchData(): Promise>; /** * Initializes the provider by loading initial data. * * @returns Promise that resolves when initialization is complete */ initialize(): Promise; /** * Performs the actual initialization work. * * @private * @returns Promise that resolves when initialization is complete */ private doInitialize; /** * Gets a feature flag evaluation for the specified key and context. * * @param key - The feature flag key * @param context - Optional context for evaluation * @returns Promise resolving to the flag evaluation */ getFlag(key: FeatureFlagKey, context?: FeatureFlagContext): Promise>; /** * Checks if a feature flag is enabled. * * @param key - The feature flag key * @param context - Optional context for evaluation * @returns Promise resolving to boolean indicating if flag is enabled */ isEnabled(key: FeatureFlagKey, context?: FeatureFlagContext): Promise; /** * Gets the value of a feature flag. * * @template T - The expected type of the flag value * @param key - The feature flag key * @param context - Optional context for evaluation * @returns Promise resolving to the flag value */ getValue(key: FeatureFlagKey, context?: FeatureFlagContext): Promise; /** * Gets all feature flag evaluations for the given context. * * @param context - Optional context for evaluation * @returns Promise resolving to record of flag evaluations */ getAllFlags(context?: FeatureFlagContext): Promise>>; /** * Refreshes the provider by fetching latest data from the source. * * @returns Promise that resolves when refresh is complete */ refresh(): Promise; /** * Subscribes to provider updates. * * @param callback - Function to call when provider updates * @returns Unsubscribe function */ subscribe(callback: SubscriptionCallback): () => void; /** * Sets an override for a specific flag key. * * @param key - The flag key to override * @param value - The value to force for this flag */ setOverride(key: FeatureFlagKey, value: FeatureFlagValue): void; /** * Removes an override for a specific flag key. * * @param key - The flag key to remove override for */ removeOverride(key: FeatureFlagKey): void; /** * Clears all overrides. */ clearOverrides(): void; /** * Disposes of the provider, cleaning up resources. */ dispose(): void; /** * Creates a new feature flag. * Abstract - each provider implements based on its storage backend. * * @param data - Flag creation data * @returns The created feature flag */ abstract createFlag(data: CreateFlagRequest): Promise>; /** * Updates an existing feature flag. * Abstract - each provider implements based on its storage backend. * * @param key - Flag key to update * @param data - Partial flag data to update * @returns The updated feature flag */ abstract updateFlag(key: FeatureFlagKey, data: Partial>): Promise>; /** * Deletes a feature flag. * Abstract - each provider implements based on its storage backend. * * @param key - Flag key to delete */ abstract deleteFlag(key: FeatureFlagKey): Promise; /** * Gets all rules for a specific flag. * Abstract - each provider implements based on its storage backend. * * @param key - Flag key to get rules for * @returns Array of rules for the flag */ abstract getRules(key: FeatureFlagKey): Promise[]>; /** * Gets all enabled rules across all flags. * Abstract - each provider implements based on its storage backend. * * @returns Array of all enabled rules */ abstract getAllRules(): Promise[]>; /** * Optional method to sync features at runtime. * This is useful for providers that can update their features dynamically. * * @param newFeatures - New features to sync * @returns Promise that resolves when sync is complete */ syncFeatures?(newFeatures: Record): Promise; /** * Generates a cache key for flag evaluation. * * @protected * @param key - Feature flag key * @param context - Evaluation context * @returns Cache key string */ protected generateCacheKey(key: FeatureFlagKey, context?: FeatureFlagContext): string; /** * Sets up the automatic refresh timer if configured. * * @protected */ protected setupRefreshTimer(): void; /** * Notifies all subscribers of provider updates. * * @protected */ protected notifySubscribers(): void; /** * Logs a message if logging is enabled. * * @protected * @param args - Arguments to log */ protected log(...args: unknown[]): void; } //# sourceMappingURL=provider.d.ts.map