emilsoftware-utilities 2.0.0-dev.23 → 2.0.0-dev.25

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 (261) hide show
  1. package/README.MD +147 -0
  2. package/dist/ContractGenerator.d.ts +4 -3
  3. package/dist/ContractGenerator.js +15 -5
  4. package/dist/ContractGenerator.js.map +1 -1
  5. package/dist/DailyFileTransport.d.ts +8 -2
  6. package/dist/DailyFileTransport.js +9 -2
  7. package/dist/DailyFileTransport.js.map +1 -1
  8. package/dist/DatabaseUpdater.js +8 -3
  9. package/dist/DatabaseUpdater.js.map +1 -1
  10. package/dist/ExecutionTimeLogger.d.ts +2 -2
  11. package/dist/ExecutionTimeLogger.js +3 -2
  12. package/dist/ExecutionTimeLogger.js.map +1 -1
  13. package/dist/Logger.d.ts +22 -9
  14. package/dist/Logger.js +131 -54
  15. package/dist/Logger.js.map +1 -1
  16. package/dist/Orm.d.ts +26 -6
  17. package/dist/Orm.js +144 -40
  18. package/dist/Orm.js.map +1 -1
  19. package/dist/Utilities.d.ts +12 -7
  20. package/dist/Utilities.js +57 -22
  21. package/dist/Utilities.js.map +1 -1
  22. package/dist/accessi-module/AccessiModule.d.ts +9 -0
  23. package/dist/accessi-module/AccessiModule.js +12 -4
  24. package/dist/accessi-module/AccessiModule.js.map +1 -1
  25. package/dist/accessi-module/Console/console.css +529 -281
  26. package/dist/accessi-module/Console/console.js +2081 -85
  27. package/dist/accessi-module/Console/console.js.map +1 -1
  28. package/dist/accessi-module/Console/generated/accessiApi.d.ts +167 -1
  29. package/dist/accessi-module/Console/generated/accessiApi.js +156 -2
  30. package/dist/accessi-module/Console/generated/accessiApi.js.map +1 -1
  31. package/dist/accessi-module/Console/generated/model/abilitazioneMenu.d.ts +20 -8
  32. package/dist/accessi-module/Console/generated/model/abilitazioneMenu.js.map +1 -1
  33. package/dist/accessi-module/Console/generated/model/createFilterTypeRequest.d.ts +23 -0
  34. package/dist/accessi-module/Console/generated/model/createFilterTypeRequest.js +3 -0
  35. package/dist/accessi-module/Console/generated/model/createFilterTypeRequest.js.map +1 -0
  36. package/dist/accessi-module/Console/generated/model/createFilterTypeRequestFlgEnabled.d.ts +14 -0
  37. package/dist/accessi-module/Console/generated/model/createFilterTypeRequestFlgEnabled.js +15 -0
  38. package/dist/accessi-module/Console/generated/model/createFilterTypeRequestFlgEnabled.js.map +1 -0
  39. package/dist/accessi-module/Console/generated/model/createMenuGroupRequest.d.ts +27 -0
  40. package/dist/accessi-module/Console/generated/model/createMenuGroupRequest.js +9 -0
  41. package/dist/accessi-module/Console/generated/model/createMenuGroupRequest.js.map +1 -0
  42. package/dist/accessi-module/Console/generated/model/createMenuRequest.d.ts +52 -0
  43. package/dist/accessi-module/Console/generated/model/createMenuRequest.js +9 -0
  44. package/dist/accessi-module/Console/generated/model/createMenuRequest.js.map +1 -0
  45. package/dist/accessi-module/Console/generated/model/createMenuTypeRequest.d.ts +18 -0
  46. package/dist/accessi-module/Console/generated/model/createMenuTypeRequest.js +9 -0
  47. package/dist/accessi-module/Console/generated/model/createMenuTypeRequest.js.map +1 -0
  48. package/dist/accessi-module/Console/generated/model/createServiceTokenRequest.d.ts +16 -0
  49. package/dist/accessi-module/Console/generated/model/createServiceTokenRequest.js +9 -0
  50. package/dist/accessi-module/Console/generated/model/createServiceTokenRequest.js.map +1 -0
  51. package/dist/accessi-module/Console/generated/model/createServiceTokenResponse.d.ts +14 -0
  52. package/dist/accessi-module/Console/generated/model/createServiceTokenResponse.js +3 -0
  53. package/dist/accessi-module/Console/generated/model/createServiceTokenResponse.js.map +1 -0
  54. package/dist/accessi-module/Console/generated/model/getMenuTypesResponse.d.ts +14 -0
  55. package/dist/accessi-module/Console/generated/model/getMenuTypesResponse.js +3 -0
  56. package/dist/accessi-module/Console/generated/model/getMenuTypesResponse.js.map +1 -0
  57. package/dist/accessi-module/Console/generated/model/getServiceTokensParams.d.ts +12 -0
  58. package/dist/accessi-module/Console/generated/model/getServiceTokensParams.js +9 -0
  59. package/dist/accessi-module/Console/generated/model/getServiceTokensParams.js.map +1 -0
  60. package/dist/accessi-module/Console/generated/model/getServiceTokensResponse.d.ts +14 -0
  61. package/dist/accessi-module/Console/generated/model/getServiceTokensResponse.js +3 -0
  62. package/dist/accessi-module/Console/generated/model/getServiceTokensResponse.js.map +1 -0
  63. package/dist/accessi-module/Console/generated/model/getUsersParams.d.ts +8 -0
  64. package/dist/accessi-module/Console/generated/model/getUsersParams.js.map +1 -1
  65. package/dist/accessi-module/Console/generated/model/index.d.ts +18 -0
  66. package/dist/accessi-module/Console/generated/model/index.js +18 -0
  67. package/dist/accessi-module/Console/generated/model/index.js.map +1 -1
  68. package/dist/accessi-module/Console/generated/model/issuedServiceTokenDto.d.ts +30 -0
  69. package/dist/accessi-module/Console/generated/model/issuedServiceTokenDto.js +9 -0
  70. package/dist/accessi-module/Console/generated/model/issuedServiceTokenDto.js.map +1 -0
  71. package/dist/accessi-module/Console/generated/model/menuTypeEntity.d.ts +12 -0
  72. package/dist/accessi-module/Console/generated/model/menuTypeEntity.js +9 -0
  73. package/dist/accessi-module/Console/generated/model/menuTypeEntity.js.map +1 -0
  74. package/dist/accessi-module/Console/generated/model/serviceTokenDto.d.ts +28 -0
  75. package/dist/accessi-module/Console/generated/model/serviceTokenDto.js +9 -0
  76. package/dist/accessi-module/Console/generated/model/serviceTokenDto.js.map +1 -0
  77. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequest.d.ts +21 -0
  78. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequest.js +3 -0
  79. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequest.js.map +1 -0
  80. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequestFlgEnabled.d.ts +14 -0
  81. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequestFlgEnabled.js +15 -0
  82. package/dist/accessi-module/Console/generated/model/updateFilterTypeRequestFlgEnabled.js.map +1 -0
  83. package/dist/accessi-module/Console/generated/model/updateMenuGroupRequest.d.ts +22 -0
  84. package/dist/accessi-module/Console/generated/model/updateMenuGroupRequest.js +9 -0
  85. package/dist/accessi-module/Console/generated/model/updateMenuGroupRequest.js.map +1 -0
  86. package/dist/accessi-module/Console/generated/model/updateMenuRequest.d.ts +47 -0
  87. package/dist/accessi-module/Console/generated/model/updateMenuRequest.js +9 -0
  88. package/dist/accessi-module/Console/generated/model/updateMenuRequest.js.map +1 -0
  89. package/dist/accessi-module/Console/generated/model/updateMenuTypeRequest.d.ts +13 -0
  90. package/dist/accessi-module/Console/generated/model/updateMenuTypeRequest.js +9 -0
  91. package/dist/accessi-module/Console/generated/model/updateMenuTypeRequest.js.map +1 -0
  92. package/dist/accessi-module/Console/help.d.ts +13 -0
  93. package/dist/accessi-module/Console/help.js +348 -0
  94. package/dist/accessi-module/Console/help.js.map +1 -0
  95. package/dist/accessi-module/Console/index.html +89 -21
  96. package/dist/accessi-module/Console/wiki.d.ts +52 -0
  97. package/dist/accessi-module/Console/wiki.js +689 -0
  98. package/dist/accessi-module/Console/wiki.js.map +1 -0
  99. package/dist/accessi-module/Controllers/AccessiConsoleController.d.ts +8 -1
  100. package/dist/accessi-module/Controllers/AccessiConsoleController.js +52 -15
  101. package/dist/accessi-module/Controllers/AccessiConsoleController.js.map +1 -1
  102. package/dist/accessi-module/Controllers/ConfiguratorController.d.ts +1 -3
  103. package/dist/accessi-module/Controllers/ConfiguratorController.js +6 -8
  104. package/dist/accessi-module/Controllers/ConfiguratorController.js.map +1 -1
  105. package/dist/accessi-module/Controllers/EmailController.d.ts +1 -1
  106. package/dist/accessi-module/Controllers/EmailController.js +1 -1
  107. package/dist/accessi-module/Controllers/EmailController.js.map +1 -1
  108. package/dist/accessi-module/Controllers/FiltriController.d.ts +5 -4
  109. package/dist/accessi-module/Controllers/FiltriController.js +92 -4
  110. package/dist/accessi-module/Controllers/FiltriController.js.map +1 -1
  111. package/dist/accessi-module/Controllers/PermissionController.d.ts +11 -0
  112. package/dist/accessi-module/Controllers/PermissionController.js +273 -8
  113. package/dist/accessi-module/Controllers/PermissionController.js.map +1 -1
  114. package/dist/accessi-module/Controllers/ServiceTokenController.d.ts +23 -0
  115. package/dist/accessi-module/Controllers/ServiceTokenController.js +176 -0
  116. package/dist/accessi-module/Controllers/ServiceTokenController.js.map +1 -0
  117. package/dist/accessi-module/Controllers/UserController.d.ts +2 -2
  118. package/dist/accessi-module/Controllers/UserController.js +25 -9
  119. package/dist/accessi-module/Controllers/UserController.js.map +1 -1
  120. package/dist/accessi-module/Dtos/Abilitazione.js.map +1 -1
  121. package/dist/accessi-module/Dtos/AbilitazioneMenu.js +16 -8
  122. package/dist/accessi-module/Dtos/AbilitazioneMenu.js.map +1 -1
  123. package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js.map +1 -1
  124. package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js.map +1 -1
  125. package/dist/accessi-module/Dtos/AuthenticatedUserPayloadDto.js.map +1 -1
  126. package/dist/accessi-module/Dtos/BaseResponse.js.map +1 -1
  127. package/dist/accessi-module/Dtos/CatalogDtos.d.ts +66 -0
  128. package/dist/accessi-module/Dtos/CatalogDtos.js +336 -0
  129. package/dist/accessi-module/Dtos/CatalogDtos.js.map +1 -0
  130. package/dist/accessi-module/Dtos/ConfirmResetPasswordRequest.js.map +1 -1
  131. package/dist/accessi-module/Dtos/FiltriUtente.js.map +1 -1
  132. package/dist/accessi-module/Dtos/GetGroupsWithMenusResponse.js.map +1 -1
  133. package/dist/accessi-module/Dtos/GetMenusResponse.js +1 -1
  134. package/dist/accessi-module/Dtos/GetMenusResponse.js.map +1 -1
  135. package/dist/accessi-module/Dtos/GetRolesResponse.js.map +1 -1
  136. package/dist/accessi-module/Dtos/GetUserByTokenRequest.js.map +1 -1
  137. package/dist/accessi-module/Dtos/GetUserByTokenResponse.js.map +1 -1
  138. package/dist/accessi-module/Dtos/GetUsersResponse.d.ts +1 -1
  139. package/dist/accessi-module/Dtos/GetUsersResponse.js.map +1 -1
  140. package/dist/accessi-module/Dtos/LoginRequest.js.map +1 -1
  141. package/dist/accessi-module/Dtos/LoginResponse.d.ts +1 -1
  142. package/dist/accessi-module/Dtos/LoginResponse.js +1 -1
  143. package/dist/accessi-module/Dtos/LoginResponse.js.map +1 -1
  144. package/dist/accessi-module/Dtos/MenuItem.js +1 -0
  145. package/dist/accessi-module/Dtos/Permission.js.map +1 -1
  146. package/dist/accessi-module/Dtos/RegisterRequest.js +2 -1
  147. package/dist/accessi-module/Dtos/RegisterRequest.js.map +1 -1
  148. package/dist/accessi-module/Dtos/RegisterResponse.js.map +1 -1
  149. package/dist/accessi-module/Dtos/Role.js.map +1 -1
  150. package/dist/accessi-module/Dtos/RuoliMenu.js.map +1 -1
  151. package/dist/accessi-module/Dtos/SendResetPasswordEmailRequest.js.map +1 -1
  152. package/dist/accessi-module/Dtos/ServiceToken.d.ts +34 -0
  153. package/dist/accessi-module/Dtos/ServiceToken.js +128 -0
  154. package/dist/accessi-module/Dtos/ServiceToken.js.map +1 -0
  155. package/dist/accessi-module/Dtos/SetStatoRegistrazione.js.map +1 -1
  156. package/dist/accessi-module/Dtos/TipoFiltro.js.map +1 -1
  157. package/dist/accessi-module/Dtos/TokenResult.js.map +1 -1
  158. package/dist/accessi-module/Dtos/TwoFactorDtos.js.map +1 -1
  159. package/dist/accessi-module/Dtos/UpdateEnabledStatusRequest.js.map +1 -1
  160. package/dist/accessi-module/Dtos/UserDto.js +4 -2
  161. package/dist/accessi-module/Dtos/UserDto.js.map +1 -1
  162. package/dist/accessi-module/Dtos/UserGrantsDto.js.map +1 -1
  163. package/dist/accessi-module/Dtos/UserGrantsResponse.js.map +1 -1
  164. package/dist/accessi-module/Dtos/index.d.ts +2 -0
  165. package/dist/accessi-module/Dtos/index.js +2 -0
  166. package/dist/accessi-module/Dtos/index.js.map +1 -1
  167. package/dist/accessi-module/Services/AuthService/AuthService.d.ts +2 -2
  168. package/dist/accessi-module/Services/AuthService/AuthService.js +36 -36
  169. package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
  170. package/dist/accessi-module/Services/EmailService/EmailService.d.ts +2 -1
  171. package/dist/accessi-module/Services/EmailService/EmailService.js +9 -6
  172. package/dist/accessi-module/Services/EmailService/EmailService.js.map +1 -1
  173. package/dist/accessi-module/Services/FiltriService/FiltriService.d.ts +10 -3
  174. package/dist/accessi-module/Services/FiltriService/FiltriService.js +64 -6
  175. package/dist/accessi-module/Services/FiltriService/FiltriService.js.map +1 -1
  176. package/dist/accessi-module/Services/PermissionService/PermissionService.d.ts +44 -1
  177. package/dist/accessi-module/Services/PermissionService/PermissionService.js +418 -110
  178. package/dist/accessi-module/Services/PermissionService/PermissionService.js.map +1 -1
  179. package/dist/accessi-module/Services/ServiceTokenService/ServiceTokenService.d.ts +75 -0
  180. package/dist/accessi-module/Services/ServiceTokenService/ServiceTokenService.js +265 -0
  181. package/dist/accessi-module/Services/ServiceTokenService/ServiceTokenService.js.map +1 -0
  182. package/dist/accessi-module/Services/TwoFactorService/TwoFactorService.js +23 -27
  183. package/dist/accessi-module/Services/TwoFactorService/TwoFactorService.js.map +1 -1
  184. package/dist/accessi-module/Services/UserService/UserService.d.ts +10 -3
  185. package/dist/accessi-module/Services/UserService/UserService.js +170 -84
  186. package/dist/accessi-module/Services/UserService/UserService.js.map +1 -1
  187. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.d.ts +9 -0
  188. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js +76 -28
  189. package/dist/accessi-module/database-updates/AccessiDatabaseUpdater.js.map +1 -1
  190. package/dist/accessi-module/database-updates/accessiSchema.d.ts +1 -1
  191. package/dist/accessi-module/database-updates/accessiSchema.js +9 -1
  192. package/dist/accessi-module/database-updates/accessiSchema.js.map +1 -1
  193. package/dist/accessi-module/database-updates/optionalColumns.d.ts +2 -0
  194. package/dist/accessi-module/database-updates/optionalColumns.js +33 -1
  195. package/dist/accessi-module/database-updates/optionalColumns.js.map +1 -1
  196. package/dist/accessi-module/database-updates/runAccessiDbUpdate.js +7 -2
  197. package/dist/accessi-module/database-updates/runAccessiDbUpdate.js.map +1 -1
  198. package/dist/accessi-module/federated-auth/FederatedAuthController.d.ts +1 -0
  199. package/dist/accessi-module/federated-auth/FederatedAuthController.js +26 -0
  200. package/dist/accessi-module/federated-auth/FederatedAuthController.js.map +1 -1
  201. package/dist/accessi-module/federated-auth/FederatedAuthService.d.ts +6 -0
  202. package/dist/accessi-module/federated-auth/FederatedAuthService.js +28 -1
  203. package/dist/accessi-module/federated-auth/FederatedAuthService.js.map +1 -1
  204. package/dist/accessi-module/index.d.ts +4 -1
  205. package/dist/accessi-module/index.js +8 -2
  206. package/dist/accessi-module/index.js.map +1 -1
  207. package/dist/accessi-module/jwt/jwt.strategy.js +8 -5
  208. package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
  209. package/dist/accessi-module/middleware/accessiRequirements.d.ts +1 -1
  210. package/dist/accessi-module/middleware/accessiRequirements.js.map +1 -1
  211. package/dist/accessi-module/middleware/authenticateGen.js +11 -7
  212. package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
  213. package/dist/accessi-module/security/accessControl.js +8 -3
  214. package/dist/accessi-module/security/accessControl.js.map +1 -1
  215. package/dist/accessi-module/security/authenticatedToken.d.ts +1 -1
  216. package/dist/accessi-module/security/authenticatedToken.js +2 -1
  217. package/dist/accessi-module/security/authenticatedToken.js.map +1 -1
  218. package/dist/accessi-module/security/passwordResetToken.d.ts +9 -3
  219. package/dist/accessi-module/security/passwordResetToken.js +9 -5
  220. package/dist/accessi-module/security/passwordResetToken.js.map +1 -1
  221. package/dist/accessi-module/security/publicAuthRateLimit.d.ts +1 -1
  222. package/dist/accessi-module/security/publicAuthRateLimit.js +28 -8
  223. package/dist/accessi-module/security/publicAuthRateLimit.js.map +1 -1
  224. package/dist/accessi-module/security/serviceTokenGuard.d.ts +25 -0
  225. package/dist/accessi-module/security/serviceTokenGuard.js +85 -0
  226. package/dist/accessi-module/security/serviceTokenGuard.js.map +1 -0
  227. package/dist/accessi-module/security/serviceTokenRateLimit.d.ts +8 -0
  228. package/dist/accessi-module/security/serviceTokenRateLimit.js +49 -0
  229. package/dist/accessi-module/security/serviceTokenRateLimit.js.map +1 -0
  230. package/dist/allegati-module/AllegatiModule.d.ts +11 -0
  231. package/dist/allegati-module/AllegatiModule.js +11 -1
  232. package/dist/allegati-module/AllegatiModule.js.map +1 -1
  233. package/dist/allegati-module/Controllers/AllegatiController.d.ts +2 -1
  234. package/dist/allegati-module/Controllers/AllegatiController.js +23 -15
  235. package/dist/allegati-module/Controllers/AllegatiController.js.map +1 -1
  236. package/dist/allegati-module/Dtos/AllegatoDto.js.map +1 -1
  237. package/dist/allegati-module/Dtos/BaseResponse.js.map +1 -1
  238. package/dist/allegati-module/Dtos/UploadSingleFileRequest.js.map +1 -1
  239. package/dist/allegati-module/Dtos/responses/DownloadAllegatoResponseDto.js.map +1 -1
  240. package/dist/allegati-module/Dtos/responses/GetListResponse.js.map +1 -1
  241. package/dist/allegati-module/Dtos/responses/UploadAllegatoResponseDto.js.map +1 -1
  242. package/dist/allegati-module/Services/AllegatiService/AllegatiService.d.ts +10 -3
  243. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js +101 -52
  244. package/dist/allegati-module/Services/AllegatiService/AllegatiService.js.map +1 -1
  245. package/dist/allegati-module/security/allegatiAuthorizationGuard.d.ts +14 -0
  246. package/dist/allegati-module/security/allegatiAuthorizationGuard.js +70 -0
  247. package/dist/allegati-module/security/allegatiAuthorizationGuard.js.map +1 -0
  248. package/dist/autobind.d.ts +10 -3
  249. package/dist/autobind.js +24 -9
  250. package/dist/autobind.js.map +1 -1
  251. package/dist/emilsoftware-utilities-2.0.0-dev.25.tgz +0 -0
  252. package/dist/firebird-compat.d.ts +13 -0
  253. package/dist/firebird-compat.js +3 -2
  254. package/dist/firebird-compat.js.map +1 -1
  255. package/dist/scripts/generateAccessiWiki.d.ts +1 -0
  256. package/dist/scripts/generateAccessiWiki.js +131 -0
  257. package/dist/scripts/generateAccessiWiki.js.map +1 -0
  258. package/dist/swagger/SwaggerConfig.js +6 -3
  259. package/dist/swagger/SwaggerConfig.js.map +1 -1
  260. package/package.json +19 -8
  261. package/dist/emilsoftware-utilities-2.0.0-dev.23.tgz +0 -0
