@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,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSRF防护配置
|
|
3
|
+
*/
|
|
4
|
+
export interface SSRFProtectionConfig {
|
|
5
|
+
/** 是否启用SSRF防护 */
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** 允许的URL协议 */
|
|
8
|
+
allowedProtocols: string[];
|
|
9
|
+
/** 禁止访问的IP段(私有网络、本地回环等) */
|
|
10
|
+
blockedIPRanges: string[];
|
|
11
|
+
/** 允许的主机名白名单 */
|
|
12
|
+
allowedHostnames?: string[];
|
|
13
|
+
/** 禁止的主机名黑名单 */
|
|
14
|
+
blockedHostnames?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* URL验证配置
|
|
18
|
+
*/
|
|
19
|
+
export interface URLValidationConfig {
|
|
20
|
+
/** 最大URL长度 */
|
|
21
|
+
maxURLLength: number;
|
|
22
|
+
/** 是否允许本地回环地址 */
|
|
23
|
+
allowLoopback: boolean;
|
|
24
|
+
/** 是否允许私有网络地址 */
|
|
25
|
+
allowPrivateNetwork: boolean;
|
|
26
|
+
/** 是否允许Link-local地址 */
|
|
27
|
+
allowLinkLocal: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 安全验证工具类
|
|
31
|
+
* 提供URL验证、SSRF防护等功能
|
|
32
|
+
*/
|
|
33
|
+
export declare class SecurityValidator {
|
|
34
|
+
private static readonly logger;
|
|
35
|
+
/**
|
|
36
|
+
* 默认SSRF防护配置
|
|
37
|
+
*/
|
|
38
|
+
private static readonly defaultSSRFConfig;
|
|
39
|
+
/**
|
|
40
|
+
* 默认URL验证配置
|
|
41
|
+
*/
|
|
42
|
+
private static readonly defaultURLConfig;
|
|
43
|
+
/**
|
|
44
|
+
* 验证URL安全性
|
|
45
|
+
* @param url 要验证的URL字符串
|
|
46
|
+
* @param urlConfig URL验证配置
|
|
47
|
+
* @returns 验证结果和错误信息
|
|
48
|
+
*/
|
|
49
|
+
static validateURL(url: string, urlConfig?: Partial<URLValidationConfig>): {
|
|
50
|
+
valid: boolean;
|
|
51
|
+
error?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* SSRF防护检查
|
|
55
|
+
* @param url 要检查的URL
|
|
56
|
+
* @param ssrfConfig SSRF防护配置
|
|
57
|
+
* @returns 检查结果和错误信息
|
|
58
|
+
*/
|
|
59
|
+
static checkSSRF(url: string, ssrfConfig?: Partial<SSRFProtectionConfig>): {
|
|
60
|
+
safe: boolean;
|
|
61
|
+
error?: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* 清理和验证URL
|
|
65
|
+
* 综合验证和SSRF防护
|
|
66
|
+
* @param url 要清理的URL
|
|
67
|
+
* @param config 完整的安全配置
|
|
68
|
+
* @returns 清理后的URL和验证结果
|
|
69
|
+
*/
|
|
70
|
+
static sanitizeURL(url: string, config?: {
|
|
71
|
+
urlConfig?: Partial<URLValidationConfig>;
|
|
72
|
+
ssrfConfig?: Partial<SSRFProtectionConfig>;
|
|
73
|
+
}): {
|
|
74
|
+
url: string;
|
|
75
|
+
valid: boolean;
|
|
76
|
+
error?: string;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* 敏感数据检测
|
|
80
|
+
* 检查数据中是否包含敏感信息(如密码、token等)
|
|
81
|
+
* @param data 要检查的数据对象
|
|
82
|
+
* @param additionalPatterns 额外的敏感数据模式
|
|
83
|
+
* @returns 检测结果
|
|
84
|
+
*/
|
|
85
|
+
static detectSensitiveData(data: any, additionalPatterns?: RegExp[]): {
|
|
86
|
+
hasSensitiveData: boolean;
|
|
87
|
+
fields: string[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* 获取默认SSRF防护配置
|
|
91
|
+
*/
|
|
92
|
+
static getDefaultSSRFConfig(): SSRFProtectionConfig;
|
|
93
|
+
/**
|
|
94
|
+
* 获取默认URL验证配置
|
|
95
|
+
*/
|
|
96
|
+
static getDefaultURLConfig(): URLValidationConfig;
|
|
97
|
+
/**
|
|
98
|
+
* 从主机名中提取IP地址
|
|
99
|
+
*/
|
|
100
|
+
private static extractIPAddress;
|
|
101
|
+
/**
|
|
102
|
+
* 验证IP地址
|
|
103
|
+
*/
|
|
104
|
+
private static validateIPAddress;
|
|
105
|
+
/**
|
|
106
|
+
* 检查IP地址是否在阻止的范围内
|
|
107
|
+
*/
|
|
108
|
+
private static checkIPRange;
|
|
109
|
+
/**
|
|
110
|
+
* 检查IP地址是否在指定范围内
|
|
111
|
+
* 简化版本,主要用于常见CIDR范围
|
|
112
|
+
*/
|
|
113
|
+
private static isIPInRange;
|
|
114
|
+
/**
|
|
115
|
+
* 验证主机名格式
|
|
116
|
+
*/
|
|
117
|
+
private static isValidHostname;
|
|
118
|
+
}
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecurityValidator = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
/**
|
|
6
|
+
* 安全验证工具类
|
|
7
|
+
* 提供URL验证、SSRF防护等功能
|
|
8
|
+
*/
|
|
9
|
+
class SecurityValidator {
|
|
10
|
+
/**
|
|
11
|
+
* 验证URL安全性
|
|
12
|
+
* @param url 要验证的URL字符串
|
|
13
|
+
* @param urlConfig URL验证配置
|
|
14
|
+
* @returns 验证结果和错误信息
|
|
15
|
+
*/
|
|
16
|
+
static validateURL(url, urlConfig = {}) {
|
|
17
|
+
const config = Object.assign(Object.assign({}, this.defaultURLConfig), urlConfig);
|
|
18
|
+
// 检查URL长度
|
|
19
|
+
if (url.length > config.maxURLLength) {
|
|
20
|
+
return {
|
|
21
|
+
valid: false,
|
|
22
|
+
error: `URL length exceeds maximum allowed length of ${config.maxURLLength}`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
let parsedURL;
|
|
26
|
+
try {
|
|
27
|
+
parsedURL = new URL(url);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return {
|
|
31
|
+
valid: false,
|
|
32
|
+
error: `Invalid URL format: ${error instanceof Error ? error.message : String(error)}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
// 检查协议
|
|
36
|
+
if (!['http:', 'https:', 'ws:', 'wss:'].includes(parsedURL.protocol)) {
|
|
37
|
+
return {
|
|
38
|
+
valid: false,
|
|
39
|
+
error: `Unsupported protocol: ${parsedURL.protocol}`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// 检查主机名
|
|
43
|
+
if (!parsedURL.hostname) {
|
|
44
|
+
return {
|
|
45
|
+
valid: false,
|
|
46
|
+
error: 'Hostname is required',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// 检查是否为IP地址
|
|
50
|
+
const ipAddress = this.extractIPAddress(parsedURL.hostname);
|
|
51
|
+
if (ipAddress) {
|
|
52
|
+
return this.validateIPAddress(ipAddress, config);
|
|
53
|
+
}
|
|
54
|
+
// 检查主机名格式
|
|
55
|
+
if (!this.isValidHostname(parsedURL.hostname)) {
|
|
56
|
+
return {
|
|
57
|
+
valid: false,
|
|
58
|
+
error: `Invalid hostname format: ${parsedURL.hostname}`,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return { valid: true };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* SSRF防护检查
|
|
65
|
+
* @param url 要检查的URL
|
|
66
|
+
* @param ssrfConfig SSRF防护配置
|
|
67
|
+
* @returns 检查结果和错误信息
|
|
68
|
+
*/
|
|
69
|
+
static checkSSRF(url, ssrfConfig = {}) {
|
|
70
|
+
const config = Object.assign(Object.assign({}, this.defaultSSRFConfig), ssrfConfig);
|
|
71
|
+
if (!config.enabled) {
|
|
72
|
+
return { safe: true };
|
|
73
|
+
}
|
|
74
|
+
let parsedURL;
|
|
75
|
+
try {
|
|
76
|
+
parsedURL = new URL(url);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return {
|
|
80
|
+
safe: false,
|
|
81
|
+
error: `Invalid URL format: ${error instanceof Error ? error.message : String(error)}`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// 检查协议
|
|
85
|
+
if (!config.allowedProtocols.includes(parsedURL.protocol)) {
|
|
86
|
+
return {
|
|
87
|
+
safe: false,
|
|
88
|
+
error: `Protocol not allowed: ${parsedURL.protocol}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
// 检查黑名单主机名
|
|
92
|
+
if (config.blockedHostnames) {
|
|
93
|
+
if (config.blockedHostnames.includes(parsedURL.hostname)) {
|
|
94
|
+
return {
|
|
95
|
+
safe: false,
|
|
96
|
+
error: `Hostname is blocked: ${parsedURL.hostname}`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// 检查白名单主机名(如果配置了)
|
|
101
|
+
if (config.allowedHostnames && config.allowedHostnames.length > 0) {
|
|
102
|
+
if (!config.allowedHostnames.includes(parsedURL.hostname)) {
|
|
103
|
+
return {
|
|
104
|
+
safe: false,
|
|
105
|
+
error: `Hostname not in whitelist: ${parsedURL.hostname}`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 检查IP地址范围
|
|
110
|
+
const ipAddress = this.extractIPAddress(parsedURL.hostname);
|
|
111
|
+
if (ipAddress) {
|
|
112
|
+
const ipCheck = this.checkIPRange(ipAddress, config.blockedIPRanges);
|
|
113
|
+
if (!ipCheck.allowed) {
|
|
114
|
+
return {
|
|
115
|
+
safe: false,
|
|
116
|
+
error: `IP address is blocked: ${ipAddress} (${ipCheck.reason})`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { safe: true };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 清理和验证URL
|
|
124
|
+
* 综合验证和SSRF防护
|
|
125
|
+
* @param url 要清理的URL
|
|
126
|
+
* @param config 完整的安全配置
|
|
127
|
+
* @returns 清理后的URL和验证结果
|
|
128
|
+
*/
|
|
129
|
+
static sanitizeURL(url, config = {}) {
|
|
130
|
+
// 去除首尾空格
|
|
131
|
+
let sanitizedURL = url.trim();
|
|
132
|
+
// 移除可能的换行符和控制字符
|
|
133
|
+
sanitizedURL = sanitizedURL.replace(/[\r\n\t]/g, '');
|
|
134
|
+
// 验证URL格式
|
|
135
|
+
const validationResult = this.validateURL(sanitizedURL, config.urlConfig);
|
|
136
|
+
if (!validationResult.valid) {
|
|
137
|
+
return { url: sanitizedURL, valid: false, error: validationResult.error };
|
|
138
|
+
}
|
|
139
|
+
// SSRF防护检查
|
|
140
|
+
const ssrfResult = this.checkSSRF(sanitizedURL, config.ssrfConfig);
|
|
141
|
+
if (!ssrfResult.safe) {
|
|
142
|
+
return { url: sanitizedURL, valid: false, error: ssrfResult.error };
|
|
143
|
+
}
|
|
144
|
+
return { url: sanitizedURL, valid: true };
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 敏感数据检测
|
|
148
|
+
* 检查数据中是否包含敏感信息(如密码、token等)
|
|
149
|
+
* @param data 要检查的数据对象
|
|
150
|
+
* @param additionalPatterns 额外的敏感数据模式
|
|
151
|
+
* @returns 检测结果
|
|
152
|
+
*/
|
|
153
|
+
static detectSensitiveData(data, additionalPatterns = []) {
|
|
154
|
+
const sensitiveFields = [];
|
|
155
|
+
// 默认敏感字段名模式
|
|
156
|
+
const defaultPatterns = [
|
|
157
|
+
/password/i,
|
|
158
|
+
/secret/i,
|
|
159
|
+
/token/i,
|
|
160
|
+
/api[_-]?key/i,
|
|
161
|
+
/authorization/i,
|
|
162
|
+
/credential/i,
|
|
163
|
+
/private[_-]?key/i,
|
|
164
|
+
/access[_-]?token/i,
|
|
165
|
+
/refresh[_-]?token/i,
|
|
166
|
+
/session[_-]?id/i,
|
|
167
|
+
/csrf/i,
|
|
168
|
+
/ssn/i,
|
|
169
|
+
/credit[_-]?card/i,
|
|
170
|
+
];
|
|
171
|
+
const allPatterns = [...defaultPatterns, ...additionalPatterns];
|
|
172
|
+
const checkObject = (obj, path = '') => {
|
|
173
|
+
if (!obj || typeof obj !== 'object') {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
for (const key in obj) {
|
|
177
|
+
if (!obj.hasOwnProperty(key)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
181
|
+
// 检查键名是否匹配敏感模式
|
|
182
|
+
if (allPatterns.some((pattern) => pattern.test(key))) {
|
|
183
|
+
sensitiveFields.push(currentPath);
|
|
184
|
+
}
|
|
185
|
+
// 递归检查嵌套对象
|
|
186
|
+
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
187
|
+
checkObject(obj[key], currentPath);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
checkObject(data);
|
|
192
|
+
return {
|
|
193
|
+
hasSensitiveData: sensitiveFields.length > 0,
|
|
194
|
+
fields: sensitiveFields,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 获取默认SSRF防护配置
|
|
199
|
+
*/
|
|
200
|
+
static getDefaultSSRFConfig() {
|
|
201
|
+
return Object.assign({}, this.defaultSSRFConfig);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 获取默认URL验证配置
|
|
205
|
+
*/
|
|
206
|
+
static getDefaultURLConfig() {
|
|
207
|
+
return Object.assign({}, this.defaultURLConfig);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* 从主机名中提取IP地址
|
|
211
|
+
*/
|
|
212
|
+
static extractIPAddress(hostname) {
|
|
213
|
+
// IPv4地址
|
|
214
|
+
const ipv4Regex = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
215
|
+
const ipv4Match = hostname.match(ipv4Regex);
|
|
216
|
+
if (ipv4Match) {
|
|
217
|
+
return hostname;
|
|
218
|
+
}
|
|
219
|
+
// IPv6地址(简化版)
|
|
220
|
+
if (hostname.includes(':') && !hostname.includes('.')) {
|
|
221
|
+
return hostname;
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 验证IP地址
|
|
227
|
+
*/
|
|
228
|
+
static validateIPAddress(ipAddress, config) {
|
|
229
|
+
// 检查是否为本地回环地址
|
|
230
|
+
if (!config.allowLoopback) {
|
|
231
|
+
if (ipAddress === '127.0.0.1' ||
|
|
232
|
+
ipAddress === '::1' ||
|
|
233
|
+
ipAddress.startsWith('127.')) {
|
|
234
|
+
return {
|
|
235
|
+
valid: false,
|
|
236
|
+
error: 'Loopback addresses are not allowed',
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// 检查是否为私有网络地址
|
|
241
|
+
if (!config.allowPrivateNetwork) {
|
|
242
|
+
if (ipAddress.startsWith('10.') ||
|
|
243
|
+
ipAddress.startsWith('172.16.') ||
|
|
244
|
+
ipAddress.startsWith('192.168.') ||
|
|
245
|
+
ipAddress.startsWith('fc00:') ||
|
|
246
|
+
ipAddress.startsWith('fd')) {
|
|
247
|
+
return {
|
|
248
|
+
valid: false,
|
|
249
|
+
error: 'Private network addresses are not allowed',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// 检查是否为Link-local地址
|
|
254
|
+
if (!config.allowLinkLocal) {
|
|
255
|
+
if (ipAddress.startsWith('169.254.') || ipAddress.startsWith('fe80:')) {
|
|
256
|
+
return {
|
|
257
|
+
valid: false,
|
|
258
|
+
error: 'Link-local addresses are not allowed',
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return { valid: true };
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* 检查IP地址是否在阻止的范围内
|
|
266
|
+
*/
|
|
267
|
+
static checkIPRange(ipAddress, blockedRanges) {
|
|
268
|
+
for (const range of blockedRanges) {
|
|
269
|
+
if (this.isIPInRange(ipAddress, range)) {
|
|
270
|
+
return {
|
|
271
|
+
allowed: false,
|
|
272
|
+
reason: `IP address is in blocked range: ${range}`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return { allowed: true };
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* 检查IP地址是否在指定范围内
|
|
280
|
+
* 简化版本,主要用于常见CIDR范围
|
|
281
|
+
*/
|
|
282
|
+
static isIPInRange(ipAddress, cidrRange) {
|
|
283
|
+
// 处理IPv4 CIDR
|
|
284
|
+
const [range, prefixStr] = cidrRange.split('/');
|
|
285
|
+
const prefix = parseInt(prefixStr, 10);
|
|
286
|
+
// 精确匹配
|
|
287
|
+
if (ipAddress === range) {
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
// 简化的CIDR匹配(仅支持常见范围)
|
|
291
|
+
if (cidrRange.includes('/')) {
|
|
292
|
+
// IPv4范围检查
|
|
293
|
+
if (range.includes('.') && ipAddress.includes('.')) {
|
|
294
|
+
const rangeParts = range.split('.').map(Number);
|
|
295
|
+
const ipParts = ipAddress.split('.').map(Number);
|
|
296
|
+
if (prefix === 8) {
|
|
297
|
+
return ipParts[0] === rangeParts[0];
|
|
298
|
+
}
|
|
299
|
+
else if (prefix === 16) {
|
|
300
|
+
return ipParts[0] === rangeParts[0] && ipParts[1] === rangeParts[1];
|
|
301
|
+
}
|
|
302
|
+
else if (prefix === 24) {
|
|
303
|
+
return (ipParts[0] === rangeParts[0] &&
|
|
304
|
+
ipParts[1] === rangeParts[1] &&
|
|
305
|
+
ipParts[2] === rangeParts[2]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* 验证主机名格式
|
|
313
|
+
*/
|
|
314
|
+
static isValidHostname(hostname) {
|
|
315
|
+
// RFC 1123主机名规范
|
|
316
|
+
const hostnameRegex = /^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$/;
|
|
317
|
+
return hostnameRegex.test(hostname);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.SecurityValidator = SecurityValidator;
|
|
321
|
+
SecurityValidator.logger = new common_1.Logger(SecurityValidator.name);
|
|
322
|
+
/**
|
|
323
|
+
* 默认SSRF防护配置
|
|
324
|
+
*/
|
|
325
|
+
SecurityValidator.defaultSSRFConfig = {
|
|
326
|
+
enabled: true,
|
|
327
|
+
allowedProtocols: ['http:', 'https:'],
|
|
328
|
+
blockedIPRanges: [
|
|
329
|
+
'127.0.0.0/8', // Loopback
|
|
330
|
+
'10.0.0.0/8', // Private Class A
|
|
331
|
+
'172.16.0.0/12', // Private Class B
|
|
332
|
+
'192.168.0.0/16', // Private Class C
|
|
333
|
+
'169.254.0.0/16', // Link-local
|
|
334
|
+
'::1/128', // IPv6 loopback
|
|
335
|
+
'fc00::/7', // IPv6 private
|
|
336
|
+
'fe80::/10', // IPv6 link-local
|
|
337
|
+
'0.0.0.0/8', // Current network
|
|
338
|
+
],
|
|
339
|
+
allowedHostnames: undefined,
|
|
340
|
+
blockedHostnames: [
|
|
341
|
+
'localhost',
|
|
342
|
+
'metadata.google.internal', // GCP metadata
|
|
343
|
+
'169.254.169.254', // AWS/GCP/Azure metadata
|
|
344
|
+
],
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* 默认URL验证配置
|
|
348
|
+
*/
|
|
349
|
+
SecurityValidator.defaultURLConfig = {
|
|
350
|
+
maxURLLength: 2000,
|
|
351
|
+
allowLoopback: false,
|
|
352
|
+
allowPrivateNetwork: false,
|
|
353
|
+
allowLinkLocal: false,
|
|
354
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './common';
|
|
1
2
|
export * from './constants';
|
|
2
3
|
export * from './decorators';
|
|
3
4
|
export * from './exceptions';
|
|
@@ -7,7 +8,6 @@ export * from './interceptors';
|
|
|
7
8
|
export * from './shared';
|
|
8
9
|
export * from './middlewares';
|
|
9
10
|
export * from './validators';
|
|
10
|
-
export * from './common';
|
|
11
11
|
export * from './validator-json';
|
|
12
12
|
export * from './helpers';
|
|
13
13
|
export * from './providers';
|
|
@@ -18,3 +18,6 @@ export * from './vault';
|
|
|
18
18
|
export * from './setup';
|
|
19
19
|
export * from './health-checker';
|
|
20
20
|
export * from './audit';
|
|
21
|
+
export * from './file-upload';
|
|
22
|
+
export * from './email-log';
|
|
23
|
+
export * from '@nest-omni/transaction';
|
package/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
// Core modules
|
|
18
|
+
__exportStar(require("./common"), exports);
|
|
18
19
|
__exportStar(require("./constants"), exports);
|
|
19
20
|
__exportStar(require("./decorators"), exports);
|
|
20
21
|
__exportStar(require("./exceptions"), exports);
|
|
@@ -24,7 +25,6 @@ __exportStar(require("./interceptors"), exports);
|
|
|
24
25
|
__exportStar(require("./shared"), exports);
|
|
25
26
|
__exportStar(require("./middlewares"), exports);
|
|
26
27
|
__exportStar(require("./validators"), exports);
|
|
27
|
-
__exportStar(require("./common"), exports);
|
|
28
28
|
__exportStar(require("./validator-json"), exports);
|
|
29
29
|
__exportStar(require("./helpers"), exports);
|
|
30
30
|
__exportStar(require("./providers"), exports);
|
|
@@ -42,3 +42,8 @@ __exportStar(require("./setup"), exports);
|
|
|
42
42
|
__exportStar(require("./health-checker"), exports);
|
|
43
43
|
// Audit module
|
|
44
44
|
__exportStar(require("./audit"), exports);
|
|
45
|
+
// File upload module
|
|
46
|
+
__exportStar(require("./file-upload"), exports);
|
|
47
|
+
// Email log module
|
|
48
|
+
__exportStar(require("./email-log"), exports);
|
|
49
|
+
__exportStar(require("@nest-omni/transaction"), exports);
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
2
2
|
import type { Observable } from 'rxjs';
|
|
3
|
+
import { TranslationService } from '../shared/services/translation.service';
|
|
4
|
+
/**
|
|
5
|
+
* 翻译拦截器
|
|
6
|
+
* 自动翻译响应数据中标记为需要翻译的字段
|
|
7
|
+
*/
|
|
3
8
|
export declare class TranslationInterceptor implements NestInterceptor {
|
|
9
|
+
private readonly translationService?;
|
|
10
|
+
constructor(translationService?: TranslationService);
|
|
4
11
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any>;
|
|
5
12
|
}
|
|
@@ -5,35 +5,67 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
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
|
+
};
|
|
8
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
24
|
exports.TranslationInterceptor = void 0;
|
|
10
25
|
const common_1 = require("@nestjs/common");
|
|
11
26
|
const operators_1 = require("rxjs/operators");
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
const translation_service_1 = require("../shared/services/translation.service");
|
|
28
|
+
/**
|
|
29
|
+
* 翻译拦截器
|
|
30
|
+
* 自动翻译响应数据中标记为需要翻译的字段
|
|
31
|
+
*/
|
|
14
32
|
let TranslationInterceptor = class TranslationInterceptor {
|
|
15
|
-
|
|
33
|
+
constructor(translationService) {
|
|
34
|
+
this.translationService = translationService;
|
|
35
|
+
}
|
|
16
36
|
intercept(context, next) {
|
|
17
37
|
const ctx = context.switchToHttp();
|
|
18
38
|
const req = ctx.getRequest();
|
|
19
39
|
const res = ctx.getResponse();
|
|
20
|
-
return next.handle().pipe((0, operators_1.map)((data) => {
|
|
21
|
-
//
|
|
40
|
+
return next.handle().pipe((0, operators_1.map)((data) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
// 如果 TranslationService 可用,翻译响应数据
|
|
42
|
+
let translatedData = data;
|
|
43
|
+
if (this.translationService) {
|
|
44
|
+
try {
|
|
45
|
+
translatedData = yield this.translationService.translateNecessaryKeys(data);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
// 翻译失败时返回原始数据,不中断请求
|
|
49
|
+
translatedData = data;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
22
52
|
// status 201 => 200
|
|
23
53
|
if (res.statusCode === common_1.HttpStatus.CREATED) {
|
|
24
54
|
res.status(common_1.HttpStatus.OK);
|
|
25
55
|
}
|
|
26
56
|
return {
|
|
27
57
|
code: 200,
|
|
28
|
-
data,
|
|
58
|
+
data: translatedData,
|
|
29
59
|
msg: 'success',
|
|
30
60
|
requestId: req.id,
|
|
31
61
|
timestamp: new Date().toISOString(),
|
|
32
62
|
};
|
|
33
|
-
}));
|
|
63
|
+
})));
|
|
34
64
|
}
|
|
35
65
|
};
|
|
36
66
|
exports.TranslationInterceptor = TranslationInterceptor;
|
|
37
67
|
exports.TranslationInterceptor = TranslationInterceptor = __decorate([
|
|
38
|
-
(0, common_1.Injectable)()
|
|
68
|
+
(0, common_1.Injectable)(),
|
|
69
|
+
__param(0, (0, common_1.Optional)()),
|
|
70
|
+
__metadata("design:paramtypes", [translation_service_1.TranslationService])
|
|
39
71
|
], TranslationInterceptor);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP过滤元数据键名
|
|
3
|
+
* 用于在路由元数据中存储IP过滤配置
|
|
4
|
+
*/
|
|
5
|
+
export declare const IP_FILTER_KEY = "ip_filter";
|
|
6
|
+
/**
|
|
7
|
+
* IP过滤选项依赖注入键名
|
|
8
|
+
*/
|
|
9
|
+
export declare const IP_FILTER_OPTIONS = "IP_FILTER_OPTIONS";
|
|
10
|
+
/**
|
|
11
|
+
* 默认错误消息
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_ERROR_MESSAGE = "Access denied: Your IP address is not authorized";
|
|
14
|
+
/**
|
|
15
|
+
* 默认HTTP状态码
|
|
16
|
+
*/
|
|
17
|
+
export declare const DEFAULT_ERROR_STATUS_CODE = 403;
|
|
18
|
+
/**
|
|
19
|
+
* 默认优先级
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_PRIORITY = 50;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_PRIORITY = exports.DEFAULT_ERROR_STATUS_CODE = exports.DEFAULT_ERROR_MESSAGE = exports.IP_FILTER_OPTIONS = exports.IP_FILTER_KEY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* IP过滤元数据键名
|
|
6
|
+
* 用于在路由元数据中存储IP过滤配置
|
|
7
|
+
*/
|
|
8
|
+
exports.IP_FILTER_KEY = 'ip_filter';
|
|
9
|
+
/**
|
|
10
|
+
* IP过滤选项依赖注入键名
|
|
11
|
+
*/
|
|
12
|
+
exports.IP_FILTER_OPTIONS = 'IP_FILTER_OPTIONS';
|
|
13
|
+
/**
|
|
14
|
+
* 默认错误消息
|
|
15
|
+
*/
|
|
16
|
+
exports.DEFAULT_ERROR_MESSAGE = 'Access denied: Your IP address is not authorized';
|
|
17
|
+
/**
|
|
18
|
+
* 默认HTTP状态码
|
|
19
|
+
*/
|
|
20
|
+
exports.DEFAULT_ERROR_STATUS_CODE = 403;
|
|
21
|
+
/**
|
|
22
|
+
* 默认优先级
|
|
23
|
+
*/
|
|
24
|
+
exports.DEFAULT_PRIORITY = 50;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ip-filter.decorator';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./ip-filter.decorator"), exports);
|