@flipt-io/flipt-client

中文文档
0.14.0发布于 2025/03/30MITTypeScriptCommonJS零依赖近 30 天下载 2779

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.

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

Flipt Client Node

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

flipt-client-node deprecated

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

Installation

npm install @flipt-io/flipt-client

Usage

In your Node.js code you can import this client and use it as so:

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

// 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",
//  "updateInterval": 120,
//  "authentication": {
//    "clientToken": "secret"
//  }
// }
//
// You can replace the url with where your upstream Flipt instance points to, the updateInterval for how long you are willing
// to wait for updated flag state, and the auth token if your Flipt instance requires it.
const fliptEvaluationClient = await FliptEvaluationClient.init('default', {
  url: 'http://localhost:8080',
  authentication: {
    clientToken: 'secret'
  }
});

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.
    • updateInterval: The interval (in seconds) in which to fetch new flag state. If not provided, the client will default to 120 seconds.
    • 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 Node.js'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](#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.

Timer Management

The FliptEvaluationClient class uses a timer to fetch new flag state at a regular interval.

Make sure to call the close method on the FliptEvaluationClient class once you are done using it to stop the timer and clean up resources.

fliptEvaluationClient.close();

State Management

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

This state is pulled from the Flipt instance on instantiation and every update_interval seconds thereafter.

To update the flag state manually, 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 overhead building and sending previously observed snapshots. 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 Node.js 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 共发布 26 个版本,首次发布于 2023/12/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.14.0latest2025/03/301.6 年前
0.13.02025/03/051.7 年前
0.12.02024/12/121.9 年前
0.11.02024/10/172 年前
0.10.12024/09/212 年前
0.10.02024/09/152 年前

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

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

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?

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

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

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

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

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

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

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

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

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

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

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