Merge pull request #19792 from scottharwell/express-brute-redis

Add typings for express-brute-redis
This commit is contained in:
Benjamin Lichtman
2017-09-20 12:52:53 -07:00
committed by GitHub
4 changed files with 93 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import express = require("express");
import expressbrute = require("express-brute");
import expressbruteredis = require("express-brute-redis");
const store: expressbruteredis = new expressbruteredis({
host: "localhost",
port: 6379,
db: "0"
});
const bruteforce: expressbrute = new expressbrute(store, {
failCallback: (req: express.Request, res: express.Response, next: express.NextFunction, validTime: Date) => {
// Don't send a message back to the user in production
res.send("You cannot submit a request again until: " + validTime);
}
});
const app: express.Express = express();
app.post("/", bruteforce.prevent, (req, res, next) => {
res.send("Success!");
});

48
types/express-brute-redis/index.d.ts vendored Normal file
View File

@@ -0,0 +1,48 @@
// Type definitions for express-brute-redis 0.0
// Project: https://github.com/AdamPflug/express-brute-redis
// Definitions by: Scott Harwell <https://github.com/scottharwell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { ClientOpts } from "redis";
/**
* @summary Redis store for Express Brute
* @class
*/
declare class express_brute_redis {
/**
* Default options for the Redis client
*/
static defaults: ClientOpts;
/**
* @summary constructor
* @param options Options to configure the Redis client.
*/
constructor(options?: ClientOpts, ...args: any[]);
/**
* @summary Sets a key in Redis storage.
* @param key
* @param value
* @param lifetime
* @param callback
*/
set(key: string, value: string, lifetime?: number, callback?: (sender: express_brute_redis) => void): void;
/**
* @summary Gets a key in Redis storage.
* @param key
* @param callback
*/
get(key: string, callback?: (err: Error, data: any) => void): void;
/**
* @summary Resets a key in Redis storage.
* @param key
* @param callback
*/
reset(key: string, callback?: (err: Error, data: any) => void, ...args: any[]): void;
}
export = express_brute_redis;

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"express-brute-redis-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }