import type { IConfigCatClient } from "./ConfigCatClient.js"; import type { ClientCacheState, RefreshResult } from "./ConfigServiceBase.js"; import type { IEventEmitter, IEventProvider } from "./EventEmitter.js"; import type { Config } from "./ProjectConfig.js"; import type { EvaluationDetails } from "./RolloutEvaluator.js"; import type { Message } from "./Utils.js"; /** Hooks (events) that can be emitted by `ConfigCatClient`. */ export type HookEvents = { /** * Occurs when the client reaches the ready state, i.e. completes initialization. * * @remarks Ready state is reached as soon as the initial sync with the external cache (if any) completes. * If this does not produce up-to-date config data, and the client is online (i.e. HTTP requests are allowed), * the first config fetch operation is also awaited in Auto Polling mode before ready state is reported. * * That is, reaching the ready state usually means the client is ready to evaluate feature flags and settings. * However, please note that this is not guaranteed. In case of initialization failure or timeout, the internal cache * may be empty or expired even after the ready state is reported. You can verify this by checking the `cacheState` parameter. */ clientReady: [cacheState: ClientCacheState]; /** Occurs after the value of a feature flag of setting has been evaluated. */ flagEvaluated: [evaluationDetails: EvaluationDetails]; /** * Occurs after attempting to update the cached config by fetching the latest version from the ConfigCat CDN. */ configFetched: [result: RefreshResult, isInitiatedByUser: boolean]; /** * Occurs after the internally cached config has been updated to a newer version, either as a result of synchronization * with the external cache, or as a result of fetching a newer version from the ConfigCat CDN. */ configChanged: [newConfig: Config]; /** Occurs in the case of a failure in the client. */ clientError: [message: Message, exception?: any]; }; /** Defines hooks (events) for providing notifications of `ConfigCatClient`'s actions. */ export interface IProvidesHooks extends IEventProvider { } export interface IProvidesConfigCatClient { /** The `IConfigCatClient` instance that emitted the event. */ readonly configCatClient: IConfigCatClient; } export declare class Hooks implements IProvidesHooks { private eventEmitter; configCatClient: IConfigCatClient; constructor(eventEmitter: IEventEmitter); tryDisconnect(): boolean; /** @inheritdoc */ addListener: (eventName: TEventName, listener: (this: IProvidesConfigCatClient, ...args: HookEvents[TEventName]) => void) => this; /** @inheritdoc */ on(eventName: TEventName, listener: (this: IProvidesConfigCatClient, ...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ once(eventName: TEventName, listener: (this: IProvidesConfigCatClient, ...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ removeListener(eventName: TEventName, listener: (this: IProvidesConfigCatClient, ...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ off: (eventName: TEventName, listener: (this: IProvidesConfigCatClient, ...args: HookEvents[TEventName]) => void) => this; /** @inheritdoc */ removeAllListeners(eventName?: keyof HookEvents): this; /** @inheritdoc */ listeners(eventName: keyof HookEvents): Function[]; /** @inheritdoc */ listenerCount(eventName: keyof HookEvents): number; /** @inheritdoc */ eventNames(): (keyof HookEvents)[]; /** @inheritdoc */ emit(eventName: TEventName, ...args: HookEvents[TEventName]): boolean; } export type SafeHooksWrapper = Pick & { unwrap(): Hooks | undefined; };