Upgrade nodemailer typings to 1.0

This commit is contained in:
Rogier Schouten 2015-04-14 17:47:16 +02:00
parent ed38db403a
commit 231e5fd730
10 changed files with 504 additions and 207 deletions

View File

@ -604,7 +604,10 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
* [:link:](mdns/mdns.d.ts) [node_mdns](https://github.com/agnat/node_mdns) by [Stefan Steinhart](https://github.com/reppners)
* [:link:](node_redis/node_redis.d.ts) [node_redis](https://github.com/mranney/node_redis) by [Boris Yankov](https://github.com/borisyankov)
* [:link:](each/each.d.ts) [NodeEach](http://www.adaltas.com/projects/node-each) by [Michael Zabka](https://github.com/misak113)
* [:link:](nodemailer/nodemailer.d.ts) [Nodemailer](https://github.com/andris9/Nodemailer) by [Vincent Bortone](https://github.com/vbortone)
* [:link:](nodemailer/nodemailer.d.ts) [Nodemailer](https://github.com/andris9/Nodemailer) by [Rogier Schouten](https://github.com/rogierschouten)
* [:link:](nodemailer-direct-transport/nodemailer-direct-transport.d.ts) [Nodemailer](https://github.com/andris9/nodemailer-direct-transport) by [Rogier Schouten](https://github.com/rogierschouten)
* [:link:](nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts) [Nodemailer](https://github.com/andris9/nodemailer-smptp-transport) by [Rogier Schouten](https://github.com/rogierschouten)
* [:link:](nodemailer-smtp-pool/nodemailer-smtp-pool.d.ts) [Nodemailer](https://github.com/andris9/nodemailer-smtp-pool) by [Rogier Schouten](https://github.com/rogierschouten)
* [:link:](nodeunit/nodeunit.d.ts) [nodeunit](https://github.com/caolan/nodeunit) by [Jeff Goddard](https://github.com/jedigo)
* [:link:](nomnom/nomnom.d.ts) [nomnom](https://github.com/harthur/nomnom) by [Paul Vick](https://github.com/panopticoncentral)
* [:link:](nopt/nopt.d.ts) [nopt](https://github.com/npm/nopt) by [jbondc](https://github.com/jbondc)

View File

@ -0,0 +1,22 @@
/// <reference path="nodemailer-direct-transport.d.ts" />
import directTransport = require('nodemailer-direct-transport');
var opts: directTransport.DirectOptions = {
name: "harry"
};
var transport: nodemailer.Transport = directTransport(opts);
// setup e-mail data with unicode symbols
var mailOptions: nodemailer.SendMailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
};
transport.send(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
// nothing
});

View File

@ -0,0 +1,35 @@
// Type definitions for nodemailer-direct-transport 1.0.2
// Project: https://github.com/andris9/nodemailer-direct-transport
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../nodemailer/nodemailer-types.d.ts" />
declare module "nodemailer-direct-transport" {
module directTransport {
export interface AuthOptions {
user?: string;
pass?: string;
xoauth2?: any;
}
export interface DirectOptions {
/**
* optional hostname of the client, used for identifying to the server
*/
name?: string;
/**
* if true, the connection emits all traffic between client and server as 'log' events
*/
debug?: boolean;
}
}
function directTransport(options: directTransport.DirectOptions): nodemailer.Transport;
export = directTransport;
}

View File

@ -0,0 +1,23 @@
/// <reference path="nodemailer-smtp-pool.d.ts" />
import smtpPool = require('nodemailer-smtp-pool');
var opts: smtpPool.SmtpPoolOptions = {
maxConnections: 5,
maxMessages: 10
};
var transport: nodemailer.Transport = smtpPool(opts);
// setup e-mail data with unicode symbols
var mailOptions: nodemailer.SendMailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
};
transport.send(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
// nothing
});

View File

@ -0,0 +1,88 @@
// Type definitions for nodemailer-smtp-pool 1.0.1
// Project: https://github.com/andris9/nodemailer-smtp-pool
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../nodemailer/nodemailer-types.d.ts" />
declare module "nodemailer-smtp-pool" {
import tls = require("tls");
module smtpPool {
export interface AuthOptions {
user?: string;
pass?: string;
xoauth2?: any;
}
export interface SmtpPoolOptions {
/**
* is the port to connect to (defaults to 25 or 465)
*/
port?: number;
/**
* is the hostname or IP address to connect to (defaults to 'localhost')
*/
host?: string;
/**
* defines if the connection should use SSL (if true) or not (if false)
*/
secure?: boolean;
/**
* defines authentication data (see authentication section below)
*/
auth?: AuthOptions;
/**
* turns off STARTTLS support if true
*/
ignoreTLS?: boolean;
/**
* optional hostname of the client, used for identifying to the server
*/
name?: string;
/**
* is the local interface to bind to for network connections
*/
localAddress?: string;
/**
* how many milliseconds to wait for the connection to establish
*/
connectionTimeout?: number;
/**
* how many milliseconds to wait for the greeting after connection is established
*/
greetingTimeout?: number;
/**
* how many milliseconds of inactivity to allow
*/
socketTimeout?: number;
/**
* if true, the connection emits all traffic between client and server as 'log' events
*/
debug?: boolean;
/**
* defines preferred authentication method, eg. 'PLAIN'
*/
authMethod?: string;
/**
* defines additional options to be passed to the socket constructor, eg. {rejectUnauthorized: true}
*/
tls?: tls.ConnectionOptions;
/**
* (defaults to 5) is the count of maximum simultaneous connections to make against the SMTP server
*/
maxConnections?: number;
/**
* (defaults to 100) limits the message count to be sent using a single connection. After maxMessages messages the connection is dropped and a new one is created for the following messages
*/
maxMessages?: number;
}
}
function smtpPool(options: smtpPool.SmtpPoolOptions): nodemailer.Transport;
export = smtpPool;
}

View File

@ -0,0 +1,23 @@
/// <reference path="nodemailer-smtp-transport.d.ts" />
import smtpTransport = require('nodemailer-smtp-transport');
var opts: smtpTransport.SmtpOptions = {
host: "localhost",
port: 25
};
var transport: nodemailer.Transport = smtpTransport(opts);
// setup e-mail data with unicode symbols
var mailOptions: nodemailer.SendMailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
};
transport.send(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
// nothing
});

View File

@ -0,0 +1,79 @@
// Type definitions for nodemailer-smtp-transport 1.0.2
// Project: https://github.com/andris9/nodemailer-smtp-transport
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../nodemailer/nodemailer-types.d.ts" />
declare module "nodemailer-smtp-transport" {
import tls = require("tls");
module smtpTransport {
export interface AuthOptions {
user?: string;
pass?: string;
xoauth2?: any;
}
export interface SmtpOptions {
/**
* is the port to connect to (defaults to 25 or 465)
*/
port?: number;
/**
* is the hostname or IP address to connect to (defaults to 'localhost')
*/
host?: string;
/**
* defines if the connection should use SSL (if true) or not (if false)
*/
secure?: boolean;
/**
* defines authentication data (see authentication section below)
*/
auth?: AuthOptions;
/**
* turns off STARTTLS support if true
*/
ignoreTLS?: boolean;
/**
* optional hostname of the client, used for identifying to the server
*/
name?: string;
/**
* is the local interface to bind to for network connections
*/
localAddress?: string;
/**
* how many milliseconds to wait for the connection to establish
*/
connectionTimeout?: number;
/**
* how many milliseconds to wait for the greeting after connection is established
*/
greetingTimeout?: number;
/**
* how many milliseconds of inactivity to allow
*/
socketTimeout?: number;
/**
* if true, the connection emits all traffic between client and server as 'log' events
*/
debug?: boolean;
/**
* defines preferred authentication method, eg. 'PLAIN'
*/
authMethod?: string;
/**
* defines additional options to be passed to the socket constructor, eg. {rejectUnauthorized: true}
*/
tls?: tls.ConnectionOptions;
}
}
function smtpTransport(options: smtpTransport.SmtpOptions): nodemailer.Transport;
export = smtpTransport;
}

View File

@ -1,105 +1,28 @@
/// <reference path="..\node\node.d.ts" />
/// <reference path="nodemailer.d.ts" />
var nodemailer: Nodemailer;
var fs: any;
var pathlib: any;
import nodemailer = require('nodemailer');
// Create an Amazon SES transport object
var transport:Transport = nodemailer.createTransport("SES", {
AWSAccessKeyID: "AWSACCESSKEY",
AWSSecretKey: "/AWS/SECRET",
ServiceUrl: "https://email.us-east-1.amazonaws.com" // optional
// create reusable transporter object using SMTP transport
var transporter: nodemailer.Transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
});
console.log('SES Configured');
// optional DKIM signing
transport.useDKIM({
domainName: "do-not-trust.node.ee", // signing domain
keySelector: "dkim", // selector name (in this case there's a dkim._domainkey.do-not-trust.node.ee TXT record set up)
privateKey: fs.readFileSync(pathlib.join(__dirname,"test_private.pem"))
});
// Message object
var message:MailComposer = {
// sender info
from: 'Sender Name <sender@example.com>',
// Comma separated list of recipients
to: '"Receiver Name" <receiver@example.com>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
// plaintext body
text: 'Hello to myself!',
// HTML body
html: '<p><b>Hello</b> to myself <img src="cid:note@node"/></p>' +
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@node"/></p>',
// An array of attachments
attachments: [
// String attachment
{
fileName: 'notes.txt',
contents: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
},
// Binary Buffer attachment
{
fileName: 'image.png',
contents: new Buffer('iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC', 'base64'),
cid: 'note@node' // should be as unique as possible
},
// File Stream attachment
{
fileName: 'nyancat.gif',
filePath: __dirname + "/nyan.gif",
cid: 'nyan@node' // should be as unique as possible
}
]
// setup e-mail data with unicode symbols
var mailOptions: nodemailer.SendMailOptions = {
from: 'Fred Foo ✔ <foo@blurdybloop.com>', // sender address
to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
};
console.log('Sending Mail');
transport.sendMail(message, function (error) {
if (error) {
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// send mail with defined transport object
transporter.sendMail(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
// nothing
});
// From the SMTP section of https://npmjs.org/package/nodemailer README
var smptTransport1: Transport = nodemailer.createTransport("SMTP", {
service: "Gmail", // sets automatically host, port and connection security settings
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
});
var smtpTransport2: Transport = nodemailer.createTransport("SMTP", {
host: "smtp.gmail.com", // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
auth: {
user: "gmail.user@gmail.com",
pass: "userpass"
}
});

149
nodemailer/nodemailer-types.d.ts vendored Normal file
View File

@ -0,0 +1,149 @@
// Type definitions for Nodemailer 1.3.2
// Project: https://github.com/andris9/Nodemailer
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module nodemailer {
export interface AttachmentObject {
/**
* filename to be reported as the name of the attached file, use of unicode is allowed
*/
filename?: string;
/**
* optional content id for using inline images in HTML message source
*/
cid?: string;
/**
* Pathname or URL to use streaming
*/
path?: string;
/**
* String, Buffer or a Stream contents for the attachment
*/
content: string|Buffer|NodeJS.ReadableStream;
/**
* If set and content is string, then encodes the content to a Buffer using the specified encoding. Example values: base64, hex, 'binary' etc. Useful if you want to use binary attachments in a JSON formatted e-mail object.
*/
encoding?: string;
/**
* optional content type for the attachment, if not set will be derived from the filename property
*/
contentType?: string;
/**
* optional content disposition type for the attachment, defaults to 'attachment'
*/
contentDisposition?: string;
}
export interface SendMailOptions {
/**
* The e-mail address of the sender. All e-mail addresses can be plain 'sender@server.com' or formatted 'Sender Name <sender@server.com>', see here for details
*/
from?: string;
/**
* An e-mail address that will appear on the Sender: field
*/
sender?: string;
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the To: field
*/
to?: string|string[];
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the Cc: field
*/
cc?: string|string[];
/**
* Comma separated list or an array of recipients e-mail addresses that will appear on the Bcc: field
*/
bcc?: string|string[];
/**
* An e-mail address that will appear on the Reply-To: field
*/
replyTo?: string;
/**
* The message-id this message is replying
*/
inReplyTo?: string;
/**
* Message-id list (an array or space separated string)
*/
references?: string|string[];
/**
* The subject of the e-mail
*/
sbject?: string;
/**
* The plaintext version of the message as an Unicode string, Buffer, Stream or an object {path: '...'}
*/
text?: string|Buffer|NodeJS.ReadableStream|AttachmentObject;
/**
* The HTML version of the message as an Unicode string, Buffer, Stream or an object {path: '...'}
*/
html?: string|Buffer|NodeJS.ReadableStream|AttachmentObject;
/**
* An object or array of additional header fields (e.g. {"X-Key-Name": "key value"} or [{key: "X-Key-Name", value: "val1"}, {key: "X-Key-Name", value: "val2"}])
*/
headers?: any;
/**
* An array of attachment objects (see below for details)
*/
attachments?: AttachmentObject[];
/**
* An array of alternative text contents (in addition to text and html parts) (see below for details)
*/
alternatives?: AttachmentObject[];
/**
* optional Message-Id value, random value will be generated if not set
*/
messageId?: string;
/**
* optional Date value, current UTC string will be used if not set
*/
date?: Date;
/**
* optional transfer encoding for the textual parts (defaults to 'quoted-printable')
*/
encoding?: string;
}
export interface SentMessageInfo {
/**
* most transports should return the final Message-Id value used with this property
*/
messageId: string;
/**
* includes the envelope object for the message
*/
envelope: any;
/**
* is an array returned by SMTP transports (includes recipient addresses that were accepted by the server)
*/
accepted: string[];
/**
* is an array returned by SMTP transports (includes recipient addresses that were rejected by the server)
*/
rejected: string[];
/**
* is an array returned by Direct SMTP transport. Includes recipient addresses that were temporarily rejected together with the server response
*/
pending?: string[];
/**
* is a string returned by SMTP transports and includes the last SMTP response from the server
*/
response: string;
}
/**
* This is what you implement to create a new transporter yourself
*/
export interface Transport {
name: string;
version: string;
send(mail: SendMailOptions, callback?: (error: Error, info: SentMessageInfo) => void): void;
close(): void;
}
}

View File

@ -1,111 +1,63 @@
// Type definitions for Nodemailer
// Project: https://github.com/andris9/Nodemailer
// Definitions by: Vincent Bortone <https://github.com/vbortone/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
// Nodemailer is an easy to use module to send e-mails with Node.JS (using SMTP or sendmail or Amazon SES) and is unicode friendly .
declare class Transport {
static transports: {
SMTP: Transport;
SES: Transport;
SENDMAIL: Transport;
STUB: Transport;
};
constructor(type: string, options?: any);
options: Object;
transportType: string;
sendMailWithTransport(emailMessage: MailComposer, callback?: (err: Error) => any): any;
useDKIM(dkim: DKIMOptions): void;
close(callback?: (err: Error) => any): any;
sendMail(message: MailComposer, callback?: (err: Error) => any): any;
send_mail(message:MailComposer, callback?: (err: Error) => any): any;
}
interface NodeMailerAttachment {
fileName: string;
filePath?: string;
contents?: any;
contentType?: string;
cid?: string;
}
interface MailComposer {
from: string; // sender info
to: string; // Comma separated list of recipients
subject: string; // Subject of the message
headers?: {};
text?: string; // plaintext body
html?: string; // HTML body
attachments?: NodeMailerAttachment[]; // An array of attachments
forceEmbeddedImages?: boolean;
}
interface DKIMOptions{
domainName: string; // signing domain
keySelector: string; // selector name (in this case there's a dkim._domainkey.do-not-trust.node.ee TXT record set up)
privateKey: any;
}
declare class XOAuthGenerator {
constructor(options: XOAuthGeneratorOptions);
generate(callback: () => any): string;
}
interface XOAuthGeneratorOptions {
user: string;
consumerKey: string; // optional
consumerSecret: string; // optional
token: string;
tokenSecret: string;
}
interface XOAuth2Options {
user: string;
clientId: string;
clientSecret: string;
refreshToken: string;
}
interface NodemailerTransportOptions {
service?: string;
auth?: NodemailerAuthInterface;
debug?: boolean;
AWSAccessKeyID?: string;
AWSSecretKey: string;
ServiceUrl: string;
}
interface NodemailerAuthInterface {
user?: string;
pass?: string;
XOAuthToken?: XOAuthGenerator;
XOAuth2?: XOAuth2Options;
}
interface NodemailerSMTPTransportOptions {
service?: string;
host?: string;
port?: number;
secureConnection?: boolean;
name?: string;
auth: NodemailerAuthInterface;
ignoreTLS?: boolean;
debug?: boolean;
maxConnections?: number;
}
interface Nodemailer {
createTransport(type: string): Transport;
createTransport(type: string, options: NodemailerTransportOptions): Transport;
createTransport(type: string, options: NodemailerSMTPTransportOptions): Transport;
createTransport(type: string, path: string): Transport;
createXOAuthGenerator(options: XOAuthGeneratorOptions): XOAuthGenerator;
}
declare module "nodemailer" {
var nodemailer: Nodemailer;
export = nodemailer;
}
// Type definitions for Nodemailer 1.3.2
// Project: https://github.com/andris9/Nodemailer
// Definitions by: Rogier Schouten <https://github.com/rogierschouten/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="./nodemailer-types.d.ts" />
/// <reference path="../nodemailer-direct-transport/nodemailer-direct-transport.d.ts" />
/// <reference path="../nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts" />
declare module "nodemailer" {
import directTransport = require("nodemailer-direct-transport");
import smtpTransport = require("nodemailer-smtp-transport");
export type Transport = nodemailer.Transport;
export type SendMailOptions = nodemailer.SendMailOptions;
export type SentMessageInfo = nodemailer.SentMessageInfo;
/**
* Transporter plugin
*/
export interface Plugin {
(mail: SendMailOptions, callback?: (error: Error, info: SentMessageInfo) => void): void;
}
/**
* This is what you use to send mail
*/
export interface Transporter {
/**
* Send a mail
*/
sendMail(mail: SendMailOptions, callback?: (error: Error, info: SentMessageInfo) => void): void;
/**
* Attach a plugin. 'compile' and 'stream' plugins can be attached with use(plugin) method
*
* @param step is a string, either 'compile' or 'stream' thatd defines when the plugin should be hooked
* @param pluginFunc is a function that takes two arguments: the mail object and a callback function
*/
use(step: string, plugin: Plugin): void;
/**
* Close all connections
*/
close?(): void;
}
/**
* Create a direct transporter
*/
export function createTransport(options?: directTransport.DirectOptions): Transporter;
/**
* Create an SMTP transporter
*/
export function createTransport(options?: smtpTransport.SmtpOptions): Transporter;
/**
* Create a transporter from a given implementation
*/
export function createTransport(transport: Transport): Transporter;
}