@devcycle/devcycle-nodejs-sdk v0.0.0-alpha-3
DevCycle NodeJS SDK
The NodeJS SDK for DevCycle!
Installation
Our library can be found on npm and installed by the following:
npm install @devcycle/devcycle-nodejs-sdkTo use in your project, import the initialize function:
Usage
import { DVC, Configuration } from '@devcycle/devcycle-nodejs-sdk'const config = new Configuration({
apiKey: 'your_server_key_here'
})
const instance: DVC = new DVC(config)User Object
The full user data must be passed into every request. The only required field is the user_id. The rest are optional and may affect the variables and features that are returned from the calls below.
const user = {
user_id: 'user1',
name: 'user 1 name',
customData: {
customKey: 'customValue'
}
}Getting All Features
You can wait on the features to be loaded from our servers by using getFeatures() function. It returns a promise that you can use to wait until features are ready to be used:
const features = await instance.getFeatures(user)Grabbing Variable Values
To get values from your Variables, getVariable() is used to fetch variable values using the identifier key coupled with a default value. The default value can be of type string, boolean, number, or object.
const variable = instance.getVariableByKey(user, 'YOUR_VARIABLE_KEY', 'default value')To grab the value, there is a property on the object returned to grab the value
const variable = {
_id,
value,
key,
type
}The variable also contains the variable _id, key, and type.
In a situation where the default value is needed (e.g. the user in the request is not part of a feature that controls the variable), then the default value is used.
In that case, the variable returned from the function will not contain the _id or type fields.
Grabbing All Variables
To grab all the Variables for a user:
const variables = await instance.getVariables(user)