opticore-webapp 1.0.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.
Files changed (44) hide show
  1. package/dist/index.cjs +1080 -0
  2. package/dist/index.d.cts +408 -0
  3. package/dist/index.d.ts +408 -0
  4. package/dist/index.js +1038 -0
  5. package/package.json +46 -0
  6. package/src/application/exceptions/messages.exception.ts +67 -0
  7. package/src/application/http/response.http.ts +67 -0
  8. package/src/application/service/core.service.ts +180 -0
  9. package/src/core/config/.gitkeep +0 -0
  10. package/src/core/errors/.gitkeep +0 -0
  11. package/src/core/events/errors/serverListen.event.error.ts +421 -0
  12. package/src/core/events/requestCalls.event.ts +86 -0
  13. package/src/core/handlers/errors/base/stackTraceError.ts +23 -0
  14. package/src/core/handlers/errors/stackTraceAssertionError.ts +13 -0
  15. package/src/core/handlers/errors/stackTraceEvalError.ts +12 -0
  16. package/src/core/handlers/errors/stackTraceGeneralError.ts +13 -0
  17. package/src/core/handlers/errors/stackTraceOpenSSLError.ts +12 -0
  18. package/src/core/handlers/errors/stackTraceRangeError.ts +12 -0
  19. package/src/core/handlers/errors/stackTraceReferenceError.ts +13 -0
  20. package/src/core/handlers/errors/stackTraceSyntaxError.ts +12 -0
  21. package/src/core/handlers/errors/stackTraceSystemError.ts +14 -0
  22. package/src/core/handlers/errors/stackTraceTypeError.ts +13 -0
  23. package/src/core/handlers/errors/stackTraceURIError.ts +13 -0
  24. package/src/core/handlers/eventProcess.handler.ts +106 -0
  25. package/src/core/utils/dateTimeFormatted.utils.ts +6 -0
  26. package/src/core/utils/logMessage.utils.ts +20 -0
  27. package/src/core/utils/modulesLoaded.utils.ts +16 -0
  28. package/src/core/webServer.core.ts +110 -0
  29. package/src/domains/constants/errorName.constant.ts +12 -0
  30. package/src/domains/constants/event.constant.ts +15 -0
  31. package/src/domains/constants/eventNameError.constant.ts +8 -0
  32. package/src/domains/constants/httpStatusCodes.constant.ts +375 -0
  33. package/src/domains/constants/logLevel.constant.ts +6 -0
  34. package/src/domains/env/access.env.ts +23 -0
  35. package/src/domains/interfaces/envVariables.interface.ts +16 -0
  36. package/src/domains/interfaces/kernelModule.interface.ts +6 -0
  37. package/src/domains/interfaces/routeDefinition.interface.ts +6 -0
  38. package/src/domains/types/kernelModule.type.ts +3 -0
  39. package/src/index.ts +20 -0
  40. package/src/infrastructure/events/.gitkeep +0 -0
  41. package/src/infrastructure/handlers/.gitkeep +0 -0
  42. package/src/presentation/middleware/.gitkeep +0 -0
  43. package/tsconfig.json +26 -0
  44. package/tsup.config.ts +11 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,1080 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ HttpStatusCode: () => HttpStatusCodesConstant,
