@nestjs-modules/mailer 1.4.2 → 1.6.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 (45) hide show
  1. package/.dockerignore +2 -2
  2. package/CHANGELOG.md +277 -196
  3. package/Dockerfile +10 -10
  4. package/LICENSE +20 -20
  5. package/README.md +66 -59
  6. package/dist/adapters/ejs.adapter.d.ts +9 -6
  7. package/dist/adapters/ejs.adapter.js +55 -35
  8. package/dist/adapters/handlebars.adapter.d.ts +10 -8
  9. package/dist/adapters/handlebars.adapter.js +70 -58
  10. package/dist/adapters/pug.adapter.d.ts +8 -5
  11. package/dist/adapters/pug.adapter.js +41 -27
  12. package/dist/constants/mailer.constant.d.ts +2 -0
  13. package/dist/constants/mailer.constant.js +5 -0
  14. package/dist/index.d.ts +8 -8
  15. package/dist/index.js +10 -10
  16. package/dist/interfaces/mailer-async-options.interface.d.ts +9 -9
  17. package/dist/interfaces/mailer-async-options.interface.js +2 -2
  18. package/dist/interfaces/mailer-options-factory.interface.d.ts +4 -4
  19. package/dist/interfaces/mailer-options-factory.interface.js +2 -2
  20. package/dist/interfaces/mailer-options.interface.d.ts +35 -35
  21. package/dist/interfaces/mailer-options.interface.js +2 -2
  22. package/dist/interfaces/mailer-send-mail-options.interface.d.ts +5 -5
  23. package/dist/interfaces/mailer-send-mail-options.interface.js +2 -2
  24. package/dist/interfaces/mailer-transport-factory.interface.d.ts +5 -0
  25. package/dist/{constants/mailer-options.constant.js → interfaces/mailer-transport-factory.interface.js} +2 -3
  26. package/dist/interfaces/send-mail-options.interface.d.ts +51 -48
  27. package/dist/interfaces/send-mail-options.interface.js +2 -2
  28. package/dist/interfaces/template-adapter-config.interface.d.ts +5 -0
  29. package/dist/interfaces/template-adapter-config.interface.js +2 -0
  30. package/dist/interfaces/template-adapter.interface.d.ts +4 -4
  31. package/dist/interfaces/template-adapter.interface.js +2 -2
  32. package/dist/mailer-core.module.d.ts +9 -9
  33. package/dist/mailer-core.module.js +73 -72
  34. package/dist/mailer-transport.factory.d.ts +8 -0
  35. package/dist/mailer-transport.factory.js +20 -0
  36. package/dist/mailer.module.d.ts +7 -7
  37. package/dist/mailer.module.js +29 -28
  38. package/dist/mailer.service.d.ts +13 -11
  39. package/dist/mailer.service.js +90 -83
  40. package/docker-compose.yml +18 -18
  41. package/index.d.ts +0 -0
  42. package/index.js +5 -5
  43. package/jest.config.js +17 -17
  44. package/package.json +100 -93
  45. package/dist/constants/mailer-options.constant.d.ts +0 -1
