@varia-bly/variably-sdk
Version:
Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, LLM experiments with React hooks, and real-time dynamic configurations
177 lines • 5.79 kB
TypeScript
/**
* Variably JavaScript/TypeScript SDK Client
*/
import { ABTestResult, CohortAnalysisResult, FunnelAnalysisResult } from './statistical-analysis';
import { MetricThreshold, AlertChannel, MetricDataPoint } from './alerting';
import { VariablyConfig, UserContext, Event, FlagResult, SDKMetrics, ExperimentMetric, GateEvaluationResponse } from './types';
export declare class VariablyClient {
private graphqlClient;
private cache;
private metrics;
private logger;
private config;
private autoTracker?;
private alerting?;
private realTimeSync?;
private currentUserContext;
private lastExperimentContext;
private experimentSuccessMetrics;
constructor(config: VariablyConfig);
/**
* Evaluate a boolean feature flag
*/
evaluateFlagBool(flagKey: string, defaultValue: boolean, userContext: UserContext): Promise<boolean>;
/**
* Evaluate a string feature flag
*/
evaluateFlagString(flagKey: string, defaultValue: string, userContext: UserContext): Promise<string>;
/**
* Evaluate a number feature flag
*/
evaluateFlagNumber(flagKey: string, defaultValue: number, userContext: UserContext): Promise<number>;
/**
* Evaluate a JSON feature flag
*/
evaluateFlagJSON<T = any>(flagKey: string, defaultValue: T, userContext: UserContext): Promise<T>;
/**
* Evaluate a feature flag with full result details
*/
evaluateFlag(flagKey: string, defaultValue: any, userContext: UserContext): Promise<FlagResult>;
/**
* Evaluate multiple feature flags in batch
*/
evaluateFlags(flagKeys: string[], userContext: UserContext): Promise<Record<string, FlagResult>>;
/**
* Evaluate a feature gate
*/
evaluateGate(gateKey: string, userContext: UserContext): Promise<boolean>;
/**
* Evaluate a feature gate and return full context including experiment information
*/
evaluateGateWithContext(gateKey: string, userContext: UserContext): Promise<GateEvaluationResponse>;
/**
* Track an analytics event
*/
track(event: Event): Promise<void>;
/**
* Track multiple events in batch
*/
trackBatch(events: Event[]): Promise<void>;
/**
* Track an experiment-specific metric
*/
trackMetric(experimentId: string, metric: ExperimentMetric): Promise<void>;
/**
* Clear the cache
*/
clearCache(): void;
/**
* Get SDK metrics
*/
getMetrics(): SDKMetrics;
/**
* Calculate A/B test statistical significance
*/
calculateABTestSignificance(treatmentConversions: number, treatmentTotal: number, controlConversions: number, controlTotal: number, confidenceLevel?: number): ABTestResult;
/**
* Calculate required sample size for A/B test
*/
calculateRequiredSampleSize(baselineConversion: number, minimumDetectableEffect: number, power?: number, confidenceLevel?: number): number;
/**
* Perform cohort analysis for user retention
*/
analyzeCohort(cohortUsers: string[], userEvents: {
userId: string;
eventName: string;
timestamp: Date;
}[], retentionEvent?: string, periods?: string[]): CohortAnalysisResult;
/**
* Analyze conversion funnel
*/
analyzeFunnel(funnelSteps: string[], userEvents: {
userId: string;
eventName: string;
timestamp: Date;
}[], timeWindow?: number): FunnelAnalysisResult;
/**
* Add metric threshold for real-time alerting
*/
addMetricThreshold(threshold: MetricThreshold): void;
/**
* Remove metric threshold
*/
removeMetricThreshold(thresholdId: string): void;
/**
* Add alert channel for notifications
*/
addAlertChannel(channel: AlertChannel): void;
/**
* Record a metric data point for real-time monitoring
*/
recordMetric(dataPoint: MetricDataPoint): void;
/**
* Get alert history
*/
getAlertHistory(hours?: number): import("./alerting").MetricAlert[];
/**
* Get current metric value
*/
getCurrentMetricValue(metricName: string): number | undefined;
/**
* Get metric statistics over time window
*/
getMetricStats(metricName: string, timeWindow: number): {
avg: number;
min: number;
max: number;
count: number;
trend: "up" | "down" | "stable";
} | undefined;
/**
* Logout user and clear tokens
*/
logout(): Promise<void>;
/**
* Clear stored authentication tokens from local storage
*/
private clearStoredTokens;
/**
* Initialize experiment success metrics - metrics will be populated dynamically from gate evaluation responses
*/
private loadExperimentSuccessMetrics;
/**
* Check if an event should be enriched with experiment context
*/
private shouldEnrichWithExperimentContext;
/**
* Set current user context for auto-tracking
*/
setUserContext(userContext: UserContext | null): void;
/**
* Get current user context
*/
getCurrentUserContext(): UserContext | null;
/**
* Destroy the client and clean up resources
*/
destroy(): void;
/**
* Validate and normalize configuration
*/
private validateAndNormalizeConfig;
/**
* Generate cache key for flag evaluation
*/
private generateCacheKey;
/**
* Generate cache key for gate evaluation
*/
private generateGateCacheKey;
/**
* Generate a simple hash of user context for caching
*/
private hashUserContext;
}
export declare function createClient(config: VariablyConfig): VariablyClient;
export declare function createClientFromEnv(): VariablyClient;
//# sourceMappingURL=client.d.ts.map