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,154 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import colors from "ansi-colors";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import { TranslationLoader } from "opticore-translator";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class Utility {
|
|
10
|
+
private readonly localLang: string;
|
|
11
|
+
|
|
12
|
+
constructor(localLanguage: string) {
|
|
13
|
+
this.localLang = localLanguage;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param data
|
|
19
|
+
* @private
|
|
20
|
+
* Return a string converted in MegaBytes
|
|
21
|
+
*/
|
|
22
|
+
private formatMemoryUsage(data: any): string {
|
|
23
|
+
return `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns an Object containing a node version, openssl, and v0
|
|
28
|
+
*/
|
|
29
|
+
public getVersions() {
|
|
30
|
+
const processVers: NodeJS.ProcessVersions = process.versions;
|
|
31
|
+
const data = {
|
|
32
|
+
"node version" : processVers.node,
|
|
33
|
+
"openssl": processVers.openssl,
|
|
34
|
+
"v8": processVers.v8
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
"nodeVersion" : data["node version"],
|
|
39
|
+
"openssl": data.openssl,
|
|
40
|
+
"v8": data.v8
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return an Object containing a Resident Set Size - total memory allocated for the process execution
|
|
46
|
+
* Total size of the allocated heap
|
|
47
|
+
* Actual memory used during the execution
|
|
48
|
+
* Memory usage user
|
|
49
|
+
* and Memory usage system
|
|
50
|
+
*/
|
|
51
|
+
public getUsageMemory() {
|
|
52
|
+
const memoryData: NodeJS.MemoryUsage = process.memoryUsage();
|
|
53
|
+
const data = {
|
|
54
|
+
"Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
|
|
55
|
+
"Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
|
|
56
|
+
"Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
|
|
57
|
+
"V8 external memory": this.formatMemoryUsage(memoryData.external),
|
|
58
|
+
"Memory usage user": this.formatMemoryUsage(process.cpuUsage().user),
|
|
59
|
+
"Memory usage system": this.formatMemoryUsage(process.cpuUsage().system),
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
"rss": data["Resident Set Size - total memory allocated for the process execution"],
|
|
64
|
+
"heapTotal": data["Total size of the allocated heap"],
|
|
65
|
+
"heapUsed": data["Actual memory used during the execution"],
|
|
66
|
+
"external": data["V8 external memory"],
|
|
67
|
+
"user": data["Memory usage user"],
|
|
68
|
+
"system": data["Memory usage system"]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Return an Object containing a project path and running server time
|
|
74
|
+
*/
|
|
75
|
+
public getProjectInfo() {
|
|
76
|
+
const startTime:[number, number] = process.hrtime();
|
|
77
|
+
const endTime:[number, number] = process.hrtime(startTime);
|
|
78
|
+
const executionTime: number = (endTime[0] * 1e9 + endTime[1]) / 1e6; // Convert to milliseconds
|
|
79
|
+
return {
|
|
80
|
+
"projectPath": path.join(process.cwd()),
|
|
81
|
+
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param filePath
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
private getEnvFileLoading(filePath: string): void {
|
|
91
|
+
const fullPath: string = path.resolve(process.cwd(), filePath);
|
|
92
|
+
if (fs.existsSync(fullPath)) {
|
|
93
|
+
const env: string = fs.readFileSync(fullPath, 'utf-8');
|
|
94
|
+
const lines: string[] = env.split('\n');
|
|
95
|
+
|
|
96
|
+
lines.forEach((line: string): void => {
|
|
97
|
+
const match: RegExpMatchArray | null = line.match(/^([^#=]+)=([^#]+)$/);
|
|
98
|
+
if (match) {
|
|
99
|
+
const key: string = match[1].trim();
|
|
100
|
+
process.env[key] = match[2].trim();
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @param development
|
|
109
|
+
* @param production
|
|
110
|
+
*/
|
|
111
|
+
public getServerRunningMode(development: string, production: string): string {
|
|
112
|
+
/**
|
|
113
|
+
* Load environment variables from the .env file
|
|
114
|
+
*/
|
|
115
|
+
this.getEnvFileLoading('.env');
|
|
116
|
+
|
|
117
|
+
const isDevelopment: boolean = process.env.NODE_ENV === 'development';
|
|
118
|
+
if (isDevelopment) {
|
|
119
|
+
return `${TranslationLoader.t("serverRunning", this.localLang)} ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
120
|
+
} else {
|
|
121
|
+
return `${TranslationLoader.t("serverRunning", this.localLang)} ${colors.bgBlue(`${colors.bold(`${production}`)}`)} mode`;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public infoServer(nodeVersion: string, startingTime: any, host: string, port: number, rss: string, heapUsed: string, user: string, system: string): void {
|
|
126
|
+
// Padding length
|
|
127
|
+
const paddingLength = 52;
|
|
128
|
+
|
|
129
|
+
// Creating padded messages
|
|
130
|
+
const msg0: string = ' '.padEnd(paddingLength, ' ');
|
|
131
|
+
const msg1: string = ` ${TranslationLoader.t("okServerListening", this.localLang)}`;
|
|
132
|
+
const msg2Value: string = `${colors.bgBlue(`${colors.bold(`${nodeVersion}`)}`)}`;
|
|
133
|
+
const msg2: string = ` ${TranslationLoader.t("webServerUseNodeVersion", this.localLang)}`;
|
|
134
|
+
const msg3Value: string = `${colors.bgBlue(`${colors.bold(`${startingTime}`)}`)}`;
|
|
135
|
+
const msg3: string = ` ${TranslationLoader.t("startupTime", this.localLang)}`;
|
|
136
|
+
const msg4: string = ` ${this.getServerRunningMode('development', 'production')}`;
|
|
137
|
+
const msg5: string = ` ${colors.underline(`http://${host}:${port}`)}`;
|
|
138
|
+
|
|
139
|
+
// display the message
|
|
140
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
141
|
+
console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, ' ')));
|
|
142
|
+
console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, ' ')));
|
|
143
|
+
console.log(chalk.bgGreen.white(msg3, msg3Value.padEnd(56, ' ')));
|
|
144
|
+
console.log(chalk.bgGreen.white(msg4.padEnd(71, ' ')));
|
|
145
|
+
console.log(chalk.bgGreen.white(msg5.padEnd(61, ' ')));
|
|
146
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
147
|
+
console.log(``);
|
|
148
|
+
console.log(`${(`${TranslationLoader.t("totalMemory", this.localLang)}`)} ${colors.cyan(`${colors.bold(`${rss}`)}`)}`);
|
|
149
|
+
console.log(`${(`${TranslationLoader.t("memoryUsedDuringExecution", this.localLang)}`)} ${colors.cyan(`${colors.bold(`${heapUsed}`)}`)}`);
|
|
150
|
+
console.log(`${(`${TranslationLoader.t("memoryUsedByUser", this.localLang)}`)} ${colors.cyan(`${colors.bold(`${user}`)}`)}`);
|
|
151
|
+
console.log(`${(`${TranslationLoader.t("memoryUsedBySystem", this.localLang)}`)} ${colors.cyan(`${colors.bold(`${system}`)}`)}`);
|
|
152
|
+
console.log(``);
|
|
153
|
+
}
|
|
154
|
+
}
|