Skip to content

Commit 5a8fc5e

Browse files
committed
Merge pull request DefinitelyTyped#7092 from cyrilschumacher/master
Add and update definitions
2 parents a81c34d + b8c6180 commit 5a8fc5e

File tree

11 files changed

+284
-7
lines changed

11 files changed

+284
-7
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="connect-timeout.d.ts" />
2+
/// <reference path="../body-parser/body-parser.d.ts" />
3+
/// <reference path="../cookie-parser/cookie-parser.d.ts" />
4+
/// <reference path="../express/express.d.ts" />
5+
6+
import express = require("express");
7+
import timeout = require("connect-timeout");
8+
import bodyParser = require("body-parser");
9+
import cookieParser = require("cookie-parser");
10+
11+
// example of using this top-level; note the use of haltOnTimedout
12+
// after every middleware; it will stop the request flow on a timeout
13+
var app = express();
14+
app.use(timeout("5s", { respond: false }));
15+
app.use(bodyParser());
16+
app.use(haltOnTimedout);
17+
app.use(cookieParser());
18+
app.use(haltOnTimedout);
19+
20+
// Add your routes here, etc.
21+
22+
function haltOnTimedout(req: express.Request, res: express.Response, next: Function) {
23+
if (!req.timedout) {
24+
next();
25+
}
26+
}
27+
28+
app.listen(3000);

