diff --git a/connect-timeout/connect-timeout-tests.ts b/connect-timeout/connect-timeout-tests.ts new file mode 100644 index 000000000..920c7fdc6 --- /dev/null +++ b/connect-timeout/connect-timeout-tests.ts @@ -0,0 +1,28 @@ +/// +/// +/// +/// + +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); diff --git a/connect-timeout/connect-timeout.d.ts b/connect-timeout/connect-timeout.d.ts new file mode 100644 index 000000000..8494a3afb --- /dev/null +++ b/connect-timeout/connect-timeout.d.ts @@ -0,0 +1,36 @@ +// Type definitions for connect-timeout +// Project: https://github.com/expressjs/timeout +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +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; +} diff --git a/express-brute-mongo/express-brute-mongo-tests.ts b/express-brute-mongo/express-brute-mongo-tests.ts new file mode 100644 index 000000000..a4512782b --- /dev/null +++ b/express-brute-mongo/express-brute-mongo-tests.ts @@ -0,0 +1,27 @@ +/// +/// +/// + +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!"); +}); diff --git a/express-brute-mongo/express-brute-mongo.d.ts b/express-brute-mongo/express-brute-mongo.d.ts new file mode 100644 index 000000000..bc4d5e43d --- /dev/null +++ b/express-brute-mongo/express-brute-mongo.d.ts @@ -0,0 +1,22 @@ +// Type definitions for express-brute-mongo +// Project: https://github.com/auth0/express-brute-mongo +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +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); + } +} diff --git a/express-brute/express-brute-tests.ts b/express-brute/express-brute-tests.ts new file mode 100644 index 000000000..ea0f2f5b4 --- /dev/null +++ b/express-brute/express-brute-tests.ts @@ -0,0 +1,16 @@ +/// + +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!"); +}); diff --git a/express-brute/express-brute.d.ts b/express-brute/express-brute.d.ts new file mode 100644 index 000000000..7242d44dc --- /dev/null +++ b/express-brute/express-brute.d.ts @@ -0,0 +1,129 @@ +// Type definitions for express-brute +// Project: https://github.com/AdamPflug/express-brute +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +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; +} diff --git a/express-validator/express-validator.d.ts b/express-validator/express-validator.d.ts index 428c90afd..78073231b 100644 --- a/express-validator/express-validator.d.ts +++ b/express-validator/express-validator.d.ts @@ -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; diff --git a/nodemailer/nodemailer-tests.ts b/nodemailer/nodemailer-tests.ts index 1d99046c0..a991096d5 100644 --- a/nodemailer/nodemailer-tests.ts +++ b/nodemailer/nodemailer-tests.ts @@ -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 ✔ ', // sender address @@ -24,5 +38,3 @@ var mailOptions: nodemailer.SendMailOptions = { transporter.sendMail(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => { // nothing }); - - diff --git a/nodemailer/nodemailer.d.ts b/nodemailer/nodemailer.d.ts index e0d1300b0..e7d09f54f 100644 --- a/nodemailer/nodemailer.d.ts +++ b/nodemailer/nodemailer.d.ts @@ -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; } diff --git a/validator/validator-tests.ts b/validator/validator-tests.ts index b7f45d427..c5a55f59c 100644 --- a/validator/validator-tests.ts +++ b/validator/validator-tests.ts @@ -19,6 +19,8 @@ validator.isURL("sample"); validator.isFQDN("sample"); +validator.isMACAddress("sample"); + validator.isIP("sample"); validator.isAlpha("sample"); diff --git a/validator/validator.d.ts b/validator/validator.d.ts index 05a391fa4..2b29efac0 100644 --- a/validator/validator.d.ts +++ b/validator/validator.d.ts @@ -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.