Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rate-limiter-flexible

Package Overview
Dependencies
Maintainers
1
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rate-limiter-flexible - npm Package Compare versions

Comparing version 0.23.1 to 0.23.2

2

package.json
{
"name": "rate-limiter-flexible",
"version": "0.23.1",
"version": "0.23.2",
"description": "Flexible API rate limiter backed by Redis for distributed node.js applications",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -17,3 +17,3 @@ [![Build Status](https://travis-ci.org/animir/node-rate-limiter-flexible.png)](https://travis-ci.org/animir/node-rate-limiter-flexible)

**Fast.** Average request takes `0.7ms` in Cluster and `2.5ms` in Distributed application.
**Fast.** Average request takes `0.7ms` in Cluster and `2.5ms` in Distributed application. See [benchmarks](https://github.com/animir/node-rate-limiter-flexible#benchmark).

@@ -107,2 +107,3 @@ **Flexible.** Combine limiters, block key for some duration, delay actions, manage failover with insurance options, configure smart key blocking in memory and many others.

* [Options](https://github.com/animir/node-rate-limiter-flexible/wiki/Options)
* [API methods](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods)
* [RateLimiterRedis](https://github.com/animir/node-rate-limiter-flexible/wiki/Redis)

@@ -119,3 +120,2 @@ * [RateLimiterMemcache](https://github.com/animir/node-rate-limiter-flexible/wiki/Memcache)

* [Koa middleware](https://github.com/animir/node-rate-limiter-flexible/wiki/Koa-Middleware)
* [API](#api)

@@ -163,74 +163,12 @@ ## Basic Options

### rateLimiter.consume(key, points = 1)
Read detailed description on Wiki.
Returns Promise, which:
* **resolved** with `RateLimiterRes` when point(s) is consumed, so action can be done
* **rejected** only for store and database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
* **rejected** when there is no points to be consumed, where reject reason `rejRes` is `RateLimiterRes` object
* **rejected** when key is blocked (if block strategy is set up), where reject reason `rejRes` is `RateLimiterRes` object
* [consume(key, points = 1)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimiterconsumekey-points--1) Consume points by key.
* [get(key)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimitergetkey) Get `RateLimiterRes` or `null`.
* [block(key, secDuration)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimiterblockkey-secduration) Block key for `secDuration` seconds.
* [delete(key)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimiterdeletekey) Reset consumed points.
* [penalty(key, points = 1)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimiterpenaltykey-points--1) Increase number of consumed points in current duration.
* [reward(key, points = 1)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimiterrewardkey-points--1) Decrease number of consumed points in current duration.
* [getKey(key)](https://github.com/animir/node-rate-limiter-flexible/wiki/API-methods#ratelimitergetkeykey) Get internal prefixed key.
Arguments:
* `key` is usually IP address or some unique client id
* `points` number of points consumed. `default: 1`
### rateLimiter.get(key)
Get `RateLimiterRes` in current duration.
Returns Promise, which:
* **resolved** with `RateLimiterRes` if key is set
* **resolved** with `null` if key is NOT set or expired
* **rejected** only for database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
Arguments:
* `key` is usually IP address or some unique client id
### rateLimiter.penalty(key, points = 1)
Fine `key` by `points` number of points for **one duration**.
Note: Depending on time penalty may go to next durations
Returns Promise, which:
* **resolved** with `RateLimiterRes`
* **rejected** only for database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
### rateLimiter.reward(key, points = 1)
Reward `key` by `points` number of points for **one duration**.
Note: Depending on time reward may go to next durations
Returns Promise, which:
* **resolved** with `RateLimiterRes`
* **rejected** only for database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
### rateLimiter.block(key, secDuration)
Block `key` for `secDuration` seconds
Returns Promise, which:
* **resolved** with `RateLimiterRes`
* **rejected** only for database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
### rateLimiter.delete(key)
Delete all data related to `key`.
For example, previously blocked key is not blocked after delete as there is no data anymore.
Returns Promise, which:
* **resolved** with `boolean`, `true` if data is removed by key, `false` if there is no such key.
* **rejected** only for database limiters if `insuranceLimiter` isn't setup: when some error happened, where reject reason `rejRes` is Error object
* **rejected** only for RateLimiterCluster if `insuranceLimiter` isn't setup: when `timeoutMs` exceeded, where reject reason `rejRes` is Error object
### rateLimiter.getKey(key)
Returns internal key prefixed with `keyPrefix` option as it is saved in store.
## Benchmark

@@ -237,0 +175,0 @@

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