@8ms/helpers 2.4.10 → 2.4.11
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/_class/BaseClass.cjs +31 -21
- package/dist/_class/BaseClass.mjs +31 -21
- package/dist/_class/BaseNamespace.cjs +10 -9
- package/dist/_class/BaseNamespace.mjs +10 -9
- package/dist/api/ApiResponseClass.cjs +96 -96
- package/dist/api/ApiResponseClass.mjs +96 -96
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.cjs +70 -60
- package/dist/aws/cloudWatchLog/server/AwsCloudWatchLogNamespace.mjs +70 -60
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.cjs +30 -28
- package/dist/aws/cloudWatchMetric/server/AwsCloudWatchMetricNamespace.mjs +30 -28
- package/dist/aws/ec2/server/AwsEc2Namespace.cjs +29 -32
- package/dist/aws/ec2/server/AwsEc2Namespace.mjs +29 -32
- package/dist/aws/ecs/server/AwsEcsNamespace.cjs +92 -78
- package/dist/aws/ecs/server/AwsEcsNamespace.mjs +92 -78
- package/dist/aws/glue/server/AwsGlueNamespace.cjs +17 -17
- package/dist/aws/glue/server/AwsGlueNamespace.mjs +17 -17
- package/dist/aws/lambda/server/AwsLambdaNamespace.cjs +33 -31
- package/dist/aws/lambda/server/AwsLambdaNamespace.mjs +33 -31
- package/dist/aws/s3/server/AwsS3Namespace.cjs +280 -265
- package/dist/aws/s3/server/AwsS3Namespace.mjs +280 -265
- package/dist/aws/ses/server/AwsSesNamespace.cjs +27 -30
- package/dist/aws/ses/server/AwsSesNamespace.mjs +27 -30
- package/dist/aws/ses/server/SimpleEmail.cjs +202 -199
- package/dist/aws/ses/server/SimpleEmail.mjs +202 -199
- package/dist/aws/sqs/server/AwsSqsNamespace.cjs +35 -38
- package/dist/aws/sqs/server/AwsSqsNamespace.mjs +35 -38
- package/dist/aws/ssm/server/AwsSsmNamespace.cjs +24 -23
- package/dist/aws/ssm/server/AwsSsmNamespace.mjs +24 -23
- package/dist/date/index.cjs +1 -1
- package/dist/date/index.mjs +1 -1
- package/dist/drizzle/server/DrizzleNamespace.cjs +39 -42
- package/dist/drizzle/server/DrizzleNamespace.mjs +39 -42
- package/dist/googleAds/server/GoogleAdsNamespace.cjs +21 -24
- package/dist/googleAds/server/GoogleAdsNamespace.mjs +21 -24
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.cjs +86 -70
- package/dist/googleCloud/bigquery/server/GoogleCloudBigqueryNamespace.mjs +86 -70
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.cjs +22 -25
- package/dist/googleCloud/sheets/server/GoogleCloudSheetsNamespace.mjs +22 -25
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.cjs +44 -38
- package/dist/googleCloud/storage/server/GoogleCloudStorageNamespace.mjs +44 -38
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.cjs +12 -15
- package/dist/googlePageSpeed/server/GooglePageSpeedNamespace.mjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.cjs +12 -15
- package/dist/littleWarden/server/LittleWardenNamespace.mjs +12 -15
- package/dist/onePassword/server/OnePasswordNamespace.cjs +30 -33
- package/dist/onePassword/server/OnePasswordNamespace.mjs +30 -33
- package/dist/openAi/server/OpenAiNamespace.cjs +20 -20
- package/dist/openAi/server/OpenAiNamespace.mjs +20 -20
- package/dist/prisma/server/PrismaNamespace.cjs +35 -38
- package/dist/prisma/server/PrismaNamespace.mjs +35 -38
- package/dist/snapchat/server/SnapchatNamespace.cjs +12 -12
- package/dist/snapchat/server/SnapchatNamespace.mjs +12 -12
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.cjs +19 -19
- package/dist/upTimeRobot/server/UpTimeRobotNamespace.mjs +19 -19
- package/package.json +1 -1
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
import { BaseNamespace } from "../../../_class/BaseNamespace.mjs";
|
|
2
2
|
//#region src/aws/ses/server/AwsSesNamespace.ts
|
|
3
3
|
var AwsSesNamespace = class extends BaseNamespace {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return response;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
4
|
+
ensureInit = async () => {
|
|
5
|
+
if (!this.client) try {
|
|
6
|
+
const { SESClient } = await import("@aws-sdk/client-ses");
|
|
7
|
+
this.client = new SESClient(this.config);
|
|
8
|
+
} catch (e) {
|
|
9
|
+
throw new Error("AWS SES Client not installed");
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
send = async (input) => {
|
|
13
|
+
await this.ensureInit();
|
|
14
|
+
let response;
|
|
15
|
+
if (input?.Message?.Body?.Html?.Data) try {
|
|
16
|
+
const { SendEmailCommand } = await import("@aws-sdk/client-ses");
|
|
17
|
+
const command = new SendEmailCommand(input);
|
|
18
|
+
response = await this.client.send(command);
|
|
19
|
+
} catch (exception) {
|
|
20
|
+
response = exception;
|
|
21
|
+
}
|
|
22
|
+
else try {
|
|
23
|
+
const { SendRawEmailCommand } = await import("@aws-sdk/client-ses");
|
|
24
|
+
const command = new SendRawEmailCommand(input);
|
|
25
|
+
response = await this.client.send(command);
|
|
26
|
+
} catch (exception) {
|
|
27
|
+
response = exception;
|
|
28
|
+
}
|
|
29
|
+
return response;
|
|
30
|
+
};
|
|
34
31
|
};
|
|
35
32
|
//#endregion
|
|
36
33
|
export { AwsSesNamespace };
|
|
@@ -5,207 +5,15 @@ const require__class_BaseClass = require("../../../_class/BaseClass.cjs");
|
|
|
5
5
|
* Class to build and send an AWS SES email.
|
|
6
6
|
*/
|
|
7
7
|
var SimpleEmail = class extends require__class_BaseClass.BaseClass {
|
|
8
|
+
from;
|
|
9
|
+
to = [];
|
|
10
|
+
cc = [];
|
|
11
|
+
bcc = [];
|
|
12
|
+
html;
|
|
13
|
+
subject;
|
|
14
|
+
attachments = [];
|
|
8
15
|
constructor({ bcc, cc, from, html, subject, to, attachments }) {
|
|
9
16
|
super();
|
|
10
|
-
this.to = [];
|
|
11
|
-
this.cc = [];
|
|
12
|
-
this.bcc = [];
|
|
13
|
-
this.attachments = [];
|
|
14
|
-
this.setFrom = (from) => {
|
|
15
|
-
return this._setValue("from", from);
|
|
16
|
-
};
|
|
17
|
-
this.setHtml = (html) => {
|
|
18
|
-
return this._setValue("html", html);
|
|
19
|
-
};
|
|
20
|
-
this.setSubject = (subject) => {
|
|
21
|
-
return this._setValue("subject", subject);
|
|
22
|
-
};
|
|
23
|
-
this.setAttachments = (attachments) => {
|
|
24
|
-
return this._setValue("attachments", attachments);
|
|
25
|
-
};
|
|
26
|
-
this.addAttachment = (attachment) => {
|
|
27
|
-
this.attachments.push(attachment);
|
|
28
|
-
return this;
|
|
29
|
-
};
|
|
30
|
-
this.addAttachmentFromdata = (filename, data, contentType) => {
|
|
31
|
-
return this.addAttachment({
|
|
32
|
-
filename,
|
|
33
|
-
data,
|
|
34
|
-
contentType: contentType || this._getContentTypeFromFilename(filename)
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
this.addAttachmentFromUrl = (filename, url, contentType) => {
|
|
38
|
-
return this.addAttachment({
|
|
39
|
-
filename,
|
|
40
|
-
url,
|
|
41
|
-
contentType: contentType || this._getContentTypeFromFilename(filename)
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
this.clearAttachments = () => {
|
|
45
|
-
this.attachments = [];
|
|
46
|
-
return this;
|
|
47
|
-
};
|
|
48
|
-
this.pushBcc = (recipient) => {
|
|
49
|
-
return this._push("bcc", recipient);
|
|
50
|
-
};
|
|
51
|
-
this.pushCc = (recipient) => {
|
|
52
|
-
return this._push("cc", recipient);
|
|
53
|
-
};
|
|
54
|
-
this.pushTo = (recipient) => {
|
|
55
|
-
return this._push("to", recipient);
|
|
56
|
-
};
|
|
57
|
-
this.setBcc = (recipient) => {
|
|
58
|
-
return this._setArray("bcc", recipient);
|
|
59
|
-
};
|
|
60
|
-
this.setCc = (recipient) => {
|
|
61
|
-
return this._setArray("cc", recipient);
|
|
62
|
-
};
|
|
63
|
-
this.setTo = (recipient) => {
|
|
64
|
-
return this._setArray("to", recipient);
|
|
65
|
-
};
|
|
66
|
-
this.getSendParam = async () => {
|
|
67
|
-
if (this.attachments.length > 0) return await this._getRawEmailParams();
|
|
68
|
-
return {
|
|
69
|
-
Destination: {
|
|
70
|
-
BccAddresses: this._filterRecipients("bcc"),
|
|
71
|
-
CcAddresses: this._filterRecipients("cc"),
|
|
72
|
-
ToAddresses: this._filterRecipients("to")
|
|
73
|
-
},
|
|
74
|
-
Message: {
|
|
75
|
-
Body: {
|
|
76
|
-
Html: {
|
|
77
|
-
Charset: "UTF-8",
|
|
78
|
-
Data: this.html
|
|
79
|
-
},
|
|
80
|
-
Text: {
|
|
81
|
-
Charset: "UTF-8",
|
|
82
|
-
Data: this.html
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
Subject: {
|
|
86
|
-
Charset: "UTF-8",
|
|
87
|
-
Data: this.subject
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
Source: this.from
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
this._getRawEmailParams = async () => {
|
|
94
|
-
const boundary = `----=_NextPart_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
95
|
-
const allRecipients = [
|
|
96
|
-
...this._filterRecipients("to"),
|
|
97
|
-
...this._filterRecipients("cc"),
|
|
98
|
-
...this._filterRecipients("bcc")
|
|
99
|
-
];
|
|
100
|
-
let rawMessage = "";
|
|
101
|
-
rawMessage += `From: ${this.from}\r\n`;
|
|
102
|
-
if (this._filterRecipients("to").length > 0) rawMessage += `To: ${this._filterRecipients("to").join(", ")}\r\n`;
|
|
103
|
-
if (this._filterRecipients("cc").length > 0) rawMessage += `Cc: ${this._filterRecipients("cc").join(", ")}\r\n`;
|
|
104
|
-
rawMessage += `Subject: ${this.subject}\r\n`;
|
|
105
|
-
rawMessage += `MIME-Version: 1.0\r\n`;
|
|
106
|
-
rawMessage += `Content-Type: multipart/mixed; boundary="${boundary}"\r\n\r\n`;
|
|
107
|
-
rawMessage += `--${boundary}\r\n`;
|
|
108
|
-
rawMessage += `Content-Type: text/html; charset=UTF-8\r\n`;
|
|
109
|
-
rawMessage += `Content-Transfer-Encoding: 7bit\r\n\r\n`;
|
|
110
|
-
rawMessage += `${this.html}\r\n\r\n`;
|
|
111
|
-
for (const attachment of this.attachments) {
|
|
112
|
-
const isTextFile = this._isTextFile(attachment.contentType || this._getContentTypeFromFilename(attachment.filename));
|
|
113
|
-
rawMessage += `--${boundary}\r\n`;
|
|
114
|
-
rawMessage += `Content-Type: ${attachment.contentType || "application/octet-stream"}\r\n`;
|
|
115
|
-
rawMessage += `Content-Disposition: attachment; filename="${attachment.filename}"\r\n`;
|
|
116
|
-
if (isTextFile) {
|
|
117
|
-
rawMessage += `Content-Transfer-Encoding: 7bit\r\n\r\n`;
|
|
118
|
-
const textData = await this._getAttachmentTextData(attachment);
|
|
119
|
-
rawMessage += `${textData}\r\n\r\n`;
|
|
120
|
-
} else {
|
|
121
|
-
rawMessage += `Content-Transfer-Encoding: base64\r\n\r\n`;
|
|
122
|
-
const attachmentData = await this._getAttachmentData(attachment);
|
|
123
|
-
rawMessage += `${attachmentData}\r\n\r\n`;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
rawMessage += `--${boundary}--\r\n`;
|
|
127
|
-
return {
|
|
128
|
-
Destinations: allRecipients,
|
|
129
|
-
RawMessage: { Data: rawMessage },
|
|
130
|
-
Source: this.from
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
this._isTextFile = (contentType) => {
|
|
134
|
-
return [
|
|
135
|
-
"text/csv",
|
|
136
|
-
"text/plain",
|
|
137
|
-
"text/html",
|
|
138
|
-
"application/json",
|
|
139
|
-
"application/xml",
|
|
140
|
-
"text/xml"
|
|
141
|
-
].some((type) => contentType.startsWith(type));
|
|
142
|
-
};
|
|
143
|
-
this._getAttachmentTextData = async (attachment) => {
|
|
144
|
-
if (attachment.data) {
|
|
145
|
-
const base64Data = attachment.data.replace(/^data:[^;]+;base64,/, "");
|
|
146
|
-
if (this._isBase64(base64Data)) return Buffer.from(base64Data, "base64").toString("utf-8");
|
|
147
|
-
return attachment.data;
|
|
148
|
-
}
|
|
149
|
-
if (attachment.url) return await (await (await Promise.resolve().then(() => require("../../../node_modules/node-fetch/src/index.cjs")).then((mod) => mod.default))(attachment.url)).text();
|
|
150
|
-
throw new Error(`No valid data source provided for attachment: ${attachment.filename}`);
|
|
151
|
-
};
|
|
152
|
-
this._getAttachmentData = async (attachment) => {
|
|
153
|
-
if (attachment.data) {
|
|
154
|
-
const cleanData = attachment.data.replace(/^data:[^;]+;base64,/, "");
|
|
155
|
-
if (this._isBase64(cleanData)) return cleanData;
|
|
156
|
-
return Buffer.from(attachment.data, "utf-8").toString("base64");
|
|
157
|
-
}
|
|
158
|
-
if (attachment.url) return (await (await (await Promise.resolve().then(() => require("../../../node_modules/node-fetch/src/index.cjs")).then((mod) => mod.default))(attachment.url)).buffer()).toString("base64");
|
|
159
|
-
throw new Error(`No valid data source provided for attachment: ${attachment.filename}`);
|
|
160
|
-
};
|
|
161
|
-
this._isBase64 = (str) => {
|
|
162
|
-
try {
|
|
163
|
-
return Buffer.from(str, "base64").toString("base64") === str;
|
|
164
|
-
} catch {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
this._getContentTypeFromFilename = (filename) => {
|
|
169
|
-
return {
|
|
170
|
-
"jpg": "image/jpeg",
|
|
171
|
-
"jpeg": "image/jpeg",
|
|
172
|
-
"png": "image/png",
|
|
173
|
-
"gif": "image/gif",
|
|
174
|
-
"svg": "image/svg+xml",
|
|
175
|
-
"webp": "image/webp",
|
|
176
|
-
"bmp": "image/bmp",
|
|
177
|
-
"ico": "image/x-icon",
|
|
178
|
-
"pdf": "application/pdf",
|
|
179
|
-
"doc": "application/msword",
|
|
180
|
-
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
181
|
-
"xls": "application/vnd.ms-excel",
|
|
182
|
-
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
183
|
-
"ppt": "application/vnd.ms-powerpoint",
|
|
184
|
-
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
185
|
-
"csv": "text/csv",
|
|
186
|
-
"tsv": "text/tab-separated-values",
|
|
187
|
-
"json": "application/json",
|
|
188
|
-
"xml": "application/xml",
|
|
189
|
-
"txt": "text/plain",
|
|
190
|
-
"zip": "application/zip",
|
|
191
|
-
"rar": "application/x-rar-compressed",
|
|
192
|
-
"7z": "application/x-7z-compressed",
|
|
193
|
-
"tar": "application/x-tar",
|
|
194
|
-
"gz": "application/gzip",
|
|
195
|
-
"mp3": "audio/mpeg",
|
|
196
|
-
"wav": "audio/wav",
|
|
197
|
-
"mp4": "video/mp4",
|
|
198
|
-
"avi": "video/x-msvideo",
|
|
199
|
-
"mov": "video/quicktime"
|
|
200
|
-
}[filename.split(".").pop()?.toLowerCase() || ""] || "application/octet-stream";
|
|
201
|
-
};
|
|
202
|
-
this._filterRecipients = (field) => {
|
|
203
|
-
let response = this[field].filter((recipient) => recipient && null !== recipient);
|
|
204
|
-
response = response.map((recipient) => recipient.toLowerCase().trim());
|
|
205
|
-
response = response.filter((recipient) => "" !== recipient);
|
|
206
|
-
response = [...new Set(response)];
|
|
207
|
-
return response;
|
|
208
|
-
};
|
|
209
17
|
if (bcc) this.setBcc(bcc);
|
|
210
18
|
if (cc) this.setCc(cc);
|
|
211
19
|
if (from) this.setFrom(from);
|
|
@@ -215,6 +23,201 @@ var SimpleEmail = class extends require__class_BaseClass.BaseClass {
|
|
|
215
23
|
if (attachments) this.setAttachments(attachments);
|
|
216
24
|
return this;
|
|
217
25
|
}
|
|
26
|
+
setFrom = (from) => {
|
|
27
|
+
return this._setValue("from", from);
|
|
28
|
+
};
|
|
29
|
+
setHtml = (html) => {
|
|
30
|
+
return this._setValue("html", html);
|
|
31
|
+
};
|
|
32
|
+
setSubject = (subject) => {
|
|
33
|
+
return this._setValue("subject", subject);
|
|
34
|
+
};
|
|
35
|
+
setAttachments = (attachments) => {
|
|
36
|
+
return this._setValue("attachments", attachments);
|
|
37
|
+
};
|
|
38
|
+
addAttachment = (attachment) => {
|
|
39
|
+
this.attachments.push(attachment);
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
addAttachmentFromdata = (filename, data, contentType) => {
|
|
43
|
+
return this.addAttachment({
|
|
44
|
+
filename,
|
|
45
|
+
data,
|
|
46
|
+
contentType: contentType || this._getContentTypeFromFilename(filename)
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
addAttachmentFromUrl = (filename, url, contentType) => {
|
|
50
|
+
return this.addAttachment({
|
|
51
|
+
filename,
|
|
52
|
+
url,
|
|
53
|
+
contentType: contentType || this._getContentTypeFromFilename(filename)
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
clearAttachments = () => {
|
|
57
|
+
this.attachments = [];
|
|
58
|
+
return this;
|
|
59
|
+
};
|
|
60
|
+
pushBcc = (recipient) => {
|
|
61
|
+
return this._push("bcc", recipient);
|
|
62
|
+
};
|
|
63
|
+
pushCc = (recipient) => {
|
|
64
|
+
return this._push("cc", recipient);
|
|
65
|
+
};
|
|
66
|
+
pushTo = (recipient) => {
|
|
67
|
+
return this._push("to", recipient);
|
|
68
|
+
};
|
|
69
|
+
setBcc = (recipient) => {
|
|
70
|
+
return this._setArray("bcc", recipient);
|
|
71
|
+
};
|
|
72
|
+
setCc = (recipient) => {
|
|
73
|
+
return this._setArray("cc", recipient);
|
|
74
|
+
};
|
|
75
|
+
setTo = (recipient) => {
|
|
76
|
+
return this._setArray("to", recipient);
|
|
77
|
+
};
|
|
78
|
+
getSendParam = async () => {
|
|
79
|
+
if (this.attachments.length > 0) return await this._getRawEmailParams();
|
|
80
|
+
return {
|
|
81
|
+
Destination: {
|
|
82
|
+
BccAddresses: this._filterRecipients("bcc"),
|
|
83
|
+
CcAddresses: this._filterRecipients("cc"),
|
|
84
|
+
ToAddresses: this._filterRecipients("to")
|
|
85
|
+
},
|
|
86
|
+
Message: {
|
|
87
|
+
Body: {
|
|
88
|
+
Html: {
|
|
89
|
+
Charset: "UTF-8",
|
|
90
|
+
Data: this.html
|
|
91
|
+
},
|
|
92
|
+
Text: {
|
|
93
|
+
Charset: "UTF-8",
|
|
94
|
+
Data: this.html
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
Subject: {
|
|
98
|
+
Charset: "UTF-8",
|
|
99
|
+
Data: this.subject
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
Source: this.from
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
_getRawEmailParams = async () => {
|
|
106
|
+
const boundary = `----=_NextPart_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
107
|
+
const allRecipients = [
|
|
108
|
+
...this._filterRecipients("to"),
|
|
109
|
+
...this._filterRecipients("cc"),
|
|
110
|
+
...this._filterRecipients("bcc")
|
|
111
|
+
];
|
|
112
|
+
let rawMessage = "";
|
|
113
|
+
rawMessage += `From: ${this.from}\r\n`;
|
|
114
|
+
if (this._filterRecipients("to").length > 0) rawMessage += `To: ${this._filterRecipients("to").join(", ")}\r\n`;
|
|
115
|
+
if (this._filterRecipients("cc").length > 0) rawMessage += `Cc: ${this._filterRecipients("cc").join(", ")}\r\n`;
|
|
116
|
+
rawMessage += `Subject: ${this.subject}\r\n`;
|
|
117
|
+
rawMessage += `MIME-Version: 1.0\r\n`;
|
|
118
|
+
rawMessage += `Content-Type: multipart/mixed; boundary="${boundary}"\r\n\r\n`;
|
|
119
|
+
rawMessage += `--${boundary}\r\n`;
|
|
120
|
+
rawMessage += `Content-Type: text/html; charset=UTF-8\r\n`;
|
|
121
|
+
rawMessage += `Content-Transfer-Encoding: 7bit\r\n\r\n`;
|
|
122
|
+
rawMessage += `${this.html}\r\n\r\n`;
|
|
123
|
+
for (const attachment of this.attachments) {
|
|
124
|
+
const isTextFile = this._isTextFile(attachment.contentType || this._getContentTypeFromFilename(attachment.filename));
|
|
125
|
+
rawMessage += `--${boundary}\r\n`;
|
|
126
|
+
rawMessage += `Content-Type: ${attachment.contentType || "application/octet-stream"}\r\n`;
|
|
127
|
+
rawMessage += `Content-Disposition: attachment; filename="${attachment.filename}"\r\n`;
|
|
128
|
+
if (isTextFile) {
|
|
129
|
+
rawMessage += `Content-Transfer-Encoding: 7bit\r\n\r\n`;
|
|
130
|
+
const textData = await this._getAttachmentTextData(attachment);
|
|
131
|
+
rawMessage += `${textData}\r\n\r\n`;
|
|
132
|
+
} else {
|
|
133
|
+
rawMessage += `Content-Transfer-Encoding: base64\r\n\r\n`;
|
|
134
|
+
const attachmentData = await this._getAttachmentData(attachment);
|
|
135
|
+
rawMessage += `${attachmentData}\r\n\r\n`;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
rawMessage += `--${boundary}--\r\n`;
|
|
139
|
+
return {
|
|
140
|
+
Destinations: allRecipients,
|
|
141
|
+
RawMessage: { Data: rawMessage },
|
|
142
|
+
Source: this.from
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
_isTextFile = (contentType) => {
|
|
146
|
+
return [
|
|
147
|
+
"text/csv",
|
|
148
|
+
"text/plain",
|
|
149
|
+
"text/html",
|
|
150
|
+
"application/json",
|
|
151
|
+
"application/xml",
|
|
152
|
+
"text/xml"
|
|
153
|
+
].some((type) => contentType.startsWith(type));
|
|
154
|
+
};
|
|
155
|
+
_getAttachmentTextData = async (attachment) => {
|
|
156
|
+
if (attachment.data) {
|
|
157
|
+
const base64Data = attachment.data.replace(/^data:[^;]+;base64,/, "");
|
|
158
|
+
if (this._isBase64(base64Data)) return Buffer.from(base64Data, "base64").toString("utf-8");
|
|
159
|
+
return attachment.data;
|
|
160
|
+
}
|
|
161
|
+
if (attachment.url) return await (await (await Promise.resolve().then(() => require("../../../node_modules/node-fetch/src/index.cjs")).then((mod) => mod.default))(attachment.url)).text();
|
|
162
|
+
throw new Error(`No valid data source provided for attachment: ${attachment.filename}`);
|
|
163
|
+
};
|
|
164
|
+
_getAttachmentData = async (attachment) => {
|
|
165
|
+
if (attachment.data) {
|
|
166
|
+
const cleanData = attachment.data.replace(/^data:[^;]+;base64,/, "");
|
|
167
|
+
if (this._isBase64(cleanData)) return cleanData;
|
|
168
|
+
return Buffer.from(attachment.data, "utf-8").toString("base64");
|
|
169
|
+
}
|
|
170
|
+
if (attachment.url) return (await (await (await Promise.resolve().then(() => require("../../../node_modules/node-fetch/src/index.cjs")).then((mod) => mod.default))(attachment.url)).buffer()).toString("base64");
|
|
171
|
+
throw new Error(`No valid data source provided for attachment: ${attachment.filename}`);
|
|
172
|
+
};
|
|
173
|
+
_isBase64 = (str) => {
|
|
174
|
+
try {
|
|
175
|
+
return Buffer.from(str, "base64").toString("base64") === str;
|
|
176
|
+
} catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
_getContentTypeFromFilename = (filename) => {
|
|
181
|
+
return {
|
|
182
|
+
"jpg": "image/jpeg",
|
|
183
|
+
"jpeg": "image/jpeg",
|
|
184
|
+
"png": "image/png",
|
|
185
|
+
"gif": "image/gif",
|
|
186
|
+
"svg": "image/svg+xml",
|
|
187
|
+
"webp": "image/webp",
|
|
188
|
+
"bmp": "image/bmp",
|
|
189
|
+
"ico": "image/x-icon",
|
|
190
|
+
"pdf": "application/pdf",
|
|
191
|
+
"doc": "application/msword",
|
|
192
|
+
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
193
|
+
"xls": "application/vnd.ms-excel",
|
|
194
|
+
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
195
|
+
"ppt": "application/vnd.ms-powerpoint",
|
|
196
|
+
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
197
|
+
"csv": "text/csv",
|
|
198
|
+
"tsv": "text/tab-separated-values",
|
|
199
|
+
"json": "application/json",
|
|
200
|
+
"xml": "application/xml",
|
|
201
|
+
"txt": "text/plain",
|
|
202
|
+
"zip": "application/zip",
|
|
203
|
+
"rar": "application/x-rar-compressed",
|
|
204
|
+
"7z": "application/x-7z-compressed",
|
|
205
|
+
"tar": "application/x-tar",
|
|
206
|
+
"gz": "application/gzip",
|
|
207
|
+
"mp3": "audio/mpeg",
|
|
208
|
+
"wav": "audio/wav",
|
|
209
|
+
"mp4": "video/mp4",
|
|
210
|
+
"avi": "video/x-msvideo",
|
|
211
|
+
"mov": "video/quicktime"
|
|
212
|
+
}[filename.split(".").pop()?.toLowerCase() || ""] || "application/octet-stream";
|
|
213
|
+
};
|
|
214
|
+
_filterRecipients = (field) => {
|
|
215
|
+
let response = this[field].filter((recipient) => recipient && null !== recipient);
|
|
216
|
+
response = response.map((recipient) => recipient.toLowerCase().trim());
|
|
217
|
+
response = response.filter((recipient) => "" !== recipient);
|
|
218
|
+
response = [...new Set(response)];
|
|
219
|
+
return response;
|
|
220
|
+
};
|
|
218
221
|
};
|
|
219
222
|
//#endregion
|
|
220
223
|
exports.SimpleEmail = SimpleEmail;
|