Constructs a FlagshipBinding instance.
Optionalsettings: FlagshipSettings
Resolved settings. Defaults to resolve('flagship'), so callers
normally construct this with no arguments at all.
The binding name this instance resolves.
The binding name as declared in wrangler.json.
Evaluates a boolean flag.
The Worker environment.
The flag key, as it is named in the Flagship app.
The value to use when the flag cannot be evaluated. Pass the deployed behaviour.
Optionalcontext: FlagshipEvaluationContext
Per-request attributes for targeting, merged over the configured context.
The evaluated value, or fallback.
PrivatecontextMerges a call's evaluation context over the configured one.
Optionalcontext: FlagshipEvaluationContext
Per-request attributes, if the caller supplied any.
The combined context, or undefined when neither side has one.
PrivateevaluateRuns an evaluation, answering with the fallback rather than raising.
The flag's value type.
The evaluated value, or fallback.
Reports whether this deployment can evaluate flags at all.
The Worker environment.
true when the binding is present.
Checks whether the binding is available on the given environment.
Use this to degrade gracefully when a binding is optional.
The Worker environment.
true when the binding is present.
Evaluates a numeric flag.
The Worker environment.
The flag key, as it is named in the Flagship app.
The value to use when the flag cannot be evaluated. Pass the deployed behaviour.
Optionalcontext: FlagshipEvaluationContext
Per-request attributes for targeting, merged over the configured context.
The evaluated value, or fallback.
Evaluates a structured flag.
The shape the flag carries.
The Worker environment.
The flag key, as it is named in the Flagship app.
The value to use when the flag cannot be evaluated. Pass the deployed behaviour.
Optionalcontext: FlagshipEvaluationContext
Per-request attributes for targeting, merged over the configured context.
The evaluated value, or fallback.
Resolves the binding, failing fast when it is not configured.
The Worker environment.
The resolved binding.
MissingBindingError When the binding is absent from the environment.
Evaluates a string flag.
The Worker environment.
The flag key, as it is named in the Flagship app.
The value to use when the flag cannot be evaluated. Pass the deployed behaviour.
Optionalcontext: FlagshipEvaluationContext
Per-request attributes for targeting, merged over the configured context.
The evaluated value, or fallback.
Resolves the binding without throwing.
The Worker environment.
The resolved binding, or null when it is not configured.
Accessor for a Flagship feature-flag binding.
Remarks
Flagship evaluates a flag at request time, so a value that is a
varsentry today — read once per deploy, changed only by deploying again — becomes something a targeting rule can move for a percentage of traffic, or for named callers first. That is the whole reason to reach for it: a rollback stops being a deploy.This one degrades instead of throwing, and that is the point
Every other accessor here answers a missing binding with a
MissingBindingError, because a Worker that lost its database cannot serve the request either way and should say so. A flag is the opposite. The value exists to decide between two paths that both work, so a Worker that cannot reach Flagship should take the path it would have taken before flags existed — not fail.So every method here takes a fallback and returns it when the binding is absent, when evaluation fails, or when the flag's type does not match. An evaluation error is logged and swallowed, the way AnalyticsBinding's
writeSafetreats a failed telemetry write: the caller asked a question that has a safe answer, and raising instead would make the flag service a new way for the Worker to be down.The corollary is that the fallback is not boilerplate. It is the deployed behaviour, and choosing it badly is how a flag outage becomes an incident — so pass the value the Worker used before the flag existed, which for the migration this package was written for means the
varsentry it replaces.resolve(env)is still inherited and still throws, for the rare caller that genuinely cannot proceed without a live evaluation.Why there is no
FlagshipServiceSame reason as WorkflowBinding: the kernel names no capability this could implement. Unlike durable execution, feature flagging is the strongest candidate in this package for one — it has many providers, and none of its vocabulary is Cloudflare's. When a second provider is actually in play, a
FeatureFlagsinterface belongs in@bayudwiyansatria/coreand this becomes its adapter. Declaring it now, against one implementation and no consumers, would be ceremony rather than abstraction.Example
Author
Bayu Dwiyan Satria
Version
1.0.0
Since
1.3.0