@ikonintegration/ikapi 5.0.3 → 5.0.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.
- package/dist/package-lock.json +10 -10
- package/dist/package.json +2 -2
- package/dist/src/BaseEvent/Launchable/ContainerExec.js.map +1 -1
- package/dist/src/Mailer/Mailer.d.ts +3 -2
- package/dist/src/Mailer/Mailer.js +15 -14
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/BaseEvent/Launchable/ContainerExec.ts +0 -1
- package/src/Mailer/Mailer.ts +43 -52
package/dist/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ikonintegration/ikapi",
|
|
9
|
-
"version": "5.0.
|
|
9
|
+
"version": "5.0.5",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-dynamodb": "^3.650.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"cuid": "^3.0.0",
|
|
27
27
|
"dotenv": "^16.4.1",
|
|
28
28
|
"email-templates": "^12.0.1",
|
|
29
|
-
"express": "^4.21.
|
|
29
|
+
"express": "^4.21.1",
|
|
30
30
|
"json-stringify-safe": "^5.0.1",
|
|
31
31
|
"kysely": "^0.27.2",
|
|
32
32
|
"node-cache": "^5.1.2",
|
|
@@ -4911,9 +4911,9 @@
|
|
|
4911
4911
|
"devOptional": true
|
|
4912
4912
|
},
|
|
4913
4913
|
"node_modules/cookie": {
|
|
4914
|
-
"version": "0.
|
|
4915
|
-
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.
|
|
4916
|
-
"integrity": "sha512-
|
|
4914
|
+
"version": "0.7.1",
|
|
4915
|
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
|
|
4916
|
+
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
|
4917
4917
|
"engines": {
|
|
4918
4918
|
"node": ">= 0.6"
|
|
4919
4919
|
}
|
|
@@ -6219,16 +6219,16 @@
|
|
|
6219
6219
|
}
|
|
6220
6220
|
},
|
|
6221
6221
|
"node_modules/express": {
|
|
6222
|
-
"version": "4.21.
|
|
6223
|
-
"resolved": "https://registry.npmjs.org/express/-/express-4.21.
|
|
6224
|
-
"integrity": "sha512-
|
|
6222
|
+
"version": "4.21.1",
|
|
6223
|
+
"resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz",
|
|
6224
|
+
"integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==",
|
|
6225
6225
|
"dependencies": {
|
|
6226
6226
|
"accepts": "~1.3.8",
|
|
6227
6227
|
"array-flatten": "1.1.1",
|
|
6228
6228
|
"body-parser": "1.20.3",
|
|
6229
6229
|
"content-disposition": "0.5.4",
|
|
6230
6230
|
"content-type": "~1.0.4",
|
|
6231
|
-
"cookie": "0.
|
|
6231
|
+
"cookie": "0.7.1",
|
|
6232
6232
|
"cookie-signature": "1.0.6",
|
|
6233
6233
|
"debug": "2.6.9",
|
|
6234
6234
|
"depd": "2.0.0",
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"cuid": "^3.0.0",
|
|
37
37
|
"dotenv": "^16.4.1",
|
|
38
38
|
"email-templates": "^12.0.1",
|
|
39
|
-
"express": "^4.21.
|
|
39
|
+
"express": "^4.21.1",
|
|
40
40
|
"json-stringify-safe": "^5.0.1",
|
|
41
41
|
"kysely": "^0.27.2",
|
|
42
42
|
"node-cache": "^5.1.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContainerExec.js","sourceRoot":"","sources":["../../../../src/BaseEvent/Launchable/ContainerExec.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ContainerExec.js","sourceRoot":"","sources":["../../../../src/BaseEvent/Launchable/ContainerExec.ts"],"names":[],"mappings":";;;;;;;;;AAIA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAkB;IAMrC;;;;OAIG;IACH,YAAY,OAAqC;QAC/C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED;;;;OAIG;IACU,OAAO;;YAClB,IAAI,CAAC;gBACH,SAAS;gBACT,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;gBAChD,SAAS;gBACT,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACnB,IACE,CAAC,IAAI,CAAC,GAAG;oBACT,IAAI,CAAC,IAAI;oBACT,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,CAAC,CAAC;oBAElF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;;oBACZ,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACtB,CAAC;YAAC,OAAO,CAAC,EAAE,C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AO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;oBACxB,CAAC,CAAC,CAAA;oBACF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;oBAC/C,IAAI,IAAI;wBAAE,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;gBACnC,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,MAAM,CAAC,CAAC,CAAC,CAAA;gBACX,CAAC;YACH,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC;KAAA;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Email from
|
|
1
|
+
import Email from "email-templates";
|
|
2
2
|
export default class Mailer {
|
|
3
3
|
/**
|
|
4
4
|
* The starting point of a range.
|
|
@@ -42,8 +42,9 @@ export default class Mailer {
|
|
|
42
42
|
* @param {string} [optionalFrom] - The email address to send the email from.
|
|
43
43
|
* @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
|
|
44
44
|
* @param {any[]} [optionalAttachments] - An array
|
|
45
|
+
* @param {Record<string, string>} [optionalHeaders] - Optional headers to be added to the message. Passed in a key value object.
|
|
45
46
|
*/
|
|
46
|
-
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<null>;
|
|
47
|
+
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: string, optionalReplyTo?: string, optionalAttachments?: any[], optionalHeaders?: Record<string, string>, optionalTransport?: Email.NodeMailerTransportOptions): Promise<null>;
|
|
47
48
|
/**
|
|
48
49
|
* Creates a new SMTP transporter for sending emails using NodeMailer.
|
|
49
50
|
* @param {string} host - The SMTP server host.
|
|
@@ -7,10 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
10
|
+
/* eslint-disable prettier/prettier */
|
|
11
|
+
import * as SES from "@aws-sdk/client-ses";
|
|
12
|
+
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
|
13
|
+
import Email from "email-templates";
|
|
14
|
+
import nodemailer from "nodemailer";
|
|
14
15
|
export default class Mailer {
|
|
15
16
|
/**
|
|
16
17
|
* Constructs a new instance of the EmailSender class.
|
|
@@ -23,13 +24,13 @@ export default class Mailer {
|
|
|
23
24
|
* The default file template for the application.
|
|
24
25
|
* @type {string}
|
|
25
26
|
*/
|
|
26
|
-
this.templateDefaultFile =
|
|
27
|
+
this.templateDefaultFile = "html";
|
|
27
28
|
this.from = defaultFrom;
|
|
28
29
|
this.transporter = nodemailer.createTransport({
|
|
29
30
|
SES: {
|
|
30
31
|
ses: new SES.SESClient({
|
|
31
32
|
credentials: defaultProvider(),
|
|
32
|
-
apiVersion:
|
|
33
|
+
apiVersion: "2010-12-01",
|
|
33
34
|
region,
|
|
34
35
|
}),
|
|
35
36
|
aws: SES,
|
|
@@ -60,10 +61,10 @@ export default class Mailer {
|
|
|
60
61
|
let resp = null;
|
|
61
62
|
try {
|
|
62
63
|
resp = yield email.send();
|
|
63
|
-
console.debug(
|
|
64
|
+
console.debug("Mailer resp:", resp);
|
|
64
65
|
}
|
|
65
66
|
catch (e) {
|
|
66
|
-
console.error(
|
|
67
|
+
console.error("Mailer error:", e);
|
|
67
68
|
throw e;
|
|
68
69
|
}
|
|
69
70
|
return resp;
|
|
@@ -78,14 +79,15 @@ export default class Mailer {
|
|
|
78
79
|
* @param {string} [optionalFrom] - The email address to send the email from.
|
|
79
80
|
* @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
|
|
80
81
|
* @param {any[]} [optionalAttachments] - An array
|
|
82
|
+
* @param {Record<string, string>} [optionalHeaders] - Optional headers to be added to the message. Passed in a key value object.
|
|
81
83
|
*/
|
|
82
84
|
sendTemplatedEmail(to, templates, data, optionalCC, optionalFrom, optionalReplyTo,
|
|
83
85
|
// TODO: improve attachment type -> Attachment
|
|
84
|
-
optionalAttachments, optionalTransport) {
|
|
86
|
+
optionalAttachments, optionalHeaders, optionalTransport) {
|
|
85
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
88
|
//Generate emails
|
|
87
89
|
const email = new Email({
|
|
88
|
-
message: Object.assign(Object.assign(Object.assign({ from: optionalFrom || this.from, to: to }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
90
|
+
message: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (optionalHeaders ? { headers: optionalHeaders } : {})), { from: optionalFrom || this.from, to: to }), (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})), (optionalReplyTo ? { replyTo: optionalReplyTo } : {})),
|
|
89
91
|
transport: optionalTransport || this.transporter,
|
|
90
92
|
send: true,
|
|
91
93
|
});
|
|
@@ -94,10 +96,10 @@ export default class Mailer {
|
|
|
94
96
|
try {
|
|
95
97
|
const chosenTemplate = yield this.chooseTemplate(templates, data);
|
|
96
98
|
resp = yield email.send({ template: chosenTemplate, locals: data });
|
|
97
|
-
console.debug(
|
|
99
|
+
console.debug("Mailer resp:", resp);
|
|
98
100
|
}
|
|
99
101
|
catch (e) {
|
|
100
|
-
console.error(
|
|
102
|
+
console.error("Mailer error:", e);
|
|
101
103
|
throw e;
|
|
102
104
|
}
|
|
103
105
|
return resp;
|
|
@@ -143,8 +145,7 @@ export default class Mailer {
|
|
|
143
145
|
if (yield this.canRenderTemplate(templates, data))
|
|
144
146
|
return templates;
|
|
145
147
|
}
|
|
146
|
-
throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above! ` +
|
|
147
|
-
JSON.stringify(data, null, 2));
|
|
148
|
+
throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above! ` + JSON.stringify(data, null, 2));
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
151
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,GAAG,MAAM,qBAAqB,
|
|
1
|
+
{"version":3,"file":"Mailer.js","sourceRoot":"","sources":["../../../src/Mailer/Mailer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,sCAAsC;AACtC,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,KAAK,MAAM,iBAAiB,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,MAAM,CAAC,OAAO,OAAO,MAAM;IAiBzB;;;;;OAKG;IACH,YAAY,WAAmB,EAAE,MAAc;QAjB/C;;;WAGG;QACc,wBAAmB,GAAW,MAAM,CAAC;QAcpD,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,eAAe,CAAC;YAC5C,GAAG,EAAE;gBACH,GAAG,EAAE,IAAI,GAAG,CAAC,SAAS,CAAC;oBACrB,WAAW,EAAE,eAAe,EAAE;oBAC9B,UAAU,EAAE,YAAY;oBACxB,MAAM;iBACP,CAAC;gBACF,GAAG,EAAE,GAAG;aACT;SACF,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;;OASG;IACU,YAAY,CACvB,EAA0B,EAC1B,WAAmB,EACnB,OAAe,EACf,UAAmC,EACnC,YAAqB,EACrB,eAAwB;IACxB,8CAA8C;IAC9C,mBAA2B,EAC3B,iBAAoD;;YAEpD,iBAAiB;YACjB,MAAM,KAAK,GAAG,IAA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AwD,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;YACrF,CAAC;YACD,OAAO,eAAe,CAAC;QACzB,CAAC;KAAA;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../index.ts","../src/
|
|
1
|
+
{"root":["../index.ts","../src/Globals.ts","../src/API/Request.ts","../src/API/Response.ts","../src/BaseEvent/DynamoTransaction.ts","../src/BaseEvent/EventProcessor.ts","../src/BaseEvent/Process.ts","../src/BaseEvent/StepTransaction.ts","../src/BaseEvent/Transaction.ts","../src/BaseEvent/Launchable/ContainerExec.ts","../src/BaseEvent/Launchable/index.ts","../src/BaseEvent/Launchable/types.ts","../src/Cache/Redis.ts","../src/Cache/types.ts","../src/Config/Configuration.ts","../src/Config/EnvironmentVar.ts","../src/Crypto/Crypto.ts","../src/Database/Database.ts","../src/Database/DatabaseManager.ts","../src/Database/DatabaseTransaction.ts","../src/Database/index.ts","../src/Database/types.ts","../src/Database/integrations/dynamo/DynamoDatabase.ts","../src/Database/integrations/kysely/KyselyDatabase.ts","../src/Database/integrations/kysely/KyselyTransaction.ts","../src/Database/integrations/pgsql/PostgresDatabase.ts","../src/Database/integrations/pgsql/PostgresTransaction.ts","../src/Logger/Logger.ts","../src/Mailer/Mailer.ts","../src/Publisher/Publisher.ts","../src/Server/RouteResolver.ts","../src/Server/Router.ts","../src/Server/lib/ContainerServer.ts","../src/Server/lib/Server.ts","../src/Server/lib/container/GenericHandler.ts","../src/Server/lib/container/GenericHandlerEvent.ts","../src/Server/lib/container/HealthHandler.ts","../src/Server/lib/container/Proxy.ts","../src/Server/lib/container/Utils.ts","../src/Util/AsyncSingleton.ts","../src/Util/Utils.ts","../src/Validation/Validator.ts","../package-lock.json","../package.json"],"version":"5.6.2"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ikonintegration/ikapi",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"cuid": "^3.0.0",
|
|
37
37
|
"dotenv": "^16.4.1",
|
|
38
38
|
"email-templates": "^12.0.1",
|
|
39
|
-
"express": "^4.21.
|
|
39
|
+
"express": "^4.21.1",
|
|
40
40
|
"json-stringify-safe": "^5.0.1",
|
|
41
41
|
"kysely": "^0.27.2",
|
|
42
42
|
"node-cache": "^5.1.2",
|
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
import * as SES from "@aws-sdk/client-ses";
|
|
3
|
+
import { defaultProvider } from "@aws-sdk/credential-provider-node";
|
|
4
|
+
import Email from "email-templates";
|
|
5
|
+
import nodemailer from "nodemailer";
|
|
6
|
+
import type SESTransport from "nodemailer/lib/ses-transport";
|
|
6
7
|
|
|
7
8
|
export default class Mailer {
|
|
8
9
|
/**
|
|
9
10
|
* The starting point of a range.
|
|
10
11
|
* @type {string}
|
|
11
12
|
*/
|
|
12
|
-
private readonly from: string
|
|
13
|
+
private readonly from: string;
|
|
13
14
|
/**
|
|
14
15
|
* The default file template for the application.
|
|
15
16
|
* @type {string}
|
|
16
17
|
*/
|
|
17
|
-
private readonly templateDefaultFile: string =
|
|
18
|
+
private readonly templateDefaultFile: string = "html";
|
|
18
19
|
/**
|
|
19
20
|
* The transporter object used for sending emails using the AWS SES service.
|
|
20
21
|
* @type {ReturnType<typeof nodemailer.createTransport<SESTransport.SentMessageInfo>>}
|
|
21
22
|
*/
|
|
22
|
-
private readonly transporter: ReturnType<
|
|
23
|
-
typeof nodemailer.createTransport<SESTransport.SentMessageInfo>
|
|
24
|
-
>
|
|
23
|
+
private readonly transporter: ReturnType<typeof nodemailer.createTransport<SESTransport.SentMessageInfo>>;
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Constructs a new instance of the EmailSender class.
|
|
@@ -30,17 +29,17 @@ export default class Mailer {
|
|
|
30
29
|
* @returns None
|
|
31
30
|
*/
|
|
32
31
|
constructor(defaultFrom: string, region: string) {
|
|
33
|
-
this.from = defaultFrom
|
|
32
|
+
this.from = defaultFrom;
|
|
34
33
|
this.transporter = nodemailer.createTransport({
|
|
35
34
|
SES: {
|
|
36
35
|
ses: new SES.SESClient({
|
|
37
36
|
credentials: defaultProvider(),
|
|
38
|
-
apiVersion:
|
|
37
|
+
apiVersion: "2010-12-01",
|
|
39
38
|
region,
|
|
40
39
|
}),
|
|
41
40
|
aws: SES,
|
|
42
41
|
},
|
|
43
|
-
})
|
|
42
|
+
});
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
/**
|
|
@@ -77,17 +76,17 @@ export default class Mailer {
|
|
|
77
76
|
},
|
|
78
77
|
transport: optionalTransport || this.transporter,
|
|
79
78
|
send: true,
|
|
80
|
-
})
|
|
79
|
+
});
|
|
81
80
|
//
|
|
82
|
-
let resp = null
|
|
81
|
+
let resp = null;
|
|
83
82
|
try {
|
|
84
|
-
resp = await email.send()
|
|
85
|
-
console.debug(
|
|
83
|
+
resp = await email.send();
|
|
84
|
+
console.debug("Mailer resp:", resp);
|
|
86
85
|
} catch (e) {
|
|
87
|
-
console.error(
|
|
88
|
-
throw e
|
|
86
|
+
console.error("Mailer error:", e);
|
|
87
|
+
throw e;
|
|
89
88
|
}
|
|
90
|
-
return resp
|
|
89
|
+
return resp;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
/**
|
|
@@ -99,6 +98,7 @@ export default class Mailer {
|
|
|
99
98
|
* @param {string} [optionalFrom] - The email address to send the email from.
|
|
100
99
|
* @param {string} [optionalReplyTo] - The email address to set as the reply-to address.
|
|
101
100
|
* @param {any[]} [optionalAttachments] - An array
|
|
101
|
+
* @param {Record<string, string>} [optionalHeaders] - Optional headers to be added to the message. Passed in a key value object.
|
|
102
102
|
*/
|
|
103
103
|
public async sendTemplatedEmail(
|
|
104
104
|
to: string | Array<string>,
|
|
@@ -109,11 +109,13 @@ export default class Mailer {
|
|
|
109
109
|
optionalReplyTo?: string,
|
|
110
110
|
// TODO: improve attachment type -> Attachment
|
|
111
111
|
optionalAttachments?: any[],
|
|
112
|
+
optionalHeaders?: Record<string, string>,
|
|
112
113
|
optionalTransport?: Email.NodeMailerTransportOptions
|
|
113
114
|
) {
|
|
114
115
|
//Generate emails
|
|
115
116
|
const email = new Email({
|
|
116
117
|
message: {
|
|
118
|
+
...(optionalHeaders ? { headers: optionalHeaders } : {}),
|
|
117
119
|
from: optionalFrom || this.from,
|
|
118
120
|
to: to,
|
|
119
121
|
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
@@ -122,18 +124,18 @@ export default class Mailer {
|
|
|
122
124
|
},
|
|
123
125
|
transport: optionalTransport || this.transporter,
|
|
124
126
|
send: true,
|
|
125
|
-
})
|
|
127
|
+
});
|
|
126
128
|
//
|
|
127
|
-
let resp = null
|
|
129
|
+
let resp = null;
|
|
128
130
|
try {
|
|
129
|
-
const chosenTemplate = await this.chooseTemplate(templates, data)
|
|
130
|
-
resp = await email.send({ template: chosenTemplate, locals: data })
|
|
131
|
-
console.debug(
|
|
131
|
+
const chosenTemplate = await this.chooseTemplate(templates, data);
|
|
132
|
+
resp = await email.send({ template: chosenTemplate, locals: data });
|
|
133
|
+
console.debug("Mailer resp:", resp);
|
|
132
134
|
} catch (e) {
|
|
133
|
-
console.error(
|
|
134
|
-
throw e
|
|
135
|
+
console.error("Mailer error:", e);
|
|
136
|
+
throw e;
|
|
135
137
|
}
|
|
136
|
-
return resp
|
|
138
|
+
return resp;
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
/**
|
|
@@ -144,12 +146,7 @@ export default class Mailer {
|
|
|
144
146
|
* @param {string} password - The password for authentication with the SMTP server.
|
|
145
147
|
* @returns {Email.NodeMailerTransportOptions} - The SMTP transporter object.
|
|
146
148
|
*/
|
|
147
|
-
public newSMTPTransporter(
|
|
148
|
-
host: string,
|
|
149
|
-
portNumber: number,
|
|
150
|
-
user: string,
|
|
151
|
-
password: string
|
|
152
|
-
): Email.NodeMailerTransportOptions {
|
|
149
|
+
public newSMTPTransporter(host: string, portNumber: number, user: string, password: string): Email.NodeMailerTransportOptions {
|
|
153
150
|
const smtpTransporter = nodemailer.createTransport({
|
|
154
151
|
host: host,
|
|
155
152
|
port: portNumber,
|
|
@@ -158,8 +155,8 @@ export default class Mailer {
|
|
|
158
155
|
user: user,
|
|
159
156
|
pass: password,
|
|
160
157
|
},
|
|
161
|
-
})
|
|
162
|
-
return smtpTransporter
|
|
158
|
+
});
|
|
159
|
+
return smtpTransporter;
|
|
163
160
|
}
|
|
164
161
|
|
|
165
162
|
/**
|
|
@@ -173,15 +170,12 @@ export default class Mailer {
|
|
|
173
170
|
if (Array.isArray(templates)) {
|
|
174
171
|
//For each template check if can render it
|
|
175
172
|
for (const template of templates) {
|
|
176
|
-
if (await this.canRenderTemplate(template, data)) return template
|
|
173
|
+
if (await this.canRenderTemplate(template, data)) return template;
|
|
177
174
|
}
|
|
178
175
|
} else if (templates) {
|
|
179
|
-
if (await this.canRenderTemplate(templates, data)) return templates
|
|
176
|
+
if (await this.canRenderTemplate(templates, data)) return templates;
|
|
180
177
|
}
|
|
181
|
-
throw new Error(
|
|
182
|
-
`Could not render email with template ${templates} and following data. Please, check logs above! ` +
|
|
183
|
-
JSON.stringify(data, null, 2)
|
|
184
|
-
)
|
|
178
|
+
throw new Error(`Could not render email with template ${templates} and following data. Please, check logs above! ` + JSON.stringify(data, null, 2));
|
|
185
179
|
}
|
|
186
180
|
|
|
187
181
|
/**
|
|
@@ -191,11 +185,8 @@ export default class Mailer {
|
|
|
191
185
|
* @returns {Promise<boolean>} - A promise that resolves to true if the template can be rendered, false otherwise.
|
|
192
186
|
*/
|
|
193
187
|
private async canRenderTemplate(template: string, data: object): Promise<boolean> {
|
|
194
|
-
const validRenderResp = await Mailer.renderTemplate(
|
|
195
|
-
|
|
196
|
-
data
|
|
197
|
-
)
|
|
198
|
-
return validRenderResp != null
|
|
188
|
+
const validRenderResp = await Mailer.renderTemplate(`${template}/${this.templateDefaultFile}`, data);
|
|
189
|
+
return validRenderResp != null;
|
|
199
190
|
}
|
|
200
191
|
|
|
201
192
|
/**
|
|
@@ -205,13 +196,13 @@ export default class Mailer {
|
|
|
205
196
|
* @returns {Promise<boolean>} - A promise that resolves to true if the template was rendered successfully, false otherwise.
|
|
206
197
|
*/
|
|
207
198
|
public static async renderTemplate(template: string, data: object): Promise<any> {
|
|
208
|
-
let validRenderResp: string | null = null
|
|
199
|
+
let validRenderResp: string | null = null;
|
|
209
200
|
try {
|
|
210
|
-
const email = new Email()
|
|
211
|
-
validRenderResp = await email.render(`${template}`, data)
|
|
201
|
+
const email = new Email();
|
|
202
|
+
validRenderResp = await email.render(`${template}`, data);
|
|
212
203
|
} catch (e) {
|
|
213
|
-
console.log(`Error while checking renderability of email template ${template}`, e)
|
|
204
|
+
console.log(`Error while checking renderability of email template ${template}`, e);
|
|
214
205
|
}
|
|
215
|
-
return validRenderResp
|
|
206
|
+
return validRenderResp;
|
|
216
207
|
}
|
|
217
208
|
}
|