connect-timeout/connect-timeout.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Type definitions for connect-timeout
2+
// Project: https://github.com/expressjs/timeout
3+
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../express/express.d.ts" />
7+
8+
declare module Express {
9+
export interface Request {
10+
/**
11+
* @summary Clears the timeout on the request.
12+
*/
13+
clearTimeout(): void;
14+
15+
/**
16+
*
17+
* @return {boolean} true if timeout fired; false otherwise.
18+
*/
19+
timedout(event: string, message: string): boolean;
20+
}
21+
}
22+
23+
declare module "connect-timeout" {
24+
import express = require("express");
25+
26+
interface TimeoutOptions extends Object {
27+
/**
28+
* @summary Controls if this module will "respond" in the form of forwarding an error.
29+
* @type {boolean}
30+
*/
31+
respond: boolean;
32+
}
33+
34+
function timeout(timeout: string, options?: TimeoutOptions): express.RequestHandler;
35+
export = timeout;
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference path="../express-brute/express-brute.d.ts"/>
2+
/// <reference path="../mongodb/mongodb.d.ts"/>
3+
/// <reference path="express-brute-mongo.d.ts"/>
4+
5+
import express = require("express");
6+
import ExpressBrute = require("express-brute");
7+
import MongoStore = require("express-brute-mongo");
8+
import mongodb = require("mongodb");
9+
var MongoClient = mongodb.MongoClient;
10+
11+
var store = new MongoStore(ready => {
12+
MongoClient.connect("mongodb://127.0.0.1:27017/test", (err, db) => {
13+
if (err) {
14+
throw err;
15+
}
16+
17+
var collection = db.collection("bruteforce-store");
18+
ready(collection);
19+
});
20+
});
21+
22+
var app = express();
23+
var bruteforce = new ExpressBrute(store);
24+
25+
app.post("/auth", bruteforce.prevent, (req, res, next) => {
26+
res.send("Success!");
27+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Type definitions for express-brute-mongo
2+
// Project: https://github.com/auth0/express-brute-mongo
3+
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../express/express.d.ts" />
7+
8+
declare module "express-brute-mongo" {
9+
/**
10+
* @summary MongoDB store adapter.
11+
* @class
12+
*/
13+
export = class MongoStore {
14+
/**
15+
* @summary Constructor.
16+
* @constructor
17+
* @param {Function} getCollection The collection.
18+
* @param {Object} options The otpions.
19+
*/
20+
constructor(getCollection: (collection: any) => void, options?: Object);
21+
}
22+
}

express-brute/express-brute-tests.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path="express-brute.d.ts"/>
2+
3+
import express = require("express");
4+
import ExpressBrute = require("express-brute");
5+
6+
var store = new ExpressBrute.MemoryStore();
7+
store = new ExpressBrute.MemoryStore({ prefix: "prefix" });
8+
store.set("key", "value", 0, (error: any) => { });
9+
store.get("key", (error: any, data: Object) => { });
10+
store.reset("key", (error: any) => { });
11+
12+
var app = express();
13+
var bruteforce = new ExpressBrute(store);
14+
app.post("/auth", bruteforce.prevent, (req, res, next) => {
15+
res.send("Success!");
16+
});

express-brute/express-brute.d.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Type definitions for express-brute
2+
// Project: https://github.com/AdamPflug/express-brute
3+
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher/>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
/// <reference path="../express/express.d.ts" />
7+
8+
declare module "express-brute" {
9+
import express = require("express");
10+
11+
/**
12+
* @summary Options for {@link MemoryStore} class.
13+
* @interface
14+
*/
15+
interface MemoryStoreOptions {
16+
/**
17+
* @summary Key prefix.
18+
* @type {string}
19+
*/
20+
prefix: string;
21+
}
22+
23+
/**
24+
* @summary Options for {@link ExpressBrute#getMiddleware} class.
25+
* @interface
26+
*/
27+
interface ExpressBruteMiddleware {
28+
/**
29+
* @summary Allows you to override the value of failCallback for this middleware.
30+
* @type {Function}
31+
*/
32+
failCallback: Function;
33+
34+
/**
35+
* @summary Disregard IP address when matching requests if set to true. Defaults to false.
36+
* @type {boolean}
37+
*/
38+
ignoreIP: boolean;
39+
40+
/**
41+
* @summary Key.
42+
* @type {any}
43+
*/
44+
key: any;
45+
}
46+
47+
/**
48+
* @summary Middleware.
49+
* @class
50+
*/
51+
class ExpressBrute {
52+
/**
53+
* @summary Constructor.
54+
* @constructor
55+
* @param {any} store The store.
56+
*/
57+
constructor(store: any);
58+
59+
/**
60+
* @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.
61+
* @param {Object} options The options.
62+
*/
63+
getMiddleware(options: ExpressBruteMiddleware): express.RequestHandler;
64+
65+
/**
66+
* @summary Uses the current proxy trust settings to get the current IP from a request object.
67+
* @param {Request} request The HTTP request.
68+
* @return {RequestHandler} The Request handler.
69+
*/
70+
getIPFromRequest(request: express.Request): express.RequestHandler;
71+
72+
/**
73+
* @summary Middleware that will bounce requests that happen faster than the current wait time by calling failCallback.
74+
* @param {Request} request The HTTP request.
75+
* @param {Response} response The HTTP response.
76+
* @param {Function} next The next middleware.
77+
* @return {RequestHandler} The Request handler.
78+
*/
79+
prevent(request: express.Request, response: express.Response, next: Function): express.RequestHandler;
80+
81+
/**
82+
* @summary Resets the wait time between requests back to its initial value.
83+
* @param {string} ip The IP address.
84+
* @param {string} key The key. response.
85+
* @param {Function} next The next middleware.
86+
* @return {RequestHandler} The Request handler.
87+
*/
88+
reset(ip: string, key: string, next: Function): express.RequestHandler;
89+
}
90+
91+
module ExpressBrute {
92+
/**
93+
* @summary In-memory store.
94+
* @class
95+
*/
96+
export class MemoryStore {
97+
/**
98+
* @summary Constructor.
99+
* @constructor
100+
* @param {Object} options The options.
101+
*/
102+
constructor(options?: MemoryStoreOptions);
103+
/**
104+
* @summary Gets key value.
105+
* @param {string} key The key name.
106+
* @param {Function} callbck The callback.
107+
*/
108+
get(key: string, callback: (error: any, data: Object) => void): void;
109+
110+
/**
111+
* @summary Sets the key value.
112+
* @param {string} key The name.
113+
* @param {string} value The value.
114+
* @param {number} lifetime The lifetime.
115+
* @param {Function} callback The callback.
116+
*/
117+
set(key: string, value: any, lifetime: number, callback: (error: any) => void): void;
118+
119+
/**
120+
* @summary Deletes the key.
121+
* @param {string} key The name.
122+
* @param {Function} callback The callback.
123+
*/
124+
reset(key: string, callback: (error: any) => void): void;
125+
}
126+
}
127+
128+
export = ExpressBrute;
129+
}

express-validator/express-validator.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ declare module ExpressValidator {
6666
* Accepts http, https, ftp
6767
*/
6868
isUrl(): Validator;
69+
6970
/**
7071
* Combines isIPv4 and isIPv6
7172
*/
7273
isIP(): Validator;
7374
isIPv4(): Validator;
7475
isIPv6(): Validator;
76+
isMACAddress(): Validator;
7577
isAlpha(): Validator;
7678
isAlphanumeric(): Validator;
7779
isNumeric(): Validator;

nodemailer/nodemailer-tests.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ var transporter: nodemailer.Transporter = nodemailer.createTransport({
1111
}
1212
});
1313

14+
// create reusable transporter object using SMTP transport and set default values for mail options.
15+
transporter = nodemailer.createTransport({
16+
service: 'Gmail',
17+
auth: {
18+
19+
pass: 'userpass'
20+
}
21+
}, {
22+
from: 'sender@address',
23+
headers: {
24+
'My-Awesome-Header': '123'
25+
}
26+
});
27+
1428
// setup e-mail data with unicode symbols
1529
var mailOptions: nodemailer.SendMailOptions = {
1630
from: 'Fred Foo ✔ <[email protected]>', // sender address
@@ -24,5 +38,3 @@ var mailOptions: nodemailer.SendMailOptions = {
2438
transporter.sendMail(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
2539
// nothing
2640
});
27-
28-

nodemailer/nodemailer.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ declare module "nodemailer" {
5151
/**
5252
* Create a direct transporter
5353
*/
54-
export function createTransport(options?: directTransport.DirectOptions): Transporter;
54+
export function createTransport(options?: directTransport.DirectOptions, defaults?: Object): Transporter;
5555
/**
5656
* Create an SMTP transporter
5757
*/
58-
export function createTransport(options?: smtpTransport.SmtpOptions): Transporter;
58+
export function createTransport(options?: smtpTransport.SmtpOptions, defaults?: Object): Transporter;
5959
/**
6060
* Create a transporter from a given implementation
6161
*/
62-
export function createTransport(transport: Transport): Transporter;
62+
export function createTransport(transport: Transport, defaults?: Object): Transporter;
6363
}

validator/validator-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ validator.isURL("sample");
1919

2020
validator.isFQDN("sample");
2121

22+
validator.isMACAddress("sample");
23+
2224
validator.isIP("sample");
2325

2426
validator.isAlpha("sample");

validator/validator.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface IEmailoptions {
2222
lowercase?: boolean
2323
}
2424

25-
// callback type for #extend
25+
// callback type for #extend
2626
interface IExtendCallback {
2727
(argv: string): any
2828
}
@@ -54,6 +54,9 @@ interface IValidatorStatic {
5454
// check if the string is a fully qualified domain name (e.g. domain.com).
5555
isFQDN(str: string, options?: IFQDNoptions): boolean;
5656

57+
// check if the string is a MAC address.
58+
isMACAddress(str: string): boolean;
59+
5760
// check if the string is an IP (version 4 or 6).
5861
isIP(str: string, version?: number): boolean;
5962

@@ -177,7 +180,7 @@ interface IValidatorStatic {
177180
// remove characters that do not appear in the whitelist.
178181
whitelist(input: string, chars: string): string;
179182

180-
// remove characters that appear in the blacklist.
183+
// remove characters that appear in the blacklist.
181184
blacklist(input: string, chars: string): string;
182185

183186
// canonicalize an email address.

0 commit comments

Comments
 (0)