flagship

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Cloudflare Flagship

Cloudflare Flagship

Flagship is Cloudflare's feature flag service: apps group flags, flags have typed variants and ordered targeting rules, and evaluation runs at the edge against propagated configuration. Your knowledge of the Flagship API may be outdated or missing. Prefer retrieval over pre-training: read the matching page below before writing code or commands, and treat the docs and generated types as the source of truth over this skill.
Flagship 是 Cloudflare 的 feature flag 服务:应用用于对 flags 进行分组,flags 包含带类型的 variants 和有序的 targeting rules,评估则依据已传播的配置在 edge 运行。你对 Flagship API 的了解可能已经过时或不完整。优先检索而非依赖预训练知识:编写代码或命令前,先阅读下方对应页面,并将文档和生成的类型视为事实来源,而不是本 skill。

Documentation

文档

TaskDocsCheck for
Understand the modelConceptsApps, flags, variant types, rule order, evaluation context, propagation
Evaluate flags in a WorkerGet started, Configuration, Binding methods, TypesBinding config, typed and
*Details
methods, context value types
Evaluate outside Workers or through OpenFeatureOpenFeature SDK, TypeScript server, TypeScript client, Python, Go, RustPackage names, provider options, caching, minimum versions for structured context
Evaluate over HTTP without an SDKEvaluation API
GET
for scalar context,
POST
for structured context, token permissions
Target users or roll out graduallyTargeting rules, Operators, Percentage rolloutsRule shape, nested attribute paths, bucketing attribute, cumulative A/B thresholds
Manage flags from the CLIWrangler commands
--rule
syntax,
rollout
,
split
,
enable
/
disable
,
--local
,
--json
Manage flags over HTTPAPI referenceApps, flags, and flag changelog endpoints; rules live on the flag object. Update flag is a
PUT
that clears omitted fields, so read the flag before writing
Create tokens for SDKs or automationAPI tokensAccount-wide vs app-scoped tokens, Evaluate vs Read vs Write
Debug unexpected valuesEvaluation reasons and error codes
reason
and
errorCode
values
Plan rollouts and cleanupBest practices, LimitsRollout steps, flag removal order, key and context limits
For the full page list, read Flagship llms.txt. After adding a binding, run
npx wrangler types
and read the
Flagship
declarations in the generated
worker-configuration.d.ts
; they match the installed Wrangler version.
任务文档检查项
了解模型概念应用、flags、variant 类型、规则顺序、evaluation context、传播
在 Worker 中评估 flags快速入门、配置、Binding 方法、类型Binding 配置、类型化方法和
*Details
方法、context value 类型
在 Workers 之外或通过 OpenFeature 进行评估OpenFeature SDK、TypeScript server、TypeScript client、Python、Go、Rust包名、provider 选项、缓存、支持结构化 context 的最低版本
不使用 SDK,通过 HTTP 进行评估Evaluation API标量 context 使用
GET
,结构化 context 使用
POST
,token 权限
定向用户或渐进式发布Targeting rules、Operators、Percentage rollouts规则结构、嵌套属性路径、bucketing 属性、累积式 A/B 阈值
通过 CLI 管理 flagsWrangler commands
--rule
语法、
rollout
、
split
、
enable
/
disable
、
--local
、
--json
通过 HTTP 管理 flagsAPI reference应用、flags 和 flag changelog endpoints;rules 存储在 flag 对象中。Update flag 是
PUT
,会清除省略的字段,因此写入前先读取 flag
为 SDKs 或自动化创建 tokensAPI tokens账户级与 app 级 tokens、Evaluate、Read 和 Write 权限
调试异常值Evaluation reasons and error codes
reason
和
errorCode
值
规划 rollout 和清理最佳实践、限制Rollout 步骤、flag 删除顺序、key 和 context 限制
如需完整的页面列表,请阅读 Flagship llms.txt。添加 binding 后,运行
npx wrangler types
并阅读生成的
worker-configuration.d.ts
中的
Flagship
声明;它们与已安装的 Wrangler 版本匹配。

Gotchas

常见陷阱

