Star
SDKs

Client SDK

One client for browsers, React Native, Deno, Bun and edge runtimes. It holds the values for one user and updates them live. The rules never leave your server.

npm i featurekit-client
import { FeaturekitClient } from "featurekit-client";

      export const flags = new FeaturekitClient({
        clientKey: "fk_clt_…",                  // public: safe to ship
        baseUrl: "https://flags.acme.com",
        context: { key: user.id, plan: user.plan },
        stream: true,
      });

      await flags.ready();

      flags.get("new-checkout", false);           // synchronous, no context argument
      flags.on("change", () => render());        // pushed, no polling

Only flags created with clientAvailable: true reach the client. The rest aren't filtered out; they're never named, so an unreleased feature's existence stays private.

One instance, one user

The server SDK takes a context per call. This one holds a single context, because there's one user in front of a screen. Build it once, at module scope, and share it.

await flags.identify({ key: newUser.id, plan: newUser.plan });   // the one async call

When the key changes, the previous user's values are dropped before the request goes out: until the answer arrives, get() returns your defaults, never the last user's flags. Changing only attributes on the same key keeps serving the old values until the new ones land.

Not for a backend serving many users

On a server handling requests for many users, one shared client would answer user B with user A's values. Use the server SDK there: it evaluates any context in memory.

Responses apply in call order

Two quick identify() calls can answer out of order. The client numbers each request and drops any response older than the newest applied, or for a user it's no longer on. A superseded call's promise resolves rather than hanging. You don't have to do anything; it's why you build the client only once.

Live updates

With stream: true the client opens a server-sent events stream and receives only the flags whose value changed for this user. A targeted change reaches the few users it affects and nobody else. Without it, values are fetched on start and on each identify().

flags.on("change", (flagKeys) => console.log("changed:", flagKeys));
      flags.on("state", (state) => {});   // initializing | ready | identifying | offline

No flicker with server rendering

Inline the values your server evaluated, and the first paint uses them:

new FeaturekitClient({ clientKey, baseUrl, context, bootstrap: window.__FLAGS__ });

In production: sign the context

Production environments only accept contexts your backend signed, so nobody can read another user's flags with your public key. Pass contextSignature, contextSignatureExpiresAt and onSignatureExpiring. See secure mode.

React Native and Expo

The same package. React Native's built-in fetch can't stream, so the client falls back to re-fetching on a timer. Pass Expo's streaming fetch to get live updates:

import { fetch as expoFetch } from "expo/fetch";

      new FeaturekitClient({ ...options, clientKey: "fk_mob_…", fetchImpl: expoFetch as unknown as typeof fetch });

When things fail

Every failure ends at your default: a network error, a revoked key, an expired signature it can't refresh. get() never throws and never returns undefined. A value whose type doesn't match the default (a flag retyped while the client held the old value) also returns the default, so "false" never reaches your if.

Next