emilsoftware-utilities 2.0.0-dev.45 → 2.0.0-dev.46

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.
@@ -62,7 +62,7 @@ export declare class RestUtilities {
62
62
  * @param status - HTTP status code (default: 500).
63
63
  * @returns The Response object.
64
64
  */
65
- static sendErrorMessage(res: Response, error: unknown, _tag?: string, status?: number): Response;
65
+ static sendErrorMessage(res: Response, error: unknown, tag?: string, status?: number): Response;
66
66
  /** Riconosce errori di metadata Firebird che richiedono una migrazione. */
67
67
  static isDatabaseSchemaError(error: unknown): boolean;
68
68
  static sendUnauthorized(res: Response): Response;
@@ -75,7 +75,7 @@ export declare class RestUtilities {
75
75
  * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.
76
76
  * @returns The Response object.
77
77
  */
78
- static sendBaseResponse(res: Response, payload: unknown, status?: number): Response;
78
+ static sendBaseResponse(res: Response, payload: unknown, statusOrTag?: number | string, status?: number): Response;
79
79
  /**
80
80
  * Sends an execution message as a response.
81
81
  * @param res - Express Response object.
package/dist/Utilities.js CHANGED
@@ -117,9 +117,13 @@ class RestUtilities {
117
117
  * @param status - HTTP status code (default: 500).
118
118
  * @returns The Response object.
119
119
  */
120
- static sendErrorMessage(res, error, _tag = "[BASE ERROR]", status = 500) {
120
+ static sendErrorMessage(res, error, tag = "[BASE ERROR]", status = 500) {
121
121
  var _a, _b;
122
122
  const rawMessage = error instanceof Error ? error.message : String(error !== null && error !== void 0 ? error : "");
123
+ // Logga SEMPRE l'errore reale lato server: la risposta HTTP resta generica,
124
+ // ma senza questo log gli errori 5xx risultano impossibili da diagnosticare.
125
+ const errorStack = error instanceof Error ? error.stack : undefined;
126
+ new Logger_1.Logger(tag || "[BASE ERROR]").error(rawMessage, ...(errorStack ? [errorStack] : []));
123
127
  const errorWithResponse = error;
124
128
  const exceptionResponse = typeof (errorWithResponse === null || errorWithResponse === void 0 ? void 0 : errorWithResponse.getResponse) === "function"
125
129
  ? errorWithResponse.getResponse()
@@ -208,21 +212,28 @@ class RestUtilities {
208
212
  * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.
209
213
  * @returns The Response object.
210
214
  */
211
- static sendBaseResponse(res, payload, status = 200) {
215
+ static sendBaseResponse(res, payload, statusOrTag, status = 200) {
216
+ // Retro-compatibilita: molti controller passano un "tag" come terzo
217
+ // argomento (es. sendBaseResponse(res, dati, 'clienti')). Il tag NON e uno
218
+ // status HTTP: veniva ignorato nella firma storica e non deve rompere la risposta.
219
+ const httpStatus = typeof statusOrTag === 'number'
220
+ ? statusOrTag
221
+ : (Number.isInteger(status) ? status : 200);
222
+ const tag = typeof statusOrTag === 'string' ? statusOrTag : "[UTILITIES]";
212
223
  try {
213
- payload = JSON.parse(JSON.stringify(payload));
224
+ const normalizedPayload = JSON.parse(JSON.stringify(payload, (_key, value) => typeof value === 'bigint' ? value.toString() : value));
214
225
  const response = {
215
226
  Status: {
216
227
  errorCode: "0",
217
228
  errorDescription: "",
218
229
  },
219
- Result: payload,
230
+ Result: normalizedPayload,
220
231
  Message: "Dati recuperati con successo.",
221
232
  };
222
- return res.status(status).send(response);
233
+ return res.status(httpStatus).send(response);
223
234
  }
224
235
  catch (error) {
225
- return this.sendErrorMessage(res, `Error sending response: ${error}`, "[UTILITIES]", 500);
236
+ return this.sendErrorMessage(res, error, tag, 500);
226
237
  }
227
238
  }
228
239
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../src/Utilities.ts"],"names":[],"mappings":";;;;;;AAwjBA,gCAOG;AA7jBH,qCAAkC;AAClC,oDAA4B;AAG5B,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,uCAAM,CAAA;IACN,iDAAW,CAAA;IACX,6CAAS,CAAA;AACb,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,MAAa,aAAa;IACtB;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAAW,EAAE,WAAmB;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AC,OAAO,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Response } from 'express';\nimport { FirebirdOptions } from \"./firebird-compat\";\nimport { Logger } from \"./Logger\";\nimport crypto from \"crypto\";\n\n\nexport enum StatusCode {\n Ok = 0,\n Warning = 1,\n Error = 2,\n}\n\nexport class DateUtilities {\n /**\n * Pads a number with leading zeros to reach a specified length.\n * @param num - The number to pad.\n * @param totalLength - The total length of the resulting string.\n * @returns The padded string.\n */\n static addStartingZeros(num: number, totalLength: number): string {\n return String(num).padStart(totalLength, '0');\n }\n\n /**\n * Formats a Date object as a Moncler-style string.\n * @param dData - The date to format.\n * @param bAddMs - Whether to include milliseconds.\n * @returns The formatted date string.\n */\n static dateToMoncler(dData: Date, bAddMs: boolean = false): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n const hh = this.addStartingZeros(dData.getHours(), 2);\n const nn = this.addStartingZeros(dData.getMinutes(), 2);\n const ss = this.addStartingZeros(dData.getSeconds(), 2);\n const ms = this.addStartingZeros(dData.getMilliseconds(), 3);\n return bAddMs ? `${yy}${mm}${dd}${hh}${nn}${ss}${ms}` : `${yy}${mm}${dd}${hh}${nn}${ss}`;\n }\n\n /**\n * Formats a Date object as a SQL-style string.\n * @param dData - The date to format.\n * @param bAddMs - Whether to include milliseconds.\n * @returns The formatted date string.\n */\n static dateToSql(dData: Date, bAddMs: boolean = false): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n const hh = this.addStartingZeros(dData.getHours(), 2);\n const nn = this.addStartingZeros(dData.getMinutes(), 2);\n const ss = this.addStartingZeros(dData.getSeconds(), 2);\n const ms = this.addStartingZeros(dData.getMilliseconds(), 3);\n return bAddMs\n ? `${yy}-${mm}-${dd} ${hh}:${nn}:${ss}.${ms}`\n : `${yy}-${mm}-${dd} ${hh}:${nn}:${ss}`;\n }\n\n /**\n * Formats a Date object as a simple string (dd-MM-yyyy).\n * @param dData - The date to format.\n * @returns The formatted date string.\n */\n static dateToSimple(dData: Date): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n return `${dd}-${mm}-${yy}`;\n }\n\n /**\n * Gets the current date and time as a formatted string.\n * @returns The current date and time in the format dd.MM.yyyy HH:mm:ss.\n */\n static getNowDateString(): string {\n const now: Date = new Date();\n const day = now.getDate().toString().padStart(2, \"0\");\n const month = (now.getMonth() + 1).toString().padStart(2, \"0\");\n const year = now.getFullYear();\n const hours = now.getHours().toString().padStart(2, \"0\");\n const minutes = now.getMinutes().toString().padStart(2, \"0\");\n const seconds = now.getSeconds().toString().padStart(2, \"0\");\n return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`;\n }\n\n /**\n * Parses a date string in the format dd/MM/yyyy into a Date object.\n * @param date - The date string to parse.\n * @returns A Date object.\n */\n static parseDate(date: string): Date {\n const parts: string[] = date.split(\"/\");\n return new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));\n }\n}\n\n\nexport class RestUtilities {\n /**\n * Sends an OK message as a response.\n * @param res - Express Response object.\n * @param message - The success message.\n * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.\n * @returns The Response object.\n */\n static sendOKMessage(res: Response, message: string, status: number = 200): Response {\n return res.status(status).send({\n severity: \"success\",\n status,\n statusCode: StatusCode.Ok,\n message,\n });\n }\n\n /**\n * Sends an error message as a response.\n * @param res - Express Response object.\n * @param error - The error to send.\n * @param tag - Optional tag for additional context.\n * @param status - HTTP status code (default: 500).\n * @returns The Response object.\n */\n static sendErrorMessage(res: Response, error: unknown, _tag: string = \"[BASE ERROR]\", status: number = 500): Response {\n const rawMessage = error instanceof Error ? error.message : String(error ?? \"\");\n const errorWithResponse = error as { getResponse?: () => unknown } | null | undefined;\n const exceptionResponse = typeof errorWithResponse?.getResponse === \"function\"\n ? errorWithResponse.getResponse()\n : undefined;\n const exceptionPayload = exceptionResponse && typeof exceptionResponse === \"object\"\n ? exceptionResponse as { code?: unknown; message?: unknown; details?: unknown }\n : undefined;\n const explicitCode = typeof exceptionPayload?.code === \"string\" ? exceptionPayload.code : undefined;\n const explicitMessage = typeof exceptionPayload?.message === \"string\" ? exceptionPayload.message : undefined;\n const explicitDetails = Array.isArray(exceptionPayload?.details)\n ? exceptionPayload.details.filter((detail): detail is string => typeof detail === \"string\")\n : undefined;\n const schemaError = this.isDatabaseSchemaError(error);\n // Per le HttpException lo status corretto e quello dell'eccezione (es. 400 di validazione),\n // anche quando il chiamante non lo passa esplicitamente. Lo status esplicito vale per gli altri errori.\n const exceptionStatus = typeof errorWithResponse?.getResponse === \"function\"\n ? Number((error as { getStatus?: () => number }).getStatus?.())\n : undefined;\n const effectiveStatus = schemaError\n ? 503\n : Number.isInteger(exceptionStatus) && (exceptionStatus as number) >= 400\n ? (exceptionStatus as number)\n : status;\n const code = schemaError\n ? \"ACCESSI_DATABASE_SCHEMA_OUTDATED\"\n : explicitCode ?? (effectiveStatus >= 500\n ? \"ACCESSI_INTERNAL_ERROR\"\n : effectiveStatus === 401\n ? \"ACCESSI_UNAUTHORIZED\"\n : effectiveStatus === 403\n ? \"ACCESSI_FORBIDDEN\"\n : \"ACCESSI_REQUEST_ERROR\");\n const message = schemaError\n ? \"Lo schema del database Accessi non e aggiornato. Eseguire la migrazione database e riprovare.\"\n : explicitMessage ?? (effectiveStatus >= 500\n ? \"Errore interno del modulo Accessi.\"\n : effectiveStatus === 401\n ? \"Autenticazione non valida o scaduta.\"\n : effectiveStatus === 403\n ? \"Operazione non autorizzata.\"\n : rawMessage || \"Richiesta non valida.\");\n\n return res.status(effectiveStatus).send({\n severity: \"error\",\n status: effectiveStatus,\n statusCode: StatusCode.Error,\n code,\n message,\n // Compatibilita: il campo storico resta presente, ma non espone SQL, stack o dati sensibili.\n error: code,\n ...(explicitDetails?.length ? { details: explicitDetails } : {}),\n });\n }\n\n /** Riconosce errori di metadata Firebird che richiedono una migrazione. */\n static isDatabaseSchemaError(error: unknown): boolean {\n const message = error instanceof Error ? error.message : String(error ?? \"\");\n return /column unknown|table unknown|dynamic sql error|unsuccessful metadata update|invalid request blr/i.test(message);\n }\n\n\n static sendUnauthorized(res: Response): Response {\n return res.status(401).send({\n severity: \"error\",\n status: 401,\n statusCode: StatusCode.Error,\n code: \"ACCESSI_UNAUTHORIZED\",\n error: \"ACCESSI_UNAUTHORIZED\",\n message: \"Autenticazione non valida o scaduta.\",\n });\n }\n\n static sendInvalidCredentials(res: Response): Response {\n return res.status(401).send({\n severity: \"error\",\n status: 401,\n statusCode: StatusCode.Error,\n code: \"ACCESSI_INVALID_CREDENTIALS\",\n error: \"ACCESSI_INVALID_CREDENTIALS\",\n message: \"Credenziali non valide\",\n });\n }\n\n static sendPasswordExpired(res: Response): Response {\n return res.status(403).send({\n severity: \"warning\",\n status: 403,\n statusCode: StatusCode.Warning,\n code: \"PASSWORD_EXPIRED\",\n error: \"PASSWORD_EXPIRED\",\n message: \"Password scaduta. E' necessario aggiornarla\"\n })\n }\n\n /**\n * Sends a base response with a payload.\n * @param res - Express Response object.\n * @param payload - The payload to include in the response.\n * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.\n * @returns The Response object.\n */\n static sendBaseResponse(res: Response, payload: unknown, status: number = 200): Response {\n try {\n payload = JSON.parse(JSON.stringify(payload));\n const response = {\n Status: {\n errorCode: \"0\",\n errorDescription: \"\",\n },\n Result: payload,\n Message: \"Dati recuperati con successo.\",\n };\n return res.status(status).send(response);\n } catch (error) {\n return this.sendErrorMessage(res, `Error sending response: ${error}`, \"[UTILITIES]\", 500);\n }\n }\n\n /**\n * Sends an execution message as a response.\n * @param res - Express Response object.\n * @param executionObject - The execution data.\n * @param title - The title of the response.\n * @param status - HTTP success status. Defaults to 200.\n * @returns The Response object.\n */\n static sendExecMessage(res: Response, executionObject: unknown, title: string, status: number = 200): Response {\n try {\n const response = {\n Status: {\n errorCode: \"0\",\n errorDescription: \"\",\n },\n Sql: \"\",\n ID: (executionObject as { id?: unknown } | null | undefined)?.id,\n data: executionObject,\n Title: title,\n };\n return res.status(status).send(response);\n } catch (error) {\n return this.sendErrorMessage(res, `Error sending execution message: ${error}`, title, 500);\n }\n }\n\n /**\n * Prints a SQL query with parameters replaced. Replacement is literal: values\n * containing `?` or `$&` no longer corrupt the output as in the legacy\n * `String.replace` implementation.\n * @param query - The SQL query.\n * @param params - The parameters to replace.\n * @returns The formatted query.\n */\n static printQueryWithParams(query: string = \"\", params: unknown[] = []): string {\n let index = 0;\n return query.replace(/\\?/g, () => {\n if (index >= params.length) {\n return \"?\";\n }\n const param = params[index++];\n return param === undefined || param === null ? \"NULL\" : String(param);\n });\n }\n\n\n public static convertKeysToCamelCase<T = Record<string, unknown>>(obj: unknown): T {\n if (obj !== null && typeof obj === \"object\" && obj.constructor === Object) {\n const source = obj as Record<string, unknown>;\n const converted = Object.keys(source).reduce((acc: Record<string, unknown>, key: string) => {\n const camelCaseKey = key.toLowerCase().replace(/_([a-z])/g, g => (g[1] ?? '').toUpperCase());\n acc[camelCaseKey] = source[key];\n return acc;\n }, {});\n return converted as T;\n }\n return obj as T;\n }\n}\n\n\nexport class CryptUtilities {\n private static readonly logger = new Logger(CryptUtilities.name);\n\n /**\n * Cifra un testo in chiaro usando l'algoritmo AES-128 in modalità ECB.\n * \n * @param plainText - Il testo in chiaro da cifrare.\n * @param key - La chiave di cifratura (16 byte per AES-128).\n * @param outputEncoding - Codifica del risultato cifrato (predefinito: \"base64\").\n * @returns Il testo cifrato codificato.\n * @throws Errore in caso di problemi durante la cifratura.\n */\n public static encrypt(plainData: string, key: string, outputEncoding: BufferEncoding = \"base64\"): string {\n try {\n // Crea un oggetto Cipher usando AES-128 in modalità ECB\n const cipher = crypto.createCipheriv(\"aes-128-ecb\", Buffer.from(key, \"utf8\"), null);\n\n // Cifra il testo in chiaro e finalizza il processo\n const encryptedBuffer = Buffer.concat([\n cipher.update(plainData, \"utf8\"),\n cipher.final(),\n ]);\n\n // Restituisce il risultato cifrato codificato\n return encryptedBuffer.toString(outputEncoding);\n } catch (error) {\n // Gestisce eventuali errori di cifratura\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Errore durante la cifratura: ${message}`);\n }\n }\n\n /**\n * Decifra un testo cifrato usando l'algoritmo AES-128 in modalità ECB.\n * \n * @param encryptedData - Il testo cifrato da decifrare.\n * @param key - La chiave di decifratura (16 byte per AES-128).\n * @returns Il testo decifrato o null in caso di errore.\n */\n public static decrypt(encryptedData: string, key: string): string | null {\n try {\n // Crea un oggetto Decipher usando AES-128 in modalità ECB\n const decipher = crypto.createDecipheriv(\"aes-128-ecb\", Buffer.from(key, \"utf8\"), null);\n decipher.setAutoPadding(false);\n\n // Decifra il testo cifrato\n let decoded = decipher.update(encryptedData, \"base64\", \"utf8\");\n decoded += decipher.final(\"utf8\");\n\n // Rimuove il padding manuale\n const lastChar = decoded.charCodeAt(decoded.length - 1);\n decoded = decoded.slice(0, decoded.length - lastChar);\n\n return decoded;\n } catch (error) {\n CryptUtilities.logger.error(\"Errore durante la decifratura:\", error);\n return null;\n }\n }\n}\n\nexport class PasswordUtilities {\n private static readonly HASH_PREFIX = \"scrypt\";\n private static readonly LEGACY_HASH_PREFIX = \"scrypt-legacy\";\n private static readonly SCRYPT_N = 16384;\n private static readonly SCRYPT_R = 8;\n private static readonly SCRYPT_P = 1;\n private static readonly SALT_LENGTH = 16;\n\n private static hashSecret(secretValue: string, prefix: string): string {\n if (typeof secretValue !== \"string\" || secretValue.length === 0) {\n throw new Error(\"Il valore da proteggere non puo essere vuoto.\");\n }\n const salt = crypto.randomBytes(this.SALT_LENGTH).toString(\"hex\");\n const derivedKey = crypto.scryptSync(\n secretValue,\n salt,\n 64,\n {\n N: this.SCRYPT_N,\n r: this.SCRYPT_R,\n p: this.SCRYPT_P,\n maxmem: 64 * 1024 * 1024,\n },\n );\n\n return [\n prefix,\n this.SCRYPT_N,\n this.SCRYPT_R,\n this.SCRYPT_P,\n salt,\n derivedKey.toString(\"hex\"),\n ].join(\"$\");\n }\n\n private static hasPrefix(value: string, prefix: string): boolean {\n return typeof value === \"string\" && value.startsWith(`${prefix}$`);\n }\n\n private static parseHash(\n storedPassword: string,\n expectedPrefix: string\n ): {\n salt: string;\n expectedHash: Buffer;\n N: number;\n r: number;\n p: number;\n } | null {\n if (!this.hasPrefix(storedPassword, expectedPrefix)) {\n return null;\n }\n\n const [, rawN, rawR, rawP, salt, expectedHashHex] = storedPassword.split(\"$\");\n const N = Number(rawN);\n const r = Number(rawR);\n const p = Number(rawP);\n\n if (!salt || !expectedHashHex || !Number.isFinite(N) || !Number.isFinite(r) || !Number.isFinite(p)) {\n return null;\n }\n\n const expectedHash = Buffer.from(expectedHashHex, \"hex\");\n if (expectedHash.length === 0) {\n return null;\n }\n\n return {\n salt,\n expectedHash,\n N,\n r,\n p,\n };\n }\n\n private static verifySecret(secretValue: string, storedPassword: string, expectedPrefix: string): boolean {\n if (typeof secretValue !== \"string\") {\n return false;\n }\n\n const parsedHash = this.parseHash(storedPassword, expectedPrefix);\n if (!parsedHash) {\n return false;\n }\n\n const derivedKey = crypto.scryptSync(\n secretValue,\n parsedHash.salt,\n parsedHash.expectedHash.length,\n {\n N: parsedHash.N,\n r: parsedHash.r,\n p: parsedHash.p,\n maxmem: 64 * 1024 * 1024,\n },\n );\n\n return crypto.timingSafeEqual(derivedKey, parsedHash.expectedHash);\n }\n\n public static hashPassword(plainPassword: string): string {\n return this.hashSecret(plainPassword, this.HASH_PREFIX);\n }\n\n public static hashLegacyEncryptedPassword(legacyEncryptedPassword: string): string {\n return this.hashSecret(legacyEncryptedPassword, this.LEGACY_HASH_PREFIX);\n }\n\n public static isPasswordHash(value: string): boolean {\n return this.hasPrefix(value, this.HASH_PREFIX);\n }\n\n public static isLegacyPasswordHash(value: string): boolean {\n return this.hasPrefix(value, this.LEGACY_HASH_PREFIX);\n }\n\n /** Confronto a tempo costante tra due stringhe (per dati legacy non hashati). */\n public static timingSafeStringEquals(value: string, candidate: string): boolean {\n if (typeof value !== \"string\" || typeof candidate !== \"string\") {\n return false;\n }\n\n const valueBuffer = Buffer.from(value, \"utf8\");\n const candidateBuffer = Buffer.from(candidate, \"utf8\");\n\n if (valueBuffer.length !== candidateBuffer.length) {\n // Confronta comunque per non rivelare la lunghezza tramite timing.\n crypto.timingSafeEqual(valueBuffer, valueBuffer);\n return false;\n }\n\n return crypto.timingSafeEqual(valueBuffer, candidateBuffer);\n }\n\n public static verifyPassword(plainPassword: string, storedPassword: string): boolean {\n return this.verifySecret(plainPassword, storedPassword, this.HASH_PREFIX);\n }\n\n public static verifyLegacyEncryptedPassword(\n legacyEncryptedPassword: string,\n storedPassword: string\n ): boolean {\n return this.verifySecret(legacyEncryptedPassword, storedPassword, this.LEGACY_HASH_PREFIX);\n }\n}\n\n\n\n\n\n/**\n * Utility class for managing database-related configurations and operations.\n */\nexport class DatabaseUtilities {\n /**\n * Creates a configuration object for connecting to a Firebird database.\n *\n * @param {string} host - The hostname or IP address of the database server.\n * @param {number} port - The port number on which the database server is running.\n * @param {string} database - The path or alias of the database to connect to.\n * @param {string} [username='SYSDBA'] - The username for authentication. Defaults to 'SYSDBA'.\n * @param {string} [password='masterkey'] - The password for authentication. Defaults to 'masterkey'.\n * @returns {Options} - The configuration object to use for establishing a Firebird database connection.\n *\n * @example\n * ```typescript\n * const options = DatabaseUtilities.createOption(\n * 'localhost',\n * 3050,\n * '/path/to/database.fdb',\n * 'myUsername',\n * 'myPassword'\n * );\n * ```\n */\n public static createOption(\n host: string,\n port: number,\n database: string,\n username = 'SYSDBA',\n password = 'masterkey'\n ): FirebirdOptions {\n return {\n host, // The hostname or IP address of the database server.\n port, // The port number used by the database server.\n user: username, // The username for database authentication.\n password, // The password for database authentication.\n database, // The path or alias of the target database.\n lowercase_keys: false, // Determines if the keys in query results should be in lowercase. Default: false.\n role: undefined, // The role for the database connection. Default: undefined.\n pageSize: 100000, // The page size for database transactions. Default: 100,000.\n retryConnectionInterval: 1000, // The interval (in ms) to retry a failed connection. Default: 1,000 ms.\n blobAsText: true, // Determines if BLOB fields should be treated as text. Default: true.\n connectTimeout: 15000,\n connectTimeoutMs: 15000,\n trimStringResults: true,\n };\n }\n}\n\nconst deprecationLogger = new Logger('Deprecated');\n\nexport function Deprecated(message: string) {\n return function (target: object, key?: string, descriptor?: PropertyDescriptor) {\n void target;\n void key;\n void descriptor;\n deprecationLogger.warning(`[DEPRECATED] ${message}`);\n };\n }\n"]}
1
+ {"version":3,"file":"Utilities.js","sourceRoot":"","sources":["../src/Utilities.ts"],"names":[],"mappings":";;;;;;AAqkBA,gCAOG;AA1kBH,qCAAkC;AAClC,oDAA4B;AAG5B,IAAY,UAIX;AAJD,WAAY,UAAU;IAClB,uCAAM,CAAA;IACN,iDAAW,CAAA;IACX,6CAAS,CAAA;AACb,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,MAAa,aAAa;IACtB;;;;;OAKG;IACH,MAAM,CAAC,gBAAgB,CAAC,GAAW,EAAE,WAAmB;QACpD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,KAAW,EAAE,SAAkB,KAAK;QACrD,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1D,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QACrD,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ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,iBAAiB,EAAE,IAAI;SAC1B,CAAC;IACN,CAAC;CACJ;AA7CD,8CA6CC;AAED,MAAM,iBAAiB,GAAG,IAAI,eAAM,CAAC,YAAY,CAAC,CAAC;AAEnD,SAAgB,UAAU,CAAC,OAAe;IACtC,OAAO,UAAU,MAAc,EAAE,GAAY,EAAE,UAA+B;QAC5E,KAAK,MAAM,CAAC;QACZ,KAAK,GAAG,CAAC;QACT,KAAK,UAAU,CAAC;QAChB,iBAAiB,CAAC,OAAO,CAAC,gBAAgB,OAAO,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { Response } from 'express';\nimport { FirebirdOptions } from \"./firebird-compat\";\nimport { Logger } from \"./Logger\";\nimport crypto from \"crypto\";\n\n\nexport enum StatusCode {\n Ok = 0,\n Warning = 1,\n Error = 2,\n}\n\nexport class DateUtilities {\n /**\n * Pads a number with leading zeros to reach a specified length.\n * @param num - The number to pad.\n * @param totalLength - The total length of the resulting string.\n * @returns The padded string.\n */\n static addStartingZeros(num: number, totalLength: number): string {\n return String(num).padStart(totalLength, '0');\n }\n\n /**\n * Formats a Date object as a Moncler-style string.\n * @param dData - The date to format.\n * @param bAddMs - Whether to include milliseconds.\n * @returns The formatted date string.\n */\n static dateToMoncler(dData: Date, bAddMs: boolean = false): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n const hh = this.addStartingZeros(dData.getHours(), 2);\n const nn = this.addStartingZeros(dData.getMinutes(), 2);\n const ss = this.addStartingZeros(dData.getSeconds(), 2);\n const ms = this.addStartingZeros(dData.getMilliseconds(), 3);\n return bAddMs ? `${yy}${mm}${dd}${hh}${nn}${ss}${ms}` : `${yy}${mm}${dd}${hh}${nn}${ss}`;\n }\n\n /**\n * Formats a Date object as a SQL-style string.\n * @param dData - The date to format.\n * @param bAddMs - Whether to include milliseconds.\n * @returns The formatted date string.\n */\n static dateToSql(dData: Date, bAddMs: boolean = false): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n const hh = this.addStartingZeros(dData.getHours(), 2);\n const nn = this.addStartingZeros(dData.getMinutes(), 2);\n const ss = this.addStartingZeros(dData.getSeconds(), 2);\n const ms = this.addStartingZeros(dData.getMilliseconds(), 3);\n return bAddMs\n ? `${yy}-${mm}-${dd} ${hh}:${nn}:${ss}.${ms}`\n : `${yy}-${mm}-${dd} ${hh}:${nn}:${ss}`;\n }\n\n /**\n * Formats a Date object as a simple string (dd-MM-yyyy).\n * @param dData - The date to format.\n * @returns The formatted date string.\n */\n static dateToSimple(dData: Date): string {\n const yy = dData.getFullYear();\n const mm = this.addStartingZeros(dData.getMonth() + 1, 2);\n const dd = this.addStartingZeros(dData.getDate(), 2);\n return `${dd}-${mm}-${yy}`;\n }\n\n /**\n * Gets the current date and time as a formatted string.\n * @returns The current date and time in the format dd.MM.yyyy HH:mm:ss.\n */\n static getNowDateString(): string {\n const now: Date = new Date();\n const day = now.getDate().toString().padStart(2, \"0\");\n const month = (now.getMonth() + 1).toString().padStart(2, \"0\");\n const year = now.getFullYear();\n const hours = now.getHours().toString().padStart(2, \"0\");\n const minutes = now.getMinutes().toString().padStart(2, \"0\");\n const seconds = now.getSeconds().toString().padStart(2, \"0\");\n return `${day}.${month}.${year} ${hours}:${minutes}:${seconds}`;\n }\n\n /**\n * Parses a date string in the format dd/MM/yyyy into a Date object.\n * @param date - The date string to parse.\n * @returns A Date object.\n */\n static parseDate(date: string): Date {\n const parts: string[] = date.split(\"/\");\n return new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));\n }\n}\n\n\nexport class RestUtilities {\n /**\n * Sends an OK message as a response.\n * @param res - Express Response object.\n * @param message - The success message.\n * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.\n * @returns The Response object.\n */\n static sendOKMessage(res: Response, message: string, status: number = 200): Response {\n return res.status(status).send({\n severity: \"success\",\n status,\n statusCode: StatusCode.Ok,\n message,\n });\n }\n\n /**\n * Sends an error message as a response.\n * @param res - Express Response object.\n * @param error - The error to send.\n * @param tag - Optional tag for additional context.\n * @param status - HTTP status code (default: 500).\n * @returns The Response object.\n */\n static sendErrorMessage(res: Response, error: unknown, tag: string = \"[BASE ERROR]\", status: number = 500): Response {\n const rawMessage = error instanceof Error ? error.message : String(error ?? \"\");\n // Logga SEMPRE l'errore reale lato server: la risposta HTTP resta generica,\n // ma senza questo log gli errori 5xx risultano impossibili da diagnosticare.\n const errorStack = error instanceof Error ? error.stack : undefined;\n new Logger(tag || \"[BASE ERROR]\").error(rawMessage, ...(errorStack ? [errorStack] : []));\n const errorWithResponse = error as { getResponse?: () => unknown } | null | undefined;\n const exceptionResponse = typeof errorWithResponse?.getResponse === \"function\"\n ? errorWithResponse.getResponse()\n : undefined;\n const exceptionPayload = exceptionResponse && typeof exceptionResponse === \"object\"\n ? exceptionResponse as { code?: unknown; message?: unknown; details?: unknown }\n : undefined;\n const explicitCode = typeof exceptionPayload?.code === \"string\" ? exceptionPayload.code : undefined;\n const explicitMessage = typeof exceptionPayload?.message === \"string\" ? exceptionPayload.message : undefined;\n const explicitDetails = Array.isArray(exceptionPayload?.details)\n ? exceptionPayload.details.filter((detail): detail is string => typeof detail === \"string\")\n : undefined;\n const schemaError = this.isDatabaseSchemaError(error);\n // Per le HttpException lo status corretto e quello dell'eccezione (es. 400 di validazione),\n // anche quando il chiamante non lo passa esplicitamente. Lo status esplicito vale per gli altri errori.\n const exceptionStatus = typeof errorWithResponse?.getResponse === \"function\"\n ? Number((error as { getStatus?: () => number }).getStatus?.())\n : undefined;\n const effectiveStatus = schemaError\n ? 503\n : Number.isInteger(exceptionStatus) && (exceptionStatus as number) >= 400\n ? (exceptionStatus as number)\n : status;\n const code = schemaError\n ? \"ACCESSI_DATABASE_SCHEMA_OUTDATED\"\n : explicitCode ?? (effectiveStatus >= 500\n ? \"ACCESSI_INTERNAL_ERROR\"\n : effectiveStatus === 401\n ? \"ACCESSI_UNAUTHORIZED\"\n : effectiveStatus === 403\n ? \"ACCESSI_FORBIDDEN\"\n : \"ACCESSI_REQUEST_ERROR\");\n const message = schemaError\n ? \"Lo schema del database Accessi non e aggiornato. Eseguire la migrazione database e riprovare.\"\n : explicitMessage ?? (effectiveStatus >= 500\n ? \"Errore interno del modulo Accessi.\"\n : effectiveStatus === 401\n ? \"Autenticazione non valida o scaduta.\"\n : effectiveStatus === 403\n ? \"Operazione non autorizzata.\"\n : rawMessage || \"Richiesta non valida.\");\n\n return res.status(effectiveStatus).send({\n severity: \"error\",\n status: effectiveStatus,\n statusCode: StatusCode.Error,\n code,\n message,\n // Compatibilita: il campo storico resta presente, ma non espone SQL, stack o dati sensibili.\n error: code,\n ...(explicitDetails?.length ? { details: explicitDetails } : {}),\n });\n }\n\n /** Riconosce errori di metadata Firebird che richiedono una migrazione. */\n static isDatabaseSchemaError(error: unknown): boolean {\n const message = error instanceof Error ? error.message : String(error ?? \"\");\n return /column unknown|table unknown|dynamic sql error|unsuccessful metadata update|invalid request blr/i.test(message);\n }\n\n\n static sendUnauthorized(res: Response): Response {\n return res.status(401).send({\n severity: \"error\",\n status: 401,\n statusCode: StatusCode.Error,\n code: \"ACCESSI_UNAUTHORIZED\",\n error: \"ACCESSI_UNAUTHORIZED\",\n message: \"Autenticazione non valida o scaduta.\",\n });\n }\n\n static sendInvalidCredentials(res: Response): Response {\n return res.status(401).send({\n severity: \"error\",\n status: 401,\n statusCode: StatusCode.Error,\n code: \"ACCESSI_INVALID_CREDENTIALS\",\n error: \"ACCESSI_INVALID_CREDENTIALS\",\n message: \"Credenziali non valide\",\n });\n }\n\n static sendPasswordExpired(res: Response): Response {\n return res.status(403).send({\n severity: \"warning\",\n status: 403,\n statusCode: StatusCode.Warning,\n code: \"PASSWORD_EXPIRED\",\n error: \"PASSWORD_EXPIRED\",\n message: \"Password scaduta. E' necessario aggiornarla\"\n })\n }\n\n /**\n * Sends a base response with a payload.\n * @param res - Express Response object.\n * @param payload - The payload to include in the response.\n * @param status - HTTP success status. Defaults to 200; pass 201 only after creating a resource.\n * @returns The Response object.\n */\n static sendBaseResponse(res: Response, payload: unknown, statusOrTag?: number | string, status: number = 200): Response {\n // Retro-compatibilita: molti controller passano un \"tag\" come terzo\n // argomento (es. sendBaseResponse(res, dati, 'clienti')). Il tag NON e uno\n // status HTTP: veniva ignorato nella firma storica e non deve rompere la risposta.\n const httpStatus = typeof statusOrTag === 'number'\n ? statusOrTag\n : (Number.isInteger(status) ? status : 200);\n const tag = typeof statusOrTag === 'string' ? statusOrTag : \"[UTILITIES]\";\n try {\n const normalizedPayload = JSON.parse(JSON.stringify(payload, (_key, value) =>\n typeof value === 'bigint' ? value.toString() : value\n ));\n const response = {\n Status: {\n errorCode: \"0\",\n errorDescription: \"\",\n },\n Result: normalizedPayload,\n Message: \"Dati recuperati con successo.\",\n };\n return res.status(httpStatus).send(response);\n } catch (error) {\n return this.sendErrorMessage(res, error, tag, 500);\n }\n }\n\n /**\n * Sends an execution message as a response.\n * @param res - Express Response object.\n * @param executionObject - The execution data.\n * @param title - The title of the response.\n * @param status - HTTP success status. Defaults to 200.\n * @returns The Response object.\n */\n static sendExecMessage(res: Response, executionObject: unknown, title: string, status: number = 200): Response {\n try {\n const response = {\n Status: {\n errorCode: \"0\",\n errorDescription: \"\",\n },\n Sql: \"\",\n ID: (executionObject as { id?: unknown } | null | undefined)?.id,\n data: executionObject,\n Title: title,\n };\n return res.status(status).send(response);\n } catch (error) {\n return this.sendErrorMessage(res, `Error sending execution message: ${error}`, title, 500);\n }\n }\n\n /**\n * Prints a SQL query with parameters replaced. Replacement is literal: values\n * containing `?` or `$&` no longer corrupt the output as in the legacy\n * `String.replace` implementation.\n * @param query - The SQL query.\n * @param params - The parameters to replace.\n * @returns The formatted query.\n */\n static printQueryWithParams(query: string = \"\", params: unknown[] = []): string {\n let index = 0;\n return query.replace(/\\?/g, () => {\n if (index >= params.length) {\n return \"?\";\n }\n const param = params[index++];\n return param === undefined || param === null ? \"NULL\" : String(param);\n });\n }\n\n\n public static convertKeysToCamelCase<T = Record<string, unknown>>(obj: unknown): T {\n if (obj !== null && typeof obj === \"object\" && obj.constructor === Object) {\n const source = obj as Record<string, unknown>;\n const converted = Object.keys(source).reduce((acc: Record<string, unknown>, key: string) => {\n const camelCaseKey = key.toLowerCase().replace(/_([a-z])/g, g => (g[1] ?? '').toUpperCase());\n acc[camelCaseKey] = source[key];\n return acc;\n }, {});\n return converted as T;\n }\n return obj as T;\n }\n}\n\n\nexport class CryptUtilities {\n private static readonly logger = new Logger(CryptUtilities.name);\n\n /**\n * Cifra un testo in chiaro usando l'algoritmo AES-128 in modalità ECB.\n * \n * @param plainText - Il testo in chiaro da cifrare.\n * @param key - La chiave di cifratura (16 byte per AES-128).\n * @param outputEncoding - Codifica del risultato cifrato (predefinito: \"base64\").\n * @returns Il testo cifrato codificato.\n * @throws Errore in caso di problemi durante la cifratura.\n */\n public static encrypt(plainData: string, key: string, outputEncoding: BufferEncoding = \"base64\"): string {\n try {\n // Crea un oggetto Cipher usando AES-128 in modalità ECB\n const cipher = crypto.createCipheriv(\"aes-128-ecb\", Buffer.from(key, \"utf8\"), null);\n\n // Cifra il testo in chiaro e finalizza il processo\n const encryptedBuffer = Buffer.concat([\n cipher.update(plainData, \"utf8\"),\n cipher.final(),\n ]);\n\n // Restituisce il risultato cifrato codificato\n return encryptedBuffer.toString(outputEncoding);\n } catch (error) {\n // Gestisce eventuali errori di cifratura\n const message = error instanceof Error ? error.message : String(error);\n throw new Error(`Errore durante la cifratura: ${message}`);\n }\n }\n\n /**\n * Decifra un testo cifrato usando l'algoritmo AES-128 in modalità ECB.\n * \n * @param encryptedData - Il testo cifrato da decifrare.\n * @param key - La chiave di decifratura (16 byte per AES-128).\n * @returns Il testo decifrato o null in caso di errore.\n */\n public static decrypt(encryptedData: string, key: string): string | null {\n try {\n // Crea un oggetto Decipher usando AES-128 in modalità ECB\n const decipher = crypto.createDecipheriv(\"aes-128-ecb\", Buffer.from(key, \"utf8\"), null);\n decipher.setAutoPadding(false);\n\n // Decifra il testo cifrato\n let decoded = decipher.update(encryptedData, \"base64\", \"utf8\");\n decoded += decipher.final(\"utf8\");\n\n // Rimuove il padding manuale\n const lastChar = decoded.charCodeAt(decoded.length - 1);\n decoded = decoded.slice(0, decoded.length - lastChar);\n\n return decoded;\n } catch (error) {\n CryptUtilities.logger.error(\"Errore durante la decifratura:\", error);\n return null;\n }\n }\n}\n\nexport class PasswordUtilities {\n private static readonly HASH_PREFIX = \"scrypt\";\n private static readonly LEGACY_HASH_PREFIX = \"scrypt-legacy\";\n private static readonly SCRYPT_N = 16384;\n private static readonly SCRYPT_R = 8;\n private static readonly SCRYPT_P = 1;\n private static readonly SALT_LENGTH = 16;\n\n private static hashSecret(secretValue: string, prefix: string): string {\n if (typeof secretValue !== \"string\" || secretValue.length === 0) {\n throw new Error(\"Il valore da proteggere non puo essere vuoto.\");\n }\n const salt = crypto.randomBytes(this.SALT_LENGTH).toString(\"hex\");\n const derivedKey = crypto.scryptSync(\n secretValue,\n salt,\n 64,\n {\n N: this.SCRYPT_N,\n r: this.SCRYPT_R,\n p: this.SCRYPT_P,\n maxmem: 64 * 1024 * 1024,\n },\n );\n\n return [\n prefix,\n this.SCRYPT_N,\n this.SCRYPT_R,\n this.SCRYPT_P,\n salt,\n derivedKey.toString(\"hex\"),\n ].join(\"$\");\n }\n\n private static hasPrefix(value: string, prefix: string): boolean {\n return typeof value === \"string\" && value.startsWith(`${prefix}$`);\n }\n\n private static parseHash(\n storedPassword: string,\n expectedPrefix: string\n ): {\n salt: string;\n expectedHash: Buffer;\n N: number;\n r: number;\n p: number;\n } | null {\n if (!this.hasPrefix(storedPassword, expectedPrefix)) {\n return null;\n }\n\n const [, rawN, rawR, rawP, salt, expectedHashHex] = storedPassword.split(\"$\");\n const N = Number(rawN);\n const r = Number(rawR);\n const p = Number(rawP);\n\n if (!salt || !expectedHashHex || !Number.isFinite(N) || !Number.isFinite(r) || !Number.isFinite(p)) {\n return null;\n }\n\n const expectedHash = Buffer.from(expectedHashHex, \"hex\");\n if (expectedHash.length === 0) {\n return null;\n }\n\n return {\n salt,\n expectedHash,\n N,\n r,\n p,\n };\n }\n\n private static verifySecret(secretValue: string, storedPassword: string, expectedPrefix: string): boolean {\n if (typeof secretValue !== \"string\") {\n return false;\n }\n\n const parsedHash = this.parseHash(storedPassword, expectedPrefix);\n if (!parsedHash) {\n return false;\n }\n\n const derivedKey = crypto.scryptSync(\n secretValue,\n parsedHash.salt,\n parsedHash.expectedHash.length,\n {\n N: parsedHash.N,\n r: parsedHash.r,\n p: parsedHash.p,\n maxmem: 64 * 1024 * 1024,\n },\n );\n\n return crypto.timingSafeEqual(derivedKey, parsedHash.expectedHash);\n }\n\n public static hashPassword(plainPassword: string): string {\n return this.hashSecret(plainPassword, this.HASH_PREFIX);\n }\n\n public static hashLegacyEncryptedPassword(legacyEncryptedPassword: string): string {\n return this.hashSecret(legacyEncryptedPassword, this.LEGACY_HASH_PREFIX);\n }\n\n public static isPasswordHash(value: string): boolean {\n return this.hasPrefix(value, this.HASH_PREFIX);\n }\n\n public static isLegacyPasswordHash(value: string): boolean {\n return this.hasPrefix(value, this.LEGACY_HASH_PREFIX);\n }\n\n /** Confronto a tempo costante tra due stringhe (per dati legacy non hashati). */\n public static timingSafeStringEquals(value: string, candidate: string): boolean {\n if (typeof value !== \"string\" || typeof candidate !== \"string\") {\n return false;\n }\n\n const valueBuffer = Buffer.from(value, \"utf8\");\n const candidateBuffer = Buffer.from(candidate, \"utf8\");\n\n if (valueBuffer.length !== candidateBuffer.length) {\n // Confronta comunque per non rivelare la lunghezza tramite timing.\n crypto.timingSafeEqual(valueBuffer, valueBuffer);\n return false;\n }\n\n return crypto.timingSafeEqual(valueBuffer, candidateBuffer);\n }\n\n public static verifyPassword(plainPassword: string, storedPassword: string): boolean {\n return this.verifySecret(plainPassword, storedPassword, this.HASH_PREFIX);\n }\n\n public static verifyLegacyEncryptedPassword(\n legacyEncryptedPassword: string,\n storedPassword: string\n ): boolean {\n return this.verifySecret(legacyEncryptedPassword, storedPassword, this.LEGACY_HASH_PREFIX);\n }\n}\n\n\n\n\n\n/**\n * Utility class for managing database-related configurations and operations.\n */\nexport class DatabaseUtilities {\n /**\n * Creates a configuration object for connecting to a Firebird database.\n *\n * @param {string} host - The hostname or IP address of the database server.\n * @param {number} port - The port number on which the database server is running.\n * @param {string} database - The path or alias of the database to connect to.\n * @param {string} [username='SYSDBA'] - The username for authentication. Defaults to 'SYSDBA'.\n * @param {string} [password='masterkey'] - The password for authentication. Defaults to 'masterkey'.\n * @returns {Options} - The configuration object to use for establishing a Firebird database connection.\n *\n * @example\n * ```typescript\n * const options = DatabaseUtilities.createOption(\n * 'localhost',\n * 3050,\n * '/path/to/database.fdb',\n * 'myUsername',\n * 'myPassword'\n * );\n * ```\n */\n public static createOption(\n host: string,\n port: number,\n database: string,\n username = 'SYSDBA',\n password = 'masterkey'\n ): FirebirdOptions {\n return {\n host, // The hostname or IP address of the database server.\n port, // The port number used by the database server.\n user: username, // The username for database authentication.\n password, // The password for database authentication.\n database, // The path or alias of the target database.\n lowercase_keys: false, // Determines if the keys in query results should be in lowercase. Default: false.\n role: undefined, // The role for the database connection. Default: undefined.\n pageSize: 100000, // The page size for database transactions. Default: 100,000.\n retryConnectionInterval: 1000, // The interval (in ms) to retry a failed connection. Default: 1,000 ms.\n blobAsText: true, // Determines if BLOB fields should be treated as text. Default: true.\n connectTimeout: 15000,\n connectTimeoutMs: 15000,\n trimStringResults: true,\n };\n }\n}\n\nconst deprecationLogger = new Logger('Deprecated');\n\nexport function Deprecated(message: string) {\n return function (target: object, key?: string, descriptor?: PropertyDescriptor) {\n void target;\n void key;\n void descriptor;\n deprecationLogger.warning(`[DEPRECATED] ${message}`);\n };\n }\n"]}
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AccessiHttpExceptionFilter = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  const Utilities_1 = require("../../Utilities");
12
+ const Logger_1 = require("../../Logger");
12
13
  /**
13
14
  * Finalizes every exception raised before an Accessi controller can reply.
14
15
  *
@@ -53,6 +54,8 @@ let AccessiHttpExceptionFilter = class AccessiHttpExceptionFilter {
53
54
  : status >= common_1.HttpStatus.INTERNAL_SERVER_ERROR
54
55
  ? 'Errore interno del modulo Accessi.'
55
56
  : 'Richiesta non valida.');
57
+ const stack = exception instanceof Error ? exception.stack : undefined;
58
+ new Logger_1.Logger('[ACCESSI-EXCEPTION]').error(`HTTP ${status} ${code}: ${exception instanceof Error ? exception.message : String(exception)}`, ...(stack ? [stack] : []));
56
59
  response.status(status).json(Object.assign({ severity: 'error', status, statusCode: Utilities_1.StatusCode.Error, code, error: code, message }, (((_b = payload.details) === null || _b === void 0 ? void 0 : _b.length) ? { details: payload.details } : {})));
57
60
  }
58
61
  getPayload(exception) {
@@ -1 +1 @@
1
- {"version":3,"file":"AccessiHttpExceptionFilter.js","sourceRoot":"","sources":["../../../src/accessi-module/security/AccessiHttpExceptionFilter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAkG;AAElG,+CAA4D;AAS5D;;;;;GAKG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACrC,KAAK,CAAC,SAAkB,EAAE,IAAmB;;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAY,CAAC;QAC7D,IAAI,QAAQ,CAAC,WAAW;YAAE,OAAO;QAEjC,MAAM,MAAM,GAAG,SAAS,YAAY,sBAAa;YAC/C,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE;YACvB,CAAC,CAAC,yBAAa,CAAC,qBAAqB,CAAC,SAAS,CAAC;gBAC9C,CAAC,CAAC,mBAAU,CAAC,mBAAmB;gBAChC,CAAC,CAAC,mBAAU,CAAC,qBAAqB,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,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'express';\nimport { RestUtilities, StatusCode } from '../../Utilities';\n\ntype ExceptionPayload = {\n code?: string;\n error?: string;\n message?: string | string[];\n details?: string[];\n};\n\n/**\n * Finalizes every exception raised before an Accessi controller can reply.\n *\n * This includes invalid JSON, validation-pipe errors and guard failures. The\n * filter deliberately never return SQL, stack traces or provider diagnostics.\n */\n@Catch()\nexport class AccessiHttpExceptionFilter implements ExceptionFilter {\n catch(exception: unknown, host: ArgumentsHost): void {\n const response = host.switchToHttp().getResponse<Response>();\n if (response.headersSent) return;\n\n const status = exception instanceof HttpException\n ? exception.getStatus()\n : RestUtilities.isDatabaseSchemaError(exception)\n ? HttpStatus.SERVICE_UNAVAILABLE\n : HttpStatus.INTERNAL_SERVER_ERROR;\n const payload = this.getPayload(exception);\n const invalidJson = status === HttpStatus.BAD_REQUEST && this.isInvalidJson(exception, payload);\n const explicitMessage = typeof payload.message === 'string' ? payload.message : undefined;\n const code = payload.code\n ?? (RestUtilities.isDatabaseSchemaError(exception)\n ? 'ACCESSI_DATABASE_SCHEMA_OUTDATED'\n : invalidJson\n ? 'ACCESSI_INVALID_JSON'\n : status === HttpStatus.BAD_REQUEST\n ? 'ACCESSI_REQUEST_ERROR'\n : status === HttpStatus.UNAUTHORIZED\n ? 'ACCESSI_UNAUTHORIZED'\n : status === HttpStatus.FORBIDDEN\n ? 'ACCESSI_FORBIDDEN'\n : 'ACCESSI_INTERNAL_ERROR');\n\n const message = code === 'ACCESSI_VALIDATION_ERROR'\n ? 'La richiesta contiene dati non validi.'\n : code === 'ACCESSI_DATABASE_SCHEMA_OUTDATED'\n ? 'Lo schema del database Accessi non e aggiornato. Eseguire la migrazione database e riprovare.'\n : invalidJson\n ? 'Il corpo della richiesta non contiene JSON valido.'\n : explicitMessage ?? (status === HttpStatus.UNAUTHORIZED\n ? 'Autenticazione non valida o scaduta.'\n : status === HttpStatus.FORBIDDEN\n ? 'Operazione non autorizzata.'\n : status >= HttpStatus.INTERNAL_SERVER_ERROR\n ? 'Errore interno del modulo Accessi.'\n : 'Richiesta non valida.');\n\n response.status(status).json({\n severity: 'error',\n status,\n statusCode: StatusCode.Error,\n code,\n error: code,\n message,\n ...(payload.details?.length ? { details: payload.details } : {}),\n });\n }\n\n private getPayload(exception: unknown): ExceptionPayload {\n if (!(exception instanceof HttpException)) return {};\n const response = exception.getResponse();\n return typeof response === 'string' ? { message: response } : response as ExceptionPayload;\n }\n\n private isInvalidJson(exception: unknown, payload: ExceptionPayload): boolean {\n const message = exception instanceof Error ? exception.message : payload.message;\n const text = Array.isArray(message) ? message.join(' ') : String(message ?? '');\n return /json|unexpected token|expected property name|unterminated string/i.test(text);\n }\n}\n"]}
1
+ {"version":3,"file":"AccessiHttpExceptionFilter.js","sourceRoot":"","sources":["../../../src/accessi-module/security/AccessiHttpExceptionFilter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAkG;AAElG,+CAA4D;AAC5D,yCAAsC;AAStC;;;;;GAKG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACrC,KAAK,CAAC,SAAkB,EAAE,IAAmB;;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC,WAAW,EAAY,CAAC;QAC7D,IAAI,QAAQ,CAAC,WAAW;YAAE,OAAO;QAEjC,MAAM,MAAM,GAAG,SAAS,YAAY,sBAAa;YAC/C,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE;YACvB,CAAC,CAAC,yBAAa,CAAC,qBAAqB,CAAC,SAAS,CAAC;gBAC9C,CAAC,CAAC,mBAAU,CAAC,mBAAmB;gBAChC,CAAC,CAAC,mBAAU,CAAC,qBAAqB,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,WAAW,GAAG,MAAM,KAAK,mBAAU,CAAC,WAAW,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAChG,MAAM,eAAe,GAAG,OAAO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AChF,OAAO,mEAAmE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxF,CAAC;CACF,CAAA;AApEY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,cAAK,GAAE;GACK,0BAA0B,CAoEtC","sourcesContent":["import { ArgumentsHost, Catch, ExceptionFilter, HttpException, HttpStatus } from '@nestjs/common';\nimport { Response } from 'express';\nimport { RestUtilities, StatusCode } from '../../Utilities';\nimport { Logger } from '../../Logger';\n\ntype ExceptionPayload = {\n code?: string;\n error?: string;\n message?: string | string[];\n details?: string[];\n};\n\n/**\n * Finalizes every exception raised before an Accessi controller can reply.\n *\n * This includes invalid JSON, validation-pipe errors and guard failures. The\n * filter deliberately never return SQL, stack traces or provider diagnostics.\n */\n@Catch()\nexport class AccessiHttpExceptionFilter implements ExceptionFilter {\n catch(exception: unknown, host: ArgumentsHost): void {\n const response = host.switchToHttp().getResponse<Response>();\n if (response.headersSent) return;\n\n const status = exception instanceof HttpException\n ? exception.getStatus()\n : RestUtilities.isDatabaseSchemaError(exception)\n ? HttpStatus.SERVICE_UNAVAILABLE\n : HttpStatus.INTERNAL_SERVER_ERROR;\n const payload = this.getPayload(exception);\n const invalidJson = status === HttpStatus.BAD_REQUEST && this.isInvalidJson(exception, payload);\n const explicitMessage = typeof payload.message === 'string' ? payload.message : undefined;\n const code = payload.code\n ?? (RestUtilities.isDatabaseSchemaError(exception)\n ? 'ACCESSI_DATABASE_SCHEMA_OUTDATED'\n : invalidJson\n ? 'ACCESSI_INVALID_JSON'\n : status === HttpStatus.BAD_REQUEST\n ? 'ACCESSI_REQUEST_ERROR'\n : status === HttpStatus.UNAUTHORIZED\n ? 'ACCESSI_UNAUTHORIZED'\n : status === HttpStatus.FORBIDDEN\n ? 'ACCESSI_FORBIDDEN'\n : 'ACCESSI_INTERNAL_ERROR');\n\n const message = code === 'ACCESSI_VALIDATION_ERROR'\n ? 'La richiesta contiene dati non validi.'\n : code === 'ACCESSI_DATABASE_SCHEMA_OUTDATED'\n ? 'Lo schema del database Accessi non e aggiornato. Eseguire la migrazione database e riprovare.'\n : invalidJson\n ? 'Il corpo della richiesta non contiene JSON valido.'\n : explicitMessage ?? (status === HttpStatus.UNAUTHORIZED\n ? 'Autenticazione non valida o scaduta.'\n : status === HttpStatus.FORBIDDEN\n ? 'Operazione non autorizzata.'\n : status >= HttpStatus.INTERNAL_SERVER_ERROR\n ? 'Errore interno del modulo Accessi.'\n : 'Richiesta non valida.');\n\n const stack = exception instanceof Error ? exception.stack : undefined;\n new Logger('[ACCESSI-EXCEPTION]').error(\n `HTTP ${status} ${code}: ${exception instanceof Error ? exception.message : String(exception)}`,\n ...(stack ? [stack] : [])\n );\n\n response.status(status).json({\n severity: 'error',\n status,\n statusCode: StatusCode.Error,\n code,\n error: code,\n message,\n ...(payload.details?.length ? { details: payload.details } : {}),\n });\n }\n\n private getPayload(exception: unknown): ExceptionPayload {\n if (!(exception instanceof HttpException)) return {};\n const response = exception.getResponse();\n return typeof response === 'string' ? { message: response } : response as ExceptionPayload;\n }\n\n private isInvalidJson(exception: unknown, payload: ExceptionPayload): boolean {\n const message = exception instanceof Error ? exception.message : payload.message;\n const text = Array.isArray(message) ? message.join(' ') : String(message ?? '');\n return /json|unexpected token|expected property name|unterminated string/i.test(text);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "2.0.0-dev.45",
3
+ "version": "2.0.0-dev.46",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",