UNPKG

statsig-js

Version:

Statsig JavaScript client SDK for single user environments.

142 lines (141 loc) 5.22 kB
import DynamicConfig from './DynamicConfig'; import FeatureGate from './FeatureGate'; import Layer from './Layer'; import { StatsigUser } from './StatsigUser'; export declare const INIT_TIMEOUT_DEFAULT_MS = 3000; export type StatsigEnvironment = { tier?: 'production' | 'staging' | 'development' | string; [key: string]: string | undefined; }; export type InitCompletionCallback = (initDurationMs: number, success: boolean, message: string | null) => void; export type UpdateUserCompletionCallback = (durationMs: number, success: boolean, message: string | null) => void; export type GateEvaluationCallback = (key: string, value: boolean, details: { withExposureLoggingDisabled: boolean; }) => void; export type EvaluationCallbackParams = { type: 'gate'; gate: FeatureGate; } | { type: 'config' | 'experiment'; config: DynamicConfig; } | { type: 'layer'; layer: Layer; }; export type EvaluationCallback = (args: EvaluationCallbackParams) => void; export interface UserPersistentStorageInterface { load(key: string): string; save(key: string, data: string): void; userIDType: string | undefined; } export type StatsigOptions = { api?: string; disableAllLogging?: boolean; disableAutoMetricsLogging?: boolean; disableCurrentPageLogging?: boolean; disableDiagnosticsLogging?: boolean; disableErrorLogging?: boolean; disableLocalOverrides?: boolean; disableLocalStorage?: boolean; disableNetworkKeepalive?: boolean; initRequestRetries?: number; environment?: StatsigEnvironment; eventLoggingApi?: string; fetchMode?: FetchMode; gateEvaluationCallback?: GateEvaluationCallback; ignoreWindowUndefined?: boolean; initCompletionCallback?: InitCompletionCallback | null; initializeValues?: Record<string, unknown> | null; initTimeoutMs?: number; localMode?: boolean; loggingBufferMaxSize?: number; loggingIntervalMillis?: number; logLevel?: LogLevel | null; logger?: LoggerInterface; overrideStableID?: string; prefetchUsers?: StatsigUser[]; updateUserCompletionCallback?: UpdateUserCompletionCallback | null; userPersistentStorage?: UserPersistentStorageInterface; disableHashing?: boolean; evaluationCallback?: EvaluationCallback; }; export interface LoggerInterface { error(message?: any, ...optionalParams: any[]): void; info(message?: any, ...optionalParams: any[]): void; debug?(message?: any, ...optionalParams: any[]): void; warn(message?: any, ...optionalParams: any[]): void; } export declare enum LogLevel { NONE = "NONE", INFO = "INFO", DEBUG = "DEBUG", WARN = "WARN", ERROR = "ERROR" } export type FetchMode = 'cache-or-network' | 'network-only'; export default class StatsigSDKOptions { private api; private disableAllLogging; private disableAutoMetricsLogging; private disableCurrentPageLogging; private disableDiagnosticsLogging; private disableErrorLogging; private disableLocalOverrides; private disableLocalStorage; private disableNetworkKeepalive; private initRequestRetries; private environment; private eventLoggingApi; private fetchMode; private gateEvaluationCallback; private ignoreWindowUndefined; private initCompletionCallback; private initializeValues; private initTimeoutMs; private localMode; private loggingBufferMaxSize; private loggingIntervalMillis; private logLevel; private logger; private overrideStableID; private prefetchUsers; private updateCompletionCallback; private userPersistentStorage; private disableHashing; private evaluationCallback; private loggingCopy; constructor(options?: StatsigOptions | null); setLoggingCopy(options: StatsigOptions | null): void; getLoggingCopy(): Record<string, unknown> | undefined; getOutputLogger(): LoggerInterface; getApi(): string; getEnvironment(): StatsigEnvironment | null; getDisableCurrentPageLogging(): boolean; getLoggingIntervalMillis(): number; getLoggingBufferMaxSize(): number; getDisableNetworkKeepalive(): boolean; getOverrideStableID(): string | null; getLocalModeEnabled(): boolean; getInitTimeoutMs(): number; getDisableErrorLogging(): boolean; getDisableAutoMetricsLogging(): boolean; getInitializeValues(): Record<string, unknown> | null; getEventLoggingApi(): string; getPrefetchUsers(): StatsigUser[]; getDisableLocalStorage(): boolean; getInitCompletionCallback(): InitCompletionCallback | null; getUpdateUserCompletionCallback(): UpdateUserCompletionCallback | null; getDisableDiagnosticsLogging(): boolean; getLogLevel(): LogLevel; getIgnoreWindowUndefined(): boolean; getFetchMode(): FetchMode; getDisableLocalOverrides(): boolean; getGateEvaluationCallback(): GateEvaluationCallback | null; getUserPersistentStorage(): UserPersistentStorageInterface | null; getDisableHashing(): boolean; getInitRequestRetries(): number; isAllLoggingDisabled(): boolean; reenableAllLogging(): void; getEvaluationCallback(): EvaluationCallback | null; private normalizeNumberInput; }