Socket
Socket
Sign inDemoInstall

koa-simple-ratelimit

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-simple-ratelimit - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0

10

dist/index.d.ts

@@ -18,3 +18,3 @@ export declare type RatelimitExpires = (expires: number) => string;

*/
id?: (ctx: any) => any;
id?: (ctx: any) => string | false;
/**

@@ -25,9 +25,9 @@ * redis key prefix default: "limit"

/**
* array of ids to whitelist
* array of ids to always allow
*/
whitelist?: string[];
allowlist?: string[];
/**
* array of ids to blacklist
* array of ids to always deny
*/
blacklist?: string[];
blocklist?: string[];
/**

@@ -34,0 +34,0 @@ * throw on rate limit exceeded default: false

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.ratelimit = void 0;
const debug_1 = __importDefault(require("debug"));

@@ -34,9 +35,22 @@ const ms_1 = __importDefault(require("ms"));

function ratelimit(options) {
const opts = Object.assign({ max: 2500, duration: 3600000, throw: false, prefix: 'limit', id: (ctx) => ctx.ip, whitelist: [], blacklist: [], headers: {
const opts = {
max: 2500,
duration: 3600000,
throw: false,
prefix: 'limit',
id: (ctx) => ctx.ip,
allowlist: [],
blocklist: [],
headers: {
remaining: 'X-RateLimit-Remaining',
reset: 'X-RateLimit-Reset',
total: 'X-RateLimit-Limit',
}, errorMessage: (exp) => `Rate limit exceeded, retry in ${ms_1.default(exp, { long: true })}.` }, options);
},
errorMessage: (exp) => `Rate limit exceeded, retry in ${ms_1.default(exp, { long: true })}.`,
...options,
};
const { remaining = 'X-RateLimit-Remaining', reset = 'X-RateLimit-Reset', total = 'X-RateLimit-Limit', } = opts.headers || {};
return async function (ctx, next) {
// eslint-disable-next-line func-names
return async function rateLimitMiddleware(ctx, next) {
var _a, _b;
const id = opts.id(ctx);

@@ -46,8 +60,6 @@ if (id === false) {

}
// Whitelist
if (opts.whitelist && opts.whitelist.includes(id)) {
if ((_a = opts.allowlist) === null || _a === void 0 ? void 0 : _a.includes(id)) {
return next();
}
// Blacklist
if (opts.blacklist && opts.blacklist.includes(id)) {
if ((_b = opts.blocklist) === null || _b === void 0 ? void 0 : _b.includes(id)) {
return ctx.throw(403);

@@ -54,0 +66,0 @@ }

{
"name": "koa-simple-ratelimit",
"version": "4.0.2",
"version": "5.0.0",
"description": "Simple Rate limiter middleware for koa v2",

@@ -27,4 +27,3 @@ "repository": "scttcper/koa-simple-ratelimit",

"test:watch": "jest --watch --runInBand",
"test:ci": "jest --ci --runInBand --reporters=default --reporters=jest-junit --coverage",
"semantic-release": "semantic-release"
"test:ci": "jest --ci --runInBand --reporters=default --reporters=jest-junit --coverage"
},

@@ -36,23 +35,20 @@ "dependencies": {

"devDependencies": {
"@ctrl/eslint-config": "1.0.3",
"@jest/globals": "26.1.0",
"@types/debug": "4.1.5",
"@types/jest": "25.2.1",
"@types/ioredis": "4.17.2",
"@types/koa": "2.11.3",
"@types/node": "13.13.4",
"@types/redis": "2.8.18",
"@types/supertest": "2.0.8",
"@typescript-eslint/eslint-plugin": "2.30.0",
"@typescript-eslint/parser": "2.30.0",
"eslint": "6.8.0",
"eslint-config-xo-space": "0.24.0",
"eslint-config-xo-typescript": "0.28.0",
"eslint-plugin-import": "2.20.2",
"ioredis": "4.16.3",
"jest": "25.5.3",
"jest-junit": "10.0.0",
"koa": "2.11.0",
"@types/ms": "0.7.31",
"@types/node": "14.0.23",
"@types/redis": "2.8.25",
"@types/supertest": "2.0.10",
"delay": "4.3.0",
"ioredis": "4.17.3",
"jest": "26.1.0",
"jest-junit": "11.0.1",
"koa": "2.13.0",
"redis": "3.0.2",
"semantic-release": "17.0.7",
"supertest": "4.0.2",
"ts-jest": "25.4.0",
"typescript": "3.8.3"
"ts-jest": "26.1.3",
"typescript": "3.9.7"
},

@@ -67,4 +63,4 @@ "jest": {

"engines": {
"node": ">=8"
"node": ">=10"
}
}

@@ -57,4 +57,4 @@ # koa-simple-ratelimit

- `id` id to compare requests [ip]
- `whitelist` array of ids to whitelist
- `blacklist` array of ids to blacklist
- `allowlist` array of ids to allowlist
- `blocklist` array of ids to blocklist
- `prefix` redis key prefix ["limit"]

@@ -61,0 +61,0 @@

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