@flaghoist/adapter-cloudflare-kv

中文文档
0.3.1发布于 2026/10/31Apache-2.0TypeScriptESM + CJS近 30 天下载 8193

Cloudflare Workers KV StorageAdapter for Flaghoist — the default storage backend.

原始使用文档

@flaghoist/adapter-cloudflare-kv

Store Flaghoist flags in Cloudflare Workers KV. This is the default storage for a Flaghoist deploy, and the one the CLI picks unless you tell it otherwise.

npm install @flaghoist/adapter-cloudflare-kv
import { cloudflareKV } from '@flaghoist/adapter-cloudflare-kv'
import { createFlagServer } from '@flaghoist/server'

export default createFlagServer((env) => ({
  storage: cloudflareKV(env.FLAGS),
  auth: {/* ... */},
}))

FLAGS is a KV namespace binding in your wrangler.toml. If you are using the CLI, flaghoist deploy creates the namespace and fills in its id for you. By hand it is:

npx wrangler kv namespace create FLAGS

Sharing a namespace

By default Flaghoist writes each flag under its own key, so a flag called checkout is stored as checkout. That keeps the namespace readable when you browse it in the Cloudflare dashboard.

If the namespace holds anything besides Flaghoist's flags, give it a prefix:

cloudflareKV(env.FLAGS, { prefix: 'flag:' })

Without one, list() reads every key in the namespace. Values that are not flags are skipped rather than showing up as broken rows, so nothing breaks, but you pay a read for each one.

Changing the prefix on a running deployment hides the flags written under the old one. They are still in KV, the adapter is just no longer looking there.

Webhook endpoints (if you use them) live in the same namespace, under a separate webhook: prefix by default. Change it with { webhookPrefix: '...' }.

Worth knowing: KV is eventually consistent. A flag you just changed can take a few seconds to reach every edge location, which is fine for flags and would not be fine for a bank balance.

Storage is an interface, so moving to Redis or Postgres later is a one line change in your server config.

Status

Beta. The core is feature-complete and ready for real projects. The API can still change before 1.0, and every breaking change is called out in the changelog, so pin your versions and read the notes when you upgrade. If something breaks, an issue is genuinely useful.

Apache-2.0. Part of Flaghoist.

版本与发布记录

@flaghoist/adapter-cloudflare-kv 共发布 6 个版本,首次发布于 2026/08/22;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.3.1latest2026/10/3115 天前
0.3.02026/09/271 个月前
0.2.12026/08/252 个月前
0.2.02026/08/252 个月前
0.1.12026/08/222 个月前
0.1.02026/08/222 个月前

关于 @flaghoist/adapter-cloudflare-kv 的常见问题

@flaghoist/adapter-cloudflare-kv 是什么?

Cloudflare Workers KV StorageAdapter for Flaghoist — the default storage backend.

如何安装 @flaghoist/adapter-cloudflare-kv?

在项目目录运行 npm install @flaghoist/adapter-cloudflare-kv,或使用 pnpm add / yarn add / bun add。

@flaghoist/adapter-cloudflare-kv 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flaghoist/adapter-cloudflare-kv 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flaghoist/adapter-cloudflare-kv 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@flaghoist/adapter-cloudflare-kv 可以商用吗?

@flaghoist/adapter-cloudflare-kv 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@flaghoist/adapter-cloudflare-kv 的下载量有多少?

根据 npm 官方下载统计,@flaghoist/adapter-cloudflare-kv 在 2026/10/15 – 2026/11/13 这 30 天内被下载 8,193 次,日均约 273 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flaghoist/adapter-cloudflare-kv 还在维护吗?

最新版本 0.3.1 发布于 2026/10/31(15 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/08/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。