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.isEnabledanswers from a per-context snapshot cache. On a cache miss — the first evaluation for a givenuserId— it returns the configuredfallbackValueand schedules a background refill, so every subsequent call for that user is answered from real LaunchDarkly state.start()prewarms the anonymous context, and an SDKupdateevent drops the whole cache.LaunchDarklyProvider.isEnabledAsynchas no such caveat: it awaitsboolVariationdirectly and is always correct.
Choose the async method wherever a wrong answer on a cold context would matter.
LaunchDarklyProvider(config: LaunchDarklyProviderConfig,logger?: ILogger)
config: LaunchDarklyProviderConfig
The provider configuration
type: "launchdarkly"
Provider type identifier.
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.