
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
This README details the Node.js implementation of Variants. For general background, see the general README.
The frontend server will load all defined variants to modify variant flags for individual requests.
The variants are provided in a JSON file that is loaded at startup by the server and watched for changes in development.
Example
{
"variants": [
{
"id": "ProductAccess"
, "conditions": [
{
"type": "USER_ID"
, "values": [
"somedude74"
, "anotherdude323"
, "hax0r1337"
]
}
]
, "mods": [
{
"enable_access": true
}
]
}
, {
"id": "ShinyNewFeature"
, "conditions": [
{
"type": "USER_ID_MOD"
, "values": [ 0, 9 ]
, "cookie_type": "NSID"
}
]
, "mods": [
{
"enable_shiny_new_feature": true
}
]
}
]
}
In the above example, there are two variants: ProductAccess and ShinyNewFeature. For some set of users, we declare that the global variable "enable_access" is set to true. Similarily, for ShinyNewFeature, a different condition is used to modify a different value, and so on.
npm install variants
Or grab the source and
npm install
npm install nodeunit -g
nodeunit tests/variants_test.js
Below is a list of the "exposed" interfaces.
Assuming the following:
var variants = require('variants')
Evaluates the flag value based on the given context object.
Asynchronously oads a JSON file that can declare variants and variant flags. Uses node fs
API. Accepts a callback path that returns either an error object or a callback signaling completion.
Asynchronously oads a given raw JSON object that contains variants and variant flags. Accepts a callback path that returns either an error object or a callback signaling completion.
Registers a new condition type and handler associated with it.
Any context passed into the method that evaluates a flag will be passed into the condition handler, allowing you to define custom conditions based on context within your application.
E.g.
registerConditionType('RANDOM', function (value) {
if (value < 0 || value > 1) {
throw new Error('Fractional value from 0-1 required')
}
return function() {
if (!value) {
return false
}
return Math.random() <= value
}
})
Programmatic way to register a global flag value. This must come before parsing any files that use the flag.
Returns a list of all registered variants.
Returns a list of all registered flags.
Returns the value for the specific flag name.
Questions, comments, bug reports, and pull requests are all welcome. Submit them at the project on GitHub.
Bug reports that include steps-to-reproduce (including code) are the best. Even better, make them in the form of pull requests that update the test suite. Thanks!
David Byttow supported by The Obvious Corporation.
Copyright 2012 The Obvious Corporation.
Licensed under the Apache License, Version 2.0.
See the top-level file LICENSE.txt
and
(http://www.apache.org/licenses/LICENSE-2.0).
FAQs
Framework for declaring dynamic flags based on pluggable conditions.
We found that variants demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.