@nest-omni/core 4.1.3-2 → 4.1.3-20

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 (386) hide show
  1. package/audit/audit.module.d.ts +10 -0
  2. package/audit/audit.module.js +63 -1
  3. package/audit/controllers/audit.controller.d.ts +88 -0
  4. package/audit/controllers/audit.controller.js +74 -0
  5. package/audit/decorators/audit-action.decorator.d.ts +74 -0
  6. package/audit/decorators/audit-action.decorator.js +42 -0
  7. package/audit/decorators/audit-controller.decorator.d.ts +9 -1
  8. package/audit/decorators/audit-controller.decorator.js +11 -2
  9. package/audit/decorators/audit-operation.decorator.d.ts +45 -0
  10. package/audit/decorators/audit-operation.decorator.js +49 -0
  11. package/audit/decorators/entity-audit.decorator.d.ts +85 -1
  12. package/audit/decorators/entity-audit.decorator.js +153 -3
  13. package/audit/decorators/index.d.ts +2 -0
  14. package/audit/decorators/index.js +2 -0
  15. package/audit/dto/audit-log-query.dto.d.ts +3 -0
  16. package/audit/dto/audit-log-query.dto.js +3 -0
  17. package/audit/dto/begin-transaction.dto.d.ts +3 -0
  18. package/audit/dto/begin-transaction.dto.js +3 -0
  19. package/audit/dto/compare-entities.dto.d.ts +3 -0
  20. package/audit/dto/compare-entities.dto.js +3 -0
  21. package/audit/dto/pre-check-restore.dto.d.ts +3 -0
  22. package/audit/dto/pre-check-restore.dto.js +3 -0
  23. package/audit/dto/restore-entity.dto.d.ts +3 -0
  24. package/audit/dto/restore-entity.dto.js +3 -0
  25. package/audit/entities/audit-action-summary.entity.d.ts +23 -0
  26. package/audit/entities/audit-action-summary.entity.js +101 -0
  27. package/audit/entities/entity-audit-log.entity.d.ts +11 -0
  28. package/audit/entities/entity-audit-log.entity.js +57 -2
  29. package/audit/entities/entity-transaction.entity.d.ts +11 -2
  30. package/audit/entities/entity-transaction.entity.js +42 -3
  31. package/audit/entities/index.d.ts +3 -0
  32. package/audit/entities/index.js +3 -0
  33. package/audit/entities/manual-operation-log.entity.d.ts +4 -0
  34. package/audit/entities/manual-operation-log.entity.js +12 -1
  35. package/audit/entities/operation-template.entity.d.ts +4 -0
  36. package/audit/entities/operation-template.entity.js +4 -0
  37. package/audit/enums/audit.enums.d.ts +37 -6
  38. package/audit/enums/audit.enums.js +40 -7
  39. package/audit/index.d.ts +4 -1
  40. package/audit/index.js +34 -1
  41. package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
  42. package/audit/interceptors/audit-action.interceptor.js +215 -0
  43. package/audit/interceptors/audit.interceptor.d.ts +15 -0
  44. package/audit/interceptors/audit.interceptor.js +23 -1
  45. package/audit/interceptors/index.d.ts +1 -0
  46. package/audit/interceptors/index.js +1 -0
  47. package/audit/interfaces/audit.interfaces.d.ts +187 -2
  48. package/audit/services/audit-action.service.d.ts +141 -0
  49. package/audit/services/audit-action.service.js +244 -0
  50. package/audit/services/audit-context.service.d.ts +97 -0
  51. package/audit/services/audit-context.service.js +185 -0
  52. package/audit/services/audit-strategy.service.d.ts +6 -0
  53. package/audit/services/audit-strategy.service.js +13 -0
  54. package/audit/services/entity-audit.service.d.ts +230 -3
  55. package/audit/services/entity-audit.service.js +607 -14
  56. package/audit/services/index.d.ts +3 -0
  57. package/audit/services/index.js +3 -0
  58. package/audit/services/manual-audit-log.service.d.ts +134 -9
  59. package/audit/services/manual-audit-log.service.js +157 -40
  60. package/audit/services/multi-database.service.d.ts +9 -2
  61. package/audit/services/multi-database.service.js +9 -21
  62. package/audit/services/operation-description.service.d.ts +71 -2
  63. package/audit/services/operation-description.service.js +231 -20
  64. package/audit/services/transaction-audit.service.d.ts +30 -0
  65. package/audit/services/transaction-audit.service.js +53 -5
  66. package/audit/subscribers/entity-audit.subscriber.d.ts +19 -0
  67. package/audit/subscribers/entity-audit.subscriber.js +76 -1
  68. package/cache/cache-metrics.service.d.ts +67 -0
  69. package/cache/cache-metrics.service.js +68 -4
  70. package/cache/cache-serialization.service.d.ts +31 -0
  71. package/cache/cache-serialization.service.js +25 -0
  72. package/cache/cache.constants.d.ts +9 -0
  73. package/cache/cache.constants.js +9 -0
  74. package/cache/cache.health.d.ts +26 -0
  75. package/cache/cache.health.js +30 -0
  76. package/cache/cache.module.d.ts +82 -2
  77. package/cache/cache.module.js +76 -5
  78. package/cache/cache.service.d.ts +140 -0
  79. package/cache/cache.service.js +169 -0
  80. package/cache/cache.warmup.service.d.ts +39 -0
  81. package/cache/cache.warmup.service.js +32 -0
  82. package/cache/decorators/cache-evict.decorator.d.ts +47 -0
  83. package/cache/decorators/cache-evict.decorator.js +56 -0
  84. package/cache/decorators/cache-put.decorator.d.ts +34 -0
  85. package/cache/decorators/cache-put.decorator.js +39 -0
  86. package/cache/decorators/cacheable.decorator.d.ts +40 -0
  87. package/cache/decorators/cacheable.decorator.js +55 -0
  88. package/cache/dependencies/callback.dependency.d.ts +33 -0
  89. package/cache/dependencies/callback.dependency.js +39 -1
  90. package/cache/dependencies/chain.dependency.d.ts +28 -0
  91. package/cache/dependencies/chain.dependency.js +34 -0
  92. package/cache/dependencies/db.dependency.d.ts +83 -7
  93. package/cache/dependencies/db.dependency.js +89 -14
  94. package/cache/dependencies/file.dependency.d.ts +32 -0
  95. package/cache/dependencies/file.dependency.js +34 -0
  96. package/cache/dependencies/tag.dependency.d.ts +75 -4
  97. package/cache/dependencies/tag.dependency.js +145 -11
  98. package/cache/dependencies/time.dependency.d.ts +43 -0
  99. package/cache/dependencies/time.dependency.js +43 -0
  100. package/cache/examples/basic-usage.d.ts +15 -0
  101. package/cache/examples/basic-usage.js +62 -8
  102. package/cache/index.js +9 -0
  103. package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
  104. package/cache/interfaces/cache-options.interface.d.ts +89 -0
  105. package/cache/interfaces/cache-options.interface.js +6 -0
  106. package/cache/interfaces/cache-provider.interface.d.ts +78 -0
  107. package/cache/providers/base-cache.provider.d.ts +14 -0
  108. package/cache/providers/base-cache.provider.js +16 -0
  109. package/cache/providers/cls-cache.provider.d.ts +20 -0
  110. package/cache/providers/cls-cache.provider.js +28 -0
  111. package/cache/providers/memory-cache.provider.d.ts +43 -0
  112. package/cache/providers/memory-cache.provider.js +66 -0
  113. package/cache/providers/redis-cache.provider.d.ts +26 -0
  114. package/cache/providers/redis-cache.provider.js +29 -0
  115. package/cache/utils/dependency-manager.util.d.ts +52 -0
  116. package/cache/utils/dependency-manager.util.js +59 -0
  117. package/cache/utils/key-generator.util.d.ts +42 -0
  118. package/cache/utils/key-generator.util.js +53 -1
  119. package/common/abstract.entity.d.ts +14 -0
  120. package/common/abstract.entity.js +14 -0
  121. package/common/boilerplate.polyfill.d.ts +142 -0
  122. package/common/boilerplate.polyfill.js +18 -1
  123. package/common/dto/dto-container.d.ts +16 -0
  124. package/common/dto/dto-container.js +20 -0
  125. package/common/dto/dto-decorators.d.ts +18 -0
  126. package/common/dto/dto-decorators.js +14 -0
  127. package/common/dto/dto-extensions.d.ts +11 -0
  128. package/common/dto/dto-extensions.js +9 -0
  129. package/common/dto/dto-service-accessor.d.ts +17 -0
  130. package/common/dto/dto-service-accessor.js +18 -0
  131. package/common/dto/dto-transformer.d.ts +12 -0
  132. package/common/dto/dto-transformer.js +9 -0
  133. package/common/dto/index.js +2 -0
  134. package/common/examples/paginate-and-map.example.d.ts +6 -0
  135. package/common/examples/paginate-and-map.example.js +26 -0
  136. package/common/utils.d.ts +15 -0
  137. package/common/utils.js +15 -0
  138. package/constants/language-code.js +1 -0
  139. package/decorators/field.decorators.d.ts +1 -1
  140. package/decorators/field.decorators.js +8 -1
  141. package/decorators/property.decorators.js +1 -0
  142. package/decorators/public-route.decorator.js +1 -0
  143. package/decorators/transform.decorators.d.ts +27 -0
  144. package/decorators/transform.decorators.js +29 -0
  145. package/decorators/translate.decorator.js +1 -0
  146. package/decorators/user.decorator.js +1 -0
  147. package/decorators/validator.decorators.d.ts +8 -18
  148. package/decorators/validator.decorators.js +22 -190
  149. package/file-upload/controllers/file-access.controller.d.ts +23 -0
  150. package/file-upload/controllers/file-access.controller.js +128 -0
  151. package/file-upload/decorators/column.decorator.d.ts +151 -0
  152. package/file-upload/decorators/column.decorator.js +273 -0
  153. package/file-upload/decorators/csv-data.decorator.d.ts +30 -0
  154. package/file-upload/decorators/csv-data.decorator.js +85 -0
  155. package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
  156. package/file-upload/decorators/csv-import.decorator.js +24 -0
  157. package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
  158. package/file-upload/decorators/examples/column-mapping.example.js +122 -0
  159. package/file-upload/decorators/excel-data.decorator.d.ts +30 -0
  160. package/file-upload/decorators/excel-data.decorator.js +85 -0
  161. package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
  162. package/file-upload/decorators/file-upload.decorator.js +172 -0
  163. package/file-upload/decorators/index.d.ts +5 -0
  164. package/file-upload/decorators/index.js +38 -0
  165. package/file-upload/decorators/process.decorator.d.ts +40 -0
  166. package/file-upload/decorators/process.decorator.js +52 -0
  167. package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
  168. package/file-upload/decorators/validate-data.decorator.js +39 -0
  169. package/file-upload/dto/create-file.dto.d.ts +24 -0
  170. package/file-upload/dto/create-file.dto.js +112 -0
  171. package/file-upload/dto/find-files.dto.d.ts +15 -0
  172. package/file-upload/dto/find-files.dto.js +76 -0
  173. package/file-upload/dto/index.d.ts +4 -0
  174. package/file-upload/dto/index.js +20 -0
  175. package/file-upload/dto/pagination.dto.d.ts +7 -0
  176. package/file-upload/dto/pagination.dto.js +39 -0
  177. package/file-upload/dto/update-file.dto.d.ts +15 -0
  178. package/file-upload/dto/update-file.dto.js +67 -0
  179. package/file-upload/entities/file-metadata.entity.d.ts +25 -0
  180. package/file-upload/entities/file-metadata.entity.js +76 -0
  181. package/file-upload/entities/file.entity.d.ts +114 -0
  182. package/file-upload/entities/file.entity.js +350 -0
  183. package/file-upload/entities/index.d.ts +2 -0
  184. package/file-upload/entities/index.js +18 -0
  185. package/file-upload/enums/file-type.enum.d.ts +72 -0
  186. package/file-upload/enums/file-type.enum.js +212 -0
  187. package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
  188. package/file-upload/exceptions/file-upload.exception.js +120 -0
  189. package/file-upload/exceptions/index.d.ts +1 -0
  190. package/file-upload/exceptions/index.js +17 -0
  191. package/file-upload/file-upload.module.d.ts +89 -0
  192. package/file-upload/file-upload.module.js +292 -0
  193. package/file-upload/index.d.ts +37 -0
  194. package/file-upload/index.js +77 -0
  195. package/file-upload/interceptors/file-upload.interceptor.d.ts +101 -0
  196. package/file-upload/interceptors/file-upload.interceptor.js +594 -0
  197. package/file-upload/interceptors/index.d.ts +1 -0
  198. package/file-upload/interceptors/index.js +17 -0
  199. package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
  200. package/file-upload/interfaces/custom-file-type.interface.js +2 -0
  201. package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
  202. package/file-upload/interfaces/file-buffer.interface.js +2 -0
  203. package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
  204. package/file-upload/interfaces/file-entity.interface.js +28 -0
  205. package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
  206. package/file-upload/interfaces/file-metadata.interface.js +2 -0
  207. package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
  208. package/file-upload/interfaces/file-processor.interface.js +2 -0
  209. package/file-upload/interfaces/file-upload-options.interface.d.ts +74 -0
  210. package/file-upload/interfaces/file-upload-options.interface.js +5 -0
  211. package/file-upload/interfaces/index.d.ts +7 -0
  212. package/file-upload/interfaces/index.js +24 -0
  213. package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
  214. package/file-upload/interfaces/processor-options.interface.js +2 -0
  215. package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
  216. package/file-upload/interfaces/storage-provider.interface.js +2 -0
  217. package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
  218. package/file-upload/interfaces/upload-options.interface.js +2 -0
  219. package/file-upload/processors/csv.processor.d.ts +98 -0
  220. package/file-upload/processors/csv.processor.js +391 -0
  221. package/file-upload/processors/excel.processor.d.ts +130 -0
  222. package/file-upload/processors/excel.processor.js +547 -0
  223. package/file-upload/processors/image.processor.d.ts +199 -0
  224. package/file-upload/processors/image.processor.js +377 -0
  225. package/file-upload/providers/index.d.ts +2 -0
  226. package/file-upload/providers/index.js +18 -0
  227. package/file-upload/providers/local-storage.provider.d.ts +98 -0
  228. package/file-upload/providers/local-storage.provider.js +484 -0
  229. package/file-upload/providers/s3-storage.provider.d.ts +87 -0
  230. package/file-upload/providers/s3-storage.provider.js +455 -0
  231. package/file-upload/services/file-signature-validator.service.d.ts +118 -0
  232. package/file-upload/services/file-signature-validator.service.js +376 -0
  233. package/file-upload/services/file.service.d.ts +193 -0
  234. package/file-upload/services/file.service.js +638 -0
  235. package/file-upload/services/index.d.ts +4 -0
  236. package/file-upload/services/index.js +20 -0
  237. package/file-upload/services/malicious-file-detector.service.d.ts +300 -0
  238. package/file-upload/services/malicious-file-detector.service.js +1234 -0
  239. package/file-upload/services/mime-registry.service.d.ts +47 -0
  240. package/file-upload/services/mime-registry.service.js +167 -0
  241. package/file-upload/utils/checksum.util.d.ts +28 -0
  242. package/file-upload/utils/checksum.util.js +65 -0
  243. package/file-upload/utils/dynamic-import.util.d.ts +54 -0
  244. package/file-upload/utils/dynamic-import.util.js +156 -0
  245. package/file-upload/utils/filename.util.d.ts +59 -0
  246. package/file-upload/utils/filename.util.js +184 -0
  247. package/file-upload/utils/filepath.util.d.ts +70 -0
  248. package/file-upload/utils/filepath.util.js +152 -0
  249. package/file-upload/utils/index.d.ts +4 -0
  250. package/file-upload/utils/index.js +20 -0
  251. package/filters/constraint-errors.js +1 -0
  252. package/helpers/common.helper.d.ts +13 -0
  253. package/helpers/common.helper.js +13 -0
  254. package/http-client/config/http-client.config.d.ts +20 -0
  255. package/http-client/config/http-client.config.js +48 -21
  256. package/http-client/decorators/http-client.decorators.d.ts +55 -14
  257. package/http-client/decorators/http-client.decorators.js +154 -78
  258. package/http-client/entities/http-log.entity.d.ts +217 -8
  259. package/http-client/entities/http-log.entity.js +7 -22
  260. package/http-client/errors/http-client.errors.d.ts +57 -0
  261. package/http-client/errors/http-client.errors.js +58 -0
  262. package/http-client/examples/advanced-usage.example.d.ts +40 -0
  263. package/http-client/examples/advanced-usage.example.js +53 -61
  264. package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
  265. package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
  266. package/http-client/examples/basic-usage.example.d.ts +60 -0
  267. package/http-client/examples/basic-usage.example.js +60 -0
  268. package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
  269. package/http-client/examples/multi-api-configuration.example.js +76 -5
  270. package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
  271. package/http-client/examples/proxy-from-environment.example.js +409 -0
  272. package/http-client/http-client.module.d.ts +48 -2
  273. package/http-client/http-client.module.js +147 -68
  274. package/http-client/index.d.ts +1 -1
  275. package/http-client/index.js +8 -0
  276. package/http-client/interfaces/api-client-config.interface.d.ts +80 -45
  277. package/http-client/interfaces/api-client-config.interface.js +3 -0
  278. package/http-client/interfaces/http-client-config.interface.d.ts +109 -52
  279. package/http-client/services/api-client-registry.service.d.ts +50 -11
  280. package/http-client/services/api-client-registry.service.js +90 -250
  281. package/http-client/services/circuit-breaker.service.d.ts +115 -2
  282. package/http-client/services/circuit-breaker.service.js +237 -7
  283. package/http-client/services/http-client.service.d.ts +124 -14
  284. package/http-client/services/http-client.service.js +437 -148
  285. package/http-client/services/http-log-query.service.d.ts +83 -0
  286. package/http-client/services/http-log-query.service.js +121 -13
  287. package/http-client/services/http-replay.service.d.ts +101 -0
  288. package/http-client/services/http-replay.service.js +86 -0
  289. package/http-client/services/index.d.ts +0 -1
  290. package/http-client/services/index.js +0 -1
  291. package/http-client/services/log-cleanup.service.d.ts +63 -0
  292. package/http-client/services/log-cleanup.service.js +54 -2
  293. package/http-client/services/logging.service.d.ts +116 -7
  294. package/http-client/services/logging.service.js +349 -86
  295. package/http-client/utils/call-stack-extractor.util.d.ts +63 -0
  296. package/http-client/utils/call-stack-extractor.util.js +83 -0
  297. package/http-client/utils/context-extractor.util.d.ts +49 -0
  298. package/http-client/utils/context-extractor.util.js +52 -0
  299. package/http-client/utils/curl-generator.util.d.ts +21 -0
  300. package/http-client/utils/curl-generator.util.js +44 -3
  301. package/http-client/utils/index.d.ts +1 -0
  302. package/http-client/utils/index.js +1 -0
  303. package/http-client/utils/proxy-environment.util.d.ts +42 -0
  304. package/http-client/utils/proxy-environment.util.js +148 -0
  305. package/http-client/utils/request-id.util.d.ts +18 -0
  306. package/http-client/utils/request-id.util.js +20 -0
  307. package/http-client/utils/retry-recorder.util.d.ts +42 -0
  308. package/http-client/utils/retry-recorder.util.js +44 -0
  309. package/http-client/utils/security-validator.util.d.ts +118 -0
  310. package/http-client/utils/security-validator.util.js +352 -0
  311. package/index.d.ts +3 -1
  312. package/index.js +12 -1
  313. package/interceptors/translation-interceptor.service.js +5 -0
  314. package/package.json +11 -7
  315. package/providers/context.provider.js +2 -0
  316. package/providers/generator.provider.d.ts +4 -0
  317. package/providers/generator.provider.js +4 -0
  318. package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
  319. package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
  320. package/redis-lock/examples/lock-strategy.examples.d.ts +89 -0
  321. package/redis-lock/examples/lock-strategy.examples.js +130 -15
  322. package/redis-lock/index.d.ts +2 -0
  323. package/redis-lock/index.js +8 -1
  324. package/redis-lock/lock-heartbeat.service.d.ts +80 -0
  325. package/redis-lock/lock-heartbeat.service.js +232 -0
  326. package/redis-lock/redis-lock.decorator.d.ts +101 -0
  327. package/redis-lock/redis-lock.decorator.js +120 -0
  328. package/redis-lock/redis-lock.module.d.ts +66 -0
  329. package/redis-lock/redis-lock.module.js +175 -70
  330. package/redis-lock/redis-lock.service.d.ts +282 -0
  331. package/redis-lock/redis-lock.service.js +343 -20
  332. package/setup/bootstrap.setup.d.ts +1 -0
  333. package/setup/bootstrap.setup.js +21 -0
  334. package/setup/index.d.ts +1 -0
  335. package/setup/index.js +1 -0
  336. package/setup/mode.setup.d.ts +44 -0
  337. package/setup/mode.setup.js +44 -0
  338. package/setup/run-in-mode.decorator.d.ts +56 -0
  339. package/setup/run-in-mode.decorator.js +92 -0
  340. package/setup/schedule.decorator.d.ts +227 -0
  341. package/setup/schedule.decorator.js +240 -12
  342. package/setup/worker.decorator.d.ts +86 -0
  343. package/setup/worker.decorator.js +97 -0
  344. package/shared/index.d.ts +1 -1
  345. package/shared/index.js +1 -1
  346. package/shared/{serviceRegistryModule.js → service-registry.module.js} +19 -17
  347. package/shared/services/api-config.service.d.ts +3 -0
  348. package/shared/services/api-config.service.js +21 -9
  349. package/shared/services/index.d.ts +0 -1
  350. package/shared/services/index.js +0 -1
  351. package/validator-json/decorators.d.ts +17 -0
  352. package/validator-json/decorators.js +17 -2
  353. package/validator-json/default.d.ts +6 -0
  354. package/validator-json/default.js +30 -2
  355. package/validator-json/defaultConverters.js +1 -0
  356. package/validator-json/options.d.ts +23 -0
  357. package/validators/common-validators.d.ts +143 -0
  358. package/validators/common-validators.js +249 -0
  359. package/validators/custom-validate.examples.d.ts +23 -0
  360. package/validators/custom-validate.examples.js +78 -6
  361. package/validators/custom-validate.validator.d.ts +108 -0
  362. package/validators/custom-validate.validator.js +85 -0
  363. package/validators/file-mimetype.validator.d.ts +0 -2
  364. package/validators/file-mimetype.validator.js +4 -6
  365. package/validators/index.d.ts +1 -0
  366. package/validators/index.js +1 -0
  367. package/validators/is-exists.validator.d.ts +26 -6
  368. package/validators/is-exists.validator.js +30 -7
  369. package/validators/is-unique.validator.d.ts +33 -7
  370. package/validators/is-unique.validator.js +59 -17
  371. package/validators/skip-empty.validator.d.ts +5 -0
  372. package/validators/skip-empty.validator.js +5 -0
  373. package/vault/interfaces/vault-options.interface.d.ts +9 -0
  374. package/vault/vault-config.loader.d.ts +30 -0
  375. package/vault/vault-config.loader.js +48 -1
  376. package/vault/vault-config.service.d.ts +53 -0
  377. package/vault/vault-config.service.js +57 -0
  378. package/vault/vault.module.d.ts +4 -0
  379. package/vault/vault.module.js +4 -0
  380. package/decorators/examples/validation-decorators.example.d.ts +0 -69
  381. package/decorators/examples/validation-decorators.example.js +0 -331
  382. package/http-client/services/cache.service.d.ts +0 -24
  383. package/http-client/services/cache.service.js +0 -264
  384. package/shared/services/validator.service.d.ts +0 -3
  385. package/shared/services/validator.service.js +0 -20
  386. /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
