/** * Feature Flag Context Utilities * * Utilities for building, validating, and manipulating feature flag contexts. * * @fileoverview Feature flag context utilities * @version 1.0.0 */ import type { FeatureFlagContext } from '@plyaz/types'; /** * Builder class for creating feature flag evaluation contexts. * Provides a fluent interface for setting context properties. * * @class FeatureFlagContextBuilder * * @example * ```typescript * const context = new FeatureFlagContextBuilder() * .setUserId('user123') * .setUserRole('premium') * .setEnvironment('production') * .setPlatform('web') * .setCustom({ subscription: 'premium', betaTester: true }) * .build(); * ``` */ export declare class FeatureFlagContextBuilder { private context; /** * Sets the user ID in the context. * * @param userId - User identifier * @returns Builder instance for chaining */ setUserId(userId: string): this; /** * Sets the user email in the context. * * @param userEmail - User email address * @returns Builder instance for chaining */ setUserEmail(userEmail: string): this; /** * Sets the user role in the context. * * @param userRole - User role or permission level * @returns Builder instance for chaining */ setUserRole(userRole: string): this; /** * Sets the country in the context. * * @param country - Country code (ISO 3166-1 alpha-2) * @returns Builder instance for chaining */ setCountry(country: string): this; /** * Sets the platform in the context. * * @param platform - Platform type * @returns Builder instance for chaining */ setPlatform(platform: 'web' | 'mobile' | 'desktop'): this; /** * Sets the version in the context. * * @param version - Application version * @returns Builder instance for chaining */ setVersion(version: string): this; /** * Sets the environment in the context. * * @param environment - Current environment * @returns Builder instance for chaining */ setEnvironment(environment: 'development' | 'staging' | 'production'): this; /** * Sets custom context data. * * @param custom - Custom context properties * @returns Builder instance for chaining */ setCustom(custom: Record): this; /** * Adds a single custom property to the context. * * @param key - Custom property key * @param value - Custom property value * @returns Builder instance for chaining */ addCustomProperty(key: string, value: unknown): this; /** * Builds the final context object. * Validates required fields and returns the context. * * @returns Complete feature flag context * @throws Error if required environment is not set */ build(): FeatureFlagContext; /** * Clears all context data and resets the builder. * * @returns Builder instance for chaining */ clear(): this; /** * Creates a copy of the current builder state. * * @returns New builder instance with copied context */ clone(): FeatureFlagContextBuilder; } /** * Context utilities for common scenarios. */ export declare const ContextUtils: { /** * Creates a basic context for anonymous users using the builder. * * @param environment - Target environment * @param platform - User platform * @returns Basic anonymous context */ readonly createAnonymousContext: (environment: "development" | "staging" | "production", platform?: "web" | "mobile" | "desktop") => FeatureFlagContext; /** * Creates a context for authenticated users using the builder. * * @param params - User context parameters * @returns User context */ readonly createUserContext: (params: { userId: string; environment: "development" | "staging" | "production"; userEmail?: string; userRole?: string; platform?: "web" | "mobile" | "desktop"; country?: string; version?: string; custom?: Record; }) => FeatureFlagContext; /** * Creates a testing context with minimal required fields. * * @param overrides - Optional context overrides * @returns Testing context */ readonly createTestingContext: (overrides?: Partial) => FeatureFlagContext; /** * Validates if a context object is complete and valid. * * @param context - Context to validate * @returns Validation result */ readonly validateContext: (context: Partial) => { isValid: boolean; errors: string[]; }; /** * Merges multiple context objects, with later contexts taking precedence. * * @param contexts - Array of contexts to merge * @returns Merged context */ readonly mergeContexts: (...contexts: Partial[]) => FeatureFlagContext; /** * Extracts a specific field value from a context. * * @param field - Field name to extract * @param context - Context object * @returns Field value or undefined */ readonly getContextValue: (field: string, context: FeatureFlagContext) => unknown; /** * Creates a context fingerprint for caching and consistency. * * @param context - Context to fingerprint * @returns String fingerprint */ readonly createFingerprint: (context: FeatureFlagContext) => string; /** * Sanitizes a context by removing sensitive information. * * @param context - Context to sanitize * @param sensitiveFields - Fields to remove (default: ['userEmail']) * @returns Sanitized context */ readonly sanitizeContext: (context: FeatureFlagContext, sensitiveFields?: string[]) => FeatureFlagContext; }; /** * Utility for creating feature flag context for backend applications. * * @param params - Context parameters * @returns Backend-optimized feature flag context */ export declare function createBackendContext(params: { userId?: string; userEmail?: string; environment: 'development' | 'staging' | 'production'; userRole?: string; platform?: 'api' | 'worker' | 'cron'; country?: string; version?: string; custom?: Record; }): { environment: 'development' | 'staging' | 'production'; userId?: string; userEmail?: string; userRole?: string; platform: 'api' | 'worker' | 'cron'; country?: string; version?: string; custom?: Record; }; /** * Utility for creating feature flag context for frontend applications. * * @param params - Context parameters * @returns Frontend-optimized feature flag context */ export declare function createFrontendContext(params: { userId?: string; userEmail?: string; environment: 'development' | 'staging' | 'production'; userRole?: string; platform?: 'web' | 'mobile' | 'desktop'; country?: string; version?: string; custom?: Record; }): { environment: 'development' | 'staging' | 'production'; userId?: string; userEmail?: string; userRole?: string; platform: 'web' | 'mobile' | 'desktop'; country?: string; version?: string; custom?: Record; }; //# sourceMappingURL=context.d.ts.map