Add options for "express-brute".

Add definition for "i18next-sprintf-postprocessor".
This commit is contained in:
Cyril Schumacher
2016-01-14 19:17:06 +01:00
parent 5f2a5d25bb
commit 257f49655e
4 changed files with 117 additions and 67 deletions
+82 -66
View File
@@ -45,85 +45,101 @@ declare module "express-brute" {
}
/**
* @summary Middleware.
* @summary Options for {@link ExpressBrute} class.
* @interface
*/
interface ExpressBruteOptions {
freeRetries: number;
proxyDepth: number;
attachResetToRequest: boolean;
refreshTimeoutOnRequest: boolean;
minWait: number;
maxWait: number;
lifetime: number;
failCallback: (req: express.Request, res: express.Response, next: Function, nextValidRequestDate: any) => void;
handleStoreError: 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
*/
class ExpressBrute {
export class MemoryStore {
/**
* @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;
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 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.
* @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.
*/
getIPFromRequest(request: express.Request): express.RequestHandler;
set(key: string, value: any, lifetime: number, callback: (error: any) => void): void;
/**
* @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.
* @summary Deletes the key.
* @param {string} key The name.
* @param {Function} callback The callback.
*/
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;
reset(key: string, callback: (error: any) => void): void;
}
}
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;
export = ExpressBrute;
}
@@ -0,0 +1,10 @@
///<reference path="i18next-sprintf-postProcessor.d.ts"/>
import * as i18next from "i18next";
import sprintf from "i18next-sprintf-postprocessor";
function initTest() {
const i18nextOptions = {};
i18next.use(sprintf).init(i18nextOptions);
i18next.init({ overloadTranslationOptionHandler: sprintf.overloadTranslationOptionHandler });
}
@@ -0,0 +1,17 @@
// Type definitions for i18next-sprintf-postProcessor
// Project: https://github.com/i18next/i18next-sprintf-postProcessor
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../express/express.d.ts"/>
///<reference path="../i18next/i18next.d.ts"/>
declare module "i18next-sprintf-postprocessor" {
import i18next = require("i18next");
export default interface i18nextSprintfPostProcessor {
process(value: any, key: string, options: Object): void;
overloadTranslationOptionHandler(args: Array<any>): void;
}
//export default function sprintf(): any;
}
+8 -1
View File
@@ -8,6 +8,7 @@
/// <reference path="../express/express.d.ts" />
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../i18next-express-middleware/i18next-express-middleware.d.ts" />
/// <reference path="../i18next-sprintf-postprocessor/i18next-sprintf-postprocessor.d.ts" />
interface IResourceStore {
[language: string]: IResourceStoreLanguage;
@@ -29,7 +30,11 @@ interface I18nTranslateOptions extends I18nextOptions {
context?: any;
}
interface I18nextOptions {
interface i18nextSprintfPostProcessorStatic {
overloadTranslationOptionHandler: any;
}
interface I18nextOptions extends i18nextSprintfPostProcessorStatic {
lng?: string; // Default value: undefined
load?: string; // Default value: 'all'
preload?: string[]; // Default value: []
@@ -77,6 +82,8 @@ interface I18nextOptions {
// NOTE https://github.com/borisyankov/DefinitelyTyped/pull/5590
replace?: any;
overloadTranslationOptionHandler: (args: Array<any>) => void;
}
interface I18nextStatic {