Socket
Socket
Sign inDemoInstall

rate-limit-redis

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rate-limit-redis - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

dist/index.d.cts

46

changelog.md

@@ -9,10 +9,34 @@ # Changelog

## [v3.0.1](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v3.0.1)
## [v4.0.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v4.0.0)
### Breaking
- Dropped `node` v14 support.
- Added support for `express-rate-limit` v7.
### Changed
- Updated documentation related to `ioredis` integration [#48](https://github.com/wyattjoh/rate-limit-redis/pull/48)
- Use `pkgroll` to bundle library.
- Bumped dependencies.
## [v3.0.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v3.0.0)
## [v3.1.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v3.1.0)
### Changed
- Retry the `EVALSHA` command if it fails the first time.
## [v3.0.2](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v3.0.2)
### Changed
- Added the `types` field to the `export` map in `package.json`.
## [v3.0.1](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v3.0.1)
### Changed
- Updated documentation related to `ioredis` integration.
## [v3.0.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v3.0.0)
### Added

@@ -46,3 +70,3 @@

## [v2.1.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v2.1.0)
## [v2.1.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v2.1.0)

@@ -59,3 +83,3 @@ ### Added

## [v2.0.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v2.0.0)
## [v2.0.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v2.0.0)

@@ -66,3 +90,3 @@ ### Changed

## [v1.7.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.7.0)
## [v1.7.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.7.0)

@@ -74,3 +98,3 @@ ### Added

## [v1.6.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.6.0)
## [v1.6.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.6.0)

@@ -82,3 +106,3 @@ ### Added

## [v1.5.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.5.0)
## [v1.5.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.5.0)

@@ -93,3 +117,3 @@ ### Added

## [v1.4.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.4.0)
## [v1.4.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.4.0)

@@ -101,3 +125,3 @@ ### Added

## [v1.3.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.3.0)
## [v1.3.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.3.0)

@@ -108,3 +132,3 @@ ### Added

## [v1.1.0](https://github.com/wyattjoh/rate-limit-redis/releases/tag/v1.1.0)
## [v1.1.0](https://github.com/express-rate-limit/rate-limit-redis/releases/tag/v1.1.0)

@@ -111,0 +135,0 @@ ### Added

@@ -1,9 +0,7 @@

// Generated by dts-bundle-generator v6.4.0
import { Store, Options as Options$1, IncrementResponse } from 'express-rate-limit';
import { IncrementResponse, Options as RateLimitConfiguration, Store } from 'express-rate-limit';
/**
* The type of data Redis might return to us.
*/
export declare type RedisReply = number | string;
type RedisReply = number | string;
/**

@@ -13,91 +11,92 @@ * The library sends Redis raw commands, so all we need to know are the

*/
export declare type SendCommandFn = (...args: string[]) => Promise<RedisReply | RedisReply[]>;
type SendCommandFn = (...args: string[]) => Promise<RedisReply | RedisReply[]>;
/**
* The configuration options for the store.
*/
export interface Options {
/**
* The function used to send commands to Redis.
*/
readonly sendCommand: SendCommandFn;
/**
* The text to prepend to the key in Redis.
*/
readonly prefix?: string;
/**
* Whether to reset the expiry for a particular key whenever its hit count
* changes.
*/
readonly resetExpiryOnChange?: boolean;
}
type Options = {
/**
* The function used to send commands to Redis.
*/
readonly sendCommand: SendCommandFn;
/**
* The text to prepend to the key in Redis.
*/
readonly prefix?: string;
/**
* Whether to reset the expiry for a particular key whenever its hit count
* changes.
*/
readonly resetExpiryOnChange?: boolean;
};
/**
* A `Store` for the `express-rate-limit` package that stores hit counts in
* Redis.
*/
declare class RedisStore implements Store {
/**
* The function used to send raw commands to Redis.
*/
sendCommand: SendCommandFn;
/**
* The text to prepend to the key in Redis.
*/
prefix: string;
/**
* Whether to reset the expiry for a particular key whenever its hit count
* changes.
*/
resetExpiryOnChange: boolean;
/**
* Stores the loaded SHA1 of the LUA script for executing the increment operations.
*/
loadedScriptSha1: Promise<string>;
/**
* The number of milliseconds to remember that user's requests.
*/
windowMs: number;
/**
* @constructor for `RedisStore`.
*
* @param options {Options} - The configuration options for the store.
*/
constructor(options: Options);
loadScript(): Promise<string>;
/**
* Method to prefix the keys with the given text.
*
* @param key {string} - The key.
*
* @returns {string} - The text + the key.
*/
prefixKey(key: string): string;
/**
* Method that actually initializes the store.
*
* @param options {RateLimitConfiguration} - The options used to setup the middleware.
*/
init(options: RateLimitConfiguration): void;
runCommandWithRetry(key: string): Promise<RedisReply | RedisReply[]>;
/**
* Method to increment a client's hit counter.
*
* @param key {string} - The identifier for a client
*
* @returns {IncrementResponse} - The number of hits and reset time for that client
*/
increment(key: string): Promise<IncrementResponse>;
/**
* Method to decrement a client's hit counter.
*
* @param key {string} - The identifier for a client
*/
decrement(key: string): Promise<void>;
/**
* Method to reset a client's hit counter.
*
* @param key {string} - The identifier for a client
*/
resetKey(key: string): Promise<void>;
/**
* The function used to send raw commands to Redis.
*/
sendCommand: SendCommandFn;
/**
* The text to prepend to the key in Redis.
*/
prefix: string;
/**
* Whether to reset the expiry for a particular key whenever its hit count
* changes.
*/
resetExpiryOnChange: boolean;
/**
* Stores the loaded SHA1 of the LUA script for executing the increment operations.
*/
loadedScriptSha1: Promise<string>;
/**
* The number of milliseconds to remember that user's requests.
*/
windowMs: number;
/**
* @constructor for `RedisStore`.
*
* @param options {Options} - The configuration options for the store.
*/
constructor(options: Options);
loadScript(): Promise<string>;
/**
* Method to prefix the keys with the given text.
*
* @param key {string} - The key.
*
* @returns {string} - The text + the key.
*/
prefixKey(key: string): string;
/**
* Method that actually initializes the store.
*
* @param options {RateLimitConfiguration} - The options used to setup the middleware.
*/
init(options: Options$1): void;
runCommandWithRetry(key: string): Promise<RedisReply | RedisReply[]>;
/**
* Method to increment a client's hit counter.
*
* @param key {string} - The identifier for a client
*
* @returns {IncrementResponse} - The number of hits and reset time for that client
*/
increment(key: string): Promise<IncrementResponse>;
/**
* Method to decrement a client's hit counter.
*
* @param key {string} - The identifier for a client
*/
decrement(key: string): Promise<void>;
/**
* Method to reset a client's hit counter.
*
* @param key {string} - The identifier for a client
*/
resetKey(key: string): Promise<void>;
}
export {
RedisStore as default,
};
export {};
export { Options, RedisReply, SendCommandFn, RedisStore as default };
MIT License
Copyright (c) 2021 Wyatt Johnson
Copyright (c) 2023 Wyatt Johnson, Nathan Friedly, Vedant K
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "rate-limit-redis",
"version": "3.1.0",
"version": "4.0.0",
"description": "A Redis store for the `express-rate-limit` middleware",

@@ -10,10 +10,15 @@ "author": {

"license": "MIT",
"homepage": "https://github.com/wyattjoh/rate-limit-redis",
"repository": "https://github.com/wyattjoh/rate-limit-redis",
"homepage": "https://github.com/express-rate-limit/rate-limit-redis",
"repository": "https://github.com/express-rate-limit/rate-limit-redis",
"type": "module",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}

@@ -33,17 +38,15 @@ },

