Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@harnessio/ff-javascript-client-sdk
Advanced tools
Basic library for integrating CF into javascript applications.
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/
Library for integrating Harness Feature Flags into JavaScript UI applications.
npm i @harnessio/ff-javascript-client-sdk
or
yarn add @harnessio/ff-javascript-client-sdk
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
eventUrl?: string
eventsSyncInterval?: number
streamEnabled?: boolean
allAttributesPrivate?: boolean
privateAttributeNames?: string[]
debug?: boolean
}
For example:
const client = 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'
}
})
client
instance.client.on(Event.READY, flags => {
// Event happens when connection to server is established
// flags contains all evaluations against SDK key
})
client.on(Event.FLAGS_LOADED, evaluations => {
// Event happens when flags are loaded from the server
})
client.on(Event.CACHE_LOADED, evaluations => {
// Event happens when flags are loaded from the cache
})
client.on(Event.CHANGED, flagInfo => {
// Event happens when a changed event is pushed
// flagInfo contains information about the updated feature flag
})
client.on(Event.DISCONNECTED, () => {
// Event happens when connection is disconnected
})
client.on(Event.ERROR, error => {
// Event happens when connection some error has occurred
})
client.on(Event.ERROR_AUTH, error => {
// Event happens when unable to authenticate
})
client.on(Event.ERROR_FETCH_FLAGS, error => {
// Event happens when unable to fetch flags from the service
})
client.on(Event.ERROR_FETCH_FLAG, error => {
// Event happens when unable to fetch an individual flag from the service
})
client.on(Event.ERROR_METRICS, error => {
// Event happens when unable to report metrics back to the service
})
client.on(Event.ERROR_STREAM, error => {
// Event happens when the stream returns an error
})
const value = client.variation('Dark_Theme', false) // second argument is default value when variation does not exist
Remove a listener of an event by client.off
.
client.off(Event.ERROR, error => {
// Do something when an error occurs
})
Remove all listeners:
client.off()
On closing your application, call client.close()
to close the event stream.
client.close()
In practice flags rarely change and so it can be useful to cache the last received evaluations from the server to allow
your application to get started as fast as possible. Setting the cache
option as true
or as an object (see interface
below) will allow the SDK to store its evaluations to localStorage
and retrieve at startup. This lets the SDK get
started near instantly and begin serving flags, while it carries on authenticating and fetching up-to-date evaluations
from the server behind the scenes.
const client = initialize('00000000-1111-2222-3333-444444444444', {
identifier: YOUR_TARGET_IDENTIFIER,
name: YOUR_TARGET_NAME
}, {
cache: true // enable caching
}
)
The cache
option can also be passed as an object with the following options.
export interface CacheOptions {
ttl?: number // maximum age of stored cache, in ms, before it is considered stale
}
In some cases it might be worthwhile providing the SDK with a set of evaluations which it can then serve instantly. You might want to consider this when you need to:
To achieve this you can call the setEvaluations
method at any time after initializing the client. The
setEvaluations
method takes an array of Evaluation
objects as an argument.
client.setEvaluations(evals);
In which Evaluation
is defined as:
export interface Evaluation {
flag: string // Feature flag identifier
identifier: string // variation identifier
value: boolean | string | number | object | undefined // variation value
kind: string // boolean | json | string | int
deleted?: boolean // mark that feature flag is deleted
}
In case you want to import this library directly (without having to use npm or yarn):
<script type="module">
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk/dist/sdk.client.js'
</script>
If you need to support old browsers which don't support ES Module:
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk/dist/sdk.client.js"></script>
<script>
var initialize = HarnessFFSDK.initialize
var Event = HarnessFFSDK.Event
</script>
Integrating with webviews on mobile devices
Apache version 2.
FAQs
Basic library for integrating CF into javascript applications.
The npm package @harnessio/ff-javascript-client-sdk receives a total of 7,983 weekly downloads. As such, @harnessio/ff-javascript-client-sdk popularity was classified as popular.
We found that @harnessio/ff-javascript-client-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.