mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-07 16:30:12 +08:00
Add definition "express-brute".
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/// <reference path="express-brute.d.ts"/>
|
||||
|
||||
import express = require("express");
|
||||
import ExpressBrute = require("express-brute");
|
||||
|
||||
var store = new ExpressBrute.MemoryStore();
|
||||
store = new ExpressBrute.MemoryStore({ prefix: "prefix" });
|
||||
store.set("key", "value", 0, (error: any) => { });
|
||||
store.get("key", (error: any, data: Object) => { });
|
||||
store.reset("key", (error: any) => { });
|
||||
|
||||
var app = express();
|
||||
var bruteforce = new ExpressBrute(store);
|
||||
app.post("/auth", bruteforce.prevent, (req, res, next) => {
|
||||
res.send("Success!");
|
||||
});
|
||||
Vendored
+129
@@ -0,0 +1,129 @@
|
||||
// Type definitions for express-validator 2.9.0
|
||||
// Project: https://github.com/AdamPflug/express-brute
|
||||
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../express/express.d.ts" />
|
||||
|
||||
declare module "express-brute" {
|
||||
import express = require("express");
|
||||
|
||||
/**
|
||||
* @summary Options for {@link MemoryStore} class.
|
||||
* @interface
|
||||
*/
|
||||
interface MemoryStoreOptions {
|
||||
/**
|
||||
* @summary Key prefix.
|
||||
* @type {string}
|
||||
*/
|
||||
prefix: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Options for {@link ExpressBrute#getMiddleware} class.
|
||||
* @interface
|
||||
*/
|
||||
interface ExpressBruteMiddleware {
|
||||
/**
|
||||
* @summary Allows you to override the value of failCallback for this middleware.
|
||||
* @type {Function}
|
||||
*/
|
||||
failCallback: Function;
|
||||
|
||||
/**
|
||||
* @summary Disregard IP address when matching requests if set to true. Defaults to false.
|
||||
* @type {boolean}
|
||||
*/
|
||||
ignoreIP: boolean;
|
||||
|
||||
/**
|
||||
* @summary Key.
|
||||
* @type {any}
|
||||
*/
|
||||
key: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* @summary Middleware.
|
||||
* @class
|
||||
*/
|
||||
class ExpressBrute {
|
||||
/**
|
||||
* @summary Constructor.
|
||||
* @constructor
|
||||
* @param {any} store The store.
|
||||
*/
|
||||
constructor(store: any);
|
||||
|
||||
/**
|
||||
* @summary Generates middleware that will bounce requests with the same key and IP address that happen faster than the current wait time by calling failCallback.
|
||||
* @param {Object} options The options.
|
||||
*/
|
||||
getMiddleware(options: ExpressBruteMiddleware): express.RequestHandler;
|
||||
|
||||
/**
|
||||
* @summary Uses the current proxy trust settings to get the current IP from a request object.
|
||||
* @param {Request} request The HTTP request.
|
||||
* @return {RequestHandler} The Request handler.
|
||||
*/
|
||||
getIPFromRequest(request: express.Request): express.RequestHandler;
|
||||
|
||||
/**
|
||||
* @summary Middleware that will bounce requests that happen faster than the current wait time by calling failCallback.
|
||||
* @param {Request} request The HTTP request.
|
||||
* @param {Response} response The HTTP response.
|
||||
* @param {Function} next The next middleware.
|
||||
* @return {RequestHandler} The Request handler.
|
||||
*/
|
||||
prevent(request: express.Request, response: express.Response, next: Function): express.RequestHandler;
|
||||
|
||||
/**
|
||||
* @summary Resets the wait time between requests back to its initial value.
|
||||
* @param {string} ip The IP address.
|
||||
* @param {string} key The key. response.
|
||||
* @param {Function} next The next middleware.
|
||||
* @return {RequestHandler} The Request handler.
|
||||
*/
|
||||
reset(ip: string, key: string, next: Function): express.RequestHandler;
|
||||
}
|
||||
|
||||
module ExpressBrute {
|
||||
/**
|
||||
* @summary In-memory store.
|
||||
* @class
|
||||
*/
|
||||
export class MemoryStore {
|
||||
/**
|
||||
* @summary Constructor.
|
||||
* @constructor
|
||||
* @param {Object} options The options.
|
||||
*/
|
||||
constructor(options?: MemoryStoreOptions);
|
||||
/**
|
||||
* @summary Gets key value.
|
||||
* @param {string} key The key name.
|
||||
* @param {Function} callbck The callback.
|
||||
*/
|
||||
get(key: string, callback: (error: any, data: Object) => void): void;
|
||||
|
||||
/**
|
||||
* @summary Sets the key value.
|
||||
* @param {string} key The name.
|
||||
* @param {string} value The value.
|
||||
* @param {number} lifetime The lifetime.
|
||||
* @param {Function} callback The callback.
|
||||
*/
|
||||
set(key: string, value: any, lifetime: number, callback: (error: any) => void): void;
|
||||
|
||||
/**
|
||||
* @summary Deletes the key.
|
||||
* @param {string} key The name.
|
||||
* @param {Function} callback The callback.
|
||||
*/
|
||||
reset(key: string, callback: (error: any) => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = ExpressBrute;
|
||||
}
|
||||
Reference in New Issue
Block a user