import * as React from 'react'; import { x as FlagMap, G as FlagResult, ao as Variant, E as EvalReason } from './types-DdEZ8iqq.mjs'; import { RolleaseBrowserClient } from './client.mjs'; import './core/metrics.mjs'; import './core/flag-types.mjs'; interface RolleaseContextValue { flags: FlagMap; flagDetails: Record; /** True while the initial flag fetch (from flagsUrl) is in-flight */ isLoading: boolean; /** True while a background refresh is in-flight (not the initial load) */ isRefetching: boolean; /** Last fetch error (cleared on successful fetch) */ error: Error | null; /** Manually trigger a refetch of flags from flagsUrl */ refetch: () => Promise; /** Invalidate all cached flags and refetch from flagsUrl */ invalidate: () => Promise; /** Timestamp of the last successful fetch */ lastUpdatedAt: Date | null; } interface RolleaseProviderProps { /** * A `RolleaseBrowserClient` from `rollease/client`. * When provided, the provider subscribes to real-time flag changes * from the client and exposes `refetch()` / `identify()` via context. * Takes precedence over `flagsUrl`. */ client?: RolleaseBrowserClient; /** Pre-evaluated flag values (key → value map or FlagResult map) */ initialFlags?: FlagMap | Record; /** * URL to fetch flags from. When set, flags are fetched on mount * and optionally polled at `refreshInterval`. * Ignored when `client` is provided. */ flagsUrl?: string; /** * Polling interval in ms (default: 30000). Set 0 to disable polling. * Only used when `flagsUrl` is set (not `client`). */ refreshInterval?: number; /** Custom fetch options (headers, credentials, etc.) */ fetchOptions?: RequestInit; /** Called after flags are successfully refreshed from flagsUrl */ onRefresh?: (flags: FlagMap) => void; /** Called when a fetch error occurs */ onError?: (error: Error) => void; /** Children components */ children: React.ReactNode; } /** * RolleaseProvider supplies flag evaluation results to React applications. * * **Server-rendered (no loading state):** * ```tsx * * * * ``` * * **Client-fetched (with loading/error states):** * ```tsx * * * * ``` */ declare function RolleaseProvider({ client, initialFlags, flagsUrl, refreshInterval, fetchOptions, onRefresh, onError, children, }: RolleaseProviderProps): React.FunctionComponentElement>; /** * Hook to check if a boolean flag is enabled. * Returns loading/error states and control functions for async flag fetching. * * ```tsx * const { enabled, isLoading, error, refetch } = useFlag('new_checkout') * * if (isLoading) return * if (error) return * if (enabled) return * ``` */ declare function useFlag(key: string): { enabled: boolean; isLoading: boolean; isRefetching: boolean; error: Error | null; refetch: () => Promise; invalidate: () => Promise; lastUpdatedAt: Date | null; }; /** * Hook to get the variant of a multivariate flag. * Returns loading/error states and control functions for async flag fetching. * * ```tsx * const { variant, isLoading, error } = useVariant('pricing_layout') * // variant → { key: 'horizontal', value: { columns: 1 }, reason: 'weighted_random' } * ``` */ declare function useVariant(key: string): { variant: Variant | null; isLoading: boolean; isRefetching: boolean; error: Error | null; refetch: () => Promise; invalidate: () => Promise; lastUpdatedAt: Date | null; }; /** * Hook to get all flag values as a flat key→value map. * Includes loading/error states for async-aware rendering. * * ```tsx * const { flags, isLoading } = useFlags() * if (isLoading) return * // flags → { new_checkout: true, pricing_layout: { columns: 1 } } * ``` */ declare function useFlags(): { flags: FlagMap; isLoading: boolean; isRefetching: boolean; error: Error | null; refetch: () => Promise; invalidate: () => Promise; lastUpdatedAt: Date | null; }; /** * Hook to get full evaluation details for a specific flag. * Includes the full FlagResult plus async lifecycle states. * * ```tsx * const { details, isLoading } = useFlagDetails('new_checkout') * // details → { key, value, variant, enabled, reason, ruleId, evaluatedAt } * ``` */ declare function useFlagDetails(key: string): { details: FlagResult; isLoading: boolean; isRefetching: boolean; error: Error | null; refetch: () => Promise; invalidate: () => Promise; lastUpdatedAt: Date | null; }; /** * Hook to get the typed value of a flag with a fallback default. * Prevents undefined values from leaking into your rendering logic. * * ```tsx * const maxRetries = useFlagValue('max_retries', 3) * const theme = useFlagValue('theme', 'light') * ``` */ declare function useFlagValue(key: string, defaultValue: T): T; /** * Hook to access full Rollease context: flags, details, loading, error, * refetch, and invalidate. The kitchen-sink hook. * * ```tsx * const { flags, isLoading, error, refetch, invalidate, lastUpdatedAt } = useRollease() * ``` */ declare function useRollease(): RolleaseContextValue; /** * Hook that only re-renders when specific flag keys change. * Use for performance-sensitive components that only care about a subset of flags. * * ```tsx * const { enabled, value } = useWatchFlag('feature_x') * ``` */ declare function useWatchFlag(key: string): { enabled: boolean; value: unknown; variant: string | null; reason: EvalReason; isLoading: boolean; error: Error | null; }; /** * Hook to check multiple flags at once. Returns an object keyed by flag name * with enabled status. Useful for rendering based on multiple feature gates. * * ```tsx * const features = useFlagSet(['new_checkout', 'dark_mode', 'beta_api']) * // features → { new_checkout: true, dark_mode: false, beta_api: true } * ``` */ declare function useFlagSet(keys: string[]): { features: Record; isLoading: boolean; error: Error | null; }; interface FeatureGateProps { /** Flag key to check */ flag: string; /** Content shown when flag is disabled (optional) */ fallback?: React.ReactNode; /** Content shown while flags are still loading (optional) */ loading?: React.ReactNode; /** * Children rendered when the flag is enabled. Optional so the gate can be * used declaratively for side-effects only or as a "render nothing when * disabled" guard. With no children, an empty Fragment is rendered when * the flag is on. */ children?: React.ReactNode; } /** * Declarative feature gate component. * Shows children when flag is enabled, fallback when disabled, * and a loading state while flags are being fetched. * * ```tsx * } * fallback={} * > * * * ``` */ declare function FeatureGate({ flag, fallback, loading, children }: FeatureGateProps): React.FunctionComponentElement | null; /** * Component that renders children only when ALL specified flags are enabled. * * ```tsx * * * * ``` */ declare function FeatureRequire({ flags: flagKeys, fallback, children, }: { flags: string[]; fallback?: React.ReactNode; /** * Children rendered when all flags are enabled. Optional — same rationale * as {@link FeatureGateProps.children}. */ children?: React.ReactNode; }): React.FunctionComponentElement | null; export { FeatureGate, type FeatureGateProps, FeatureRequire, RolleaseProvider, type RolleaseProviderProps, useFlag, useFlagDetails, useFlagSet, useFlagValue, useFlags, useRollease, useVariant, useWatchFlag };