diff --git a/types/email-templates/email-templates-tests.ts b/types/email-templates/email-templates-tests.ts
index 3c4493402c..c36852de31 100644
--- a/types/email-templates/email-templates-tests.ts
+++ b/types/email-templates/email-templates-tests.ts
@@ -1,29 +1,14 @@
-import EmailTemplates = require('email-templates');
+import * as Email from 'email-templates';
-const EmailTemplate = EmailTemplates.EmailTemplate;
-const template = new EmailTemplate("./");
-const templateWithOptions = new EmailTemplate('./', {disableJuice: true, sassOptions: {}, juiceOptions: {}});
-const users = [
- {
- email: 'pappa.pizza@spaghetti.com',
- name: {
- first: 'Pappa',
- last: 'Pizza'
- }
+const email = new Email.EmailTemplate({
+ message: {
+ from: 'Test@tesitng.com'
},
- {
- email: 'mister.geppetto@spaghetti.com',
- name: {
- first: 'Mister',
- last: 'Geppetto'
- }
- }
-];
+ transport: {
+ jsonTransport: true
+ }}
+);
-const templates = users.map((user) => {
- return template.render(user)
- .then((results) => {
- const {html, subject, text} = results;
- return html;
- });
-});
+email.juiceResources('
bob
');
+email.render('mars/html.pug', {name: 'elon'});
+email.send({template: 'mars', message: {to: 'elon@spacex.com'}, locals: {name: 'Elon'}});
diff --git a/types/email-templates/index.d.ts b/types/email-templates/index.d.ts
index d76c23aed3..bb6a3321c7 100644
--- a/types/email-templates/index.d.ts
+++ b/types/email-templates/index.d.ts
@@ -1,152 +1,84 @@
-// Type definitions for node-email-templates 2.6
+// Type definitions for node-email-templates 3.1
// Project: https://github.com/niftylettuce/node-email-templates
// Definitions by: Cyril Schumacher
// Matus Gura
+// Jacob Copeland
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
-/**
- * @summary Interface for result of email template.
- * @interface
- */
-interface EmailTemplateResults {
+export interface EmailConfig {
/**
- * @summary HTML result.
- * @type {string}
+ * The message
*/
- html: string;
-
+ message: any;
/**
- * @summary Text result.
- * @type {string}
+ * The nodemailer Transport created via nodemailer.createTransport
*/
- text: string;
-
+ transport: any;
/**
- * @summary Subject result.
- * @type {string}
+ * The email template directory and engine information
*/
- subject: string;
+ views?: any;
+ /**
+ * Do you really want to send, false for test or development
+ */
+ send?: boolean;
+ /**
+ * Preview the email
+ */
+ preview?: boolean;
+ /**
+ * Set to object to configure and Enable
+ */
+ i18n?: any;
+ /**
+ * Pass a custom render function if necessary
+ */
+ render?: { view: string, locals: any };
+ /**
+ *
+ */
+ htmlToText?: any;
+ /**
+ *
+ */
+ juice?: boolean;
+ /**
+ *
+ */
+ juiceResources?: any;
}
-/**
- * @summary Callback signature.
- */
-type EmailTemplateCallback = (err: any, results: EmailTemplateResults) => void;
-
-/**
- * @summary Interface for email-template options
- * @interface
- */
-interface EmailTemplateOptions {
- disableJuice?: boolean;
- juiceOptions?: any;
- sassOptions?: any;
-}
-
-declare module "email-templates" {
+export interface EmailOptions {
/**
- * @summary Email template class.
- * @class
+ * The template name
*/
- class EmailTemplate {
- /**
- * @summary Constructor.
- * @param {string} templateDir The template directory.
- */
- constructor(templateDir: string, options?: EmailTemplateOptions);
-
- /**
- * @summary Render a single template.
- * @param locals The template variables.
- * @param locale The language code.
- */
- render(locals: any, locale?: string): Promise;
-
- /**
- * @summary Render a single template.
- * @param callback The callback function.
- */
- render(callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render a single template.
- * @param locals The template variables.
- * @param callback The callback function.
- */
- render(locals: any, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render a single template.
- * @param locals The template variables.
- * @param locale The language code.
- * @param callback The callback function.
- */
- render(locals: any, locale: string, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render text
- * @param locals The template variables.
- * @param locale The language code.
- */
- renderText(locals: any, locale?: string): Promise;
-
- /**
- * @summary Render text
- * @param locals The template variables.
- * @param callback The language code.
- */
- renderText(locals: any, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render text
- * @param locals The template variables.
- * @param locale The language code.
- * @param callback The language code.
- */
- renderText(locals: any, locale: string, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render subject
- * @param locals The template variables.
- * @param locale The language code.
- */
- renderSubject(locals: any, locale?: string): Promise;
-
- /**
- * @summary Render subject
- * @param locals The template variables.
- * @param callback The language code.
- */
- renderSubject(locals: any, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render subject
- * @param locals The template variables.
- * @param locale The language code.
- * @param callback The language code.
- */
- renderSubject(locals: any, locale: string, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render HTML
- * @param locals The template variables.
- * @param locale The language code.
- */
- renderHtml(locals: any, locale?: string): Promise;
-
- /**
- * @summary Render HTML
- * @param locals The template variables.
- * @param callback The language code.
- */
- renderHtml(locals: any, callback: EmailTemplateCallback): void;
-
- /**
- * @summary Render HTML
- * @param locals The template variables.
- * @param locale The language code.
- * @param callback The language code.
- */
- renderHtml(locals: any, locale: string, callback: EmailTemplateCallback): void;
- }
+ template: string;
+ /**
+ * Nodemailer Message
+ */
+ message: any;
+ /**
+ * The Template Variables
+ */
+ locals: any;
+}
+
+export class EmailTemplate {
+ constructor(config: EmailConfig);
+
+ /**
+ * shorthand use of `juiceResources` with the config
+ * mainly for custom renders like from a database).
+ */
+ juiceResources(html: string): Promise ;
+
+ /**
+ * Render the Email, Used by send, but can be called by itself.
+ */
+ render(view: string, locals: any): Promise;
+
+ /**
+ * Send the Email.
+ */
+ send(options: EmailOptions): any;
}