@nest-omni/core 4.1.3-3 → 4.1.3-31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audit/audit.module.d.ts +1 -0
- package/audit/audit.module.js +51 -2
- package/audit/controllers/audit.controller.d.ts +57 -1
- package/audit/controllers/audit.controller.js +43 -0
- package/audit/decorators/audit-action.decorator.d.ts +74 -0
- package/audit/decorators/audit-action.decorator.js +42 -0
- package/audit/decorators/audit-controller.decorator.d.ts +1 -1
- package/audit/decorators/audit-controller.decorator.js +2 -2
- package/audit/decorators/audit-operation.decorator.d.ts +0 -7
- package/audit/decorators/audit-operation.decorator.js +0 -7
- package/audit/decorators/entity-audit.decorator.d.ts +78 -2
- package/audit/decorators/entity-audit.decorator.js +145 -4
- package/audit/decorators/index.d.ts +2 -0
- package/audit/decorators/index.js +2 -0
- package/audit/dto/audit-action-query.dto.d.ts +13 -0
- package/audit/dto/audit-action-query.dto.js +77 -0
- package/audit/dto/index.d.ts +1 -0
- package/audit/dto/index.js +1 -0
- package/audit/entities/audit-action-summary.entity.d.ts +23 -0
- package/audit/entities/audit-action-summary.entity.js +101 -0
- package/audit/entities/entity-audit-log.entity.d.ts +7 -2
- package/audit/entities/entity-audit-log.entity.js +45 -9
- package/audit/entities/entity-transaction.entity.d.ts +8 -2
- package/audit/entities/entity-transaction.entity.js +39 -3
- package/audit/entities/index.d.ts +3 -0
- package/audit/entities/index.js +3 -0
- package/audit/entities/manual-operation-log.entity.d.ts +0 -2
- package/audit/entities/manual-operation-log.entity.js +8 -9
- package/audit/enums/audit.enums.d.ts +14 -6
- package/audit/enums/audit.enums.js +18 -9
- package/audit/examples/decorator-value-mapping.example.d.ts +70 -0
- package/audit/examples/decorator-value-mapping.example.js +414 -0
- package/audit/index.d.ts +5 -1
- package/audit/index.js +29 -2
- package/audit/interceptors/audit-action.interceptor.d.ts +39 -0
- package/audit/interceptors/audit-action.interceptor.js +217 -0
- package/audit/interceptors/audit.interceptor.d.ts +1 -0
- package/audit/interceptors/audit.interceptor.js +19 -11
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +1 -0
- package/audit/interfaces/audit.interfaces.d.ts +132 -4
- package/audit/services/audit-action.service.d.ts +142 -0
- package/audit/services/audit-action.service.js +246 -0
- package/audit/services/audit-context.service.d.ts +91 -0
- package/audit/services/audit-context.service.js +170 -0
- package/audit/services/entity-audit.service.d.ts +220 -9
- package/audit/services/entity-audit.service.js +761 -72
- package/audit/services/index.d.ts +3 -0
- package/audit/services/index.js +3 -0
- package/audit/services/manual-audit-log.service.d.ts +23 -23
- package/audit/services/manual-audit-log.service.js +34 -57
- package/audit/services/multi-database.service.d.ts +0 -5
- package/audit/services/multi-database.service.js +0 -24
- package/audit/services/operation-description.service.d.ts +14 -3
- package/audit/services/operation-description.service.js +165 -26
- package/audit/services/transaction-audit.service.d.ts +1 -0
- package/audit/services/transaction-audit.service.js +12 -9
- package/audit/subscribers/entity-audit.subscriber.d.ts +5 -0
- package/audit/subscribers/entity-audit.subscriber.js +69 -5
- package/cache/cache.module.d.ts +7 -8
- package/cache/cache.module.js +15 -13
- package/cache/cache.service.d.ts +6 -4
- package/cache/cache.service.js +24 -12
- package/cache/decorators/cache-put.decorator.js +5 -4
- package/cache/dependencies/callback.dependency.js +9 -0
- package/cache/dependencies/db.dependency.d.ts +43 -12
- package/cache/dependencies/db.dependency.js +46 -18
- package/cache/dependencies/tag.dependency.d.ts +31 -4
- package/cache/dependencies/tag.dependency.js +100 -11
- package/cache/entities/index.d.ts +1 -0
- package/cache/entities/index.js +17 -0
- package/cache/entities/typeorm-cache.entity.d.ts +71 -0
- package/cache/entities/typeorm-cache.entity.js +110 -0
- package/cache/index.d.ts +2 -1
- package/cache/index.js +19 -2
- package/cache/interfaces/cache-options.interface.d.ts +8 -0
- package/cache/providers/index.d.ts +2 -1
- package/cache/providers/index.js +2 -1
- package/cache/providers/lrucache.provider.d.ts +77 -0
- package/cache/providers/lrucache.provider.js +228 -0
- package/cache/providers/redis-cache.provider.d.ts +1 -0
- package/cache/providers/redis-cache.provider.js +8 -6
- package/cache/providers/typeorm-cache.provider.d.ts +211 -0
- package/cache/providers/typeorm-cache.provider.js +483 -0
- package/common/boilerplate.polyfill.d.ts +1 -0
- package/common/boilerplate.polyfill.js +18 -1
- package/common/helpers/validation-metadata-helper.d.ts +112 -0
- package/common/helpers/validation-metadata-helper.js +164 -0
- package/common/index.d.ts +1 -0
- package/common/index.js +4 -0
- package/decorators/examples/field-i18n.example.d.ts +294 -0
- package/decorators/examples/field-i18n.example.js +478 -0
- package/decorators/field.decorators.d.ts +95 -3
- package/decorators/field.decorators.js +152 -18
- package/decorators/transform.decorators.d.ts +0 -2
- package/decorators/transform.decorators.js +0 -23
- package/decorators/translate.decorator.d.ts +26 -0
- package/decorators/translate.decorator.js +26 -1
- package/email-log/email-log.constants.d.ts +8 -0
- package/email-log/email-log.constants.js +11 -0
- package/email-log/email-log.module.d.ts +47 -0
- package/email-log/email-log.module.js +140 -0
- package/email-log/index.d.ts +11 -0
- package/email-log/index.js +48 -0
- package/email-log/interfaces/email-log-options.interface.d.ts +61 -0
- package/email-log/interfaces/email-log-options.interface.js +134 -0
- package/email-log/interfaces/email-log-transport.interface.d.ts +20 -0
- package/email-log/interfaces/email-log-transport.interface.js +2 -0
- package/email-log/interfaces/index.d.ts +2 -0
- package/email-log/interfaces/index.js +18 -0
- package/email-log/providers/email-provider.d.ts +42 -0
- package/email-log/providers/email-provider.js +127 -0
- package/email-log/providers/index.d.ts +1 -0
- package/email-log/providers/index.js +17 -0
- package/email-log/services/email-log-alert.service.d.ts +46 -0
- package/email-log/services/email-log-alert.service.js +162 -0
- package/email-log/services/email-log-formatter.service.d.ts +78 -0
- package/email-log/services/email-log-formatter.service.js +442 -0
- package/email-log/services/email-log-logger.service.d.ts +85 -0
- package/email-log/services/email-log-logger.service.js +168 -0
- package/email-log/services/email-log-rate-limiter.service.d.ts +42 -0
- package/email-log/services/email-log-rate-limiter.service.js +110 -0
- package/email-log/services/email-log-transport.service.d.ts +80 -0
- package/email-log/services/email-log-transport.service.js +271 -0
- package/email-log/services/index.d.ts +5 -0
- package/email-log/services/index.js +21 -0
- package/email-log/transports/index.d.ts +1 -0
- package/email-log/transports/index.js +17 -0
- package/email-log/transports/pino-email.transport.d.ts +56 -0
- package/email-log/transports/pino-email.transport.js +188 -0
- package/email-log/utils/index.d.ts +2 -0
- package/email-log/utils/index.js +18 -0
- package/email-log/utils/log-level.helper.d.ts +46 -0
- package/email-log/utils/log-level.helper.js +74 -0
- package/email-log/utils/pino-transport.utils.d.ts +135 -0
- package/email-log/utils/pino-transport.utils.js +238 -0
- package/file-upload/controllers/file-access.controller.d.ts +23 -0
- package/file-upload/controllers/file-access.controller.js +128 -0
- package/file-upload/decorators/column.decorator.d.ts +151 -0
- package/file-upload/decorators/column.decorator.js +273 -0
- package/file-upload/decorators/csv-data.decorator.d.ts +30 -0
- package/file-upload/decorators/csv-data.decorator.js +85 -0
- package/file-upload/decorators/csv-import.decorator.d.ts +34 -0
- package/file-upload/decorators/csv-import.decorator.js +24 -0
- package/file-upload/decorators/examples/column-mapping.example.d.ts +76 -0
- package/file-upload/decorators/examples/column-mapping.example.js +122 -0
- package/file-upload/decorators/excel-data.decorator.d.ts +30 -0
- package/file-upload/decorators/excel-data.decorator.js +85 -0
- package/file-upload/decorators/file-upload.decorator.d.ts +83 -0
- package/file-upload/decorators/file-upload.decorator.js +172 -0
- package/file-upload/decorators/index.d.ts +5 -0
- package/file-upload/decorators/index.js +38 -0
- package/file-upload/decorators/process.decorator.d.ts +40 -0
- package/file-upload/decorators/process.decorator.js +52 -0
- package/file-upload/decorators/validate-data.decorator.d.ts +91 -0
- package/file-upload/decorators/validate-data.decorator.js +39 -0
- package/file-upload/dto/create-file.dto.d.ts +24 -0
- package/file-upload/dto/create-file.dto.js +112 -0
- package/file-upload/dto/find-files.dto.d.ts +15 -0
- package/file-upload/dto/find-files.dto.js +76 -0
- package/file-upload/dto/index.d.ts +4 -0
- package/file-upload/dto/index.js +20 -0
- package/file-upload/dto/pagination.dto.d.ts +7 -0
- package/file-upload/dto/pagination.dto.js +39 -0
- package/file-upload/dto/update-file.dto.d.ts +15 -0
- package/file-upload/dto/update-file.dto.js +67 -0
- package/file-upload/entities/file-metadata.entity.d.ts +25 -0
- package/file-upload/entities/file-metadata.entity.js +76 -0
- package/file-upload/entities/file.entity.d.ts +114 -0
- package/file-upload/entities/file.entity.js +350 -0
- package/file-upload/entities/index.d.ts +2 -0
- package/file-upload/entities/index.js +18 -0
- package/file-upload/enums/file-type.enum.d.ts +72 -0
- package/file-upload/enums/file-type.enum.js +212 -0
- package/file-upload/exceptions/file-upload.exception.d.ts +57 -0
- package/file-upload/exceptions/file-upload.exception.js +120 -0
- package/file-upload/exceptions/index.d.ts +1 -0
- package/file-upload/exceptions/index.js +17 -0
- package/file-upload/file-upload.module.d.ts +89 -0
- package/file-upload/file-upload.module.js +292 -0
- package/file-upload/index.d.ts +37 -0
- package/file-upload/index.js +77 -0
- package/file-upload/interceptors/file-upload.interceptor.d.ts +101 -0
- package/file-upload/interceptors/file-upload.interceptor.js +594 -0
- package/file-upload/interceptors/index.d.ts +1 -0
- package/file-upload/interceptors/index.js +17 -0
- package/file-upload/interfaces/custom-file-type.interface.d.ts +72 -0
- package/file-upload/interfaces/custom-file-type.interface.js +2 -0
- package/file-upload/interfaces/file-buffer.interface.d.ts +72 -0
- package/file-upload/interfaces/file-buffer.interface.js +2 -0
- package/file-upload/interfaces/file-entity.interface.d.ts +142 -0
- package/file-upload/interfaces/file-entity.interface.js +28 -0
- package/file-upload/interfaces/file-metadata.interface.d.ts +21 -0
- package/file-upload/interfaces/file-metadata.interface.js +2 -0
- package/file-upload/interfaces/file-processor.interface.d.ts +93 -0
- package/file-upload/interfaces/file-processor.interface.js +2 -0
- package/file-upload/interfaces/file-upload-options.interface.d.ts +74 -0
- package/file-upload/interfaces/file-upload-options.interface.js +5 -0
- package/file-upload/interfaces/index.d.ts +7 -0
- package/file-upload/interfaces/index.js +24 -0
- package/file-upload/interfaces/processor-options.interface.d.ts +102 -0
- package/file-upload/interfaces/processor-options.interface.js +2 -0
- package/file-upload/interfaces/storage-provider.interface.d.ts +239 -0
- package/file-upload/interfaces/storage-provider.interface.js +2 -0
- package/file-upload/interfaces/upload-options.interface.d.ts +19 -0
- package/file-upload/interfaces/upload-options.interface.js +2 -0
- package/file-upload/processors/csv.processor.d.ts +98 -0
- package/file-upload/processors/csv.processor.js +391 -0
- package/file-upload/processors/excel.processor.d.ts +130 -0
- package/file-upload/processors/excel.processor.js +547 -0
- package/file-upload/processors/image.processor.d.ts +199 -0
- package/file-upload/processors/image.processor.js +377 -0
- package/file-upload/providers/index.d.ts +2 -0
- package/file-upload/providers/index.js +18 -0
- package/file-upload/providers/local-storage.provider.d.ts +98 -0
- package/file-upload/providers/local-storage.provider.js +484 -0
- package/file-upload/providers/s3-storage.provider.d.ts +87 -0
- package/file-upload/providers/s3-storage.provider.js +455 -0
- package/file-upload/services/file-signature-validator.service.d.ts +118 -0
- package/file-upload/services/file-signature-validator.service.js +376 -0
- package/file-upload/services/file.service.d.ts +193 -0
- package/file-upload/services/file.service.js +638 -0
- package/file-upload/services/index.d.ts +4 -0
- package/file-upload/services/index.js +20 -0
- package/file-upload/services/malicious-file-detector.service.d.ts +300 -0
- package/file-upload/services/malicious-file-detector.service.js +1234 -0
- package/file-upload/services/mime-registry.service.d.ts +47 -0
- package/file-upload/services/mime-registry.service.js +167 -0
- package/file-upload/utils/checksum.util.d.ts +28 -0
- package/file-upload/utils/checksum.util.js +65 -0
- package/file-upload/utils/dynamic-import.util.d.ts +54 -0
- package/file-upload/utils/dynamic-import.util.js +156 -0
- package/file-upload/utils/filename.util.d.ts +59 -0
- package/file-upload/utils/filename.util.js +184 -0
- package/file-upload/utils/filepath.util.d.ts +70 -0
- package/file-upload/utils/filepath.util.js +152 -0
- package/file-upload/utils/index.d.ts +4 -0
- package/file-upload/utils/index.js +20 -0
- package/filters/bad-request.filter.d.ts +9 -0
- package/filters/bad-request.filter.js +57 -16
- package/http-client/config/http-client.config.d.ts +5 -0
- package/http-client/config/http-client.config.js +27 -14
- package/http-client/decorators/http-client.decorators.d.ts +7 -28
- package/http-client/decorators/http-client.decorators.js +124 -99
- package/http-client/entities/http-log.entity.d.ts +0 -20
- package/http-client/entities/http-log.entity.js +1 -21
- package/http-client/examples/advanced-usage.example.d.ts +4 -5
- package/http-client/examples/advanced-usage.example.js +7 -59
- package/http-client/examples/axios-config-extended.example.d.ts +17 -0
- package/http-client/examples/axios-config-extended.example.js +311 -0
- package/http-client/examples/flexible-response-example.d.ts +28 -0
- package/http-client/examples/flexible-response-example.js +120 -0
- package/http-client/examples/index.d.ts +2 -0
- package/http-client/examples/index.js +2 -0
- package/http-client/examples/proxy-from-environment.example.d.ts +133 -0
- package/http-client/examples/proxy-from-environment.example.js +409 -0
- package/http-client/examples/ssl-certificate.example.d.ts +47 -0
- package/http-client/examples/ssl-certificate.example.js +432 -0
- package/http-client/http-client.module.d.ts +43 -2
- package/http-client/http-client.module.js +150 -90
- package/http-client/index.d.ts +1 -1
- package/http-client/interfaces/api-client-config.interface.d.ts +24 -103
- package/http-client/interfaces/http-client-config.interface.d.ts +137 -62
- package/http-client/services/api-client-registry.service.d.ts +8 -21
- package/http-client/services/api-client-registry.service.js +31 -282
- package/http-client/services/circuit-breaker.service.d.ts +69 -2
- package/http-client/services/circuit-breaker.service.js +185 -7
- package/http-client/services/http-client.service.d.ts +85 -23
- package/http-client/services/http-client.service.js +512 -168
- package/http-client/services/http-log-query.service.js +0 -13
- package/http-client/services/index.d.ts +0 -1
- package/http-client/services/index.js +0 -1
- package/http-client/services/logging.service.d.ts +69 -16
- package/http-client/services/logging.service.js +290 -170
- package/http-client/utils/call-stack-extractor.util.d.ts +26 -0
- package/http-client/utils/call-stack-extractor.util.js +35 -0
- package/http-client/utils/context-extractor.util.d.ts +2 -0
- package/http-client/utils/context-extractor.util.js +17 -3
- package/http-client/utils/curl-generator.util.js +2 -5
- package/http-client/utils/index.d.ts +2 -0
- package/http-client/utils/index.js +2 -0
- package/http-client/utils/proxy-environment.util.d.ts +42 -0
- package/http-client/utils/proxy-environment.util.js +154 -0
- package/http-client/utils/retry-recorder.util.d.ts +0 -4
- package/http-client/utils/retry-recorder.util.js +2 -27
- package/http-client/utils/sanitize.util.d.ts +58 -0
- package/http-client/utils/sanitize.util.js +188 -0
- package/http-client/utils/security-validator.util.d.ts +118 -0
- package/http-client/utils/security-validator.util.js +354 -0
- package/index.d.ts +4 -1
- package/index.js +6 -1
- package/interceptors/translation-interceptor.service.d.ts +7 -0
- package/interceptors/translation-interceptor.service.js +40 -8
- package/ip-filter/constants.d.ts +21 -0
- package/ip-filter/constants.js +24 -0
- package/ip-filter/decorators/index.d.ts +1 -0
- package/ip-filter/decorators/index.js +17 -0
- package/ip-filter/decorators/ip-filter.decorator.d.ts +58 -0
- package/ip-filter/decorators/ip-filter.decorator.js +79 -0
- package/ip-filter/guards/index.d.ts +1 -0
- package/ip-filter/guards/index.js +17 -0
- package/ip-filter/guards/ip-filter.guard.d.ts +62 -0
- package/ip-filter/guards/ip-filter.guard.js +174 -0
- package/ip-filter/index.d.ts +7 -0
- package/ip-filter/index.js +23 -0
- package/ip-filter/interfaces/index.d.ts +4 -0
- package/ip-filter/interfaces/index.js +20 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.d.ts +15 -0
- package/ip-filter/interfaces/ip-filter-async-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.d.ts +26 -0
- package/ip-filter/interfaces/ip-filter-metadata.interface.js +2 -0
- package/ip-filter/interfaces/ip-filter-options.interface.d.ts +34 -0
- package/ip-filter/interfaces/ip-filter-options.interface.js +2 -0
- package/ip-filter/interfaces/ip-rule.interface.d.ts +36 -0
- package/ip-filter/interfaces/ip-rule.interface.js +2 -0
- package/ip-filter/ip-filter.module.d.ts +55 -0
- package/ip-filter/ip-filter.module.js +105 -0
- package/ip-filter/services/index.d.ts +1 -0
- package/ip-filter/services/index.js +17 -0
- package/ip-filter/services/ip-filter.service.d.ts +92 -0
- package/ip-filter/services/ip-filter.service.js +238 -0
- package/ip-filter/utils/index.d.ts +1 -0
- package/ip-filter/utils/index.js +17 -0
- package/ip-filter/utils/ip-utils.d.ts +61 -0
- package/ip-filter/utils/ip-utils.js +162 -0
- package/package.json +34 -29
- package/providers/context.provider.d.ts +9 -0
- package/providers/context.provider.js +13 -0
- package/redis-lock/comprehensive-lock-cleanup.service.d.ts +94 -0
- package/redis-lock/comprehensive-lock-cleanup.service.js +253 -0
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +5 -1
- package/redis-lock/lock-heartbeat.service.d.ts +80 -0
- package/redis-lock/lock-heartbeat.service.js +232 -0
- package/redis-lock/redis-lock.module.d.ts +6 -0
- package/redis-lock/redis-lock.module.js +136 -77
- package/redis-lock/redis-lock.service.d.ts +31 -0
- package/redis-lock/redis-lock.service.js +124 -17
- package/setup/bootstrap.setup.d.ts +2 -1
- package/setup/bootstrap.setup.js +3 -2
- package/setup/index.d.ts +1 -0
- package/setup/index.js +1 -0
- package/setup/run-in-mode.decorator.d.ts +56 -0
- package/setup/run-in-mode.decorator.js +92 -0
- package/setup/schedule.decorator.d.ts +1 -0
- package/setup/schedule.decorator.js +28 -13
- package/setup/worker.decorator.js +10 -1
- package/shared/index.d.ts +1 -1
- package/shared/index.js +1 -1
- package/shared/{serviceRegistryModule.js → service-registry.module.js} +28 -17
- package/shared/services/api-config.service.d.ts +41 -0
- package/shared/services/api-config.service.js +175 -8
- package/shared/services/index.d.ts +0 -1
- package/shared/services/index.js +0 -1
- package/validators/custom-validate.validator.d.ts +1 -0
- package/validators/custom-validate.validator.js +1 -0
- package/validators/file-mimetype.validator.d.ts +0 -2
- package/validators/file-mimetype.validator.js +4 -6
- package/validators/is-exists.validator.d.ts +15 -6
- package/validators/is-exists.validator.js +8 -7
- package/validators/is-unique.validator.d.ts +22 -7
- package/validators/is-unique.validator.js +41 -17
- package/vault/vault-config.service.js +1 -1
- package/cache/providers/memory-cache.provider.d.ts +0 -49
- package/cache/providers/memory-cache.provider.js +0 -197
- package/http-client/services/cache.service.d.ts +0 -76
- package/http-client/services/cache.service.js +0 -333
- package/shared/services/validator.service.d.ts +0 -3
- package/shared/services/validator.service.js +0 -20
- /package/shared/{serviceRegistryModule.d.ts → service-registry.module.d.ts} +0 -0
|
@@ -0,0 +1,217 @@
|
|
|
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
|
+
var AuditActionInterceptor_1;
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.AuditActionInterceptor = void 0;
|
|
26
|
+
const common_1 = require("@nestjs/common");
|
|
27
|
+
const core_1 = require("@nestjs/core");
|
|
28
|
+
const rxjs_1 = require("rxjs");
|
|
29
|
+
const operators_1 = require("rxjs/operators");
|
|
30
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
31
|
+
const typeorm_2 = require("typeorm");
|
|
32
|
+
const audit_context_service_1 = require("../services/audit-context.service");
|
|
33
|
+
const operation_description_service_1 = require("../services/operation-description.service");
|
|
34
|
+
const entities_1 = require("../entities");
|
|
35
|
+
const audit_action_decorator_1 = require("../decorators/audit-action.decorator");
|
|
36
|
+
/**
|
|
37
|
+
* 审计动作拦截器
|
|
38
|
+
* 在请求开始时创建审计动作上下文,在请求结束时生成汇总记录
|
|
39
|
+
*/
|
|
40
|
+
let AuditActionInterceptor = AuditActionInterceptor_1 = class AuditActionInterceptor {
|
|
41
|
+
constructor(reflector, contextService, summaryRepository, descriptionService) {
|
|
42
|
+
this.reflector = reflector;
|
|
43
|
+
this.contextService = contextService;
|
|
44
|
+
this.summaryRepository = summaryRepository;
|
|
45
|
+
this.descriptionService = descriptionService;
|
|
46
|
+
this.logger = new common_1.Logger(AuditActionInterceptor_1.name);
|
|
47
|
+
}
|
|
48
|
+
intercept(context, next) {
|
|
49
|
+
// 获取装饰器元数据
|
|
50
|
+
const metadata = this.reflector.get(audit_action_decorator_1.AUDIT_ACTION_METADATA, context.getHandler());
|
|
51
|
+
// 如果没有 @AuditAction 装饰器或已禁用,直接放行
|
|
52
|
+
if (!metadata || metadata.options.enabled === false) {
|
|
53
|
+
return next.handle();
|
|
54
|
+
}
|
|
55
|
+
const request = context.switchToHttp().getRequest();
|
|
56
|
+
const actionId = this.contextService.generateActionId();
|
|
57
|
+
const startTime = new Date();
|
|
58
|
+
// 创建审计动作上下文
|
|
59
|
+
const actionContext = {
|
|
60
|
+
actionId,
|
|
61
|
+
actionName: metadata.actionName,
|
|
62
|
+
operationTemplateKey: metadata.options.templateKey,
|
|
63
|
+
paramsBuilder: metadata.options.paramsBuilder,
|
|
64
|
+
startTime,
|
|
65
|
+
entityChanges: [],
|
|
66
|
+
detailedChanges: [],
|
|
67
|
+
req: request,
|
|
68
|
+
};
|
|
69
|
+
// 设置到 CLS
|
|
70
|
+
this.contextService.setActionContext(actionContext);
|
|
71
|
+
return next.handle().pipe((0, operators_1.tap)((result) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
// 请求成功,记录结果
|
|
73
|
+
actionContext.result = result;
|
|
74
|
+
yield this.generateSummary(actionContext, metadata, false);
|
|
75
|
+
})), (0, operators_1.catchError)((error) => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
// 请求失败,记录错误
|
|
77
|
+
actionContext.error = error;
|
|
78
|
+
yield this.generateSummary(actionContext, metadata, true, error);
|
|
79
|
+
return (0, rxjs_1.throwError)(() => error);
|
|
80
|
+
})));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 生成审计汇总记录
|
|
84
|
+
*/
|
|
85
|
+
generateSummary(actionContext, metadata, hasError, error) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
try {
|
|
88
|
+
const duration = Date.now() - actionContext.startTime.getTime();
|
|
89
|
+
const auditContext = yield this.contextService.getCurrentContext();
|
|
90
|
+
// 构建描述参数
|
|
91
|
+
let descriptionParams = {};
|
|
92
|
+
if (metadata.options.paramsBuilder) {
|
|
93
|
+
const paramsContext = this.contextService.buildParamsContext();
|
|
94
|
+
if (paramsContext) {
|
|
95
|
+
descriptionParams = metadata.options.paramsBuilder(paramsContext);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 生成描述文本
|
|
99
|
+
const description = yield this.generateDescription(actionContext.operationTemplateKey, actionContext.actionName, descriptionParams, !hasError);
|
|
100
|
+
// 统计实体类型和操作
|
|
101
|
+
const entityTypes = Array.from(new Set(actionContext.detailedChanges.map((c) => c.entityType)));
|
|
102
|
+
const operationStats = {};
|
|
103
|
+
actionContext.detailedChanges.forEach((change) => {
|
|
104
|
+
const op = change.operation;
|
|
105
|
+
operationStats[op] = (operationStats[op] || 0) + 1;
|
|
106
|
+
});
|
|
107
|
+
// 创建汇总记录
|
|
108
|
+
const summary = this.summaryRepository.create({
|
|
109
|
+
id: actionContext.actionId,
|
|
110
|
+
actionName: actionContext.actionName,
|
|
111
|
+
operationTemplateKey: actionContext.operationTemplateKey,
|
|
112
|
+
descriptionParams,
|
|
113
|
+
description,
|
|
114
|
+
requestId: auditContext.requestId || '',
|
|
115
|
+
userId: auditContext.userId || '',
|
|
116
|
+
username: auditContext.username || '',
|
|
117
|
+
requestIp: auditContext.requestIp || '',
|
|
118
|
+
userAgent: auditContext.userAgent || '',
|
|
119
|
+
entityChangesCount: actionContext.detailedChanges.length,
|
|
120
|
+
entityTypes,
|
|
121
|
+
operationStats,
|
|
122
|
+
success: !hasError,
|
|
123
|
+
errorMessage: error === null || error === void 0 ? void 0 : error.message,
|
|
124
|
+
duration,
|
|
125
|
+
metadata: metadata.options.metadata,
|
|
126
|
+
});
|
|
127
|
+
yield this.summaryRepository.save(summary);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
this.logger.error(`Failed to generate audit action summary: ${err.message}`, err.stack);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
// 清除审计动作上下文
|
|
134
|
+
this.contextService.clearActionContext();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 生成操作描述文本
|
|
140
|
+
* 优先从 OperationDescriptionService 获取多语言模板
|
|
141
|
+
* 如果没有,则使用默认格式
|
|
142
|
+
*/
|
|
143
|
+
generateDescription(templateKey, actionName, params, success) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
let template;
|
|
146
|
+
// 1. 尝试从模板服务获取模板
|
|
147
|
+
if (templateKey && this.descriptionService) {
|
|
148
|
+
try {
|
|
149
|
+
template = yield this.descriptionService.getTemplate(templateKey);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
// 如果获取模板失败,继续使用默认逻辑
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// 2. 如果没有模板,使用默认格式
|
|
156
|
+
if (!template) {
|
|
157
|
+
template = success
|
|
158
|
+
? `执行操作: ${actionName}`
|
|
159
|
+
: `执行操作失败: ${actionName}`;
|
|
160
|
+
}
|
|
161
|
+
// 3. 执行模板替换
|
|
162
|
+
return this.replaceTemplatePlaceholders(template, params);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 替换模板中的占位符
|
|
167
|
+
* 支持格式:{key} 或 {key:format}
|
|
168
|
+
*/
|
|
169
|
+
replaceTemplatePlaceholders(template, params) {
|
|
170
|
+
let result = template;
|
|
171
|
+
// 遍历所有参数,替换占位符
|
|
172
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
173
|
+
const placeholder = `{${key}}`;
|
|
174
|
+
const valueStr = this.formatValue(value);
|
|
175
|
+
// 替换所有匹配的占位符
|
|
176
|
+
const regex = new RegExp(placeholder.replace(/[{}]/g, '\\$&'), 'g');
|
|
177
|
+
result = result.replace(regex, valueStr);
|
|
178
|
+
});
|
|
179
|
+
// 清理未替换的占位符
|
|
180
|
+
result = result.replace(/\{[^}]+\}/g, '');
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* 格式化值为字符串
|
|
185
|
+
*/
|
|
186
|
+
formatValue(value) {
|
|
187
|
+
if (value === null || value === undefined) {
|
|
188
|
+
return '';
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(value)) {
|
|
191
|
+
// 处理数组
|
|
192
|
+
if (value.length === 0) {
|
|
193
|
+
return '';
|
|
194
|
+
}
|
|
195
|
+
// 如果是对象数组,序列化
|
|
196
|
+
if (typeof value[0] === 'object') {
|
|
197
|
+
return JSON.stringify(value);
|
|
198
|
+
}
|
|
199
|
+
// 否则用顿号连接
|
|
200
|
+
return value.join('、');
|
|
201
|
+
}
|
|
202
|
+
if (typeof value === 'object') {
|
|
203
|
+
return JSON.stringify(value);
|
|
204
|
+
}
|
|
205
|
+
return String(value);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
exports.AuditActionInterceptor = AuditActionInterceptor;
|
|
209
|
+
exports.AuditActionInterceptor = AuditActionInterceptor = AuditActionInterceptor_1 = __decorate([
|
|
210
|
+
(0, common_1.Injectable)(),
|
|
211
|
+
__param(2, (0, common_1.Inject)((0, typeorm_1.getRepositoryToken)(entities_1.AuditActionSummaryEntity))),
|
|
212
|
+
__param(3, (0, common_1.Optional)()),
|
|
213
|
+
__metadata("design:paramtypes", [core_1.Reflector,
|
|
214
|
+
audit_context_service_1.AuditContextService,
|
|
215
|
+
typeorm_2.Repository,
|
|
216
|
+
operation_description_service_1.OperationDescriptionService])
|
|
217
|
+
], AuditActionInterceptor);
|
|
@@ -6,6 +6,7 @@ import { AuditContextService } from '../services/audit-context.service';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare class AuditInterceptor implements NestInterceptor {
|
|
8
8
|
private readonly contextService;
|
|
9
|
+
private readonly logger;
|
|
9
10
|
constructor(contextService: AuditContextService);
|
|
10
11
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
11
12
|
/**
|
|
@@ -17,6 +17,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
17
17
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
|
+
var AuditInterceptor_1;
|
|
20
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
22
|
exports.AuditInterceptor = void 0;
|
|
22
23
|
const common_1 = require("@nestjs/common");
|
|
@@ -27,9 +28,10 @@ const decorators_1 = require("../decorators");
|
|
|
27
28
|
/**
|
|
28
29
|
* 审计拦截器
|
|
29
30
|
*/
|
|
30
|
-
let AuditInterceptor = class AuditInterceptor {
|
|
31
|
+
let AuditInterceptor = AuditInterceptor_1 = class AuditInterceptor {
|
|
31
32
|
constructor(contextService) {
|
|
32
33
|
this.contextService = contextService;
|
|
34
|
+
this.logger = new common_1.Logger(AuditInterceptor_1.name);
|
|
33
35
|
}
|
|
34
36
|
intercept(context, next) {
|
|
35
37
|
const request = context.switchToHttp().getRequest();
|
|
@@ -70,16 +72,22 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
70
72
|
*/
|
|
71
73
|
handleError(error, request) {
|
|
72
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
try {
|
|
76
|
+
// 记录错误信息到上下文
|
|
77
|
+
this.contextService.setContext({
|
|
78
|
+
metadata: {
|
|
79
|
+
error: {
|
|
80
|
+
message: error.message,
|
|
81
|
+
stack: error.stack,
|
|
82
|
+
status: error.status,
|
|
83
|
+
},
|
|
80
84
|
},
|
|
81
|
-
}
|
|
82
|
-
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
catch (contextError) {
|
|
88
|
+
// 不影响请求处理,只记录日志
|
|
89
|
+
this.logger.warn(`Failed to set error context: ${contextError.message}`);
|
|
90
|
+
}
|
|
83
91
|
});
|
|
84
92
|
}
|
|
85
93
|
/**
|
|
@@ -111,7 +119,7 @@ let AuditInterceptor = class AuditInterceptor {
|
|
|
111
119
|
}
|
|
112
120
|
};
|
|
113
121
|
exports.AuditInterceptor = AuditInterceptor;
|
|
114
|
-
exports.AuditInterceptor = AuditInterceptor = __decorate([
|
|
122
|
+
exports.AuditInterceptor = AuditInterceptor = AuditInterceptor_1 = __decorate([
|
|
115
123
|
(0, common_1.Injectable)(),
|
|
116
124
|
__metadata("design:paramtypes", [audit_context_service_1.AuditContextService])
|
|
117
125
|
], AuditInterceptor);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuditOperation, MaskingStrategy, RecordStrategy } from '../enums/audit.enums';
|
|
1
|
+
import { AuditOperation, MaskingStrategy, RecordStrategy, ChangeType } from '../enums/audit.enums';
|
|
2
2
|
/**
|
|
3
3
|
* 审计上下文
|
|
4
4
|
*/
|
|
@@ -113,8 +113,6 @@ export interface AuditConfig {
|
|
|
113
113
|
entities?: Record<string, EntityAuditConfig>;
|
|
114
114
|
operations?: Record<string, OperationAuditConfig>;
|
|
115
115
|
security?: {
|
|
116
|
-
hashChainEnabled?: boolean;
|
|
117
|
-
hashAlgorithm?: string;
|
|
118
116
|
masking?: {
|
|
119
117
|
defaultStrategy?: MaskingStrategy;
|
|
120
118
|
strategies?: Record<string, MaskingStrategy>;
|
|
@@ -124,12 +122,43 @@ export interface AuditConfig {
|
|
|
124
122
|
/**
|
|
125
123
|
* 实体级别审计配置
|
|
126
124
|
*/
|
|
125
|
+
/**
|
|
126
|
+
* 实体审计配置
|
|
127
|
+
*
|
|
128
|
+
* @description
|
|
129
|
+
* 支持基础审计配置
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* @EntityAudit({
|
|
134
|
+
* enabled: true,
|
|
135
|
+
* excludeFields: ['password'],
|
|
136
|
+
* maskFields: ['email', 'phone'],
|
|
137
|
+
* templateKey: 'user',
|
|
138
|
+
* })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
127
141
|
export interface EntityAuditConfig {
|
|
128
142
|
enabled?: boolean;
|
|
129
143
|
strategy?: RecordStrategy;
|
|
130
144
|
includeFields?: string[];
|
|
131
145
|
excludeFields?: string[];
|
|
132
146
|
maskFields?: string[];
|
|
147
|
+
/**
|
|
148
|
+
* 实体标签(支持多语言)
|
|
149
|
+
* @example
|
|
150
|
+
* // 单语言
|
|
151
|
+
* label: '订单'
|
|
152
|
+
*
|
|
153
|
+
* // 多语言
|
|
154
|
+
* label: { zh: '订单', en: 'Order', ja: '注文' }
|
|
155
|
+
*/
|
|
156
|
+
label?: string | Record<string, string>;
|
|
157
|
+
/**
|
|
158
|
+
* 操作模板键前缀
|
|
159
|
+
* @example 'user' -> 生成 'user.create', 'user.update', 'user.delete'
|
|
160
|
+
*/
|
|
161
|
+
templateKey?: string;
|
|
133
162
|
}
|
|
134
163
|
/**
|
|
135
164
|
* 操作级别审计配置
|
|
@@ -142,7 +171,25 @@ export interface OperationAuditConfig {
|
|
|
142
171
|
* 字段显示选项
|
|
143
172
|
*/
|
|
144
173
|
export interface FieldDisplayOptions {
|
|
145
|
-
|
|
174
|
+
/**
|
|
175
|
+
* 字段标签(支持多语言)
|
|
176
|
+
* @example
|
|
177
|
+
* // 单语言
|
|
178
|
+
* label: '姓名'
|
|
179
|
+
*
|
|
180
|
+
* // 多语言
|
|
181
|
+
* label: { zh: '姓名', en: 'Name' }
|
|
182
|
+
*/
|
|
183
|
+
label?: string | Record<string, string>;
|
|
184
|
+
/**
|
|
185
|
+
* 字段值的多语言标签映射
|
|
186
|
+
* @example
|
|
187
|
+
* valueLabels: {
|
|
188
|
+
* active: { zh: '激活', en: 'Active' },
|
|
189
|
+
* inactive: { zh: '未激活', en: 'Inactive' }
|
|
190
|
+
* }
|
|
191
|
+
*/
|
|
192
|
+
valueLabels?: Record<string, Record<string, string>>;
|
|
146
193
|
sensitive?: boolean;
|
|
147
194
|
formatter?: (value: any) => string;
|
|
148
195
|
}
|
|
@@ -159,3 +206,84 @@ export interface ControllerAuditOptions {
|
|
|
159
206
|
export interface MethodAuditOptions {
|
|
160
207
|
enabled?: boolean;
|
|
161
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* 变更详情
|
|
211
|
+
*/
|
|
212
|
+
export interface ChangeDetail {
|
|
213
|
+
fieldName: string;
|
|
214
|
+
fieldLabels?: Record<string, string>;
|
|
215
|
+
oldValue: any;
|
|
216
|
+
newValue: any;
|
|
217
|
+
displayOldValue?: Record<string, string>;
|
|
218
|
+
displayNewValue?: Record<string, string>;
|
|
219
|
+
changeType: ChangeType;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* 操作模板配置(用于数据库存储)
|
|
223
|
+
*/
|
|
224
|
+
export interface OperationTemplateData {
|
|
225
|
+
key: string;
|
|
226
|
+
entityName: string;
|
|
227
|
+
operation: AuditOperation;
|
|
228
|
+
nameTemplates: Record<string, string>;
|
|
229
|
+
descriptionTemplates: Record<string, string>;
|
|
230
|
+
fieldLabels?: Record<string, Record<string, string>>;
|
|
231
|
+
valueDisplays?: Record<string, Record<string, Record<string, string>>>;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 手动操作日志数据
|
|
235
|
+
*/
|
|
236
|
+
export interface ManualOperationData {
|
|
237
|
+
transactionId: string;
|
|
238
|
+
operationTemplateKey: string;
|
|
239
|
+
descriptionParams: Record<string, any>;
|
|
240
|
+
userId?: string;
|
|
241
|
+
username?: string;
|
|
242
|
+
requestIp?: string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* 手动日志记录选项(支持三种模式)
|
|
246
|
+
*/
|
|
247
|
+
export interface ManualLogOptions {
|
|
248
|
+
templateKey?: string;
|
|
249
|
+
descriptionParams?: Record<string, any>;
|
|
250
|
+
description?: string | Record<string, string>;
|
|
251
|
+
descriptionTemplate?: Record<string, string>;
|
|
252
|
+
userId?: string;
|
|
253
|
+
username?: string;
|
|
254
|
+
requestIp?: string;
|
|
255
|
+
transactionId?: string;
|
|
256
|
+
autoCreateTransaction?: boolean;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* 方法审计选项(支持模板)
|
|
260
|
+
*/
|
|
261
|
+
export interface AuditOperationOptions {
|
|
262
|
+
templateKey: string;
|
|
263
|
+
descriptionParams?: (args: any[], result: any, context: any) => Record<string, any>;
|
|
264
|
+
autoTransaction?: boolean;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 增强的实体审计配置(支持多语言)
|
|
268
|
+
*/
|
|
269
|
+
export interface EnhancedEntityAuditConfig extends EntityAuditConfig {
|
|
270
|
+
templateKey?: string;
|
|
271
|
+
fieldLabels?: Record<string, Record<string, string>>;
|
|
272
|
+
valueDisplays?: Record<string, Record<string, Record<string, string>>>;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* 事务描述结果
|
|
276
|
+
*/
|
|
277
|
+
export interface TransactionDescription {
|
|
278
|
+
operationName: string;
|
|
279
|
+
description: string;
|
|
280
|
+
changes: Array<{
|
|
281
|
+
entityName?: string;
|
|
282
|
+
entityId?: string;
|
|
283
|
+
operation?: AuditOperation;
|
|
284
|
+
type?: string;
|
|
285
|
+
description: string;
|
|
286
|
+
details: any;
|
|
287
|
+
createdAt: Date;
|
|
288
|
+
}>;
|
|
289
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { AuditContextService } from './audit-context.service';
|
|
2
|
+
import { EntityAuditService } from './entity-audit.service';
|
|
3
|
+
import { AuditOperation } from '../enums';
|
|
4
|
+
/**
|
|
5
|
+
* 审计动作选项
|
|
6
|
+
*/
|
|
7
|
+
export interface AuditActionOptions {
|
|
8
|
+
/**
|
|
9
|
+
* 动作名称,如 'createOrder', 'updateUser'
|
|
10
|
+
*/
|
|
11
|
+
actionName: string;
|
|
12
|
+
/**
|
|
13
|
+
* 操作模板键(可选)
|
|
14
|
+
* @example 'order.create'
|
|
15
|
+
*/
|
|
16
|
+
operationTemplateKey?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 描述参数,用于模板填充
|
|
19
|
+
* @example { productCount: 3, receiver: '张三', totalAmount: 299.99 }
|
|
20
|
+
*/
|
|
21
|
+
descriptionParams?: Record<string, any>;
|
|
22
|
+
/**
|
|
23
|
+
* 自定义元数据
|
|
24
|
+
*/
|
|
25
|
+
metadata?: Record<string, any>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 审计动作结果
|
|
29
|
+
*/
|
|
30
|
+
export interface AuditActionResult {
|
|
31
|
+
actionId: string;
|
|
32
|
+
actionName: string;
|
|
33
|
+
entityChanges: Array<{
|
|
34
|
+
entityType: string;
|
|
35
|
+
entityId: string;
|
|
36
|
+
operation: string;
|
|
37
|
+
sequence: number;
|
|
38
|
+
}>;
|
|
39
|
+
duration: number;
|
|
40
|
+
success: boolean;
|
|
41
|
+
error?: Error;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 审计动作服务
|
|
45
|
+
* 提供声明式的审计动作管理,自动关联同一业务操作的所有实体变化
|
|
46
|
+
*/
|
|
47
|
+
export declare class AuditActionService {
|
|
48
|
+
private readonly contextService;
|
|
49
|
+
private readonly auditService;
|
|
50
|
+
private readonly logger;
|
|
51
|
+
constructor(contextService: AuditContextService, auditService: EntityAuditService);
|
|
52
|
+
/**
|
|
53
|
+
* 在审计动作上下文中执行操作
|
|
54
|
+
* 自动关联该动作内的所有实体变化
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const result = await auditActionService.executeAction(
|
|
59
|
+
* {
|
|
60
|
+
* actionName: 'createOrder',
|
|
61
|
+
* operationTemplateKey: 'order.create',
|
|
62
|
+
* descriptionParams: {
|
|
63
|
+
* productCount: orderItems.length,
|
|
64
|
+
* receiver: order.receiverName,
|
|
65
|
+
* totalAmount: order.totalAmount,
|
|
66
|
+
* address: order.shippingAddress,
|
|
67
|
+
* },
|
|
68
|
+
* },
|
|
69
|
+
* async () => {
|
|
70
|
+
* // 1. 创建订单
|
|
71
|
+
* const order = await this.orderRepository.save(newOrder);
|
|
72
|
+
*
|
|
73
|
+
* // 2. 创建订单项
|
|
74
|
+
* await this.orderItemRepository.save(orderItems);
|
|
75
|
+
*
|
|
76
|
+
* // 3. 扣减库存
|
|
77
|
+
* await this.inventoryService.deduct(orderItems);
|
|
78
|
+
*
|
|
79
|
+
* // 4. 创建物流信息
|
|
80
|
+
* await this.shippingService.create(order.id);
|
|
81
|
+
*
|
|
82
|
+
* return order;
|
|
83
|
+
* }
|
|
84
|
+
* );
|
|
85
|
+
*
|
|
86
|
+
* // 结果中包含所有实体变化:
|
|
87
|
+
* // result.entityChanges = [
|
|
88
|
+
* // { entityType: 'Order', entityId: '1', operation: 'CREATE', sequence: 1 },
|
|
89
|
+
* // { entityType: 'OrderItem', entityId: '1', operation: 'CREATE', sequence: 2 },
|
|
90
|
+
* // { entityType: 'OrderItem', entityId: '2', operation: 'CREATE', sequence: 3 },
|
|
91
|
+
* // { entityType: 'Inventory', entityId: '1', operation: 'UPDATE', sequence: 4 },
|
|
92
|
+
* // { entityType: 'Shipping', entityId: '1', operation: 'CREATE', sequence: 5 },
|
|
93
|
+
* // ]
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
executeAction<T>(options: AuditActionOptions, operation: () => Promise<T>): Promise<AuditActionResult>;
|
|
97
|
+
/**
|
|
98
|
+
* 记录审计动作汇总日志
|
|
99
|
+
*/
|
|
100
|
+
private recordActionSummary;
|
|
101
|
+
/**
|
|
102
|
+
* 获取审计动作的所有实体变化
|
|
103
|
+
*/
|
|
104
|
+
getActionAuditLogs(actionId: string): Promise<{
|
|
105
|
+
actionId: string;
|
|
106
|
+
logs: import("..").EntityAuditLogEntity[];
|
|
107
|
+
summary: {
|
|
108
|
+
totalChanges: number;
|
|
109
|
+
operations: {
|
|
110
|
+
[k: string]: number;
|
|
111
|
+
};
|
|
112
|
+
entities: {
|
|
113
|
+
[k: string]: number;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}>;
|
|
117
|
+
/**
|
|
118
|
+
* 获取请求内的所有审计动作
|
|
119
|
+
*/
|
|
120
|
+
getRequestActions(requestId: string): Promise<{
|
|
121
|
+
requestId: string;
|
|
122
|
+
actions: {
|
|
123
|
+
actionId: string;
|
|
124
|
+
actionName: string;
|
|
125
|
+
entityChanges: {
|
|
126
|
+
entityType: string;
|
|
127
|
+
entityId: string;
|
|
128
|
+
operation: AuditOperation;
|
|
129
|
+
sequence: number;
|
|
130
|
+
timestamp: Date;
|
|
131
|
+
}[];
|
|
132
|
+
logs: import("..").EntityAuditLogEntity[];
|
|
133
|
+
}[];
|
|
134
|
+
noActionLogs: import("..").EntityAuditLogEntity[];
|
|
135
|
+
summary: {
|
|
136
|
+
totalActions: number;
|
|
137
|
+
totalChanges: number;
|
|
138
|
+
};
|
|
139
|
+
}>;
|
|
140
|
+
private groupByOperation;
|
|
141
|
+
private groupByEntity;
|
|
142
|
+
}
|