biz-email-builder-shared 1.6.77 → 1.6.78

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.
@@ -19,7 +19,7 @@ async function sendFromSendGrid(config, recipient, subject, text, isHtml, analyt
19
19
  cc: recipient.cc ? normalizeEmails(recipient.cc) : undefined,
20
20
  bcc: recipient.bcc ? normalizeEmails(recipient.bcc) : undefined,
21
21
  subject,
22
- custom_args: Object.assign({}, ((analytics === null || analytics === void 0 ? void 0 : analytics.custom_args) || {})),
22
+ custom_args: Object.assign({}, ((analytics === null || analytics === void 0 ? void 0 : analytics.custom_args) && { custom_args: analytics.custom_args })),
23
23
  },
24
24
  ],
25
25
  from: {
@@ -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, analytics: any, organisationId?: string): Promise<any>;
2
+ export declare function sendMail(userId: string, recipient: Recipient, subject: string, body: string, attachments: Attachment[], isHtml: boolean, organisationId?: string, analytics?: any): 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;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"}
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,EACd,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,OAAO,EACf,cAAc,CAAC,EAAE,MAAM,EACvB,SAAS,CAAC,EAAE,GAAG,gBA6DhB"}
@@ -10,27 +10,32 @@ 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
+ async function sendMail(userId, recipient, subject, body, attachments, isHtml, organisationId, analytics) {
14
14
  let config = null;
15
15
  let isOwner;
16
16
  let isMember;
17
17
  // If organisationId is provided
18
18
  if (organisationId) {
19
- isOwner = await entity_1.OrganisationModel.findOne({ createdBy: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
19
+ isOwner = await entity_1.OrganisationModel.findOne({ createdBy: new mongoose_1.Types.ObjectId(userId), isDeleted: false }).lean();
20
20
  if (isOwner) {
21
- config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
21
+ config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false }).lean();
22
22
  }
23
- 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();
23
+ isMember = await entity_1.OrganisationTeamModel.findOne({
24
+ organisationId: new mongoose_1.Types.ObjectId(organisationId),
25
+ user: new mongoose_1.Types.ObjectId(userId),
26
+ isDeleted: false,
27
+ inviteStatus: "ACCEPTED",
28
+ }).lean();
24
29
  if (isMember) {
25
30
  const org = await entity_1.OrganisationModel.findById(organisationId);
26
- config = await entity_1.EmailConfigurationModel.findOne({ user: org === null || org === void 0 ? void 0 : org.createdBy, isDeleted: false, }).lean();
31
+ config = await entity_1.EmailConfigurationModel.findOne({ user: org === null || org === void 0 ? void 0 : org.createdBy, isDeleted: false }).lean();
27
32
  }
28
33
  if (!isMember && !isOwner) {
29
34
  throw new errorHandler_1.ForbiddenRequestError(serverMessages_1.SERVER_MESSAGES.SE_USER_IS_NOT_PART_OF_ORGANISATION);
30
35
  }
31
36
  }
32
37
  else {
33
- config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false, }).lean();
38
+ config = await entity_1.EmailConfigurationModel.findOne({ user: new mongoose_1.Types.ObjectId(userId), isDeleted: false }).lean();
34
39
  }
35
40
  if (!config) {
36
41
  return (0, sendMailViaEnvFallback_1.sendMailViaEnvFallback)(recipient, subject, body, attachments, isHtml);
@@ -42,7 +47,7 @@ async function sendMail(userId, recipient, subject, body, attachments, isHtml, a
42
47
  };
43
48
  return (0, sendFromGmail_1.sendFromGmail)(gmailConfig, recipient, subject, body, attachments, isHtml);
44
49
  }
45
- if (config.defaultMethod === entity_1.CONFIG_METHOD.SMTP && config.smtpConfig) {
50
+ else if (config.defaultMethod === entity_1.CONFIG_METHOD.SMTP && config.smtpConfig) {
46
51
  const smtpConfig = {
47
52
  host: config.smtpConfig.host,
48
53
  port: config.smtpConfig.port,
@@ -55,7 +60,7 @@ async function sendMail(userId, recipient, subject, body, attachments, isHtml, a
55
60
  };
56
61
  return (0, sendMailViaSMTP_1.sendMailViaSMTP)(smtpConfig, recipient, subject, body, attachments, isHtml);
57
62
  }
58
- if (config.defaultMethod === entity_1.CONFIG_METHOD.SEND_GRID && config.sendGridConfig) {
63
+ else if (config.defaultMethod === entity_1.CONFIG_METHOD.SEND_GRID && config.sendGridConfig) {
59
64
  const sendGridConfig = {
60
65
  email: config.sendGridConfig.email,
61
66
  api_key: (0, cryptoUtils_1.decrypt)(config.sendGridConfig.api_key),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "biz-email-builder-shared",
3
- "version": "1.6.77",
3
+ "version": "1.6.78",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [