@nest-omni/core 4.1.3-2 → 4.1.3-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/audit/audit.module.d.ts +10 -0
- package/audit/audit.module.js +63 -1
- package/audit/controllers/audit.controller.d.ts +88 -0
- package/audit/controllers/audit.controller.js +74 -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 +9 -1
- package/audit/decorators/audit-controller.decorator.js +11 -2
- package/audit/decorators/audit-operation.decorator.d.ts +45 -0
- package/audit/decorators/audit-operation.decorator.js +49 -0
- package/audit/decorators/entity-audit.decorator.d.ts +85 -1
- package/audit/decorators/entity-audit.decorator.js +153 -3
- package/audit/decorators/index.d.ts +2 -0
- package/audit/decorators/index.js +2 -0
- package/audit/dto/audit-log-query.dto.d.ts +3 -0
- package/audit/dto/audit-log-query.dto.js +3 -0
- package/audit/dto/begin-transaction.dto.d.ts +3 -0
- package/audit/dto/begin-transaction.dto.js +3 -0
- package/audit/dto/compare-entities.dto.d.ts +3 -0
- package/audit/dto/compare-entities.dto.js +3 -0
- package/audit/dto/pre-check-restore.dto.d.ts +3 -0
- package/audit/dto/pre-check-restore.dto.js +3 -0
- package/audit/dto/restore-entity.dto.d.ts +3 -0
- package/audit/dto/restore-entity.dto.js +3 -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 +11 -0
- package/audit/entities/entity-audit-log.entity.js +57 -2
- package/audit/entities/entity-transaction.entity.d.ts +11 -2
- package/audit/entities/entity-transaction.entity.js +42 -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 +4 -0
- package/audit/entities/manual-operation-log.entity.js +12 -1
- package/audit/entities/operation-template.entity.d.ts +4 -0
- package/audit/entities/operation-template.entity.js +4 -0
- package/audit/enums/audit.enums.d.ts +37 -6
- package/audit/enums/audit.enums.js +40 -7
- package/audit/index.d.ts +4 -1
- package/audit/index.js +34 -1
- package/audit/interceptors/audit-action.interceptor.d.ts +38 -0
- package/audit/interceptors/audit-action.interceptor.js +215 -0
- package/audit/interceptors/audit.interceptor.d.ts +15 -0
- package/audit/interceptors/audit.interceptor.js +23 -1
- package/audit/interceptors/index.d.ts +1 -0
- package/audit/interceptors/index.js +1 -0
- package/audit/interfaces/audit.interfaces.d.ts +187 -2
- package/audit/services/audit-action.service.d.ts +141 -0
- package/audit/services/audit-action.service.js +244 -0
- package/audit/services/audit-context.service.d.ts +97 -0
- package/audit/services/audit-context.service.js +185 -0
- package/audit/services/audit-strategy.service.d.ts +6 -0
- package/audit/services/audit-strategy.service.js +13 -0
- package/audit/services/entity-audit.service.d.ts +230 -3
- package/audit/services/entity-audit.service.js +607 -14
- package/audit/services/index.d.ts +3 -0
- package/audit/services/index.js +3 -0
- package/audit/services/manual-audit-log.service.d.ts +134 -9
- package/audit/services/manual-audit-log.service.js +157 -40
- package/audit/services/multi-database.service.d.ts +9 -2
- package/audit/services/multi-database.service.js +9 -21
- package/audit/services/operation-description.service.d.ts +71 -2
- package/audit/services/operation-description.service.js +231 -20
- package/audit/services/transaction-audit.service.d.ts +30 -0
- package/audit/services/transaction-audit.service.js +53 -5
- package/audit/subscribers/entity-audit.subscriber.d.ts +19 -0
- package/audit/subscribers/entity-audit.subscriber.js +76 -1
- package/cache/cache-metrics.service.d.ts +67 -0
- package/cache/cache-metrics.service.js +68 -4
- package/cache/cache-serialization.service.d.ts +31 -0
- package/cache/cache-serialization.service.js +25 -0
- package/cache/cache.constants.d.ts +9 -0
- package/cache/cache.constants.js +9 -0
- package/cache/cache.health.d.ts +26 -0
- package/cache/cache.health.js +30 -0
- package/cache/cache.module.d.ts +82 -2
- package/cache/cache.module.js +76 -5
- package/cache/cache.service.d.ts +140 -0
- package/cache/cache.service.js +169 -0
- package/cache/cache.warmup.service.d.ts +39 -0
- package/cache/cache.warmup.service.js +32 -0
- package/cache/decorators/cache-evict.decorator.d.ts +47 -0
- package/cache/decorators/cache-evict.decorator.js +56 -0
- package/cache/decorators/cache-put.decorator.d.ts +34 -0
- package/cache/decorators/cache-put.decorator.js +39 -0
- package/cache/decorators/cacheable.decorator.d.ts +40 -0
- package/cache/decorators/cacheable.decorator.js +55 -0
- package/cache/dependencies/callback.dependency.d.ts +33 -0
- package/cache/dependencies/callback.dependency.js +39 -1
- package/cache/dependencies/chain.dependency.d.ts +28 -0
- package/cache/dependencies/chain.dependency.js +34 -0
- package/cache/dependencies/db.dependency.d.ts +83 -7
- package/cache/dependencies/db.dependency.js +89 -14
- package/cache/dependencies/file.dependency.d.ts +32 -0
- package/cache/dependencies/file.dependency.js +34 -0
- package/cache/dependencies/tag.dependency.d.ts +75 -4
- package/cache/dependencies/tag.dependency.js +145 -11
- package/cache/dependencies/time.dependency.d.ts +43 -0
- package/cache/dependencies/time.dependency.js +43 -0
- package/cache/examples/basic-usage.d.ts +15 -0
- package/cache/examples/basic-usage.js +62 -8
- package/cache/index.js +9 -0
- package/cache/interfaces/cache-dependency.interface.d.ts +53 -0
- package/cache/interfaces/cache-options.interface.d.ts +89 -0
- package/cache/interfaces/cache-options.interface.js +6 -0
- package/cache/interfaces/cache-provider.interface.d.ts +78 -0
- package/cache/providers/base-cache.provider.d.ts +14 -0
- package/cache/providers/base-cache.provider.js +16 -0
- package/cache/providers/cls-cache.provider.d.ts +20 -0
- package/cache/providers/cls-cache.provider.js +28 -0
- package/cache/providers/memory-cache.provider.d.ts +43 -0
- package/cache/providers/memory-cache.provider.js +66 -0
- package/cache/providers/redis-cache.provider.d.ts +26 -0
- package/cache/providers/redis-cache.provider.js +29 -0
- package/cache/utils/dependency-manager.util.d.ts +52 -0
- package/cache/utils/dependency-manager.util.js +59 -0
- package/cache/utils/key-generator.util.d.ts +42 -0
- package/cache/utils/key-generator.util.js +53 -1
- package/common/abstract.entity.d.ts +14 -0
- package/common/abstract.entity.js +14 -0
- package/common/boilerplate.polyfill.d.ts +142 -0
- package/common/boilerplate.polyfill.js +18 -1
- package/common/dto/dto-container.d.ts +16 -0
- package/common/dto/dto-container.js +20 -0
- package/common/dto/dto-decorators.d.ts +18 -0
- package/common/dto/dto-decorators.js +14 -0
- package/common/dto/dto-extensions.d.ts +11 -0
- package/common/dto/dto-extensions.js +9 -0
- package/common/dto/dto-service-accessor.d.ts +17 -0
- package/common/dto/dto-service-accessor.js +18 -0
- package/common/dto/dto-transformer.d.ts +12 -0
- package/common/dto/dto-transformer.js +9 -0
- package/common/dto/index.js +2 -0
- package/common/examples/paginate-and-map.example.d.ts +6 -0
- package/common/examples/paginate-and-map.example.js +26 -0
- package/common/utils.d.ts +15 -0
- package/common/utils.js +15 -0
- package/constants/language-code.js +1 -0
- package/decorators/field.decorators.d.ts +1 -1
- package/decorators/field.decorators.js +8 -1
- package/decorators/property.decorators.js +1 -0
- package/decorators/public-route.decorator.js +1 -0
- package/decorators/transform.decorators.d.ts +27 -0
- package/decorators/transform.decorators.js +29 -0
- package/decorators/translate.decorator.js +1 -0
- package/decorators/user.decorator.js +1 -0
- package/decorators/validator.decorators.d.ts +8 -18
- package/decorators/validator.decorators.js +22 -190
- 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/constraint-errors.js +1 -0
- package/helpers/common.helper.d.ts +13 -0
- package/helpers/common.helper.js +13 -0
- package/http-client/config/http-client.config.d.ts +20 -0
- package/http-client/config/http-client.config.js +48 -21
- package/http-client/decorators/http-client.decorators.d.ts +55 -14
- package/http-client/decorators/http-client.decorators.js +154 -78
- package/http-client/entities/http-log.entity.d.ts +217 -8
- package/http-client/entities/http-log.entity.js +7 -22
- package/http-client/errors/http-client.errors.d.ts +57 -0
- package/http-client/errors/http-client.errors.js +58 -0
- package/http-client/examples/advanced-usage.example.d.ts +40 -0
- package/http-client/examples/advanced-usage.example.js +53 -61
- package/http-client/examples/auth-with-waiting-lock.example.d.ts +31 -0
- package/http-client/examples/auth-with-waiting-lock.example.js +52 -5
- package/http-client/examples/basic-usage.example.d.ts +60 -0
- package/http-client/examples/basic-usage.example.js +60 -0
- package/http-client/examples/multi-api-configuration.example.d.ts +60 -0
- package/http-client/examples/multi-api-configuration.example.js +76 -5
- 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/http-client.module.d.ts +48 -2
- package/http-client/http-client.module.js +147 -68
- package/http-client/index.d.ts +1 -1
- package/http-client/index.js +8 -0
- package/http-client/interfaces/api-client-config.interface.d.ts +80 -45
- package/http-client/interfaces/api-client-config.interface.js +3 -0
- package/http-client/interfaces/http-client-config.interface.d.ts +109 -52
- package/http-client/services/api-client-registry.service.d.ts +50 -11
- package/http-client/services/api-client-registry.service.js +90 -250
- package/http-client/services/circuit-breaker.service.d.ts +115 -2
- package/http-client/services/circuit-breaker.service.js +237 -7
- package/http-client/services/http-client.service.d.ts +124 -14
- package/http-client/services/http-client.service.js +437 -148
- package/http-client/services/http-log-query.service.d.ts +83 -0
- package/http-client/services/http-log-query.service.js +121 -13
- package/http-client/services/http-replay.service.d.ts +101 -0
- package/http-client/services/http-replay.service.js +86 -0
- package/http-client/services/index.d.ts +0 -1
- package/http-client/services/index.js +0 -1
- package/http-client/services/log-cleanup.service.d.ts +63 -0
- package/http-client/services/log-cleanup.service.js +54 -2
- package/http-client/services/logging.service.d.ts +116 -7
- package/http-client/services/logging.service.js +349 -86
- package/http-client/utils/call-stack-extractor.util.d.ts +63 -0
- package/http-client/utils/call-stack-extractor.util.js +83 -0
- package/http-client/utils/context-extractor.util.d.ts +49 -0
- package/http-client/utils/context-extractor.util.js +52 -0
- package/http-client/utils/curl-generator.util.d.ts +21 -0
- package/http-client/utils/curl-generator.util.js +44 -3
- package/http-client/utils/index.d.ts +1 -0
- package/http-client/utils/index.js +1 -0
- package/http-client/utils/proxy-environment.util.d.ts +42 -0
- package/http-client/utils/proxy-environment.util.js +148 -0
- package/http-client/utils/request-id.util.d.ts +18 -0
- package/http-client/utils/request-id.util.js +20 -0
- package/http-client/utils/retry-recorder.util.d.ts +42 -0
- package/http-client/utils/retry-recorder.util.js +44 -0
- package/http-client/utils/security-validator.util.d.ts +118 -0
- package/http-client/utils/security-validator.util.js +352 -0
- package/index.d.ts +3 -1
- package/index.js +12 -1
- package/interceptors/translation-interceptor.service.js +5 -0
- package/package.json +11 -7
- package/providers/context.provider.js +2 -0
- package/providers/generator.provider.d.ts +4 -0
- package/providers/generator.provider.js +4 -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/examples/lock-strategy.examples.d.ts +89 -0
- package/redis-lock/examples/lock-strategy.examples.js +130 -15
- package/redis-lock/index.d.ts +2 -0
- package/redis-lock/index.js +8 -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.decorator.d.ts +101 -0
- package/redis-lock/redis-lock.decorator.js +120 -0
- package/redis-lock/redis-lock.module.d.ts +66 -0
- package/redis-lock/redis-lock.module.js +175 -70
- package/redis-lock/redis-lock.service.d.ts +282 -0
- package/redis-lock/redis-lock.service.js +343 -20
- package/setup/bootstrap.setup.d.ts +1 -0
- package/setup/bootstrap.setup.js +21 -0
- package/setup/index.d.ts +1 -0
- package/setup/index.js +1 -0
- package/setup/mode.setup.d.ts +44 -0
- package/setup/mode.setup.js +44 -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 +227 -0
- package/setup/schedule.decorator.js +240 -12
- package/setup/worker.decorator.d.ts +86 -0
- package/setup/worker.decorator.js +97 -0
- package/shared/index.d.ts +1 -1
- package/shared/index.js +1 -1
- package/shared/{serviceRegistryModule.js → service-registry.module.js} +19 -17
- package/shared/services/api-config.service.d.ts +3 -0
- package/shared/services/api-config.service.js +21 -9
- package/shared/services/index.d.ts +0 -1
- package/shared/services/index.js +0 -1
- package/validator-json/decorators.d.ts +17 -0
- package/validator-json/decorators.js +17 -2
- package/validator-json/default.d.ts +6 -0
- package/validator-json/default.js +30 -2
- package/validator-json/defaultConverters.js +1 -0
- package/validator-json/options.d.ts +23 -0
- package/validators/common-validators.d.ts +143 -0
- package/validators/common-validators.js +249 -0
- package/validators/custom-validate.examples.d.ts +23 -0
- package/validators/custom-validate.examples.js +78 -6
- package/validators/custom-validate.validator.d.ts +108 -0
- package/validators/custom-validate.validator.js +85 -0
- package/validators/file-mimetype.validator.d.ts +0 -2
- package/validators/file-mimetype.validator.js +4 -6
- package/validators/index.d.ts +1 -0
- package/validators/index.js +1 -0
- package/validators/is-exists.validator.d.ts +26 -6
- package/validators/is-exists.validator.js +30 -7
- package/validators/is-unique.validator.d.ts +33 -7
- package/validators/is-unique.validator.js +59 -17
- package/validators/skip-empty.validator.d.ts +5 -0
- package/validators/skip-empty.validator.js +5 -0
- package/vault/interfaces/vault-options.interface.d.ts +9 -0
- package/vault/vault-config.loader.d.ts +30 -0
- package/vault/vault-config.loader.js +48 -1
- package/vault/vault-config.service.d.ts +53 -0
- package/vault/vault-config.service.js +57 -0
- package/vault/vault.module.d.ts +4 -0
- package/vault/vault.module.js +4 -0
- package/decorators/examples/validation-decorators.example.d.ts +0 -69
- package/decorators/examples/validation-decorators.example.js +0 -331
- package/http-client/services/cache.service.d.ts +0 -24
- package/http-client/services/cache.service.js +0 -264
- 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,23 +1,63 @@
|
|
|
1
1
|
import { HttpClientService } from '../services/http-client.service';
|
|
2
|
+
/**
|
|
3
|
+
* 高级使用示例 - GitHub API客户端
|
|
4
|
+
*/
|
|
2
5
|
export declare class GitHubHttpService {
|
|
3
6
|
private httpClient;
|
|
4
7
|
constructor(httpClient: HttpClientService);
|
|
8
|
+
/**
|
|
9
|
+
* 获取用户信息 - 带重试、熔断器和日志
|
|
10
|
+
*/
|
|
5
11
|
getUser(username: string): Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* 搜索仓库 - 带重试
|
|
14
|
+
*/
|
|
6
15
|
searchRepositories(query: string, sort?: string, order?: string): Promise<any>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取用户仓库 - 使用代理
|
|
18
|
+
*/
|
|
7
19
|
getUserRepositories(username: string): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
* 创建仓库 - 带详细日志
|
|
22
|
+
*/
|
|
8
23
|
createRepository(repoData: any, token: string): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* 获取仓库贡献者 - 熔断器保护
|
|
26
|
+
*/
|
|
9
27
|
getRepositoryContributors(owner: string, repo: string): Promise<any>;
|
|
28
|
+
/**
|
|
29
|
+
* 批量获取用户信息 - 并行请求
|
|
30
|
+
*/
|
|
10
31
|
getMultipleUsers(usernames: string[]): Promise<any[]>;
|
|
32
|
+
/**
|
|
33
|
+
* 获取仓库详情
|
|
34
|
+
*/
|
|
11
35
|
getRepositoryDetails(owner: string, repo: string, options?: {
|
|
12
36
|
public?: boolean;
|
|
13
37
|
}): Promise<any>;
|
|
14
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 支付服务示例 - 高安全性要求
|
|
41
|
+
* 使用Redis锁定确保并发安全
|
|
42
|
+
*/
|
|
15
43
|
export declare class PaymentHttpService {
|
|
16
44
|
private httpClient;
|
|
17
45
|
constructor(httpClient: HttpClientService);
|
|
46
|
+
/**
|
|
47
|
+
* 创建支付 - 严格的安全控制
|
|
48
|
+
*/
|
|
18
49
|
createPayment(paymentData: any, apiKey: string): Promise<any>;
|
|
50
|
+
/**
|
|
51
|
+
* 查询支付状态
|
|
52
|
+
*/
|
|
19
53
|
getPaymentStatus(paymentId: string, apiKey: string): Promise<any>;
|
|
54
|
+
/**
|
|
55
|
+
* 退款操作 - 重试机制
|
|
56
|
+
*/
|
|
20
57
|
refundPayment(paymentId: string, refundData: any, apiKey: string): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
* 动态调用示例 - 手动设置调用信息
|
|
60
|
+
*/
|
|
21
61
|
callExternalApi(url: string, method?: string, data?: any): Promise<any>;
|
|
22
62
|
private generateIdempotencyKey;
|
|
23
63
|
}
|
|
@@ -22,16 +22,24 @@ exports.PaymentHttpService = exports.GitHubHttpService = void 0;
|
|
|
22
22
|
const common_1 = require("@nestjs/common");
|
|
23
23
|
const decorators_1 = require("../decorators");
|
|
24
24
|
const http_client_service_1 = require("../services/http-client.service");
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 高级使用示例 - GitHub API客户端
|
|
27
|
+
*/
|
|
26
28
|
let GitHubHttpService = class GitHubHttpService {
|
|
27
29
|
constructor(httpClient) {
|
|
28
30
|
this.httpClient = httpClient;
|
|
29
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* 获取用户信息 - 带重试、熔断器和日志
|
|
34
|
+
*/
|
|
30
35
|
getUser(username) {
|
|
31
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
37
|
return this.httpClient.get(`/users/${username}`);
|
|
33
38
|
});
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* 搜索仓库 - 带重试
|
|
42
|
+
*/
|
|
35
43
|
searchRepositories(query_1) {
|
|
36
44
|
return __awaiter(this, arguments, void 0, function* (query, sort = 'stars', order = 'desc') {
|
|
37
45
|
return this.httpClient.get('/search/repositories', {
|
|
@@ -44,6 +52,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
44
52
|
});
|
|
45
53
|
});
|
|
46
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* 获取用户仓库 - 使用代理
|
|
57
|
+
*/
|
|
47
58
|
getUserRepositories(username) {
|
|
48
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
60
|
return this.httpClient.get(`/users/${username}/repos`, {
|
|
@@ -55,6 +66,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
55
66
|
});
|
|
56
67
|
});
|
|
57
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* 创建仓库 - 带详细日志
|
|
71
|
+
*/
|
|
58
72
|
createRepository(repoData, token) {
|
|
59
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
74
|
return this.httpClient.post('/user/repos', repoData, {
|
|
@@ -65,11 +79,17 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
65
79
|
});
|
|
66
80
|
});
|
|
67
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* 获取仓库贡献者 - 熔断器保护
|
|
84
|
+
*/
|
|
68
85
|
getRepositoryContributors(owner, repo) {
|
|
69
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
87
|
return this.httpClient.get(`/repos/${owner}/${repo}/contributors`);
|
|
71
88
|
});
|
|
72
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* 批量获取用户信息 - 并行请求
|
|
92
|
+
*/
|
|
73
93
|
getMultipleUsers(usernames) {
|
|
74
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
95
|
const promises = usernames.map((username) => this.getUser(username).catch((error) => {
|
|
@@ -79,6 +99,9 @@ let GitHubHttpService = class GitHubHttpService {
|
|
|
79
99
|
return Promise.all(promises);
|
|
80
100
|
});
|
|
81
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* 获取仓库详情
|
|
104
|
+
*/
|
|
82
105
|
getRepositoryDetails(owner, repo, options) {
|
|
83
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
107
|
return this.httpClient.get(`/repos/${owner}/${repo}`);
|
|
@@ -92,27 +115,22 @@ __decorate([
|
|
|
92
115
|
retryDelay: (retryCount) => Math.pow(2, retryCount) * 1000,
|
|
93
116
|
retryCondition: (error) => {
|
|
94
117
|
if (!error.response)
|
|
95
|
-
return true;
|
|
118
|
+
return true; // 网络错误
|
|
96
119
|
const status = error.response.status;
|
|
97
|
-
return status >= 500 || status === 429;
|
|
120
|
+
return status >= 500 || status === 429; // 5xx错误或429限流
|
|
98
121
|
},
|
|
99
122
|
}),
|
|
100
123
|
(0, decorators_1.HttpCircuitBreaker)({
|
|
101
124
|
failureThreshold: 3,
|
|
102
125
|
recoveryTimeoutMs: 30000,
|
|
103
126
|
}),
|
|
104
|
-
(0, decorators_1.HttpCacheable)({
|
|
105
|
-
ttl: 300000,
|
|
106
|
-
layers: ['cls', 'memory', 'redis'],
|
|
107
|
-
namespace: 'github',
|
|
108
|
-
}),
|
|
109
127
|
(0, decorators_1.HttpLogRequest)({
|
|
110
128
|
databaseLog: true,
|
|
111
129
|
logHeaders: true,
|
|
112
130
|
logBody: false,
|
|
113
|
-
serviceClass: 'GitHubHttpService',
|
|
114
|
-
methodName: 'getUser',
|
|
115
|
-
operationName: 'github.getUser',
|
|
131
|
+
serviceClass: 'GitHubHttpService', // 自定义服务类名
|
|
132
|
+
methodName: 'getUser', // 自定义方法名
|
|
133
|
+
operationName: 'github.getUser', // 自定义操作名
|
|
116
134
|
}),
|
|
117
135
|
(0, decorators_1.HttpTimeout)(15000),
|
|
118
136
|
__metadata("design:type", Function),
|
|
@@ -121,12 +139,6 @@ __decorate([
|
|
|
121
139
|
], GitHubHttpService.prototype, "getUser", null);
|
|
122
140
|
__decorate([
|
|
123
141
|
(0, decorators_1.HttpRetry)({ retries: 3 }),
|
|
124
|
-
(0, decorators_1.HttpCacheable)({
|
|
125
|
-
ttl: 600000,
|
|
126
|
-
layers: ['memory', 'redis'],
|
|
127
|
-
namespace: 'github-search',
|
|
128
|
-
condition: (args) => args[0].length > 2,
|
|
129
|
-
}),
|
|
130
142
|
__metadata("design:type", Function),
|
|
131
143
|
__metadata("design:paramtypes", [String, String, String]),
|
|
132
144
|
__metadata("design:returntype", Promise)
|
|
@@ -137,10 +149,6 @@ __decorate([
|
|
|
137
149
|
port: 8080,
|
|
138
150
|
protocol: 'http',
|
|
139
151
|
}),
|
|
140
|
-
(0, decorators_1.HttpCacheable)({
|
|
141
|
-
ttl: 120000,
|
|
142
|
-
namespace: 'github-repos',
|
|
143
|
-
}),
|
|
144
152
|
__metadata("design:type", Function),
|
|
145
153
|
__metadata("design:paramtypes", [String]),
|
|
146
154
|
__metadata("design:returntype", Promise)
|
|
@@ -161,39 +169,14 @@ __decorate([
|
|
|
161
169
|
failureThreshold: 5,
|
|
162
170
|
recoveryTimeoutMs: 60000,
|
|
163
171
|
}),
|
|
164
|
-
(0, decorators_1.HttpCacheable)({
|
|
165
|
-
ttl: 900000,
|
|
166
|
-
namespace: 'github-contributors',
|
|
167
|
-
}),
|
|
168
172
|
__metadata("design:type", Function),
|
|
169
173
|
__metadata("design:paramtypes", [String, String]),
|
|
170
174
|
__metadata("design:returntype", Promise)
|
|
171
175
|
], GitHubHttpService.prototype, "getRepositoryContributors", null);
|
|
172
|
-
__decorate([
|
|
173
|
-
(0, decorators_1.HttpCacheable)({
|
|
174
|
-
ttl: 120000,
|
|
175
|
-
layers: ['memory'],
|
|
176
|
-
namespace: 'github-repo-details',
|
|
177
|
-
condition: (args) => { var _a; return ((_a = args[2]) === null || _a === void 0 ? void 0 : _a.public) === true; },
|
|
178
|
-
unless: (result, args) => (result === null || result === void 0 ? void 0 : result.archived) === true,
|
|
179
|
-
}),
|
|
180
|
-
__metadata("design:type", Function),
|
|
181
|
-
__metadata("design:paramtypes", [String, String, Object]),
|
|
182
|
-
__metadata("design:returntype", Promise)
|
|
183
|
-
], GitHubHttpService.prototype, "getRepositoryDetails", null);
|
|
184
176
|
exports.GitHubHttpService = GitHubHttpService = __decorate([
|
|
185
177
|
(0, decorators_1.HttpClient)({
|
|
186
178
|
baseURL: 'https://api.github.com',
|
|
187
179
|
timeout: 10000,
|
|
188
|
-
cache: {
|
|
189
|
-
enabled: true,
|
|
190
|
-
defaultTtl: 300000,
|
|
191
|
-
cacheableMethods: ['GET', 'HEAD'],
|
|
192
|
-
cacheableStatusCodes: [200, 304],
|
|
193
|
-
options: {
|
|
194
|
-
layers: [cache_options_interface_1.CacheLayer.MEMORY, cache_options_interface_1.CacheLayer.REDIS],
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
180
|
logging: {
|
|
198
181
|
enabled: true,
|
|
199
182
|
logRequests: true,
|
|
@@ -209,10 +192,17 @@ exports.GitHubHttpService = GitHubHttpService = __decorate([
|
|
|
209
192
|
(0, common_1.Injectable)(),
|
|
210
193
|
__metadata("design:paramtypes", [http_client_service_1.HttpClientService])
|
|
211
194
|
], GitHubHttpService);
|
|
195
|
+
/**
|
|
196
|
+
* 支付服务示例 - 高安全性要求
|
|
197
|
+
* 使用Redis锁定确保并发安全
|
|
198
|
+
*/
|
|
212
199
|
let PaymentHttpService = class PaymentHttpService {
|
|
213
200
|
constructor(httpClient) {
|
|
214
201
|
this.httpClient = httpClient;
|
|
215
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* 创建支付 - 严格的安全控制
|
|
205
|
+
*/
|
|
216
206
|
createPayment(paymentData, apiKey) {
|
|
217
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
208
|
return this.httpClient.post('/payments', paymentData, {
|
|
@@ -224,6 +214,9 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
224
214
|
});
|
|
225
215
|
});
|
|
226
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* 查询支付状态
|
|
219
|
+
*/
|
|
227
220
|
getPaymentStatus(paymentId, apiKey) {
|
|
228
221
|
return __awaiter(this, void 0, void 0, function* () {
|
|
229
222
|
return this.httpClient.get(`/payments/${paymentId}`, {
|
|
@@ -233,6 +226,9 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
233
226
|
});
|
|
234
227
|
});
|
|
235
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* 退款操作 - 重试机制
|
|
231
|
+
*/
|
|
236
232
|
refundPayment(paymentId, refundData, apiKey) {
|
|
237
233
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
234
|
return this.httpClient.post(`/payments/${paymentId}/refund`, refundData, {
|
|
@@ -243,8 +239,12 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
243
239
|
});
|
|
244
240
|
});
|
|
245
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* 动态调用示例 - 手动设置调用信息
|
|
244
|
+
*/
|
|
246
245
|
callExternalApi(url_1) {
|
|
247
246
|
return __awaiter(this, arguments, void 0, function* (url, method = 'GET', data) {
|
|
247
|
+
// 手动设置调用信息
|
|
248
248
|
const { CallStackExtractor } = require('../utils');
|
|
249
249
|
CallStackExtractor.setCallInfo('PaymentHttpService', 'callExternalApi', `payment.${method.toLowerCase()}`);
|
|
250
250
|
try {
|
|
@@ -259,6 +259,7 @@ let PaymentHttpService = class PaymentHttpService {
|
|
|
259
259
|
});
|
|
260
260
|
}
|
|
261
261
|
finally {
|
|
262
|
+
// 清理调用信息
|
|
262
263
|
CallStackExtractor.clearCallInfo();
|
|
263
264
|
}
|
|
264
265
|
});
|
|
@@ -279,21 +280,12 @@ __decorate([
|
|
|
279
280
|
__metadata("design:paramtypes", [Object, String]),
|
|
280
281
|
__metadata("design:returntype", Promise)
|
|
281
282
|
], PaymentHttpService.prototype, "createPayment", null);
|
|
282
|
-
__decorate([
|
|
283
|
-
(0, decorators_1.HttpCacheable)({
|
|
284
|
-
ttl: 30000,
|
|
285
|
-
layers: ['redis'],
|
|
286
|
-
namespace: 'payment-status',
|
|
287
|
-
}),
|
|
288
|
-
__metadata("design:type", Function),
|
|
289
|
-
__metadata("design:paramtypes", [String, String]),
|
|
290
|
-
__metadata("design:returntype", Promise)
|
|
291
|
-
], PaymentHttpService.prototype, "getPaymentStatus", null);
|
|
292
283
|
__decorate([
|
|
293
284
|
(0, decorators_1.HttpRetry)({
|
|
294
285
|
retries: 2,
|
|
295
|
-
retryDelay: (retryCount) => retryCount * 2000,
|
|
286
|
+
retryDelay: (retryCount) => retryCount * 2000, // 线性退避
|
|
296
287
|
retryCondition: (error) => {
|
|
288
|
+
// 只对网络错误和5xx错误重试,4xx错误不重试
|
|
297
289
|
if (!error.response)
|
|
298
290
|
return true;
|
|
299
291
|
return error.response.status >= 500;
|
|
@@ -302,7 +294,7 @@ __decorate([
|
|
|
302
294
|
(0, decorators_1.HttpLogRequest)({
|
|
303
295
|
logHeaders: false,
|
|
304
296
|
logBody: false,
|
|
305
|
-
databaseLog: true,
|
|
297
|
+
databaseLog: true, // 退款操作需要记录到数据库
|
|
306
298
|
}),
|
|
307
299
|
__metadata("design:type", Function),
|
|
308
300
|
__metadata("design:paramtypes", [String, Object, String]),
|
|
@@ -313,15 +305,15 @@ exports.PaymentHttpService = PaymentHttpService = __decorate([
|
|
|
313
305
|
baseURL: 'https://api.payment-provider.com',
|
|
314
306
|
timeout: 15000,
|
|
315
307
|
retry: {
|
|
316
|
-
enabled: false,
|
|
308
|
+
enabled: false, // 支付操作不自动重试
|
|
317
309
|
},
|
|
318
310
|
logging: {
|
|
319
311
|
enabled: true,
|
|
320
312
|
logRequests: true,
|
|
321
313
|
logResponses: true,
|
|
322
314
|
logErrors: true,
|
|
323
|
-
logHeaders: false,
|
|
324
|
-
logBody: false,
|
|
315
|
+
logHeaders: false, // 不记录敏感头信息
|
|
316
|
+
logBody: false, // 不记录支付数据
|
|
325
317
|
maxBodyLength: 1000,
|
|
326
318
|
sanitizeHeaders: ['authorization', 'x-api-key', 'x-client-secret'],
|
|
327
319
|
logLevel: 'info',
|
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
import { HttpClientService } from '../services/http-client.service';
|
|
2
2
|
import { HttpLogQueryService } from '../services/http-log-query.service';
|
|
3
3
|
import { HttpReplayService } from '../services/http-replay.service';
|
|
4
|
+
/**
|
|
5
|
+
* 使用等待锁的认证示例
|
|
6
|
+
* 演示如何在原有的HTTP客户端中使用等待锁机制
|
|
7
|
+
*/
|
|
4
8
|
export declare class AuthWithWaitingLockExample {
|
|
5
9
|
private readonly httpClient;
|
|
6
10
|
private readonly logQueryService;
|
|
7
11
|
private readonly replayService;
|
|
8
12
|
private readonly logger;
|
|
9
13
|
constructor(httpClient: HttpClientService, logQueryService: HttpLogQueryService, replayService: HttpReplayService);
|
|
14
|
+
/**
|
|
15
|
+
* 示例1: 基本的带等待锁的认证请求
|
|
16
|
+
* 演示如何使用authRequest方法确保只有一个进程获取token
|
|
17
|
+
*/
|
|
10
18
|
basicAuthWithLock(): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* 示例2: 批量带等待锁的认证请求
|
|
21
|
+
* 演示如何在批量操作中共享token,避免重复认证
|
|
22
|
+
*/
|
|
11
23
|
batchAuthWithLock(): Promise<any[]>;
|
|
24
|
+
/**
|
|
25
|
+
* 示例3: 从HTTP日志生成curl命令
|
|
26
|
+
* 演示如何从已有的HTTP日志生成可执行的curl命令
|
|
27
|
+
*/
|
|
12
28
|
generateCurlFromLogs(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 示例4: 请求重放功能
|
|
31
|
+
* 演示如何重放已有的HTTP请求
|
|
32
|
+
*/
|
|
13
33
|
demonstrateRequestReplay(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* 示例5: 批量重放和比较
|
|
36
|
+
* 演示如何批量重放请求并比较结果
|
|
37
|
+
*/
|
|
14
38
|
batchReplayAndCompare(): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* 示例6: 综合演示 - 等待锁 + curl生成 + 请求重放
|
|
41
|
+
* 演示完整的工作流程
|
|
42
|
+
*/
|
|
15
43
|
comprehensiveDemo(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* 运行所有示例
|
|
46
|
+
*/
|
|
16
47
|
runAllExamples(): Promise<void>;
|
|
17
48
|
}
|
|
@@ -24,6 +24,10 @@ const common_1 = require("@nestjs/common");
|
|
|
24
24
|
const http_client_service_1 = require("../services/http-client.service");
|
|
25
25
|
const http_log_query_service_1 = require("../services/http-log-query.service");
|
|
26
26
|
const http_replay_service_1 = require("../services/http-replay.service");
|
|
27
|
+
/**
|
|
28
|
+
* 使用等待锁的认证示例
|
|
29
|
+
* 演示如何在原有的HTTP客户端中使用等待锁机制
|
|
30
|
+
*/
|
|
27
31
|
let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWaitingLockExample {
|
|
28
32
|
constructor(httpClient, logQueryService, replayService) {
|
|
29
33
|
this.httpClient = httpClient;
|
|
@@ -31,6 +35,10 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
31
35
|
this.replayService = replayService;
|
|
32
36
|
this.logger = new common_1.Logger(AuthWithWaitingLockExample_1.name);
|
|
33
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* 示例1: 基本的带等待锁的认证请求
|
|
40
|
+
* 演示如何使用authRequest方法确保只有一个进程获取token
|
|
41
|
+
*/
|
|
34
42
|
basicAuthWithLock() {
|
|
35
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
44
|
this.logger.log('=== 示例1: 基本带等待锁的认证请求 ===');
|
|
@@ -41,18 +49,21 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
41
49
|
Accept: 'application/vnd.github.v3+json',
|
|
42
50
|
},
|
|
43
51
|
};
|
|
52
|
+
// Token提供函数
|
|
44
53
|
const tokenProvider = () => __awaiter(this, void 0, void 0, function* () {
|
|
45
54
|
this.logger.log('开始获取GitHub访问令牌...');
|
|
55
|
+
// 模拟token获取过程
|
|
46
56
|
yield new Promise((resolve) => setTimeout(resolve, 1000));
|
|
47
57
|
const token = `ghp_${Math.random().toString(36).substring(2, 15)}${Date.now()}`;
|
|
48
58
|
this.logger.log(`成功获取令牌: ${token.substring(0, 20)}...`);
|
|
49
59
|
return token;
|
|
50
60
|
});
|
|
51
61
|
try {
|
|
62
|
+
// 使用等待锁执行认证请求
|
|
52
63
|
const response = yield this.httpClient.authRequest(requestConfig, tokenProvider, {
|
|
53
64
|
lockKey: 'github-token-refresh',
|
|
54
|
-
lockTimeout: 30000,
|
|
55
|
-
waitTimeout: 60000,
|
|
65
|
+
lockTimeout: 30000, // 30秒锁超时
|
|
66
|
+
waitTimeout: 60000, // 60秒等待超时
|
|
56
67
|
enableRetry: true,
|
|
57
68
|
});
|
|
58
69
|
this.logger.log('认证请求成功完成');
|
|
@@ -64,6 +75,10 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
64
75
|
}
|
|
65
76
|
});
|
|
66
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* 示例2: 批量带等待锁的认证请求
|
|
80
|
+
* 演示如何在批量操作中共享token,避免重复认证
|
|
81
|
+
*/
|
|
67
82
|
batchAuthWithLock() {
|
|
68
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
69
84
|
this.logger.log('=== 示例2: 批量带等待锁的认证请求 ===');
|
|
@@ -90,6 +105,7 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
90
105
|
key: 'user-followers',
|
|
91
106
|
},
|
|
92
107
|
];
|
|
108
|
+
// Token提供函数
|
|
93
109
|
const tokenProvider = () => __awaiter(this, void 0, void 0, function* () {
|
|
94
110
|
this.logger.log('开始获取批量操作的GitHub访问令牌...');
|
|
95
111
|
yield new Promise((resolve) => setTimeout(resolve, 1500));
|
|
@@ -99,11 +115,12 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
99
115
|
});
|
|
100
116
|
try {
|
|
101
117
|
const startTime = Date.now();
|
|
118
|
+
// 使用批量认证请求,所有请求共享同一个token
|
|
102
119
|
const results = yield this.httpClient.authBatchRequest(requests, tokenProvider, {
|
|
103
120
|
lockKey: 'github-batch-token-refresh',
|
|
104
|
-
lockTimeout: 60000,
|
|
105
|
-
waitTimeout: 120000,
|
|
106
|
-
maxConcurrency: 3,
|
|
121
|
+
lockTimeout: 60000, // 60秒锁超时
|
|
122
|
+
waitTimeout: 120000, // 2分钟等待超时
|
|
123
|
+
maxConcurrency: 3, // 最大并发数
|
|
107
124
|
});
|
|
108
125
|
const endTime = Date.now();
|
|
109
126
|
const duration = endTime - startTime;
|
|
@@ -125,10 +142,15 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
125
142
|
}
|
|
126
143
|
});
|
|
127
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* 示例3: 从HTTP日志生成curl命令
|
|
147
|
+
* 演示如何从已有的HTTP日志生成可执行的curl命令
|
|
148
|
+
*/
|
|
128
149
|
generateCurlFromLogs() {
|
|
129
150
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
151
|
this.logger.log('=== 示例3: 从HTTP日志生成curl命令 ===');
|
|
131
152
|
try {
|
|
153
|
+
// 查询最近的日志
|
|
132
154
|
const recentLogs = yield this.logQueryService.findLogs({
|
|
133
155
|
limit: 5,
|
|
134
156
|
sortBy: 'createdAt',
|
|
@@ -139,6 +161,7 @@ let AuthWithWaitingLockExample = AuthWithWaitingLockExample_1 = class AuthWithWa
|
|
|
139
161
|
return;
|
|
140
162
|
}
|
|
141
163
|
this.logger.log(`找到 ${recentLogs.logs.length} 条最近的HTTP日志`);
|
|
164
|
+
// 为每条日志生成curl命令
|
|
142
165
|
for (const log of recentLogs.logs) {
|
|
143
166
|
const curlCommand = yield this.logQueryService.generateCurlFromLog(log.id);
|
|
144
167
|
if (curlCommand) {
|
|
@@ -148,6 +171,7 @@ ${curlCommand}
|
|
|
148
171
|
`);
|
|
149
172
|
}
|
|
150
173
|
}
|
|
174
|
+
// 批量生成curl命令
|
|
151
175
|
const batchCurlCommands = yield this.logQueryService.generateBatchCurlCommands({
|
|
152
176
|
limit: 3,
|
|
153
177
|
method: 'GET',
|
|
@@ -159,11 +183,16 @@ ${curlCommand}
|
|
|
159
183
|
}
|
|
160
184
|
});
|
|
161
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* 示例4: 请求重放功能
|
|
188
|
+
* 演示如何重放已有的HTTP请求
|
|
189
|
+
*/
|
|
162
190
|
demonstrateRequestReplay() {
|
|
163
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
164
192
|
var _a, _b, _c;
|
|
165
193
|
this.logger.log('=== 示例4: 请求重放功能 ===');
|
|
166
194
|
try {
|
|
195
|
+
// 查询一个成功的请求进行重放
|
|
167
196
|
const successfulLogs = yield this.logQueryService.findLogs({
|
|
168
197
|
limit: 1,
|
|
169
198
|
success: true,
|
|
@@ -177,6 +206,7 @@ ${curlCommand}
|
|
|
177
206
|
}
|
|
178
207
|
const logToReplay = successfulLogs.logs[0];
|
|
179
208
|
this.logger.log(`准备重放请求: ${logToReplay.method} ${logToReplay.url}`);
|
|
209
|
+
// 重放请求
|
|
180
210
|
const replayResult = yield this.replayService.replayByLogId(logToReplay.id, {
|
|
181
211
|
overrideHeaders: false,
|
|
182
212
|
additionalHeaders: {
|
|
@@ -206,11 +236,16 @@ ${curlCommand}
|
|
|
206
236
|
}
|
|
207
237
|
});
|
|
208
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* 示例5: 批量重放和比较
|
|
241
|
+
* 演示如何批量重放请求并比较结果
|
|
242
|
+
*/
|
|
209
243
|
batchReplayAndCompare() {
|
|
210
244
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
245
|
var _a, _b, _c;
|
|
212
246
|
this.logger.log('=== 示例5: 批量重放和比较 ===');
|
|
213
247
|
try {
|
|
248
|
+
// 查询最近的3个GET请求进行批量重放
|
|
214
249
|
const batchReplayResult = yield this.replayService.batchReplayByQuery({
|
|
215
250
|
method: 'GET',
|
|
216
251
|
limit: 3,
|
|
@@ -234,6 +269,7 @@ ${curlCommand}
|
|
|
234
269
|
│ 平均响应时间 │ ${batchReplayResult.averageResponseTime.toFixed(1).toString().padStart(7)}ms │
|
|
235
270
|
└─────────────────┴──────────┘
|
|
236
271
|
`);
|
|
272
|
+
// 详细比较每个重放结果
|
|
237
273
|
for (let i = 0; i < Math.min(batchReplayResult.results.length, 3); i++) {
|
|
238
274
|
const result = batchReplayResult.results[i];
|
|
239
275
|
if (result.originalLog.id) {
|
|
@@ -262,12 +298,18 @@ ${curlCommand}
|
|
|
262
298
|
}
|
|
263
299
|
});
|
|
264
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* 示例6: 综合演示 - 等待锁 + curl生成 + 请求重放
|
|
303
|
+
* 演示完整的工作流程
|
|
304
|
+
*/
|
|
265
305
|
comprehensiveDemo() {
|
|
266
306
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
307
|
this.logger.log('=== 示例6: 综合演示 ===');
|
|
268
308
|
try {
|
|
309
|
+
// 1. 执行带等待锁的认证请求
|
|
269
310
|
this.logger.log('步骤1: 执行带等待锁的认证请求');
|
|
270
311
|
const authResponse = yield this.basicAuthWithLock();
|
|
312
|
+
// 2. 查询刚才的请求日志
|
|
271
313
|
this.logger.log('\n步骤2: 查询请求日志');
|
|
272
314
|
const recentLogs = yield this.logQueryService.findLogs({
|
|
273
315
|
limit: 1,
|
|
@@ -276,12 +318,14 @@ ${curlCommand}
|
|
|
276
318
|
});
|
|
277
319
|
if (recentLogs.logs.length > 0) {
|
|
278
320
|
const log = recentLogs.logs[0];
|
|
321
|
+
// 3. 生成curl命令
|
|
279
322
|
this.logger.log('\n步骤3: 生成curl命令');
|
|
280
323
|
const curlCommand = yield this.logQueryService.generateCurlFromLog(log.id);
|
|
281
324
|
if (curlCommand) {
|
|
282
325
|
this.logger.log('生成的curl命令:');
|
|
283
326
|
this.logger.log(curlCommand);
|
|
284
327
|
}
|
|
328
|
+
// 4. 重放请求
|
|
285
329
|
this.logger.log('\n步骤4: 重放请求');
|
|
286
330
|
const replayResult = yield this.replayService.replayByLogId(log.id, {
|
|
287
331
|
additionalHeaders: {
|
|
@@ -304,6 +348,9 @@ ${curlCommand}
|
|
|
304
348
|
}
|
|
305
349
|
});
|
|
306
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* 运行所有示例
|
|
353
|
+
*/
|
|
307
354
|
runAllExamples() {
|
|
308
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
356
|
this.logger.log('开始运行HTTP客户端等待锁和请求重放示例...\n');
|