biz-email-builder-shared 1.6.69 → 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.
@@ -6,6 +6,9 @@ export interface ICampaignUsers extends Document {
6
6
  createdAt: Date;
7
7
  updatedAt: Date;
8
8
  isDelivered?: boolean;
9
+ bounceType: string;
10
+ opened: boolean;
11
+ openCount: number;
9
12
  }
10
13
  export declare const CampaignUsersModel: import("mongoose").Model<ICampaignUsers, {}, {}, {}, import("mongoose").Document<unknown, {}, ICampaignUsers> & ICampaignUsers & {
11
14
  _id: Types.ObjectId;
@@ -1 +1 @@
1
- {"version":3,"file":"campaignUsers.entity.d.ts","sourceRoot":"","sources":["../../src/entity/campaignUsers.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAEhD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAYD,eAAO,MAAM,kBAAkB;SACouI,MAAO,QAAQ;;;OADprI,CAAC"}
1
+ {"version":3,"file":"campaignUsers.entity.d.ts","sourceRoot":"","sources":["../../src/entity/campaignUsers.entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAE,MAAM,UAAU,CAAC;AAGhD,MAAM,WAAW,cAAe,SAAQ,QAAQ;IAC9C,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAeD,eAAO,MAAM,kBAAkB;SAEg7H,MAAO,QAAQ;;;OAFh4H,CAAC"}
@@ -2,10 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CampaignUsersModel = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
+ const utilities_1 = require("../utilities");
5
6
  const CampaignUsersSchema = new mongoose_1.Schema({
6
7
  campaignId: { type: mongoose_1.Schema.Types.ObjectId, ref: "campaign", required: true },
7
8
  email: { type: String, required: true },
8
9
  sentAt: { type: Date, default: Date.now },
9
10
  isDelivered: { type: Boolean, default: false },
11
+ bounceType: { type: String, enum: Object.values(utilities_1.BOUNCE_STATUS), default: utilities_1.BOUNCE_STATUS.NULL },
12
+ opened: { type: Boolean, default: false },
13
+ openCount: { type: Number, default: 0 },
10
14
  }, { timestamps: true });
11
15
  exports.CampaignUsersModel = (0, mongoose_1.model)("campaign-users", CampaignUsersSchema);
@@ -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;CAChB;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,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,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;AAqCD,eAAO,MAAM,uBAAuB;SAAq0F,MAAO,QAAQ;;;OAAtwF,CAAC"}
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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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 || '2c6ee24b09816a6f14f95d2838a429d8e5e8b028fbd421d24fc43b96b4a9f3c0';
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) {
@@ -2,4 +2,10 @@ export declare enum INVITE_STATUS {
2
2
  PENDING = "PENDING",
3
3
  ACCEPTED = "ACCEPTED"
4
4
  }
5
+ export declare enum BOUNCE_STATUS {
6
+ SOFT = "SOFT",
7
+ HARD = "HARD",
8
+ BLOCK = "BLOCK",
9
+ NULL = "NULL"
10
+ }
5
11
  //# sourceMappingURL=enums.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/utilities/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB"}
1
+ {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../../src/utilities/enums.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED,oBAAY,aAAa;IACvB,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;IACf,IAAI,SAAS;CACd"}
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.INVITE_STATUS = void 0;
3
+ exports.BOUNCE_STATUS = exports.INVITE_STATUS = void 0;
4
4
  var INVITE_STATUS;
5
5
  (function (INVITE_STATUS) {
6
6
  INVITE_STATUS["PENDING"] = "PENDING";
7
7
  INVITE_STATUS["ACCEPTED"] = "ACCEPTED";
8
8
  })(INVITE_STATUS || (exports.INVITE_STATUS = INVITE_STATUS = {}));
9
+ var BOUNCE_STATUS;
10
+ (function (BOUNCE_STATUS) {
11
+ BOUNCE_STATUS["SOFT"] = "SOFT";
12
+ BOUNCE_STATUS["HARD"] = "HARD";
13
+ BOUNCE_STATUS["BLOCK"] = "BLOCK";
14
+ BOUNCE_STATUS["NULL"] = "NULL";
15
+ })(BOUNCE_STATUS || (exports.BOUNCE_STATUS = BOUNCE_STATUS = {}));
@@ -12,4 +12,5 @@ export * from "./sendMail";
12
12
  export * from "./sendFromGmail";
13
13
  export * from "./getPromptResult";
14
14
  export * from "./createRouterWith405";
15
+ export * from "./sendFromSendGrid";
15
16
  //# 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;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"}
@@ -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<import("nodemailer/lib/smtp-transport").SentMessageInfo>;
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;AAMhD,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"}
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
- async function sendMail(userId, recipient, subject, body, attachments, isHtml, organisationId) {
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.69",
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",