JavaScript/TypeScript client SDK for FlagTGL feature flag management. Evaluates flags remotely with real-time SSE streaming for instant updates.
npm install @flagtgl/js-sdkOr with Yarn:
yarn add @flagtgl/js-sdkimport { FlagsClient } from '@flagtgl/js-sdk';
const client = new FlagsClient({
sdkKey: 'sdk-cli-your-key',
baseURL: 'https://flagtgl.com',
user: { key: 'user-123', attributes: { plan: 'premium' } },
});
await client.initialize();
const enabled = client.boolVariation('new-feature', false);
console.log('Feature enabled:', enabled);
// Listen for real-time changes
client.on('change', (key, newValue, oldValue) => {
console.log(`Flag ${key} changed from ${oldValue} to ${newValue}`);
});- Remote evaluation - flags evaluated server-side, no rules exposed to the client
- Real-time streaming - SSE streaming for instant flag updates
- Event tracking - built-in analytics with automatic batching
- TypeScript - full type definitions included
- Reactive - event-driven updates for UI frameworks
const client = new FlagsClient(config: FlagsConfig);
await client.initialize();client.boolVariation(key: string, defaultValue: boolean): boolean
client.stringVariation(key: string, defaultValue: string): string
client.numberVariation(key: string, defaultValue: number): number
client.jsonVariation<T>(key: string, defaultValue: T): T
client.allFlags(): Record<string, FlagValue>client.on('change', (key, newValue, oldValue) => { ... })
client.on('ready', () => { ... })
client.track('event-name', { custom: 'data' })await client.identify({ key: 'new-user', attributes: { plan: 'pro' } })interface FlagsConfig {
sdkKey: string; // Client SDK key
baseURL: string; // FlagTGL server URL
user: FlagUser; // User context for evaluation
streaming?: boolean; // Enable SSE streaming (default: true)
flushInterval?: number; // Event flush interval in ms (default: 30000)
flushSize?: number; // Buffer size before auto-flush (default: 100)
}Full documentation available at flagtgl.com/docs.
MIT