/** * File Feature Flag Provider * * File-based provider implementation supporting JSON and YAML configuration files. * This will be moved to @plyaz/core when the package structure is finalized. * * @fileoverview File provider implementation for feature flags * @version 1.0.0 */ import type { FeatureFlag, FeatureFlagRule, FeatureFlagConfig, FeatureFlagValue, CreateFlagRequest } from '@plyaz/types'; import { FeatureFlagProvider } from '../provider'; /** * File-based feature flag provider supporting JSON and YAML formats. * * @class FileFeatureFlagProvider * @extends {FeatureFlagProvider} * * @example * ```typescript * const provider = new FileFeatureFlagProvider({ * provider: 'file', * fileConfig: { * filePath: './config/feature-flags.json', * format: 'json', * shouldWatchForChanges: true, * }, * isCacheEnabled: true, * cacheTtl: 60, * }, FEATURES); * * await provider.initialize(); * const isEnabled = await provider.isEnabled('AUTH_GOOGLE'); * ``` */ export declare class FileFeatureFlagProvider extends FeatureFlagProvider { private fileWatcher?; private lastFileContent?; private fileCheckInterval?; private flags; private rules; /** * Creates a new file feature flag provider. * * @param config - Provider configuration with file settings * @param features - Record of feature flag keys to their default values */ constructor(config: FeatureFlagConfig, features: Record); /** * Initializes the provider and sets up file watching if enabled. */ initialize(): Promise; /** * Fetches flags and rules from the configuration file. * * @protected * @returns Promise resolving to flags and rules from file */ protected fetchData(): Promise<{ flags: FeatureFlag[]; rules: FeatureFlagRule[]; }>; /** * Parses file content based on format. * * @private */ private parseFileContent; /** * Handles errors for fetchData, including file creation and fallback. * * @private */ private handleFetchDataError; /** * Type guard for NodeJS.ErrnoException. */ private isFileNotFoundError; /** * Handles the case when the file is not found and fallback is enabled. */ private handleFileNotFound; /** * Handles fallback to default flags and rules. */ private handleFallbackToDefaults; /** * Validates the file provider configuration. * * @private * @throws Error if configuration is invalid */ private validateConfig; /** * Resolves the file path, supporting relative and absolute paths. * * @private * @param filePath - The file path from configuration * @returns Resolved absolute file path */ private resolveFilePath; /** * Parses JSON content. * * @private * @param content - File content * @returns Parsed data */ private parseJSON; /** * Parses YAML content. * * @private * @param content - File content * @returns Parsed data */ private parseYAML; /** * Validates the structure of file data. * * @private * @param data - Parsed file data */ private validateFileData; private checkFlagsArray; private checkRulesArray; private validateFlags; private validateRules; /** * Creates a default configuration file with values from features. * * @private * @param filePath - Path where to create the file * @param format - File format (json or yaml) */ private createDefaultFile; /** * Creates default flags from the features configuration. * * @private * @returns Array of default flags */ private createDefaultFlags; /** * Sets up file watching for hot reload if enabled. * * @private */ private setupFileWatcher; /** * Disposes of the file provider and stops file watching. */ dispose(): void; /** * Refreshes the provider by fetching latest data from the file. * Overrides base class to store rules. * * @returns Promise that resolves when refresh is complete */ refresh(): Promise; /** * Creates a new feature flag and persists to file. * * @param data - Flag creation data * @returns The created feature flag */ createFlag(data: CreateFlagRequest): Promise>; /** * Updates an existing feature flag and persists to file. * * @param key - Flag key to update * @param data - Partial flag data to update * @returns The updated feature flag */ updateFlag(key: FeatureFlagKey, data: Partial>): Promise>; /** * Deletes a feature flag and persists to file. * * @param key - Flag key to delete */ deleteFlag(key: FeatureFlagKey): Promise; /** * Gets all rules for a specific flag. * * @param key - Flag key to get rules for * @returns Array of rules for the flag */ getRules(key: FeatureFlagKey): Promise[]>; /** * Gets all enabled rules. * * @returns Array of all enabled rules */ getAllRules(): Promise[]>; /** * Persists current flags and rules to file. * * @private */ private persistToFile; /** * Infers the flag type from its value. * * @private */ private inferFlagType; /** * Updates the features object and writes to file. * This allows updating the FEATURES at runtime and persisting to file. * * @param newFeatures - New features object to sync with */ syncFeatures(newFeatures: Record): Promise; /** * Gets information about the file provider. * * @returns File provider information */ getFileInfo(): { filePath?: string; resolvedPath?: string; format?: string; isWatchEnabled: boolean; isImplemented: boolean; lastModified?: Date; }; } //# sourceMappingURL=file.d.ts.map