import { DVCFeatureSet, DevCycleOptions, DVCVariableSet, DVCVariableValue, DevCycleEvent, DevCycleUser, ErrorCallback, DVCFeature, VariableDefinitions } from './types'; import { DVCVariable } from './Variable'; import { DVCPopulatedUser } from './User'; import { EventEmitter } from './EventEmitter'; import { BucketedUserConfig, VariableTypeAlias } from '@devcycle/types'; import { DVCLogger } from '@devcycle/types'; type variableUpdatedHandler = (key: string, variable: DVCVariable | null) => void; type featureUpdatedHandler = (key: string, feature: DVCFeature | null) => void; type newVariablesHandler = () => void; type errorHandler = (error: unknown) => void; type initializedHandler = (success: boolean) => void; type configUpdatedHandler = (newVars: DVCVariableSet) => void; type variableEvaluatedHandler = (key: string, variable: DVCVariable) => void; export type DevCycleOptionsWithDeferredInitialization = DevCycleOptions & { deferInitialization: true; bootstrapConfig?: never; }; export declare const isDeferredOptions: (arg: DevCycleUser | DevCycleOptionsWithDeferredInitialization) => arg is DevCycleOptionsWithDeferredInitialization; export declare class DevCycleClient { logger: DVCLogger; config?: BucketedUserConfig; user?: DVCPopulatedUser; _isInitialized: boolean; get isInitialized(): boolean; private sdkKey; private readonly options; private onInitialized; private resolveOnInitialized; private userSaved; private _closing; private isConfigCached; private initializeTriggered; private variableDefaultMap; private store; private eventQueue; private requestConsolidator; eventEmitter: EventEmitter; private streamingConnection?; private pageVisibilityHandler?; private inactivityHandlerId?; private windowMessageHandler?; private windowPageHideHandler?; constructor(sdkKey: string, options: DevCycleOptionsWithDeferredInitialization); constructor(sdkKey: string, user: DevCycleUser, options?: DevCycleOptions); /** * Logic to initialize the client with the appropriate user and configuration data by making requests to DevCycle * and loading from local storage. This either happens immediately on client initialization, or when the user is * first identified (in deferred mode) * @param initialUser */ private clientInitialization; /** * Notify the user when configuration data has been loaded from the server. * An optional callback can be passed in, and will return * a promise if no callback has been passed in. */ onClientInitialized(): Promise>; onClientInitialized(onInitialized: ErrorCallback>): void; /** * Get variable object associated with Features. Use the variable's key to fetch the DVCVariable object. * If the user does not receive the feature, the default value is used in the returned DVCVariable object. * DVCVariable is returned, which has a `value` property that is used to grab the variable value, * and a convenience method to pass in a callback to notify the user when the value has changed from the server. * * @param key * @param defaultValue */ variable(key: K, defaultValue: T): DVCVariable; private trackVariableEvaluated; /** * Get a variable's value associated with a Feature. Use the variable's key to fetch the variable's value. * If the user is not segmented into the feature, the default value is returned. * * @param key * @param defaultValue */ variableValue(key: K, defaultValue: T): VariableTypeAlias; /** * Update user data after SDK initialization, this will trigger updates to variable values. * The `callback` parameter or returned `promise` can be used to return the set of variables * for the new user. * * @param user * @param callback */ identifyUser(user: DevCycleUser): Promise; identifyUser(user: DevCycleUser, callback?: ErrorCallback): void; private _identifyUser; /** * Resets the user to an Anonymous user. `callback` or `Promise` can be used to return * the set of variables for the new user. * * @param callback */ resetUser(): Promise; resetUser(callback: ErrorCallback): void; /** * Retrieve data on all Features, Object mapped by feature `key`. * Use the `DVCFeature.segmented` value to determine if the user was segmented into a * feature's audience. */ allFeatures(): DVCFeatureSet; /** * Retrieve data on all Variables, Object mapped by variable `key`. */ allVariables(): DVCVariableSet; /** * Subscribe to events emitted by the SDK, `onUpdate` will be called everytime an * event is emitted by the SDK. * * Events: * - `initialized` -> (initialized: boolean) * - `error` -> (error: Error) * - `variableUpdated:*` -> (key: string, variable: DVCVariable) * - `variableUpdated:` -> (key: string, variable: DVCVariable) * - `featureUpdated:*` -> (key: string, feature: DVCFeature) * - `featureUpdated:` -> (key: string, feature: DVCFeature) * - `variableEvaluated:*` -> (key: string, variable: DVCVariable) * - `variableEvaluated:` -> (key: string, variable: DVCVariable) * * @param key * @param handler */ subscribe(key: `variableUpdated:${string}`, handler: variableUpdatedHandler): void; subscribe(key: `newVariables:${string}`, handler: newVariablesHandler): void; subscribe(key: `featureUpdated:${string}`, handler: featureUpdatedHandler): void; subscribe(key: `variableEvaluated:${string}`, handler: variableEvaluatedHandler): void; subscribe(key: 'error', handler: errorHandler): void; subscribe(key: 'initialized', handler: initializedHandler): void; subscribe(key: 'configUpdated', handler: configUpdatedHandler): void; /** * Unsubscribe to remove existing event emitter subscription. * * @param key * @param handler */ unsubscribe(key: string, handler?: (...args: any[]) => void): void; /** * Track Event to DevCycle * * @param event */ track(event: DevCycleEvent): void; /** * Flush all queued events to DevCycle * * @param callback */ flushEvents(callback?: () => void): Promise; /** * Close all open connections to DevCycle, flush any pending events and * stop any running timers and event handlers. Use to clean up a client instance * that is no longer needed. */ close(): Promise; /** * Reflects whether `close()` has been called on the client instance. */ get closing(): boolean; private refetchConfig; private handleConfigReceived; private onSSEMessage; private registerVisibilityChangeHandler; private getConfigCache; } export {};