dipswitch
Dipswitch is a multi-tenant feature toggle library.
npm)
Installation (via$ npm install dipswitch --save
If you wish to use redis to store this data, also install dipswitch-redis. Otherwise, an in-memory store will be used.
Usage
The Basics
var Dipswitch = dipswitch = redis: { // default is `return tenant.id;` return tenanttenantId; } { // default is `return user.id;` return useruserId; } { // default is `return user.groups || [];` if userisAdmin return 'admins'; return ; } ; // ADDING & REMOVING FEATURES -------------------------------------------------- // add & remove a featuredipswitchfeatures;dipswitchfeatures; // and another syntax for registering many features at oncedipswitchfeatures; // and unregister many features at once as welldipswitchfeatures; // retrieve all registered featuresdipswitchfeatures; // ENABLING FEATURES ----------------------------------------------------------- // enable a feature globallydipswitchfeatures; // enable a feature for an entire tenantdipswitch; // enable a feature for a group within a tenantdipswitch; // enable a feature a group across all tenantsdipswitch; // enable a feature for a user within a tenantdipswitch; // enable a feature for a user across all tenantsdipswitch; // SCHEDULING FEATURES --------------------------------------------------------- // when enabling a feature you may optionally pass a `start` and/or `end` datedipswitchfeatures; // CHECKING FEATURES ----------------------------------------------------------- // retrieve all features and whether they're enabled or not for a userdipswitch; // check a single feature and whether it is enabled or not for a userdipswitch; // DISABLING FEATURES ---------------------------------------------------------- // anywhere that you can call #enable, you can also call #disabledipswitch;
Unregistering Out-of-Date Features
Rather than having to have an admin UI for unregistering features you no longer care about, you can use a bit of underscore
/lodash
magic to automate the process:
var _ = Dipswitch = dipswitch = options; // note that FEATURE_2 was removed at some pointvar desiredFeatures = 'FEATURE_1' 'FEATURE_3'; dipswitch ;
Interacting With Unregistered Features
When enabling or disabling a feature that has never been registered, that feature is automatically registered. When testing to see the value of a feature that isn't registered, the result will be false
.