import DynamicConfig from './DynamicConfig'; import { ClientInitializeResponse } from './Evaluator'; import { FeatureGate } from './FeatureGate'; import { InitializationDetails } from './InitializationDetails'; import { UserPersistedValues } from './interfaces/IUserPersistentStorage'; import Layer from './Layer'; import { CheckGateOptions, ClientInitializeResponseOptions, GetConfigOptions, GetExperimentOptions, GetLayerOptions, StatsigOptions } from './StatsigOptions'; import { StatsigUser } from './StatsigUser'; export type LogEventObject = { eventName: string; user: StatsigUser; value?: string | number | null; metadata?: Record | null; time?: string | null; }; /** * The global statsig class for interacting with gates, configs, experiments configured in the statsig developer console. Also used for event logging to view in the statsig console, or for analyzing experiment impacts using pulse. */ export default class StatsigServer { private _pendingInitPromise; private _ready; private _options; private _logger; private _secretKey; private _evaluator; private _fetcher; private _errorBoundary; private _sessionID; private _store; constructor(secretKey: string, options?: StatsigOptions); initializeAsync(): Promise; /** * Initializes the statsig server SDK. This must be called before checking gates/configs or logging events. * @throws Error if a Server Secret Key is not provided */ private initializeImpl; /** * Check the value of a gate configured in the statsig console * @throws Error if initialize() was not called first * @throws Error if the gateName is not provided or not a non-empty string */ checkGate(user: StatsigUser, gateName: string, options?: CheckGateOptions): boolean; getFeatureGate(user: StatsigUser, gateName: string, options?: CheckGateOptions): FeatureGate; logGateExposure(inputUser: StatsigUser, gateName: string): void; /** * Checks the value of a config for a given user */ getConfig(user: StatsigUser, configName: string, options?: GetConfigOptions): DynamicConfig; logConfigExposure(inputUser: StatsigUser, experimentName: string): void; /** * Checks the value of a config for a given user * @throws Error if initialize() was not called first * @throws Error if the experimentName is not provided or not a non-empty string */ getExperiment(user: StatsigUser, experimentName: string, options?: GetExperimentOptions): DynamicConfig; logExperimentExposure(inputUser: StatsigUser, experimentName: string): void; getExperimentLayer(experiment: string): string | null; /** * Checks the value of a config for a given user * @throws Error if initialize() was not called first * @throws Error if the layerName is not provided or not a non-empty string */ getLayer(user: StatsigUser, layerName: string, options?: GetLayerOptions): Layer; logLayerParameterExposure(inputUser: StatsigUser, layerName: string, parameterName: string): void; getPromptSet(aiConfigName: string): Record[] | null; getUserPersistedValues(user: StatsigUser, idType: string): UserPersistedValues; /** * Log an event for data analysis and alerting or to measure the impact of an experiment * @throws Error if initialize() was not called first */ logEvent(user: StatsigUser, eventName: string, value?: string | number | null, metadata?: Record | null): void; logEventObject(eventObject: LogEventObject): void; /** * Informs the statsig SDK that the server is closing or shutting down * so the SDK can clean up internal state */ shutdown(timeout?: number): void; /** * Informs the statsig SDK that the server is closing or shutting down * so the SDK can clean up internal state * Ensures any pending promises are resolved and remaining events are flushed. */ shutdownAsync(timeout?: number): Promise; flush(timeout?: number): Promise; clearAllGateOverrides(): void; clearAllConfigOverrides(): void; clearAllLayerOverrides(): void; syncStoreSpecs(): Promise; syncStoreIdLists(): Promise; getClientInitializeResponse(user: StatsigUser, clientSDKKey?: string, options?: ClientInitializeResponseOptions): ClientInitializeResponse | null; overrideGate(gateName: string, value: boolean, userOrCustomID?: string | null): void; overrideConfig(configName: string, value: Record, userOrCustomID?: string | null): void; overrideLayer(layerName: string, value: Record, userOrCustomID?: string | null): void; getFeatureGateList(): string[]; getDynamicConfigList(): string[]; getExperimentList(): string[]; getAutotuneList(): string[]; getLayerList(): string[]; /** * @deprecated Please use checkGate instead. * @see https://docs.statsig.com/server/deprecation-notices */ checkGateSync(user: StatsigUser, gateName: string): boolean; /** * @deprecated Please use getFeatureGate instead. * @see https://docs.statsig.com/server/deprecation-notices */ getFeatureGateSync(user: StatsigUser, gateName: string): FeatureGate; /** * @deprecated Please use checkGate() with CheckGateOptions instead. * @see https://docs.statsig.com/server/deprecation-notices */ checkGateWithExposureLoggingDisabledSync(user: StatsigUser, gateName: string): boolean; /** * @deprecated Please use getFeatureGate with CheckGateOptions instead. * @see https://docs.statsig.com/server/deprecation-notices */ getFeatureGateWithExposureLoggingDisabledSync(user: StatsigUser, gateName: string): FeatureGate; /** * @deprecated Please use getConfig instead. * @see https://docs.statsig.com/server/deprecation-notices */ getConfigSync(user: StatsigUser, configName: string): DynamicConfig; /** * @deprecated Please use getConfigWithExposureLoggingDisabled instead. * @see https://docs.statsig.com/server/deprecation-notices */ getConfigWithExposureLoggingDisabledSync(user: StatsigUser, configName: string): DynamicConfig; /** * @deprecated Please use getExperiment instead. * @see https://docs.statsig.com/server/deprecation-notices */ getExperimentSync(user: StatsigUser, experimentName: string, options?: GetExperimentOptions): DynamicConfig; /** * @deprecated Please use getExperimentWithExposureLoggingDisabled instead. * @see https://docs.statsig.com/server/deprecation-notices */ getExperimentWithExposureLoggingDisabledSync(user: StatsigUser, experimentName: string, options?: GetExperimentOptions): DynamicConfig; /** * @deprecated Please use getLayer instead. * @see https://docs.statsig.com/server/deprecation-notices */ getLayerSync(user: StatsigUser, layerName: string, options?: GetLayerOptions): Layer; /** * @deprecated Please use getLayer with GetLayerOptions instead. * @see https://docs.statsig.com/server/deprecation-notices */ getLayerWithExposureLoggingDisabledSync(user: StatsigUser, layerName: string, options?: GetLayerOptions): Layer; /** * @deprecated Please use checkGate with CheckGateOptions instead. * @see https://docs.statsig.com/server/deprecation-notices */ checkGateWithExposureLoggingDisabled(user: StatsigUser, gateName: string): boolean; /** * @deprecated use getFeatureGate() with CheckGateOptions instead */ getFeatureGateWithExposureLoggingDisabled(user: StatsigUser, gateName: string): FeatureGate; /** * @deprecated use getConfig() with GetConfigOptions instead */ getConfigWithExposureLoggingDisabled(user: StatsigUser, configName: string): DynamicConfig; /** * @deprecated use getExperiment() with GetExperimentOptions instead * GetExperimentOptions.disableExposureDisabled will be ignored */ getExperimentWithExposureLoggingDisabled(user: StatsigUser, experimentName: string, options?: GetExperimentOptions): DynamicConfig; /** * @deprecated use getLayer() with GetLayerOptions instead * GetLayerOptions.disableExposureDisabled will be ignored */ getLayerWithExposureLoggingDisabled(user: StatsigUser, layerName: string, options?: GetLayerOptions): Layer; private logGateExposureImpl; private evalGate; private getGateImpl; private logConfigExposureImpl; private evalConfig; private getConfigImpl; private evalLayer; private getLayerImpl; private logLayerParameterExposureImpl; private _validateInputs; private _makeOnDefaultValueFallbackFunction; private _normalizeUser; }