@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.
Files changed (49) hide show
  1. package/CHANGELOG.md +319 -231
  2. package/LICENSE +20 -20
  3. package/README.md +66 -64
  4. package/SECURITY.md +21 -0
  5. package/dist/adapters/ejs.adapter.d.ts +9 -6
  6. package/dist/adapters/ejs.adapter.js +58 -43
  7. package/dist/adapters/handlebars.adapter.d.ts +10 -8
  8. package/dist/adapters/handlebars.adapter.js +76 -58
  9. package/dist/adapters/mjml.adapter.d.ts +12 -0
  10. package/dist/adapters/mjml.adapter.js +34 -0
  11. package/dist/adapters/pug.adapter.d.ts +8 -5
  12. package/dist/adapters/pug.adapter.js +44 -27
  13. package/dist/constants/mailer.constant.d.ts +2 -0
  14. package/dist/constants/mailer.constant.js +5 -0
  15. package/dist/index.d.ts +8 -6
  16. package/dist/index.js +10 -6
  17. package/dist/interfaces/mailer-async-options.interface.d.ts +11 -9
  18. package/dist/interfaces/mailer-async-options.interface.js +2 -2
  19. package/dist/interfaces/mailer-options-factory.interface.d.ts +4 -4
  20. package/dist/interfaces/mailer-options-factory.interface.js +2 -2
  21. package/dist/interfaces/mailer-options.interface.d.ts +35 -35
  22. package/dist/interfaces/mailer-options.interface.js +2 -2
  23. package/dist/interfaces/mailer-send-mail-options.interface.d.ts +5 -5
  24. package/dist/interfaces/mailer-send-mail-options.interface.js +2 -2
  25. package/dist/interfaces/mailer-transport-factory.interface.d.ts +5 -0
  26. package/dist/{constants/mailer-options.constant.js → interfaces/mailer-transport-factory.interface.js} +2 -3
  27. package/dist/interfaces/send-mail-options.interface.d.ts +54 -49
  28. package/dist/interfaces/send-mail-options.interface.js +2 -2
  29. package/dist/interfaces/template-adapter-config.interface.d.ts +5 -0
  30. package/dist/interfaces/template-adapter-config.interface.js +2 -0
  31. package/dist/interfaces/template-adapter.interface.d.ts +4 -4
  32. package/dist/interfaces/template-adapter.interface.js +2 -2
  33. package/dist/mailer-core.module.d.ts +9 -9
  34. package/dist/mailer-core.module.js +74 -72
  35. package/dist/mailer-transport.factory.d.ts +8 -0
  36. package/dist/mailer-transport.factory.js +20 -0
  37. package/dist/mailer.module.d.ts +7 -7
  38. package/dist/mailer.module.js +29 -28
  39. package/dist/mailer.service.d.ts +13 -11
  40. package/dist/mailer.service.js +90 -83
  41. package/index.d.ts +0 -0
  42. package/index.js +5 -5
  43. package/package.json +102 -100
  44. package/yarn-error.log +6492 -0
  45. package/.dockerignore +0 -2
  46. package/Dockerfile +0 -10
  47. package/dist/constants/mailer-options.constant.d.ts +0 -1
  48. package/docker-compose.yml +0 -18
  49. 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
