emilsoftware-utilities 2.0.0-dev.2 → 2.0.0-dev.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.
Files changed (141) hide show
  1. package/README.MD +38 -38
  2. package/dist/ContractGenerator.js.map +1 -1
  3. package/dist/DatabaseUpdater.d.ts +1 -1
  4. package/dist/DatabaseUpdater.js +24 -24
  5. package/dist/DatabaseUpdater.js.map +1 -1
  6. package/dist/EmilsoftwareModule.js.map +1 -1
  7. package/dist/ExecutionTimeLogger.js.map +1 -1
  8. package/dist/Logger.js.map +1 -1
  9. package/dist/Orm.d.ts +7 -1
  10. package/dist/Orm.js +172 -78
  11. package/dist/Orm.js.map +1 -1
  12. package/dist/RoutesLoggerMiddleware.js.map +1 -1
  13. package/dist/Utilities.d.ts +2 -2
  14. package/dist/Utilities.js +3 -0
  15. package/dist/Utilities.js.map +1 -1
  16. package/dist/accessi-module/AccessiModule.d.ts +1 -1
  17. package/dist/accessi-module/AccessiModule.js.map +1 -1
  18. package/dist/accessi-module/Controllers/AuthController.d.ts +4 -4
  19. package/dist/accessi-module/Controllers/AuthController.js +43 -33
  20. package/dist/accessi-module/Controllers/AuthController.js.map +1 -1
  21. package/dist/accessi-module/Controllers/ConfiguratorController.js +25 -30
  22. package/dist/accessi-module/Controllers/ConfiguratorController.js.map +1 -1
  23. package/dist/accessi-module/Controllers/EmailController.d.ts +2 -4
  24. package/dist/accessi-module/Controllers/EmailController.js +8 -12
  25. package/dist/accessi-module/Controllers/EmailController.js.map +1 -1
  26. package/dist/accessi-module/Controllers/FiltriController.js +29 -0
  27. package/dist/accessi-module/Controllers/FiltriController.js.map +1 -1
  28. package/dist/accessi-module/Controllers/PermissionController.js +35 -33
  29. package/dist/accessi-module/Controllers/PermissionController.js.map +1 -1
  30. package/dist/accessi-module/Controllers/UserController.d.ts +2 -2
  31. package/dist/accessi-module/Controllers/UserController.js +30 -12
  32. package/dist/accessi-module/Controllers/UserController.js.map +1 -1
  33. package/dist/accessi-module/Dtos/Abilitazione.js.map +1 -1
  34. package/dist/accessi-module/Dtos/AbilitazioneMenu.js.map +1 -1
  35. package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js +0 -1
  36. package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js.map +1 -1
  37. package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js +0 -1
  38. package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js.map +1 -1
  39. package/dist/accessi-module/Dtos/AuthenticatedUserPayloadDto.d.ts +10 -0
  40. package/dist/accessi-module/Dtos/AuthenticatedUserPayloadDto.js +52 -0
  41. package/dist/accessi-module/Dtos/AuthenticatedUserPayloadDto.js.map +1 -0
  42. package/dist/accessi-module/Dtos/BaseResponse.d.ts +20 -0
  43. package/dist/accessi-module/Dtos/BaseResponse.js +87 -1
  44. package/dist/accessi-module/Dtos/BaseResponse.js.map +1 -1
  45. package/dist/accessi-module/Dtos/ConfirmResetPasswordRequest.d.ts +3 -0
  46. package/dist/accessi-module/Dtos/ConfirmResetPasswordRequest.js +31 -0
  47. package/dist/accessi-module/Dtos/ConfirmResetPasswordRequest.js.map +1 -0
  48. package/dist/accessi-module/Dtos/FiltriUtente.js +1 -0
  49. package/dist/accessi-module/Dtos/FiltriUtente.js.map +1 -1
  50. package/dist/accessi-module/Dtos/GetGroupsWithMenusResponse.js.map +1 -1
  51. package/dist/accessi-module/Dtos/GetMenusResponse.js.map +1 -1
  52. package/dist/accessi-module/Dtos/GetRolesResponse.js.map +1 -1
  53. package/dist/accessi-module/Dtos/GetUserByTokenRequest.d.ts +3 -0
  54. package/dist/accessi-module/Dtos/GetUserByTokenRequest.js +26 -0
  55. package/dist/accessi-module/Dtos/GetUserByTokenRequest.js.map +1 -0
  56. package/dist/accessi-module/Dtos/GetUserByTokenResponse.d.ts +5 -0
  57. package/dist/accessi-module/Dtos/GetUserByTokenResponse.js +27 -0
  58. package/dist/accessi-module/Dtos/GetUserByTokenResponse.js.map +1 -0
  59. package/dist/accessi-module/Dtos/GetUsersResponse.js.map +1 -1
  60. package/dist/accessi-module/Dtos/LoginRequest.js.map +1 -1
  61. package/dist/accessi-module/Dtos/LoginResponse.js.map +1 -1
  62. package/dist/accessi-module/Dtos/Permission.js.map +1 -1
  63. package/dist/accessi-module/Dtos/PublicRegisterRequest.d.ts +5 -0
  64. package/dist/accessi-module/Dtos/PublicRegisterRequest.js +14 -0
  65. package/dist/accessi-module/Dtos/PublicRegisterRequest.js.map +1 -0
  66. package/dist/accessi-module/Dtos/RegisterRequest.js +4 -0
  67. package/dist/accessi-module/Dtos/RegisterRequest.js.map +1 -1
  68. package/dist/accessi-module/Dtos/RegisterResponse.d.ts +1 -1
  69. package/dist/accessi-module/Dtos/RegisterResponse.js +3 -3
  70. package/dist/accessi-module/Dtos/RegisterResponse.js.map +1 -1
  71. package/dist/accessi-module/Dtos/Role.js.map +1 -1
  72. package/dist/accessi-module/Dtos/RuoliMenu.js.map +1 -1
  73. package/dist/accessi-module/Dtos/SendResetPasswordEmailRequest.d.ts +4 -0
  74. package/dist/accessi-module/Dtos/SendResetPasswordEmailRequest.js +36 -0
  75. package/dist/accessi-module/Dtos/SendResetPasswordEmailRequest.js.map +1 -0
  76. package/dist/accessi-module/Dtos/SetStatoRegistrazione.js.map +1 -1
  77. package/dist/accessi-module/Dtos/StatoRegistrazione.js.map +1 -1
  78. package/dist/accessi-module/Dtos/TipoAbilitazione.js.map +1 -1
  79. package/dist/accessi-module/Dtos/TipoFiltro.js.map +1 -1
  80. package/dist/accessi-module/Dtos/TokenResult.js.map +1 -1
  81. package/dist/accessi-module/Dtos/UpdateEnabledStatusRequest.js.map +1 -1
  82. package/dist/accessi-module/Dtos/UserDto.js +5 -1
  83. package/dist/accessi-module/Dtos/UserDto.js.map +1 -1
  84. package/dist/accessi-module/Dtos/UserGrantsDto.js.map +1 -1
  85. package/dist/accessi-module/Dtos/UserGrantsResponse.d.ts +5 -0
  86. package/dist/accessi-module/Dtos/UserGrantsResponse.js +27 -0
  87. package/dist/accessi-module/Dtos/UserGrantsResponse.js.map +1 -0
  88. package/dist/accessi-module/Dtos/index.d.ts +7 -0
  89. package/dist/accessi-module/Dtos/index.js +7 -0
  90. package/dist/accessi-module/Dtos/index.js.map +1 -1
  91. package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
  92. package/dist/accessi-module/Services/ConfiguratorService/ConfiguratorService.js.map +1 -1
  93. package/dist/accessi-module/Services/EmailService/EmailService.js +11 -11
  94. package/dist/accessi-module/Services/EmailService/EmailService.js.map +1 -1
  95. package/dist/accessi-module/Services/FiltriService/FiltriService.js +1 -8
  96. package/dist/accessi-module/Services/FiltriService/FiltriService.js.map +1 -1
  97. package/dist/accessi-module/Services/PermissionService/PermissionService.d.ts +4 -0
  98. package/dist/accessi-module/Services/PermissionService/PermissionService.js +210 -147
  99. package/dist/accessi-module/Services/PermissionService/PermissionService.js.map +1 -1
  100. package/dist/accessi-module/Services/UserService/UserService.js +77 -174
  101. package/dist/accessi-module/Services/UserService/UserService.js.map +1 -1
  102. package/dist/accessi-module/Views/reset-password.html +213 -213
  103. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js +16 -16
  104. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js.map +1 -1
  105. package/dist/accessi-module/database-updates/runAccessiDbUpdate.js.map +1 -1
  106. package/dist/accessi-module/index.d.ts +1 -0
  107. package/dist/accessi-module/index.js +28 -5
  108. package/dist/accessi-module/index.js.map +1 -1
  109. package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
  110. package/dist/accessi-module/middleware/accessiRequirements.js.map +1 -1
  111. package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
  112. package/dist/accessi-module/security/accessControl.js.map +1 -1
  113. package/dist/accessi-module/security/authenticatedToken.js.map +1 -1
  114. package/dist/accessi-module/security/passwordResetToken.js.map +1 -1
  115. package/dist/accessi-module/security/publicAuthRateLimit.js.map +1 -1
  116. package/dist/allegati-module/AllegatiModule.d.ts +1 -1
  117. package/dist/allegati-module/AllegatiModule.js.map +1 -1
  118. package/dist/allegati-module/Controllers/AllegatiController.js.map +1 -1
  119. package/dist/allegati-module/Dtos/AllegatoDto.js.map +1 -1
  120. package/dist/allegati-module/Dtos/BaseResponse.js.map +1 -1
  121. package/dist/allegati-module/Dtos/UploadSingleFileRequest.js.map +1 -1
  122. package/dist/allegati-module/Dtos/index.js.map +1 -1
  123. package/dist/allegati-module/Dtos/responses/DownloadAllegatoResponseDto.js.map +1 -1
  124. package/dist/allegati-module/Dtos/responses/GetListResponse.js.map +1 -1
  125. package/dist/allegati-module/Dtos/responses/UploadAllegatoResponseDto.js.map +1 -1
  126. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js +49 -49
  127. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js.map +1 -1
  128. package/dist/allegati-module/index.js.map +1 -1
  129. package/dist/autobind.js.map +1 -1
  130. package/dist/emilsoftware-utilities-2.0.0-dev.21.tgz +0 -0
  131. package/dist/firebird-compat.d.ts +25 -0
  132. package/dist/firebird-compat.js +218 -0
  133. package/dist/firebird-compat.js.map +1 -0
  134. package/dist/index.d.ts +5 -2
  135. package/dist/index.js +28 -2
  136. package/dist/index.js.map +1 -1
  137. package/dist/initEmilsoftwareModule.js.map +1 -1
  138. package/dist/swagger/SwaggerConfig.d.ts +7 -1
  139. package/dist/swagger/SwaggerConfig.js +18 -7
  140. package/dist/swagger/SwaggerConfig.js.map +1 -1
  141. package/package.json +83 -83
