biz-email-builder-shared 1.6.45 → 1.6.47
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/utilities/index.d.ts +5 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +5 -0
- package/dist/utilities/sendFromGmail.d.ts +4 -0
- package/dist/utilities/sendFromGmail.d.ts.map +1 -0
- package/dist/utilities/sendFromGmail.js +19 -0
- package/dist/utilities/sendMail.d.ts +3 -0
- package/dist/utilities/sendMail.d.ts.map +1 -0
- package/dist/utilities/sendMail.js +58 -0
- package/dist/utilities/sendMailViaEnvFallback.d.ts +3 -0
- package/dist/utilities/sendMailViaEnvFallback.d.ts.map +1 -0
- package/dist/utilities/sendMailViaEnvFallback.js +21 -0
- package/dist/utilities/sendMailViaSMTP.d.ts +4 -0
- package/dist/utilities/sendMailViaSMTP.d.ts.map +1 -0
- package/dist/utilities/sendMailViaSMTP.js +26 -0
- package/dist/utilities/sendviaGmail.d.ts +4 -0
- package/dist/utilities/sendviaGmail.d.ts.map +1 -0
- package/dist/utilities/sendviaGmail.js +19 -0
- package/dist/utilities/types.d.ts +14 -0
- package/dist/utilities/types.d.ts.map +1 -0
- package/dist/utilities/types.js +2 -0
- package/package.json +1 -1
|
@@ -5,4 +5,9 @@ export * from "./sendMailViaGmail";
|
|
|
5
5
|
export * from "./serverMessages";
|
|
6
6
|
export * from "./cryptoUtils";
|
|
7
7
|
export * from "./enums";
|
|
8
|
+
export * from "./types";
|
|
9
|
+
export * from "./sendMailViaSMTP";
|
|
10
|
+
export * from "./sendMailViaEnvFallback";
|
|
11
|
+
export * from "./sendMail";
|
|
12
|
+
export * from "./sendFromGmail";
|
|
8
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
package/dist/utilities/index.js
CHANGED
|
@@ -21,3 +21,8 @@ __exportStar(require("./sendMailViaGmail"), exports);
|
|
|
21
21
|
__exportStar(require("./serverMessages"), exports);
|
|
22
22
|
__exportStar(require("./cryptoUtils"), exports);
|
|
23
23
|
__exportStar(require("./enums"), exports);
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
__exportStar(require("./sendMailViaSMTP"), exports);
|
|
26
|
+
__exportStar(require("./sendMailViaEnvFallback"), exports);
|
|
27
|
+
__exportStar(require("./sendMail"), exports);
|
|
28
|
+
__exportStar(require("./sendFromGmail"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Attachment, Recipient } from "./types";
|
|
2
|
+
import { IGmailConfig } from "../entity";
|
|
3
|
+
export declare function sendFromGmail(creds: IGmailConfig, recipient: Recipient, subject: string, text: string, attachments: Attachment[], isHtml: boolean): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
|
|
4
|
+
//# sourceMappingURL=sendFromGmail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendFromGmail.d.ts","sourceRoot":"","sources":["../../src/utilities/sendFromGmail.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,wBAAsB,aAAa,CACjC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,OAAO,oEAqBhB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendFromGmail = sendFromGmail;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
async function sendFromGmail(creds, recipient, subject, text, attachments, isHtml) {
|
|
9
|
+
const transporter = nodemailer_1.default.createTransport({
|
|
10
|
+
service: "gmail",
|
|
11
|
+
auth: {
|
|
12
|
+
user: creds.email,
|
|
13
|
+
pass: creds.password,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const mailOptions = Object.assign({ from: creds.email, to: recipient.to, cc: recipient.cc, bcc: recipient.bcc, subject,
|
|
17
|
+
attachments }, (isHtml ? { html: text } : { text }));
|
|
18
|
+
return transporter.sendMail(mailOptions);
|
|
19
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attachment, Recipient } from "./types";
|
|
2
|
+
export declare function sendMail(userId: string, recipient: Recipient, subject: string, body: string, attachments: Attachment[], isHtml: boolean, organisationId?: string): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
|
|
3
|
+
//# sourceMappingURL=sendMail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMail.d.ts","sourceRoot":"","sources":["../../src/utilities/sendMail.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKhD,wBAAsB,QAAQ,CAC5B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EACpC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAC7B,WAAW,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,OAAO,EAC1C,cAAc,CAAC,EAAE,MAAM,oEAqDxB"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendMail = sendMail;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
const sendMailViaEnvFallback_1 = require("./sendMailViaEnvFallback");
|
|
7
|
+
const sendMailViaSMTP_1 = require("./sendMailViaSMTP");
|
|
8
|
+
const errorHandler_1 = require("../resHandler/errorHandler");
|
|
9
|
+
const sendFromGmail_1 = require("./sendFromGmail");
|
|
10
|
+
const cryptoUtils_1 = require("./cryptoUtils");
|
|
11
|
+
async function sendMail(userId, recipient, subject, body, attachments, isHtml, organisationId) {
|
|
12
|
+
let config = null;
|
|
13
|
+
let isOwner;
|
|
14
|
+
let isMember;
|
|
15
|
+
// If organisationId is provided
|
|
16
|
+
if (organisationId) {
|
|
17
|
+
isOwner = await entity_1.OrganisationModel.findOne({ createdBy: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
|
|
18
|
+
if (isOwner) {
|
|
19
|
+
config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
|
|
20
|
+
}
|
|
21
|
+
isMember = await entity_1.OrganisationTeamModel.findOne({ organisationId: new mongoose_1.Types.ObjectId(organisationId), user: new mongoose_1.Types.ObjectId(userId), isDeleted: false, inviteStatus: "ACCEPTED", }).lean();
|
|
22
|
+
if (isMember) {
|
|
23
|
+
const org = await entity_1.OrganisationModel.findById(organisationId);
|
|
24
|
+
config = await entity_1.EmailConfigurationModel.findOne({ user: org === null || org === void 0 ? void 0 : org.createdBy, isDeleted: false, }).lean();
|
|
25
|
+
}
|
|
26
|
+
if (!isMember || !isOwner) {
|
|
27
|
+
throw new errorHandler_1.ForbiddenRequestError("User is not part of the organisation");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
|
|
32
|
+
}
|
|
33
|
+
if (!config) {
|
|
34
|
+
return (0, sendMailViaEnvFallback_1.sendMailViaEnvFallback)(recipient, subject, body, attachments, isHtml);
|
|
35
|
+
}
|
|
36
|
+
if (config.method === entity_1.CONFIG_METHOD.GMAIL && config.gmailConfig) {
|
|
37
|
+
const gmailConfig = {
|
|
38
|
+
email: config.gmailConfig.email,
|
|
39
|
+
password: (0, cryptoUtils_1.decrypt)(config.gmailConfig.password),
|
|
40
|
+
};
|
|
41
|
+
return (0, sendFromGmail_1.sendFromGmail)(gmailConfig, recipient, subject, body, attachments, isHtml);
|
|
42
|
+
}
|
|
43
|
+
if (config.method === entity_1.CONFIG_METHOD.SMTP && config.smtpConfig) {
|
|
44
|
+
const smtpConfig = {
|
|
45
|
+
host: config.smtpConfig.host,
|
|
46
|
+
port: config.smtpConfig.port,
|
|
47
|
+
secure: config.smtpConfig.secure,
|
|
48
|
+
userName: config.smtpConfig.userName,
|
|
49
|
+
password: (0, cryptoUtils_1.decrypt)(config.smtpConfig.password),
|
|
50
|
+
fromEmail: config.smtpConfig.fromEmail,
|
|
51
|
+
fromName: config.smtpConfig.fromName,
|
|
52
|
+
encriptionMethod: config.smtpConfig.encriptionMethod,
|
|
53
|
+
};
|
|
54
|
+
return (0, sendMailViaSMTP_1.sendMailViaSMTP)(smtpConfig, recipient, subject, body, attachments, isHtml);
|
|
55
|
+
}
|
|
56
|
+
//. Final fallback
|
|
57
|
+
return (0, sendMailViaEnvFallback_1.sendMailViaEnvFallback)(recipient, subject, body, attachments, isHtml);
|
|
58
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Attachment, Recipient } from "./types";
|
|
2
|
+
export declare function sendMailViaEnvFallback(recipient: Recipient, subject: string, text: string, attachments: Attachment[], isHtml: boolean): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
|
|
3
|
+
//# sourceMappingURL=sendMailViaEnvFallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMailViaEnvFallback.d.ts","sourceRoot":"","sources":["../../src/utilities/sendMailViaEnvFallback.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,OAAO,oEAuBhB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendMailViaEnvFallback = sendMailViaEnvFallback;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
async function sendMailViaEnvFallback(recipient, subject, text, attachments, isHtml) {
|
|
9
|
+
const transporter = nodemailer_1.default.createTransport({
|
|
10
|
+
service: "gmail",
|
|
11
|
+
auth: {
|
|
12
|
+
user: process.env.GMAIL_ID,
|
|
13
|
+
pass: process.env.GMAIL_PASSWORD,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const mailOptions = Object.assign({ from: process.env.GMAIL_FROM_ID, to: recipient.to, cc: recipient.cc, bcc: recipient.bcc, subject,
|
|
17
|
+
attachments }, (isHtml
|
|
18
|
+
? { html: text.replace("${username}", process.env.GMAIL_FROM_USERNAME || "") }
|
|
19
|
+
: { text }));
|
|
20
|
+
return transporter.sendMail(mailOptions);
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ISMTPConfig } from "../entity";
|
|
2
|
+
import { Attachment, Recipient } from "./types";
|
|
3
|
+
export declare function sendMailViaSMTP(creds: ISMTPConfig, recipient: Recipient, subject: string, text: string, attachments: Attachment[], isHtml: boolean): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
|
|
4
|
+
//# sourceMappingURL=sendMailViaSMTP.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendMailViaSMTP.d.ts","sourceRoot":"","sources":["../../src/utilities/sendMailViaSMTP.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,WAAW,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEhD,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,OAAO,oEAoChB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendMailViaSMTP = sendMailViaSMTP;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
const entity_1 = require("../entity");
|
|
9
|
+
async function sendMailViaSMTP(creds, recipient, subject, text, attachments, isHtml) {
|
|
10
|
+
const { encriptionMethod } = creds;
|
|
11
|
+
// Determine transport settings based on encryption method
|
|
12
|
+
const useSSL = encriptionMethod === entity_1.ENCRYPTION_METHOD.SSL;
|
|
13
|
+
const useTLS = encriptionMethod === entity_1.ENCRYPTION_METHOD.TLS;
|
|
14
|
+
const useNone = encriptionMethod === entity_1.ENCRYPTION_METHOD.NONE;
|
|
15
|
+
const transporter = nodemailer_1.default.createTransport(Object.assign({ host: creds.host, port: creds.port, secure: useSSL, requireTLS: useTLS, auth: {
|
|
16
|
+
user: creds.userName,
|
|
17
|
+
pass: creds.password,
|
|
18
|
+
} }, (useNone && {
|
|
19
|
+
tls: {
|
|
20
|
+
rejectUnauthorized: false, // Allow self-signed or no certs
|
|
21
|
+
},
|
|
22
|
+
})));
|
|
23
|
+
const mailOptions = Object.assign({ from: `"${creds.fromName}" <${creds.fromEmail}>`, to: recipient.to, cc: recipient.cc, bcc: recipient.bcc, subject,
|
|
24
|
+
attachments }, (isHtml ? { html: text } : { text }));
|
|
25
|
+
return transporter.sendMail(mailOptions);
|
|
26
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Attachment, Recipient } from "./types";
|
|
2
|
+
import { IGmailConfig } from "../entity";
|
|
3
|
+
export declare function sendViaGmail(creds: IGmailConfig, recipient: Recipient, subject: string, text: string, attachments: Attachment[], isHtml: boolean): Promise<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
|
|
4
|
+
//# sourceMappingURL=sendviaGmail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendviaGmail.d.ts","sourceRoot":"","sources":["../../src/utilities/sendviaGmail.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,wBAAsB,YAAY,CAChC,KAAK,EAAE,YAAY,EACnB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,OAAO,oEAqBhB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sendViaGmail = sendViaGmail;
|
|
7
|
+
const nodemailer_1 = __importDefault(require("nodemailer"));
|
|
8
|
+
async function sendViaGmail(creds, recipient, subject, text, attachments, isHtml) {
|
|
9
|
+
const transporter = nodemailer_1.default.createTransport({
|
|
10
|
+
service: "gmail",
|
|
11
|
+
auth: {
|
|
12
|
+
user: creds.email,
|
|
13
|
+
pass: creds.password,
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const mailOptions = Object.assign({ from: creds.email, to: recipient.to, cc: recipient.cc, bcc: recipient.bcc, subject,
|
|
17
|
+
attachments }, (isHtml ? { html: text } : { text }));
|
|
18
|
+
return transporter.sendMail(mailOptions);
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CONFIG_METHOD, IGmailConfig, ISMTPConfig } from "../entity/emailConfiguration.entity";
|
|
2
|
+
export interface Recipient {
|
|
3
|
+
to: string[];
|
|
4
|
+
cc?: string[];
|
|
5
|
+
bcc?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface Attachment {
|
|
8
|
+
filename: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
content?: any;
|
|
11
|
+
}
|
|
12
|
+
export type EmailMethod = CONFIG_METHOD | "ENV";
|
|
13
|
+
export type EmailCredentials = IGmailConfig | ISMTPConfig | null;
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utilities/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAE/F,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,MAAM,WAAW,GAAG,aAAa,GAAG,KAAK,CAAC;AAChD,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,WAAW,GAAG,IAAI,CAAC"}
|