import { V as VariantId, R as ResolutionReason, D as DatafileInput, S as StreamOptions, P as PollingOptions, M as MetricEnvironment, C as ControllerInterface, a as Datafile, B as BundledDefinitions, E as EvaluationParams, b as EvaluationResult, F as FlagsClient } from './types-C2-sIv2D.cjs'; export { c as Packed, d as Value } from './types-C2-sIv2D.cjs'; interface TrackEvaluationOptions { flagKey: string; variant: VariantId | null; reason: ResolutionReason; clientName?: string; } type BundledDefinitionsLookup = { type: 'sdk-key'; sdkKey: string; } | { type: 'project-id'; projectId: string; }; interface Auth { sdkKey?: string; resolveToken(): Promise; resolveBundledDefinitionsLookup(): Promise; } /** * Configuration options for Controller */ type ControllerOptions = { /** Authentication which resolves the token for requests */ auth: Auth; /** * Initial datafile to use immediately * - At runtime: used while waiting for stream/poll, then updated in background * - At build step: used as primary source (skips network) */ datafile?: DatafileInput; /** * Configure streaming connection (runtime only, ignored during build step) * - `true`: Enable with default options (initTimeoutMs: 3000) * - `false`: Disable streaming * - `{ initTimeoutMs: number }`: Enable with custom timeout * @default true */ stream?: boolean | StreamOptions; /** * Configure polling fallback (runtime only, ignored during build step) * - `true`: Enable with default options (intervalMs: 30000, initTimeoutMs: 3000) * - `false`: Disable polling * - `{ intervalMs: number, initTimeoutMs: number }`: Enable with custom options * @default true */ polling?: boolean | PollingOptions; /** * Override build step detection * - `true`: Treat as build step (use datafile/bundled only, no network) * - `false`: Treat as runtime (try stream/poll first) * @default auto-detected via CI=1 or NEXT_PHASE=phase-production-build */ buildStep?: boolean; /** * Custom fetch function for making HTTP requests. * Useful for testing (e.g. resolving to a different IP). * @default globalThis.fetch */ fetch?: typeof globalThis.fetch; /** * Environment included with evaluation metrics sent to the ingest endpoint. * Falls back to the `VERCEL_ENV` environment variable when not set. * This does not select the environment used for flag evaluation. */ metricEnvironment?: MetricEnvironment; /** * Custom client name included in evaluation telemetry. */ clientName?: string; /** * Disable evaluation metrics for this client. * @default false */ disableMetrics?: boolean; }; /** * Connects to flags.vercel.com and manages flag definitions. * * Implemented as a state machine controller that delegates all I/O to * source modules (StreamSource, PollingSource, BundledSource). * * **Build step** (CI=1 or Next.js build, or buildStep: true): * - Uses datafile (if provided), bundled definitions, or one-time fetch as fallback * - No streaming or polling * * **Runtime — streaming mode** (stream enabled): * - Uses streaming exclusively; polling is never started, even if configured * - Init fallback (no data yet): constructor datafile → bundled → throw * - Read fallback (post-init): in-memory value → constructor datafile → bundled → throw * * **Runtime — polling mode** (polling enabled, stream disabled): * - Uses polling exclusively * - Same fallback chains as streaming mode * * **Runtime — offline mode** (neither stream nor polling): * - Init fallback: constructor datafile → bundled → one-time fetch → throw * - Read fallback: in-memory value → constructor datafile → bundled → one-time fetch → throw */ declare class Controller implements ControllerInterface { private options; private state; private data; private dataViewSource; private dataViewBase; private streamSource; private pollingSource; private bundledSource; private usageTracker; private isFirstGetData; private buildDataPromise; private buildReadTracked; private unauthorized; constructor(options: ControllerOptions); private onStreamData; private onStreamPrimed; private onStreamConnected; private onStreamDisconnected; private onPollData; private onPollError; private wireSourceEvents; private unwireSourceEvents; private transition; private get isConnected(); private get mode(); /** * Initializes the data source. * * Build step: datafile → bundled → one-time fetch * Streaming mode: stream → datafile → bundled * Polling mode (no stream): poll → datafile → bundled * Offline mode (neither): datafile → bundled → one-time fetch */ initialize(): Promise; /** * Reads the current datafile with metrics. */ read(): Promise; /** * Shuts down the data source and releases resources. */ shutdown(): Promise; /** * Returns the datafile with metrics. * Uses in-memory data if available, otherwise falls back to bundled, * then to a one-time fetch if called without prior initialization. */ getDatafile(): Promise; /** * Returns the bundled fallback datafile. */ getFallbackDatafile(): Promise; /** * Resolves the current data, using the appropriate strategy for the * current mode. Returns tagged data and cache status. * * Build step: cached → bundled → one-time fetch * Runtime with cache: return cached data * Runtime without cache: stream/poll → datafile → bundled → fetch → throw */ private resolveData; /** * Attempts to initialize via stream with timeout. * Returns true if stream connected successfully within timeout. */ private tryInitializeStream; /** * Attempts to initialize via polling with timeout. * Returns true if first poll succeeded within timeout. * * Only used when streaming is disabled and polling is the primary source. */ private tryInitializePolling; /** * Initializes data for build step environments. */ private initializeForBuildStep; /** * Retrieves data during build steps. * Concurrent callers share a single load promise. The first caller to * populate `this.data` gets cacheStatus MISS; subsequent callers get HIT. */ private resolveDataForBuildStep; /** * Loads data for a build step: bundled → one-time fetch. */ private loadBuildData; /** * Shared fallback chain used by both initialize() and resolveData(). */ private initializeFromFallbacks; /** * Retrieves data using the fallback chain (called when no cached data exists). * Streaming mode: stream → datafile → bundled. * Polling mode: poll → datafile → bundled. * Offline mode: datafile → bundled → one-time fetch. */ private resolveDataWithFallbacks; /** * Checks if the incoming data is newer than the current in-memory data. * Returns true if the update should proceed, false if it should be skipped. * * Always accepts the update if: * - There is no current data * - The current data has no configUpdatedAt * - The incoming data has no configUpdatedAt * * Skips the update only when both have configUpdatedAt and incoming is not newer. */ private isNewerData; /** * Tracks a read operation for usage analytics. * During build steps, only the first read is tracked. */ private trackRead; /** * Tracks a flag evaluation for usage analytics. */ trackEvaluation(options: TrackEvaluationOptions): void; } /** * Factory functions for exports of index.default.ts and index.next-js.ts */ /** * Options for createClient */ type CreateClientOptions = Omit; /** * Error thrown when the fallback definitions file does not exist. * This typically means the "vercel-flags prepare" command was not run before building. */ declare class FallbackNotFoundError extends Error { constructor(); } /** * Error thrown when the fallback definitions file exists but has no entry for the SDK key. * This means the SDK key was not included when running "vercel-flags prepare". */ declare class FallbackEntryNotFoundError extends Error { constructor(); } /** * Evaluates a single feature flag. * * This function should never throw for expected errors, instead it returns * { reason: Reason.ERROR, errorMessage: ... }. * * The function can however throw for situations which should not happen under * normal circumstances, for example if the environment config is not found. */ declare function evaluate( /** * The params used for the evaluation */ params: EvaluationParams, /** Tracks visited environments to detect circular reuse. */ _visited?: Set): EvaluationResult; declare const /** * A lazily-initialized default flags client. * * - relies on process.env.FLAGS * - does not use process.env.GLOBAL_CONFIG */ flagsClient: FlagsClient; declare const /** * For testing purposes */ resetDefaultFlagsClient: () => void; declare const /** * Create a flags client using an SDK key, connection string, or Vercel OIDC. */ createClient: { >(options: CreateClientOptions): FlagsClient; >(sdkKeyOrConnectionString?: string, options?: CreateClientOptions): FlagsClient; }; export { BundledDefinitions, Controller, type ControllerOptions, type CreateClientOptions, Datafile, DatafileInput, EvaluationParams, EvaluationResult, FallbackEntryNotFoundError, FallbackNotFoundError, Controller as FlagNetworkDataSource, type ControllerOptions as FlagNetworkDataSourceOptions, FlagsClient, PollingOptions, ResolutionReason as Reason, StreamOptions, createClient, evaluate, flagsClient, resetDefaultFlagsClient };