biz-email-builder-shared 1.6.56 → 1.6.58
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/middleware/authentication.d.ts.map +1 -1
- package/dist/middleware/authentication.js +37 -29
- package/dist/utilities/serverMessages.d.ts +2 -1
- package/dist/utilities/serverMessages.d.ts.map +1 -1
- package/dist/utilities/serverMessages.js +1 -0
- package/package.json +1 -1
- package/dist/utilities/sendviaGmail.d.ts +0 -4
- package/dist/utilities/sendviaGmail.d.ts.map +0 -1
- package/dist/utilities/sendviaGmail.js +0 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middleware/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE1D,QAAA,MAAM,SAAS,cACe,QAAQ,OAAO,QAAQ,QAAQ,YAAY,
|
|
1
|
+
{"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../src/middleware/authentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGpC,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE1D,QAAA,MAAM,SAAS,cACe,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAyDxE,CAAC;AAEF,QAAA,MAAM,eAAe,UAAW,KAAK,EAAE,WACT,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAaxE,CAAC;AAEF,QAAA,MAAM,kBAAkB,aAAc,YAAY,EAAE,WACtB,QAAQ,OAAO,QAAQ,QAAQ,YAAY,kBAgBxE,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -22,41 +22,49 @@ const authorize = () => {
|
|
|
22
22
|
if (!req.headers.authorization) {
|
|
23
23
|
throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_UNAUTHORIZED);
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let token;
|
|
26
|
+
try {
|
|
27
|
+
token = await (0, utilities_1.verifyUid)(req.headers.authorization);
|
|
27
28
|
if (!token) {
|
|
28
29
|
throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_SESSION_EXPIRED);
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
return next(new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_INVALID_TOKEN));
|
|
34
|
+
}
|
|
35
|
+
let user = await entity_1.UserModel.findById(token.value.id)
|
|
36
|
+
.populate({
|
|
37
|
+
path: "groups",
|
|
38
|
+
populate: { path: "features", select: "name" },
|
|
39
|
+
})
|
|
40
|
+
.lean();
|
|
41
|
+
if (!user) {
|
|
42
|
+
throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_USER_NOT_FOUND);
|
|
43
|
+
}
|
|
44
|
+
if (user.role === undefined || user.role === null || !Object.values(email_builder_utils_1.ROLES).includes(user.role)) {
|
|
45
|
+
throw new resHandler_1.UnauthorizedRequestError(utilities_1.SERVER_MESSAGES.SE_NO_ROLE_ASSIGNED_ROLE_INVALID);
|
|
46
|
+
}
|
|
47
|
+
const { createdAt, updatedAt, deletedAt, password, verificationToken, __v, updateBy } = user, rest = __rest(user, ["createdAt", "updatedAt", "deletedAt", "password", "verificationToken", "__v", "updateBy"]);
|
|
48
|
+
req.user = Object.assign({}, rest);
|
|
49
|
+
if (req.user && user.role === email_builder_utils_1.ROLES.ADMIN) {
|
|
50
|
+
req.user.isAdmin = true;
|
|
51
|
+
req.user.groups.push({ name: "ADMIN_GROUP", features: Object.values(email_builder_utils_1.FEATURE_TYPE).map((value) => ({ name: value })) });
|
|
52
|
+
}
|
|
53
|
+
let currentPlanDetail = await entity_1.PlanHistoryModel.find({ user: user._id.toString(), isTransactionSuccessfull: true })
|
|
54
|
+
.populate({ path: "subscriptionPlanId", select: "_id planName" })
|
|
55
|
+
.lean()
|
|
56
|
+
.exec();
|
|
57
|
+
if (currentPlanDetail && currentPlanDetail.length) {
|
|
58
|
+
req.userSubsciptionQuota = currentPlanDetail[0].subscriptionQuota;
|
|
59
|
+
req.currentPlan = currentPlanDetail[0].subscriptionPlanId;
|
|
60
|
+
if (currentPlanDetail[0].renewalDate) {
|
|
61
|
+
req.isSubscriptionActive = !(currentPlanDetail[0].renewalDate < new Date());
|
|
54
62
|
}
|
|
55
|
-
next();
|
|
56
63
|
}
|
|
64
|
+
next();
|
|
57
65
|
}
|
|
58
|
-
catch (
|
|
59
|
-
next(
|
|
66
|
+
catch (error) {
|
|
67
|
+
next(error);
|
|
60
68
|
}
|
|
61
69
|
};
|
|
62
70
|
};
|
|
@@ -5,6 +5,7 @@ export declare enum SERVER_MESSAGES {
|
|
|
5
5
|
SE_USER_NOT_FOUND = "SE_USER_NOT_FOUND",
|
|
6
6
|
SE_FORBIDDEN_ROLE_ACCESS_DENIED = "SE_FORBIDDEN_ROLE_ACCESS_DENIED",
|
|
7
7
|
SE_FORBIDDEN_FEATURE_ACCESS_DENIED = "SE_FORBIDDEN_FEATURE_ACCESS_DENIED",
|
|
8
|
-
SE_NO_ROLE_ASSIGNED_ROLE_INVALID = "SE_NO_ROLE_ASSIGNED_ROLE_INVALID"
|
|
8
|
+
SE_NO_ROLE_ASSIGNED_ROLE_INVALID = "SE_NO_ROLE_ASSIGNED_ROLE_INVALID",
|
|
9
|
+
SE_INVALID_TOKEN = "SE_INVALID_TOKEN"
|
|
9
10
|
}
|
|
10
11
|
//# sourceMappingURL=serverMessages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverMessages.d.ts","sourceRoot":"","sources":["../../src/utilities/serverMessages.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,gBAAgB,qBAAqB;IACrC,eAAe,oBAAoB;IACnC,kBAAkB,uBAAuB;IACzC,iBAAiB,sBAAsB;IACvC,+BAA+B,oCAAoC;IACnE,kCAAkC,uCAAuC;IACzE,gCAAgC,qCAAqC;
|
|
1
|
+
{"version":3,"file":"serverMessages.d.ts","sourceRoot":"","sources":["../../src/utilities/serverMessages.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,gBAAgB,qBAAqB;IACrC,eAAe,oBAAoB;IACnC,kBAAkB,uBAAuB;IACzC,iBAAiB,sBAAsB;IACvC,+BAA+B,oCAAoC;IACnE,kCAAkC,uCAAuC;IACzE,gCAAgC,qCAAqC;IACrE,gBAAgB,qBAAqB;CACtC"}
|
|
@@ -10,4 +10,5 @@ var SERVER_MESSAGES;
|
|
|
10
10
|
SERVER_MESSAGES["SE_FORBIDDEN_ROLE_ACCESS_DENIED"] = "SE_FORBIDDEN_ROLE_ACCESS_DENIED";
|
|
11
11
|
SERVER_MESSAGES["SE_FORBIDDEN_FEATURE_ACCESS_DENIED"] = "SE_FORBIDDEN_FEATURE_ACCESS_DENIED";
|
|
12
12
|
SERVER_MESSAGES["SE_NO_ROLE_ASSIGNED_ROLE_INVALID"] = "SE_NO_ROLE_ASSIGNED_ROLE_INVALID";
|
|
13
|
+
SERVER_MESSAGES["SE_INVALID_TOKEN"] = "SE_INVALID_TOKEN";
|
|
13
14
|
})(SERVER_MESSAGES || (exports.SERVER_MESSAGES = SERVER_MESSAGES = {}));
|
package/package.json
CHANGED
|
@@ -1,4 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|