@@ -93,12 +93,12 @@ let AllegatiService = class AllegatiService {
93
93
  const chunk = file.buffer.slice(i, i + chunkSize);
94
94
  base64Content += chunk.toString('base64');
95
95
  }
96
- const insertQuery = `
97
- INSERT INTO ALLEGATI (
98
- CODICE, TIPCOD, ORDINE, DESALL, NOMEFILE,
99
- DADATAVAL, ADATAVAL, ALLEGATO, IDXTIPOALL, DATMODIF, DOCRIF
100
- ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)
101
- RETURNING IDXALL
96
+ const insertQuery = `
97
+ INSERT INTO ALLEGATI (
98
+ CODICE, TIPCOD, ORDINE, DESALL, NOMEFILE,
99
+ DADATAVAL, ADATAVAL, ALLEGATO, IDXTIPOALL, DATMODIF, DOCRIF
100
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)
101
+ RETURNING IDXALL
102
102
  `;
103
103
  const params = [
104
104
  uploadSingleFileRequest.codice,
@@ -133,10 +133,10 @@ let AllegatiService = class AllegatiService {
133
133
  ensureTableExists() {
134
134
  return __awaiter(this, void 0, void 0, function* () {
135
135
  try {
136
- const query = `
137
- SELECT RDB$RELATION_NAME
138
- FROM RDB$RELATIONS
139
- WHERE RDB$RELATION_NAME = 'ALLEGATI'
136
+ const query = `
137
+ SELECT RDB$RELATION_NAME
138
+ FROM RDB$RELATIONS
139
+ WHERE RDB$RELATION_NAME = 'ALLEGATI'
140
140
  `;
141
141
  const result = yield Orm_1.Orm.query(this.allegatiOptions.databaseOptions, query);