These follow from the pages above and are the usual causes of flags that look broken but are working as documented.
  • Use the binding inside Workers. It authenticates automatically and needs no API token. Outside Workers, use an OpenFeature provider with an Evaluate token; local evaluation in any server SDK needs a Read token instead. Only the TypeScript server provider accepts the binding: in a Worker that wants OpenFeature APIs, pass the binding to
    FlagshipServerProvider
    . Do not ship the TypeScript client provider in public-facing apps: it requires an API token that would be visible in client code.
  • Known evaluation failures return your default silently. The typed binding methods return
    defaultValue
    for known failures such as a missing flag, type mismatch, or invalid context. Unexpected runtime failures can still throw, and
    get()
    without a
    defaultValue
    throws on known failures. Other clients differ: the Rust SDK returns a
    Result
    , and the evaluation API
    POST
    returns
    400
    for invalid context. Pick a default that is the safe, existing behavior, and use the matching
    *Details
    method to see
    reason
    and
    errorCode
    when a value looks wrong.
  • Local development starts with an empty flag store.
    wrangler dev
    , the Vite plugin, the Vitest integration, and
    cf dev
    evaluate against a local store, so every flag returns its default until you seed it. Run
    npx wrangler flagship flags pull <APP_ID>
    , create flags with
    --local
    , or set
    "remote": true
    on the binding.
    pull
    overwrites local flags with matching keys and writes to
    .wrangler/state
    , which
    wrangler dev
    and the Vite plugin 1.x use.
    cf dev
    and the Vite plugin 2.0 use
    .cloudflare/state
    , so for them pass
    --persist-to .cloudflare/state
    to
    pull
    , or every flag still returns its default.
    cf
    cannot copy flags from the remote app, so seed it with
    wrangler flagship flags pull
    . On flag commands other than
    pull
    ,
    --persist-to
    requires
    --local
    . Check Configuration for the minimum tool versions.
  • Rollouts need a stable bucketing value. The bucketing attribute defaults to
    targetingKey
    . If it is missing or
    null
    , each evaluation gets a random bucket, so the same user can flip between values. Pass the same stable identifier under the same attribute name on every call, and use
    targetingKey
    with OpenFeature SDKs.
  • Rules are ordered and rollout misses fall through. The first matching rule wins. A context that matches a rule's conditions but falls outside its rollout percentage continues to the next rule. Put specific rules before broad ones, and use cumulative thresholds that end at 100 for API-managed A/B/n splits, or
    wrangler flagship flags split
    , which calculates them.
  • Changes take up to 30 seconds to propagate. Do not expect the next evaluation to reflect an update immediately; for scripted checks, allow for the propagation window.
  • flags update --rule
    ,
    rollout
    , and
    split
    replace every rule.
    rollout
    and
    split
    overwrite the flag's entire rule set with the rules they generate, and prompt first only when existing rules have conditions;
    --force
    skips the prompt. Use
    --add-rule
    to append, or
    rules update
    and
    rules delete
    to change one rule by priority. Wrangler commands take the app ID as an argument and do not read it from the Worker binding.
  • Keep context small and JSON-only. Send only attributes that rules or bucketing use, and no sensitive data. Serialize
    Date
    values to ISO 8601 strings for the binding in TypeScript. A condition whose attribute is absent from the context never matches, including with negative operators such as
    not_equals
    . Evaluate a flag once per request and reuse the value instead of calling it in a loop.
  • Disabling a flag is the kill switch. A disabled flag always serves its default variant, regardless of targeting rules.
  • Delete flags last. Disable the flag, watch for problems, remove the evaluation code, deploy, then delete the flag. A deleted flag that is still evaluated silently returns its default.
