@creator.co/wapi 1.1.0 → 1.1.2
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.
|
@@ -3,6 +3,7 @@ export default class Mailer {
|
|
|
3
3
|
private readonly templateDefaultFile;
|
|
4
4
|
private readonly transporter;
|
|
5
5
|
constructor(defaultFrom: string, region: string);
|
|
6
|
+
sendRawEmail(to: string | Array<string>, htmlMessage: string, optionalCC?: string | Array<string>, optionalAttachments?: any[]): Promise<any>;
|
|
6
7
|
sendTemplatedEmail(to: string | Array<string>, templates: string | Array<string>, data: object, optionalCC?: string | Array<string>, optionalAttachments?: any[]): Promise<any>;
|
|
7
8
|
private chooseTemplate;
|
|
8
9
|
private canRenderTemplate;
|
|
@@ -66,12 +66,42 @@ var Mailer = /** @class */ (function () {
|
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
Mailer.prototype.sendRawEmail = function (to, htmlMessage, optionalCC,
|
|
70
|
+
// TODO: improve attachment type -> Attachment
|
|
71
|
+
optionalAttachments) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
73
|
+
var email, resp, e_1;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
email = new Email({
|
|
78
|
+
message: __assign(__assign({ from: this.from, to: to, html: htmlMessage }, (optionalAttachments ? { attachments: optionalAttachments } : {})), (optionalCC ? { cc: optionalCC } : {})),
|
|
79
|
+
transport: this.transporter,
|
|
80
|
+
send: true,
|
|
81
|
+
});
|
|
82
|
+
resp = null;
|
|
83
|
+
_a.label = 1;
|
|
84
|
+
case 1:
|
|
85
|
+
_a.trys.push([1, 3, , 4]);
|
|
86
|
+
return [4 /*yield*/, email.send()];
|
|
87
|
+
case 2:
|
|
88
|
+
resp = _a.sent();
|
|
89
|
+
console.debug("Mailer resp:", resp);
|
|
90
|
+
return [3 /*break*/, 4];
|
|
91
|
+
case 3:
|
|
92
|
+
e_1 = _a.sent();
|
|
93
|
+
console.error("Mailer error:", e_1);
|
|
94
|
+
return [3 /*break*/, 4];
|
|
95
|
+
case 4: return [2 /*return*/, resp];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
};
|
|
70
100
|
Mailer.prototype.sendTemplatedEmail = function (to, templates, data, optionalCC,
|
|
71
101
|
// TODO: improve attachment type -> Attachment
|
|
72
102
|
optionalAttachments) {
|
|
73
103
|
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
-
var email, resp, chosenTemplate,
|
|
104
|
+
var email, resp, chosenTemplate, e_2;
|
|
75
105
|
return __generator(this, function (_a) {
|
|
76
106
|
switch (_a.label) {
|
|
77
107
|
case 0:
|
|
@@ -93,8 +123,8 @@ var Mailer = /** @class */ (function () {
|
|
|
93
123
|
console.debug("Mailer resp:", resp);
|
|
94
124
|
return [3 /*break*/, 5];
|
|
95
125
|
case 4:
|
|
96
|
-
|
|
97
|
-
console.error("Mailer error:",
|
|
126
|
+
e_2 = _a.sent();
|
|
127
|
+
console.error("Mailer error:", e_2);
|
|
98
128
|
return [3 /*break*/, 5];
|
|
99
129
|
case 5: return [2 /*return*/, resp];
|
|
100
130
|
}
|
|
@@ -138,7 +168,7 @@ var Mailer = /** @class */ (function () {
|
|
|
138
168
|
};
|
|
139
169
|
Mailer.prototype.canRenderTemplate = function (template, data) {
|
|
140
170
|
return __awaiter(this, void 0, void 0, function () {
|
|
141
|
-
var validRenderResp, email,
|
|
171
|
+
var validRenderResp, email, e_3;
|
|
142
172
|
return __generator(this, function (_a) {
|
|
143
173
|
switch (_a.label) {
|
|
144
174
|
case 0:
|
|
@@ -152,8 +182,8 @@ var Mailer = /** @class */ (function () {
|
|
|
152
182
|
validRenderResp = _a.sent();
|
|
153
183
|
return [3 /*break*/, 4];
|
|
154
184
|
case 3:
|
|
155
|
-
|
|
156
|
-
console.log("Error while checking renderability of email template ".concat(template),
|
|
185
|
+
e_3 = _a.sent();
|
|
186
|
+
console.log("Error while checking renderability of email template ".concat(template), e_3);
|
|
157
187
|
return [3 /*break*/, 4];
|
|
158
188
|
case 4: return [2 /*return*/, validRenderResp != null];
|
|
159
189
|
}
|
|
@@ -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;
|
|
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,0C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ChC,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,AArHD,IAqHC"}
|
package/package.json
CHANGED
package/src/Mailer/Mailer.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as SES from "@aws-sdk/client-ses"
|
|
|
2
2
|
import { defaultProvider } from "@aws-sdk/credential-provider-node"
|
|
3
3
|
import * as Email from "email-templates"
|
|
4
4
|
import * as nodemailer from "nodemailer"
|
|
5
|
-
import SESTransport
|
|
5
|
+
import type * as SESTransport from "nodemailer/lib/ses-transport"
|
|
6
6
|
|
|
7
7
|
export default class Mailer {
|
|
8
8
|
private readonly from: string
|
|
@@ -24,8 +24,36 @@ export default class Mailer {
|
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
public async sendRawEmail(
|
|
28
|
+
to: string | Array<string>,
|
|
29
|
+
htmlMessage: string,
|
|
30
|
+
optionalCC?: string | Array<string>,
|
|
31
|
+
// TODO: improve attachment type -> Attachment
|
|
32
|
+
optionalAttachments?: any[],
|
|
33
|
+
) {
|
|
34
|
+
//Generate emails
|
|
35
|
+
const email = new Email({
|
|
36
|
+
message: {
|
|
37
|
+
from: this.from,
|
|
38
|
+
to: to,
|
|
39
|
+
html: htmlMessage,
|
|
40
|
+
...(optionalAttachments ? { attachments: optionalAttachments } : {}),
|
|
41
|
+
...(optionalCC ? { cc: optionalCC } : {}),
|
|
42
|
+
},
|
|
43
|
+
transport: this.transporter,
|
|
44
|
+
send: true,
|
|
45
|
+
})
|
|
46
|
+
//
|
|
47
|
+
let resp = null
|
|
48
|
+
try {
|
|
49
|
+
resp = await email.send()
|
|
50
|
+
console.debug("Mailer resp:", resp)
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.error("Mailer error:", e)
|
|
53
|
+
}
|
|
54
|
+
return resp
|
|
55
|
+
}
|
|
56
|
+
public async sendTemplatedEmail(
|
|
29
57
|
to: string | Array<string>,
|
|
30
58
|
templates: string | Array<string>,
|
|
31
59
|
data: object,
|