class LaunchDarklyProvider
implements FlagProvider
Since 0.2.0

A FlagProvider backed by LaunchDarkly.

The synchronous/asynchronous bridge. LaunchDarkly's server SDK evaluates flags locally against a ruleset it streams into the process, but every evaluation method it exposes is asynchronous, so it cannot directly satisfy the committed synchronous IFeatureFlags.isEnabled. This provider bridges the two using the one synchronous read the SDK does offer: LDFlagsState.getFlagValue.

  • LaunchDarklyProvider.isEnabled answers from a per-context snapshot cache. On a cache miss — the first evaluation for a given userId — it returns the configured fallbackValue and schedules a background refill, so every subsequent call for that user is answered from real LaunchDarkly state. start() prewarms the anonymous context, and an SDK update event drops the whole cache.
  • LaunchDarklyProvider.isEnabledAsync has no such caveat: it awaits boolVariation directly and is always correct.

Choose the async method wherever a wrong answer on a cold context would matter.

Examples

Example 1

app.register(FeatureFlagsPlugin({
  provider: 'launchdarkly',
  options: { sdkKey: runtime.env.LD_SDK_KEY ?? '', fallbackValue: false },
}));

Constructors

LaunchDarklyProvider(
logger?: ILogger
)
Parameters

The provider configuration

optional
logger: ILogger

Optional logger for background-refill failures

Properties

readonly
type: "launchdarkly"

Provider type identifier.

Methods

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

Evaluates a flag against the cached snapshot for this context.

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

Evaluates a flag by awaiting LaunchDarkly directly.

Unlike LaunchDarklyProvider.isEnabled this has no cold-context caveat. It also refreshes the snapshot cache, so a later synchronous read for the same context is answered from real state.

start(): Promise<void>

Builds the client (unless one was injected), waits for its initial connection, subscribes to flag updates, and prewarms the anonymous snapshot.

A connection that does not complete within initTimeoutSeconds is logged and tolerated rather than thrown: a flag backend being briefly unreachable should leave the application serving with fallback values, not refuse to boot. The condition is reported through LaunchDarklyProvider.status.

Reports whether the client is connected.

stop(): Promise<void>

Closes the client and drops every cached snapshot.

Usage

import { LaunchDarklyProvider } from "feature-flags-plugin/src/index.ts";