opticore-webapp-core 1.0.19 → 1.0.21
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 +11 -11
- package/dist/index.d.cts +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +12 -12
- package/package.json +7 -8
- package/src/application/middlewares/bodyParser.middleware.ts +74 -0
- package/src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts +194 -0
- package/src/application/services/asymmetricCryptionDataWithPublicRSAKey.service.ts +188 -0
- package/src/application/services/loggerFileConfiguration.service.ts +6 -0
- package/src/core/config/database/connexion.config.database.ts +116 -0
- package/src/core/config/database/middleware/postgresChecker.database.ts +35 -0
- package/src/core/config/loaders/localLanguage.loader.ts +31 -0
- package/src/core/config/loaders/translateLanguage.loader.ts +27 -0
- package/src/core/config/logger/logger.config.ts +33 -0
- package/src/core/constants/signRSA/algorithm.constant.ts +54 -0
- package/src/core/constants/signRSA/encodingFormat.constant.ts +14 -0
- package/src/core/constants/signRSA/keyType.constant.ts +4 -0
- package/src/core/constants/signRSA/outputFormat.constant.ts +6 -0
- package/src/core/constants/signRSAKeyComponent.constant.ts +11 -0
- package/src/core/errors/databaseConnexion.error.ts +107 -0
- package/src/core/events/pathModuleVerifier.event.ts +58 -0
- package/src/domains/constants/logLevel.constant.ts +6 -0
- package/src/index.ts +56 -0
- package/src/interfaces/bodyParserOptions.interface.ts +4 -0
- package/src/interfaces/responseBodyEndFromResponseEvent.interface.ts +7 -0
- package/src/interfaces/responseBodyWriteFromResponseEvent.interface.ts +4 -0
- package/src/interfaces/wrappingBodyResponse.interface.ts +4 -0
- package/src/types/json.type.ts +18 -0
- package/src/types/logLevel.type.ts +3 -0
- package/src/types/originalWriteEncoding.type.ts +1 -0
- package/src/types/parseFunction.type.ts +1 -0
- package/src/types/raw.type.ts +23 -0
- package/src/types/text.type.ts +18 -0
- package/src/types/urlencoded.type.ts +19 -0
- package/src/utils/cryptography/decryption/rsaKey.decryption.ts +19 -0
- package/src/utils/cryptography/encryption/rsaKey.encryption.ts +25 -0
- package/src/utils/dateTimeFormatted.utils.ts +6 -0
- package/src/utils/environment.utils.ts +11 -0
- package/src/utils/logMessage.utils.ts +20 -0
- package/src/utils/parseUrlencoded.utils.ts +17 -0
- package/src/utils/parsing/parsingYaml.utils.ts +81 -0
- package/src/utils/translations/message.translation.en.json +130 -0
- package/src/utils/translations/message.translation.fr.json +49 -0
- package/src/utils/utility.utils.ts +154 -0
- package/tsup.config.ts +11 -0
package/dist/index.cjs
CHANGED
|
@@ -188,7 +188,7 @@ var import_opticore_logger = require("opticore-logger");
|
|
|
188
188
|
// src/core/config/logger/logger.config.ts
|
|
189
189
|
var import_opticore_env_access = require("opticore-env-access");
|
|
190
190
|
var loggerConfig = (envDir) => {
|
|
191
|
-
const getEnvAccess = (0, import_opticore_env_access.
|
|
191
|
+
const getEnvAccess = (0, import_opticore_env_access.getEnvironmentValue)(envDir);
|
|
192
192
|
return {
|
|
193
193
|
logLevels: [
|
|
194
194
|
getEnvAccess.logLevelInfo,
|
|
@@ -215,8 +215,8 @@ var loggerConfig = (envDir) => {
|
|
|
215
215
|
};
|
|
216
216
|
|
|
217
217
|
// src/application/services/loggerFileConfiguration.service.ts
|
|
218
|
-
var SLoggerFileConfiguration = (
|
|
219
|
-
return new import_opticore_logger.LoggerCore(loggerConfig(
|
|
218
|
+
var SLoggerFileConfiguration = (environmentPath) => {
|
|
219
|
+
return new import_opticore_logger.LoggerCore(loggerConfig(environmentPath));
|
|
220
220
|
};
|
|
221
221
|
|
|
222
222
|
// src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts
|
|
@@ -556,14 +556,14 @@ var import_path = __toESM(require("path"), 1);
|
|
|
556
556
|
var import_module = require("module");
|
|
557
557
|
var import_opticore_translator3 = require("opticore-translator");
|
|
558
558
|
var import_opticore_http_response3 = require("opticore-http-response");
|
|
559
|
-
var translateWebAppCoreLanguageLoader = (
|
|
559
|
+
var translateWebAppCoreLanguageLoader = (environmentPath, localLang) => {
|
|
560
560
|
try {
|
|
561
561
|
const require2 = (0, import_module.createRequire)(importMetaUrl);
|
|
562
562
|
const packagePath = import_path.default.dirname(require2.resolve("opticore-webapp-core"));
|
|
563
563
|
const translateMsgJsonFilePath = import_path.default.join(packagePath, "utils", "translations");
|
|
564
564
|
import_opticore_translator3.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
565
565
|
} catch (err) {
|
|
566
|
-
SLoggerFileConfiguration(
|
|
566
|
+
SLoggerFileConfiguration(environmentPath).error({
|
|
567
567
|
message: import_opticore_translator3.TranslationLoader.t(err.message, localLang),
|
|
568
568
|
title: err.code,
|
|
569
569
|
errorType: err.code,
|
|
@@ -792,9 +792,9 @@ var import_opticore_translator6 = require("opticore-translator");
|
|
|
792
792
|
var PathModuleVerifier = class {
|
|
793
793
|
log;
|
|
794
794
|
localeLanguage;
|
|
795
|
-
constructor(localeLanguage,
|
|
795
|
+
constructor(localeLanguage, environmentPath) {
|
|
796
796
|
this.localeLanguage = localeLanguage;
|
|
797
|
-
this.log = SLoggerFileConfiguration(
|
|
797
|
+
this.log = SLoggerFileConfiguration(environmentPath);
|
|
798
798
|
}
|
|
799
799
|
/**
|
|
800
800
|
* Verifies if modules at specific paths are loaded.
|
|
@@ -840,17 +840,17 @@ var import_opticore_translator7 = require("opticore-translator");
|
|
|
840
840
|
var import_opticore_http_response6 = require("opticore-http-response");
|
|
841
841
|
var LocalLanguageLoader = class {
|
|
842
842
|
localeLanguage;
|
|
843
|
-
|
|
844
|
-
constructor(localeLanguage,
|
|
843
|
+
environmentPath;
|
|
844
|
+
constructor(localeLanguage, environmentPath) {
|
|
845
845
|
this.localeLanguage = localeLanguage;
|
|
846
|
-
this.
|
|
846
|
+
this.environmentPath = environmentPath;
|
|
847
847
|
}
|
|
848
848
|
load() {
|
|
849
849
|
try {
|
|
850
850
|
const translateMsgJsonFilePath = import_path5.default.join(process.cwd(), "src", "utils", "translations");
|
|
851
851
|
import_opticore_translator7.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
852
852
|
} catch (err) {
|
|
853
|
-
SLoggerFileConfiguration(this.
|
|
853
|
+
SLoggerFileConfiguration(this.environmentPath).error({
|
|
854
854
|
message: err.message,
|
|
855
855
|
title: err.code,
|
|
856
856
|
errorType: err.code,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { StackTraceError } from 'opticore-catch-exception-error';
|
|
2
2
|
import { ServerResponse, IncomingMessage } from 'node:http';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import * as qs from 'qs';
|
|
5
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
3
6
|
|
|
4
7
|
declare class SAsymmetricCryptionDataWithPrivateRSAKey {
|
|
5
8
|
private readonly log;
|
|
@@ -313,7 +316,7 @@ declare class Utility {
|
|
|
313
316
|
declare class PathModuleVerifier {
|
|
314
317
|
private log;
|
|
315
318
|
private readonly localeLanguage;
|
|
316
|
-
constructor(localeLanguage: string,
|
|
319
|
+
constructor(localeLanguage: string, environmentPath: any);
|
|
317
320
|
/**
|
|
318
321
|
* Verifies if modules at specific paths are loaded.
|
|
319
322
|
* If any module is not loaded, it throws an error.
|
|
@@ -330,13 +333,14 @@ declare class PathModuleVerifier {
|
|
|
330
333
|
|
|
331
334
|
declare class LocalLanguageLoader {
|
|
332
335
|
private readonly localeLanguage;
|
|
333
|
-
private readonly
|
|
334
|
-
constructor(localeLanguage: string,
|
|
336
|
+
private readonly environmentPath;
|
|
337
|
+
constructor(localeLanguage: string, environmentPath: any);
|
|
335
338
|
load(): void;
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
interface IBodyParserOptions {
|
|
339
342
|
type: string;
|
|
343
|
+
limit?: number;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
interface IResponseBodyEndFromResponseEvent {
|
|
@@ -372,7 +376,7 @@ type TParseFunction = (rawBody: string) => any;
|
|
|
372
376
|
* in express, it can be used like this: app.use(TJSONBodyParser({ type: 'application/vnd.custom-type' }));
|
|
373
377
|
*
|
|
374
378
|
*/
|
|
375
|
-
declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): void;
|
|
379
|
+
declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
376
380
|
|
|
377
381
|
/**
|
|
378
382
|
*
|
|
@@ -385,32 +389,32 @@ declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: str
|
|
|
385
389
|
* in express, it can be used like this: app.use(rawBodyParserType({ type: 'application/vnd.custom-type' }));
|
|
386
390
|
*
|
|
387
391
|
*/
|
|
388
|
-
declare function TRawBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): void;
|
|
392
|
+
declare function TRawBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
389
393
|
|
|
390
394
|
/**
|
|
391
395
|
*
|
|
392
396
|
* @param options
|
|
393
397
|
* @param localLanguage
|
|
394
|
-
* @param
|
|
398
|
+
* @param environmentPath
|
|
395
399
|
*
|
|
396
400
|
* Use by this: textBodyParserType({ type: 'text/html' })
|
|
397
401
|
*
|
|
398
402
|
* in express, it can be used like this: app.use(textBodyParserType({ type: 'text/html' }));
|
|
399
403
|
*
|
|
400
404
|
*/
|
|
401
|
-
declare function TTextBodyParser(options: IBodyParserOptions, localLanguage: string,
|
|
405
|
+
declare function TTextBodyParser(options: IBodyParserOptions, localLanguage: string, environmentPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
402
406
|
|
|
403
407
|
/**
|
|
404
408
|
*
|
|
405
409
|
* @param options
|
|
406
410
|
* @param localLanguage
|
|
407
|
-
* @param
|
|
411
|
+
* @param environmentPath
|
|
408
412
|
*
|
|
409
413
|
* Use by this: urlencodedBodyParserType({ type: 'application/x-www-form-urlencoded' })
|
|
410
414
|
*
|
|
411
415
|
* in express, it can be used like this: app.use(urlencodedBodyParserType({ type: 'application/x-www-form-urlencoded' }));
|
|
412
416
|
*
|
|
413
417
|
*/
|
|
414
|
-
declare function TUrlencodedBodyParser(options: IBodyParserOptions, localLanguage: string,
|
|
418
|
+
declare function TUrlencodedBodyParser(options: IBodyParserOptions, localLanguage: string, environmentPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
415
419
|
|
|
416
420
|
export { CLogLevel, CSignRSAKeyComponent, Environment, type IBodyParserOptions, type IResponseBodyEndFromResponseEvent, type IResponseBodyWriteFromResponseEvent, type IWrappingBodyResponse, LocalLanguageLoader, PathModuleVerifier, RSAKeyDecryption, RSAKeyEncryption, SAsymmetricCryptionDataWithPrivateRSAKey, SAsymmetricCryptionDataWithPublicRSAKey, TJSONBodyParser, type TLogLevel, type TOriginalWriteEncoding, type TParseFunction, TRawBodyParser, TTextBodyParser, TUrlencodedBodyParser, Utility, YamlParsing, dateTimeFormatted, loggerConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { StackTraceError } from 'opticore-catch-exception-error';
|
|
2
2
|
import { ServerResponse, IncomingMessage } from 'node:http';
|
|
3
|
+
import * as express from 'express';
|
|
4
|
+
import * as qs from 'qs';
|
|
5
|
+
import * as express_serve_static_core from 'express-serve-static-core';
|
|
3
6
|
|
|
4
7
|
declare class SAsymmetricCryptionDataWithPrivateRSAKey {
|
|
5
8
|
private readonly log;
|
|
@@ -313,7 +316,7 @@ declare class Utility {
|
|
|
313
316
|
declare class PathModuleVerifier {
|
|
314
317
|
private log;
|
|
315
318
|
private readonly localeLanguage;
|
|
316
|
-
constructor(localeLanguage: string,
|
|
319
|
+
constructor(localeLanguage: string, environmentPath: any);
|
|
317
320
|
/**
|
|
318
321
|
* Verifies if modules at specific paths are loaded.
|
|
319
322
|
* If any module is not loaded, it throws an error.
|
|
@@ -330,13 +333,14 @@ declare class PathModuleVerifier {
|
|
|
330
333
|
|
|
331
334
|
declare class LocalLanguageLoader {
|
|
332
335
|
private readonly localeLanguage;
|
|
333
|
-
private readonly
|
|
334
|
-
constructor(localeLanguage: string,
|
|
336
|
+
private readonly environmentPath;
|
|
337
|
+
constructor(localeLanguage: string, environmentPath: any);
|
|
335
338
|
load(): void;
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
interface IBodyParserOptions {
|
|
339
342
|
type: string;
|
|
343
|
+
limit?: number;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
interface IResponseBodyEndFromResponseEvent {
|
|
@@ -372,7 +376,7 @@ type TParseFunction = (rawBody: string) => any;
|
|
|
372
376
|
* in express, it can be used like this: app.use(TJSONBodyParser({ type: 'application/vnd.custom-type' }));
|
|
373
377
|
*
|
|
374
378
|
*/
|
|
375
|
-
declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): void;
|
|
379
|
+
declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
376
380
|
|
|
377
381
|
/**
|
|
378
382
|
*
|
|
@@ -385,32 +389,32 @@ declare function TJSONBodyParser(options: IBodyParserOptions, localLanguage: str
|
|
|
385
389
|
* in express, it can be used like this: app.use(rawBodyParserType({ type: 'application/vnd.custom-type' }));
|
|
386
390
|
*
|
|
387
391
|
*/
|
|
388
|
-
declare function TRawBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): void;
|
|
392
|
+
declare function TRawBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
389
393
|
|
|
390
394
|
/**
|
|
391
395
|
*
|
|
392
396
|
* @param options
|
|
393
397
|
* @param localLanguage
|
|
394
|
-
* @param
|
|
398
|
+
* @param environmentPath
|
|
395
399
|
*
|
|
396
400
|
* Use by this: textBodyParserType({ type: 'text/html' })
|
|
397
401
|
*
|
|
398
402
|
* in express, it can be used like this: app.use(textBodyParserType({ type: 'text/html' }));
|
|
399
403
|
*
|
|
400
404
|
*/
|
|
401
|
-
declare function TTextBodyParser(options: IBodyParserOptions, localLanguage: string,
|
|
405
|
+
declare function TTextBodyParser(options: IBodyParserOptions, localLanguage: string, environmentPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
402
406
|
|
|
403
407
|
/**
|
|
404
408
|
*
|
|
405
409
|
* @param options
|
|
406
410
|
* @param localLanguage
|
|
407
|
-
* @param
|
|
411
|
+
* @param environmentPath
|
|
408
412
|
*
|
|
409
413
|
* Use by this: urlencodedBodyParserType({ type: 'application/x-www-form-urlencoded' })
|
|
410
414
|
*
|
|
411
415
|
* in express, it can be used like this: app.use(urlencodedBodyParserType({ type: 'application/x-www-form-urlencoded' }));
|
|
412
416
|
*
|
|
413
417
|
*/
|
|
414
|
-
declare function TUrlencodedBodyParser(options: IBodyParserOptions, localLanguage: string,
|
|
418
|
+
declare function TUrlencodedBodyParser(options: IBodyParserOptions, localLanguage: string, environmentPath: any): (req: express.Request<express_serve_static_core.ParamsDictionary, any, any, qs.ParsedQs, Record<string, any>>, res: express.Response<any, Record<string, any>>, next: express.NextFunction) => void;
|
|
415
419
|
|
|
416
420
|
export { CLogLevel, CSignRSAKeyComponent, Environment, type IBodyParserOptions, type IResponseBodyEndFromResponseEvent, type IResponseBodyWriteFromResponseEvent, type IWrappingBodyResponse, LocalLanguageLoader, PathModuleVerifier, RSAKeyDecryption, RSAKeyEncryption, SAsymmetricCryptionDataWithPrivateRSAKey, SAsymmetricCryptionDataWithPublicRSAKey, TJSONBodyParser, type TLogLevel, type TOriginalWriteEncoding, type TParseFunction, TRawBodyParser, TTextBodyParser, TUrlencodedBodyParser, Utility, YamlParsing, dateTimeFormatted, loggerConfig };
|
package/dist/index.js
CHANGED
|
@@ -141,9 +141,9 @@ var RSAKeyDecryption = class {
|
|
|
141
141
|
import { LoggerCore } from "opticore-logger";
|
|
142
142
|
|
|
143
143
|
// src/core/config/logger/logger.config.ts
|
|
144
|
-
import {
|
|
144
|
+
import { getEnvironmentValue } from "opticore-env-access";
|
|
145
145
|
var loggerConfig = (envDir) => {
|
|
146
|
-
const getEnvAccess =
|
|
146
|
+
const getEnvAccess = getEnvironmentValue(envDir);
|
|
147
147
|
return {
|
|
148
148
|
logLevels: [
|
|
149
149
|
getEnvAccess.logLevelInfo,
|
|
@@ -170,8 +170,8 @@ var loggerConfig = (envDir) => {
|
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
// src/application/services/loggerFileConfiguration.service.ts
|
|
173
|
-
var SLoggerFileConfiguration = (
|
|
174
|
-
return new LoggerCore(loggerConfig(
|
|
173
|
+
var SLoggerFileConfiguration = (environmentPath) => {
|
|
174
|
+
return new LoggerCore(loggerConfig(environmentPath));
|
|
175
175
|
};
|
|
176
176
|
|
|
177
177
|
// src/application/services/asymmetricCryptionDataWithPrivateRSAKey.service.ts
|
|
@@ -511,14 +511,14 @@ import path from "path";
|
|
|
511
511
|
import { createRequire } from "module";
|
|
512
512
|
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
513
513
|
import { HttpStatusCode as HttpStatusCode2 } from "opticore-http-response";
|
|
514
|
-
var translateWebAppCoreLanguageLoader = (
|
|
514
|
+
var translateWebAppCoreLanguageLoader = (environmentPath, localLang) => {
|
|
515
515
|
try {
|
|
516
516
|
const require2 = createRequire(import.meta.url);
|
|
517
517
|
const packagePath = path.dirname(require2.resolve("opticore-webapp-core"));
|
|
518
518
|
const translateMsgJsonFilePath = path.join(packagePath, "utils", "translations");
|
|
519
519
|
TranslationLoader3.loadTranslations(translateMsgJsonFilePath);
|
|
520
520
|
} catch (err) {
|
|
521
|
-
SLoggerFileConfiguration(
|
|
521
|
+
SLoggerFileConfiguration(environmentPath).error({
|
|
522
522
|
message: TranslationLoader3.t(err.message, localLang),
|
|
523
523
|
title: err.code,
|
|
524
524
|
errorType: err.code,
|
|
@@ -747,9 +747,9 @@ import { TranslationLoader as TranslationLoader6 } from "opticore-translator";
|
|
|
747
747
|
var PathModuleVerifier = class {
|
|
748
748
|
log;
|
|
749
749
|
localeLanguage;
|
|
750
|
-
constructor(localeLanguage,
|
|
750
|
+
constructor(localeLanguage, environmentPath) {
|
|
751
751
|
this.localeLanguage = localeLanguage;
|
|
752
|
-
this.log = SLoggerFileConfiguration(
|
|
752
|
+
this.log = SLoggerFileConfiguration(environmentPath);
|
|
753
753
|
}
|
|
754
754
|
/**
|
|
755
755
|
* Verifies if modules at specific paths are loaded.
|
|
@@ -795,17 +795,17 @@ import { TranslationLoader as TranslationLoader7 } from "opticore-translator";
|
|
|
795
795
|
import { HttpStatusCode as HttpStatusCode5 } from "opticore-http-response";
|
|
796
796
|
var LocalLanguageLoader = class {
|
|
797
797
|
localeLanguage;
|
|
798
|
-
|
|
799
|
-
constructor(localeLanguage,
|
|
798
|
+
environmentPath;
|
|
799
|
+
constructor(localeLanguage, environmentPath) {
|
|
800
800
|
this.localeLanguage = localeLanguage;
|
|
801
|
-
this.
|
|
801
|
+
this.environmentPath = environmentPath;
|
|
802
802
|
}
|
|
803
803
|
load() {
|
|
804
804
|
try {
|
|
805
805
|
const translateMsgJsonFilePath = path4.join(process.cwd(), "src", "utils", "translations");
|
|
806
806
|
TranslationLoader7.loadTranslations(translateMsgJsonFilePath);
|
|
807
807
|
} catch (err) {
|
|
808
|
-
SLoggerFileConfiguration(this.
|
|
808
|
+
SLoggerFileConfiguration(this.environmentPath).error({
|
|
809
809
|
message: err.message,
|
|
810
810
|
title: err.code,
|
|
811
811
|
errorType: err.code,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"description": "opticore Web Application core module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,13 +30,12 @@
|
|
|
30
30
|
"dotenv": "^16.5.0",
|
|
31
31
|
"mongodb": "^6.6.1",
|
|
32
32
|
"mysql": "^2.18.1",
|
|
33
|
-
"opticore-catch-exception-error": "^1.0.
|
|
34
|
-
"opticore-env-access": "^1.0.
|
|
35
|
-
"opticore-express": "^1.0.
|
|
36
|
-
"opticore-http-response": "^1.0.
|
|
37
|
-
"opticore-
|
|
38
|
-
"opticore-
|
|
39
|
-
"opticore-translator": "^1.0.10",
|
|
33
|
+
"opticore-catch-exception-error": "^1.0.29",
|
|
34
|
+
"opticore-env-access": "^1.0.23",
|
|
35
|
+
"opticore-express": "^1.0.9",
|
|
36
|
+
"opticore-http-response": "^1.0.11",
|
|
37
|
+
"opticore-logger": "^1.0.32",
|
|
38
|
+
"opticore-translator": "^1.0.16",
|
|
40
39
|
"pg": "^8.15.6"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { express, NextFunction } from "opticore-express";
|
|
2
|
+
import { LoggerCore } from "opticore-logger";
|
|
3
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
4
|
+
import { TranslationLoader } from "opticore-translator";
|
|
5
|
+
|
|
6
|
+
import { IBodyParserOptions } from "@webAppCore/interfaces/bodyParserOptions.interface";
|
|
7
|
+
import { TParseFunction } from "@webAppCore/types/parseFunction.type";
|
|
8
|
+
import { loggerConfig } from "@webAppCore/core/config/logger/logger.config";
|
|
9
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param localeLanguage
|
|
15
|
+
* @param parseFunction
|
|
16
|
+
* @param options
|
|
17
|
+
* @param environmentPath
|
|
18
|
+
*
|
|
19
|
+
* This is a middleware that allows parsing data
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export function MBodyParser(parseFunction: TParseFunction,
|
|
23
|
+
options: IBodyParserOptions,
|
|
24
|
+
localeLanguage: string,
|
|
25
|
+
environmentPath: any): (req: express.Request,
|
|
26
|
+
res: express.Response,
|
|
27
|
+
next: NextFunction) => void {
|
|
28
|
+
const logger: LoggerCore = SLoggerFileConfiguration(environmentPath);
|
|
29
|
+
|
|
30
|
+
return function (req: express.Request, res: express.Response, next: NextFunction): void {
|
|
31
|
+
if (!req.headers['content-type']?.includes(options.type)) {
|
|
32
|
+
return next();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const maxSize: number = options.limit ?? 1024 * 1024;
|
|
36
|
+
let body: Uint8Array[] = [];
|
|
37
|
+
let totalSize: number = 0;
|
|
38
|
+
|
|
39
|
+
req.on("data", (chunk: any): void => {
|
|
40
|
+
totalSize += chunk.length;
|
|
41
|
+
if (totalSize > maxSize) {
|
|
42
|
+
req.destroy();
|
|
43
|
+
res.status(HttpStatusCode.PAYLOAD_TOO_LARGE).json({
|
|
44
|
+
message: TranslationLoader.t("payloadTooLarge", localeLanguage, loggerConfig)
|
|
45
|
+
});
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
body.push(chunk);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
req.on("end", (): void => {
|
|
52
|
+
const rawBody: string = Buffer.concat(body).toString();
|
|
53
|
+
try {
|
|
54
|
+
req.body = parseFunction(rawBody);
|
|
55
|
+
next();
|
|
56
|
+
} catch (error: any) {
|
|
57
|
+
res.status(HttpStatusCode.BAD_REQUEST).json({
|
|
58
|
+
message: TranslationLoader.t("invalidRequest", localeLanguage, loggerConfig)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
req.on("error", (err: any): void => {
|
|
64
|
+
logger.error({
|
|
65
|
+
message: err.message,
|
|
66
|
+
title: "Content Type error",
|
|
67
|
+
errorType: TranslationLoader.t("invalidRequest", localeLanguage, loggerConfig),
|
|
68
|
+
stackTrace: err.stack,
|
|
69
|
+
httpCodeValue: HttpStatusCode.BAD_REQUEST
|
|
70
|
+
});
|
|
71
|
+
next(err);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { BinaryToTextEncoding } from "node:crypto";
|
|
3
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
4
|
+
import { LoggerCore } from "opticore-logger";
|
|
5
|
+
import { TranslationLoader } from "opticore-translator";
|
|
6
|
+
import { StackTraceError as ErrorHandler } from "opticore-catch-exception-error";
|
|
7
|
+
|
|
8
|
+
import { RSAKeyEncryption } from "@webAppCore/utils/cryptography/encryption/rsaKey.encryption";
|
|
9
|
+
import { RSAKeyDecryption } from "@webAppCore/utils/cryptography/decryption/rsaKey.decryption";
|
|
10
|
+
import { CSignRSAKeyComponent } from "@webAppCore/core/constants/signRSAKeyComponent.constant";
|
|
11
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export class SAsymmetricCryptionDataWithPrivateRSAKey {
|
|
15
|
+
private readonly log: LoggerCore;
|
|
16
|
+
private readonly localeLanguage: string;
|
|
17
|
+
|
|
18
|
+
constructor(localeLanguage: string, environnementPath: any) {
|
|
19
|
+
this.localeLanguage = localeLanguage;
|
|
20
|
+
this.log = SLoggerFileConfiguration(environnementPath)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param rsaKey
|
|
27
|
+
* @param keyType
|
|
28
|
+
* @protected
|
|
29
|
+
*
|
|
30
|
+
* Return ErrorHandler | string
|
|
31
|
+
*/
|
|
32
|
+
protected verifyExistingKey(rsaKey: string, keyType: string): string | ErrorHandler {
|
|
33
|
+
if (!rsaKey) {
|
|
34
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
35
|
+
keyType +" "+ TranslationLoader.t("rsaKeyNotFound", this.localeLanguage, this.log),
|
|
36
|
+
TranslationLoader.t("erBadDbError", this.localeLanguage, this.log),
|
|
37
|
+
status.NOT_FOUND
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
this.log.error({
|
|
41
|
+
message: TranslationLoader.t("rsaKeyNotFound", this.localeLanguage, this.log),
|
|
42
|
+
title: TranslationLoader.t("verifyExistingKey", this.localeLanguage, this.log),
|
|
43
|
+
errorType: TranslationLoader.t("erBadDbError", this.localeLanguage, this.log),
|
|
44
|
+
stackTrace: stackTrace.stack,
|
|
45
|
+
httpCodeValue: status.NOT_FOUND
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return rsaKey;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param privateKey
|
|
55
|
+
* @param payload
|
|
56
|
+
* @private
|
|
57
|
+
*
|
|
58
|
+
* Return Buffer
|
|
59
|
+
*/
|
|
60
|
+
private encryptionWithPrivateKey(privateKey: string, payload: any): Buffer {
|
|
61
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const bufferedData: Buffer = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
65
|
+
return RSAKeyEncryption.privateEncrypt(privateKey, bufferedData);
|
|
66
|
+
} catch (err: any) {
|
|
67
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
68
|
+
TranslationLoader.t("encryptionWithPrivateKeyFailed", this.localeLanguage, this.log),
|
|
69
|
+
TranslationLoader.t("encryptionFailed", this.localeLanguage, this.log),
|
|
70
|
+
status.NOT_FOUND
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
this.log.error({
|
|
74
|
+
message: err.message,
|
|
75
|
+
title: TranslationLoader.t("encryptionFailed", this.localeLanguage, this.log),
|
|
76
|
+
errorType: TranslationLoader.t("encryptionWithPrivateKeyFailed", this.localeLanguage, this.log),
|
|
77
|
+
stackTrace: stackTrace.stack,
|
|
78
|
+
httpCodeValue: status.NOT_FOUND
|
|
79
|
+
});
|
|
80
|
+
process.exit();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
* @param privateKey
|
|
87
|
+
* @param publicKey
|
|
88
|
+
* @param payload
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
private decryptionWithPublicKey(privateKey: string, publicKey: string, payload: any): Buffer {
|
|
92
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const encryptedPayload: Buffer = this.encryptionWithPrivateKey(privateKey, payload);
|
|
96
|
+
|
|
97
|
+
return RSAKeyDecryption.publicDecrypt(publicKey, encryptedPayload);
|
|
98
|
+
} catch (error: any) {
|
|
99
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
100
|
+
TranslationLoader.t("errorDecryption", this.localeLanguage, this.log),
|
|
101
|
+
TranslationLoader.t("decryptionFailed", this.localeLanguage, this.log),
|
|
102
|
+
status.NOT_ACCEPTABLE
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
this.log.error({
|
|
106
|
+
message: TranslationLoader.t("decryptionWithPublicKeyFailed", this.localeLanguage, this.log),
|
|
107
|
+
title: TranslationLoader.t("decryptionFailed", this.localeLanguage, this.log),
|
|
108
|
+
errorType: TranslationLoader.t("errorDecryption", this.localeLanguage, this.log),
|
|
109
|
+
stackTrace: stackTrace.stack,
|
|
110
|
+
httpCodeValue: status.NOT_ACCEPTABLE
|
|
111
|
+
});
|
|
112
|
+
process.exit();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param privateKey
|
|
119
|
+
* @param payload
|
|
120
|
+
* @private
|
|
121
|
+
*/
|
|
122
|
+
private signWithRSAKey(privateKey: string, payload: any): string {
|
|
123
|
+
this.verifyExistingKey(privateKey, CSignRSAKeyComponent.keyType.private);
|
|
124
|
+
|
|
125
|
+
const sign: crypto.Sign = crypto.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
126
|
+
sign.update(payload);
|
|
127
|
+
|
|
128
|
+
return sign.sign(privateKey, CSignRSAKeyComponent.outputFormat.base64 as BinaryToTextEncoding);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @param privateKey
|
|
134
|
+
* @param publicKey
|
|
135
|
+
* @param payload
|
|
136
|
+
*/
|
|
137
|
+
public verifyRSAKey(privateKey: string, publicKey: string, payload: any): string | Error {
|
|
138
|
+
try {
|
|
139
|
+
const verify: crypto.Verify = crypto.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
140
|
+
verify.update(payload);
|
|
141
|
+
|
|
142
|
+
const signature: string = this.signWithRSAKey(privateKey, payload);
|
|
143
|
+
const isVerified: boolean = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64 as BinaryToTextEncoding);
|
|
144
|
+
|
|
145
|
+
if (isVerified) {
|
|
146
|
+
const decryptedData: Buffer = this.decryptionWithPublicKey(privateKey, publicKey, payload);
|
|
147
|
+
|
|
148
|
+
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8 as BufferEncoding);
|
|
149
|
+
} else {
|
|
150
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
151
|
+
TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage, this.log),
|
|
152
|
+
TranslationLoader.t("verifyRSAKeyFailed", this.localeLanguage, this.log),
|
|
153
|
+
status.NOT_ACCEPTABLE
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
this.log.error({
|
|
157
|
+
message: TranslationLoader.t("verifyRSAKey", this.localeLanguage, this.log),
|
|
158
|
+
title: TranslationLoader.t("verifyRSAKeyFailed", this.localeLanguage, this.log),
|
|
159
|
+
errorType: TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage, this.log),
|
|
160
|
+
stackTrace: stackTrace.stack,
|
|
161
|
+
httpCodeValue: status.NOT_FOUND
|
|
162
|
+
});
|
|
163
|
+
process.exit();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
} catch (err: any) {
|
|
167
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
168
|
+
err.name,
|
|
169
|
+
TranslationLoader.t("signatureRSAKeysError", this.localeLanguage, this.log),
|
|
170
|
+
status.NOT_ACCEPTABLE
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
this.log.error({
|
|
174
|
+
message: TranslationLoader.t("signatureRSAKeysError", this.localeLanguage, this.log),
|
|
175
|
+
title: TranslationLoader.t("errorNameNotVerifyingRSAKey", this.localeLanguage, this.log),
|
|
176
|
+
errorType: err.name,
|
|
177
|
+
stackTrace: stackTrace.stack,
|
|
178
|
+
httpCodeValue: status.NOT_FOUND
|
|
179
|
+
});
|
|
180
|
+
process.exit();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
*
|
|
186
|
+
* @param props
|
|
187
|
+
* @param name
|
|
188
|
+
* @param status
|
|
189
|
+
* @private
|
|
190
|
+
*/
|
|
191
|
+
private traceError(props: string, name: string, status: number): ErrorHandler {
|
|
192
|
+
return new ErrorHandler(props, name, status, true);
|
|
193
|
+
}
|
|
194
|
+
}
|