Merge pull request #7092 from cyrilschumacher/master

Add and update definitions
This commit is contained in:
Horiuchi_H
2015-12-11 17:21:59 +09:00
11 changed files with 284 additions and 7 deletions
+28
View File
@@ -0,0 +1,28 @@
/// <reference path="connect-timeout.d.ts" />
/// <reference path="../body-parser/body-parser.d.ts" />
/// <reference path="../cookie-parser/cookie-parser.d.ts" />
/// <reference path="../express/express.d.ts" />
import express = require("express");
import timeout = require("connect-timeout");
import bodyParser = require("body-parser");
import cookieParser = require("cookie-parser");
// example of using this top-level; note the use of haltOnTimedout
// after every middleware; it will stop the request flow on a timeout
var app = express();
app.use(timeout("5s", { respond: false }));
app.use(bodyParser());
app.use(haltOnTimedout);
app.use(cookieParser());
app.use(haltOnTimedout);
// Add your routes here, etc.
function haltOnTimedout(req: express.Request, res: express.Response, next: Function) {
if (!req.timedout) {
next();
}
}
app.listen(3000);
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for connect-timeout
// Project: https://github.com/expressjs/timeout
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare module Express {
export interface Request {
/**
* @summary Clears the timeout on the request.
*/
clearTimeout(): void;
/**
*
* @return {boolean} true if timeout fired; false otherwise.
*/
timedout(event: string, message: string): boolean;
}
}
declare module "connect-timeout" {
import express = require("express");
interface TimeoutOptions extends Object {
/**
* @summary Controls if this module will "respond" in the form of forwarding an error.
* @type {boolean}
*/
respond: boolean;
}
function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
export = timeout;
}
@@ -0,0 +1,27 @@
/// <reference path="../express-brute/express-brute.d.ts"/>
/// <reference path="../mongodb/mongodb.d.ts"/>
/// <reference path="express-brute-mongo.d.ts"/>
import express = require("express");
import ExpressBrute = require("express-brute");
import MongoStore = require("express-brute-mongo");
import mongodb = require("mongodb");
var MongoClient = mongodb.MongoClient;
var store = new MongoStore(ready => {
MongoClient.connect("mongodb://127.0.0.1:27017/test", (err, db) => {
if (err) {
throw err;
}
var collection = db.collection("bruteforce-store");
ready(collection);
});
});
var app = express();
var bruteforce = new ExpressBrute(store);
app.post("/auth", bruteforce.prevent, (req, res, next) => {
res.send("Success!");
});
+22
View File
@@ -0,0 +1,22 @@
// Type definitions for express-brute-mongo
// Project: https://github.com/auth0/express-brute-mongo
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare module "express-brute-mongo" {
/**
* @summary MongoDB store adapter.
* @class
*/
export = class MongoStore {
/**
* @summary Constructor.
* @constructor
* @param {Function} getCollection The collection.
* @param {Object} options The otpions.
*/
constructor(getCollection: (collection: any) => void, options?: Object);
}
}
+16
View File
@@ -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!");
});
+129
View File
@@ -0,0 +1,129 @@
// Type definitions for express-brute
// 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;
}
+2
View File
@@ -66,12 +66,14 @@ declare module ExpressValidator {
* Accepts http, https, ftp
*/
isUrl(): Validator;
/**
* Combines isIPv4 and isIPv6
*/
isIP(): Validator;
isIPv4(): Validator;
isIPv6(): Validator;
isMACAddress(): Validator;
isAlpha(): Validator;
isAlphanumeric(): Validator;
isNumeric(): Validator;
+14 -2
View File
@@ -11,6 +11,20 @@ var transporter: nodemailer.Transporter = nodemailer.createTransport({
}
});
// create reusable transporter object using SMTP transport and set default values for mail options.
transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
}, {
from: 'sender@address',
headers: {
'My-Awesome-Header': '123'
}
});
// setup e-mail data with unicode symbols
var mailOptions: nodemailer.SendMailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
@@ -24,5 +38,3 @@ var mailOptions: nodemailer.SendMailOptions = {
transporter.sendMail(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
// nothing
});
+3 -3
View File
@@ -51,13 +51,13 @@ declare module "nodemailer" {
/**
* Create a direct transporter
*/
export function createTransport(options?: directTransport.DirectOptions): Transporter;
export function createTransport(options?: directTransport.DirectOptions, defaults?: Object): Transporter;
/**
* Create an SMTP transporter
*/
export function createTransport(options?: smtpTransport.SmtpOptions): Transporter;
export function createTransport(options?: smtpTransport.SmtpOptions, defaults?: Object): Transporter;
/**
* Create a transporter from a given implementation
*/
export function createTransport(transport: Transport): Transporter;
export function createTransport(transport: Transport, defaults?: Object): Transporter;
}
+2
View File
@@ -19,6 +19,8 @@ validator.isURL("sample");
validator.isFQDN("sample");
validator.isMACAddress("sample");
validator.isIP("sample");
validator.isAlpha("sample");
+5 -2
View File
@@ -22,7 +22,7 @@ interface IEmailoptions {
lowercase?: boolean
}
// callback type for #extend
// callback type for #extend
interface IExtendCallback {
(argv: string): any
}
@@ -54,6 +54,9 @@ interface IValidatorStatic {
// check if the string is a fully qualified domain name (e.g. domain.com).
isFQDN(str: string, options?: IFQDNoptions): boolean;
// check if the string is a MAC address.
isMACAddress(str: string): boolean;
// check if the string is an IP (version 4 or 6).
isIP(str: string, version?: number): boolean;
@@ -177,7 +180,7 @@ interface IValidatorStatic {
// remove characters that do not appear in the whitelist.
whitelist(input: string, chars: string): string;
// remove characters that appear in the blacklist.
// remove characters that appear in the blacklist.
blacklist(input: string, chars: string): string;
// canonicalize an email address.