0.1.0 • Published 6 months ago

@forest-bush/sdk-js v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

Forest Bush JS SDK

The official Javascript SDK for the Forest Bush feature flag and experimentation platform.

This SDK is designed to be lightweight and work in both Node.js and browser environments. It provides a simple interface to evaluate feature flags from your Forest Bush API.

Installation

npm install @forest-bush/sdk-js

(Note: This package is not yet published to npm. This is the command you would run once it is.)

Usage

First, import and initialize the client with the host of your deployed Forest Bush API.

import { ForestBushClient } from '@forest-bush/sdk-js';

const forestBush = new ForestBushClient({
  host: 'https://forest-bush.fly.dev', // your api host
});

// example usage in an async function
async function checkMyFeature() {
  const isEnabled = await forestBush.evaluate(
    'new-cool-feature', // the key of the flag you want to evaluate
    false,              // a default value to return in case of any errors
    'user-123'          // optional: a user id for sticky rollouts
  );

  if (isEnabled) {
    console.log('the new cool feature is enabled for user-123!');
    // show the new feature...
  } else {
    console.log('the new cool feature is not enabled for user-123.');
    // show the old feature or nothing...
  }
}

checkMyFeature();

API Reference

new ForestBushClient(config)

Creates a new client instance.

  • config (ForestBushClientConfig):
    • host (string, required): The base URL of your Forest Bush API.

client.evaluate(key, defaultValue, userId)

Asynchronously evaluates a feature flag.

  • key (string, required): The key of the flag to evaluate.
  • defaultValue (boolean, required): The safe default value to return in case the API is unreachable or an error occurs.
  • userId (string, optional): A unique identifier for the user. Providing this ensures that percentage-based rollouts are "sticky" for that user.

Returns a Promise<boolean> with the evaluated state of the flag.

0.1.0

6 months ago