emilsoftware-utilities 1.3.48 → 1.3.49
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/dist/DatabaseUpdater.js +75 -141
- package/dist/ExecutionTimeLogger.js +24 -68
- package/dist/Logger.js +67 -158
- package/dist/Orm.js +173 -266
- package/dist/RoutesLoggerMiddleware.js +10 -12
- package/dist/Utilities.js +93 -113
- package/dist/accessi-module/AccessiController.d.ts +23 -371
- package/dist/accessi-module/AccessiController.js +178 -664
- package/dist/accessi-module/AccessiControllerBase.d.ts +378 -0
- package/dist/accessi-module/AccessiControllerBase.js +11 -0
- package/dist/accessi-module/AccessiModule.d.ts +18 -24
- package/dist/accessi-module/AccessiModule.js +39 -118
- package/dist/accessi-module/AccessiRoutes.js +44 -80
- package/dist/accessi-module/Services/AuthService/AuthService.d.ts +19 -0
- package/dist/accessi-module/Services/AuthService/AuthService.js +144 -0
- package/dist/accessi-module/Services/AuthService/IAuthService.d.ts +62 -0
- package/dist/accessi-module/Services/EmailService/EmailService.d.ts +17 -0
- package/dist/accessi-module/Services/EmailService/EmailService.js +78 -0
- package/dist/accessi-module/Services/EmailService/IEmailService.d.ts +31 -0
- package/dist/accessi-module/Services/PermissionService/IPermissionService.d.ts +58 -0
- package/dist/accessi-module/Services/PermissionService/IPermissionService.js +9 -0
- package/dist/accessi-module/Services/PermissionService/PermissionService.d.ts +17 -0
- package/dist/accessi-module/Services/PermissionService/PermissionService.js +147 -0
- package/dist/accessi-module/Services/UserService/IUserService.d.ts +110 -0
- package/dist/accessi-module/Services/UserService/UserService.d.ts +27 -0
- package/dist/accessi-module/Services/UserService/UserService.js +227 -0
- package/dist/accessi-module/index.d.ts +0 -3
- package/dist/accessi-module/inversify.config.d.ts +3 -0
- package/dist/accessi-module/inversify.config.js +35 -0
- package/dist/accessi-module/swagger/SwaggerConfig.d.ts +2 -1
- package/dist/accessi-module/swagger/SwaggerConfig.js +7 -7
- package/dist/autobind.js +7 -29
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/package.json +8 -1
- package/dist/accessi-module/AccessiModel.d.ts +0 -126
- package/dist/accessi-module/AccessiModel.js +0 -625
- package/dist/accessi-module/models/DTO/LoginRequest.d.ts +0 -4
- package/dist/accessi-module/models/DTO/LoginResponse.d.ts +0 -11
- package/dist/accessi-module/models/DTO/RegisterRequest.d.ts +0 -14
- package/dist/accessi-module/models/JwtOptions.d.ts +0 -4
- package/dist/accessi-module/models/JwtOptions.js +0 -9
- /package/dist/accessi-module/{models/DTO/LoginRequest.js → Services/AuthService/IAuthService.js} +0 -0
- /package/dist/accessi-module/{models/DTO/LoginResponse.js → Services/EmailService/IEmailService.js} +0 -0
- /package/dist/accessi-module/{models/DTO/RegisterRequest.js → Services/UserService/IUserService.js} +0 -0
package/dist/DatabaseUpdater.js
CHANGED
|
@@ -8,40 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.DatabaseUpdater = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function DatabaseUpdater() {
|
|
44
|
-
}
|
|
13
|
+
const Orm_1 = require("./Orm");
|
|
14
|
+
const Logger_1 = require("./Logger");
|
|
15
|
+
class DatabaseUpdater {
|
|
45
16
|
//#endregion
|
|
46
17
|
//#region Utility Methods
|
|
47
18
|
/**
|
|
@@ -51,133 +22,96 @@ var DatabaseUpdater = /** @class */ (function () {
|
|
|
51
22
|
* @param column Column name.
|
|
52
23
|
* @returns True if the column exists, false otherwise.
|
|
53
24
|
*/
|
|
54
|
-
|
|
55
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
throw error_1;
|
|
73
|
-
case 3: return [2 /*return*/];
|
|
74
|
-
}
|
|
75
|
-
});
|
|
25
|
+
static columnExists(options, table, column) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
try {
|
|
28
|
+
const query = `
|
|
29
|
+
SELECT 1
|
|
30
|
+
FROM RDB$RELATION_FIELDS
|
|
31
|
+
WHERE RDB$RELATION_NAME = ?
|
|
32
|
+
AND RDB$FIELD_NAME = ?`;
|
|
33
|
+
const result = yield Orm_1.Orm.query(options, query, [
|
|
34
|
+
table.toUpperCase(),
|
|
35
|
+
column.toUpperCase(),
|
|
36
|
+
]);
|
|
37
|
+
return result.length > 0;
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
this.logger.error(`Error checking column ${column} on table ${table}:`, error);
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
76
43
|
});
|
|
77
|
-
}
|
|
44
|
+
}
|
|
78
45
|
/**
|
|
79
46
|
* Retrieves the current database version from the PARAMETRI table.
|
|
80
47
|
* @param options Database connection options.
|
|
81
48
|
* @returns The current database version or null if not found.
|
|
82
49
|
*/
|
|
83
|
-
|
|
84
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return [2 /*return*/, parameters.length > 0 ? parameters[0].DESPAR : null];
|
|
94
|
-
case 2:
|
|
95
|
-
error_2 = _a.sent();
|
|
96
|
-
this.logger.error("Error getting database version:", error_2);
|
|
97
|
-
throw error_2;
|
|
98
|
-
case 3: return [2 /*return*/];
|
|
99
|
-
}
|
|
100
|
-
});
|
|
50
|
+
static getDatabaseVersion(options) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
try {
|
|
53
|
+
const parameters = (yield Orm_1.Orm.query(options, "SELECT CODPAR, DESPAR FROM PARAMETRI WHERE CODPAR = ?", ["VersioneDB"]));
|
|
54
|
+
return parameters.length > 0 ? parameters[0].DESPAR : null;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
this.logger.error(`Error getting database version:`, error);
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
101
60
|
});
|
|
102
|
-
}
|
|
61
|
+
}
|
|
103
62
|
/**
|
|
104
63
|
* Updates the database version in the PARAMETRI table.
|
|
105
64
|
* @param options Database connection options.
|
|
106
65
|
* @param version The new database version.
|
|
107
66
|
*/
|
|
108
|
-
|
|
109
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
_a.sent();
|
|
121
|
-
return [3 /*break*/, 3];
|
|
122
|
-
case 2:
|
|
123
|
-
error_3 = _a.sent();
|
|
124
|
-
this.logger.error("Error setting database version:", error_3);
|
|
125
|
-
throw error_3;
|
|
126
|
-
case 3: return [2 /*return*/];
|
|
127
|
-
}
|
|
128
|
-
});
|
|
67
|
+
static setDatabaseVersion(options, version) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
try {
|
|
70
|
+
yield Orm_1.Orm.query(options, "UPDATE PARAMETRI SET DESPAR = ? WHERE CODPAR = ?", [
|
|
71
|
+
version,
|
|
72
|
+
"VersioneDB",
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
this.logger.error(`Error setting database version:`, error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
129
79
|
});
|
|
130
|
-
}
|
|
80
|
+
}
|
|
131
81
|
//#endregion
|
|
132
82
|
//#region Initialization Methods
|
|
133
83
|
/**
|
|
134
84
|
* Ensures the PARAMETRI table exists and initializes it if necessary.
|
|
135
85
|
* @param options Database connection options.
|
|
136
86
|
*/
|
|
137
|
-
|
|
138
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
case 6:
|
|
164
|
-
versioneDb = _a.sent();
|
|
165
|
-
if (versioneDb !== null && versioneDb !== undefined)
|
|
166
|
-
return [2 /*return*/];
|
|
167
|
-
return [4 /*yield*/, Orm_1.Orm.query(options, "INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?,?,?,?)", ["VersioneDB", "0.0a", "versione", null])];
|
|
168
|
-
case 7:
|
|
169
|
-
_a.sent();
|
|
170
|
-
return [3 /*break*/, 9];
|
|
171
|
-
case 8:
|
|
172
|
-
error_4 = _a.sent();
|
|
173
|
-
this.logger.error("Error creating table PARAMETRI:", error_4);
|
|
174
|
-
throw error_4;
|
|
175
|
-
case 9: return [2 /*return*/];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
87
|
+
static createParametersTable(options) {
|
|
88
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
+
try {
|
|
90
|
+
const columnAlreadyExists = yield this.columnExists(options, "PARAMETRI", "CODPAR");
|
|
91
|
+
if (columnAlreadyExists)
|
|
92
|
+
return;
|
|
93
|
+
const createTableQuery = `
|
|
94
|
+
CREATE TABLE PARAMETRI (
|
|
95
|
+
CODPAR VARCHAR(15) NOT NULL,
|
|
96
|
+
DESPAR VARCHAR(255),
|
|
97
|
+
NOTE BLOB SUB_TYPE 1 SEGMENT SIZE 80,
|
|
98
|
+
GRUPPO VARCHAR(20)
|
|
99
|
+
);`;
|
|
100
|
+
yield Orm_1.Orm.query(options, createTableQuery);
|
|
101
|
+
yield Orm_1.Orm.query(options, "ALTER TABLE PARAMETRI ADD CONSTRAINT PK_PARAMETRI PRIMARY KEY (CODPAR);");
|
|
102
|
+
yield Orm_1.Orm.query(options, "GRANT ALL ON PARAMETRI TO PUBLIC;");
|
|
103
|
+
yield Orm_1.Orm.query(options, "GRANT SELECT ON PARAMETRI TO TABX;");
|
|
104
|
+
const versioneDb = yield this.getDatabaseVersion(options);
|
|
105
|
+
if (versioneDb !== null && versioneDb !== undefined)
|
|
106
|
+
return;
|
|
107
|
+
yield Orm_1.Orm.query(options, "INSERT INTO PARAMETRI (CODPAR, DESPAR, NOTE, GRUPPO) VALUES (?,?,?,?)", ["VersioneDB", "0.0a", "versione", null]);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.logger.error("Error creating table PARAMETRI:", error);
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
178
113
|
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return DatabaseUpdater;
|
|
182
|
-
}());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
183
116
|
exports.DatabaseUpdater = DatabaseUpdater;
|
|
117
|
+
DatabaseUpdater.logger = new Logger_1.Logger(DatabaseUpdater.name);
|
|
@@ -8,39 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
12
|
exports.ExecutionTimeLogger = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function ExecutionTimeLogger() {
|
|
43
|
-
}
|
|
13
|
+
const _1 = require("./");
|
|
14
|
+
class ExecutionTimeLogger {
|
|
44
15
|
/**
|
|
45
16
|
* Wraps a method to log its execution time and errors.
|
|
46
17
|
* @param target The target object.
|
|
@@ -48,46 +19,31 @@ var ExecutionTimeLogger = /** @class */ (function () {
|
|
|
48
19
|
* @param descriptor The property descriptor of the method.
|
|
49
20
|
* @description use ExecutionTimeLogger.apply on any method
|
|
50
21
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
22
|
+
static apply(target, propertyKey, descriptor) {
|
|
23
|
+
const originalMethod = descriptor.value;
|
|
53
24
|
if (typeof originalMethod !== "function") {
|
|
54
|
-
throw new TypeError(
|
|
25
|
+
throw new TypeError(`ExecutionTimeLogger can only be applied to methods, not: ${typeof originalMethod}`);
|
|
55
26
|
}
|
|
56
|
-
descriptor.value = function () {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return [4 /*yield*/, originalMethod.apply(this, args)];
|
|
74
|
-
case 2:
|
|
75
|
-
result = _a.sent();
|
|
76
|
-
end = process.hrtime(start);
|
|
77
|
-
durationInMilliseconds = end[0] * 1000 + end[1] / 1e6;
|
|
78
|
-
logger.info("[".concat(className, "] ").concat(propertyKey, " method took ").concat(durationInMilliseconds.toFixed(2), " ms to execute"));
|
|
79
|
-
return [2 /*return*/, result];
|
|
80
|
-
case 3:
|
|
81
|
-
error_1 = _a.sent();
|
|
82
|
-
logger.error("[".concat(className, "] ").concat(propertyKey, " method threw an error: ").concat(error_1.message));
|
|
83
|
-
throw error_1;
|
|
84
|
-
case 4: return [2 /*return*/];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
27
|
+
descriptor.value = function (...args) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const className = target.constructor.name; // Get the class name dynamically
|
|
30
|
+
const logger = new _1.Logger(className); // Use the class name for logger
|
|
31
|
+
const start = process.hrtime();
|
|
32
|
+
logger.info(`[${className}] ${propertyKey} method execution started . . .`);
|
|
33
|
+
try {
|
|
34
|
+
const result = yield originalMethod.apply(this, args);
|
|
35
|
+
const end = process.hrtime(start);
|
|
36
|
+
const durationInMilliseconds = end[0] * 1000 + end[1] / 1e6;
|
|
37
|
+
logger.info(`[${className}] ${propertyKey} method took ${durationInMilliseconds.toFixed(2)} ms to execute`);
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
logger.error(`[${className}] ${propertyKey} method threw an error: ${error.message}`);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
87
44
|
});
|
|
88
45
|
};
|
|
89
46
|
return descriptor;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
93
49
|
exports.ExecutionTimeLogger = ExecutionTimeLogger;
|