@konplit-services/common 1.13.0 → 1.15.0
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/helper/errorCodes/error-codes.d.ts +4 -0
- package/build/helper/errorCodes/error-codes.js +4 -0
- package/build/middlewares/token-validation-session.d.ts +1 -0
- package/build/middlewares/token-validation-session.js +7 -2
- package/build/repository/abstract/base-repository.d.ts +5 -0
- package/build/repository/abstract/base-repository.js +30 -0
- package/build/repository/index.d.ts +1 -0
- package/build/repository/index.js +1 -0
- package/package.json +1 -1
|
@@ -9,13 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TwoFactorSessionValidation = void 0;
|
|
12
|
+
exports.TwoFactorSessionValidation = exports.expiredTime = void 0;
|
|
13
13
|
const Jwt_1 = require("../services/Jwt");
|
|
14
14
|
const notAuthorized_1 = require("../errors/notAuthorized");
|
|
15
15
|
const error_codes_1 = require("../helper/errorCodes/error-codes");
|
|
16
16
|
const app_configs_1 = require("../app.configs");
|
|
17
17
|
const helper_1 = require("../helper");
|
|
18
18
|
const redis_1 = require("../redis");
|
|
19
|
+
const expiredTime = (expires) => {
|
|
20
|
+
const expiryTime = expires - Math.floor(Date.now() / 1000);
|
|
21
|
+
return expiryTime;
|
|
22
|
+
};
|
|
23
|
+
exports.expiredTime = expiredTime;
|
|
19
24
|
const TwoFactorSessionValidation = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
25
|
if (!req.headers["k-2fa-session"]) {
|
|
21
26
|
throw new notAuthorized_1.NotAuthorizedError("k-2fa-session token not provided", error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
@@ -29,7 +34,7 @@ const TwoFactorSessionValidation = (req, res, next) => __awaiter(void 0, void 0,
|
|
|
29
34
|
if (isValidToken) {
|
|
30
35
|
throw new notAuthorized_1.NotAuthorizedError(helper_1.lang.not_authorized, error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
31
36
|
}
|
|
32
|
-
yield redis_1.redisWrapper.
|
|
37
|
+
yield redis_1.redisWrapper.revokeToken((0, redis_1.setsetRevokedToken)(payload.userId, token), (0, exports.expiredTime)(payload.exp));
|
|
33
38
|
req.twoFaData = payload;
|
|
34
39
|
}
|
|
35
40
|
return next();
|
|
@@ -0,0 +1,30 @@
|
|
|
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.BaseRepository = void 0;
|
|
13
|
+
const errors_1 = require("../../errors");
|
|
14
|
+
const helper_1 = require("../../helper");
|
|
15
|
+
class BaseRepository {
|
|
16
|
+
constructor(model) {
|
|
17
|
+
this.Model = model;
|
|
18
|
+
}
|
|
19
|
+
exec(operation) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
return yield operation();
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
throw new errors_1.DatabaseConnectionError("Database unavailable. Please retry.", helper_1.error_codes.DATABASE_ERROR);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.BaseRepository = BaseRepository;
|
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./interface/baseRepository"), exports);
|
|
18
18
|
__exportStar(require("./interface/based"), exports);
|
|
19
|
+
__exportStar(require("./abstract/base-repository"), exports);
|