import { Segment, SegmentId, UserId, EvaluationContext, TargetingCondition, JsonValue } from './types'; /** * Result of segment matching. */ export interface SegmentMatchResult { /** Whether the context matches the segment */ readonly matched: boolean; /** The segment that was matched */ readonly segmentId: SegmentId; /** Reason for the match result */ readonly reason: SegmentMatchReason; /** Detailed match information */ readonly details?: SegmentMatchDetails; } /** * Reasons for segment match results. */ export type SegmentMatchReason = 'RULE_MATCH' | 'EXPLICIT_INCLUDE' | 'EXPLICIT_EXCLUDE' | 'NO_MATCH'; /** * Detailed information about segment matching. */ export interface SegmentMatchDetails { /** Rules that were evaluated */ readonly rulesEvaluated: number; /** Evaluation time in ms */ readonly evaluationTimeMs: number; /** Specific conditions that matched */ readonly matchedConditions?: string[]; } /** * Segment composition operations. */ export type SegmentCompositionOp = 'union' | 'intersection' | 'difference'; /** * A composed segment. */ export interface ComposedSegment { /** The operation to perform */ readonly operation: SegmentCompositionOp; /** Segments to compose */ readonly segments: readonly SegmentId[]; } /** * Matches evaluation contexts against segment definitions. */ export declare class SegmentMatcher { private cache; private readonly cacheTtl; constructor(options?: { cacheTtl?: number; }); /** * Check if a context matches a segment. */ matches(segment: Segment, context: EvaluationContext): boolean; /** * Check if a context matches a segment with detailed results. */ matchWithDetails(segment: Segment, context: EvaluationContext): SegmentMatchResult; /** * Check if a context matches any of the given segments. */ matchesAny(segments: readonly Segment[], context: EvaluationContext): { matched: boolean; matchedSegment?: Segment; }; /** * Check if a context matches all of the given segments. */ matchesAll(segments: readonly Segment[], context: EvaluationContext): boolean; /** * Get all segments that match a context. */ getMatchingSegments(segments: readonly Segment[], context: EvaluationContext): Segment[]; /** * Clear the segment cache. */ clearCache(): void; /** * Clear cache for a specific segment. */ clearSegmentCache(segmentId: SegmentId): void; private evaluateConditionGroup; private evaluateConditionOrGroup; private evaluateCondition; private resolveAttributePath; private compare; private getCacheKey; private cacheResult; } /** * Fluent builder for creating segments. */ export declare class SegmentBuilder { private segment; private conditions; private groupOperator; /** * Set the segment ID. */ id(id: SegmentId): this; /** * Set the segment name. */ name(name: string): this; /** * Set the segment description. */ description(description: string): this; /** * Use AND to combine conditions. */ and(): this; /** * Use OR to combine conditions. */ or(): this; /** * Add a condition. */ where(attribute: string, operator: TargetingCondition['operator'], value: JsonValue | readonly JsonValue[]): this; /** * Add an equals condition. */ equals(attribute: string, value: JsonValue): this; /** * Add an in condition. */ in(attribute: string, values: readonly JsonValue[]): this; /** * Add a contains condition. */ contains(attribute: string, value: string): this; /** * Add a starts with condition. */ startsWith(attribute: string, value: string): this; /** * Add an ends with condition. */ endsWith(attribute: string, value: string): this; /** * Add users to explicitly include. */ include(...userIds: UserId[]): this; /** * Add users to explicitly exclude. */ exclude(...userIds: UserId[]): this; /** * Add tags. */ tag(...tags: string[]): this; /** * Set estimated size. */ estimatedSize(size: number): this; /** * Build the segment. */ build(): Segment; } /** * Create a new segment builder. */ export declare function createSegment(): SegmentBuilder; /** * Factory functions for common segment patterns. */ export declare const SegmentFactories: { /** * Create an internal users segment (employees). */ internal(id?: string, emailDomain?: string): Segment; /** * Create a beta users segment. */ beta(id?: string): Segment; /** * Create a segment for specific plans/tiers. */ plan(id: string, plans: string[]): Segment; /** * Create a segment for users with specific roles. */ roles(id: string, roles: string[]): Segment; /** * Create a geographic segment. */ country(id: string, countryCodes: string[]): Segment; /** * Create a mobile users segment. */ mobile(id?: string): Segment; /** * Create a new users segment (registered in last N days). */ newUsers(id: string, daysAgo: number): Segment; }; /** * Compose segments using set operations. */ export declare function composeSegments(segments: Map, composition: ComposedSegment, context: EvaluationContext, matcher: SegmentMatcher): boolean;