import { HttpClient } from '../httpClient'; import { Logger } from '../logger'; import { default as RateLimiter } from '../rateLimiter'; import { FeatureCache } from './featureCache'; /** * A feature fetched from the server. */ export type FetchedFeature = { /** * Feature key. */ key: string; /** * Result of feature flag evaluation. * Note: does not take local overrides into account. */ isEnabled: boolean; /** * Version of targeting rules. */ targetingVersion?: number; /** * Rule evaluation results. */ ruleEvaluationResults?: boolean[]; /** * Missing context fields. */ missingContextFields?: string[]; /** * Optional user-defined dynamic configuration. */ config?: { /** * The key of the matched configuration value. */ key: string; /** * The version of the matched configuration value. */ version?: number; /** * The optional user-supplied payload data. */ payload?: any; /** * The rule evaluation results. */ ruleEvaluationResults?: boolean[]; /** * The missing context fields. */ missingContextFields?: string[]; }; }; /** * @internal */ export type FetchedFeatures = Record; export type RawFeature = FetchedFeature & { /** * If not null, the result is being overridden locally */ isEnabledOverride: boolean | null; }; export type RawFeatures = Record; export type FallbackFeatureOverride = { key: string; payload: any; } | true; type Config = { fallbackFeatures: Record; timeoutMs: number; staleWhileRevalidate: boolean; offline: boolean; }; export declare const DEFAULT_FEATURES_CONFIG: Config; export declare function validateFeaturesResponse(response: any): { success: any; features: FetchedFeatures; } | undefined; export declare function flattenJSON(obj: Record): Record; /** * Event representing checking the feature flag evaluation result */ export interface CheckEvent { /** * `check-is-enabled` means `isEnabled` was checked, `check-config` means `config` was checked. */ action: "check-is-enabled" | "check-config"; /** * Feature key. */ key: string; /** * Result of feature flag or configuration evaluation. * If `action` is `check-is-enabled`, this is the result of the feature flag evaluation and `value` is a boolean. * If `action` is `check-config`, this is the result of the configuration evaluation. */ value?: boolean | { key: string; payload: any; }; /** * Version of targeting rules. */ version?: number; /** * Rule evaluation results. */ ruleEvaluationResults?: boolean[]; /** * Missing context fields. */ missingContextFields?: string[]; } type context = { user?: Record; company?: Record; other?: Record; }; export declare const FEATURES_EXPIRE_MS: number; /** * @internal */ export declare class FeaturesClient { private httpClient; private context; private cache; private fetchedFeatures; private featureOverrides; private features; private config; private rateLimiter; private readonly logger; private eventTarget; private abortController; constructor(httpClient: HttpClient, context: context, logger: Logger, options?: { fallbackFeatures?: Record | string[]; timeoutMs?: number; staleTimeMs?: number; expireTimeMs?: number; cache?: FeatureCache; rateLimiter?: RateLimiter; offline?: boolean; }); initialize(): Promise; setContext(context: context): Promise; /** * Stop the client. */ stop(): void; /** * Register a callback to be called when the features are updated. * Features are not guaranteed to have actually changed when the callback is called. * * @param callback this will be called when the features are updated. * @returns a function that can be called to remove the listener */ onUpdated(callback: () => void): void; getFeatures(): RawFeatures; getFetchedFeatures(): FetchedFeatures; fetchFeatures(): Promise; /** * Send a feature "check" event. * * * @param checkEvent - The feature to send the event for. * @param cb - Callback to call after the event is sent. Might be skipped if the event was rate limited. */ sendCheckEvent(checkEvent: CheckEvent, cb: () => void): Promise; private triggerFeaturesChanged; private setFetchedFeatures; private fetchParams; private warnMissingFeatureContextFields; private maybeFetchFeatures; setFeatureOverride(key: string, isEnabled: boolean | null): void; getFeatureOverride(key: string): boolean | null; } export {}; //# sourceMappingURL=features.d.ts.map