The `tggl-client` package provides a TypeScript SDK for integrating Tggl feature flags into both client-side (browsers, React Native) and server-side (Node.js) applications. Currently at version 3.2.2, the library maintains an active release cadence with frequent updates and bug fixes, as evidenced by recent v3.x releases. Version 3 represents a complete rewrite focused on improved reliability, fault tolerance, and maintainability, introducing a simpler API, better error handling, and automatic HTTP retries via `ky`. A key differentiator is its enforcement of feature flag best practices, specifically by removing the `isActive` method and making the default value a required argument for the `get` method since v2.0.0, guiding developers to always handle the absence of a flag gracefully. It also offers built-in storage options for Postgres, Redis, and Static storage for server-side usage, requiring corresponding peer dependencies like `pg` or `redis` for these features. The SDK supports Node.js environments version 20.0.0 and above.
npm install tggl-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the initialization and usage of both TgglClient (for client-side) and TgglLocalClient (for server-side) to evaluate feature flags with different contexts and built-in storage options.
Replace any calls to `client.isActive('flag-name')` with `client.get('flag-name', false)` or similar, and ensure all `client.get('flag-name')` calls are updated to `client.get('flag-name', defaultValue)`.Review the v3 release notes and documentation for any changes to client configuration or behavior. Ensure your Node.js environment meets the `>=20.0.0` requirement. Verify all peer dependencies are correctly installed if using built-in storages.
Always use `TgglClient` with a client API key in frontend applications and `TgglLocalClient` with a server API key in backend applications. `TgglLocalClient` also requires a storage mechanism (e.g., `StaticStorage`, `PostgresStorage`, `RedisStorage`).
Always `await client.waitReady()` immediately after client initialization to ensure that the initial set of flags has been loaded before any `get()` calls are made. This is essential for reliable flag evaluation.
Update your code to use the `get` method with a default boolean value instead, e.g., `client.get('feature-name', false)`.Provide a default value for the flag, e.g., `client.get('feature-name', true)` or `localClient.get(context, 'feature-name', 'default_value')`.Use ESM `import` statements (e.g., `import { TgglClient } from 'tggl-client';`) and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`). If running in Node.js, ensure your environment supports ESM.Verify your `apiKey` is correct and has the necessary permissions. Check network connectivity to `tggl.io` (or your configured `baseUrl`). Review Tggl's status page or logs for potential service outages or errors. Ensure firewalls are not blocking access.