opticore-webapp-core 1.0.20 → 1.0.22
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.d.cts +8 -4
- package/dist/index.d.ts +8 -4
- 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/utility.utils.ts +154 -0
- package/tsup.config.ts +11 -0
- /package/{dist → src}/utils/translations/message.translation.en.json +0 -0
- /package/{dist → src}/utils/translations/message.translation.fr.json +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import mySQL from "mysql";
|
|
2
|
+
import stream from "stream";
|
|
3
|
+
import { CustomTypesConfig } from "pg";
|
|
4
|
+
import { ConnectionOptions } from "tls";
|
|
5
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
6
|
+
import { ILoggerConfig, LoggerCore } from "opticore-logger";
|
|
7
|
+
import { TranslationLoader } from "opticore-translator";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import { DbConnexionConfigError } from "@webAppCore/core/errors/databaseConnexion.error";
|
|
11
|
+
import { Environment as env } from "@webAppCore/utils/environment.utils";
|
|
12
|
+
import { StackTraceError as ErrorHandler } from "opticore-catch-exception-error";
|
|
13
|
+
import { loggerConfig } from "@webAppCore/core/config/logger/logger.config";
|
|
14
|
+
import { MPostgresCheckerDatabase } from "@webAppCore/core/config/database/middleware/postgresChecker.database";
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* ConnexionConfigDatabase is a class extending on the EnvConfig class so that by inheritance,
|
|
21
|
+
* certain methods make it possible to retrieve the variable values defined in
|
|
22
|
+
* the .env environment file to establish the connection with the database service.
|
|
23
|
+
*/
|
|
24
|
+
export class DatabaseConnectionConfig {
|
|
25
|
+
private env: env<any>;
|
|
26
|
+
private logger: LoggerCore;
|
|
27
|
+
private readonly localeLanguage: string;
|
|
28
|
+
private readonly environmentPath: string;
|
|
29
|
+
private DbConnexionConfigError: DbConnexionConfigError ;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
constructor(localeLanguage: string, environmentPath: any) {
|
|
33
|
+
this.localeLanguage = localeLanguage;
|
|
34
|
+
this.environmentPath = environmentPath;
|
|
35
|
+
|
|
36
|
+
this.DbConnexionConfigError = new DbConnexionConfigError(localeLanguage, environmentPath);
|
|
37
|
+
this.env = new env(environmentPath);
|
|
38
|
+
this.logger = new LoggerCore(loggerConfig(environmentPath) as ILoggerConfig)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @param keepAlive
|
|
45
|
+
* @param stream
|
|
46
|
+
* @param statement_timeout
|
|
47
|
+
* @param ssl
|
|
48
|
+
* @param query_timeout
|
|
49
|
+
* @param keepAliveInitialDelayMillis
|
|
50
|
+
* @param idle_in_transaction_session_timeout
|
|
51
|
+
* @param application_name
|
|
52
|
+
* @param connectionTimeoutMillis
|
|
53
|
+
* @param types
|
|
54
|
+
* @param options
|
|
55
|
+
*
|
|
56
|
+
* Postgres database connection with optional connection arguments
|
|
57
|
+
*/
|
|
58
|
+
public async databasePostgresDBConnectionChecker(keepAlive?: boolean | undefined,
|
|
59
|
+
stream?: (() => (stream.Duplex | undefined)) | undefined,
|
|
60
|
+
statement_timeout?: false | number | undefined,
|
|
61
|
+
ssl?: boolean | ConnectionOptions | undefined,
|
|
62
|
+
query_timeout?: number | undefined,
|
|
63
|
+
keepAliveInitialDelayMillis?: number | undefined,
|
|
64
|
+
idle_in_transaction_session_timeout?: number | undefined,
|
|
65
|
+
application_name?: string | undefined,
|
|
66
|
+
connectionTimeoutMillis?: number | undefined,
|
|
67
|
+
types?: CustomTypesConfig | undefined,
|
|
68
|
+
options?: string | undefined): Promise<void> {
|
|
69
|
+
const url: string = `postgresql:/${this.env.get("dataBaseUser")}:${this.env.get("dataBasePassword")}@${this.env.get("dataBaseHost")}:${this.env.get("dataBasePort")}/${this.env.get("dataBaseName")}`;
|
|
70
|
+
try {
|
|
71
|
+
await MPostgresCheckerDatabase(
|
|
72
|
+
this.localeLanguage,
|
|
73
|
+
this.environmentPath,
|
|
74
|
+
url,
|
|
75
|
+
keepAlive,
|
|
76
|
+
stream,
|
|
77
|
+
statement_timeout,
|
|
78
|
+
ssl,
|
|
79
|
+
query_timeout,
|
|
80
|
+
keepAliveInitialDelayMillis,
|
|
81
|
+
idle_in_transaction_session_timeout,
|
|
82
|
+
application_name,
|
|
83
|
+
connectionTimeoutMillis,
|
|
84
|
+
types,
|
|
85
|
+
options
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
this.logger.success({
|
|
89
|
+
title: TranslationLoader.t("postgresDBConnectionChecker", this.localeLanguage, loggerConfig),
|
|
90
|
+
message: TranslationLoader.t("postgresConnectionSuccess", this.localeLanguage, loggerConfig)
|
|
91
|
+
});
|
|
92
|
+
console.log("");
|
|
93
|
+
} catch (err: any) {
|
|
94
|
+
const stackTrace: ErrorHandler = this.traceError(
|
|
95
|
+
TranslationLoader.t(
|
|
96
|
+
err.message,
|
|
97
|
+
this.localeLanguage,
|
|
98
|
+
loggerConfig
|
|
99
|
+
),
|
|
100
|
+
"PostgresConnectionError",
|
|
101
|
+
status.NOT_ACCEPTABLE
|
|
102
|
+
);
|
|
103
|
+
this.logger.error({
|
|
104
|
+
message: err.message,
|
|
105
|
+
title: "PostgresConnectionError",
|
|
106
|
+
errorType: "Postgres connection error",
|
|
107
|
+
stackTrace: stackTrace.stack,
|
|
108
|
+
httpCodeValue: status.NOT_ACCEPTABLE
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private traceError(props: string, name: string, status: number): ErrorHandler {
|
|
114
|
+
return new ErrorHandler(props, name, status, true);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {ConnectionOptions} from "tls";
|
|
2
|
+
import {CustomTypesConfig} from "pg";
|
|
3
|
+
import stream from "stream";
|
|
4
|
+
import { DatabaseConnectionConfig } from "@webAppCore/core/config/database/connexion.config.database";
|
|
5
|
+
|
|
6
|
+
export const MPostgresCheckerDatabase = (localLanguage: string,
|
|
7
|
+
environmentPath: any,
|
|
8
|
+
host?: string | undefined,
|
|
9
|
+
keepAlive?: boolean | undefined,
|
|
10
|
+
stream?: (() => (stream.Duplex | undefined)) | undefined,
|
|
11
|
+
statement_timeout?: false | number | undefined,
|
|
12
|
+
ssl?: boolean | ConnectionOptions | undefined,
|
|
13
|
+
query_timeout?: number | undefined,
|
|
14
|
+
keepAliveInitialDelayMillis?: number | undefined,
|
|
15
|
+
idle_in_transaction_session_timeout?: number | undefined,
|
|
16
|
+
application_name?: string | undefined,
|
|
17
|
+
connectionTimeoutMillis?: number | undefined,
|
|
18
|
+
types?: CustomTypesConfig | undefined,
|
|
19
|
+
options?: string | undefined) => {
|
|
20
|
+
const DbConnexion: DatabaseConnectionConfig = new DatabaseConnectionConfig(localLanguage, environmentPath);
|
|
21
|
+
return DbConnexion.databasePostgresDBConnectionChecker(
|
|
22
|
+
host,
|
|
23
|
+
keepAlive,
|
|
24
|
+
stream,
|
|
25
|
+
statement_timeout,
|
|
26
|
+
ssl,
|
|
27
|
+
query_timeout,
|
|
28
|
+
keepAliveInitialDelayMillis,
|
|
29
|
+
idle_in_transaction_session_timeout,
|
|
30
|
+
application_name,
|
|
31
|
+
connectionTimeoutMillis,
|
|
32
|
+
types,
|
|
33
|
+
options
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { TranslationLoader } from "opticore-translator";
|
|
3
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
4
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class LocalLanguageLoader {
|
|
9
|
+
private readonly localeLanguage: string;
|
|
10
|
+
private readonly environmentPath: string;
|
|
11
|
+
|
|
12
|
+
constructor(localeLanguage: string, environmentPath: any) {
|
|
13
|
+
this.localeLanguage = localeLanguage;
|
|
14
|
+
this.environmentPath = environmentPath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public load(): void {
|
|
18
|
+
try {
|
|
19
|
+
const translateMsgJsonFilePath: string = path.join(process.cwd(), "src", "utils", "translations");
|
|
20
|
+
TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
21
|
+
} catch (err: any) {
|
|
22
|
+
SLoggerFileConfiguration(this.environmentPath).error({
|
|
23
|
+
message: err.message,
|
|
24
|
+
title: err.code,
|
|
25
|
+
errorType: err.code,
|
|
26
|
+
stackTrace: err.stackTrace,
|
|
27
|
+
httpCodeValue: HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createRequire } from "module";
|
|
3
|
+
import { TranslationLoader } from "opticore-translator";
|
|
4
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
5
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const translateWebAppCoreLanguageLoader: (environmentPath: any,
|
|
9
|
+
localLang: string) => void = (environmentPath: any, localLang: string): void => {
|
|
10
|
+
try {
|
|
11
|
+
const require: NodeJS.Require = createRequire(import.meta.url);
|
|
12
|
+
const packagePath: string = path.dirname(require.resolve("opticore-webapp-core"));
|
|
13
|
+
|
|
14
|
+
// Relative path based on package root
|
|
15
|
+
const translateMsgJsonFilePath: string = path.join(packagePath, "utils", "translations");
|
|
16
|
+
TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
17
|
+
|
|
18
|
+
} catch (err: any) {
|
|
19
|
+
SLoggerFileConfiguration(environmentPath).error({
|
|
20
|
+
message: TranslationLoader.t(err.message, localLang),
|
|
21
|
+
title: err.code,
|
|
22
|
+
errorType: err.code,
|
|
23
|
+
stackTrace: err.stackTrace,
|
|
24
|
+
httpCodeValue: HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getEnvironmentValue, IEnvVariables } from "opticore-env-access";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param envDir
|
|
6
|
+
*/
|
|
7
|
+
export const loggerConfig = (envDir: any) => {
|
|
8
|
+
const getEnvAccess: IEnvVariables = getEnvironmentValue(envDir);
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
logLevels: [
|
|
12
|
+
getEnvAccess.logLevelInfo,
|
|
13
|
+
getEnvAccess.logLevelWarning,
|
|
14
|
+
getEnvAccess.logLevelSuccess,
|
|
15
|
+
getEnvAccess.logLevelError,
|
|
16
|
+
getEnvAccess.logLevelDebug,
|
|
17
|
+
],
|
|
18
|
+
transports: {
|
|
19
|
+
file: {
|
|
20
|
+
enabled: getEnvAccess.logFileEnabled,
|
|
21
|
+
maxSizeMB: getEnvAccess.logFileMaxSize,
|
|
22
|
+
rotate: getEnvAccess.logFileRotate,
|
|
23
|
+
},
|
|
24
|
+
console: {
|
|
25
|
+
enabled: getEnvAccess.logConsoleEnabled,
|
|
26
|
+
},
|
|
27
|
+
remote: {
|
|
28
|
+
enabled: getEnvAccess.logRemoteEnabled,
|
|
29
|
+
endpoint: getEnvAccess.logRemoteEndPoint,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const CAlgorithm = {
|
|
2
|
+
RSA_MD5: "RSA-MD5",
|
|
3
|
+
RSA_RIPEMD160: "RSA-RIPEMD160",
|
|
4
|
+
RSA_SHA1: "RSA-SHA1",
|
|
5
|
+
RSA_SHA1_2: "RSA-SHA1-2",
|
|
6
|
+
RSA_SHA224: "RSA-SHA224",
|
|
7
|
+
RSA_SHA256: "RSA-SHA256",
|
|
8
|
+
RSA_SHA3_224: "RSA-SHA3-224",
|
|
9
|
+
RSA_SHA3_256: "RSA-SHA3-256",
|
|
10
|
+
RSA_SHA3_384: "RSA-SHA3-384",
|
|
11
|
+
RSA_SHA3_512: "RSA-SHA3-512",
|
|
12
|
+
RSA_SHA384: "RSA-SHA384",
|
|
13
|
+
RSA_SHA512: "RSA-SHA512",
|
|
14
|
+
RSA_SHA512_224: "RSA-SHA512/224",
|
|
15
|
+
RSA_SHA512_256: "RSA-SHA512/256",
|
|
16
|
+
RSA_SM3: "RSA-SM3",
|
|
17
|
+
blake2b512: "blake2b512",
|
|
18
|
+
blake2s256: "blake2s256",
|
|
19
|
+
id_rsassa_pkcs1_v1_5_with_sha3_224: "id-rsassa-pkcs1-v1_5-with-sha3-224",
|
|
20
|
+
id_rsassa_pkcs1_v1_5_with_sha3_256: "id-rsassa-pkcs1-v1_5-with-sha3-256",
|
|
21
|
+
id_rsassa_pkcs1_v1_5_with_sha3_384: "id-rsassa-pkcs1-v1_5-with-sha3-384",
|
|
22
|
+
id_rsassa_pkcs1_v1_5_with_sha3_512: "id-rsassa-pkcs1-v1_5-with-sha3-512",
|
|
23
|
+
md5: "md5",
|
|
24
|
+
md5_sha1: "md5-sha1",
|
|
25
|
+
md5WithRSAEncryption: "md5WithRSAEncryption",
|
|
26
|
+
ripemd: "ripemd",
|
|
27
|
+
ripemd160: "ripemd160",
|
|
28
|
+
ripemd160WithRSA: "ripemd160WithRSA",
|
|
29
|
+
rmd160: "rmd160",
|
|
30
|
+
sha1: "sha1",
|
|
31
|
+
sha1WithRSAEncryption: "sha1WithRSAEncryption",
|
|
32
|
+
sha224: "sha224",
|
|
33
|
+
sha224WithRSAEncryption: "sha224WithRSAEncryption",
|
|
34
|
+
sha256: "SHA256",
|
|
35
|
+
sha256WithRSAEncryption: "sha256WithRSAEncryption",
|
|
36
|
+
sha3_224: "sha3-224",
|
|
37
|
+
sha3_256: "sha3-256",
|
|
38
|
+
sha3_384: "sha3-384",
|
|
39
|
+
sha3_512: "sha3-512",
|
|
40
|
+
sha384: "sha384",
|
|
41
|
+
sha384WithRSAEncryption: "sha384WithRSAEncryption",
|
|
42
|
+
sha512: "sha512",
|
|
43
|
+
sha512_224: "sha512-224",
|
|
44
|
+
sha512_224WithRSAEncryption: "sha512-224WithRSAEncryption",
|
|
45
|
+
sha512_256: "sha512-256",
|
|
46
|
+
sha512_256WithRSAEncryption: "sha512-256WithRSAEncryption",
|
|
47
|
+
sha512WithRSAEncryption: "sha512WithRSAEncryption",
|
|
48
|
+
shake128: "shake128",
|
|
49
|
+
shake256: "shake256",
|
|
50
|
+
sm3: "sm3",
|
|
51
|
+
sm3WithRSAEncryption: "sm3WithRSAEncryption",
|
|
52
|
+
ssl3_md5: "ssl3-md5",
|
|
53
|
+
ssl3_sha1: "ssl3-sha1"
|
|
54
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const CEncodingFormat = {
|
|
2
|
+
ascii: "ascii",
|
|
3
|
+
utf8: "utf8",
|
|
4
|
+
utf_8 :"utf-8",
|
|
5
|
+
utf16le: "utf16le",
|
|
6
|
+
utf_16le: "utf-16le",
|
|
7
|
+
ucs2: "ucs2",
|
|
8
|
+
ucs_2: "ucs-2",
|
|
9
|
+
base64: "base64",
|
|
10
|
+
base64url: "base64url",
|
|
11
|
+
latin1: "latin1",
|
|
12
|
+
binary: "binary",
|
|
13
|
+
hex: "hex"
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CAlgorithm } from "@webAppCore/core/constants/signRSA/algorithm.constant";
|
|
2
|
+
import { CKeyType } from "@webAppCore/core/constants/signRSA/keyType.constant";
|
|
3
|
+
import { COutputFormat } from "@webAppCore/core/constants/signRSA/outputFormat.constant";
|
|
4
|
+
import { CEncodingFormat } from "@webAppCore/core/constants/signRSA/encodingFormat.constant";
|
|
5
|
+
|
|
6
|
+
export const CSignRSAKeyComponent = {
|
|
7
|
+
algorithm: CAlgorithm,
|
|
8
|
+
keyType: CKeyType,
|
|
9
|
+
outputFormat: COutputFormat,
|
|
10
|
+
encodingFormat: CEncodingFormat
|
|
11
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
2
|
+
import { LoggerCore } from "opticore-logger";
|
|
3
|
+
|
|
4
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
5
|
+
import { TranslationLoader } from "opticore-translator";
|
|
6
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
7
|
+
|
|
8
|
+
export class DbConnexionConfigError {
|
|
9
|
+
|
|
10
|
+
private logger: LoggerCore;
|
|
11
|
+
private readonly localeLanguage: string;
|
|
12
|
+
|
|
13
|
+
constructor(localeLanguage: string, environmentPath: any) {
|
|
14
|
+
this.localeLanguage = localeLanguage;
|
|
15
|
+
this.logger = SLoggerFileConfiguration(environmentPath);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param e
|
|
21
|
+
*/
|
|
22
|
+
public mongoDBAuthenticationFailed(e: any): void {
|
|
23
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
24
|
+
TranslationLoader.t("mongoDBConnection", this.localeLanguage, { e: e }),
|
|
25
|
+
TranslationLoader.t("mongoDBAuthentication", this.localeLanguage),
|
|
26
|
+
status.UNAUTHORIZED
|
|
27
|
+
);
|
|
28
|
+
this.logger.error({
|
|
29
|
+
message: TranslationLoader.t("mongoDBAuthenticationError", this.localeLanguage),
|
|
30
|
+
title: TranslationLoader.t("mongoDBConnection", this.localeLanguage),
|
|
31
|
+
errorType: TranslationLoader.t("mongoDBAuthenticationFailed", this.localeLanguage),
|
|
32
|
+
stackTrace: stackTrace.stack!,
|
|
33
|
+
httpCodeValue: status.UNAUTHORIZED
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param err
|
|
40
|
+
* @param dbHost
|
|
41
|
+
* @param dbPort
|
|
42
|
+
*/
|
|
43
|
+
public mongoDBInvalidUrl(err: any, dbHost: string, dbPort: string): void {
|
|
44
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
45
|
+
TranslationLoader.t("mongoDBConnection", this.localeLanguage, { err: err }),
|
|
46
|
+
TranslationLoader.t("mongoDBUnableParsingUrl", this.localeLanguage),
|
|
47
|
+
status.BAD_REQUEST
|
|
48
|
+
);
|
|
49
|
+
this.logger.error({
|
|
50
|
+
message: TranslationLoader.t("dbUrlParsingError", this.localeLanguage, {dbHost: dbHost, dbPort: dbPort}),
|
|
51
|
+
title: TranslationLoader.t("mongoDBConnection", this.localeLanguage),
|
|
52
|
+
errorType: TranslationLoader.t("mongoDBUnableParsingUrl", this.localeLanguage),
|
|
53
|
+
stackTrace: stackTrace.stack!,
|
|
54
|
+
httpCodeValue: status.BAD_REQUEST
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param err
|
|
61
|
+
* @param dbHost
|
|
62
|
+
*/
|
|
63
|
+
public mongoDBEaiAgain(err: any, dbHost: string): void {
|
|
64
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
65
|
+
TranslationLoader.t("mongoDBConnection", this.localeLanguage, { err: err }),
|
|
66
|
+
TranslationLoader.t("mongoDBServerSelection", this.localeLanguage),
|
|
67
|
+
status.BAD_REQUEST
|
|
68
|
+
);
|
|
69
|
+
this.logger.error({
|
|
70
|
+
message: TranslationLoader.t("mongoServerError", this.localeLanguage, {dbHost: dbHost}),
|
|
71
|
+
title: TranslationLoader.t("mongoDBConnection", this.localeLanguage),
|
|
72
|
+
errorType: TranslationLoader.t("mongoDBServerSelection", this.localeLanguage),
|
|
73
|
+
stackTrace: stackTrace.stack!,
|
|
74
|
+
httpCodeValue: status.BAD_REQUEST
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param err
|
|
81
|
+
*/
|
|
82
|
+
public mongoDbGlobalError (err: any): void {
|
|
83
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
84
|
+
TranslationLoader.t("mongoDBConnection", this.localeLanguage, { err: err }),
|
|
85
|
+
TranslationLoader.t("mongoDBConnection", this.localeLanguage),
|
|
86
|
+
status.NOT_ACCEPTABLE
|
|
87
|
+
);
|
|
88
|
+
this.logger.error({
|
|
89
|
+
message: TranslationLoader.t("mongoDBConnection", this.localeLanguage),
|
|
90
|
+
title: TranslationLoader.t("mongoDBConnectionError", this.localeLanguage),
|
|
91
|
+
stackTrace: stackTrace.stack!,
|
|
92
|
+
errorType: err.code,
|
|
93
|
+
httpCodeValue:status.NOT_ACCEPTABLE
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param props
|
|
100
|
+
* @param name
|
|
101
|
+
* @param status
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
private traceError(props: string, name: string, status: number): StackTraceError {
|
|
105
|
+
return new StackTraceError(props, name, status, true);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { LoggerCore } from "opticore-logger";
|
|
3
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
4
|
+
import { TranslationLoader } from "opticore-translator";
|
|
5
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class PathModuleVerifier {
|
|
9
|
+
private log: LoggerCore;
|
|
10
|
+
private readonly localeLanguage: string;
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
constructor(localeLanguage: string, environmentPath: any) {
|
|
14
|
+
this.localeLanguage = localeLanguage;
|
|
15
|
+
this.log = SLoggerFileConfiguration(environmentPath);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Verifies if modules at specific paths are loaded.
|
|
21
|
+
* If any module is not loaded, it throws an error.
|
|
22
|
+
* @param modulePaths - An array of paths to the modules to verify.
|
|
23
|
+
*/
|
|
24
|
+
public verifyModulePaths(modulePaths: string[]): void {
|
|
25
|
+
const notLoadedPaths: string[] = [];
|
|
26
|
+
|
|
27
|
+
for (const modulePath of modulePaths) {
|
|
28
|
+
if (!this.isModulePathLoaded(modulePath)) {
|
|
29
|
+
notLoadedPaths.push(modulePath);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (notLoadedPaths.length > 0) {
|
|
34
|
+
this.log.error({
|
|
35
|
+
message: TranslationLoader.t("moduleNotLoaded", this.localeLanguage, {notLoadedPaths: notLoadedPaths.join(', ')}),
|
|
36
|
+
title: '',
|
|
37
|
+
errorType: '',
|
|
38
|
+
stackTrace: modulePaths,
|
|
39
|
+
httpCodeValue: HttpStatusCode.NOT_ACCEPTABLE
|
|
40
|
+
});
|
|
41
|
+
throw new Error();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Checks if a specific module at a given path is loaded in the Node.js require cache.
|
|
47
|
+
* @param modulePath - The path to the module.
|
|
48
|
+
* @returns True if the module is loaded, false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
private isModulePathLoaded(modulePath: string): boolean {
|
|
51
|
+
try {
|
|
52
|
+
const resolvedPath: string = resolve(modulePath);
|
|
53
|
+
return require.cache[resolvedPath] !== undefined;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SAsymmetricCryptionDataWithPrivateRSAKey } from "@webAppCore/application/services/asymmetricCryptionDataWithPrivateRSAKey.service";
|
|
2
|
+
import { SAsymmetricCryptionDataWithPublicRSAKey } from "@webAppCore/application/services/asymmetricCryptionDataWithPublicRSAKey.service";
|
|
3
|
+
import { CLogLevel } from "@webAppCore/domains/constants/logLevel.constant";
|
|
4
|
+
import { RSAKeyDecryption } from "@webAppCore/utils/cryptography/decryption/rsaKey.decryption";
|
|
5
|
+
import { RSAKeyEncryption } from "@webAppCore/utils/cryptography/encryption/rsaKey.encryption";
|
|
6
|
+
import { YamlParsing } from "@webAppCore/utils/parsing/parsingYaml.utils";
|
|
7
|
+
import { dateTimeFormatted } from "@webAppCore/utils/dateTimeFormatted.utils";
|
|
8
|
+
import { Environment } from "@webAppCore/utils/environment.utils";
|
|
9
|
+
import { loggerConfig } from "@webAppCore/core/config/logger/logger.config";
|
|
10
|
+
import { CSignRSAKeyComponent } from "@webAppCore/core/constants/signRSAKeyComponent.constant";
|
|
11
|
+
import { Utility } from "@webAppCore/utils/utility.utils";
|
|
12
|
+
import { PathModuleVerifier } from "@webAppCore/core/events/pathModuleVerifier.event";
|
|
13
|
+
import { LocalLanguageLoader } from "@webAppCore/core/config/loaders/localLanguage.loader";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Interfaces exported
|
|
19
|
+
*/
|
|
20
|
+
export { type IBodyParserOptions } from "@webAppCore/interfaces/bodyParserOptions.interface";
|
|
21
|
+
export { type IResponseBodyEndFromResponseEvent } from "@webAppCore/interfaces/responseBodyEndFromResponseEvent.interface";
|
|
22
|
+
export { type IResponseBodyWriteFromResponseEvent} from "@webAppCore/interfaces/responseBodyWriteFromResponseEvent.interface";
|
|
23
|
+
export { type IWrappingBodyResponse } from "@webAppCore/interfaces/wrappingBodyResponse.interface";
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Types exported
|
|
28
|
+
*/
|
|
29
|
+
export { type TLogLevel } from "@webAppCore/types/logLevel.type";
|
|
30
|
+
export { type TOriginalWriteEncoding } from "@webAppCore/types/originalWriteEncoding.type";
|
|
31
|
+
export { type TParseFunction } from "@webAppCore/types/parseFunction.type";
|
|
32
|
+
/**
|
|
33
|
+
* Types function exported
|
|
34
|
+
*/
|
|
35
|
+
export { type TJSONBodyParser } from "@webAppCore/types/json.type";
|
|
36
|
+
export { type TRawBodyParser } from "@webAppCore/types/raw.type";
|
|
37
|
+
export { type TTextBodyParser } from "@webAppCore/types/text.type";
|
|
38
|
+
export { type TUrlencodedBodyParser } from "@webAppCore/types/urlencoded.type";
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
CLogLevel,
|
|
44
|
+
CSignRSAKeyComponent,
|
|
45
|
+
dateTimeFormatted,
|
|
46
|
+
Environment,
|
|
47
|
+
loggerConfig,
|
|
48
|
+
LocalLanguageLoader,
|
|
49
|
+
PathModuleVerifier,
|
|
50
|
+
RSAKeyDecryption,
|
|
51
|
+
RSAKeyEncryption,
|
|
52
|
+
SAsymmetricCryptionDataWithPrivateRSAKey,
|
|
53
|
+
SAsymmetricCryptionDataWithPublicRSAKey,
|
|
54
|
+
Utility,
|
|
55
|
+
YamlParsing
|
|
56
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
|
|
3
|
+
export interface IResponseBodyEndFromResponseEvent {
|
|
4
|
+
(cb?: () => void): ServerResponse<IncomingMessage>;
|
|
5
|
+
(chunk: any, cb?: () => void): ServerResponse<IncomingMessage>;
|
|
6
|
+
(chunk: any, encoding: BufferEncoding, cb?: () => void): ServerResponse<IncomingMessage>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IBodyParserOptions } from "@webAppCore/interfaces/bodyParserOptions.interface";
|
|
2
|
+
import { MBodyParser } from "@webAppCore/application/middlewares/bodyParser.middleware";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param options
|
|
8
|
+
* @param localLanguage
|
|
9
|
+
* @param environnementPath
|
|
10
|
+
*
|
|
11
|
+
* Use by this: TJSONBodyParser({ type: 'application/vnd.custom-type' })
|
|
12
|
+
*
|
|
13
|
+
* in express, it can be used like this: app.use(TJSONBodyParser({ type: 'application/vnd.custom-type' }));
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export function TJSONBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any) {
|
|
17
|
+
return MBodyParser(JSON.parse, options, localLanguage, environnementPath);
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TOriginalWriteEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "utf-16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TParseFunction = (rawBody: string) => any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { IBodyParserOptions } from "@webAppCore/interfaces/bodyParserOptions.interface";
|
|
2
|
+
import { MBodyParser } from "@webAppCore/application/middlewares/bodyParser.middleware";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param options
|
|
8
|
+
* @param localLanguage
|
|
9
|
+
* @param environnementPath
|
|
10
|
+
*
|
|
11
|
+
* Use by this: TRawBodyParser({ type: 'application/vnd.custom-type' })
|
|
12
|
+
*
|
|
13
|
+
* in express, it can be used like this: app.use(rawBodyParserType({ type: 'application/vnd.custom-type' }));
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export function TRawBodyParser(options: IBodyParserOptions, localLanguage: string, environnementPath: any) {
|
|
17
|
+
return MBodyParser(
|
|
18
|
+
(rawBody: string) => Buffer.from(rawBody, "binary"),
|
|
19
|
+
options,
|
|
20
|
+
localLanguage,
|
|
21
|
+
environnementPath
|
|
22
|
+
);
|
|
23
|
+
}
|