@flaghoist/provider-web

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

OpenFeature web SDK provider for Flaghoist — a pre-wired OFREP provider for browser/client apps.

原始使用文档

@flaghoist/provider-web

An OpenFeature provider for browser apps, pointed at a Flaghoist server.

It is the official OFREP web provider with the wiring already done: your server URL, and the read API key attached as the x-api-key header on every request.

npm install @flaghoist/provider-web @openfeature/web-sdk
import { OpenFeature } from '@openfeature/web-sdk'
import { FlaghoistWebProvider } from '@flaghoist/provider-web'

await OpenFeature.setProviderAndWait(
  new FlaghoistWebProvider({
    url: 'https://team-flags.example.workers.dev',
    apiKey: import.meta.env.VITE_FLAGS_KEY,
  }),
)

const client = OpenFeature.getClient()
client.getBooleanValue('new-checkout', false)

Using Vue? @flaghoist/vue wraps this with a useFeatureFlag() composable.

Options

Every option of the official OFREP web provider passes through unchanged, with the same defaults. Two are worth deciding on deliberately.

Staying up to date. The provider fetches every flag in one request when it starts, when the evaluation context changes, and when the tab becomes visible again. It does not poll by default, so a user who stays on one page will not see a toggle until one of those happens. Set pollInterval for live updates:

new FlaghoistWebProvider({
  url: 'https://team-flags.example.workers.dev',
  apiKey: import.meta.env.VITE_FLAGS_KEY,
  pollInterval: 30_000, // re-fetch every 30 seconds. Default 0 (off)
})

The server caches flag definitions for cacheTtlSeconds (30 by default), so polling much faster than that mostly fetches the same answer. changeDetection: 'none' turns all background refreshes off, and disableVisibilityRefresh: true stops the refresh on tab focus.

What an outage looks like. By default (cacheMode: 'local-cache-first') the provider saves the last flags it saw in localStorage for up to 30 days (cacheTTL, in seconds). It starts from them instantly, and if the server is unreachable, users keep the last known values. That differs from @flaghoist/provider-node, which returns the defaults in your code when the server is down. Choose what fits:

cacheModeOn startupServer unreachable
'local-cache-first' (default)Saved flags, refresh behindLast known values
'network-first'Waits for the serverLast known values
'disabled'Waits for the serverYour code defaults

A rejected key (401, 403) or bad request (400) is never hidden behind saved flags, in any mode.

timeoutMs, headersFactory, query, fetchImplementation, cacheKeyGenerator and the SSE settings are also accepted; see the upstream README for each.

Because it is a standard OFREP provider, nothing here is Flaghoist specific on the wire. If you later move to another OFREP backend, your app code does not change.

Use the read only API key. Anything you put here is visible to anyone who opens devtools.

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/provider-web 共发布 5 个版本,首次发布于 2026/08/22;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.2.1latest2026/10/3115 天前
0.2.02026/10/2620 天前
0.1.22026/08/242 个月前
0.1.12026/08/222 个月前
0.1.02026/08/222 个月前

关于 @flaghoist/provider-web 的常见问题

@flaghoist/provider-web 是什么?

OpenFeature web SDK provider for Flaghoist — a pre-wired OFREP provider for browser/client apps.

如何安装 @flaghoist/provider-web?

在项目目录运行 npm install @flaghoist/provider-web,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@openfeature/web-sdk(^1.10.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flaghoist/provider-web 支持 TypeScript 吗?

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

@flaghoist/provider-web 支持 ESM 还是 CommonJS?

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

@flaghoist/provider-web 需要什么版本的 Node.js?

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

@flaghoist/provider-web 可以商用吗?

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

@flaghoist/provider-web 的下载量有多少?

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

@flaghoist/provider-web 还在维护吗?

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