@creator.co/wapi 1.1.3 → 1.1.5

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.
@@ -1,10 +1,12 @@
1
+ import * as Email from "email-templates";
1
2
  export default class Mailer {
2
3
  private readonly from;
3
4
  private readonly templateDefaultFile;
4
5
  private readonly transporter;
5
6
  constructor(defaultFrom: string, region: string);
6
- sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalAttachments?: any[]): Promise<any>;
7
- sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalAttachments?: any[]): Promise<any>;
7
+ sendRawEmail(to: string | Array<string>, htmlMessage: string, subject: string, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<any>;
8
+ sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalTransport?: Email.NodeMailerTransportOptions): Promise<any>;
9
+ newSMTPTransporter(host: string, portNumber: number, user: string, password: string): Email.NodeMailerTransportOptions;
8
10
  private chooseTemplate;
9
11
  private canRenderTemplate;
10
12
  }
@@ -66,17 +66,17 @@ var Mailer = /** @class */ (function () {
66
66
  },
67
67
  });
68
68
  }
69
- Mailer.prototype.sendRawEmail = function (to, htmlMessage, subject, optionalCC,
69
+ Mailer.prototype.sendRawEmail = function (to, htmlMessage, subject, optionalCC, optionalFrom, optionalReplyTo,
70
70
  // TODO: improve attachment type -> Attachment
71
- optionalAttachments) {
71
+ optionalAttachments, optionalTransport) {
72
72
  return __awaiter(this, void 0, void 0, function () {
73
73
  var email, resp, e_1;
74
74
  return __generator(this, function (_a) {
75
75
  switch (_a.label) {
76
76
  case 0:
77
77
  email = new Email({
78
- message: __assign(__assign({ from: this.from, to: to, html: htmlMessage, subject: subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})),
79
- transport: this.transporter,
78
+ message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to, html: htmlMessage, subject: subject }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
79
+ transport: optionalTransport || this.transporter,
80
80
  send: true,
81
81
  });
82
82
  resp = null;
@@ -97,17 +97,17 @@ var Mailer = /** @class */ (function () {
97
97
  });
98
98
  });
99
99
  };
100
- Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC,
100
+ Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
101
101
  // TODO: improve attachment type -> Attachment
102
- optionalAttachments) {
102
+ optionalAttachments, optionalTransport) {
103
103
  return __awaiter(this, void 0, void 0, function () {
104
104
  var email, resp, chosenTemplate, e_2;
105
105
  return __generator(this, function (_a) {
106
106
  switch (_a.label) {
107
107
  case 0:
108
108
  email = new Email({
109
- message: __assign(__assign({ from: this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})),
110
- transport: this.transporter,
109
+ message: __assign(__assign(__assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
110
+ transport: optionalTransport || this.transporter,
111
111
  send: true,
112
112
  });
113
113
  resp = null;
@@ -131,6 +131,18 @@ var Mailer = /** @class */ (function () {
131
131
  });
132
132
  });
133
133
  };
134
+ Mailer.prototype.newSMTPTransporter = function (host, portNumber, user, password) {
135
+ var smtpTransporter = nodemailer.createTransport({
136
+ host: host,
137
+ port: portNumber,
138
+ connectionTimeout: 2000,
139
+ auth: {
140
+ user: user,
141
+ pass: password,
142
+ },
143
+ });
144
+ return smtpTransporter;
145
+ };
134
146
  /* private */
135
147
  Mailer.prototype.chooseTemplate = function (templates, data) {
136
148
  return __awaiter(this, void 0, void 0, function () {
@@ -1 +1 @@
1
- {"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA0C;AAC1C,8EAAmE;AACnE,uCAAwC;AACxC,uCAAwC;AAGxC;IAME,gBAAY,WAAmB,EAAE,MAAc;QAJ9B,wBAAmB,GAAW,MAAM,CAAA;QAKnD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC5C,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,CAAC;oBACrB,WAAW,EAAE,IAAA,0CAAe,GAAE;oBAC9B,UAAU,EAAE,YAAY;oBACxB,MAAM,QAAA;iBACP,CAAC;gBACF,GAAG,EAAE,GAAG;aACT;SACF,CAAC,CAAA;IACJ,CAAC;IAEY,6BAAY,GAAzB,UACE,EAA0B,EAC1B,WAAmB,EACnB,OAAe,EACf,UAAmC;IACnC,8CAA8C;IAC9C,mBAA2B;;;;;;wBAGrB,KAAK,GAAG,IAAI,KAAK,CAAC;4BACtB,OAAO,sBACL,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,WAAW,EACjB,OAAO,SAAA,IACJ,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GACjE,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC1C;4BACD,SAAS,EAAE,IAAI,CAAC,WAAW;4BAC3B,IAAI,EAAE,IAAI;yBACX,CAAC,CAAA;wB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;;;wBAED,OAAO,CAAC,GAAG,CACT,+DAAwD,QAAQ,CAAE,EAClE,GAAC,CACF,CAAA;;4BAEH,sBAAO,eAAe,IAAI,IAAI,EAAA;;;;KAC/B;IACH,aAAC;AAAD,CAAC,AAhJD,IAgJC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,20 +29,24 @@ export default class Mailer {
29
29
  htmlMessage: string,
30
30
  subject: string,
31
31
  optionalCC?: string | Array<string>,
32
+ optionalFrom?: string,
33
+ optionalReplyTo?: string,
32
34
  // TODO: improve attachment type -> Attachment
33
35
  optionalAttachments?: any[],
36
+ optionalTransport?: Email.NodeMailerTransportOptions,
34
37
  ) {
35
38
  //Generate emails
36
39
  const email = new Email({
37
40
  message: {
38
- from: this.from,
41
+ from: optionalFrom || this.from,
39
42
  to: to,
40
43
  html: htmlMessage,
41
44
  subject,
42
45
  ...(optionalAttachments ? { attachments: optionalAttachments } : {}),
43
46
  ...(optionalCC ? { cc: optionalCC } : {}),
47
+ ...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
44
48
  },
45
- transport: this.transporter,
49
+ transport: optionalTransport || this.transporter,
46
50
  send: true,
47
51
  })
48
52
  //
@@ -60,18 +64,22 @@ export default class Mailer {
60
64
  templates: string | Array<string>,
61
65
  data: object,
62
66
  optionalCC?: string | Array<string>,
67
+ optionalFrom?: string,
68
+ optionalReplyTo?: string,
63
69
  // TODO: improve attachment type -> Attachment
64
70
  optionalAttachments?: any[],
71
+ optionalTransport?: Email.NodeMailerTransportOptions,
65
72
  ) {
66
73
  //Generate emails
67
74
  const email = new Email({
68
75
  message: {
69
- from: this.from,
76
+ from: optionalFrom || this.from,
70
77
  to: to,
71
78
  ...(optionalAttachments ? { attachments: optionalAttachments } : {}),
72
79
  ...(optionalCC ? { cc: optionalCC } : {}),
80
+ ...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
73
81
  },
74
- transport: this.transporter,
82
+ transport: optionalTransport || this.transporter,
75
83
  send: true,
76
84
  })
77
85
  //
@@ -85,6 +93,23 @@ export default class Mailer {
85
93
  }
86
94
  return resp
87
95
  }
96
+ public newSMTPTransporter(
97
+ host: string,
98
+ portNumber: number,
99
+ user: string,
100
+ password: string,
101
+ ): Email.NodeMailerTransportOptions {
102
+ const smtpTransporter = nodemailer.createTransport({
103
+ host: host,
104
+ port: portNumber,
105
+ connectionTimeout: 2000,
106
+ auth: {
107
+ user: user,
108
+ pass: password,
109
+ },
110
+ })
111
+ return smtpTransporter
112
+ }
88
113
 
89
114
  /* private */
90
115
  private async chooseTemplate(