statsig-js
Version:
Statsig JavaScript client SDK for single user environments.
135 lines (134 loc) • 5.36 kB
TypeScript
import StatsigSDKOptions from '../StatsigSDKOptions';
import { EvaluationDetails } from '../StatsigStore';
export declare type ContextType = 'initialize' | 'config_sync' | 'event_logging' | 'api_call';
export declare type KeyType = 'initialize' | 'bootstrap' | 'overall' | 'check_gate' | 'get_config' | 'get_experiment' | 'get_layer';
export declare type StepType = 'process' | 'network_request';
export declare type ActionType = 'start' | 'end';
export interface Marker {
key: KeyType;
action: ActionType;
timestamp: number;
step?: StepType;
statusCode?: number;
success?: boolean;
url?: string;
idListCount?: number;
sdkRegion?: string | null;
markerID?: string;
attempt?: number;
isRetry?: boolean;
configName?: string;
message?: string | null;
evaluationDetails?: EvaluationDetails;
error?: Record<string, unknown>;
}
declare type DiagnosticsMarkers = {
initialize: Marker[];
config_sync: Marker[];
event_logging: Marker[];
api_call: Marker[];
};
declare type DiagnosticsMaxMarkers = {
[K in ContextType]: number;
};
export declare class DiagnosticsImpl {
readonly mark: {
overall: {
start: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
end: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
};
initialize: {
process: {
start: (data: Record<string, never>, context?: ContextType | undefined) => boolean;
end: (data: {
success: boolean;
}, context?: ContextType | undefined) => boolean;
};
networkRequest: {
start: (data: {
attempt: number;
}, context?: ContextType | undefined) => boolean;
end: (data: {
success: boolean;
attempt: number;
isDelta?: boolean | undefined;
sdkRegion?: string | null | undefined;
statusCode?: number | undefined;
}, context?: ContextType | undefined) => boolean;
};
};
bootstrap: {
process: {
start: (data: Record<string, never>, context?: ContextType | undefined) => boolean;
end: (data: {
success: boolean;
}, context?: ContextType | undefined) => boolean;
};
networkRequest: {
start: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
end: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
};
};
api_call: (tag: string) => {
start: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
end: (data: RequiredActionTags, context?: ContextType | undefined) => boolean;
} | null;
};
markers: DiagnosticsMarkers;
disabled: boolean;
context: ContextType;
defaultMaxMarkers: number;
maxMarkers: DiagnosticsMaxMarkers;
constructor(args: {
options: StatsigSDKOptions;
markers?: DiagnosticsMarkers;
});
setContext(context: ContextType): void;
selectAction<ActionType extends RequiredStepTags>(key: KeyType, step?: StepType): {
start: (data: ActionType["start"], context?: ContextType | undefined) => boolean;
end: (data: ActionType["end"], context?: ContextType | undefined) => boolean;
};
selectStep<StepType extends RequiredMarkerTags>(key: KeyType): {
process: {
start: (data: StepType["process"]["start"], context?: ContextType | undefined) => boolean;
end: (data: StepType["process"]["end"], context?: ContextType | undefined) => boolean;
};
networkRequest: {
start: (data: StepType["networkRequest"]["start"], context?: ContextType | undefined) => boolean;
end: (data: StepType["networkRequest"]["end"], context?: ContextType | undefined) => boolean;
};
};
addMarker(marker: Marker, overrideContext?: ContextType): boolean;
getMarkers(context: ContextType): Marker[];
setMaxMarkers(context: ContextType, max: number): void;
getMarkerCount(context: ContextType): number;
clearContext(context: ContextType): void;
}
export default abstract class Diagnostics {
private static instance;
static mark: DiagnosticsImpl['mark'];
static disabled: DiagnosticsImpl['disabled'];
static getMarkers: DiagnosticsImpl['getMarkers'];
static getMarkerCount: DiagnosticsImpl['getMarkerCount'];
static setMaxMarkers: DiagnosticsImpl['setMaxMarkers'];
static setContext: DiagnosticsImpl['setContext'];
static clearContext: DiagnosticsImpl['clearContext'];
static initialize(args: {
options: StatsigSDKOptions;
markers?: DiagnosticsMarkers;
}): void;
static formatError(e: unknown): Record<string, unknown> | undefined;
private static safeGetField;
}
declare type RequiredActionTags = {
[K in keyof Marker]?: Marker[K];
};
interface RequiredStepTags {
start: RequiredActionTags;
end: RequiredActionTags;
}
interface RequiredMarkerTags {
process: RequiredStepTags;
networkRequest: RequiredStepTags;
}
export {};