Skip to content

Repository files navigation

Before you Begin

Harness Feature Flags (FF) is a feature management solution that enables users to change the software’s functionality, without deploying new code. FF uses feature flags to hide code or behaviours without having to ship new versions of the software. A feature flag is like a powerful if statement.

For more information, see https://harness.io/products/feature-flags/

To read more, see https://ngdocs.harness.io/category/vjolt35atg-feature-flags

To sign up, https://app.harness.io/auth/#/signup/

Harness Feature Flags Client SDK for JavaScript

Library for integrating Harness Feature Flags into JavaScript UI 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:

interfaceTarget{identifier: stringname?: stringanonymous?: booleanattributes?: object}interfaceOptions{baseUrl?: stringdebug?: boolean}

For example:

constcf=initialize('00000000-1111-2222-3333-444444444444',{identifier: YOUR_TARGET_IDENTIFIER,// Target identifiername: YOUR_TARGET_NAME,// Optional target nameattributes: {// Optional target attributesemail: 'sample@sample.com'}});

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,error=>{// Event happens when connection some error has occurred})

Getting value for a particular feature flag

constvalue=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,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();

Import directly from unpkg

In case you want to import this library directly (without having to use npm or yarn):

<scripttype="module">import{initialize,Event}from'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.11/dist/sdk.client.js'</script>

If you need to support old browsers which don't support ES Module:

<scriptsrc="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.4.11/dist/sdk.client.js"></script><script>varinitialize=HarnessFFSDK.initializevarEvent=HarnessFFSDK.Event</script>

Remember to change the version 1.4.11 in the unpkg url accordingly.

License

Apache version 2.

About

Feature flags Demo App

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages