@varia-bly/variably-sdk
Version:
Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, and real-time dynamic configurations
165 lines • 4.38 kB
TypeScript
/**
* Type definitions for Variably SDK
*/
export interface VariablyConfig {
/** API key for authentication */
apiKey: string;
/** Base URL for the GraphQL API (default: https://graphql.variably.tech) */
baseUrl?: string;
/** Environment (development, staging, production) */
environment?: string;
/** Request timeout in milliseconds (default: 5000) */
timeout?: number;
/** Number of retry attempts (default: 3) */
retryAttempts?: number;
/** Enable analytics tracking (default: true) */
enableAnalytics?: boolean;
/** Cache configuration */
cache?: CacheConfig;
}
export interface CacheConfig {
/** Cache TTL in milliseconds (default: 300000 = 5 minutes) */
ttl?: number;
/** Maximum cache size (default: 1000) */
maxSize?: number;
/** Enable cache (default: true) */
enabled?: boolean;
}
export interface UserContext {
/** Unique user identifier */
userId: string;
/** User email address */
email?: string;
/** User's country code */
country?: string;
/** User's preferred language */
language?: string;
/** Device/platform information */
platform?: string;
/** Application version */
version?: string;
/** User's IP address */
ipAddress?: string;
/** User agent string */
userAgent?: string;
/** Custom user attributes for targeting */
attributes?: Record<string, any>;
/** Session ID */
sessionId?: string;
}
export interface Event {
/** Event name */
name: string;
/** User ID associated with the event */
userId: string;
/** Event properties */
properties?: Record<string, any>;
/** Event timestamp (auto-generated if not provided) */
timestamp?: Date;
/** User context for the event */
context?: UserContext;
/** Session ID */
sessionId?: string;
}
export interface FlagResult {
/** Flag key */
key: string;
/** Flag value */
value: any;
/** Evaluation reason */
reason: string;
/** Rule ID that matched (if any) */
ruleId?: string;
/** Variation name (if any) */
variation?: string;
/** Whether the result came from cache */
cacheHit: boolean;
/** When the flag was evaluated */
evaluatedAt: Date;
/** Error if evaluation failed */
error?: Error;
}
export interface FlagEvaluationRequest {
flag_key: string;
context: UserContext;
}
export interface FlagEvaluationResponse {
flag_key: string;
value: any;
reason: string;
rule_id?: string;
}
export interface GateEvaluationRequest {
gate_key: string;
context: UserContext;
}
export interface GateEvaluationResponse {
gate_key: string;
value: boolean;
reason: string;
rule_id?: string;
environment: string;
}
export interface EventTrackingRequest {
name: string;
user_id: string;
properties?: Record<string, any>;
timestamp: Date;
}
export interface BatchFlagEvaluationRequest {
flag_keys: string[];
context: UserContext;
}
export interface BatchFlagEvaluationResponse {
results: Record<string, FlagEvaluationResponse>;
}
export interface CacheEntry<T = any> {
value: T;
timestamp: number;
ttl: number;
}
export interface SDKMetrics {
/** Total API calls made */
apiCalls: number;
/** Cache hits */
cacheHits: number;
/** Cache misses */
cacheMisses: number;
/** Total errors */
errors: number;
/** Average response time in ms */
averageLatency: number;
/** Cache hit rate (0-1) */
cacheHitRate: number;
/** Error rate (0-1) */
errorRate: number;
/** Flags evaluated */
flagsEvaluated: number;
/** Gates evaluated */
gatesEvaluated: number;
/** Events tracked */
eventsTracked: number;
/** SDK start time */
startTime: Date;
}
export interface DynamicConfigEvaluationRequest {
config_key: string;
context: UserContext;
}
export interface DynamicConfigEvaluationResponse {
config_key: string;
value: any;
reason: string;
rule_id?: string;
etag?: string;
version?: number;
updated_at?: string;
}
export interface DynamicConfigBatchRequest {
config_keys: string[];
context: UserContext;
}
export interface DynamicConfigBatchResponse {
results: Record<string, DynamicConfigEvaluationResponse>;
}
//# sourceMappingURL=types.d.ts.map