@vtex/api 6.45.4
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/CHANGELOG.md +1685 -0
- package/README.md +65 -0
- package/gen/manifest.schema +189 -0
- package/lib/HttpClient/GraphQLClient.d.ts +28 -0
- package/lib/HttpClient/GraphQLClient.js +30 -0
- package/lib/HttpClient/HttpClient.d.ts +29 -0
- package/lib/HttpClient/HttpClient.js +130 -0
- package/lib/HttpClient/agents.d.ts +3 -0
- package/lib/HttpClient/agents.js +24 -0
- package/lib/HttpClient/index.d.ts +6 -0
- package/lib/HttpClient/index.js +14 -0
- package/lib/HttpClient/middlewares/cache.d.ts +35 -0
- package/lib/HttpClient/middlewares/cache.js +173 -0
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +3 -0
- package/lib/HttpClient/middlewares/cancellationToken.js +72 -0
- package/lib/HttpClient/middlewares/inflight.d.ts +5 -0
- package/lib/HttpClient/middlewares/inflight.js +50 -0
- package/lib/HttpClient/middlewares/memoization.d.ts +7 -0
- package/lib/HttpClient/middlewares/memoization.js +40 -0
- package/lib/HttpClient/middlewares/metrics.d.ts +9 -0
- package/lib/HttpClient/middlewares/metrics.js +110 -0
- package/lib/HttpClient/middlewares/notFound.d.ts +7 -0
- package/lib/HttpClient/middlewares/notFound.js +20 -0
- package/lib/HttpClient/middlewares/recorder.d.ts +3 -0
- package/lib/HttpClient/middlewares/recorder.js +21 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +14 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +37 -0
- package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
- package/lib/HttpClient/middlewares/request/index.js +83 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +20 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +48 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +7 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +51 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +29 -0
- package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
- package/lib/HttpClient/middlewares/tracing.js +54 -0
- package/lib/HttpClient/typings.d.ts +123 -0
- package/lib/HttpClient/typings.js +11 -0
- package/lib/caches/CacheLayer.d.ts +7 -0
- package/lib/caches/CacheLayer.js +2 -0
- package/lib/caches/DiskCache.d.ts +17 -0
- package/lib/caches/DiskCache.js +70 -0
- package/lib/caches/LRUCache.d.ts +16 -0
- package/lib/caches/LRUCache.js +48 -0
- package/lib/caches/LRUDiskCache.d.ts +21 -0
- package/lib/caches/LRUDiskCache.js +132 -0
- package/lib/caches/MultilayeredCache.d.ts +14 -0
- package/lib/caches/MultilayeredCache.js +68 -0
- package/lib/caches/index.d.ts +6 -0
- package/lib/caches/index.js +9 -0
- package/lib/caches/typings.d.ts +48 -0
- package/lib/caches/typings.js +2 -0
- package/lib/clients/IOClient.d.ts +13 -0
- package/lib/clients/IOClient.js +19 -0
- package/lib/clients/IOClients.d.ts +37 -0
- package/lib/clients/IOClients.js +89 -0
- package/lib/clients/IOGraphQLClient.d.ts +13 -0
- package/lib/clients/IOGraphQLClient.js +16 -0
- package/lib/clients/apps/AppClient.d.ts +9 -0
- package/lib/clients/apps/AppClient.js +34 -0
- package/lib/clients/apps/AppGraphQLClient.d.ts +9 -0
- package/lib/clients/apps/AppGraphQLClient.js +34 -0
- package/lib/clients/apps/Billing.d.ts +12 -0
- package/lib/clients/apps/Billing.js +21 -0
- package/lib/clients/apps/Builder.d.ts +45 -0
- package/lib/clients/apps/Builder.js +114 -0
- package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
- package/lib/clients/apps/MessagesGraphQL.js +121 -0
- package/lib/clients/apps/Settings.d.ts +14 -0
- package/lib/clients/apps/Settings.js +38 -0
- package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
- package/lib/clients/apps/catalogGraphQL/brand.js +18 -0
- package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
- package/lib/clients/apps/catalogGraphQL/category.js +16 -0
- package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
- package/lib/clients/apps/catalogGraphQL/index.js +88 -0
- package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
- package/lib/clients/apps/catalogGraphQL/product.js +30 -0
- package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
- package/lib/clients/apps/catalogGraphQL/sku.js +30 -0
- package/lib/clients/apps/index.d.ts +7 -0
- package/lib/clients/apps/index.js +12 -0
- package/lib/clients/external/ExternalClient.d.ts +9 -0
- package/lib/clients/external/ExternalClient.js +21 -0
- package/lib/clients/external/ID.d.ts +23 -0
- package/lib/clients/external/ID.js +60 -0
- package/lib/clients/external/Masterdata.d.ts +93 -0
- package/lib/clients/external/Masterdata.js +223 -0
- package/lib/clients/external/PaymentProvider.d.ts +31 -0
- package/lib/clients/external/PaymentProvider.js +42 -0
- package/lib/clients/external/index.d.ts +4 -0
- package/lib/clients/external/index.js +9 -0
- package/lib/clients/index.d.ts +9 -0
- package/lib/clients/index.js +17 -0
- package/lib/clients/infra/Apps.d.ts +88 -0
- package/lib/clients/infra/Apps.js +508 -0
- package/lib/clients/infra/Assets.d.ts +34 -0
- package/lib/clients/infra/Assets.js +165 -0
- package/lib/clients/infra/BillingMetrics.d.ts +13 -0
- package/lib/clients/infra/BillingMetrics.js +15 -0
- package/lib/clients/infra/Events.d.ts +12 -0
- package/lib/clients/infra/Events.js +33 -0
- package/lib/clients/infra/Housekeeper.d.ts +10 -0
- package/lib/clients/infra/Housekeeper.js +30 -0
- package/lib/clients/infra/InfraClient.d.ts +9 -0
- package/lib/clients/infra/InfraClient.js +34 -0
- package/lib/clients/infra/Metadata.d.ts +26 -0
- package/lib/clients/infra/Metadata.js +83 -0
- package/lib/clients/infra/Registry.d.ts +59 -0
- package/lib/clients/infra/Registry.js +207 -0
- package/lib/clients/infra/Router.d.ts +34 -0
- package/lib/clients/infra/Router.js +81 -0
- package/lib/clients/infra/Sphinx.d.ts +13 -0
- package/lib/clients/infra/Sphinx.js +29 -0
- package/lib/clients/infra/VBase.d.ts +60 -0
- package/lib/clients/infra/VBase.js +171 -0
- package/lib/clients/infra/Workspaces.d.ts +18 -0
- package/lib/clients/infra/Workspaces.js +65 -0
- package/lib/clients/infra/index.d.ts +12 -0
- package/lib/clients/infra/index.js +17 -0
- package/lib/clients/janus/JanusClient.d.ts +21 -0
- package/lib/clients/janus/JanusClient.js +30 -0
- package/lib/clients/janus/LicenseManager.d.ts +7 -0
- package/lib/clients/janus/LicenseManager.js +58 -0
- package/lib/clients/janus/Segment.d.ts +36 -0
- package/lib/clients/janus/Segment.js +79 -0
- package/lib/clients/janus/Session.d.ts +15 -0
- package/lib/clients/janus/Session.js +75 -0
- package/lib/clients/janus/Tenant.d.ts +29 -0
- package/lib/clients/janus/Tenant.js +28 -0
- package/lib/clients/janus/index.d.ts +5 -0
- package/lib/clients/janus/index.js +10 -0
- package/lib/constants.d.ts +59 -0
- package/lib/constants.js +65 -0
- package/lib/errors/AuthenticationError.d.ts +18 -0
- package/lib/errors/AuthenticationError.js +24 -0
- package/lib/errors/ForbiddenError.d.ts +18 -0
- package/lib/errors/ForbiddenError.js +24 -0
- package/lib/errors/NotFoundError.d.ts +18 -0
- package/lib/errors/NotFoundError.js +24 -0
- package/lib/errors/RequestCancelledError.d.ts +6 -0
- package/lib/errors/RequestCancelledError.js +11 -0
- package/lib/errors/ResolverError.d.ts +29 -0
- package/lib/errors/ResolverError.js +35 -0
- package/lib/errors/ResolverWarning.d.ts +21 -0
- package/lib/errors/ResolverWarning.js +28 -0
- package/lib/errors/TooManyRequestsError.d.ts +4 -0
- package/lib/errors/TooManyRequestsError.js +9 -0
- package/lib/errors/UserInputError.d.ts +18 -0
- package/lib/errors/UserInputError.js +24 -0
- package/lib/errors/customGraphQLError.d.ts +4 -0
- package/lib/errors/customGraphQLError.js +9 -0
- package/lib/errors/index.d.ts +8 -0
- package/lib/errors/index.js +13 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +21 -0
- package/lib/metrics/MetricsAccumulator.d.ts +35 -0
- package/lib/metrics/MetricsAccumulator.js +125 -0
- package/lib/responses.d.ts +79 -0
- package/lib/responses.js +2 -0
- package/lib/service/index.d.ts +2 -0
- package/lib/service/index.js +30 -0
- package/lib/service/loaders.d.ts +8 -0
- package/lib/service/loaders.js +54 -0
- package/lib/service/logger/console.d.ts +10 -0
- package/lib/service/logger/console.js +36 -0
- package/lib/service/logger/index.d.ts +2 -0
- package/lib/service/logger/index.js +7 -0
- package/lib/service/logger/logger.d.ts +35 -0
- package/lib/service/logger/logger.js +73 -0
- package/lib/service/logger/metricsLogger.d.ts +40 -0
- package/lib/service/logger/metricsLogger.js +149 -0
- package/lib/service/master.d.ts +2 -0
- package/lib/service/master.js +91 -0
- package/lib/service/tracing/TracerSingleton.d.ts +7 -0
- package/lib/service/tracing/TracerSingleton.js +54 -0
- package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
- package/lib/service/tracing/metrics/MetricNames.js +44 -0
- package/lib/service/tracing/metrics/instruments.d.ts +9 -0
- package/lib/service/tracing/metrics/instruments.js +11 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +25 -0
- package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
- package/lib/service/tracing/tracingMiddlewares.js +119 -0
- package/lib/service/worker/index.d.ts +11 -0
- package/lib/service/worker/index.js +193 -0
- package/lib/service/worker/listeners.d.ts +3 -0
- package/lib/service/worker/listeners.js +43 -0
- package/lib/service/worker/runtime/Service.d.ts +17 -0
- package/lib/service/worker/runtime/Service.js +23 -0
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/handlers.js +27 -0
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/middlewares.js +40 -0
- package/lib/service/worker/runtime/events/index.d.ts +4 -0
- package/lib/service/worker/runtime/events/index.js +46 -0
- package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/body.js +22 -0
- package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/context.js +22 -0
- package/lib/service/worker/runtime/events/router.d.ts +2 -0
- package/lib/service/worker/runtime/events/router.js +27 -0
- package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/index.js +27 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.js +16 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.js +93 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.js +52 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.js +38 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.js +19 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +28 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/index.js +31 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +79 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +73 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +37 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +61 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +40 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.d.ts +9 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.js +35 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +34 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.js +29 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +39 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +33 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +36 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +12 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.d.ts +3 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.js +16 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.d.ts +10 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +39 -0
- package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
- package/lib/service/worker/runtime/graphql/typings.js +2 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +32 -0
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +76 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.d.ts +1 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.js +7 -0
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
- package/lib/service/worker/runtime/graphql/utils/translations.js +38 -0
- package/lib/service/worker/runtime/http/index.d.ts +5 -0
- package/lib/service/worker/runtime/http/index.js +58 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.js +18 -0
- package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/clients.js +12 -0
- package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/context.js +36 -0
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
- package/lib/service/worker/runtime/http/middlewares/error.js +84 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +42 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.d.ts +17 -0
- package/lib/service/worker/runtime/http/middlewares/requestStats.js +40 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.js +52 -0
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
- package/lib/service/worker/runtime/http/middlewares/settings.js +43 -0
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/timings.js +45 -0
- package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
- package/lib/service/worker/runtime/http/middlewares/vary.js +52 -0
- package/lib/service/worker/runtime/http/router.d.ts +2 -0
- package/lib/service/worker/runtime/http/router.js +23 -0
- package/lib/service/worker/runtime/http/routes.d.ts +19 -0
- package/lib/service/worker/runtime/http/routes.js +12 -0
- package/lib/service/worker/runtime/method.d.ts +9 -0
- package/lib/service/worker/runtime/method.js +23 -0
- package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
- package/lib/service/worker/runtime/statusTrack.js +37 -0
- package/lib/service/worker/runtime/typings.d.ts +172 -0
- package/lib/service/worker/runtime/typings.js +2 -0
- package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
- package/lib/service/worker/runtime/utils/compose.js +11 -0
- package/lib/service/worker/runtime/utils/context.d.ts +2 -0
- package/lib/service/worker/runtime/utils/context.js +40 -0
- package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
- package/lib/service/worker/runtime/utils/diff.js +21 -0
- package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
- package/lib/service/worker/runtime/utils/recorder.js +37 -0
- package/lib/service/worker/runtime/utils/toArray.d.ts +1 -0
- package/lib/service/worker/runtime/utils/toArray.js +3 -0
- package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
- package/lib/service/worker/runtime/utils/tokenBucket.js +16 -0
- package/lib/tracing/LogEvents.d.ts +31 -0
- package/lib/tracing/LogEvents.js +3 -0
- package/lib/tracing/LogFields.d.ts +61 -0
- package/lib/tracing/LogFields.js +3 -0
- package/lib/tracing/Tags.d.ts +79 -0
- package/lib/tracing/Tags.js +7 -0
- package/lib/tracing/UserLandTracer.d.ts +27 -0
- package/lib/tracing/UserLandTracer.js +55 -0
- package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
- package/lib/tracing/errorReporting/ErrorReport.js +61 -0
- package/lib/tracing/index.d.ts +9 -0
- package/lib/tracing/index.js +19 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.js +7 -0
- package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
- package/lib/tracing/spanReference/createSpanReference.js +8 -0
- package/lib/tracing/utils.d.ts +13 -0
- package/lib/tracing/utils.js +40 -0
- package/lib/utils/MineWinsConflictsResolver.d.ts +28 -0
- package/lib/utils/MineWinsConflictsResolver.js +130 -0
- package/lib/utils/app.d.ts +23 -0
- package/lib/utils/app.js +48 -0
- package/lib/utils/appsStaleIfError.d.ts +11 -0
- package/lib/utils/appsStaleIfError.js +63 -0
- package/lib/utils/billingOptions.d.ts +36 -0
- package/lib/utils/billingOptions.js +9 -0
- package/lib/utils/binding.d.ts +13 -0
- package/lib/utils/binding.js +38 -0
- package/lib/utils/cancel.d.ts +3 -0
- package/lib/utils/cancel.js +12 -0
- package/lib/utils/domain.d.ts +1 -0
- package/lib/utils/domain.js +5 -0
- package/lib/utils/error.d.ts +8 -0
- package/lib/utils/error.js +94 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +14 -0
- package/lib/utils/message.d.ts +25 -0
- package/lib/utils/message.js +23 -0
- package/lib/utils/renameBy.d.ts +1 -0
- package/lib/utils/renameBy.js +4 -0
- package/lib/utils/retry.d.ts +4 -0
- package/lib/utils/retry.js +32 -0
- package/lib/utils/status.d.ts +1 -0
- package/lib/utils/status.js +11 -0
- package/lib/utils/tenant.d.ts +5 -0
- package/lib/utils/tenant.js +6 -0
- package/lib/utils/throwOnGraphQLErrors.d.ts +2 -0
- package/lib/utils/throwOnGraphQLErrors.js +15 -0
- package/lib/utils/time.d.ts +31 -0
- package/lib/utils/time.js +118 -0
- package/package.json +127 -0
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import HttpAgent, { HttpOptions as AgentHttpOptions, HttpsAgent, HttpsOptions as AgentHttpsOptions } from 'agentkeepalive';
|
|
2
|
+
export declare const createHttpAgent: (opts?: Pick<AgentHttpOptions, "freeSocketKeepAliveTimeout" | "timeout" | "socketActiveTTL" | "keepAliveMsecs" | "maxSockets"> | undefined) => HttpAgent;
|
|
3
|
+
export declare const createHttpsAgent: (opts?: Pick<AgentHttpsOptions, "freeSocketKeepAliveTimeout" | "timeout" | "socketActiveTTL" | "keepAliveMsecs" | "maxSockets" | "rejectUnauthorized" | "maxCachedSessions" | "host" | "port" | "path" | "socket" | "checkServerIdentity" | "servername" | "session" | "minDHSize" | "lookup" | "ca" | "cert" | "sigalgs" | "ciphers" | "clientCertEngine" | "crl" | "dhparam" | "ecdhCurve" | "honorCipherOrder" | "key" | "privateKeyEngine" | "privateKeyIdentifier" | "maxVersion" | "minVersion" | "passphrase" | "pfx" | "secureOptions" | "secureProtocol" | "sessionIdContext" | "secureContext" | "enableTrace" | "requestCert" | "ALPNProtocols" | "SNICallback"> | undefined) => HttpsAgent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
|
+
if (mod && mod.__esModule) return mod;
|
|
4
|
+
var result = {};
|
|
5
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
6
|
+
result["default"] = mod;
|
|
7
|
+
return result;
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const agentkeepalive_1 = __importStar(require("agentkeepalive"));
|
|
11
|
+
exports.createHttpAgent = (opts) => new agentkeepalive_1.default({
|
|
12
|
+
...opts,
|
|
13
|
+
freeSocketTimeout: 30 * 1000,
|
|
14
|
+
keepAlive: true,
|
|
15
|
+
maxFreeSockets: 256,
|
|
16
|
+
socketActiveTTL: 120 * 1000,
|
|
17
|
+
});
|
|
18
|
+
exports.createHttpsAgent = (opts) => new agentkeepalive_1.HttpsAgent({
|
|
19
|
+
...opts,
|
|
20
|
+
freeSocketTimeout: 30 * 1000,
|
|
21
|
+
keepAlive: true,
|
|
22
|
+
maxFreeSockets: 256,
|
|
23
|
+
socketActiveTTL: 120 * 1000,
|
|
24
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function __export(m) {
|
|
3
|
+
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
4
|
+
}
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
__export(require("./HttpClient"));
|
|
7
|
+
__export(require("./typings"));
|
|
8
|
+
__export(require("./GraphQLClient"));
|
|
9
|
+
__export(require("./agents"));
|
|
10
|
+
var cache_1 = require("./middlewares/cache");
|
|
11
|
+
exports.CacheType = cache_1.CacheType;
|
|
12
|
+
var inflight_1 = require("./middlewares/inflight");
|
|
13
|
+
exports.inflightURL = inflight_1.inflightURL;
|
|
14
|
+
exports.inflightUrlWithQuery = inflight_1.inflightUrlWithQuery;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
3
|
+
import { CacheLayer } from '../../caches/CacheLayer';
|
|
4
|
+
import { MiddlewareContext, RequestConfig } from '../typings';
|
|
5
|
+
export declare const cacheKey: (config: AxiosRequestConfig) => string;
|
|
6
|
+
export declare function isLocallyCacheable(arg: RequestConfig, type: CacheType): arg is CacheableRequestConfig;
|
|
7
|
+
export declare enum CacheType {
|
|
8
|
+
None = 0,
|
|
9
|
+
Memory = 1,
|
|
10
|
+
Disk = 2,
|
|
11
|
+
Any = 3
|
|
12
|
+
}
|
|
13
|
+
export declare const enum CacheResult {
|
|
14
|
+
HIT = "HIT",
|
|
15
|
+
MISS = "MISS",
|
|
16
|
+
STALE = "STALE"
|
|
17
|
+
}
|
|
18
|
+
interface CacheOptions {
|
|
19
|
+
type: CacheType;
|
|
20
|
+
storage: CacheLayer<string, Cached>;
|
|
21
|
+
}
|
|
22
|
+
export declare const cacheMiddleware: ({ type, storage }: CacheOptions) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
23
|
+
export interface Cached {
|
|
24
|
+
etag: string;
|
|
25
|
+
expiration: number;
|
|
26
|
+
response: Partial<AxiosResponse>;
|
|
27
|
+
responseType?: string;
|
|
28
|
+
responseEncoding?: BufferEncoding;
|
|
29
|
+
}
|
|
30
|
+
export declare type CacheableRequestConfig = RequestConfig & {
|
|
31
|
+
url: string;
|
|
32
|
+
cacheable: CacheType;
|
|
33
|
+
memoizable: boolean;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../../constants");
|
|
4
|
+
const RANGE_HEADER_QS_KEY = '__range_header';
|
|
5
|
+
const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501]; // https://tools.ietf.org/html/rfc7231#section-6.1
|
|
6
|
+
exports.cacheKey = (config) => {
|
|
7
|
+
const { baseURL = '', url = '', params, headers } = config;
|
|
8
|
+
const locale = headers[constants_1.LOCALE_HEADER];
|
|
9
|
+
const encodedBaseURL = baseURL.replace(/\//g, '\\');
|
|
10
|
+
const encodedURL = url.replace(/\//g, '\\');
|
|
11
|
+
let key = `${locale}--${encodedBaseURL}--${encodedURL}?`;
|
|
12
|
+
if (params) {
|
|
13
|
+
Object.keys(params).sort().forEach(p => key = key.concat(`--${p}=${params[p]}`));
|
|
14
|
+
}
|
|
15
|
+
if (headers === null || headers === void 0 ? void 0 : headers.range) {
|
|
16
|
+
key = key.concat(`--${RANGE_HEADER_QS_KEY}=${headers.range}`);
|
|
17
|
+
}
|
|
18
|
+
return key;
|
|
19
|
+
};
|
|
20
|
+
const parseCacheHeaders = (headers) => {
|
|
21
|
+
const { 'cache-control': cacheControl = '', etag, age: ageStr } = headers;
|
|
22
|
+
const cacheDirectives = cacheControl.split(',').map(d => d.trim());
|
|
23
|
+
const maxAgeDirective = cacheDirectives.find(d => d.startsWith('max-age'));
|
|
24
|
+
const [, maxAgeStr] = maxAgeDirective ? maxAgeDirective.split('=') : [null, null];
|
|
25
|
+
const maxAge = maxAgeStr ? parseInt(maxAgeStr, 10) : 0;
|
|
26
|
+
const age = ageStr ? parseInt(ageStr, 10) : 0;
|
|
27
|
+
return {
|
|
28
|
+
age,
|
|
29
|
+
etag,
|
|
30
|
+
maxAge,
|
|
31
|
+
noCache: cacheDirectives.indexOf('no-cache') !== -1,
|
|
32
|
+
noStore: cacheDirectives.indexOf('no-store') !== -1,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
function isLocallyCacheable(arg, type) {
|
|
36
|
+
return arg && !!arg.cacheable
|
|
37
|
+
&& (arg.cacheable === type || arg.cacheable === CacheType.Any || type === CacheType.Any);
|
|
38
|
+
}
|
|
39
|
+
exports.isLocallyCacheable = isLocallyCacheable;
|
|
40
|
+
const addNotModified = (validateStatus) => (status) => validateStatus(status) || status === 304;
|
|
41
|
+
var CacheType;
|
|
42
|
+
(function (CacheType) {
|
|
43
|
+
CacheType[CacheType["None"] = 0] = "None";
|
|
44
|
+
CacheType[CacheType["Memory"] = 1] = "Memory";
|
|
45
|
+
CacheType[CacheType["Disk"] = 2] = "Disk";
|
|
46
|
+
CacheType[CacheType["Any"] = 3] = "Any";
|
|
47
|
+
})(CacheType = exports.CacheType || (exports.CacheType = {}));
|
|
48
|
+
const CacheTypeNames = {
|
|
49
|
+
[CacheType.None]: 'none',
|
|
50
|
+
[CacheType.Memory]: 'memory',
|
|
51
|
+
[CacheType.Disk]: 'disk',
|
|
52
|
+
[CacheType.Any]: 'any',
|
|
53
|
+
};
|
|
54
|
+
exports.cacheMiddleware = ({ type, storage }) => {
|
|
55
|
+
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* HTTP_MEMORY_CACHE_RESULT */;
|
|
56
|
+
const cacheType = CacheTypeNames[type];
|
|
57
|
+
return async (ctx, next) => {
|
|
58
|
+
if (!isLocallyCacheable(ctx.config, type)) {
|
|
59
|
+
return await next();
|
|
60
|
+
}
|
|
61
|
+
const span = ctx.tracing.rootSpan;
|
|
62
|
+
const key = exports.cacheKey(ctx.config);
|
|
63
|
+
const segmentToken = ctx.config.headers[constants_1.SEGMENT_HEADER];
|
|
64
|
+
const keyWithSegment = key + segmentToken;
|
|
65
|
+
span.log({
|
|
66
|
+
event: "cache-key-created" /* CACHE_KEY_CREATE */,
|
|
67
|
+
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
68
|
+
["key" /* KEY */]: key,
|
|
69
|
+
["key-with-segment" /* KEY_WITH_SEGMENT */]: keyWithSegment,
|
|
70
|
+
});
|
|
71
|
+
const cacheHasWithSegment = await storage.has(keyWithSegment);
|
|
72
|
+
const cached = cacheHasWithSegment ? await storage.get(keyWithSegment) : await storage.get(key);
|
|
73
|
+
if (cached && cached.response) {
|
|
74
|
+
const { etag: cachedEtag, response, expiration, responseType, responseEncoding } = cached;
|
|
75
|
+
if (type === CacheType.Disk && responseType === 'arraybuffer') {
|
|
76
|
+
response.data = Buffer.from(response.data, responseEncoding);
|
|
77
|
+
}
|
|
78
|
+
const now = Date.now();
|
|
79
|
+
span.log({
|
|
80
|
+
event: "local-cache-hit-info" /* LOCAL_CACHE_HIT_INFO */,
|
|
81
|
+
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
82
|
+
["etag" /* ETAG */]: cachedEtag,
|
|
83
|
+
["expiration-time" /* EXPIRATION_TIME */]: (expiration - now) / 1000,
|
|
84
|
+
["response-type" /* RESPONSE_TYPE */]: responseType,
|
|
85
|
+
["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
|
|
86
|
+
});
|
|
87
|
+
if (expiration > now) {
|
|
88
|
+
ctx.response = response;
|
|
89
|
+
ctx.cacheHit = {
|
|
90
|
+
memory: 1,
|
|
91
|
+
revalidated: 0,
|
|
92
|
+
router: 0,
|
|
93
|
+
};
|
|
94
|
+
span.setTag(CACHE_RESULT_TAG, "HIT" /* HIT */);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
span.setTag(CACHE_RESULT_TAG, "STALE" /* STALE */);
|
|
98
|
+
const validateStatus = addNotModified(ctx.config.validateStatus);
|
|
99
|
+
if (cachedEtag && validateStatus(response.status)) {
|
|
100
|
+
ctx.config.headers['if-none-match'] = cachedEtag;
|
|
101
|
+
ctx.config.validateStatus = validateStatus;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
span.setTag(CACHE_RESULT_TAG, "MISS" /* MISS */);
|
|
106
|
+
}
|
|
107
|
+
await next();
|
|
108
|
+
if (!ctx.response) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const revalidated = ctx.response.status === 304;
|
|
112
|
+
if (revalidated && cached) {
|
|
113
|
+
ctx.response = cached.response;
|
|
114
|
+
ctx.cacheHit = {
|
|
115
|
+
memory: 1,
|
|
116
|
+
revalidated: 1,
|
|
117
|
+
router: 0,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const { data, headers, status } = ctx.response;
|
|
121
|
+
const { age, etag, maxAge: headerMaxAge, noStore, noCache } = parseCacheHeaders(headers);
|
|
122
|
+
const { forceMaxAge } = ctx.config;
|
|
123
|
+
const maxAge = forceMaxAge && cacheableStatusCodes.includes(status) ? Math.max(forceMaxAge, headerMaxAge) : headerMaxAge;
|
|
124
|
+
span.log({
|
|
125
|
+
event: "cache-config" /* CACHE_CONFIG */,
|
|
126
|
+
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
127
|
+
["age" /* AGE */]: age,
|
|
128
|
+
["calculated-max-age" /* CALCULATED_MAX_AGE */]: maxAge,
|
|
129
|
+
["max-age" /* MAX_AGE */]: headerMaxAge,
|
|
130
|
+
["force-max-age" /* FORCE_MAX_AGE */]: forceMaxAge,
|
|
131
|
+
["etag" /* ETAG */]: etag,
|
|
132
|
+
["no-cache" /* NO_CACHE */]: noCache,
|
|
133
|
+
["no-store" /* NO_STORE */]: noStore,
|
|
134
|
+
});
|
|
135
|
+
// Indicates this should NOT be cached and this request will not be considered a miss.
|
|
136
|
+
if (!forceMaxAge && (noStore || (noCache && !etag))) {
|
|
137
|
+
span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const shouldCache = maxAge || etag;
|
|
141
|
+
const varySession = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.SESSION_HEADER);
|
|
142
|
+
if (shouldCache && !varySession) {
|
|
143
|
+
const { responseType, responseEncoding: configResponseEncoding } = ctx.config;
|
|
144
|
+
const currentAge = revalidated ? 0 : age;
|
|
145
|
+
const varySegment = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.SEGMENT_HEADER);
|
|
146
|
+
const setKey = varySegment ? keyWithSegment : key;
|
|
147
|
+
const responseEncoding = configResponseEncoding || (responseType === 'arraybuffer' ? 'base64' : undefined);
|
|
148
|
+
const cacheableData = type === CacheType.Disk && responseType === 'arraybuffer'
|
|
149
|
+
? data.toString(responseEncoding)
|
|
150
|
+
: data;
|
|
151
|
+
const expiration = Date.now() + (maxAge - currentAge) * 1000;
|
|
152
|
+
await storage.set(setKey, {
|
|
153
|
+
etag,
|
|
154
|
+
expiration,
|
|
155
|
+
response: { data: cacheableData, headers, status },
|
|
156
|
+
responseEncoding,
|
|
157
|
+
responseType,
|
|
158
|
+
});
|
|
159
|
+
span.log({
|
|
160
|
+
event: "local-cache-saved" /* LOCAL_CACHE_SAVED */,
|
|
161
|
+
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
162
|
+
["key-set" /* KEY_SET */]: setKey,
|
|
163
|
+
["age" /* AGE */]: currentAge,
|
|
164
|
+
["etag" /* ETAG */]: etag,
|
|
165
|
+
["expiration-time" /* EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
|
|
166
|
+
["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
|
|
167
|
+
["response-type" /* RESPONSE_TYPE */]: responseType,
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
172
|
+
};
|
|
173
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const constants_1 = require("../../constants");
|
|
8
|
+
const production = process.env.VTEX_PRODUCTION === 'true';
|
|
9
|
+
const handleCancellation = (ctx, cancellation) => {
|
|
10
|
+
let cancellable = true;
|
|
11
|
+
return {
|
|
12
|
+
cancelToken: new axios_1.default.CancelToken((canceller) => {
|
|
13
|
+
cancellation.source.token.promise.then(cancel => {
|
|
14
|
+
if (cancellable) {
|
|
15
|
+
canceller(cancel.message);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}),
|
|
19
|
+
onRequestFinish: () => {
|
|
20
|
+
if (!ctx.config.cancelToken) {
|
|
21
|
+
// don't have cancelToken: not cancelable
|
|
22
|
+
cancellable = false;
|
|
23
|
+
}
|
|
24
|
+
else if (!ctx.response) {
|
|
25
|
+
// response is not ready: cancelable
|
|
26
|
+
cancellable = true;
|
|
27
|
+
}
|
|
28
|
+
else if (ctx.config.responseType !== 'stream') {
|
|
29
|
+
// response is ready and it is not a stream: not cancelable
|
|
30
|
+
cancellable = false;
|
|
31
|
+
}
|
|
32
|
+
else if (ctx.response.data.readableEnded) {
|
|
33
|
+
// response stream has ended: not cancelable
|
|
34
|
+
cancellable = false;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// when response stream ends: not cancelable
|
|
38
|
+
ctx.response.data.on('end', function streamEnded() {
|
|
39
|
+
cancellable = false;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.cancellationToken = (cancellation) => async (ctx, next) => {
|
|
46
|
+
const { config: { method } } = ctx;
|
|
47
|
+
if (!cancellation) {
|
|
48
|
+
return await next();
|
|
49
|
+
}
|
|
50
|
+
if (method && !constants_1.cancellableMethods.has(method.toUpperCase())) {
|
|
51
|
+
cancellation.cancelable = false;
|
|
52
|
+
}
|
|
53
|
+
if (!cancellation.cancelable || !cancellation.source) {
|
|
54
|
+
return await next();
|
|
55
|
+
}
|
|
56
|
+
if (!cancellation.source.token.throwIfRequested) {
|
|
57
|
+
if (!production) {
|
|
58
|
+
throw new Error('Missing cancellation function. Are you trying to use HttpClient via workers threads?');
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return await next();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const { onRequestFinish, cancelToken } = handleCancellation(ctx, cancellation);
|
|
65
|
+
ctx.config.cancelToken = cancelToken;
|
|
66
|
+
try {
|
|
67
|
+
await next();
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
onRequestFinish();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InflightKeyGenerator, MiddlewareContext } from '../typings';
|
|
2
|
+
export declare type Inflight = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
|
+
export declare const singleFlightMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
4
|
+
export declare const inflightURL: InflightKeyGenerator;
|
|
5
|
+
export declare const inflightUrlWithQuery: InflightKeyGenerator;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const qs_1 = require("qs");
|
|
4
|
+
const inflight = new Map();
|
|
5
|
+
let metricsAdded = false;
|
|
6
|
+
exports.singleFlightMiddleware = async (ctx, next) => {
|
|
7
|
+
const { inflightKey } = ctx.config;
|
|
8
|
+
if (!inflightKey) {
|
|
9
|
+
return await next();
|
|
10
|
+
}
|
|
11
|
+
// We cannot allow single flight requests to
|
|
12
|
+
// cancel any request
|
|
13
|
+
ctx.config.cancelToken = undefined;
|
|
14
|
+
if (!metricsAdded) {
|
|
15
|
+
metrics.addOnFlushMetric(() => ({
|
|
16
|
+
name: 'node-vtex-api-inflight-map-size',
|
|
17
|
+
size: inflight.entries.length,
|
|
18
|
+
}));
|
|
19
|
+
metricsAdded = true;
|
|
20
|
+
}
|
|
21
|
+
const key = inflightKey(ctx.config);
|
|
22
|
+
const isInflight = !!inflight.has(key);
|
|
23
|
+
if (isInflight) {
|
|
24
|
+
const memoized = await inflight.get(key);
|
|
25
|
+
ctx.inflightHit = isInflight;
|
|
26
|
+
ctx.response = memoized.response;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
31
|
+
try {
|
|
32
|
+
await next();
|
|
33
|
+
resolve({
|
|
34
|
+
cacheHit: ctx.cacheHit,
|
|
35
|
+
response: ctx.response,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
reject(err);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
inflight.delete(key);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
inflight.set(key, promise);
|
|
46
|
+
await promise;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.inflightURL = ({ baseURL, url }) => baseURL + url;
|
|
50
|
+
exports.inflightUrlWithQuery = ({ baseURL, url, params }) => baseURL + url + qs_1.stringify(params, { arrayFormat: 'repeat', addQueryPrefix: true });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MiddlewareContext } from '../typings';
|
|
2
|
+
export declare type Memoized = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
|
+
interface MemoizationOptions {
|
|
4
|
+
memoizedCache: Map<string, Promise<Memoized>>;
|
|
5
|
+
}
|
|
6
|
+
export declare const memoizationMiddleware: ({ memoizedCache }: MemoizationOptions) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const cache_1 = require("./cache");
|
|
4
|
+
exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
5
|
+
return async (ctx, next) => {
|
|
6
|
+
if (!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable) {
|
|
7
|
+
return next();
|
|
8
|
+
}
|
|
9
|
+
const span = ctx.tracing.rootSpan;
|
|
10
|
+
const key = cache_1.cacheKey(ctx.config);
|
|
11
|
+
const isMemoized = !!memoizedCache.has(key);
|
|
12
|
+
span.log({ event: "cache-key-created" /* CACHE_KEY_CREATE */, ["cache-type" /* CACHE_TYPE */]: 'memoization', ["key" /* KEY */]: key });
|
|
13
|
+
if (isMemoized) {
|
|
14
|
+
span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* HIT */);
|
|
15
|
+
const memoized = await memoizedCache.get(key);
|
|
16
|
+
ctx.memoizedHit = isMemoized;
|
|
17
|
+
ctx.response = memoized.response;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* MISS */);
|
|
22
|
+
const promise = new Promise(async (resolve, reject) => {
|
|
23
|
+
try {
|
|
24
|
+
await next();
|
|
25
|
+
resolve({
|
|
26
|
+
cacheHit: ctx.cacheHit,
|
|
27
|
+
response: ctx.response,
|
|
28
|
+
});
|
|
29
|
+
span.log({ event: "memoization-cache-saved" /* MEMOIZATION_CACHE_SAVED */, ["key-set" /* KEY_SET */]: key });
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
reject(err);
|
|
33
|
+
span.log({ event: "memoization-cache-saved-error" /* MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* KEY_SET */]: key });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
memoizedCache.set(key, promise);
|
|
37
|
+
await promise;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|