Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@harnessio/ff-javascript-client-sdk

Package Overview
Dependencies
Maintainers
1
Versions
113
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
  • Socket score

Version published
Weekly downloads
7K
increased by51.37%
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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc