Skip to content

flagtgl/js-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlagTGL JavaScript Client SDK

JavaScript/TypeScript client SDK for FlagTGL feature flag management. Evaluates flags remotely with real-time SSE streaming for instant updates.

Installation

npm install @flagtgl/js-sdk

Or with Yarn:

yarn add @flagtgl/js-sdk

Quick Start

import { 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}`);
});

Features

  • 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

API Reference

Client Creation

const client = new FlagsClient(config: FlagsConfig);
await client.initialize();

Evaluation Methods

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>

Events

client.on('change', (key, newValue, oldValue) => { ... })
client.on('ready', () => { ... })
client.track('event-name', { custom: 'data' })

User Management

await client.identify({ key: 'new-user', attributes: { plan: 'pro' } })

Configuration

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)
}

Documentation

Full documentation available at flagtgl.com/docs.

License

MIT

About

FlagTGL JavaScript Client SDK - feature flags for web applications

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors