Shipeasy
ReferenceTypeScript / JavaScript

Feature flags (`getFlag`)

A flag (a.k.a. a gate) evaluates to a boolean for a given user.

Generated from the SDK's own /docs/ — also served raw at https://shipeasy-ai.github.io/sdk/pages/flags.md.

A flag (a.k.a. a gate) evaluates to a boolean for a given user.

Read a flag

Configure once at startup, then bind the user and read:

import { configure, Client } from "@shipeasy/sdk/server"; // or /client

configure({ apiKey: process.env.SHIPEASY_SERVER_KEY! });

const flags = new Client(req.user); // construct once per callsite
if (flags.getFlag("new_checkout")) {
  /* ship it */
}

Browser is identical, swapping the entrypoint + key:

import { configure, Client } from "@shipeasy/sdk/client";

configure({ clientKey: process.env.NEXT_PUBLIC_SHIPEASY_CLIENT_KEY! });
const flags = new Client(currentUser);
await flags.ready();
flags.getFlag("new_checkout"); // boolean

Default / fallback behaviour

getFlag takes a caller-supplied default returned only when the value can't be evaluated — the client isn't initialized yet, or the key isn't in the loaded rules. A flag that legitimately evaluates to false (disabled, rule denied, rolled out to 0%) still returns false, never the default.

const flags = new Client(req.user); // construct once per callsite

flags.getFlag("new_checkout"); // false for a missing/disabled flag
flags.getFlag("new_checkout", true); // true ONLY if not-ready / not-found

Evaluation detail — getFlagDetail

getFlagDetail returns { value, reason } (LaunchDarkly variationDetail parity) so you can see why a flag resolved:

import type { FlagReason } from "@shipeasy/sdk/server"; // or /client

const d = flags.getFlagDetail("new_checkout"); // bound Client
// → { value: true, reason: "RULE_MATCH" }
FlagReasonmeaning
CLIENT_NOT_READYno rules loaded yet (init() / identify() pending)
FLAG_NOT_FOUNDthe gate name isn't in the loaded rules
OFFthe gate exists but is disabled / killed (server only)
OVERRIDEa local override (or ?se_gate_… URL override) decided it
RULE_MATCHthe gate evaluated true
DEFAULTthe gate evaluated false

getFlag is implemented on top of getFlagDetail (single evaluation, single telemetry beacon). On the browser the server pre-evaluates enabled/killed state, so OFF folds into DEFAULT there.

Was this page helpful?
✎ Edit this page

On this page