@toggles/experiments
v1.1.0
Published
Create, update, and delete experiments and determine if they are active for users/audiences.
Downloads
7
Maintainers
Readme
@toggles/experiments
Create, update, and delete experiments and determine if they are active for users/audiences.
Install
Install with npm.
$ npm i @toggles/experiments
Usage
const toggles = require('@toggles/experiments');
const client = toggles({
apiKey: 'KEY',
})
async function main() {
const {uuid} = await toggles.createExperiment({name: 'foo'})
await toggles.updateExperiment(uuid, {name: 'bar', percent: 100})
const experiments = await toggles.getExperiments()
const experiment = await toggles.getExperimentById(uuid)
const active = await toggles.isExperimentActive(uuid, {uniqueId: '[email protected]'})
}
Client Methods
createExperimentClient
Creates a new experiment client.
const options = {
apiKey: 'string', // This comes from the Settings tab of the Dashboard.
}
const client = toggles.createClient(options)
createExperiment
Create a new experiment.
const params = {
name: 'string',
}
const experiment = await client.createExperiment(params)
console.log(experiment)
// {
// description: 'string',
// enabled: boolean,
// name: 'string',
// percent: number,
// uuid: 'string',
// }
deleteExperiment
Delete an experiment.
const success = await client.createExperiment(experiment.uuid)
console.log(success) // boolean
getAPIKey
Returns the provided API Key.
const key = client.getAPIKey()
getAPIUrl
Returns the provided API Url.
const url = client.getAPIUrl()
getExperiment
, getExperimentById
Returns an experiment provided an experiment id.
const experiment = await client.getExperiment(experiment.uuid)
console.log(experiment)
// {
// description: 'string',
// enabled: boolean,
// name: 'string',
// percent: number,
// uuid: 'string',
// }
getExperiments
Returns a list of all of the user's experiments.
const experiments = await client.getExperiments()
console.log(experiment)
// [
// {
// description: 'string',
// enabled: boolean,
// name: 'string',
// percent: number,
// uuid: 'string',
// },
// ]
getLocalExperiment
, getLocalExperimentByUuid
Returns an experiment from the localized experiments cache, or the global state.
const experiment = client.getLocalExperiment(experiment.uuid)
console.log(experiment)
// {
// description: 'string',
// enabled: boolean,
// name: 'string',
// percent: number,
// uuid: 'string',
// }
isExperimentActive
Used to determine whether an experiment is active for the current user. If this method is used in a response handler, it will not use cookies, or the global state, unless expressly passed.
const params = {
uniqueId: 'string', // optional
}
const active = await client.isExperimentActive(experiment.uuid, params)
console.log(active) // boolean
setAPIKey
Sets the API Key used to make requests to the API.
client.setAPIKey('KEY')
updateExperiment
Updates an experiment provided an experiment id and an experiment payload.
const params = {
description: 'string',
enabled: true,
name: 'string',
percent: 100,
}
const experiment = await client.updateExperiment(experiment.uuid, params)
console.log(experiment)
// {
// description: 'string',
// enabled: boolean,
// name: 'string',
// percent: number,
// uuid: 'string',
// }
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
License
Copyright © 2019 [] Licensed under the MIT license.
This file was generated by readme-generator on June 21, 2019.