"engines": {
"node": ">= 14.5.0"
"node": ">= 16"
},
"scripts": {
"clean": "del-cli dist/ coverage/ *.log *.tmp *.tgz *.bak",
"build:cjs": "esbuild --bundle --platform=node --format=cjs --outfile=dist/index.cjs --footer:js=\"module.exports = RedisStore; module.exports.default = RedisStore;\" src/index.ts",
"build:esm": "esbuild --bundle --platform=node --format=esm --outfile=dist/index.mjs src/index.ts",
"build:types": "dts-bundle-generator --out-file=dist/index.d.ts src/index.ts",
"compile": "run-s clean build:*",
"build": "pkgroll --src source/",
"compile": "run-s clean build",
"lint:code": "xo",
"lint:rest": "prettier --check --ignore-path=.gitignore .",
"lint:rest": "prettier --check .",
"lint": "run-s lint:*",
"autofix:code": "xo --fix",
"autofix:rest": "prettier --write --ignore-path=.gitignore .",
"autofix": "run-s autofix:*",
"test:lib": "cross-env NODE_OPTIONS=\"--experimental-vm-modules\" jest --passWithNoTests",
"format:code": "xo --fix",
"format:rest": "prettier --write .",
"format": "run-s format:*",
"test:lib": "jest",
"test": "run-s lint test:*",

@@ -54,28 +57,31 @@ "pre-commit": "lint-staged",

"peerDependencies": {
"express-rate-limit": "^6"
"express-rate-limit": ">= 6"
},
"devDependencies": {
"@jest/globals": "^27.4.6",
"@types/express": "^4.17.13",
"@types/ioredis-mock": "^5.6.0",
"@types/jest": "^27.0.3",
"@types/node": "^16.11.19",
"cross-env": "^7.0.3",
"del-cli": "^4.0.1",
"dts-bundle-generator": "^6.4.0",
"esbuild": "^0.14.11",
"express": "^4.17.2",
"express-rate-limit": "^6.1.0",
"husky": "^7.0.4",
"ioredis": "^4.28.3",
"ioredis-mock": "^5.8.1",
"jest": "^27.4.2",
"lint-staged": "^12.1.7",
"npm-run-all": "^4.1.5",
"prettier": "^2.5.1",
"serve": "^13.0.2",
"ts-jest": "^27.1.3",
"ts-node": "^10.4.0",
"typescript": "^4.5.2",
"xo": "^0.47.0"
"@express-rate-limit/prettier": "1.1.0",
"@express-rate-limit/tsconfig": "1.0.0",
"@jest/globals": "29.7.0",
"@types/express": "4.17.17",
"@types/ioredis-mock": "8.2.2",
"@types/jest": "29.5.4",
"@types/node": "20.6.1",
"cross-env": "7.0.3",
"del-cli": "5.1.0",
"dts-bundle-generator": "8.0.1",
"esbuild": "0.19.3",
"express": "4.18.2",
"express-rate-limit": "7.0.0",
"husky": "8.0.3",
"ioredis": "5.3.2",
"ioredis-mock": "8.8.3",
"jest": "29.7.0",
"lint-staged": "14.0.1",
"npm-run-all": "4.1.5",
"pkgroll": "1.11.0",
"prettier": "3.0.3",
"serve": "14.2.1",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"xo": "0.56.0"
},

@@ -93,37 +99,7 @@ "xo": {

},
"prettier": {
"useTabs": false,
"trailingComma": "es5",
"singleQuote": false,
"bracketSpacing": true
},
"jest": {
"verbose": true,
"preset": "ts-jest/presets/default-esm",
"globals": {
"ts-jest": {
"useESM": true
}
},
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.ts"
],
"testTimeout": 30000,
"testMatch": [
"**/test/**/*-test.[jt]s"
],
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
}
},
"prettier": "@express-rate-limit/prettier",
"lint-staged": {
"{src,test}/**/*.ts": "xo --fix",
"{source,test}/**/*.ts": "xo --fix",
"*.{yaml,json,md}": "prettier --write"
}
}
# <div align="center"> `rate-limit-redis` </div>
<div align="center">
<img alt="Github Workflow Status" src="https://img.shields.io/github/workflow/status/wyattjoh/rate-limit-redis/CI"/>
<img alt="Github Workflow Status" src="https://github.com/express-rate-limit/rate-limit-redis/actions/workflows/ci.yaml/badge.svg"/>
<img alt="npm version" src="https://img.shields.io/npm/v/rate-limit-redis.svg"/>
<img alt="GitHub Stars" src="https://img.shields.io/github/stars/wyattjoh/rate-limit-redis"/>
<img alt="GitHub Stars" src="https://img.shields.io/github/stars/express-rate-limit/rate-limit-redis"/>
<img alt="npm downloads" src="https://img.shields.io/npm/dm/rate-limit-redis"/>

