@fluyappgocore/commons-backend 1.0.202
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/classes/BacklogManager.d.ts +129 -0
- package/build/classes/BacklogManager.js +417 -0
- package/build/classes/BacklogMonitor.d.ts +102 -0
- package/build/classes/BacklogMonitor.js +222 -0
- package/build/classes/HttpResponse.d.ts +7 -0
- package/build/classes/HttpResponse.js +13 -0
- package/build/classes/index.d.ts +3 -0
- package/build/classes/index.js +15 -0
- package/build/dtos/file.dto.d.ts +5 -0
- package/build/dtos/file.dto.js +25 -0
- package/build/dtos/index.d.ts +1 -0
- package/build/dtos/index.js +13 -0
- package/build/events/BatchEnhancedListener.d.ts +106 -0
- package/build/events/BatchEnhancedListener.js +307 -0
- package/build/events/EnhancedListener.d.ts +75 -0
- package/build/events/EnhancedListener.js +185 -0
- package/build/events/baseListener.d.ts +19 -0
- package/build/events/baseListener.js +90 -0
- package/build/events/basePublisher.d.ts +14 -0
- package/build/events/basePublisher.js +84 -0
- package/build/events/config.d.ts +7 -0
- package/build/events/config.js +14 -0
- package/build/events/createClient.d.ts +38 -0
- package/build/events/createClient.js +416 -0
- package/build/events/index.d.ts +6 -0
- package/build/events/index.js +18 -0
- package/build/events/interfaces/agent.event.d.ts +7 -0
- package/build/events/interfaces/agent.event.js +2 -0
- package/build/events/interfaces/agentCrud.event.d.ts +7 -0
- package/build/events/interfaces/agentCrud.event.js +2 -0
- package/build/events/interfaces/agentTracking.event.d.ts +7 -0
- package/build/events/interfaces/agentTracking.event.js +2 -0
- package/build/events/interfaces/audit.event.d.ts +7 -0
- package/build/events/interfaces/audit.event.js +2 -0
- package/build/events/interfaces/branch.event.d.ts +7 -0
- package/build/events/interfaces/branch.event.js +2 -0
- package/build/events/interfaces/deleteTracking.event.d.ts +7 -0
- package/build/events/interfaces/deleteTracking.event.js +2 -0
- package/build/events/interfaces/department.event.d.ts +7 -0
- package/build/events/interfaces/department.event.js +2 -0
- package/build/events/interfaces/entity.event.d.ts +7 -0
- package/build/events/interfaces/entity.event.js +2 -0
- package/build/events/interfaces/index.d.ts +23 -0
- package/build/events/interfaces/index.js +35 -0
- package/build/events/interfaces/manualMatch.event.d.ts +7 -0
- package/build/events/interfaces/manualMatch.event.js +2 -0
- package/build/events/interfaces/match.event.d.ts +7 -0
- package/build/events/interfaces/match.event.js +2 -0
- package/build/events/interfaces/monitor.event.d.ts +7 -0
- package/build/events/interfaces/monitor.event.js +2 -0
- package/build/events/interfaces/notification.event.d.ts +7 -0
- package/build/events/interfaces/notification.event.js +2 -0
- package/build/events/interfaces/object.event.d.ts +7 -0
- package/build/events/interfaces/object.event.js +2 -0
- package/build/events/interfaces/payments.event.d.ts +7 -0
- package/build/events/interfaces/payments.event.js +2 -0
- package/build/events/interfaces/planning.event.d.ts +7 -0
- package/build/events/interfaces/planning.event.js +2 -0
- package/build/events/interfaces/service.event.d.ts +7 -0
- package/build/events/interfaces/service.event.js +2 -0
- package/build/events/interfaces/subscription.event.d.ts +7 -0
- package/build/events/interfaces/subscription.event.js +2 -0
- package/build/events/interfaces/ticket.event.d.ts +7 -0
- package/build/events/interfaces/ticket.event.js +2 -0
- package/build/events/interfaces/ticketNote.event.d.ts +7 -0
- package/build/events/interfaces/ticketNote.event.js +2 -0
- package/build/events/interfaces/ticketTracking.event.d.ts +7 -0
- package/build/events/interfaces/ticketTracking.event.js +2 -0
- package/build/events/interfaces/ticketxTopics.event.d.ts +7 -0
- package/build/events/interfaces/ticketxTopics.event.js +2 -0
- package/build/events/interfaces/topics.event.d.ts +7 -0
- package/build/events/interfaces/topics.event.js +2 -0
- package/build/events/interfaces/waitingList.event.d.ts +7 -0
- package/build/events/interfaces/waitingList.event.js +2 -0
- package/build/exceptions/AuthenticationTokenMissingException.d.ts +5 -0
- package/build/exceptions/AuthenticationTokenMissingException.js +27 -0
- package/build/exceptions/HttpException.d.ts +5 -0
- package/build/exceptions/HttpException.js +27 -0
- package/build/exceptions/MongoErrorException.d.ts +4 -0
- package/build/exceptions/MongoErrorException.js +27 -0
- package/build/exceptions/MulterException.d.ts +4 -0
- package/build/exceptions/MulterException.js +27 -0
- package/build/exceptions/QwizardException.d.ts +5 -0
- package/build/exceptions/QwizardException.js +27 -0
- package/build/exceptions/RecordingServerException.d.ts +5 -0
- package/build/exceptions/RecordingServerException.js +27 -0
- package/build/exceptions/UserNotFoundException.d.ts +4 -0
- package/build/exceptions/UserNotFoundException.js +27 -0
- package/build/exceptions/UserWithThatEmailAlreadyExistsException.d.ts +4 -0
- package/build/exceptions/UserWithThatEmailAlreadyExistsException.js +27 -0
- package/build/exceptions/WrongAnonymousAuthException.d.ts +5 -0
- package/build/exceptions/WrongAnonymousAuthException.js +27 -0
- package/build/exceptions/WrongAuthenticationTokenException.d.ts +5 -0
- package/build/exceptions/WrongAuthenticationTokenException.js +27 -0
- package/build/exceptions/WrongBusinessAuthException.d.ts +5 -0
- package/build/exceptions/WrongBusinessAuthException.js +27 -0
- package/build/exceptions/WrongCredentialsException.d.ts +4 -0
- package/build/exceptions/WrongCredentialsException.js +27 -0
- package/build/exceptions/WrongRoomException.d.ts +4 -0
- package/build/exceptions/WrongRoomException.js +27 -0
- package/build/exceptions/index.d.ts +16 -0
- package/build/exceptions/index.js +28 -0
- package/build/exceptions/invalidToken.exception.d.ts +4 -0
- package/build/exceptions/invalidToken.exception.js +27 -0
- package/build/exceptions/missingToken.exception.d.ts +4 -0
- package/build/exceptions/missingToken.exception.js +27 -0
- package/build/exceptions/wrongAuth.exception.d.ts +5 -0
- package/build/exceptions/wrongAuth.exception.js +27 -0
- package/build/index.d.ts +12 -0
- package/build/index.js +32 -0
- package/build/interfaces/controller.interface.d.ts +5 -0
- package/build/interfaces/controller.interface.js +2 -0
- package/build/interfaces/index.d.ts +3 -0
- package/build/interfaces/index.js +15 -0
- package/build/interfaces/requesWithUser.interface.d.ts +11 -0
- package/build/interfaces/requesWithUser.interface.js +2 -0
- package/build/interfaces/token.interface.d.ts +12 -0
- package/build/interfaces/token.interface.js +2 -0
- package/build/lib/ensureDatabase.d.ts +11 -0
- package/build/lib/ensureDatabase.js +97 -0
- package/build/lib/functions.d.ts +89 -0
- package/build/lib/functions.js +214 -0
- package/build/lib/helpers.d.ts +29 -0
- package/build/lib/helpers.js +33 -0
- package/build/lib/index.d.ts +4 -0
- package/build/lib/index.js +16 -0
- package/build/lib/logger.d.ts +2 -0
- package/build/lib/logger.js +41 -0
- package/build/middlewares/auth.middleware.d.ts +6 -0
- package/build/middlewares/auth.middleware.js +287 -0
- package/build/middlewares/error.middleware.d.ts +3 -0
- package/build/middlewares/error.middleware.js +14 -0
- package/build/middlewares/index.d.ts +3 -0
- package/build/middlewares/index.js +15 -0
- package/build/middlewares/validation.middleware.d.ts +2 -0
- package/build/middlewares/validation.middleware.js +22 -0
- package/package.json +45 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
+
function step(op) {
|
|
35
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
+
while (_) try {
|
|
37
|
+
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;
|
|
38
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
+
switch (op[0]) {
|
|
40
|
+
case 0: case 1: t = op; break;
|
|
41
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
+
default:
|
|
45
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
+
if (t[2]) _.ops.pop();
|
|
50
|
+
_.trys.pop(); continue;
|
|
51
|
+
}
|
|
52
|
+
op = body.call(thisArg, _);
|
|
53
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
exports.authTokenMiddleware = exports.midAuthMiddleware = exports.authMiddleware = exports.authFBMiddleware = void 0;
|
|
59
|
+
var jwt = __importStar(require("jsonwebtoken"));
|
|
60
|
+
var exceptions_1 = require("../exceptions/");
|
|
61
|
+
var wrongAuth_exception_1 = require("../exceptions/wrongAuth.exception");
|
|
62
|
+
var redis = __importStar(require("redis"));
|
|
63
|
+
var promisify = require("util").promisify;
|
|
64
|
+
var RedisClient = redis.createClient({ host: process.env.REDIS_HOST, port: 6379 });
|
|
65
|
+
var hGetAsync = promisify(RedisClient.hget).bind(RedisClient);
|
|
66
|
+
var hDelAsync = promisify(RedisClient.hdel).bind(RedisClient);
|
|
67
|
+
function authFBMiddleware(request, response, next) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
70
|
+
var authorization, secret, verificationResponse, userJwt, userRaw, user, jwtPayload, error_1;
|
|
71
|
+
return __generator(this, function (_c) {
|
|
72
|
+
switch (_c.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
|
|
75
|
+
if (!authorization) return [3 /*break*/, 9];
|
|
76
|
+
secret = process.env.JWT_KEY || " ";
|
|
77
|
+
_c.label = 1;
|
|
78
|
+
case 1:
|
|
79
|
+
_c.trys.push([1, 7, , 8]);
|
|
80
|
+
verificationResponse = jwt.verify(authorization, secret);
|
|
81
|
+
userJwt = verificationResponse;
|
|
82
|
+
return [4 /*yield*/, hGetAsync("user", userJwt.uuid)];
|
|
83
|
+
case 2:
|
|
84
|
+
userRaw = _c.sent();
|
|
85
|
+
if (!userRaw) {
|
|
86
|
+
console.error("🚨 SECURITY ALERT - User not found in Redis:", {
|
|
87
|
+
uuid: userJwt.uuid,
|
|
88
|
+
timestamp: new Date().toISOString(),
|
|
89
|
+
ip: request.ip,
|
|
90
|
+
userAgent: request.get("User-Agent"),
|
|
91
|
+
});
|
|
92
|
+
return [2 /*return*/, next(new wrongAuth_exception_1.WrongAuthException())];
|
|
93
|
+
}
|
|
94
|
+
user = JSON.parse(userRaw);
|
|
95
|
+
if (!(user.id !== userJwt.id || user.uuid !== userJwt.uuid || user.entityUuid !== userJwt.entityUuid)) return [3 /*break*/, 4];
|
|
96
|
+
console.error("🚨 CRITICAL SECURITY ALERT - Data mismatch detected:", {
|
|
97
|
+
error: "Token and Redis data mismatch",
|
|
98
|
+
jwtData: {
|
|
99
|
+
id: userJwt.id,
|
|
100
|
+
uuid: userJwt.uuid,
|
|
101
|
+
entityUuid: userJwt.entityUuid,
|
|
102
|
+
},
|
|
103
|
+
redisData: {
|
|
104
|
+
id: user.id,
|
|
105
|
+
uuid: user.uuid,
|
|
106
|
+
entityUuid: user.entityUuid,
|
|
107
|
+
email: user.email,
|
|
108
|
+
},
|
|
109
|
+
timestamp: new Date().toISOString(),
|
|
110
|
+
ip: request.ip,
|
|
111
|
+
userAgent: request.get("User-Agent"),
|
|
112
|
+
url: request.originalUrl,
|
|
113
|
+
method: request.method,
|
|
114
|
+
});
|
|
115
|
+
return [4 /*yield*/, hDelAsync("user", userJwt.uuid)];
|
|
116
|
+
case 3:
|
|
117
|
+
_c.sent();
|
|
118
|
+
return [2 /*return*/, next(new wrongAuth_exception_1.WrongAuthException())];
|
|
119
|
+
case 4:
|
|
120
|
+
jwtPayload = userJwt;
|
|
121
|
+
if (!(jwtPayload.exp && jwtPayload.exp < Math.floor(Date.now() / 1000))) return [3 /*break*/, 6];
|
|
122
|
+
console.error("🚨 SECURITY ALERT - Expired token used:", {
|
|
123
|
+
uuid: userJwt.uuid,
|
|
124
|
+
exp: jwtPayload.exp,
|
|
125
|
+
now: Math.floor(Date.now() / 1000),
|
|
126
|
+
timestamp: new Date().toISOString(),
|
|
127
|
+
});
|
|
128
|
+
return [4 /*yield*/, hDelAsync("user", userJwt.uuid)];
|
|
129
|
+
case 5:
|
|
130
|
+
_c.sent();
|
|
131
|
+
return [2 /*return*/, next(new wrongAuth_exception_1.WrongAuthException())];
|
|
132
|
+
case 6:
|
|
133
|
+
request.user = user;
|
|
134
|
+
next();
|
|
135
|
+
return [3 /*break*/, 8];
|
|
136
|
+
case 7:
|
|
137
|
+
error_1 = _c.sent();
|
|
138
|
+
console.error("🚨 JWT VERIFICATION ERROR:", {
|
|
139
|
+
error: error_1 instanceof Error ? error_1.message : String(error_1),
|
|
140
|
+
timestamp: new Date().toISOString(),
|
|
141
|
+
});
|
|
142
|
+
next(new exceptions_1.MissingTokenException("Error: " + error_1));
|
|
143
|
+
return [3 /*break*/, 8];
|
|
144
|
+
case 8: return [3 /*break*/, 10];
|
|
145
|
+
case 9:
|
|
146
|
+
next(new exceptions_1.MissingTokenException("Error: no auth"));
|
|
147
|
+
_c.label = 10;
|
|
148
|
+
case 10: return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.authFBMiddleware = authFBMiddleware;
|
|
154
|
+
function authMiddleware(request, response, next) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var authorization, secret, verificationResponse, user, userPayload;
|
|
158
|
+
return __generator(this, function (_c) {
|
|
159
|
+
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
|
|
160
|
+
if (authorization) {
|
|
161
|
+
secret = process.env.JWT_KEY || "";
|
|
162
|
+
try {
|
|
163
|
+
verificationResponse = jwt.verify(authorization, secret);
|
|
164
|
+
user = verificationResponse;
|
|
165
|
+
if (user) {
|
|
166
|
+
userPayload = user;
|
|
167
|
+
if (userPayload.exp && userPayload.exp < Math.floor(Date.now() / 1000)) {
|
|
168
|
+
console.error("🚨 SECURITY ALERT - Expired token in basic auth:", {
|
|
169
|
+
exp: userPayload.exp,
|
|
170
|
+
now: Math.floor(Date.now() / 1000),
|
|
171
|
+
timestamp: new Date().toISOString(),
|
|
172
|
+
});
|
|
173
|
+
return [2 /*return*/, next(new wrongAuth_exception_1.WrongAuthException())];
|
|
174
|
+
}
|
|
175
|
+
request.user = user;
|
|
176
|
+
next();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
next(new wrongAuth_exception_1.WrongAuthException());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error("🚨 AUTH MIDDLEWARE ERROR:", {
|
|
184
|
+
error: error instanceof Error ? error.message : String(error),
|
|
185
|
+
timestamp: new Date().toISOString(),
|
|
186
|
+
});
|
|
187
|
+
next(new exceptions_1.MissingTokenException("JWT verification failed"));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
next(new exceptions_1.MissingTokenException("No authorization token provided"));
|
|
192
|
+
}
|
|
193
|
+
return [2 /*return*/];
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
exports.authMiddleware = authMiddleware;
|
|
198
|
+
function midAuthMiddleware(request, response, next) {
|
|
199
|
+
var _a, _b;
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var authorization, secret, verificationResponse, user;
|
|
202
|
+
return __generator(this, function (_c) {
|
|
203
|
+
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
|
|
204
|
+
if (authorization) {
|
|
205
|
+
secret = process.env.JWT_KEY || "";
|
|
206
|
+
try {
|
|
207
|
+
verificationResponse = jwt.verify(authorization, secret);
|
|
208
|
+
user = verificationResponse;
|
|
209
|
+
if (user) {
|
|
210
|
+
request.user = user;
|
|
211
|
+
next();
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
request.user = {
|
|
215
|
+
_id: "",
|
|
216
|
+
email: "",
|
|
217
|
+
password: "",
|
|
218
|
+
lastName: "",
|
|
219
|
+
};
|
|
220
|
+
next();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
request.user = {
|
|
225
|
+
_id: "",
|
|
226
|
+
email: "",
|
|
227
|
+
password: "",
|
|
228
|
+
lastName: "",
|
|
229
|
+
};
|
|
230
|
+
next();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
request.user = {
|
|
235
|
+
_id: "",
|
|
236
|
+
email: "",
|
|
237
|
+
password: "",
|
|
238
|
+
lastName: "",
|
|
239
|
+
};
|
|
240
|
+
next();
|
|
241
|
+
}
|
|
242
|
+
return [2 /*return*/];
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
exports.midAuthMiddleware = midAuthMiddleware;
|
|
247
|
+
function authTokenMiddleware(request, response, next) {
|
|
248
|
+
var _a, _b;
|
|
249
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
+
var authorization, secret, verificationResponse;
|
|
251
|
+
return __generator(this, function (_c) {
|
|
252
|
+
authorization = ((_a = request.headers) === null || _a === void 0 ? void 0 : _a.authorization) || ((_b = request === null || request === void 0 ? void 0 : request.session) === null || _b === void 0 ? void 0 : _b.jwt);
|
|
253
|
+
if (authorization) {
|
|
254
|
+
secret = process.env.JWT_KEY || "";
|
|
255
|
+
try {
|
|
256
|
+
verificationResponse = jwt.verify(authorization, secret);
|
|
257
|
+
if (typeof verificationResponse !== "object" ||
|
|
258
|
+
(verificationResponse.type !== "onboarding" && verificationResponse.type !== "recoverPassword")) {
|
|
259
|
+
console.error("🚨 AUTH TOKEN MIDDLEWARE ERROR:", {
|
|
260
|
+
error: "Invalid token type",
|
|
261
|
+
tokenType: verificationResponse.type,
|
|
262
|
+
timestamp: new Date().toISOString(),
|
|
263
|
+
});
|
|
264
|
+
return [2 /*return*/, next(new exceptions_1.InvalidTokenException("Error: invalid token type"))];
|
|
265
|
+
}
|
|
266
|
+
next();
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
console.error("🚨 AUTH TOKEN MIDDLEWARE ERROR:", {
|
|
270
|
+
error: error instanceof Error ? error.message : String(error),
|
|
271
|
+
timestamp: new Date().toISOString(),
|
|
272
|
+
});
|
|
273
|
+
next(new exceptions_1.HttpException(401, "Error veryfying token."));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
console.error("🚨 AUTH TOKEN MIDDLEWARE ERROR:", {
|
|
278
|
+
error: "No token provided",
|
|
279
|
+
timestamp: new Date().toISOString(),
|
|
280
|
+
});
|
|
281
|
+
next(new exceptions_1.MissingTokenException("Error: no token provided."));
|
|
282
|
+
}
|
|
283
|
+
return [2 /*return*/];
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
exports.authTokenMiddleware = authTokenMiddleware;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorMiddleware = void 0;
|
|
4
|
+
var errorMiddleware = function (error, request, response, next) {
|
|
5
|
+
var status = error.status || 500;
|
|
6
|
+
var message = error.message || 'Something went wrong';
|
|
7
|
+
response
|
|
8
|
+
.status(status)
|
|
9
|
+
.send({
|
|
10
|
+
status: status,
|
|
11
|
+
message: message,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
exports.errorMiddleware = errorMiddleware;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./auth.middleware"), exports);
|
|
14
|
+
__exportStar(require("./error.middleware"), exports);
|
|
15
|
+
__exportStar(require("./validation.middleware"), exports);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validationMiddleware = void 0;
|
|
4
|
+
var class_transformer_1 = require("class-transformer");
|
|
5
|
+
var class_validator_1 = require("class-validator");
|
|
6
|
+
var exceptions_1 = require("../exceptions");
|
|
7
|
+
var validationMiddleware = function (type, skipMissingProperties) {
|
|
8
|
+
if (skipMissingProperties === void 0) { skipMissingProperties = false; }
|
|
9
|
+
return function (req, res, next) {
|
|
10
|
+
class_validator_1.validate(class_transformer_1.plainToClass(type, req.body), { skipMissingProperties: skipMissingProperties })
|
|
11
|
+
.then(function (errors) {
|
|
12
|
+
if (errors.length > 0) {
|
|
13
|
+
var message = errors.map(function (error) { return Object.values(error.constraints); }).join(', ');
|
|
14
|
+
next(new exceptions_1.HttpException(400, message));
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
next();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.validationMiddleware = validationMiddleware;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluyappgocore/commons-backend",
|
|
3
|
+
"version": "1.0.202",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./build/index.js",
|
|
6
|
+
"types": "./build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"/build/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"clean": "del ./build/*",
|
|
13
|
+
"build": "npm run clean && tsc",
|
|
14
|
+
"pub": "npm version patch && npm run build && npm publish"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/amqplib": "^0.10.8",
|
|
20
|
+
"@types/express": "^4.17.13",
|
|
21
|
+
"@types/express-session": "^1.17.0",
|
|
22
|
+
"@types/jsonwebtoken": "^8.5.6",
|
|
23
|
+
"@types/redis": "^2.8.28",
|
|
24
|
+
"@types/validator": "^13.7.1",
|
|
25
|
+
"del-cli": "^3.0.1",
|
|
26
|
+
"typescript": "^4.1.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@fluyappgo/commons": "^2.1.148",
|
|
30
|
+
"amqplib": "^0.10.9",
|
|
31
|
+
"class-transformer": "^0.5.1",
|
|
32
|
+
"class-validator": "^0.14.2",
|
|
33
|
+
"cookie-parser": "^1.4.6",
|
|
34
|
+
"cookie-session": "^2.0.0",
|
|
35
|
+
"express": "^4.17.2",
|
|
36
|
+
"express-rate-limit": "^7.5.0",
|
|
37
|
+
"express-session": "^1.17.2",
|
|
38
|
+
"jsonwebtoken": "^9.0.2",
|
|
39
|
+
"kafkajs": "^1.15.0",
|
|
40
|
+
"moment-timezone": "^0.5.33",
|
|
41
|
+
"pino": "^9.6.0",
|
|
42
|
+
"pino-pretty": "^13.0.0",
|
|
43
|
+
"redis": "^3.1.2"
|
|
44
|
+
}
|
|
45
|
+
}
|