Skip to main content
The JavaScript SDK is a framework-agnostic client for browsers and other JavaScript runtimes. It loads your configuration, evaluates flags locally, and stays subscribed for real-time updates.

Install

npm install @softlaunch/js

Initialize

Create a client with a client key (slc_). init returns immediately and starts loading in the background.
import { init } from "@softlaunch/js";

const client = init({ sdkKey: "slc_..." });
Flag reads work right away, returning your default value until the configuration is ready. To wait for the first load, await waitUntilReady:
await client.waitUntilReady();

Read a flag

Each flag type has a method. Pass the flag key, a subject key, attributes, and a default value.
const showRedesign = client.getBooleanFlag(
  "checkout-redesign",
  "user-123",
  { plan: "pro" },
  false,
);
Available methods:
  • getBooleanFlag(flagKey, subjectKey, attributes, defaultValue)
  • getStringFlag(flagKey, subjectKey, attributes, defaultValue)
  • getIntegerFlag(flagKey, subjectKey, attributes, defaultValue)
  • getNumericFlag(flagKey, subjectKey, attributes, defaultValue)
  • getJsonFlag<T>(flagKey, subjectKey, attributes, defaultValue)

React to changes

The client stays subscribed after the first load. Use subscribe to run code whenever flag values may have changed — re-read the flags you care about inside the listener.
const unsubscribe = client.subscribe(() => {
  render(client.getBooleanFlag("checkout-redesign", "user-123", { plan: "pro" }, false));
});

// Later, stop listening:
unsubscribe();

Check status

getStatus reports the current load state as a discriminated union:
const status = client.getStatus();
// { state: "initializing" }
// { state: "ready" }
// { state: "error", error: string }

Clean up

Call close to tear down the subscription and release resources when the client is no longer needed.
client.close();
Reads always return a value — your default until the configuration loads, and the resolved variation once it’s ready. You never need to guard a read against an unready client.