🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@harnessio/ff-javascript-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harnessio/ff-javascript-client-sdk

Basic library for integrating CF into javascript applications.

1.1.0
Source
npm
Version published
Weekly downloads
14K
-3.19%
Maintainers
1
Weekly downloads
 
Created
Source

Harness Feature Flags Client SDK for JavaScript

Library for integrating Harness Feature Flags into JavaScript applications.

Install

npm i @harnessio/ff-javascript-client-sdk

or

yarn add @harnessio/ff-javascript-client-sdk

Usage

import { initialize, Event } from '@harnessio/ff-javascript-client-sdk'

Initialize SDK with api key and target information.

initialize(FeatureFlagSDKKey: string, target: Target, options?: Options)

In which Target and Options are defined as:

interface Target {
  identifier: string
  name?: string
  anonymous?: boolean
  attributes?: object
}

interface Options {
  baseUrl?: string
  debug?: boolean
}

For example:

const cf = initialize('00000000-1111-2222-3333-444444444444', {
    identifier: YOUR-TARGET-IDENTIFIER,      // Target identifier
    name: YOUR-TARGET-NAME,                  // Optional target name
    attributes: {                            // Optional target attributes
      email: 'sample@sample.com'
    }
  }, {
    baseURL: HARNESS-FEATURE-FLAG-BASE-URL,  // Optional Harness Feature Flag server base URL
  });

Listening to events from the cf instance.

cf.on(Event.READY, flags => {
  // Event happens when connection to server is established
  // flags contains all evaluations against SDK key
})

cf.on(Event.CHANGED, flagInfo => {
  // Event happens when a changed event is pushed
  // flagInfo contains information about the updated feature flag
})

cf.on(Event.DISCONNECTED, () => {
  // Event happens when connection is disconnected
})

cf.on(Event.ERROR, () => {
  // Event happens when connection some error has occurred
})

Getting value for a particular feature flag

const value = cf.variation('Dark_Theme', false) // second argument is default value when variation does not exist

Cleaning up

Remove a listener of an event by cf.off.

cf.off(Event.ERROR, () => {
  // Do something when an error occurs
})

Remove all listeners:

cf.off()

On closing your application, call cf.close() to close the event stream.

cf.close();

License

Apache version 2.

Keywords

Harness

FAQs

Package last updated on 18 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts