UNPKG

statsig-js

Version:

Statsig JavaScript client SDK for single user environments.

57 lines (56 loc) 1.98 kB
import { IHasStatsigInternal } from './StatsigClient'; import { StatsigUser } from './StatsigUser'; import Diagnostics from './utils/Diagnostics'; export declare enum StatsigEndpoint { Initialize = "initialize", Rgstr = "rgstr", LogEventBeacon = "log_event_beacon" } declare type NetworkResponse = Response & { data?: Record<string, unknown>; }; /** * An extension of the promise type, it adds a * function `eventually`. In the event that the provided timeout * is reached, the function will still be called regardless. * * This function WILL NOT BE CALLED if the promise resolves normally. */ declare type PromiseWithTimeout<T> = Promise<T> & { eventually: (fn: (t: T) => void) => PromiseWithTimeout<T>; }; export default class StatsigNetwork { private sdkInternal; private readonly retryCodes; private leakyBucket; private canUseKeepalive; constructor(sdkInternal: IHasStatsigInternal); private init; fetchValues(args: { user: StatsigUser | null; sinceTime: number | null; timeout: number; useDeltas: boolean; prefetchUsers?: Record<string, StatsigUser>; previousDerivedFields?: Record<string, string>; hadBadDeltaChecksum?: boolean; badChecksum?: string; badMergedConfigs?: Record<string, unknown>; badFullResponse?: Record<string, unknown>; }): PromiseWithTimeout<Record<string, unknown>>; private postWithTimeout; sendLogBeacon(payload: Record<string, unknown>): boolean; postToEndpoint(endpointName: StatsigEndpoint, body: object, options?: { retryOptions?: { retryLimit?: number; attempt?: number; backoff?: number; }; useKeepalive?: boolean; diagnostics?: typeof Diagnostics.mark.initialize.networkRequest | null; }): Promise<NetworkResponse>; supportsKeepalive(): boolean; private getDiagnosticsData; private getErrorData; } export {};