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
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { BinaryToTextEncoding } from "node:crypto";
|
|
3
|
+
import { LoggerCore } from "opticore-logger";
|
|
4
|
+
import { TranslationLoader } from "opticore-translator";
|
|
5
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
6
|
+
|
|
7
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
8
|
+
import { RSAKeyEncryption } from "@webAppCore/utils/cryptography/encryption/rsaKey.encryption";
|
|
9
|
+
import { CSignRSAKeyComponent } from "@webAppCore/core/constants/signRSAKeyComponent.constant";
|
|
10
|
+
import { RSAKeyDecryption } from "@webAppCore/utils/cryptography/decryption/rsaKey.decryption";
|
|
11
|
+
import { SLoggerFileConfiguration } from "@webAppCore/application/services/loggerFileConfiguration.service";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export class SAsymmetricCryptionDataWithPublicRSAKey {
|
|
15
|
+
private readonly logger: LoggerCore;
|
|
16
|
+
private readonly localeLanguage: string;
|
|
17
|
+
|
|
18
|
+
constructor(localeLanguage: string, environnementPath: any) {
|
|
19
|
+
this.localeLanguage = localeLanguage;
|
|
20
|
+
this.logger = SLoggerFileConfiguration(environnementPath);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param rsaKey
|
|
26
|
+
* @param keyType
|
|
27
|
+
*
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
protected verifyExistingKey(rsaKey: string, keyType: string): string | Error {
|
|
31
|
+
if (!rsaKey) {
|
|
32
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
33
|
+
keyType + TranslationLoader.t("verifyExistingKey", this.localeLanguage),
|
|
34
|
+
TranslationLoader.t("verifyExistingKey", this.localeLanguage),
|
|
35
|
+
HttpStatusCode.NOT_FOUND
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
this.logger.error({
|
|
39
|
+
message: TranslationLoader.t("verifyExistingKey", this.localeLanguage),
|
|
40
|
+
title: "key verification",
|
|
41
|
+
errorType: TranslationLoader.t("verifyExistingKeyError", this.localeLanguage),
|
|
42
|
+
stackTrace: stackTrace.stack!,
|
|
43
|
+
httpCodeValue: HttpStatusCode.NOT_FOUND
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return rsaKey;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param publicKey
|
|
54
|
+
* @param payload
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private encryptionWithPublicKey(publicKey: string, payload: any): Buffer {
|
|
59
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const bufferedData: Buffer = Buffer.from(payload, Number(CSignRSAKeyComponent.encodingFormat));
|
|
63
|
+
return RSAKeyEncryption.publicEncrypt(publicKey, bufferedData);
|
|
64
|
+
} catch (err: any) {
|
|
65
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
66
|
+
err.message,
|
|
67
|
+
TranslationLoader.t("encryptionWithPublicKey", this.localeLanguage),
|
|
68
|
+
HttpStatusCode.NOT_ACCEPTABLE
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
this.logger.error({
|
|
72
|
+
message: TranslationLoader.t("errorEncryptionPublicKey", this.localeLanguage),
|
|
73
|
+
title: TranslationLoader.t("encryptionWithPublicKey", this.localeLanguage),
|
|
74
|
+
errorType: err.code,
|
|
75
|
+
stackTrace: stackTrace.stack,
|
|
76
|
+
httpCodeValue: HttpStatusCode.NOT_ACCEPTABLE
|
|
77
|
+
});
|
|
78
|
+
process.exit();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param privateKey
|
|
86
|
+
* @param publicKey
|
|
87
|
+
* @param payload
|
|
88
|
+
*
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
private decryptionWithPrivateKey(privateKey: string, publicKey: string, payload: any): Buffer {
|
|
92
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.public);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const encryptedPayload: Buffer = this.encryptionWithPublicKey(publicKey, payload);
|
|
96
|
+
return RSAKeyDecryption.privateDecrypt(privateKey, encryptedPayload);
|
|
97
|
+
} catch (err: any) {
|
|
98
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
99
|
+
err.code,
|
|
100
|
+
TranslationLoader.t("errorDecryption", this.localeLanguage),
|
|
101
|
+
HttpStatusCode.NOT_ACCEPTABLE
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
this.logger.error({
|
|
105
|
+
message: TranslationLoader.t("errorDecryptionWithPrivateKey", this.localeLanguage),
|
|
106
|
+
title: TranslationLoader.t("errorDecryption", this.localeLanguage),
|
|
107
|
+
errorType: err.message,
|
|
108
|
+
stackTrace: stackTrace.stack,
|
|
109
|
+
httpCodeValue: HttpStatusCode.NOT_ACCEPTABLE
|
|
110
|
+
});
|
|
111
|
+
process.exit();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param publicKey
|
|
119
|
+
* @param payload
|
|
120
|
+
*
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
private signWithPublicRSAKey(publicKey: string, payload: any): string {
|
|
124
|
+
this.verifyExistingKey(publicKey, CSignRSAKeyComponent.keyType.private);
|
|
125
|
+
|
|
126
|
+
const sign: crypto.Sign = crypto.createSign(CSignRSAKeyComponent.algorithm.sha256);
|
|
127
|
+
sign.update(payload);
|
|
128
|
+
|
|
129
|
+
return sign.sign(publicKey, CSignRSAKeyComponent.outputFormat.base64 as BinaryToTextEncoding);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @param privateKey
|
|
136
|
+
* @param publicKey
|
|
137
|
+
* @param payload
|
|
138
|
+
*
|
|
139
|
+
*/
|
|
140
|
+
public verifyPublicRSAKey(privateKey: string, publicKey: string, payload: any): string | StackTraceError {
|
|
141
|
+
try {
|
|
142
|
+
const verify: crypto.Verify = crypto.createVerify(CSignRSAKeyComponent.algorithm.sha256);
|
|
143
|
+
verify.update(payload);
|
|
144
|
+
|
|
145
|
+
const signature: string = this.signWithPublicRSAKey(publicKey, payload);
|
|
146
|
+
const isVerified: boolean = verify.verify(publicKey, signature, CSignRSAKeyComponent.outputFormat.base64 as BinaryToTextEncoding);
|
|
147
|
+
|
|
148
|
+
if (isVerified) {
|
|
149
|
+
const decryptedData: Buffer = this.decryptionWithPrivateKey(privateKey, publicKey, payload);
|
|
150
|
+
return decryptedData.toString(CSignRSAKeyComponent.encodingFormat.utf_8 as BufferEncoding | undefined);
|
|
151
|
+
} else {
|
|
152
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
153
|
+
TranslationLoader.t("verifyPublicRSAKeyError", this.localeLanguage),
|
|
154
|
+
TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage),
|
|
155
|
+
HttpStatusCode.NOT_FOUND
|
|
156
|
+
);
|
|
157
|
+
this.logger.error({
|
|
158
|
+
message: TranslationLoader.t("verifyPublicRSAKey", this.localeLanguage),
|
|
159
|
+
title: TranslationLoader.t("signatureRSAKeyFailed", this.localeLanguage),
|
|
160
|
+
errorType: TranslationLoader.t("verifyPublicRSAKeyError", this.localeLanguage),
|
|
161
|
+
stackTrace: stackTrace.stack,
|
|
162
|
+
httpCodeValue: HttpStatusCode.NOT_FOUND
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return stackTrace;
|
|
166
|
+
}
|
|
167
|
+
} catch (err: any) {
|
|
168
|
+
const stackTrace: StackTraceError = this.traceError(
|
|
169
|
+
err.code,
|
|
170
|
+
TranslationLoader.t("verifyPublicRSAKey", this.localeLanguage),
|
|
171
|
+
HttpStatusCode.NOT_ACCEPTABLE
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
this.logger.error({
|
|
175
|
+
message: TranslationLoader.t("verifyPublicRSAKey", this.localeLanguage),
|
|
176
|
+
title: TranslationLoader.t("errorDecryption", this.localeLanguage),
|
|
177
|
+
errorType: err.message,
|
|
178
|
+
stackTrace: stackTrace.stack,
|
|
179
|
+
httpCodeValue: HttpStatusCode.NOT_ACCEPTABLE
|
|
180
|
+
});
|
|
181
|
+
process.exit();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private traceError(props: string, name: string, HttpStatusCode: number): StackTraceError {
|
|
186
|
+
return new StackTraceError(props, name, HttpStatusCode, true);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ILoggerConfig, LoggerCore } from "opticore-logger";
|
|
2
|
+
import { loggerConfig } from "@webAppCore/core/config/logger/logger.config";
|
|
3
|
+
|
|
4
|
+
export const SLoggerFileConfiguration: (environmentPath: any) => LoggerCore = (environmentPath: any): LoggerCore => {
|
|
5
|
+
return new LoggerCore(loggerConfig(environmentPath) as ILoggerConfig);
|
|
6
|
+
}
|
|
@@ -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
|
+
}
|