opticore-webapp-core 1.0.8 → 1.0.10
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 +153 -147
- package/dist/index.d.cts +33 -34
- package/dist/index.d.ts +33 -34
- package/dist/index.js +153 -147
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -173,27 +173,30 @@ var SLoggerFileConfiguration = () => {
|
|
|
173
173
|
|
|
174
174
|
// src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts
|
|
175
175
|
var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
176
|
-
|
|
176
|
+
log = SLoggerFileConfiguration();
|
|
177
|
+
localeLanguage;
|
|
178
|
+
constructor(localeLanguage) {
|
|
179
|
+
this.localeLanguage = localeLanguage;
|
|
180
|
+
}
|
|
177
181
|
/**
|
|
178
182
|
*
|
|
179
183
|
* @param rsaKey
|
|
180
184
|
* @param keyType
|
|
181
|
-
* @param localeLanguage
|
|
182
185
|
* @protected
|
|
183
186
|
*
|
|
184
187
|
* Return ErrorHandler | string
|
|
185
188
|
*/
|
|
186
|
-
|
|
189
|
+
verifyExistingKey(rsaKey, keyType) {
|
|
187
190
|
if (!rsaKey) {
|
|
188
191
|
const stackTrace = this.traceError(
|
|
189
|
-
keyType + " " + TranslationLoader.t("rsaKeyNotFound", localeLanguage, this.log),
|
|
190
|
-
TranslationLoader.t("erBadDbError", localeLanguage, this.log),
|
|
192
|
+
keyType + " " + TranslationLoader.t("rsaKeyNotFound", this.localeLanguage, this.log),
|
|
193
|
+
TranslationLoader.t("erBadDbError", this.localeLanguage, this.log),
|
|
191
194
|
status.NOT_FOUND
|
|
192
195
|
);
|
|
193
196
|
this.log.error(
|
|
194
|
-
TranslationLoader.t("rsaKeyNotFound", localeLanguage, this.log),
|
|
195
|
-
TranslationLoader.t("verifyExistingKey", localeLanguage, this.log),
|
|
196
|
-
TranslationLoader.t("erBadDbError", localeLanguage, this.log),
|
|
197
|
+
TranslationLoader.t("rsaKeyNotFound", this.localeLanguage, this.log),
|
|
198
|
+
TranslationLoader.t("verifyExistingKey", this.localeLanguage, this.log),
|
|
199
|
+
TranslationLoader.t("erBadDbError", this.localeLanguage, this.log),
|
|
197
200
|
stackTrace.stack,
|
|
198
201
|
status.NOT_FOUND
|
|
199
202
|
);
|
|
@@ -205,26 +208,25 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
205
208
|
*
|
|
206
209
|
* @param privateKey
|
|
207
210
|
* @param payload
|
|
208
|
-
* @param localeLanguage
|
|
209
211
|
* @private
|
|
210
212
|
*
|
|
211
213
|
* Return Buffer
|
|
212
214
|
*/
|
|
213
|
-
|
|
214
|
-
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private
|
|
215
|
+
encryptionWithPrivateKey(privateKey, payload) {
|
|
216
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
215
217
|
try {
|
|
216
218
|
const bufferedData = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
217
219
|
return RSAKeyEncryption.privateEncrypt(privateKey, bufferedData);
|
|
218
220
|
} catch (err) {
|
|
219
221
|
const stackTrace = this.traceError(
|
|
220
|
-
TranslationLoader.t("encryptionWithPrivateKeyFailed", localeLanguage, this.log),
|
|
221
|
-
TranslationLoader.t("encryptionFailed", localeLanguage, this.log),
|
|
222
|
+
TranslationLoader.t("encryptionWithPrivateKeyFailed", this.localeLanguage, this.log),
|
|
223
|
+
TranslationLoader.t("encryptionFailed", this.localeLanguage, this.log),
|
|
222
224
|
status.NOT_FOUND
|
|
223
225
|
);
|
|
224
226
|
this.log.error(
|
|
225
227
|
err.message,
|
|
226
|
-
TranslationLoader.t("encryptionFailed", localeLanguage, this.log),
|
|
227
|
-
TranslationLoader.t("encryptionWithPrivateKeyFailed", localeLanguage, this.log),
|
|
228
|
+
TranslationLoader.t("encryptionFailed", this.localeLanguage, this.log),
|
|
229
|
+
TranslationLoader.t("encryptionWithPrivateKeyFailed", this.localeLanguage, this.log),
|
|
228
230
|
stackTrace.stack,
|
|
229
231
|
status.NOT_FOUND
|
|
230
232
|
);
|
|
@@ -236,25 +238,24 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
236
238
|
* @param privateKey
|
|
237
239
|
* @param publicKey
|
|
238
240
|
* @param payload
|
|
239
|
-
* @param localeLanguage
|
|
240
241
|
* @private
|
|
241
242
|
*/
|
|
242
|
-
|
|
243
|
-
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public
|
|
243
|
+
decryptionWithPublicKey(privateKey, publicKey, payload) {
|
|
244
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
244
245
|
try {
|
|
245
|
-
const encryptedPayload = this.encryptionWithPrivateKey(privateKey, payload
|
|
246
|
+
const encryptedPayload = this.encryptionWithPrivateKey(privateKey, payload);
|
|
246
247
|
return RSAKeyDecryption.publicDecrypt(publicKey, encryptedPayload);
|
|
247
248
|
} catch (error) {
|
|
248
249
|
const stackTrace = this.traceError(
|
|
249
|
-
TranslationLoader.t("errorDecryption", localeLanguage, this.log),
|
|
250
|
-
TranslationLoader.t("decryptionFailed", localeLanguage, this.log),
|
|
250
|
+
TranslationLoader.t("errorDecryption", this.localeLanguage, this.log),
|
|
251
|
+
TranslationLoader.t("decryptionFailed", this.localeLanguage, this.log),
|
|
251
252
|
status.NOT_ACCEPTABLE
|
|
252
253
|
);
|
|
253
254
|
this.log.error(
|
|
254
|
-
TranslationLoader.t("decryptionWithPublicKeyFailed", localeLanguage, this.log),
|
|
255
|
-
TranslationLoader.t("decryptionFailed", localeLanguage, this.log),
|
|
255
|
+
TranslationLoader.t("decryptionWithPublicKeyFailed", this.localeLanguage, this.log),
|
|
256
|
+
TranslationLoader.t("decryptionFailed", this.localeLanguage, this.log),
|
|
256
257
|
stackTrace.stack,
|
|
257
|
-
TranslationLoader.t("errorDecryption", localeLanguage, this.log),
|
|
258
|
+
TranslationLoader.t("errorDecryption", this.localeLanguage, this.log),
|
|
258
259
|
status.NOT_ACCEPTABLE
|
|
259
260
|
);
|
|
260
261
|
throw new Error();
|
|
@@ -264,11 +265,10 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
264
265
|
*
|
|
265
266
|
* @param privateKey
|
|
266
267
|
* @param payload
|
|
267
|
-
* @param localeLanguage
|
|
268
268
|
* @private
|
|
269
269
|
*/
|
|
270
|
-
|
|
271
|
-
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private
|
|
270
|
+
signWithRSAKey(privateKey, payload) {
|
|
271
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
272
272
|
const sign = crypto3.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
273
273
|
sign.update(payload);
|
|
274
274
|
return sign.sign(privateKey, CSignRSAKeyComponent.outputFormat.base64);
|
|
@@ -278,28 +278,27 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
278
278
|
* @param privateKey
|
|
279
279
|
* @param publicKey
|
|
280
280
|
* @param payload
|
|
281
|
-
* @param localeLanguage
|
|
282
281
|
*/
|
|
283
|
-
|
|
282
|
+
verifyRSAKey(privateKey, publicKey, payload) {
|
|
284
283
|
try {
|
|
285
284
|
const verify = crypto3.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
286
285
|
verify.update(payload);
|
|
287
|
-
const signature = this.signWithRSAKey(privateKey, payload
|
|
286
|
+
const signature = this.signWithRSAKey(privateKey, payload);
|
|
288
287
|
const isVerified = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64);
|
|
289
288
|
if (isVerified) {
|
|
290
|
-
const decryptedData = this.decryptionWithPublicKey(privateKey, publicKey, payload
|
|
289
|
+
const decryptedData = this.decryptionWithPublicKey(privateKey, publicKey, payload);
|
|
291
290
|
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8);
|
|
292
291
|
} else {
|
|
293
292
|
const stackTrace = this.traceError(
|
|
294
|
-
TranslationLoader.t("signatureRSAKeyFailed", localeLanguage, this.log),
|
|
295
|
-
TranslationLoader.t("verifyRSAKeyFailed", localeLanguage, this.log),
|
|
293
|
+
TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage, this.log),
|
|
294
|
+
TranslationLoader.t("verifyRSAKeyFailed", this.localeLanguage, this.log),
|
|
296
295
|
status.NOT_ACCEPTABLE
|
|
297
296
|
);
|
|
298
297
|
this.log.error(
|
|
299
|
-
TranslationLoader.t("verifyRSAKey", localeLanguage, this.log),
|
|
300
|
-
TranslationLoader.t("verifyRSAKeyFailed", localeLanguage, this.log),
|
|
298
|
+
TranslationLoader.t("verifyRSAKey", this.localeLanguage, this.log),
|
|
299
|
+
TranslationLoader.t("verifyRSAKeyFailed", this.localeLanguage, this.log),
|
|
301
300
|
stackTrace.stack,
|
|
302
|
-
TranslationLoader.t("signatureRSAKeyFailed", localeLanguage, this.log),
|
|
301
|
+
TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage, this.log),
|
|
303
302
|
status.NOT_FOUND
|
|
304
303
|
);
|
|
305
304
|
return new Error();
|
|
@@ -307,12 +306,12 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
307
306
|
} catch (err) {
|
|
308
307
|
const stackTrace = this.traceError(
|
|
309
308
|
err.name,
|
|
310
|
-
TranslationLoader.t("signatureRSAKeysError", localeLanguage, this.log),
|
|
309
|
+
TranslationLoader.t("signatureRSAKeysError", this.localeLanguage, this.log),
|
|
311
310
|
status.NOT_ACCEPTABLE
|
|
312
311
|
);
|
|
313
312
|
this.log.error(
|
|
314
|
-
TranslationLoader.t("signatureRSAKeysError", localeLanguage, this.log),
|
|
315
|
-
TranslationLoader.t("errorNameNotVerifyingRSAKey", localeLanguage, this.log),
|
|
313
|
+
TranslationLoader.t("signatureRSAKeysError", this.localeLanguage, this.log),
|
|
314
|
+
TranslationLoader.t("errorNameNotVerifyingRSAKey", this.localeLanguage, this.log),
|
|
316
315
|
stackTrace.stack,
|
|
317
316
|
err.message,
|
|
318
317
|
status.NOT_FOUND
|
|
@@ -327,7 +326,7 @@ var SAsymmetricCryptionDataWithPrivateRSAKey = class {
|
|
|
327
326
|
* @param status
|
|
328
327
|
* @private
|
|
329
328
|
*/
|
|
330
|
-
|
|
329
|
+
traceError(props, name, status7) {
|
|
331
330
|
return new ErrorHandler(props, name, status7, true);
|
|
332
331
|
}
|
|
333
332
|
};
|
|
@@ -338,26 +337,30 @@ import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
|
338
337
|
import { HttpStatusCode as status2 } from "opticore-http-response";
|
|
339
338
|
import { StackTraceError } from "opticore-catch-exception-error";
|
|
340
339
|
var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
341
|
-
|
|
340
|
+
logger = SLoggerFileConfiguration();
|
|
341
|
+
localeLanguage;
|
|
342
|
+
constructor(localeLanguage) {
|
|
343
|
+
this.localeLanguage = localeLanguage;
|
|
344
|
+
}
|
|
342
345
|
/**
|
|
343
346
|
*
|
|
344
347
|
* @param rsaKey
|
|
345
348
|
* @param keyType
|
|
346
|
-
*
|
|
349
|
+
*
|
|
347
350
|
* @protected
|
|
348
351
|
*/
|
|
349
|
-
|
|
352
|
+
verifyExistingKey(rsaKey, keyType) {
|
|
350
353
|
if (!rsaKey) {
|
|
351
354
|
const stackTrace = this.traceError(
|
|
352
|
-
keyType + TranslationLoader2.t("verifyExistingKey", localeLanguage, this.logger),
|
|
353
|
-
TranslationLoader2.t("verifyExistingKey", localeLanguage, this.logger),
|
|
355
|
+
keyType + TranslationLoader2.t("verifyExistingKey", this.localeLanguage, this.logger),
|
|
356
|
+
TranslationLoader2.t("verifyExistingKey", this.localeLanguage, this.logger),
|
|
354
357
|
status2.NOT_FOUND
|
|
355
358
|
);
|
|
356
359
|
this.logger.error(
|
|
357
|
-
TranslationLoader2.t("verifyExistingKey", localeLanguage, this.logger),
|
|
360
|
+
TranslationLoader2.t("verifyExistingKey", this.localeLanguage, this.logger),
|
|
358
361
|
"key verification",
|
|
359
362
|
stackTrace.stack,
|
|
360
|
-
TranslationLoader2.t("verifyExistingKeyError", localeLanguage, this.logger),
|
|
363
|
+
TranslationLoader2.t("verifyExistingKeyError", this.localeLanguage, this.logger),
|
|
361
364
|
status2.NOT_FOUND
|
|
362
365
|
);
|
|
363
366
|
return new Error();
|
|
@@ -368,23 +371,23 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
368
371
|
*
|
|
369
372
|
* @param publicKey
|
|
370
373
|
* @param payload
|
|
371
|
-
*
|
|
374
|
+
*
|
|
372
375
|
* @private
|
|
373
376
|
*/
|
|
374
|
-
|
|
375
|
-
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public
|
|
377
|
+
encryptionWithPublicKey(publicKey, payload) {
|
|
378
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
376
379
|
try {
|
|
377
380
|
const bufferedData = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
378
381
|
return RSAKeyEncryption.publicEncrypt(publicKey, bufferedData);
|
|
379
382
|
} catch (err) {
|
|
380
383
|
const stackTrace = this.traceError(
|
|
381
384
|
err.message,
|
|
382
|
-
TranslationLoader2.t("encryptionWithPublicKey", localeLanguage, this.logger),
|
|
385
|
+
TranslationLoader2.t("encryptionWithPublicKey", this.localeLanguage, this.logger),
|
|
383
386
|
status2.NOT_ACCEPTABLE
|
|
384
387
|
);
|
|
385
388
|
this.logger.error(
|
|
386
|
-
TranslationLoader2.t("errorEncryptionPublicKey", localeLanguage, this.logger),
|
|
387
|
-
TranslationLoader2.t("encryptionWithPublicKey", localeLanguage, this.logger),
|
|
389
|
+
TranslationLoader2.t("errorEncryptionPublicKey", this.localeLanguage, this.logger),
|
|
390
|
+
TranslationLoader2.t("encryptionWithPublicKey", this.localeLanguage, this.logger),
|
|
388
391
|
stackTrace.stack,
|
|
389
392
|
err.message,
|
|
390
393
|
status2.NOT_ACCEPTABLE
|
|
@@ -397,23 +400,23 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
397
400
|
* @param privateKey
|
|
398
401
|
* @param publicKey
|
|
399
402
|
* @param payload
|
|
400
|
-
*
|
|
403
|
+
*
|
|
401
404
|
* @private
|
|
402
405
|
*/
|
|
403
|
-
|
|
404
|
-
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public
|
|
406
|
+
decryptionWithPrivateKey(privateKey, publicKey, payload) {
|
|
407
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
405
408
|
try {
|
|
406
|
-
const encryptedPayload = this.encryptionWithPublicKey(publicKey, payload
|
|
409
|
+
const encryptedPayload = this.encryptionWithPublicKey(publicKey, payload);
|
|
407
410
|
return RSAKeyDecryption.privateDecrypt(privateKey, encryptedPayload);
|
|
408
411
|
} catch (err) {
|
|
409
412
|
const stackTrace = this.traceError(
|
|
410
413
|
err.code,
|
|
411
|
-
TranslationLoader2.t("errorDecryption", localeLanguage, this.logger),
|
|
414
|
+
TranslationLoader2.t("errorDecryption", this.localeLanguage, this.logger),
|
|
412
415
|
status2.NOT_ACCEPTABLE
|
|
413
416
|
);
|
|
414
417
|
this.logger.error(
|
|
415
|
-
TranslationLoader2.t("errorDecryptionWithPrivateKey", localeLanguage, this.logger),
|
|
416
|
-
TranslationLoader2.t("errorDecryption", localeLanguage, this.logger),
|
|
418
|
+
TranslationLoader2.t("errorDecryptionWithPrivateKey", this.localeLanguage, this.logger),
|
|
419
|
+
TranslationLoader2.t("errorDecryption", this.localeLanguage, this.logger),
|
|
417
420
|
stackTrace.stack,
|
|
418
421
|
err.message,
|
|
419
422
|
status2.NOT_ACCEPTABLE
|
|
@@ -425,11 +428,11 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
425
428
|
*
|
|
426
429
|
* @param publicKey
|
|
427
430
|
* @param payload
|
|
428
|
-
*
|
|
431
|
+
*
|
|
429
432
|
* @private
|
|
430
433
|
*/
|
|
431
|
-
|
|
432
|
-
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.private
|
|
434
|
+
signWithPublicRSAKey(publicKey, payload) {
|
|
435
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.private);
|
|
433
436
|
const sign = crypto4.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
434
437
|
sign.update(payload);
|
|
435
438
|
return sign.sign(publicKey, CSignRSAKeyComponent.outputFormat.base64);
|
|
@@ -439,28 +442,28 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
439
442
|
* @param privateKey
|
|
440
443
|
* @param publicKey
|
|
441
444
|
* @param payload
|
|
442
|
-
*
|
|
445
|
+
*
|
|
443
446
|
*/
|
|
444
|
-
|
|
447
|
+
verifyPublicRSAKey(privateKey, publicKey, payload) {
|
|
445
448
|
try {
|
|
446
449
|
const verify = crypto4.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
447
450
|
verify.update(payload);
|
|
448
|
-
const signature = this.signWithPublicRSAKey(publicKey, payload
|
|
451
|
+
const signature = this.signWithPublicRSAKey(publicKey, payload);
|
|
449
452
|
const isVerified = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64);
|
|
450
453
|
if (isVerified) {
|
|
451
|
-
const decryptedData = this.decryptionWithPrivateKey(privateKey, publicKey, payload
|
|
454
|
+
const decryptedData = this.decryptionWithPrivateKey(privateKey, publicKey, payload);
|
|
452
455
|
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8);
|
|
453
456
|
} else {
|
|
454
457
|
const stackTrace = this.traceError(
|
|
455
|
-
TranslationLoader2.t("verifyPublicRSAKeyError", localeLanguage, this.logger),
|
|
456
|
-
TranslationLoader2.t("signatureRSAKeyFailed", localeLanguage, this.logger),
|
|
458
|
+
TranslationLoader2.t("verifyPublicRSAKeyError", this.localeLanguage, this.logger),
|
|
459
|
+
TranslationLoader2.t("signatureRSAKeyFailed", this.localeLanguage, this.logger),
|
|
457
460
|
status2.NOT_FOUND
|
|
458
461
|
);
|
|
459
462
|
this.logger.error(
|
|
460
|
-
TranslationLoader2.t("verifyPublicRSAKey", localeLanguage, this.logger),
|
|
461
|
-
TranslationLoader2.t("signatureRSAKeyFailed", localeLanguage, this.logger),
|
|
463
|
+
TranslationLoader2.t("verifyPublicRSAKey", this.localeLanguage, this.logger),
|
|
464
|
+
TranslationLoader2.t("signatureRSAKeyFailed", this.localeLanguage, this.logger),
|
|
462
465
|
stackTrace.stack,
|
|
463
|
-
TranslationLoader2.t("verifyPublicRSAKeyError", localeLanguage, this.logger),
|
|
466
|
+
TranslationLoader2.t("verifyPublicRSAKeyError", this.localeLanguage, this.logger),
|
|
464
467
|
status2.NOT_FOUND
|
|
465
468
|
);
|
|
466
469
|
return stackTrace;
|
|
@@ -468,12 +471,12 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
468
471
|
} catch (err) {
|
|
469
472
|
const stackTrace = this.traceError(
|
|
470
473
|
err.code,
|
|
471
|
-
TranslationLoader2.t("verifyPublicRSAKey", localeLanguage, this.logger),
|
|
474
|
+
TranslationLoader2.t("verifyPublicRSAKey", this.localeLanguage, this.logger),
|
|
472
475
|
status2.NOT_ACCEPTABLE
|
|
473
476
|
);
|
|
474
477
|
this.logger.error(
|
|
475
|
-
TranslationLoader2.t("verifyPublicRSAKey", localeLanguage, this.logger),
|
|
476
|
-
TranslationLoader2.t("errorDecryption", localeLanguage, this.logger),
|
|
478
|
+
TranslationLoader2.t("verifyPublicRSAKey", this.localeLanguage, this.logger),
|
|
479
|
+
TranslationLoader2.t("errorDecryption", this.localeLanguage, this.logger),
|
|
477
480
|
stackTrace.stack,
|
|
478
481
|
err.message,
|
|
479
482
|
status2.NOT_ACCEPTABLE
|
|
@@ -481,7 +484,7 @@ var SAsymmetricCryptionDataWithPublicRSAKey = class {
|
|
|
481
484
|
throw new Error();
|
|
482
485
|
}
|
|
483
486
|
}
|
|
484
|
-
|
|
487
|
+
traceError(props, name, status7) {
|
|
485
488
|
return new StackTraceError(props, name, status7, true);
|
|
486
489
|
}
|
|
487
490
|
};
|
|
@@ -660,22 +663,21 @@ var translateWebAppCoreLanguageLoader = () => {
|
|
|
660
663
|
|
|
661
664
|
// src/utils/parsing/parsingYaml.utils.ts
|
|
662
665
|
var YamlParsing = class {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
translateWebAppCoreLanguageLoader();
|
|
666
|
+
logger = new LoggerCore3(loggerConfig);
|
|
667
|
+
localeLanguage;
|
|
668
|
+
constructor(localeLanguage) {
|
|
667
669
|
this.localeLanguage = localeLanguage;
|
|
668
|
-
|
|
670
|
+
translateWebAppCoreLanguageLoader();
|
|
669
671
|
}
|
|
670
|
-
|
|
672
|
+
async readFile(filePath) {
|
|
671
673
|
try {
|
|
672
674
|
const yamlContent = await readFile(filePath, "utf-8");
|
|
673
|
-
await this.parsing(yamlContent
|
|
675
|
+
await this.parsing(yamlContent);
|
|
674
676
|
} catch (error) {
|
|
675
677
|
this.logger.error(
|
|
676
678
|
error.message,
|
|
677
|
-
TranslationLoader7.t("parsingFailed", localeLanguage, this.logger),
|
|
678
|
-
TranslationLoader7.t("readingError", localeLanguage, this.logger),
|
|
679
|
+
TranslationLoader7.t("parsingFailed", this.localeLanguage, this.logger),
|
|
680
|
+
TranslationLoader7.t("readingError", this.localeLanguage, this.logger),
|
|
679
681
|
error.stack,
|
|
680
682
|
HttpStatusCode.NOT_ACCEPTABLE
|
|
681
683
|
);
|
|
@@ -684,10 +686,9 @@ var YamlParsing = class {
|
|
|
684
686
|
/**
|
|
685
687
|
*
|
|
686
688
|
* @param content
|
|
687
|
-
* @param localeLanguage
|
|
688
689
|
* @private
|
|
689
690
|
*/
|
|
690
|
-
|
|
691
|
+
async parsing(content) {
|
|
691
692
|
const result = {};
|
|
692
693
|
const lines = content.split("\n");
|
|
693
694
|
let currentKey = null;
|
|
@@ -707,9 +708,9 @@ var YamlParsing = class {
|
|
|
707
708
|
}
|
|
708
709
|
} else {
|
|
709
710
|
this.logger.error(
|
|
710
|
-
TranslationLoader7.t("badFormat", localeLanguage, { line }),
|
|
711
|
-
TranslationLoader7.t("parsingFailed", localeLanguage, this.logger),
|
|
712
|
-
TranslationLoader7.t("unsupportedFormat", localeLanguage, this.logger),
|
|
711
|
+
TranslationLoader7.t("badFormat", this.localeLanguage, { line }),
|
|
712
|
+
TranslationLoader7.t("parsingFailed", this.localeLanguage, this.logger),
|
|
713
|
+
TranslationLoader7.t("unsupportedFormat", this.localeLanguage, this.logger),
|
|
713
714
|
content,
|
|
714
715
|
HttpStatusCode.NOT_ACCEPTABLE
|
|
715
716
|
);
|
|
@@ -746,81 +747,81 @@ import { LoggerCore as LoggerCore4 } from "opticore-logger";
|
|
|
746
747
|
import { StackTraceError as StackTraceError2 } from "opticore-catch-exception-error";
|
|
747
748
|
import { TranslationLoader as TranslationLoader8 } from "opticore-translator";
|
|
748
749
|
var DbConnexionConfigError = class {
|
|
749
|
-
|
|
750
|
+
logger = new LoggerCore4(loggerConfig);
|
|
751
|
+
localeLanguage;
|
|
752
|
+
constructor(localeLanguage) {
|
|
753
|
+
this.localeLanguage = localeLanguage;
|
|
754
|
+
}
|
|
750
755
|
/**
|
|
751
756
|
*
|
|
752
|
-
* @param localLanguage
|
|
753
757
|
* @param e
|
|
754
758
|
*/
|
|
755
|
-
|
|
759
|
+
mongoDBAuthenticationFailed(e) {
|
|
756
760
|
const stackTrace = this.traceError(
|
|
757
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
758
|
-
TranslationLoader8.t("mongoDBAuthentication",
|
|
761
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage, { e }),
|
|
762
|
+
TranslationLoader8.t("mongoDBAuthentication", this.localeLanguage),
|
|
759
763
|
status5.UNAUTHORIZED
|
|
760
764
|
);
|
|
761
765
|
this.logger.error(
|
|
762
|
-
TranslationLoader8.t("mongoDBAuthenticationError",
|
|
763
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
764
|
-
TranslationLoader8.t("mongoDBAuthenticationFailed",
|
|
766
|
+
TranslationLoader8.t("mongoDBAuthenticationError", this.localeLanguage),
|
|
767
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage),
|
|
768
|
+
TranslationLoader8.t("mongoDBAuthenticationFailed", this.localeLanguage),
|
|
765
769
|
stackTrace.stack,
|
|
766
770
|
status5.UNAUTHORIZED
|
|
767
771
|
);
|
|
768
772
|
}
|
|
769
773
|
/**
|
|
770
774
|
*
|
|
771
|
-
* @param localLanguage
|
|
772
775
|
* @param err
|
|
773
776
|
* @param dbHost
|
|
774
777
|
* @param dbPort
|
|
775
778
|
*/
|
|
776
|
-
|
|
779
|
+
mongoDBInvalidUrl(err, dbHost, dbPort) {
|
|
777
780
|
const stackTrace = this.traceError(
|
|
778
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
779
|
-
TranslationLoader8.t("mongoDBUnableParsingUrl",
|
|
781
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage, { err }),
|
|
782
|
+
TranslationLoader8.t("mongoDBUnableParsingUrl", this.localeLanguage),
|
|
780
783
|
status5.BAD_REQUEST
|
|
781
784
|
);
|
|
782
785
|
this.logger.error(
|
|
783
|
-
TranslationLoader8.t("dbUrlParsingError",
|
|
784
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
785
|
-
TranslationLoader8.t("mongoDBUnableParsingUrl",
|
|
786
|
+
TranslationLoader8.t("dbUrlParsingError", this.localeLanguage, { dbHost, dbPort }),
|
|
787
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage),
|
|
788
|
+
TranslationLoader8.t("mongoDBUnableParsingUrl", this.localeLanguage),
|
|
786
789
|
stackTrace.stack,
|
|
787
790
|
status5.BAD_REQUEST
|
|
788
791
|
);
|
|
789
792
|
}
|
|
790
793
|
/**
|
|
791
794
|
*
|
|
792
|
-
* @param localLanguage
|
|
793
795
|
* @param err
|
|
794
796
|
* @param dbHost
|
|
795
797
|
*/
|
|
796
|
-
|
|
798
|
+
mongoDBEaiAgain(err, dbHost) {
|
|
797
799
|
const stackTrace = this.traceError(
|
|
798
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
799
|
-
TranslationLoader8.t("mongoDBServerSelection",
|
|
800
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage, { err }),
|
|
801
|
+
TranslationLoader8.t("mongoDBServerSelection", this.localeLanguage),
|
|
800
802
|
status5.BAD_REQUEST
|
|
801
803
|
);
|
|
802
804
|
this.logger.error(
|
|
803
|
-
TranslationLoader8.t("mongoServerError",
|
|
804
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
805
|
-
TranslationLoader8.t("mongoDBServerSelection",
|
|
805
|
+
TranslationLoader8.t("mongoServerError", this.localeLanguage, { dbHost }),
|
|
806
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage),
|
|
807
|
+
TranslationLoader8.t("mongoDBServerSelection", this.localeLanguage),
|
|
806
808
|
stackTrace.stack,
|
|
807
809
|
status5.BAD_REQUEST
|
|
808
810
|
);
|
|
809
811
|
}
|
|
810
812
|
/**
|
|
811
813
|
*
|
|
812
|
-
* @param localLanguage
|
|
813
814
|
* @param err
|
|
814
815
|
*/
|
|
815
|
-
|
|
816
|
+
mongoDbGlobalError(err) {
|
|
816
817
|
const stackTrace = this.traceError(
|
|
817
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
818
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
818
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage, { err }),
|
|
819
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage),
|
|
819
820
|
status5.NOT_ACCEPTABLE
|
|
820
821
|
);
|
|
821
822
|
this.logger.error(
|
|
822
|
-
TranslationLoader8.t("mongoDBConnection",
|
|
823
|
-
TranslationLoader8.t("mongoDBConnectionError",
|
|
823
|
+
TranslationLoader8.t("mongoDBConnection", this.localeLanguage),
|
|
824
|
+
TranslationLoader8.t("mongoDBConnectionError", this.localeLanguage),
|
|
824
825
|
stackTrace.stack,
|
|
825
826
|
err.message,
|
|
826
827
|
status5.NOT_ACCEPTABLE
|
|
@@ -833,7 +834,7 @@ var DbConnexionConfigError = class {
|
|
|
833
834
|
* @param status
|
|
834
835
|
* @private
|
|
835
836
|
*/
|
|
836
|
-
|
|
837
|
+
traceError(props, name, status7) {
|
|
837
838
|
return new StackTraceError2(props, name, status7, true);
|
|
838
839
|
}
|
|
839
840
|
};
|
|
@@ -843,10 +844,15 @@ import { StackTraceError as ErrorHandler2 } from "opticore-catch-exception-error
|
|
|
843
844
|
var DatabaseConnectionConfig = class {
|
|
844
845
|
env = new Environment(getEnvVariable3);
|
|
845
846
|
logger = new LoggerCore5(loggerConfig);
|
|
847
|
+
localeLanguage;
|
|
848
|
+
DbConnexionConfigError;
|
|
849
|
+
constructor(localeLanguage) {
|
|
850
|
+
this.localeLanguage = localeLanguage;
|
|
851
|
+
this.DbConnexionConfigError = new DbConnexionConfigError(localeLanguage);
|
|
852
|
+
}
|
|
846
853
|
/**
|
|
847
854
|
*
|
|
848
855
|
* @param optionalArgumentConnection
|
|
849
|
-
* @param localeLanguage
|
|
850
856
|
*
|
|
851
857
|
* MySQL database connection with an optional arguments
|
|
852
858
|
* Establish the connection between app and Database Management System.
|
|
@@ -854,46 +860,44 @@ var DatabaseConnectionConfig = class {
|
|
|
854
860
|
* and it's show off in the log that the connection has been created successfully.
|
|
855
861
|
* But if any error is occurring during trying connection, it'd specify that error by stack traces.
|
|
856
862
|
*/
|
|
857
|
-
databaseMySQLConnexionChecker(optionalArgumentConnection
|
|
863
|
+
databaseMySQLConnexionChecker(optionalArgumentConnection) {
|
|
858
864
|
const dbURL = `${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
859
865
|
let url = `mysql://${dbURL}?${optionalArgumentConnection}`;
|
|
860
866
|
const dbConnection = mySQL.createConnection(url);
|
|
861
|
-
return SCheckerMySqlDatabaseConnection(localeLanguage, dbConnection, this.env.get("dataBaseUser"), this.env.get("dataBaseName"), this.env.get("dataBaseHost"), this.env.get("dataBasePassword"));
|
|
867
|
+
return SCheckerMySqlDatabaseConnection(this.localeLanguage, dbConnection, this.env.get("dataBaseUser"), this.env.get("dataBaseName"), this.env.get("dataBaseHost"), this.env.get("dataBasePassword"));
|
|
862
868
|
}
|
|
863
869
|
/**
|
|
864
870
|
*
|
|
865
871
|
* @param optionalArgumentConnection
|
|
866
|
-
* @param localeLanguage
|
|
867
872
|
*
|
|
868
873
|
* Mongo database connection with optional connection arguments
|
|
869
874
|
*/
|
|
870
|
-
async databaseMongoDBConnectionChecker(optionalArgumentConnection
|
|
875
|
+
async databaseMongoDBConnectionChecker(optionalArgumentConnection) {
|
|
871
876
|
const dbUrl = `${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
872
877
|
const url = `mongodb://${dbUrl}${optionalArgumentConnection}`;
|
|
873
878
|
try {
|
|
874
879
|
await SCheckerMongoDatabaseConnection(url, this.env.get("dataBaseUser"), this.env.get("dataBasePassword"), this.env.get("dataBaseName"));
|
|
875
880
|
this.logger.success(
|
|
876
|
-
TranslationLoader9.t("mongoDBConnectionChecker", localeLanguage, loggerConfig),
|
|
877
|
-
TranslationLoader9.t("mongoConnectionSuccess", localeLanguage, loggerConfig)
|
|
881
|
+
TranslationLoader9.t("mongoDBConnectionChecker", this.localeLanguage, loggerConfig),
|
|
882
|
+
TranslationLoader9.t("mongoConnectionSuccess", this.localeLanguage, loggerConfig)
|
|
878
883
|
);
|
|
879
884
|
console.log("");
|
|
880
885
|
} catch (e) {
|
|
881
886
|
if (e.code === 18) {
|
|
882
|
-
DbConnexionConfigError.mongoDBAuthenticationFailed(e);
|
|
887
|
+
this.DbConnexionConfigError.mongoDBAuthenticationFailed(e);
|
|
883
888
|
}
|
|
884
889
|
if (e.cause.code === "ERR_INVALID_URL") {
|
|
885
|
-
DbConnexionConfigError.mongoDBInvalidUrl(e, this.env.get("dataBaseHost"), this.env.get("dataBasePort"));
|
|
890
|
+
this.DbConnexionConfigError.mongoDBInvalidUrl(e, this.env.get("dataBaseHost"), this.env.get("dataBasePort"));
|
|
886
891
|
}
|
|
887
892
|
if (e.code === void 0) {
|
|
888
|
-
DbConnexionConfigError.mongoDBEaiAgain(e, this.env.get("dataBaseHost"));
|
|
893
|
+
this.DbConnexionConfigError.mongoDBEaiAgain(e, this.env.get("dataBaseHost"));
|
|
889
894
|
} else {
|
|
890
|
-
DbConnexionConfigError.mongoDbGlobalError(e);
|
|
895
|
+
this.DbConnexionConfigError.mongoDbGlobalError(e);
|
|
891
896
|
}
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
/**
|
|
895
900
|
*
|
|
896
|
-
* @param localeLanguage
|
|
897
901
|
* @param keepAlive
|
|
898
902
|
* @param stream
|
|
899
903
|
* @param statement_timeout
|
|
@@ -908,11 +912,11 @@ var DatabaseConnectionConfig = class {
|
|
|
908
912
|
*
|
|
909
913
|
* Postgres database connection with optional connection arguments
|
|
910
914
|
*/
|
|
911
|
-
async databasePostgresDBConnectionChecker(
|
|
915
|
+
async databasePostgresDBConnectionChecker(keepAlive, stream, statement_timeout, ssl, query_timeout, keepAliveInitialDelayMillis, idle_in_transaction_session_timeout, application_name, connectionTimeoutMillis, types, options) {
|
|
912
916
|
const url = `postgresql:/${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
913
917
|
try {
|
|
914
918
|
await SCheckerPostgresDatabaseConnection(
|
|
915
|
-
localeLanguage,
|
|
919
|
+
this.localeLanguage,
|
|
916
920
|
url,
|
|
917
921
|
keepAlive,
|
|
918
922
|
stream,
|
|
@@ -927,13 +931,13 @@ var DatabaseConnectionConfig = class {
|
|
|
927
931
|
options
|
|
928
932
|
);
|
|
929
933
|
this.logger.success(
|
|
930
|
-
TranslationLoader9.t("postgresDBConnectionChecker", localeLanguage, loggerConfig),
|
|
931
|
-
TranslationLoader9.t("postgresConnectionSuccess", localeLanguage, loggerConfig)
|
|
934
|
+
TranslationLoader9.t("postgresDBConnectionChecker", this.localeLanguage, loggerConfig),
|
|
935
|
+
TranslationLoader9.t("postgresConnectionSuccess", this.localeLanguage, loggerConfig)
|
|
932
936
|
);
|
|
933
937
|
console.log("");
|
|
934
938
|
} catch (err) {
|
|
935
939
|
const stackTrace = this.traceError(
|
|
936
|
-
TranslationLoader9.t(`${err.message}`, localeLanguage, loggerConfig),
|
|
940
|
+
TranslationLoader9.t(`${err.message}`, this.localeLanguage, loggerConfig),
|
|
937
941
|
"PostgresConnectionError",
|
|
938
942
|
status6.NOT_ACCEPTABLE
|
|
939
943
|
);
|
|
@@ -953,21 +957,20 @@ var DatabaseConnectionConfig = class {
|
|
|
953
957
|
|
|
954
958
|
// src/core/config/database/middleware/mongoChecker.database.ts
|
|
955
959
|
var MMongoCheckerDatabase = (optionalArgumentConnection, localLanguage) => {
|
|
956
|
-
const DbConnexion = new DatabaseConnectionConfig();
|
|
957
|
-
return DbConnexion.databaseMongoDBConnectionChecker(optionalArgumentConnection
|
|
960
|
+
const DbConnexion = new DatabaseConnectionConfig(localLanguage);
|
|
961
|
+
return DbConnexion.databaseMongoDBConnectionChecker(optionalArgumentConnection);
|
|
958
962
|
};
|
|
959
963
|
|
|
960
964
|
// src/core/config/database/middleware/mySqlChecker.database.ts
|
|
961
965
|
var MMySqlCheckerDatabase = (optionalArgumentConnection, localLanguage) => {
|
|
962
|
-
const DbConnexion = new DatabaseConnectionConfig();
|
|
963
|
-
return DbConnexion.databaseMySQLConnexionChecker(optionalArgumentConnection
|
|
966
|
+
const DbConnexion = new DatabaseConnectionConfig(localLanguage);
|
|
967
|
+
return DbConnexion.databaseMySQLConnexionChecker(optionalArgumentConnection);
|
|
964
968
|
};
|
|
965
969
|
|
|
966
970
|
// src/core/config/database/middleware/postgresChecker.database.ts
|
|
967
971
|
var MPostgresCheckerDatabase = (localLanguage, keepAlive, stream, statement_timeout, ssl, query_timeout, keepAliveInitialDelayMillis, idle_in_transaction_session_timeout, application_name, connectionTimeoutMillis, types, options) => {
|
|
968
|
-
const DbConnexion = new DatabaseConnectionConfig();
|
|
972
|
+
const DbConnexion = new DatabaseConnectionConfig(localLanguage);
|
|
969
973
|
return DbConnexion.databasePostgresDBConnectionChecker(
|
|
970
|
-
localLanguage,
|
|
971
974
|
keepAlive,
|
|
972
975
|
stream,
|
|
973
976
|
statement_timeout,
|
|
@@ -1122,14 +1125,17 @@ import { LoggerCore as LoggerCore6 } from "opticore-logger";
|
|
|
1122
1125
|
import { HttpStatusCode as HttpStatusCode2 } from "opticore-http-response";
|
|
1123
1126
|
import { TranslationLoader as TranslationLoader11 } from "opticore-translator";
|
|
1124
1127
|
var PathModuleVerifier = class {
|
|
1125
|
-
|
|
1128
|
+
log = new LoggerCore6(loggerConfig);
|
|
1129
|
+
localeLanguage;
|
|
1130
|
+
constructor(localeLanguage) {
|
|
1131
|
+
this.localeLanguage = localeLanguage;
|
|
1132
|
+
}
|
|
1126
1133
|
/**
|
|
1127
1134
|
* Verifies if modules at specific paths are loaded.
|
|
1128
1135
|
* If any module is not loaded, it throws an error.
|
|
1129
|
-
* @param localLanguage
|
|
1130
1136
|
* @param modulePaths - An array of paths to the modules to verify.
|
|
1131
1137
|
*/
|
|
1132
|
-
|
|
1138
|
+
verifyModulePaths(modulePaths) {
|
|
1133
1139
|
const notLoadedPaths = [];
|
|
1134
1140
|
for (const modulePath of modulePaths) {
|
|
1135
1141
|
if (!this.isModulePathLoaded(modulePath)) {
|
|
@@ -1138,7 +1144,7 @@ var PathModuleVerifier = class {
|
|
|
1138
1144
|
}
|
|
1139
1145
|
if (notLoadedPaths.length > 0) {
|
|
1140
1146
|
this.log.error(
|
|
1141
|
-
TranslationLoader11.t("moduleNotLoaded",
|
|
1147
|
+
TranslationLoader11.t("moduleNotLoaded", this.localeLanguage, { notLoadedPaths: notLoadedPaths.join(", ") }),
|
|
1142
1148
|
"",
|
|
1143
1149
|
"",
|
|
1144
1150
|
modulePaths,
|
|
@@ -1152,7 +1158,7 @@ var PathModuleVerifier = class {
|
|
|
1152
1158
|
* @param modulePath - The path to the module.
|
|
1153
1159
|
* @returns True if the module is loaded, false otherwise.
|
|
1154
1160
|
*/
|
|
1155
|
-
|
|
1161
|
+
isModulePathLoaded(modulePath) {
|
|
1156
1162
|
try {
|
|
1157
1163
|
const resolvedPath = resolve(modulePath);
|
|
1158
1164
|
return __require.cache[resolvedPath] !== void 0;
|