@flaglayer/sdk
v0.1.1
Published
Core JavaScript/TypeScript SDK for Flaglayer feature flags.
Downloads
291
Readme
@flaglayer/sdk
Core JavaScript/TypeScript SDK for Flaglayer feature flags.
Install
npm install @flaglayer/sdkUsage
import { FlagLayer } from '@flaglayer/sdk';
const fl = new FlagLayer({ apiKey: 'your-api-key' });
await fl.identify({ userId: 'user-123' });
const showFeature = fl.getBooleanValue('new-feature', false);API
new FlagLayer(options)— Create a client instance. Options includeapiKeyand optionalbaseUrl.identify(context)— Set the evaluation context (user, org, custom attributes).evaluate(key, context)— Evaluate a flag and return the full result.getBooleanValue(key, fallback)— Get a boolean flag value.getStringValue(key, fallback)— Get a string flag value.getNumberValue(key, fallback)— Get a number flag value.getValue(key, fallback)— Get a flag value of any type.getFlags()— Get all evaluated flags.refresh()— Re-fetch flags from the server.
Configuration
The API base URL is configurable via the baseUrl option and defaults to the Flaglayer cloud API.
const fl = new FlagLayer({
apiKey: 'your-api-key',
baseUrl: 'https://your-self-hosted-instance.com',
});