@@ -20,10 +20,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  step((generator = generator.apply(thisArg, _arguments || [])).next());
21
21
  });
22
22
  };
23
+ var AllegatiService_1;
23
24
  Object.defineProperty(exports, "__esModule", { value: true });
24
25
  exports.AllegatiService = exports.AllegatiError = void 0;
25
26
  const common_1 = require("@nestjs/common");
26
27
  const autobind_1 = require("../../../autobind");
28
+ const Logger_1 = require("../../../Logger");
27
29
  const Orm_1 = require("../../../Orm");
28
30
  class AllegatiError extends Error {
29
31
  constructor(message, code, statusCode = 500) {
@@ -34,9 +36,10 @@ class AllegatiError extends Error {
34
36
  }
35
37
  }
36
38
  exports.AllegatiError = AllegatiError;
37
- let AllegatiService = class AllegatiService {
39
+ let AllegatiService = AllegatiService_1 = class AllegatiService {
38
40
  constructor(allegatiOptions) {
39
41
  this.allegatiOptions = allegatiOptions;
42
+ this.logger = new Logger_1.Logger(AllegatiService_1.name);
40
43
  this.MAX_FILE_SIZE = 90 * 1024 * 1024; // 90MB
41
44
  this.ALLOWED_MIME_TYPES = [
42
45
  'application/pdf',
@@ -47,11 +50,37 @@ let AllegatiService = class AllegatiService {
47
50
  'application/vnd.ms-excel',
48
51
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
49
52
  ];
50
- this.ensureTableExists().catch(error => {
51
- console.error('[AllegatiService] Errore creazione tabella ALLEGATI:', error);
52
- // throw new InternalServerErrorException('Errore durante l\'inizializzazione del servizio allegati');
53
+ }
54
+ /** Verifica la tabella ALLEGATI all'avvio (attesa da Nest, senza promise floating). */
55
+ onModuleInit() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ yield this.ensureTableExists();
59
+ }
60
+ catch (error) {
61
+ this.logger.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);
62
+ }
53
63
  });
54
64
  }
65
+ toAllegatoDto(row) {
66
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
67
+ const optionalString = (value) => value === undefined || value === null ? undefined : String(value);
68
+ const optionalNumber = (value) => value === undefined || value === null ? undefined : Number(value);
69
+ return {
70
+ id: Number((_a = row.ID) !== null && _a !== void 0 ? _a : row.id),
71
+ filename: String((_c = (_b = row.FILENAME) !== null && _b !== void 0 ? _b : row.filename) !== null && _c !== void 0 ? _c : ''),
72
+ mimetype: String((_e = (_d = row.MIMETYPE) !== null && _d !== void 0 ? _d : row.mimetype) !== null && _e !== void 0 ? _e : ''),
73
+ uploadDate: String((_g = (_f = row.UPLOADDATE) !== null && _f !== void 0 ? _f : row.uploadDate) !== null && _g !== void 0 ? _g : ''),
74
+ codice: optionalString((_h = row.CODICE) !== null && _h !== void 0 ? _h : row.codice),
75
+ tipoCodice: optionalString((_j = row.TIPOCODICE) !== null && _j !== void 0 ? _j : row.tipoCodice),
76
+ ordine: optionalString((_k = row.ORDINE) !== null && _k !== void 0 ? _k : row.ordine),
77
+ descrizioneAllegato: optionalString((_l = row.DESCRIZIONEALLEGATO) !== null && _l !== void 0 ? _l : row.descrizioneAllegato),
78
+ dataInizioValidita: optionalString((_m = row.DATAINIZIOVALIDITA) !== null && _m !== void 0 ? _m : row.dataInizioValidita),
79
+ dataFineValidita: optionalString((_o = row.DATAFINEVALIDITA) !== null && _o !== void 0 ? _o : row.dataFineValidita),
80
+ idTipoAllegato: optionalNumber((_p = row.IDTIPOALLEGATO) !== null && _p !== void 0 ? _p : row.idTipoAllegato),
81
+ riferimentoDocumento: optionalString((_q = row.RIFERIMENTODOCUMENTO) !== null && _q !== void 0 ? _q : row.riferimentoDocumento),
82
+ };
83
+ }
55
84
  validateFile(file) {
56
85
  if (!file) {
57
86
  throw new common_1.BadRequestException('Nessun file fornito');
@@ -62,6 +91,43 @@ let AllegatiService = class AllegatiService {
62
91
  if (!this.ALLOWED_MIME_TYPES.includes(file.mimetype)) {
63
92
  throw new common_1.BadRequestException(`Tipo di file non consentito. Tipi consentiti: ${this.ALLOWED_MIME_TYPES.join(', ')}`);
64
93
  }
94
+ // Il mimetype dichiarato dal client e falsificabile: verifica i magic byte reali.
95
+ if (!this.hasValidSignature(file)) {
96
+ throw new common_1.BadRequestException('Il contenuto del file non corrisponde al tipo dichiarato.');
97
+ }
98
+ }
99
+ hasValidSignature(file) {
100
+ const buffer = file === null || file === void 0 ? void 0 : file.buffer;
101
+ if (!buffer || buffer.length < 4) {
102
+ return false;
103
+ }
104
+ const startsWith = (...bytes) => bytes.every((byte, index) => buffer[index] === byte);
105
+ switch (file.mimetype) {
106
+ case 'application/pdf':
107
+ return startsWith(0x25, 0x50, 0x44, 0x46);
108
+ case 'image/jpeg':
109
+ return startsWith(0xff, 0xd8, 0xff);
110
+ case 'image/png':
111
+ return startsWith(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a);
112
+ case 'application/msword':
113
+ case 'application/vnd.ms-excel':
114
+ return startsWith(0xd0, 0xcf, 0x11, 0xe0);
115
+ case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
116
+ case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
117
+ // DOCX/XLSX sono archivi ZIP.
118
+ return startsWith(0x50, 0x4b, 0x03, 0x04)
119
+ || startsWith(0x50, 0x4b, 0x05, 0x06)
120
+ || startsWith(0x50, 0x4b, 0x07, 0x08);
121
+ default:
122
+ return false;
123
+ }
124
+ }
125
+ sanitizeFilename(name) {
126
+ var _a;
127
+ const raw = typeof name === 'string' ? name : '';
128
+ const base = (_a = raw.replace(/\\/g, '/').split('/').pop()) !== null && _a !== void 0 ? _a : '';
129
+ const cleaned = base.replace(/[\u0000-\u001f\u007f<>:"|?*]/g, '_').trim();
130
+ return cleaned.slice(0, 255) || 'allegato';
65
131
  }
66
132
  getAttachmentTypes() {
67
133
  return __awaiter(this, void 0, void 0, function* () {
@@ -74,7 +140,7 @@ let AllegatiService = class AllegatiService {
74
140
  return results;
75
141
  }
76
142
  catch (error) {
77
- console.error('[AllegatiService] getAttachmentTypes - Errore:', error);
143
+ this.logger.error('[AllegatiService] getAttachmentTypes - Errore:', error);
78
144
  if (error instanceof common_1.InternalServerErrorException) {
79
145
  throw error;
80
146
  }
@@ -84,6 +150,7 @@ let AllegatiService = class AllegatiService {
84
150
  }
85
151
  uploadFile(file, uploadSingleFileRequest) {
86
152
  return __awaiter(this, void 0, void 0, function* () {
153
+ var _a;
87
154
  try {
88
155
  this.validateFile(file);
89
156
  // Convert buffer to base64 in chunks to avoid memory issues
@@ -105,7 +172,7 @@ let AllegatiService = class AllegatiService {
105
172
  uploadSingleFileRequest.tipoCodice,
106
173
  uploadSingleFileRequest.ordine,
107
174
  uploadSingleFileRequest.descrizioneAllegato,
108
- file.originalname,
175
+ this.sanitizeFilename(file.originalname),
109
176
  uploadSingleFileRequest.dataInizioValidita,
110
177
  uploadSingleFileRequest.dataFineValidita,
111
178
  base64Content,
@@ -113,16 +180,20 @@ let AllegatiService = class AllegatiService {
113
180
  uploadSingleFileRequest.riferimentoDocumento
114
181
  ];
115
182
  const result = yield Orm_1.Orm.query(this.allegatiOptions.databaseOptions, insertQuery, params);
116
- if (!result || !result.IDXALL) {
183
+ // node-firebird restituisce le righe di INSERT ... RETURNING come array; il fallback
184
+ // copre le versioni/driver che restituiscono un singolo oggetto.
185
+ const inserted = (Array.isArray(result) ? result[0] : result);
186
+ const insertedId = (_a = inserted === null || inserted === void 0 ? void 0 : inserted.IDXALL) !== null && _a !== void 0 ? _a : inserted === null || inserted === void 0 ? void 0 : inserted.idxall;
187
+ if (insertedId === undefined || insertedId === null) {
117
188
  throw new common_1.InternalServerErrorException('Errore durante il salvataggio del file');
118
189
  }
119
190
  return {
120
- id: result.IDXALL,
121
- filename: file.originalname,
191
+ id: Number(insertedId),
192
+ filename: this.sanitizeFilename(file.originalname),
122
193
  };
123
194
  }
124
195
  catch (error) {
125
- console.error('[AllegatiService] uploadFile - Errore:', error);
196
+ this.logger.error('[AllegatiService] uploadFile - Errore:', error);
126
197
  if (error instanceof common_1.BadRequestException || error instanceof common_1.InternalServerErrorException) {
127
198
  throw error;
128
199
  }
@@ -144,13 +215,14 @@ let AllegatiService = class AllegatiService {
144
215
  }
145
216
  }
146
217
  catch (error) {
147
- console.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);
218
+ this.logger.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);
148
219
  throw new common_1.InternalServerErrorException('Errore durante la verifica della tabella ALLEGATI');
149
220
  }
150
221
  });
151
222
  }
152
223
  downloadFile(id) {
153
224
  return __awaiter(this, void 0, void 0, function* () {
225
+ var _a, _b;
154
226
  try {
155
227
  if (!id || id <= 0) {
156
228
  throw new common_1.BadRequestException('ID allegato non valido');
@@ -168,21 +240,23 @@ let AllegatiService = class AllegatiService {
168
240
  throw new common_1.NotFoundException(`Allegato con ID ${id} non trovato`);
169
241
  }
170
242
  const result = results[0];
171
- if (!result.CONTENT) {
243
+ const content = (_a = result === null || result === void 0 ? void 0 : result.CONTENT) !== null && _a !== void 0 ? _a : result === null || result === void 0 ? void 0 : result.content;
244
+ const filename = (_b = result === null || result === void 0 ? void 0 : result.FILENAME) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.filename;
245
+ if (typeof content !== 'string' || content.length === 0) {
172
246
  throw new common_1.InternalServerErrorException('Contenuto file non disponibile');
173
247
  }
174
- if (!result.FILENAME) {
248
+ if (typeof filename !== 'string' || filename.length === 0) {
175
249
  throw new common_1.InternalServerErrorException('Nome file non disponibile');
176
250
  }
177
- const mimetype = this.detectMimeType(result.FILENAME);
251
+ const mimetype = this.detectMimeType(filename);
178
252
  return {
179
- contentBase64: result.CONTENT,
180
- filename: result.FILENAME,
253
+ contentBase64: content,
254
+ filename,
181
255
  mimetype
182
256
  };
183
257
  }
184
258
  catch (error) {
185
- console.error('[AllegatiService] downloadFile - Errore:', error);
259
+ this.logger.error('[AllegatiService] downloadFile - Errore:', error);
186
260
  if (error instanceof common_1.BadRequestException ||
187
261
  error instanceof common_1.NotFoundException ||
188
262
  error instanceof common_1.InternalServerErrorException) {
@@ -222,7 +296,7 @@ let AllegatiService = class AllegatiService {
222
296
  yield Orm_1.Orm.execute(this.allegatiOptions.databaseOptions, query, [id]);
223
297
  }
224
298
  catch (error) {
225
- console.error('[AllegatiService] deleteFile - Errore:', error);
299
+ this.logger.error('[AllegatiService] deleteFile - Errore:', error);
226
300
  if (error instanceof common_1.BadRequestException ||
227
301
  error instanceof common_1.NotFoundException ||
228
302
  error instanceof common_1.InternalServerErrorException) {
@@ -276,23 +350,10 @@ let AllegatiService = class AllegatiService {
276
350
  if (!results) {
277
351
  throw new common_1.InternalServerErrorException('Errore durante il recupero della lista dei file');
278
352
  }
279
- return results.map((r) => ({
280
- id: r.ID,
281
- filename: r.FILENAME,
282
- mimetype: r.MIMETYPE,
283
- uploadDate: r.UPLOADDATE,
284
- codice: r.CODICE,
285
- tipoCodice: r.TIPOCODICE,
286
- ordine: r.ORDINE,
287
- descrizioneAllegato: r.DESCRIZIONEALLEGATO,
288
- dataInizioValidita: r.DATAINIZIOVALIDITA,
289
- dataFineValidita: r.DATAFINEVALIDITA,
290
- idTipoAllegato: r.IDTIPOALLEGATO,
291
- riferimentoDocumento: r.RIFERIMENTODOCUMENTO
292
- }));
353
+ return results.map((r) => this.toAllegatoDto(r));
293
354
  }
294
355
  catch (error) {
295
- console.error('[AllegatiService] listFiles - Errore:', error);
356
+ this.logger.error('[AllegatiService] listFiles - Errore:', error);
296
357
  if (error instanceof common_1.InternalServerErrorException) {
297
358
  throw error;
298
359
  }
@@ -301,7 +362,7 @@ let AllegatiService = class AllegatiService {
301
362
  });
302
363
  }
303
364
  /**
304
- * Find allegati by any combination of tipcod, codice, docrif, idxtipoall
365
+ * Find allegati by a combination of tipcod, codice, docrif, idxtipoall
305
366
  */
306
367
  findByFields(fields) {
307
368
  return __awaiter(this, void 0, void 0, function* () {
@@ -345,23 +406,10 @@ let AllegatiService = class AllegatiService {
345
406
  if (!results) {
346
407
  throw new common_1.InternalServerErrorException('Errore durante la ricerca degli allegati');
347
408
  }
348
- return results.map((r) => ({
349
- id: r.ID,
350
- filename: r.FILENAME,
351
- mimetype: r.MIMETYPE,
352
- uploadDate: r.UPLOADDATE,
353
- codice: r.CODICE,
354
- tipoCodice: r.TIPOCODICE,
355
- ordine: r.ORDINE,
356
- descrizioneAllegato: r.DESCRIZIONEALLEGATO,
357
- dataInizioValidita: r.DATAINIZIOVALIDITA,
358
- dataFineValidita: r.DATAFINEVALIDITA,
359
- idTipoAllegato: r.IDTIPOALLEGATO,
360
- riferimentoDocumento: r.RIFERIMENTODOCUMENTO
361
- }));
409
+ return results.map((r) => this.toAllegatoDto(r));
362
410
  }
363
411
  catch (error) {
364
- console.error('[AllegatiService] findByFields - Errore:', error);
412
+ this.logger.error('[AllegatiService] findByFields - Errore:', error);
365
413
  throw new common_1.InternalServerErrorException('Errore durante la ricerca degli allegati');
366
414
  }
367
415
  });
@@ -404,7 +452,7 @@ let AllegatiService = class AllegatiService {
404
452
  }
405
453
  }
406
454
  catch (error) {
407
- console.error('[AllegatiService] updateFieldsById - Errore:', error);
455
+ this.logger.error('[AllegatiService] updateFieldsById - Errore:', error);
408
456
  throw error;
409
457
  }
410
458
  });
@@ -414,13 +462,14 @@ let AllegatiService = class AllegatiService {
414
462
  */
415
463
  getOneByFields(fields) {
416
464
  return __awaiter(this, void 0, void 0, function* () {
465
+ var _a;
417
466
  const results = yield this.findByFields(fields);
418
- return results.length > 0 ? results[0] : null;
467
+ return results.length > 0 ? ((_a = results[0]) !== null && _a !== void 0 ? _a : null) : null;
419
468
  });
420
469
  }
421
470
  };
422
471
  exports.AllegatiService = AllegatiService;
423
- exports.AllegatiService = AllegatiService = __decorate([
472
+ exports.AllegatiService = AllegatiService = AllegatiService_1 = __decorate([
424
473
  autobind_1.autobind,
425
474
  (0, common_1.Injectable)(),
426
475
  __param(0, (0, common_1.Inject)('ALLEGATI_OPTIONS')),
@@ -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,EAAE,KAAK,CAAC,CAAC;YAC9E,sGAAsG;QACzG,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,YAAY,CAAC,IAAyB;QAC1C,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,IAAI,4BAAmB,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACjC,MAAM,IAAI,4BAAmB,CAAC,sDAAsD,IAAI,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,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\";\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
+ {"version":3,"file":"AllegatiService.js","sourceRoot":"","sources":["../../../../src/allegati-module/Services/AllegatiService/AllegatiService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwI;AACxI,gDAA6C;AAC7C,4CAAyC;AACzC,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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AAC,CAAC;oBAC/B,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;gBACnC,CAAC;gBACD,IAAI,OAAO,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,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8CAA8C,EAAE,KAAK,CAAC,CAAC;gBACzE,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,CAAC,MAAA,OAAO,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5D,CAAC;KAAA;CAEJ,CAAA;AAjcY,0CAAe;0BAAf,eAAe;IAF3B,mBAAQ;IACR,IAAA,mBAAU,GAAE;IAcI,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;;GAb9B,eAAe,CAic3B","sourcesContent":["import { Inject, Injectable, NotFoundException, BadRequestException, InternalServerErrorException, OnModuleInit } from \"@nestjs/common\";\nimport { autobind } from \"../../../autobind\";\nimport { Logger } from \"../../../Logger\";\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 implements OnModuleInit {\n private readonly logger = new Logger(AllegatiService.name);\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\n /** Verifica la tabella ALLEGATI all'avvio (attesa da Nest, senza promise floating). */\n async onModuleInit(): Promise<void> {\n try {\n await this.ensureTableExists();\n } catch (error) {\n this.logger.error('[AllegatiService] Errore verifica tabella ALLEGATI:', error);\n }\n }\n\n private toAllegatoDto(row: Record<string, unknown>): AllegatoDto {\n const optionalString = (value: unknown): string | undefined => value === undefined || value === null ? undefined : String(value);\n const optionalNumber = (value: unknown): number | undefined => value === undefined || value === null ? undefined : Number(value);\n\n return {\n id: Number(row.ID ?? row.id),\n filename: String(row.FILENAME ?? row.filename ?? ''),\n mimetype: String(row.MIMETYPE ?? row.mimetype ?? ''),\n uploadDate: String(row.UPLOADDATE ?? row.uploadDate ?? ''),\n codice: optionalString(row.CODICE ?? row.codice),\n tipoCodice: optionalString(row.TIPOCODICE ?? row.tipoCodice),\n ordine: optionalString(row.ORDINE ?? row.ordine),\n descrizioneAllegato: optionalString(row.DESCRIZIONEALLEGATO ?? row.descrizioneAllegato),\n dataInizioValidita: optionalString(row.DATAINIZIOVALIDITA ?? row.dataInizioValidita),\n dataFineValidita: optionalString(row.DATAFINEVALIDITA ?? row.dataFineValidita),\n idTipoAllegato: optionalNumber(row.IDTIPOALLEGATO ?? row.idTipoAllegato),\n riferimentoDocumento: optionalString(row.RIFERIMENTODOCUMENTO ?? row.riferimentoDocumento),\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 // Il mimetype dichiarato dal client e falsificabile: verifica i magic byte reali.\n if (!this.hasValidSignature(file)) {\n throw new BadRequestException('Il contenuto del file non corrisponde al tipo dichiarato.');\n }\n }\n\n private hasValidSignature(file: Express.Multer.File): boolean {\n const buffer = file?.buffer;\n if (!buffer || buffer.length < 4) {\n return false;\n }\n\n const startsWith = (...bytes: number[]): boolean => bytes.every((byte, index) => buffer[index] === byte);\n\n switch (file.mimetype) {\n case 'application/pdf':\n return startsWith(0x25, 0x50, 0x44, 0x46);\n case 'image/jpeg':\n return startsWith(0xff, 0xd8, 0xff);\n case 'image/png':\n return startsWith(0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a);\n case 'application/msword':\n case 'application/vnd.ms-excel':\n return startsWith(0xd0, 0xcf, 0x11, 0xe0);\n case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':\n case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':\n // DOCX/XLSX sono archivi ZIP.\n return startsWith(0x50, 0x4b, 0x03, 0x04)\n || startsWith(0x50, 0x4b, 0x05, 0x06)\n || startsWith(0x50, 0x4b, 0x07, 0x08);\n default:\n return false;\n }\n }\n\n private sanitizeFilename(name: unknown): string {\n const raw = typeof name === 'string' ? name : '';\n const base = raw.replace(/\\\\/g, '/').split('/').pop() ?? '';\n const cleaned = base.replace(/[\\u0000-\\u001f\\u007f<>:\"|?*]/g, '_').trim();\n return cleaned.slice(0, 255) || 'allegato';\n }\n\n\n async getAttachmentTypes(): Promise<Array<Record<string, unknown>>> {\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 this.logger.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 this.sanitizeFilename(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 // node-firebird restituisce le righe di INSERT ... RETURNING come array; il fallback\n // copre le versioni/driver che restituiscono un singolo oggetto.\n const inserted = (Array.isArray(result) ? result[0] : result) as Record<string, unknown> | undefined;\n const insertedId = inserted?.IDXALL ?? inserted?.idxall;\n\n if (insertedId === undefined || insertedId === null) {\n throw new InternalServerErrorException('Errore durante il salvataggio del file');\n }\n\n return {\n id: Number(insertedId),\n filename: this.sanitizeFilename(file.originalname),\n };\n } catch (error) {\n this.logger.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 this.logger.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 const content = result?.CONTENT ?? result?.content;\n const filename = result?.FILENAME ?? result?.filename;\n\n if (typeof content !== 'string' || content.length === 0) {\n throw new InternalServerErrorException('Contenuto file non disponibile');\n }\n\n if (typeof filename !== 'string' || filename.length === 0) {\n throw new InternalServerErrorException('Nome file non disponibile');\n }\n\n const mimetype = this.detectMimeType(filename);\n \n return {\n contentBase64: content,\n filename,\n mimetype\n };\n } catch (error) {\n this.logger.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 this.logger.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: unknown[] = [];\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: Record<string, unknown>) => this.toAllegatoDto(r));\n } catch (error) {\n this.logger.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 a 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: unknown[] = [];\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: Record<string, unknown>) => this.toAllegatoDto(r));\n } catch (error) {\n this.logger.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: unknown[] = [];\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 this.logger.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) : null;\n }\n\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { CanActivate, ExecutionContext } from "@nestjs/common";
2
+ import type { AllegatiOptions } from "../AllegatiModule";
3
+ /**
4
+ * Guard opt-in per i controller Allegati.
5
+ *
6
+ * Senza `authorize` configurato nelle `AllegatiOptions` il guard e un no-op, cosi da
7
+ * preservare la retrocompatibilita. Quando configurato, delega la decisione
8
+ * all'applicazione host (tipicamente il controllo di autenticazione/ownership).
9
+ */
10
+ export declare class AllegatiAuthorizationGuard implements CanActivate {
11
+ private readonly options;
12
+ constructor(options: AllegatiOptions);
13
+ canActivate(context: ExecutionContext): Promise<boolean>;
14
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.AllegatiAuthorizationGuard = void 0;
25
+ const common_1 = require("@nestjs/common");
26
+ /**
27
+ * Guard opt-in per i controller Allegati.
28
+ *
29
+ * Senza `authorize` configurato nelle `AllegatiOptions` il guard e un no-op, cosi da
30
+ * preservare la retrocompatibilita. Quando configurato, delega la decisione
31
+ * all'applicazione host (tipicamente il controllo di autenticazione/ownership).
32
+ */
33
+ let AllegatiAuthorizationGuard = class AllegatiAuthorizationGuard {
34
+ constructor(options) {
35
+ this.options = options;
36
+ }
37
+ canActivate(context) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ var _a, _b;
40
+ // Opt-out esplicito: ripristina il comportamento storico (endpoint aperti).
41
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.requireAuthorization) === false) {
42
+ return true;
43
+ }
44
+ const authorize = (_b = this.options) === null || _b === void 0 ? void 0 : _b.authorize;
45
+ if (!authorize) {
46
+ // Secure by default: senza un controllo configurato l'accesso e negato.
47
+ throw new common_1.ForbiddenException({
48
+ code: 'ALLEGATI_AUTHORIZATION_NOT_CONFIGURED',
49
+ message: 'Allegati: nessun controllo di autorizzazione configurato. Definire allegatiOptions.authorize oppure impostare requireAuthorization: false per il comportamento storico.',
50
+ });
51
+ }
52
+ const request = context.switchToHttp().getRequest();
53
+ const allowed = yield authorize(request);
54
+ if (!allowed) {
55
+ throw new common_1.ForbiddenException({
56
+ code: 'ALLEGATI_FORBIDDEN',
57
+ message: 'Operazione non autorizzata.',
58
+ });
59
+ }
60
+ return true;
61
+ });
62
+ }
63
+ };
64
+ exports.AllegatiAuthorizationGuard = AllegatiAuthorizationGuard;
65
+ exports.AllegatiAuthorizationGuard = AllegatiAuthorizationGuard = __decorate([
66
+ (0, common_1.Injectable)(),
67
+ __param(0, (0, common_1.Inject)('ALLEGATI_OPTIONS')),
68
+ __metadata("design:paramtypes", [Object])
69
+ ], AllegatiAuthorizationGuard);
70
+ //# sourceMappingURL=allegatiAuthorizationGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allegatiAuthorizationGuard.js","sourceRoot":"","sources":["../../../src/allegati-module/security/allegatiAuthorizationGuard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAuG;AAIvG;;;;;;GAMG;AAEI,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IACnC,YAAyD,OAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;IAAG,CAAC;IAE/E,WAAW,CAAC,OAAyB;;;YACvC,4EAA4E;YAC5E,IAAI,CAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,oBAAoB,MAAK,KAAK,EAAE,CAAC;gBAC/C,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,MAAM,SAAS,GAAG,MAAA,IAAI,CAAC,OAAO,0CAAE,SAAS,CAAC;YAC1C,IAAI,CAAC,SAAS,EAAE,CAAC;gBACb,wEAAwE;gBACxE,MAAM,IAAI,2BAAkB,CAAC;oBACzB,IAAI,EAAE,uCAAuC;oBAC7C,OAAO,EAAE,yKAAyK;iBACrL,CAAC,CAAC;YACP,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAW,CAAC;YAC7D,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;YACzC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,MAAM,IAAI,2BAAkB,CAAC;oBACzB,IAAI,EAAE,oBAAoB;oBAC1B,OAAO,EAAE,6BAA6B;iBACzC,CAAC,CAAC;YACP,CAAC;YAED,OAAO,IAAI,CAAC;QAChB,CAAC;KAAA;CACJ,CAAA;AA7BY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;IAEI,WAAA,IAAA,eAAM,EAAC,kBAAkB,CAAC,CAAA;;GAD9B,0BAA0B,CA6BtC","sourcesContent":["import { CanActivate, ExecutionContext, ForbiddenException, Inject, Injectable } from \"@nestjs/common\";\nimport type { Request } from \"express\";\nimport type { AllegatiOptions } from \"../AllegatiModule\";\n\n/**\n * Guard opt-in per i controller Allegati.\n *\n * Senza `authorize` configurato nelle `AllegatiOptions` il guard e un no-op, cosi da\n * preservare la retrocompatibilita. Quando configurato, delega la decisione\n * all'applicazione host (tipicamente il controllo di autenticazione/ownership).\n */\n@Injectable()\nexport class AllegatiAuthorizationGuard implements CanActivate {\n constructor(@Inject('ALLEGATI_OPTIONS') private readonly options: AllegatiOptions) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n // Opt-out esplicito: ripristina il comportamento storico (endpoint aperti).\n if (this.options?.requireAuthorization === false) {\n return true;\n }\n\n const authorize = this.options?.authorize;\n if (!authorize) {\n // Secure by default: senza un controllo configurato l'accesso e negato.\n throw new ForbiddenException({\n code: 'ALLEGATI_AUTHORIZATION_NOT_CONFIGURED',\n message: 'Allegati: nessun controllo di autorizzazione configurato. Definire allegatiOptions.authorize oppure impostare requireAuthorization: false per il comportamento storico.',\n });\n }\n\n const request = context.switchToHttp().getRequest<Request>();\n const allowed = await authorize(request);\n if (!allowed) {\n throw new ForbiddenException({\n code: 'ALLEGATI_FORBIDDEN',\n message: 'Operazione non autorizzata.',\n });\n }\n\n return true;\n }\n}\n"]}
@@ -1,3 +1,10 @@
1
- export declare function autobind<T extends {
2
- new (...args: any[]): any;
3
- }>(constructor: T): T;
1
+ type AutobindConstructor = new (...args: never[]) => object;
2
+ /**
3
+ * Class decorator that binds every prototype method to the instance.
4
+ *
5
+ * Uses `Reflect.construct` instead of a class-expression mixin because
6
+ * TypeScript requires mixin constructors to use `any[]`, which this codebase
7
+ * avoids.
8
+ */
9
+ export declare function autobind<T extends AutobindConstructor>(constructor: T): T;
10
+ export {};
package/dist/autobind.js CHANGED
@@ -1,17 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.autobind = autobind;
4
+ /**
5
+ * Class decorator that binds every prototype method to the instance.
6
+ *
7
+ * Uses `Reflect.construct` instead of a class-expression mixin because
8
+ * TypeScript requires mixin constructors to use `any[]`, which this codebase
9
+ * avoids.
10
+ */
4
11
  function autobind(constructor) {
5
- return class extends constructor {
6
- constructor(...args) {
7
- super(...args);
8
- Object.getOwnPropertyNames(constructor.prototype).forEach(key => {
9
- const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, key);
10
- if (descriptor && typeof descriptor.value === 'function' && key !== 'constructor') {
11
- this[key] = this[key].bind(this);
12
+ const boundConstructor = function (...args) {
13
+ const instance = Reflect.construct(constructor, args);
14
+ Object.getOwnPropertyNames(constructor.prototype).forEach(key => {
15
+ const descriptor = Object.getOwnPropertyDescriptor(constructor.prototype, key);
16
+ if (descriptor && typeof descriptor.value === 'function' && key !== 'constructor') {
17
+ const method = instance[key];
18
+ if (typeof method === 'function') {
19
+ instance[key] = method.bind(instance);
12
20
  }
13
- });
14
- }
21
+ }
22
+ });
23
+ return instance;
15
24
  };
25
+ // Mirror `class extends`: the constructor's prototype chain must point at the
26
+ // original class so reflect-metadata (design:paramtypes) stays reachable and
27
+ // NestJS dependency injection keeps working.
28
+ Object.setPrototypeOf(boundConstructor, constructor);
29
+ boundConstructor.prototype = constructor.prototype;
30
+ return boundConstructor;
16
31
  }
17
32
  //# sourceMappingURL=autobind.js.map
@@ -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 {\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"]}
1
+ {"version":3,"file":"autobind.js","sourceRoot":"","sources":["../src/autobind.ts"],"names":[],"mappings":";;AASA,4BAuBC;AA9BD;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAgC,WAAc;IAClE,MAAM,gBAAgB,GAAG,UAAyB,GAAG,IAAe;QAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,CAA4B,CAAC;QAEjF,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC5D,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,WAAW,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YAC/E,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,IAAI,GAAG,KAAK,aAAa,EAAE,CAAC;gBAChF,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;gBAC7B,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;oBAC/B,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAC1C,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IACpB,CAAC,CAAC;IAEF,8EAA8E;IAC9E,6EAA6E;IAC7E,6CAA6C;IAC7C,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;IACrD,gBAAgB,CAAC,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC;IACnD,OAAO,gBAAgC,CAAC;AAC5C,CAAC","sourcesContent":["type AutobindConstructor = new (...args: never[]) => object;\n\n/**\n * Class decorator that binds every prototype method to the instance.\n *\n * Uses `Reflect.construct` instead of a class-expression mixin because\n * TypeScript requires mixin constructors to use `any[]`, which this codebase\n * avoids.\n */\nexport function autobind<T extends AutobindConstructor>(constructor: T): T {\n const boundConstructor = function (this: unknown, ...args: unknown[]): object {\n const instance = Reflect.construct(constructor, args) as Record<string, unknown>;\n\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 const method = instance[key];\n if (typeof method === 'function') {\n instance[key] = method.bind(instance);\n }\n }\n });\n\n return instance;\n };\n\n // Mirror `class extends`: the constructor's prototype chain must point at the\n // original class so reflect-metadata (design:paramtypes) stays reachable and\n // NestJS dependency injection keeps working.\n Object.setPrototypeOf(boundConstructor, constructor);\n boundConstructor.prototype = constructor.prototype;\n return boundConstructor as unknown as T;\n}\n"]}