- #or
23
- yarn add @nestjs-modules/mailer nodemailer
24
- ```
25
-
26
- **Hint:** handlebars and pug is an optional dependency, if you want to use the template, you must install it.
27
-
28
- #### with npm
29
- ```sh
30
- npm install --save handlebars
31
- #or
32
- npm install --save pug
33
- #or
34
- npm install --save ejs
35
- ```
36
-
37
- #### with yarn
38
- ```sh
39
- yarn add handlebars
40
- #or
41
- yarn add pug
42
- #or
43
- yarn add ejs
44
- ```
45
-
46
- ### Documentation
47
-
48
- you can find all the documentation [here](https://nest-modules.github.io/mailer/) for the email module
49
-
50
- ### Starter kit
51
-
52
- - [Sending email-template with outlook](https://github.com/yanarp/nestjs-mailer) - Starter kit, nestjs mailer implementation on outlook smtp with email-template
53
-
54
- ### Contributing
55
-
56
- * [Cristiam Diaz](https://github.com/cdiaz)
57
- * [Eduardo Leal](https://github.com/eduardoleal)
58
- * [Juan Echeverry](https://github.com/juandav)
59
- * [Pat McGowan](https://github.com/p-mcgowan)
60
- * [Paweł Partyka](https://github.com/partyka95)
61
-
62
- ### License
63
-
64
- MIT
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
- export declare class EjsAdapter implements TemplateAdapter {
4
- private precompiledTemplates;
5
- compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
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
- const ejs_1 = require("ejs");
4
- const lodash_1 = require("lodash");
5
- const fs = require("fs");
6
- const path = require("path");
7
- const inlineCss = require("inline-css");
8
- class EjsAdapter {
9
- constructor() {
10
- this.precompiledTemplates = {};
11
- }
12
- compile(mail, callback, mailerOptions) {
13
- const templateExt = path.extname(mail.data.template) || '.ejs';
14
- const templateName = path.basename(mail.data.template, path.extname(mail.data.template));
15
- const templateDir = path.dirname(mail.data.template) !== '.'
16
- ? path.dirname(mail.data.template)
17
- : lodash_1.get(mailerOptions, 'template.dir', '');
18
- const templatePath = path.join(templateDir, templateName + templateExt);
19
- if (!this.precompiledTemplates[templateName]) {
20
- try {
21
- const template = fs.readFileSync(templatePath, 'UTF-8');
22
- this.precompiledTemplates[templateName] = ejs_1.compile(template, Object.assign(Object.assign({}, lodash_1.get(mailerOptions, 'template.options', {})), { filename: templatePath }));
23
- }
24
- catch (err) {
25
- return callback(err);
26
- }
27
- }
28
- const rendered = this.precompiledTemplates[templateName](mail.data.context);
29
- const render = (html) => {
30
- inlineCss(html, { url: ' ' }).then((html) => {
31
- mail.data.html = html;
32
- return callback();
33
- });
34
- };
35
- if (typeof rendered === 'string') {
36
- render(rendered);
37
- }
38
- else {
39
- rendered.then(render);
40
- }
41
- }
42
- }
43
- exports.EjsAdapter = EjsAdapter;
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
- export declare class HandlebarsAdapter implements TemplateAdapter {
5
- private precompiledTemplates;
6
- constructor(helpers?: HelperDeclareSpec);
7
- compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
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
- const fs = require("fs");
4
- const path = require("path");
5
- const handlebars = require("handlebars");
6
- const inlineCss = require("inline-css");
7
- const glob = require("glob");
8
- const lodash_1 = require("lodash");
9
- class HandlebarsAdapter {
10
- constructor(helpers) {
11
- this.precompiledTemplates = {};
12
- handlebars.registerHelper('concat', (...args) => {
13
- args.pop();
14
- return args.join('');
15
- });
16
- handlebars.registerHelper(helpers || {});
17
- }
18
- compile(mail, callback, mailerOptions) {
19
- const precompile = (template, callback, options) => {
20
- const templateExt = path.extname(template) || '.hbs';
21
- const templateName = path.basename(template, path.extname(template));
22
- const templateDir = path.dirname(template) !== '.'
23
- ? path.dirname(template)
24
- : lodash_1.get(options, 'dir', '');
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] = handlebars.compile(template, lodash_1.get(options, 'options', {}));
30
- }
31
- catch (err) {
32
- return callback(err);
33
- }
34
- }
35
- return {
36
- templateExt,
37
- templateName,
38
- templateDir,
39
- templatePath,
40
- };
41
- };
42
- const { templateName } = precompile(mail.data.template, callback, mailerOptions.template);
43
- const runtimeOptions = lodash_1.get(mailerOptions, 'options', {
44
- partials: false,
45
- data: {},
46
- });
47
- if (runtimeOptions.partials) {
48
- const files = glob.sync(path.join(runtimeOptions.partials.dir, '*.hbs'));
49
- files.forEach((file) => precompile(file, () => { }, runtimeOptions.partials));
50
- }
51
- const rendered = this.precompiledTemplates[templateName](mail.data.context, Object.assign(Object.assign({}, runtimeOptions), { partials: this.precompiledTemplates }));
52
- inlineCss(rendered, { url: ' ' }).then((html) => {
53
- mail.data.html = html;
54
- return callback();
55
- });
56
- }
57
- }
58
- exports.HandlebarsAdapter = HandlebarsAdapter;
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
- export declare class PugAdapter implements TemplateAdapter {
4
- compile(mail: any, callback: any, mailerOptions: MailerOptions): void;
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
- const path = require("path");
4
- const lodash_1 = require("lodash");
5
- const pug_1 = require("pug");
6
- const inlineCss = require("inline-css");
7
- class PugAdapter {
8
- compile(mail, callback, mailerOptions) {
9
- const templateExt = path.extname(mail.data.template) || '.pug';
10
- const templateName = path.basename(mail.data.template, path.extname(mail.data.template));
11
- const templateDir = path.dirname(mail.data.template) !== '.'
12
- ? path.dirname(mail.data.template)
13
- : lodash_1.get(mailerOptions, 'template.dir', '');
14
- const templatePath = path.join(templateDir, templateName + templateExt);
15
- const options = Object.assign(Object.assign({}, mail.data.context), lodash_1.get(mailerOptions, 'template.options', {}));
16
- pug_1.renderFile(templatePath, options, (err, body) => {
17
- if (err) {
18
- return callback(err);
19
- }
20
- inlineCss(body, { url: ' ' }).then((html) => {
21
- mail.data.html = html;
22
- return callback();
23
- });
24
- });
25
- }
26
- }
27
- exports.PugAdapter = PugAdapter;
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;
@@ -0,0 +1,2 @@
1
+ export declare const MAILER_OPTIONS = "MAILER_OPTIONS";
2
+ export declare const MAILER_TRANSPORT_FACTORY = "MAILER_TRANSPORT_FACTORY";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAILER_TRANSPORT_FACTORY = exports.MAILER_OPTIONS = void 0;
4
+ exports.MAILER_OPTIONS = 'MAILER_OPTIONS';
5
+ exports.MAILER_TRANSPORT_FACTORY = 'MAILER_TRANSPORT_FACTORY';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export { MailerModule } from './mailer.module';
2
- export { MailerOptions } from './interfaces/mailer-options.interface';
3
- export { TemplateAdapter } from './interfaces/template-adapter.interface';
4
- export { MailerOptionsFactory } from './interfaces/mailer-options-factory.interface';
5
- export { ISendMailOptions } from './interfaces/send-mail-options.interface';
6
- export { MailerService } from './mailer.service';
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
- var mailer_module_1 = require("./mailer.module");
4
- exports.MailerModule = mailer_module_1.MailerModule;
5
- var mailer_service_1 = require("./mailer.service");
6
- exports.MailerService = mailer_service_1.MailerService;
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; } });