opticore-webapp-core 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.
- package/dist/index.cjs +1177 -0
- package/dist/index.d.cts +438 -0
- package/dist/index.d.ts +438 -0
- package/dist/index.js +1128 -0
- package/package.json +50 -0
- package/tsconfig.json +26 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1177 @@
|
|
|
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
|
+
CLogLevel: () => CLogLevel,
|
|
34
|
+
CSignRSAKeyComponent: () => CSignRSAKeyComponent,
|
|
35
|
+
Environment: () => Environment,
|
|
36
|
+
MMongoCheckerDatabase: () => MMongoCheckerDatabase,
|
|
37
|
+
MMySqlCheckerDatabase: () => MMySqlCheckerDatabase,
|
|
38
|
+
MPostgresCheckerDatabase: () => MPostgresCheckerDatabase,
|
|
39
|
+
PathModuleVerifier: () => PathModuleVerifier,
|
|
40
|
+
RSAKeyDecryption: () => RSAKeyDecryption,
|
|
41
|
+
RSAKeyEncryption: () => RSAKeyEncryption,
|
|
42
|
+
SAsymmetricCryptionDataWithPrivateRSAKey: () => SAsymmetricCryptionDataWithPrivateRSAKey,
|
|
43
|
+
SAsymmetricCryptionDataWithPublicRSAKey: () => SAsymmetricCryptionDataWithPublicRSAKey,
|
|
44
|
+
SCheckerMongoDatabaseConnection: () => SCheckerMongoDatabaseConnection,
|
|
45
|
+
SCheckerMySqlDatabaseConnection: () => SCheckerMySqlDatabaseConnection,
|
|
46
|
+
SCheckerPostgresDatabaseConnection: () => SCheckerPostgresDatabaseConnection,
|
|
47
|
+
Utility: () => Utility,
|
|
48
|
+
YamlParsing: () => YamlParsing,
|
|
49
|
+
dateTimeFormatted: () => dateTimeFormatted,
|
|
50
|
+
loggerConfig: () => loggerConfig,
|
|
51
|
+
optionalArgumentConnectionUtil: () => optionalArgumentConnectionUtil,
|
|
52
|
+
translateLanguageLoader: () => translateLanguageLoader
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(index_exports);
|
|
55
|
+
|
|
56
|
+
// src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts
|
|
57
|
+
var import_crypto3 = __toESM(require("crypto"), 1);
|
|
58
|
+
var import_opticore_http_response = require("opticore-http-response");
|
|
59
|
+
var import_opticore_logger = require("opticore-logger");
|
|
60
|
+
var import_opticore_translator = require("opticore-translator");
|
|
61
|
+
var import_opticore_catch_exception_error = require("opticore-catch-exception-error");
|
|
62
|
+
|
|
63
|
+
// src/utils/cryptography/encryption/rsaKey.encryption.ts
|
|
64
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
65
|
+
|
|
66
|
+
// src/core/constants/signRSA/algorithm.constant.ts
|
|
67
|
+
var CAlgorithm = {
|
|
68
|
+
RSA_MD5: "RSA-MD5",
|
|
69
|
+
RSA_RIPEMD160: "RSA-RIPEMD160",
|
|
70
|
+
RSA_SHA1: "RSA-SHA1",
|
|
71
|
+
RSA_SHA1_2: "RSA-SHA1-2",
|
|
72
|
+
RSA_SHA224: "RSA-SHA224",
|
|
73
|
+
RSA_SHA256: "RSA-SHA256",
|
|
74
|
+
RSA_SHA3_224: "RSA-SHA3-224",
|
|
75
|
+
RSA_SHA3_256: "RSA-SHA3-256",
|
|
76
|
+
RSA_SHA3_384: "RSA-SHA3-384",
|
|
77
|
+
RSA_SHA3_512: "RSA-SHA3-512",
|
|
78
|
+
RSA_SHA384: "RSA-SHA384",
|
|
79
|
+
RSA_SHA512: "RSA-SHA512",
|
|
80
|
+
RSA_SHA512_224: "RSA-SHA512/224",
|
|
81
|
+
RSA_SHA512_256: "RSA-SHA512/256",
|
|
82
|
+
RSA_SM3: "RSA-SM3",
|
|
83
|
+
blake2b512: "blake2b512",
|
|
84
|
+
blake2s256: "blake2s256",
|
|
85
|
+
id_rsassa_pkcs1_v1_5_with_sha3_224: "id-rsassa-pkcs1-v1_5-with-sha3-224",
|
|
86
|
+
id_rsassa_pkcs1_v1_5_with_sha3_256: "id-rsassa-pkcs1-v1_5-with-sha3-256",
|
|
87
|
+
id_rsassa_pkcs1_v1_5_with_sha3_384: "id-rsassa-pkcs1-v1_5-with-sha3-384",
|
|
88
|
+
id_rsassa_pkcs1_v1_5_with_sha3_512: "id-rsassa-pkcs1-v1_5-with-sha3-512",
|
|
89
|
+
md5: "md5",
|
|
90
|
+
md5_sha1: "md5-sha1",
|
|
91
|
+
md5WithRSAEncryption: "md5WithRSAEncryption",
|
|
92
|
+
ripemd: "ripemd",
|
|
93
|
+
ripemd160: "ripemd160",
|
|
94
|
+
ripemd160WithRSA: "ripemd160WithRSA",
|
|
95
|
+
rmd160: "rmd160",
|
|
96
|
+
sha1: "sha1",
|
|
97
|
+
sha1WithRSAEncryption: "sha1WithRSAEncryption",
|
|
98
|
+
sha224: "sha224",
|
|
99
|
+
sha224WithRSAEncryption: "sha224WithRSAEncryption",
|
|
100
|
+
sha256: "SHA256",
|
|
101
|
+
sha256WithRSAEncryption: "sha256WithRSAEncryption",
|
|
102
|
+
sha3_224: "sha3-224",
|
|
103
|
+
sha3_256: "sha3-256",
|
|
104
|
+
sha3_384: "sha3-384",
|
|
105
|
+
sha3_512: "sha3-512",
|
|
106
|
+
sha384: "sha384",
|
|
107
|
+
sha384WithRSAEncryption: "sha384WithRSAEncryption",
|
|
108
|
+
sha512: "sha512",
|
|
109
|
+
sha512_224: "sha512-224",
|
|
110
|
+
sha512_224WithRSAEncryption: "sha512-224WithRSAEncryption",
|
|
111
|
+
sha512_256: "sha512-256",
|
|
112
|
+
sha512_256WithRSAEncryption: "sha512-256WithRSAEncryption",
|
|
113
|
+
sha512WithRSAEncryption: "sha512WithRSAEncryption",
|
|
114
|
+
shake128: "shake128",
|
|
115
|
+
shake256: "shake256",
|
|
116
|
+
sm3: "sm3",
|
|
117
|
+
sm3WithRSAEncryption: "sm3WithRSAEncryption",
|
|
118
|
+
ssl3_md5: "ssl3-md5",
|
|
119
|
+
ssl3_sha1: "ssl3-sha1"
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/core/constants/signRSA/keyType.constant.ts
|
|
123
|
+
var CKeyType = {
|
|
124
|
+
private: "Private",
|
|
125
|
+
public: "Public"
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// src/core/constants/signRSA/outputFormat.constant.ts
|
|
129
|
+
var COutputFormat = {
|
|
130
|
+
base64: "base64",
|
|
131
|
+
base64url: "base64url",
|
|
132
|
+
hex: "hex",
|
|
133
|
+
binary: "binary"
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/core/constants/signRSA/encodingFormat.constant.ts
|
|
137
|
+
var CEncodingFormat = {
|
|
138
|
+
ascii: "ascii",
|
|
139
|
+
utf8: "utf8",
|
|
140
|
+
utf_8: "utf-8",
|
|
141
|
+
utf16le: "utf16le",
|
|
142
|
+
utf_16le: "utf-16le",
|
|
143
|
+
ucs2: "ucs2",
|
|
144
|
+
ucs_2: "ucs-2",
|
|
145
|
+
base64: "base64",
|
|
146
|
+
base64url: "base64url",
|
|
147
|
+
latin1: "latin1",
|
|
148
|
+
binary: "binary",
|
|
149
|
+
hex: "hex"
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/core/constants/signRSAKeyComponent.constant.ts
|
|
153
|
+
var CSignRSAKeyComponent = {
|
|
154
|
+
algorithm: CAlgorithm,
|
|
155
|
+
keyType: CKeyType,
|
|
156
|
+
outputFormat: COutputFormat,
|
|
157
|
+
encodingFormat: CEncodingFormat
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/utils/cryptography/encryption/rsaKey.encryption.ts
|
|
161
|
+
var RSAKeyEncryption = class {
|
|
162
|
+
static privateEncrypt(privateKey, encryptData) {
|
|
163
|
+
const rsaPrivateKey = {
|
|
164
|
+
key: privateKey
|
|
165
|
+
};
|
|
166
|
+
const bufferData = Buffer.from(encryptData, CSignRSAKeyComponent.encodingFormat.utf8);
|
|
167
|
+
return import_crypto.default.privateEncrypt(rsaPrivateKey, bufferData);
|
|
168
|
+
}
|
|
169
|
+
static publicEncrypt(publicKey, encryptData) {
|
|
170
|
+
const rsaPublicKey = { key: publicKey };
|
|
171
|
+
const bufferData = Buffer.from(encryptData, CSignRSAKeyComponent.encodingFormat.utf8);
|
|
172
|
+
return import_crypto.default.publicEncrypt(rsaPublicKey, bufferData);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/utils/cryptography/decryption/rsaKey.decryption.ts
|
|
177
|
+
var import_crypto2 = __toESM(require("crypto"), 1);
|
|
178
|
+
var RSAKeyDecryption = class {
|
|
179
|
+
static privateDecrypt(privateKey, decryptData) {
|
|
180
|
+
const rsaPrivateKey = { key: privateKey };
|
|
181
|
+
return import_crypto2.default.privateDecrypt(rsaPrivateKey, decryptData);
|
|
182
|
+
}
|
|
183
|
+
static publicDecrypt(publicKey, decryptData) {
|
|
184
|
+
const rsaPublicKey = { key: publicKey };
|
|
185
|
+
return import_crypto2.default.publicDecrypt(rsaPublicKey, decryptData);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// src/core/config/logger/logger.config.ts
|
|
190
|
+
var import_opticore_env_access = require("opticore-env-access");
|
|
191
|
+
var loggerConfig = {
|
|
192
|
+
logLevels: [
|
|
193
|
+
import_opticore_env_access.getEnvVariable.logLevelInfo,
|
|
194
|
+
import_opticore_env_access.getEnvVariable.logLevelWarning,
|
|
195
|
+
import_opticore_env_access.getEnvVariable.logLevelSuccess,
|
|
196
|
+
import_opticore_env_access.getEnvVariable.logLevelError,
|
|
197
|
+
import_opticore_env_access.getEnvVariable.logLevelDebug
|
|
198
|
+
],
|
|
199
|
+
transports: {
|
|
200
|
+
file: {
|
|
201
|
+
enabled: import_opticore_env_access.getEnvVariable.logFileEnabled,
|
|
202
|
+
maxSizeMB: import_opticore_env_access.getEnvVariable.logFileMaxSize,
|
|
203
|
+
rotate: import_opticore_env_access.getEnvVariable.logFileRotate
|
|
204
|
+
},
|
|
205
|
+
console: {
|
|
206
|
+
enabled: import_opticore_env_access.getEnvVariable.logConsoleEnabled
|
|
207
|
+
},
|
|
208
|
+
remote: {
|
|
209
|
+
enabled: import_opticore_env_access.getEnvVariable.logRemoteEnabled,
|
|
210
|
+
endpoint: import_opticore_env_access.getEnvVariable.logRemoteEndPoint
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts
|
|
216
|
+
var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
217
|
+
/**
|
|
218
|
+
*
|
|
219
|
+
* @param rsaKey
|
|
220
|
+
* @param keyType
|
|
221
|
+
* @protected
|
|
222
|
+
*
|
|
223
|
+
* Return ErrorHandler | string
|
|
224
|
+
*/
|
|
225
|
+
static verifyExistingKey(rsaKey, keyType) {
|
|
226
|
+
if (!rsaKey) {
|
|
227
|
+
const stackTrace = this.traceError(
|
|
228
|
+
keyType + " " + import_opticore_translator.TranslationLoader.t("rsaKeyNotFound", import_opticore_translator.CLocal),
|
|
229
|
+
import_opticore_translator.TranslationLoader.t("erBadDbError", import_opticore_translator.CLocal),
|
|
230
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
231
|
+
);
|
|
232
|
+
this.log.error(
|
|
233
|
+
import_opticore_translator.TranslationLoader.t("rsaKeyNotFound", import_opticore_translator.CLocal),
|
|
234
|
+
import_opticore_translator.TranslationLoader.t("verifyExistingKey", import_opticore_translator.CLocal),
|
|
235
|
+
import_opticore_translator.TranslationLoader.t("erBadDbError", import_opticore_translator.CLocal),
|
|
236
|
+
stackTrace.stack,
|
|
237
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
238
|
+
);
|
|
239
|
+
throw new Error();
|
|
240
|
+
}
|
|
241
|
+
return rsaKey;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @param privateKey
|
|
246
|
+
* @param payload
|
|
247
|
+
* @private
|
|
248
|
+
*
|
|
249
|
+
* Return Buffer
|
|
250
|
+
*/
|
|
251
|
+
static encryptionWithPrivateKey(privateKey, payload) {
|
|
252
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
253
|
+
try {
|
|
254
|
+
const bufferedData = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
255
|
+
return RSAKeyEncryption.privateEncrypt(privateKey, bufferedData);
|
|
256
|
+
} catch (err) {
|
|
257
|
+
const stackTrace = this.traceError(
|
|
258
|
+
import_opticore_translator.TranslationLoader.t("encryptionWithPrivateKeyFailed", import_opticore_translator.CLocal),
|
|
259
|
+
import_opticore_translator.TranslationLoader.t("encryptionFailed", import_opticore_translator.CLocal),
|
|
260
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
261
|
+
);
|
|
262
|
+
this.log.error(
|
|
263
|
+
err.message,
|
|
264
|
+
import_opticore_translator.TranslationLoader.t("encryptionFailed", import_opticore_translator.CLocal),
|
|
265
|
+
import_opticore_translator.TranslationLoader.t("encryptionWithPrivateKeyFailed", import_opticore_translator.CLocal),
|
|
266
|
+
stackTrace.stack,
|
|
267
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
268
|
+
);
|
|
269
|
+
throw new Error();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
*
|
|
274
|
+
* @param privateKey
|
|
275
|
+
* @param publicKey
|
|
276
|
+
* @param payload
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
static decryptionWithPublicKey(privateKey, publicKey, payload) {
|
|
280
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
281
|
+
try {
|
|
282
|
+
const encryptedPayload = this.encryptionWithPrivateKey(privateKey, payload);
|
|
283
|
+
return RSAKeyDecryption.publicDecrypt(publicKey, encryptedPayload);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
const stackTrace = this.traceError(
|
|
286
|
+
import_opticore_translator.TranslationLoader.t("errorDecryption", import_opticore_translator.CLocal),
|
|
287
|
+
import_opticore_translator.TranslationLoader.t("decryptionFailed", import_opticore_translator.CLocal),
|
|
288
|
+
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE
|
|
289
|
+
);
|
|
290
|
+
this.log.error(
|
|
291
|
+
import_opticore_translator.TranslationLoader.t("decryptionWithPublicKeyFailed", import_opticore_translator.CLocal),
|
|
292
|
+
import_opticore_translator.TranslationLoader.t("decryptionFailed", import_opticore_translator.CLocal),
|
|
293
|
+
stackTrace.stack,
|
|
294
|
+
import_opticore_translator.TranslationLoader.t("errorDecryption", import_opticore_translator.CLocal),
|
|
295
|
+
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE
|
|
296
|
+
);
|
|
297
|
+
throw new Error();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
*
|
|
302
|
+
* @param privateKey
|
|
303
|
+
* @param payload
|
|
304
|
+
* @private
|
|
305
|
+
*/
|
|
306
|
+
static signWithRSAKey(privateKey, payload) {
|
|
307
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
308
|
+
const sign = import_crypto3.default.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
309
|
+
sign.update(payload);
|
|
310
|
+
return sign.sign(privateKey, CSignRSAKeyComponent.outputFormat.base64);
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
*
|
|
314
|
+
* @param privateKey
|
|
315
|
+
* @param publicKey
|
|
316
|
+
* @param payload
|
|
317
|
+
*/
|
|
318
|
+
static verifyRSAKey(privateKey, publicKey, payload) {
|
|
319
|
+
try {
|
|
320
|
+
const verify = import_crypto3.default.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
321
|
+
verify.update(payload);
|
|
322
|
+
const signature = this.signWithRSAKey(privateKey, payload);
|
|
323
|
+
const isVerified = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64);
|
|
324
|
+
if (isVerified) {
|
|
325
|
+
const decryptedData = this.decryptionWithPublicKey(privateKey, publicKey, payload);
|
|
326
|
+
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8);
|
|
327
|
+
} else {
|
|
328
|
+
const stackTrace = this.traceError(
|
|
329
|
+
import_opticore_translator.TranslationLoader.t("signatureRSAKeyFailed", import_opticore_translator.CLocal),
|
|
330
|
+
import_opticore_translator.TranslationLoader.t("verifyRSAKeyFailed", import_opticore_translator.CLocal),
|
|
331
|
+
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE
|
|
332
|
+
);
|
|
333
|
+
this.log.error(
|
|
334
|
+
import_opticore_translator.TranslationLoader.t("verifyRSAKey", import_opticore_translator.CLocal),
|
|
335
|
+
import_opticore_translator.TranslationLoader.t("verifyRSAKeyFailed", import_opticore_translator.CLocal),
|
|
336
|
+
stackTrace.stack,
|
|
337
|
+
import_opticore_translator.TranslationLoader.t("signatureRSAKeyFailed", import_opticore_translator.CLocal),
|
|
338
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
339
|
+
);
|
|
340
|
+
return new Error();
|
|
341
|
+
}
|
|
342
|
+
} catch (err) {
|
|
343
|
+
const stackTrace = this.traceError(
|
|
344
|
+
err.name,
|
|
345
|
+
import_opticore_translator.TranslationLoader.t("signatureRSAKeysError", import_opticore_translator.CLocal),
|
|
346
|
+
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE
|
|
347
|
+
);
|
|
348
|
+
this.log.error(
|
|
349
|
+
import_opticore_translator.TranslationLoader.t("signatureRSAKeysError", import_opticore_translator.CLocal),
|
|
350
|
+
import_opticore_translator.TranslationLoader.t("errorNameNotVerifyingRSAKey", import_opticore_translator.CLocal),
|
|
351
|
+
stackTrace.stack,
|
|
352
|
+
err.message,
|
|
353
|
+
import_opticore_http_response.HttpStatusCode.NOT_FOUND
|
|
354
|
+
);
|
|
355
|
+
throw new Error();
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
*
|
|
360
|
+
* @param props
|
|
361
|
+
* @param name
|
|
362
|
+
* @param status
|
|
363
|
+
* @private
|
|
364
|
+
*/
|
|
365
|
+
static traceError(props, name, status7) {
|
|
366
|
+
return new import_opticore_catch_exception_error.StackTraceError(props, name, status7, true);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
SAsymmetricCryptionDataWithPrivateRSAKey.log = new import_opticore_logger.LoggerCore(loggerConfig);
|
|
370
|
+
|
|
371
|
+
// src/application/services/asymmetricCryptionDataWithPublicRSAKey.service.ts
|
|
372
|
+
var import_crypto4 = __toESM(require("crypto"), 1);
|
|
373
|
+
var import_opticore_logger2 = require("opticore-logger");
|
|
374
|
+
var import_opticore_translator2 = require("opticore-translator");
|
|
375
|
+
var import_opticore_http_response2 = require("opticore-http-response");
|
|
376
|
+
var import_opticore_catch_exception_error2 = require("opticore-catch-exception-error");
|
|
377
|
+
var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
378
|
+
/**
|
|
379
|
+
*
|
|
380
|
+
* @param rsaKey
|
|
381
|
+
* @param keyType
|
|
382
|
+
* @protected
|
|
383
|
+
*/
|
|
384
|
+
static verifyExistingKey(rsaKey, keyType) {
|
|
385
|
+
if (!rsaKey) {
|
|
386
|
+
const stackTrace = this.traceError(
|
|
387
|
+
keyType + import_opticore_translator2.TranslationLoader.t("verifyExistingKey", import_opticore_translator2.CLocal),
|
|
388
|
+
import_opticore_translator2.TranslationLoader.t("verifyExistingKey", import_opticore_translator2.CLocal),
|
|
389
|
+
import_opticore_http_response2.HttpStatusCode.NOT_FOUND
|
|
390
|
+
);
|
|
391
|
+
this.log.error(
|
|
392
|
+
import_opticore_translator2.TranslationLoader.t("verifyExistingKey", import_opticore_translator2.CLocal),
|
|
393
|
+
"key verification",
|
|
394
|
+
stackTrace.stack,
|
|
395
|
+
import_opticore_translator2.TranslationLoader.t("verifyExistingKeyError", import_opticore_translator2.CLocal),
|
|
396
|
+
import_opticore_http_response2.HttpStatusCode.NOT_FOUND
|
|
397
|
+
);
|
|
398
|
+
return new Error();
|
|
399
|
+
}
|
|
400
|
+
return rsaKey;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
*
|
|
404
|
+
* @param publicKey
|
|
405
|
+
* @param payload
|
|
406
|
+
* @private
|
|
407
|
+
*/
|
|
408
|
+
static encryptionWithPublicKey(publicKey, payload) {
|
|
409
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
410
|
+
try {
|
|
411
|
+
const bufferedData = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
412
|
+
return RSAKeyEncryption.publicEncrypt(publicKey, bufferedData);
|
|
413
|
+
} catch (err) {
|
|
414
|
+
const stackTrace = this.traceError(
|
|
415
|
+
err.message,
|
|
416
|
+
import_opticore_translator2.TranslationLoader.t("encryptionWithPublicKey", import_opticore_translator2.CLocal),
|
|
417
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
418
|
+
);
|
|
419
|
+
this.log.error(
|
|
420
|
+
import_opticore_translator2.TranslationLoader.t("errorEncryptionPublicKey", import_opticore_translator2.CLocal),
|
|
421
|
+
import_opticore_translator2.TranslationLoader.t("encryptionWithPublicKey", import_opticore_translator2.CLocal),
|
|
422
|
+
stackTrace.stack,
|
|
423
|
+
err.message,
|
|
424
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
425
|
+
);
|
|
426
|
+
throw new Error();
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
*
|
|
431
|
+
* @param privateKey
|
|
432
|
+
* @param publicKey
|
|
433
|
+
* @param payload
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
static decryptionWithPrivateKey(privateKey, publicKey, payload) {
|
|
437
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
438
|
+
try {
|
|
439
|
+
const encryptedPayload = this.encryptionWithPublicKey(publicKey, payload);
|
|
440
|
+
return RSAKeyDecryption.privateDecrypt(privateKey, encryptedPayload);
|
|
441
|
+
} catch (err) {
|
|
442
|
+
const stackTrace = this.traceError(
|
|
443
|
+
err.code,
|
|
444
|
+
import_opticore_translator2.TranslationLoader.t("errorDecryption", import_opticore_translator2.CLocal),
|
|
445
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
446
|
+
);
|
|
447
|
+
this.log.error(
|
|
448
|
+
import_opticore_translator2.TranslationLoader.t("errorDecryptionWithPrivateKey", import_opticore_translator2.CLocal),
|
|
449
|
+
import_opticore_translator2.TranslationLoader.t("errorDecryption", import_opticore_translator2.CLocal),
|
|
450
|
+
stackTrace.stack,
|
|
451
|
+
err.message,
|
|
452
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
453
|
+
);
|
|
454
|
+
throw new Error();
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
*
|
|
459
|
+
* @param publicKey
|
|
460
|
+
* @param payload
|
|
461
|
+
* @private
|
|
462
|
+
*/
|
|
463
|
+
static signWithPublicRSAKey(publicKey, payload) {
|
|
464
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.private);
|
|
465
|
+
const sign = import_crypto4.default.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
466
|
+
sign.update(payload);
|
|
467
|
+
return sign.sign(publicKey, CSignRSAKeyComponent.outputFormat.base64);
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
*
|
|
471
|
+
* @param privateKey
|
|
472
|
+
* @param publicKey
|
|
473
|
+
* @param payload
|
|
474
|
+
*/
|
|
475
|
+
static verifyPublicRSAKey(privateKey, publicKey, payload) {
|
|
476
|
+
try {
|
|
477
|
+
const verify = import_crypto4.default.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
478
|
+
verify.update(payload);
|
|
479
|
+
const signature = this.signWithPublicRSAKey(publicKey, payload);
|
|
480
|
+
const isVerified = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64);
|
|
481
|
+
if (isVerified) {
|
|
482
|
+
const decryptedData = this.decryptionWithPrivateKey(privateKey, publicKey, payload);
|
|
483
|
+
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8);
|
|
484
|
+
} else {
|
|
485
|
+
const stackTrace = this.traceError(
|
|
486
|
+
import_opticore_translator2.TranslationLoader.t("verifyPublicRSAKeyError", import_opticore_translator2.CLocal),
|
|
487
|
+
import_opticore_translator2.TranslationLoader.t("signatureRSAKeyFailed", import_opticore_translator2.CLocal),
|
|
488
|
+
import_opticore_http_response2.HttpStatusCode.NOT_FOUND
|
|
489
|
+
);
|
|
490
|
+
this.log.error(
|
|
491
|
+
import_opticore_translator2.TranslationLoader.t("verifyPublicRSAKey", import_opticore_translator2.CLocal),
|
|
492
|
+
import_opticore_translator2.TranslationLoader.t("signatureRSAKeyFailed", import_opticore_translator2.CLocal),
|
|
493
|
+
stackTrace.stack,
|
|
494
|
+
import_opticore_translator2.TranslationLoader.t("verifyPublicRSAKeyError", import_opticore_translator2.CLocal),
|
|
495
|
+
import_opticore_http_response2.HttpStatusCode.NOT_FOUND
|
|
496
|
+
);
|
|
497
|
+
return stackTrace;
|
|
498
|
+
}
|
|
499
|
+
} catch (err) {
|
|
500
|
+
const stackTrace = this.traceError(
|
|
501
|
+
err.code,
|
|
502
|
+
import_opticore_translator2.TranslationLoader.t("verifyPublicRSAKey", import_opticore_translator2.CLocal),
|
|
503
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
504
|
+
);
|
|
505
|
+
this.log.error(
|
|
506
|
+
import_opticore_translator2.TranslationLoader.t("verifyPublicRSAKey", import_opticore_translator2.CLocal),
|
|
507
|
+
import_opticore_translator2.TranslationLoader.t("errorDecryption", import_opticore_translator2.CLocal),
|
|
508
|
+
stackTrace.stack,
|
|
509
|
+
err.message,
|
|
510
|
+
import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE
|
|
511
|
+
);
|
|
512
|
+
throw new Error();
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
static traceError(props, name, status7) {
|
|
516
|
+
return new import_opticore_catch_exception_error2.StackTraceError(props, name, status7, true);
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
SAsymmetricCryptionDataWithPublicRSAKey.log = new import_opticore_logger2.LoggerCore(loggerConfig);
|
|
520
|
+
|
|
521
|
+
// src/application/services/checkerMongoDatabaseConnection.service.ts
|
|
522
|
+
var import_mongodb = require("mongodb");
|
|
523
|
+
async function SCheckerMongoDatabaseConnection(url, user, password, dbName) {
|
|
524
|
+
const client = new import_mongodb.MongoClient(
|
|
525
|
+
url,
|
|
526
|
+
{
|
|
527
|
+
auth: { username: user, password }
|
|
528
|
+
}
|
|
529
|
+
);
|
|
530
|
+
await client.connect();
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// src/core/handlers/errors/database/mySqlError.handler.database.ts
|
|
534
|
+
var import_opticore_logger3 = require("opticore-logger");
|
|
535
|
+
var import_opticore_http_response3 = require("opticore-http-response");
|
|
536
|
+
var import_opticore_translator3 = require("opticore-translator");
|
|
537
|
+
function mySqlErrorHandlerDatabase(err, dbHost, database, user, password) {
|
|
538
|
+
const logger = new import_opticore_logger3.LoggerCore(loggerConfig);
|
|
539
|
+
switch (err.code) {
|
|
540
|
+
case "EAI_AGAIN":
|
|
541
|
+
logger.error(
|
|
542
|
+
import_opticore_translator3.TranslationLoader.t("errorDBHost", import_opticore_translator3.CLocal, { dbHost }),
|
|
543
|
+
import_opticore_translator3.TranslationLoader.t("mySQLError", import_opticore_translator3.CLocal),
|
|
544
|
+
import_opticore_translator3.TranslationLoader.t("eAiAgain", import_opticore_translator3.CLocal),
|
|
545
|
+
err.stack,
|
|
546
|
+
import_opticore_http_response3.HttpStatusCode.NOT_ACCEPTABLE
|
|
547
|
+
);
|
|
548
|
+
break;
|
|
549
|
+
case "ER_NOT_SUPPORTED_AUTH_MODE":
|
|
550
|
+
logger.error(
|
|
551
|
+
import_opticore_translator3.TranslationLoader.t("erNotSupportedAuthModeError", import_opticore_translator3.CLocal),
|
|
552
|
+
import_opticore_translator3.TranslationLoader.t("dbConnection", import_opticore_translator3.CLocal),
|
|
553
|
+
import_opticore_translator3.TranslationLoader.t("erNotSupportedAuthMode", import_opticore_translator3.CLocal),
|
|
554
|
+
err.stack,
|
|
555
|
+
import_opticore_http_response3.HttpStatusCode.NOT_ACCEPTABLE
|
|
556
|
+
);
|
|
557
|
+
break;
|
|
558
|
+
case "ER_ACCESS_DENIED_ERROR":
|
|
559
|
+
logger.error(
|
|
560
|
+
import_opticore_translator3.TranslationLoader.t("accessDeniedToDBCon", import_opticore_translator3.CLocal, { user, password }),
|
|
561
|
+
import_opticore_translator3.TranslationLoader.t("dbConnection", import_opticore_translator3.CLocal),
|
|
562
|
+
import_opticore_translator3.TranslationLoader.t("erAccessDeniedError", import_opticore_translator3.CLocal),
|
|
563
|
+
err.stack,
|
|
564
|
+
import_opticore_http_response3.HttpStatusCode.NOT_ACCEPTABLE
|
|
565
|
+
);
|
|
566
|
+
break;
|
|
567
|
+
case "ER_BAD_DB_ERROR":
|
|
568
|
+
logger.error(
|
|
569
|
+
import_opticore_translator3.TranslationLoader.t("unknownDB", import_opticore_translator3.CLocal, { database }),
|
|
570
|
+
import_opticore_translator3.TranslationLoader.t("dbConnection", import_opticore_translator3.CLocal),
|
|
571
|
+
import_opticore_translator3.TranslationLoader.t("erBadDbError", import_opticore_translator3.CLocal),
|
|
572
|
+
err.stack,
|
|
573
|
+
import_opticore_http_response3.HttpStatusCode.NOT_ACCEPTABLE
|
|
574
|
+
);
|
|
575
|
+
break;
|
|
576
|
+
default:
|
|
577
|
+
logger.error(
|
|
578
|
+
err.message,
|
|
579
|
+
import_opticore_translator3.TranslationLoader.t("dbConnection", import_opticore_translator3.CLocal),
|
|
580
|
+
import_opticore_translator3.TranslationLoader.t("mysqlErrorCon", import_opticore_translator3.CLocal),
|
|
581
|
+
err.stack,
|
|
582
|
+
import_opticore_http_response3.HttpStatusCode.NOT_ACCEPTABLE
|
|
583
|
+
);
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/application/services/checkerMySqlDatabaseConnection.service.ts
|
|
589
|
+
var import_opticore_logger4 = require("opticore-logger");
|
|
590
|
+
var import_opticore_translator4 = require("opticore-translator");
|
|
591
|
+
function SCheckerMySqlDatabaseConnection(dbConnection, user, database, dbHost, password) {
|
|
592
|
+
const log = new import_opticore_logger4.LoggerCore(loggerConfig);
|
|
593
|
+
dbConnection.connect((err) => {
|
|
594
|
+
if (err) {
|
|
595
|
+
return mySqlErrorHandlerDatabase(err, dbHost, database, user, password);
|
|
596
|
+
} else {
|
|
597
|
+
log.success(
|
|
598
|
+
import_opticore_translator4.TranslationLoader.t("dbConnection", import_opticore_translator4.CLocal),
|
|
599
|
+
import_opticore_translator4.TranslationLoader.t("dbConnexionSuccess", import_opticore_translator4.CLocal)
|
|
600
|
+
);
|
|
601
|
+
return dbConnection.end((endConErr) => {
|
|
602
|
+
if (endConErr) {
|
|
603
|
+
return mySqlErrorHandlerDatabase(err, dbHost, database, user, password);
|
|
604
|
+
} else {
|
|
605
|
+
log.success(
|
|
606
|
+
import_opticore_translator4.TranslationLoader.t("dbConnection", import_opticore_translator4.CLocal),
|
|
607
|
+
import_opticore_translator4.TranslationLoader.t("dbConnectionClosed", import_opticore_translator4.CLocal)
|
|
608
|
+
);
|
|
609
|
+
console.log("");
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/application/services/checkerPostgresDatabaseConnection.service.ts
|
|
617
|
+
var import_opticore_http_response4 = require("opticore-http-response");
|
|
618
|
+
var import_pg = require("pg");
|
|
619
|
+
var import_opticore_logger5 = require("opticore-logger");
|
|
620
|
+
var import_opticore_translator5 = require("opticore-translator");
|
|
621
|
+
async function SCheckerPostgresDatabaseConnection(connectionString, keepAlive, stream, statement_timeout, ssl, query_timeout, keepAliveInitialDelayMillis, idle_in_transaction_session_timeout, application_name, connectionTimeoutMillis, types, options) {
|
|
622
|
+
const logger = new import_opticore_logger5.LoggerCore(loggerConfig);
|
|
623
|
+
const configOptions = {
|
|
624
|
+
connectionString,
|
|
625
|
+
keepAlive,
|
|
626
|
+
stream,
|
|
627
|
+
statement_timeout,
|
|
628
|
+
ssl,
|
|
629
|
+
query_timeout,
|
|
630
|
+
keepAliveInitialDelayMillis,
|
|
631
|
+
idle_in_transaction_session_timeout,
|
|
632
|
+
application_name,
|
|
633
|
+
connectionTimeoutMillis,
|
|
634
|
+
types,
|
|
635
|
+
options
|
|
636
|
+
};
|
|
637
|
+
const client = new import_pg.Client(configOptions);
|
|
638
|
+
await client.connect();
|
|
639
|
+
await client.end().then(
|
|
640
|
+
() => {
|
|
641
|
+
logger.success(
|
|
642
|
+
import_opticore_translator5.TranslationLoader.t("postgresSuccessConn", import_opticore_translator5.CLocal),
|
|
643
|
+
import_opticore_translator5.TranslationLoader.t("postgresClosingConnSuccess", import_opticore_translator5.CLocal)
|
|
644
|
+
);
|
|
645
|
+
},
|
|
646
|
+
(onRejected) => {
|
|
647
|
+
logger.error(
|
|
648
|
+
import_opticore_translator5.TranslationLoader.t("postgresEndClientRejection", import_opticore_translator5.CLocal),
|
|
649
|
+
import_opticore_translator5.TranslationLoader.t("postgresClientError", import_opticore_translator5.CLocal),
|
|
650
|
+
import_opticore_translator5.TranslationLoader.t("postgresEndRejection", import_opticore_translator5.CLocal),
|
|
651
|
+
onRejected,
|
|
652
|
+
import_opticore_http_response4.HttpStatusCode.BAD_REQUEST
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
).catch((onError) => {
|
|
656
|
+
logger.error(
|
|
657
|
+
onError.message,
|
|
658
|
+
import_opticore_translator5.TranslationLoader.t("postgresConnError", import_opticore_translator5.CLocal),
|
|
659
|
+
import_opticore_translator5.TranslationLoader.t("postgresException", import_opticore_translator5.CLocal),
|
|
660
|
+
onError.stack,
|
|
661
|
+
import_opticore_http_response4.HttpStatusCode.BAD_REQUEST
|
|
662
|
+
);
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/domains/constants/logLevel.constant.ts
|
|
667
|
+
var CLogLevel = {
|
|
668
|
+
debug: "DEBUG",
|
|
669
|
+
info: "INFO",
|
|
670
|
+
warn: "WARN",
|
|
671
|
+
error: "ERROR"
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
// src/utils/connection/optionalArgumentConnection.util.ts
|
|
675
|
+
var import_opticore_env_access2 = require("opticore-env-access");
|
|
676
|
+
var optionalArgumentConnectionUtil = import_opticore_env_access2.getEnvVariable.argumentsDatabaseConnection;
|
|
677
|
+
|
|
678
|
+
// src/utils/parsing/parsingYaml.utils.ts
|
|
679
|
+
var import_promises = require("fs/promises");
|
|
680
|
+
var import_opticore_http_response5 = require("opticore-http-response");
|
|
681
|
+
var import_opticore_logger6 = require("opticore-logger");
|
|
682
|
+
var import_opticore_translator6 = require("opticore-translator");
|
|
683
|
+
var YamlParsing = class {
|
|
684
|
+
static async readFile(filePath) {
|
|
685
|
+
try {
|
|
686
|
+
const yamlContent = await (0, import_promises.readFile)(filePath, "utf-8");
|
|
687
|
+
await this.parsing(yamlContent);
|
|
688
|
+
} catch (error) {
|
|
689
|
+
this.logger.error(
|
|
690
|
+
error.message,
|
|
691
|
+
import_opticore_translator6.TranslationLoader.t("parsingFailed", import_opticore_translator6.CLocal),
|
|
692
|
+
import_opticore_translator6.TranslationLoader.t("readingError", import_opticore_translator6.CLocal),
|
|
693
|
+
error.stack,
|
|
694
|
+
import_opticore_http_response5.HttpStatusCode.NOT_ACCEPTABLE
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
*
|
|
700
|
+
* @param content
|
|
701
|
+
* @private
|
|
702
|
+
*/
|
|
703
|
+
static async parsing(content) {
|
|
704
|
+
const result = {};
|
|
705
|
+
const lines = content.split("\n");
|
|
706
|
+
let currentKey = null;
|
|
707
|
+
for (const line of lines) {
|
|
708
|
+
if (!line.trim() || line.trim().startsWith("#")) {
|
|
709
|
+
continue;
|
|
710
|
+
}
|
|
711
|
+
const keyValueMatch = line.match(/^(\s*)([a-zA-Z0-9_]+):(?:\s*(.*))?$/);
|
|
712
|
+
if (keyValueMatch) {
|
|
713
|
+
const [, indent, key, value] = keyValueMatch;
|
|
714
|
+
if (indent.length > 0 && currentKey) {
|
|
715
|
+
result[currentKey] = result[currentKey] || {};
|
|
716
|
+
result[currentKey][key] = (value == null ? void 0 : value.trim()) || null;
|
|
717
|
+
} else {
|
|
718
|
+
currentKey = key;
|
|
719
|
+
result[key] = (value == null ? void 0 : value.trim()) || null;
|
|
720
|
+
}
|
|
721
|
+
} else {
|
|
722
|
+
this.logger.error(
|
|
723
|
+
import_opticore_translator6.TranslationLoader.t("badFormat", import_opticore_translator6.CLocal, { line }),
|
|
724
|
+
import_opticore_translator6.TranslationLoader.t("parsingFailed", import_opticore_translator6.CLocal),
|
|
725
|
+
import_opticore_translator6.TranslationLoader.t("unsupportedFormat", import_opticore_translator6.CLocal),
|
|
726
|
+
content,
|
|
727
|
+
import_opticore_http_response5.HttpStatusCode.NOT_ACCEPTABLE
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return result;
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
YamlParsing.logger = new import_opticore_logger6.LoggerCore(loggerConfig);
|
|
735
|
+
|
|
736
|
+
// src/utils/dateTimeFormatted.utils.ts
|
|
737
|
+
var dateTimeFormatted = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
|
|
738
|
+
|
|
739
|
+
// src/utils/environment.utils.ts
|
|
740
|
+
var Environment = class {
|
|
741
|
+
constructor(config) {
|
|
742
|
+
this.config = config;
|
|
743
|
+
}
|
|
744
|
+
get(key) {
|
|
745
|
+
return this.config[key];
|
|
746
|
+
}
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
// src/core/config/database/connexion.config.database.ts
|
|
750
|
+
var import_mysql = __toESM(require("mysql"), 1);
|
|
751
|
+
var import_opticore_http_response7 = require("opticore-http-response");
|
|
752
|
+
var import_opticore_env_access3 = require("opticore-env-access");
|
|
753
|
+
var import_opticore_logger8 = require("opticore-logger");
|
|
754
|
+
var import_opticore_translator8 = require("opticore-translator");
|
|
755
|
+
|
|
756
|
+
// src/core/errors/databaseConnexion.error.ts
|
|
757
|
+
var import_opticore_http_response6 = require("opticore-http-response");
|
|
758
|
+
var import_opticore_logger7 = require("opticore-logger");
|
|
759
|
+
var import_opticore_catch_exception_error3 = require("opticore-catch-exception-error");
|
|
760
|
+
var import_opticore_translator7 = require("opticore-translator");
|
|
761
|
+
var DbConnexionConfigError = class {
|
|
762
|
+
/**
|
|
763
|
+
*
|
|
764
|
+
* @param e
|
|
765
|
+
*/
|
|
766
|
+
static mongoDBAuthenticationFailed(e) {
|
|
767
|
+
const stackTrace = this.traceError(
|
|
768
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
769
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBAuthentication", import_opticore_translator7.CLocal),
|
|
770
|
+
import_opticore_http_response6.HttpStatusCode.UNAUTHORIZED
|
|
771
|
+
);
|
|
772
|
+
this.logger.error(
|
|
773
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBAuthenticationError", import_opticore_translator7.CLocal),
|
|
774
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
775
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBAuthenticationFailed", import_opticore_translator7.CLocal),
|
|
776
|
+
stackTrace.stack,
|
|
777
|
+
import_opticore_http_response6.HttpStatusCode.UNAUTHORIZED
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
*
|
|
782
|
+
* @param err
|
|
783
|
+
* @param dbHost
|
|
784
|
+
* @param dbPort
|
|
785
|
+
*/
|
|
786
|
+
static mongoDBInvalidUrl(err, dbHost, dbPort) {
|
|
787
|
+
const stackTrace = this.traceError(
|
|
788
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
789
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBUnableParsingUrl", import_opticore_translator7.CLocal),
|
|
790
|
+
import_opticore_http_response6.HttpStatusCode.BAD_REQUEST
|
|
791
|
+
);
|
|
792
|
+
this.logger.error(
|
|
793
|
+
import_opticore_translator7.TranslationLoader.t("dbUrlParsingError", import_opticore_translator7.CLocal, { dbHost, dbPort }),
|
|
794
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
795
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBUnableParsingUrl", import_opticore_translator7.CLocal),
|
|
796
|
+
stackTrace.stack,
|
|
797
|
+
import_opticore_http_response6.HttpStatusCode.BAD_REQUEST
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
/**
|
|
801
|
+
*
|
|
802
|
+
* @param err
|
|
803
|
+
* @param dbHost
|
|
804
|
+
*/
|
|
805
|
+
static mongoDBEaiAgain(err, dbHost) {
|
|
806
|
+
const stackTrace = this.traceError(
|
|
807
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
808
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBServerSelection", import_opticore_translator7.CLocal),
|
|
809
|
+
import_opticore_http_response6.HttpStatusCode.BAD_REQUEST
|
|
810
|
+
);
|
|
811
|
+
this.logger.error(
|
|
812
|
+
import_opticore_translator7.TranslationLoader.t("mongoServerError", import_opticore_translator7.CLocal, { dbHost }),
|
|
813
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
814
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBServerSelection", import_opticore_translator7.CLocal),
|
|
815
|
+
stackTrace.stack,
|
|
816
|
+
import_opticore_http_response6.HttpStatusCode.BAD_REQUEST
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
*
|
|
821
|
+
* @param err
|
|
822
|
+
*/
|
|
823
|
+
static mongoDbGlobalError(err) {
|
|
824
|
+
const stackTrace = this.traceError(
|
|
825
|
+
err.message,
|
|
826
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
827
|
+
import_opticore_http_response6.HttpStatusCode.NOT_ACCEPTABLE
|
|
828
|
+
);
|
|
829
|
+
this.logger.error(
|
|
830
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnection", import_opticore_translator7.CLocal),
|
|
831
|
+
import_opticore_translator7.TranslationLoader.t("mongoDBConnectionError", import_opticore_translator7.CLocal),
|
|
832
|
+
stackTrace.stack,
|
|
833
|
+
err.message,
|
|
834
|
+
import_opticore_http_response6.HttpStatusCode.NOT_ACCEPTABLE
|
|
835
|
+
);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
*
|
|
839
|
+
* @param props
|
|
840
|
+
* @param name
|
|
841
|
+
* @param status
|
|
842
|
+
* @private
|
|
843
|
+
*/
|
|
844
|
+
static traceError(props, name, status7) {
|
|
845
|
+
return new import_opticore_catch_exception_error3.StackTraceError(props, name, status7, true);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
DbConnexionConfigError.logger = new import_opticore_logger7.LoggerCore(loggerConfig);
|
|
849
|
+
|
|
850
|
+
// src/core/config/database/connexion.config.database.ts
|
|
851
|
+
var import_opticore_catch_exception_error4 = require("opticore-catch-exception-error");
|
|
852
|
+
var DatabaseConnectionConfig = class {
|
|
853
|
+
constructor() {
|
|
854
|
+
this.env = new Environment(import_opticore_env_access3.getEnvVariable);
|
|
855
|
+
this.logger = new import_opticore_logger8.LoggerCore(loggerConfig);
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* MySQL database connection with an optional arguments
|
|
859
|
+
* Establish the connection between app and Database Management System.
|
|
860
|
+
* Inside this class, a checker verifies if database credentials are right,
|
|
861
|
+
* and it's show off in the log that the connection has been created successfully.
|
|
862
|
+
* But if any error is occurring during trying connection, it'd specify that error by stack traces.
|
|
863
|
+
*/
|
|
864
|
+
databaseMySQLConnexionChecker(optionalArgumentConnection) {
|
|
865
|
+
const dbURL = `${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
866
|
+
let url = `mysql://${dbURL}?${optionalArgumentConnection}`;
|
|
867
|
+
const dbConnection = import_mysql.default.createConnection(url);
|
|
868
|
+
return SCheckerMySqlDatabaseConnection(dbConnection, this.env.get("dataBaseUser"), this.env.get("dataBaseName"), this.env.get("dataBaseHost"), this.env.get("dataBasePassword"));
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
*
|
|
872
|
+
* @param optionalArgumentConnection
|
|
873
|
+
*
|
|
874
|
+
* Mongo database connection with optional connection arguments
|
|
875
|
+
*/
|
|
876
|
+
async databaseMongoDBConnectionChecker(optionalArgumentConnection) {
|
|
877
|
+
const dbUrl = `${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
878
|
+
const url = `mongodb://${dbUrl}${optionalArgumentConnection}`;
|
|
879
|
+
try {
|
|
880
|
+
await SCheckerMongoDatabaseConnection(url, this.env.get("dataBaseUser"), this.env.get("dataBasePassword"), this.env.get("dataBaseName"));
|
|
881
|
+
this.logger.success(
|
|
882
|
+
import_opticore_translator8.TranslationLoader.t("mongoDBConnectionChecker", import_opticore_translator8.CLocal),
|
|
883
|
+
import_opticore_translator8.TranslationLoader.t("mongoConnectionSuccess", import_opticore_translator8.CLocal)
|
|
884
|
+
);
|
|
885
|
+
console.log("");
|
|
886
|
+
} catch (e) {
|
|
887
|
+
if (e.code === 18) {
|
|
888
|
+
DbConnexionConfigError.mongoDBAuthenticationFailed(e);
|
|
889
|
+
}
|
|
890
|
+
if (e.cause.code === "ERR_INVALID_URL") {
|
|
891
|
+
DbConnexionConfigError.mongoDBInvalidUrl(e, this.env.get("dataBaseHost"), this.env.get("dataBasePort"));
|
|
892
|
+
}
|
|
893
|
+
if (e.code === void 0) {
|
|
894
|
+
DbConnexionConfigError.mongoDBEaiAgain(e, this.env.get("dataBaseHost"));
|
|
895
|
+
} else {
|
|
896
|
+
DbConnexionConfigError.mongoDbGlobalError(e);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
*
|
|
902
|
+
* @param keepAlive
|
|
903
|
+
* @param stream
|
|
904
|
+
* @param statement_timeout
|
|
905
|
+
* @param ssl
|
|
906
|
+
* @param query_timeout
|
|
907
|
+
* @param keepAliveInitialDelayMillis
|
|
908
|
+
* @param idle_in_transaction_session_timeout
|
|
909
|
+
* @param application_name
|
|
910
|
+
* @param connectionTimeoutMillis
|
|
911
|
+
* @param types
|
|
912
|
+
* @param options
|
|
913
|
+
*
|
|
914
|
+
* Postgres database connection with optional connection arguments
|
|
915
|
+
*/
|
|
916
|
+
async databasePostgresDBConnectionChecker(keepAlive, stream, statement_timeout, ssl, query_timeout, keepAliveInitialDelayMillis, idle_in_transaction_session_timeout, application_name, connectionTimeoutMillis, types, options) {
|
|
917
|
+
const url = `postgresql:/${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
918
|
+
try {
|
|
919
|
+
await SCheckerPostgresDatabaseConnection(
|
|
920
|
+
url,
|
|
921
|
+
keepAlive,
|
|
922
|
+
stream,
|
|
923
|
+
statement_timeout,
|
|
924
|
+
ssl,
|
|
925
|
+
query_timeout,
|
|
926
|
+
keepAliveInitialDelayMillis,
|
|
927
|
+
idle_in_transaction_session_timeout,
|
|
928
|
+
application_name,
|
|
929
|
+
connectionTimeoutMillis,
|
|
930
|
+
types,
|
|
931
|
+
options
|
|
932
|
+
);
|
|
933
|
+
this.logger.success(import_opticore_translator8.TranslationLoader.t("postgresDBConnectionChecker", import_opticore_translator8.CLocal), import_opticore_translator8.TranslationLoader.t("postgresConnectionSuccess", import_opticore_translator8.CLocal));
|
|
934
|
+
console.log("");
|
|
935
|
+
} catch (err) {
|
|
936
|
+
const stackTrace = this.traceError(
|
|
937
|
+
import_opticore_translator8.TranslationLoader.t(`${err.message}`, import_opticore_translator8.CLocal),
|
|
938
|
+
"PostgresConnectionError",
|
|
939
|
+
import_opticore_http_response7.HttpStatusCode.NOT_ACCEPTABLE
|
|
940
|
+
);
|
|
941
|
+
this.logger.error(
|
|
942
|
+
err.message,
|
|
943
|
+
"PostgresConnectionError",
|
|
944
|
+
"Postgres connection error",
|
|
945
|
+
stackTrace.stack,
|
|
946
|
+
import_opticore_http_response7.HttpStatusCode.NOT_ACCEPTABLE
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
traceError(props, name, status7) {
|
|
951
|
+
return new import_opticore_catch_exception_error4.StackTraceError(props, name, status7, true);
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
// src/core/config/database/middleware/mongoChecker.database.ts
|
|
956
|
+
var MMongoCheckerDatabase = (optionalArgumentConnection) => {
|
|
957
|
+
const DbConnexion = new DatabaseConnectionConfig();
|
|
958
|
+
return DbConnexion.databaseMongoDBConnectionChecker(optionalArgumentConnection);
|
|
959
|
+
};
|
|
960
|
+
|
|
961
|
+
// src/core/config/database/middleware/mySqlChecker.database.ts
|
|
962
|
+
var MMySqlCheckerDatabase = (optionalArgumentConnection) => {
|
|
963
|
+
const DbConnexion = new DatabaseConnectionConfig();
|
|
964
|
+
return DbConnexion.databaseMySQLConnexionChecker(optionalArgumentConnection);
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// src/core/config/database/middleware/postgresChecker.database.ts
|
|
968
|
+
var MPostgresCheckerDatabase = (optionalArgumentConnection) => {
|
|
969
|
+
const DbConnexion = new DatabaseConnectionConfig();
|
|
970
|
+
return DbConnexion.databasePostgresDBConnectionChecker(optionalArgumentConnection);
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
// src/utils/utility.utils.ts
|
|
974
|
+
var import_node_process = __toESM(require("process"), 1);
|
|
975
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
976
|
+
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
977
|
+
var import_path = __toESM(require("path"), 1);
|
|
978
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
979
|
+
var import_opticore_translator9 = require("opticore-translator");
|
|
980
|
+
var Utility = class {
|
|
981
|
+
/**
|
|
982
|
+
*
|
|
983
|
+
* @param data
|
|
984
|
+
* @private
|
|
985
|
+
* Return a string converted in MegaBytes
|
|
986
|
+
*/
|
|
987
|
+
formatMemoryUsage(data) {
|
|
988
|
+
return `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Returns an Object containing a node version, openssl, and v0
|
|
992
|
+
*/
|
|
993
|
+
getVersions() {
|
|
994
|
+
const processVers = import_node_process.default.versions;
|
|
995
|
+
const data = {
|
|
996
|
+
"node version": processVers.node,
|
|
997
|
+
"openssl": processVers.openssl,
|
|
998
|
+
"v8": processVers.v8
|
|
999
|
+
};
|
|
1000
|
+
return {
|
|
1001
|
+
"nodeVersion": data["node version"],
|
|
1002
|
+
"openssl": data.openssl,
|
|
1003
|
+
"v8": data.v8
|
|
1004
|
+
};
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
* Return an Object containing a Resident Set Size - total memory allocated for the process execution
|
|
1008
|
+
* Total size of the allocated heap
|
|
1009
|
+
* Actual memory used during the execution
|
|
1010
|
+
* Memory usage user
|
|
1011
|
+
* and Memory usage system
|
|
1012
|
+
*/
|
|
1013
|
+
getUsageMemory() {
|
|
1014
|
+
const memoryData = import_node_process.default.memoryUsage();
|
|
1015
|
+
const data = {
|
|
1016
|
+
"Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
|
|
1017
|
+
"Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
|
|
1018
|
+
"Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
|
|
1019
|
+
"V8 external memory": this.formatMemoryUsage(memoryData.external),
|
|
1020
|
+
"Memory usage user": this.formatMemoryUsage(import_node_process.default.cpuUsage().user),
|
|
1021
|
+
"Memory usage system": this.formatMemoryUsage(import_node_process.default.cpuUsage().system)
|
|
1022
|
+
};
|
|
1023
|
+
return {
|
|
1024
|
+
"rss": data["Resident Set Size - total memory allocated for the process execution"],
|
|
1025
|
+
"heapTotal": data["Total size of the allocated heap"],
|
|
1026
|
+
"heapUsed": data["Actual memory used during the execution"],
|
|
1027
|
+
"external": data["V8 external memory"],
|
|
1028
|
+
"user": data["Memory usage user"],
|
|
1029
|
+
"system": data["Memory usage system"]
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
/**
|
|
1033
|
+
* Return an Object containing a project path and running server time
|
|
1034
|
+
*/
|
|
1035
|
+
getProjectInfo() {
|
|
1036
|
+
const startTime = import_node_process.default.hrtime();
|
|
1037
|
+
const endTime = import_node_process.default.hrtime(startTime);
|
|
1038
|
+
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
1039
|
+
return {
|
|
1040
|
+
"projectPath": import_path.default.join(import_node_process.default.cwd()),
|
|
1041
|
+
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
1042
|
+
};
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
*
|
|
1046
|
+
* @param filePath
|
|
1047
|
+
* @private
|
|
1048
|
+
*/
|
|
1049
|
+
getEnvFileLoading(filePath) {
|
|
1050
|
+
const fullPath = import_path.default.resolve(import_node_process.default.cwd(), filePath);
|
|
1051
|
+
if (import_fs.default.existsSync(fullPath)) {
|
|
1052
|
+
const env = import_fs.default.readFileSync(fullPath, "utf-8");
|
|
1053
|
+
const lines = env.split("\n");
|
|
1054
|
+
lines.forEach((line) => {
|
|
1055
|
+
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
1056
|
+
if (match) {
|
|
1057
|
+
const key = match[1].trim();
|
|
1058
|
+
import_node_process.default.env[key] = match[2].trim();
|
|
1059
|
+
}
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
*
|
|
1065
|
+
* @param development
|
|
1066
|
+
* @param production
|
|
1067
|
+
*/
|
|
1068
|
+
getServerRunningMode(development, production) {
|
|
1069
|
+
this.getEnvFileLoading(".env");
|
|
1070
|
+
const isDevelopment = import_node_process.default.env.NODE_ENV === "development";
|
|
1071
|
+
if (isDevelopment) {
|
|
1072
|
+
return `${import_opticore_translator9.TranslationLoader.t("serverRunning", import_opticore_translator9.CLocal)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${development}`)}`)} mode`;
|
|
1073
|
+
} else {
|
|
1074
|
+
return `${import_opticore_translator9.TranslationLoader.t("serverRunning", import_opticore_translator9.CLocal)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${production}`)}`)} mode`;
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
infoServer(nodeVersion, startingTime, host, port, rss, heapUsed, user, system) {
|
|
1078
|
+
const paddingLength = 52;
|
|
1079
|
+
const msg0 = " ".padEnd(paddingLength, " ");
|
|
1080
|
+
const msg1 = ` ${import_opticore_translator9.TranslationLoader.t("okServerListening", import_opticore_translator9.CLocal)}`;
|
|
1081
|
+
const msg2Value = `${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${nodeVersion}`)}`)}`;
|
|
1082
|
+
const msg2 = ` ${import_opticore_translator9.TranslationLoader.t("webServerUseNodeVersion", import_opticore_translator9.CLocal)}`;
|
|
1083
|
+
const msg3Value = `${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${startingTime}`)}`)}`;
|
|
1084
|
+
const msg3 = ` ${import_opticore_translator9.TranslationLoader.t("startupTime", import_opticore_translator9.CLocal)}`;
|
|
1085
|
+
const msg4 = ` ${this.getServerRunningMode("development", "production")}`;
|
|
1086
|
+
const msg5 = ` ${import_ansi_colors.default.underline(`http://${host}:${port}`)}`;
|
|
1087
|
+
console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
1088
|
+
console.log(import_chalk.default.bgGreen.white(msg1.padEnd(paddingLength, " ")));
|
|
1089
|
+
console.log(import_chalk.default.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
|
|
1090
|
+
console.log(import_chalk.default.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
|
|
1091
|
+
console.log(import_chalk.default.bgGreen.white(msg4.padEnd(71, " ")));
|
|
1092
|
+
console.log(import_chalk.default.bgGreen.white(msg5.padEnd(61, " ")));
|
|
1093
|
+
console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
1094
|
+
console.log(``);
|
|
1095
|
+
console.log(`${`${import_opticore_translator9.TranslationLoader.t("totalMemory", import_opticore_translator9.CLocal)}`} ${import_ansi_colors.default.cyan(`${import_ansi_colors.default.bold(`${rss}`)}`)}`);
|
|
1096
|
+
console.log(`${`${import_opticore_translator9.TranslationLoader.t("memoryUsedDuringExecution", import_opticore_translator9.CLocal)}`} ${import_ansi_colors.default.cyan(`${import_ansi_colors.default.bold(`${heapUsed}`)}`)}`);
|
|
1097
|
+
console.log(`${`${import_opticore_translator9.TranslationLoader.t("memoryUsedByUser", import_opticore_translator9.CLocal)}`} ${import_ansi_colors.default.cyan(`${import_ansi_colors.default.bold(`${user}`)}`)}`);
|
|
1098
|
+
console.log(`${`${import_opticore_translator9.TranslationLoader.t("memoryUsedBySystem", import_opticore_translator9.CLocal)}`} ${import_ansi_colors.default.cyan(`${import_ansi_colors.default.bold(`${system}`)}`)}`);
|
|
1099
|
+
console.log(``);
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// src/core/events/pathModuleVerifier.event.ts
|
|
1104
|
+
var import_path2 = require("path");
|
|
1105
|
+
var import_opticore_logger9 = require("opticore-logger");
|
|
1106
|
+
var import_opticore_http_response8 = require("opticore-http-response");
|
|
1107
|
+
var import_opticore_translator10 = require("opticore-translator");
|
|
1108
|
+
var PathModuleVerifier = class {
|
|
1109
|
+
/**
|
|
1110
|
+
* Verifies if modules at specific paths are loaded.
|
|
1111
|
+
* If any module is not loaded, it throws an error.
|
|
1112
|
+
* @param modulePaths - An array of paths to the modules to verify.
|
|
1113
|
+
*/
|
|
1114
|
+
static verifyModulePaths(modulePaths) {
|
|
1115
|
+
const notLoadedPaths = [];
|
|
1116
|
+
for (const modulePath of modulePaths) {
|
|
1117
|
+
if (!this.isModulePathLoaded(modulePath)) {
|
|
1118
|
+
notLoadedPaths.push(modulePath);
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
if (notLoadedPaths.length > 0) {
|
|
1122
|
+
this.log.error(
|
|
1123
|
+
import_opticore_translator10.TranslationLoader.t("moduleNotLoaded", import_opticore_translator10.CLocal, { notLoadedPaths: notLoadedPaths.join(", ") }),
|
|
1124
|
+
"",
|
|
1125
|
+
"",
|
|
1126
|
+
modulePaths,
|
|
1127
|
+
import_opticore_http_response8.HttpStatusCode.NOT_ACCEPTABLE
|
|
1128
|
+
);
|
|
1129
|
+
throw new Error();
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Checks if a specific module at a given path is loaded in the Node.js require cache.
|
|
1134
|
+
* @param modulePath - The path to the module.
|
|
1135
|
+
* @returns True if the module is loaded, false otherwise.
|
|
1136
|
+
*/
|
|
1137
|
+
static isModulePathLoaded(modulePath) {
|
|
1138
|
+
try {
|
|
1139
|
+
const resolvedPath = (0, import_path2.resolve)(modulePath);
|
|
1140
|
+
return require.cache[resolvedPath] !== void 0;
|
|
1141
|
+
} catch (e) {
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
PathModuleVerifier.log = new import_opticore_logger9.LoggerCore(loggerConfig);
|
|
1147
|
+
|
|
1148
|
+
// src/core/config/loaders/translateLanguage.loader.ts
|
|
1149
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
1150
|
+
var import_opticore_translator11 = require("opticore-translator");
|
|
1151
|
+
var import_opticore_env_access4 = require("opticore-env-access");
|
|
1152
|
+
var translateLanguageLoader = () => {
|
|
1153
|
+
import_opticore_translator11.TranslationLoader.loadTranslations(import_path3.default.join(process.cwd(), "src", "utils", "translations"), import_opticore_env_access4.getEnvVariable.defaultLocal);
|
|
1154
|
+
};
|
|
1155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1156
|
+
0 && (module.exports = {
|
|
1157
|
+
CLogLevel,
|
|
1158
|
+
CSignRSAKeyComponent,
|
|
1159
|
+
Environment,
|
|
1160
|
+
MMongoCheckerDatabase,
|
|
1161
|
+
MMySqlCheckerDatabase,
|
|
1162
|
+
MPostgresCheckerDatabase,
|
|
1163
|
+
PathModuleVerifier,
|
|
1164
|
+
RSAKeyDecryption,
|
|
1165
|
+
RSAKeyEncryption,
|
|
1166
|
+
SAsymmetricCryptionDataWithPrivateRSAKey,
|
|
1167
|
+
SAsymmetricCryptionDataWithPublicRSAKey,
|
|
1168
|
+
SCheckerMongoDatabaseConnection,
|
|
1169
|
+
SCheckerMySqlDatabaseConnection,
|
|
1170
|
+
SCheckerPostgresDatabaseConnection,
|
|
1171
|
+
Utility,
|
|
1172
|
+
YamlParsing,
|
|
1173
|
+
dateTimeFormatted,
|
|
1174
|
+
loggerConfig,
|
|
1175
|
+
optionalArgumentConnectionUtil,
|
|
1176
|
+
translateLanguageLoader
|
|
1177
|
+
});
|