@vtex/api 6.48.1-beta → 6.48.1-beta.2
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/gen/manifest.schema +5 -3
- package/lib/HttpClient/GraphQLClient.d.ts +3 -2
- package/lib/HttpClient/GraphQLClient.js +5 -1
- package/lib/HttpClient/HttpClient.d.ts +9 -7
- package/lib/HttpClient/HttpClient.js +70 -27
- package/lib/HttpClient/agents.d.ts +6 -0
- package/lib/HttpClient/agents.js +43 -0
- package/lib/HttpClient/index.d.ts +1 -7
- package/lib/HttpClient/index.js +22 -16
- package/lib/HttpClient/middlewares/cache.d.ts +9 -3
- package/lib/HttpClient/middlewares/cache.js +130 -35
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +2 -2
- package/lib/HttpClient/middlewares/cancellationToken.js +5 -2
- package/lib/HttpClient/middlewares/inflight.d.ts +1 -1
- package/lib/HttpClient/middlewares/inflight.js +7 -3
- package/lib/HttpClient/middlewares/memoization.d.ts +1 -1
- package/lib/HttpClient/middlewares/memoization.js +13 -4
- package/lib/HttpClient/middlewares/metrics.js +25 -38
- package/lib/HttpClient/middlewares/notFound.d.ts +1 -1
- package/lib/HttpClient/middlewares/notFound.js +5 -2
- package/lib/HttpClient/middlewares/recorder.d.ts +1 -1
- package/lib/HttpClient/middlewares/recorder.js +21 -12
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +11 -0
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +31 -0
- package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
- package/lib/HttpClient/middlewares/request/index.js +88 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +22 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +55 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +56 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +32 -0
- package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
- package/lib/HttpClient/middlewares/tracing.js +62 -0
- package/lib/HttpClient/typings.d.ts +46 -12
- package/lib/HttpClient/typings.js +1 -0
- package/lib/caches/DiskCache.d.ts +1 -1
- package/lib/caches/DiskCache.js +3 -2
- package/lib/caches/LRUCache.d.ts +3 -3
- package/lib/caches/LRUCache.js +6 -1
- package/lib/caches/LRUDiskCache.d.ts +2 -2
- package/lib/caches/LRUDiskCache.js +8 -3
- package/lib/caches/MultilayeredCache.d.ts +2 -2
- package/lib/caches/MultilayeredCache.js +8 -7
- package/lib/caches/index.js +20 -7
- package/lib/caches/typings.d.ts +5 -5
- package/lib/clients/IOClient.d.ts +13 -0
- package/lib/clients/IOClient.js +20 -0
- package/lib/clients/IOClients.d.ts +29 -25
- package/lib/clients/IOClients.js +36 -28
- package/lib/{HttpClient → clients}/IOGraphQLClient.d.ts +4 -4
- package/lib/{HttpClient → clients}/IOGraphQLClient.js +3 -2
- package/lib/{HttpClient → clients/apps}/AppClient.d.ts +3 -3
- package/lib/{HttpClient → clients/apps}/AppClient.js +11 -5
- package/lib/{HttpClient → clients/apps}/AppGraphQLClient.d.ts +3 -3
- package/lib/{HttpClient → clients/apps}/AppGraphQLClient.js +11 -5
- package/lib/clients/apps/Billing.d.ts +12 -0
- package/lib/clients/{Billing.js → apps/Billing.js} +9 -3
- package/lib/clients/{Builder.d.ts → apps/Builder.d.ts} +12 -11
- package/lib/clients/{Builder.js → apps/Builder.js} +51 -23
- package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
- package/lib/clients/apps/MessagesGraphQL.js +122 -0
- package/lib/clients/{Settings.d.ts → apps/Settings.d.ts} +5 -4
- package/lib/clients/apps/Settings.js +39 -0
- package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
- package/lib/clients/apps/catalogGraphQL/brand.js +19 -0
- package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
- package/lib/clients/apps/catalogGraphQL/category.js +17 -0
- package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
- package/lib/clients/apps/catalogGraphQL/index.js +89 -0
- package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
- package/lib/clients/apps/catalogGraphQL/product.js +31 -0
- package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
- package/lib/clients/apps/catalogGraphQL/sku.js +31 -0
- package/lib/clients/apps/index.d.ts +7 -0
- package/lib/clients/apps/index.js +23 -0
- package/lib/{HttpClient → clients/external}/ExternalClient.d.ts +3 -3
- package/lib/{HttpClient → clients/external}/ExternalClient.js +10 -2
- package/lib/clients/external/ID.d.ts +23 -0
- package/lib/clients/external/ID.js +61 -0
- package/lib/clients/external/Masterdata.d.ts +94 -0
- package/lib/clients/external/Masterdata.js +225 -0
- package/lib/clients/external/PaymentProvider.d.ts +31 -0
- package/lib/clients/external/PaymentProvider.js +43 -0
- package/lib/clients/external/index.d.ts +4 -0
- package/lib/clients/external/index.js +20 -0
- package/lib/clients/index.d.ts +9 -21
- package/lib/clients/index.js +27 -24
- package/lib/clients/infra/Apps.d.ts +93 -0
- package/lib/clients/infra/Apps.js +511 -0
- package/lib/clients/infra/Assets.d.ts +35 -0
- package/lib/clients/infra/Assets.js +166 -0
- package/lib/clients/infra/BillingMetrics.d.ts +13 -0
- package/lib/clients/infra/BillingMetrics.js +16 -0
- package/lib/clients/infra/Events.d.ts +12 -0
- package/lib/clients/infra/Events.js +34 -0
- package/lib/clients/infra/Housekeeper.d.ts +10 -0
- package/lib/clients/infra/Housekeeper.js +31 -0
- package/lib/{HttpClient → clients/infra}/InfraClient.d.ts +3 -3
- package/lib/{HttpClient → clients/infra}/InfraClient.js +10 -4
- package/lib/clients/infra/Registry.d.ts +65 -0
- package/lib/clients/infra/Registry.js +209 -0
- package/lib/clients/infra/Router.d.ts +34 -0
- package/lib/clients/infra/Router.js +82 -0
- package/lib/clients/infra/Sphinx.d.ts +13 -0
- package/lib/clients/infra/Sphinx.js +30 -0
- package/lib/clients/infra/VBase.d.ts +61 -0
- package/lib/clients/infra/VBase.js +197 -0
- package/lib/clients/infra/Workspaces.d.ts +18 -0
- package/lib/clients/infra/Workspaces.js +66 -0
- package/lib/clients/infra/index.d.ts +11 -0
- package/lib/clients/infra/index.js +27 -0
- package/lib/{HttpClient → clients/janus}/JanusClient.d.ts +4 -4
- package/lib/{HttpClient → clients/janus}/JanusClient.js +8 -3
- package/lib/clients/janus/LicenseManager.d.ts +7 -0
- package/lib/clients/janus/LicenseManager.js +59 -0
- package/lib/clients/{Segment.d.ts → janus/Segment.d.ts} +7 -11
- package/lib/clients/janus/Segment.js +89 -0
- package/lib/clients/{Session.d.ts → janus/Session.d.ts} +4 -4
- package/lib/clients/{Session.js → janus/Session.js} +25 -13
- package/lib/clients/{Tenant.d.ts → janus/Tenant.d.ts} +7 -8
- package/lib/clients/janus/Tenant.js +29 -0
- package/lib/clients/janus/index.d.ts +5 -0
- package/lib/clients/janus/index.js +21 -0
- package/lib/constants.d.ts +50 -2
- package/lib/constants.js +55 -1
- package/lib/errors/AuthenticationError.js +1 -0
- package/lib/errors/ForbiddenError.js +1 -0
- package/lib/errors/NotFoundError.js +1 -0
- package/lib/errors/RequestCancelledError.js +1 -0
- package/lib/errors/ResolverError.d.ts +1 -1
- package/lib/errors/ResolverError.js +4 -3
- package/lib/errors/ResolverWarning.d.ts +1 -1
- package/lib/errors/ResolverWarning.js +3 -2
- package/lib/errors/TooManyRequestsError.js +1 -0
- package/lib/errors/UserInputError.js +1 -0
- package/lib/errors/index.js +22 -11
- package/lib/index.d.ts +9 -7
- package/lib/index.js +31 -16
- package/lib/metrics/MetricsAccumulator.d.ts +3 -20
- package/lib/metrics/MetricsAccumulator.js +44 -27
- package/lib/responses.d.ts +5 -46
- package/lib/service/index.d.ts +2 -0
- package/lib/service/index.js +35 -0
- package/lib/service/loaders.d.ts +8 -0
- package/lib/service/loaders.js +57 -0
- package/lib/service/logger/console.d.ts +10 -0
- package/lib/service/logger/console.js +40 -0
- package/lib/service/logger/index.d.ts +2 -28
- package/lib/service/logger/index.js +16 -68
- package/lib/service/logger/logger.d.ts +29 -0
- package/lib/service/logger/logger.js +62 -0
- package/lib/service/logger/metricsLogger.d.ts +40 -0
- package/lib/service/logger/metricsLogger.js +150 -0
- package/lib/service/master.d.ts +2 -0
- package/lib/service/master.js +89 -0
- package/lib/service/metrics/requestMetricsMiddleware.d.ts +2 -0
- package/lib/service/metrics/requestMetricsMiddleware.js +46 -0
- package/lib/service/tracing/TracerSingleton.d.ts +7 -0
- package/lib/service/tracing/TracerSingleton.js +49 -0
- package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
- package/lib/service/tracing/metrics/MetricNames.js +45 -0
- package/lib/service/tracing/metrics/instruments.d.ts +9 -0
- package/lib/service/tracing/metrics/instruments.js +19 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +26 -0
- package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
- package/lib/service/tracing/tracingMiddlewares.js +117 -0
- package/lib/service/worker/index.d.ts +11 -0
- package/lib/service/worker/index.js +197 -0
- package/lib/service/worker/listeners.d.ts +3 -0
- package/lib/{utils/unhandled.js → service/worker/listeners.js} +12 -16
- package/lib/service/{Service.d.ts → worker/runtime/Service.d.ts} +5 -5
- package/lib/service/{Service.js → worker/runtime/Service.js} +3 -1
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/handlers.js +34 -0
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
- package/lib/service/worker/runtime/builtIn/middlewares.js +43 -0
- package/lib/service/worker/runtime/events/index.d.ts +4 -0
- package/lib/service/worker/runtime/events/index.js +48 -0
- package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/body.js +26 -0
- package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
- package/lib/service/worker/runtime/events/middlewares/context.js +23 -0
- package/lib/service/worker/runtime/events/router.d.ts +2 -0
- package/lib/service/worker/runtime/events/router.js +29 -0
- package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/index.js +29 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/context.js +17 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.js +97 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +3 -0
- package/lib/service/worker/runtime/graphql/middlewares/query.js +54 -0
- package/lib/service/worker/runtime/graphql/middlewares/response.js +39 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/middlewares/run.js +21 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +5 -0
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +30 -0
- package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
- package/lib/service/{graphql → worker/runtime/graphql}/middlewares/upload.js +2 -1
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/index.js +33 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +81 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Auth.d.ts +1 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Auth.js +17 -10
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +38 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +62 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +41 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Sanitize.d.ts +1 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Sanitize.js +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +35 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/SmartCacheDirective.d.ts +1 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/SmartCacheDirective.js +9 -3
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +40 -0
- package/lib/service/{graphql/schema/schemaDirectives/Translatable.d.ts → worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts} +2 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +34 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +37 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +8 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +14 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/ioUpload.js +1 -0
- package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/sanitizedString.js +8 -3
- package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +34 -0
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +2 -0
- package/lib/service/worker/runtime/graphql/utils/error.js +78 -0
- package/lib/service/worker/runtime/graphql/utils/pathname.js +9 -0
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
- package/lib/service/worker/runtime/graphql/utils/translations.js +42 -0
- package/lib/service/worker/runtime/http/index.d.ts +5 -0
- package/lib/service/worker/runtime/http/index.js +61 -0
- package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/authTokens.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/cancellationToken.js +3 -1
- package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/clients.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
- package/lib/service/worker/runtime/http/middlewares/context.js +39 -0
- package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/error.js +29 -16
- package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +43 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/requestStats.d.ts +3 -3
- package/lib/service/{http → worker/runtime/http}/middlewares/requestStats.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/setCookie.js +6 -5
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
- package/lib/service/worker/runtime/http/middlewares/settings.js +49 -0
- package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/timings.js +25 -11
- package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
- package/lib/service/{http → worker/runtime/http}/middlewares/vary.js +4 -3
- package/lib/service/worker/runtime/http/router.d.ts +2 -0
- package/lib/service/worker/runtime/http/router.js +25 -0
- package/lib/service/worker/runtime/http/routes.d.ts +19 -0
- package/lib/service/worker/runtime/http/routes.js +16 -0
- package/lib/service/worker/runtime/method.d.ts +9 -0
- package/lib/service/{method.js → worker/runtime/method.js} +2 -1
- package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
- package/lib/service/worker/runtime/statusTrack.js +43 -0
- package/lib/service/worker/runtime/typings.d.ts +173 -0
- package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
- package/lib/service/worker/runtime/utils/compose.js +14 -0
- package/lib/service/worker/runtime/utils/context.d.ts +5 -0
- package/lib/service/worker/runtime/utils/context.js +42 -0
- package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
- package/lib/service/worker/runtime/utils/diff.js +22 -0
- package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
- package/lib/service/worker/runtime/utils/recorder.js +38 -0
- package/lib/service/worker/runtime/utils/toArray.js +5 -0
- package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
- package/lib/service/worker/runtime/utils/tokenBucket.js +17 -0
- package/lib/tracing/LogEvents.d.ts +31 -0
- package/lib/{service/graphql/utils/array.js → tracing/LogEvents.js} +1 -1
- package/lib/tracing/LogFields.d.ts +66 -0
- package/lib/tracing/LogFields.js +3 -0
- package/lib/tracing/Tags.d.ts +81 -0
- package/lib/tracing/Tags.js +8 -0
- package/lib/tracing/UserLandTracer.d.ts +27 -0
- package/lib/tracing/UserLandTracer.js +58 -0
- package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
- package/lib/tracing/errorReporting/ErrorReport.js +71 -0
- package/lib/tracing/index.d.ts +9 -0
- package/lib/tracing/index.js +20 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
- package/lib/tracing/spanReference/SpanReferenceTypes.js +8 -0
- package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
- package/lib/tracing/spanReference/createSpanReference.js +9 -0
- package/lib/tracing/utils.d.ts +13 -0
- package/lib/tracing/utils.js +42 -0
- package/lib/utils/MineWinsConflictsResolver.d.ts +7 -5
- package/lib/utils/MineWinsConflictsResolver.js +40 -22
- package/lib/utils/app.d.ts +3 -1
- package/lib/utils/app.js +40 -21
- package/lib/utils/appsStaleIfError.d.ts +2 -1
- package/lib/utils/appsStaleIfError.js +33 -12
- package/lib/utils/billingOptions.d.ts +36 -3
- package/lib/utils/billingOptions.js +9 -3
- package/lib/utils/binding.d.ts +3 -3
- package/lib/utils/binding.js +5 -2
- package/lib/utils/cancel.d.ts +2 -2
- package/lib/utils/cancel.js +3 -1
- package/lib/utils/conflicts.mock.d.ts +17 -0
- package/lib/utils/conflicts.mock.js +28 -0
- package/lib/utils/domain.js +2 -1
- package/lib/utils/error.js +6 -4
- package/lib/utils/index.js +23 -12
- package/lib/utils/json.js +1 -0
- package/lib/utils/log.d.ts +1 -3
- package/lib/utils/log.js +6 -4
- package/lib/utils/message.js +11 -4
- package/lib/utils/renameBy.js +3 -1
- package/lib/utils/retry.js +10 -7
- package/lib/utils/status.js +3 -1
- package/lib/utils/tenant.d.ts +3 -3
- package/lib/utils/tenant.js +5 -2
- package/lib/utils/throwOnGraphQLErrors.js +1 -0
- package/lib/utils/time.d.ts +7 -7
- package/lib/utils/time.js +29 -12
- package/package.json +3 -3
- package/lib/HttpClient/IOClient.d.ts +0 -13
- package/lib/HttpClient/IOClient.js +0 -14
- package/lib/HttpClient/factories/index.d.ts +0 -8
- package/lib/HttpClient/factories/index.js +0 -31
- package/lib/HttpClient/middlewares/request.d.ts +0 -10
- package/lib/HttpClient/middlewares/request.js +0 -87
- package/lib/IODataSource.d.ts +0 -27
- package/lib/IODataSource.js +0 -46
- package/lib/clients/Apps.d.ts +0 -84
- package/lib/clients/Apps.js +0 -326
- package/lib/clients/Assets.d.ts +0 -21
- package/lib/clients/Assets.js +0 -110
- package/lib/clients/Billing.d.ts +0 -11
- package/lib/clients/BillingMetrics.d.ts +0 -12
- package/lib/clients/BillingMetrics.js +0 -10
- package/lib/clients/Events.d.ts +0 -6
- package/lib/clients/Events.js +0 -19
- package/lib/clients/Housekeeper.d.ts +0 -11
- package/lib/clients/Housekeeper.js +0 -24
- package/lib/clients/ID.d.ts +0 -22
- package/lib/clients/ID.js +0 -48
- package/lib/clients/LicenseManager.d.ts +0 -6
- package/lib/clients/LicenseManager.js +0 -43
- package/lib/clients/Logger.d.ts +0 -27
- package/lib/clients/Logger.js +0 -32
- package/lib/clients/Messages.d.ts +0 -18
- package/lib/clients/Messages.js +0 -20
- package/lib/clients/MessagesGraphQL.d.ts +0 -63
- package/lib/clients/MessagesGraphQL.js +0 -50
- package/lib/clients/Metadata.d.ts +0 -25
- package/lib/clients/Metadata.js +0 -53
- package/lib/clients/Registry.d.ts +0 -61
- package/lib/clients/Registry.js +0 -147
- package/lib/clients/Router.d.ts +0 -33
- package/lib/clients/Router.js +0 -50
- package/lib/clients/Segment.js +0 -69
- package/lib/clients/Settings.js +0 -44
- package/lib/clients/Sphinx.d.ts +0 -12
- package/lib/clients/Sphinx.js +0 -19
- package/lib/clients/Tenant.js +0 -13
- package/lib/clients/VBase.d.ts +0 -57
- package/lib/clients/VBase.js +0 -116
- package/lib/clients/Workspaces.d.ts +0 -17
- package/lib/clients/Workspaces.js +0 -38
- package/lib/service/Runtime.d.ts +0 -18
- package/lib/service/Runtime.js +0 -57
- package/lib/service/events/index.d.ts +0 -3
- package/lib/service/events/index.js +0 -21
- package/lib/service/graphql/index.d.ts +0 -7
- package/lib/service/graphql/index.js +0 -33
- package/lib/service/graphql/middlewares/error.js +0 -107
- package/lib/service/graphql/middlewares/formatters.d.ts +0 -2
- package/lib/service/graphql/middlewares/formatters.js +0 -64
- package/lib/service/graphql/middlewares/query.d.ts +0 -2
- package/lib/service/graphql/middlewares/query.js +0 -32
- package/lib/service/graphql/middlewares/response.js +0 -36
- package/lib/service/graphql/middlewares/run.d.ts +0 -4
- package/lib/service/graphql/middlewares/run.js +0 -55
- package/lib/service/graphql/middlewares/schema.d.ts +0 -2
- package/lib/service/graphql/middlewares/schema.js +0 -8
- package/lib/service/graphql/middlewares/timings.d.ts +0 -2
- package/lib/service/graphql/middlewares/timings.js +0 -10
- package/lib/service/graphql/middlewares/upload.d.ts +0 -7
- package/lib/service/graphql/schema/index.d.ts +0 -3
- package/lib/service/graphql/schema/index.js +0 -66
- package/lib/service/graphql/schema/messagesLoader.d.ts +0 -4
- package/lib/service/graphql/schema/messagesLoader.js +0 -41
- package/lib/service/graphql/schema/messagesLoaderV2.d.ts +0 -5
- package/lib/service/graphql/schema/messagesLoaderV2.js +0 -44
- package/lib/service/graphql/schema/schemaDirectives/Translatable.js +0 -54
- package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.d.ts +0 -13
- package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.js +0 -67
- package/lib/service/graphql/schema/schemaDirectives/index.d.ts +0 -13
- package/lib/service/graphql/schema/schemaDirectives/index.js +0 -17
- package/lib/service/graphql/schema/typeDefs/index.d.ts +0 -16
- package/lib/service/graphql/schema/typeDefs/index.js +0 -21
- package/lib/service/graphql/schema/typeDefs/ioMessage.d.ts +0 -8
- package/lib/service/graphql/schema/typeDefs/ioMessage.js +0 -33
- package/lib/service/graphql/typings.d.ts +0 -21
- package/lib/service/graphql/utils/cacheControl.d.ts +0 -6
- package/lib/service/graphql/utils/cacheControl.js +0 -38
- package/lib/service/graphql/utils/maxAgeEnum.d.ts +0 -6
- package/lib/service/graphql/utils/maxAgeEnum.js +0 -17
- package/lib/service/graphql/utils/pathname.js +0 -7
- package/lib/service/http/index.d.ts +0 -3
- package/lib/service/http/index.js +0 -18
- package/lib/service/http/middlewares/authTokens.d.ts +0 -3
- package/lib/service/http/middlewares/cancellationToken.d.ts +0 -3
- package/lib/service/http/middlewares/clients.d.ts +0 -4
- package/lib/service/http/middlewares/error.d.ts +0 -3
- package/lib/service/http/middlewares/setCookie.d.ts +0 -3
- package/lib/service/http/middlewares/timings.d.ts +0 -3
- package/lib/service/http/middlewares/vary.d.ts +0 -3
- package/lib/service/method.d.ts +0 -9
- package/lib/service/typings.d.ts +0 -139
- package/lib/service/utils/compose.d.ts +0 -4
- package/lib/service/utils/compose.js +0 -11
- package/lib/utils/MineWinsConflictsResolver.test.d.ts +0 -1
- package/lib/utils/MineWinsConflictsResolver.test.js +0 -134
- package/lib/utils/unhandled.d.ts +0 -1
- /package/lib/service/{graphql → worker/runtime/graphql}/middlewares/error.d.ts +0 -0
- /package/lib/service/{graphql → worker/runtime/graphql}/middlewares/response.d.ts +0 -0
- /package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/ioUpload.d.ts +0 -0
- /package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/sanitizedString.d.ts +0 -0
- /package/lib/service/{graphql → worker/runtime/graphql}/typings.js +0 -0
- /package/lib/service/{graphql → worker/runtime/graphql}/utils/pathname.d.ts +0 -0
- /package/lib/service/{typings.js → worker/runtime/typings.js} +0 -0
- /package/lib/service/{graphql/utils/array.d.ts → worker/runtime/utils/toArray.d.ts} +0 -0
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.cacheMiddleware = exports.CacheType = exports.isLocallyCacheable = exports.cacheKey = void 0;
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
|
-
const
|
|
5
|
+
const tracing_1 = require("../../tracing");
|
|
6
6
|
const RANGE_HEADER_QS_KEY = '__range_header';
|
|
7
7
|
const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501]; // https://tools.ietf.org/html/rfc7231#section-6.1
|
|
8
|
-
|
|
8
|
+
const cacheKey = (config) => {
|
|
9
9
|
const { baseURL = '', url = '', params, headers } = config;
|
|
10
|
-
const locale = headers[
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
urlObject.searchParams.append(RANGE_HEADER_QS_KEY, headers.range);
|
|
15
|
-
}
|
|
10
|
+
const locale = headers === null || headers === void 0 ? void 0 : headers[constants_1.LOCALE_HEADER];
|
|
11
|
+
const encodedBaseURL = baseURL.replace(/\//g, '\\');
|
|
12
|
+
const encodedURL = url.replace(/\//g, '\\');
|
|
13
|
+
let key = `${locale}--${encodedBaseURL}--${encodedURL}?`;
|
|
16
14
|
if (params) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
Object.keys(params).sort().forEach(p => key = key.concat(`--${p}=${params[p]}`));
|
|
16
|
+
}
|
|
17
|
+
if (headers === null || headers === void 0 ? void 0 : headers.range) {
|
|
18
|
+
key = key.concat(`--${RANGE_HEADER_QS_KEY}=${headers.range}`);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
const encodedPath = `${locale}/${urlObject.pathname}${urlObject.search}`.replace(/\//g, '\\\\');
|
|
23
|
-
// Add hostname as top level directory on disk cache
|
|
24
|
-
return `${urlObject.hostname}/${encodedPath}`;
|
|
20
|
+
return key;
|
|
25
21
|
};
|
|
22
|
+
exports.cacheKey = cacheKey;
|
|
26
23
|
const parseCacheHeaders = (headers) => {
|
|
27
24
|
const { 'cache-control': cacheControl = '', etag, age: ageStr } = headers;
|
|
28
25
|
const cacheDirectives = cacheControl.split(',').map(d => d.trim());
|
|
@@ -51,36 +48,80 @@ var CacheType;
|
|
|
51
48
|
CacheType[CacheType["Disk"] = 2] = "Disk";
|
|
52
49
|
CacheType[CacheType["Any"] = 3] = "Any";
|
|
53
50
|
})(CacheType = exports.CacheType || (exports.CacheType = {}));
|
|
54
|
-
|
|
51
|
+
const CacheTypeNames = {
|
|
52
|
+
[CacheType.None]: 'none',
|
|
53
|
+
[CacheType.Memory]: 'memory',
|
|
54
|
+
[CacheType.Disk]: 'disk',
|
|
55
|
+
[CacheType.Any]: 'any',
|
|
56
|
+
};
|
|
57
|
+
const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
58
|
+
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* CustomHttpTags.HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* CustomHttpTags.HTTP_MEMORY_CACHE_RESULT */;
|
|
59
|
+
const cacheType = CacheTypeNames[type];
|
|
55
60
|
return async (ctx, next) => {
|
|
61
|
+
var _a, _b;
|
|
56
62
|
if (!isLocallyCacheable(ctx.config, type)) {
|
|
57
63
|
return await next();
|
|
58
64
|
}
|
|
59
|
-
const
|
|
60
|
-
const
|
|
65
|
+
const { rootSpan: span, tracer, logger } = (_a = ctx.tracing) !== null && _a !== void 0 ? _a : {};
|
|
66
|
+
const key = (0, exports.cacheKey)(ctx.config);
|
|
67
|
+
const segmentToken = (_b = ctx.config.headers) === null || _b === void 0 ? void 0 : _b[constants_1.SEGMENT_HEADER];
|
|
61
68
|
const keyWithSegment = key + segmentToken;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
70
|
+
event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */,
|
|
71
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
72
|
+
["key" /* HttpCacheLogFields.KEY */]: key,
|
|
73
|
+
["key-with-segment" /* HttpCacheLogFields.KEY_WITH_SEGMENT */]: keyWithSegment,
|
|
74
|
+
});
|
|
75
|
+
const cacheReadSpan = createCacheSpan(cacheType, 'read', tracer, span);
|
|
76
|
+
let cached = undefined;
|
|
77
|
+
try {
|
|
78
|
+
const cacheHasWithSegment = await storage.has(keyWithSegment);
|
|
79
|
+
cached = cacheHasWithSegment ? await storage.get(keyWithSegment) : await storage.get(key);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
tracing_1.ErrorReport.create({ originalError: error }).injectOnSpan(cacheReadSpan);
|
|
83
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ message: 'Error reading from the HttpClient cache', error });
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
cacheReadSpan === null || cacheReadSpan === void 0 ? void 0 : cacheReadSpan.finish();
|
|
87
|
+
}
|
|
88
|
+
if (cached && cached.response) {
|
|
65
89
|
const { etag: cachedEtag, response, expiration, responseType, responseEncoding } = cached;
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
90
|
+
if (type === CacheType.Disk && responseType === 'arraybuffer') {
|
|
91
|
+
response.data = Buffer.from(response.data, responseEncoding);
|
|
92
|
+
}
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
95
|
+
event: "local-cache-hit-info" /* HttpLogEvents.LOCAL_CACHE_HIT_INFO */,
|
|
96
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
97
|
+
["etag" /* HttpCacheLogFields.ETAG */]: cachedEtag,
|
|
98
|
+
["expiration-time" /* HttpCacheLogFields.EXPIRATION_TIME */]: (expiration - now) / 1000,
|
|
99
|
+
["response-type" /* HttpCacheLogFields.RESPONSE_TYPE */]: responseType,
|
|
100
|
+
["response-encoding" /* HttpCacheLogFields.RESPONSE_ENCONDING */]: responseEncoding,
|
|
101
|
+
});
|
|
102
|
+
if (expiration > now) {
|
|
70
103
|
ctx.response = response;
|
|
71
104
|
ctx.cacheHit = {
|
|
72
105
|
memory: 1,
|
|
73
106
|
revalidated: 0,
|
|
74
107
|
router: 0,
|
|
75
108
|
};
|
|
109
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "HIT" /* CacheResult.HIT */);
|
|
76
110
|
return;
|
|
77
111
|
}
|
|
112
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "STALE" /* CacheResult.STALE */);
|
|
78
113
|
const validateStatus = addNotModified(ctx.config.validateStatus);
|
|
79
114
|
if (cachedEtag && validateStatus(response.status)) {
|
|
80
|
-
ctx.config.headers
|
|
115
|
+
ctx.config.headers = {
|
|
116
|
+
...ctx.config.headers,
|
|
117
|
+
'if-none-match': cachedEtag
|
|
118
|
+
};
|
|
81
119
|
ctx.config.validateStatus = validateStatus;
|
|
82
120
|
}
|
|
83
121
|
}
|
|
122
|
+
else {
|
|
123
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "MISS" /* CacheResult.MISS */);
|
|
124
|
+
}
|
|
84
125
|
await next();
|
|
85
126
|
if (!ctx.response) {
|
|
86
127
|
return;
|
|
@@ -98,28 +139,82 @@ exports.cacheMiddleware = ({ type, storage }) => {
|
|
|
98
139
|
const { age, etag, maxAge: headerMaxAge, noStore, noCache } = parseCacheHeaders(headers);
|
|
99
140
|
const { forceMaxAge } = ctx.config;
|
|
100
141
|
const maxAge = forceMaxAge && cacheableStatusCodes.includes(status) ? Math.max(forceMaxAge, headerMaxAge) : headerMaxAge;
|
|
142
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
143
|
+
event: "cache-config" /* HttpLogEvents.CACHE_CONFIG */,
|
|
144
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
145
|
+
["age" /* HttpCacheLogFields.AGE */]: age,
|
|
146
|
+
["calculated-max-age" /* HttpCacheLogFields.CALCULATED_MAX_AGE */]: maxAge,
|
|
147
|
+
["max-age" /* HttpCacheLogFields.MAX_AGE */]: headerMaxAge,
|
|
148
|
+
["force-max-age" /* HttpCacheLogFields.FORCE_MAX_AGE */]: forceMaxAge,
|
|
149
|
+
["etag" /* HttpCacheLogFields.ETAG */]: etag,
|
|
150
|
+
["no-cache" /* HttpCacheLogFields.NO_CACHE */]: noCache,
|
|
151
|
+
["no-store" /* HttpCacheLogFields.NO_STORE */]: noStore,
|
|
152
|
+
});
|
|
101
153
|
// Indicates this should NOT be cached and this request will not be considered a miss.
|
|
102
154
|
if (!forceMaxAge && (noStore || (noCache && !etag))) {
|
|
155
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* HttpLogEvents.NO_LOCAL_CACHE_SAVE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType });
|
|
103
156
|
return;
|
|
104
157
|
}
|
|
105
158
|
const shouldCache = maxAge || etag;
|
|
106
159
|
const varySession = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.SESSION_HEADER);
|
|
107
160
|
if (shouldCache && !varySession) {
|
|
108
|
-
const { responseType, responseEncoding } = ctx.config;
|
|
161
|
+
const { responseType, responseEncoding: configResponseEncoding } = ctx.config;
|
|
109
162
|
const currentAge = revalidated ? 0 : age;
|
|
110
163
|
const varySegment = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.SEGMENT_HEADER);
|
|
111
164
|
const setKey = varySegment ? keyWithSegment : key;
|
|
165
|
+
const responseEncoding = configResponseEncoding || (responseType === 'arraybuffer' ? 'base64' : undefined);
|
|
112
166
|
const cacheableData = type === CacheType.Disk && responseType === 'arraybuffer'
|
|
113
167
|
? data.toString(responseEncoding)
|
|
114
168
|
: data;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
169
|
+
const now = Date.now();
|
|
170
|
+
const expiration = now + (maxAge - currentAge) * 1000;
|
|
171
|
+
const alreadyExpired = expiration <= now;
|
|
172
|
+
const reusingRevalidatedCache = cached && (ctx.response === cached.response);
|
|
173
|
+
const shouldSkipCacheUpdate = alreadyExpired && reusingRevalidatedCache;
|
|
174
|
+
if (shouldSkipCacheUpdate) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const cacheWriteSpan = createCacheSpan(cacheType, 'write', tracer, span);
|
|
178
|
+
try {
|
|
179
|
+
const storageSet = () => storage.set(setKey, {
|
|
180
|
+
etag,
|
|
181
|
+
expiration,
|
|
182
|
+
response: { data: cacheableData, headers, status },
|
|
183
|
+
responseEncoding: responseEncoding,
|
|
184
|
+
responseType,
|
|
185
|
+
});
|
|
186
|
+
if (asyncSet) {
|
|
187
|
+
storageSet();
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
await storageSet();
|
|
191
|
+
span === null || span === void 0 ? void 0 : span.log({
|
|
192
|
+
event: "local-cache-saved" /* HttpLogEvents.LOCAL_CACHE_SAVED */,
|
|
193
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
194
|
+
["key-set" /* HttpCacheLogFields.KEY_SET */]: setKey,
|
|
195
|
+
["age" /* HttpCacheLogFields.AGE */]: currentAge,
|
|
196
|
+
["etag" /* HttpCacheLogFields.ETAG */]: etag,
|
|
197
|
+
["expiration-time" /* HttpCacheLogFields.EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
|
|
198
|
+
["response-encoding" /* HttpCacheLogFields.RESPONSE_ENCONDING */]: responseEncoding,
|
|
199
|
+
["response-type" /* HttpCacheLogFields.RESPONSE_TYPE */]: responseType,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
tracing_1.ErrorReport.create({ originalError: error }).injectOnSpan(cacheWriteSpan);
|
|
205
|
+
logger === null || logger === void 0 ? void 0 : logger.warn({ message: 'Error writing to the HttpClient cache', error });
|
|
206
|
+
}
|
|
207
|
+
finally {
|
|
208
|
+
cacheWriteSpan === null || cacheWriteSpan === void 0 ? void 0 : cacheWriteSpan.finish();
|
|
209
|
+
}
|
|
122
210
|
return;
|
|
123
211
|
}
|
|
212
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* HttpLogEvents.NO_LOCAL_CACHE_SAVE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType });
|
|
124
213
|
};
|
|
125
214
|
};
|
|
215
|
+
exports.cacheMiddleware = cacheMiddleware;
|
|
216
|
+
const createCacheSpan = (cacheType, operation, tracer, parentSpan) => {
|
|
217
|
+
if (tracer && tracer.isTraceSampled && cacheType === 'disk') {
|
|
218
|
+
return tracer.startSpan(`${operation}-disk-cache`, { childOf: parentSpan });
|
|
219
|
+
}
|
|
220
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Cancellation } from '../../service/typings';
|
|
1
|
+
import { Cancellation } from '../../service/worker/runtime/typings';
|
|
2
2
|
import { MiddlewareContext } from '../typings';
|
|
3
|
-
export declare const cancellationToken: (cancellation?: Cancellation
|
|
3
|
+
export declare const cancellationToken: (cancellation?: Cancellation) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
@@ -3,7 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cancellationToken = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const constants_1 = require("../../constants");
|
|
7
9
|
const production = process.env.VTEX_PRODUCTION === 'true';
|
|
8
10
|
const handleCancellation = (ctx, cancellation) => {
|
|
9
11
|
let cancellable = true;
|
|
@@ -41,12 +43,12 @@ const handleCancellation = (ctx, cancellation) => {
|
|
|
41
43
|
},
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
|
-
|
|
46
|
+
const cancellationToken = (cancellation) => async (ctx, next) => {
|
|
45
47
|
const { config: { method } } = ctx;
|
|
46
48
|
if (!cancellation) {
|
|
47
49
|
return await next();
|
|
48
50
|
}
|
|
49
|
-
if (method && method.toUpperCase()
|
|
51
|
+
if (method && !constants_1.cancellableMethods.has(method.toUpperCase())) {
|
|
50
52
|
cancellation.cancelable = false;
|
|
51
53
|
}
|
|
52
54
|
if (!cancellation.cancelable || !cancellation.source) {
|
|
@@ -69,3 +71,4 @@ exports.cancellationToken = (cancellation) => async (ctx, next) => {
|
|
|
69
71
|
onRequestFinish();
|
|
70
72
|
}
|
|
71
73
|
};
|
|
74
|
+
exports.cancellationToken = cancellationToken;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InflightKeyGenerator, MiddlewareContext } from '../typings';
|
|
2
|
-
export
|
|
2
|
+
export type Inflight = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
3
|
export declare const singleFlightMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
4
4
|
export declare const inflightURL: InflightKeyGenerator;
|
|
5
5
|
export declare const inflightUrlWithQuery: InflightKeyGenerator;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inflightUrlWithQuery = exports.inflightURL = exports.singleFlightMiddleware = void 0;
|
|
3
4
|
const qs_1 = require("qs");
|
|
4
5
|
const inflight = new Map();
|
|
5
6
|
let metricsAdded = false;
|
|
6
|
-
|
|
7
|
+
const singleFlightMiddleware = async (ctx, next) => {
|
|
7
8
|
const { inflightKey } = ctx.config;
|
|
8
9
|
if (!inflightKey) {
|
|
9
10
|
return await next();
|
|
@@ -46,5 +47,8 @@ exports.singleFlightMiddleware = async (ctx, next) => {
|
|
|
46
47
|
await promise;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
exports.
|
|
50
|
-
|
|
50
|
+
exports.singleFlightMiddleware = singleFlightMiddleware;
|
|
51
|
+
const inflightURL = ({ baseURL, url }) => baseURL + url;
|
|
52
|
+
exports.inflightURL = inflightURL;
|
|
53
|
+
const inflightUrlWithQuery = ({ baseURL, url, params }) => baseURL + url + (0, qs_1.stringify)(params, { arrayFormat: 'repeat', addQueryPrefix: true });
|
|
54
|
+
exports.inflightUrlWithQuery = inflightUrlWithQuery;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MiddlewareContext } from '../typings';
|
|
2
|
-
export
|
|
2
|
+
export type Memoized = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
3
|
interface MemoizationOptions {
|
|
4
4
|
memoizedCache: Map<string, Promise<Memoized>>;
|
|
5
5
|
}
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memoizationMiddleware = void 0;
|
|
3
4
|
const cache_1 = require("./cache");
|
|
4
|
-
|
|
5
|
+
const memoizationMiddleware = ({ memoizedCache }) => {
|
|
5
6
|
return async (ctx, next) => {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
if (!(0, cache_1.isLocallyCacheable)(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable) {
|
|
9
|
+
return next();
|
|
8
10
|
}
|
|
9
|
-
const
|
|
11
|
+
const span = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.rootSpan;
|
|
12
|
+
const key = (0, cache_1.cacheKey)(ctx.config);
|
|
10
13
|
const isMemoized = !!memoizedCache.has(key);
|
|
14
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: 'memoization', ["key" /* HttpCacheLogFields.KEY */]: key });
|
|
11
15
|
if (isMemoized) {
|
|
16
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* CustomHttpTags.HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* CacheResult.HIT */);
|
|
12
17
|
const memoized = await memoizedCache.get(key);
|
|
13
18
|
ctx.memoizedHit = isMemoized;
|
|
14
19
|
ctx.response = memoized.response;
|
|
15
20
|
return;
|
|
16
21
|
}
|
|
17
22
|
else {
|
|
23
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* CustomHttpTags.HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* CacheResult.MISS */);
|
|
18
24
|
const promise = new Promise(async (resolve, reject) => {
|
|
19
25
|
try {
|
|
20
26
|
await next();
|
|
@@ -22,9 +28,11 @@ exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
|
22
28
|
cacheHit: ctx.cacheHit,
|
|
23
29
|
response: ctx.response,
|
|
24
30
|
});
|
|
31
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved" /* HttpLogEvents.MEMOIZATION_CACHE_SAVED */, ["key-set" /* HttpCacheLogFields.KEY_SET */]: key });
|
|
25
32
|
}
|
|
26
33
|
catch (err) {
|
|
27
34
|
reject(err);
|
|
35
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved-error" /* HttpLogEvents.MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* HttpCacheLogFields.KEY_SET */]: key });
|
|
28
36
|
}
|
|
29
37
|
});
|
|
30
38
|
memoizedCache.set(key, promise);
|
|
@@ -32,3 +40,4 @@ exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
|
32
40
|
}
|
|
33
41
|
};
|
|
34
42
|
};
|
|
43
|
+
exports.memoizationMiddleware = memoizationMiddleware;
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.metricsMiddleware = void 0;
|
|
4
4
|
const RequestCancelledError_1 = require("../../errors/RequestCancelledError");
|
|
5
|
-
const requestStats_1 = require("../../service/http/middlewares/requestStats");
|
|
5
|
+
const requestStats_1 = require("../../service/worker/runtime/http/middlewares/requestStats");
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const retry_1 = require("../../utils/retry");
|
|
8
8
|
const status_1 = require("../../utils/status");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const [_, dur] = durStr ? durStr.split('=') : [null, null];
|
|
12
|
-
const { hopNumber, source, target } = utils_1.parseTimingName(name);
|
|
13
|
-
const formatted = utils_1.formatTimingName({
|
|
14
|
-
hopNumber: Number.isNaN(hopNumber) ? null : hopNumber + 1,
|
|
15
|
-
source,
|
|
16
|
-
target,
|
|
17
|
-
});
|
|
18
|
-
if (dur && formatted) {
|
|
19
|
-
acc.push([formatted, dur]);
|
|
20
|
-
}
|
|
21
|
-
return acc;
|
|
22
|
-
}, []), ramda_1.split(','), ramda_1.replace(/\s/g, ''))(serverTimingsHeaderValue);
|
|
23
|
-
exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
9
|
+
const axios_1 = require("axios");
|
|
10
|
+
const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
24
11
|
const serverTimingStart = process.hrtime();
|
|
25
|
-
const serverTimingLabel = utils_1.shrinkTimings(utils_1.formatTimingName({
|
|
12
|
+
const serverTimingLabel = (0, utils_1.shrinkTimings)((0, utils_1.formatTimingName)({
|
|
26
13
|
hopNumber: 0,
|
|
27
14
|
source: process.env.VTEX_APP_NAME,
|
|
28
15
|
target: name || 'unknown',
|
|
@@ -38,10 +25,13 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
38
25
|
}
|
|
39
26
|
await next();
|
|
40
27
|
if (ctx.config.metric && ctx.response && ctx.response.status) {
|
|
41
|
-
status = status_1.statusLabel(ctx.response.status);
|
|
28
|
+
status = (0, status_1.statusLabel)(ctx.response.status);
|
|
42
29
|
}
|
|
43
30
|
}
|
|
44
31
|
catch (err) {
|
|
32
|
+
if (!(err instanceof axios_1.AxiosError)) {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
45
35
|
const isCancelled = (err.message === requestStats_1.cancelMessage);
|
|
46
36
|
if (ctx.config.metric) {
|
|
47
37
|
errorCode = err.code;
|
|
@@ -53,7 +43,7 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
53
43
|
status = 'timeout';
|
|
54
44
|
}
|
|
55
45
|
else if (err.response && err.response.status) {
|
|
56
|
-
status = status_1.statusLabel(err.response.status);
|
|
46
|
+
status = (0, status_1.statusLabel)(err.response.status);
|
|
57
47
|
}
|
|
58
48
|
else if (isCancelled) {
|
|
59
49
|
status = 'cancelled';
|
|
@@ -84,9 +74,9 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
84
74
|
if (ctx.memoizedHit) {
|
|
85
75
|
Object.assign(extensions, { [`${status}-memoized`]: 1 });
|
|
86
76
|
}
|
|
87
|
-
if (ctx.config
|
|
88
|
-
const
|
|
89
|
-
if (retryCount
|
|
77
|
+
if (ctx.config.retryCount) {
|
|
78
|
+
const retryCount = ctx.config.retryCount;
|
|
79
|
+
if (retryCount > 0) {
|
|
90
80
|
extensions[`retry-${status}-${retryCount}`] = 1;
|
|
91
81
|
}
|
|
92
82
|
}
|
|
@@ -95,11 +85,17 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
95
85
|
: undefined;
|
|
96
86
|
metrics.batch(label, end, extensions);
|
|
97
87
|
if (ctx.config.verbose) {
|
|
98
|
-
console.log(`VERBOSE: ${name}.${ctx.config.label}`,
|
|
99
|
-
|
|
88
|
+
console.log(`VERBOSE: ${name}.${ctx.config.label}`, {
|
|
89
|
+
...extensions,
|
|
90
|
+
...errorCode || errorStatus ? { errorCode, errorStatus } : null,
|
|
91
|
+
millis: end
|
|
92
|
+
? (0, utils_1.hrToMillis)(end)
|
|
100
93
|
: extensions.revalidated || extensions.router || status !== 'success'
|
|
101
|
-
? utils_1.hrToMillis(process.hrtime(start))
|
|
102
|
-
: '(from cache)',
|
|
94
|
+
? (0, utils_1.hrToMillis)(process.hrtime(start))
|
|
95
|
+
: '(from cache)',
|
|
96
|
+
status: ctx.response && ctx.response.status,
|
|
97
|
+
headers: ctx.response && ctx.response.headers,
|
|
98
|
+
});
|
|
103
99
|
}
|
|
104
100
|
}
|
|
105
101
|
else {
|
|
@@ -109,21 +105,12 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
109
105
|
}
|
|
110
106
|
if (serverTiming) {
|
|
111
107
|
// Timings in the client's perspective
|
|
112
|
-
const dur = utils_1.hrToMillis(process.hrtime(serverTimingStart));
|
|
108
|
+
const dur = (0, utils_1.hrToMillis)(process.hrtime(serverTimingStart));
|
|
113
109
|
if (!serverTiming[serverTimingLabel] || Number(serverTiming[serverTimingLabel]) < dur) {
|
|
114
110
|
serverTiming[serverTimingLabel] = `${dur}`;
|
|
115
111
|
}
|
|
116
|
-
// Forward server timings
|
|
117
|
-
const serverTimingsHeader = ramda_1.path(['response', 'headers', 'server-timing'], ctx);
|
|
118
|
-
if (!ctx.cacheHit && !ctx.inflightHit && !ctx.memoizedHit && serverTimingsHeader) {
|
|
119
|
-
const parsedServerTiming = parseServerTiming(serverTimingsHeader);
|
|
120
|
-
ramda_1.forEach(([timingsName, timingsDur]) => {
|
|
121
|
-
if (!serverTiming[timingsName] || Number(serverTiming[timingsName]) < Number(timingsDur)) {
|
|
122
|
-
serverTiming[timingsName] = timingsDur;
|
|
123
|
-
}
|
|
124
|
-
}, parsedServerTiming);
|
|
125
|
-
}
|
|
126
112
|
}
|
|
127
113
|
}
|
|
128
114
|
};
|
|
129
115
|
};
|
|
116
|
+
exports.metricsMiddleware = metricsMiddleware;
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { MiddlewareContext } from '../typings';
|
|
3
3
|
export declare const acceptNotFoundMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
4
4
|
export declare const notFoundFallbackMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
5
|
-
export
|
|
5
|
+
export type IgnoreNotFoundRequestConfig = AxiosRequestConfig & {
|
|
6
6
|
nullIfNotFound?: boolean;
|
|
7
7
|
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notFoundFallbackMiddleware = exports.acceptNotFoundMiddleware = void 0;
|
|
3
4
|
const addNotFound = (validateStatus) => (status) => validateStatus(status) || status === 404;
|
|
4
5
|
function nullIfNotFound(config) {
|
|
5
6
|
return config && config.nullIfNotFound;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
const acceptNotFoundMiddleware = async (ctx, next) => {
|
|
8
9
|
const { config } = ctx;
|
|
9
10
|
if (nullIfNotFound(config)) {
|
|
10
11
|
ctx.config.validateStatus = addNotFound(config.validateStatus);
|
|
11
12
|
}
|
|
12
13
|
await next();
|
|
13
14
|
};
|
|
14
|
-
exports.
|
|
15
|
+
exports.acceptNotFoundMiddleware = acceptNotFoundMiddleware;
|
|
16
|
+
const notFoundFallbackMiddleware = async (ctx, next) => {
|
|
15
17
|
await next();
|
|
16
18
|
const { config } = ctx;
|
|
17
19
|
if (nullIfNotFound(config) && ctx.response && ctx.response.status === 404) {
|
|
18
20
|
ctx.response.data = null;
|
|
19
21
|
}
|
|
20
22
|
};
|
|
23
|
+
exports.notFoundFallbackMiddleware = notFoundFallbackMiddleware;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { MiddlewareContext } from '../typings';
|
|
2
|
+
import { Recorder } from './../../service/worker/runtime/utils/recorder';
|
|
2
3
|
export declare const recorderMiddleware: (recorder: Recorder) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
3
|
-
export declare type Recorder = (headers: any) => void;
|
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recorderMiddleware =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
exports.recorderMiddleware = void 0;
|
|
4
|
+
const axios_1 = require("axios");
|
|
5
|
+
const recorderMiddleware = (recorder) => async (ctx, next) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if ((_a = ctx.config) === null || _a === void 0 ? void 0 : _a.ignoreRecorder) {
|
|
8
|
+
await next();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
await next();
|
|
13
|
+
if (ctx.response) {
|
|
14
|
+
recorder.record(ctx.response.headers);
|
|
10
15
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (!(err instanceof axios_1.AxiosError)) {
|
|
15
19
|
throw err;
|
|
16
20
|
}
|
|
17
|
-
|
|
21
|
+
if (err.response && err.response.headers && err.response.status === 404) {
|
|
22
|
+
recorder.record(err.response.headers);
|
|
23
|
+
}
|
|
24
|
+
throw err;
|
|
25
|
+
}
|
|
18
26
|
};
|
|
27
|
+
exports.recorderMiddleware = recorderMiddleware;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import HttpAgent from 'agentkeepalive';
|
|
2
|
+
export declare class HttpAgentSingleton {
|
|
3
|
+
static getHttpAgent(): HttpAgent;
|
|
4
|
+
static httpAgentStats(): {
|
|
5
|
+
freeSockets: number;
|
|
6
|
+
pendingRequests: number;
|
|
7
|
+
sockets: number;
|
|
8
|
+
};
|
|
9
|
+
private static httpAgent;
|
|
10
|
+
private static count;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpAgentSingleton = void 0;
|
|
4
|
+
const agents_1 = require("../../agents");
|
|
5
|
+
class HttpAgentSingleton {
|
|
6
|
+
static getHttpAgent() {
|
|
7
|
+
if (!HttpAgentSingleton.httpAgent) {
|
|
8
|
+
HttpAgentSingleton.httpAgent = (0, agents_1.createHttpAgent)();
|
|
9
|
+
}
|
|
10
|
+
return HttpAgentSingleton.httpAgent;
|
|
11
|
+
}
|
|
12
|
+
static httpAgentStats() {
|
|
13
|
+
const sockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.sockets);
|
|
14
|
+
const freeSockets = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.freeSockets);
|
|
15
|
+
const pendingRequests = HttpAgentSingleton.count(HttpAgentSingleton.httpAgent.requests);
|
|
16
|
+
return {
|
|
17
|
+
freeSockets,
|
|
18
|
+
pendingRequests,
|
|
19
|
+
sockets,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
static count(obj) {
|
|
23
|
+
try {
|
|
24
|
+
return Object.values(obj).reduce((acc, val) => acc += val.length, 0);
|
|
25
|
+
}
|
|
26
|
+
catch (_) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.HttpAgentSingleton = HttpAgentSingleton;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Limit } from 'p-limit';
|
|
3
|
+
import { MiddlewareContext } from '../../typings';
|
|
4
|
+
export interface DefaultMiddlewareArgs {
|
|
5
|
+
baseURL: string | undefined;
|
|
6
|
+
rawHeaders: Record<string, string>;
|
|
7
|
+
params: Record<string, string> | undefined;
|
|
8
|
+
timeout: number;
|
|
9
|
+
retries?: number;
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
exponentialTimeoutCoefficient?: number;
|
|
12
|
+
initialBackoffDelay?: number;
|
|
13
|
+
exponentialBackoffCoefficient?: number;
|
|
14
|
+
httpsAgent?: AxiosRequestConfig['httpsAgent'];
|
|
15
|
+
}
|
|
16
|
+
export declare const defaultsMiddleware: ({ baseURL, rawHeaders, params, timeout, retries, verbose, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent }: DefaultMiddlewareArgs) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
17
|
+
export declare const routerCacheMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
18
|
+
export declare const requestMiddleware: (limit?: Limit) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|