unleash-client
Advanced tools
Comparing version 1.0.1 to 2.1.0
@@ -16,4 +16,5 @@ const { Strategy, initialize, isEnabled } = require('../lib'); | ||
appName: 'my-application', | ||
url: 'http://unleash.herokuapp.com/', | ||
refreshInterval: 10000, | ||
url: 'https://unleash-new-ui.herokuapp.com/api/', | ||
refreshInterval: 5000, | ||
metricsInterval: 5000, | ||
strategies: [new ActiveForUserWithEmailStrategy()], | ||
@@ -25,6 +26,11 @@ }); | ||
console.log('Fetching toggles from: http://unleash.herokuapp.com', client); | ||
console.log('Fetching toggles from: https://unleash-new-ui.herokuapp.com', client); | ||
setInterval(() => { | ||
console.log(`featureX enabled: ${isEnabled('featureX', { email: 'user@mail.com' })}`); | ||
console.log(`Test enabled: ${isEnabled('Test', { userId: '1234' })}`); | ||
}, 1000); | ||
setInterval(() => { | ||
console.log(`Test enabled: ${isEnabled('Test', { userId: '12' })}`); | ||
}, 1000); |
@@ -5,3 +5,3 @@ const { initialize, isEnabled } = require('../lib'); | ||
appName: 'my-application', | ||
url: 'http://unleash.herokuapp.com/', | ||
url: 'http://unleash.herokuapp.com/api/', | ||
}); | ||
@@ -8,0 +8,0 @@ |
@@ -7,10 +7,10 @@ 'use strict'; | ||
}; | ||
var events_1 = require("events"); | ||
var events_1 = require('events'); | ||
var UnleashClient = (function (_super) { | ||
__extends(UnleashClient, _super); | ||
function UnleashClient(repository, strategies) { | ||
var _this = _super.call(this) || this; | ||
_this.repository = repository; | ||
_this.strategies = strategies || []; | ||
_this.warned = {}; | ||
_super.call(this); | ||
this.repository = repository; | ||
this.strategies = strategies || []; | ||
this.warned = {}; | ||
strategies.forEach(function (strategy) { | ||
@@ -25,3 +25,2 @@ if (!strategy || | ||
}); | ||
return _this; | ||
} | ||
@@ -28,0 +27,0 @@ UnleashClient.prototype.getStrategy = function (name) { |
"use strict"; | ||
var unleash_1 = require("./unleash"); | ||
var strategy_1 = require("./strategy"); | ||
var unleash_1 = require('./unleash'); | ||
var strategy_1 = require('./strategy'); | ||
exports.Strategy = strategy_1.Strategy; | ||
var unleash_2 = require("./unleash"); | ||
var unleash_2 = require('./unleash'); | ||
exports.Unleash = unleash_2.Unleash; | ||
@@ -7,0 +7,0 @@ var instance; |
@@ -7,5 +7,5 @@ "use strict"; | ||
}; | ||
var events_1 = require("events"); | ||
var url_1 = require("url"); | ||
var request_1 = require("./request"); | ||
var events_1 = require('events'); | ||
var url_1 = require('url'); | ||
var request_1 = require('./request'); | ||
var Metrics = (function (_super) { | ||
@@ -15,16 +15,15 @@ __extends(Metrics, _super); | ||
var appName = _a.appName, instanceId = _a.instanceId, strategies = _a.strategies, _b = _a.metricsInterval, metricsInterval = _b === void 0 ? 0 : _b, _c = _a.disableMetrics, disableMetrics = _c === void 0 ? false : _c, url = _a.url; | ||
var _this = _super.call(this) || this; | ||
_this.disabled = disableMetrics; | ||
_this.metricsInterval = metricsInterval; | ||
_this.appName = appName; | ||
_this.instanceId = instanceId; | ||
_this.strategies = strategies; | ||
_this.url = url; | ||
_this.started = new Date(); | ||
_this.resetBucket(); | ||
if (typeof _this.metricsInterval === 'number' && _this.metricsInterval > 0) { | ||
_this.startTimer(); | ||
_this.registerInstance(); | ||
_super.call(this); | ||
this.disabled = disableMetrics; | ||
this.metricsInterval = metricsInterval; | ||
this.appName = appName; | ||
this.instanceId = instanceId; | ||
this.strategies = strategies; | ||
this.url = url; | ||
this.started = new Date(); | ||
this.resetBucket(); | ||
if (typeof this.metricsInterval === 'number' && this.metricsInterval > 0) { | ||
this.startTimer(); | ||
this.registerInstance(); | ||
} | ||
return _this; | ||
} | ||
@@ -31,0 +30,0 @@ Metrics.prototype.startTimer = function () { |
@@ -7,7 +7,7 @@ 'use strict'; | ||
}; | ||
var events_1 = require("events"); | ||
var data_formatter_1 = require("./data-formatter"); | ||
var storage_1 = require("./storage"); | ||
var url_1 = require("url"); | ||
var request_1 = require("./request"); | ||
var events_1 = require('events'); | ||
var data_formatter_1 = require('./data-formatter'); | ||
var storage_1 = require('./storage'); | ||
var url_1 = require('url'); | ||
var request_1 = require('./request'); | ||
; | ||
@@ -17,13 +17,13 @@ var Repository = (function (_super) { | ||
function Repository(_a) { | ||
var _this = this; | ||
var backupPath = _a.backupPath, url = _a.url, appName = _a.appName, instanceId = _a.instanceId, refreshInterval = _a.refreshInterval, _b = _a.StorageImpl, StorageImpl = _b === void 0 ? storage_1.Storage : _b; | ||
var _this = _super.call(this) || this; | ||
_this.url = url; | ||
_this.refreshInterval = refreshInterval; | ||
_this.instanceId = instanceId; | ||
_this.appName = appName; | ||
_this.storage = new StorageImpl({ backupPath: backupPath, appName: appName }); | ||
_this.storage.on('error', function (err) { return _this.emit('error', err); }); | ||
_this.storage.on('ready', function () { return _this.emit('ready'); }); | ||
_super.call(this); | ||
this.url = url; | ||
this.refreshInterval = refreshInterval; | ||
this.instanceId = instanceId; | ||
this.appName = appName; | ||
this.storage = new StorageImpl({ backupPath: backupPath, appName: appName }); | ||
this.storage.on('error', function (err) { return _this.emit('error', err); }); | ||
this.storage.on('ready', function () { return _this.emit('ready'); }); | ||
process.nextTick(function () { return _this.fetch(); }); | ||
return _this; | ||
} | ||
@@ -30,0 +30,0 @@ Repository.prototype.timedFetch = function () { |
"use strict"; | ||
var request = require("request"); | ||
var request = require('request'); | ||
exports.post = function (options, cb) { | ||
@@ -4,0 +4,0 @@ if (!options.timeout) { |
@@ -7,5 +7,5 @@ 'use strict'; | ||
}; | ||
var events_1 = require("events"); | ||
var path_1 = require("path"); | ||
var fs_1 = require("fs"); | ||
var events_1 = require('events'); | ||
var path_1 = require('path'); | ||
var fs_1 = require('fs'); | ||
var Storage = (function (_super) { | ||
@@ -15,10 +15,9 @@ __extends(Storage, _super); | ||
var backupPath = _a.backupPath, appName = _a.appName; | ||
var _this = _super.call(this) || this; | ||
_super.call(this); | ||
// ready is a "ready"-flag to signal that storage is ready with data, | ||
// and to signal to backup not to store fetched backup | ||
_this.ready = false; | ||
_this.data = {}; | ||
_this.path = path_1.join(backupPath, "/unleash-repo-schema-v1-" + appName + ".json"); | ||
_this.load(); | ||
return _this; | ||
this.ready = false; | ||
this.data = {}; | ||
this.path = path_1.join(backupPath, "/unleash-repo-schema-v1-" + appName + ".json"); | ||
this.load(); | ||
} | ||
@@ -25,0 +24,0 @@ Storage.prototype.reset = function (data, doPersist) { |
@@ -0,1 +1,2 @@ | ||
import { Context } from './context'; | ||
export declare class Strategy { | ||
@@ -5,3 +6,3 @@ name: string; | ||
constructor(name: string, returnValue?: boolean); | ||
isEnabled(parameters: any, context: any): boolean; | ||
isEnabled(parameters: any, context: Context): boolean; | ||
} | ||
@@ -8,0 +9,0 @@ export interface StrategyTransportInterface { |
/// <reference types="node" /> | ||
import { Strategy } from './strategy'; | ||
export { Strategy as Strategy } from './strategy'; | ||
import { Strategy } from './strategy/index'; | ||
export { Strategy as Strategy } from './strategy/index'; | ||
import { EventEmitter } from 'events'; | ||
@@ -5,0 +5,0 @@ export interface UnleashConfig { |
@@ -7,11 +7,11 @@ 'use strict'; | ||
}; | ||
var client_1 = require("./client"); | ||
var repository_1 = require("./repository"); | ||
var metrics_1 = require("./metrics"); | ||
var strategy_1 = require("./strategy"); | ||
var strategy_2 = require("./strategy"); | ||
exports.Strategy = strategy_2.Strategy; | ||
var os_1 = require("os"); | ||
var events_1 = require("events"); | ||
var os_2 = require("os"); | ||
var client_1 = require('./client'); | ||
var repository_1 = require('./repository'); | ||
var metrics_1 = require('./metrics'); | ||
var index_1 = require('./strategy/index'); | ||
var index_2 = require('./strategy/index'); | ||
exports.Strategy = index_2.Strategy; | ||
var os_1 = require('os'); | ||
var events_1 = require('events'); | ||
var os_2 = require('os'); | ||
var BACKUP_PATH = os_1.tmpdir(); | ||
@@ -22,4 +22,5 @@ ; | ||
function Unleash(_a) { | ||
var _this = this; | ||
var appName = _a.appName, instanceId = _a.instanceId, url = _a.url, _b = _a.refreshInterval, refreshInterval = _b === void 0 ? 15 * 1000 : _b, _c = _a.metricsInterval, metricsInterval = _c === void 0 ? 60 * 1000 : _c, _d = _a.disableMetrics, disableMetrics = _d === void 0 ? false : _d, _e = _a.backupPath, backupPath = _e === void 0 ? BACKUP_PATH : _e, _f = _a.strategies, strategies = _f === void 0 ? [] : _f; | ||
var _this = _super.call(this) || this; | ||
_super.call(this); | ||
if (!url) { | ||
@@ -44,3 +45,3 @@ throw new Error('Unleash server URL missing'); | ||
} | ||
_this.repository = new repository_1["default"]({ | ||
this.repository = new repository_1["default"]({ | ||
backupPath: backupPath, | ||
@@ -52,4 +53,4 @@ url: url, | ||
}); | ||
strategies = [new strategy_1.Strategy('default', true)].concat(strategies); | ||
_this.repository.on('ready', function () { | ||
strategies = index_1.defaultStrategies.concat(strategies); | ||
this.repository.on('ready', function () { | ||
_this.client = new client_1["default"](_this.repository, strategies); | ||
@@ -60,10 +61,10 @@ _this.client.on('error', function (err) { return _this.emit('error', err); }); | ||
}); | ||
_this.repository.on('error', function (err) { | ||
this.repository.on('error', function (err) { | ||
err.message = "Unleash Repository error: " + err.message; | ||
_this.emit('error', err); | ||
}); | ||
_this.repository.on('warn', function (msg) { | ||
this.repository.on('warn', function (msg) { | ||
_this.emit('warn', msg); | ||
}); | ||
_this.metrics = new metrics_1["default"]({ | ||
this.metrics = new metrics_1["default"]({ | ||
disableMetrics: disableMetrics, | ||
@@ -76,19 +77,18 @@ appName: appName, | ||
}); | ||
_this.metrics.on('error', function (err) { | ||
this.metrics.on('error', function (err) { | ||
err.message = "Unleash Metrics error: " + err.message; | ||
_this.emit('error', err); | ||
}); | ||
_this.metrics.on('warn', function (msg) { | ||
this.metrics.on('warn', function (msg) { | ||
_this.emit('warn', msg); | ||
}); | ||
_this.metrics.on('count', function (name, enabled) { | ||
this.metrics.on('count', function (name, enabled) { | ||
_this.emit('count', name, enabled); | ||
}); | ||
_this.metrics.on('sent', function (payload) { | ||
this.metrics.on('sent', function (payload) { | ||
_this.emit('sent', payload); | ||
}); | ||
_this.metrics.on('registered', function (payload) { | ||
this.metrics.on('registered', function (payload) { | ||
_this.emit('registered', payload); | ||
}); | ||
return _this; | ||
} | ||
@@ -95,0 +95,0 @@ Unleash.prototype.destroy = function () { |
{ | ||
"name": "unleash-client", | ||
"version": "1.0.1", | ||
"version": "2.1.0", | ||
"description": "Unleash Client for Node", | ||
@@ -9,3 +9,3 @@ "main": "./lib/index.js", | ||
"lint": "eslint .", | ||
"build": "tsc src/*.ts -d --strictNullChecks --sourceMap --outdir ./lib --lib ES6,ES5", | ||
"build": "tsc src/*.ts src/**/*.ts -d --strictNullChecks --sourceMap --outdir ./lib --lib ES6,ES5", | ||
"prepublish": "not-in-install && npm run build || in-install", | ||
@@ -12,0 +12,0 @@ "test": "ava test", |
@@ -52,5 +52,30 @@ # unleash-client-node | ||
### Built in activation strategies | ||
The Java client comes with implementations for the built-in activation strategies | ||
provided by unleash. | ||
- DefaultStrategy | ||
- UserWithIdStrategy | ||
- GradualRolloutRandomStrategy | ||
- GradualRolloutUserWithIdStrategy | ||
- GradualRolloutSessionIdStrategy | ||
- RemoteAddressStrategy | ||
- ApplicationHostnameStrategy | ||
Read more about the strategies in [activation-strategy.md](https://github.com/Unleash/unleash/blob/master/docs/activation-strategies.md). | ||
### Unleash context | ||
In order to use some of the common activation strategies you must provide a [unleash-context](https://github.com/Unleash/unleash/blob/master/docs/unleash-context.md). | ||
This client SDK allows you to send in the unleash context as part of the `isEnabled` call: | ||
```javascript | ||
const context = { | ||
userId: '123', | ||
sessionId: 'some-session-id', | ||
remoteAddress: '127.0.0.1', | ||
}; | ||
unleash.isEnabled("someToggle", unleashContext); | ||
``` | ||
## Advanced usage | ||
@@ -57,0 +82,0 @@ The initialize method takes the following arguments: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
72707
71
1112
133
2