izanami-node
v1.11.5
Published
Client for Izanami
Downloads
128
Readme
Node js client
Install
npm install izanami-node
Import
const Izanami = require('izanami-node');
Usage
The node client expose conveniant methods to call Izanami.
Configure the client:
const izanamicConfig = Object.assign({}, Izanami.defaultConfig, {
host: 'http://localhost:9000',
clientId: process.env.CLIENT_ID || 'xxxx',
clientSecret: process.env.CLIENT_SECRET || 'xxxx',
});
// Get a configs client
const configClient = Izanami.configClient(izanamicConfig);
// Get a feature client
const featureClient = Izanami.featureClient(izanamicConfig);
// Get a experiments client
const experimentsClient = Izanami.experimentsClient(izanamicConfig);
Configs
Get a config
configClient.config("my.config.id").then(config => {
console.log('The config is ', config);
tree.should.be.deep.equal({
"value": "test"
})
});
Get the configs tree
configClient.configs("my.config.*").then(tree => {
tree.should.be.deep.equal({
"my": {
"config": {
"id": {
"value": "test"
},
"id2": {
"another": {
"value": "a value"
}
}
}
}
});
});
Features
Check a feature
featureClient.checkFeature("my.feature.id").then(active => {
console.log('The feature is ', active);
});
Or with a context:
featureClient.checkFeature("my.feature.id", {client: "[email protected]"}).then(active => {
console.log('The feature is ', active);
});
Get the features tree
featureClient.features("my.feature.*").then(tree => {
tree.should.be.deep.equal({
"my": {
"feature": {
"id": {
"active": true
},
"id2": {
"active": false
}
}
}
});
});
Or with a context:
featureClient.features("my.feature.*", {client: "[email protected]"}).then(tree => {
tree.should.be.deep.equal({
"my": {
"feature": {
"id": {
"active": true
},
"id2": {
"active": false
}
}
}
});
});
Experiments
Get an experiment
experimentsClient.experiment("my.experiment.id").then(experiment => {
//Empty json if the experiment doesn't exists
console.log('The experiment is ', experiment);
});
Get experiments as tree
experimentsClient.experiments("my.experiment.*", "[email protected]").then(tree => {
//Empty json if the experiment doesn't exists
console.log('The experiment is ', experiment);
tree.should.be.deep.equal({
"my": {
"experiment": {
"id": {
"variant": "A"
},
"id2": {
"variant": "B"
}
}
}
})
});
Get a variant
experimentsClient.variantFor("my.experiment.id", "[email protected]").then(variant => {
//Empty json if the variant doesn't exists
console.log('The variant is ', variant);
});
Mark variant displayed
experimentsClient.displayed("my.experiment.id", "[email protected]").then(__ => {
console.log('The variant is marked displayed');
});
Mark variant won
experimentsClient.won("my.experiment.id", "[email protected]").then(__ => {
console.log('The variant is marked won');
});
Express proxy
You use express as a proxy to expose Izanami to the client side.
const app = express();
Izanami.expressProxy({
sessionPath: '/api/izanami', // default '/api/me'
featureClient, // Optional
experimentsClient, // Optional
configClient, // Optional
app, // Express app
path: 'my.namespace.*' // The pattern to filter experiments, configs and features
});