UNPKG

@varia-bly/variably-sdk

Version:

Official JavaScript/TypeScript SDK for Variably feature flags, experimentation, LLM experiments with React hooks, and real-time dynamic configurations

95 lines 2.88 kB
/** * GraphQL WebSocket subscription client for real-time Feature Gate updates * Uses graphql-ws protocol for GraphQL subscriptions */ import { Logger } from './logger'; export interface FeatureGateUpdate { id: string; gateKey: string; projectId: string; isEnabled: boolean; description?: string; trafficAllocation?: number; updatedAt: string; } export type FeatureGateUpdateCallback = (gate: FeatureGateUpdate) => void; export type ConnectionStateCallback = (state: 'connecting' | 'connected' | 'disconnected' | 'error') => void; export interface GraphQLSubscriptionConfig { /** GraphQL endpoint URL */ url: string; /** API key for authentication */ apiKey: string; /** Project ID to subscribe to */ projectId: string; /** Enable automatic reconnection (default: true) */ autoReconnect?: boolean; /** Reconnection interval in ms (default: 5000) */ reconnectInterval?: number; /** Maximum reconnection attempts (default: 10) */ maxReconnectAttempts?: number; } export declare class GraphQLSubscriptionClient { private client; private config; private logger; private connectionState; private gateUpdateCallbacks; private connectionStateCallbacks; private activeSubscriptions; private reconnectAttempts; private reconnectTimer; constructor(config: GraphQLSubscriptionConfig, logger: Logger); /** * Connect to GraphQL WebSocket server */ connect(): Promise<void>; /** * Disconnect from GraphQL WebSocket server */ disconnect(): void; /** * Subscribe to Feature Gate updates for a specific project */ subscribeToFeatureGates(projectId: string, gateKey?: string): () => void; /** * Add callback for Feature Gate updates */ onFeatureGateUpdate(gateKey: string, callback: FeatureGateUpdateCallback): () => void; /** * Add callback for all Feature Gate updates (wildcard) */ onAnyFeatureGateUpdate(callback: FeatureGateUpdateCallback): () => void; /** * Add callback for connection state changes */ onConnectionState(callback: ConnectionStateCallback): () => void; /** * Get current connection state */ getConnectionState(): string; /** * Check if client is connected */ isConnected(): boolean; /** * Handle Feature Gate update from subscription */ private handleGateUpdate; /** * Resubscribe to all active subscriptions after reconnection */ private resubscribeAll; /** * Schedule reconnection attempt */ private scheduleReconnect; /** * Clear reconnection timer */ private clearReconnectTimer; /** * Update connection state and notify callbacks */ private setConnectionState; } //# sourceMappingURL=graphql-subscription-client.d.ts.map