rate-limiter-flexible
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -81,8 +81,14 @@ export interface IRateLimiterResOptions { | ||
whiteList?: string[] | number[]; | ||
isBlackListed?(key: any): boolean; | ||
isWhiteListed?(key: any): boolean; | ||
runActionAnyway?: boolean; | ||
/** | ||
* @deprecated Use isBlackListed instead | ||
*/ | ||
isBlack?(key: string | number): boolean; | ||
/** | ||
* @deprecated Use isWhiteListed instead | ||
*/ | ||
isWhite?(key: string | number): boolean; | ||
runActionAnyway?: boolean; | ||
} | ||
@@ -89,0 +95,0 @@ |
const RateLimiterRes = require('./RateLimiterRes'); | ||
const util = require('util'); | ||
@@ -8,5 +9,23 @@ module.exports = class RLWrapperBlackAndWhite { | ||
this.whiteList = opts.whiteList; | ||
this.isBlack = opts.isBlack; | ||
this.isWhite = opts.isWhite; | ||
this.isBlackListed = opts.isBlackListed || opts.isBlack; | ||
this.isWhiteListed = opts.isWhiteListed || opts.isWhite; | ||
this.runActionAnyway = opts.runActionAnyway; | ||
Object.defineProperty(this, 'isWhite', { | ||
get: util.deprecate(() => { | ||
return this.isWhiteListed | ||
}, 'isWhite is deprecated. Use isWhiteListed instead.'), | ||
set: util.deprecate(() => { | ||
this.isWhiteListed = func | ||
}, 'isWhite is deprecated. Use isWhiteListed instead.'), | ||
}); | ||
Object.defineProperty(this, 'isBlack', { | ||
get: util.deprecate(() => { | ||
return this.isBlackListed | ||
}, 'isBlack is deprecated. Use isBlackListed instead.'), | ||
set: util.deprecate(() => { | ||
this.isBlackListed = func | ||
}, 'isBlack is deprecated. Use isBlackListed instead.'), | ||
}); | ||
} | ||
@@ -42,7 +61,7 @@ | ||
get isBlack() { | ||
return this._isBlack; | ||
get isBlackListed() { | ||
return this._isBlackListed; | ||
} | ||
set isBlack(func) { | ||
set isBlackListed(func) { | ||
if (typeof func === 'undefined') { | ||
@@ -52,5 +71,5 @@ func = () => false; | ||
if (typeof func !== 'function') { | ||
throw new Error('isBlack must be function'); | ||
throw new Error('isBlackListed must be function'); | ||
} | ||
this._isBlack = func; | ||
this._isBlackListed = func; | ||
} | ||
@@ -66,7 +85,7 @@ | ||
get isWhite() { | ||
return this._isWhite; | ||
get isWhiteListed() { | ||
return this._isWhiteListed; | ||
} | ||
set isWhite(func) { | ||
set isWhiteListed(func) { | ||
if (typeof func === 'undefined') { | ||
@@ -76,13 +95,13 @@ func = () => false; | ||
if (typeof func !== 'function') { | ||
throw new Error('isWhite must be function'); | ||
throw new Error('isWhiteListed must be function'); | ||
} | ||
this._isWhite = func; | ||
this._isWhiteListed = func; | ||
} | ||
isBlackSomewhere(key) { | ||
return this.blackList.indexOf(key) >= 0 || this.isBlack(key); | ||
isBlackListedSomewhere(key) { | ||
return this.blackList.indexOf(key) >= 0 || this.isBlackListed(key); | ||
} | ||
isWhiteSomewhere(key) { | ||
return this.whiteList.indexOf(key) >= 0 || this.isWhite(key); | ||
isWhiteListedSomewhere(key) { | ||
return this.whiteList.indexOf(key) >= 0 || this.isWhiteListed(key); | ||
} | ||
@@ -112,5 +131,5 @@ | ||
let res; | ||
if (this.isWhiteSomewhere(key)) { | ||
if (this.isWhiteListedSomewhere(key)) { | ||
res = this.resolveWhite(); | ||
} else if (this.isBlackSomewhere(key)) { | ||
} else if (this.isBlackListedSomewhere(key)) { | ||
res = this.rejectBlack(); | ||
@@ -131,5 +150,5 @@ } | ||
let res; | ||
if (this.isWhiteSomewhere(key)) { | ||
if (this.isWhiteListedSomewhere(key)) { | ||
res = this.resolveWhite(); | ||
} else if (this.isBlackSomewhere(key)) { | ||
} else if (this.isBlackListedSomewhere(key)) { | ||
res = this.resolveBlack(); | ||
@@ -150,5 +169,5 @@ } | ||
let res; | ||
if (this.isWhiteSomewhere(key)) { | ||
if (this.isWhiteListedSomewhere(key)) { | ||
res = this.resolveWhite(); | ||
} else if (this.isBlackSomewhere(key)) { | ||
} else if (this.isBlackListedSomewhere(key)) { | ||
res = this.resolveBlack(); | ||
@@ -169,5 +188,5 @@ } | ||
let res; | ||
if (this.isWhiteSomewhere(key)) { | ||
if (this.isWhiteListedSomewhere(key)) { | ||
res = this.resolveWhite(); | ||
} else if (this.isBlackSomewhere(key)) { | ||
} else if (this.isBlackListedSomewhere(key)) { | ||
res = this.resolveBlack(); | ||
@@ -188,5 +207,5 @@ } | ||
let res; | ||
if (this.isWhiteSomewhere(key)) { | ||
if (this.isWhiteListedSomewhere(key)) { | ||
res = this.resolveWhite(); | ||
} else if (this.isBlackSomewhere(key)) { | ||
} else if (this.isBlackListedSomewhere(key)) { | ||
res = this.resolveBlack(); | ||
@@ -193,0 +212,0 @@ } |
{ | ||
"name": "rate-limiter-flexible", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Node.js rate limiter by key and protection from DDoS and Brute-Force attacks in process Memory, Redis, MongoDb, Memcached, MySQL, PostgreSQL, Cluster or PM", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104186
2833