@@ -35,5 +35,5 @@ </div>

# Using npm
> npm install https://github.com/wyattjoh/rate-limit-redis/releases/download/v{version}/rate-limit-redis.tgz
> npm install https://github.com/express-rate-limit/rate-limit-redis/releases/download/v{version}/rate-limit-redis.tgz
# Using yarn or pnpm
> yarn/pnpm add https://github.com/wyattjoh/rate-limit-redis/releases/download/v{version}/rate-limit-redis.tgz
> yarn/pnpm add https://github.com/express-rate-limit/rate-limit-redis/releases/download/v{version}/rate-limit-redis.tgz
```

@@ -57,3 +57,3 @@

```ts
const RedisStore = require("rate-limit-redis");
const RedisStore = require('rate-limit-redis')
```

@@ -64,3 +64,3 @@

```ts
import RedisStore from "rate-limit-redis";
import RedisStore from 'rate-limit-redis'
```

@@ -73,27 +73,27 @@

```ts
import rateLimit from "express-rate-limit";
import RedisStore from "rate-limit-redis";
import { createClient } from "redis";
import rateLimit from 'express-rate-limit'
import RedisStore from 'rate-limit-redis'
import { createClient } from 'redis'
// Create a `node-redis` client
const client = createClient({
// ... (see https://github.com/redis/node-redis/blob/master/docs/client-configuration.md)
});
// ... (see https://github.com/redis/node-redis/blob/master/docs/client-configuration.md)
})
// Then connect to the Redis server
await client.connect();
await client.connect()
// Create and use the rate limiter
const limiter = rateLimit({
// Rate limiter configuration
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
// Rate limiter configuration
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
// Redis store configuration
store: new RedisStore({
sendCommand: (...args: string[]) => client.sendCommand(args),
}),
});
app.use(limiter);
// Redis store configuration
store: new RedisStore({
sendCommand: (...args: string[]) => client.sendCommand(args),
}),
})
app.use(limiter)
```

@@ -104,8 +104,8 @@

```ts
import rateLimit from "express-rate-limit";
import RedisStore from "rate-limit-redis";
import RedisClient from "ioredis";
import rateLimit from 'express-rate-limit'
import RedisStore from 'rate-limit-redis'
import RedisClient from 'ioredis'
// Create a `ioredis` client
const client = new RedisClient();
const client = new RedisClient()
// ... (see https://github.com/luin/ioredis#connect-to-redis)

@@ -115,15 +115,15 @@

const limiter = rateLimit({
// Rate limiter configuration
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
// Rate limiter configuration
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
// Redis store configuration
store: new RedisStore({
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
sendCommand: (...args: string[]) => client.call(...args),
}),
});
app.use(limiter);
// Redis store configuration
store: new RedisStore({
// @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis
sendCommand: (...args: string[]) => client.call(...args),
}),
})
app.use(limiter)
```

@@ -139,3 +139,3 @@

```ts
(...args: string[]) => Promise<number> | number
;(...args: string[]) => Promise<number> | number
```

@@ -170,2 +170,4 @@

MIT © [Wyatt Johnson](https://github.com/wyattjoh)
MIT © [Wyatt Johnson](https://github.com/wyattjoh),
[Nathan Friedly](https://nfriedly.com),
[Vedant K](https://github.com/gamemaker1)
{
"include": ["src/"],
"exclude": ["node_modules/"],
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"declaration": true,
"strict": true,
"noUnusedLocals": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"esModuleInterop": true
}
"include": ["source/"],
"exclude": ["node_modules/"],
"extends": "@express-rate-limit/tsconfig",
"compilerOptions": {
"target": "es2022"
}
}

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