@bucketeer/openfeature-js-client-sdk

中文文档
0.0.6发布于 2026/05/26Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 5892

This is the official JS OpenFeature provider for accessing your feature flags with Bucketeer.

原始使用文档
文档目录11 节
  1. Table of Contents
  2. Web (JavaScript / TypeScript)
  3. Installation (Web)
  4. Usage (Web)
  5. React
  6. React Native
  7. Examples
  8. Contributing
  9. Development
  10. Environment
  11. License

Bucketeer - OpenFeature JS provider

This is the official JS OpenFeature provider for accessing your feature flags with Bucketeer.

Bucketeer is an open-source platform created by CyberAgent to help teams make better decisions, reduce deployment lead time and release risk through feature flags. Bucketeer offers advanced features like dark launches and staged rollouts that perform limited releases based on user attributes, devices, and other segments.

In conjunction with the OpenFeature SDK you will be able to evaluate your feature flags in your web, React, and React Native applications.

[!WARNING] This is a beta version. Breaking changes may be introduced before general release.

For documentation related to flags management in Bucketeer, refer to the Bucketeer documentation website.

Table of Contents


Web (JavaScript / TypeScript)

Installation (Web)

npm install @bucketeer/openfeature-js-client-sdk

[!NOTE] npm versions 7 and above will automatically install the required peer dependencies: @openfeature/web-sdk and @bucketeer/js-client-sdk. If you get an error about missing peer dependencies, please install them manually:

npm install @openfeature/core @openfeature/web-sdk @bucketeer/js-client-sdk

Usage (Web)

Configuration

Use defineBKTConfig to create your configuration.

import { defineBKTConfig } from '@bucketeer/openfeature-js-client-sdk';

const config = defineBKTConfig({
  apiEndpoint: 'BUCKETEER_API_ENDPOINT',
  apiKey: 'BUCKETEER_API_KEY',
  featureTag: 'FEATURE_TAG',
  appVersion: '1.2.3',
  fetch: window.fetch,
})

See our documentation for more SDK configuration.

Initialization

Initialize and set the Bucketeer provider to OpenFeature.

import { OpenFeature } from '@openfeature/web-sdk';
import { defineBKTConfig, BucketeerProvider } from '@bucketeer/openfeature-js-client-sdk';

const config = defineBKTConfig({
  apiEndpoint: 'BUCKETEER_API_ENDPOINT',
  apiKey: 'BUCKETEER_API_KEY',
  featureTag: 'FEATURE_TAG',
  appVersion: '1.2.3',
  fetch: window.fetch,
})

const initEvaluationContext = {
  targetingKey: 'USER_ID',
  app_version: '1.2.3',
}
await OpenFeature.setContext(initEvaluationContext)
const provider = new BucketeerProvider(config)
await OpenFeature.setProviderAndWait(provider)

Evaluate a feature flag

After the provider is set and the provider's status is ClientProviderEvents.Ready, you can evaluate a feature flag using the OpenFeature client.

const client = OpenFeature.getClient();

// boolean flag
const flagValueBool = client.getBooleanValue('my-feature-flag', false);

// string flag
const flagValueStr = client.getStringValue('my-feature-flag', 'default-value');

// number flag
const flagValueNum = client.getNumberValue('my-number-flag', 0);

// object flag
const flagValueObj = client.getObjectValue('my-object-flag', {});

More details can be found in the OpenFeature Web SDK documentation.

Update the Evaluation Context

The evaluation context allows the client to specify contextual data that Bucketeer uses to evaluate feature flags. The targetingKey is the user ID (Unique ID) and cannot be empty.

You can update the evaluation context with the new attributes if the user attributes change.

const newEvaluationContext = {
  targetingKey: 'USER_ID',
  app_version: '2.0.0',
  age: 25,
  country: 'US',
}
await OpenFeature.setContext(newEvaluationContext)

[!WARNING] Changing the targetingKey is not supported in the current implementation of the BucketeerProvider.

To change the user ID, the BucketeerProvider must be removed and reinitialized.

await OpenFeature.clearProviders()
await OpenFeature.clearContext()

// Reinitialize the provider with new targetingKey
const newEvaluationContext = {
  targetingKey: 'USER_ID_NEW',
  app_version: '2.0.0',
  age: 25,
  country: 'US',
}

const config = defineBKTConfig({
  apiEndpoint: 'BUCKETEER_API_ENDPOINT',
  apiKey: 'BUCKETEER_API_KEY',
  featureTag: 'FEATURE_TAG',
  appVersion: '1.2.3',
  fetch: window.fetch,
})

await OpenFeature.setContext(newEvaluationContext)
const provider = new BucketeerProvider(config)
await OpenFeature.setProviderAndWait(provider)

React

For React instructions, please see our React documentation.


React Native

For React Native instructions, please see our React Native documentation.


Examples

We provide several examples to help you get started with the Bucketeer OpenFeature provider:

Each example contains a README with instructions on how to run it.


Contributing

We would ❤️ for you to contribute to Bucketeer and help improve it! Anyone can use and enjoy it!

Please follow our contribution guide here.

Development

Environment

  • pnpm
    • enable it via corepack enable
  • Node.js
    • check ./.node-version

You need .env file to provide api secrets. Just copy env.template and rename it to .env, then update it with your secrets.

License

Apache License 2.0, see LICENSE.

版本与发布记录

@bucketeer/openfeature-js-client-sdk 共发布 7 个版本,首次发布于 2025/06/17;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.6latest2026/05/265 个月前
0.0.42025/12/2410 个月前
0.0.4-1765959947-0f6fc7dnext2025/12/1710 个月前
0.0.4-1765958283-343eb492025/12/1710 个月前
0.0.32025/11/1911 个月前
0.0.22025/11/1811 个月前

关于 @bucketeer/openfeature-js-client-sdk 的常见问题

@bucketeer/openfeature-js-client-sdk 是什么?

This is the official JS OpenFeature provider for accessing your feature flags with Bucketeer.

如何安装 @bucketeer/openfeature-js-client-sdk?

在项目目录运行 npm install @bucketeer/openfeature-js-client-sdk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@openfeature/web-sdk(>=1.4.0 <2.0.0)、@bucketeer/js-client-sdk(>=2.6.1 <3.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bucketeer/openfeature-js-client-sdk 支持 TypeScript 吗?

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

@bucketeer/openfeature-js-client-sdk 支持 ESM 还是 CommonJS?

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

@bucketeer/openfeature-js-client-sdk 可以商用吗?

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

@bucketeer/openfeature-js-client-sdk 的下载量有多少?

根据 npm 官方下载统计,@bucketeer/openfeature-js-client-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 5,892 次,日均约 196 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bucketeer/openfeature-js-client-sdk 还在维护吗?

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