interface IFeatureFlags
Since 0.1.0

Feature flag evaluator. Evaluation is synchronous against the provider's cached state; providers refresh their state out of band.

Examples

Example 1

const flags = ctx.services.get<IFeatureFlags>(CAPABILITIES.FEATURE_FLAGS);
if (flags.isEnabled('new-dashboard', { userId: user.id })) {
  return renderNewDashboard();
}

Methods

isEnabled(
flag: string,
context?: FlagContext
): boolean

Evaluates a flag.

Since 0.2.0
optional
isEnabledAsync(
flag: string,
context?: FlagContext
): Promise<boolean>

Evaluates a flag, awaiting the backing provider when it can produce a more accurate answer asynchronously.

Optional, and additive: a provider with a purely local snapshot (config, memory, database polling) has nothing to await, so its implementation simply resolves IFeatureFlags.isEnabled. The method exists for providers whose SDK evaluates asynchronously — LaunchDarkly's server SDK being the motivating case — where the synchronous path must answer from a cached snapshot and therefore returns a configured fallback the first time it sees a given context.

Prefer this method wherever a wrong answer on a cold context would matter (billing, entitlement, an irreversible action); prefer IFeatureFlags.isEnabled on hot paths that cannot await.

Usage

import { type IFeatureFlags } from "common/src/index.ts";