@@ -32,33 +32,50 @@ const audit_context_service_1 = require("./audit-context.service");
32
32
  const audit_strategy_service_1 = require("./audit-strategy.service");
33
33
  const multi_database_service_1 = require("./multi-database.service");
34
34
  const dto_1 = require("../../common/dto");
35
+ const entity_audit_decorator_1 = require("../decorators/entity-audit.decorator");
36
+ const transaction_1 = require("@nest-omni/transaction");
37
+ /**
38
+ * 实体审计服务
39
+ */
35
40
  let EntityAuditService = class EntityAuditService {
36
- constructor(auditLogRepository, transactionRepository, entityManager, contextService, multiDbService, auditStrategy = new audit_strategy_service_1.DefaultAuditStrategy(), config, auditConnectionName) {
41
+ constructor(auditLogRepository, transactionRepository, manualOperationRepository, entityManager, contextService, multiDbService, auditStrategy = new audit_strategy_service_1.DefaultAuditStrategy(), config, auditConnectionName, actionSummaryRepository) {
37
42
  this.auditLogRepository = auditLogRepository;
38
43
  this.transactionRepository = transactionRepository;
44
+ this.manualOperationRepository = manualOperationRepository;
39
45
  this.entityManager = entityManager;
40
46
  this.contextService = contextService;
41
47
  this.multiDbService = multiDbService;
42
48
  this.auditStrategy = auditStrategy;
43
49
  this.config = config;
50
+ this.actionSummaryRepository = actionSummaryRepository;
44
51
  this.auditConnectionName = auditConnectionName || 'default';
45
52
  }
53
+ /**
54
+ * 记录实体变更
55
+ */
46
56
  logEntityChange(entityType_1, entityId_1, operation_1, oldValue_1, newValue_1) {
47
57
  return __awaiter(this, arguments, void 0, function* (entityType, entityId, operation, oldValue, newValue, metadata = {}) {
48
58
  var _a, _b;
59
+ // 检查是否应该记录
49
60
  if (!this.auditStrategy.shouldRecord(entityType, operation)) {
50
61
  return null;
51
62
  }
63
+ // 获取记录策略
52
64
  const recordStrategy = this.auditStrategy.getRecordStrategy(entityType, operation);
53
65
  if (recordStrategy === enums_1.RecordStrategy.DISABLED) {
54
66
  return null;
55
67
  }
68
+ // 获取字段过滤器
56
69
  const fieldFilter = this.auditStrategy.getFieldFilter(entityType);
70
+ // 过滤和脱敏字段
57
71
  const filteredOldValue = this.filterAndMaskFields(oldValue, fieldFilter);
58
72
  const filteredNewValue = this.filterAndMaskFields(newValue, fieldFilter);
73
+ // 计算变更字段
59
74
  const changedFields = this.calculateChangedFields(filteredOldValue, filteredNewValue);
60
75
  const changedFieldPaths = this.calculateChangedFieldPaths(filteredOldValue, filteredNewValue);
76
+ // 获取上下文信息
61
77
  const context = yield this.contextService.getCurrentContext();
78
+ // 创建审计日志
62
79
  const auditLog = this.auditLogRepository.create({
63
80
  entityType,
64
81
  entityId,
@@ -76,18 +93,28 @@ let EntityAuditService = class EntityAuditService {
76
93
  hashChain: ((_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.security) === null || _b === void 0 ? void 0 : _b.hashChainEnabled)
77
94
  ? yield this.generateHashChain(entityType, entityId, filteredNewValue)
78
95
  : undefined,
96
+ // 新增:审计动作关联字段
97
+ auditActionId: metadata.auditActionId,
98
+ auditActionName: metadata.auditActionName,
99
+ sequenceInAction: metadata.sequenceInAction || 0,
79
100
  });
101
+ // 保存变更日志
80
102
  const savedLog = yield this.auditLogRepository.save(auditLog);
81
103
  return savedLog;
82
104
  });
83
105
  }
106
+ /**
107
+ * 查询审计日志
108
+ */
84
109
  getAuditLogs(query) {
85
110
  return __awaiter(this, void 0, void 0, function* () {
111
+ // 应用默认值
86
112
  const page = query.page || 1;
87
113
  const limit = query.limit || 20;
88
114
  const sortBy = query.sortBy || 'createdAt';
89
115
  const sortOrder = query.sortOrder || 'DESC';
90
116
  const queryBuilder = this.auditLogRepository.createQueryBuilder('log');
117
+ // 应用过滤条件
91
118
  if (query.entityType) {
92
119
  queryBuilder.andWhere('log.entityType = :entityType', { entityType: query.entityType });
93
120
  }
@@ -111,7 +138,9 @@ let EntityAuditService = class EntityAuditService {
111
138
  search: `%${query.search}%`,
112
139
  });
113
140
  }
141
+ // 应用排序
114
142
  queryBuilder.orderBy(`log.${sortBy}`, sortOrder);
143
+ // 应用分页
115
144
  const skip = (page - 1) * limit;
116
145
  queryBuilder.skip(skip).take(limit);
117
146
  const [data, total] = yield queryBuilder.getManyAndCount();
@@ -124,6 +153,9 @@ let EntityAuditService = class EntityAuditService {
124
153
  return new dto_1.PageDto(data, pageMetaDto);
125
154
  });
126
155
  }
156
+ /**
157
+ * 比较实体差异
158
+ */
127
159
  compareEntities(entityType, entityId, fromLogId, toLogId) {
128
160
  return __awaiter(this, void 0, void 0, function* () {
129
161
  let fromData = {};
@@ -137,6 +169,7 @@ let EntityAuditService = class EntityAuditService {
137
169
  toData = (toLog === null || toLog === void 0 ? void 0 : toLog.newValue) || {};
138
170
  }
139
171
  else {
172
+ // 获取最新的日志
140
173
  const latestLog = yield this.auditLogRepository.findOne({
141
174
  where: { entityType, entityId },
142
175
  order: { createdAt: 'DESC' },
@@ -146,6 +179,9 @@ let EntityAuditService = class EntityAuditService {
146
179
  return this.compareSnapshotData(fromData, toData);
147
180
  });
148
181
  }
182
+ /**
183
+ * 预检查恢复操作
184
+ */
149
185
  preCheckRestore(entityType, entityId, auditLogId) {
150
186
  return __awaiter(this, void 0, void 0, function* () {
151
187
  const auditLog = yield this.auditLogRepository.findOne({ where: { id: auditLogId } });
@@ -163,6 +199,7 @@ let EntityAuditService = class EntityAuditService {
163
199
  warnings: [],
164
200
  };
165
201
  }
202
+ // 获取当前实体状态
166
203
  const repository = this.entityManager.getRepository(entityType);
167
204
  const currentEntity = yield repository.findOne({ where: { id: entityId } });
168
205
  if (!currentEntity) {
@@ -179,6 +216,7 @@ let EntityAuditService = class EntityAuditService {
179
216
  warnings: [],
180
217
  };
181
218
  }
219
+ // 检查冲突
182
220
  const conflicts = this.detectConflicts(currentEntity, auditLog.oldValue);
183
221
  return {
184
222
  canRestore: conflicts.length === 0,
@@ -187,6 +225,9 @@ let EntityAuditService = class EntityAuditService {
187
225
  };
188
226
  });
189
227
  }
228
+ /**
229
+ * 恢复实体
230
+ */
190
231
  restoreEntity(entityType_1, entityId_1, auditLogId_1) {
191
232
  return __awaiter(this, arguments, void 0, function* (entityType, entityId, auditLogId, options = {}) {
192
233
  const auditLog = yield this.auditLogRepository.findOne({ where: { id: auditLogId } });
@@ -196,6 +237,7 @@ let EntityAuditService = class EntityAuditService {
196
237
  message: '审计日志不存在',
197
238
  };
198
239
  }
240
+ // 预检查
199
241
  const preCheckResult = yield this.preCheckRestore(entityType, entityId, auditLogId);
200
242
  if (!preCheckResult.canRestore && !options.force) {
201
243
  return {
@@ -205,10 +247,13 @@ let EntityAuditService = class EntityAuditService {
205
247
  };
206
248
  }
207
249
  try {
250
+ // 获取指定的数据库连接
208
251
  const connectionName = options.connectionName || 'default';
209
- const dataSource = yield this.multiDbService.getDataSource(connectionName);
252
+ const dataSource = (0, transaction_1.getDataSource)(connectionName);
210
253
  const repository = dataSource.getRepository(entityType);
254
+ // 恢复实体
211
255
  const restoreData = Object.assign({}, auditLog.oldValue);
256
+ // 应用字段过滤
212
257
  if (options.includeFields && options.includeFields.length > 0) {
213
258
  Object.keys(restoreData).forEach((key) => {
214
259
  if (!options.includeFields.includes(key)) {
@@ -221,8 +266,10 @@ let EntityAuditService = class EntityAuditService {
221
266
  delete restoreData[field];
222
267
  });
223
268
  }
269
+ // 执行恢复
224
270
  if (!options.dryRun) {
225
271
  yield repository.update({ id: entityId }, restoreData);
272
+ // 记录恢复操作
226
273
  yield this.logEntityChange(entityType, entityId, enums_1.AuditOperation.RESTORE, auditLog.newValue, restoreData);
227
274
  }
228
275
  return {
@@ -239,9 +286,14 @@ let EntityAuditService = class EntityAuditService {
239
286
  }
240
287
  });
241
288
  }
289
+ /**
290
+ * 计算变更字段
291
+ */
242
292
  calculateChangedFields(oldValue, newValue) {
243
293
  const changedFields = [];
294
+ // 获取所有字段
244
295
  const allFields = new Set([...Object.keys(oldValue || {}), ...Object.keys(newValue || {})]);
296
+ // 比较每个字段
245
297
  for (const field of allFields) {
246
298
  const oldVal = oldValue === null || oldValue === void 0 ? void 0 : oldValue[field];
247
299
  const newVal = newValue === null || newValue === void 0 ? void 0 : newValue[field];
@@ -251,14 +303,22 @@ let EntityAuditService = class EntityAuditService {
251
303
  }
252
304
  return changedFields;
253
305
  }
306
+ /**
307
+ * 计算变更字段路径
308
+ */
254
309
  calculateChangedFieldPaths(oldValue, newValue) {
255
310
  const changedPaths = [];
311
+ // 使用深度比较获取变更路径
256
312
  const diff = this.deepDiff(oldValue, newValue);
313
+ // 提取路径
257
314
  for (const change of diff) {
258
315
  changedPaths.push(change.path.join('.'));
259
316
  }
260
317
  return changedPaths;
261
318
  }
319
+ /**
320
+ * 深度比较对象
321
+ */
262
322
  deepEqual(a, b) {
263
323
  if (a === b)
264
324
  return true;
@@ -282,13 +342,18 @@ let EntityAuditService = class EntityAuditService {
282
342
  }
283
343
  return true;
284
344
  }
285
- deepDiff(oldObj, newObj, path = []) {
345
+ /**
346
+ * 深度差异比较
347
+ */
348
+ deepDiff(oldObj, newObj, path = [], visited = new WeakSet()) {
286
349
  var _a;
287
350
  const changes = [];
288
351
  const maxDepth = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.maxDiffDepth) || 5;
352
+ // 防止过深
289
353
  if (path.length > maxDepth) {
290
354
  return changes;
291
355
  }
356
+ // 处理基本类型
292
357
  if (typeof oldObj !== 'object' || oldObj === null) {
293
358
  if (oldObj !== newObj) {
294
359
  changes.push({
@@ -300,6 +365,20 @@ let EntityAuditService = class EntityAuditService {
300
365
  }
301
366
  return changes;
302
367
  }
368
+ // 检测循环引用
369
+ if (visited.has(oldObj)) {
370
+ // 检测到循环引用,停止递归
371
+ return changes;
372
+ }
373
+ visited.add(oldObj);
374
+ // 如果newObj也是对象,也加入访问集合
375
+ if (typeof newObj === 'object' && newObj !== null) {
376
+ if (visited.has(newObj)) {
377
+ return changes;
378
+ }
379
+ visited.add(newObj);
380
+ }
381
+ // 处理数组
303
382
  if (Array.isArray(oldObj)) {
304
383
  if (!Array.isArray(newObj)) {
305
384
  changes.push({
@@ -320,10 +399,11 @@ let EntityAuditService = class EntityAuditService {
320
399
  return changes;
321
400
  }
322
401
  for (let i = 0; i < oldObj.length; i++) {
323
- changes.push(...this.deepDiff(oldObj[i], newObj[i], [...path, i.toString()]));
402
+ changes.push(...this.deepDiff(oldObj[i], newObj[i], [...path, i.toString()], visited));
324
403
  }
325
404
  return changes;
326
405
  }
406
+ // 处理对象
327
407
  const allKeys = new Set([...Object.keys(oldObj), ...Object.keys(newObj)]);
328
408
  for (const key of allKeys) {
329
409
  const oldVal = oldObj[key];
@@ -345,11 +425,14 @@ let EntityAuditService = class EntityAuditService {
345
425
  });
346
426
  }
347
427
  else {
348
- changes.push(...this.deepDiff(oldVal, newVal, [...path, key]));
428
+ changes.push(...this.deepDiff(oldVal, newVal, [...path, key], visited));
349
429
  }
350
430
  }
351
431
  return changes;
352
432
  }
433
+ /**
434
+ * 比较快照数据
435
+ */
353
436
  compareSnapshotData(fromData, toData) {
354
437
  const changes = this.deepDiff(fromData, toData);
355
438
  return {
@@ -361,6 +444,9 @@ let EntityAuditService = class EntityAuditService {
361
444
  },
362
445
  };
363
446
  }
447
+ /**
448
+ * 过滤和脱敏字段
449
+ */
364
450
  filterAndMaskFields(data, fieldFilter, path = []) {
365
451
  if (typeof data !== 'object' || data === null) {
366
452
  return data;
@@ -368,14 +454,17 @@ let EntityAuditService = class EntityAuditService {
368
454
  const result = {};
369
455
  for (const [key, value] of Object.entries(data)) {
370
456
  const currentPath = [...path, key];
457
+ // 检查是否应该包含此字段
371
458
  if (!fieldFilter.shouldIncludeField(key, currentPath)) {
372
459
  continue;
373
460
  }
461
+ // 检查是否应该脱敏此字段
374
462
  if (fieldFilter.shouldMaskField(key, currentPath)) {
375
463
  const maskingStrategy = fieldFilter.getMaskingStrategy(key, currentPath);
376
464
  result[key] = this.applyMasking(value, maskingStrategy);
377
465
  }
378
466
  else if (typeof value === 'object' && value !== null) {
467
+ // 递归处理嵌套对象
379
468
  result[key] = this.filterAndMaskFields(value, fieldFilter, currentPath);
380
469
  }
381
470
  else {
@@ -384,6 +473,9 @@ let EntityAuditService = class EntityAuditService {
384
473
  }
385
474
  return result;
386
475
  }
476
+ /**
477
+ * 应用脱敏策略
478
+ */
387
479
  applyMasking(value, strategy) {
388
480
  if (value == null)
389
481
  return value;
@@ -400,14 +492,23 @@ let EntityAuditService = class EntityAuditService {
400
492
  return '***MASKED***';
401
493
  }
402
494
  }
495
+ /**
496
+ * 哈希值
497
+ */
403
498
  hashValue(value) {
404
499
  const strValue = String(value);
405
500
  return (0, crypto_1.createHash)('sha256').update(strValue).digest('hex');
406
501
  }
502
+ /**
503
+ * 掩码值
504
+ */
407
505
  maskValue(value) {
408
506
  const strValue = String(value);
409
507
  return '*'.repeat(strValue.length);
410
508
  }
509
+ /**
510
+ * 部分掩码值
511
+ */
411
512
  partialMaskValue(value) {
412
513
  const strValue = String(value);
413
514
  if (strValue.length <= 4) {
@@ -417,14 +518,19 @@ let EntityAuditService = class EntityAuditService {
417
518
  '*'.repeat(strValue.length - 4) +
418
519
  strValue.substring(strValue.length - 2));
419
520
  }
521
+ /**
522
+ * 生成哈希链
523
+ */
420
524
  generateHashChain(entityType, entityId, data) {
421
525
  return __awaiter(this, void 0, void 0, function* () {
422
526
  var _a, _b, _c;
527
+ // 获取上一个审计记录的哈希
423
528
  const lastLog = yield this.auditLogRepository.findOne({
424
529
  where: { entityType, entityId },
425
530
  order: { createdAt: 'DESC' },
426
531
  });
427
532
  const previousHash = ((_a = lastLog === null || lastLog === void 0 ? void 0 : lastLog.hashChain) === null || _a === void 0 ? void 0 : _a.currentHash) || '';
533
+ // 计算当前数据的哈希
428
534
  const currentData = JSON.stringify(data);
429
535
  const hashAlgorithm = ((_c = (_b = this.config) === null || _b === void 0 ? void 0 : _b.security) === null || _c === void 0 ? void 0 : _c.hashAlgorithm) || 'sha256';
430
536
  const currentHash = (0, crypto_1.createHash)(hashAlgorithm).update(currentData + previousHash).digest('hex');
@@ -435,7 +541,16 @@ let EntityAuditService = class EntityAuditService {
435
541
  };
436
542
  });
437
543
  }
438
- generateDescription(operation, entityType, entityId, changedFields) {
544
+ /**
545
+ * 生成描述(支持多语言)
546
+ * @param operation 操作类型
547
+ * @param entityType 实体类型
548
+ * @param entityId 实体ID
549
+ * @param changedFields 变更字段列表
550
+ * @param language 语言(默认中文)
551
+ * @param entityClass 实体类(可选,用于获取实体标签)
552
+ */
553
+ generateDescription(operation, entityType, entityId, changedFields, language = 'zh', entityClass) {
439
554
  const operationText = {
440
555
  [enums_1.AuditOperation.CREATE]: '创建',
441
556
  [enums_1.AuditOperation.UPDATE]: '更新',
@@ -443,11 +558,36 @@ let EntityAuditService = class EntityAuditService {
443
558
  [enums_1.AuditOperation.RESTORE]: '恢复',
444
559
  };
445
560
  const text = operationText[operation] || operation;
561
+ // 尝试获取实体的多语言标签
562
+ let entityLabel = entityType;
563
+ if (entityClass) {
564
+ try {
565
+ entityLabel = (0, entity_audit_decorator_1.getEntityLabel)(entityClass, language);
566
+ }
567
+ catch (error) {
568
+ // 忽略错误,使用默认的 entityType
569
+ }
570
+ }
446
571
  if (operation === enums_1.AuditOperation.UPDATE && changedFields.length > 0) {
447
- return `${text} ${entityType}(${entityId}), 变更字段: ${changedFields.join(', ')}`;
572
+ // 对于更新操作,显示哪些字段发生了变化
573
+ const fieldLabels = changedFields.map(field => {
574
+ if (entityClass) {
575
+ try {
576
+ return (0, entity_audit_decorator_1.getFieldLabel)(entityClass, field, language);
577
+ }
578
+ catch (error) {
579
+ return field;
580
+ }
581
+ }
582
+ return field;
583
+ });
584
+ return `${text}${entityLabel}(${entityId}), 变更字段: ${fieldLabels.join('、')}`;
448
585
  }
449
- return `${text} ${entityType}(${entityId})`;
586
+ return `${text}${entityLabel}(${entityId})`;
450
587
  }
588
+ /**
589
+ * 检测冲突
590
+ */
451
591
  detectConflicts(currentEntity, targetValue) {
452
592
  const conflicts = [];
453
593
  for (const [key, targetVal] of Object.entries(targetValue)) {
@@ -463,22 +603,475 @@ let EntityAuditService = class EntityAuditService {
463
603
  }
464
604
  return conflicts;
465
605
  }
606
+ // ========== 新增方法:支持模板和手动操作 ==========
607
+ /**
608
+ * 增强的记录实体变更(支持模板和结构化变更详情)
609
+ * @param data 审计数据
610
+ * @returns 审计日志实体
611
+ */
612
+ logEntityChangeWithTemplate(data) {
613
+ return __awaiter(this, void 0, void 0, function* () {
614
+ var _a, _b, _c, _d, _e, _f, _g;
615
+ // 检查是否应该记录
616
+ if (!this.auditStrategy.shouldRecord(data.entityType, data.operation)) {
617
+ return null;
618
+ }
619
+ // 获取记录策略
620
+ const recordStrategy = this.auditStrategy.getRecordStrategy(data.entityType, data.operation);
621
+ if (recordStrategy === enums_1.RecordStrategy.DISABLED) {
622
+ return null;
623
+ }
624
+ // 获取字段过滤器
625
+ const fieldFilter = this.auditStrategy.getFieldFilter(data.entityType);
626
+ // 过滤和脱敏字段
627
+ const filteredOldValue = this.filterAndMaskFields(data.oldValue || {}, fieldFilter);
628
+ const filteredNewValue = this.filterAndMaskFields(data.newValue || {}, fieldFilter);
629
+ // 计算变更字段
630
+ const changedFields = data.changedFields || this.calculateChangedFields(filteredOldValue, filteredNewValue);
631
+ const changedFieldPaths = this.calculateChangedFieldPaths(filteredOldValue, filteredNewValue);
632
+ // 获取上下文信息
633
+ const context = yield this.contextService.getCurrentContext();
634
+ // 如果没有提供操作模板键,使用默认模板
635
+ const operationTemplateKey = data.operationTemplateKey || `${data.entityType}.${data.operation}`;
636
+ // 如果没有提供描述参数,使用实体数据
637
+ const descriptionParams = data.descriptionParams || Object.assign(Object.assign(Object.assign({}, filteredOldValue), filteredNewValue), { changedFields, changedFieldsCount: changedFields.length });
638
+ // 创建审计日志
639
+ const auditLog = this.auditLogRepository.create({
640
+ entityType: data.entityType,
641
+ entityId: data.entityId,
642
+ operation: data.operation,
643
+ oldValue: filteredOldValue,
644
+ newValue: filteredNewValue,
645
+ changedFields,
646
+ changedFieldPaths: changedFieldPaths.join(','),
647
+ userId: context.userId || ((_a = data.metadata) === null || _a === void 0 ? void 0 : _a.userId),
648
+ username: context.username || ((_b = data.metadata) === null || _b === void 0 ? void 0 : _b.username),
649
+ requestId: context.requestId || ((_c = data.metadata) === null || _c === void 0 ? void 0 : _c.requestId),
650
+ requestIp: context.requestIp || ((_d = data.metadata) === null || _d === void 0 ? void 0 : _d.requestIp),
651
+ userAgent: context.userAgent || ((_e = data.metadata) === null || _e === void 0 ? void 0 : _e.userAgent),
652
+ description: this.generateDescription(data.operation, data.entityType, data.entityId, changedFields),
653
+ hashChain: ((_g = (_f = this.config) === null || _f === void 0 ? void 0 : _f.security) === null || _g === void 0 ? void 0 : _g.hashChainEnabled)
654
+ ? yield this.generateHashChain(data.entityType, data.entityId, filteredNewValue)
655
+ : undefined,
656
+ // 新增字段
657
+ operationTemplateKey,
658
+ descriptionParams,
659
+ changeDetails: data.changeDetails,
660
+ rollbackActions: data.rollbackActions,
661
+ });
662
+ // 保存变更日志
663
+ const savedLog = yield this.auditLogRepository.save(auditLog);
664
+ return savedLog;
665
+ });
666
+ }
667
+ /**
668
+ * 记录手动操作
669
+ * @param data 手动操作数据
670
+ * @returns 手动操作日志实体
671
+ */
672
+ logManualOperation(data) {
673
+ return __awaiter(this, void 0, void 0, function* () {
674
+ // 获取上下文信息
675
+ const context = yield this.contextService.getCurrentContext();
676
+ const manualLog = this.manualOperationRepository.create({
677
+ transactionId: data.transactionId,
678
+ operationTemplateKey: data.operationTemplateKey,
679
+ descriptionParams: data.descriptionParams,
680
+ userId: data.userId || context.userId,
681
+ username: data.username || context.username,
682
+ requestIp: data.requestIp || context.requestIp,
683
+ rollbackActions: data.rollbackActions || [],
684
+ });
685
+ return yield this.manualOperationRepository.save(manualLog);
686
+ });
687
+ }
688
+ /**
689
+ * 在事务中执行操作
690
+ * @param fn 执行函数
691
+ * @param options 事务选项
692
+ * @returns 执���结果
693
+ */
694
+ withTransaction(fn, options) {
695
+ return __awaiter(this, void 0, void 0, function* () {
696
+ var _a;
697
+ // 获取上下文信息
698
+ const context = yield this.contextService.getCurrentContext();
699
+ // 创建事务
700
+ const transaction = this.transactionRepository.create({
701
+ description: ((_a = options === null || options === void 0 ? void 0 : options.descriptionParams) === null || _a === void 0 ? void 0 : _a.description) || 'Transaction',
702
+ status: 'PENDING',
703
+ entities: [],
704
+ userId: (options === null || options === void 0 ? void 0 : options.userId) || context.userId,
705
+ username: (options === null || options === void 0 ? void 0 : options.username) || context.username,
706
+ requestIp: (options === null || options === void 0 ? void 0 : options.requestIp) || context.requestIp,
707
+ operationTemplateKey: options === null || options === void 0 ? void 0 : options.operationTemplateKey,
708
+ descriptionParams: options === null || options === void 0 ? void 0 : options.descriptionParams,
709
+ metadata: options === null || options === void 0 ? void 0 : options.metadata,
710
+ });
711
+ const savedTransaction = yield this.transactionRepository.save(transaction);
712
+ const transactionId = savedTransaction.id;
713
+ try {
714
+ // 设置事务ID到上下文
715
+ yield this.contextService.setContext(Object.assign(Object.assign({}, context), { transactionId }));
716
+ // 执行操作
717
+ const result = yield fn(transactionId);
718
+ // 提交事务
719
+ yield this.transactionRepository.update(transactionId, {
720
+ status: 'COMMITTED',
721
+ completedAt: new Date(),
722
+ });
723
+ return result;
724
+ }
725
+ catch (error) {
726
+ // 回滚事务
727
+ yield this.transactionRepository.update(transactionId, {
728
+ status: 'ROLLED_BACK',
729
+ completedAt: new Date(),
730
+ });
731
+ throw error;
732
+ }
733
+ });
734
+ }
735
+ /**
736
+ * 获取当前事务ID
737
+ * @returns 当前事务ID或null
738
+ */
739
+ getCurrentTransactionId() {
740
+ return __awaiter(this, void 0, void 0, function* () {
741
+ const context = yield this.contextService.getCurrentContext();
742
+ return context.transactionId || null;
743
+ });
744
+ }
745
+ /**
746
+ * 设置当前事务ID
747
+ * @param transactionId 事务ID
748
+ */
749
+ setCurrentTransactionId(transactionId) {
750
+ return __awaiter(this, void 0, void 0, function* () {
751
+ const context = yield this.contextService.getCurrentContext();
752
+ yield this.contextService.setContext(Object.assign(Object.assign({}, context), { transactionId }));
753
+ });
754
+ }
755
+ /**
756
+ * 开始事务
757
+ * @param userId 用户ID
758
+ * @param userName 用户名
759
+ * @param ip IP地址
760
+ * @param operationTemplateKey 操作模板键
761
+ * @param descriptionParams 描述参数
762
+ * @returns 事务ID
763
+ */
764
+ beginTransaction(userId, userName, ip, operationTemplateKey, descriptionParams) {
765
+ return __awaiter(this, void 0, void 0, function* () {
766
+ // 获取上下文信息
767
+ const context = yield this.contextService.getCurrentContext();
768
+ // 创建事务
769
+ const transaction = this.transactionRepository.create({
770
+ description: (descriptionParams === null || descriptionParams === void 0 ? void 0 : descriptionParams.description) || 'Transaction',
771
+ status: 'pending',
772
+ entities: [],
773
+ userId: userId || context.userId,
774
+ username: userName || context.username,
775
+ requestIp: ip || context.requestIp,
776
+ operationTemplateKey,
777
+ descriptionParams,
778
+ });
779
+ const savedTransaction = yield this.transactionRepository.save(transaction);
780
+ return savedTransaction.id;
781
+ });
782
+ }
783
+ /**
784
+ * 提交事务
785
+ * @param transactionId 事务ID
786
+ */
787
+ commitTransaction(transactionId) {
788
+ return __awaiter(this, void 0, void 0, function* () {
789
+ yield this.transactionRepository.update(transactionId, {
790
+ status: 'committed',
791
+ completedAt: new Date(),
792
+ });
793
+ });
794
+ }
795
+ /**
796
+ * 回滚事务
797
+ * @param transactionId 事务ID
798
+ */
799
+ rollbackTransaction(transactionId) {
800
+ return __awaiter(this, void 0, void 0, function* () {
801
+ yield this.transactionRepository.update(transactionId, {
802
+ status: 'rolled_back',
803
+ completedAt: new Date(),
804
+ });
805
+ });
806
+ }
807
+ /**
808
+ * 查询审计动作汇总记录
809
+ */
810
+ getAuditActions(options) {
811
+ return __awaiter(this, void 0, void 0, function* () {
812
+ if (!this.actionSummaryRepository) {
813
+ throw new Error('AuditActionSummaryEntity repository not available');
814
+ }
815
+ const { page = 1, limit = 20 } = options;
816
+ const queryBuilder = this.actionSummaryRepository.createQueryBuilder('action');
817
+ // 应用过滤条件
818
+ if (options.userId) {
819
+ queryBuilder.andWhere('action.userId = :userId', { userId: options.userId });
820
+ }
821
+ if (options.username) {
822
+ queryBuilder.andWhere('action.username LIKE :username', { username: `%${options.username}%` });
823
+ }
824
+ if (options.actionName) {
825
+ queryBuilder.andWhere('action.actionName = :actionName', { actionName: options.actionName });
826
+ }
827
+ if (options.success !== undefined) {
828
+ queryBuilder.andWhere('action.success = :success', { success: options.success });
829
+ }
830
+ if (options.startTime && options.endTime) {
831
+ queryBuilder.andWhere('action.createdAt BETWEEN :startTime AND :endTime', {
832
+ startTime: options.startTime,
833
+ endTime: options.endTime,
834
+ });
835
+ }
836
+ // 排序
837
+ queryBuilder.orderBy('action.createdAt', 'DESC');
838
+ // 分页
839
+ const skip = (page - 1) * limit;
840
+ queryBuilder.skip(skip).take(limit);
841
+ const [data, total] = yield queryBuilder.getManyAndCount();
842
+ const pageOptionsDto = new dto_1.PageOptionsDto();
843
+ Object.assign(pageOptionsDto, { page, pageSize: limit });
844
+ const pageMetaDto = new dto_1.PageMetaDto({
845
+ pageOptionsDto,
846
+ itemCount: total,
847
+ });
848
+ return new dto_1.PageDto(data, pageMetaDto);
849
+ });
850
+ }
851
+ /**
852
+ * 查询单个审计动作的详细信息(包含关联的实体变更)
853
+ */
854
+ getAuditActionDetail(actionId) {
855
+ return __awaiter(this, void 0, void 0, function* () {
856
+ if (!this.actionSummaryRepository) {
857
+ throw new Error('AuditActionSummaryEntity repository not available');
858
+ }
859
+ // 查询汇总信息
860
+ const summary = yield this.actionSummaryRepository.findOne({
861
+ where: { id: actionId },
862
+ });
863
+ if (!summary) {
864
+ throw new Error(`Audit action with id ${actionId} not found`);
865
+ }
866
+ // 查询关联的实体变更
867
+ const entityChanges = yield this.auditLogRepository.find({
868
+ where: { auditActionId: actionId },
869
+ order: { sequenceInAction: 'ASC' },
870
+ });
871
+ // 分析每个实体的详细变化
872
+ const detailedChanges = entityChanges.map((change) => {
873
+ const fieldChanges = this.analyzeFieldChanges(change.oldValue || {}, change.newValue || {}, change.operation);
874
+ return {
875
+ id: change.id,
876
+ entityType: change.entityType,
877
+ entityId: change.entityId,
878
+ operation: change.operation,
879
+ operationLabel: this.getOperationLabel(change.operation),
880
+ description: change.description,
881
+ sequenceInAction: change.sequenceInAction,
882
+ createdAt: change.createdAt,
883
+ // 数据快照
884
+ oldValue: change.oldValue,
885
+ newValue: change.newValue,
886
+ // 详细的字段变化分析
887
+ fieldChanges,
888
+ changedFieldsCount: fieldChanges.length,
889
+ changedFields: change.changedFields,
890
+ };
891
+ });
892
+ // 统计信息
893
+ const statistics = {
894
+ totalChanges: entityChanges.length,
895
+ totalFieldChanges: detailedChanges.reduce((sum, c) => sum + c.changedFieldsCount, 0),
896
+ byEntityType: this.groupBy(entityChanges, 'entityType'),
897
+ byOperation: this.groupBy(entityChanges, 'operation'),
898
+ operationSequence: entityChanges.map((c) => ({
899
+ sequence: c.sequenceInAction,
900
+ entityType: c.entityType,
901
+ operation: c.operation,
902
+ })),
903
+ };
904
+ return {
905
+ // 汇总信息
906
+ summary: {
907
+ id: summary.id,
908
+ actionName: summary.actionName,
909
+ operationTemplateKey: summary.operationTemplateKey,
910
+ description: summary.description,
911
+ descriptionParams: summary.descriptionParams,
912
+ success: summary.success,
913
+ errorMessage: summary.errorMessage,
914
+ duration: summary.duration,
915
+ userId: summary.userId,
916
+ username: summary.username,
917
+ requestId: summary.requestId,
918
+ requestIp: summary.requestIp,
919
+ userAgent: summary.userAgent,
920
+ entityChangesCount: summary.entityChangesCount,
921
+ entityTypes: summary.entityTypes,
922
+ operationStats: summary.operationStats,
923
+ createdAt: summary.createdAt,
924
+ metadata: summary.metadata,
925
+ },
926
+ // 原始实体变更记录
927
+ entityChanges,
928
+ // 详细的变化分析
929
+ detailedChanges,
930
+ // 统计信息
931
+ statistics,
932
+ };
933
+ });
934
+ }
935
+ /**
936
+ * 分析字段变化(支持多语言)
937
+ * @param oldValue 旧值
938
+ * @param newValue 新值
939
+ * @param operation 操作类型
940
+ * @param entityClass 实体类(可选,用于获取字段和值的多语言标签)
941
+ * @param language 语言(默认中文)
942
+ */
943
+ analyzeFieldChanges(oldValue, newValue, operation, entityClass, language = 'zh') {
944
+ const changes = [];
945
+ const allFields = new Set([...Object.keys(oldValue), ...Object.keys(newValue)]);
946
+ for (const field of allFields) {
947
+ const oldVal = oldValue[field];
948
+ const newVal = newValue[field];
949
+ let changeType;
950
+ if (operation === enums_1.AuditOperation.CREATE) {
951
+ // 创建操作,所有字段都是新增
952
+ changeType = 'added';
953
+ }
954
+ else if (operation === enums_1.AuditOperation.DELETE) {
955
+ // 删除操作,所有字段都是移除
956
+ changeType = 'removed';
957
+ }
958
+ else {
959
+ // 更新操作,判断字段变化
960
+ if (oldVal === undefined && newVal !== undefined) {
961
+ changeType = 'added';
962
+ }
963
+ else if (oldVal !== undefined && newVal === undefined) {
964
+ changeType = 'removed';
965
+ }
966
+ else if (JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
967
+ changeType = 'modified';
968
+ }
969
+ else {
970
+ changeType = 'unchanged';
971
+ }
972
+ }
973
+ // 跳过未变化的字段(对于UPDATE操作)
974
+ if (changeType === 'unchanged' && operation === enums_1.AuditOperation.UPDATE) {
975
+ continue;
976
+ }
977
+ // 获取字段的多语言标签
978
+ let fieldLabel = field;
979
+ if (entityClass) {
980
+ try {
981
+ fieldLabel = (0, entity_audit_decorator_1.getFieldLabel)(entityClass, field, language);
982
+ }
983
+ catch (error) {
984
+ // 忽略错误,使用原字段名
985
+ }
986
+ }
987
+ // 获取字段值的多语言标签
988
+ let displayOldValue = this.formatDisplayValue(oldVal);
989
+ let displayNewValue = this.formatDisplayValue(newVal);
990
+ if (entityClass) {
991
+ try {
992
+ if (oldVal !== null && oldVal !== undefined) {
993
+ const valueLabel = (0, entity_audit_decorator_1.getFieldValueLabel)(entityClass, field, oldVal, language);
994
+ if (valueLabel !== oldVal) {
995
+ displayOldValue = valueLabel;
996
+ }
997
+ }
998
+ if (newVal !== null && newVal !== undefined) {
999
+ const valueLabel = (0, entity_audit_decorator_1.getFieldValueLabel)(entityClass, field, newVal, language);
1000
+ if (valueLabel !== newVal) {
1001
+ displayNewValue = valueLabel;
1002
+ }
1003
+ }
1004
+ }
1005
+ catch (error) {
1006
+ // 忽略错误,使用默认格式化值
1007
+ }
1008
+ }
1009
+ changes.push({
1010
+ field,
1011
+ fieldLabel,
1012
+ oldValue: oldVal,
1013
+ newValue: newVal,
1014
+ changeType,
1015
+ displayOldValue,
1016
+ displayNewValue,
1017
+ });
1018
+ }
1019
+ return changes;
1020
+ }
1021
+ /**
1022
+ * 格式化显示值
1023
+ */
1024
+ formatDisplayValue(value) {
1025
+ if (value === null || value === undefined) {
1026
+ return '';
1027
+ }
1028
+ if (typeof value === 'object') {
1029
+ return JSON.stringify(value);
1030
+ }
1031
+ return String(value);
1032
+ }
1033
+ /**
1034
+ * 获取操作标签
1035
+ */
1036
+ getOperationLabel(operation) {
1037
+ const labels = {
1038
+ [enums_1.AuditOperation.CREATE]: '创建',
1039
+ [enums_1.AuditOperation.UPDATE]: '更新',
1040
+ [enums_1.AuditOperation.DELETE]: '删除',
1041
+ [enums_1.AuditOperation.RESTORE]: '恢复',
1042
+ };
1043
+ return labels[operation] || operation;
1044
+ }
1045
+ /**
1046
+ * 按字段分组统计
1047
+ */
1048
+ groupBy(items, field) {
1049
+ return items.reduce((acc, item) => {
1050
+ const key = item[field];
1051
+ acc[key] = (acc[key] || 0) + 1;
1052
+ return acc;
1053
+ }, {});
1054
+ }
466
1055
  };
467
1056
  exports.EntityAuditService = EntityAuditService;
468
1057
  exports.EntityAuditService = EntityAuditService = __decorate([
469
1058
  (0, common_1.Injectable)(),
470
1059
  __param(0, (0, typeorm_1.InjectRepository)(entities_1.EntityAuditLogEntity)),
471
1060
  __param(1, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
472
- __param(2, (0, common_1.Inject)('AUDIT_ENTITY_MANAGER')),
473
- __param(5, (0, common_1.Optional)()),
474
- __param(5, (0, common_1.Inject)('AUDIT_STRATEGY')),
1061
+ __param(2, (0, typeorm_1.InjectRepository)(entities_1.ManualOperationLogEntity)),
1062
+ __param(3, (0, common_1.Inject)('AUDIT_ENTITY_MANAGER')),
475
1063
  __param(6, (0, common_1.Optional)()),
476
- __param(6, (0, common_1.Inject)('AUDIT_CONFIG')),
1064
+ __param(6, (0, common_1.Inject)('AUDIT_STRATEGY')),
477
1065
  __param(7, (0, common_1.Optional)()),
478
- __param(7, (0, common_1.Inject)('AUDIT_CONNECTION_NAME')),
1066
+ __param(7, (0, common_1.Inject)('AUDIT_CONFIG')),
1067
+ __param(8, (0, common_1.Optional)()),
1068
+ __param(8, (0, common_1.Inject)('AUDIT_CONNECTION_NAME')),
1069
+ __param(9, (0, common_1.Optional)()),
1070
+ __param(9, (0, typeorm_1.InjectRepository)(entities_1.AuditActionSummaryEntity)),
479
1071
  __metadata("design:paramtypes", [typeorm_2.Repository,
1072
+ typeorm_2.Repository,
480
1073
  typeorm_2.Repository,
481
1074
  typeorm_2.EntityManager,
482
1075
  audit_context_service_1.AuditContextService,
483
- multi_database_service_1.MultiDatabaseService, Object, Object, String])
1076
+ multi_database_service_1.MultiDatabaseService, Object, Object, String, typeorm_2.Repository])
484
1077
  ], EntityAuditService);