@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.
@@ -6,3 +6,4 @@ export * from './goalCategory';
6
6
  export * from './companyIndustryEnum';
7
7
  export * from './specialitiesEnum';
8
8
  export * from './countriesEnum';
9
+ export * from './plan';
@@ -22,3 +22,4 @@ __exportStar(require("./goalCategory"), exports);
22
22
  __exportStar(require("./companyIndustryEnum"), exports);
23
23
  __exportStar(require("./specialitiesEnum"), exports);
24
24
  __exportStar(require("./countriesEnum"), exports);
25
+ __exportStar(require("./plan"), exports);
@@ -0,0 +1,10 @@
1
+ export declare enum PlanType {
2
+ NoStripe = 0,
3
+ StartPriceMonth = 10,
4
+ StartPriceYear = 15,
5
+ DrivePriceMonth = 20,
6
+ DrivePriceYear = 25,
7
+ GrowPriceMonth = 30,
8
+ GrowPriceYear = 35,
9
+ Custom = 40
10
+ }
@@ -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 = {}));
@@ -4,4 +4,5 @@ export interface TokenDataStruct {
4
4
  active: boolean;
5
5
  firstName: string;
6
6
  lastName: string;
7
+ isAdmin: boolean;
7
8
  }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param {*} req Express req Object
3
+ * @param {*} res Express res Object
4
+ * @param {*} next Express next Function
5
+ */
6
+ export declare const checkIsAdmin: (sessionLogService: any, req: any, res: any, next: any) => Promise<any>;
@@ -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;
@@ -1 +1,2 @@
1
1
  export * from './checkToken';
2
+ export * from './checkIsAdmin';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./checkToken"), exports);
18
+ __exportStar(require("./checkIsAdmin"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@otters.ai/common-backend",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",