142
142
  if (!result || result.length === 0) {
@@ -155,13 +155,13 @@ let AllegatiService = class AllegatiService {
155
155
  if (!id || id <= 0) {
156
156
  throw new common_1.BadRequestException('ID allegato non valido');
157
157
  }
158
- const query = `
159
- SELECT
160
- ALLEGATO as content,
161
- NOMEFILE as filename,
162
- IDXTIPOALL as idTipoAllegato
163
- FROM ALLEGATI
164
- WHERE IDXALL = ?
158
+ const query = `
159
+ SELECT
160
+ ALLEGATO as content,
161
+ NOMEFILE as filename,
162
+ IDXTIPOALL as idTipoAllegato
163
+ FROM ALLEGATI
164
+ WHERE IDXALL = ?
165
165
  `;
166
166
  const results = yield Orm_1.Orm.query(this.allegatiOptions.databaseOptions, query, [id]);
167
167
  if (!results || results.length === 0) {
@@ -255,22 +255,22 @@ let AllegatiService = class AllegatiService {
255
255
  params.push(filters.idxtipoall);
256
256
  }
257
257
  }
258
- const query = `
259
- SELECT
260
- IDXALL as id,
261
- NOMEFILE as filename,
262
- 'application/octet-stream' as mimetype,
263
- DATMODIF as uploadDate,
264
- CODICE as codice,
265
- TIPCOD as tipoCodice,
266
- ORDINE as ordine,
267
- DESALL as descrizioneAllegato,
268
- DADATAVAL as dataInizioValidita,
269
- ADATAVAL as dataFineValidita,
270
- IDXTIPOALL as idTipoAllegato,
271
- DOCRIF as riferimentoDocumento
272
- FROM ALLEGATI
273
- ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}
258
+ const query = `
259
+ SELECT
260
+ IDXALL as id,
261
+ NOMEFILE as filename,
262
+ 'application/octet-stream' as mimetype,
263
+ DATMODIF as uploadDate,
264
+ CODICE as codice,
265
+ TIPCOD as tipoCodice,
266
+ ORDINE as ordine,
267
+ DESALL as descrizioneAllegato,
268
+ DADATAVAL as dataInizioValidita,
269
+ ADATAVAL as dataFineValidita,
270
+ IDXTIPOALL as idTipoAllegato,
271
+ DOCRIF as riferimentoDocumento
272
+ FROM ALLEGATI
273
+ ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}
274
274
  `;
275
275
  const results = yield Orm_1.Orm.query(this.allegatiOptions.databaseOptions, query, params);
276
276
  if (!results) {
@@ -324,22 +324,22 @@ let AllegatiService = class AllegatiService {
324
324
  whereConditions.push('IDXTIPOALL = ?');
325
325
  params.push(fields.idxtipoall);
326
326
  }
327
- const query = `
328
- SELECT
329
- IDXALL as id,
330
- NOMEFILE as filename,
331
- 'application/octet-stream' as mimetype,
332
- DATMODIF as uploadDate,
333
- CODICE as codice,
334
- TIPCOD as tipoCodice,
335
- ORDINE as ordine,
336
- DESALL as descrizioneAllegato,
337
- DADATAVAL as dataInizioValidita,
338
- ADATAVAL as dataFineValidita,
339
- IDXTIPOALL as idTipoAllegato,
340
- DOCRIF as riferimentoDocumento
341
- FROM ALLEGATI
342
- ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}
327
+ const query = `
328
+ SELECT
329
+ IDXALL as id,
330
+ NOMEFILE as filename,
331
+ 'application/octet-stream' as mimetype,
332
+ DATMODIF as uploadDate,
333
+ CODICE as codice,
334
+ TIPCOD as tipoCodice,
335
+ ORDINE as ordine,
336
+ DESALL as descrizioneAllegato,
337
+ DADATAVAL as dataInizioValidita,
338
+ ADATAVAL as dataFineValidita,
339
+ IDXTIPOALL as idTipoAllegato,
340
+ DOCRIF as riferimentoDocumento
341
+ FROM ALLEGATI
342
+ ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}
343
343
  `;
344
344
  const results = yield Orm_1.Orm.query(this.allegatiOptions.databaseOptions, query, params);
345
345
  if (!results) {
@@ -1 +1 @@
1
- {"version":3,"file":"AllegatiService.js","sourceRoot":"","sources":["../../../../src/allegati-module/Services/AllegatiService/AllegatiService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA0H;AAC1H,gDAA6C;AAC7C,sCAAmC;AAKnC,MAAa,aAAc,SAAQ,KAAK;IACpC,YACI,OAAe,EACC,IAAY,EACZ,aAAqB,GAAG;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAQ;QACZ,eAAU,GAAV,UAAU,CAAc;QAGxC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAChC,CAAC;CACJ;AATD,sCASC;AAIM,IAAM,eAAe,GAArB,MAAM,eAAe;IAYxB,YAAwC,eAAiD;QAAhC,oBAAe,GAAf,eAAe,CAAiB;QAXxE,kBAAa,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO;QACzC,uBAAkB,GAAG;YAClC,iBAAiB;YACjB,YAAY;YACZ,WAAW;YACX,oBAAoB;YACpB,yEAAyE;YACzE,0BAA0B;YAC1B,mEAAmE;SACtE,CAAC;QAGE,IAAI,CAAC,iBAAiB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;YACnC,OAAO,CAAC,KAAK,CAAC,sDAAsD,EA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,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACvB,MAAM,IAAI,4BAAmB,CAAC,4BAA4B,CAAC,CAAC;gBAChE,CAAC;gBACD,MAAM,KAAK,GAAG,uBAAuB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC;gBAC3E,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAChB,MAAM,MAAM,GAAG,MAAM,SAAG,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,eAAe,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;gBACtF,IAAI,CAAC,MAAM,EAAE,CAAC;oBACV,MAAM,IAAI,qCAA4B,CAAC,0CAA0C,CAAC,CAAC;gBACvF,CAAC;YACL,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;gBACrE,MAAM,KAAK,CAAC;YAChB,CAAC;QACL,CAAC;KAAA;IAED;;OAEG;IACG,cAAc,CAAC,MAAkF;;YACnG,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;YAChD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,CAAC;KAAA;CAEJ,CAAA;AAlZY,0CAAe;0BAAf,eAAe;IAF3B,mBAAQ;IACR,IAAA,mBAAU,GAAE;IAaI,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;;GAZ9B,eAAe,CAkZ3B","sourcesContent":["import { Inject, Injectable, NotFoundException, BadRequestException, InternalServerErrorException } from \"@nestjs/common\";\r\nimport { autobind } from \"../../../autobind\";\r\nimport { Orm } from \"../../../Orm\";\r\nimport { AllegatiOptions } from \"../../AllegatiModule\";\r\nimport { UploadAllegatoResponseDto, DownloadAllegatoResponseDto, AllegatoDto} from \"../../Dtos\";\r\nimport { UploadSingleFileRequest } from \"../../Dtos/UploadSingleFileRequest\";\r\n\r\nexport class AllegatiError extends Error {\r\n constructor(\r\n message: string,\r\n public readonly code: string,\r\n public readonly statusCode: number = 500\r\n ) {\r\n super(message);\r\n this.name = 'AllegatiError';\r\n }\r\n}\r\n\r\n@autobind\r\n@Injectable()\r\nexport class AllegatiService {\r\n private readonly MAX_FILE_SIZE = 90 * 1024 * 1024; // 90MB\r\n private readonly ALLOWED_MIME_TYPES = [\r\n 'application/pdf',\r\n 'image/jpeg',\r\n 'image/png',\r\n 'application/msword',\r\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\r\n 'application/vnd.ms-excel',\r\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\r\n ];\r\n\r\n constructor(@Inject('ALLEGATI_OPTIONS') private readonly allegatiOptions: AllegatiOptions) {\r\n this.ensureTableExists().catch(error => {\r\n console.error('[AllegatiService] Errore creazione tabella ALLEGATI:', error);\r\n // throw new InternalServerErrorException('Errore durante l\\'inizializzazione del servizio allegati');\r\n });\r\n }\r\n\r\n private validateFile(file: Express.Multer.File): void {\r\n if (!file) {\r\n throw new BadRequestException('Nessun file fornito');\r\n }\r\n\r\n if (file.size > this.MAX_FILE_SIZE) {\r\n throw new BadRequestException(`File troppo grande. Dimensione massima consentita: ${this.MAX_FILE_SIZE / (1024 * 1024)}MB`);\r\n }\r\n\r\n if (!this.ALLOWED_MIME_TYPES.includes(file.mimetype)) {\r\n throw new BadRequestException(`Tipo di file non consentito. Tipi consentiti: ${this.ALLOWED_MIME_TYPES.join(', ')}`);\r\n }\r\n }\r\n\r\n\r\n async getAttachmentTypes(): Promise<any[]> {\r\n try {\r\n const query = `SELECT IDXTIPOALL as id, DESCRIZIONE as description FROM TIPOALL`;\r\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query);\r\n \r\n if (!results) {\r\n throw new InternalServerErrorException('Errore durante il recupero dei tipi di allegato');\r\n }\r\n\r\n return results;\r\n } catch (error) {\r\n console.error('[AllegatiService] getAttachmentTypes - Errore:', error);\r\n if (error instanceof InternalServerErrorException) {\r\n throw error;\r\n }\r\n throw new InternalServerErrorException('Errore durante il recupero dei tipi di allegato');\r\n }\r\n }\r\n async uploadFile(file: Express.Multer.File, uploadSingleFileRequest: UploadSingleFileRequest): Promise<UploadAllegatoResponseDto> {\r\n try {\r\n this.validateFile(file);\r\n\r\n // Convert buffer to base64 in chunks to avoid memory issues\r\n const chunkSize = 1024 * 1024; // 1MB chunks\r\n let base64Content = '';\r\n for (let i = 0; i < file.buffer.length; i += chunkSize) {\r\n const chunk = file.buffer.slice(i, i + chunkSize);\r\n base64Content += chunk.toString('base64');\r\n }\r\n\r\n const insertQuery = `\r\n INSERT INTO ALLEGATI (\r\n CODICE, TIPCOD, ORDINE, DESALL, NOMEFILE,\r\n DADATAVAL, ADATAVAL, ALLEGATO, IDXTIPOALL, DATMODIF, DOCRIF\r\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)\r\n RETURNING IDXALL\r\n `;\r\n\r\n const params = [\r\n uploadSingleFileRequest.codice,\r\n uploadSingleFileRequest.tipoCodice,\r\n uploadSingleFileRequest.ordine,\r\n uploadSingleFileRequest.descrizioneAllegato,\r\n file.originalname,\r\n uploadSingleFileRequest.dataInizioValidita,\r\n uploadSingleFileRequest.dataFineValidita,\r\n base64Content,\r\n uploadSingleFileRequest.idTipoAllegato,\r\n uploadSingleFileRequest.riferimentoDocumento\r\n ];\r\n\r\n const result = await Orm.query(this.allegatiOptions.databaseOptions, insertQuery, params);\r\n \r\n if (!result || !result.IDXALL) {\r\n throw new InternalServerErrorException('Errore durante il salvataggio del file');\r\n }\r\n\r\n return {\r\n id: result.IDXALL,\r\n filename: file.originalname,\r\n };\r\n } catch (error) {\r\n console.error('[AllegatiService] uploadFile - Errore:', error);\r\n if (error instanceof BadRequestException || error instanceof InternalServerErrorException) {\r\n throw error;\r\n }\r\n throw new InternalServerErrorException('Errore durante il caricamento del file');\r\n }\r\n }\r\n\r\n async ensureTableExists(): Promise<void> {\r\n try {\r\n const query = `\r\n SELECT RDB$RELATION_NAME \r\n FROM RDB$RELATIONS \r\n WHERE RDB$RELATION_NAME = 'ALLEGATI'\r\n `;\r\n const result = await Orm.query(this.allegatiOptions.databaseOptions, query);\r\n \r\n if (!result || result.length === 0) {\r\n throw new Error('Tabella ALLEGATI non trovata nel database');\r\n }\r\n } catch (error) {\r\n console.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);\r\n throw new InternalServerErrorException('Errore durante la verifica della tabella ALLEGATI');\r\n }\r\n }\r\n\r\n async downloadFile(id: number): Promise<DownloadAllegatoResponseDto> {\r\n try {\r\n if (!id || id <= 0) {\r\n throw new BadRequestException('ID allegato non valido');\r\n }\r\n\r\n const query = `\r\n SELECT \r\n ALLEGATO as content,\r\n NOMEFILE as filename,\r\n IDXTIPOALL as idTipoAllegato\r\n FROM ALLEGATI \r\n WHERE IDXALL = ?\r\n `;\r\n \r\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, [id]);\r\n \r\n if (!results || results.length === 0) {\r\n throw new NotFoundException(`Allegato con ID ${id} non trovato`);\r\n }\r\n\r\n const result = results[0];\r\n if (!result.CONTENT) {\r\n throw new InternalServerErrorException('Contenuto file non disponibile');\r\n }\r\n\r\n if (!result.FILENAME) {\r\n throw new InternalServerErrorException('Nome file non disponibile');\r\n }\r\n\r\n const mimetype = this.detectMimeType(result.FILENAME);\r\n \r\n return {\r\n contentBase64: result.CONTENT,\r\n filename: result.FILENAME,\r\n mimetype\r\n };\r\n } catch (error) {\r\n console.error('[AllegatiService] downloadFile - Errore:', error);\r\n if (error instanceof BadRequestException || \r\n error instanceof NotFoundException || \r\n error instanceof InternalServerErrorException) {\r\n throw error;\r\n }\r\n throw new InternalServerErrorException('Errore durante il download del file');\r\n }\r\n }\r\n\r\n private detectMimeType(filename: string): string {\r\n const extension = filename.split('.').pop()?.toLowerCase();\r\n const mimeTypes: { [key: string]: string } = {\r\n 'pdf': 'application/pdf',\r\n 'jpg': 'image/jpeg',\r\n 'jpeg': 'image/jpeg',\r\n 'png': 'image/png',\r\n 'doc': 'application/msword',\r\n 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\r\n 'xls': 'application/vnd.ms-excel',\r\n 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\r\n };\r\n return mimeTypes[extension || ''] || 'application/octet-stream';\r\n }\r\n\r\n async deleteFile(id: number): Promise<void> {\r\n try {\r\n if (!id || id <= 0) {\r\n throw new BadRequestException('ID allegato non valido');\r\n }\r\n\r\n const checkQuery = `SELECT IDXALL FROM ALLEGATI WHERE IDXALL = ?`;\r\n const checkResult = await Orm.query(this.allegatiOptions.databaseOptions, checkQuery, [id]);\r\n \r\n if (!checkResult || checkResult.length === 0) {\r\n throw new NotFoundException(`Allegato con ID ${id} non trovato`);\r\n }\r\n\r\n const query = `DELETE FROM ALLEGATI WHERE IDXALL = ?`;\r\n await Orm.execute(this.allegatiOptions.databaseOptions, query, [id]);\r\n \r\n \r\n } catch (error) {\r\n console.error('[AllegatiService] deleteFile - Errore:', error);\r\n if (error instanceof BadRequestException || \r\n error instanceof NotFoundException || \r\n error instanceof InternalServerErrorException) {\r\n throw error;\r\n }\r\n throw new InternalServerErrorException('Errore durante la cancellazione del file');\r\n }\r\n }\r\n\r\n async listFiles(filters?: { \r\n tipcod?: string;\r\n codice?: number;\r\n docrif?: string;\r\n idxtipoall?: number;\r\n }): Promise<AllegatoDto[]> {\r\n try {\r\n const whereConditions: string[] = [];\r\n const params: any[] = [];\r\n\r\n if (filters) {\r\n if (filters.tipcod) {\r\n whereConditions.push('TIPCOD = ?');\r\n params.push(filters.tipcod);\r\n }\r\n if (filters.codice) {\r\n whereConditions.push('CODICE = ?');\r\n params.push(filters.codice);\r\n }\r\n if (filters.docrif) {\r\n whereConditions.push('DOCRIF = ?');\r\n params.push(filters.docrif);\r\n }\r\n if (filters.idxtipoall !== undefined) {\r\n whereConditions.push('IDXTIPOALL = ?');\r\n params.push(filters.idxtipoall);\r\n }\r\n }\r\n\r\n const query = `\r\n SELECT \r\n IDXALL as id,\r\n NOMEFILE as filename,\r\n 'application/octet-stream' as mimetype,\r\n DATMODIF as uploadDate,\r\n CODICE as codice,\r\n TIPCOD as tipoCodice,\r\n ORDINE as ordine,\r\n DESALL as descrizioneAllegato,\r\n DADATAVAL as dataInizioValidita,\r\n ADATAVAL as dataFineValidita,\r\n IDXTIPOALL as idTipoAllegato,\r\n DOCRIF as riferimentoDocumento\r\n FROM ALLEGATI\r\n ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}\r\n `;\r\n\r\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, params);\r\n \r\n if (!results) {\r\n throw new InternalServerErrorException('Errore durante il recupero della lista dei file');\r\n }\r\n\r\n return results.map((r: any) => ({\r\n id: r.ID,\r\n filename: r.FILENAME,\r\n mimetype: r.MIMETYPE,\r\n uploadDate: r.UPLOADDATE,\r\n codice: r.CODICE,\r\n tipoCodice: r.TIPOCODICE,\r\n ordine: r.ORDINE,\r\n descrizioneAllegato: r.DESCRIZIONEALLEGATO,\r\n dataInizioValidita: r.DATAINIZIOVALIDITA,\r\n dataFineValidita: r.DATAFINEVALIDITA,\r\n idTipoAllegato: r.IDTIPOALLEGATO,\r\n riferimentoDocumento: r.RIFERIMENTODOCUMENTO\r\n }));\r\n } catch (error) {\r\n console.error('[AllegatiService] listFiles - Errore:', error);\r\n if (error instanceof InternalServerErrorException) {\r\n throw error;\r\n }\r\n throw new InternalServerErrorException('Errore durante il recupero della lista dei file');\r\n }\r\n }\r\n\r\n /**\r\n * Find allegati by any combination of tipcod, codice, docrif, idxtipoall\r\n */\r\n async findByFields(fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<AllegatoDto[]> {\r\n try {\r\n const whereConditions: string[] = [];\r\n const params: any[] = [];\r\n if (fields.tipcod) {\r\n whereConditions.push('TIPCOD = ?');\r\n params.push(fields.tipcod);\r\n }\r\n if (fields.codice) {\r\n whereConditions.push('CODICE = ?');\r\n params.push(fields.codice);\r\n }\r\n if (fields.docrif) {\r\n whereConditions.push('DOCRIF = ?');\r\n params.push(fields.docrif);\r\n }\r\n if (fields.idxtipoall !== undefined) {\r\n whereConditions.push('IDXTIPOALL = ?');\r\n params.push(fields.idxtipoall);\r\n }\r\n const query = `\r\n SELECT \r\n IDXALL as id,\r\n NOMEFILE as filename,\r\n 'application/octet-stream' as mimetype,\r\n DATMODIF as uploadDate,\r\n CODICE as codice,\r\n TIPCOD as tipoCodice,\r\n ORDINE as ordine,\r\n DESALL as descrizioneAllegato,\r\n DADATAVAL as dataInizioValidita,\r\n ADATAVAL as dataFineValidita,\r\n IDXTIPOALL as idTipoAllegato,\r\n DOCRIF as riferimentoDocumento\r\n FROM ALLEGATI\r\n ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}\r\n `;\r\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, params);\r\n if (!results) {\r\n throw new InternalServerErrorException('Errore durante la ricerca degli allegati');\r\n }\r\n return results.map((r: any) => ({\r\n id: r.ID,\r\n filename: r.FILENAME,\r\n mimetype: r.MIMETYPE,\r\n uploadDate: r.UPLOADDATE,\r\n codice: r.CODICE,\r\n tipoCodice: r.TIPOCODICE,\r\n ordine: r.ORDINE,\r\n descrizioneAllegato: r.DESCRIZIONEALLEGATO,\r\n dataInizioValidita: r.DATAINIZIOVALIDITA,\r\n dataFineValidita: r.DATAFINEVALIDITA,\r\n idTipoAllegato: r.IDTIPOALLEGATO,\r\n riferimentoDocumento: r.RIFERIMENTODOCUMENTO\r\n }));\r\n } catch (error) {\r\n console.error('[AllegatiService] findByFields - Errore:', error);\r\n throw new InternalServerErrorException('Errore durante la ricerca degli allegati');\r\n }\r\n }\r\n\r\n /**\r\n * Update tipcod, codice, docrif, idxtipoall for a given allegato by id\r\n */\r\n async updateFieldsById(id: number, fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<void> {\r\n try {\r\n if (!id || id <= 0) {\r\n throw new BadRequestException('ID allegato non valido');\r\n }\r\n const updates: string[] = [];\r\n const params: any[] = [];\r\n if (fields.tipcod !== undefined) {\r\n updates.push('TIPCOD = ?');\r\n params.push(fields.tipcod);\r\n }\r\n if (fields.codice !== undefined) {\r\n updates.push('CODICE = ?');\r\n params.push(fields.codice);\r\n }\r\n if (fields.docrif !== undefined) {\r\n updates.push('DOCRIF = ?');\r\n params.push(fields.docrif);\r\n }\r\n if (fields.idxtipoall !== undefined) {\r\n updates.push('IDXTIPOALL = ?');\r\n params.push(fields.idxtipoall);\r\n }\r\n if (updates.length === 0) {\r\n throw new BadRequestException('Nessun campo da aggiornare');\r\n }\r\n const query = `UPDATE ALLEGATI SET ${updates.join(', ')} WHERE IDXALL = ?`;\r\n params.push(id);\r\n const result = await Orm.execute(this.allegatiOptions.databaseOptions, query, params);\r\n if (!result) {\r\n throw new InternalServerErrorException('Errore durante l\\'aggiornamento del file');\r\n }\r\n } catch (error) {\r\n console.error('[AllegatiService] updateFieldsById - Errore:', error);\r\n throw error;\r\n }\r\n }\r\n\r\n /**\r\n * Get a single allegato by fields (returns the first match)\r\n */\r\n async getOneByFields(fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<AllegatoDto | null> {\r\n const results = await this.findByFields(fields);\r\n return results.length > 0 ? results[0] : null;\r\n }\r\n\r\n}"]}
1
+ {"version":3,"file":"AllegatiService.js","sourceRoot":"","sources":["../../../../src/allegati-module/Services/AllegatiService/AllegatiService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA0H;AAC1H,gDAA6C;AAC7C,sCAAmC;AAKnC,MAAa,aAAc,SAAQ,KAAK;IACpC,YACI,OAAe,EACC,IAAY,EACZ,aAAqB,GAAG;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,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CAAC,CAAC;YAChD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClD,CAAC;KAAA;CAEJ,CAAA;AAlZY,0CAAe;0BAAf,eAAe;IAF3B,mBAAQ;IACR,IAAA,mBAAU,GAAE;IAaI,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;;GAZ9B,eAAe,CAkZ3B","sourcesContent":["import { Inject, Injectable, NotFoundException, BadRequestException, InternalServerErrorException } from \"@nestjs/common\";\nimport { autobind } from \"../../../autobind\";\nimport { Orm } from \"../../../Orm\";\nimport { AllegatiOptions } from \"../../AllegatiModule\";\nimport { UploadAllegatoResponseDto, DownloadAllegatoResponseDto, AllegatoDto} from \"../../Dtos\";\nimport { UploadSingleFileRequest } from \"../../Dtos/UploadSingleFileRequest\";\n\nexport class AllegatiError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly statusCode: number = 500\n ) {\n super(message);\n this.name = 'AllegatiError';\n }\n}\n\n@autobind\n@Injectable()\nexport class AllegatiService {\n private readonly MAX_FILE_SIZE = 90 * 1024 * 1024; // 90MB\n private readonly ALLOWED_MIME_TYPES = [\n 'application/pdf',\n 'image/jpeg',\n 'image/png',\n 'application/msword',\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'application/vnd.ms-excel',\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\n ];\n\n constructor(@Inject('ALLEGATI_OPTIONS') private readonly allegatiOptions: AllegatiOptions) {\n this.ensureTableExists().catch(error => {\n console.error('[AllegatiService] Errore creazione tabella ALLEGATI:', error);\n // throw new InternalServerErrorException('Errore durante l\\'inizializzazione del servizio allegati');\n });\n }\n\n private validateFile(file: Express.Multer.File): void {\n if (!file) {\n throw new BadRequestException('Nessun file fornito');\n }\n\n if (file.size > this.MAX_FILE_SIZE) {\n throw new BadRequestException(`File troppo grande. Dimensione massima consentita: ${this.MAX_FILE_SIZE / (1024 * 1024)}MB`);\n }\n\n if (!this.ALLOWED_MIME_TYPES.includes(file.mimetype)) {\n throw new BadRequestException(`Tipo di file non consentito. Tipi consentiti: ${this.ALLOWED_MIME_TYPES.join(', ')}`);\n }\n }\n\n\n async getAttachmentTypes(): Promise<any[]> {\n try {\n const query = `SELECT IDXTIPOALL as id, DESCRIZIONE as description FROM TIPOALL`;\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query);\n \n if (!results) {\n throw new InternalServerErrorException('Errore durante il recupero dei tipi di allegato');\n }\n\n return results;\n } catch (error) {\n console.error('[AllegatiService] getAttachmentTypes - Errore:', error);\n if (error instanceof InternalServerErrorException) {\n throw error;\n }\n throw new InternalServerErrorException('Errore durante il recupero dei tipi di allegato');\n }\n }\n async uploadFile(file: Express.Multer.File, uploadSingleFileRequest: UploadSingleFileRequest): Promise<UploadAllegatoResponseDto> {\n try {\n this.validateFile(file);\n\n // Convert buffer to base64 in chunks to avoid memory issues\n const chunkSize = 1024 * 1024; // 1MB chunks\n let base64Content = '';\n for (let i = 0; i < file.buffer.length; i += chunkSize) {\n const chunk = file.buffer.slice(i, i + chunkSize);\n base64Content += chunk.toString('base64');\n }\n\n const insertQuery = `\n INSERT INTO ALLEGATI (\n CODICE, TIPCOD, ORDINE, DESALL, NOMEFILE,\n DADATAVAL, ADATAVAL, ALLEGATO, IDXTIPOALL, DATMODIF, DOCRIF\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, ?)\n RETURNING IDXALL\n `;\n\n const params = [\n uploadSingleFileRequest.codice,\n uploadSingleFileRequest.tipoCodice,\n uploadSingleFileRequest.ordine,\n uploadSingleFileRequest.descrizioneAllegato,\n file.originalname,\n uploadSingleFileRequest.dataInizioValidita,\n uploadSingleFileRequest.dataFineValidita,\n base64Content,\n uploadSingleFileRequest.idTipoAllegato,\n uploadSingleFileRequest.riferimentoDocumento\n ];\n\n const result = await Orm.query(this.allegatiOptions.databaseOptions, insertQuery, params);\n \n if (!result || !result.IDXALL) {\n throw new InternalServerErrorException('Errore durante il salvataggio del file');\n }\n\n return {\n id: result.IDXALL,\n filename: file.originalname,\n };\n } catch (error) {\n console.error('[AllegatiService] uploadFile - Errore:', error);\n if (error instanceof BadRequestException || error instanceof InternalServerErrorException) {\n throw error;\n }\n throw new InternalServerErrorException('Errore durante il caricamento del file');\n }\n }\n\n async ensureTableExists(): Promise<void> {\n try {\n const query = `\n SELECT RDB$RELATION_NAME \n FROM RDB$RELATIONS \n WHERE RDB$RELATION_NAME = 'ALLEGATI'\n `;\n const result = await Orm.query(this.allegatiOptions.databaseOptions, query);\n \n if (!result || result.length === 0) {\n throw new Error('Tabella ALLEGATI non trovata nel database');\n }\n } catch (error) {\n console.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);\n throw new InternalServerErrorException('Errore durante la verifica della tabella ALLEGATI');\n }\n }\n\n async downloadFile(id: number): Promise<DownloadAllegatoResponseDto> {\n try {\n if (!id || id <= 0) {\n throw new BadRequestException('ID allegato non valido');\n }\n\n const query = `\n SELECT \n ALLEGATO as content,\n NOMEFILE as filename,\n IDXTIPOALL as idTipoAllegato\n FROM ALLEGATI \n WHERE IDXALL = ?\n `;\n \n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, [id]);\n \n if (!results || results.length === 0) {\n throw new NotFoundException(`Allegato con ID ${id} non trovato`);\n }\n\n const result = results[0];\n if (!result.CONTENT) {\n throw new InternalServerErrorException('Contenuto file non disponibile');\n }\n\n if (!result.FILENAME) {\n throw new InternalServerErrorException('Nome file non disponibile');\n }\n\n const mimetype = this.detectMimeType(result.FILENAME);\n \n return {\n contentBase64: result.CONTENT,\n filename: result.FILENAME,\n mimetype\n };\n } catch (error) {\n console.error('[AllegatiService] downloadFile - Errore:', error);\n if (error instanceof BadRequestException || \n error instanceof NotFoundException || \n error instanceof InternalServerErrorException) {\n throw error;\n }\n throw new InternalServerErrorException('Errore durante il download del file');\n }\n }\n\n private detectMimeType(filename: string): string {\n const extension = filename.split('.').pop()?.toLowerCase();\n const mimeTypes: { [key: string]: string } = {\n 'pdf': 'application/pdf',\n 'jpg': 'image/jpeg',\n 'jpeg': 'image/jpeg',\n 'png': 'image/png',\n 'doc': 'application/msword',\n 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n 'xls': 'application/vnd.ms-excel',\n 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'\n };\n return mimeTypes[extension || ''] || 'application/octet-stream';\n }\n\n async deleteFile(id: number): Promise<void> {\n try {\n if (!id || id <= 0) {\n throw new BadRequestException('ID allegato non valido');\n }\n\n const checkQuery = `SELECT IDXALL FROM ALLEGATI WHERE IDXALL = ?`;\n const checkResult = await Orm.query(this.allegatiOptions.databaseOptions, checkQuery, [id]);\n \n if (!checkResult || checkResult.length === 0) {\n throw new NotFoundException(`Allegato con ID ${id} non trovato`);\n }\n\n const query = `DELETE FROM ALLEGATI WHERE IDXALL = ?`;\n await Orm.execute(this.allegatiOptions.databaseOptions, query, [id]);\n \n \n } catch (error) {\n console.error('[AllegatiService] deleteFile - Errore:', error);\n if (error instanceof BadRequestException || \n error instanceof NotFoundException || \n error instanceof InternalServerErrorException) {\n throw error;\n }\n throw new InternalServerErrorException('Errore durante la cancellazione del file');\n }\n }\n\n async listFiles(filters?: { \n tipcod?: string;\n codice?: number;\n docrif?: string;\n idxtipoall?: number;\n }): Promise<AllegatoDto[]> {\n try {\n const whereConditions: string[] = [];\n const params: any[] = [];\n\n if (filters) {\n if (filters.tipcod) {\n whereConditions.push('TIPCOD = ?');\n params.push(filters.tipcod);\n }\n if (filters.codice) {\n whereConditions.push('CODICE = ?');\n params.push(filters.codice);\n }\n if (filters.docrif) {\n whereConditions.push('DOCRIF = ?');\n params.push(filters.docrif);\n }\n if (filters.idxtipoall !== undefined) {\n whereConditions.push('IDXTIPOALL = ?');\n params.push(filters.idxtipoall);\n }\n }\n\n const query = `\n SELECT \n IDXALL as id,\n NOMEFILE as filename,\n 'application/octet-stream' as mimetype,\n DATMODIF as uploadDate,\n CODICE as codice,\n TIPCOD as tipoCodice,\n ORDINE as ordine,\n DESALL as descrizioneAllegato,\n DADATAVAL as dataInizioValidita,\n ADATAVAL as dataFineValidita,\n IDXTIPOALL as idTipoAllegato,\n DOCRIF as riferimentoDocumento\n FROM ALLEGATI\n ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}\n `;\n\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, params);\n \n if (!results) {\n throw new InternalServerErrorException('Errore durante il recupero della lista dei file');\n }\n\n return results.map((r: any) => ({\n id: r.ID,\n filename: r.FILENAME,\n mimetype: r.MIMETYPE,\n uploadDate: r.UPLOADDATE,\n codice: r.CODICE,\n tipoCodice: r.TIPOCODICE,\n ordine: r.ORDINE,\n descrizioneAllegato: r.DESCRIZIONEALLEGATO,\n dataInizioValidita: r.DATAINIZIOVALIDITA,\n dataFineValidita: r.DATAFINEVALIDITA,\n idTipoAllegato: r.IDTIPOALLEGATO,\n riferimentoDocumento: r.RIFERIMENTODOCUMENTO\n }));\n } catch (error) {\n console.error('[AllegatiService] listFiles - Errore:', error);\n if (error instanceof InternalServerErrorException) {\n throw error;\n }\n throw new InternalServerErrorException('Errore durante il recupero della lista dei file');\n }\n }\n\n /**\n * Find allegati by any combination of tipcod, codice, docrif, idxtipoall\n */\n async findByFields(fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<AllegatoDto[]> {\n try {\n const whereConditions: string[] = [];\n const params: any[] = [];\n if (fields.tipcod) {\n whereConditions.push('TIPCOD = ?');\n params.push(fields.tipcod);\n }\n if (fields.codice) {\n whereConditions.push('CODICE = ?');\n params.push(fields.codice);\n }\n if (fields.docrif) {\n whereConditions.push('DOCRIF = ?');\n params.push(fields.docrif);\n }\n if (fields.idxtipoall !== undefined) {\n whereConditions.push('IDXTIPOALL = ?');\n params.push(fields.idxtipoall);\n }\n const query = `\n SELECT \n IDXALL as id,\n NOMEFILE as filename,\n 'application/octet-stream' as mimetype,\n DATMODIF as uploadDate,\n CODICE as codice,\n TIPCOD as tipoCodice,\n ORDINE as ordine,\n DESALL as descrizioneAllegato,\n DADATAVAL as dataInizioValidita,\n ADATAVAL as dataFineValidita,\n IDXTIPOALL as idTipoAllegato,\n DOCRIF as riferimentoDocumento\n FROM ALLEGATI\n ${whereConditions.length > 0 ? `WHERE ${whereConditions.join(' AND ')}` : ''}\n `;\n const results = await Orm.query(this.allegatiOptions.databaseOptions, query, params);\n if (!results) {\n throw new InternalServerErrorException('Errore durante la ricerca degli allegati');\n }\n return results.map((r: any) => ({\n id: r.ID,\n filename: r.FILENAME,\n mimetype: r.MIMETYPE,\n uploadDate: r.UPLOADDATE,\n codice: r.CODICE,\n tipoCodice: r.TIPOCODICE,\n ordine: r.ORDINE,\n descrizioneAllegato: r.DESCRIZIONEALLEGATO,\n dataInizioValidita: r.DATAINIZIOVALIDITA,\n dataFineValidita: r.DATAFINEVALIDITA,\n idTipoAllegato: r.IDTIPOALLEGATO,\n riferimentoDocumento: r.RIFERIMENTODOCUMENTO\n }));\n } catch (error) {\n console.error('[AllegatiService] findByFields - Errore:', error);\n throw new InternalServerErrorException('Errore durante la ricerca degli allegati');\n }\n }\n\n /**\n * Update tipcod, codice, docrif, idxtipoall for a given allegato by id\n */\n async updateFieldsById(id: number, fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<void> {\n try {\n if (!id || id <= 0) {\n throw new BadRequestException('ID allegato non valido');\n }\n const updates: string[] = [];\n const params: any[] = [];\n if (fields.tipcod !== undefined) {\n updates.push('TIPCOD = ?');\n params.push(fields.tipcod);\n }\n if (fields.codice !== undefined) {\n updates.push('CODICE = ?');\n params.push(fields.codice);\n }\n if (fields.docrif !== undefined) {\n updates.push('DOCRIF = ?');\n params.push(fields.docrif);\n }\n if (fields.idxtipoall !== undefined) {\n updates.push('IDXTIPOALL = ?');\n params.push(fields.idxtipoall);\n }\n if (updates.length === 0) {\n throw new BadRequestException('Nessun campo da aggiornare');\n }\n const query = `UPDATE ALLEGATI SET ${updates.join(', ')} WHERE IDXALL = ?`;\n params.push(id);\n const result = await Orm.execute(this.allegatiOptions.databaseOptions, query, params);\n if (!result) {\n throw new InternalServerErrorException('Errore durante l\\'aggiornamento del file');\n }\n } catch (error) {\n console.error('[AllegatiService] updateFieldsById - Errore:', error);\n throw error;\n }\n }\n\n /**\n * Get a single allegato by fields (returns the first match)\n */\n async getOneByFields(fields: { tipcod?: string; codice?: number; docrif?: string; idxtipoall?: number }): Promise<AllegatoDto | null> {\n const results = await this.findByFields(fields);\n return results.length > 0 ? results[0] : null;\n }\n\n}"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/allegati-module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,4DAqBC;AA1BD,uCAA2C;AAC3C,+DAA0D;AAC1D,qDAAmE;AACnE,sCAAmC;AAEnC,SAAsB,wBAAwB,CAAC,GAAgB,EAAE,OAAwB;;QACrF,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,0BAA0B,CAAC,CAAC;QAC9D,IAAI,CAAC;YACD,MAAM,mBAAmB,GAAG,IAAI,iCAAc,CAAC,GAAG,CAAC,CAAC;YACpD,MAAM,OAAO,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,+BAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,mBAAmB,EAAE;gBAC3F,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;YAEH,OAAO,CAAC,UAAU,EAAE,CAAC;YAErB,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE;gBAC3B,OAAO,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC;aACzC,CAAC,CAAC;YAEH,2DAA2D;YAC3D,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QAEzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC5D,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CAAA;AAED,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,yCAAuB,CAAC,yFAAyF","sourcesContent":["import { Application } from \"express\";\r\nimport { NestFactory } from \"@nestjs/core\";\r\nimport { ExpressAdapter } from \"@nestjs/platform-express\";\r\nimport { AllegatiModule, AllegatiOptions } from \"./AllegatiModule\";\r\nimport { Logger } from \"../Logger\";\r\n\r\nexport async function initializeAllegatiModule(app: Application, options: AllegatiOptions) {\r\n const logger: Logger = new Logger(\"initializeAllegatiModule\");\r\n try {\r\n const nestExpressInstance = new ExpressAdapter(app);\r\n const nestApp = await NestFactory.create(AllegatiModule.forRoot(options), nestExpressInstance, {\r\n bufferLogs: true\r\n });\r\n\r\n nestApp.enableCors();\r\n\r\n nestApp.setGlobalPrefix('api', {\r\n exclude: ['/swagger', '/swagger/(.*)']\r\n });\r\n\r\n // Note: Swagger setup is now handled by the unified module\r\n await nestApp.init();\r\n\r\n } catch (error) {\r\n logger.error(\"Errore in initialize AllegatiModule:\", error);\r\n throw error;\r\n }\r\n}\r\n\r\nexport { AllegatiModule } from \"./AllegatiModule\";\r\nexport * from \"./Dtos\"; // per esportare automaticamente i DTOs tipo AllegatoDto, UploadAllegatoResponseDto, etc."]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/allegati-module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,4DAqBC;AA1BD,uCAA2C;AAC3C,+DAA0D;AAC1D,qDAAmE;AACnE,sCAAmC;AAEnC,SAAsB,wBAAwB,CAAC,GAAgB,EAAE,OAAwB;;QACrF,MAAM,MAAM,GAAW,IAAI,eAAM,CAAC,0BAA0B,CAAC,CAAC;QAC9D,IAAI,CAAC;YACD,MAAM,mBAAmB,GAAG,IAAI,iCAAc,CAAC,GAAG,CAAC,CAAC;YACpD,MAAM,OAAO,GAAG,MAAM,kBAAW,CAAC,MAAM,CAAC,+BAAc,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,mBAAmB,EAAE;gBAC3F,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;YAEH,OAAO,CAAC,UAAU,EAAE,CAAC;YAErB,OAAO,CAAC,eAAe,CAAC,KAAK,EAAE;gBAC3B,OAAO,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC;aACzC,CAAC,CAAC;YAEH,2DAA2D;YAC3D,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC;QAEzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;YAC5D,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;CAAA;AAED,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,yCAAuB,CAAC,yFAAyF","sourcesContent":["import { Application } from \"express\";\nimport { NestFactory } from \"@nestjs/core\";\nimport { ExpressAdapter } from \"@nestjs/platform-express\";\nimport { AllegatiModule, AllegatiOptions } from \"./AllegatiModule\";\nimport { Logger } from \"../Logger\";\n\nexport async function initializeAllegatiModule(app: Application, options: AllegatiOptions) {\n const logger: Logger = new Logger(\"initializeAllegatiModule\");\n try {\n const nestExpressInstance = new ExpressAdapter(app);\n const nestApp = await NestFactory.create(AllegatiModule.forRoot(options), nestExpressInstance, {\n bufferLogs: true\n });\n\n nestApp.enableCors();\n\n nestApp.setGlobalPrefix('api', {\n exclude: ['/swagger', '/swagger/(.*)']\n });\n\n // Note: Swagger setup is now handled by the unified module\n await nestApp.init();\n\n } catch (error) {\n logger.error(\"Errore in initialize AllegatiModule:\", error);\n throw error;\n }\n}\n\nexport { AllegatiModule } from \"./AllegatiModule\";\nexport * from \"./Dtos\"; // per esportare automaticamente i DTOs tipo AllegatoDto, UploadAllegatoResponseDto, etc."]}
@@ -1 +1 @@
1
- {"version":3,"file":"autobind.js","sourceRoot":"","sources":["../src/autobind.ts"],"names":[],"mappings":";;AAAA,4BAYC;AAZD,SAAgB,QAAQ,CAA0C,WAAc;IAC5E,OAAO,KAAM,SAAQ,WAAW;QAC5B,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAC/E,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;oBAChF,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrC,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["export function autobind<T extends { new (...args: any[]): any }>(constructor: T): T {\r\n return class extends constructor {\r\n constructor(...args: any[]) {\r\n super(...args);\r\n Object.getOwnPropertyNames(constructor.prototype).forEach(key => {\r\n const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, key);\r\n if (descriptor && typeof descriptor.value === 'function' && key !== 'constructor') {\r\n this[key] = this[key].bind(this);\r\n }\r\n });\r\n }\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"autobind.js","sourceRoot":"","sources":["../src/autobind.ts"],"names":[],"mappings":";;AAAA,4BAYC;AAZD,SAAgB,QAAQ,CAA0C,WAAc;IAC5E,OAAO,KAAM,SAAQ,WAAW;QAC5B,YAAY,GAAG,IAAW;YACtB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBAC/E,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;oBAChF,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACrC,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["export function autobind<T extends { new (...args: any[]): any }>(constructor: T): T {\n return class extends constructor {\n constructor(...args: any[]) {\n super(...args);\n Object.getOwnPropertyNames(constructor.prototype).forEach(key => {\n const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, key);\n if (descriptor && typeof descriptor.value === 'function' && key !== 'constructor') {\n this[key] = this[key].bind(this);\n }\n });\n }\n };\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import type { Options } from "node-firebird";
2
+ export type FirebirdWireCryptMode = "disabled" | "enabled" | "required";
3
+ export type FirebirdAuthPlugin = "Legacy_Auth" | "Srp" | "Srp256" | "Srp384" | "Srp512";
4
+ export type FirebirdDriverStrategy = "modern";
5
+ export type FirebirdOptions = Options & {
6
+ wireCrypt?: FirebirdWireCryptMode | number;
7
+ pluginName?: FirebirdAuthPlugin;
8
+ authPlugins?: FirebirdAuthPlugin[];
9
+ connectTimeoutMs?: number;
10
+ compatibilityProbeTimeoutMs?: number;
11
+ compatibilityTotalTimeoutMs?: number;
12
+ firebirdDriver?: FirebirdDriverStrategy;
13
+ trimStringResults?: boolean;
14
+ };
15
+ type FirebirdErrorContext = {
16
+ stage: "attach" | "query" | "execute" | "transaction";
17
+ sql?: string;
18
+ };
19
+ export declare function normalizeFirebirdOptions(options: Options): FirebirdOptions;
20
+ export declare function describeFirebirdCompatibilityOptions(options: Options): string;
21
+ export declare function enhanceFirebirdError(error: unknown, options: Options, context: FirebirdErrorContext): Error;
22
+ export declare function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[];
23
+ export declare function shouldRetryFirebirdCompatibility(): boolean;
24
+ export declare function ensureEsNodeFirebirdCompatibilityPatch(): void;
25
+ export {};
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __rest = (this && this.__rest) || function (s, e) {
36
+ var t = {};
37
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
38
+ t[p] = s[p];
39
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
40
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
41
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
42
+ t[p[i]] = s[p[i]];
43
+ }
44
+ return t;
45
+ };
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.normalizeFirebirdOptions = normalizeFirebirdOptions;
48
+ exports.describeFirebirdCompatibilityOptions = describeFirebirdCompatibilityOptions;
49
+ exports.enhanceFirebirdError = enhanceFirebirdError;
50
+ exports.buildFirebirdCompatibilityCandidates = buildFirebirdCompatibilityCandidates;
51
+ exports.shouldRetryFirebirdCompatibility = shouldRetryFirebirdCompatibility;
52
+ exports.ensureEsNodeFirebirdCompatibilityPatch = ensureEsNodeFirebirdCompatibilityPatch;
53
+ const Firebird = __importStar(require("node-firebird"));
54
+ function isBlank(value) {
55
+ return value === undefined || value === null || (typeof value === "string" && value.trim() === "");
56
+ }
57
+ function normalizeWireCryptMode(value) {
58
+ if (isBlank(value)) {
59
+ return undefined;
60
+ }
61
+ if (typeof value === "number") {
62
+ return value;
63
+ }
64
+ const normalized = String(value).trim().toLowerCase();
65
+ if (normalized === "disabled") {
66
+ return Firebird.WIRE_CRYPT_DISABLE;
67
+ }
68
+ return Firebird.WIRE_CRYPT_ENABLE;
69
+ }
70
+ function normalizeAuthPlugin(value) {
71
+ if (isBlank(value)) {
72
+ return undefined;
73
+ }
74
+ const normalized = String(value).trim().toLowerCase();
75
+ if (normalized === "legacy" || normalized === "legacy_auth") {
76
+ return "Legacy_Auth";
77
+ }
78
+ if (normalized === "srp256") {
79
+ return "Srp256";
80
+ }
81
+ if (normalized === "srp384") {
82
+ return "Srp384";
83
+ }
84
+ if (normalized === "srp512") {
85
+ return "Srp512";
86
+ }
87
+ return "Srp";
88
+ }
89
+ function formatWireCryptValue(value) {
90
+ if (isBlank(value)) {
91
+ return "auto";
92
+ }
93
+ if (typeof value === "number") {
94
+ if (value === Firebird.WIRE_CRYPT_DISABLE) {
95
+ return "disabled";
96
+ }
97
+ if (value === Firebird.WIRE_CRYPT_ENABLE) {
98
+ return "enabled";
99
+ }
100
+ return String(value);
101
+ }
102
+ return String(value);
103
+ }
104
+ function formatTarget(options) {
105
+ var _a, _b, _c;
106
+ return `${(_a = options.host) !== null && _a !== void 0 ? _a : "?"}:${(_b = options.port) !== null && _b !== void 0 ? _b : "?"} -> ${(_c = options.database) !== null && _c !== void 0 ? _c : "?"}`;
107
+ }
108
+ function uniqueDiagnostics(values) {
109
+ return values.filter((value, index) => values.indexOf(value) === index);
110
+ }
111
+ function buildDiagnostics(message, options) {
112
+ const diagnostics = [];
113
+ const pluginMismatch = message.match(/Server don't accept plugin\s*:\s*([^,]+),\s*but support\s*:\s*(.+)$/i);
114
+ if (pluginMismatch) {
115
+ const supportedPlugins = pluginMismatch[2]
116
+ .split(",")
117
+ .map((plugin) => plugin.trim())
118
+ .filter((plugin) => plugin.length > 0);
119
+ const supportedMessage = supportedPlugins.length === 1
120
+ ? `The server explicitly reported that only the "${supportedPlugins[0]}" authentication plugin is supported.`
121
+ : `The server explicitly reported the supported authentication plugins: ${supportedPlugins.join(", ")}.`;
122
+ diagnostics.push(supportedMessage);
123
+ }
124
+ if (/Incompatible wire encryption levels requested on client and server/i.test(message)) {
125
+ diagnostics.push("The server rejected the requested wire encryption mode. Keep wire encryption auto-enabled unless the server is known to allow disabled encryption.");
126
+ }
127
+ if (/No matching plugins on server/i.test(message)) {
128
+ diagnostics.push("The server did not find a common authentication plugin with the client configuration.");
129
+ }
130
+ if (/Connection timeout after \d+ms/i.test(message) || /Timeout during Firebird attach after \d+ ms/i.test(message)) {
131
+ diagnostics.push("The TCP connection was accepted but the Firebird wire-protocol attach did not complete in time.");
132
+ }
133
+ if (options.pluginName) {
134
+ diagnostics.push(`Client authentication plugin was forced to "${options.pluginName}". Leave pluginName empty to let the driver auto-negotiate when possible.`);
135
+ }
136
+ if (!isBlank(options.wireCrypt)) {
137
+ diagnostics.push(`Client wire encryption was forced to "${formatWireCryptValue(options.wireCrypt)}".`);
138
+ }
139
+ return uniqueDiagnostics(diagnostics);
140
+ }
141
+ function copyFirebirdMetadata(target, source) {
142
+ if (!source || typeof source !== "object") {
143
+ return;
144
+ }
145
+ const firebirdSource = source;
146
+ if ("gdscode" in firebirdSource) {
147
+ target.gdscode = firebirdSource.gdscode;
148
+ }
149
+ if ("gdsparams" in firebirdSource) {
150
+ target.gdsparams = firebirdSource.gdsparams;
151
+ }
152
+ }
153
+ function formatFirebirdMetadata(source) {
154
+ if (!source || typeof source !== "object") {
155
+ return "";
156
+ }
157
+ const firebirdSource = source;
158
+ const metadata = [];
159
+ if (typeof firebirdSource.gdscode === "number") {
160
+ metadata.push(`gdscode=${firebirdSource.gdscode}`);
161
+ }
162
+ if (firebirdSource.gdsparams !== undefined) {
163
+ try {
164
+ metadata.push(`gdsparams=${JSON.stringify(firebirdSource.gdsparams)}`);
165
+ }
166
+ catch (_a) {
167
+ metadata.push(`gdsparams=${String(firebirdSource.gdsparams)}`);
168
+ }
169
+ }
170
+ return metadata.length > 0 ? ` Metadata: ${metadata.join(", ")}.` : "";
171
+ }
172
+ function normalizeFirebirdOptions(options) {
173
+ var _a, _b;
174
+ const compatibilityOptions = options;
175
+ const { authPlugins: _authPlugins, compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs, compatibilityTotalTimeoutMs, connectTimeoutMs, firebirdDriver: _firebirdDriver, trimStringResults } = compatibilityOptions, baseOptions = __rest(compatibilityOptions, ["authPlugins", "compatibilityProbeTimeoutMs", "compatibilityTotalTimeoutMs", "connectTimeoutMs", "firebirdDriver", "trimStringResults"]);
176
+ const normalizedOptions = Object.assign(Object.assign({}, baseOptions), { pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName), trimStringResults, wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt) });
177
+ const timeoutCandidate = (_b = (_a = compatibilityOptions.connectTimeout) !== null && _a !== void 0 ? _a : connectTimeoutMs) !== null && _b !== void 0 ? _b : compatibilityTotalTimeoutMs;
178
+ if (Number.isFinite(timeoutCandidate) && Number(timeoutCandidate) > 0) {
179
+ normalizedOptions.connectTimeout = Math.trunc(Number(timeoutCandidate));
180
+ }
181
+ return normalizedOptions;
182
+ }
183
+ function describeFirebirdCompatibilityOptions(options) {
184
+ var _a, _b;
185
+ const normalized = normalizeFirebirdOptions(options);
186
+ return `plugin=${(_a = normalized.pluginName) !== null && _a !== void 0 ? _a : "auto"}, wireCrypt=${formatWireCryptValue(normalized.wireCrypt)}, connectTimeout=${(_b = normalized.connectTimeout) !== null && _b !== void 0 ? _b : "default"}`;
187
+ }
188
+ function enhanceFirebirdError(error, options, context) {
189
+ var _a;
190
+ if (error instanceof Error && error.__emilsoftwareFirebirdEnhanced) {
191
+ return error;
192
+ }
193
+ const normalizedOptions = normalizeFirebirdOptions(options);
194
+ const target = formatTarget(normalizedOptions);
195
+ const original = error instanceof Error ? error : new Error(String(error));
196
+ const diagnostics = buildDiagnostics(original.message, normalizedOptions);
197
+ const sqlSuffix = context.sql ? ` SQL: ${context.sql.replace(/\s+/g, " ").trim()}` : "";
198
+ const diagnosticsSuffix = diagnostics.length > 0 ? ` Diagnostics: ${diagnostics.join(" ")}` : "";
199
+ const metadataSuffix = formatFirebirdMetadata(original);
200
+ const enhanced = new Error(`Firebird ${context.stage} failed on ${target}: ${original.message}.${diagnosticsSuffix}${metadataSuffix}${sqlSuffix}`);
201
+ enhanced.cause = original;
202
+ enhanced.__emilsoftwareFirebirdEnhanced = true;
203
+ copyFirebirdMetadata(enhanced, original);
204
+ enhanced.stack = `${enhanced.name}: ${enhanced.message}\nCaused by: ${(_a = original.stack) !== null && _a !== void 0 ? _a : original.message}`;
205
+ return enhanced;
206
+ }
207
+ function buildFirebirdCompatibilityCandidates(options) {
208
+ return [normalizeFirebirdOptions(options)];
209
+ }
210
+ function shouldRetryFirebirdCompatibility() {
211
+ return false;
212
+ }
213
+ function ensureEsNodeFirebirdCompatibilityPatch() {
214
+ // No-op kept for backward compatibility. The library now relies on the
215
+ // official node-firebird driver, which handles Firebird 2.5+ protocol
216
+ // negotiation natively.
217
+ }
218
+ //# sourceMappingURL=firebird-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebird-compat.js","sourceRoot":"","sources":["../src/firebird-compat.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoLA,4DA4BC;AAED,oFAGC;AAED,oDAqBC;AAED,oFAEC;AAED,4EAEC;AAED,wFAIC;AA1PD,wDAA0C;AA8B1C,SAAS,OAAO,CAAC,KAAc;IAC3B,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AACvG,CAAC;AAED,SAAS,sBAAsB,CAAC,KAAmC;IAC/D,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtD,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,kBAAkB,CAAC;IACvC,CAAC;IAED,OAAO,QAAQ,CAAC,iBAAiB,CAAC;AACtC,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAc;IACvC,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtD,IAAI,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,aAAa,EAAE,CAAC;QAC1D,OAAO,aAAa,CAAC;IACzB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AAI,KAAK,QAAQ,CAAC,OAAO,gBAAgB,MAAA,QAAQ,CAAC,KAAK,mCAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3G,OAAO,QAAQ,CAAC;AACpB,CAAC;AAED,SAAgB,oCAAoC,CAAC,OAAgB;IACjE,OAAO,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,gCAAgC;IAC5C,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,sCAAsC;IAClD,uEAAuE;IACvE,sEAAsE;IACtE,wBAAwB;AAC5B,CAAC","sourcesContent":["import * as Firebird from \"node-firebird\";\nimport type { Options } from \"node-firebird\";\n\nexport type FirebirdWireCryptMode = \"disabled\" | \"enabled\" | \"required\";\nexport type FirebirdAuthPlugin = \"Legacy_Auth\" | \"Srp\" | \"Srp256\" | \"Srp384\" | \"Srp512\";\nexport type FirebirdDriverStrategy = \"modern\";\n\nexport type FirebirdOptions = Options & {\n wireCrypt?: FirebirdWireCryptMode | number;\n pluginName?: FirebirdAuthPlugin;\n authPlugins?: FirebirdAuthPlugin[];\n connectTimeoutMs?: number;\n compatibilityProbeTimeoutMs?: number;\n compatibilityTotalTimeoutMs?: number;\n firebirdDriver?: FirebirdDriverStrategy;\n trimStringResults?: boolean;\n};\n\ntype FirebirdErrorContext = {\n stage: \"attach\" | \"query\" | \"execute\" | \"transaction\";\n sql?: string;\n};\n\ntype EnhancedFirebirdError = Error & {\n cause?: unknown;\n gdscode?: number;\n gdsparams?: unknown;\n __emilsoftwareFirebirdEnhanced?: boolean;\n};\n\nfunction isBlank(value: unknown): boolean {\n return value === undefined || value === null || (typeof value === \"string\" && value.trim() === \"\");\n}\n\nfunction normalizeWireCryptMode(value: FirebirdOptions[\"wireCrypt\"]): number | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n if (typeof value === \"number\") {\n return value;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"disabled\") {\n return Firebird.WIRE_CRYPT_DISABLE;\n }\n\n return Firebird.WIRE_CRYPT_ENABLE;\n}\n\nfunction normalizeAuthPlugin(value: unknown): FirebirdAuthPlugin | undefined {\n if (isBlank(value)) {\n return undefined;\n }\n\n const normalized = String(value).trim().toLowerCase();\n if (normalized === \"legacy\" || normalized === \"legacy_auth\") {\n return \"Legacy_Auth\";\n }\n\n if (normalized === \"srp256\") {\n return \"Srp256\";\n }\n\n if (normalized === \"srp384\") {\n return \"Srp384\";\n }\n\n if (normalized === \"srp512\") {\n return \"Srp512\";\n }\n\n return \"Srp\";\n}\n\nfunction formatWireCryptValue(value: FirebirdOptions[\"wireCrypt\"]): string {\n if (isBlank(value)) {\n return \"auto\";\n }\n\n if (typeof value === \"number\") {\n if (value === Firebird.WIRE_CRYPT_DISABLE) {\n return \"disabled\";\n }\n\n if (value === Firebird.WIRE_CRYPT_ENABLE) {\n return \"enabled\";\n }\n\n return String(value);\n }\n\n return String(value);\n}\n\nfunction formatTarget(options: Options): string {\n return `${options.host ?? \"?\"}:${options.port ?? \"?\"} -> ${options.database ?? \"?\"}`;\n}\n\nfunction uniqueDiagnostics(values: string[]): string[] {\n return values.filter((value, index) => values.indexOf(value) === index);\n}\n\nfunction buildDiagnostics(message: string, options: FirebirdOptions): string[] {\n const diagnostics: string[] = [];\n const pluginMismatch = message.match(/Server don't accept plugin\\s*:\\s*([^,]+),\\s*but support\\s*:\\s*(.+)$/i);\n\n if (pluginMismatch) {\n const supportedPlugins = pluginMismatch[2]\n .split(\",\")\n .map((plugin) => plugin.trim())\n .filter((plugin) => plugin.length > 0);\n const supportedMessage = supportedPlugins.length === 1\n ? `The server explicitly reported that only the \"${supportedPlugins[0]}\" authentication plugin is supported.`\n : `The server explicitly reported the supported authentication plugins: ${supportedPlugins.join(\", \")}.`;\n diagnostics.push(supportedMessage);\n }\n\n if (/Incompatible wire encryption levels requested on client and server/i.test(message)) {\n diagnostics.push(\"The server rejected the requested wire encryption mode. Keep wire encryption auto-enabled unless the server is known to allow disabled encryption.\");\n }\n\n if (/No matching plugins on server/i.test(message)) {\n diagnostics.push(\"The server did not find a common authentication plugin with the client configuration.\");\n }\n\n if (/Connection timeout after \\d+ms/i.test(message) || /Timeout during Firebird attach after \\d+ ms/i.test(message)) {\n diagnostics.push(\"The TCP connection was accepted but the Firebird wire-protocol attach did not complete in time.\");\n }\n\n if (options.pluginName) {\n diagnostics.push(`Client authentication plugin was forced to \"${options.pluginName}\". Leave pluginName empty to let the driver auto-negotiate when possible.`);\n }\n\n if (!isBlank(options.wireCrypt)) {\n diagnostics.push(`Client wire encryption was forced to \"${formatWireCryptValue(options.wireCrypt)}\".`);\n }\n\n return uniqueDiagnostics(diagnostics);\n}\n\nfunction copyFirebirdMetadata(target: EnhancedFirebirdError, source: unknown): void {\n if (!source || typeof source !== \"object\") {\n return;\n }\n\n const firebirdSource = source as Record<string, unknown>;\n if (\"gdscode\" in firebirdSource) {\n target.gdscode = firebirdSource.gdscode as number;\n }\n\n if (\"gdsparams\" in firebirdSource) {\n target.gdsparams = firebirdSource.gdsparams;\n }\n}\n\nfunction formatFirebirdMetadata(source: unknown): string {\n if (!source || typeof source !== \"object\") {\n return \"\";\n }\n\n const firebirdSource = source as Record<string, unknown>;\n const metadata: string[] = [];\n\n if (typeof firebirdSource.gdscode === \"number\") {\n metadata.push(`gdscode=${firebirdSource.gdscode}`);\n }\n\n if (firebirdSource.gdsparams !== undefined) {\n try {\n metadata.push(`gdsparams=${JSON.stringify(firebirdSource.gdsparams)}`);\n } catch {\n metadata.push(`gdsparams=${String(firebirdSource.gdsparams)}`);\n }\n }\n\n return metadata.length > 0 ? ` Metadata: ${metadata.join(\", \")}.` : \"\";\n}\n\nexport function normalizeFirebirdOptions(options: Options): FirebirdOptions {\n const compatibilityOptions = options as FirebirdOptions;\n const {\n authPlugins: _authPlugins,\n compatibilityProbeTimeoutMs: _compatibilityProbeTimeoutMs,\n compatibilityTotalTimeoutMs,\n connectTimeoutMs,\n firebirdDriver: _firebirdDriver,\n trimStringResults,\n ...baseOptions\n } = compatibilityOptions;\n\n const normalizedOptions: FirebirdOptions = {\n ...baseOptions,\n pluginName: normalizeAuthPlugin(compatibilityOptions.pluginName),\n trimStringResults,\n wireCrypt: normalizeWireCryptMode(compatibilityOptions.wireCrypt),\n };\n\n const timeoutCandidate = compatibilityOptions.connectTimeout\n ?? connectTimeoutMs\n ?? compatibilityTotalTimeoutMs;\n\n if (Number.isFinite(timeoutCandidate) && Number(timeoutCandidate) > 0) {\n normalizedOptions.connectTimeout = Math.trunc(Number(timeoutCandidate));\n }\n\n return normalizedOptions;\n}\n\nexport function describeFirebirdCompatibilityOptions(options: Options): string {\n const normalized = normalizeFirebirdOptions(options);\n return `plugin=${normalized.pluginName ?? \"auto\"}, wireCrypt=${formatWireCryptValue(normalized.wireCrypt)}, connectTimeout=${normalized.connectTimeout ?? \"default\"}`;\n}\n\nexport function enhanceFirebirdError(error: unknown, options: Options, context: FirebirdErrorContext): Error {\n if (error instanceof Error && (error as EnhancedFirebirdError).__emilsoftwareFirebirdEnhanced) {\n return error;\n }\n\n const normalizedOptions = normalizeFirebirdOptions(options);\n const target = formatTarget(normalizedOptions);\n const original = error instanceof Error ? error : new Error(String(error));\n const diagnostics = buildDiagnostics(original.message, normalizedOptions);\n const sqlSuffix = context.sql ? ` SQL: ${context.sql.replace(/\\s+/g, \" \").trim()}` : \"\";\n const diagnosticsSuffix = diagnostics.length > 0 ? ` Diagnostics: ${diagnostics.join(\" \")}` : \"\";\n const metadataSuffix = formatFirebirdMetadata(original);\n const enhanced = new Error(\n `Firebird ${context.stage} failed on ${target}: ${original.message}.${diagnosticsSuffix}${metadataSuffix}${sqlSuffix}`\n ) as EnhancedFirebirdError;\n\n enhanced.cause = original;\n enhanced.__emilsoftwareFirebirdEnhanced = true;\n copyFirebirdMetadata(enhanced, original);\n enhanced.stack = `${enhanced.name}: ${enhanced.message}\\nCaused by: ${original.stack ?? original.message}`;\n return enhanced;\n}\n\nexport function buildFirebirdCompatibilityCandidates(options: Options): FirebirdOptions[] {\n return [normalizeFirebirdOptions(options)];\n}\n\nexport function shouldRetryFirebirdCompatibility(): boolean {\n return false;\n}\n\nexport function ensureEsNodeFirebirdCompatibilityPatch(): void {\n // No-op kept for backward compatibility. The library now relies on the\n // official node-firebird driver, which handles Firebird 2.5+ protocol\n // negotiation natively.\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import { DatabaseUpdater } from "./DatabaseUpdater";
2
2
  import { ExecutionTimeLogger } from "./ExecutionTimeLogger";
3
+ import * as Firebird from "node-firebird";
3
4
  import { LogLevels, Logger } from "./Logger";
4
5
  import { Orm } from "./Orm";
5
6
  import { DateUtilities, RestUtilities, DatabaseUtilities, StatusCode } from "./Utilities";
6
7
  import { autobind } from "./autobind";
7
8
  import { DocumentGenerator } from "./ContractGenerator";
9
+ import "./firebird-compat";
8
10
  export * from "./Orm";
9
11
  export * from "./Utilities";
10
12
  export * from "./Logger";
@@ -13,9 +15,10 @@ export * from "./ExecutionTimeLogger";
13
15
  export * from "./RoutesLoggerMiddleware";
14
16
  export * from "./ContractGenerator";
15
17
  export * from "./DatabaseUpdater";
18
+ export * from "./firebird-compat";
16
19
  export * from "./accessi-module";
17
20
  export * from "./allegati-module";
18
- export * from "es-node-firebird";
19
- export { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode, DocumentGenerator };
21
+ export * from "node-firebird";
22
+ export { autobind, ExecutionTimeLogger, Logger, LogLevels, Orm, DateUtilities, RestUtilities, DatabaseUtilities, DatabaseUpdater, StatusCode, DocumentGenerator, Firebird };
20
23
  export * from "./swagger/SwaggerConfig";
21
24
  export * from "./initEmilsoftwareModule";