@hedhog/mail 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  export declare enum MailConfigurationTypeEnum {
2
2
  AWS = "AWS",
3
+ SMTP = "SMTP",
3
4
  GMAIL = "GMAIL"
4
5
  }
5
6
  //# sourceMappingURL=mail-configuration-type.enum.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mail-configuration-type.enum.d.ts","sourceRoot":"","sources":["../../src/enums/mail-configuration-type.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,yBAAyB;IACjC,GAAG,QAAQ;IACX,KAAK,UAAU;CAClB"}
1
+ {"version":3,"file":"mail-configuration-type.enum.d.ts","sourceRoot":"","sources":["../../src/enums/mail-configuration-type.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,yBAAyB;IACnC,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,KAAK,UAAU;CAChB"}
@@ -4,6 +4,7 @@ exports.MailConfigurationTypeEnum = void 0;
4
4
  var MailConfigurationTypeEnum;
5
5
  (function (MailConfigurationTypeEnum) {
6
6
  MailConfigurationTypeEnum["AWS"] = "AWS";
7
+ MailConfigurationTypeEnum["SMTP"] = "SMTP";
7
8
  MailConfigurationTypeEnum["GMAIL"] = "GMAIL";
8
9
  })(MailConfigurationTypeEnum || (exports.MailConfigurationTypeEnum = MailConfigurationTypeEnum = {}));
9
10
  //# sourceMappingURL=mail-configuration-type.enum.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mail-configuration-type.enum.js","sourceRoot":"","sources":["../../src/enums/mail-configuration-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,yBAGX;AAHD,WAAY,yBAAyB;IACjC,wCAAW,CAAA;IACX,4CAAe,CAAA;AACnB,CAAC,EAHW,yBAAyB,yCAAzB,yBAAyB,QAGpC"}
1
+ {"version":3,"file":"mail-configuration-type.enum.js","sourceRoot":"","sources":["../../src/enums/mail-configuration-type.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,yBAIX;AAJD,WAAY,yBAAyB;IACnC,wCAAW,CAAA;IACX,0CAAa,CAAA;IACb,4CAAe,CAAA;AACjB,CAAC,EAJW,yBAAyB,yCAAzB,yBAAyB,QAIpC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './enums/mail-configuration-type.enum';
2
+ export * from './interfaces';
1
3
  export * from './mail.module';
2
4
  export * from './mail.service';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sCAAsC,CAAC;AACrD,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -14,6 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./enums/mail-configuration-type.enum"), exports);
18
+ __exportStar(require("./interfaces"), exports);
17
19
  __exportStar(require("./mail.module"), exports);
18
20
  __exportStar(require("./mail.service"), exports);
19
21
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uEAAqD;AACrD,+CAA6B;AAC7B,gDAA8B;AAC9B,iDAA+B"}
@@ -0,0 +1,3 @@
1
+ export * from './mail-module-options.interface';
2
+ export * from './mail-type';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./mail-module-options.interface"), exports);
18
+ __exportStar(require("./mail-type"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kEAAgD;AAChD,8CAA4B"}
@@ -1,13 +1,36 @@
1
- import { MailConfigurationTypeEnum } from "../enums/mail-configuration-type.enum";
2
- export interface MailModuleOptions {
3
- global?: boolean;
4
- mailConfigurationType: MailConfigurationTypeEnum;
5
- host?: string;
6
- from?: string;
7
- accessKeyId?: string;
8
- secretAccessKey?: string;
9
- clientId?: string;
10
- clientSecret?: string;
11
- refreshToken?: string;
1
+ import { ModuleMetadata, Provider, Type } from '@nestjs/common';
2
+ export type MailModuleOptions = {
3
+ global?: boolean;
4
+ type: 'AWS';
5
+ region: string;
6
+ accessKeyId: string;
7
+ secretAccessKey: string;
8
+ from: string;
9
+ } | {
10
+ global?: boolean;
11
+ type: 'SMTP';
12
+ host: string;
13
+ port: number;
14
+ secure?: boolean;
15
+ user: string;
16
+ pass: string;
17
+ } | {
18
+ global?: boolean;
19
+ type: 'GMAIL';
20
+ clientId: string;
21
+ clientSecret: string;
22
+ refreshToken: string;
23
+ from: string;
24
+ };
25
+ export interface MailOptionsFactory {
26
+ createMailOptions(): Promise<MailModuleOptions> | MailModuleOptions;
27
+ }
28
+ export interface MailModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
29
+ global?: boolean;
30
+ useExisting?: Type<MailOptionsFactory>;
31
+ useClass?: Type<MailOptionsFactory>;
32
+ useFactory?: (...args: any[]) => Promise<MailModuleOptions> | MailModuleOptions;
33
+ inject?: any[];
34
+ extraProviders?: Provider[];
12
35
  }
13
36
  //# sourceMappingURL=mail-module-options.interface.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mail-module-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mail-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAElF,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,qBAAqB,EAAE,yBAAyB,CAAC;IACjD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB"}
1
+ {"version":3,"file":"mail-module-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mail-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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 -1,6 +1,9 @@
1
1
  import { DynamicModule } from '@nestjs/common';
2
- import { MailModuleOptions } from './interfaces/mail-module-options.interface';
2
+ import { MailModuleAsyncOptions, MailModuleOptions } from './interfaces/mail-module-options.interface';
3
3
  export declare class MailModule {
4
- static init(options: MailModuleOptions): DynamicModule;
4
+ static register(options: MailModuleOptions): DynamicModule;
5
+ static registerAsync(options: MailModuleAsyncOptions): DynamicModule;
6
+ private static createAsyncProviders;
7
+ private static createAsyncOptionsProvider;
5
8
  }
6
9
  //# sourceMappingURL=mail.module.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mail.module.d.ts","sourceRoot":"","sources":["../src/mail.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAU,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAK/E,qBAKa,UAAU;IACrB,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;CAYvD"}
1
+ {"version":3,"file":"mail.module.d.ts","sourceRoot":"","sources":["../src/mail.module.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AACjE,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EAElB,MAAM,4CAA4C,CAAC;AAIpD,qBAKa,UAAU;IACrB,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;IAc1D,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa;IAYpE,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAenC,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAiB1C"}
@@ -8,12 +8,13 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var MailModule_1;
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MailModule = void 0;
11
+ const axios_1 = require("@nestjs/axios");
11
12
  const common_1 = require("@nestjs/common");
12
- const mail_service_1 = require("./mail.service");
13
13
  const mail_consts_1 = require("./mail.consts");
14
- const axios_1 = require("@nestjs/axios");
14
+ const mail_service_1 = require("./mail.service");
15
15
  let MailModule = MailModule_1 = class MailModule {
16
- static init(options) {
16
+ static register(options) {
17
+ console.log('MailModule.register', { options });
17
18
  return {
18
19
  module: MailModule_1,
19
20
  global: options.global,
@@ -25,6 +26,44 @@ let MailModule = MailModule_1 = class MailModule {
25
26
  ],
26
27
  };
27
28
  }
29
+ static registerAsync(options) {
30
+ var _a;
31
+ return {
32
+ module: MailModule_1,
33
+ global: options.global,
34
+ imports: options.imports || [],
35
+ providers: [
36
+ ...this.createAsyncProviders(options),
37
+ ...((_a = options.extraProviders) !== null && _a !== void 0 ? _a : []),
38
+ ],
39
+ };
40
+ }
41
+ static createAsyncProviders(options) {
42
+ if (options.useExisting || options.useFactory) {
43
+ return [this.createAsyncOptionsProvider(options)];
44
+ }
45
+ return [
46
+ this.createAsyncOptionsProvider(options),
47
+ {
48
+ provide: options.useClass,
49
+ useClass: options.useClass,
50
+ },
51
+ ];
52
+ }
53
+ static createAsyncOptionsProvider(options) {
54
+ if (options.useFactory) {
55
+ return {
56
+ provide: mail_consts_1.MAIL_MODULE_OPTIONS,
57
+ useFactory: options.useFactory,
58
+ inject: options.inject || [],
59
+ };
60
+ }
61
+ return {
62
+ provide: mail_consts_1.MAIL_MODULE_OPTIONS,
63
+ useFactory: async (optionsFactory) => await optionsFactory.createMailOptions(),
64
+ inject: [options.useExisting || options.useClass],
65
+ };
66
+ }
28
67
  };
29
68
  exports.MailModule = MailModule;
30
69
  exports.MailModule = MailModule = MailModule_1 = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"mail.module.js","sourceRoot":"","sources":["../src/mail.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,iDAA6C;AAG7C,+CAAoD;AACpD,yCAAwD;AAOjD,IAAM,UAAU,kBAAhB,MAAM,UAAU;IACrB,MAAM,CA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O,MAAM,CAAC,oBAAoB,CACjC,OAA+B;QAE/B,IAAI,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YAC9C,OAAO,CAAC,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO;YACL,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YACxC;gBACE,OAAO,EAAE,OAAO,CAAC,QAAQ;gBACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,0BAA0B,CACvC,OAA+B;QAE/B,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO;gBACL,OAAO,EAAE,iCAAmB;gBAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;aAC7B,CAAC;QACJ,CAAC;QACD,OAAO;YACL,OAAO,EAAE,iCAAmB;YAC5B,UAAU,EAAE,KAAK,EAAE,cAAkC,EAAE,EAAE,CACvD,MAAM,cAAc,CAAC,iBAAiB,EAAE;YAC1C,MAAM,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAQ,CAAC;SAClD,CAAC;IACJ,CAAC;CACF,CAAA;AA3DY,gCAAU;qBAAV,UAAU;IALtB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,kBAAU,CAAC;QACrB,SAAS,EAAE,CAAC,0BAAW,CAAC;QACxB,OAAO,EAAE,CAAC,0BAAW,CAAC;KACvB,CAAC;GACW,UAAU,CA2DtB"}
@@ -1,14 +1,14 @@
1
- import { Mail } from './mail.consts';
2
- import { SES } from 'aws-sdk';
3
- import { MailModuleOptions } from './interfaces/mail-module-options.interface';
4
1
  import { HttpService } from '@nestjs/axios';
2
+ import { MailModuleOptions } from './interfaces/mail-module-options.interface';
3
+ import { Mail } from './mail.consts';
5
4
  export declare class MailService {
6
5
  private readonly mailConfig;
7
6
  private readonly httpService;
8
7
  constructor(mailConfig: MailModuleOptions, httpService: HttpService);
9
- send(mail: Mail): Promise<void>;
8
+ send(mail: Mail): Promise<any>;
10
9
  createRawEmail(mail: Mail): Promise<string>;
10
+ sendWithSMTP(mail: Mail): Promise<any>;
11
11
  sendWithGmail(mail: Mail): Promise<import("axios").AxiosResponse<any, any>>;
12
- sendWithSES(mail: Mail): Promise<import("aws-sdk/lib/request").PromiseResult<SES.SendRawEmailResponse, import("aws-sdk").AWSError>>;
12
+ sendWithSES(mail: Mail): Promise<import("aws-sdk/lib/request").PromiseResult<import("aws-sdk/clients/ses").SendRawEmailResponse, import("aws-sdk").AWSError>>;
13
13
  }
14
14
  //# sourceMappingURL=mail.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mail.service.d.ts","sourceRoot":"","sources":["../src/mail.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAuB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,qBACa,WAAW;IAES,OAAO,CAAC,QAAQ,CAAC,UAAU;IACxD,OAAO,CAAC,QAAQ,CAAC,WAAW;gBADkB,UAAU,EAAE,iBAAiB,EAC1D,WAAW,EAAE,WAAW;IAGrC,IAAI,CAAC,IAAI,EAAE,IAAI;IAYf,cAAc,CAAC,IAAI,EAAE,IAAI;IAyEzB,aAAa,CAAC,IAAI,EAAE,IAAI;IAqCxB,WAAW,CAAC,IAAI,EAAE,IAAI;CAoH7B"}
1
+ {"version":3,"file":"mail.service.d.ts","sourceRoot":"","sources":["../src/mail.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAK5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAuB,MAAM,eAAe,CAAC;AAE1D,qBACa,WAAW;IAES,OAAO,CAAC,QAAQ,CAAC,UAAU;IACxD,OAAO,CAAC,QAAQ,CAAC,WAAW;gBADkB,UAAU,EAAE,iBAAiB,EAC1D,WAAW,EAAE,WAAW;IAGrC,IAAI,CAAC,IAAI,EAAE,IAAI;IAaf,cAAc,CAAC,IAAI,EAAE,IAAI;IAyEzB,YAAY,CAAC,IAAI,EAAE,IAAI;IA+BvB,aAAa,CAAC,IAAI,EAAE,IAAI;IA0CxB,WAAW,CAAC,IAAI,EAAE,IAAI;CAyH7B"}
@@ -36,31 +36,29 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.MailService = void 0;
39
+ const axios_1 = require("@nestjs/axios");
39
40
  const common_1 = require("@nestjs/common");
40
- const mail_consts_1 = require("./mail.consts");
41
- const aws_sdk_1 = require("aws-sdk");
42
41
  const mimemessage = __importStar(require("mimemessage"));
43
- const mail_configuration_type_enum_1 = require("./enums/mail-configuration-type.enum");
44
- const googleapis_1 = require("googleapis");
45
- const axios_1 = require("@nestjs/axios");
46
42
  const rxjs_1 = require("rxjs");
43
+ const mail_configuration_type_enum_1 = require("./enums/mail-configuration-type.enum");
44
+ const mail_consts_1 = require("./mail.consts");
47
45
  let MailService = class MailService {
48
46
  constructor(mailConfig, httpService) {
49
47
  this.mailConfig = mailConfig;
50
48
  this.httpService = httpService;
51
49
  }
52
50
  async send(mail) {
53
- switch (this.mailConfig.mailConfigurationType) {
51
+ switch (this.mailConfig.type) {
54
52
  case mail_configuration_type_enum_1.MailConfigurationTypeEnum.AWS:
55
- await this.sendWithSES(mail);
56
- break;
53
+ return this.sendWithSES(mail);
57
54
  case mail_configuration_type_enum_1.MailConfigurationTypeEnum.GMAIL:
58
- await this.sendWithGmail(mail);
59
- break;
55
+ return this.sendWithGmail(mail);
56
+ case mail_configuration_type_enum_1.MailConfigurationTypeEnum.SMTP:
57
+ return this.sendWithSMTP(mail);
60
58
  }
61
59
  }
62
60
  async createRawEmail(mail) {
63
- var _a;
61
+ var _a, _b;
64
62
  if (mail.attachments instanceof Array && ((_a = mail.attachments) === null || _a === void 0 ? void 0 : _a.length)) {
65
63
  const mailContent = mimemessage.factory({
66
64
  contentType: 'multipart/mixed',
@@ -79,7 +77,7 @@ let MailService = class MailService {
79
77
  });
80
78
  alternateEntity.body.push(htmlEntity);
81
79
  mailContent.body.push(alternateEntity);
82
- await Promise.all(mail.attachments.map(async (attachment) => {
80
+ await Promise.all(((_b = mail.attachments) !== null && _b !== void 0 ? _b : []).map(async (attachment) => {
83
81
  const attachmentEntity = mimemessage.factory({
84
82
  contentType: attachment.contentType,
85
83
  contentTransferEncoding: 'base64',
@@ -116,10 +114,40 @@ let MailService = class MailService {
116
114
  return encodedMessage;
117
115
  }
118
116
  }
117
+ async sendWithSMTP(mail) {
118
+ if (this.mailConfig.type !== 'SMTP') {
119
+ throw new Error('Invalid mail configuration type');
120
+ }
121
+ const { pass, user, host, port, secure = false } = this.mailConfig;
122
+ const nodemailer = await Promise.resolve().then(() => __importStar(require('nodemailer')));
123
+ const transporter = nodemailer.createTransport({
124
+ host,
125
+ port,
126
+ secure,
127
+ auth: {
128
+ user,
129
+ pass,
130
+ },
131
+ });
132
+ return transporter.sendMail({
133
+ from: mail.from || process.env.SMTP_FROM || process.env.SMTP_USER,
134
+ to: mail.to,
135
+ subject: mail.subject,
136
+ html: mail.body,
137
+ cc: mail.cc,
138
+ bcc: mail.bcc,
139
+ replyTo: mail.replyTo,
140
+ priority: mail.priority,
141
+ });
142
+ }
119
143
  async sendWithGmail(mail) {
144
+ if (this.mailConfig.type !== 'GMAIL') {
145
+ throw new Error('Invalid mail configuration type');
146
+ }
120
147
  const { clientId, clientSecret, from, refreshToken } = this.mailConfig;
121
148
  const redirectURI = 'https://developers.google.com/oauthplayground';
122
- const oauth2Client = new googleapis_1.google.auth.OAuth2(clientId, clientSecret, redirectURI);
149
+ const { google } = await Promise.resolve().then(() => __importStar(require('googleapis')));
150
+ const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, redirectURI);
123
151
  oauth2Client.setCredentials({
124
152
  refresh_token: refreshToken,
125
153
  });
@@ -137,10 +165,15 @@ let MailService = class MailService {
137
165
  return (0, rxjs_1.firstValueFrom)(response);
138
166
  }
139
167
  async sendWithSES(mail) {
140
- const { host, from, accessKeyId, secretAccessKey } = this.mailConfig;
141
- const ses = new aws_sdk_1.SES({
168
+ var _a;
169
+ if (this.mailConfig.type !== 'AWS') {
170
+ throw new Error('Invalid mail configuration type');
171
+ }
172
+ const { region, from, accessKeyId, secretAccessKey } = this.mailConfig;
173
+ const { SES } = await Promise.resolve().then(() => __importStar(require('aws-sdk')));
174
+ const ses = new SES({
142
175
  apiVersion: '2010-12-01',
143
- region: host.split('.')[1],
176
+ region,
144
177
  credentials: {
145
178
  accessKeyId,
146
179
  secretAccessKey,
@@ -191,7 +224,7 @@ let MailService = class MailService {
191
224
  });
192
225
  alternateEntity.body.push(htmlEntity);
193
226
  mailContent.body.push(alternateEntity);
194
- await Promise.all(mail.attachments.map((item) => {
227
+ await Promise.all(((_a = mail.attachments) !== null && _a !== void 0 ? _a : []).map((item) => {
195
228
  const attachmentEntity = mimemessage.factory({
196
229
  contentType: item.contentType,
197
230
  contentTransferEncoding: 'base64',
@@ -1 +1 @@
1
- {"version":3,"file":"mail.service.js","sourceRoot":"","sources":["../src/mail.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,+CAA0D;AAC1D,qCAA8B;AAC9B,yDAA2C;AAC3C,uFAAiF;AAEjF,2CAAoC;AACpC,yCAA4C;AAC5C,+BAAsC;AAG/B,IAAM,WAAW,GAAjB,MAAM,WAAW;IACtB,YACgD,UAA6B,EAC1D,WAAwB;QADK,eAAU,GAAV,UAAU,CAAmB;QAC1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AEF,OAAO,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;QACzC,CAAC;IACH,CAAC;CACF,CAAA;AA9RY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,iCAAmB,CAAC,CAAA;6CACE,mBAAW;GAHhC,WAAW,CA8RvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedhog/mail",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "build": "tsc --project tsconfig.production.json && npm version patch",
@@ -9,5 +9,24 @@
9
9
  "keywords": [],
10
10
  "author": "HedHog",
11
11
  "license": "MIT",
12
- "description": ""
12
+ "description": "",
13
+ "dependencies": {
14
+ "mimemessage": "1.0.5"
15
+ },
16
+ "peerDependencies": {
17
+ "aws-sdk": "2.1691.0",
18
+ "googleapis": "144.0.0",
19
+ "nodemailer": "6.9.15"
20
+ },
21
+ "peerDependenciesMeta": {
22
+ "aws-sdk": {
23
+ "optional": true
24
+ },
25
+ "googleapis": {
26
+ "optional": true
27
+ },
28
+ "nodemailer": {
29
+ "optional": true
30
+ }
31
+ }
13
32
  }
@@ -1,4 +1,5 @@
1
1
  export enum MailConfigurationTypeEnum {
2
- AWS = 'AWS',
3
- GMAIL = 'GMAIL',
4
- }
2
+ AWS = 'AWS',
3
+ SMTP = 'SMTP',
4
+ GMAIL = 'GMAIL',
5
+ }
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
+ export * from './enums/mail-configuration-type.enum';
2
+ export * from './interfaces';
1
3
  export * from './mail.module';
2
4
  export * from './mail.service';
@@ -0,0 +1,2 @@
1
+ export * from './mail-module-options.interface';
2
+ export * from './mail-type';
@@ -1,13 +1,44 @@
1
- import { MailConfigurationTypeEnum } from "../enums/mail-configuration-type.enum";
1
+ import { ModuleMetadata, Provider, Type } from '@nestjs/common';
2
2
 
3
- export interface MailModuleOptions {
4
- global?: boolean;
5
- mailConfigurationType: MailConfigurationTypeEnum;
6
- host?: string;
7
- from?: string;
8
- accessKeyId?: string;
9
- secretAccessKey?: string;
10
- clientId?: string;
11
- clientSecret?: string;
12
- refreshToken?: string;
13
- }
3
+ export type MailModuleOptions =
4
+ | {
5
+ global?: boolean;
6
+ type: 'AWS';
7
+ region: string;
8
+ accessKeyId: string;
9
+ secretAccessKey: string;
10
+ from: string;
11
+ }
12
+ | {
13
+ global?: boolean;
14
+ type: 'SMTP';
15
+ host: string;
16
+ port: number;
17
+ secure?: boolean;
18
+ user: string;
19
+ pass: string;
20
+ }
21
+ | {
22
+ global?: boolean;
23
+ type: 'GMAIL';
24
+ clientId: string;
25
+ clientSecret: string;
26
+ refreshToken: string;
27
+ from: string;
28
+ };
29
+
30
+ export interface MailOptionsFactory {
31
+ createMailOptions(): Promise<MailModuleOptions> | MailModuleOptions;
32
+ }
33
+
34
+ export interface MailModuleAsyncOptions
35
+ extends Pick<ModuleMetadata, 'imports'> {
36
+ global?: boolean;
37
+ useExisting?: Type<MailOptionsFactory>;
38
+ useClass?: Type<MailOptionsFactory>;
39
+ useFactory?: (
40
+ ...args: any[]
41
+ ) => Promise<MailModuleOptions> | MailModuleOptions;
42
+ inject?: any[];
43
+ extraProviders?: Provider[];
44
+ }
@@ -1,9 +1,12 @@
1
- import { DynamicModule, Module } from '@nestjs/common';
2
- import { MailService } from './mail.service';
3
- import { MailModuleOptions } from './interfaces/mail-module-options.interface';
4
- import { MailConfigurationTypeEnum } from './enums/mail-configuration-type.enum';
1
+ import { HttpModule } from '@nestjs/axios';
2
+ import { DynamicModule, Module, Provider } from '@nestjs/common';
3
+ import {
4
+ MailModuleAsyncOptions,
5
+ MailModuleOptions,
6
+ MailOptionsFactory,
7
+ } from './interfaces/mail-module-options.interface';
5
8
  import { MAIL_MODULE_OPTIONS } from './mail.consts';
6
- import { HttpModule, HttpService } from '@nestjs/axios';
9
+ import { MailService } from './mail.service';
7
10
 
8
11
  @Module({
9
12
  imports: [HttpModule],
@@ -11,7 +14,8 @@ import { HttpModule, HttpService } from '@nestjs/axios';
11
14
  exports: [MailService],
12
15
  })
13
16
  export class MailModule {
14
- static init(options: MailModuleOptions): DynamicModule {
17
+ static register(options: MailModuleOptions): DynamicModule {
18
+ console.log('MailModule.register', { options });
15
19
  return {
16
20
  module: MailModule,
17
21
  global: options.global,
@@ -23,4 +27,49 @@ export class MailModule {
23
27
  ],
24
28
  };
25
29
  }
30
+
31
+ static registerAsync(options: MailModuleAsyncOptions): DynamicModule {
32
+ return {
33
+ module: MailModule,
34
+ global: options.global,
35
+ imports: options.imports || [],
36
+ providers: [
37
+ ...this.createAsyncProviders(options),
38
+ ...(options.extraProviders ?? []),
39
+ ],
40
+ };
41
+ }
42
+
43
+ private static createAsyncProviders(
44
+ options: MailModuleAsyncOptions,
45
+ ): Provider[] {
46
+ if (options.useExisting || options.useFactory) {
47
+ return [this.createAsyncOptionsProvider(options)];
48
+ }
49
+ return [
50
+ this.createAsyncOptionsProvider(options),
51
+ {
52
+ provide: options.useClass,
53
+ useClass: options.useClass,
54
+ },
55
+ ];
56
+ }
57
+
58
+ private static createAsyncOptionsProvider(
59
+ options: MailModuleAsyncOptions,
60
+ ): Provider {
61
+ if (options.useFactory) {
62
+ return {
63
+ provide: MAIL_MODULE_OPTIONS,
64
+ useFactory: options.useFactory,
65
+ inject: options.inject || [],
66
+ };
67
+ }
68
+ return {
69
+ provide: MAIL_MODULE_OPTIONS,
70
+ useFactory: async (optionsFactory: MailOptionsFactory) =>
71
+ await optionsFactory.createMailOptions(),
72
+ inject: [options.useExisting || options.useClass],
73
+ };
74
+ }
26
75
  }
@@ -1,12 +1,10 @@
1
+ import { HttpService } from '@nestjs/axios';
1
2
  import { Inject, Injectable } from '@nestjs/common';
2
- import { Mail, MAIL_MODULE_OPTIONS } from './mail.consts';
3
- import { SES } from 'aws-sdk';
4
3
  import * as mimemessage from 'mimemessage';
4
+ import { firstValueFrom } from 'rxjs';
5
5
  import { MailConfigurationTypeEnum } from './enums/mail-configuration-type.enum';
6
6
  import { MailModuleOptions } from './interfaces/mail-module-options.interface';
7
- import { google } from 'googleapis';
8
- import { HttpService } from '@nestjs/axios';
9
- import { firstValueFrom } from 'rxjs';
7
+ import { Mail, MAIL_MODULE_OPTIONS } from './mail.consts';
10
8
 
11
9
  @Injectable()
12
10
  export class MailService {
@@ -16,14 +14,15 @@ export class MailService {
16
14
  ) {}
17
15
 
18
16
  async send(mail: Mail) {
19
- switch (this.mailConfig.mailConfigurationType) {
17
+ switch (this.mailConfig.type) {
20
18
  case MailConfigurationTypeEnum.AWS:
21
- await this.sendWithSES(mail);
22
- break;
19
+ return this.sendWithSES(mail);
23
20
 
24
21
  case MailConfigurationTypeEnum.GMAIL:
25
- await this.sendWithGmail(mail);
26
- break;
22
+ return this.sendWithGmail(mail);
23
+
24
+ case MailConfigurationTypeEnum.SMTP:
25
+ return this.sendWithSMTP(mail);
27
26
  }
28
27
  }
29
28
 
@@ -53,7 +52,7 @@ export class MailService {
53
52
  mailContent.body.push(alternateEntity);
54
53
 
55
54
  await Promise.all(
56
- mail.attachments.map(async (attachment) => {
55
+ (mail.attachments ?? []).map(async (attachment) => {
57
56
  const attachmentEntity = mimemessage.factory({
58
57
  contentType: attachment.contentType,
59
58
  contentTransferEncoding: 'base64',
@@ -100,10 +99,46 @@ export class MailService {
100
99
  }
101
100
  }
102
101
 
102
+ async sendWithSMTP(mail: Mail) {
103
+ if (this.mailConfig.type !== 'SMTP') {
104
+ throw new Error('Invalid mail configuration type');
105
+ }
106
+
107
+ const { pass, user, host, port, secure = false } = this.mailConfig;
108
+
109
+ const nodemailer = await import('nodemailer');
110
+
111
+ const transporter = nodemailer.createTransport({
112
+ host,
113
+ port,
114
+ secure,
115
+ auth: {
116
+ user,
117
+ pass,
118
+ },
119
+ });
120
+
121
+ return transporter.sendMail({
122
+ from: mail.from || process.env.SMTP_FROM || process.env.SMTP_USER,
123
+ to: mail.to,
124
+ subject: mail.subject,
125
+ html: mail.body,
126
+ cc: mail.cc,
127
+ bcc: mail.bcc,
128
+ replyTo: mail.replyTo,
129
+ priority: mail.priority,
130
+ });
131
+ }
132
+
103
133
  async sendWithGmail(mail: Mail) {
134
+ if (this.mailConfig.type !== 'GMAIL') {
135
+ throw new Error('Invalid mail configuration type');
136
+ }
104
137
  const { clientId, clientSecret, from, refreshToken } = this.mailConfig;
105
138
  const redirectURI = 'https://developers.google.com/oauthplayground';
106
139
 
140
+ const { google } = await import('googleapis');
141
+
107
142
  const oauth2Client = new google.auth.OAuth2(
108
143
  clientId,
109
144
  clientSecret,
@@ -138,11 +173,16 @@ export class MailService {
138
173
  }
139
174
 
140
175
  async sendWithSES(mail: Mail) {
141
- const { host, from, accessKeyId, secretAccessKey } = this.mailConfig;
176
+ if (this.mailConfig.type !== 'AWS') {
177
+ throw new Error('Invalid mail configuration type');
178
+ }
179
+ const { region, from, accessKeyId, secretAccessKey } = this.mailConfig;
180
+
181
+ const { SES } = await import('aws-sdk');
142
182
 
143
183
  const ses = new SES({
144
184
  apiVersion: '2010-12-01',
145
- region: host.split('.')[1],
185
+ region,
146
186
  credentials: {
147
187
  accessKeyId,
148
188
  secretAccessKey,
@@ -200,7 +240,7 @@ export class MailService {
200
240
  mailContent.body.push(alternateEntity);
201
241
 
202
242
  await Promise.all(
203
- mail.attachments.map((item) => {
243
+ (mail.attachments ?? []).map((item) => {
204
244
  const attachmentEntity = mimemessage.factory({
205
245
  contentType: item.contentType,
206
246
  contentTransferEncoding: 'base64',