Skip to content

Commit 1ddecfd

Browse files
1 parent 6fe0875 commit 1ddecfd

File tree

4 files changed

+120
-78
lines changed

4 files changed

+120
-78
lines changed

‎types/email-templates/email-templates-tests.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
import EmailTemplates = require('email-templates');
1+
import Email = require('email-templates');
22
import { createTransport } from 'nodemailer';
33
import path = require('path');
44

55
const locals = {
66
locale: 'en',
77
name: 'Elon',
88
};
9-
const email = new EmailTemplates({
9+
10+
let email = new Email();
11+
12+
email = new Email({
1013
message: {
1114
1215
},
1316
transport: {
1417
jsonTransport: true
1518
},
16-
/** returns different template based on current locale */
1719
getPath: (type, template, locales) => {
1820
const locale = locales.locale;
1921
return path.join(template, locale, type);
2022
},
2123
});
2224

23-
const emailNoTransporter = new EmailTemplates({
25+
const emailNoTransporter = new Email({
2426
message: {
2527
2628
},
@@ -41,7 +43,7 @@ interface Locals {
4143
firstName: string;
4244
}
4345

44-
const withTransportInstance = new EmailTemplates<Locals>({
46+
const withTransportInstance = new Email<Locals>({
4547
message: {
4648
4749
},
@@ -52,7 +54,7 @@ const withTransportInstance = new EmailTemplates<Locals>({
5254

5355
withTransportInstance.render('tmpl', { firstName: 'TypeScript' });
5456

55-
const emailOptions: EmailTemplates.EmailOptions<Locals> = {
57+
const emailOptions: Email.EmailOptions<Locals> = {
5658
template: 'tmpl',
5759
locals: {
5860
firstName: 'TypeScript'
@@ -75,3 +77,19 @@ promise.then(value => {
7577
const html: string | undefined = value.html;
7678
const text: string | undefined = value.text;
7779
});
80+
81+
email = new Email({
82+
message: {
83+
84+
},
85+
juice: true,
86+
juiceSettings: {
87+
tableElements: ['TABLE'],
88+
},
89+
juiceResources: {
90+
preserveImportant: true,
91+
webResources: {
92+
relativeTo: path.resolve('build'),
93+
},
94+
},
95+
});

‎types/email-templates/index.d.ts

Lines changed: 88 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for node-email-templates 7.1
1+
// Type definitions for node-email-templates 8.0
22
// Project: https://github.com/forwardemail/email-templates
33
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
44
// Matus Gura <https://github.com/gurisko>
@@ -20,8 +20,9 @@ import SESTransport = require('nodemailer/lib/ses-transport');
2020
import SMTPPool = require('nodemailer/lib/smtp-pool');
2121
import SMTPTransport = require('nodemailer/lib/smtp-transport');
2222
import StreamTransport = require('nodemailer/lib/stream-transport');
23+
import juice = require('juice');
2324

24-
declare namespace EmailTemplate {
25+
declare namespace Email {
2526
// email-templates accepts nodemailer.createTransport options directly
2627
// too and calls createTransport if given a non-function, thus a lot
2728
// of different types accepted for transport
@@ -92,69 +93,81 @@ declare namespace EmailTemplate {
9293
}
9394

9495
interface EmailConfig<T = any> {
95-
/**
96-
* The message <Nodemailer.com/message/>
97-
*/
98-
message: Mail.Options;
99-
/**
100-
* The nodemailer Transport created via nodemailer.createTransport
101-
*/
102-
transport?: NodeMailerTransportOptions;
103-
/**
104-
* The email template directory and engine information
105-
*/
106-
views?: View;
107-
/**
108-
* Do you really want to send, false for test or development
109-
*/
110-
send?: boolean;
111-
/**
112-
* Preview the email
113-
*/
114-
preview?: boolean | PreviewEmailOpts;
115-
/**
116-
* Set to object to configure and Enable <https://github.com/ladjs/il8n>
117-
*/
118-
i18n?: any;
119-
/**
120-
* defaults to false, unless you pass your own render function,
121-
* and in that case it will be automatically set to true.
122-
* @default false
123-
*/
124-
customRender?: boolean;
125-
/**
126-
* Pass a custom render function if necessary
127-
*/
128-
render?: (view: string, locals?: T) => Promise<any>;
129-
/**
130-
* force text-only rendering of template (disregards template folder)
131-
*/
132-
textOnly?: boolean;
133-
/**
134-
* <Https://github.com/werk85/node-html-to-text>
135-
*
136-
* configuration object for html-to-text
137-
*/
138-
htmlToText?: HtmlToTextOptions | false;
139-
/**
140-
* You can pass an option to prefix subject lines with a string
141-
* env === 'production' ? false : `[${env.toUpperCase()}] `; // <--- HERE
142-
*/
143-
subjectPrefix?: string | false;
144-
/**
145-
* <https://github.com/Automattic/juice>
146-
*/
147-
juice?: boolean;
148-
/**
149-
* <https://github.com/Automattic/juice>
150-
*/
151-
juiceResources?: any;
152-
/**
153-
* a function that returns the path to a template file
154-
* @default (path: string, template: string) => string
155-
*/
156-
getPath?: (path: string, template: string, locals: any) => string;
157-
}
96+
/**
97+
* The message <Nodemailer.com/message/>
98+
*/
99+
message: Mail.Options;
100+
/**
101+
* The nodemailer Transport created via nodemailer.createTransport
102+
*/
103+
transport?: NodeMailerTransportOptions;
104+
/**
105+
* The email template directory and engine information
106+
*/
107+
views?: View;
108+
/**
109+
* Do you really want to send, false for test or development
110+
*/
111+
send?: boolean;
112+
/**
113+
* Preview the email
114+
*/
115+
preview?: boolean | PreviewEmailOpts;
116+
/**
117+
* Set to object to configure and Enable <https://github.com/ladjs/il8n>
118+
*/
119+
i18n?: any;
120+
/**
121+
* defaults to false, unless you pass your own render function,
122+
* and in that case it will be automatically set to true.
123+
* @default false
124+
*/
125+
customRender?: boolean;
126+
/**
127+
* Pass a custom render function if necessary
128+
*/
129+
render?: (view: string, locals?: T) => Promise<any>;
130+
/**
131+
* force text-only rendering of template (disregards template folder)
132+
*/
133+
textOnly?: boolean;
134+
/**
135+
* <Https://github.com/werk85/node-html-to-text>
136+
*
137+
* configuration object for html-to-text
138+
*/
139+
htmlToText?: HtmlToTextOptions | false;
140+
/**
141+
* You can pass an option to prefix subject lines with a string
142+
* env === 'production' ? false : `[${env.toUpperCase()}] `; // <--- HERE
143+
*/
144+
subjectPrefix?: string | false;
145+
/**
146+
* <https://github.com/Automattic/juice>
147+
*/
148+
juice?: boolean;
149+
juiceSettings?: JuiceGlobalConfig;
150+
/**
151+
* <https://github.com/Automattic/juice>
152+
*/
153+
juiceResources?: juice.Options;
154+
/**
155+
* a function that returns the path to a template file
156+
* @default (path: string, template: string) => string
157+
*/
158+
getPath?: (path: string, template: string, locals: any) => string;
159+
}
160+
161+
type JuiceGlobalConfig = Partial<{
162+
codeBlocks: typeof juice.codeBlocks;
163+
excludedProperties: typeof juice.excludedProperties;
164+
heightElements: string[];
165+
ignoredPseudos: typeof juice.ignoredPseudos;
166+
nonVisualElements: typeof juice.nonVisualElements;
167+
styleToAttribute: typeof juice.styleToAttribute;
168+
tableElements: string[];
169+
widthElements: string[];
170+
}>;
158171

159172
interface EmailOptions<T = any> {
160173
/**
@@ -180,31 +193,35 @@ declare namespace EmailTemplate {
180193
}
181194
}
182195

183-
declare class EmailTemplate<T = any> {
184-
constructor(config: EmailTemplate.EmailConfig);
196+
declare class Email<T = any> {
197+
constructor(config?: Email.EmailConfig);
198+
185199
/**
186200
* shorthand use of `juiceResources` with the config
187201
* mainly for custom renders like from a database).
188202
*/
189-
juiceResources(html: string): Promise<string>;
203+
juiceResources(html: string, options?: juice.Options): Promise<string>;
204+
190205
/**
191206
*
192207
* @param view The Html pug to render
193208
* @param locals The template Variables
194209
*/
195210
render(view: string, locals?: T): Promise<string>;
211+
196212
/**
197213
* Render all available template files for a given email
198214
* template (e.g. `html.pug`, `text.pug`, and `subject.pug`)
199215
*
200216
* @param view Name of the template
201217
* @param locals The template variables
202218
*/
203-
renderAll(view: string, locals?: T): Promise<Partial<EmailTemplate.EmailMessage>>;
219+
renderAll(view: string, locals?: T): Promise<Partial<Email.EmailMessage>>;
220+
204221
/**
205222
* Send the Email
206223
*/
207-
send(options: EmailTemplate.EmailOptions<T>): Promise<any>;
224+
send(options: Email.EmailOptions<T>): Promise<any>;
208225
}
209226

210-
export = EmailTemplate;
227+
export = Email;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"juice": "^7.0.0"
5+
}
6+
}

‎types/email-templates/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"module": "commonjs",
44
"lib": [
5-
"es6"
5+
"es6",
6+
"dom"
67
],
78
"noImplicitAny": true,
89
"noImplicitThis": true,

0 commit comments

Comments
 (0)