以下内容源自上述页面,也是 flags 看起来失效但实际上按文档正常工作的常见原因。
  • 在 Workers 内部使用 binding。 它会自动进行身份验证,无需 API token。在 Workers 之外,使用带 Evaluate token 的 OpenFeature provider;任何 server SDK 中的本地评估都需要 Read token。只有 TypeScript server provider 支持 binding:在希望使用 OpenFeature APIs 的 Worker 中,将 binding 传给
    FlagshipServerProvider
    。不要在面向公众的应用中部署 TypeScript client provider:它需要 API token,而该 token 会在客户端代码中暴露。
  • 已知评估失败会静默返回默认值。 类型化 binding 方法在遇到已知失败(例如 flag 不存在、类型不匹配或 context 无效)时返回
    defaultValue
    。意外运行时故障仍可能抛出异常,而不带
    defaultValue
    的
    get()
    在已知失败时会抛出异常。其他客户端的行为有所不同:Rust SDK 返回
    Result
    ,Evaluation API 的
    POST
    在 context 无效时返回
    400
    。请选择安全且符合现有行为的默认值,并在值看起来不正确时使用相应的
    *Details
    方法查看
    reason
    和
    errorCode
    。
  • 本地开发以空 flag store 开始。
    wrangler dev
    、Vite plugin、Vitest integration 和
    cf dev
    都针对本地 store 进行评估,因此在完成初始化前,每个 flag 都会返回默认值。运行
    npx wrangler flagship flags pull <APP_ID>
    ,使用
    --local
    创建 flags,或在 binding 上设置
    "remote": true
    。
    pull
    会使用键匹配的 flags 覆盖本地 flags,并写入
    .wrangler/state
    ;
    wrangler dev
    和 Vite plugin 1.x 使用该目录。
    cf dev
    和 Vite plugin 2.0 使用
    .cloudflare/state
    ,因此应对
    pull
    传入
    --persist-to .cloudflare/state
    ,否则每个 flag 仍会返回默认值。
    cf
    无法从远程应用复制 flags,因此需要使用
    wrangler flagship flags pull
    为其初始化。在
    pull
    以外的 flag 命令中,
    --persist-to
    必须与
    --local
    一起使用。请查看配置以了解工具的最低版本。
  • Rollout 需要稳定的 bucketing 值。 Bucketing 属性默认为
    targetingKey
    。如果该属性缺失或为
    null
    ,每次评估都会进入随机 bucket,因此同一用户可能在不同值之间切换。每次调用时,都应在同一属性名下传入相同的稳定标识符;使用 OpenFeature SDKs 时则使用
    targetingKey
    。
  • Rules 有序,且 rollout 未命中时会继续向下匹配。 第一条匹配的 rule 获胜。某个 context 符合 rule 的条件但超出其 rollout 百分比时,会继续匹配下一条 rule。将具体规则放在宽泛规则之前;对于通过 API 管理的 A/B/n 分流,使用最终达到 100 的累积阈值,或使用
    wrangler flagship flags split
    ,它会自动计算这些阈值。
  • 更改最多需要 30 秒传播。 不要期望下一次评估立即反映更新;对于脚本检查,应预留传播窗口。
  • flags update --rule
    、
    rollout
    和
    split
    会替换所有 rules。
    rollout
    和
    split
    会用其生成的 rules 覆盖 flag 的整个 rule 集合,并且仅当现有 rules 带有条件时才先提示确认;
    --force
    可跳过提示。使用
    --add-rule
    追加 rule,或使用
    rules update
    和
    rules delete
    按优先级修改单个 rule。Wrangler 命令将 app ID 作为参数传入,不会从 Worker binding 读取它。
  • 保持 context 小巧且仅限 JSON。 仅发送 rules 或 bucketing 使用的属性,不要发送敏感数据。在 TypeScript 中将
    Date
    值序列化为 ISO 8601 字符串,供 binding 使用。如果某个条件的属性未出现在 context 中,则永远不会匹配,包括使用
    not_equals
    等负向运算符时。每个请求只评估 flag 一次并复用结果,不要在循环中反复调用。
  • 禁用 flag 就是 kill switch。 被禁用的 flag 无论 targeting rules 如何,始终返回其默认 variant。
  • 最后删除 flags。 先禁用 flag,观察问题,移除评估代码,部署,然后再删除 flag。已删除但仍被评估的 flag 会静默返回默认值。

Skill feedback

Skill 反馈

If the user reports that this skill gave incorrect or outdated guidance, or is missing information, read references/skill-feedback.md.
如果用户反馈此 skill 给出了不正确或过时的指导,或者信息缺失,请阅读 references/skill-feedback.md。