@creator.co/wapi 1.1.4 → 1.1.6
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/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/src/Crypto/Crypto.d.ts +8 -0
- package/dist/src/Crypto/Crypto.js +84 -0
- package/dist/src/Crypto/Crypto.js.map +1 -0
- package/dist/src/Mailer/Mailer.d.ts +4 -2
- package/dist/src/Mailer/Mailer.js +20 -8
- package/dist/src/Mailer/Mailer.js.map +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/src/Crypto/Crypto.ts +35 -0
- package/src/Mailer/Mailer.ts +25 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Utils from "./src/API/Utils";
|
|
|
3
3
|
import EventProcessor from "./src/BaseEvent/EventProcessor";
|
|
4
4
|
import Process from "./src/BaseEvent/Process";
|
|
5
5
|
import Transaction from "./src/BaseEvent/Transaction";
|
|
6
|
+
import Crypto from "./src/Crypto/Crypto";
|
|
6
7
|
import Mailer from "./src/Mailer/Mailer";
|
|
7
8
|
import Publisher from "./src/Publisher/Publisher";
|
|
8
|
-
export { Transaction, Process, EventProcessor, Publisher, Mailer, Response, Utils, };
|
|
9
|
+
export { Transaction, Process, EventProcessor, Publisher, Mailer, Crypto, Response, Utils, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.Response = exports.Mailer = exports.Publisher = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
3
|
+
exports.Utils = exports.Response = exports.Crypto = exports.Mailer = exports.Publisher = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
|
|
4
4
|
var Response_1 = require("./src/API/Response");
|
|
5
5
|
exports.Response = Response_1.default;
|
|
6
6
|
var Utils_1 = require("./src/API/Utils");
|
|
@@ -11,6 +11,8 @@ var Process_1 = require("./src/BaseEvent/Process");
|
|
|
11
11
|
exports.Process = Process_1.default;
|
|
12
12
|
var Transaction_1 = require("./src/BaseEvent/Transaction");
|
|
13
13
|
exports.Transaction = Transaction_1.default;
|
|
14
|
+
var Crypto_1 = require("./src/Crypto/Crypto");
|
|
15
|
+
exports.Crypto = Crypto_1.default;
|
|
14
16
|
var Mailer_1 = require("./src/Mailer/Mailer");
|
|
15
17
|
exports.Mailer = Mailer_1.default;
|
|
16
18
|
var Publisher_1 = require("./src/Publisher/Publisher");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAmBvC,mBAnBK,kBAAQ,CAmBL;AAlBV,yCAAmC;AAoBjC,gBApBK,eAAK,CAoBL;AAnBP,iEAA2D;AAWzD,yBAXK,wBAAc,CAWL;AAVhB,mDAA6C;AAS3C,kBATK,iBAAO,CASL;AART,2DAAqD;AAOnD,sBAPK,qBAAW,CAOL;AANb,8CAAwC;AAYtC,iBAZK,gBAAM,CAYL;AAXR,8CAAwC;AAUtC,iBAVK,gBAAM,CAUL;AATR,uDAAiD;AAQ/C,oBARK,mBAAS,CAQL"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var client_kms_1 = require("@aws-sdk/client-kms");
|
|
40
|
+
var Crypto = /** @class */ (function () {
|
|
41
|
+
function Crypto(region, keyId) {
|
|
42
|
+
this.region = region;
|
|
43
|
+
this.keyId = keyId;
|
|
44
|
+
this.client = new client_kms_1.KMSClient({ region: this.region });
|
|
45
|
+
}
|
|
46
|
+
//
|
|
47
|
+
Crypto.prototype.encryptData = function (data) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var resp;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
52
|
+
case 0: return [4 /*yield*/, this.client.send(new client_kms_1.EncryptCommand({
|
|
53
|
+
KeyId: this.keyId,
|
|
54
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
55
|
+
Plaintext: new TextEncoder().encode(typeof data === "string" ? data : JSON.stringify(data)),
|
|
56
|
+
}))];
|
|
57
|
+
case 1:
|
|
58
|
+
resp = _a.sent();
|
|
59
|
+
return [2 /*return*/, Buffer.from(String(resp.CiphertextBlob), "utf8").toString("hex")];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
Crypto.prototype.decryptData = function (data) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var resp;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, this.client.send(new client_kms_1.DecryptCommand({
|
|
70
|
+
KeyId: this.keyId,
|
|
71
|
+
CiphertextBlob: Buffer.from(data, "hex"),
|
|
72
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
73
|
+
}))];
|
|
74
|
+
case 1:
|
|
75
|
+
resp = _a.sent();
|
|
76
|
+
return [2 /*return*/, new TextDecoder().decode(resp.Plaintext)];
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
return Crypto;
|
|
82
|
+
}());
|
|
83
|
+
exports.default = Crypto;
|
|
84
|
+
//# sourceMappingURL=Crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Crypto.js","sourceRoot":"","sources":["../../../src/Crypto/Crypto.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA+E;AAE/E;IAIE,gBAAY,MAAc,EAAE,KAAa;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,sBAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACtD,CAAC;IACD,EAAE;IACI,4BAAW,GAAjB,UAAkB,IAAkB;;;;;4BACrB,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,2BAAc,CAAC;4BACjB,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,mBAAmB,EAAE,oBAAoB;4BACzC,SAAS,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CACjC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CACvD;yBACF,CAAC,CACH,EAAA;;wBARK,IAAI,GAAG,SAQZ;wBACD,sBAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAA;;;;KACxE;IACK,4BAAW,GAAjB,UAAkB,IAAY;;;;;4BACf,qBAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CACjC,IAAI,2BAAc,CAAC;4BACjB,KAAK,EAAE,IAAI,CAAC,KAAK;4BACjB,cAAc,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC;4BACxC,mBAAmB,EAAE,oBAAoB;yBAC1C,CAAC,CACH,EAAA;;wBANK,IAAI,GAAG,SAMZ;wBACD,sBAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAA;;;;KAChD;IACH,aAAC;AAAD,CAAC,AAhCD,IAgCC"}
|
|
@@ -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>, optionalFrom?: string, optionalAttachments?: any[]): Promise<any>;
|
|
7
|
-
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalFrom?: 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, optionalFrom,
|
|
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: optionalFrom || 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, optionalFrom,
|
|
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: optionalFrom || 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,wBAAm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AAI,SAA4C;4BAAE,sBAAO,QAAQ,EAAA;;;wBAD5C,IAAS,CAAA;;;;6BAGvB,SAAS,EAAT,wBAAS;wBACd,qBAAM,IAAI,CAAC,iBAAiB,CAAC,SAAS,EAAE,IAAI,CAAC,EAAA;;wBAAjD,IAAI,SAA6C;4BAAE,sBAAO,SAAS,EAAA;;4BAErE,MAAM,IAAI,KAAK,CACb,+CAAwC,SAAS,oDAAiD;wBAChG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAChC,CAAA;;;;KACF;IACa,kCAAiB,GAA/B,UACE,QAAgB,EAChB,IAAY;;;;;;wBAER,eAAe,GAAG,IAAI,CAAA;;;;wBAElB,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;wBACP,qBAAM,KAAK,CAAC,MAAM,CAClC,UAAG,QAAQ,cAAI,IAAI,CAAC,mBAAmB,CAAE,EACzC,IAAI,CACL,EAAA;;wBAHD,eAAe,GAAG,SAGjB,CAAA;;;;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/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import Utils from "./src/API/Utils"
|
|
|
3
3
|
import EventProcessor from "./src/BaseEvent/EventProcessor"
|
|
4
4
|
import Process from "./src/BaseEvent/Process"
|
|
5
5
|
import Transaction from "./src/BaseEvent/Transaction"
|
|
6
|
+
import Crypto from "./src/Crypto/Crypto"
|
|
6
7
|
import Mailer from "./src/Mailer/Mailer"
|
|
7
8
|
import Publisher from "./src/Publisher/Publisher"
|
|
8
9
|
|
|
@@ -14,6 +15,7 @@ export {
|
|
|
14
15
|
//Client
|
|
15
16
|
Publisher,
|
|
16
17
|
Mailer,
|
|
18
|
+
Crypto,
|
|
17
19
|
//Responses
|
|
18
20
|
Response,
|
|
19
21
|
//Helpers
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { KMSClient, EncryptCommand, DecryptCommand } from "@aws-sdk/client-kms"
|
|
2
|
+
|
|
3
|
+
export default class Crypto {
|
|
4
|
+
private readonly client: KMSClient
|
|
5
|
+
private readonly region: string
|
|
6
|
+
private readonly keyId: string
|
|
7
|
+
constructor(region: string, keyId: string) {
|
|
8
|
+
this.region = region
|
|
9
|
+
this.keyId = keyId
|
|
10
|
+
this.client = new KMSClient({ region: this.region })
|
|
11
|
+
}
|
|
12
|
+
//
|
|
13
|
+
async encryptData(data: string | any): Promise<string> {
|
|
14
|
+
const resp = await this.client.send(
|
|
15
|
+
new EncryptCommand({
|
|
16
|
+
KeyId: this.keyId,
|
|
17
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
18
|
+
Plaintext: new TextEncoder().encode(
|
|
19
|
+
typeof data === "string" ? data : JSON.stringify(data),
|
|
20
|
+
),
|
|
21
|
+
}),
|
|
22
|
+
)
|
|
23
|
+
return Buffer.from(String(resp.CiphertextBlob), "utf8").toString("hex")
|
|
24
|
+
}
|
|
25
|
+
async decryptData(data: string): Promise<string> {
|
|
26
|
+
const resp = await this.client.send(
|
|
27
|
+
new DecryptCommand({
|
|
28
|
+
KeyId: this.keyId,
|
|
29
|
+
CiphertextBlob: Buffer.from(data, "hex"),
|
|
30
|
+
EncryptionAlgorithm: "RSAES_OAEP_SHA_256",
|
|
31
|
+
}),
|
|
32
|
+
)
|
|
33
|
+
return new TextDecoder().decode(resp.Plaintext)
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -30,8 +30,10 @@ export default class Mailer {
|
|
|
30
30
|
subject: string,
|
|
31
31
|
optionalCC?: string | Array<string>,
|
|
32
32
|
optionalFrom?: string,
|
|
33
|
+
optionalReplyTo?: string,
|
|
33
34
|
// TODO: improve attachment type -> Attachment
|
|
34
35
|
optionalAttachments?: any[],
|
|
36
|
+
optionalTransport?: Email.NodeMailerTransportOptions,
|
|
35
37
|
) {
|
|
36
38
|
//Generate emails
|
|
37
39
|
const email = new Email({
|
|
@@ -42,8 +44,9 @@ export default class Mailer {
|
|
|
42
44
|
subject,
|
|
43
45
|
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
44
46
|
...(optionalCC ? { cc: optionalCC } : {}),
|
|
47
|
+
...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
|
|
45
48
|
},
|
|
46
|
-
transport: this.transporter,
|
|
49
|
+
transport: optionalTransport || this.transporter,
|
|
47
50
|
send: true,
|
|
48
51
|
})
|
|
49
52
|
//
|
|
@@ -62,8 +65,10 @@ export default class Mailer {
|
|
|
62
65
|
data: object,
|
|
63
66
|
optionalCC?: string | Array<string>,
|
|
64
67
|
optionalFrom?: string,
|
|
68
|
+
optionalReplyTo?: string,
|
|
65
69
|
// TODO: improve attachment type -> Attachment
|
|
66
70
|
optionalAttachments?: any[],
|
|
71
|
+
optionalTransport?: Email.NodeMailerTransportOptions,
|
|
67
72
|
) {
|
|
68
73
|
//Generate emails
|
|
69
74
|
const email = new Email({
|
|
@@ -72,8 +77,9 @@ export default class Mailer {
|
|
|
72
77
|
to: to,
|
|
73
78
|
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
74
79
|
...(optionalCC ? { cc: optionalCC } : {}),
|
|
80
|
+
...(optionalReplyTo ? { replyTo: optionalReplyTo } : {}),
|
|
75
81
|
},
|
|
76
|
-
transport: this.transporter,
|
|
82
|
+
transport: optionalTransport || this.transporter,
|
|
77
83
|
send: true,
|
|
78
84
|
})
|
|
79
85
|
//
|
|
@@ -87,6 +93,23 @@ export default class Mailer {
|
|
|
87
93
|
}
|
|
88
94
|
return resp
|
|
89
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
|
+
}
|
|
90
113
|
|
|
91
114
|
/* private */
|
|
92
115
|
private async chooseTemplate(
|