Feature flags & experiments
Code-defined flags (Pennant-style): a constant, a predicate over the context, or a deterministic, sticky percentage() rollout — the same user always gets the same answer. No server needed; remote falls through to the Rust engine for keys you don't define locally.
Tip
Try different names: “alice” and “bob” get the beta banner; ~30% of users get the new checkout, ~50% priority support — and it's stable per user (reload, it won't flip). Variant assignment is sticky too.
Enter a user id to evaluate its flags.
import { defineFlags, percentage, forUsers } from "@bext-stack/framework/flags";
const flags = defineFlags({
flags: {
"new-checkout": percentage(30), // sticky 30% rollout
"beta-banner": forUsers("alice", "bob"),
"holiday": (ctx) => ctx.attributes?.country === "FR",
},
remote: { appId: "my-site" }, // optional: fall through to the Rust engine
});
if (await flags.isEnabled("new-checkout", { userId: user.id })) { /* … */ }
// deterministic, sticky A/B/n assignment:
const arm = flags.variant("home-hero", ["control", "b", "c"], { userId: user.id });