@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
|
@@ -1,37 +1,119 @@
|
|
|
1
1
|
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
-
import { CacheOptions } from '../../cache/interfaces/cache-options.interface';
|
|
3
2
|
import { LogCleanupConfig } from '../services/log-cleanup.service';
|
|
3
|
+
import { SSRFProtectionConfig, URLValidationConfig } from '../utils/security-validator.util';
|
|
4
|
+
import type { AgentOptions } from 'https';
|
|
5
|
+
/**
|
|
6
|
+
* SSL/TLS 证书配置
|
|
7
|
+
* 兼容 Node.js https.Agent 的选项
|
|
8
|
+
* 参考: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
|
|
9
|
+
*/
|
|
10
|
+
export interface SslCertificateConfig extends Partial<Omit<AgentOptions, 'host' | 'port' | 'path'>> {
|
|
11
|
+
/**
|
|
12
|
+
* 是否禁用证书验证(仅用于开发/测试环境)
|
|
13
|
+
* 警告:设置为 true 会使连接不安全,生产环境严禁使用
|
|
14
|
+
*/
|
|
15
|
+
rejectUnauthorized?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* CA 证书内容(PEM 格式)
|
|
18
|
+
* 可以是单个证书或多个证书的字符串
|
|
19
|
+
*/
|
|
20
|
+
ca?: string | string[] | Buffer;
|
|
21
|
+
/**
|
|
22
|
+
* 客户端证书内容(PEM 格式)
|
|
23
|
+
*/
|
|
24
|
+
cert?: string | string[] | Buffer;
|
|
25
|
+
/**
|
|
26
|
+
* 客户端私钥内容(PEM 格式)
|
|
27
|
+
*/
|
|
28
|
+
key?: string | string[] | Buffer;
|
|
29
|
+
/**
|
|
30
|
+
* 私钥密码
|
|
31
|
+
*/
|
|
32
|
+
passphrase?: string;
|
|
33
|
+
/**
|
|
34
|
+
* 服务器名称(用于 SNI)
|
|
35
|
+
*/
|
|
36
|
+
servername?: string;
|
|
37
|
+
/**
|
|
38
|
+
* 支持的 TLS 版本
|
|
39
|
+
*/
|
|
40
|
+
minVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
|
|
41
|
+
maxVersion?: 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
|
|
42
|
+
/**
|
|
43
|
+
* 支持的加密套件
|
|
44
|
+
*/
|
|
45
|
+
ciphers?: string;
|
|
46
|
+
/**
|
|
47
|
+
* 是否支持 DH 参数
|
|
48
|
+
*/
|
|
49
|
+
dhparam?: string | Buffer;
|
|
50
|
+
/**
|
|
51
|
+
* 是否使用安全 renegotiation
|
|
52
|
+
*/
|
|
53
|
+
secureOptions?: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Axios 原生配置透传
|
|
57
|
+
* 基于 AxiosRequestConfig,排除已在 HttpClientConfig 中定义的字段
|
|
58
|
+
*
|
|
59
|
+
* 使用方式:
|
|
60
|
+
* - 直接传 Axios 原生配置对象
|
|
61
|
+
* - 类型安全,支持所有 Axios 配置项
|
|
62
|
+
* - ssl 配置会被自动转换为 httpsAgent
|
|
63
|
+
*/
|
|
64
|
+
export type AxiosNativeConfig = Omit<AxiosRequestConfig, 'baseURL' | 'timeout' | 'proxy' | 'url' | 'method' | 'data' | 'headers' | 'params'> & {
|
|
65
|
+
/**
|
|
66
|
+
* SSL/TLS 证书配置(简化版)
|
|
67
|
+
* 会自动转换为 httpsAgent,优先级高于直接指定的 httpsAgent
|
|
68
|
+
*/
|
|
69
|
+
ssl?: SslCertificateConfig;
|
|
70
|
+
};
|
|
4
71
|
/**
|
|
5
72
|
* HTTP客户端配置接口
|
|
6
73
|
* 基于Spring Boot的@ConfigurationProperties设计理念
|
|
74
|
+
* 所有字段都是可选的,模块会使用合理的默认值
|
|
7
75
|
*/
|
|
8
76
|
export interface HttpClientConfig {
|
|
9
77
|
/** 基础配置 */
|
|
10
78
|
baseURL?: string;
|
|
11
79
|
timeout?: number;
|
|
12
80
|
/** 重试配置 */
|
|
13
|
-
retry?: RetryConfig
|
|
81
|
+
retry?: Partial<RetryConfig>;
|
|
14
82
|
/** 熔断器配置 */
|
|
15
|
-
circuitBreaker?: CircuitBreakerConfig
|
|
16
|
-
/** 缓存配置 */
|
|
17
|
-
cache?: HttpCacheConfig;
|
|
83
|
+
circuitBreaker?: Partial<CircuitBreakerConfig>;
|
|
18
84
|
/** 代理配置 */
|
|
19
|
-
proxy?: ProxyConfig
|
|
85
|
+
proxy?: Partial<ProxyConfig>;
|
|
20
86
|
/** 日志配置 */
|
|
21
|
-
logging?: LoggingConfig
|
|
87
|
+
logging?: Partial<LoggingConfig>;
|
|
22
88
|
/** 日志清理配置 */
|
|
23
|
-
logCleanup?: LogCleanupConfig
|
|
89
|
+
logCleanup?: Partial<LogCleanupConfig>;
|
|
24
90
|
/** 拦截器配置 */
|
|
25
|
-
interceptors?: InterceptorConfig
|
|
91
|
+
interceptors?: Partial<InterceptorConfig>;
|
|
26
92
|
/** 连接池配置 */
|
|
27
|
-
connectionPool?: ConnectionPoolConfig
|
|
93
|
+
connectionPool?: Partial<ConnectionPoolConfig>;
|
|
94
|
+
/** 安全配置 */
|
|
95
|
+
security?: {
|
|
96
|
+
/** URL验证配置 */
|
|
97
|
+
urlValidation?: Partial<URLValidationConfig>;
|
|
98
|
+
/** SSRF防护配置 */
|
|
99
|
+
ssrfProtection?: Partial<SSRFProtectionConfig>;
|
|
100
|
+
/** 是否启用安全验证 */
|
|
101
|
+
enabled?: boolean;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Axios 原生配置透传
|
|
105
|
+
* 用于直接传递 Axios 支持的任何配置项,提供最大灵活性
|
|
106
|
+
* 优先级低于上述显式配置,会进行深度合并
|
|
107
|
+
*/
|
|
108
|
+
axiosConfig?: AxiosNativeConfig;
|
|
28
109
|
}
|
|
29
110
|
/**
|
|
30
111
|
* 重试配置
|
|
31
112
|
* 基于axios-retry库的配置
|
|
113
|
+
* 所有字段都是可选的
|
|
32
114
|
*/
|
|
33
115
|
export interface RetryConfig {
|
|
34
|
-
enabled
|
|
116
|
+
enabled?: boolean;
|
|
35
117
|
retries?: number;
|
|
36
118
|
retryDelay?: (retryCount: number) => number;
|
|
37
119
|
retryCondition?: (error: any) => boolean;
|
|
@@ -41,82 +123,80 @@ export interface RetryConfig {
|
|
|
41
123
|
/**
|
|
42
124
|
* 熔断器配置
|
|
43
125
|
* 类似Spring Cloud CircuitBreaker
|
|
126
|
+
* 所有字段都是可选的
|
|
44
127
|
*/
|
|
45
128
|
export interface CircuitBreakerConfig {
|
|
46
|
-
enabled
|
|
47
|
-
failureThreshold
|
|
48
|
-
recoveryTimeoutMs
|
|
49
|
-
monitoringPeriodMs
|
|
50
|
-
minimumThroughputThreshold
|
|
51
|
-
countHalfOpenCalls
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* HTTP缓存配置
|
|
55
|
-
* 集成现有的三层缓存架构
|
|
56
|
-
*/
|
|
57
|
-
export interface HttpCacheConfig {
|
|
58
|
-
enabled: boolean;
|
|
59
|
-
/** 缓存选项,使用core中的CacheOptions */
|
|
60
|
-
options?: Omit<CacheOptions, 'ttl' | 'namespace'>;
|
|
61
|
-
/** 默认TTL(毫秒) */
|
|
62
|
-
defaultTtl?: number;
|
|
63
|
-
/** 可缓存的方法 */
|
|
64
|
-
cacheableMethods: string[];
|
|
65
|
-
/** 可缓存的状态码 */
|
|
66
|
-
cacheableStatusCodes: number[];
|
|
67
|
-
/** 自定义缓存键生成器 */
|
|
68
|
-
keyGenerator?: (config: AxiosRequestConfig) => string;
|
|
129
|
+
enabled?: boolean;
|
|
130
|
+
failureThreshold?: number;
|
|
131
|
+
recoveryTimeoutMs?: number;
|
|
132
|
+
monitoringPeriodMs?: number;
|
|
133
|
+
minimumThroughputThreshold?: number;
|
|
134
|
+
countHalfOpenCalls?: boolean;
|
|
69
135
|
}
|
|
70
136
|
/**
|
|
71
137
|
* 代理配置
|
|
138
|
+
* 所有字段都是可选的
|
|
72
139
|
*/
|
|
73
140
|
export interface ProxyConfig {
|
|
74
|
-
enabled
|
|
141
|
+
enabled?: boolean;
|
|
142
|
+
/** 是否从环境变量读取代理配置 (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) */
|
|
143
|
+
fromEnvironment?: boolean;
|
|
144
|
+
/** 手动指定的代理主机 (当 fromEnvironment 为 false 时使用) */
|
|
75
145
|
host?: string;
|
|
146
|
+
/** 手动指定的代理端口 (当 fromEnvironment 为 false 时使用) */
|
|
76
147
|
port?: number;
|
|
148
|
+
/** 代理协议 */
|
|
77
149
|
protocol?: 'http' | 'https';
|
|
150
|
+
/** 代理认证信息 */
|
|
78
151
|
auth?: {
|
|
79
|
-
username
|
|
80
|
-
password
|
|
152
|
+
username?: string;
|
|
153
|
+
password?: string;
|
|
81
154
|
};
|
|
82
155
|
}
|
|
83
156
|
/**
|
|
84
157
|
* 日志配置
|
|
85
158
|
* 类似Spring Boot的logging配置
|
|
159
|
+
* 所有字段都是可选的
|
|
86
160
|
*/
|
|
87
161
|
export interface LoggingConfig {
|
|
88
|
-
enabled
|
|
89
|
-
logRequests
|
|
90
|
-
logResponses
|
|
91
|
-
logErrors
|
|
92
|
-
logHeaders
|
|
93
|
-
logBody
|
|
94
|
-
maxBodyLength
|
|
95
|
-
|
|
96
|
-
|
|
162
|
+
enabled?: boolean;
|
|
163
|
+
logRequests?: boolean;
|
|
164
|
+
logResponses?: boolean;
|
|
165
|
+
logErrors?: boolean;
|
|
166
|
+
logHeaders?: boolean;
|
|
167
|
+
logBody?: boolean;
|
|
168
|
+
maxBodyLength?: number;
|
|
169
|
+
/**
|
|
170
|
+
* 脱敏配置
|
|
171
|
+
* 敏感字段列表,统一适用于 headers、body、query string
|
|
172
|
+
* 例如:['password', 'token', 'secret', 'apiKey']
|
|
173
|
+
*/
|
|
174
|
+
sanitize?: string[];
|
|
175
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
97
176
|
databaseLogging?: {
|
|
98
|
-
enabled
|
|
99
|
-
dataSource
|
|
100
|
-
tableName: string;
|
|
177
|
+
enabled?: boolean;
|
|
178
|
+
dataSource?: string;
|
|
101
179
|
};
|
|
102
180
|
}
|
|
103
181
|
/**
|
|
104
182
|
* 拦截器配置
|
|
183
|
+
* 所有字段都是可选的
|
|
105
184
|
*/
|
|
106
185
|
export interface InterceptorConfig {
|
|
107
|
-
requestInterceptors
|
|
108
|
-
responseInterceptors
|
|
109
|
-
errorInterceptors
|
|
186
|
+
requestInterceptors?: string[];
|
|
187
|
+
responseInterceptors?: string[];
|
|
188
|
+
errorInterceptors?: string[];
|
|
110
189
|
}
|
|
111
190
|
/**
|
|
112
191
|
* 连接池配置
|
|
192
|
+
* 所有字段都是可选的
|
|
113
193
|
*/
|
|
114
194
|
export interface ConnectionPoolConfig {
|
|
115
|
-
enabled
|
|
116
|
-
maxSockets
|
|
117
|
-
maxFreeSockets
|
|
118
|
-
timeoutMs
|
|
119
|
-
keepAlive
|
|
195
|
+
enabled?: boolean;
|
|
196
|
+
maxSockets?: number;
|
|
197
|
+
maxFreeSockets?: number;
|
|
198
|
+
timeoutMs?: number;
|
|
199
|
+
keepAlive?: boolean;
|
|
120
200
|
}
|
|
121
201
|
/**
|
|
122
202
|
* HTTP请求上下文
|
|
@@ -175,9 +255,4 @@ export interface HttpStats {
|
|
|
175
255
|
requestsByMethod: Record<HttpMethod, number>;
|
|
176
256
|
requestsByStatus: Record<number, number>;
|
|
177
257
|
circuitBreakerStats: Record<string, any>;
|
|
178
|
-
cacheStats: {
|
|
179
|
-
hits: number;
|
|
180
|
-
misses: number;
|
|
181
|
-
hitRate: number;
|
|
182
|
-
};
|
|
183
258
|
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig, AuthType,
|
|
2
|
-
import { HttpClientService } from './http-client.service';
|
|
1
|
+
import { ApiClientConfig, ApiClientInstanceConfig, ApiClientRegistryConfig, AuthType, ResponseTransformerConfig } from '../interfaces/api-client-config.interface';
|
|
3
2
|
import { HttpCircuitBreakerService } from './circuit-breaker.service';
|
|
4
3
|
import { HttpLoggingService } from './logging.service';
|
|
5
|
-
|
|
6
|
-
export { ApiClientInstanceConfig, AuthType, OAuth2Config, ResponseTransformerConfig, };
|
|
4
|
+
export { ApiClientInstanceConfig, AuthType, ResponseTransformerConfig };
|
|
7
5
|
/**
|
|
8
6
|
* API客户端注册服务
|
|
7
|
+
* 负责管理多个 HttpClientService 实例
|
|
9
8
|
*/
|
|
10
9
|
export declare class ApiClientRegistryService {
|
|
11
|
-
private readonly httpClientService;
|
|
12
10
|
private readonly circuitBreakerService;
|
|
13
11
|
private readonly loggingService;
|
|
14
|
-
private readonly cacheService;
|
|
15
12
|
private readonly logger;
|
|
16
13
|
private readonly clients;
|
|
17
14
|
private readonly clientConfigs;
|
|
18
15
|
private readonly globalDefaults;
|
|
19
|
-
constructor(
|
|
16
|
+
constructor(circuitBreakerService: HttpCircuitBreakerService, loggingService: HttpLoggingService, globalConfig?: ApiClientRegistryConfig);
|
|
20
17
|
/**
|
|
21
18
|
* 创建API客户端实例
|
|
19
|
+
* 使用 HttpClientService.createApiClient 静态方法创建
|
|
22
20
|
*/
|
|
23
21
|
createClient<T = any>(config: ApiClientInstanceConfig): T;
|
|
24
22
|
/**
|
|
@@ -76,21 +74,10 @@ export declare class ApiClientRegistryService {
|
|
|
76
74
|
}>;
|
|
77
75
|
}>;
|
|
78
76
|
/**
|
|
79
|
-
*
|
|
77
|
+
* 深度合并配置(已废弃,不再需要)
|
|
78
|
+
* @deprecated 配置结构简化后不再需要此方法
|
|
80
79
|
*/
|
|
81
|
-
private
|
|
82
|
-
/**
|
|
83
|
-
* 应用鉴权配置
|
|
84
|
-
*/
|
|
85
|
-
private applyAuthentication;
|
|
86
|
-
/**
|
|
87
|
-
* 应用响应转换器
|
|
88
|
-
*/
|
|
89
|
-
private applyResponseTransformer;
|
|
90
|
-
/**
|
|
91
|
-
* 根据路径提取数据
|
|
92
|
-
*/
|
|
93
|
-
private extractDataByPath;
|
|
80
|
+
private deepMergeConfigs;
|
|
94
81
|
/**
|
|
95
82
|
* 合并环境特定配置
|
|
96
83
|
*/
|
|
@@ -21,25 +21,19 @@ var ApiClientRegistryService_1;
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.ApiClientRegistryService = exports.AuthType = void 0;
|
|
23
23
|
const common_1 = require("@nestjs/common");
|
|
24
|
-
const axios_1 = require("axios");
|
|
25
|
-
const axios_retry_1 = require("axios-retry");
|
|
26
24
|
const api_client_config_interface_1 = require("../interfaces/api-client-config.interface");
|
|
27
25
|
Object.defineProperty(exports, "AuthType", { enumerable: true, get: function () { return api_client_config_interface_1.AuthType; } });
|
|
28
26
|
const http_client_service_1 = require("./http-client.service");
|
|
29
27
|
const circuit_breaker_service_1 = require("./circuit-breaker.service");
|
|
30
28
|
const logging_service_1 = require("./logging.service");
|
|
31
|
-
const cache_service_1 = require("./cache.service");
|
|
32
|
-
const context_extractor_util_1 = require("../utils/context-extractor.util");
|
|
33
|
-
const utils_1 = require("../../common/utils");
|
|
34
29
|
/**
|
|
35
30
|
* API客户端注册服务
|
|
31
|
+
* 负责管理多个 HttpClientService 实例
|
|
36
32
|
*/
|
|
37
33
|
let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegistryService {
|
|
38
|
-
constructor(
|
|
39
|
-
this.httpClientService = httpClientService;
|
|
34
|
+
constructor(circuitBreakerService, loggingService, globalConfig = {}) {
|
|
40
35
|
this.circuitBreakerService = circuitBreakerService;
|
|
41
36
|
this.loggingService = loggingService;
|
|
42
|
-
this.cacheService = cacheService;
|
|
43
37
|
this.logger = new common_1.Logger(ApiClientRegistryService_1.name);
|
|
44
38
|
this.clients = new Map();
|
|
45
39
|
this.clientConfigs = new Map();
|
|
@@ -53,7 +47,7 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
|
|
|
53
47
|
logHeaders: true,
|
|
54
48
|
logBody: true,
|
|
55
49
|
maxBodyLength: 10000,
|
|
56
|
-
|
|
50
|
+
sanitize: ['authorization', 'api-key'],
|
|
57
51
|
logLevel: 'info',
|
|
58
52
|
},
|
|
59
53
|
timeout: 30000,
|
|
@@ -65,6 +59,7 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
|
|
|
65
59
|
}
|
|
66
60
|
/**
|
|
67
61
|
* 创建API客户端实例
|
|
62
|
+
* 使用 HttpClientService.createApiClient 静态方法创建
|
|
68
63
|
*/
|
|
69
64
|
createClient(config) {
|
|
70
65
|
const clientName = config.name;
|
|
@@ -75,15 +70,30 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
|
|
|
75
70
|
}
|
|
76
71
|
// 合并环境特定配置
|
|
77
72
|
const finalConfig = this.mergeEnvironmentConfig(config);
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
//
|
|
81
|
-
|
|
73
|
+
// 构建 HttpClient 配置
|
|
74
|
+
// 1. 从全局默认配置开始
|
|
75
|
+
// 2. 合并 ApiClient 的 httpConfig
|
|
76
|
+
// 3. 应用 ApiClient 特有的 retry 配置(兼容旧代码)
|
|
77
|
+
const mergedHttpConfig = Object.assign(Object.assign({}, this.globalDefaults.globalDefaults), finalConfig.httpConfig);
|
|
78
|
+
// 兼容:如果 ApiClientConfig 顶层有 retry 配置,合并到 httpConfig.retry
|
|
79
|
+
if (finalConfig.retry) {
|
|
80
|
+
mergedHttpConfig.retry = Object.assign(Object.assign({}, mergedHttpConfig.retry), finalConfig.retry);
|
|
81
|
+
}
|
|
82
|
+
// 使用静态工厂方法创建 HttpClientService 实例
|
|
83
|
+
const httpClient = http_client_service_1.HttpClientService.createApiClient({
|
|
84
|
+
circuitBreakerService: this.circuitBreakerService,
|
|
85
|
+
loggingService: this.loggingService,
|
|
86
|
+
}, {
|
|
87
|
+
name: clientName,
|
|
88
|
+
baseURL: finalConfig.baseURL,
|
|
89
|
+
httpConfig: mergedHttpConfig,
|
|
90
|
+
auth: finalConfig.auth,
|
|
91
|
+
});
|
|
82
92
|
// 存储客户端和配置
|
|
83
|
-
this.clients.set(clientName,
|
|
93
|
+
this.clients.set(clientName, httpClient);
|
|
84
94
|
this.clientConfigs.set(clientName, finalConfig);
|
|
85
95
|
this.logger.log(`Created API client: ${clientName}`);
|
|
86
|
-
return
|
|
96
|
+
return httpClient;
|
|
87
97
|
}
|
|
88
98
|
/**
|
|
89
99
|
* 获取已注册的客户端
|
|
@@ -210,180 +220,11 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
|
|
|
210
220
|
});
|
|
211
221
|
}
|
|
212
222
|
/**
|
|
213
|
-
*
|
|
214
|
-
|
|
215
|
-
createAxiosInstance(config) {
|
|
216
|
-
var _a, _b, _c, _d, _e, _f;
|
|
217
|
-
const axiosConfig = {
|
|
218
|
-
baseURL: config.baseURL,
|
|
219
|
-
timeout: ((_a = config.httpConfig) === null || _a === void 0 ? void 0 : _a.timeout) || 30000,
|
|
220
|
-
headers: Object.assign({ 'Content-Type': 'application/json', 'User-Agent': `${config.name}/1.0.0` }, config.defaultHeaders),
|
|
221
|
-
params: config.defaultParams,
|
|
222
|
-
};
|
|
223
|
-
const instance = axios_1.default.create(axiosConfig);
|
|
224
|
-
const clientName = config.name; // Capture client name for use in closures
|
|
225
|
-
// 配置请求拦截器
|
|
226
|
-
instance.interceptors.request.use((config) => {
|
|
227
|
-
// 添加鉴权信息 - for now, skip async authentication to avoid type issues
|
|
228
|
-
const authenticatedConfig = config;
|
|
229
|
-
// Add simple auth headers for basic cases
|
|
230
|
-
if (config.auth) {
|
|
231
|
-
switch (config.auth.type) {
|
|
232
|
-
case api_client_config_interface_1.AuthType.BEARER_TOKEN:
|
|
233
|
-
const bearerConfig = config.auth.config;
|
|
234
|
-
authenticatedConfig.headers = authenticatedConfig.headers || {};
|
|
235
|
-
authenticatedConfig.headers['Authorization'] =
|
|
236
|
-
`Bearer ${bearerConfig.token}`;
|
|
237
|
-
break;
|
|
238
|
-
case api_client_config_interface_1.AuthType.API_KEY:
|
|
239
|
-
const apiKeyConfig = config.auth.config;
|
|
240
|
-
if (apiKeyConfig.location === 'header') {
|
|
241
|
-
const headerName = apiKeyConfig.name || 'X-API-Key';
|
|
242
|
-
const value = apiKeyConfig.prefix
|
|
243
|
-
? `${apiKeyConfig.prefix} ${apiKeyConfig.key}`
|
|
244
|
-
: apiKeyConfig.key;
|
|
245
|
-
authenticatedConfig.headers = authenticatedConfig.headers || {};
|
|
246
|
-
authenticatedConfig.headers[headerName] = value;
|
|
247
|
-
}
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
// 添加请求ID和上下文信息
|
|
252
|
-
const context = context_extractor_util_1.ContextExtractor.getHttpContext();
|
|
253
|
-
const requestId = context.requestId || (0, utils_1.generateRequestId)();
|
|
254
|
-
authenticatedConfig.headers = authenticatedConfig.headers || {};
|
|
255
|
-
authenticatedConfig.headers['X-Request-ID'] = requestId;
|
|
256
|
-
if (context.userId) {
|
|
257
|
-
authenticatedConfig.headers['X-User-ID'] = context.userId;
|
|
258
|
-
}
|
|
259
|
-
// 添加API标识
|
|
260
|
-
authenticatedConfig.headers['X-API-Client'] = clientName;
|
|
261
|
-
return authenticatedConfig;
|
|
262
|
-
}, (error) => {
|
|
263
|
-
this.logger.error(`[${clientName}] Request interceptor error`, error);
|
|
264
|
-
return Promise.reject(error);
|
|
265
|
-
});
|
|
266
|
-
// 配置响应拦截器
|
|
267
|
-
instance.interceptors.response.use((response) => {
|
|
268
|
-
// 应用响应转换器
|
|
269
|
-
return this.applyResponseTransformer(response, config.responseTransformer);
|
|
270
|
-
}, (error) => {
|
|
271
|
-
var _a;
|
|
272
|
-
// 应用错误转换器
|
|
273
|
-
if ((_a = config.responseTransformer) === null || _a === void 0 ? void 0 : _a.error) {
|
|
274
|
-
return config.responseTransformer.error(error);
|
|
275
|
-
}
|
|
276
|
-
return Promise.reject(error);
|
|
277
|
-
});
|
|
278
|
-
// 配置axios-retry
|
|
279
|
-
if (((_b = config.retry) === null || _b === void 0 ? void 0 : _b.enabled) !== false &&
|
|
280
|
-
this.globalDefaults.enableGlobalRetry) {
|
|
281
|
-
(0, axios_retry_1.default)(instance, {
|
|
282
|
-
retries: ((_c = config.retry) === null || _c === void 0 ? void 0 : _c.retries) ||
|
|
283
|
-
((_e = (_d = this.globalDefaults.globalDefaults) === null || _d === void 0 ? void 0 : _d.retry) === null || _e === void 0 ? void 0 : _e.retries) ||
|
|
284
|
-
3,
|
|
285
|
-
retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
|
|
286
|
-
retryCondition: ((_f = config.retry) === null || _f === void 0 ? void 0 : _f.retryCondition) ||
|
|
287
|
-
((error) => {
|
|
288
|
-
if (!error.response)
|
|
289
|
-
return true;
|
|
290
|
-
const status = error.response.status;
|
|
291
|
-
return status >= 500 || status === 429;
|
|
292
|
-
}),
|
|
293
|
-
shouldResetTimeout: true,
|
|
294
|
-
onRetry: (retryCount, error, requestConfig) => {
|
|
295
|
-
var _a;
|
|
296
|
-
this.logger.warn(`[${config.name}] Retrying request (attempt ${retryCount}): ${(_a = requestConfig.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()} ${requestConfig.url}`);
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
return instance;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* 应用鉴权配置
|
|
304
|
-
*/
|
|
305
|
-
applyAuthentication(config, auth) {
|
|
306
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
307
|
-
if (!auth) {
|
|
308
|
-
return config;
|
|
309
|
-
}
|
|
310
|
-
const authenticatedConfig = Object.assign({}, config);
|
|
311
|
-
switch (auth.type) {
|
|
312
|
-
case api_client_config_interface_1.AuthType.NONE:
|
|
313
|
-
break;
|
|
314
|
-
case api_client_config_interface_1.AuthType.API_KEY:
|
|
315
|
-
const apiKeyConfig = auth.config;
|
|
316
|
-
if (apiKeyConfig.location === 'header') {
|
|
317
|
-
const headerName = apiKeyConfig.name || 'X-API-Key';
|
|
318
|
-
const value = apiKeyConfig.prefix
|
|
319
|
-
? `${apiKeyConfig.prefix} ${apiKeyConfig.key}`
|
|
320
|
-
: apiKeyConfig.key;
|
|
321
|
-
authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { [headerName]: value });
|
|
322
|
-
}
|
|
323
|
-
else if (apiKeyConfig.location === 'query') {
|
|
324
|
-
const paramName = apiKeyConfig.name || 'api_key';
|
|
325
|
-
authenticatedConfig.params = Object.assign(Object.assign({}, authenticatedConfig.params), { [paramName]: apiKeyConfig.key });
|
|
326
|
-
}
|
|
327
|
-
break;
|
|
328
|
-
case api_client_config_interface_1.AuthType.BEARER_TOKEN:
|
|
329
|
-
const bearerConfig = auth.config;
|
|
330
|
-
const scheme = bearerConfig.scheme || 'Bearer';
|
|
331
|
-
authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `${scheme} ${bearerConfig.token}` });
|
|
332
|
-
break;
|
|
333
|
-
case api_client_config_interface_1.AuthType.BASIC_AUTH:
|
|
334
|
-
const basicConfig = auth.config;
|
|
335
|
-
const credentials = Buffer.from(`${basicConfig.username}:${basicConfig.password}`).toString('base64');
|
|
336
|
-
authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `Basic ${credentials}` });
|
|
337
|
-
break;
|
|
338
|
-
case api_client_config_interface_1.AuthType.OAUTH2:
|
|
339
|
-
const oauthConfig = auth.config;
|
|
340
|
-
// OAuth2实现需要异步获取token
|
|
341
|
-
// 这里简化处理,实际项目中可能需要更复杂的逻辑
|
|
342
|
-
authenticatedConfig.headers = Object.assign(Object.assign({}, authenticatedConfig.headers), { Authorization: `Bearer ${oauthConfig.clientSecret}` });
|
|
343
|
-
break;
|
|
344
|
-
case api_client_config_interface_1.AuthType.CUSTOM:
|
|
345
|
-
const customConfig = auth.config;
|
|
346
|
-
return yield customConfig.authenticator(authenticatedConfig);
|
|
347
|
-
}
|
|
348
|
-
return authenticatedConfig;
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* 应用响应转换器
|
|
353
|
-
*/
|
|
354
|
-
applyResponseTransformer(response, transformer) {
|
|
355
|
-
if (!transformer) {
|
|
356
|
-
return response;
|
|
357
|
-
}
|
|
358
|
-
// 应用成功响应转换器
|
|
359
|
-
if (transformer.success) {
|
|
360
|
-
response.data = transformer.success(response);
|
|
361
|
-
}
|
|
362
|
-
// 应用数据路径提取
|
|
363
|
-
if (transformer.dataPath) {
|
|
364
|
-
response.data = this.extractDataByPath(response.data, transformer.dataPath);
|
|
365
|
-
}
|
|
366
|
-
// 应用响应验证
|
|
367
|
-
if (transformer.validateResponse && transformer.validator) {
|
|
368
|
-
if (!transformer.validator(response.data)) {
|
|
369
|
-
throw new Error(`Response validation failed for ${transformer.dataPath}`);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
return response;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* 根据路径提取数据
|
|
223
|
+
* 深度合并配置(已废弃,不再需要)
|
|
224
|
+
* @deprecated 配置结构简化后不再需要此方法
|
|
376
225
|
*/
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
let current = data;
|
|
380
|
-
for (const key of keys) {
|
|
381
|
-
if (current === null || current === undefined) {
|
|
382
|
-
return undefined;
|
|
383
|
-
}
|
|
384
|
-
current = current[key];
|
|
385
|
-
}
|
|
386
|
-
return current;
|
|
226
|
+
deepMergeConfigs(defaults, userConfig) {
|
|
227
|
+
return Object.assign(Object.assign({}, defaults), userConfig);
|
|
387
228
|
}
|
|
388
229
|
/**
|
|
389
230
|
* 合并环境特定配置
|
|
@@ -398,98 +239,6 @@ let ApiClientRegistryService = ApiClientRegistryService_1 = class ApiClientRegis
|
|
|
398
239
|
exports.ApiClientRegistryService = ApiClientRegistryService;
|
|
399
240
|
exports.ApiClientRegistryService = ApiClientRegistryService = ApiClientRegistryService_1 = __decorate([
|
|
400
241
|
(0, common_1.Injectable)(),
|
|
401
|
-
__metadata("design:paramtypes", [
|
|
402
|
-
|
|
403
|
-
logging_service_1.HttpLoggingService,
|
|
404
|
-
cache_service_1.HttpCacheService, Object])
|
|
242
|
+
__metadata("design:paramtypes", [circuit_breaker_service_1.HttpCircuitBreakerService,
|
|
243
|
+
logging_service_1.HttpLoggingService, Object])
|
|
405
244
|
], ApiClientRegistryService);
|
|
406
|
-
/**
|
|
407
|
-
* API客户端实例实现
|
|
408
|
-
*/
|
|
409
|
-
class ApiClientInstance {
|
|
410
|
-
constructor(name, config, axiosInstance, httpClientService, loggingService, cacheService) {
|
|
411
|
-
this.name = name;
|
|
412
|
-
this.config = config;
|
|
413
|
-
this.axiosInstance = axiosInstance;
|
|
414
|
-
this.httpClientService = httpClientService;
|
|
415
|
-
this.loggingService = loggingService;
|
|
416
|
-
this.cacheService = cacheService;
|
|
417
|
-
this.stats = {
|
|
418
|
-
totalRequests: 0,
|
|
419
|
-
successfulRequests: 0,
|
|
420
|
-
failedRequests: 0,
|
|
421
|
-
totalResponseTime: 0,
|
|
422
|
-
averageResponseTime: 0,
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
get(url, config) {
|
|
426
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
427
|
-
return this.request(Object.assign(Object.assign({}, config), { method: 'GET', url }));
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
post(url, data, config) {
|
|
431
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
432
|
-
return this.request(Object.assign(Object.assign({}, config), { method: 'POST', url, data }));
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
put(url, data, config) {
|
|
436
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
return this.request(Object.assign(Object.assign({}, config), { method: 'PUT', url, data }));
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
patch(url, data, config) {
|
|
441
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
442
|
-
return this.request(Object.assign(Object.assign({}, config), { method: 'PATCH', url, data }));
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
delete(url, config) {
|
|
446
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
447
|
-
return this.request(Object.assign(Object.assign({}, config), { method: 'DELETE', url }));
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
request(config) {
|
|
451
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
-
const startTime = Date.now();
|
|
453
|
-
this.stats.totalRequests++;
|
|
454
|
-
try {
|
|
455
|
-
const response = yield this.axiosInstance.request(config);
|
|
456
|
-
// 更新统计信息
|
|
457
|
-
const responseTime = Date.now() - startTime;
|
|
458
|
-
this.updateStats(true, responseTime);
|
|
459
|
-
return response.data;
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
// 更新统计信息
|
|
463
|
-
const responseTime = Date.now() - startTime;
|
|
464
|
-
this.updateStats(false, responseTime);
|
|
465
|
-
throw error;
|
|
466
|
-
}
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
getStats() {
|
|
470
|
-
return Object.assign({}, this.stats);
|
|
471
|
-
}
|
|
472
|
-
resetStats() {
|
|
473
|
-
this.stats.totalRequests = 0;
|
|
474
|
-
this.stats.successfulRequests = 0;
|
|
475
|
-
this.stats.failedRequests = 0;
|
|
476
|
-
this.stats.totalResponseTime = 0;
|
|
477
|
-
this.stats.averageResponseTime = 0;
|
|
478
|
-
}
|
|
479
|
-
updateStats(success, responseTime) {
|
|
480
|
-
if (success) {
|
|
481
|
-
this.stats.successfulRequests++;
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
this.stats.failedRequests++;
|
|
485
|
-
}
|
|
486
|
-
this.stats.totalResponseTime += responseTime;
|
|
487
|
-
this.stats.averageResponseTime =
|
|
488
|
-
this.stats.totalResponseTime / this.stats.totalRequests;
|
|
489
|
-
// 响应时间警告
|
|
490
|
-
if (this.config.responseTimeWarningThreshold &&
|
|
491
|
-
responseTime > this.config.responseTimeWarningThreshold) {
|
|
492
|
-
console.warn(`[API Client ${this.name}] Slow response detected: ${responseTime}ms for ${this.axiosInstance.defaults.baseURL}`);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
}
|