biz-email-builder-shared 1.0.2 → 1.0.4
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/{entity → dist/entity}/user.entity.js +2 -2
- package/{index.js → dist/index.js} +1 -0
- package/dist/middleware/authentication.js +44 -0
- package/dist/middleware/schemaValidate.js +16 -0
- package/dist/resHandler/errorHandler.js +55 -0
- package/{resHandler → dist/resHandler}/successHandler.js +1 -1
- package/dist/utilities/callWithRetries.js +15 -0
- package/dist/utilities/createFolder.js +18 -0
- package/dist/utilities/encryptionUtils.js +26 -0
- package/package.json +4 -2
- package/middleware/authentication.js +0 -104
- package/middleware/schemaValidate.js +0 -58
- package/resHandler/errorHandler.js +0 -77
- package/utilities/callWithRetries.js +0 -73
- package/utilities/createFolder.js +0 -59
- package/utilities/encryptionUtils.js +0 -66
- /package/{entity → dist/entity}/index.d.ts +0 -0
- /package/{entity → dist/entity}/index.d.ts.map +0 -0
- /package/{entity → dist/entity}/index.js +0 -0
- /package/{entity → dist/entity}/user.entity.d.ts +0 -0
- /package/{entity → dist/entity}/user.entity.d.ts.map +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
- /package/{middleware → dist/middleware}/authentication.d.ts +0 -0
- /package/{middleware → dist/middleware}/authentication.d.ts.map +0 -0
- /package/{middleware → dist/middleware}/index.d.ts +0 -0
- /package/{middleware → dist/middleware}/index.d.ts.map +0 -0
- /package/{middleware → dist/middleware}/index.js +0 -0
- /package/{middleware → dist/middleware}/schemaValidate.d.ts +0 -0
- /package/{middleware → dist/middleware}/schemaValidate.d.ts.map +0 -0
- /package/{resHandler → dist/resHandler}/errorHandler.d.ts +0 -0
- /package/{resHandler → dist/resHandler}/errorHandler.d.ts.map +0 -0
- /package/{resHandler → dist/resHandler}/index.d.ts +0 -0
- /package/{resHandler → dist/resHandler}/index.d.ts.map +0 -0
- /package/{resHandler → dist/resHandler}/index.js +0 -0
- /package/{resHandler → dist/resHandler}/successHandler.d.ts +0 -0
- /package/{resHandler → dist/resHandler}/successHandler.d.ts.map +0 -0
- /package/{types → dist/types}/IController.d.ts +0 -0
- /package/{types → dist/types}/IController.d.ts.map +0 -0
- /package/{types → dist/types}/IController.js +0 -0
- /package/{types → dist/types}/IRequest.d.ts +0 -0
- /package/{types → dist/types}/IRequest.d.ts.map +0 -0
- /package/{types → dist/types}/IRequest.js +0 -0
- /package/{types → dist/types}/index.d.ts +0 -0
- /package/{types → dist/types}/index.d.ts.map +0 -0
- /package/{types → dist/types}/index.js +0 -0
- /package/{utilities → dist/utilities}/callWithRetries.d.ts +0 -0
- /package/{utilities → dist/utilities}/callWithRetries.d.ts.map +0 -0
- /package/{utilities → dist/utilities}/createFolder.d.ts +0 -0
- /package/{utilities → dist/utilities}/createFolder.d.ts.map +0 -0
- /package/{utilities → dist/utilities}/encryptionUtils.d.ts +0 -0
- /package/{utilities → dist/utilities}/encryptionUtils.d.ts.map +0 -0
- /package/{utilities → dist/utilities}/index.d.ts +0 -0
- /package/{utilities → dist/utilities}/index.d.ts.map +0 -0
- /package/{utilities → dist/utilities}/index.js +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const UserSchema = new mongoose_1.Schema({
|
|
6
6
|
email: { type: String, unique: true, sparse: true },
|
|
7
7
|
password: { type: String, default: null },
|
|
8
8
|
role: { type: String, default: null },
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.authorize = void 0;
|
|
15
|
+
const utilities_1 = require("../utilities");
|
|
16
|
+
const entity_1 = require("../entity");
|
|
17
|
+
const authorize = (roles) => {
|
|
18
|
+
return async function (req, res, next) {
|
|
19
|
+
if (!req.headers.authorization) {
|
|
20
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
21
|
+
}
|
|
22
|
+
if (!roles.length) {
|
|
23
|
+
return res.status(401).json({ message: 'Unauthorized' });
|
|
24
|
+
}
|
|
25
|
+
if (req.headers.authorization) {
|
|
26
|
+
const token = await (0, utilities_1.verifyUid)(req.headers.authorization);
|
|
27
|
+
if (!token) {
|
|
28
|
+
return res.status(401).json({ message: 'Session Expired' });
|
|
29
|
+
}
|
|
30
|
+
let user = await entity_1.UserModel.findOne({ email: token.value.email });
|
|
31
|
+
if (!user) {
|
|
32
|
+
return res.status(401).json({ message: 'No User Found' });
|
|
33
|
+
}
|
|
34
|
+
const hasAccess = roles.find(role => role === user.role);
|
|
35
|
+
if (!hasAccess) {
|
|
36
|
+
return res.status(403).json({ message: 'Forbbiden' });
|
|
37
|
+
}
|
|
38
|
+
const _a = user.toObject(), { createdAt, updatedAt, deletedAt, password } = _a, rest = __rest(_a, ["createdAt", "updatedAt", "deletedAt", "password"]);
|
|
39
|
+
req.user = Object.assign(Object.assign({}, rest), { userId: rest.email });
|
|
40
|
+
next();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.authorize = authorize;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSchema = void 0;
|
|
4
|
+
const validateSchema = (schema) => {
|
|
5
|
+
return async function (req, res, next) {
|
|
6
|
+
const { error } = schema.validate(req.body, { abortEarly: false });
|
|
7
|
+
if (error) {
|
|
8
|
+
const errorMessage = error.details.map((err) => err.message).join(', ');
|
|
9
|
+
return res.status(400).json({ message: errorMessage });
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
next();
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.validateSchema = validateSchema;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorHandler = exports.CustomRequestError = exports.NotFoundRequestError = exports.BadRequestError = void 0;
|
|
4
|
+
class BadRequestError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
8
|
+
this.name = 'BadRequestError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.BadRequestError = BadRequestError;
|
|
12
|
+
class NotFoundRequestError extends Error {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message);
|
|
15
|
+
Object.setPrototypeOf(this, NotFoundRequestError.prototype);
|
|
16
|
+
this.name = 'NotFoundRequestError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.NotFoundRequestError = NotFoundRequestError;
|
|
20
|
+
class CustomRequestError {
|
|
21
|
+
constructor(title, description) {
|
|
22
|
+
this.name = 'CustomRequestError';
|
|
23
|
+
this.message = {
|
|
24
|
+
title,
|
|
25
|
+
description
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.CustomRequestError = CustomRequestError;
|
|
30
|
+
// Custom error handler middleware
|
|
31
|
+
const errorHandler = (err, req, res, next) => {
|
|
32
|
+
let statusCode = 500; // Default status code
|
|
33
|
+
let errorMessage = 'Internal Server Error'; // Default error message
|
|
34
|
+
if (err instanceof BadRequestError) {
|
|
35
|
+
statusCode = 400;
|
|
36
|
+
errorMessage = err.message;
|
|
37
|
+
}
|
|
38
|
+
else if (err instanceof NotFoundRequestError) {
|
|
39
|
+
statusCode = 404;
|
|
40
|
+
errorMessage = err.message;
|
|
41
|
+
}
|
|
42
|
+
else if (err instanceof CustomRequestError) {
|
|
43
|
+
statusCode = 422;
|
|
44
|
+
errorMessage = err.message;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.error(err.stack); // Log the error for debugging
|
|
48
|
+
}
|
|
49
|
+
// Send an error response
|
|
50
|
+
res.status(statusCode).json({
|
|
51
|
+
message: errorMessage,
|
|
52
|
+
error: err.name // Optionally send the error name/type
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.errorHandler = errorHandler;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.successHandler = void 0;
|
|
4
|
-
|
|
4
|
+
const successHandler = (data, req, res, next) => {
|
|
5
5
|
res.status(200).json(data);
|
|
6
6
|
};
|
|
7
7
|
exports.successHandler = successHandler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callWithRetries = void 0;
|
|
4
|
+
async function callWithRetries(retryCount, failedMessage, functionRef, ...args) {
|
|
5
|
+
try {
|
|
6
|
+
return await functionRef(...args);
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
if (retryCount <= 0)
|
|
10
|
+
throw error;
|
|
11
|
+
console.log("callWithRetries", (error === null || error === void 0 ? void 0 : error.message) || error);
|
|
12
|
+
return callWithRetries(retryCount - 1, failedMessage, functionRef, ...args);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.callWithRetries = callWithRetries;
|
|
@@ -0,0 +1,18 @@
|
|
|
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.createFolder = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
async function createFolder(folderPath) {
|
|
9
|
+
try {
|
|
10
|
+
if (!fs_1.default.existsSync(folderPath)) {
|
|
11
|
+
fs_1.default.mkdirSync(folderPath);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error(`Error: ${error.message}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.createFolder = createFolder;
|
|
@@ -0,0 +1,26 @@
|
|
|
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.verifyUid = exports.signUid = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const signUid = (value) => {
|
|
9
|
+
return jsonwebtoken_1.default.sign({ value }, process.env.JWTSECRET || 'secret', {
|
|
10
|
+
expiresIn: '8h' // expires in 8 hours
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.signUid = signUid;
|
|
14
|
+
const verifyUid = async (token) => new Promise(resolve => {
|
|
15
|
+
const jwtToken = token.split(" ")[1] || token;
|
|
16
|
+
jsonwebtoken_1.default.verify(jwtToken, process.env.JWTSECRET || 'secret', (err, decoded) => {
|
|
17
|
+
if (err) {
|
|
18
|
+
// console.log("error verifyUid", err)
|
|
19
|
+
resolve(null);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
resolve(decoded);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
exports.verifyUid = verifyUid;
|
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "biz-email-builder-shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
|
+
"files": ["dist"],
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
-
"build": "tsc"
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"start": "npm run build && node dist/index.js"
|
|
9
11
|
},
|
|
10
12
|
"dependencies": {
|
|
11
13
|
"express": "^4.18.2",
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
-
t[p] = s[p];
|
|
53
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
-
t[p[i]] = s[p[i]];
|
|
57
|
-
}
|
|
58
|
-
return t;
|
|
59
|
-
};
|
|
60
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
-
exports.authorize = void 0;
|
|
62
|
-
var utilities_1 = require("../utilities");
|
|
63
|
-
var entity_1 = require("../entity");
|
|
64
|
-
var authorize = function (roles) {
|
|
65
|
-
return function (req, res, next) {
|
|
66
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
-
var token, user_1, hasAccess, _a, createdAt, updatedAt, deletedAt, password, rest;
|
|
68
|
-
return __generator(this, function (_b) {
|
|
69
|
-
switch (_b.label) {
|
|
70
|
-
case 0:
|
|
71
|
-
if (!req.headers.authorization) {
|
|
72
|
-
return [2 /*return*/, res.status(401).json({ message: 'Unauthorized' })];
|
|
73
|
-
}
|
|
74
|
-
if (!roles.length) {
|
|
75
|
-
return [2 /*return*/, res.status(401).json({ message: 'Unauthorized' })];
|
|
76
|
-
}
|
|
77
|
-
if (!req.headers.authorization) return [3 /*break*/, 3];
|
|
78
|
-
return [4 /*yield*/, (0, utilities_1.verifyUid)(req.headers.authorization)];
|
|
79
|
-
case 1:
|
|
80
|
-
token = _b.sent();
|
|
81
|
-
if (!token) {
|
|
82
|
-
return [2 /*return*/, res.status(401).json({ message: 'Session Expired' })];
|
|
83
|
-
}
|
|
84
|
-
return [4 /*yield*/, entity_1.UserModel.findOne({ email: token.value.email })];
|
|
85
|
-
case 2:
|
|
86
|
-
user_1 = _b.sent();
|
|
87
|
-
if (!user_1) {
|
|
88
|
-
return [2 /*return*/, res.status(401).json({ message: 'No User Found' })];
|
|
89
|
-
}
|
|
90
|
-
hasAccess = roles.find(function (role) { return role === user_1.role; });
|
|
91
|
-
if (!hasAccess) {
|
|
92
|
-
return [2 /*return*/, res.status(403).json({ message: 'Forbbiden' })];
|
|
93
|
-
}
|
|
94
|
-
_a = user_1.toObject(), createdAt = _a.createdAt, updatedAt = _a.updatedAt, deletedAt = _a.deletedAt, password = _a.password, rest = __rest(_a, ["createdAt", "updatedAt", "deletedAt", "password"]);
|
|
95
|
-
req.user = __assign(__assign({}, rest), { userId: rest.email });
|
|
96
|
-
next();
|
|
97
|
-
_b.label = 3;
|
|
98
|
-
case 3: return [2 /*return*/];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
exports.authorize = authorize;
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.validateSchema = void 0;
|
|
40
|
-
var validateSchema = function (schema) {
|
|
41
|
-
return function (req, res, next) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var error, errorMessage;
|
|
44
|
-
return __generator(this, function (_a) {
|
|
45
|
-
error = schema.validate(req.body, { abortEarly: false }).error;
|
|
46
|
-
if (error) {
|
|
47
|
-
errorMessage = error.details.map(function (err) { return err.message; }).join(', ');
|
|
48
|
-
return [2 /*return*/, res.status(400).json({ message: errorMessage })];
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
next();
|
|
52
|
-
}
|
|
53
|
-
return [2 /*return*/];
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.validateSchema = validateSchema;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.errorHandler = exports.CustomRequestError = exports.NotFoundRequestError = exports.BadRequestError = void 0;
|
|
19
|
-
var BadRequestError = /** @class */ (function (_super) {
|
|
20
|
-
__extends(BadRequestError, _super);
|
|
21
|
-
function BadRequestError(message) {
|
|
22
|
-
var _this = _super.call(this, message) || this;
|
|
23
|
-
Object.setPrototypeOf(_this, BadRequestError.prototype);
|
|
24
|
-
_this.name = 'BadRequestError';
|
|
25
|
-
return _this;
|
|
26
|
-
}
|
|
27
|
-
return BadRequestError;
|
|
28
|
-
}(Error));
|
|
29
|
-
exports.BadRequestError = BadRequestError;
|
|
30
|
-
var NotFoundRequestError = /** @class */ (function (_super) {
|
|
31
|
-
__extends(NotFoundRequestError, _super);
|
|
32
|
-
function NotFoundRequestError(message) {
|
|
33
|
-
var _this = _super.call(this, message) || this;
|
|
34
|
-
Object.setPrototypeOf(_this, NotFoundRequestError.prototype);
|
|
35
|
-
_this.name = 'NotFoundRequestError';
|
|
36
|
-
return _this;
|
|
37
|
-
}
|
|
38
|
-
return NotFoundRequestError;
|
|
39
|
-
}(Error));
|
|
40
|
-
exports.NotFoundRequestError = NotFoundRequestError;
|
|
41
|
-
var CustomRequestError = /** @class */ (function () {
|
|
42
|
-
function CustomRequestError(title, description) {
|
|
43
|
-
this.name = 'CustomRequestError';
|
|
44
|
-
this.message = {
|
|
45
|
-
title: title,
|
|
46
|
-
description: description
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return CustomRequestError;
|
|
50
|
-
}());
|
|
51
|
-
exports.CustomRequestError = CustomRequestError;
|
|
52
|
-
// Custom error handler middleware
|
|
53
|
-
var errorHandler = function (err, req, res, next) {
|
|
54
|
-
var statusCode = 500; // Default status code
|
|
55
|
-
var errorMessage = 'Internal Server Error'; // Default error message
|
|
56
|
-
if (err instanceof BadRequestError) {
|
|
57
|
-
statusCode = 400;
|
|
58
|
-
errorMessage = err.message;
|
|
59
|
-
}
|
|
60
|
-
else if (err instanceof NotFoundRequestError) {
|
|
61
|
-
statusCode = 404;
|
|
62
|
-
errorMessage = err.message;
|
|
63
|
-
}
|
|
64
|
-
else if (err instanceof CustomRequestError) {
|
|
65
|
-
statusCode = 422;
|
|
66
|
-
errorMessage = err.message;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
console.error(err.stack); // Log the error for debugging
|
|
70
|
-
}
|
|
71
|
-
// Send an error response
|
|
72
|
-
res.status(statusCode).json({
|
|
73
|
-
message: errorMessage,
|
|
74
|
-
error: err.name // Optionally send the error name/type
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
exports.errorHandler = errorHandler;
|
|
@@ -1,73 +0,0 @@
|
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.callWithRetries = void 0;
|
|
49
|
-
function callWithRetries(retryCount, failedMessage, functionRef) {
|
|
50
|
-
var args = [];
|
|
51
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
52
|
-
args[_i - 3] = arguments[_i];
|
|
53
|
-
}
|
|
54
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
var error_1;
|
|
56
|
-
return __generator(this, function (_a) {
|
|
57
|
-
switch (_a.label) {
|
|
58
|
-
case 0:
|
|
59
|
-
_a.trys.push([0, 2, , 3]);
|
|
60
|
-
return [4 /*yield*/, functionRef.apply(void 0, args)];
|
|
61
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
62
|
-
case 2:
|
|
63
|
-
error_1 = _a.sent();
|
|
64
|
-
if (retryCount <= 0)
|
|
65
|
-
throw error_1;
|
|
66
|
-
console.log("callWithRetries", (error_1 === null || error_1 === void 0 ? void 0 : error_1.message) || error_1);
|
|
67
|
-
return [2 /*return*/, callWithRetries.apply(void 0, __spreadArray([retryCount - 1, failedMessage, functionRef], args, false))];
|
|
68
|
-
case 3: return [2 /*return*/];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
exports.callWithRetries = callWithRetries;
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.createFolder = void 0;
|
|
43
|
-
var fs_1 = __importDefault(require("fs"));
|
|
44
|
-
function createFolder(folderPath) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
return __generator(this, function (_a) {
|
|
47
|
-
try {
|
|
48
|
-
if (!fs_1.default.existsSync(folderPath)) {
|
|
49
|
-
fs_1.default.mkdirSync(folderPath);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
console.error("Error: ".concat(error.message));
|
|
54
|
-
}
|
|
55
|
-
return [2 /*return*/];
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
exports.createFolder = createFolder;
|
|
@@ -1,66 +0,0 @@
|
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.verifyUid = exports.signUid = void 0;
|
|
43
|
-
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
44
|
-
var signUid = function (value) {
|
|
45
|
-
return jsonwebtoken_1.default.sign({ value: value }, process.env.JWTSECRET || 'secret', {
|
|
46
|
-
expiresIn: '8h' // expires in 8 hours
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
exports.signUid = signUid;
|
|
50
|
-
var verifyUid = function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
51
|
-
return __generator(this, function (_a) {
|
|
52
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
53
|
-
var jwtToken = token.split(" ")[1] || token;
|
|
54
|
-
jsonwebtoken_1.default.verify(jwtToken, process.env.JWTSECRET || 'secret', function (err, decoded) {
|
|
55
|
-
if (err) {
|
|
56
|
-
// console.log("error verifyUid", err)
|
|
57
|
-
resolve(null);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
resolve(decoded);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
})];
|
|
64
|
-
});
|
|
65
|
-
}); };
|
|
66
|
-
exports.verifyUid = verifyUid;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|