![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@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:
bucketKeySeparator
string
.
configureBucketKey
function
Use it to take over bucketing key generation process.
const sdk = createInstance({
configureBucketKey: (feature, context, bucketKey) => {
return bucketKey;
}
});
configureBucketValue
function
Use it to take over bucketing process.
const sdk = createInstance({
configureBucketValue: (feature, context, bucketValue) => {
return bucketValue; // 0 to 100,000
}
});
datafile
object
datafile
or datafileUrl
is requiredUse it to pass the datafile object directly.
datafileUrl
string
datafile
or datafileUrl
is requiredUse it to pass the URL to fetch the datafile from.
handleDatafileFetch
function
Pass 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;
}
});
initialFeatures
object
Pass 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"
}
}
}
});
interceptContext
function
Intercept 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,
};
}
});
logger
object
Pass 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
},
}),
});
onActivation
function
Capture 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.
onReady
function
Triggered maximum once when the SDK is ready to be used.
const sdk = createInstance({
onReady: () => {
// do something when the SDK is ready
}
});
onRefresh
function
Triggered 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
}
});
onUpdate
function
Triggered 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
}
});
refreshInterval
number
(in seconds)Set the interval to refresh the datafile.
const sdk = createInstance({
refreshInterval: 60 * 5, // every 5 minutes
});
stickyFeatures
object
If 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:
getVariableBoolean
getVariableString
getVariableInteger
getVariableDouble
getVariableArray
getVariableObject
getVariableJSON
activate
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:
ready
activation
refresh
update
addListener
Alias for on
method.
off
off(event: string, callback: function): void
removeListener
Alias for off
method.
removeAllListeners
removeAllListeners(event?: string): void
onReady
Resolves 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 0 weekly downloads. As such, @featurevisor/sdk popularity was classified as not 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 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.