The flipt-client-browser
library contains the JavaScript/TypeScript source code for the Flipt client-side evaluation client for the browser.
npm install @flipt-io/flipt-client-browser
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.
// engine_opts is the second positional argument and is also optional, the structure is:
// {
// "url": "http://localhost:8080",
// "authentication": {
// "client_token": "secret"
// }
// }
//
const fliptEvaluationClient = await FliptEvaluationClient.init('default', {
url: 'http://localhost:8080',
authentication: {
client_token
}
});
const variant = fliptEvaluationClient.evaluateVariant('flag1', 'someentity', {
fizz: 'buzz'
});
console.log(variant);
The FliptEvaluationClient
class pulls flag state from the Flipt instance at the url
provided in the engine_opts
object on instantiation.
To update the flag state, you can call the refresh
method on the FliptEvaluationClient
class.
// Refresh the flag state
fliptEvaluationClient.refresh();
This allows you to update the flag state in a controlled manner, such as in a polling loop or when a user interacts with your application.
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.
npm run build
npm install
npm test