import { Context, internal, LDFlagValue, LDLogger, Platform } from '@launchdarkly/js-sdk-common'; import { FlagsChangeCallback } from './FlagUpdater'; import { ItemDescriptor } from './ItemDescriptor'; /** * Top level manager of flags for the client. LDClient should be using this * interface and not any of the specific instances managed by it. Updates from * data sources should be directed to the [init] and [upsert] methods of this * interface. */ export interface FlagManager { /** * Attempts to get a flag by key from the current flags. */ get(key: string): ItemDescriptor | undefined; /** * Gets all the current flags. */ getAll(): { [key: string]: ItemDescriptor; }; /** * Initializes the flag manager with data from a data source. * Persistence initialization is handled by {@link FlagPersistence} */ init(context: Context, newFlags: { [key: string]: ItemDescriptor; }): Promise; /** * Attempt to update a flag. If the flag is for the wrong context, or * it is of an older version, then an update will not be performed. */ upsert(context: Context, key: string, item: ItemDescriptor): Promise; /** * Asynchronously load cached values from persistence. */ loadCached(context: Context): Promise; /** * Updates in-memory storage with the specified flags without a context * or persistent storage. Flags set in this way are considered emphemeral and * should be replaced as soon as initialization is done. * * @param newFlags - cached flags */ presetFlags(newFlags: { [key: string]: ItemDescriptor; }): void; /** * Update in-memory storage with the specified flags, but do not persistent them to cache * storage. */ setBootstrap(context: Context, newFlags: { [key: string]: ItemDescriptor; }): void; /** * Applies a changeset to the flag store. * - `'full'`: replaces all flags (like {@link init}). * - `'partial'`: upserts individual flags (like calling {@link upsert} for each entry). * - `'none'`: persists cache (updating freshness) without changing any flags. * * Designed for the FDv2 data path where init/upsert semantics, selector * tracking, and freshness updates are all handled in one call. */ applyChanges(context: Context, updates: { [key: string]: ItemDescriptor; }, type: internal.PayloadType): Promise; /** * Register a flag change callback. */ on(callback: FlagsChangeCallback): void; /** * Unregister a flag change callback. */ off(callback: FlagsChangeCallback): void; /** * Obtain debug override functions that allows plugins * to manipulate the outcome of the flags managed by * this manager * * @experimental This function is experimental and intended for use by LaunchDarkly tools at this time. */ getDebugOverride?(): LDDebugOverride; } /** * Debug interface for plugins that need to override flag values during development. * This interface provides methods to temporarily override flag values that take * precedence over the actual flag values from LaunchDarkly. These overrides are * useful for testing, development, and debugging scenarios. * * @experimental This interface is experimental and intended for use by LaunchDarkly tools at this time. * The API may change in future versions. */ export interface LDDebugOverride { /** * Set an override value for a flag that takes precedence over the real flag value. * * @param flagKey The flag key. * @param value The override value. */ setOverride(flagKey: string, value: LDFlagValue): void; /** * Remove an override value for a flag, reverting to the real flag value. * * @param flagKey The flag key. */ removeOverride(flagKey: string): void; /** * Clear all override values, reverting all flags to their real values. */ clearAllOverrides(): void; /** * Get all currently active flag overrides. * * @returns * An object containing all active overrides as key-value pairs, * where keys are flag keys and values are the overridden flag values. * Returns an empty object if no overrides are active. */ getAllOverrides(): { [key: string]: ItemDescriptor; }; } export default class DefaultFlagManager implements FlagManager { private _flagStore; private _flagUpdater; private _flagPersistencePromise; private _overrides?; /** * @param platform implementation of various platform provided functionality * @param sdkKey that will be used to distinguish different environments * @param maxCachedContexts that specifies the max number of contexts that will be cached in persistence * @param disableCache set to true to completely disable the persistent flag cache * @param logger used for logging various messages * @param timeStamper exists for testing purposes */ constructor(platform: Platform, sdkKey: string, maxCachedContexts: number, disableCache: boolean, logger: LDLogger, timeStamper?: () => number); private _initPersistence; get(key: string): ItemDescriptor | undefined; getAll(): { [key: string]: ItemDescriptor; }; presetFlags(newFlags: { [key: string]: ItemDescriptor; }): void; setBootstrap(context: Context, newFlags: { [key: string]: ItemDescriptor; }): void; init(context: Context, newFlags: { [key: string]: ItemDescriptor; }): Promise; upsert(context: Context, key: string, item: ItemDescriptor): Promise; loadCached(context: Context): Promise; applyChanges(context: Context, updates: { [key: string]: ItemDescriptor; }, type: internal.PayloadType): Promise; on(callback: FlagsChangeCallback): void; off(callback: FlagsChangeCallback): void; private _convertValueToOverrideDescripter; setOverride(key: string, value: LDFlagValue): void; removeOverride(flagKey: string): void; clearAllOverrides(): void; getAllOverrides(): { [key: string]: ItemDescriptor; }; getDebugOverride(): LDDebugOverride; } //# sourceMappingURL=FlagManager.d.ts.map