New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

unleash-client

Package Overview
Dependencies
Maintainers
4
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unleash-client - npm Package Compare versions

Comparing version 3.2.4 to 3.2.5

examples/custom_repository.js

19

CHANGELOG.md
# Changelog
## 3.2.5
- feature: Allow user to implement custom toggle repository
- feat: Drop node 6 support (EOL)
- feat: Get all feature toggle definitions at once
- fix: Update lint-staged to the latest version 8.1.7
- fix: Update nock to version 10.0.6
- fix: Update @types/node to version 12.0.2
- fix: Update husky to version 2.3.0
- fix: Update ava to version 1.4.1
- fix: Update eslint to version 5.16.0
- fix: Update nyc to version 14.1.1
## 3.2.4

@@ -7,5 +20,5 @@

- fix: Upgrade husky to version 2.2.0
- Update lint-staged to the latest version 🚀 (#112)
- Update @types/node to the latest version 🚀 (#113)
- Update @types/nock to the latest version 🚀 (#111)
- fix: Update lint-staged to the latest version 🚀 (#112)
- fix: Update @types/node to the latest version 🚀 (#113)
- fix: Update @types/nock to the latest version 🚀 (#111)
- chore: update deails.json

@@ -12,0 +25,0 @@

2

examples/variant.js

@@ -14,3 +14,3 @@ const { initialize, getVariant } = require('../lib');

setInterval(() => {
console.log(`featureX enabled`, getVariant('Test.variants', { userId: `${Math.random()}` }));
console.log(`Variant config`, getVariant('Test.variants', { userId: `${Math.random()}` }));
}, 1000);
import { EventEmitter } from 'events';
import { Strategy, StrategyTransportInterface } from './strategy';
import { FeatureInterface } from './feature';
import Repository from './repository';
import { RepositoryInterface } from './repository';
import { Variant } from './variant';

@@ -11,3 +11,3 @@ import { Context } from './context';

private warned;
constructor(repository: Repository, strategies: Strategy[]);
constructor(repository: RepositoryInterface, strategies: Strategy[]);
private getStrategy;

@@ -14,0 +14,0 @@ warnOnce(missingStrategy: string, name: string, strategies: StrategyTransportInterface[]): void;

@@ -1,1 +0,1 @@

{ "name": "unleash-client-node", "version": "3.2.4", "sdkVersion": "unleash-client-node:3.2.4" }
{ "name": "unleash-client-node", "version": "3.2.5", "sdkVersion": "unleash-client-node:3.2.5" }

@@ -10,2 +10,3 @@ import { Unleash, UnleashConfig } from './unleash';

export declare function getFeatureToggleDefinition(toggleName: string): import("./feature").FeatureInterface | undefined;
export declare function getFeatureToggleDefinitions(): import("./feature").FeatureInterface[] | undefined;
export declare function getVariant(name: string, context?: Context, fallbackVariant?: Variant): Variant;

@@ -12,0 +13,0 @@ export declare function count(toggleName: string, enabled: boolean): void | undefined;

@@ -29,2 +29,6 @@ "use strict";

exports.getFeatureToggleDefinition = getFeatureToggleDefinition;
function getFeatureToggleDefinitions() {
return instance && instance.getFeatureToggleDefinitions();
}
exports.getFeatureToggleDefinitions = getFeatureToggleDefinitions;
function getVariant(name, context, fallbackVariant) {

@@ -31,0 +35,0 @@ if (context === void 0) { context = {}; }

@@ -6,2 +6,7 @@ import { EventEmitter } from 'events';

export declare type StorageImpl = typeof Storage;
export interface RepositoryInterface extends EventEmitter {
getToggle(name: string): FeatureInterface;
getToggles(): FeatureInterface[];
stop(): void;
}
export interface RepositoryOptions {

@@ -33,3 +38,4 @@ backupPath: string;

getToggle(name: string): FeatureInterface;
getToggles(): FeatureInterface[];
}
//# sourceMappingURL=repository.d.ts.map

@@ -113,2 +113,6 @@ "use strict";

};
Repository.prototype.getToggles = function () {
var toggles = this.storage.getAll();
return Object.keys(toggles).map(function (key) { return toggles[key]; });
};
return Repository;

@@ -115,0 +119,0 @@ }(events_1.EventEmitter));

@@ -14,2 +14,3 @@ import { EventEmitter } from 'events';

get(key: string): any;
getAll(): any;
persist(): void;

@@ -16,0 +17,0 @@ load(): void;

@@ -54,2 +54,5 @@ "use strict";

};
Storage.prototype.getAll = function () {
return this.data;
};
Storage.prototype.persist = function () {

@@ -56,0 +59,0 @@ var _this = this;

@@ -0,1 +1,2 @@

import { RepositoryInterface } from './repository';
import { Strategy } from './strategy';

@@ -20,2 +21,3 @@ export { Strategy };

timeout?: number;
repository?: RepositoryInterface;
}

@@ -26,3 +28,3 @@ export declare class Unleash extends EventEmitter {

private metrics;
constructor({ appName, instanceId, url, refreshInterval, metricsInterval, disableMetrics, backupPath, strategies, customHeaders, timeout, }: UnleashConfig);
constructor({ appName, instanceId, url, refreshInterval, metricsInterval, disableMetrics, backupPath, strategies, repository, customHeaders, timeout, }: UnleashConfig);
destroy(): void;

@@ -32,2 +34,3 @@ isEnabled(name: string, context: any, fallbackValue?: boolean): boolean;

getFeatureToggleDefinition(toggleName: string): FeatureInterface;
getFeatureToggleDefinitions(): FeatureInterface[];
count(toggleName: string, enabled: boolean): void;

@@ -34,0 +37,0 @@ countVariant(toggleName: string, variantName: string): void;

@@ -29,3 +29,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, customHeaders = _a.customHeaders, timeout = _a.timeout;
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, repository = _a.repository, customHeaders = _a.customHeaders, timeout = _a.timeout;
var _this = _super.call(this) || this;

@@ -61,11 +61,13 @@ if (!url) {

}
_this.repository = new repository_1.default({
backupPath: backupPath,
url: url,
appName: appName,
instanceId: instanceId,
refreshInterval: refreshInterval,
headers: customHeaders,
timeout: timeout,
});
_this.repository =
repository ||
new repository_1.default({
backupPath: backupPath,
url: url,
appName: appName,
instanceId: instanceId,
refreshInterval: refreshInterval,
headers: customHeaders,
timeout: timeout,
});
strategies = strategy_1.defaultStrategies.concat(strategies);

@@ -150,2 +152,5 @@ _this.repository.on('ready', function () {

};
Unleash.prototype.getFeatureToggleDefinitions = function () {
return this.repository.getToggles();
};
Unleash.prototype.count = function (toggleName, enabled) {

@@ -152,0 +157,0 @@ this.metrics.count(toggleName, enabled);

{
"name": "unleash-client",
"version": "3.2.4",
"version": "3.2.5",
"description": "Unleash Client for Node",

@@ -14,3 +14,3 @@ "license": "Apache-2.0",

"prepare": "npm run build",
"test": "NODE_ENV=test npm run build && ava test",
"test": "cross-env NODE_ENV=test npm run build && ava test",
"coverage": "nyc --check-coverage=true npm test",

@@ -38,3 +38,3 @@ "coveralls": "nyc report --reporter=text-lcov | coveralls"

"engines": {
"node": ">=6",
"node": ">=8",
"npm": ">=4.0.0"

@@ -49,17 +49,18 @@ },

"@types/murmurhash3js": "^3.0.2",
"@types/nock": "^10.0.0",
"@types/node": "^12.0.0",
"@types/nock": "^10.0.3",
"@types/node": "^12.0.2",
"@types/request": "^2.0.8",
"@unleash/client-specification": "^3.2.0",
"ava": "^1.0.1",
"coveralls": "^3.0.0",
"eslint": "^5.0.0",
"ava": "^1.4.1",
"cross-env": "^5.2.0",
"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"eslint-config-finn": "^3.0.0",
"eslint-config-finn-prettier": "^3.0.0",
"husky": "^2.2.0",
"lint-staged": "^8.1.6",
"husky": "^2.3.0",
"lint-staged": "^8.1.7",
"mkdirp": "^0.5.1",
"nock": "^10.0.0",
"nyc": "^13.1.0",
"prettier": "^1.9.1",
"nock": "^10.0.6",
"nyc": "^14.1.1",
"prettier": "^1.17.1",
"typescript": "^3.2.2"

@@ -76,3 +77,4 @@ },

],
"all": true
"all": true,
"exclude-after-remap": false
},

@@ -79,0 +81,0 @@ "prettier": {

@@ -52,3 +52,8 @@ # unleash-client-node

```js
const { isEnabled, getVariant } = require('unleash-client');
const {
isEnabled,
getVariant,
getFeatureToggleDefinition,
getFeatureToggleDefinitions,
} = require('unleash-client');

@@ -58,2 +63,5 @@ isEnabled('app.ToggleX');

const { enabled, name, payload } = getVariant('app.ToggleY', { userId: '1234' });
const featureToogleX = getFeatureToggleDefinition('app.ToggleX');
const featureToggles = getFeatureToggleDefinitions();
```

@@ -114,2 +122,3 @@

- **timeout** - specify a timeout in milliseconds for outgoing HTTP requests. Defaults to 10000ms.
- **repository** - Provide a custom repository implementation to manage the underlying data

@@ -159,1 +168,37 @@ ## Custom strategies

```
## Events
The unleash instance object implements the EventEmitter class and **emits** the following events:
| event | payload | description |
| ---------- | -------------------------------- | ---------------------------------------------------------------------------------------- |
| ready | - | is emitted once the fs-cache is ready. if no cache file exists it will still be emitted. |
| registered | - | is emitted after the app has been registered at the api server |
| sent | `object` data | key/value pair of delivered metrics |
| count | `string` name, `boolean` enabled | is emitted when a feature is evaluated |
| warn | `string` msg | is emitted on a warning |
| error | `Error` err | is emitted on a error |
Example usage:
```js
const { Unleash, isEnabled } = require('unleash-client');
const instance = new Unleash({
appName: 'my-app-name',
url: 'http://unleash.herokuapp.com',
});
await instance.once('ready');
// do something
```
## Custom repository
You can manage the underlying data layer yourself if you want to. This enables you to use unleash
offline, from a browser environment or implement your own caching layer. See
[example](examples/custom_repository.js).
Unleash depends on a `ready` event of the repository you pass in. Be sure that you emit the event
**after** you've initialized unleash.

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc