@nestjs-modules/mailer 1.5.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +319 -231
- package/LICENSE +20 -20
- package/README.md +66 -64
- package/SECURITY.md +21 -0
- package/dist/adapters/ejs.adapter.d.ts +9 -6
- package/dist/adapters/ejs.adapter.js +58 -43
- package/dist/adapters/handlebars.adapter.d.ts +10 -8
- package/dist/adapters/handlebars.adapter.js +76 -58
- package/dist/adapters/mjml.adapter.d.ts +12 -0
- package/dist/adapters/mjml.adapter.js +34 -0
- package/dist/adapters/pug.adapter.d.ts +8 -5
- package/dist/adapters/pug.adapter.js +44 -27
- package/dist/constants/mailer.constant.d.ts +2 -0
- package/dist/constants/mailer.constant.js +5 -0
- package/dist/index.d.ts +8 -6
- package/dist/index.js +10 -6
- package/dist/interfaces/mailer-async-options.interface.d.ts +11 -9
- package/dist/interfaces/mailer-async-options.interface.js +2 -2
- package/dist/interfaces/mailer-options-factory.interface.d.ts +4 -4
- package/dist/interfaces/mailer-options-factory.interface.js +2 -2
- package/dist/interfaces/mailer-options.interface.d.ts +35 -35
- package/dist/interfaces/mailer-options.interface.js +2 -2
- package/dist/interfaces/mailer-send-mail-options.interface.d.ts +5 -5
- package/dist/interfaces/mailer-send-mail-options.interface.js +2 -2
- package/dist/interfaces/mailer-transport-factory.interface.d.ts +5 -0
- package/dist/{constants/mailer-options.constant.js → interfaces/mailer-transport-factory.interface.js} +2 -3
- package/dist/interfaces/send-mail-options.interface.d.ts +54 -49
- package/dist/interfaces/send-mail-options.interface.js +2 -2
- package/dist/interfaces/template-adapter-config.interface.d.ts +5 -0
- package/dist/interfaces/template-adapter-config.interface.js +2 -0
- package/dist/interfaces/template-adapter.interface.d.ts +4 -4
- package/dist/interfaces/template-adapter.interface.js +2 -2
- package/dist/mailer-core.module.d.ts +9 -9
- package/dist/mailer-core.module.js +74 -72
- package/dist/mailer-transport.factory.d.ts +8 -0
- package/dist/mailer-transport.factory.js +20 -0
- package/dist/mailer.module.d.ts +7 -7
- package/dist/mailer.module.js +29 -28
- package/dist/mailer.service.d.ts +13 -11
- package/dist/mailer.service.js +90 -83
- package/index.d.ts +0 -0
- package/index.js +5 -5
- package/package.json +102 -100
- package/yarn-error.log +6492 -0
- package/.dockerignore +0 -2
- package/Dockerfile +0 -10
- package/dist/constants/mailer-options.constant.d.ts +0 -1
- package/docker-compose.yml +0 -18
- package/jest.config.js +0 -17
package/README.md
CHANGED
|
@@ -1,64 +1,66 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<a href="http://nestjs.com/" target="blank">
|
|
3
|
-
<img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" />
|
|
4
|
-
</a>
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
A mailer module for Nest framework (node.js) using <a href="https://nodemailer.com/">Nodemailer</a> library
|
|
9
|
-
</p>
|
|
10
|
-
|
|
11
|
-
<p align="center">
|
|
12
|
-
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/v/@nestjs-modules/mailer.svg" alt="NPM Version" /></a>
|
|
13
|
-
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/l/@nestjs-modules/mailer.svg" alt="Package License" /></a>
|
|
14
|
-
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/dm/@nestjs-modules/mailer.svg" alt="NPM Downloads" /></a>
|
|
15
|
-
<a href="https://opencollective.com/nest-modules#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
|
16
|
-
</p>
|
|
17
|
-
|
|
18
|
-
### Installation
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
npm install --save @nestjs-modules/mailer nodemailer
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
npm install --save
|
|
33
|
-
#or
|
|
34
|
-
npm install --save
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
yarn add
|
|
42
|
-
#or
|
|
43
|
-
yarn add
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
* [
|
|
59
|
-
* [
|
|
60
|
-
* [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="http://nestjs.com/" target="blank">
|
|
3
|
+
<img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A mailer module for Nest framework (node.js) using <a href="https://nodemailer.com/">Nodemailer</a> library
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/v/@nestjs-modules/mailer.svg" alt="NPM Version" /></a>
|
|
13
|
+
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/l/@nestjs-modules/mailer.svg" alt="Package License" /></a>
|
|
14
|
+
<a href="https://www.npmjs.com/org/nestjs-modules"><img src="https://img.shields.io/npm/dm/@nestjs-modules/mailer.svg" alt="NPM Downloads" /></a>
|
|
15
|
+
<a href="https://opencollective.com/nest-modules#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
### Installation
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install --save @nestjs-modules/mailer nodemailer
|
|
22
|
+
npm install --save-dev @types/nodemailer
|
|
23
|
+
#or
|
|
24
|
+
yarn add @nestjs-modules/mailer nodemailer
|
|
25
|
+
yarn add -D @types/nodemailer
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Hint:** handlebars and pug is an optional dependency, if you want to use the template, you must install it.
|
|
29
|
+
|
|
30
|
+
#### with npm
|
|
31
|
+
```sh
|
|
32
|
+
npm install --save handlebars
|
|
33
|
+
#or
|
|
34
|
+
npm install --save pug
|
|
35
|
+
#or
|
|
36
|
+
npm install --save ejs
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
#### with yarn
|
|
40
|
+
```sh
|
|
41
|
+
yarn add handlebars
|
|
42
|
+
#or
|
|
43
|
+
yarn add pug
|
|
44
|
+
#or
|
|
45
|
+
yarn add ejs
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Documentation
|
|
49
|
+
|
|
50
|
+
you can find all the documentation [here](https://nest-modules.github.io/mailer/) for the email module
|
|
51
|
+
|
|
52
|
+
### Starter kit
|
|
53
|
+
|
|
54
|
+
- [Sending email-template with outlook](https://github.com/yanarp/nestjs-mailer) - Starter kit, nestjs mailer implementation on outlook smtp with email-template
|
|
55
|
+
|
|
56
|
+
### Contributing
|
|
57
|
+
|
|
58
|
+
* [Cristiam Diaz](https://github.com/cdiaz)
|
|
59
|
+
* [Eduardo Leal](https://github.com/eduardoleal)
|
|
60
|
+
* [Juan Echeverry](https://github.com/juandav)
|
|
61
|
+
* [Pat McGowan](https://github.com/p-mcgowan)
|
|
62
|
+
* [Paweł Partyka](https://github.com/partyka95)
|
|
63
|
+
|
|
64
|
+
### License
|
|
65
|
+
|
|
66
|
+
MIT
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported Versions
|
|
4
|
+
|
|
5
|
+
Use this section to tell people about which versions of your project are
|
|
6
|
+
currently being supported with security updates.
|
|
7
|
+
|
|
8
|
+
| Version | Supported |
|
|
9
|
+
| ------- | ------------------ |
|
|
10
|
+
| 5.1.x | :white_check_mark: |
|
|
11
|
+
| 5.0.x | :x: |
|
|
12
|
+
| 4.0.x | :white_check_mark: |
|
|
13
|
+
| < 4.0 | :x: |
|
|
14
|
+
|
|
15
|
+
## Reporting a Vulnerability
|
|
16
|
+
|
|
17
|
+
Use this section to tell people how to report a vulnerability.
|
|
18
|
+
|
|
19
|
+
Tell them where to go, how often they can expect to get an update on a
|
|
20
|
+
reported vulnerability, what to expect if the vulnerability is accepted or
|
|
21
|
+
declined, etc.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
2
|
-
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
2
|
+
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
3
|
+
import { TemplateAdapterConfig } from '../interfaces/template-adapter-config.interface';
|
|
4
|
+
export declare class EjsAdapter implements TemplateAdapter {
|
|
5
|
+
private precompiledTemplates;
|
|
6
|
+
private config;
|
|
7
|
+
constructor(config?: TemplateAdapterConfig);
|
|
8
|
+
compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
|
|
9
|
+
}
|
|
@@ -1,43 +1,58 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return callback();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EjsAdapter = void 0;
|
|
4
|
+
const ejs_1 = require("ejs");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const path = require("path");
|
|
8
|
+
const inlineCss = require("inline-css");
|
|
9
|
+
class EjsAdapter {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.precompiledTemplates = {};
|
|
12
|
+
this.config = {
|
|
13
|
+
inlineCssOptions: { url: ' ' },
|
|
14
|
+
inlineCssEnabled: true,
|
|
15
|
+
};
|
|
16
|
+
Object.assign(this.config, config);
|
|
17
|
+
}
|
|
18
|
+
compile(mail, callback, mailerOptions) {
|
|
19
|
+
const { context, template } = mail.data;
|
|
20
|
+
const templateExt = path.extname(template) || '.ejs';
|
|
21
|
+
const templateName = path.basename(template, path.extname(template));
|
|
22
|
+
const templateDir = path.isAbsolute(template)
|
|
23
|
+
? path.dirname(template)
|
|
24
|
+
: path.join(lodash_1.get(mailerOptions, 'template.dir', ''), path.dirname(template));
|
|
25
|
+
const templatePath = path.join(templateDir, templateName + templateExt);
|
|
26
|
+
if (!this.precompiledTemplates[templateName]) {
|
|
27
|
+
try {
|
|
28
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
29
|
+
this.precompiledTemplates[templateName] = ejs_1.compile(template, Object.assign(Object.assign({}, lodash_1.get(mailerOptions, 'template.options', {})), { filename: templatePath }));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
return callback(err);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const rendered = this.precompiledTemplates[templateName](context);
|
|
36
|
+
const render = (html) => {
|
|
37
|
+
if (this.config.inlineCssEnabled) {
|
|
38
|
+
inlineCss(html, this.config.inlineCssOptions)
|
|
39
|
+
.then((html) => {
|
|
40
|
+
mail.data.html = html;
|
|
41
|
+
return callback();
|
|
42
|
+
})
|
|
43
|
+
.catch(callback);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
mail.data.html = html;
|
|
47
|
+
return callback();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (typeof rendered === 'string') {
|
|
51
|
+
render(rendered);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
rendered.then(render);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.EjsAdapter = EjsAdapter;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { HelperDeclareSpec } from 'handlebars';
|
|
2
|
-
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
3
|
-
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { HelperDeclareSpec } from 'handlebars';
|
|
2
|
+
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
3
|
+
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
4
|
+
import { TemplateAdapterConfig } from '../interfaces/template-adapter-config.interface';
|
|
5
|
+
export declare class HandlebarsAdapter implements TemplateAdapter {
|
|
6
|
+
private precompiledTemplates;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(helpers?: HelperDeclareSpec, config?: TemplateAdapterConfig);
|
|
9
|
+
compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
|
|
10
|
+
}
|
|
@@ -1,58 +1,76 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HandlebarsAdapter = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const handlebars = require("handlebars");
|
|
7
|
+
const inlineCss = require("inline-css");
|
|
8
|
+
const glob = require("glob");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
class HandlebarsAdapter {
|
|
11
|
+
constructor(helpers, config) {
|
|
12
|
+
this.precompiledTemplates = {};
|
|
13
|
+
this.config = {
|
|
14
|
+
inlineCssOptions: { url: ' ' },
|
|
15
|
+
inlineCssEnabled: true,
|
|
16
|
+
};
|
|
17
|
+
handlebars.registerHelper('concat', (...args) => {
|
|
18
|
+
args.pop();
|
|
19
|
+
return args.join('');
|
|
20
|
+
});
|
|
21
|
+
handlebars.registerHelper(helpers || {});
|
|
22
|
+
Object.assign(this.config, config);
|
|
23
|
+
}
|
|
24
|
+
compile(mail, callback, mailerOptions) {
|
|
25
|
+
const precompile = (template, callback, options) => {
|
|
26
|
+
const templateExt = path.extname(template) || '.hbs';
|
|
27
|
+
const templateName = path.basename(template, path.extname(template));
|
|
28
|
+
const templateDir = path.isAbsolute(template)
|
|
29
|
+
? path.dirname(template)
|
|
30
|
+
: path.join(lodash_1.get(options, 'dir', ''), path.dirname(template));
|
|
31
|
+
const templatePath = path.join(templateDir, templateName + templateExt);
|
|
32
|
+
if (!this.precompiledTemplates[templateName]) {
|
|
33
|
+
try {
|
|
34
|
+
const template = fs.readFileSync(templatePath, 'utf-8');
|
|
35
|
+
this.precompiledTemplates[templateName] = handlebars.compile(template, lodash_1.get(options, 'options', {}));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
return callback(err);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
templateExt,
|
|
43
|
+
templateName,
|
|
44
|
+
templateDir,
|
|
45
|
+
templatePath,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const { templateName } = precompile(mail.data.template, callback, mailerOptions.template);
|
|
49
|
+
const runtimeOptions = lodash_1.get(mailerOptions, 'options', {
|
|
50
|
+
partials: false,
|
|
51
|
+
data: {},
|
|
52
|
+
});
|
|
53
|
+
if (runtimeOptions.partials) {
|
|
54
|
+
const files = glob.sync(path.join(runtimeOptions.partials.dir, '**', '*.hbs'));
|
|
55
|
+
files.forEach((file) => {
|
|
56
|
+
const { templateName, templatePath } = precompile(file, () => { }, runtimeOptions.partials);
|
|
57
|
+
const templateDir = path.relative(runtimeOptions.partials.dir, path.dirname(templatePath));
|
|
58
|
+
handlebars.registerPartial(path.join(templateDir, templateName), fs.readFileSync(templatePath, 'utf-8'));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const rendered = this.precompiledTemplates[templateName](mail.data.context, Object.assign(Object.assign({}, runtimeOptions), { partials: this.precompiledTemplates }));
|
|
62
|
+
if (this.config.inlineCssEnabled) {
|
|
63
|
+
inlineCss(rendered, this.config.inlineCssOptions)
|
|
64
|
+
.then((html) => {
|
|
65
|
+
mail.data.html = html;
|
|
66
|
+
return callback();
|
|
67
|
+
})
|
|
68
|
+
.catch(callback);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
mail.data.html = rendered;
|
|
72
|
+
return callback();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.HandlebarsAdapter = HandlebarsAdapter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TemplateAdapterConfig } from "../interfaces/template-adapter-config.interface";
|
|
2
|
+
import { TemplateAdapter } from "../interfaces/template-adapter.interface";
|
|
3
|
+
import { MailerOptions } from "../interfaces/mailer-options.interface";
|
|
4
|
+
export declare class MjmlAdapter implements TemplateAdapter {
|
|
5
|
+
private engine;
|
|
6
|
+
constructor(engine: TemplateAdapter | "" | "pug" | "handlebars" | "ejs", config?: TemplateAdapterConfig, others?: {
|
|
7
|
+
handlebar?: {
|
|
8
|
+
helper?: any;
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MjmlAdapter = void 0;
|
|
4
|
+
const handlebars_adapter_1 = require("./handlebars.adapter");
|
|
5
|
+
const ejs_adapter_1 = require("./ejs.adapter");
|
|
6
|
+
const pug_adapter_1 = require("./pug.adapter");
|
|
7
|
+
const mjml_1 = require("mjml");
|
|
8
|
+
class MjmlAdapter {
|
|
9
|
+
constructor(engine, config, others) {
|
|
10
|
+
this.engine = engine;
|
|
11
|
+
if (typeof engine == "string") {
|
|
12
|
+
if (engine === "pug") {
|
|
13
|
+
this.engine = new pug_adapter_1.PugAdapter(config);
|
|
14
|
+
}
|
|
15
|
+
else if (engine === "handlebars") {
|
|
16
|
+
this.engine = new handlebars_adapter_1.HandlebarsAdapter(others.handlebar.helper, config);
|
|
17
|
+
}
|
|
18
|
+
else if (engine === "ejs") {
|
|
19
|
+
this.engine = new ejs_adapter_1.EjsAdapter(config);
|
|
20
|
+
}
|
|
21
|
+
else if (engine === "") {
|
|
22
|
+
engine = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
compile(mail, callback, mailerOptions) {
|
|
27
|
+
var _a;
|
|
28
|
+
(_a = this === null || this === void 0 ? void 0 : this.engine) === null || _a === void 0 ? void 0 : _a.compile(mail, () => {
|
|
29
|
+
mail.data.html = mjml_1.default(mail.data.html).html;
|
|
30
|
+
callback();
|
|
31
|
+
}, mailerOptions);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.MjmlAdapter = MjmlAdapter;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
2
|
-
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { MailerOptions } from '../interfaces/mailer-options.interface';
|
|
2
|
+
import { TemplateAdapter } from '../interfaces/template-adapter.interface';
|
|
3
|
+
import { TemplateAdapterConfig } from '../interfaces/template-adapter-config.interface';
|
|
4
|
+
export declare class PugAdapter implements TemplateAdapter {
|
|
5
|
+
private config;
|
|
6
|
+
constructor(config?: TemplateAdapterConfig);
|
|
7
|
+
compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
|
|
8
|
+
}
|
|
@@ -1,27 +1,44 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PugAdapter = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const pug_1 = require("pug");
|
|
7
|
+
const inlineCss = require("inline-css");
|
|
8
|
+
class PugAdapter {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = {
|
|
11
|
+
inlineCssOptions: { url: ' ' },
|
|
12
|
+
inlineCssEnabled: true,
|
|
13
|
+
};
|
|
14
|
+
Object.assign(this.config, config);
|
|
15
|
+
}
|
|
16
|
+
compile(mail, callback, mailerOptions) {
|
|
17
|
+
const { context, template } = mail.data;
|
|
18
|
+
const templateExt = path.extname(template) || '.pug';
|
|
19
|
+
const templateName = path.basename(template, path.extname(template));
|
|
20
|
+
const templateDir = path.isAbsolute(template)
|
|
21
|
+
? path.dirname(template)
|
|
22
|
+
: path.join(lodash_1.get(mailerOptions, 'template.dir', ''), path.dirname(template));
|
|
23
|
+
const templatePath = path.join(templateDir, templateName + templateExt);
|
|
24
|
+
const options = Object.assign(Object.assign({}, context), lodash_1.get(mailerOptions, 'template.options', {}));
|
|
25
|
+
pug_1.renderFile(templatePath, options, (err, body) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
return callback(err);
|
|
28
|
+
}
|
|
29
|
+
if (this.config.inlineCssEnabled) {
|
|
30
|
+
inlineCss(body, this.config.inlineCssOptions)
|
|
31
|
+
.then((html) => {
|
|
32
|
+
mail.data.html = html;
|
|
33
|
+
return callback();
|
|
34
|
+
})
|
|
35
|
+
.catch(callback);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
mail.data.html = body;
|
|
39
|
+
return callback();
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.PugAdapter = PugAdapter;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export { MailerModule } from './mailer.module';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
1
|
+
export { MailerModule } from './mailer.module';
|
|
2
|
+
export { MAILER_OPTIONS, MAILER_TRANSPORT_FACTORY, } from './constants/mailer.constant';
|
|
3
|
+
export { MailerOptions } from './interfaces/mailer-options.interface';
|
|
4
|
+
export { TemplateAdapter } from './interfaces/template-adapter.interface';
|
|
5
|
+
export { MailerOptionsFactory } from './interfaces/mailer-options-factory.interface';
|
|
6
|
+
export { ISendMailOptions } from './interfaces/send-mail-options.interface';
|
|
7
|
+
export { MailerTransportFactory } from './interfaces/mailer-transport-factory.interface';
|
|
8
|
+
export { MailerService } from './mailer.service';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailerService = exports.MAILER_TRANSPORT_FACTORY = exports.MAILER_OPTIONS = exports.MailerModule = void 0;
|
|
4
|
+
var mailer_module_1 = require("./mailer.module");
|
|
5
|
+
Object.defineProperty(exports, "MailerModule", { enumerable: true, get: function () { return mailer_module_1.MailerModule; } });
|
|
6
|
+
var mailer_constant_1 = require("./constants/mailer.constant");
|
|
7
|
+
Object.defineProperty(exports, "MAILER_OPTIONS", { enumerable: true, get: function () { return mailer_constant_1.MAILER_OPTIONS; } });
|
|
8
|
+
Object.defineProperty(exports, "MAILER_TRANSPORT_FACTORY", { enumerable: true, get: function () { return mailer_constant_1.MAILER_TRANSPORT_FACTORY; } });
|
|
9
|
+
var mailer_service_1 = require("./mailer.service");
|
|
10
|
+
Object.defineProperty(exports, "MailerService", { enumerable: true, get: function () { return mailer_service_1.MailerService; } });
|