34
+ WebServer: () => WebServerCore,
35
+ errorName: () => CErrorName,
36
+ event: () => CEvent,
37
+ eventName: () => CEventNameError,
38
+ getEnvVariable: () => getEnvVariable
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/core/webServer.core.ts
43
+ var import_express2 = __toESM(require("express"), 1);
44
+ var import_cors = __toESM(require("cors"), 1);
45
+
46
+ // src/domains/env/access.env.ts
47
+ var import_dotenv = __toESM(require("dotenv"), 1);
48
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
49
+ var getEnvVariable = {
50
+ appHost: String((_b = (_a = import_dotenv.default.config()) == null ? void 0 : _a.parsed) == null ? void 0 : _b.APP_HOST),
51
+ appPort: String((_d = (_c = import_dotenv.default.config()) == null ? void 0 : _c.parsed) == null ? void 0 : _d.APP_PORT),
52
+ prodEnv: String((_f = (_e = import_dotenv.default.config()) == null ? void 0 : _e.parsed) == null ? void 0 : _f.ENV_PROD),
53
+ devEnv: String((_h = (_g = import_dotenv.default.config()) == null ? void 0 : _g.parsed) == null ? void 0 : _h.ENV_DEV),
54
+ dataBaseHost: String((_j = (_i = import_dotenv.default.config()) == null ? void 0 : _i.parsed) == null ? void 0 : _j.DATA_BASE_HOST),
55
+ dataBasePort: String((_l = (_k = import_dotenv.default.config()) == null ? void 0 : _k.parsed) == null ? void 0 : _l.DATA_BASE_PORT),
56
+ dataBaseUser: String((_n = (_m = import_dotenv.default.config()) == null ? void 0 : _m.parsed) == null ? void 0 : _n.DATA_BASE_USER),
57
+ dataBasePassword: String((_p = (_o = import_dotenv.default.config()) == null ? void 0 : _o.parsed) == null ? void 0 : _p.DATA_BASE_PASSWORD),
58
+ dataBaseName: String((_r = (_q = import_dotenv.default.config()) == null ? void 0 : _q.parsed) == null ? void 0 : _r.DATA_BASE_NAME),
59
+ apiVersion: String((_t = (_s = import_dotenv.default.config()) == null ? void 0 : _s.parsed) == null ? void 0 : _t.API_VERSION),
60
+ usernameField: String((_v = (_u = import_dotenv.default.config()) == null ? void 0 : _u.parsed) == null ? void 0 : _v.USERNAME_FIELD),
61
+ passwordField: String((_x = (_w = import_dotenv.default.config()) == null ? void 0 : _w.parsed) == null ? void 0 : _x.PASSWORD_FIELD),
62
+ argumentsDatabaseConnection: String((_z = (_y = import_dotenv.default.config()) == null ? void 0 : _y.parsed) == null ? void 0 : _z.ARGUMENTS_DATABASE_CONNECTION),
63
+ logEnv: String((_B = (_A = import_dotenv.default.config()) == null ? void 0 : _A.parsed) == null ? void 0 : _B.LOG_ENVIRONMENT)
64
+ };
65
+
66
+ // src/domains/constants/httpStatusCodes.constant.ts
67
+ var HttpStatusCodesConstant = /* @__PURE__ */ ((HttpStatusCodesConstant2) => {
68
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["CONTINUE"] = 100] = "CONTINUE";
69
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
70
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PROCESSING"] = 102] = "PROCESSING";
71
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["OK"] = 200] = "OK";
72
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["CREATED"] = 201] = "CREATED";
73
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["ACCEPTED"] = 202] = "ACCEPTED";
74
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
75
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NO_CONTENT"] = 204] = "NO_CONTENT";
76
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
77
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
78
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
79
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
80
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["IM_USED"] = 226] = "IM_USED";
81
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
82
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
83
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["FOUND"] = 302] = "FOUND";
84
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["SEE_OTHER"] = 303] = "SEE_OTHER";
85
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
86
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["USE_PROXY"] = 305] = "USE_PROXY";
87
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["SWITCH_PROXY"] = 306] = "SWITCH_PROXY";
88
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
89
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
90
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
91
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
92
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
93
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["FORBIDDEN"] = 403] = "FORBIDDEN";
94
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_FOUND"] = 404] = "NOT_FOUND";
95
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
96
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
97
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
98
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
99
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["CONFLICT"] = 409] = "CONFLICT";
100
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["GONE"] = 410] = "GONE";
101
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
102
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
103
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
104
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
105
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
106
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
107
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
108
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
109
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
110
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
111
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["LOCKED"] = 423] = "LOCKED";
112
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
113
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
114
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
115
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
116
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
117
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
118
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
119
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
120
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
121
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
122
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
123
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
124
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
125
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
126
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
127
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
128
+ HttpStatusCodesConstant2[HttpStatusCodesConstant2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
129
+ return HttpStatusCodesConstant2;
130
+ })(HttpStatusCodesConstant || {});
131
+
132
+ // src/core/handlers/errors/base/stackTraceError.ts
133
+ var StackTraceError = class extends Error {
134
+ // Centralized error objet that derives from Node's Error.
135
+ constructor(props, name, httpCode, isOperational) {
136
+ super(props);
137
+ Object.setPrototypeOf(this, new.target.prototype);
138
+ this.name = name;
139
+ this.httpCode = httpCode;
140
+ this.isOperational = isOperational;
141
+ Error.captureStackTrace(this);
142
+ }
143
+ };
144
+
145
+ // src/core/handlers/eventProcess.handler.ts
146
+ var import_express = __toESM(require("express"), 1);
147
+ var import_node_process = __toESM(require("process"), 1);
148
+ var import_node_events = __toESM(require("events"), 1);
149
+ var import_serverListen_event = require("@/errors/serverListen.event.error");
150
+ function eventProcessHandler() {
151
+ const errorEmitter = new import_node_events.default();
152
+ const app = (0, import_express.default)();
153
+ errorEmitter.on(CEventNameError.error, (error) => {
154
+ import_serverListen_event.ServerListenEventError.listenerError(error);
155
+ });
156
+ import_node_process.default.on(CEvent.beforeExit, (code) => {
157
+ setTimeout(() => {
158
+ import_serverListen_event.ServerListenEventError.processBeforeExit(code);
159
+ }, 100);
160
+ });
161
+ import_node_process.default.on(CEvent.disconnect, () => {
162
+ import_serverListen_event.ServerListenEventError.processDisconnected();
163
+ });
164
+ import_node_process.default.on(CEvent.exit, (code) => {
165
+ import_serverListen_event.ServerListenEventError.exited(code);
166
+ });
167
+ import_node_process.default.on(CEvent.rejectionHandled, (promise) => {
168
+ import_serverListen_event.ServerListenEventError.promiseRejectionHandled(promise);
169
+ });
170
+ import_node_process.default.on(CEvent.uncaughtException, (error) => {
171
+ import_serverListen_event.ServerListenEventError.uncaughtException(error);
172
+ });
173
+ import_node_process.default.on(CEvent.uncaughtExceptionMonitor, (error) => {
174
+ import_serverListen_event.ServerListenEventError.uncaughtExceptionMonitor(error);
175
+ });
176
+ import_node_process.default.on(CEvent.unhandledRejection, (reason, promise) => {
177
+ import_serverListen_event.ServerListenEventError.unhandledRejection(reason, promise);
178
+ });
179
+ import_node_process.default.on(CEvent.warning, (warning) => {
180
+ import_serverListen_event.ServerListenEventError.warning(warning);
181
+ });
182
+ import_node_process.default.on(CEvent.message, (message) => {
183
+ import_serverListen_event.ServerListenEventError.message(message);
184
+ });
185
+ import_node_process.default.on(CEvent.multipleResolves, (type, promise, reason) => {
186
+ import_serverListen_event.ServerListenEventError.multipleResolves(type, promise, reason);
187
+ });
188
+ import_node_process.default.on(CEvent.sigint, () => {
189
+ import_serverListen_event.ServerListenEventError.processInterrupted();
190
+ });
191
+ import_node_process.default.on(CEvent.sigterm, (signal) => {
192
+ import_serverListen_event.ServerListenEventError.sigtermSignalReceived(signal);
193
+ });
194
+ app.use((err, req, res, next) => {
195
+ import_serverListen_event.ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
196
+ });
197
+ }
198
+
199
+ // src/core/events/requestCalls.event.ts
200
+ var import_ansi_colors = __toESM(require("ansi-colors"), 1);
201
+ var import_opticore_logger = require("opticore-logger");
202
+ function requestCallsEvent(req, res, host, port, loadingTime) {
203
+ const logger = new import_opticore_logger.LoggerCore();
204
+ const currentDatePath = `Request called`;
205
+ if (req.originalUrl === "undefined") {
206
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.white(` 404 `)}`)}`);
207
+ logger.error("The route do not exist.");
208
+ } else {
209
+ switch (res.statusCode) {
210
+ case 200:
211
+ switch (req.method) {
212
+ case "POST":
213
+ console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
214
+ logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
215
+ break;
216
+ case "GET":
217
+ case "PUT":
218
+ console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
219
+ logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
220
+ break;
221
+ case "DELETE":
222
+ console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
223
+ logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
224
+ break;
225
+ }
226
+ break;
227
+ case 404:
228
+ switch (req.method) {
229
+ case "POST":
230
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.white(` 404 `)}`)}`);
231
+ break;
232
+ case "GET":
233
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
234
+ break;
235
+ case "PUT":
236
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
237
+ break;
238
+ case "DELETE":
239
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
240
+ break;
241
+ }
242
+ break;
243
+ case 401:
244
+ switch (req.method) {
245
+ case "POST":
246
+ console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
247
+ break;
248
+ case "GET":
249
+ console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
250
+ break;
251
+ case "PUT":
252
+ console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
253
+ break;
254
+ case "DELETE":
255
+ console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
256
+ break;
257
+ }
258
+ break;
259
+ case 500:
260
+ switch (req.method) {
261
+ case "POST":
262
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
263
+ break;
264
+ case "GET":
265
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
266
+ break;
267
+ case "PUT":
268
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
269
+ break;
270
+ case "DELETE":
271
+ console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
272
+ break;
273
+ }
274
+ break;
275
+ default:
276
+ console.log(`[ ${import_ansi_colors.default.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
277
+ break;
278
+ }
279
+ }
280
+ }
281
+
282
+ // src/domains/constants/eventNameError.constant.ts
283
+ var CEventNameError = {
284
+ error: "error",
285
+ listening: "listening",
286
+ close: "close",
287
+ connection: "connection",
288
+ drop: "drop",
289
+ request: "request"
290
+ };
291
+
292
+ // src/core/events/errors/serverListen.event.error.ts
293
+ var import_process = __toESM(require("process"), 1);
294
+ var import_ansi_colors4 = __toESM(require("ansi-colors"), 1);
295
+ var import_chalk = __toESM(require("chalk"), 1);
296
+
297
+ // src/core/utils/logMessage.utils.ts
298
+ var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
299
+
300
+ // src/core/utils/dateTimeFormatted.utils.ts
301
+ var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
302
+
303
+ // src/core/utils/logMessage.utils.ts
304
+ var LogMessageUtils = class {
305
+ static success(title, action, contentAction) {
306
+ console.log(`${import_ansi_colors2.default.green(`\u2714`)} ${import_ansi_colors2.default.bgGreen(` ${import_ansi_colors2.default.bold(`${import_ansi_colors2.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors2.default.bgGreen(`${import_ansi_colors2.default.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${import_ansi_colors2.default.bgGreen(`${import_ansi_colors2.default.white(` 200 `)}`)}`);
307
+ }
308
+ static warning(title, action, contentAction) {
309
+ console.warn(`${import_ansi_colors2.default.yellow(`\u26A0\uFE0F`)} ${import_ansi_colors2.default.bgYellow(` ${import_ansi_colors2.default.bold(`${import_ansi_colors2.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors2.default.bgYellow(`${import_ansi_colors2.default.white(` Warning `)}`)} ${contentAction}`);
310
+ }
311
+ static info(title, action, contentAction) {
312
+ console.info(`${import_ansi_colors2.default.cyan(`\u24D8`)} ${import_ansi_colors2.default.bgCyan(` ${import_ansi_colors2.default.bold(`${import_ansi_colors2.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors2.default.bgCyan(`${import_ansi_colors2.default.white(` Info `)}`)} ${contentAction}`);
313
+ }
314
+ static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
315
+ console.error(`${import_ansi_colors2.default.red(`\u2718`)} ${import_ansi_colors2.default.bgRed(` ${import_ansi_colors2.default.bold(`${import_ansi_colors2.default.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${import_ansi_colors2.default.red(`${import_ansi_colors2.default.bold(` ${errorType} `)}`)} ] | [ ${import_ansi_colors2.default.bold(`stack trace`)} ] ${import_ansi_colors2.default.red(`${stackTrace}`)} - ${import_ansi_colors2.default.red(`${messageContent}`)} - [ ${import_ansi_colors2.default.red(`${import_ansi_colors2.default.bold(` HttpCode `)}`)} ] ${import_ansi_colors2.default.red(`${import_ansi_colors2.default.bold(` ${httpCodeValue} `)}`)} `);
316
+ }
317
+ static requestError(title, errorName, errorMessage, errorCode) {
318
+ console.error(`[ ${import_ansi_colors2.default.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${import_ansi_colors2.default.bgRed(`${import_ansi_colors2.default.white(` ERROR `)}`)} ${import_ansi_colors2.default.red(`[ ${errorName} ]`)} ${import_ansi_colors2.default.red(`${errorMessage}`)} - [ Status ] ${import_ansi_colors2.default.bgRed(`${import_ansi_colors2.default.white(` ${errorCode} `)}`)}`);
319
+ }
320
+ };
321
+
322
+ // src/application/exceptions/messages.exception.ts
323
+ var import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
324
+ var messageException = {
325
+ dbConnection: "DataBase connection",
326
+ dbConnectionClosed: "MySQL connection is closed",
327
+ mysqlErrorCon: "MysqlError connection",
328
+ mySQLError: "MysqlError",
329
+ mySqlCloseConnection: "MySql close connection",
330
+ verifyExistingKey: "Verify Existing Key",
331
+ invalidRequest: "Invalid request",
332
+ tokenNotProvided: "No token provided.",
333
+ ExpiresToken: "Expires Token. You're not authorize",
334
+ privateKeyNotExist: "A private key doesn't exist.",
335
+ publicKeyNotExist: "A public key doesn't exist.",
336
+ errorNamePublicKeyNotExist: "No public key",
337
+ errorAuthorPublicKeyNotExist: "PublicKey not existing",
338
+ errorDecryption: "Error decryption with private key",
339
+ rsaKeyNotFound: "RSA key provided is not found.",
340
+ notVerifyingRSAKey: "Not verify RSA Key",
341
+ errorNameNotVerifyingRSAKey: "Error Verify RSA Key",
342
+ errorEncryptionPublicKey: "Error encryption with public key",
343
+ errorEncryptionPrivateKey: "Error encryption with private key",
344
+ errorNameRsaVerifyExistingKey: "Verify existing key",
345
+ signatureRSAKeyFailed: "Signature verification failed.",
346
+ encryptionWithPrivateKeyFailed: "Encryption With PrivateKey",
347
+ encryptionFailed: "Encryption failed",
348
+ decryptionWithPublicKeyFailed: "Decryption With PublicKey",
349
+ decryptionFailed: "Decryption failed",
350
+ verifyRSAKey: "Verify RSA Keys",
351
+ verifyRSAKeyFailed: "Verify RSA Keys Failed",
352
+ notVerifying: "Verification failed",
353
+ signatureRSAKeysError: "Signature RSA Keys Error",
354
+ encryptionWithPublicKey: "Encryption error",
355
+ errorDecryptionWithPrivateKey: "Error Decryption With PrivateKey",
356
+ verifyPublicRSAKey: "Verify Public RSA Key",
357
+ PostgresDBConnectionChecker: "PostgresDB Connection Checker",
358
+ PostgresConnection: "connection",
359
+ MongoDBConnectionChecker: "MongoDB Connection Checker",
360
+ MongoConnection: "connection",
361
+ mongoDBAuthentication: "authentication",
362
+ mongoDBConnection: "MongoDB connection",
363
+ mongoDBAuthenticationFailed: "failed",
364
+ mongoDBUnableParsingUrl: "unable to parse",
365
+ mongoDBConnectionUrl: "url",
366
+ mongoDBServerSelection: "MongoServer selection error",
367
+ mongoDBServer: "MongoServer",
368
+ mongoDBConnectionError: "connection error",
369
+ mongoDBError: "error",
370
+ loadedModules: "Loading core modules",
371
+ loadedModulesError: "Required core modules are not loaded properly",
372
+ dbConnexionSuccess: "The database connection was successful \u{1F680}",
373
+ mongoConnectionSuccess: "Connection to database is successfully.",
374
+ PostgresConnectionSuccess: "Connection to database is successfully.",
375
+ verifyExistingKeyError: "The provided key is not found",
376
+ webServer: "Web server",
377
+ listening: "listening",
378
+ webHost: "host",
379
+ badHost: "bad host",
380
+ hostNotFound: "not found",
381
+ errorHostUrl: "The host and port are not define, please define them in .env",
382
+ badPort: "bad port",
383
+ errorPort: "The port is not correct. Please define a right port with number port.",
384
+ errorHost: "The host can't be empty or blank. Please define a string host in .env",
385
+ accessDeniedToDBCon: (user, password) => `Access denied for user ${user}. Database credentials in .env file are User: ${user} and Password: ${password}. '${user}''${password}'@'localhost'. Try to set user and password in .env file`,
386
+ unknownDB: (database) => `Database ${database} is unknown. Please try to use Database CLI to create your database, or do it manually in your Database Management System`,
387
+ errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${import_ansi_colors3.default.bgRed(`${import_ansi_colors3.default.white(`localhost`)}`)} in your .env file`
388
+ };
389
+
390
+ // src/core/events/errors/serverListen.event.error.ts
391
+ var ServerListenEventError2 = class {
392
+ static hostPortUndefined() {
393
+ const stackTrace = this.traceError(messageException.errorHostUrl, messageException.listening, 400 /* BAD_REQUEST */);
394
+ LogMessageUtils.error(
395
+ messageException.webServer,
396
+ messageException.badHost,
397
+ stackTrace.stack,
398
+ messageException.errorHostUrl,
399
+ 400 /* BAD_REQUEST */
400
+ );
401
+ import_process.default.exit();
402
+ }
403
+ static hostUndefined() {
404
+ const stackTrace = this.traceError(messageException.badHost, messageException.listening, 400 /* BAD_REQUEST */);
405
+ LogMessageUtils.error(
406
+ messageException.webServer,
407
+ messageException.badHost,
408
+ stackTrace.stack,
409
+ messageException.errorHost,
410
+ 400 /* BAD_REQUEST */
411
+ );
412
+ import_process.default.exit();
413
+ }
414
+ static portUndefined() {
415
+ const stackTrace = this.traceError(messageException.badPort, messageException.listening, 400 /* BAD_REQUEST */);
416
+ LogMessageUtils.error(
417
+ messageException.webServer,
418
+ messageException.badPort,
419
+ stackTrace.stack,
420
+ messageException.errorPort,
421
+ 400 /* BAD_REQUEST */
422
+ );
423
+ import_process.default.exit();
424
+ }
425
+ static onEventError(err) {
426
+ LogMessageUtils.error(
427
+ "Server start error",
428
+ "Error",
429
+ err.stack,
430
+ err.message,
431
+ 503 /* SERVICE_UNAVAILABLE */
432
+ );
433
+ }
434
+ static listenerError(error) {
435
+ const stackTrace = this.traceError(
436
+ error.message,
437
+ error.name,
438
+ 400 /* BAD_REQUEST */
439
+ );
440
+ LogMessageUtils.error(
441
+ "Event error",
442
+ "Error",
443
+ error.stack,
444
+ stackTrace.message,
445
+ 503 /* SERVICE_UNAVAILABLE */
446
+ );
447
+ }
448
+ static processBeforeExit(code) {
449
+ const stackTrace = this.traceError(
450
+ `Process will exit with code: ${code}`,
451
+ "BeforeExit",
452
+ 503 /* SERVICE_UNAVAILABLE */
453
+ );
454
+ LogMessageUtils.error(
455
+ "BeforeExit",
456
+ "process before exit",
457
+ stackTrace.stack,
458
+ `Process will exit with code: ${code}`,
459
+ 503 /* SERVICE_UNAVAILABLE */
460
+ );
461
+ import_process.default.exit(code);
462
+ }
463
+ static processDisconnected() {
464
+ const stackTrace = this.traceError(
465
+ "Child process disconnected",
466
+ "process disconnected",
467
+ 503 /* SERVICE_UNAVAILABLE */
468
+ );
469
+ LogMessageUtils.error(
470
+ "Disconnected",
471
+ "process disconnected",
472
+ stackTrace.stack,
473
+ "Child process disconnected",
474
+ 503 /* SERVICE_UNAVAILABLE */
475
+ );
476
+ import_process.default.exit();
477
+ }
478
+ static exited(code) {
479
+ switch (code) {
480
+ case 0:
481
+ LogMessageUtils.success(
482
+ "Exited",
483
+ "completed",
484
+ "The process finished as expected and everything is ok"
485
+ );
486
+ console.log("");
487
+ const paddingLength = 35;
488
+ const msg0 = " ".padEnd(paddingLength, " ");
489
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
490
+ console.log(`${import_ansi_colors4.default.bgGreen(` [OK] The server shutting down `)}`);
491
+ console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
492
+ break;
493
+ case 1:
494
+ const gnleStackTrace = this.traceError(
495
+ "Something went wrong",
496
+ "General Errors",
497
+ 503 /* SERVICE_UNAVAILABLE */
498
+ );
499
+ LogMessageUtils.error(
500
+ "Exited",
501
+ "General Errors",
502
+ gnleStackTrace.stack,
503
+ "Something went wrong",
504
+ 503 /* SERVICE_UNAVAILABLE */
505
+ );
506
+ break;
507
+ case 2:
508
+ const incrCmdStackTrace = this.traceError(
509
+ "Incorrect using of shell commands",
510
+ "Misuse of shell builtins",
511
+ 503 /* SERVICE_UNAVAILABLE */
512
+ );
513
+ LogMessageUtils.error(
514
+ "Exited",
515
+ incrCmdStackTrace.name,
516
+ incrCmdStackTrace.stack,
517
+ "Incorrect using of shell commands",
518
+ 503 /* SERVICE_UNAVAILABLE */
519
+ );
520
+ break;
521
+ case 126:
522
+ const notExeCmdStackTrace = this.traceError(
523
+ "Incorrect using of shell commands",
524
+ "Misuse of shell builtins",
525
+ 503 /* SERVICE_UNAVAILABLE */
526
+ );
527
+ LogMessageUtils.error(
528
+ "Exited",
529
+ `command invoked`,
530
+ notExeCmdStackTrace.stack,
531
+ "The command is found but is not executable (e.g., trying to execute a directory)",
532
+ 503 /* SERVICE_UNAVAILABLE */
533
+ );
534
+ break;
535
+ case 127:
536
+ const cmdNotFoundStackTrace = this.traceError(
537
+ "The command was not found in the system's PATH or is misspelled",
538
+ "Exited",
539
+ 503 /* SERVICE_UNAVAILABLE */
540
+ );
541
+ LogMessageUtils.error(
542
+ "Exited",
543
+ "Command not found",
544
+ cmdNotFoundStackTrace.stack,
545
+ "The command was not found in the system's PATH or is misspelled",
546
+ 503 /* SERVICE_UNAVAILABLE */
547
+ );
548
+ break;
549
+ case 128:
550
+ const cmdSysNotFoundStackTrace = this.traceError(
551
+ "The command was not found in the system's PATH or is misspelled",
552
+ "Exited",
553
+ 503 /* SERVICE_UNAVAILABLE */
554
+ );
555
+ LogMessageUtils.error(
556
+ "Exited",
557
+ "Invalid argument",
558
+ cmdSysNotFoundStackTrace.stack,
559
+ "The command was not found in the system's PATH or is misspelled",
560
+ 503 /* SERVICE_UNAVAILABLE */
561
+ );
562
+ break;
563
+ case 130:
564
+ const endScriptStackTrace = this.traceError(
565
+ "Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
566
+ "Exited",
567
+ 503 /* SERVICE_UNAVAILABLE */
568
+ );
569
+ LogMessageUtils.error(
570
+ "Exited",
571
+ "Script terminated",
572
+ endScriptStackTrace.stack,
573
+ "Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
574
+ 503 /* SERVICE_UNAVAILABLE */
575
+ );
576
+ break;
577
+ case 137:
578
+ const prcKillStackTrace = this.traceError(
579
+ "Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
580
+ "Exited",
581
+ 503 /* SERVICE_UNAVAILABLE */
582
+ );
583
+ LogMessageUtils.error(
584
+ "Exited",
585
+ "SIGKILL",
586
+ prcKillStackTrace.stack,
587
+ "Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
588
+ 503 /* SERVICE_UNAVAILABLE */
589
+ );
590
+ break;
591
+ case 139:
592
+ const illegalAccessStackTrace = this.traceError(
593
+ "Indicates that the process accessed an illegal memory address (segfault)",
594
+ "Exited",
595
+ 503 /* SERVICE_UNAVAILABLE */
596
+ );
597
+ LogMessageUtils.error(
598
+ "Exited",
599
+ "Segmentation fault",
600
+ illegalAccessStackTrace.stack,
601
+ "Indicates that the process accessed an illegal memory address (segfault)",
602
+ 503 /* SERVICE_UNAVAILABLE */
603
+ );
604
+ break;
605
+ case 143:
606
+ const sigtermStackTrace = this.traceError(
607
+ "Indicates that the process received a SIGTERM signal to terminate",
608
+ "Exited",
609
+ 503 /* SERVICE_UNAVAILABLE */
610
+ );
611
+ LogMessageUtils.error(
612
+ "Exited",
613
+ "process received a SIGTERM",
614
+ sigtermStackTrace.stack,
615
+ "Indicates that the process received a SIGTERM signal to terminate",
616
+ 503 /* SERVICE_UNAVAILABLE */
617
+ );
618
+ break;
619
+ case 255:
620
+ const outsideStackTrace = this.traceError(
621
+ "An exit code that is outside the allowable range (0-255 for Unix-like systems)",
622
+ "Exited",
623
+ 503 /* SERVICE_UNAVAILABLE */
624
+ );
625
+ LogMessageUtils.error(
626
+ "Exited",
627
+ "out of range",
628
+ outsideStackTrace.stack,
629
+ "An exit code that is outside the allowable range (0-255 for Unix-like systems)",
630
+ 503 /* SERVICE_UNAVAILABLE */
631
+ );
632
+ break;
633
+ default:
634
+ const globalStackTrace = this.traceError(
635
+ "Error is occurring",
636
+ "Exited",
637
+ 503 /* SERVICE_UNAVAILABLE */
638
+ );
639
+ LogMessageUtils.error(
640
+ "Exited",
641
+ "errors",
642
+ globalStackTrace.stack,
643
+ "Error is occurring",
644
+ 503 /* SERVICE_UNAVAILABLE */
645
+ );
646
+ break;
647
+ }
648
+ }
649
+ static promiseRejectionHandled(promise) {
650
+ const globalStackTrace = this.traceError(
651
+ `Promise rejection is handled at : ${promise}`,
652
+ "rejection promise",
653
+ 503 /* SERVICE_UNAVAILABLE */
654
+ );
655
+ LogMessageUtils.error(
656
+ "PromiseRejectionHandled",
657
+ "rejection promise",
658
+ globalStackTrace.stack,
659
+ `Promise rejection is handled at : ${promise}`,
660
+ 503 /* SERVICE_UNAVAILABLE */
661
+ );
662
+ }
663
+ static uncaughtException(error) {
664
+ if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
665
+ console.log("");
666
+ } else {
667
+ const tackTrace = this.traceError(
668
+ error.message,
669
+ "uncaught exception handled",
670
+ 503 /* SERVICE_UNAVAILABLE */
671
+ );
672
+ LogMessageUtils.error(
673
+ "UncaughtException",
674
+ "uncaught exception handled",
675
+ tackTrace.stack,
676
+ error.message,
677
+ 503 /* SERVICE_UNAVAILABLE */
678
+ );
679
+ }
680
+ }
681
+ static uncaughtExceptionMonitor(error) {
682
+ if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
683
+ console.log("");
684
+ }
685
+ }
686
+ static unhandledRejection(reason, promise) {
687
+ const stackTrace = this.traceError(
688
+ `Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
689
+ "Unhandled rejection",
690
+ 503 /* SERVICE_UNAVAILABLE */
691
+ );
692
+ LogMessageUtils.error(
693
+ "UnhandledRejection",
694
+ "Unhandled rejection",
695
+ stackTrace.stack,
696
+ `Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
697
+ 503 /* SERVICE_UNAVAILABLE */
698
+ );
699
+ }
700
+ static warning(warning) {
701
+ const stackTrace = this.traceError(warning.message, "warning", 503 /* SERVICE_UNAVAILABLE */);
702
+ LogMessageUtils.error(
703
+ "Warning",
704
+ "warning",
705
+ stackTrace.stack,
706
+ warning.message,
707
+ 503 /* SERVICE_UNAVAILABLE */
708
+ );
709
+ }
710
+ static message(message) {
711
+ const stackTrace = this.traceError(
712
+ `process got message ${message}`,
713
+ "message exception",
714
+ 503 /* SERVICE_UNAVAILABLE */
715
+ );
716
+ LogMessageUtils.error(
717
+ "Message",
718
+ "message exception",
719
+ stackTrace.stack,
720
+ `process got message ${message}`,
721
+ 503 /* SERVICE_UNAVAILABLE */
722
+ );
723
+ }
724
+ static multipleResolves(type, promise, reason) {
725
+ const stackTrace = this.traceError(
726
+ `${promise} -- ${reason}`,
727
+ "multipleResolves",
728
+ 503 /* SERVICE_UNAVAILABLE */
729
+ );
730
+ LogMessageUtils.error(
731
+ "multipleResolves",
732
+ `Multiple resolves detected : ${type}`,
733
+ stackTrace.stack,
734
+ `${promise} -- ${reason}`,
735
+ 503 /* SERVICE_UNAVAILABLE */
736
+ );
737
+ }
738
+ static processInterrupted() {
739
+ LogMessageUtils.success(
740
+ "[ OK ] Success",
741
+ `Process ${import_process.default.pid} has been interrupted`,
742
+ "The Web server has been stopped !"
743
+ );
744
+ import_process.default.exit(0);
745
+ }
746
+ static sigtermSignalReceived(signal) {
747
+ const stackTrace = this.traceError(
748
+ `Process ${import_process.default.pid} received a SIGTERM signal`,
749
+ "SIGTERM",
750
+ 406 /* NOT_ACCEPTABLE */
751
+ );
752
+ LogMessageUtils.error(
753
+ "SIGTERM",
754
+ "SIGTERM",
755
+ stackTrace.stack,
756
+ `Process ${import_process.default.pid} received a SIGTERM signal : ${signal.toString()}`,
757
+ 406 /* NOT_ACCEPTABLE */
758
+ );
759
+ import_process.default.exit(0);
760
+ }
761
+ static serverClosing() {
762
+ console.log(`${import_ansi_colors4.default.bgCyanBright(` ${import_ansi_colors4.default.bold(`${import_ansi_colors4.default.white(` INFO `)}`)}`)} All processes are stopped`);
763
+ console.log(" Server is closed");
764
+ import_process.default.exit();
765
+ }
766
+ static dropNewConnection() {
767
+ console.log(`${import_ansi_colors4.default.cyan(`\u24D8`)} ${import_ansi_colors4.default.bgCyan(` ${import_ansi_colors4.default.bold(`${import_ansi_colors4.default.white(` Server maxConnection `)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` Info `)}`)} The server dropped new connections`);
768
+ }
769
+ static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
770
+ if (err) {
771
+ errorEmitter.emit(CEventNameError.error, err);
772
+ if (typeof res.status === "function") {
773
+ res.status(500).send("Internal Server Error");
774
+ } else {
775
+ console.error("res.status is not a function");
776
+ }
777
+ const stackTrace = this.traceError(err.message, "Express error", 406 /* NOT_ACCEPTABLE */);
778
+ LogMessageUtils.error(
779
+ "Express error-handling middleware",
780
+ "Express error",
781
+ stackTrace.stack,
782
+ err.message,
783
+ 503 /* SERVICE_UNAVAILABLE */
784
+ );
785
+ } else {
786
+ next();
787
+ }
788
+ }
789
+ static traceError(props, name, status) {
790
+ return new StackTraceError(props, name, status, true);
791
+ }
792
+ };
793
+
794
+ // src/application/service/core.service.ts
795
+ var import_node_process2 = __toESM(require("process"), 1);
796
+ var import_chalk2 = __toESM(require("chalk"), 1);
797
+ var path = __toESM(require("path"), 1);
798
+ var fs = __toESM(require("fs"), 1);
799
+ var import_ansi_colors6 = __toESM(require("ansi-colors"), 1);
800
+
801
+ // src/core/utils/modulesLoaded.utils.ts
802
+ var import_ansi_colors5 = __toESM(require("ansi-colors"), 1);
803
+ function modulesLoadedUtils(allAppRoutes, dbConChecker) {
804
+ LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
805
+ console.log(`${import_ansi_colors5.default.whiteBright(` content`)} ${import_ansi_colors5.default.green("Kernel :")} ${import_ansi_colors5.default.cyan(`${import_ansi_colors5.default.bold(`server side`)}`)} has been loaded successfully ${import_ansi_colors5.default.green(`\u2714`)}`);
806
+ allAppRoutes ? console.log(`${import_ansi_colors5.default.whiteBright(` content`)} ${import_ansi_colors5.default.green("Kernel :")} ${import_ansi_colors5.default.cyan(`${import_ansi_colors5.default.bold(`Routers service`)} `)} has been loaded successfully ${import_ansi_colors5.default.green(`\u2714`)}`) : console.log(`${import_ansi_colors5.default.red(`\u2718`)} ${import_ansi_colors5.default.bgRed(` ${import_ansi_colors5.default.bold(`${import_ansi_colors5.default.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${import_ansi_colors5.default.red(`${import_ansi_colors5.default.bold(` fail `)}`)} ] | [ ${import_ansi_colors5.default.bold(` loading `)} ] - ${import_ansi_colors5.default.red(` routers `)} - The route register failed to load `);
807
+ typeof dbConChecker == "function" ? console.log(`${import_ansi_colors5.default.whiteBright(` content`)} ${import_ansi_colors5.default.green("Kernel :")} ${import_ansi_colors5.default.cyan(`${import_ansi_colors5.default.bold(`database checker connection`)}`)} has been loaded successfully ${import_ansi_colors5.default.green(`\u2714`)}`) : "";
808
+ }
809
+
810
+ // src/application/service/core.service.ts
811
+ var CoreService = class {
812
+ /**
813
+ *
814
+ * @param data
815
+ * @private
816
+ * Return a string converted in MegaBytes
817
+ */
818
+ formatMemoryUsage(data) {
819
+ return `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
820
+ }
821
+ /**
822
+ * Returns an Object containing a node version, openssl, and v0
823
+ */
824
+ getVersions() {
825
+ const { node, openssl, v8 } = import_node_process2.default.versions;
826
+ const data = {
827
+ "node version": node,
828
+ "openssl": openssl,
829
+ "v8": v8
830
+ };
831
+ return {
832
+ "nodeVersion": data["node version"],
833
+ "openssl": data.openssl,
834
+ "v8": data.v8
835
+ };
836
+ }
837
+ /**
838
+ * Return an Object containing a Resident Set Size - total memory allocated for the process execution
839
+ * Total size of the allocated heap
840
+ * Actual memory used during the execution
841
+ * Memory usage user
842
+ * and Memory usage system
843
+ */
844
+ getUsageMemory() {
845
+ const memoryData = import_node_process2.default.memoryUsage();
846
+ const data = {
847
+ "Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
848
+ "Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
849
+ "Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
850
+ "V8 external memory": this.formatMemoryUsage(memoryData.external),
851
+ "Memory usage user": this.formatMemoryUsage(import_node_process2.default.cpuUsage().user),
852
+ "Memory usage system": this.formatMemoryUsage(import_node_process2.default.cpuUsage().system)
853
+ };
854
+ return {
855
+ "rss": data["Resident Set Size - total memory allocated for the process execution"],
856
+ "heapTotal": data["Total size of the allocated heap"],
857
+ "heapUsed": data["Actual memory used during the execution"],
858
+ "external": data["V8 external memory"],
859
+ "user": data["Memory usage user"],
860
+ "system": data["Memory usage system"]
861
+ };
862
+ }
863
+ /**
864
+ * Return an Object containing a project path and running server time
865
+ */
866
+ getProjectInfo() {
867
+ const startTime = import_node_process2.default.hrtime();
868
+ const endTime = import_node_process2.default.hrtime(startTime);
869
+ const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
870
+ return {
871
+ "projectPath": path.join(import_node_process2.default.cwd()),
872
+ "startingTime": `${executionTime.toFixed(5)} ms`
873
+ };
874
+ }
875
+ /**
876
+ *
877
+ * @param filePath
878
+ * @private
879
+ */
880
+ getEnvFileLoading(filePath) {
881
+ const fullPath = path.resolve(import_node_process2.default.cwd(), filePath);
882
+ if (fs.existsSync(fullPath)) {
883
+ const env = fs.readFileSync(fullPath, "utf-8");
884
+ const lines = env.split("\n");
885
+ lines.forEach((line) => {
886
+ const match = line.match(/^([^#=]+)=([^#]+)$/);
887
+ if (match) {
888
+ const key = match[1].trim();
889
+ import_node_process2.default.env[key] = match[2].trim();
890
+ }
891
+ });
892
+ }
893
+ }
894
+ /**
895
+ *
896
+ * @param development
897
+ * @param production
898
+ */
899
+ getServerRunningMode(development, production) {
900
+ this.getEnvFileLoading(".env");
901
+ const isDevelopment = import_node_process2.default.env.NODE_ENV === "development";
902
+ if (isDevelopment) {
903
+ return `The server is running in ${import_ansi_colors6.default.bgBlue(`${import_ansi_colors6.default.bold(`${development}`)}`)} mode`;
904
+ } else {
905
+ return `The server is running in ${import_ansi_colors6.default.bgBlue(`${import_ansi_colors6.default.bold(`${production}`)}`)} mode`;
906
+ }
907
+ }
908
+ infoServer(nodeVersion, startingTime, host, port, rss, heapUsed, user, system) {
909
+ const paddingLength = 52;
910
+ const msg0 = " ".padEnd(paddingLength, " ");
911
+ const msg1 = " [OK] Web server listening";
912
+ const msg2Value = `${import_ansi_colors6.default.bgBlue(`${import_ansi_colors6.default.bold(`${nodeVersion}`)}`)}`;
913
+ const msg2 = ` The Web server is using Node.js version`;
914
+ const msg3Value = `${import_ansi_colors6.default.bgBlue(`${import_ansi_colors6.default.bold(`${startingTime}`)}`)}`;
915
+ const msg3 = ` Startup time:`;
916
+ const msg4 = ` ${this.getServerRunningMode("development", "production")}`;
917
+ const msg5 = ` ${import_ansi_colors6.default.underline(`http://${host}:${port}`)}`;
918
+ console.log(import_chalk2.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
919
+ console.log(import_chalk2.default.bgGreen.white(msg1.padEnd(paddingLength, " ")));
920
+ console.log(import_chalk2.default.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
921
+ console.log(import_chalk2.default.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
922
+ console.log(import_chalk2.default.bgGreen.white(msg4.padEnd(71, " ")));
923
+ console.log(import_chalk2.default.bgGreen.white(msg5.padEnd(61, " ")));
924
+ console.log(import_chalk2.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
925
+ console.log(``);
926
+ console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${import_ansi_colors6.default.cyan(`${import_ansi_colors6.default.bold(`${rss}`)}`)}`);
927
+ console.log(`${`Actual memory used during the execution :`} ${import_ansi_colors6.default.cyan(`${import_ansi_colors6.default.bold(`${heapUsed}`)}`)}`);
928
+ console.log(`${`Memory usage by user :`} ${import_ansi_colors6.default.cyan(`${import_ansi_colors6.default.bold(`${user}`)}`)}`);
929
+ console.log(`${`Memory usage by system :`} ${import_ansi_colors6.default.cyan(`${import_ansi_colors6.default.bold(`${system}`)}`)}`);
930
+ console.log(``);
931
+ }
932
+ coreListenerEventLoaderModuleService(kernelModule) {
933
+ let router = [];
934
+ let dbCon;
935
+ kernelModule.forEach((module2) => {
936
+ if (Array.isArray(module2)) {
937
+ router = module2;
938
+ } else if (typeof module2 === "function") {
939
+ dbCon = module2;
940
+ }
941
+ });
942
+ if (router && dbCon) {
943
+ modulesLoadedUtils(router, dbCon);
944
+ (() => {
945
+ dbCon();
946
+ })();
947
+ } else {
948
+ const stackTrace = new StackTraceError(
949
+ messageException.loadedModulesError,
950
+ messageException.loadedModules,
951
+ 406 /* NOT_ACCEPTABLE */,
952
+ true
953
+ );
954
+ throw new Error(stackTrace.message);
955
+ }
956
+ }
957
+ };
958
+
959
+ // src/core/webServer.core.ts
960
+ var WebServerCore = class {
961
+ constructor(app, corsOriginOptions) {
962
+ this.serverUtility = new CoreService();
963
+ this.expressApp = (0, import_express2.default)();
964
+ this.port = Number(getEnvVariable.appPort);
965
+ this.host = getEnvVariable.appHost;
966
+ this.routerExpressApp = app;
967
+ this.expressApp.use(import_express2.default.json());
968
+ this.expressApp.use(import_express2.default.raw());
969
+ this.expressApp.use(import_express2.default.text());
970
+ this.expressApp.use(import_express2.default.urlencoded({ extended: true }));
971
+ this.expressApp.use((0, import_cors.default)(corsOriginOptions));
972
+ this.stackTraceErrorHandling();
973
+ }
974
+ onStartServer(routers) {
975
+ return this.expressApp.listen(
976
+ this.port,
977
+ this.host,
978
+ () => {
979
+ try {
980
+ if (this.host === "" && this.port === 0) {
981
+ ServerListenEventError2.hostPortUndefined();
982
+ } else if (this.host === "") {
983
+ ServerListenEventError2.hostUndefined();
984
+ } else if (this.port === 0) {
985
+ ServerListenEventError2.portUndefined();
986
+ } else {
987
+ this.registerRoutes(routers);
988
+ }
989
+ } catch (err) {
990
+ this.traceError(err.message, "Error", 406 /* NOT_ACCEPTABLE */);
991
+ }
992
+ }
993
+ );
994
+ }
995
+ onListeningOnServerEvent(serverWeb, kernelModule) {
996
+ serverWeb.on(CEventNameError.error, (err) => {
997
+ ServerListenEventError2.onEventError(err);
998
+ }).on(CEventNameError.close, () => {
999
+ ServerListenEventError2.serverClosing();
1000
+ }).on(CEventNameError.drop, () => {
1001
+ ServerListenEventError2.dropNewConnection();
1002
+ }).on(CEventNameError.listening, () => {
1003
+ this.infoWebApp();
1004
+ this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
1005
+ });
1006
+ }
1007
+ onRequestOnServerEvent(serverWeb) {
1008
+ serverWeb.on(CEventNameError.request, (req, res) => {
1009
+ requestCallsEvent(req, res, this.host, this.port, dateTimeFormattedUtils);
1010
+ });
1011
+ }
1012
+ kernelModules(registerRouter, dbConnection) {
1013
+ return [registerRouter, dbConnection];
1014
+ }
1015
+ registerRoutes(allFeatureRoutes) {
1016
+ allFeatureRoutes.map((router) => {
1017
+ router.featureRoute.map((route) => {
1018
+ this.expressApp.use(route.path, route.handler);
1019
+ });
1020
+ });
1021
+ }
1022
+ stackTraceErrorHandling() {
1023
+ eventProcessHandler();
1024
+ }
1025
+ infoWebApp() {
1026
+ this.serverUtility.infoServer(
1027
+ this.serverUtility.getVersions().nodeVersion,
1028
+ this.serverUtility.getProjectInfo().startingTime,
1029
+ getEnvVariable.appHost,
1030
+ Number(getEnvVariable.appPort),
1031
+ this.serverUtility.getUsageMemory().rss,
1032
+ this.serverUtility.getUsageMemory().heapUsed,
1033
+ this.serverUtility.getUsageMemory().user,
1034
+ this.serverUtility.getUsageMemory().system
1035
+ );
1036
+ }
1037
+ traceError(props, name, status) {
1038
+ return new StackTraceError(props, name, status, true);
1039
+ }
1040
+ };
1041
+
1042
+ // src/domains/constants/errorName.constant.ts
1043
+ var CErrorName = {
1044
+ evalError: "EvalError",
1045
+ syntaxError: "SyntaxError",
1046
+ rangeError: "RangeError",
1047
+ referenceError: "ReferenceError",
1048
+ typeError: "TypeError",
1049
+ uriError: "URIError",
1050
+ systemError: "SystemError",
1051
+ assertionError: "AssertionError",
1052
+ openSSLError: "OpenSSLError",
1053
+ generalError: "GeneralError"
1054
+ };
1055
+
1056
+ // src/domains/constants/event.constant.ts
1057
+ var CEvent = {
1058
+ beforeExit: "beforeExit",
1059
+ disconnect: "disconnect",
1060
+ exit: "exit",
1061
+ rejectionHandled: "rejectionHandled",
1062
+ uncaughtException: "uncaughtException",
1063
+ uncaughtExceptionMonitor: "uncaughtExceptionMonitor",
1064
+ unhandledRejection: "unhandledRejection",
1065
+ warning: "warning",
1066
+ message: "message",
1067
+ multipleResolves: "multipleResolves",
1068
+ worker: "worker",
1069
+ sigint: "SIGINT",
1070
+ sigterm: "SIGTERM"
1071
+ };
1072
+ // Annotate the CommonJS export names for ESM import in node:
1073
+ 0 && (module.exports = {
1074
+ HttpStatusCode,
1075
+ WebServer,
1076
+ errorName,
1077
+ event,
1078
+ eventName,
1079
+ getEnvVariable
1080
+ });