@flipt-io/flipt-client-browser
TypeScript icon, indicating that this package has built-in type declarations

0.0.17 • Public • Published

Flipt Client Browser

Status: Beta npm

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.
// 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);

State Management

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.

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

Readme

Keywords

none

Package Sidebar

Install

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

Weekly Downloads

201

Version

0.0.17

License

MIT

Unpacked Size

1.08 MB

Total Files

13

Last publish

Collaborators

  • markphelps