@@ -1,35 +1,35 @@
1
- import { Transport, TransportOptions } from 'nodemailer';
2
- import * as SMTPTransport from 'nodemailer/lib/smtp-transport';
3
- import * as SMTPPool from 'nodemailer/lib/smtp-pool';
4
- import * as SendmailTransport from 'nodemailer/lib/sendmail-transport';
5
- import * as StreamTransport from 'nodemailer/lib/stream-transport';
6
- import * as JSONTransport from 'nodemailer/lib/json-transport';
7
- import * as SESTransport from 'nodemailer/lib/ses-transport';
8
- import { TemplateAdapter } from './template-adapter.interface';
9
- declare type Options = SMTPTransport.Options | SMTPPool.Options | SendmailTransport.Options | StreamTransport.Options | JSONTransport.Options | SESTransport.Options | TransportOptions;
10
- declare type TransportType = Options | SMTPTransport | SMTPPool | SendmailTransport | StreamTransport | JSONTransport | SESTransport | Transport | string;
11
- export interface MailerOptions {
12
- defaults?: Options;
13
- transport?: TransportType;
14
- transports?: {
15
- [name: string]: SMTPTransport | SMTPTransport.Options | string;
16
- };
17
- template?: {
18
- dir?: string;
19
- adapter?: TemplateAdapter;
20
- options?: {
21
- [name: string]: any;
22
- };
23
- };
24
- options?: {
25
- [name: string]: any;
26
- };
27
- preview?: boolean | Partial<{
28
- dir: string;
29
- open: boolean | {
30
- wait: boolean;
31
- app: string | string[];
32
- };
33
- }>;
34
- }
35
- export {};
1
+ import { Transport, TransportOptions } from 'nodemailer';
2
+ import * as SMTPTransport from 'nodemailer/lib/smtp-transport';
3
+ import * as SMTPPool from 'nodemailer/lib/smtp-pool';
4
+ import * as SendmailTransport from 'nodemailer/lib/sendmail-transport';
5
+ import * as StreamTransport from 'nodemailer/lib/stream-transport';
6
+ import * as JSONTransport from 'nodemailer/lib/json-transport';
7
+ import * as SESTransport from 'nodemailer/lib/ses-transport';
8
+ import { TemplateAdapter } from './template-adapter.interface';
9
+ declare type Options = SMTPTransport.Options | SMTPPool.Options | SendmailTransport.Options | StreamTransport.Options | JSONTransport.Options | SESTransport.Options | TransportOptions;
10
+ export declare type TransportType = Options | SMTPTransport | SMTPPool | SendmailTransport | StreamTransport | JSONTransport | SESTransport | Transport | string;
11
+ export interface MailerOptions {
12
+ defaults?: Options;
13
+ transport?: TransportType;
14
+ transports?: {
15
+ [name: string]: SMTPTransport | SMTPTransport.Options | string;
16
+ };
17
+ template?: {
18
+ dir?: string;
19
+ adapter?: TemplateAdapter;
20
+ options?: {
21
+ [name: string]: any;
22
+ };
23
+ };
24
+ options?: {
25
+ [name: string]: any;
26
+ };
27
+ preview?: boolean | Partial<{
28
+ dir: string;
29
+ open: boolean | {
30
+ wait: boolean;
31
+ app: string | string[];
32
+ };
33
+ }>;
34
+ }
35
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- import { SendMailOptions } from 'nodemailer';
2
- export interface MailerSendMailOptions extends SendMailOptions {
3
- template?: string;
4
- context?: any;
5
- }
1
+ import { SendMailOptions } from 'nodemailer';
2
+ export interface MailerSendMailOptions extends SendMailOptions {
3
+ template?: string;
4
+ context?: any;
5
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import * as Mail from 'nodemailer/lib/mailer';
2
+ import { TransportType } from './mailer-options.interface';
3
+ export interface MailerTransportFactory {
4
+ createTransport(opts?: TransportType): Mail;
5
+ }
@@ -1,3 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAILER_OPTIONS = 'MAILER_OPTIONS';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,48 +1,51 @@
1
- /// <reference types="node" />
2
- import { SendMailOptions } from 'nodemailer';
3
- export declare type TextEncoding = 'quoted-printable' | 'base64';
4
- export declare type Headers = {
5
- [key: string]: string | string[] | {
6
- prepared: boolean;
7
- value: string;
8
- };
9
- } | Array<{
10
- key: string;
11
- value: string;
12
- }>;
13
- export interface Address {
14
- name: string;
15
- address: string;
16
- }
17
- export interface AttachmentLikeObject {
18
- path: string;
19
- }
20
- export interface ISendMailOptions extends SendMailOptions {
21
- to?: string | Address | Array<string | Address>;
22
- cc?: string | Address | Array<string | Address>;
23
- replyTo?: string | Address;
24
- inReplyTo?: string | Address;
25
- from?: string | Address;
26
- subject?: string;
27
- text?: string | Buffer | AttachmentLikeObject;
28
- html?: string | Buffer;
29
- sender?: string | Address;
30
- raw?: string | Buffer;
31
- textEncoding?: TextEncoding;
32
- references?: string | string[];
33
- encoding?: string;
34
- date?: Date | string;
35
- headers?: Headers;
36
- context?: {
37
- [name: string]: any;
38
- };
39
- transporterName?: string;
40
- template?: string;
41
- attachments?: {
42
- filename: string;
43
- contents?: any;
44
- path?: string;
45
- contentType?: string;
46
- cid?: string;
47
- }[];
48
- }
1
+ /// <reference types="node" />
2
+ import { SendMailOptions } from 'nodemailer';
3
+ import * as DKIM from 'nodemailer/lib/dkim';
4
+ export declare type TextEncoding = 'quoted-printable' | 'base64';
5
+ export declare type Headers = {
6
+ [key: string]: string | string[] | {
7
+ prepared: boolean;
8
+ value: string;
9
+ };
10
+ } | Array<{
11
+ key: string;
12
+ value: string;
13
+ }>;
14
+ export interface Address {
15
+ name: string;
16
+ address: string;
17
+ }
18
+ export interface AttachmentLikeObject {
19
+ path: string;
20
+ }
21
+ export interface ISendMailOptions extends SendMailOptions {
22
+ to?: string | Address | Array<string | Address>;
23
+ cc?: string | Address | Array<string | Address>;
24
+ bcc?: string | Address | Array<string | Address>;
25
+ replyTo?: string | Address;
26
+ inReplyTo?: string | Address;
27
+ from?: string | Address;
28
+ subject?: string;
29
+ text?: string | Buffer | AttachmentLikeObject;
30
+ html?: string | Buffer;
31
+ sender?: string | Address;
32
+ raw?: string | Buffer;
33
+ textEncoding?: TextEncoding;
34
+ references?: string | string[];
35
+ encoding?: string;
36
+ date?: Date | string;
37
+ headers?: Headers;
38
+ context?: {
39
+ [name: string]: any;
40
+ };
41
+ transporterName?: string;
42
+ template?: string;
43
+ attachments?: {
44
+ filename: string;
45
+ content?: any;
46
+ path?: string;
47
+ contentType?: string;
48
+ cid?: string;
49
+ }[];
50
+ dkim?: DKIM.Options;
51
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ import InlineCss = require('inline-css');
2
+ export interface TemplateAdapterConfig {
3
+ inlineCssOptions?: InlineCss.Options;
4
+ inlineCssEnabled?: boolean;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { MailerOptions } from './mailer-options.interface';
2
- export interface TemplateAdapter {
3
- compile(mail: any, callback: (err?: any, body?: string) => any, options: MailerOptions): void;
4
- }
1
+ import { MailerOptions } from './mailer-options.interface';
2
+ export interface TemplateAdapter {
3
+ compile(mail: any, callback: (err?: any, body?: string) => any, options: MailerOptions): void;
4
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,9 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { MailerOptions } from './interfaces/mailer-options.interface';
3
- import { MailerAsyncOptions } from './interfaces/mailer-async-options.interface';
4
- export declare class MailerCoreModule {
5
- static forRoot(options: MailerOptions): DynamicModule;
6
- static forRootAsync(options: MailerAsyncOptions): DynamicModule;
7
- private static createAsyncProviders;
8
- private static createAsyncOptionsProvider;
9
- }
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { MailerOptions } from './interfaces/mailer-options.interface';
3
+ import { MailerAsyncOptions } from './interfaces/mailer-async-options.interface';
4
+ export declare class MailerCoreModule {
5
+ static forRoot(options: MailerOptions): DynamicModule;
6
+ static forRootAsync(options: MailerAsyncOptions): DynamicModule;
7
+ private static createAsyncProviders;
8
+ private static createAsyncOptionsProvider;
9
+ }
@@ -1,72 +1,73 @@
1
- "use strict";
2
- var MailerCoreModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const mailer_options_constant_1 = require("./constants/mailer-options.constant");
7
- const mailer_service_1 = require("./mailer.service");
8
- let MailerCoreModule = MailerCoreModule_1 = class MailerCoreModule {
9
- static forRoot(options) {
10
- const MailerOptionsProvider = {
11
- provide: mailer_options_constant_1.MAILER_OPTIONS,
12
- useValue: options,
13
- };
14
- return {
15
- module: MailerCoreModule_1,
16
- providers: [
17
- MailerOptionsProvider,
18
- mailer_service_1.MailerService,
19
- ],
20
- exports: [
21
- mailer_service_1.MailerService,
22
- ],
23
- };
24
- }
25
- static forRootAsync(options) {
26
- const providers = this.createAsyncProviders(options);
27
- return {
28
- module: MailerCoreModule_1,
29
- providers: [
30
- ...providers,
31
- mailer_service_1.MailerService,
32
- ],
33
- imports: options.imports,
34
- exports: [
35
- mailer_service_1.MailerService,
36
- ],
37
- };
38
- }
39
- static createAsyncProviders(options) {
40
- const providers = [this.createAsyncOptionsProvider(options)];
41
- if (options.useClass) {
42
- providers.push({
43
- provide: options.useClass,
44
- useClass: options.useClass,
45
- });
46
- }
47
- return providers;
48
- }
49
- static createAsyncOptionsProvider(options) {
50
- if (options.useFactory) {
51
- return {
52
- name: mailer_options_constant_1.MAILER_OPTIONS,
53
- provide: mailer_options_constant_1.MAILER_OPTIONS,
54
- useFactory: options.useFactory,
55
- inject: options.inject || [],
56
- };
57
- }
58
- return {
59
- name: mailer_options_constant_1.MAILER_OPTIONS,
60
- provide: mailer_options_constant_1.MAILER_OPTIONS,
61
- useFactory: (optionsFactory) => tslib_1.__awaiter(this, void 0, void 0, function* () {
62
- return optionsFactory.createMailerOptions();
63
- }),
64
- inject: [options.useExisting || options.useClass],
65
- };
66
- }
67
- };
68
- MailerCoreModule = MailerCoreModule_1 = tslib_1.__decorate([
69
- common_1.Global(),
70
- common_1.Module({})
71
- ], MailerCoreModule);
72
- exports.MailerCoreModule = MailerCoreModule;
1
+ "use strict";
2
+ var MailerCoreModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MailerCoreModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const mailer_constant_1 = require("./constants/mailer.constant");
8
+ const mailer_service_1 = require("./mailer.service");
9
+ let MailerCoreModule = MailerCoreModule_1 = class MailerCoreModule {
10
+ static forRoot(options) {
11
+ const MailerOptionsProvider = {
12
+ provide: mailer_constant_1.MAILER_OPTIONS,
13
+ useValue: options,
14
+ };
15
+ return {
16
+ module: MailerCoreModule_1,
17
+ providers: [
18
+ MailerOptionsProvider,
19
+ mailer_service_1.MailerService,
20
+ ],
21
+ exports: [
22
+ mailer_service_1.MailerService,
23
+ ],
24
+ };
25
+ }
26
+ static forRootAsync(options) {
27
+ const providers = this.createAsyncProviders(options);
28
+ return {
29
+ module: MailerCoreModule_1,
30
+ providers: [
31
+ ...providers,
32
+ mailer_service_1.MailerService,
33
+ ],
34
+ imports: options.imports,
35
+ exports: [
36
+ mailer_service_1.MailerService,
37
+ ],
38
+ };
39
+ }
40
+ static createAsyncProviders(options) {
41
+ const providers = [this.createAsyncOptionsProvider(options)];
42
+ if (options.useClass) {
43
+ providers.push({
44
+ provide: options.useClass,
45
+ useClass: options.useClass,
46
+ });
47
+ }
48
+ return providers;
49
+ }
50
+ static createAsyncOptionsProvider(options) {
51
+ if (options.useFactory) {
52
+ return {
53
+ name: mailer_constant_1.MAILER_OPTIONS,
54
+ provide: mailer_constant_1.MAILER_OPTIONS,
55
+ useFactory: options.useFactory,
56
+ inject: options.inject || [],
57
+ };
58
+ }
59
+ return {
60
+ name: mailer_constant_1.MAILER_OPTIONS,
61
+ provide: mailer_constant_1.MAILER_OPTIONS,
62
+ useFactory: (optionsFactory) => tslib_1.__awaiter(this, void 0, void 0, function* () {
63
+ return optionsFactory.createMailerOptions();
64
+ }),
65
+ inject: [options.useExisting || options.useClass],
66
+ };
67
+ }
68
+ };
69
+ MailerCoreModule = MailerCoreModule_1 = tslib_1.__decorate([
70
+ common_1.Global(),
71
+ common_1.Module({})
72
+ ], MailerCoreModule);
73
+ exports.MailerCoreModule = MailerCoreModule;
@@ -0,0 +1,8 @@
1
+ import * as Mail from 'nodemailer/lib/mailer';
2
+ import { MailerOptions, TransportType } from './interfaces/mailer-options.interface';
3
+ import { MailerTransportFactory as IMailerTransportFactory } from './interfaces/mailer-transport-factory.interface';
4
+ export declare class MailerTransportFactory implements IMailerTransportFactory {
5
+ private readonly options;
6
+ constructor(options: MailerOptions);
7
+ createTransport(opts?: TransportType): Mail;
8
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MailerTransportFactory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const nodemailer_1 = require("nodemailer");
6
+ const common_1 = require("@nestjs/common");
7
+ const mailer_constant_1 = require("./constants/mailer.constant");
8
+ let MailerTransportFactory = class MailerTransportFactory {
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+ createTransport(opts) {
13
+ return nodemailer_1.createTransport(opts || this.options.transport, this.options.defaults);
14
+ }
15
+ };
16
+ MailerTransportFactory = tslib_1.__decorate([
17
+ tslib_1.__param(0, common_1.Inject(mailer_constant_1.MAILER_OPTIONS)),
18
+ tslib_1.__metadata("design:paramtypes", [Object])
19
+ ], MailerTransportFactory);
20
+ exports.MailerTransportFactory = MailerTransportFactory;
@@ -1,7 +1,7 @@
1
- import { DynamicModule } from '@nestjs/common';
2
- import { MailerOptions } from './interfaces/mailer-options.interface';
3
- import { MailerAsyncOptions } from './interfaces/mailer-async-options.interface';
4
- export declare class MailerModule {
5
- static forRoot(options?: MailerOptions): DynamicModule;
6
- static forRootAsync(options: MailerAsyncOptions): DynamicModule;
7
- }
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { MailerOptions } from './interfaces/mailer-options.interface';
3
+ import { MailerAsyncOptions } from './interfaces/mailer-async-options.interface';
4
+ export declare class MailerModule {
5
+ static forRoot(options?: MailerOptions): DynamicModule;
6
+ static forRootAsync(options: MailerAsyncOptions): DynamicModule;
7
+ }
@@ -1,28 +1,29 @@
1
- "use strict";
2
- var MailerModule_1;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@nestjs/common");
6
- const mailer_core_module_1 = require("./mailer-core.module");
7
- let MailerModule = MailerModule_1 = class MailerModule {
8
- static forRoot(options) {
9
- return {
10
- module: MailerModule_1,
11
- imports: [
12
- mailer_core_module_1.MailerCoreModule.forRoot(options),
13
- ],
14
- };
15
- }
16
- static forRootAsync(options) {
17
- return {
18
- module: MailerModule_1,
19
- imports: [
20
- mailer_core_module_1.MailerCoreModule.forRootAsync(options),
21
- ],
22
- };
23
- }
24
- };
25
- MailerModule = MailerModule_1 = tslib_1.__decorate([
26
- common_1.Module({})
27
- ], MailerModule);
28
- exports.MailerModule = MailerModule;
1
+ "use strict";
2
+ var MailerModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.MailerModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const mailer_core_module_1 = require("./mailer-core.module");
8
+ let MailerModule = MailerModule_1 = class MailerModule {
9
+ static forRoot(options) {
10
+ return {
11
+ module: MailerModule_1,
12
+ imports: [
13
+ mailer_core_module_1.MailerCoreModule.forRoot(options),
14
+ ],
15
+ };
16
+ }
17
+ static forRootAsync(options) {
18
+ return {
19
+ module: MailerModule_1,
20
+ imports: [
21
+ mailer_core_module_1.MailerCoreModule.forRootAsync(options),
22
+ ],
23
+ };
24
+ }
25
+ };
26
+ MailerModule = MailerModule_1 = tslib_1.__decorate([
27
+ common_1.Module({})
28
+ ], MailerModule);
29
+ exports.MailerModule = MailerModule;
@@ -1,11 +1,13 @@
1
- import { SentMessageInfo } from 'nodemailer';
2
- import { MailerOptions } from './interfaces/mailer-options.interface';
3
- import { ISendMailOptions } from './interfaces/send-mail-options.interface';
4
- export declare class MailerService {
5
- private readonly mailerOptions;
6
- private transporter;
7
- private transporters;
8
- private initTemplateAdapter;
9
- constructor(mailerOptions: MailerOptions);
10
- sendMail(sendMailOptions: ISendMailOptions): Promise<SentMessageInfo>;
11
- }
1
+ import { SentMessageInfo } from 'nodemailer';
2
+ import { MailerOptions } from './interfaces/mailer-options.interface';
3
+ import { ISendMailOptions } from './interfaces/send-mail-options.interface';
4
+ import { MailerTransportFactory as IMailerTransportFactory } from './interfaces/mailer-transport-factory.interface';
5
+ export declare class MailerService {
6
+ private readonly mailerOptions;
7
+ private readonly transportFactory;
8
+ private transporter;
9
+ private transporters;
10
+ private initTemplateAdapter;
11
+ constructor(mailerOptions: MailerOptions, transportFactory: IMailerTransportFactory);
12
+ sendMail(sendMailOptions: ISendMailOptions): Promise<SentMessageInfo>;
13
+ }