import { RolloutConfig, PercentageRollout, ScheduledRollout, RingRollout, CanaryRollout, ExperimentRollout, EvaluationContext, Variant, VariantId, SegmentId, RolloutStage } from './types'; /** * Result of rollout evaluation. */ export interface RolloutResult { /** Whether the user is included in the rollout */ readonly included: boolean; /** The variant to serve */ readonly variantId?: VariantId; /** The percentage bucket the user falls into */ readonly bucket?: number; /** Current rollout percentage */ readonly percentage?: number; /** Current stage (for staged rollouts) */ readonly stage?: string; /** Current ring (for ring rollouts) */ readonly ring?: string; /** Whether user is in canary group */ readonly isCanary?: boolean; /** Experiment details */ readonly experiment?: { readonly experimentId: string; readonly allocationPercentage: number; }; } /** * Hash function type for consistent user bucketing. */ export type HashFunction = (key: string, salt?: string) => number; /** * Engine for evaluating percentage-based rollouts. */ export declare class PercentageRolloutEngine { private readonly hashFunction; private stickyBuckets; constructor(hashFunction?: HashFunction); /** * Evaluate a rollout configuration. */ evaluate(rollout: RolloutConfig, context: EvaluationContext, flagKey: string, variants: readonly Variant[]): RolloutResult; /** * Set a sticky bucket for a user/flag combination. */ setStickyBucket(flagKey: string, hashKey: string, bucket: number): void; /** * Clear sticky buckets. */ clearStickyBuckets(): void; /** * Get the bucket for a user/flag combination. */ getBucket(flagKey: string, hashKey: string, salt?: string): number; private evaluatePercentage; private evaluateScheduled; private getCurrentStage; private evaluateRing; private getRingPriority; private isInRing; private evaluateCanary; private evaluateExperiment; private getDefaultHashKey; private selectVariant; } /** * Builder for creating rollout configurations. */ export declare class RolloutBuilder { /** * Create a simple percentage rollout. */ static percentage(percentage: number, options?: Partial>): PercentageRollout; /** * Create a scheduled rollout. */ static scheduled(stages: RolloutStage[], options?: { autoAdvance?: boolean; }): ScheduledRollout; /** * Create rollout stages for scheduled rollout. */ static stages(): RolloutStageBuilder; /** * Create a ring-based rollout. */ static ring(rings: Array<{ id: string; name: string; segments: SegmentId[]; priority: number; }>, currentRing: string): RingRollout; /** * Create a canary rollout. */ static canary(canaryPercentage: number, options?: { canarySegment?: SegmentId; autoRollback?: boolean; }): CanaryRollout; /** * Create an experiment rollout. */ static experiment(experimentId: string, allocation: Array<{ variantId: VariantId; percentage: number; }>, options?: { primaryMetric: string; endDate?: Date; }): ExperimentRollout; } /** * Builder for rollout stages. */ declare class RolloutStageBuilder { private stages; /** * Add a stage. */ stage(name: string, percentage: number, startTime: Date, options?: { minDuration?: number; }): this; /** * Add an internal stage (e.g., employees only). */ internal(startTime: Date): this; /** * Add a beta stage. */ beta(percentage: number, startTime: Date): this; /** * Add a GA (general availability) stage. */ ga(startTime: Date): this; /** * Build the stages. */ build(): RolloutStage[]; } /** * Calculate what percentage of users would be affected by a rollout change. */ export declare function calculateRolloutImpact(currentPercentage: number, newPercentage: number): { added: number; removed: number; unchanged: number; }; /** * Generate a suggested rollout schedule. */ export declare function generateRolloutSchedule(startDate: Date, targetPercentage?: number, durationDays?: number): RolloutStage[]; export {};