From 3aac49ea7ee2e6d15d3dcbc45f4e6bb0af544517 Mon Sep 17 00:00:00 2001
From: Seth Westphal
Date: Thu, 4 Aug 2016 18:46:50 -0500
Subject: [PATCH] Fix and improve nodemailer. Add nodemailer-ses-transport.
Improve aws-sdk.
Move types to nodemailer.d.ts.
Move namespace to bottom.
Fix spacing.
Add nodemailer-ses-transport.
Add templateSender.
Allow Exists: false to exist by itself.
Convert spacing to tabs.
Fixed references.
Add DynamoDB createTable and delete table.
They do not exist on the DocumentClient.
Fix spacing.
---
aws-sdk/aws-sdk.d.ts | 9 +-
.../nodemailer-direct-transport.d.ts | 2 +-
.../nodemailer-pickup-transport.d.ts | 2 +-
.../nodemailer-ses-transport-tests.ts | 26 +++
.../nodemailer-ses-transport.d.ts | 29 +++
.../nodemailer-smtp-pool.d.ts | 2 +-
.../nodemailer-smtp-transport.d.ts | 2 +-
nodemailer/nodemailer-tests.ts | 20 +-
nodemailer/nodemailer-types.d.ts | 149 ---------------
nodemailer/nodemailer.d.ts | 174 +++++++++++++++++-
10 files changed, 248 insertions(+), 167 deletions(-)
create mode 100644 nodemailer-ses-transport/nodemailer-ses-transport-tests.ts
create mode 100644 nodemailer-ses-transport/nodemailer-ses-transport.d.ts
delete mode 100644 nodemailer/nodemailer-types.d.ts
diff --git a/aws-sdk/aws-sdk.d.ts b/aws-sdk/aws-sdk.d.ts
index f061353812..cadb392863 100644
--- a/aws-sdk/aws-sdk.d.ts
+++ b/aws-sdk/aws-sdk.d.ts
@@ -319,7 +319,8 @@ declare module "aws-sdk" {
export class DynamoDB {
constructor(options?: any);
endpoint: Endpoint;
-
+ createTable(params: any, next: (err: any, data: any) => void): void;
+ deleteTable(params: any, next: (err: any, data: any) => void): void;
}
// ==========================================================
@@ -355,10 +356,10 @@ declare module "aws-sdk" {
ConditionalOperator?: "AND" | "OR";
Expected?: {
[someKey: string]: {
- AttributeValueList: any[];
- ComparisonOperator: _DDBDC_ComparisonOperator;
+ AttributeValueList?: any[];
+ ComparisonOperator?: _DDBDC_ComparisonOperator;
Exists: boolean;
- Value: any;
+ Value?: any;
}
}
}
diff --git a/nodemailer-direct-transport/nodemailer-direct-transport.d.ts b/nodemailer-direct-transport/nodemailer-direct-transport.d.ts
index ce5caed172..4fa8e9ad34 100644
--- a/nodemailer-direct-transport/nodemailer-direct-transport.d.ts
+++ b/nodemailer-direct-transport/nodemailer-direct-transport.d.ts
@@ -4,7 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-///
+///
declare module "nodemailer-direct-transport" {
diff --git a/nodemailer-pickup-transport/nodemailer-pickup-transport.d.ts b/nodemailer-pickup-transport/nodemailer-pickup-transport.d.ts
index 52aef3801d..35dfad9bc1 100644
--- a/nodemailer-pickup-transport/nodemailer-pickup-transport.d.ts
+++ b/nodemailer-pickup-transport/nodemailer-pickup-transport.d.ts
@@ -3,7 +3,7 @@
// Definitions by: Peter Snider
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-///
+///
declare module "nodemailer-pickup-transport" {
diff --git a/nodemailer-ses-transport/nodemailer-ses-transport-tests.ts b/nodemailer-ses-transport/nodemailer-ses-transport-tests.ts
new file mode 100644
index 0000000000..1cbd06929b
--- /dev/null
+++ b/nodemailer-ses-transport/nodemailer-ses-transport-tests.ts
@@ -0,0 +1,26 @@
+///
+///
+
+import * as AWS from 'aws-sdk';
+import * as sesTransport from 'nodemailer-ses-transport';
+
+var opts: sesTransport.SesOptions = {
+ ses: new AWS.SES(),
+ rateLimit: 5,
+ maxConnections: 3,
+};
+
+var transport: nodemailer.Transport = sesTransport(opts);
+
+// setup e-mail data with unicode symbols
+var mailOptions: nodemailer.SendMailOptions = {
+ from: 'Fred Foo ✔ ', // sender address
+ to: 'bar@blurdybloop.com, baz@blurdybloop.com', // list of receivers
+ subject: 'Hello ✔', // Subject line
+ text: 'Hello world ✔', // plaintext body
+ html: 'Hello world ✔' // html body
+};
+
+transport.send(mailOptions, (error: Error, info: nodemailer.SentMessageInfo): void => {
+ // nothing
+});
diff --git a/nodemailer-ses-transport/nodemailer-ses-transport.d.ts b/nodemailer-ses-transport/nodemailer-ses-transport.d.ts
new file mode 100644
index 0000000000..8ce3d88d69
--- /dev/null
+++ b/nodemailer-ses-transport/nodemailer-ses-transport.d.ts
@@ -0,0 +1,29 @@
+// Type definitions for nodemailer-ses-transport 1.4.0
+// Project: https://github.com/andris9/nodemailer-ses-transport
+// Definitions by: Seth Westphal
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+
+///
+///
+
+declare module "nodemailer-ses-transport" {
+
+ import * as AWS from 'aws-sdk';
+
+ namespace sesTransport {
+ export interface SesOptions {
+ ses?: AWS.SES;
+ accessKeyId?: string;
+ secretAccessKey?: string;
+ sessionToken?: string;
+ region?: string;
+ httpOptions?: AWS.HttpOptions;
+ rateLimit?: number;
+ maxConnections?: number;
+ }
+ }
+
+ function sesTransport(options: sesTransport.SesOptions): nodemailer.Transport;
+
+ export = sesTransport;
+}
diff --git a/nodemailer-smtp-pool/nodemailer-smtp-pool.d.ts b/nodemailer-smtp-pool/nodemailer-smtp-pool.d.ts
index d815bab293..b636ef7df7 100644
--- a/nodemailer-smtp-pool/nodemailer-smtp-pool.d.ts
+++ b/nodemailer-smtp-pool/nodemailer-smtp-pool.d.ts
@@ -4,7 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///
-///
+///
declare module "nodemailer-smtp-pool" {
import tls = require("tls");
diff --git a/nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts b/nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts
index 0beff75ee5..412dd269b0 100644
--- a/nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts
+++ b/nodemailer-smtp-transport/nodemailer-smtp-transport.d.ts
@@ -4,7 +4,7 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///
-///
+///
declare module "nodemailer-smtp-transport" {
diff --git a/nodemailer/nodemailer-tests.ts b/nodemailer/nodemailer-tests.ts
index 46aae5448d..85c89ddea6 100644
--- a/nodemailer/nodemailer-tests.ts
+++ b/nodemailer/nodemailer-tests.ts
@@ -42,4 +42,22 @@ transporter.sendMail(mailOptions, (error: Error, info: nodemailer.SentMessageInf
// promise send mail without callback
transporter
.sendMail(mailOptions)
- .then(info => info.messageId)
\ No newline at end of file
+ .then(info => info.messageId)
+
+// create template based sender function
+var sendPwdReset = transporter.templateSender({
+ subject: 'Password reset for {{username}}!',
+ text: 'Hello, {{username}}, Please go here to reset your password: {{ reset }}',
+ html: 'Hello, {{username}}, Please go here to reset your password: {{ reset }}
'
+}, {
+ from: 'sender@example.com',
+});
+
+// use template based sender to send a message
+sendPwdReset({
+ to: 'receiver@example.com'
+}, {
+ username: 'Node Mailer',
+ reset: 'https://www.example.com/reset?token='
+})
+.then(info => info.messageId);
diff --git a/nodemailer/nodemailer-types.d.ts b/nodemailer/nodemailer-types.d.ts
deleted file mode 100644
index 6fde6ebad9..0000000000
--- a/nodemailer/nodemailer-types.d.ts
+++ /dev/null
@@ -1,149 +0,0 @@
-// Type definitions for Nodemailer 1.3.2
-// Project: https://github.com/andris9/Nodemailer
-// Definitions by: Rogier Schouten
-// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-
-///
-
-declare namespace 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 ', 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
- */
- subject?: 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;
- }
-
-}
diff --git a/nodemailer/nodemailer.d.ts b/nodemailer/nodemailer.d.ts
index 647566437f..cd30f2acdc 100644
--- a/nodemailer/nodemailer.d.ts
+++ b/nodemailer/nodemailer.d.ts
@@ -3,8 +3,8 @@
// Definitions by: Rogier Schouten
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+///
///
-///
///
///
@@ -13,6 +13,8 @@ declare module "nodemailer" {
import directTransport = require("nodemailer-direct-transport");
import smtpTransport = require("nodemailer-smtp-transport");
+ import * as Promise from 'bluebird';
+
export type Transport = nodemailer.Transport;
export type SendMailOptions = nodemailer.SendMailOptions;
export type SentMessageInfo = nodemailer.SentMessageInfo;
@@ -39,6 +41,17 @@ declare module "nodemailer" {
*/
sendMail(mail: SendMailOptions): Promise;
+ /**
+ * Send mail using a template.
+ */
+ templateSender(template?: any, defaults?: any): (mailData: any, context: any) => Promise;
+
+ /**
+ * Send mail using a template with a callback.
+ */
+ templateSender(template?: any, defaults?: any, callback?: (error: Error, info: SentMessageInfo) => void): void;
+
+
/**
* Attach a plugin. 'compile' and 'stream' plugins can be attached with use(plugin) method
*
@@ -48,14 +61,14 @@ declare module "nodemailer" {
use(step: string, plugin: Plugin): void;
/**
- * Verifies connection with server
- */
- verify(callback: (error: Error, success?: boolean) => void): void;
-
- /**
- * Verifies connection with server
- */
- verify(): Promise;
+ * Verifies connection with server
+ */
+ verify(callback: (error: Error, success?: boolean) => void): void;
+
+ /**
+ * Verifies connection with server
+ */
+ verify(): Promise;
/**
* Close all connections
@@ -76,3 +89,146 @@ declare module "nodemailer" {
*/
export function createTransport(transport: Transport, defaults?: Object): Transporter;
}
+
+declare namespace 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 ', 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
+ */
+ subject?: 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;
+ }
+
+}