@arvind_054/flagship-sdk
v1.0.1
Published
Feature flag SDK with TTL caching
Maintainers
Readme
npm version patch
npm publish --access publicflagship-sdk
A lightweight feature flag SDK for Node.js with built-in TTL caching.
Installation
npm install @arvind_054/flagship-sdkUsage
import { Flagship } from "@arvind_054/flagship-sdk";
const flagship = new Flagship({
apiKey: "your-api-key",
environment: "production",
baseUrl: "https://your-flagship-server.com", // optional, defaults to http://localhost:3000
ttl: 30000, // optional, cache TTL in ms (default: 30000)
});
const user = {
id: "user-123",
email: "[email protected]",
plan: "premium",
};
const isFeatureEnabled = await flagship.isEnabled("new-checkout-flow", user);
if (isFeatureEnabled) {
// Show new feature
} else {
// Show default experience
}API
new Flagship(config)
Creates a new Flagship client.
| Option | Type | Required | Default | Description |
|--------|------|----------|---------|-------------|
| apiKey | string | Yes | - | Your Flagship API key |
| environment | string | Yes | - | Environment name (e.g., "production", "staging") |
| baseUrl | string | No | http://localhost:3000 | Flagship server URL |
| ttl | number | No | 30000 | Cache TTL in milliseconds |
flagship.isEnabled(featureKey, user)
Evaluates whether a feature flag is enabled for a given user.
| Parameter | Type | Description |
|-----------|------|-------------|
| featureKey | string | The feature flag key |
| user | object | User object with id (required) and any additional attributes |
Returns: Promise<boolean> - true if enabled, false otherwise (including on errors)
Caching
Results are cached per user and feature key combination. Cached values expire after the configured TTL (default 30 seconds). On cache miss or expiration, a fresh evaluation is fetched from the server.
Error Handling
The SDK gracefully handles errors by returning false and logging the error to the console. This ensures your application continues to work even if the Flagship server is unavailable.
License
N/A
