unleash-client
Advanced tools
Comparing version 2.2.1 to 2.3.0
# Changelog | ||
## 2.3.0 | ||
- Add support for custom headers | ||
## 2.2.1 | ||
- Fix broken metrics reporting | ||
## 2.2.0 | ||
@@ -4,0 +10,0 @@ - Add user-agent header to requests |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { Data } from './request'; | ||
import { CustomHeaders } from './unleash'; | ||
export interface MetricsOptions { | ||
@@ -12,2 +13,3 @@ appName: string; | ||
url: string; | ||
headers?: CustomHeaders; | ||
} | ||
@@ -25,3 +27,4 @@ export default class Metrics extends EventEmitter { | ||
private started; | ||
constructor({appName, instanceId, strategies, metricsInterval, disableMetrics, url}: MetricsOptions); | ||
private headers?; | ||
constructor({appName, instanceId, strategies, metricsInterval, disableMetrics, url, headers}: MetricsOptions); | ||
private startTimer(); | ||
@@ -28,0 +31,0 @@ stop(): void; |
@@ -19,3 +19,3 @@ "use strict"; | ||
function Metrics(_a) { | ||
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 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, headers = _a.headers; | ||
var _this = _super.call(this) || this; | ||
@@ -28,2 +28,3 @@ _this.disabled = disableMetrics; | ||
_this.url = url; | ||
_this.headers = headers; | ||
_this.started = new Date(); | ||
@@ -64,3 +65,4 @@ _this.resetBucket(); | ||
appName: this.appName, | ||
instanceId: this.instanceId | ||
instanceId: this.instanceId, | ||
headers: this.headers | ||
}, function (err, res, body) { | ||
@@ -95,3 +97,4 @@ if (err) { | ||
appName: this.appName, | ||
instanceId: this.instanceId | ||
instanceId: this.instanceId, | ||
headers: this.headers | ||
}, function (err, res, body) { | ||
@@ -98,0 +101,0 @@ _this.startTimer(); |
/// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
import { FeatureInterface } from './feature'; | ||
import { CustomHeaders } from './unleash'; | ||
export interface StorageImpl { | ||
@@ -14,2 +15,3 @@ new (Storage: any): any; | ||
StorageImpl?: StorageImpl; | ||
headers?: CustomHeaders; | ||
} | ||
@@ -24,3 +26,4 @@ export default class Repository extends EventEmitter implements EventEmitter { | ||
private refreshInterval?; | ||
constructor({backupPath, url, appName, instanceId, refreshInterval, StorageImpl}: RepositoryOptions); | ||
private headers?; | ||
constructor({backupPath, url, appName, instanceId, refreshInterval, StorageImpl, headers}: RepositoryOptions); | ||
timedFetch(): void; | ||
@@ -27,0 +30,0 @@ validateFeature(feature: FeatureInterface): void; |
@@ -21,3 +21,3 @@ "use strict"; | ||
function Repository(_a) { | ||
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 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, headers = _a.headers; | ||
var _this = _super.call(this) || this; | ||
@@ -28,2 +28,3 @@ _this.url = url; | ||
_this.appName = appName; | ||
_this.headers = headers; | ||
_this.storage = new StorageImpl({ backupPath: backupPath, appName: appName }); | ||
@@ -62,3 +63,4 @@ _this.storage.on('error', function (err) { return _this.emit('error', err); }); | ||
appName: this.appName, | ||
instanceId: this.instanceId | ||
instanceId: this.instanceId, | ||
headers: this.headers | ||
}, function (error, res, body) { | ||
@@ -65,0 +67,0 @@ // start timer for next fetch |
/// <reference types="request" /> | ||
import * as request from 'request'; | ||
import { CustomHeaders } from './unleash'; | ||
export interface RequestOptions { | ||
url: string; | ||
timeout?: number; | ||
headers?: CustomHeaders; | ||
} | ||
@@ -20,3 +22,3 @@ export interface GetRequestOptions extends RequestOptions { | ||
} | ||
export declare const post: ({url, appName, timeout, instanceId, json}: PostRequestOptions, cb: any) => request.Request; | ||
export declare const get: ({url, etag, appName, timeout, instanceId}: GetRequestOptions, cb: any) => request.Request; | ||
export declare const post: ({url, appName, timeout, instanceId, headers, json}: PostRequestOptions, cb: any) => request.Request; | ||
export declare const get: ({url, etag, appName, timeout, instanceId, headers}: GetRequestOptions, cb: any) => request.Request; |
@@ -5,11 +5,11 @@ "use strict"; | ||
exports.post = function (_a, cb) { | ||
var url = _a.url, appName = _a.appName, timeout = _a.timeout, instanceId = _a.instanceId, json = _a.json; | ||
var url = _a.url, appName = _a.appName, timeout = _a.timeout, instanceId = _a.instanceId, headers = _a.headers, json = _a.json; | ||
var options = { | ||
url: url, | ||
timeout: timeout || 10000, | ||
headers: { | ||
headers: Object.assign({ | ||
'UNLEASH-APPNAME': appName, | ||
'UNLEASH-INSTANCEID': instanceId, | ||
'User-Agent': appName | ||
}, | ||
}, headers), | ||
json: json | ||
@@ -20,11 +20,11 @@ }; | ||
exports.get = function (_a, cb) { | ||
var url = _a.url, etag = _a.etag, appName = _a.appName, timeout = _a.timeout, instanceId = _a.instanceId; | ||
var url = _a.url, etag = _a.etag, appName = _a.appName, timeout = _a.timeout, instanceId = _a.instanceId, headers = _a.headers; | ||
var options = { | ||
url: url, | ||
timeout: timeout || 10000, | ||
headers: { | ||
headers: Object.assign({ | ||
'UNLEASH-APPNAME': appName, | ||
'UNLEASH-INSTANCEID': instanceId, | ||
'User-Agent': appName | ||
} | ||
}, headers) | ||
}; | ||
@@ -31,0 +31,0 @@ if (etag) { |
@@ -5,2 +5,5 @@ /// <reference types="node" /> | ||
import { EventEmitter } from 'events'; | ||
export interface CustomHeaders { | ||
[key: string]: string; | ||
} | ||
export interface UnleashConfig { | ||
@@ -15,2 +18,3 @@ appName: string; | ||
strategies: Strategy[]; | ||
customHeaders?: CustomHeaders; | ||
} | ||
@@ -21,5 +25,5 @@ export declare class Unleash extends EventEmitter { | ||
private metrics; | ||
constructor({appName, instanceId, url, refreshInterval, metricsInterval, disableMetrics, backupPath, strategies}: UnleashConfig); | ||
constructor({appName, instanceId, url, refreshInterval, metricsInterval, disableMetrics, backupPath, strategies, customHeaders}: UnleashConfig); | ||
destroy(): void; | ||
isEnabled(name: string, context: any, fallbackValue?: boolean): boolean; | ||
} |
@@ -26,3 +26,3 @@ "use strict"; | ||
function Unleash(_a) { | ||
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 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, customHeaders = _a.customHeaders; | ||
var _this = _super.call(this) || this; | ||
@@ -64,3 +64,4 @@ if (!url) { | ||
instanceId: instanceId, | ||
refreshInterval: refreshInterval | ||
refreshInterval: refreshInterval, | ||
headers: customHeaders | ||
}); | ||
@@ -87,3 +88,4 @@ strategies = index_1.defaultStrategies.concat(strategies); | ||
metricsInterval: metricsInterval, | ||
url: url | ||
url: url, | ||
headers: customHeaders | ||
}); | ||
@@ -90,0 +92,0 @@ _this.metrics.on('error', function (err) { |
{ | ||
"name": "unleash-client", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Unleash Client for Node", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -90,2 +90,3 @@ # unleash-client-node | ||
- **disableMetrics** - disable metrics | ||
- **customHeaders** - Provide a map(object) of custom headers to be sent to the unleash-server | ||
@@ -92,0 +93,0 @@ |
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
77964
135
68
1208