biz-email-builder-shared 1.6.70 → 1.6.71
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/entity/emailConfiguration.entity.d.ts +7 -1
- package/dist/entity/emailConfiguration.entity.d.ts.map +1 -1
- package/dist/entity/emailConfiguration.entity.js +6 -0
- package/dist/utilities/cryptoUtils.js +1 -1
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.d.ts.map +1 -1
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/sendFromSendGrid.d.ts +4 -0
- package/dist/utilities/sendFromSendGrid.d.ts.map +1 -0
- package/dist/utilities/sendFromSendGrid.js +46 -0
- package/dist/utilities/sendMail.d.ts +1 -1
- package/dist/utilities/sendMail.d.ts.map +1 -1
- package/dist/utilities/sendMail.js +9 -1
- package/package.json +2 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Types } from "mongoose";
|
|
2
2
|
export declare enum CONFIG_METHOD {
|
|
3
3
|
SMTP = "SMTP",
|
|
4
|
-
GMAIL = "GMAIL"
|
|
4
|
+
GMAIL = "GMAIL",
|
|
5
|
+
SEND_GRID = "SEND_GRID"
|
|
5
6
|
}
|
|
6
7
|
export declare enum ENCRYPTION_METHOD {
|
|
7
8
|
NONE = "NONE",
|
|
@@ -22,11 +23,16 @@ export interface IGmailConfig {
|
|
|
22
23
|
email: string;
|
|
23
24
|
password: string;
|
|
24
25
|
}
|
|
26
|
+
export interface ISendGridConfig {
|
|
27
|
+
email: string;
|
|
28
|
+
api_key: string;
|
|
29
|
+
}
|
|
25
30
|
export interface IEmailConfiguration extends Document {
|
|
26
31
|
user: Types.ObjectId;
|
|
27
32
|
method: CONFIG_METHOD;
|
|
28
33
|
smtpConfig?: ISMTPConfig;
|
|
29
34
|
gmailConfig?: IGmailConfig;
|
|
35
|
+
sendGridConfig?: ISendGridConfig;
|
|
30
36
|
isDeleted: boolean;
|
|
31
37
|
updatedBy: Types.ObjectId;
|
|
32
38
|
createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emailConfiguration.entity.d.ts","sourceRoot":"","sources":["../../src/entity/emailConfiguration.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,KAAK,UAAU;
|
|
1
|
+
{"version":3,"file":"emailConfiguration.entity.d.ts","sourceRoot":"","sources":["../../src/entity/emailConfiguration.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,SAAS,cAAc;CACxB;AAED,oBAAY,iBAAiB;IAC3B,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,GAAG,QAAQ;CACZ;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,iBAAiB,CAAC;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,mBAAoB,SAAQ,QAAQ;IACnD,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,WAAW,CAAC,EAAE,YAAY,CAAC;IAC3B,cAAc,CAAC,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,aAAa,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;CACtC;AA+CD,eAAO,MAAM,uBAAuB;SAAm7E,MAAO,QAAQ;;;OAAp3E,CAAC"}
|
|
@@ -6,6 +6,7 @@ var CONFIG_METHOD;
|
|
|
6
6
|
(function (CONFIG_METHOD) {
|
|
7
7
|
CONFIG_METHOD["SMTP"] = "SMTP";
|
|
8
8
|
CONFIG_METHOD["GMAIL"] = "GMAIL";
|
|
9
|
+
CONFIG_METHOD["SEND_GRID"] = "SEND_GRID";
|
|
9
10
|
})(CONFIG_METHOD || (exports.CONFIG_METHOD = CONFIG_METHOD = {}));
|
|
10
11
|
var ENCRYPTION_METHOD;
|
|
11
12
|
(function (ENCRYPTION_METHOD) {
|
|
@@ -27,11 +28,16 @@ const gmailConfigSchema = new mongoose_1.Schema({
|
|
|
27
28
|
email: { type: String, required: true },
|
|
28
29
|
password: { type: String, required: true }
|
|
29
30
|
}, { _id: false });
|
|
31
|
+
const sendGridConfigSchema = new mongoose_1.Schema({
|
|
32
|
+
email: { type: String, required: true },
|
|
33
|
+
api_key: { type: String, required: true }
|
|
34
|
+
}, { _id: false });
|
|
30
35
|
const EmailConfigurationSchema = new mongoose_1.Schema({
|
|
31
36
|
user: { type: mongoose_1.Schema.Types.ObjectId, ref: "user", required: true },
|
|
32
37
|
method: { type: String, enum: Object.values(CONFIG_METHOD), required: true },
|
|
33
38
|
smtpConfig: { type: smtpConfigSchema, required: false },
|
|
34
39
|
gmailConfig: { type: gmailConfigSchema, required: false },
|
|
40
|
+
sendGridConfig: { type: sendGridConfigSchema, required: false },
|
|
35
41
|
isDeleted: { type: Boolean, default: false },
|
|
36
42
|
updatedBy: { type: mongoose_1.Schema.Types.ObjectId, ref: "user" },
|
|
37
43
|
defaultMethod: { type: String, enum: Object.values(CONFIG_METHOD), default: null },
|
|
@@ -7,7 +7,7 @@ exports.encrypt = encrypt;
|
|
|
7
7
|
exports.decrypt = decrypt;
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
// Ensure the encryption key is 32 bytes (256 bits)
|
|
10
|
-
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY
|
|
10
|
+
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY;
|
|
11
11
|
const IV_LENGTH = 16; // AES block size (128 bits)
|
|
12
12
|
// Validate key length and make sure it's 32 bytes
|
|
13
13
|
function getEncryptionKey(key) {
|
|
@@ -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;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,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;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
|
package/dist/utilities/index.js
CHANGED
|
@@ -28,3 +28,4 @@ __exportStar(require("./sendMail"), exports);
|
|
|
28
28
|
__exportStar(require("./sendFromGmail"), exports);
|
|
29
29
|
__exportStar(require("./getPromptResult"), exports);
|
|
30
30
|
__exportStar(require("./createRouterWith405"), exports);
|
|
31
|
+
__exportStar(require("./sendFromSendGrid"), exports);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ISendGridConfig } from '../entity';
|
|
2
|
+
import { Recipient } from './types';
|
|
3
|
+
export declare function sendFromSendGrid(config: ISendGridConfig, recipient: Recipient, subject: string, text: string, isHtml: boolean, analytics: any): Promise<any>;
|
|
4
|
+
//# sourceMappingURL=sendFromSendGrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendFromSendGrid.d.ts","sourceRoot":"","sources":["../../src/utilities/sendFromSendGrid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAUpC,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,eAAe,EACvB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,EACf,SAAS,EAAE,GAAG,gBAuCf"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendFromSendGrid = sendFromSendGrid;
|
|
4
|
+
function normalizeEmails(input) {
|
|
5
|
+
return Array.isArray(input)
|
|
6
|
+
? input.map((email) => ({ email }))
|
|
7
|
+
: [{ email: input }];
|
|
8
|
+
}
|
|
9
|
+
async function sendFromSendGrid(config, recipient, subject, text, isHtml, analytics) {
|
|
10
|
+
var _a;
|
|
11
|
+
const client = require('@sendgrid/client'); // isolate per call
|
|
12
|
+
client.setApiKey(config.api_key);
|
|
13
|
+
const contentType = isHtml ? 'text/html' : 'text/plain';
|
|
14
|
+
const request = {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
url: '/v3/mail/send',
|
|
17
|
+
body: {
|
|
18
|
+
personalizations: [
|
|
19
|
+
{
|
|
20
|
+
to: normalizeEmails(recipient.to),
|
|
21
|
+
cc: recipient.cc ? normalizeEmails(recipient.cc) : undefined,
|
|
22
|
+
bcc: recipient.bcc ? normalizeEmails(recipient.bcc) : undefined,
|
|
23
|
+
subject,
|
|
24
|
+
custom_args: Object.assign({}, analytics)
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
from: {
|
|
28
|
+
email: config.email // must be verified in SendGrid
|
|
29
|
+
},
|
|
30
|
+
content: [
|
|
31
|
+
{
|
|
32
|
+
type: contentType,
|
|
33
|
+
value: text
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
try {
|
|
39
|
+
const [response] = await client.request(request);
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('SendGrid client error:', ((_a = error.response) === null || _a === void 0 ? void 0 : _a.body) || error.message);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
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<
|
|
2
|
+
export declare function sendMail(userId: string, recipient: Recipient, subject: string, body: string, attachments: Attachment[], isHtml: boolean, analytics: any, organisationId?: string): Promise<any>;
|
|
3
3
|
//# sourceMappingURL=sendMail.d.ts.map
|
|
@@ -1 +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;
|
|
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;AAOhD,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,EAAE,SAAS,EAAE,GAAG,EAC1D,cAAc,CAAC,EAAE,MAAM,gBA6DxB"}
|
|
@@ -9,7 +9,8 @@ const errorHandler_1 = require("../resHandler/errorHandler");
|
|
|
9
9
|
const sendFromGmail_1 = require("./sendFromGmail");
|
|
10
10
|
const cryptoUtils_1 = require("./cryptoUtils");
|
|
11
11
|
const serverMessages_1 = require("./serverMessages");
|
|
12
|
-
|
|
12
|
+
const sendFromSendGrid_1 = require("./sendFromSendGrid");
|
|
13
|
+
async function sendMail(userId, recipient, subject, body, attachments, isHtml, analytics, organisationId) {
|
|
13
14
|
let config = null;
|
|
14
15
|
let isOwner;
|
|
15
16
|
let isMember;
|
|
@@ -54,6 +55,13 @@ async function sendMail(userId, recipient, subject, body, attachments, isHtml, o
|
|
|
54
55
|
};
|
|
55
56
|
return (0, sendMailViaSMTP_1.sendMailViaSMTP)(smtpConfig, recipient, subject, body, attachments, isHtml);
|
|
56
57
|
}
|
|
58
|
+
if (config.method === entity_1.CONFIG_METHOD.SEND_GRID && config.sendGridConfig) {
|
|
59
|
+
const sendGridConfig = {
|
|
60
|
+
email: config.sendGridConfig.email,
|
|
61
|
+
api_key: (0, cryptoUtils_1.decrypt)(config.sendGridConfig.api_key),
|
|
62
|
+
};
|
|
63
|
+
return (0, sendFromSendGrid_1.sendFromSendGrid)(sendGridConfig, recipient, subject, body, isHtml, analytics);
|
|
64
|
+
}
|
|
57
65
|
//. Final fallback
|
|
58
66
|
return (0, sendMailViaEnvFallback_1.sendMailViaEnvFallback)(recipient, subject, body, attachments, isHtml);
|
|
59
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biz-email-builder-shared",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.71",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"start": "npm run build && node dist/index.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@sendgrid/client": "^8.1.5",
|
|
15
16
|
"email-builder-utils": "^1.0.16",
|
|
16
17
|
"express": "^4.18.2",
|
|
17
18
|
"joi": "^17.11.0",
|