import type { IConfigCache } from "./ConfigCatCache"; import type { ConfigCatClientOptions, OptionsBase, OptionsForPollingMode } from "./ConfigCatClientOptions"; import { PollingMode } from "./ConfigCatClientOptions"; import type { IConfigFetcher } from "./ConfigFetcher"; import type { IConfigService } from "./ConfigServiceBase"; import { ClientCacheState, RefreshResult } from "./ConfigServiceBase"; import type { IEventEmitter } from "./EventEmitter"; import type { HookEvents, IProvidesHooks } from "./Hooks"; import type { IConfig, SettingValue } from "./ProjectConfig"; import type { IEvaluationDetails, IRolloutEvaluator, SettingTypeOf } from "./RolloutEvaluator"; import type { User } from "./User"; /** ConfigCat SDK client. */ export interface IConfigCatClient extends IProvidesHooks { /** * Returns the value of a feature flag or setting identified by `key`. * @remarks * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating. * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types. * @param key Key of the feature flag or setting. * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns A promise that fulfills with the value of the feature flag or setting. * @throws {Error} `key` is empty. * @throws {TypeError} `defaultValue` is not of an allowed type. */ getValueAsync(key: string, defaultValue: T, user?: User): Promise>; /** * Returns the value along with evaluation details of a feature flag or setting identified by `key`. * @remarks * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating. * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types. * @param key Key of the feature flag or setting. * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns A promise that fulfills with the value along with the details of evaluation of the feature flag or setting. * @throws {Error} `key` is empty. * @throws {TypeError} `defaultValue` is not of an allowed type. */ getValueDetailsAsync(key: string, defaultValue: T, user?: User): Promise>>; /** * Returns all setting keys. * @returns A promise that fulfills with the array of keys. */ getAllKeysAsync(): Promise; /** * Returns the keys and values of all feature flags and settings. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns A promise that fulfills with the array of key-value pairs. */ getAllValuesAsync(user?: User): Promise; /** * Returns the values along with evaluation details of all feature flags and settings. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns A promise that fulfills with the array of values along with evaluation details. */ getAllValueDetailsAsync(user?: User): Promise; /** Returns the key of a setting and it's value identified by the given Variation ID (analytics) */ /** * Returns the key of a setting and its value identified by the specified `variationId`. * @param variationId Variation ID (analytics). * @returns A promise that fulfills with the key-value pair. */ getKeyAndValueAsync(variationId: string): Promise; /** * Updates the internally cached config by synchronizing with the external cache (if any), * then by fetching the latest version from the ConfigCat CDN (provided that the client is online). * @returns A promise that fulfills with the refresh result. */ forceRefreshAsync(): Promise; /** * Waits for the client to reach the ready state, i.e. to complete 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 return value. * * @returns A promise that fulfills with the state of the internal cache at the time initialization was completed. */ waitForReady(): Promise; /** * Captures the current state of the client. * The resulting snapshot can be used to synchronously evaluate feature flags and settings based on the captured state. * * @remarks The operation captures the internally cached config data. It does not attempt to update it by synchronizing with * the external cache or by fetching the latest version from the ConfigCat CDN. * * Therefore, it is recommended to use snapshots in conjunction with the Auto Polling mode, where the SDK automatically * updates the internal cache in the background. * * For other polling modes, you will need to manually initiate a cache update by invoking `forceRefreshAsync`. */ snapshot(): IConfigCatClientSnapshot; /** * Sets the default user. * @param defaultUser The default User Object to use for evaluating targeting rules and percentage options. */ setDefaultUser(defaultUser: User): void; /** * Clears the default user. */ clearDefaultUser(): void; /** * Returns `true` when the client is configured not to initiate HTTP requests, otherwise `false`. */ readonly isOffline: boolean; /** * Configures the client to allow HTTP requests. */ setOnline(): void; /** * Configures the client to not initiate HTTP requests but work using the cache only. */ setOffline(): void; /** * Releases all resources used by the client. */ dispose(): void; } /** Represents the state of `IConfigCatClient` captured at a specific point in time. */ export interface IConfigCatClientSnapshot { /** The state of the internal cache at the time the snapshot was created. */ readonly cacheState: ClientCacheState; /** The internally cached config at the time the snapshot was created. */ readonly fetchedConfig: IConfig | null; /** * Returns the available setting keys. * (In case the client is configured to use flag override, this will also include the keys provided by the flag override). */ getAllKeys(): ReadonlyArray; /** * Returns the value of a feature flag or setting identified by `key` synchronously, based on the snapshot. * @remarks * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating. * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types. * @param key Key of the feature flag or setting. * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns The cached value of the feature flag or setting. * @throws {Error} `key` is empty. * @throws {TypeError} `defaultValue` is not of an allowed type. */ getValue(key: string, defaultValue: T, user?: User): SettingTypeOf; /** * Returns the value along with evaluation details of a feature flag or setting identified by `key` synchronously, based on the snapshot. * @remarks * It is important to provide an argument for the `defaultValue` parameter that matches the type of the feature flag or setting you are evaluating. * Please refer to {@link https://configcat.com/docs/sdk-reference/js/#setting-type-mapping | this table} for the corresponding types. * @param key Key of the feature flag or setting. * @param defaultValue In case of failure, this value will be returned. Only the following types are allowed: `string`, `boolean`, `number`, `null` and `undefined`. * @param user The User Object to use for evaluating targeting rules and percentage options. * @returns The cached value along with the details of evaluation of the feature flag or setting. * @throws {Error} `key` is empty. * @throws {TypeError} `defaultValue` is not of an allowed type. */ getValueDetails(key: string, defaultValue: T, user?: User): IEvaluationDetails>; } export interface IConfigCatKernel { configFetcher: IConfigFetcher; sdkType: string; sdkVersion: string; defaultCacheFactory?: (options: OptionsBase) => IConfigCache; eventEmitterFactory?: () => IEventEmitter; } export declare class ConfigCatClientCache { private readonly instances; getOrCreate(options: ConfigCatClientOptions, configCatKernel: IConfigCatKernel): [ConfigCatClient, boolean]; remove(sdkKey: string, cacheToken: object): boolean; clear(): ConfigCatClient[]; } export declare class ConfigCatClient implements IConfigCatClient { private readonly cacheToken?; protected configService?: IConfigService; protected evaluator: IRolloutEvaluator; private readonly options; private readonly hooks; private defaultUser?; private readonly suppressFinalize; private static get instanceCache(); static get(sdkKey: string, pollingMode: TMode, options: OptionsForPollingMode | undefined | null, configCatKernel: IConfigCatKernel): IConfigCatClient; constructor(options: ConfigCatClientOptions, configCatKernel: IConfigCatKernel, cacheToken?: object | undefined); private static finalize; private static close; dispose(): void; static disposeAll(): void; getValueAsync(key: string, defaultValue: T, user?: User): Promise>; getValueDetailsAsync(key: string, defaultValue: T, user?: User): Promise>>; getAllKeysAsync(): Promise; getAllValuesAsync(user?: User): Promise; getAllValueDetailsAsync(user?: User): Promise; getKeyAndValueAsync(variationId: string): Promise; forceRefreshAsync(): Promise; setDefaultUser(defaultUser: User): void; clearDefaultUser(): void; get isOffline(): boolean; setOnline(): void; setOffline(): void; waitForReady(): Promise; snapshot(): IConfigCatClientSnapshot; private getSettingsAsync; /** @inheritdoc */ addListener: (eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void) => this; /** @inheritdoc */ on(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ once(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ removeListener(eventName: TEventName, listener: (...args: HookEvents[TEventName]) => void): this; /** @inheritdoc */ off: (eventName: TEventName, listener: (...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(): Array; } /** Setting key-value pair. */ export declare class SettingKeyValue { settingKey: string; settingValue: TValue; constructor(settingKey: string, settingValue: TValue); } export declare function getSerializableOptions(options: ConfigCatClientOptions): Record; //# sourceMappingURL=ConfigCatClient.d.ts.map