
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@featurevisor/sdk
Advanced tools
Universal JavaScript SDK for both Node.js and the browser.
Visit https://featurevisor.com/docs/sdks/ for more information.
$ npm install --save @featurevisor/sdk
Initialize the SDK:
import { createInstance } from "@featurevisor/sdk";
const sdk = createInstance(options);
Options you can pass when creating Featurevisor SDK instance:
bucketKeySeparatorstring.configureBucketKeyfunctionUse it to take over bucketing key generation process.
const sdk = createInstance({
configureBucketKey: (feature, context, bucketKey) => {
return bucketKey;
}
});
configureBucketValuefunctionUse it to take over bucketing process.
const sdk = createInstance({
configureBucketValue: (feature, context, bucketValue) => {
return bucketValue; // 0 to 100,000
}
});
datafileobjectdatafile or datafileUrl is requiredUse it to pass the datafile object directly.
datafileUrlstringdatafile or datafileUrl is requiredUse it to pass the URL to fetch the datafile from.
handleDatafileFetchfunctionPass this function if you need to take over the datafile fetching and parsing process:
const sdk = createInstance({
handleDatafileFetch: async (datafileUrl) => {
const response = await fetch(datafileUrl);
const datafile = await response.json();
return datafile;
}
});
initialFeaturesobjectPass set of initial features with their variation and (optional) variables that you want the SDK to return until the datafile is fetched and parsed:
const sdk = createInstance({
initialFeatures: {
myFeatureKey: {
enabled: true,
// optional
variation: "treatment",
variables: {
myVariableKey: "my-variable-value"
}
}
}
});
interceptContextfunctionIntercept given context before they are used to bucket the user:
const defaultContext = {
platform: "web",
locale: "en-US",
country: "US",
timezone: "America/New_York",
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko)",
};
const sdk = createInstance({
interceptContext: (context) => {
return {
...defaultContext,
...context,
};
}
});
loggerobjectPass a custom logger with custom levels, otherwise it the SDK will print logs to the console for error and warn levels.
import { createInstance, createLogger } from "@featurevisor/sdk";
const sdk = createInstance({
logger: createLogger({
levels: ["debug", "info", "warn", "error"],
handler: (level, message, details) => {
// do something with the log
},
}),
});
onActivationfunctionCapture activated features along with their evaluated variation:
const sdk = createInstance({
onActivation: (featureKey, variation, context, captureContext) => {
// do something with the activated feature
}
});
captureContext will only contain attributes that are marked as capture: true in the Attributes' YAML files.
onReadyfunctionTriggered maximum once when the SDK is ready to be used.
const sdk = createInstance({
onReady: () => {
// do something when the SDK is ready
}
});
onRefreshfunctionTriggered every time the datafile is refreshed.
Works only when datafileUrl and refreshInterval are set.
const sdk = createInstance({
onRefresh: () => {
// do something when the datafile is refreshed
}
});
onUpdatefunctionTriggered every time the datafile is refreshed, and the newly fetched datafile is detected to have different content than last fetched one.
Works only when datafileUrl and refreshInterval are set.
const sdk = createInstance({
onUpdate: () => {
// do something when the datafile is updated
}
});
refreshIntervalnumber (in seconds)Set the interval to refresh the datafile.
const sdk = createInstance({
refreshInterval: 60 * 5, // every 5 minutes
});
stickyFeaturesobjectIf set, the SDK will skip evaluating the datafile and return variation and variable results from this object instead.
If a feature key is not present in this object, the SDK will continue to evaluate the datafile.
const sdk = createInstance({
stickyFeatures: {
myFeatureKey: {
enabled: true,
// optional
variation: "treatment",
variables: {
myVariableKey: "my-variable-value"
}
}
}
});
These methods are available once the SDK instance is created:
isEnabled
isEnabled(featureKey: string, context: Context): boolean
getVariation
getVariation(featureKey: string, context: Context): VariationValue
getVariable
getVariable(featureKey: string, variableKey: string, context: Context): VariableValue
Also supports additional type specific methods:
getVariableBooleangetVariableStringgetVariableIntegergetVariableDoublegetVariableArraygetVariableObjectgetVariableJSONactivate
activate(featureKey: string, context: Context): VariationValue
Same as getVariation, but also calls the onActivation callback.
This is a convenience method meant to be called when you know the User has been exposed to your Feature, and you also want to track the activation.
isReady
isReady(): boolean
Synchonously check if the SDK is ready to be used.
refresh
refresh(): void
Manually refresh datafile.
setLogLevels
setLogLevels(levels: LogLevel[]): void
Accepted values for levels: ["debug", "info", "warn", "error"].
on
on(event: string, callback: function): void
Listen to SDK events, like:
readyactivationrefreshupdateaddListenerAlias for on method.
off
off(event: string, callback: function): void
removeListenerAlias for off method.
removeAllListeners
removeAllListeners(event?: string): void
onReadyResolves the SDK instance with a promise for convenience when it's ready:
onReady(): Promise
MIT © Fahad Heylaal
1.29.2 (2025-01-25)
Note: Version bump only for package featurevisor
FAQs
Featurevisor SDK for Node.js and the browser
The npm package @featurevisor/sdk receives a total of 2,429 weekly downloads. As such, @featurevisor/sdk popularity was classified as popular.
We found that @featurevisor/sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.