@otters.ai/common-backend 1.0.49 → 1.0.51
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/build/enum/index.d.ts +1 -0
- package/build/enum/index.js +1 -0
- package/build/enum/plan.d.ts +10 -0
- package/build/enum/plan.js +14 -0
- package/build/interface/tokenDataStruct.d.ts +1 -0
- package/build/middleware/checkIsAdmin.d.ts +6 -0
- package/build/middleware/checkIsAdmin.js +56 -0
- package/build/middleware/index.d.ts +1 -0
- package/build/middleware/index.js +1 -0
- package/package.json +1 -1
package/build/enum/index.d.ts
CHANGED
package/build/enum/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PlanType = void 0;
|
|
4
|
+
var PlanType;
|
|
5
|
+
(function (PlanType) {
|
|
6
|
+
PlanType[PlanType["NoStripe"] = 0] = "NoStripe";
|
|
7
|
+
PlanType[PlanType["StartPriceMonth"] = 10] = "StartPriceMonth";
|
|
8
|
+
PlanType[PlanType["StartPriceYear"] = 15] = "StartPriceYear";
|
|
9
|
+
PlanType[PlanType["DrivePriceMonth"] = 20] = "DrivePriceMonth";
|
|
10
|
+
PlanType[PlanType["DrivePriceYear"] = 25] = "DrivePriceYear";
|
|
11
|
+
PlanType[PlanType["GrowPriceMonth"] = 30] = "GrowPriceMonth";
|
|
12
|
+
PlanType[PlanType["GrowPriceYear"] = 35] = "GrowPriceYear";
|
|
13
|
+
PlanType[PlanType["Custom"] = 40] = "Custom";
|
|
14
|
+
})(PlanType || (exports.PlanType = PlanType = {}));
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkIsAdmin = void 0;
|
|
13
|
+
const services_1 = require("../services");
|
|
14
|
+
/**
|
|
15
|
+
* @param {*} req Express req Object
|
|
16
|
+
* @param {*} res Express res Object
|
|
17
|
+
* @param {*} next Express next Function
|
|
18
|
+
*/
|
|
19
|
+
const checkIsAdmin = (sessionLogService, req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
try {
|
|
21
|
+
const authHeader = req.get('Authorization');
|
|
22
|
+
const token = authHeader && authHeader.toString().split(' ')[1];
|
|
23
|
+
if (!token) {
|
|
24
|
+
return res.status(200).json({ success: false, result: { error: "Token not found." } });
|
|
25
|
+
}
|
|
26
|
+
if (!req.headers['sessionid']) {
|
|
27
|
+
return res.status(200).json({ success: false, result: { error: "Session Id not found." } });
|
|
28
|
+
}
|
|
29
|
+
let result = yield sessionLogService
|
|
30
|
+
.findEntry({ sessionId: req.headers['sessionid'].toString() });
|
|
31
|
+
if (result.flag) {
|
|
32
|
+
const verifyToken = services_1.JwtService.verifyJSONToken({
|
|
33
|
+
salt: typeof result.message === "object" ? result.message['salt'] : '',
|
|
34
|
+
token: token
|
|
35
|
+
});
|
|
36
|
+
if (!verifyToken.flag) {
|
|
37
|
+
return res.status(200).json({ success: false, message: verifyToken.message });
|
|
38
|
+
}
|
|
39
|
+
if (typeof verifyToken.message === "object") {
|
|
40
|
+
console.log(verifyToken.message);
|
|
41
|
+
console.log(typeof verifyToken.message.isAdmin);
|
|
42
|
+
if (!verifyToken.message.isAdmin) {
|
|
43
|
+
return res.status(200).json({ success: false, message: "User's cannot access admin API's" });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
next();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return res.status(200).json({ success: false, message: result.message });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
return next(e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
exports.checkIsAdmin = checkIsAdmin;
|