From ca7293c5ae1bfd5d3a756ad0d275d2b0fbc8ce7a Mon Sep 17 00:00:00 2001 From: Cyril Schumacher Date: Sun, 22 Nov 2015 14:59:47 +0100 Subject: [PATCH] Add definition for "email-templates". Update definition for "helmet". --- email-templates/email-templates-tests.ts | 26 ++++++ email-templates/email-templates.d.ts | 54 +++++++++++ helmet/helmet-tests.ts | 25 ++--- helmet/helmet.d.ts | 114 +++++++++++++---------- 4 files changed, 161 insertions(+), 58 deletions(-) create mode 100644 email-templates/email-templates-tests.ts create mode 100644 email-templates/email-templates.d.ts diff --git a/email-templates/email-templates-tests.ts b/email-templates/email-templates-tests.ts new file mode 100644 index 0000000000..9b70728106 --- /dev/null +++ b/email-templates/email-templates-tests.ts @@ -0,0 +1,26 @@ +/// + +import EmailTemplates = require('email-templates'); + +var EmailTemplate = EmailTemplates.EmailTemplate; +var template = new EmailTemplate("./"); +var users = [ + { + email: 'pappa.pizza@spaghetti.com', + name: { + first: 'Pappa', + last: 'Pizza' + } + }, + { + email: 'mister.geppetto@spaghetti.com', + name: { + first: 'Mister', + last: 'Geppetto' + } + } +] + +var templates = users.map(function(user) { + return template.render(user); +}) diff --git a/email-templates/email-templates.d.ts b/email-templates/email-templates.d.ts new file mode 100644 index 0000000000..e3e1095c34 --- /dev/null +++ b/email-templates/email-templates.d.ts @@ -0,0 +1,54 @@ +// Type definitions for node-email-templates +// Project: https://github.com/niftylettuce/node-email-templates +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** + * @summary Interface for result of email template. + * @interface + */ +interface EmailTemplateResults { + /** + * @summary HTML result. + * @type {string} + */ + html: string; + + /** + * @summary Text result. + * @type {string} + */ + text: string; +} + +/** + * @summary Interface for callback of email callback. + * @interface + */ +interface EmailTemplateCallback { + /** + * @summary Callback signature. + */ + (err: Object, results: EmailTemplateResults): void; +} + +declare module "email-templates" { + /** + * @summary Email template class. + * @class + */ + export class EmailTemplate { + /** + * @summary Constructor. + * @param {string} templateDir The template directory. + */ + constructor(templateDir: string); + + /** + * @summary Render a single template. + * @param {EmailTemplateCallback|Object} locals The variables or callback function. + * @param {EmailTemplateCallback} callback The callback function. + */ + render(locals: EmailTemplateCallback|Object, callback?: EmailTemplateCallback): void; + } +} diff --git a/helmet/helmet-tests.ts b/helmet/helmet-tests.ts index 04cfcaf363..d2509a0224 100644 --- a/helmet/helmet-tests.ts +++ b/helmet/helmet-tests.ts @@ -1,59 +1,62 @@ /// +import express = require("express") import helmet = require("helmet"); +var app = express(); + /** * @summary Test for {@see helmet}. */ function helmetTest() { - helmet(); + app.use(helmet()); } /** * @summary Test for {@see helmet#xssFilter} function. */ function contentSecurityPolicyTest() { - helmet.xssFilter(); - helmet.xssFilter({ setOnOldIE: true }); + app.use(helmet.xssFilter()); + app.use(helmet.xssFilter({ setOnOldIE: true })); } /** * @summary Test for {@see helmet#frameguard} function. */ function frameguardTest() { - helmet.frameguard(); - helmet.frameguard("sameorigin"); + app.use(helmet.frameguard()); + app.use(helmet.frameguard("sameorigin")); } /** * @summary Test for {@see helmet#hsts} function. */ function hstsTest() { - helmet.hsts(); - helmet.hsts({ maxAge: 7776000000 }); + app.use(helmet.hsts()); + app.use(helmet.hsts({ maxAge: 7776000000 })); } /** * @summary Test for {@see helmet#ieNoOpen} function. */ function ieNoOpenTest() { - helmet.ieNoOpen(); + app.use(helmet.ieNoOpen()); } /** * @summary Test for {@see helmet#noSniff} function. */ function noSniffTest() { - helmet.noSniff(); + app.use(helmet.noSniff()); } /** * @summary Test for {@see helmet#publicKeyPins} function. */ function publicKeyPinsTest() { - helmet.publicKeyPins({ + app.use(helmet.publicKeyPins({ sha256s: ["AbCdEf123=", "ZyXwVu456="], includeSubdomains: true, reportUri: "http://example.com" - }); + })); } diff --git a/helmet/helmet.d.ts b/helmet/helmet.d.ts index fca15b926e..35d9bf3aef 100644 --- a/helmet/helmet.d.ts +++ b/helmet/helmet.d.ts @@ -3,55 +3,75 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface Helmet { - (): void; - - /** - * @summary Prevent clickjacking. - * @param {string} header The header. - */ - frameguard(header ?: string): void; - - /** - * @summary Hide "X-Powered-By" header. - * @param {Object} options The options. - */ - hidePoweredBy(options ?: Object): void; - - /** - * @summary Adds the "Strict-Transport-Security" header. - * @param {Object} options The options. - */ - hsts(options ?: Object): void; - - /** - * @summary Add the "X-Download-Options" header. - */ - ieNoOpen(): void; - - /** - * @summary Add the "Cache-Control" and "Pragma" headers to stop caching. - */ - nocache(options ?: Object): void; - - /** - * @summary Adds the "X-Content-Type-Options" header. - */ - noSniff(): void; - - /** - * @summary Adds the "Public-Key-Pins" header. - */ - publicKeyPins(options ?: Object): void; - - /** - * @summary Prevent Cross-site scripting attacks. - * @param {Object} options The options. - */ - xssFilter(options ?: Object): void; -} +/// declare module "helmet" { + import express = require("express"); + + /** + * @summary Interface for helmet class. + * @interface + */ + interface Helmet { + /** + * @summary Constructor. + * @return {RequestHandler} The Request handler. + */ + ():express.RequestHandler; + + /** + * @summary Prevent clickjacking. + * @param {string} header The header. + * @return {RequestHandler} The Request handler. + */ + frameguard(header ?: string):express.RequestHandler; + + /** + * @summary Hide "X-Powered-By" header. + * @param {Object} options The options. + * @return {RequestHandler} The Request handler. + */ + hidePoweredBy(options ?: Object):express.RequestHandler; + + /** + * @summary Adds the "Strict-Transport-Security" header. + * @param {Object} options The options. + * @return {RequestHandler} The Request handler. + */ + hsts(options ?: Object):express.RequestHandler; + + /** + * @summary Add the "X-Download-Options" header. + * @return {RequestHandler} The Request handler. + */ + ieNoOpen():express.RequestHandler; + + /** + * @summary Add the "Cache-Control" and "Pragma" headers to stop caching. + * @return {RequestHandler} The Request handler. + */ + noCache(options ?: Object):express.RequestHandler; + + /** + * @summary Adds the "X-Content-Type-Options" header. + * @return {RequestHandler} The Request handler. + */ + noSniff():express.RequestHandler; + + /** + * @summary Adds the "Public-Key-Pins" header. + * @return {RequestHandler} The Request handler. + */ + publicKeyPins(options ?: Object):express.RequestHandler; + + /** + * @summary Prevent Cross-site scripting attacks. + * @return {RequestHandler} The Request handler. + * @param {Object} options The options. + */ + xssFilter(options ?: Object):express.RequestHandler; + } + var helmet: Helmet; export = helmet; }