@minimalab/indie-flags
v0.2.0
Published
Feature flags for Indie Flags — isEnabled, getValue, optional 60s cache
Readme
Indie Flags SDK
Feature flags for Indie Flags — isEnabled, getValue, optional 60s cache. Works in Node.js (18+) and browser.
Install
npm install indie-flagsGet your API key
In the Indie Flags dashboard, open your project → API Keys. Copy the client key (starts with if_pub_). Use it only in client-side or server-side code; never expose it in public repos.
Usage
Init (recommended)
Call init() on app startup to fetch all flags once and cache them for 60 seconds. Later isEnabled / getValue use the cache (no extra request per flag).
import { IndieFlags } from "indie-flags";
const flags = new IndieFlags({
apiKey: "if_pub_xxxxxxxx",
// baseUrl: "https://your-api.com", // optional, for self-hosted
// email: "[email protected]", // optional, for flag overrides
});
await flags.init();
if (await flags.isEnabled("new-checkout")) {
// show new checkout
} else {
// show old checkout
}
const theme = await flags.getValue("theme"); // "dark" | "light" | "system" (string flag)Without init
You can skip init() and call isEnabled(flagKey) or getValue(flagKey) directly. Each call will request that flag from the API (no cache unless you set cacheTtlMs and call init() yourself).
const flags = new IndieFlags({ apiKey: "if_pub_xxxxxxxx" });
const enabled = await flags.isEnabled("new-feature");
const value = await flags.getValue("ab-test-variant"); // boolean or stringOptions
| Option | Type | Description |
| ------------ | ------ | ---------------------------------------------------------- |
| apiKey | string | Required. Project API key (client key from dashboard). |
| baseUrl | string | API base URL. Default https://api.indieflags.dev. |
| email | string | User email for flag overrides (targeting). |
| cacheTtlMs | number | Cache TTL after init(). Default 60000. Set 0 to disable. |
Methods
init(): Promise<Record<string, boolean \| string>>— Fetch all flags and cache them. Call once at startup.isEnabled(flagKey: string): Promise<boolean>— Whether the flag is on.getValue(flagKey: string): Promise<boolean \| string>— Flag value (boolean or string for enums).invalidateCache(): void— Clear cache so the next call refetches.
API
The SDK uses the Indie Flags eval API:
GET /eval?apiKey=...&flag=...— single flag (used when not cached).GET /eval/flags?apiKey=...— all flags (used byinit()).
You can also call the API directly with fetch or curl; see the dashboard Try API for examples.
