@nest-omni/core 4.1.3-3 → 4.1.3-30
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 +166 -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
|
@@ -20,24 +20,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
var OperationDescriptionService_1;
|
|
23
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
25
|
exports.OperationDescriptionService = void 0;
|
|
25
26
|
const common_1 = require("@nestjs/common");
|
|
26
27
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
27
28
|
const typeorm_2 = require("typeorm");
|
|
28
29
|
const entities_1 = require("../entities");
|
|
30
|
+
const cache_1 = require("../../cache");
|
|
29
31
|
/**
|
|
30
32
|
* 操作描述服务
|
|
31
33
|
* 负责根据模板和参数动态生成多语言描述
|
|
32
34
|
*/
|
|
33
|
-
let OperationDescriptionService = class OperationDescriptionService {
|
|
34
|
-
constructor(templateRepository, transactionRepository, auditLogRepository, manualOperationRepository) {
|
|
35
|
+
let OperationDescriptionService = OperationDescriptionService_1 = class OperationDescriptionService {
|
|
36
|
+
constructor(templateRepository, transactionRepository, auditLogRepository, manualOperationRepository, cacheService) {
|
|
35
37
|
this.templateRepository = templateRepository;
|
|
36
38
|
this.transactionRepository = transactionRepository;
|
|
37
39
|
this.auditLogRepository = auditLogRepository;
|
|
38
40
|
this.manualOperationRepository = manualOperationRepository;
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
+
this.cacheService = cacheService;
|
|
42
|
+
this.logger = new common_1.Logger(OperationDescriptionService_1.name);
|
|
43
|
+
// 缓存命名空间
|
|
44
|
+
this.CACHE_NAMESPACE = 'audit:template';
|
|
45
|
+
// 缓存TTL(30分钟)
|
|
46
|
+
this.CACHE_TTL = 30 * 60 * 1000;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* 动态生成操作名称
|
|
@@ -182,14 +188,123 @@ let OperationDescriptionService = class OperationDescriptionService {
|
|
|
182
188
|
*/
|
|
183
189
|
batchGetTransactionDescriptions(transactionIds_1) {
|
|
184
190
|
return __awaiter(this, arguments, void 0, function* (transactionIds, language = 'zh') {
|
|
191
|
+
if (transactionIds.length === 0) {
|
|
192
|
+
return {};
|
|
193
|
+
}
|
|
194
|
+
// 批量查询事务信息
|
|
195
|
+
const transactions = yield this.transactionRepository
|
|
196
|
+
.createQueryBuilder('tx')
|
|
197
|
+
.whereInIds(transactionIds)
|
|
198
|
+
.getMany();
|
|
199
|
+
// 批量查询审计日志
|
|
200
|
+
const auditLogs = yield this.auditLogRepository
|
|
201
|
+
.createQueryBuilder('log')
|
|
202
|
+
.where('log.requestId IN (:...transactionIds)', { transactionIds })
|
|
203
|
+
.orderBy('log.createdAt', 'ASC')
|
|
204
|
+
.getMany();
|
|
205
|
+
// 批量查询手动操作记录
|
|
206
|
+
const manualOperations = yield this.manualOperationRepository
|
|
207
|
+
.createQueryBuilder('op')
|
|
208
|
+
.where('op.transactionId IN (:...transactionIds)', { transactionIds })
|
|
209
|
+
.orderBy('op.createdAt', 'ASC')
|
|
210
|
+
.getMany();
|
|
211
|
+
// 收集所有需要的模板键
|
|
212
|
+
const templateKeys = new Set();
|
|
213
|
+
transactions.forEach(tx => {
|
|
214
|
+
if (tx.operationTemplateKey)
|
|
215
|
+
templateKeys.add(tx.operationTemplateKey);
|
|
216
|
+
});
|
|
217
|
+
auditLogs.forEach(log => {
|
|
218
|
+
if (log.operationTemplateKey)
|
|
219
|
+
templateKeys.add(log.operationTemplateKey);
|
|
220
|
+
});
|
|
221
|
+
manualOperations.forEach(op => {
|
|
222
|
+
if (op.operationTemplateKey)
|
|
223
|
+
templateKeys.add(op.operationTemplateKey);
|
|
224
|
+
});
|
|
225
|
+
// 批量预加载模板
|
|
226
|
+
if (templateKeys.size > 0) {
|
|
227
|
+
yield this.preloadTemplates(Array.from(templateKeys));
|
|
228
|
+
}
|
|
229
|
+
// 按事务ID分组
|
|
230
|
+
const logsByTxId = new Map();
|
|
231
|
+
const opsByTxId = new Map();
|
|
232
|
+
auditLogs.forEach(log => {
|
|
233
|
+
const txId = log.requestId;
|
|
234
|
+
if (!logsByTxId.has(txId))
|
|
235
|
+
logsByTxId.set(txId, []);
|
|
236
|
+
logsByTxId.get(txId).push(log);
|
|
237
|
+
});
|
|
238
|
+
manualOperations.forEach(op => {
|
|
239
|
+
const txId = op.transactionId;
|
|
240
|
+
if (!opsByTxId.has(txId))
|
|
241
|
+
opsByTxId.set(txId, []);
|
|
242
|
+
opsByTxId.get(txId).push(op);
|
|
243
|
+
});
|
|
244
|
+
// 构建结果
|
|
185
245
|
const results = {};
|
|
186
|
-
for (const
|
|
246
|
+
for (const transaction of transactions) {
|
|
187
247
|
try {
|
|
188
|
-
|
|
248
|
+
const txLogs = logsByTxId.get(transaction.id) || [];
|
|
249
|
+
const txOps = opsByTxId.get(transaction.id) || [];
|
|
250
|
+
// 生成操作名称和描述
|
|
251
|
+
let operationName;
|
|
252
|
+
let description;
|
|
253
|
+
if (transaction.operationTemplateKey) {
|
|
254
|
+
operationName = yield this.generateOperationName(transaction.operationTemplateKey, language);
|
|
255
|
+
description = yield this.generateDescription(transaction.operationTemplateKey, transaction.descriptionParams || {}, language);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const firstLog = txLogs[0];
|
|
259
|
+
if (firstLog && firstLog.operationTemplateKey) {
|
|
260
|
+
operationName = yield this.generateOperationName(firstLog.operationTemplateKey, language);
|
|
261
|
+
description = yield this.generateDescription(firstLog.operationTemplateKey, firstLog.descriptionParams || {}, language);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
operationName = 'Unknown Operation';
|
|
265
|
+
description = transaction.description || 'Unknown operation';
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// 生成变更详情
|
|
269
|
+
const changes = [];
|
|
270
|
+
// 添加实体变更
|
|
271
|
+
for (const log of txLogs) {
|
|
272
|
+
const changeDescription = log.operationTemplateKey
|
|
273
|
+
? yield this.generateDescription(log.operationTemplateKey, log.descriptionParams || {}, language)
|
|
274
|
+
: log.description || '';
|
|
275
|
+
const changeDetails = log.changeDetails
|
|
276
|
+
? yield this.generateChangeDetails(log.changeDetails, language)
|
|
277
|
+
: [];
|
|
278
|
+
changes.push({
|
|
279
|
+
entityName: log.entityType,
|
|
280
|
+
entityId: log.entityId,
|
|
281
|
+
operation: log.operation,
|
|
282
|
+
description: changeDescription,
|
|
283
|
+
details: changeDetails,
|
|
284
|
+
createdAt: log.createdAt,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// 添加手动操作
|
|
288
|
+
for (const manualOp of txOps) {
|
|
289
|
+
const opName = yield this.generateOperationName(manualOp.operationTemplateKey, language);
|
|
290
|
+
const opDescription = yield this.generateDescription(manualOp.operationTemplateKey, manualOp.descriptionParams, language);
|
|
291
|
+
changes.push({
|
|
292
|
+
type: 'manual',
|
|
293
|
+
description: `${opName}: ${opDescription}`,
|
|
294
|
+
details: manualOp.descriptionParams,
|
|
295
|
+
createdAt: manualOp.createdAt,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
// 按时间排序
|
|
299
|
+
changes.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
300
|
+
results[transaction.id] = {
|
|
301
|
+
operationName,
|
|
302
|
+
description,
|
|
303
|
+
changes,
|
|
304
|
+
};
|
|
189
305
|
}
|
|
190
306
|
catch (error) {
|
|
191
|
-
|
|
192
|
-
console.error(`Failed to get description for transaction ${transactionId}:`, error);
|
|
307
|
+
this.logger.error(`Failed to get description for transaction ${transaction.id}: ${error.message}`, error.stack);
|
|
193
308
|
}
|
|
194
309
|
}
|
|
195
310
|
return results;
|
|
@@ -230,32 +345,48 @@ let OperationDescriptionService = class OperationDescriptionService {
|
|
|
230
345
|
return String(value);
|
|
231
346
|
}
|
|
232
347
|
/**
|
|
233
|
-
*
|
|
348
|
+
* 获取操作模板(使用统一缓存服务)
|
|
234
349
|
* @param templateKey 模板键
|
|
235
350
|
* @returns 操作模板
|
|
236
351
|
*/
|
|
237
352
|
getOperationTemplate(templateKey) {
|
|
238
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
239
|
-
//
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
354
|
+
// 使用统一缓存服务的 getOrSet 方法
|
|
355
|
+
return this.cacheService.getOrSet(templateKey, () => __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
// 从数据库查询
|
|
357
|
+
const template = yield this.templateRepository.findOne({
|
|
358
|
+
where: { key: templateKey },
|
|
359
|
+
});
|
|
360
|
+
return template;
|
|
361
|
+
}), {
|
|
362
|
+
namespace: this.CACHE_NAMESPACE,
|
|
363
|
+
ttl: this.CACHE_TTL,
|
|
364
|
+
// 只使用内存缓存层,避免序列化开销
|
|
365
|
+
layers: [cache_1.CacheLayer.MEMORY],
|
|
246
366
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* 获取模板字符串(仅返回模板文本,不填充参数)
|
|
371
|
+
* @param templateKey 模板键
|
|
372
|
+
* @param language 语言
|
|
373
|
+
* @returns 模板字符串
|
|
374
|
+
*/
|
|
375
|
+
getTemplate(templateKey_1) {
|
|
376
|
+
return __awaiter(this, arguments, void 0, function* (templateKey, language = 'zh') {
|
|
377
|
+
const template = yield this.getOperationTemplate(templateKey);
|
|
378
|
+
if (!template) {
|
|
379
|
+
return null;
|
|
250
380
|
}
|
|
251
|
-
return template;
|
|
381
|
+
return template.descriptionTemplates[language] || template.descriptionTemplates['zh'] || null;
|
|
252
382
|
});
|
|
253
383
|
}
|
|
254
384
|
/**
|
|
255
385
|
* 清除模板缓存
|
|
256
386
|
*/
|
|
257
387
|
clearTemplateCache() {
|
|
258
|
-
|
|
388
|
+
// 使用统一缓存服务清除
|
|
389
|
+
this.cacheService.deletePattern(`${this.CACHE_NAMESPACE}:*`, [cache_1.CacheLayer.MEMORY]);
|
|
259
390
|
}
|
|
260
391
|
/**
|
|
261
392
|
* 预加载模板到缓存
|
|
@@ -267,14 +398,21 @@ let OperationDescriptionService = class OperationDescriptionService {
|
|
|
267
398
|
.createQueryBuilder('template')
|
|
268
399
|
.where('template.key IN (:...keys)', { keys: templateKeys })
|
|
269
400
|
.getMany();
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
401
|
+
// 批量设置到缓存
|
|
402
|
+
const cacheItems = templates.map(template => ({
|
|
403
|
+
key: template.key,
|
|
404
|
+
value: template,
|
|
405
|
+
}));
|
|
406
|
+
yield this.cacheService.mset(cacheItems, {
|
|
407
|
+
namespace: this.CACHE_NAMESPACE,
|
|
408
|
+
ttl: this.CACHE_TTL,
|
|
409
|
+
layers: [cache_1.CacheLayer.MEMORY],
|
|
410
|
+
});
|
|
273
411
|
});
|
|
274
412
|
}
|
|
275
413
|
};
|
|
276
414
|
exports.OperationDescriptionService = OperationDescriptionService;
|
|
277
|
-
exports.OperationDescriptionService = OperationDescriptionService = __decorate([
|
|
415
|
+
exports.OperationDescriptionService = OperationDescriptionService = OperationDescriptionService_1 = __decorate([
|
|
278
416
|
(0, common_1.Injectable)(),
|
|
279
417
|
__param(0, (0, typeorm_1.InjectRepository)(entities_1.OperationTemplateEntity)),
|
|
280
418
|
__param(1, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
|
|
@@ -283,5 +421,6 @@ exports.OperationDescriptionService = OperationDescriptionService = __decorate([
|
|
|
283
421
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
284
422
|
typeorm_2.Repository,
|
|
285
423
|
typeorm_2.Repository,
|
|
286
|
-
typeorm_2.Repository
|
|
424
|
+
typeorm_2.Repository,
|
|
425
|
+
cache_1.CacheService])
|
|
287
426
|
], OperationDescriptionService);
|
|
@@ -12,6 +12,7 @@ export declare class TransactionAuditService {
|
|
|
12
12
|
private readonly contextService;
|
|
13
13
|
private readonly auditService;
|
|
14
14
|
private readonly multiDbService;
|
|
15
|
+
private readonly logger;
|
|
15
16
|
constructor(transactionRepository: Repository<EntityTransactionEntity>, contextService: AuditContextService, auditService: EntityAuditService, multiDbService: MultiDatabaseService);
|
|
16
17
|
/**
|
|
17
18
|
* 开始事务
|
|
@@ -20,6 +20,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
+
var TransactionAuditService_1;
|
|
23
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
25
|
exports.TransactionAuditService = void 0;
|
|
25
26
|
const common_1 = require("@nestjs/common");
|
|
@@ -30,15 +31,17 @@ const enums_1 = require("../enums");
|
|
|
30
31
|
const audit_context_service_1 = require("./audit-context.service");
|
|
31
32
|
const entity_audit_service_1 = require("./entity-audit.service");
|
|
32
33
|
const multi_database_service_1 = require("./multi-database.service");
|
|
34
|
+
const transaction_1 = require("@nest-omni/transaction");
|
|
33
35
|
/**
|
|
34
36
|
* 事务审计服务
|
|
35
37
|
*/
|
|
36
|
-
let TransactionAuditService = class TransactionAuditService {
|
|
38
|
+
let TransactionAuditService = TransactionAuditService_1 = class TransactionAuditService {
|
|
37
39
|
constructor(transactionRepository, contextService, auditService, multiDbService) {
|
|
38
40
|
this.transactionRepository = transactionRepository;
|
|
39
41
|
this.contextService = contextService;
|
|
40
42
|
this.auditService = auditService;
|
|
41
43
|
this.multiDbService = multiDbService;
|
|
44
|
+
this.logger = new common_1.Logger(TransactionAuditService_1.name);
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* 开始事务
|
|
@@ -48,7 +51,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
48
51
|
const context = yield this.contextService.getCurrentContext();
|
|
49
52
|
const transaction = this.transactionRepository.create({
|
|
50
53
|
description,
|
|
51
|
-
status: enums_1.
|
|
54
|
+
status: enums_1.AuditTransactionStatus.PENDING,
|
|
52
55
|
entities: [],
|
|
53
56
|
userId: context.userId,
|
|
54
57
|
username: context.username,
|
|
@@ -72,7 +75,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
72
75
|
if (!transaction) {
|
|
73
76
|
throw new Error(`Transaction not found: ${transactionId}`);
|
|
74
77
|
}
|
|
75
|
-
transaction.status = enums_1.
|
|
78
|
+
transaction.status = enums_1.AuditTransactionStatus.COMMITTED;
|
|
76
79
|
yield this.transactionRepository.save(transaction);
|
|
77
80
|
});
|
|
78
81
|
}
|
|
@@ -89,7 +92,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
89
92
|
}
|
|
90
93
|
// 执行回滚操作
|
|
91
94
|
yield this.performRollback(transaction);
|
|
92
|
-
transaction.status = enums_1.
|
|
95
|
+
transaction.status = enums_1.AuditTransactionStatus.ROLLED_BACK;
|
|
93
96
|
yield this.transactionRepository.save(transaction);
|
|
94
97
|
});
|
|
95
98
|
}
|
|
@@ -140,7 +143,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
140
143
|
let connectionFound = false;
|
|
141
144
|
for (const connectionName of monitoredConnections) {
|
|
142
145
|
try {
|
|
143
|
-
const dataSource =
|
|
146
|
+
const dataSource = (0, transaction_1.getDataSource)(connectionName);
|
|
144
147
|
const metadata = dataSource.getMetadata(entity.entityType);
|
|
145
148
|
if (metadata) {
|
|
146
149
|
if (!grouped[connectionName]) {
|
|
@@ -173,7 +176,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
173
176
|
*/
|
|
174
177
|
rollbackEntitiesInConnection(connectionName, entities) {
|
|
175
178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
const dataSource =
|
|
179
|
+
const dataSource = (0, transaction_1.getDataSource)(connectionName);
|
|
177
180
|
// 使用事务执行回滚
|
|
178
181
|
yield dataSource.transaction((manager) => __awaiter(this, void 0, void 0, function* () {
|
|
179
182
|
for (const entity of entities) {
|
|
@@ -181,7 +184,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
181
184
|
yield this.rollbackSingleEntity(manager, entity, connectionName);
|
|
182
185
|
}
|
|
183
186
|
catch (error) {
|
|
184
|
-
|
|
187
|
+
this.logger.error(`Failed to rollback entity ${entity.entityType}:${entity.entityId} in connection ${connectionName}: ${error.message}`, error.stack);
|
|
185
188
|
throw error;
|
|
186
189
|
}
|
|
187
190
|
}
|
|
@@ -222,7 +225,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
222
225
|
}
|
|
223
226
|
break;
|
|
224
227
|
default:
|
|
225
|
-
|
|
228
|
+
this.logger.warn(`Unknown operation type: ${entity.operation}`);
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
}
|
|
@@ -238,7 +241,7 @@ let TransactionAuditService = class TransactionAuditService {
|
|
|
238
241
|
}
|
|
239
242
|
};
|
|
240
243
|
exports.TransactionAuditService = TransactionAuditService;
|
|
241
|
-
exports.TransactionAuditService = TransactionAuditService = __decorate([
|
|
244
|
+
exports.TransactionAuditService = TransactionAuditService = TransactionAuditService_1 = __decorate([
|
|
242
245
|
(0, common_1.Injectable)(),
|
|
243
246
|
__param(0, (0, typeorm_1.InjectRepository)(entities_1.EntityTransactionEntity)),
|
|
244
247
|
__metadata("design:paramtypes", [typeorm_2.Repository,
|
|
@@ -9,6 +9,7 @@ export declare class EntityAuditSubscriber implements EntitySubscriberInterface<
|
|
|
9
9
|
private readonly entityAuditService;
|
|
10
10
|
private readonly contextService;
|
|
11
11
|
private readonly auditStrategy;
|
|
12
|
+
private readonly logger;
|
|
12
13
|
constructor(entityAuditService: EntityAuditService, contextService: AuditContextService, auditStrategy: DefaultAuditStrategy, dataSource: DataSource);
|
|
13
14
|
/**
|
|
14
15
|
* 在实体插入后记录审计日志
|
|
@@ -22,6 +23,10 @@ export declare class EntityAuditSubscriber implements EntitySubscriberInterface<
|
|
|
22
23
|
* 在实体删除前记录审计日志
|
|
23
24
|
*/
|
|
24
25
|
beforeRemove(event: RemoveEvent<any>): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 计算变更字段
|
|
28
|
+
*/
|
|
29
|
+
private calculateChangedFields;
|
|
25
30
|
/**
|
|
26
31
|
* 检查是否启用了审计
|
|
27
32
|
*/
|
|
@@ -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 EntityAuditSubscriber_1;
|
|
20
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
22
|
exports.EntityAuditSubscriber = void 0;
|
|
22
23
|
const common_1 = require("@nestjs/common");
|
|
@@ -29,11 +30,12 @@ const decorators_1 = require("../decorators");
|
|
|
29
30
|
/**
|
|
30
31
|
* 实体审计订阅者
|
|
31
32
|
*/
|
|
32
|
-
let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
33
|
+
let EntityAuditSubscriber = EntityAuditSubscriber_1 = class EntityAuditSubscriber {
|
|
33
34
|
constructor(entityAuditService, contextService, auditStrategy, dataSource) {
|
|
34
35
|
this.entityAuditService = entityAuditService;
|
|
35
36
|
this.contextService = contextService;
|
|
36
37
|
this.auditStrategy = auditStrategy;
|
|
38
|
+
this.logger = new common_1.Logger(EntityAuditSubscriber_1.name);
|
|
37
39
|
dataSource.subscribers.push(this);
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
@@ -46,6 +48,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
46
48
|
return;
|
|
47
49
|
const entityType = entity.constructor.name;
|
|
48
50
|
const entityId = entity.id;
|
|
51
|
+
// 空值安全检查:确保实体 ID 存在
|
|
52
|
+
if (!entityId) {
|
|
53
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
49
56
|
// 检查是否启用了审计
|
|
50
57
|
if (!this.isAuditEnabled(entity)) {
|
|
51
58
|
return;
|
|
@@ -57,15 +64,25 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
57
64
|
try {
|
|
58
65
|
// 获取上下文信息
|
|
59
66
|
const context = yield this.contextService.getCurrentContext();
|
|
67
|
+
const actionContext = this.contextService.getCurrentActionContext();
|
|
68
|
+
// 记录到审计动作上下文
|
|
69
|
+
if (actionContext) {
|
|
70
|
+
this.contextService.recordEntityChangeInAction(entityType, entityId, enums_1.AuditOperation.CREATE);
|
|
71
|
+
// 记录详细的实体变更数据
|
|
72
|
+
this.contextService.recordDetailedEntityChange(entityType, entityId, enums_1.AuditOperation.CREATE, {}, entity, Object.keys(entity));
|
|
73
|
+
}
|
|
60
74
|
// 记录审计日志
|
|
61
75
|
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.CREATE, {}, entity, {
|
|
62
76
|
requestId: context.requestId,
|
|
63
77
|
requestIp: context.requestIp,
|
|
64
78
|
userAgent: context.userAgent,
|
|
79
|
+
auditActionId: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionId,
|
|
80
|
+
auditActionName: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionName,
|
|
81
|
+
sequenceInAction: (actionContext === null || actionContext === void 0 ? void 0 : actionContext.entityChanges.length) || 0,
|
|
65
82
|
});
|
|
66
83
|
}
|
|
67
84
|
catch (error) {
|
|
68
|
-
|
|
85
|
+
this.logger.error('Failed to log audit for insert:', error);
|
|
69
86
|
}
|
|
70
87
|
});
|
|
71
88
|
}
|
|
@@ -80,6 +97,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
80
97
|
return;
|
|
81
98
|
const entityType = entity.constructor.name;
|
|
82
99
|
const entityId = entity.id;
|
|
100
|
+
// 空值安全检查:确保实体 ID 存在
|
|
101
|
+
if (!entityId) {
|
|
102
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
83
105
|
// 检查是否启用了审计
|
|
84
106
|
if (!this.isAuditEnabled(entity)) {
|
|
85
107
|
return;
|
|
@@ -91,15 +113,26 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
91
113
|
try {
|
|
92
114
|
// 获取上下文信息
|
|
93
115
|
const context = yield this.contextService.getCurrentContext();
|
|
116
|
+
const actionContext = this.contextService.getCurrentActionContext();
|
|
117
|
+
// 记录到审计动作上下文
|
|
118
|
+
if (actionContext) {
|
|
119
|
+
this.contextService.recordEntityChangeInAction(entityType, entityId, enums_1.AuditOperation.UPDATE);
|
|
120
|
+
// 记录详细的实体变更数据
|
|
121
|
+
const changedFields = this.calculateChangedFields(databaseEntity || {}, entity);
|
|
122
|
+
this.contextService.recordDetailedEntityChange(entityType, entityId, enums_1.AuditOperation.UPDATE, databaseEntity || {}, entity, changedFields);
|
|
123
|
+
}
|
|
94
124
|
// 记录审计日志
|
|
95
125
|
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.UPDATE, databaseEntity || {}, entity, {
|
|
96
126
|
requestId: context.requestId,
|
|
97
127
|
requestIp: context.requestIp,
|
|
98
128
|
userAgent: context.userAgent,
|
|
129
|
+
auditActionId: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionId,
|
|
130
|
+
auditActionName: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionName,
|
|
131
|
+
sequenceInAction: (actionContext === null || actionContext === void 0 ? void 0 : actionContext.entityChanges.length) || 0,
|
|
99
132
|
});
|
|
100
133
|
}
|
|
101
134
|
catch (error) {
|
|
102
|
-
|
|
135
|
+
this.logger.error('Failed to log audit for update:', error);
|
|
103
136
|
}
|
|
104
137
|
});
|
|
105
138
|
}
|
|
@@ -113,6 +146,11 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
113
146
|
return;
|
|
114
147
|
const entityType = entity.constructor.name;
|
|
115
148
|
const entityId = entity.id;
|
|
149
|
+
// 空值安全检查:确保实体 ID 存在
|
|
150
|
+
if (!entityId) {
|
|
151
|
+
this.logger.warn(`Entity ID is missing for ${entityType}, skipping audit`);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
116
154
|
// 检查是否启用了审计
|
|
117
155
|
if (!this.isAuditEnabled(entity)) {
|
|
118
156
|
return;
|
|
@@ -124,18 +162,44 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
124
162
|
try {
|
|
125
163
|
// 获取上下文信息
|
|
126
164
|
const context = yield this.contextService.getCurrentContext();
|
|
165
|
+
const actionContext = this.contextService.getCurrentActionContext();
|
|
166
|
+
// 记录到审计动作上下文
|
|
167
|
+
if (actionContext) {
|
|
168
|
+
this.contextService.recordEntityChangeInAction(entityType, entityId, enums_1.AuditOperation.DELETE);
|
|
169
|
+
// 记录详细的实体变更数据
|
|
170
|
+
this.contextService.recordDetailedEntityChange(entityType, entityId, enums_1.AuditOperation.DELETE, entity, {}, Object.keys(entity));
|
|
171
|
+
}
|
|
127
172
|
// 记录审计日志
|
|
128
173
|
yield this.entityAuditService.logEntityChange(entityType, entityId, enums_1.AuditOperation.DELETE, entity, {}, {
|
|
129
174
|
requestId: context.requestId,
|
|
130
175
|
requestIp: context.requestIp,
|
|
131
176
|
userAgent: context.userAgent,
|
|
177
|
+
auditActionId: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionId,
|
|
178
|
+
auditActionName: actionContext === null || actionContext === void 0 ? void 0 : actionContext.actionName,
|
|
179
|
+
sequenceInAction: (actionContext === null || actionContext === void 0 ? void 0 : actionContext.entityChanges.length) || 0,
|
|
132
180
|
});
|
|
133
181
|
}
|
|
134
182
|
catch (error) {
|
|
135
|
-
|
|
183
|
+
this.logger.error('Failed to log audit for delete:', error);
|
|
136
184
|
}
|
|
137
185
|
});
|
|
138
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* 计算变更字段
|
|
189
|
+
*/
|
|
190
|
+
calculateChangedFields(oldValue, newValue) {
|
|
191
|
+
const changedFields = [];
|
|
192
|
+
const allKeys = new Set([
|
|
193
|
+
...Object.keys(oldValue || {}),
|
|
194
|
+
...Object.keys(newValue || {}),
|
|
195
|
+
]);
|
|
196
|
+
for (const key of allKeys) {
|
|
197
|
+
if (JSON.stringify(oldValue[key]) !== JSON.stringify(newValue[key])) {
|
|
198
|
+
changedFields.push(key);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return changedFields;
|
|
202
|
+
}
|
|
139
203
|
/**
|
|
140
204
|
* 检查是否启用了审计
|
|
141
205
|
*/
|
|
@@ -154,7 +218,7 @@ let EntityAuditSubscriber = class EntityAuditSubscriber {
|
|
|
154
218
|
}
|
|
155
219
|
};
|
|
156
220
|
exports.EntityAuditSubscriber = EntityAuditSubscriber;
|
|
157
|
-
exports.EntityAuditSubscriber = EntityAuditSubscriber = __decorate([
|
|
221
|
+
exports.EntityAuditSubscriber = EntityAuditSubscriber = EntityAuditSubscriber_1 = __decorate([
|
|
158
222
|
(0, common_1.Injectable)(),
|
|
159
223
|
(0, typeorm_1.EventSubscriber)(),
|
|
160
224
|
__metadata("design:paramtypes", [entity_audit_service_1.EntityAuditService,
|
package/cache/cache.module.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { DynamicModule, OnModuleInit } from '@nestjs/common';
|
|
2
|
-
import type { DataSource } from 'typeorm';
|
|
3
2
|
import type { Redis } from 'ioredis';
|
|
4
3
|
import { CacheService } from './cache.service';
|
|
5
4
|
/**
|
|
@@ -21,18 +20,18 @@ export interface CacheModuleOptions {
|
|
|
21
20
|
*/
|
|
22
21
|
redisClient?: Redis;
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
* If not provided, DbDependency will throw error when used
|
|
26
|
-
*/
|
|
27
|
-
dataSource?: DataSource;
|
|
28
|
-
/**
|
|
29
|
-
* Default TTL for memory cache in milliseconds
|
|
23
|
+
* Default TTL for LRU cache in milliseconds
|
|
30
24
|
*/
|
|
31
25
|
memoryTtl?: number;
|
|
32
26
|
/**
|
|
33
|
-
* Namespace for
|
|
27
|
+
* Namespace for LRU cache
|
|
34
28
|
*/
|
|
35
29
|
memoryNamespace?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Max size for LRU cache
|
|
32
|
+
* @default 500
|
|
33
|
+
*/
|
|
34
|
+
lruMaxSize?: number;
|
|
36
35
|
/**
|
|
37
36
|
* Enable compression for cache values
|
|
38
37
|
* @default false
|
package/cache/cache.module.js
CHANGED
|
@@ -80,10 +80,10 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
80
80
|
* Register cache module with options
|
|
81
81
|
*/
|
|
82
82
|
static forRoot(options = {}) {
|
|
83
|
-
const { isGlobal = true, redisClient,
|
|
84
|
-
// Set
|
|
85
|
-
if (
|
|
86
|
-
dependencies_1.
|
|
83
|
+
const { isGlobal = true, redisClient, memoryTtl, memoryNamespace, lruMaxSize = 500, enableCompression = false, compressionThreshold = 1024, } = options;
|
|
84
|
+
// Set Redis client for TagDependency for distributed tag support
|
|
85
|
+
if (redisClient) {
|
|
86
|
+
dependencies_1.TagDependency.setRedisClient(redisClient);
|
|
87
87
|
}
|
|
88
88
|
return {
|
|
89
89
|
module: CacheModule_1,
|
|
@@ -92,10 +92,11 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
92
92
|
// Providers
|
|
93
93
|
providers_1.ClsCacheProvider,
|
|
94
94
|
{
|
|
95
|
-
provide: providers_1.
|
|
96
|
-
useValue: new providers_1.
|
|
95
|
+
provide: providers_1.LRUCacheProvider,
|
|
96
|
+
useValue: new providers_1.LRUCacheProvider({
|
|
97
|
+
maxSize: lruMaxSize,
|
|
97
98
|
ttl: memoryTtl,
|
|
98
|
-
namespace: memoryNamespace,
|
|
99
|
+
namespace: memoryNamespace || 'cache:lru',
|
|
99
100
|
}),
|
|
100
101
|
},
|
|
101
102
|
// Redis client provider (optional)
|
|
@@ -159,15 +160,16 @@ let CacheModule = CacheModule_1 = class CacheModule {
|
|
|
159
160
|
// Providers
|
|
160
161
|
providers_1.ClsCacheProvider,
|
|
161
162
|
{
|
|
162
|
-
provide: providers_1.
|
|
163
|
+
provide: providers_1.LRUCacheProvider,
|
|
163
164
|
useFactory: (moduleOptions) => {
|
|
164
|
-
// Set
|
|
165
|
-
if (moduleOptions.
|
|
166
|
-
dependencies_1.
|
|
165
|
+
// Set Redis client for TagDependency for distributed tag support
|
|
166
|
+
if (moduleOptions.redisClient) {
|
|
167
|
+
dependencies_1.TagDependency.setRedisClient(moduleOptions.redisClient);
|
|
167
168
|
}
|
|
168
|
-
return new providers_1.
|
|
169
|
+
return new providers_1.LRUCacheProvider({
|
|
170
|
+
maxSize: moduleOptions.lruMaxSize || 500,
|
|
169
171
|
ttl: moduleOptions.memoryTtl,
|
|
170
|
-
namespace: moduleOptions.memoryNamespace,
|
|
172
|
+
namespace: moduleOptions.memoryNamespace || 'cache:lru',
|
|
171
173
|
});
|
|
172
174
|
},
|
|
173
175
|
inject: ['CACHE_MODULE_OPTIONS'],
|