import DynamicConfig from './DynamicConfig'; import { ClientInitializeResponse } from './Evaluator'; import { FeatureGate } from './FeatureGate'; import Layer from './Layer'; import { StatsigOptions } from './StatsigOptions'; import { StatsigUser } from './StatsigUser'; import { HashingAlgorithm } from './utils/Hashing'; export type LogEventObject = { eventName: string; user: StatsigUser; value?: string | number | null; metadata?: Record | null; time?: string | null; }; export type ClientInitializeResponseOptions = { hash?: HashingAlgorithm; }; /** * 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 _diagnostics; private outputLogger; constructor(secretKey: string, options?: StatsigOptions); /** * 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 */ initializeAsync(options?: StatsigOptions): Promise; /** * 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 */ checkGateSync(user: StatsigUser, gateName: string): boolean; getFeatureGateSync(user: StatsigUser, gateName: string): FeatureGate; checkGateWithExposureLoggingDisabledSync(user: StatsigUser, gateName: string): boolean; getFeatureGateWithExposureLoggingDisabledSync(user: StatsigUser, gateName: string): FeatureGate; logGateExposure(user: StatsigUser, gateName: string): void; /** * Checks the value of a config for a given user */ getConfigSync(user: StatsigUser, configName: string): DynamicConfig; getConfigWithExposureLoggingDisabledSync(user: StatsigUser, configName: string): DynamicConfig; logConfigExposure(user: StatsigUser, configName: 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 */ getExperimentSync(user: StatsigUser, experimentName: string): DynamicConfig; getExperimentWithExposureLoggingDisabledSync(user: StatsigUser, experimentName: string): DynamicConfig; logExperimentExposure(user: 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 layerName is not provided or not a non-empty string */ getLayerSync(user: StatsigUser, layerName: string): Layer; getLayerWithExposureLoggingDisabledSync(user: StatsigUser, layerName: string): Layer; logLayerParameterExposure(user: StatsigUser, layerName: string, parameterName: string): void; /** * 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(): void; flush(): Promise; clearAllGateOverrides(): void; clearAllConfigOverrides(): void; clearAllLayerOverrides(): void; syncStoreSpecs(): Promise; syncStoreIdLists(): Promise; getClientInitializeResponse(user: StatsigUser, options?: ClientInitializeResponseOptions): ClientInitializeResponse | null; overrideGate(gateName: string, value: boolean, userID?: string | null): void; overrideConfig(configName: string, value: Record, userID?: string | null): void; overrideLayer(layerName: string, value: Record, userID?: string | null): void; getFeatureGateList(): string[]; getDynamicConfigList(): string[]; getExperimentList(): string[]; getAutotuneList(): string[]; getLayerList(): string[]; /** * @deprecated Please use checkGateSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ checkGate(user: StatsigUser, gateName: string): Promise; /** * @deprecated Please use getFeatureGateSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getFeatureGate(user: StatsigUser, gateName: string): Promise; /** * @deprecated Please use checkGateWithExposureLoggingDisabledSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ checkGateWithExposureLoggingDisabled(user: StatsigUser, gateName: string): Promise; /** * @deprecated Please use getFeatureGateWithExposureLoggingDisabledSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getFeatureGateWithExposureLoggingDisabled(user: StatsigUser, gateName: string): Promise; /** * @deprecated Please use getConfigSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getConfig(user: StatsigUser, configName: string): Promise; /** * @deprecated Please use getConfigWithExposureLoggingDisabledSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getConfigWithExposureLoggingDisabled(user: StatsigUser, configName: string): Promise; /** * @deprecated Please use getExperimentSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getExperiment(user: StatsigUser, experimentName: string): Promise; /** * @deprecated Please use getExperimentWithExposureLoggingDisabledSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getExperimentWithExposureLoggingDisabled(user: StatsigUser, experimentName: string): Promise; /** * @deprecated Please use getLayerSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getLayer(user: StatsigUser, layerName: string): Promise; /** * @deprecated Please use getLayerWithExposureLoggingDisabledSync instead. * @see https://docs.statsig.com/server/deprecation-notices */ getLayerWithExposureLoggingDisabled(user: StatsigUser, layerName: string): Promise; private logGateExposureImpl; private getGateImpl; private logConfigExposureImpl; private getConfigImpl; private getLayerImpl; private logLayerParameterExposureImpl; private _validateInputs; private _makeOnDefaultValueFallbackFunction; }