feat(worker): add Flagship binding#979
Open
connyay wants to merge 10 commits intocloudflare:mainfrom
Open
Conversation
Adds first-class support for the Flagship feature-flag binding announced
on 2026-04-17. Users can now evaluate flags via `env.flagship("FLAGS")`
with a fluent `EvaluationContext` builder and typed `EvaluationDetails<T>`
responses.
- worker-sys: raw wasm_bindgen externs for all 9 Flagship JS methods
- worker: Flagship wrapper, EvaluationContext builder, EvaluationDetails<T>
- test: mini-flagship miniflare mock + 10 handlers + 16 vitest specs
- examples/flagship: runnable worker demoing value/details/context usage
Contributor
Author
|
@guybedford I took an initial swing at ts-gen for flagship. Mostly worked, but a few maybe controversial things: (resolved) - promise values that returned primitives had pretty bad ergonomics:1. promise values that returned primitives had pretty bad ergonomics: ```rust let value = env .flagship(BINDING)? .get_string_value(&flag, "fallback") .await? .as_string() .unwrap_or("fallback") ``` ~Tried this https://github.com/wasm-bindgen/ts-gen/pull/11 which improved consumer ergonomics at the cost of generation complexity and ugliness. let me know what you think.~EDIT: less bad version wasm-bindgen/ts-gen#14 not too bad: let value: bool = env
.flagship(BINDING)?
.get_boolean_value(&flag, false)
.await?
.value_of();let value = String::from(
env.flagship(BINDING)?
.get_string_value(&flag, "fallback")
.await?,
);
pub async fn handle_object(req: Request, env: Env, _data: SomeSharedData) -> Result<Response> {
let flag = last_segment(&req)?;
let default = serde_wasm_bindgen::to_value(&default_theme())?;
let raw = env
.flagship(BINDING)?
.get_object_value(&flag, &default)
.await?;
let value: Theme = serde_wasm_bindgen::from_value(raw)?;
Response::from_json(&serde_json::json!({ "flag": flag, "value": value }))
}yuck. fix for this was to comment out the type for generation and handroll. open to ideas to improve this. hit similar stuff in workflows as we've discussed before #918 (comment)
|
Collaborator
|
Thanks for working through the concerns here! This gives a lot of interesting feedback to think about - I will look into this next week and see if I can come up with some further suggestions as well. |
connyay
commented
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds first-class support for the Flagship feature-flag binding announced on 2026-04-17. Users can now evaluate flags via
env.flagship("FLAGS")with a fluentEvaluationContextbuilder and typedEvaluationDetails<T>responses.