@flipt-io/flipt-client-browser

中文文档
0.6.0发布于 2025/03/30MITTypeScriptESM + CJS零依赖近 30 天下载 4.6万

DEPRECATED: This package has been superseded by @flipt-io/flipt-client-js. Please update your dependencies.

此软件包已被标记为弃用

This package has been superseded by @flipt-io/flipt-client-js. Please update your dependencies.

原始使用文档
文档目录15 节
  1. Installation
  2. Usage
  3. Initialization Arguments
  4. Authentication
  5. Error Strategies
  6. Custom Fetcher
  7. State Management
  8. ETag Support
  9. Development
  10. WASM
  11. Prerequisites
  12. Build
  13. Test
  14. Contributing
  15. License

Flipt Client Browser

[!WARNING] This SDK is deprecated and will not be maintained going forward. Please use the new Flipt Client JS SDK instead.

flipt-client-browser deprecated

The flipt-client-browser library contains the JavaScript/TypeScript source code for the Flipt client-side evaluation client for the browser.

Installation

npm install @flipt-io/flipt-client-browser

Usage

In your JavaScript/Typescript code you can import this client and use it as so:

import { FliptEvaluationClient } from '@flipt-io/flipt-client-browser';

// namespace is the first positional argument and is optional here and will have a value of "default" if not specified.
// options is the second positional argument and is also optional, the structure is:
// {
//  "url": "http://localhost:8080",
//  "authentication": {
//    "clientToken": "secret"
//  }
// }
//
const fliptEvaluationClient = await FliptEvaluationClient.init('default', {
  url: 'http://localhost:8080',
  authentication: {
    clientToken
  }
});

const variant = fliptEvaluationClient.evaluateVariant('flag1', 'someentity', {
  fizz: 'buzz'
});

console.log(variant);

Initialization Arguments

The FliptEvaluationClient constructor accepts two optional arguments:

  • namespace: The namespace to fetch flag state from. If not provided, the client will default to the default namespace.
  • options: An instance of the ClientOptions type that supports several options for the client. The structure is:
    • url: The URL of the upstream Flipt instance. If not provided, the client will default to http://localhost:8080.
    • authentication: The authentication strategy to use when communicating with the upstream Flipt instance. If not provided, the client will default to no authentication. See the Authentication section for more information.
    • reference: The reference to use when fetching flag state. If not provided, reference will not be used.
    • fetcher: An implementation of a fetcher interface to use when requesting flag state. If not provided, a default fetcher using the browser's fetch API will be used.
    • errorStrategy: The error strategy to use when fetching flag state. If not provided, the client will default to fail. See the Error Strategies section for more information.

Authentication

The FliptEvaluationClient supports the following authentication strategies:

Error Strategies

The client errorStrategy option supports the following error strategies:

  • fail: The client will throw an error if the flag state cannot be fetched. This is the default behavior.
  • fallback: The client will maintain the last known good state and use that state for evaluation in case of an error.

Custom Fetcher

The FliptEvaluationClient supports custom fetchers. This allows you to fetch flag state from a custom source or override HTTP headers.

The fetcher can be passed in as an argument to the FliptEvaluationClient initializer function.

const fliptEvaluationClient = await FliptEvaluationClient.init('default', {
  url: 'http://localhost:8080',
  authentication: {
    clientToken
  },
  fetcher: customFetcher
});

The fetcher is a function that takes an optional IFetcherOpts argument and returns a Promise that resolves to a Response object.

State Management

The FliptEvaluationClient class pulls flag state from the Flipt instance at the url provided in the options object on instantiation.

To update the flag state, you can call the refresh method on the FliptEvaluationClient class.

[!NOTE] The refresh method returns a boolean indicating whether the flag state changed.

// Refresh the flag state
let changed = await fliptEvaluationClient.refresh();

if (changed) {
  // Do something
}

ETag Support

The default fetcher uses ETag HTTP headers to reduce the number of requests to the Flipt instance. This is useful in scenarios where the flag state is not frequently updated and you want to reduce the load on the server.

To disable ETag support, you can implement a custom fetcher that does not use ETags.

Development

WASM

This library uses a WebAssembly (WASM) layer to interact with the Flipt server. It is written in Rust and exposes a JavaScript API using the wasm-bindgen and wasm-pack tools. We wrap the built WASM layer in a JavaScript API to make it easier to use in a browser environment.

Prerequisites

Build

npm run build

Test

npm install
npm test

Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request.

License

This project is licensed under the MIT License.

版本与发布记录

@flipt-io/flipt-client-browser 共发布 28 个版本,首次发布于 2024/04/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.0latest2025/03/301.6 年前
0.5.02025/03/051.7 年前
0.4.02024/12/131.9 年前
0.3.12024/10/172 年前
0.3.02024/10/102 年前
0.2.12024/09/212 年前

关于 @flipt-io/flipt-client-browser 的常见问题

@flipt-io/flipt-client-browser 是什么?

DEPRECATED: This package has been superseded by @flipt-io/flipt-client-js. Please update your dependencies.注意:该包已被作者标记为弃用——This package has been superseded by @flipt-io/flipt-client-js. Please update your dependencies.

如何安装 @flipt-io/flipt-client-browser?

在项目目录运行 npm install @flipt-io/flipt-client-browser,或使用 pnpm add / yarn add / bun add。

@flipt-io/flipt-client-browser 支持 TypeScript 吗?

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

@flipt-io/flipt-client-browser 支持 ESM 还是 CommonJS?

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

@flipt-io/flipt-client-browser 可以商用吗?

@flipt-io/flipt-client-browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flipt-io/flipt-client-browser 的下载量有多少?

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

@flipt-io/flipt-client-browser 还在维护吗?

最新版本 0.6.0 发布于 2025/03/30(1.6 年前);至今共发布 28 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/04/07。作者已将其标记为弃用,新项目建议寻找替代方案。